handle close; use real config
This commit is contained in:
@@ -53,7 +53,7 @@ namespace shadowsocks_csharp
|
||||
{
|
||||
local.Stop();
|
||||
}
|
||||
local = new Local(config.local_port);
|
||||
local = new Local(config);
|
||||
local.Start();
|
||||
|
||||
}
|
||||
|
||||
+31
-11
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,21 @@
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
<ApplicationIcon>icon144.ico</ApplicationIcon>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -89,6 +104,28 @@
|
||||
<ItemGroup>
|
||||
<Content Include="icon144.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
Reference in New Issue
Block a user