當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Cipher.Copy方法代碼示例

本文整理匯總了Golang中github.com/shadowsocks/shadowsocks-go/shadowsocks.Cipher.Copy方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cipher.Copy方法的具體用法?Golang Cipher.Copy怎麽用?Golang Cipher.Copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/shadowsocks/shadowsocks-go/shadowsocks.Cipher的用法示例。


在下文中一共展示了Cipher.Copy方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: run

func run(port, password string) {
	ln, err := net.Listen("tcp", ":"+port)
	if err != nil {
		log.Printf("error listening port %v: %v\n", port, err)
		return
	}
	passwdManager.add(port, password, ln)
	var cipher *ss.Cipher
	log.Printf("server listening port %v ...\n", port)
	for {
		conn, err := ln.Accept()
		if err != nil {
			// listener maybe closed to update password
			debug.Printf("accept error: %v\n", err)
			return
		}
		// Creating cipher upon first connection.
		if cipher == nil {
			log.Println("creating cipher for port:", port)
			cipher, err = ss.NewCipher(config.Method, password)
			if err != nil {
				log.Printf("Error generating cipher for port: %s %v\n", port, err)
				conn.Close()
				continue
			}
		}
		go handleConnection(ss.NewConn(conn, cipher.Copy()))
	}
}
開發者ID:WaylandGod,項目名稱:shadowsocks-go,代碼行數:29,代碼來源:server.go

示例2: get

func get(connid int, uri, serverAddr string, rawAddr []byte, cipher ss.Cipher, done chan []time.Duration) {
	reqDone := 0
	reqTime := make([]time.Duration, config.nreq)
	defer func() {
		done <- reqTime[:reqDone]
	}()
	tr := &http.Transport{
		Dial: func(_, _ string) (net.Conn, error) {
			return ss.DialWithRawAddr(rawAddr, serverAddr, cipher.Copy())
		},
	}

	buf := make([]byte, 8192)
	client := &http.Client{Transport: tr}
	for ; reqDone < config.nreq; reqDone++ {
		start := time.Now()
		if err := doOneRequest(client, uri, buf); err != nil {
			return
		}
		reqTime[reqDone] = time.Now().Sub(start)

		if (reqDone+1)%1000 == 0 {
			fmt.Printf("conn %d finished %d get requests\n", connid, reqDone+1)
		}
	}
}
開發者ID:jameszhl,項目名稱:shadowsocks-go,代碼行數:26,代碼來源:httpget.go

示例3: runUDP

func runUDP(port string, password [3]string) {
	addr, _ := net.ResolveUDPAddr(netUdp, ":"+port)
	conn, err := net.ListenUDP(netUdp, addr)
	if err != nil {
		log.Printf("error listening udp port %v: %v\n", port, err)
		return
	}
	passwdManager.addUDP(port, password, conn)
	log.Printf("server listening udp port %v ...\n", port)
	defer conn.Close()
	var cipher *ss.Cipher
	cipher, err = ss.NewCipher(config.Method, password[0])
	if err != nil {
		log.Printf("Error generating cipher for udp port: %s %v\n", port, err)
		conn.Close()
	}
	ss.HandleUDPConnection(ss.NewUDPConn(conn, cipher.Copy()), password[1])
}
開發者ID:better0332,項目名稱:my-shadowsocks-go,代碼行數:18,代碼來源:server.go

示例4: run

func run(port, password string) {

	var addr string
	var lastTime int64

	ln, err := net.Listen("tcp", ":"+port)
	if err != nil {
		log.Printf("error listening port %v: %v\n", port, err)
		return
	}
	passwdManager.add(port, password, ln)
	var cipher *ss.Cipher
	log.Printf("server listening port %v ...\n", port)
	for {
		conn, err := ln.Accept()
		if err != nil {
			// listener maybe closed to update password
			debug.Printf("accept error: %v\n", err)
			return
		}

		newaddr := conn.RemoteAddr().String()
		nowtime := time.Now().Unix()
		if addr != newaddr && lastTime >= nowtime {
			conn.Close()
			continue
		}
		lastTime = nowtime
		addr = newaddr

		// Creating cipher upon first connection.
		if cipher == nil {
			log.Println("creating cipher for port:", port)
			cipher, err = ss.NewCipher(config.Method, password)
			if err != nil {
				log.Printf("Error generating cipher for port: %s %v\n", port, err)
				conn.Close()
				continue
			}
		}
		go handleConnection(ss.NewConn(conn, cipher.Copy()))
	}
}
開發者ID:neil-zeng,項目名稱:shadowsocks-go,代碼行數:43,代碼來源:server.go

示例5: run

func run(port string) {
	ln, err := net.Listen("tcp", ":"+port)
	if err != nil {
		log.Printf("error listening port %v: %v\n", port, err)
		os.Exit(0)
	}
	var cipher *ss.Cipher
	log.Printf("server listening port %v ...\n", port)
	for {
		conn, err := ln.Accept()
		if err != nil {
			log.Printf("accept error: %v\n", err)
			continue
		}

		user, err := getUser(conn)
		if err != nil {
			log.Printf("Error get passeoed: %s %v\n", port, err)
			conn.Close()
			continue
		}
		size, err := storage.GetSize("flow:" + user.Name)
		if user.Limit < size {
			log.Printf("Error user runover: %s\n", size)
			conn.Close()
			continue
		}

		// log.Println("creating cipher for user:", user.Name)
		cipher, err = ss.NewCipher(user.Method, user.Password)
		if err != nil {
			log.Printf("Error generating cipher for user: %s %v\n", user.Name, err)
			conn.Close()
			continue
		}
		go handleConnection(user, ss.NewConn(conn, cipher.Copy()))
	}
}
開發者ID:tallriham,項目名稱:shadowsocks-auth,代碼行數:38,代碼來源:server.go


注:本文中的github.com/shadowsocks/shadowsocks-go/shadowsocks.Cipher.Copy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。