From 832ebb40508660bfbb4dfa3fd1354d6ddd82d6cc Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Fri, 17 Mar 2023 13:23:37 +0800 Subject: [PATCH] Update UoT protocol --- adapter/outbound/shadowsocks.go | 13 ++++--------- go.mod | 2 +- go.sum | 2 ++ listener/sing/sing.go | 4 ++-- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/adapter/outbound/shadowsocks.go b/adapter/outbound/shadowsocks.go index c3097d09..1c64b3ca 100644 --- a/adapter/outbound/shadowsocks.go +++ b/adapter/outbound/shadowsocks.go @@ -124,12 +124,7 @@ func (ss *ShadowSocks) StreamConnContext(ctx context.Context, c net.Conn, metada } useEarly = useEarly || N.NeedHandshake(c) if metadata.NetWork == C.UDP && ss.option.UDPOverTCP { - var uotDestination M.Socksaddr - if ss.option.UDPOverTCPVersion == 1 { - uotDestination.Fqdn = uot.LegacyMagicAddress - } else { - uotDestination.Fqdn = uot.MagicAddress - } + uotDestination := uot.RequestDestination(uint8(ss.option.UDPOverTCPVersion)) if useEarly { return ss.method.DialEarlyConn(c, uotDestination), nil } else { @@ -178,7 +173,7 @@ func (ss *ShadowSocks) ListenPacketWithDialer(ctx context.Context, dialer C.Dial } destination := M.ParseSocksaddr(metadata.RemoteAddress()) if ss.option.UDPOverTCPVersion == 1 { - return newPacketConn(uot.NewConn(tcpConn, false, destination), ss), nil + return newPacketConn(uot.NewConn(tcpConn, uot.Request{Destination: destination}), ss), nil } else { return newPacketConn(uot.NewLazyConn(tcpConn, uot.Request{Destination: destination}), ss), nil } @@ -205,8 +200,8 @@ func (ss *ShadowSocks) SupportWithDialer() bool { func (ss *ShadowSocks) ListenPacketOnStreamConn(c net.Conn, metadata *C.Metadata) (_ C.PacketConn, err error) { if ss.option.UDPOverTCP { destination := M.ParseSocksaddr(metadata.RemoteAddress()) - if ss.option.UDPOverTCPVersion == 1 { - return newPacketConn(uot.NewConn(c, false, destination), ss), nil + if ss.option.UDPOverTCPVersion == uot.LegacyVersion { + return newPacketConn(uot.NewConn(c, uot.Request{Destination: destination}), ss), nil } else { return newPacketConn(uot.NewLazyConn(c, uot.Request{Destination: destination}), ss), nil } diff --git a/go.mod b/go.mod index 0f44f260..a9967400 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/mroth/weightedrand/v2 v2.0.0 github.com/oschwald/geoip2-golang v1.8.0 github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97 - github.com/sagernet/sing v0.1.9-0.20230315063014-2731df16725b + github.com/sagernet/sing v0.2.0 github.com/sagernet/sing-shadowtls v0.1.0 github.com/sagernet/sing-vmess v0.1.3 github.com/sagernet/tfo-go v0.0.0-20230303015439-ffcfd8c41cf9 diff --git a/go.sum b/go.sum index 881d2b70..eeb4e912 100644 --- a/go.sum +++ b/go.sum @@ -129,6 +129,8 @@ github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97/go.mod h1:xLnfdiJ github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY= github.com/sagernet/sing v0.1.9-0.20230315063014-2731df16725b h1:1iKGftQ59+shDSx2RaLaxXJcMK/B+IU9WqUPwyBW+E0= github.com/sagernet/sing v0.1.9-0.20230315063014-2731df16725b/go.mod h1:9uHswk2hITw8leDbiLS/xn0t9nzBcbePxzm9PJhwdlw= +github.com/sagernet/sing v0.2.0 h1:iyc4TaeXG5XYXixl48zSDDTw46C9NOEAVFq6ZE0dA2k= +github.com/sagernet/sing v0.2.0/go.mod h1:9uHswk2hITw8leDbiLS/xn0t9nzBcbePxzm9PJhwdlw= github.com/sagernet/sing-shadowtls v0.1.0 h1:05MYce8aR5xfKIn+y7xRFsdKhKt44QZTSEQW+lG5IWQ= github.com/sagernet/sing-shadowtls v0.1.0/go.mod h1:Kn1VUIprdkwCgkS6SXYaLmIpKzQbqBIKJBMY+RvBhYc= github.com/sagernet/sing-vmess v0.1.3 h1:q/+tsF46dvvapL6CpQBgPHJ6nQrDUZqEtLHCbsjO7iM= diff --git a/listener/sing/sing.go b/listener/sing/sing.go index fa9e02f1..9436fcfb 100644 --- a/listener/sing/sing.go +++ b/listener/sing/sing.go @@ -68,10 +68,10 @@ func (h *ListenerHandler) NewConnection(ctx context.Context, conn net.Conn, meta return E.Cause(err, "read UoT request") } metadata.Destination = request.Destination - return h.NewPacketConnection(ctx, uot.NewConn(conn, request.IsConnect, metadata.Destination), metadata) + return h.NewPacketConnection(ctx, uot.NewConn(conn, *request), metadata) case uot.LegacyMagicAddress: metadata.Destination = M.Socksaddr{Addr: netip.IPv4Unspecified()} - return h.NewPacketConnection(ctx, uot.NewConn(conn, false, metadata.Destination), metadata) + return h.NewPacketConnection(ctx, uot.NewConn(conn, uot.Request{}), metadata) } target := socks5.ParseAddr(metadata.Destination.String()) wg := &sync.WaitGroup{}