Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawn multiple gost instances in a single command with -- #713

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

caribpa
Copy link

@caribpa caribpa commented May 1, 2021

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 😅

@guqing637
Copy link
Contributor

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

@caribpa
Copy link
Author

caribpa commented May 3, 2021

@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 🦺

@lovitus
Copy link

lovitus commented Nov 20, 2021

@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

@caribpa
Copy link
Author

caribpa commented Nov 21, 2021

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! 🤸‍♀️

@wlclass
Copy link

wlclass commented Jul 8, 2022

i agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants