mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Refactor: *net.UDPAddr -> *net.Destination
https://t.me/projectXray/111998
This commit is contained in:
parent
6bcac6cb10
commit
13ad3fddf6
8 changed files with 59 additions and 50 deletions
|
@ -235,10 +235,8 @@ func (v *UDPReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||
buffer.Release()
|
||||
return nil, err
|
||||
}
|
||||
payload.UDP = &net.UDPAddr{
|
||||
IP: u.Address.IP(),
|
||||
Port: int(u.Port),
|
||||
}
|
||||
dest := u.Destination()
|
||||
payload.UDP = &dest
|
||||
return buf.MultiBuffer{payload}, nil
|
||||
}
|
||||
|
||||
|
@ -254,18 +252,15 @@ func (w *UDPWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||
if b == nil {
|
||||
break
|
||||
}
|
||||
var packet *buf.Buffer
|
||||
var err error
|
||||
request := w.Request
|
||||
if b.UDP != nil {
|
||||
request := &protocol.RequestHeader{
|
||||
request = &protocol.RequestHeader{
|
||||
User: w.Request.User,
|
||||
Address: net.IPAddress(b.UDP.IP),
|
||||
Port: net.Port(b.UDP.Port),
|
||||
Address: b.UDP.Address,
|
||||
Port: b.UDP.Port,
|
||||
}
|
||||
packet, err = EncodeUDPPacket(request, b.Bytes())
|
||||
} else {
|
||||
packet, err = EncodeUDPPacket(w.Request, b.Bytes())
|
||||
}
|
||||
packet, err := EncodeUDPPacket(request, b.Bytes())
|
||||
b.Release()
|
||||
if err != nil {
|
||||
buf.ReleaseMulti(mb)
|
||||
|
|
|
@ -81,8 +81,8 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
|
|||
if payload.UDP != nil {
|
||||
request = &protocol.RequestHeader{
|
||||
User: request.User,
|
||||
Address: net.IPAddress(payload.UDP.IP),
|
||||
Port: net.Port(payload.UDP.Port),
|
||||
Address: payload.UDP.Address,
|
||||
Port: payload.UDP.Port,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,25 +128,24 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
|
|||
continue
|
||||
}
|
||||
|
||||
destination := request.Destination()
|
||||
|
||||
currentPacketCtx := ctx
|
||||
if inbound.Source.IsValid() {
|
||||
currentPacketCtx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||
From: inbound.Source,
|
||||
To: request.Destination(),
|
||||
To: destination,
|
||||
Status: log.AccessAccepted,
|
||||
Reason: "",
|
||||
Email: request.User.Email,
|
||||
})
|
||||
}
|
||||
newError("tunnelling request to ", request.Destination()).WriteToLog(session.ExportIDToError(currentPacketCtx))
|
||||
newError("tunnelling request to ", destination).WriteToLog(session.ExportIDToError(currentPacketCtx))
|
||||
|
||||
data.UDP = &net.UDPAddr{
|
||||
IP: request.Address.IP(),
|
||||
Port: int(request.Port),
|
||||
}
|
||||
data.UDP = &destination
|
||||
|
||||
if dest.Network == 0 {
|
||||
dest = request.Destination() // JUST FOLLOW THE FIREST PACKET
|
||||
dest = request.Destination() // JUST FOLLOW THE FIRST PACKET
|
||||
}
|
||||
|
||||
currentPacketCtx = protocol.ContextWithRequestHeader(currentPacketCtx, request)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue