Skip to content
This repository was archived by the owner on Apr 9, 2020. It is now read-only.

Commit ff5b147

Browse files
committed
fix timeout support in config file
1 parent 6a03846 commit ff5b147

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

cmd/shadowsocks-local/local.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ var (
3434
const (
3535
socksVer5 = 5
3636
socksCmdConnect = 1
37+
38+
defaultTimeout = 300
3739
)
3840

3941
func init() {
@@ -414,7 +416,7 @@ func main() {
414416
flag.StringVar(&cmdConfig.LocalAddress, "b", "", "local address, listen only to this address if specified")
415417
flag.StringVar(&cmdConfig.Password, "k", "", "password")
416418
flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port")
417-
flag.IntVar(&cmdConfig.Timeout, "t", 300, "timeout in seconds")
419+
flag.IntVar(&cmdConfig.Timeout, "t", 0, "timeout in seconds")
418420
flag.IntVar(&cmdConfig.LocalPort, "l", 0, "local socks5 proxy port")
419421
flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, default: aes-256-cfb")
420422
flag.BoolVar((*bool)(&debug), "d", false, "print debug message")
@@ -461,6 +463,12 @@ func main() {
461463
if config.Method == "" {
462464
config.Method = "aes-256-cfb"
463465
}
466+
if config.Timeout == 0 {
467+
// must use ss.UpdateConfig to modify readTimeout in ss package
468+
ss.UpdateConfig(config, &ss.Config{
469+
Timeout: defaultTimeout,
470+
})
471+
}
464472
if len(config.ServerPassword) == 0 {
465473
if !enoughOptions(config) {
466474
fmt.Fprintln(os.Stderr, "must specify server address, password and both server/local port")

cmd/shadowsocks-server/server.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const (
3636
lenIPv6 = net.IPv6len + 2 // ipv6 + 2port
3737
lenDmBase = 2 // 1addrLen + 2port, plus addrLen
3838
// lenHmacSha1 = 10
39+
40+
defaultTimeout = 300
3941
)
4042

4143
var debug ss.DebugLog
@@ -437,7 +439,7 @@ func main() {
437439
flag.StringVar(&configFile, "c", "config.json", "specify config file")
438440
flag.StringVar(&cmdConfig.Password, "k", "", "password")
439441
flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port")
440-
flag.IntVar(&cmdConfig.Timeout, "t", 300, "timeout in seconds")
442+
flag.IntVar(&cmdConfig.Timeout, "t", 0, "timeout in seconds")
441443
flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, default: aes-256-cfb")
442444
flag.IntVar(&core, "core", 0, "maximum number of CPU cores to use, default is determinied by Go runtime")
443445
flag.BoolVar((*bool)(&debug), "d", false, "print debug message")
@@ -468,6 +470,12 @@ func main() {
468470
if config.Method == "" {
469471
config.Method = "aes-256-cfb"
470472
}
473+
if config.Timeout == 0 {
474+
// must use ss.UpdateConfig to modify readTimeout in ss package
475+
ss.UpdateConfig(config, &ss.Config{
476+
Timeout: defaultTimeout,
477+
})
478+
}
471479
if err = ss.CheckCipherMethod(config.Method); err != nil {
472480
fmt.Fprintln(os.Stderr, err)
473481
os.Exit(1)

0 commit comments

Comments
 (0)