ginuerzh / gost

GO Simple Tunnel - a simple tunnel written in golang
MIT License
15.48k stars 2.43k forks source link

有考虑增加 wireguard 支持吗 #835

Open wen-long opened 2 years ago

wen-long commented 2 years ago

这里有一个 go 的实现,只提供了 socks5 服务

https://github.com/octeep/wireproxy

pingod commented 1 year ago

3.0计划啥时候出来啊

happyharryh commented 1 year ago

可以尝试一下我的分支:https://github.com/happyharryh/gost/tree/wireguard-client

# 构建
git clone -b wireguard-client --recursive https://github.com/happyharryh/gost.git
cd gost
git apply wireproxy.patch
go build ./cmd/gost

# 用法 (1234是任意正整数)
./gost -L=auto://127.0.0.1:8000 -F=wg://:1234?c=proxy.conf

注意这个分支只支持作为WireGuard客户端,不支持作为服务器端。proxy.conf文件格式参考 https://github.com/pufferffish/wireproxy/blob/master/README.md

Gankyun commented 1 year ago

可以尝试一下我的分支:https://github.com/happyharryh/gost/tree/wireguard-client

# 构建
git clone -b wireguard-client --recursive https://github.com/happyharryh/gost.git
cd gost
git apply wireproxy.patch
go build ./cmd/gost

# 用法 (1234是任意正整数)
./gost -L=auto://127.0.0.1:8000 -F=wg://:1234?c=proxy.conf

注意这个分支只支持作为WireGuard客户端,不支持作为服务器端。proxy.conf文件格式参考 https://github.com/pufferffish/wireproxy/blob/master/README.md

管用,感谢! 不过好像双重wireguard嵌套代理不好使了。

happyharryh commented 1 year ago

可以尝试一下我的分支:https://github.com/happyharryh/gost/tree/wireguard-client


# 构建

git clone -b wireguard-client --recursive https://github.com/happyharryh/gost.git

cd gost

git apply wireproxy.patch

go build ./cmd/gost

# 用法 (1234是任意正整数)

./gost -L=auto://127.0.0.1:8000 -F=wg://:1234?c=proxy.conf

注意这个分支只支持作为WireGuard客户端,不支持作为服务器端。proxy.conf文件格式参考 https://github.com/pufferffish/wireproxy/blob/master/README.md

管用,感谢! 不过好像双重wireguard嵌套代理不好使了。

双重wireguard嵌套代理指的是什么?是多级转发代理吗?

Gankyun commented 1 year ago

是多级转发,我这边测试 wg套wg 和 wg套http好像都不好使了。

happyharryh commented 1 year ago

是多级转发,我这边测试 wg套wg 和 wg套http好像都不好使了。

这个不太好做。

如果你看我的代码,会发现目前的wireguard与gost主程序的耦合是不紧密的。或者说wireguard并没有真正融入gost,两者只是在用接口对接。现在gost主程序启动时,附带启动了一个wireguard客户端,然后gost主程序在每次处理gost客户端请求时,调用这个wireguard客户端的DialContext接口。至于wireguard客户端内部是怎么工作的,对我来说仍是黑盒。

由于wireguard客户端的启动成本大,不太适合由gost客户端发起请求,让gost服务器端(包括第2级、第3级、第N级服务器端)被动地启动wireguard客户端并使用。所以现在只能由gost服务器端自己在启动的时候,主动加载wireguard配置,启动wireguard 客户端,为gost客户端提供服务。

想要实现多级转发功能,可能需要详细解读wireguard代码,将wireguard客户端向wireguard服务器端发送的请求过程完整实现在gost中,这个需要花比较多的精力。

collins7184 commented 1 year ago

是多级转发,我这边测试 wg套wg 和 wg套http好像都不好使了。

这个不太好做。

如果你看我的代码,会发现目前的wireguard与gost主程序的耦合是不紧密的。或者说wireguard并没有真正融入gost,两者只是在用接口对接。现在gost主程序启动时,附带启动了一个wireguard客户端,然后gost主程序在每次处理gost客户端请求时,调用这个wireguard客户端的DialContext接口。至于wireguard客户端内部是怎么工作的,对我来说仍是黑盒。

由于wireguard客户端的启动成本大,不太适合由gost客户端发起请求,让gost服务器端(包括第2级、第3级、第N级服务器端)被动地启动wireguard客户端并使用。所以现在只能由gost服务器端自己在启动的时候,主动加载wireguard配置,启动wireguard 客户端,为gost客户端提供服务。

想要实现多级转发功能,可能需要详细解读wireguard代码,将wireguard客户端向wireguard服务器端发送的请求过程完整实现在gost中,这个需要花比较多的精力。

如果不考虑性能开销的话,我这里有一个思路可能可以参考一下,即在 gvisor 这种容器的网络协议栈内运行一个完整的wireguard,这样只要启用任意多个wireguard网络协议栈就可以启用多个wireguard 隧道,再通过路由表和tun链式连接这些协议栈就可以实现一个可用的多层嵌套结构,这套结构我是在容器集群中用xray-core做过技术验证可行的。当然最好性能的方案是重现一个支持嵌套的wireguard客户端。