Allow RemotePort to be optionally set in client JSON. #97
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This small patch adds the RemotePort variable to the ck-client JSON parser, so that it can be independently set when the Cloak client runs in shadowsocks mode. The motivation for this is as follows:
A single Shadowsocks instance has the ability to forward both TCP and UDP. TCP traffic will go through the plugin (Cloak), and UDP traffic will bypass the plugin and instead use a direct connection to the SS server over UDP.
When you run ss-server with -u (
tcp_and_udp
mode) and ck-server plugin, it will start a TCP listener on the port specified byBindAddr
in the Cloak config (typically port 443) and an UDP listener on portSS_REMOTE_PORT
(server_port
in the config). So this creates the situation where you can potentially chooseSS_REMOTE_PORT
different from theBindAddr
port. E.g.: Cloak can listen on public port TCP/443, and UDP raw Shadowsocks can listen on public port UDP/4000.On the client side, however, there is no way to currently set
SS_REMOTE_PORT
independent of Cloak'sRemotePort
. Cloak will useSS_REMOTE_PORT
specified in the SS config asRemotePort
. So when you run ss-redir with -u (tcp_and_udp
mode), Cloak plugin, andSS_REMOTE_PORT
set to 443, it will connect to Cloak TCP on port 443, but will also attempt to connect to SS UDP on port 443. There is no way to change the UDP port to port 4000 in our example.Technically, you could set
SS_REMOTE_PORT
on the server to port 443, and then it will create both a TCP and UDP listener on port 443. But personally I don't like doing this, because UDP port 443 is not commonly used for anything, so this may give away the fact that the server is not a normal webserver.Setting
RemotePort
in the client JSON is optional. If it is specified, it is used. If it is not specified, Cloak falls back to the default behaviour of usingSS_REMOTE_PORT
or the -p variable asRemotePort
. This is a very niche patch and most users will probably never need it, but it allows a bit more flexibility for people who also use SS as a UDP proxy and want to have different ports for TCP and UDP. I am currently using it in this way with this patch.Importing
strconv
creates a little overhead, but the difference is small (on ARM it is around 300 bytes), on windows it is around 1kB. You could specifyRemotePort
as a string in json and then we don't needstrconv
, but I think this is unconventional and better to keep it as int in json and then convert it internally to string.v2ray-plugin
also has a similar functionality, where you can set theremotePort
in JSON independently of the SS_REMOTE_PORT.