diff --git a/proxy/socks/server.go b/proxy/socks/server.go index f974df33e..880020372 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -2,6 +2,7 @@ package socks import ( "context" + "github.com/v2fly/v2ray-core/v4/common/net/packetaddr" "io" "time" @@ -186,7 +187,14 @@ func (s *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ } func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection, dispatcher routing.Dispatcher) error { - udpServer := udp.NewSplitDispatcher(dispatcher, func(ctx context.Context, packet *udp_proto.Packet) { + udpDispatcherConstructor := udp.NewSplitDispatcher + switch s.config.PacketEncoding { + case packetaddr.PacketAddrType_None: + break + case packetaddr.PacketAddrType_Packet: + udpDispatcherConstructor = udp.NewPacketAddrDispatcherCreator(ctx).NewPacketAddrDispatcher + } + udpServer := udpDispatcherConstructor(dispatcher, func(ctx context.Context, packet *udp_proto.Packet) { payload := packet.Payload newError("writing back UDP response with ", payload.Len(), " bytes").AtDebug().WriteToLog(session.ExportIDToError(ctx)) diff --git a/transport/internet/udp/dispatcher_packetaddr.go b/transport/internet/udp/dispatcher_packetaddr.go index 35f3e2e60..0785eb1f9 100644 --- a/transport/internet/udp/dispatcher_packetaddr.go +++ b/transport/internet/udp/dispatcher_packetaddr.go @@ -46,12 +46,9 @@ func NewPacketAddrDispatcherCreator(ctx context.Context) PacketAddrDispatcherCre } func (pdc *PacketAddrDispatcherCreator) NewPacketAddrDispatcher( - dispatcher routing.Dispatcher, callback ResponseCallback) (DispatcherI, error) { - packetConn, err := packetaddr.CreatePacketAddrConn(pdc.ctx, dispatcher, false) - if err != nil { - return nil, err - } + dispatcher routing.Dispatcher, callback ResponseCallback) DispatcherI { + packetConn, _ := packetaddr.CreatePacketAddrConn(pdc.ctx, dispatcher, false) pd := &PacketAddrDispatcher{conn: packetConn, callback: callback, ctx: pdc.ctx} go pd.readWorker() - return pd, nil + return pd }