mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 13:16:07 +03:00
Use buf.PacketReader when UDPOverride is available
This commit is contained in:
parent
24f564b401
commit
e1a5392beb
@ -195,11 +195,10 @@ func NewPacketReader(conn net.Conn, UDPOverride net.Destination) buf.Reader {
|
|||||||
if statConn != nil {
|
if statConn != nil {
|
||||||
counter = statConn.ReadCounter
|
counter = statConn.ReadCounter
|
||||||
}
|
}
|
||||||
if c, ok := iConn.(*internet.PacketConnWrapper); ok {
|
if c, ok := iConn.(*internet.PacketConnWrapper); ok && UDPOverride.Address == nil && UDPOverride.Port == 0 {
|
||||||
return &PacketReader{
|
return &PacketReader{
|
||||||
PacketConnWrapper: c,
|
PacketConnWrapper: c,
|
||||||
Counter: counter,
|
Counter: counter,
|
||||||
UDPOverride: UDPOverride,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &buf.PacketReader{Reader: conn}
|
return &buf.PacketReader{Reader: conn}
|
||||||
@ -208,7 +207,6 @@ func NewPacketReader(conn net.Conn, UDPOverride net.Destination) buf.Reader {
|
|||||||
type PacketReader struct {
|
type PacketReader struct {
|
||||||
*internet.PacketConnWrapper
|
*internet.PacketConnWrapper
|
||||||
stats.Counter
|
stats.Counter
|
||||||
UDPOverride net.Destination
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||||
@ -225,12 +223,6 @@ func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||||||
Port: net.Port(d.(*net.UDPAddr).Port),
|
Port: net.Port(d.(*net.UDPAddr).Port),
|
||||||
Network: net.Network_UDP,
|
Network: net.Network_UDP,
|
||||||
}
|
}
|
||||||
if r.UDPOverride.Address != nil {
|
|
||||||
b.UDP.Address = r.UDPOverride.Address
|
|
||||||
}
|
|
||||||
if r.UDPOverride.Port != 0 {
|
|
||||||
b.UDP.Port = r.UDPOverride.Port
|
|
||||||
}
|
|
||||||
if r.Counter != nil {
|
if r.Counter != nil {
|
||||||
r.Counter.Add(int64(n))
|
r.Counter.Add(int64(n))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user