mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-01 01:44:15 +00:00
Update UoT protocol
This commit is contained in:
parent
f1e35ad9d4
commit
f57ec13880
7 changed files with 66 additions and 38 deletions
|
@ -11,7 +11,6 @@ import (
|
|||
C "github.com/sagernet/sing/common"
|
||||
B "github.com/sagernet/sing/common/buf"
|
||||
"github.com/sagernet/sing/common/bufio"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/sagernet/sing/common/uot"
|
||||
"github.com/xtls/xray-core/common"
|
||||
|
@ -29,10 +28,10 @@ func init() {
|
|||
}
|
||||
|
||||
type Outbound struct {
|
||||
ctx context.Context
|
||||
server net.Destination
|
||||
method shadowsocks.Method
|
||||
uot bool
|
||||
ctx context.Context
|
||||
server net.Destination
|
||||
method shadowsocks.Method
|
||||
uotClient *uot.Client
|
||||
}
|
||||
|
||||
func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) {
|
||||
|
@ -43,7 +42,6 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) {
|
|||
Port: net.Port(config.Port),
|
||||
Network: net.Network_TCP,
|
||||
},
|
||||
uot: config.UdpOverTcp,
|
||||
}
|
||||
if C.Contains(shadowaead_2022.List, config.Method) {
|
||||
if config.Key == "" {
|
||||
|
@ -57,6 +55,9 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) {
|
|||
} else {
|
||||
return nil, newError("unknown method ", config.Method)
|
||||
}
|
||||
if config.UdpOverTcp {
|
||||
o.uotClient = &uot.Client{Version: uint8(config.UdpOverTcpVersion)}
|
||||
}
|
||||
return o, nil
|
||||
}
|
||||
|
||||
|
@ -77,7 +78,7 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
|
|||
newError("tunneling request to ", destination, " via ", o.server.NetAddr()).WriteToLog(session.ExportIDToError(ctx))
|
||||
|
||||
serverDestination := o.server
|
||||
if o.uot {
|
||||
if o.uotClient != nil {
|
||||
serverDestination.Network = net.Network_TCP
|
||||
} else {
|
||||
serverDestination.Network = network
|
||||
|
@ -149,9 +150,12 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
|
|||
}
|
||||
}
|
||||
|
||||
if o.uot {
|
||||
serverConn := o.method.DialEarlyConn(connection, M.Socksaddr{Fqdn: uot.UOTMagicAddress})
|
||||
return returnError(bufio.CopyPacketConn(ctx, packetConn, uot.NewClientConn(serverConn)))
|
||||
if o.uotClient != nil {
|
||||
uConn, err := o.uotClient.DialEarlyConn(o.method.DialEarlyConn(connection, uot.RequestDestination(o.uotClient.Version)), false, toSocksaddr(destination))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return returnError(bufio.CopyPacketConn(ctx, packetConn, uConn))
|
||||
} else {
|
||||
serverConn := o.method.DialPacketConn(connection)
|
||||
return returnError(bufio.CopyPacketConn(ctx, packetConn, serverConn))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue