wzshiming/bridge

`nc -X 5 -x 127.0.0.1:10022 host port` equivalent implementation by bridge.

hongyi-zhao opened this issue · 4 comments

Can I use bridge to construct a git-protocol proxy which is equivalent to the following command?

nc -X 5 -x 127.0.0.1:10022 host port

Regards,
Zhao

Yep

export GIT_SSH_COMMAND='ssh -o ProxyCommand="bridge -p %h:%p -p socks5://127.0.0.1:10022"'

I mean to work with git protocol like the following:

$ GIT_PROXY_COMMAND=gitproxy.sh /usr/bin/git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
# or
$ /usr/bin/git -c 'core.gitProxy=gitproxy.sh' clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

And I have the following command currently in the executable script gitproxy.sh:

werner@x13dai-t:~$ which gitproxy.sh
/home/werner/.local/bin/gitproxy.sh

werner@x13dai-t:~$ grep -E '^[^#]' ` which gitproxy.sh `
exec nc -X 5 -x 127.0.0.1:10022 "$@"

I have tried the following in the above script:

bridge -p $1:$2 -p socks5://127.0.0.1:10022
#or
#exec bridge -p $1:$2 -p socks5://127.0.0.1:10022

But the test failed:

$ /usr/bin/git -c 'core.gitProxy=gitproxy.sh' clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Cloning into 'linux'...
2024/08/12 18:30:35 INFO DIAL "tcp://git.kernel.org:9418" <- "socks5://127.0.0.1:10022" <- LOCAL <- STDIO
 chains="{Bind:[] Proxy:[{Probe: LB:[git.kernel.org:9418]} {Probe: LB:[socks5://127.0.0.1:10022]}] IdleTimeout:0s}"
2024/08/12 18:30:37 ERROR BridgeWithConfig chains="{Bind:[] Proxy:[{Probe: LB:[git.kernel.org:9418]} {Probe: LB:[socks5://127.0.0.1:10022]}] IdleTimeout:0s}" err="writeto tcp 127.0.0.1:44846->127.0.0.1:10022: read tcp 127.0.0.1:44846->127.0.0.1:10022: use of closed network connection"
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

I wonder how to use bridge to achieve the same purpose.

BTW, the above error is exactly the same with the following command set in the above script:

ncat --proxy 127.0.0.1:10022 --proxy-type socks5 $1 $2

As shown below:

$ /usr/bin/git -c 'core.gitProxy=gitproxy.sh' clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Cloning into 'linux'...
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

But the following setting in the script works smoothly:

nc -X 5 -x 127.0.0.1:10022 $1 $2
#or
#exec nc -X 5 -x 127.0.0.1:10022 "$@"

As shown below:

$ /usr/bin/git -c 'core.gitProxy=gitproxy.sh' clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Cloning into 'linux'...
remote: Enumerating objects: 10343588, done.
remote: Counting objects: 100% (181/181), done.
remote: Compressing objects: 100% (89/89), done.
Receiving objects:   0% (62579/10343588), 32.68 MiB | 3.59 MiB/s

Back in the day, I researched git's 3 different proxy methods for 3 different protocols. I ended up keeping the http and ssh proxies. I can't remember why

The git protocol doesn't seem to be very stable and robust. Here is the detailed debug information; I wonder if you can find any clues from it:

werner@x13dai-t:~$ GIT_TRACE=1 GIT_CURL_VERBOSE=1 GIT_TRACE_PERFORMANCE=1 GIT_TRACE_SETUP=1 /usr/bin/git -c 'core.gitProxy=gitproxy.sh' clone --verbose --progress git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
07:13:55.149579 git.c:455               trace: built-in: git clone --verbose --progress git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Cloning into 'linux'...
07:13:55.157708 run-command.c:668       trace: run_command: gitproxy.sh git.kernel.org 9418
2024/08/13 07:13:55 INFO DIAL "tcp://git.kernel.org:9418" <- "socks5://127.0.0.1:10022" <- LOCAL <- STDIO
 chains="{Bind:[] Proxy:[{Probe: LB:[git.kernel.org:9418]} {Probe: LB:[socks5://127.0.0.1:10022]}] IdleTimeout:0s}"
07:13:57.402731 run-command.c:668       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 10708 on x13dai-t' --check-self-contained-and-connected
2024/08/13 07:13:57 ERROR BridgeWithConfig chains="{Bind:[] Proxy:[{Probe: LB:[git.kernel.org:9418]} {Probe: LB:[socks5://127.0.0.1:10022]}] IdleTimeout:0s}" err="writeto tcp 127.0.0.1:37742->127.0.0.1:10022: read tcp 127.0.0.1:37742->127.0.0.1:10022: use of closed network connection"
fetch-pack: unexpected disconnect while reading sideband packet
07:13:57.420051 trace.c:387             setup: git_dir: /home/werner/linux/.git
07:13:57.420091 trace.c:388             setup: git_common_dir: /home/werner/linux/.git
07:13:57.420094 trace.c:389             setup: worktree: /home/werner
07:13:57.420096 trace.c:390             setup: cwd: /home/werner
07:13:57.420098 trace.c:391             setup: prefix: (null)
07:13:57.420100 git.c:455               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 10708 on x13dai-t' --check-self-contained-and-connected
fatal: early EOF
07:13:57.420618 trace.c:487             performance: 0.001764065 s: git command: /usr/lib/git-core/git index-pack --stdin -v --fix-thin '--keep=fetch-pack 10708 on x13dai-t' --check-self-contained-and-connected
fatal: fetch-pack: invalid index-pack output
07:13:57.423123 trace.c:487             performance: 2.273843841 s: git command: /usr/bin/git -c core.gitProxy=gitproxy.sh clone --verbose --progress git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git