@@ -29,10 +29,11 @@ func init() {
2929}
3030
3131type Outbound struct {
32- ctx context.Context
33- server net.Destination
34- method shadowsocks.Method
35- uot bool
32+ ctx context.Context
33+ server net.Destination
34+ method shadowsocks.Method
35+ uot bool
36+ uotVersion int
3637}
3738
3839func NewClient (ctx context.Context , config * ClientConfig ) (* Outbound , error ) {
@@ -57,6 +58,14 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) {
5758 } else {
5859 return nil , newError ("unknown method " , config .Method )
5960 }
61+ switch config .UdpOverTcpVersion {
62+ case uot .LegacyVersion :
63+ o .uotVersion = uot .LegacyVersion
64+ case 0 , uot .Version :
65+ o .uotVersion = 2
66+ default :
67+ return nil , newError ("unknown udp over tcp protocol version " , config .UdpOverTcpVersion )
68+ }
6069 return o , nil
6170}
6271
@@ -150,8 +159,13 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
150159 }
151160
152161 if o .uot {
153- serverConn := o .method .DialEarlyConn (connection , M.Socksaddr {Fqdn : uot .UOTMagicAddress })
154- return returnError (bufio .CopyPacketConn (ctx , packetConn , uot .NewClientConn (serverConn )))
162+ var uConn * uot.Conn
163+ if o .uotVersion == uot .Version {
164+ uConn = uot .NewLazyConn (o .method .DialEarlyConn (connection , M.Socksaddr {Fqdn : uot .MagicAddress }), uot.Request {Destination : toSocksaddr (destination )})
165+ } else {
166+ uConn = uot .NewConn (o .method .DialEarlyConn (connection , M.Socksaddr {Fqdn : uot .LegacyMagicAddress }), false , toSocksaddr (destination ))
167+ }
168+ return returnError (bufio .CopyPacketConn (ctx , packetConn , uConn ))
155169 } else {
156170 serverConn := o .method .DialPacketConn (connection )
157171 return returnError (bufio .CopyPacketConn (ctx , packetConn , serverConn ))
0 commit comments