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


Golang Config.GetServerArray方法代码示例

本文整理汇总了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
}
开发者ID:jameszhl,项目名称:shadowsocks-go,代码行数:59,代码来源:local.go

示例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
}
开发者ID:code2u,项目名称:shadowsocks-go,代码行数:48,代码来源:local.go

示例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
}
开发者ID:vicenteforever,项目名称:shadowsocks-go,代码行数:41,代码来源:local.go

示例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
}
开发者ID:bg4kks,项目名称:shadowsocks-go,代码行数:74,代码来源:local.go

示例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
}
开发者ID:uin57,项目名称:shadowsocks-go-hack,代码行数:73,代码来源:local.go


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