func getTable(password string) (tbl *ss.EncryptTable) {
	if table.cache != nil {
		var ok bool
		tbl, ok = table.cache[password]
		if ok {
			atomic.AddInt32(&table.hitCnt, 1)
			debug.Println("table cache hit for password:", password)
			return
		}
		tbl = ss.GetTable(password)
		table.cache[password] = tbl
	} else {
		tbl = ss.GetTable(password)
	}
	return
}
Beispiel #2
0
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
}
Beispiel #3
0
func initShadowSocks() {
	if config.ShadowSocks != "" && config.ShadowPasswd != "" {
		hasShadowSocksServer = true
		debug.Println("shadowsocks server:", config.ShadowSocks)
		encTbl = ss.GetTable(config.ShadowPasswd)
		return
	}
	if (config.ShadowSocks != "" && config.ShadowPasswd == "") ||
		(config.ShadowSocks == "" && config.ShadowPasswd != "") {
		errl.Println("Missing option: shadowSocks and shadowPasswd should be both given")
	}
}