Browse Source

Add debug log in network transfer.

tags/3.0
10people 8 years ago
parent
commit
d0e16dc658
4 changed files with 18 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -0
      nuget.config
  3. +13
    -0
      shadowsocks-csharp/Controller/Service/TCPRelay.cs
  4. +3
    -0
      shadowsocks-csharp/Controller/Service/UDPRelay.cs

+ 1
- 0
.gitignore View File

@@ -1,3 +1,4 @@
/.vs/
Backup/ Backup/
bin/ bin/
obj/ obj/


+ 1
- 0
nuget.config View File

@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<config> <config>
<add key="repositoryPath" value="shadowsocks-csharp\3rd" /> <add key="repositoryPath" value="shadowsocks-csharp\3rd" />


+ 13
- 0
shadowsocks-csharp/Controller/Service/TCPRelay.cs View File

@@ -215,6 +215,7 @@ namespace Shadowsocks.Controller
response = new byte[] { 0, 91 }; response = new byte[] { 0, 91 };
Console.WriteLine("socks 5 protocol error"); Console.WriteLine("socks 5 protocol error");
} }
Logging.Debug($"======Send Local Port, size:" + response.Length);
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(HandshakeSendCallback), null); connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(HandshakeSendCallback), null);
} }
else else
@@ -246,6 +247,7 @@ namespace Shadowsocks.Controller
// +----+-----+-------+------+----------+----------+ // +----+-----+-------+------+----------+----------+
// Skip first 3 bytes // Skip first 3 bytes
// TODO validate // TODO validate
Logging.Debug($"======Receive Local Port, size:" + 3);
connection.BeginReceive(connetionRecvBuffer, 0, 3, 0, connection.BeginReceive(connetionRecvBuffer, 0, 3, 0,
new AsyncCallback(handshakeReceive2Callback), null); new AsyncCallback(handshakeReceive2Callback), null);
} }
@@ -272,6 +274,7 @@ namespace Shadowsocks.Controller
if (command == 1) if (command == 1)
{ {
byte[] response = { 5, 0, 0, 1, 0, 0, 0, 0, 0, 0 }; byte[] response = { 5, 0, 0, 1, 0, 0, 0, 0, 0, 0 };
Logging.Debug($"======Send Local Port, size:" + response.Length);
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(ResponseCallback), null); connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(ResponseCallback), null);
} }
else if (command == 3) else if (command == 3)
@@ -310,6 +313,7 @@ namespace Shadowsocks.Controller
address.CopyTo(response, 4); address.CopyTo(response, 4);
response[response.Length - 1] = (byte)(port & 0xFF); response[response.Length - 1] = (byte)(port & 0xFF);
response[response.Length - 2] = (byte)((port >> 8) & 0xFF); response[response.Length - 2] = (byte)((port >> 8) & 0xFF);
Logging.Debug($"======Send Local Port, size:" + response.Length);
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(ReadAll), true); connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(ReadAll), true);
} }
@@ -324,6 +328,7 @@ namespace Shadowsocks.Controller
if (ar.AsyncState != null) if (ar.AsyncState != null)
{ {
connection.EndSend(ar); connection.EndSend(ar);
Logging.Debug($"======Receive Local Port, size:" + RecvSize);
connection.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0, connection.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0,
new AsyncCallback(ReadAll), null); new AsyncCallback(ReadAll), null);
} }
@@ -332,6 +337,7 @@ namespace Shadowsocks.Controller
int bytesRead = connection.EndReceive(ar); int bytesRead = connection.EndReceive(ar);
if (bytesRead > 0) if (bytesRead > 0)
{ {
Logging.Debug($"======Receive Local Port, size:" + RecvSize);
connection.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0, connection.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0,
new AsyncCallback(ReadAll), null); new AsyncCallback(ReadAll), null);
} }
@@ -402,6 +408,7 @@ namespace Shadowsocks.Controller
connected = false; connected = false;
// Connect to the remote endpoint. // Connect to the remote endpoint.
Logging.Debug($"++++++Connect Server Port");
remote.BeginConnect(remoteEP, remote.BeginConnect(remoteEP,
new AsyncCallback(ConnectCallback), connectTimer); new AsyncCallback(ConnectCallback), connectTimer);
} }
@@ -501,8 +508,10 @@ namespace Shadowsocks.Controller
} }
try try
{ {
Logging.Debug($"++++++Receive Server Port, size:" + RecvSize);
remote.BeginReceive(remoteRecvBuffer, 0, RecvSize, 0, remote.BeginReceive(remoteRecvBuffer, 0, RecvSize, 0,
new AsyncCallback(PipeRemoteReceiveCallback), null); new AsyncCallback(PipeRemoteReceiveCallback), null);
Logging.Debug($"======Receive Local Port, size:"+ RecvSize);
connection.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0, connection.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0,
new AsyncCallback(PipeConnectionReceiveCallback), null); new AsyncCallback(PipeConnectionReceiveCallback), null);
} }
@@ -536,6 +545,7 @@ namespace Shadowsocks.Controller
} }
encryptor.Decrypt(remoteRecvBuffer, bytesRead, remoteSendBuffer, out bytesToSend); encryptor.Decrypt(remoteRecvBuffer, bytesRead, remoteSendBuffer, out bytesToSend);
} }
Logging.Debug($"======Send Local Port, size:" + bytesToSend);
connection.BeginSend(remoteSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeConnectionSendCallback), null); connection.BeginSend(remoteSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeConnectionSendCallback), null);
IStrategy strategy = controller.GetCurrentStrategy(); IStrategy strategy = controller.GetCurrentStrategy();
@@ -588,6 +598,7 @@ namespace Shadowsocks.Controller
} }
encryptor.Encrypt(connetionRecvBuffer, bytesRead, connetionSendBuffer, out bytesToSend); encryptor.Encrypt(connetionRecvBuffer, bytesRead, connetionSendBuffer, out bytesToSend);
} }
Logging.Debug($"++++++Send Server Port, size:" + bytesToSend);
remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null); remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null);
IStrategy strategy = controller.GetCurrentStrategy(); IStrategy strategy = controller.GetCurrentStrategy();
@@ -619,6 +630,7 @@ namespace Shadowsocks.Controller
try try
{ {
remote.EndSend(ar); remote.EndSend(ar);
Logging.Debug($"======Receive Local Port, size:" + RecvSize);
connection.BeginReceive(this.connetionRecvBuffer, 0, RecvSize, 0, connection.BeginReceive(this.connetionRecvBuffer, 0, RecvSize, 0,
new AsyncCallback(PipeConnectionReceiveCallback), null); new AsyncCallback(PipeConnectionReceiveCallback), null);
} }
@@ -638,6 +650,7 @@ namespace Shadowsocks.Controller
try try
{ {
connection.EndSend(ar); connection.EndSend(ar);
Logging.Debug($"++++++Receive Server Port, size:" + RecvSize);
remote.BeginReceive(this.remoteRecvBuffer, 0, RecvSize, 0, remote.BeginReceive(this.remoteRecvBuffer, 0, RecvSize, 0,
new AsyncCallback(PipeRemoteReceiveCallback), null); new AsyncCallback(PipeRemoteReceiveCallback), null);
} }


