mirror of
https://github.com/cbeuw/Cloak.git
synced 2026-04-25 20:45:59 +03:00
[PR #97] [MERGED] Allow RemotePort to be optionally set in client JSON. #264
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/Cloak#264
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cbeuw/Cloak/pull/97
Author: @beanslel
Created: 2/12/2020
Status: ✅ Merged
Merged: 2/14/2020
Merged by: @cbeuw
Base:
master← Head:remoteport📝 Commits (1)
51d8ef2Allow 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📊 Changes
1 file changed (+12 additions, -0 deletions)
View changed files
📝
internal/client/state.go(+12 -0)📄 Description
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_udpmode) and ck-server plugin, it will start a TCP listener on the port specified byBindAddrin the Cloak config (typically port 443) and an UDP listener on portSS_REMOTE_PORT(server_portin the config). So this creates the situation where you can potentially chooseSS_REMOTE_PORTdifferent from theBindAddrport. 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_PORTindependent of Cloak'sRemotePort. Cloak will useSS_REMOTE_PORTspecified in the SS config asRemotePort. So when you run ss-redir with -u (tcp_and_udpmode), Cloak plugin, andSS_REMOTE_PORTset 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_PORTon 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
RemotePortin 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_PORTor 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
strconvcreates a little overhead, but the difference is small (on ARM it is around 300 bytes), on windows it is around 1kB. You could specifyRemotePortas 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-pluginalso has a similar functionality, where you can set theremotePortin JSON independently of the SS_REMOTE_PORT.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.