gost icon indicating copy to clipboard operation
gost copied to clipboard

Spawn multiple gost instances in a single command with --

Open caribpa opened this issue 4 years ago • 5 comments

Hi,

Congratulations for this amazing tool 💯! It is my go-to whenever I need to create tunnels 🎉

Due to the fact I use socks over reverse-tunnels a lot, this PR allows a single gost command to perform multiple operations in separated instances.

This is easier to explain with a short example:

Before this PR this is what you had to do if you wanted to create a socks over reverse-SSH:

# Server
gost -L forward+ssh://:2222

# Client - Terminal/Process 1
gost -L rtcp://127.0.0.1:3333/127.0.0.1:1111 -F forward+ssh://<server-ip>:2222

# Client - Terminal/Process 2
gost -L socks5://127.0.0.1:1111

# Test from Server
curl -s -L -x socks5://127.0.0.1:3333 https://example.com

After this PR the client no longer needs to use multiple terminals/processes:

# Server
gost -L forward+ssh://:2222

# Client
gost -L socks5://127.0.0.1:1111 -- -L rtcp://127.0.0.1:3333/127.0.0.1:1111 -F forward+ssh://<server-ip>:2222

# Test from Server
curl -s -L -x socks5://127.0.0.1:3333 https://example.com

This works by spawning a different gost instance in a goroutine with each --, so there are no configuration conflicts ✨!

You can certainly use multiple -- to do all sort of craziness in a single gost command:

gost -L rudp://:5353/192.168.1.1:53?ttl=60s -F socks5://172.24.10.1:1080    -- \
     -C my-proxy.json                                                       -- \
     -L redirect://:1234 -F 1.2.3.4:1080                                    -- \
     -L udp://:5353 -C forward-servers.json                                 -- \
     -L :8080 -F http://localhost:8080?ip=192.168.1.2:8081,192.168.1.3:8082    \
              -F socks5://localhost:1080?ip=172.20.1.1:1080,172.20.1.2:1081 -- \
     -L socks5://localhost:1080                                             -- \
     -L :2020 -F kcp://10.16.1.10:8388?peer=peer1.txt                          \
              -F http2://12.20.1.3:443?peer=peer2.txt

Of course, some things could be improved as I didn't alter the main logic of gost which relies on the globals gost.DefaultTLSConfig, gost.Debug, and gost.SetLogger(). Among them, gost.DefaultTLSConfig is the most "damaging" one as it means that all the gost instances spawned with -- will use the same TLS certificate (which won't happen if multiple gost processes are separately run in different terminals/processes instead of using --).

For sure, there are several ways of isolating gost.DefaultTLSConfig (and the other globals) per instance, but changes outside the scope of this simple PR are needed and, for my usage purposes, a shared TLS cert (or global debug/log) is perfectly fine 🕺

Finally, the README.md will need to be updated to include my README_en.md changes as I don't understand Chinese, unfortunately 😅

caribpa avatar May 01 '21 14:05 caribpa

@caribpa 这似乎看起来是多余的。

guqing637 avatar May 03 '21 08:05 guqing637

@guqing637 sorry, I don't understand Chinese but I'm going to reply assuming Google Translate did a good job translating your comment:

This seems redundant.

This PR adds the convenience of starting (and ending) independent gost instances in just one command, which is currently not possible unless you use different terminals (or use the background in Unix platforms). Please refer to the examples in the OP for further clarification or show me the commands that can currently achieve the same results without using different terminals/processes/Unix-background 🦺

caribpa avatar May 03 '21 09:05 caribpa

@caribpa I believe this is useful to me, did you add this future in your forked code ?if so I wanna use your fork before upstream author decide to accept the pull

lovitus avatar Nov 20 '21 14:11 lovitus

Hi @lovitus! Yes, this feature is fully implemented in my fork and I use it myself. You can clone my fork and build it in order to use this useful feature :)

  git clone -b cmd-split https://github.com/caribpa/gost.git
  cd gost/cmd/gost
  go build

Cheers! :woman_cartwheeling:

caribpa avatar Nov 21 '21 19:11 caribpa

i agree

wlclass avatar Jul 08 '22 13:07 wlclass