From 23082aff4f742e3df958ea2696b5dac7a5e945b6 Mon Sep 17 00:00:00 2001 From: beans <48507462+beanslel@users.noreply.github.com> Date: Wed, 12 Feb 2020 14:56:25 +0800 Subject: [PATCH] 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 --- internal/client/state.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/client/state.go b/internal/client/state.go index 4ecd27b..e663a49 100644 --- a/internal/client/state.go +++ b/internal/client/state.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "io/ioutil" + "strconv" "strings" "time" @@ -23,6 +24,7 @@ type rawConfig struct { Transport string NumConn int StreamTimeout int + RemotePort int } // State stores the parsed configuration fields @@ -142,5 +144,15 @@ func (sta *State) ParseConfig(conf string) (err error) { } 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 }