本文整理汇总了Golang中github.com/shadowsocks/shadowsocks-go/shadowsocks.Cipher类的典型用法代码示例。如果您正苦于以下问题:Golang Cipher类的具体用法?Golang Cipher怎么用?Golang Cipher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cipher类的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()))
}
}
示例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)
}
}
}
示例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])
}
示例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()))
}
}
示例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()))
}
}