@@ -0,0 +1,3 @@ | |||
[submodule "shadowsocks-csharp/simple-json"] | |||
path = shadowsocks-csharp/simple-json | |||
url = git@github.com:facebook-csharp-sdk/simple-json.git |
@@ -10,6 +10,10 @@ Other ports and clients can be found [here](https://github.com/clowwindy/shadows | |||
usage | |||
----------- | |||
First, clone the code: | |||
git clone --recurse-submodules git://github.com/shadowsocks/shadowsocks-iOS.git | |||
Use Visual Studio 2012 Express or higher to build. | |||
Need .Net 3.5. | |||
Need .Net 2.0. |
@@ -1,9 +1,9 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Runtime.Serialization.Json; | |||
using System.Text; | |||
using System.IO; | |||
using System.Diagnostics; | |||
using SimpleJson; | |||
namespace shadowsocks_csharp | |||
{ | |||
@@ -15,7 +15,6 @@ namespace shadowsocks_csharp | |||
public int local_port; | |||
public string password; | |||
[NonSerialized] | |||
public bool isDefault; | |||
private static void assert(bool condition) | |||
@@ -28,12 +27,11 @@ namespace shadowsocks_csharp | |||
public static Config Load() | |||
{ | |||
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Config)); | |||
try | |||
{ | |||
using (FileStream fs = File.OpenRead(@"config.json")) | |||
using (StreamReader sr = new StreamReader(File.OpenRead(@"config.json"))) | |||
{ | |||
Config config = ser.ReadObject(fs) as Config; | |||
Config config = SimpleJson.SimpleJson.DeserializeObject<Config>(sr.ReadToEnd()); | |||
assert(!string.IsNullOrEmpty(config.server)); | |||
assert(!string.IsNullOrEmpty(config.password)); | |||
assert(config.local_port > 0); | |||
@@ -58,12 +56,19 @@ namespace shadowsocks_csharp | |||
public static void Save(Config config) | |||
{ | |||
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Config)); | |||
try | |||
{ | |||
using (FileStream fs = File.Open(@"config.json", FileMode.Create)) | |||
using (StreamWriter sw = new StreamWriter(File.Open(@"config.json", FileMode.Create))) | |||
{ | |||
ser.WriteObject(fs, config); | |||
string jsonString = SimpleJson.SimpleJson.SerializeObject(new | |||
{ | |||
server = config.server, | |||
server_port = config.server_port, | |||
local_port = config.local_port, | |||
password = config.password | |||
}); | |||
sw.Write(jsonString); | |||
sw.Flush(); | |||
} | |||
} | |||
catch (IOException e) | |||
@@ -46,8 +46,8 @@ | |||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); | |||
this.ConfigItem = new System.Windows.Forms.ToolStripMenuItem(); | |||
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); | |||
this.QuitItem = new System.Windows.Forms.ToolStripMenuItem(); | |||
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); | |||
this.QuitItem = new System.Windows.Forms.ToolStripMenuItem(); | |||
this.tableLayoutPanel1.SuspendLayout(); | |||
this.panel1.SuspendLayout(); | |||
this.contextMenuStrip1.SuspendLayout(); | |||
@@ -224,6 +224,11 @@ | |||
this.aboutToolStripMenuItem.Text = "About"; | |||
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click); | |||
// | |||
// toolStripSeparator2 | |||
// | |||
this.toolStripSeparator2.Name = "toolStripSeparator2"; | |||
this.toolStripSeparator2.Size = new System.Drawing.Size(107, 6); | |||
// | |||
// QuitItem | |||
// | |||
this.QuitItem.Name = "QuitItem"; | |||
@@ -231,11 +236,6 @@ | |||
this.QuitItem.Text = "Quit"; | |||
this.QuitItem.Click += new System.EventHandler(this.Quit_Click); | |||
// | |||
// toolStripSeparator2 | |||
// | |||
this.toolStripSeparator2.Name = "toolStripSeparator2"; | |||
this.toolStripSeparator2.Size = new System.Drawing.Size(107, 6); | |||
// | |||
// Form1 | |||
// | |||
this.AcceptButton = this.button1; | |||
@@ -247,11 +247,12 @@ | |||
this.ClientSize = new System.Drawing.Size(282, 206); | |||
this.Controls.Add(this.tableLayoutPanel1); | |||
this.Controls.Add(this.panel1); | |||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); | |||
this.Name = "Form1"; | |||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; | |||
this.Text = "Shadowsocks"; | |||
this.Load += new System.EventHandler(this.Form1_Load); | |||
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed); | |||
this.Load += new System.EventHandler(this.Form1_Load); | |||
this.tableLayoutPanel1.ResumeLayout(false); | |||
this.tableLayoutPanel1.PerformLayout(); | |||
this.panel1.ResumeLayout(false); | |||
@@ -1,7 +1,6 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel; | |||
using System.Data; | |||
using System.Drawing; | |||
using System.Text; | |||
using System.Windows.Forms; | |||
@@ -6,7 +6,7 @@ using System.Net; | |||
namespace shadowsocks_csharp | |||
{ | |||
class Local | |||
{ | |||
@@ -28,8 +28,8 @@ namespace shadowsocks_csharp | |||
IPEndPoint localEndPoint = new IPEndPoint(0, config.local_port); | |||
// Bind the socket to the local endpoint and listen for incoming connections. | |||
listener.Bind(localEndPoint); | |||
listener.Listen(100); | |||
listener.Bind(localEndPoint); | |||
listener.Listen(100); | |||
// Start an asynchronous socket to listen for connections. | |||
@@ -95,24 +95,40 @@ namespace shadowsocks_csharp | |||
public void Start() | |||
{ | |||
// TODO async resolving | |||
IPHostEntry ipHostInfo = Dns.GetHostEntry(config.server); | |||
IPAddress ipAddress = ipHostInfo.AddressList[0]; | |||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, config.server_port); | |||
try | |||
{ | |||
// TODO async resolving | |||
IPAddress ipAddress; | |||
bool parsed = IPAddress.TryParse(config.server, out ipAddress); | |||
if (!parsed) | |||
{ | |||
IPHostEntry ipHostInfo = Dns.GetHostEntry(config.server); | |||
ipAddress = ipHostInfo.AddressList[0]; | |||
} | |||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, config.server_port); | |||
remote = new Socket(ipAddress.AddressFamily, | |||
SocketType.Stream, ProtocolType.Tcp); | |||
remote = new Socket(ipAddress.AddressFamily, | |||
SocketType.Stream, ProtocolType.Tcp); | |||
// Connect to the remote endpoint. | |||
remote.BeginConnect(remoteEP, | |||
new AsyncCallback(connectCallback), null); | |||
// Connect to the remote endpoint. | |||
remote.BeginConnect(remoteEP, | |||
new AsyncCallback(connectCallback), null); | |||
} | |||
catch (Exception e) | |||
{ | |||
Console.WriteLine(e.ToString()); | |||
this.Close(); | |||
} | |||
} | |||
public void Close() | |||
{ | |||
connection.Close(); | |||
remote.Close(); | |||
if (remote != null) | |||
{ | |||
remote.Close(); | |||
} | |||
} | |||
private void connectCallback(IAsyncResult ar) | |||
@@ -207,7 +223,6 @@ namespace shadowsocks_csharp | |||
} | |||
else | |||
{ | |||
Console.WriteLine("bytesRead: " + bytesRead.ToString()); | |||
this.Close(); | |||
} | |||
} | |||
@@ -232,6 +247,7 @@ namespace shadowsocks_csharp | |||
catch (Exception e) | |||
{ | |||
Console.WriteLine(e.ToString()); | |||
this.Close(); | |||
} | |||
} | |||
@@ -10,7 +10,7 @@ | |||
<AppDesignerFolder>Properties</AppDesignerFolder> | |||
<RootNamespace>shadowsocks_csharp</RootNamespace> | |||
<AssemblyName>shadowsocks-csharp</AssemblyName> | |||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | |||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> | |||
<FileAlignment>512</FileAlignment> | |||
<StartupObject> | |||
</StartupObject> | |||
@@ -42,34 +42,24 @@ | |||
<DebugType>full</DebugType> | |||
<Optimize>false</Optimize> | |||
<OutputPath>bin\Debug\</OutputPath> | |||
<DefineConstants>DEBUG;TRACE</DefineConstants> | |||
<DefineConstants>TRACE;DEBUG;SIMPLE_JSON_NO_LINQ_EXPRESSION</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<Prefer32Bit>false</Prefer32Bit> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
<DebugType>pdbonly</DebugType> | |||
<Optimize>true</Optimize> | |||
<OutputPath>bin\Release\</OutputPath> | |||
<DefineConstants>TRACE</DefineConstants> | |||
<DefineConstants>TRACE;SIMPLE_JSON_NO_LINQ_EXPRESSION</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<Prefer32Bit>false</Prefer32Bit> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Reference Include="System" /> | |||
<Reference Include="System.Core"> | |||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | |||
</Reference> | |||
<Reference Include="System.Data" /> | |||
<Reference Include="System.Deployment" /> | |||
<Reference Include="System.Drawing" /> | |||
<Reference Include="System.Runtime.Serialization"> | |||
<RequiredTargetFramework>3.0</RequiredTargetFramework> | |||
</Reference> | |||
<Reference Include="System.ServiceModel.Web"> | |||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | |||
</Reference> | |||
<Reference Include="System.Windows.Forms" /> | |||
<Reference Include="System.Xml" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Compile Include="Config.cs" /> | |||
@@ -107,6 +97,7 @@ | |||
<DependentUpon>Settings.settings</DependentUpon> | |||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | |||
</Compile> | |||
<Compile Include="simple-json\src\SimpleJson\SimpleJson.cs" /> | |||
<Compile Include="Test.cs" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
@@ -0,0 +1 @@ | |||
Subproject commit 8ef093ac7b18a9f48fb7a8e41085501c7e35e46c |