本文整理汇总了Golang中github.com/shadowsocks/shadowsocks-go/shadowsocks.Config.GetServerArray方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.GetServerArray方法的具体用法?Golang Config.GetServerArray怎么用?Golang Config.GetServerArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shadowsocks/shadowsocks-go/shadowsocks.Config
的用法示例。
在下文中一共展示了Config.GetServerArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseServerConfig
func parseServerConfig(config *ss.Config) {
if len(config.ServerPassword) == 0 {
// only one encryption table
cipher, err := ss.NewCipher(config.Method, config.Password)
if err != nil {
log.Fatal("Failed generating ciphers:", err)
}
srvPort := strconv.Itoa(config.ServerPort)
srvArr := config.GetServerArray()
n := len(srvArr)
servers.srvCipher = make([]*ServerCipher, n)
for i, s := range srvArr {
if ss.HasPort(s) {
log.Println("ignore server_port option for server", s)
servers.srvCipher[i] = &ServerCipher{s, cipher}
} else {
servers.srvCipher[i] = &ServerCipher{s + ":" + srvPort, cipher}
}
}
} else {
// multiple servers
n := len(config.ServerPassword)
servers.srvCipher = make([]*ServerCipher, n)
cipherCache := make(map[string]ss.Cipher)
i := 0
for _, serverInfo := range config.ServerPassword {
if len(serverInfo) < 2 || len(serverInfo) > 3 {
log.Fatalf("server %v syntax error\n", serverInfo)
}
server := serverInfo[0]
passwd := serverInfo[1]
encmethod := ""
if len(serverInfo) == 3 {
encmethod = serverInfo[2]
}
if !ss.HasPort(server) {
log.Fatalf("no port for server %s, please specify port in the form of %s:port\n", server, server)
}
cipher, ok := cipherCache[passwd]
if !ok {
var err error
cipher, err = ss.NewCipher(encmethod, passwd)
if err != nil {
log.Fatal("Failed generating ciphers:", err)
}
cipherCache[passwd] = cipher
}
servers.srvCipher[i] = &ServerCipher{server, cipher}
i++
}
}
servers.failCnt = make([]int, len(servers.srvCipher))
for _, se := range servers.srvCipher {
log.Println("available remote server", se.server)
}
return
}
示例2: initServers
func initServers(config *ss.Config) {
if len(config.ServerPassword) == 0 {
// only one encryption table
cipher, err := ss.NewCipher(config.Password)
if err != nil {
log.Fatal("Failed generating ciphers:", err)
}
srvPort := strconv.Itoa(config.ServerPort)
srvArr := config.GetServerArray()
n := len(srvArr)
servers.srvCipher = make([]*ServerCipher, n, n)
for i, s := range srvArr {
if ss.HasPort(s) {
log.Println("ignore server_port option for server", s)
servers.srvCipher[i] = &ServerCipher{s, cipher}
} else {
servers.srvCipher[i] = &ServerCipher{s + ":" + srvPort, cipher}
}
}
} else {
n := len(config.ServerPassword)
servers.srvCipher = make([]*ServerCipher, n, n)
cipherCache := make(map[string]ss.Cipher)
i := 0
for s, passwd := range config.ServerPassword {
if !ss.HasPort(s) {
log.Fatal("no port for server %s, please specify port in the form of %s:port", s, s)
}
cipher, ok := cipherCache[passwd]
if !ok {
var err error
cipher, err = ss.NewCipher(passwd)
if err != nil {
log.Fatal("Failed generating ciphers:", err)
}
cipherCache[passwd] = cipher
}
servers.srvCipher[i] = &ServerCipher{s, cipher}
i++
}
}
for _, se := range servers.srvCipher {
log.Println("available remote server", se.server)
}
return
}
示例3: initServers
func initServers(config *ss.Config) {
if len(config.ServerPassword) == 0 {
// only one encryption table
enctbl := ss.GetTable(config.Password)
srvPort := strconv.Itoa(config.ServerPort)
srvArr := config.GetServerArray()
n := len(srvArr)
servers.srvenc = make([]*ServerEnctbl, n, n)
for i, s := range srvArr {
if ss.HasPort(s) {
log.Println("ignore server_port option for server", s)
servers.srvenc[i] = &ServerEnctbl{s, enctbl}
} else {
servers.srvenc[i] = &ServerEnctbl{s + ":" + srvPort, enctbl}
}
}
} else {
n := len(config.ServerPassword)
servers.srvenc = make([]*ServerEnctbl, n, n)
tblCache := make(map[string]*ss.EncryptTable)
i := 0
for s, passwd := range config.ServerPassword {
if !ss.HasPort(s) {
log.Fatal("no port for server %s, please specify port in the form of %s:port", s, s)
}
tbl, ok := tblCache[passwd]
if !ok {
tbl = ss.GetTable(passwd)
tblCache[passwd] = tbl
}
servers.srvenc[i] = &ServerEnctbl{s, tbl}
i++
}
}
for _, se := range servers.srvenc {
log.Println("available remote server", se.server)
}
return
}
示例4: parseServerConfig
func parseServerConfig(config *ss.Config) {
hasPort := func(s string) bool {
_, port, err := net.SplitHostPort(s)
if err != nil {
return false
}
return port != ""
}
if len(config.ServerPassword) == 0 {
method := config.Method
if config.Auth {
method += "-ota"
}
// only one encryption table
cipher, err := ss.NewCipher(method, config.Password)
if err != nil {
log.Fatal("Failed generating ciphers:", err)
}
srvPort := strconv.Itoa(config.ServerPort)
srvArr := config.GetServerArray()
n := len(srvArr)
servers.srvCipher = make([]*ServerCipher, n)
for i, s := range srvArr {
if hasPort(s) {
log.Println("ignore server_port option for server", s)
servers.srvCipher[i] = &ServerCipher{s, cipher}
} else {
servers.srvCipher[i] = &ServerCipher{net.JoinHostPort(s, srvPort), cipher}
}
}
} else {
// multiple servers
n := len(config.ServerPassword)
servers.srvCipher = make([]*ServerCipher, n)
cipherCache := make(map[string]*ss.Cipher)
i := 0
for _, serverInfo := range config.ServerPassword {
if len(serverInfo) < 2 || len(serverInfo) > 3 {
log.Fatalf("server %v syntax error\n", serverInfo)
}
server := serverInfo[0]
passwd := serverInfo[1]
encmethod := ""
if len(serverInfo) == 3 {
encmethod = serverInfo[2]
}
if !hasPort(server) {
log.Fatalf("no port for server %s\n", server)
}
// Using "|" as delimiter is safe here, since no encryption
// method contains it in the name.
cacheKey := encmethod + "|" + passwd
cipher, ok := cipherCache[cacheKey]
if !ok {
var err error
cipher, err = ss.NewCipher(encmethod, passwd)
if err != nil {
log.Fatal("Failed generating ciphers:", err)
}
cipherCache[cacheKey] = cipher
}
servers.srvCipher[i] = &ServerCipher{server, cipher}
i++
}
}
servers.failCnt = make([]int, len(servers.srvCipher))
for _, se := range servers.srvCipher {
log.Println("available remote server", se.server)
}
return
}
示例5: parseServerConfig
func parseServerConfig(config *ss.Config) {
hasPort := func(s string) bool {
_, port, err := net.SplitHostPort(s)
if err != nil {
return false
}
return port != ""
}
debug.Printf("config.Password = \"%s\"\n", config.Password)
debug.Printf("config.Method = \"%s\"\n", config.Method)
debug.Printf("config.ServerPassword = %s", config.ServerPassword)
if len(config.ServerPassword) == 0 {
// only one encryption table
cipher, err := ss.NewCipher(config.Method, config.Password)
if err != nil {
log.Fatal("Failed generating ciphers:", err)
}
srvPort := strconv.Itoa(config.ServerPort)
srvArr := config.GetServerArray()
n := len(srvArr)
servers.srvCipher = make([]*ServerCipher, n)
for i, s := range srvArr {
if hasPort(s) {
log.Println("ignore server_port option for server", s)
servers.srvCipher[i] = &ServerCipher{s, cipher}
} else {
servers.srvCipher[i] = &ServerCipher{net.JoinHostPort(s, srvPort), cipher}
}
}
} else {
// multiple servers
n := len(config.ServerPassword)
servers.srvCipher = make([]*ServerCipher, n)
cipherCache := make(map[string]*ss.Cipher)
i := 0
for _, serverInfo := range config.ServerPassword {
if len(serverInfo) < 2 || len(serverInfo) > 3 {
log.Fatalf("server %v syntax error\n", serverInfo)
}
server := serverInfo[0]
passwd := serverInfo[1]
encmethod := ""
if len(serverInfo) == 3 {
encmethod = serverInfo[2]
debug.Printf("encryption method = \"%s\"\n", encmethod)
}
if !hasPort(server) {
log.Fatalf("no port for server %s\n", server)
}
cipher, ok := cipherCache[passwd]
if !ok {
var err error
cipher, err = ss.NewCipher(encmethod, passwd)
if err != nil {
log.Fatal("Failed generating ciphers:", err)
}
cipherCache[passwd] = cipher
}
servers.srvCipher[i] = &ServerCipher{server, cipher}
i++
}
}
servers.failCnt = make([]int, len(servers.srvCipher))
for _, se := range servers.srvCipher {
log.Println("available remote server", se.server)
}
return
}