From d04adc10b6bfae8956541c163fa2b790127652ae Mon Sep 17 00:00:00 2001 From: Student Main Date: Sat, 25 Jul 2020 02:05:23 +0800 Subject: [PATCH] fix udp downlink. --- shadowsocks-csharp/Controller/Service/UDPListener.cs | 2 +- shadowsocks-csharp/Controller/Service/UDPRelay.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/UDPListener.cs b/shadowsocks-csharp/Controller/Service/UDPListener.cs index 53b92723..52f375a9 100644 --- a/shadowsocks-csharp/Controller/Service/UDPListener.cs +++ b/shadowsocks-csharp/Controller/Service/UDPListener.cs @@ -101,7 +101,7 @@ namespace Shadowsocks.Controller var len = result.ReceivedBytes; foreach (IDatagramService service in _services) { - if (service.Handle(buffer, len, _udpSocket, remote)) + if (service.Handle(buffer, len, _udpSocket, result.RemoteEndPoint)) { break; } diff --git a/shadowsocks-csharp/Controller/Service/UDPRelay.cs b/shadowsocks-csharp/Controller/Service/UDPRelay.cs index ecef6cb2..2068d226 100644 --- a/shadowsocks-csharp/Controller/Service/UDPRelay.cs +++ b/shadowsocks-csharp/Controller/Service/UDPRelay.cs @@ -46,6 +46,7 @@ namespace Shadowsocks.Controller } // UDPListener.UDPState udpState = (UDPListener.UDPState)state; IPEndPoint remoteEndPoint = (IPEndPoint)state; + // IPEndPoint remoteEndPoint = (IPEndPoint)socket.RemoteEndPoint; UDPHandler handler = _cache.get(remoteEndPoint); if (handler == null) { @@ -109,7 +110,7 @@ namespace Shadowsocks.Controller byte[] dataOut = new byte[slicedData.Length + 1000]; var dataToSend = slicedData[3..]; int outlen = encryptor.EncryptUDP(slicedData[3..], dataOut); - logger.Debug(_localEndPoint, _remoteEndPoint, outlen, "UDP Relay"); + logger.Debug(_localEndPoint, _remoteEndPoint, outlen, "UDP Relay up"); _remote?.SendTo(dataOut, outlen, SocketFlags.None, _remoteEndPoint); } @@ -137,7 +138,7 @@ namespace Shadowsocks.Controller byte[] sendBuf = new byte[outlen + 3]; Array.Copy(dataOut, 0, sendBuf, 3, outlen); - logger.Debug(_localEndPoint, _remoteEndPoint, outlen, "UDP Relay"); + logger.Debug(_remoteEndPoint, _localEndPoint, outlen, "UDP Relay down"); _local?.SendTo(sendBuf, outlen + 3, 0, _localEndPoint); Receive();