+ 3
- 0
shadowsocks-csharp/Controller/Service/UDPRelay.cs View File

@@ -80,11 +80,13 @@ namespace Shadowsocks.Controller
byte[] dataOut = new byte[length - 3 + 16 + IVEncryptor.ONETIMEAUTH_BYTES]; byte[] dataOut = new byte[length - 3 + 16 + IVEncryptor.ONETIMEAUTH_BYTES];
int outlen; int outlen;
encryptor.Encrypt(dataIn, length - 3, dataOut, out outlen); encryptor.Encrypt(dataIn, length - 3, dataOut, out outlen);
Logging.Debug($"++++++Send Server Port, size:" + outlen);
_remote.SendTo(dataOut, outlen, SocketFlags.None, _remoteEndPoint); _remote.SendTo(dataOut, outlen, SocketFlags.None, _remoteEndPoint);
} }
public void Receive() public void Receive()
{ {
EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0); EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
Logging.Debug($"++++++Receive Server Port, size:" + _buffer.Length);
_remote.BeginReceiveFrom(_buffer, 0, _buffer.Length, 0, ref remoteEndPoint, new AsyncCallback(RecvFromCallback), null); _remote.BeginReceiveFrom(_buffer, 0, _buffer.Length, 0, ref remoteEndPoint, new AsyncCallback(RecvFromCallback), null);
} }
public void RecvFromCallback(IAsyncResult ar) public void RecvFromCallback(IAsyncResult ar)
@@ -103,6 +105,7 @@ namespace Shadowsocks.Controller
byte[] sendBuf = new byte[outlen + 3]; byte[] sendBuf = new byte[outlen + 3];
Array.Copy(dataOut, 0, sendBuf, 3, outlen); Array.Copy(dataOut, 0, sendBuf, 3, outlen);
Logging.Debug($"======Send Local Port, size:" + (outlen + 3));
_local.SendTo(sendBuf, outlen + 3, 0, _localEndPoint); _local.SendTo(sendBuf, outlen + 3, 0, _localEndPoint);
Receive(); Receive();
} }


Loading…
Cancel
Save