diff --git a/cmd/shadowsocks-local/local.go b/cmd/shadowsocks-local/local.go index 604bf9f7..256c8280 100644 --- a/cmd/shadowsocks-local/local.go +++ b/cmd/shadowsocks-local/local.go @@ -34,6 +34,8 @@ var ( const ( socksVer5 = 5 socksCmdConnect = 1 + + defaultTimeout = 300 ) func init() { @@ -414,7 +416,7 @@ func main() { flag.StringVar(&cmdConfig.LocalAddress, "b", "", "local address, listen only to this address if specified") flag.StringVar(&cmdConfig.Password, "k", "", "password") flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port") - flag.IntVar(&cmdConfig.Timeout, "t", 300, "timeout in seconds") + flag.IntVar(&cmdConfig.Timeout, "t", 0, "timeout in seconds") flag.IntVar(&cmdConfig.LocalPort, "l", 0, "local socks5 proxy port") flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, default: aes-256-cfb") flag.BoolVar((*bool)(&debug), "d", false, "print debug message") @@ -461,6 +463,12 @@ func main() { if config.Method == "" { config.Method = "aes-256-cfb" } + if config.Timeout == 0 { + // must use ss.UpdateConfig to modify readTimeout in ss package + ss.UpdateConfig(config, &ss.Config{ + Timeout: defaultTimeout, + }) + } if len(config.ServerPassword) == 0 { if !enoughOptions(config) { fmt.Fprintln(os.Stderr, "must specify server address, password and both server/local port") diff --git a/cmd/shadowsocks-server/server.go b/cmd/shadowsocks-server/server.go index 28099981..6507e598 100644 --- a/cmd/shadowsocks-server/server.go +++ b/cmd/shadowsocks-server/server.go @@ -36,6 +36,8 @@ const ( lenIPv6 = net.IPv6len + 2 // ipv6 + 2port lenDmBase = 2 // 1addrLen + 2port, plus addrLen // lenHmacSha1 = 10 + + defaultTimeout = 300 ) var debug ss.DebugLog @@ -437,7 +439,7 @@ func main() { flag.StringVar(&configFile, "c", "config.json", "specify config file") flag.StringVar(&cmdConfig.Password, "k", "", "password") flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port") - flag.IntVar(&cmdConfig.Timeout, "t", 300, "timeout in seconds") + flag.IntVar(&cmdConfig.Timeout, "t", 0, "timeout in seconds") flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, default: aes-256-cfb") flag.IntVar(&core, "core", 0, "maximum number of CPU cores to use, default is determinied by Go runtime") flag.BoolVar((*bool)(&debug), "d", false, "print debug message") @@ -468,6 +470,12 @@ func main() { if config.Method == "" { config.Method = "aes-256-cfb" } + if config.Timeout == 0 { + // must use ss.UpdateConfig to modify readTimeout in ss package + ss.UpdateConfig(config, &ss.Config{ + Timeout: defaultTimeout, + }) + } if err = ss.CheckCipherMethod(config.Method); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1)