Refactor InitState

This commit is contained in:
Andy Wang 2019-08-20 22:48:01 +01:00
parent 87a7684e10
commit 46c02d17f4
3 changed files with 10 additions and 15 deletions

View File

@ -278,7 +278,14 @@ func main() {
log.Info("Starting standalone mode")
}
sta := client.InitState(localHost, localPort, remoteHost, remotePort, time.Now)
sta := &client.State{
LocalHost: localHost,
LocalPort: localPort,
RemoteHost: remoteHost,
RemotePort: remotePort,
Now: time.Now,
}
err := sta.ParseConfig(config)
if err != nil {
log.Fatal(err)

View File

@ -39,7 +39,7 @@ func makeHiddenData(sta *State) (ret chHiddenData, sharedSecret []byte) {
copy(plaintext, sta.UID)
copy(plaintext[16:28], sta.ProxyMethod)
plaintext[28] = sta.EncryptionMethod
binary.BigEndian.PutUint64(plaintext[29:37], uint64(sta.now().Unix()))
binary.BigEndian.PutUint64(plaintext[29:37], uint64(sta.Now().Unix()))
binary.BigEndian.PutUint32(plaintext[37:41], atomic.LoadUint32(&sta.SessionID))
if sta.Unordered {

View File

@ -37,7 +37,7 @@ type State struct {
UID []byte
staticPub crypto.PublicKey
now func() time.Time // for easier testing
Now func() time.Time // for easier testing
browser browser
ProxyMethod string
@ -47,18 +47,6 @@ type State struct {
Timeout time.Duration
}
// TODO: remove this and let the caller declare it directly
func InitState(localHost, localPort, remoteHost, remotePort string, nowFunc func() time.Time) *State {
ret := &State{
LocalHost: localHost,
LocalPort: localPort,
RemoteHost: remoteHost,
RemotePort: remotePort,
now: nowFunc,
}
return ret
}
// semi-colon separated value. This is for Android plugin options
func ssvToJson(ssv string) (ret []byte) {
unescape := func(s string) string {