Apply UDPOverride to Freedom Outbound PacketReader

This commit is contained in:
RPRX 2021-03-05 12:06:37 +00:00 committed by GitHub
parent 6380abca73
commit 055fb51ed9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -169,7 +169,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
if destination.Network == net.Network_TCP { if destination.Network == net.Network_TCP {
reader = buf.NewReader(conn) reader = buf.NewReader(conn)
} else { } else {
reader = NewPacketReader(conn) reader = NewPacketReader(conn, UDPOverride)
} }
if err := buf.Copy(reader, output, buf.UpdateActivity(timer)); err != nil { if err := buf.Copy(reader, output, buf.UpdateActivity(timer)); err != nil {
return newError("failed to process response").Base(err) return newError("failed to process response").Base(err)
@ -185,7 +185,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
return nil return nil
} }
func NewPacketReader(conn net.Conn) buf.Reader { func NewPacketReader(conn net.Conn, UDPOverride net.Destination) buf.Reader {
iConn := conn iConn := conn
statConn, ok := iConn.(*internet.StatCouterConnection) statConn, ok := iConn.(*internet.StatCouterConnection)
if ok { if ok {
@ -199,6 +199,7 @@ func NewPacketReader(conn net.Conn) buf.Reader {
return &PacketReader{ return &PacketReader{
PacketConnWrapper: c, PacketConnWrapper: c,
Counter: counter, Counter: counter,
UDPOverride: UDPOverride,
} }
} }
return &buf.PacketReader{Reader: conn} return &buf.PacketReader{Reader: conn}
@ -207,6 +208,7 @@ func NewPacketReader(conn net.Conn) 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) {
@ -223,6 +225,12 @@ 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))
} }