diff --git a/shadowsocks-csharp/Form1.cs b/shadowsocks-csharp/Form1.cs index b6a8d8d8..7e3188ea 100755 --- a/shadowsocks-csharp/Form1.cs +++ b/shadowsocks-csharp/Form1.cs @@ -53,7 +53,7 @@ namespace shadowsocks_csharp { local.Stop(); } - local = new Local(config.local_port); + local = new Local(config); local.Start(); } diff --git a/shadowsocks-csharp/Local.cs b/shadowsocks-csharp/Local.cs index 12d2658a..252fab5c 100755 --- a/shadowsocks-csharp/Local.cs +++ b/shadowsocks-csharp/Local.cs @@ -10,13 +10,13 @@ namespace shadowsocks_csharp class Local { - private int port; + private Config config; private Encryptor encryptor; Socket listener; - public Local(int port) + public Local(Config config) { - this.port = port; - this.encryptor = new Encryptor("barfoo!"); + this.config = config; + this.encryptor = new Encryptor(config.password); } public void Start() @@ -25,7 +25,7 @@ namespace shadowsocks_csharp // Create a TCP/IP socket. listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - IPEndPoint localEndPoint = new IPEndPoint(0, port); + IPEndPoint localEndPoint = new IPEndPoint(0, config.local_port); // Bind the socket to the local endpoint and listen for incoming connections. listener.Bind(localEndPoint); @@ -63,6 +63,7 @@ namespace shadowsocks_csharp Handler handler = new Handler(); handler.connection = conn; handler.encryptor = encryptor; + handler.config = config; handler.Start(); //handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, @@ -79,6 +80,7 @@ namespace shadowsocks_csharp class Handler { public Encryptor encryptor; + public Config config; // Client socket. public Socket remote; public Socket connection; @@ -94,9 +96,9 @@ namespace shadowsocks_csharp public void Start() { // TODO async resolving - IPHostEntry ipHostInfo = Dns.GetHostEntry("127.0.0.1"); + IPHostEntry ipHostInfo = Dns.GetHostEntry(config.server); IPAddress ipAddress = ipHostInfo.AddressList[0]; - IPEndPoint remoteEP = new IPEndPoint(ipAddress, 8388); + IPEndPoint remoteEP = new IPEndPoint(ipAddress, config.server_port); remote = new Socket(AddressFamily.InterNetwork, @@ -107,6 +109,12 @@ namespace shadowsocks_csharp new AsyncCallback(connectCallback), null); } + public void Close() + { + connection.Close(); + remote.Close(); + } + private void connectCallback(IAsyncResult ar) { try @@ -122,6 +130,7 @@ namespace shadowsocks_csharp catch (Exception e) { Console.WriteLine(e.ToString()); + this.Close(); } } @@ -135,6 +144,7 @@ namespace shadowsocks_csharp catch (Exception e) { Console.WriteLine(e.ToString()); + this.Close(); } } @@ -151,12 +161,13 @@ namespace shadowsocks_csharp } else { - // TODO error + this.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); + this.Close(); } } @@ -179,6 +190,7 @@ namespace shadowsocks_csharp catch (Exception e) { Console.WriteLine(e.ToString()); + this.Close(); } } @@ -195,12 +207,14 @@ namespace shadowsocks_csharp } else { - // TODO error + Console.WriteLine("bytesRead: " + bytesRead.ToString()); + this.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); + this.Close(); } } @@ -235,12 +249,14 @@ namespace shadowsocks_csharp } else { - // TODO error + Console.WriteLine("bytesRead: " + bytesRead.ToString()); + this.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); + this.Close(); } } @@ -258,12 +274,14 @@ namespace shadowsocks_csharp } else { - // TODO error + Console.WriteLine("bytesRead: " + bytesRead.ToString()); + this.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); + this.Close(); } } @@ -278,6 +296,7 @@ namespace shadowsocks_csharp catch (Exception e) { Console.WriteLine(e.ToString()); + this.Close(); } } @@ -292,6 +311,7 @@ namespace shadowsocks_csharp catch (Exception e) { Console.WriteLine(e.ToString()); + this.Close(); } } } diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 51c38f8b..69a70210 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -15,6 +15,21 @@ icon144.ico + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true true @@ -89,6 +104,28 @@ + + + False + .NET Framework 2.0 %28x86%29 + false + + + False + .NET Framework 3.0 %28x86%29 + false + + + False + .NET Framework 3.5 + true + + + False + Windows Installer 3.1 + true + +