From 46c02d17f42a3cdfa409a72a4e83717ecb1ab338 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Tue, 20 Aug 2019 22:48:01 +0100 Subject: [PATCH] Refactor InitState --- cmd/ck-client/ck-client.go | 9 ++++++++- internal/client/auth.go | 2 +- internal/client/state.go | 14 +------------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/cmd/ck-client/ck-client.go b/cmd/ck-client/ck-client.go index 6dd6121..a1c4ff3 100644 --- a/cmd/ck-client/ck-client.go +++ b/cmd/ck-client/ck-client.go @@ -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) diff --git a/internal/client/auth.go b/internal/client/auth.go index 3fdebf3..6e5df04 100644 --- a/internal/client/auth.go +++ b/internal/client/auth.go @@ -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 { diff --git a/internal/client/state.go b/internal/client/state.go index b438df5..23f57e0 100644 --- a/internal/client/state.go +++ b/internal/client/state.go @@ -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 {