Browse Source

local port now is the same for different servers

tags/2.3
clowwindy 10 years ago
parent
commit
444fabaa79
6 changed files with 26 additions and 20 deletions
  1. +11
    -10
      shadowsocks-csharp/Controller/Local.cs
  2. +2
    -2
      shadowsocks-csharp/Controller/PolipoRunner.cs
  3. +1
    -1
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  4. +7
    -2
      shadowsocks-csharp/Model/Configuration.cs
  5. +0
    -2
      shadowsocks-csharp/Model/Server.cs
  6. +5
    -3
      shadowsocks-csharp/View/ConfigForm.cs

+ 11
- 10
shadowsocks-csharp/Controller/Local.cs View File

@@ -11,13 +11,13 @@ namespace Shadowsocks.Controller
class Local class Local
{ {
private Server _server;
private Configuration _config;
private bool _shareOverLAN; private bool _shareOverLAN;
//private Encryptor encryptor; //private Encryptor encryptor;
Socket _listener; Socket _listener;
public Local(Configuration config) public Local(Configuration config)
{ {
this._server = config.GetCurrentServer();
this._config = config;
_shareOverLAN = config.shareOverLan; _shareOverLAN = config.shareOverLan;
//this.encryptor = new Encryptor(config.method, config.password); //this.encryptor = new Encryptor(config.method, config.password);
} }
@@ -32,11 +32,11 @@ namespace Shadowsocks.Controller
IPEndPoint localEndPoint = null; IPEndPoint localEndPoint = null;
if (_shareOverLAN) if (_shareOverLAN)
{ {
localEndPoint = new IPEndPoint(IPAddress.Any, _server.local_port);
localEndPoint = new IPEndPoint(IPAddress.Any, _config.localPort);
} }
else else
{ {
localEndPoint = new IPEndPoint(IPAddress.Loopback, _server.local_port);
localEndPoint = new IPEndPoint(IPAddress.Loopback, _config.localPort);
} }
// Bind the socket to the local endpoint and listen for incoming connections. // Bind the socket to the local endpoint and listen for incoming connections.
@@ -74,8 +74,9 @@ namespace Shadowsocks.Controller
Handler handler = new Handler(); Handler handler = new Handler();
handler.connection = conn; handler.connection = conn;
handler.encryptor = EncryptorFactory.GetEncryptor(_server.method, _server.password);
handler.config = _server;
Server server = _config.GetCurrentServer();
handler.encryptor = EncryptorFactory.GetEncryptor(server.method, server.password);
handler.server = server;
handler.Start(); handler.Start();
} }
@@ -104,7 +105,7 @@ namespace Shadowsocks.Controller
{ {
//public Encryptor encryptor; //public Encryptor encryptor;
public IEncryptor encryptor; public IEncryptor encryptor;
public Server config;
public Server server;
// Client socket. // Client socket.
public Socket remote; public Socket remote;
public Socket connection; public Socket connection;
@@ -134,13 +135,13 @@ namespace Shadowsocks.Controller
{ {
// TODO async resolving // TODO async resolving
IPAddress ipAddress; IPAddress ipAddress;
bool parsed = IPAddress.TryParse(config.server, out ipAddress);
bool parsed = IPAddress.TryParse(server.server, out ipAddress);
if (!parsed) if (!parsed)
{ {
IPHostEntry ipHostInfo = Dns.GetHostEntry(config.server);
IPHostEntry ipHostInfo = Dns.GetHostEntry(server.server);
ipAddress = ipHostInfo.AddressList[0]; ipAddress = ipHostInfo.AddressList[0];
} }
IPEndPoint remoteEP = new IPEndPoint(ipAddress, config.server_port);
IPEndPoint remoteEP = new IPEndPoint(ipAddress, server.server_port);
remote = new Socket(ipAddress.AddressFamily, remote = new Socket(ipAddress.AddressFamily,


+ 2
- 2
shadowsocks-csharp/Controller/PolipoRunner.cs View File

@@ -45,8 +45,8 @@ namespace Shadowsocks.Controller
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
} }
} }
string polipoConfig = Resources.polipo_config;
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", server.local_port.ToString());
string polipoConfig = Resources.polipo_config;
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", configuration.localPort.ToString());
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_IP__", configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1"); polipoConfig = polipoConfig.Replace("__POLIPO_BIND_IP__", configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1");
FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig)); FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));


