当前位置: 首页>>代码示例>>Golang>>正文


Golang Conn.SetReadDeadline方法代码示例

本文整理汇总了Golang中crypto/tls.Conn.SetReadDeadline方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.SetReadDeadline方法的具体用法?Golang Conn.SetReadDeadline怎么用?Golang Conn.SetReadDeadline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在crypto/tls.Conn的用法示例。


在下文中一共展示了Conn.SetReadDeadline方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: test_conn

func test_conn(conn *tls.Conn, options *ScanOptions, record *ScanRecord) bool {
	//check SSL certificate
	success := false
	for _, cert := range conn.ConnectionState().PeerCertificates {
		for _, verifyHost := range options.Config.ScanGoogleIP.SSLCertVerifyHosts {
			if cert.VerifyHostname(verifyHost) != nil {
				return false
			} else {
				success = true
			}
		}
		if success {
			break
		}
	}
	for _, verifyHost := range options.Config.ScanGoogleIP.HTTPVerifyHosts {
		conn.SetReadDeadline(time.Now().Add(record.httpVerifyTimeout))
		req, _ := http.NewRequest("HEAD", "https://"+verifyHost, nil)
		res, err := httputil.NewClientConn(conn, nil).Do(req)
		if nil != err || res.StatusCode >= 400 {
			return false
		}
	}
	return true
}
开发者ID:XiliangSong,项目名称:gscan,代码行数:25,代码来源:scan.go

示例2: find_match_hosts

func find_match_hosts(conn *tls.Conn, options *ScanOptions, record *ScanRecord) bool {
	if nil == record.MatchHosts || len(record.MatchHosts) == 0 {
		record.MatchHosts = options.SSLMatchHosts(conn)
	}

	newhosts := make([]string, 0)
	for _, host := range record.MatchHosts {
		if options.HaveHostInRecords(host) {
			continue
		}
		newhosts = append(newhosts, host)
		valid := true
		for _, pattern := range options.Config.ScanGoogleHosts.HTTPVerifyHosts {
			if matchHostnames(pattern, host) {
				conn.SetReadDeadline(time.Now().Add(record.httpVerifyTimeout))
				req, _ := http.NewRequest("HEAD", "https://"+host, nil)
				res, err := httputil.NewClientConn(conn, nil).Do(req)
				if nil != err || res.StatusCode >= 400 {
					valid = false
				}
				break
			}
		}
		if valid {
			newhosts = append(newhosts, host)
		}
	}
	record.MatchHosts = newhosts
	return len(record.MatchHosts) > 0
}
开发者ID:XiliangSong,项目名称:gscan,代码行数:30,代码来源:scan.go

示例3: serverFunc

func serverFunc(conn *tls.Conn) {
	defer conn.Close()
	conn.SetReadDeadline(time.Now().Add(time.Second))
	io.Copy(conn, conn)
}
开发者ID:carriercomm,项目名称:gokeyless,代码行数:5,代码来源:proxy_test.go

示例4: main

