mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Refactor: Shadowsocks & Trojan UDP FullCone NAT
https://t.me/projectXray/95704
This commit is contained in:
parent
4140ed7ab0
commit
8f8f7dd66f
10 changed files with 234 additions and 44 deletions
|
@ -196,6 +196,15 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
|
|||
if request == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if payload.UDP != nil {
|
||||
request = &protocol.RequestHeader{
|
||||
User: request.User,
|
||||
Address: net.IPAddress(payload.UDP.IP),
|
||||
Port: net.Port(payload.UDP.Port),
|
||||
}
|
||||
}
|
||||
|
||||
udpMessage, err := EncodeUDPPacket(request, payload.Bytes())
|
||||
payload.Release()
|
||||
|
||||
|
@ -211,6 +220,8 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
|
|||
newError("client UDP connection from ", inbound.Source).WriteToLog(session.ExportIDToError(ctx))
|
||||
}
|
||||
|
||||
var dest net.Destination
|
||||
|
||||
reader := buf.NewPacketReader(conn)
|
||||
for {
|
||||
mpayload, err := reader.ReadMultiBuffer()
|
||||
|
@ -242,8 +253,17 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
|
|||
})
|
||||
}
|
||||
|
||||
payload.UDP = &net.UDPAddr{
|
||||
IP: request.Address.IP(),
|
||||
Port: int(request.Port),
|
||||
}
|
||||
|
||||
if dest.Network == 0 {
|
||||
dest = request.Destination() // JUST FOLLOW THE FIREST PACKET
|
||||
}
|
||||
|
||||
currentPacketCtx = protocol.ContextWithRequestHeader(currentPacketCtx, request)
|
||||
udpServer.Dispatch(currentPacketCtx, request.Destination(), payload)
|
||||
udpServer.Dispatch(currentPacketCtx, dest, payload)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue