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

Commit

Permalink
fix timeout support in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ayanamist committed Jul 2, 2019
1 parent 6a03846 commit ff5b147
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion cmd/shadowsocks-local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var (
const (
socksVer5 = 5
socksCmdConnect = 1

defaultTimeout = 300
)

func init() {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 9 additions & 1 deletion cmd/shadowsocks-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ff5b147

Please sign in to comment.