func main() {
	startTime = time.Now()
	runtime.GOMAXPROCS(4)
	rand.Seed(time.Now().Unix())
	//read in bot config, or initialize default config
	configFile, err := ioutil.ReadFile("config.json")
	if err == nil {
		err = json.Unmarshal(configFile, &config)
		if err != nil {
			log.Fatal("Error unmarshalling config.json")
		}
	} else {
		config = JSONconfig{"chat.freenode.net", 6667, "yaircb", "", "*", false, make([]string, 0), make([]string, 0)}
	}
	fmt.Println(config)

	//set up command detection regular expressions
	regexpCmds = make([]*regexp.Regexp, 3)
	regexpCmds[0] = regexp.MustCompile(`^:(\S*?)!(\S*?)@(\S*?) PRIVMSG (\S*) :` + config.Nick + `\W?\s*(.*)`)
	regexpCmds[1] = regexp.MustCompile(`^:(\S*)?!(\S*)[email protected](\S*)? PRIVMSG (\S*) :\s*\+(.*)`)
	regexpCmds[2] = regexp.MustCompile(`^:(\S*)?!(\S*)[email protected](\S*)? PRIVMSG (` + config.Nick + `) :\s*(.*)`)

	//initialize global string->function command map
	funcMap = initMap()
	err = initCmdRedis()
	if err != nil { //if redis init fails, print error
		log.Println(err)
	}

	if err == nil { //only run web server is redis init doesn't fail
		//initialize web server
		initWebRedis()
		http.Handle("/resources/", http.StripPrefix("/resources/", http.FileServer(http.Dir("resources"))))
		http.HandleFunc("/register/", registerHandler)
		http.HandleFunc("/login/", loginHandler)
		http.HandleFunc("/loginCheck/", loginCheckHandler)
		http.HandleFunc("/", indexHandler)
		http.HandleFunc("/save/", saveHandler)
		http.HandleFunc("/user/", userHandler)
		go http.ListenAndServeTLS(":8080", "ssl.crt", "ssl.pem", nil)
	}

	var conns uint16
	writeChan := make(chan string) //used to send strings from readFromConsole to writeToServer
	readChan := make(chan string)  //send strings from readFromServer to writeToConsole
	//wgSrv for goroutines to/from sever, wg for readFromConsole
	var wgSrv, wg sync.WaitGroup
	quitChans := make(chan chan bool, 2)
	error := make(chan bool, 1) //used to indicate readFromConsole exited
	//initiate connection
	wg.Add(2)
	go readFromConsole(writeChan, &wg, error, quitChans) //doesnt get restarted on connection EOF
	wtsQChan := make(chan bool, 1)
	go writeToConsole(readChan, writeChan, &wg, wtsQChan, quitChans) //doesnt get restarted on connection EOF
connectionLoop:
	for ; ; conns++ {
		select {
		case <-error: //if readFromConsole got a "QUIT", exit program
			wtsQChan <- true
			break connectionLoop
		default: //otherwise restart connections
			if conns == 0 {
				log.Println("STARTING...")
			} else {
				log.Println("RESTARTING...")
				log.Println("WAITING 1 MINUTE...")
				time.Sleep(time.Minute)
			}
			var socketRead *bufio.Reader
			var socketWrite *bufio.Writer
			err := errors.New("")
			if config.TLS {
				log.Printf("Connecting to %s:%d with TLS...\n", config.Server, config.Port)
				var sslSocket *tls.Conn
				sslSocket, err = tls.Dial("tcp", fmt.Sprintf("%s:%d", config.Server, config.Port), nil)
				if err == nil {
					sslSocket.SetReadDeadline(time.Time{})
					socketWrite = bufio.NewWriter(sslSocket)
					socketRead = bufio.NewReader(sslSocket)
				} else {
					log.Println("Disabling TLS...")
				}
			}
			if err != nil || !config.TLS { //!config.TLS shouldn't actually be evaluted, as err != nil would be true from err init
				log.Printf("Connecting to %s:%d...\n", config.Server, config.Port)
				socket, err := textproto.Dial("tcp", fmt.Sprintf("%s:%d", config.Server, config.Port))
				if err != nil {
					errOut(err, quitChans)
					return
				}
				socketWrite = socket.Writer.W
				socketRead = socket.Reader.R
			}
			//make writer/reader to/from server
			//send initial IRC messages, NICK and USER
			_, err = socketWrite.WriteString("NICK " + config.Nick + "\r\n")
			if err == nil {
				err = socketWrite.Flush()
			}
			log.Print("NICK " + config.Nick + "\r\n")
//.........这里部分代码省略.........
开发者ID:heydabop,项目名称:yaircb,代码行数:101,代码来源:irc.go


注:本文中的crypto/tls.Conn.SetReadDeadline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。