Browse Source

no hard code 8123

tags/2.3
clowwindy 9 years ago
parent
commit
5463b2859a
3 changed files with 26 additions and 2 deletions
  1. +23
    -0
      shadowsocks-csharp/Controller/PolipoRunner.cs
  2. +1
    -1
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  3. +2
    -1
      shadowsocks-csharp/Data/polipo_config.txt

+ 23
- 0
shadowsocks-csharp/Controller/PolipoRunner.cs View File

@@ -6,6 +6,8 @@ using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Net.NetworkInformation;
using System.Net;
namespace Shadowsocks.Controller
{
@@ -47,6 +49,7 @@ namespace Shadowsocks.Controller
}
string polipoConfig = Resources.polipo_config;
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", configuration.localPort.ToString());
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_PORT__", this.GetFreePort().ToString());
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));
@@ -79,5 +82,25 @@ namespace Shadowsocks.Controller
_process = null;
}
}
private int GetFreePort()
{
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] tcpEndPoints = properties.GetActiveTcpListeners();
List<int> usedPorts = new List<int>();
foreach (IPEndPoint endPoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
{
usedPorts.Add(endPoint.Port);
}
for (int port = 8123; port < 65535; port++)
{
if (!usedPorts.Contains(port))
{
return port;
}
}
throw new Exception("No free port found.");
}
}
}

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

@@ -222,7 +222,7 @@ namespace Shadowsocks.Controller
List<Listener.Service> services = new List<Listener.Service>();
services.Add(local);
services.Add(_pacServer);
services.Add(new PortForwarder(8123));
services.Add(new PortForwarder(_config.localPort));
_listener = new Listener(services);
_listener.Start(_config);
}


+ 2
- 1
shadowsocks-csharp/Data/polipo_config.txt View File

@@ -1,4 +1,5 @@
proxyAddress = "__POLIPO_BIND_IP__"
proxyAddress = "__POLIPO_BIND_IP__"
proxyPort = 8123

socksParentProxy = "127.0.0.1:__SOCKS_PORT__"
socksProxyType = socks5


Loading…
Cancel
Save