diff --git a/examples/ss.client.toml b/examples/ss.client.toml index 0d5891a..26aef03 100644 --- a/examples/ss.client.toml +++ b/examples/ss.client.toml @@ -17,4 +17,4 @@ uuid = "method:AES-128-GCM\npass:iloveverysimple" #encrypt_algo = "AES-128-GCM" # chacha20-ietf-poly1305,AES-128-GCM, AES-256-GCM, 大小写均可;一般应该是 aes 更快, 如果 encrypt_algo 给出,会覆盖 uuid中的 method 部分 -#network = "dual" #ss同时使用tcp和udp分别传输tcp和udp数据,属于双栈 \ No newline at end of file +#network = "dual" #ss同时使用tcp和udp分别传输tcp和udp数据,属于双栈, 如果设成tcp,则不会传输udp。 \ No newline at end of file diff --git a/main.go b/main.go index c1b048a..1654d13 100644 --- a/main.go +++ b/main.go @@ -73,8 +73,9 @@ non-blocking. closer used to stop listening. It means listening failed if closer func ListenSer(inServer proxy.Server, defaultOutClient proxy.Client, env *proxy.RoutingEnv) (closer io.Closer) { var extraCloser io.Closer + var is, tcp, udp bool //tproxy 和 shadowsocks 都用到了 SelfListen - if is, tcp, udp := inServer.SelfListen(); is { + if is, tcp, udp = inServer.SelfListen(); is { var chantcp chan proxy.IncomeTCPInfo var chanudp chan proxy.IncomeUDPInfo @@ -179,8 +180,19 @@ func ListenSer(inServer proxy.Server, defaultOutClient proxy.Client, env *proxy. var err error + network := inServer.Network() + if network == netLayer.DualNetworkName && is { + if is != tcp && udp { + if tcp { + network = "udp" + } else { + network = "tcp" + } + } + } + closer, err = netLayer.ListenAndAccept( - inServer.Network(), + network, inServer.AddrStr(), inServer.GetSockopt(), inServer.GetXver(),