Allow RemotePort to be optionally set in JSON. If it's not set in JSON, Cloak falls back to SS_REMOTE_PORT in SS mode, or the -p argument in standalone

This commit is contained in:
beans 2020-02-12 14:56:25 +08:00 committed by Andy Wang
parent 517a6d6e57
commit 23082aff4f
1 changed files with 12 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"io/ioutil" "io/ioutil"
"strconv"
"strings" "strings"
"time" "time"
@ -23,6 +24,7 @@ type rawConfig struct {
Transport string Transport string
NumConn int NumConn int
StreamTimeout int StreamTimeout int
RemotePort int
} }
// State stores the parsed configuration fields // State stores the parsed configuration fields
@ -142,5 +144,15 @@ func (sta *State) ParseConfig(conf string) (err error) {
} }
sta.staticPub = pub sta.staticPub = pub
// OPTIONAL: set RemotePort via JSON
// if RemotePort is specified in the JSON we overwrite sta.RemotePort
// if not, don't do anything, since sta.RemotePort is already initialised in ck-client.go
if preParse.RemotePort != 0 {
// basic validity check
if preParse.RemotePort >= 1 && preParse.RemotePort <= 65535 {
sta.RemotePort = strconv.Itoa(preParse.RemotePort)
}
}
return nil return nil
} }