本文整理匯總了Golang中github.com/orvice/shadowsocks-go/mu/user.User.GetCipher方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.GetCipher方法的具體用法?Golang User.GetCipher怎麽用?Golang User.GetCipher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/orvice/shadowsocks-go/mu/user.User
的用法示例。
在下文中一共展示了User.GetCipher方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runWithCustomMethod
func runWithCustomMethod(user user.User) {
// port, password string, Cipher *ss.Cipher
port := strconv.Itoa(user.GetPort())
password := user.GetPasswd()
ln, err := net.Listen("tcp", ":"+port)
if err != nil {
Log.Error(fmt.Sprintf("error listening port %v: %v\n", port, err))
os.Exit(1)
}
passwdManager.add(port, password, ln)
cipher, err := user.GetCipher()
if err != nil {
return
}
Log.Info(fmt.Sprintf("server listening port %v ...\n", port))
for {
conn, err := ln.Accept()
if err != nil {
// listener maybe closed to update password
Log.Debug(fmt.Sprintf("accept error: %v\n", err))
return
}
// Creating cipher upon first connection.
if cipher == nil {
Log.Debug("creating cipher for port:", port)
cipher, err = ss.NewCipher(user.GetMethod(), password)
if err != nil {
Log.Error(fmt.Sprintf("Error generating cipher for port: %s %v\n", port, err))
conn.Close()
continue
}
}
go handleConnection(user, ss.NewConn(conn, cipher.Copy()))
}
}