+ 1
- 1
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -74,7 +74,7 @@ namespace Shadowsocks.Controller
return Configuration.Load(); return Configuration.Load();
} }
public void SaveServers(List<Server> servers)
public void SaveServers(List<Server> servers, int localPort)
{ {
_config.configs = servers; _config.configs = servers;
SaveConfig(_config); SaveConfig(_config);


+ 7
- 2
shadowsocks-csharp/Model/Configuration.cs View File

@@ -16,6 +16,7 @@ namespace Shadowsocks.Model
public bool enabled; public bool enabled;
public bool shareOverLan; public bool shareOverLan;
public bool isDefault; public bool isDefault;
public int localPort;
private static string CONFIG_FILE = "gui-config.json"; private static string CONFIG_FILE = "gui-config.json";
@@ -33,7 +34,6 @@ namespace Shadowsocks.Model
public static void CheckServer(Server server) public static void CheckServer(Server server)
{ {
CheckPort(server.local_port);
CheckPort(server.server_port); CheckPort(server.server_port);
CheckPassword(server.password); CheckPassword(server.password);
CheckServer(server.server); CheckServer(server.server);
@@ -46,6 +46,10 @@ namespace Shadowsocks.Model
string configContent = File.ReadAllText(CONFIG_FILE); string configContent = File.ReadAllText(CONFIG_FILE);
Configuration config = SimpleJson.SimpleJson.DeserializeObject<Configuration>(configContent, new JsonSerializerStrategy()); Configuration config = SimpleJson.SimpleJson.DeserializeObject<Configuration>(configContent, new JsonSerializerStrategy());
config.isDefault = false; config.isDefault = false;
if (config.localPort == 0)
{
config.localPort = 1080;
}
return config; return config;
} }
catch (Exception e) catch (Exception e)
@@ -58,6 +62,7 @@ namespace Shadowsocks.Model
{ {
index = 0, index = 0,
isDefault = true, isDefault = true,
localPort = 1080,
configs = new List<Server>() configs = new List<Server>()
{ {
GetDefaultServer() GetDefaultServer()
@@ -105,7 +110,7 @@ namespace Shadowsocks.Model
} }
} }
private static void CheckPort(int port)
public static void CheckPort(int port)
{ {
if (port <= 0 || port > 65535) if (port <= 0 || port > 65535)
{ {


+ 0
- 2
shadowsocks-csharp/Model/Server.cs View File

@@ -14,7 +14,6 @@ namespace Shadowsocks.Model
{ {
public string server; public string server;
public int server_port; public int server_port;
public int local_port;
public string password; public string password;
public string method; public string method;
public string remarks; public string remarks;
@@ -39,7 +38,6 @@ namespace Shadowsocks.Model
{ {
this.server = ""; this.server = "";
this.server_port = 8388; this.server_port = 8388;
this.local_port = 1080;
this.method = "aes-256-cfb"; this.method = "aes-256-cfb";
this.password = ""; this.password = "";
this.remarks = ""; this.remarks = "";


+ 5
- 3
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -79,12 +79,14 @@ namespace Shadowsocks.View
server = IPTextBox.Text, server = IPTextBox.Text,
server_port = int.Parse(ServerPortTextBox.Text), server_port = int.Parse(ServerPortTextBox.Text),
password = PasswordTextBox.Text, password = PasswordTextBox.Text,
local_port = int.Parse(ProxyPortTextBox.Text),
method = EncryptionSelect.Text, method = EncryptionSelect.Text,
remarks = RemarksTextBox.Text remarks = RemarksTextBox.Text
}; };
int localPort = int.Parse(ProxyPortTextBox.Text);
Configuration.CheckServer(server); Configuration.CheckServer(server);
Configuration.CheckPort(localPort);
_modifiedConfiguration.configs[_oldSelectedIndex] = server; _modifiedConfiguration.configs[_oldSelectedIndex] = server;
_modifiedConfiguration.localPort = localPort;
return true; return true;
} }
@@ -108,7 +110,7 @@ namespace Shadowsocks.View
IPTextBox.Text = server.server; IPTextBox.Text = server.server;
ServerPortTextBox.Text = server.server_port.ToString(); ServerPortTextBox.Text = server.server_port.ToString();
PasswordTextBox.Text = server.password; PasswordTextBox.Text = server.password;
ProxyPortTextBox.Text = server.local_port.ToString();
ProxyPortTextBox.Text = _modifiedConfiguration.localPort.ToString();
EncryptionSelect.Text = server.method ?? "aes-256-cfb"; EncryptionSelect.Text = server.method ?? "aes-256-cfb";
RemarksTextBox.Text = server.remarks; RemarksTextBox.Text = server.remarks;
ServerGroupBox.Visible = true; ServerGroupBox.Visible = true;
@@ -202,7 +204,7 @@ namespace Shadowsocks.View
MessageBox.Show(I18N.GetString("Please add at least one server")); MessageBox.Show(I18N.GetString("Please add at least one server"));
return; return;
} }
controller.SaveServers(_modifiedConfiguration.configs);
controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort);
this.Close(); this.Close();
} }


Loading…
Cancel
Save