mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
socks5 UDP outbound packet addr support
This commit is contained in:
parent
5b20d960f1
commit
dc5cffc8b0
@ -2,6 +2,8 @@ package socks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/v2fly/v2ray-core/v4/common/net/packetaddr"
|
||||
"github.com/v2fly/v2ray-core/v4/transport/internet/udp"
|
||||
"time"
|
||||
|
||||
core "github.com/v2fly/v2ray-core/v5"
|
||||
@ -161,6 +163,30 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
timer := signal.CancelAfterInactivity(ctx, cancel, p.Timeouts.ConnectionIdle)
|
||||
|
||||
if packetConn, err := packetaddr.ToPacketAddrConn(link, destination); err == nil {
|
||||
udpConn, err := dialer.Dial(ctx, udpRequest.Destination())
|
||||
if err != nil {
|
||||
return newError("failed to create UDP connection").Base(err)
|
||||
}
|
||||
defer udpConn.Close()
|
||||
|
||||
requestDone := func() error {
|
||||
protocolWriter := NewUDPWriter(request, udpConn)
|
||||
return udp.CopyPacketConn(protocolWriter, packetConn, udp.UpdateActivity(timer))
|
||||
}
|
||||
responseDone := func() error {
|
||||
protocolReader := &UDPReader{
|
||||
reader: udpConn,
|
||||
}
|
||||
return udp.CopyPacketConn(packetConn, protocolReader, udp.UpdateActivity(timer))
|
||||
}
|
||||
responseDoneAndCloseWriter := task.OnSuccess(responseDone, task.Close(link.Writer))
|
||||
if err := task.Run(ctx, requestDone, responseDoneAndCloseWriter); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var requestFunc func() error
|
||||
var responseFunc func() error
|
||||
if request.Command == protocol.RequestCommandTCP {
|
||||
|
Loading…
Reference in New Issue
Block a user