From 25e41d0941b1ff689898b48af013fad87a510048 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Mon, 6 Apr 2020 13:11:19 +0100 Subject: [PATCH] Allow UDP option to be set in both commandline and json --- cmd/ck-client/ck-client.go | 8 ++++---- internal/client/state.go | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/ck-client/ck-client.go b/cmd/ck-client/ck-client.go index 9b55b07..869b7ef 100644 --- a/cmd/ck-client/ck-client.go +++ b/cmd/ck-client/ck-client.go @@ -106,6 +106,8 @@ func main() { rawConfig.RemoteHost = remoteHost case "p": rawConfig.RemotePort = remotePort + case "u": + rawConfig.UDP = udp case "proxy": rawConfig.ProxyMethod = proxyMethod } @@ -148,12 +150,10 @@ func main() { } } else { var network string - if udp { + if authInfo.Unordered { network = "UDP" - authInfo.Unordered = true } else { network = "TCP" - authInfo.Unordered = false } log.Infof("Listening on %v %v for %v client", network, localConfig.LocalAddr, authInfo.ProxyMethod) seshMaker = func() *mux.Session { @@ -161,7 +161,7 @@ func main() { } } - if udp { + if authInfo.Unordered { client.RouteUDP(localConfig, seshMaker) } else { client.RouteTCP(localConfig, seshMaker) diff --git a/internal/client/state.go b/internal/client/state.go index fd1cb43..b725c09 100644 --- a/internal/client/state.go +++ b/internal/client/state.go @@ -27,9 +27,9 @@ type rawConfig struct { LocalPort string // jsonOptional RemoteHost string // jsonOptional RemotePort string // jsonOptional - //TODO: udp // defaults set in SplitConfigs + UDP bool // nullable BrowserSig string // nullable Transport string // nullable StreamTimeout int // nullable @@ -57,7 +57,7 @@ func ssvToJson(ssv string) (ret []byte) { r = strings.Replace(r, `\;`, `;`, -1) return r } - unquoted := []string{"NumConn", "StreamTimeout", "KeepAlive"} + unquoted := []string{"NumConn", "StreamTimeout", "KeepAlive", "UDP"} lines := strings.Split(unescape(ssv), ";") ret = []byte("{") for _, ln := range lines { @@ -107,6 +107,8 @@ func (raw *rawConfig) SplitConfigs() (local *localConnConfig, remote *remoteConn } auth = new(authInfo) + auth.UID = raw.UID + auth.Unordered = raw.UDP if raw.ServerName == "" { return nullErr("ServerName") } @@ -118,7 +120,6 @@ func (raw *rawConfig) SplitConfigs() (local *localConnConfig, remote *remoteConn if len(raw.UID) == 0 { return nullErr("UID") } - auth.UID = raw.UID // static public key if len(raw.PublicKey) == 0 {