Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7425e09ebc | ||
|
|
e1a90da2a4 | ||
|
|
6a5432c861 | ||
|
|
5acfadcdb6 | ||
|
|
9901c2a574 | ||
|
|
e038beee3e | ||
|
|
c66ede2f59 | ||
|
|
c54735e0e4 | ||
|
|
60dc9e7d71 | ||
|
|
02f75f899f | ||
|
|
eda92b80e1 | ||
|
|
ccec6be210 | ||
|
|
01c059c4e3 | ||
|
|
a0e79f37bc | ||
|
|
a2cd2a5408 | ||
|
|
9332741e18 | ||
|
|
1a68544f7f | ||
|
|
dafe33f7ed | ||
|
|
008e3544f2 | ||
|
|
449df1022d | ||
|
|
cb5fece8b3 | ||
|
|
8c869ca38e | ||
|
|
ddd46ed8c6 | ||
|
|
4afd5faf3f | ||
|
|
da41514839 | ||
|
|
f6cbf7b73a |
@@ -1,3 +1,16 @@
|
|||||||
|
2.5.2 2015-08-04
|
||||||
|
- Add log viewer
|
||||||
|
|
||||||
|
2.5.1 2015-07-26
|
||||||
|
- Prevent HA from switching servers too frequently
|
||||||
|
- Fix server settings can not be updated when using HA
|
||||||
|
- Fix server port can't be 8123
|
||||||
|
- Other minor fixes
|
||||||
|
|
||||||
|
2.5 2015-07-25
|
||||||
|
- Support load balance
|
||||||
|
- Support high availability
|
||||||
|
|
||||||
2.4 2015-07-11
|
2.4 2015-07-11
|
||||||
- Support UDP relay
|
- Support UDP relay
|
||||||
- Support online PAC
|
- Support online PAC
|
||||||
|
|||||||
@@ -3,13 +3,17 @@ Shadowsocks for Windows
|
|||||||
|
|
||||||
[![Build Status]][Appveyor]
|
[![Build Status]][Appveyor]
|
||||||
|
|
||||||
|
Announcement: We'll drop .Net 2.0 support in our next release. The minimal installation
|
||||||
|
requirement will be .Net 4.0. If you have any questions, please post in the issue tracker.
|
||||||
|
|
||||||
#### Features
|
#### Features
|
||||||
|
|
||||||
1. System proxy configuration
|
1. System proxy configuration
|
||||||
2. Fast profile switching
|
2. PAC mode and global mode
|
||||||
3. PAC mode and global mode
|
3. GFWList and user rules
|
||||||
4. GFWList and user rules
|
4. Supports HTTP proxy
|
||||||
5. Supports HTTP proxy
|
5. Supports server auto switching
|
||||||
|
6. Supports UDP relay (see Usage)
|
||||||
|
|
||||||
#### Download
|
#### Download
|
||||||
|
|
||||||
@@ -19,7 +23,7 @@ For >= Windows 8 or with .Net 4.0, download Shadowsocks-win-dotnet4.0-x.x.x.zip.
|
|||||||
|
|
||||||
For <= Windows 7 or with .Net 2.0, download Shadowsocks-win-x.x.x.zip.
|
For <= Windows 7 or with .Net 2.0, download Shadowsocks-win-x.x.x.zip.
|
||||||
|
|
||||||
#### Usage
|
#### Basic
|
||||||
|
|
||||||
1. Find Shadowsocks icon in the notification tray
|
1. Find Shadowsocks icon in the notification tray
|
||||||
2. You can add multiple servers in servers menu
|
2. You can add multiple servers in servers menu
|
||||||
@@ -28,15 +32,24 @@ proxy addons in your browser, or set them to use system proxy
|
|||||||
4. You can also configure your browser proxy manually if you don't want to enable
|
4. You can also configure your browser proxy manually if you don't want to enable
|
||||||
system proxy. Set Socks5 or HTTP proxy to 127.0.0.1:1080. You can change this
|
system proxy. Set Socks5 or HTTP proxy to 127.0.0.1:1080. You can change this
|
||||||
port in Server -> Edit Servers
|
port in Server -> Edit Servers
|
||||||
5. You can change PAC rules by editing the PAC file. When you save the PAC file
|
|
||||||
|
#### PAC
|
||||||
|
|
||||||
|
1. You can change PAC rules by editing the PAC file. When you save the PAC file
|
||||||
with any editor, Shadowsocks will notify browsers about the change automatically
|
with any editor, Shadowsocks will notify browsers about the change automatically
|
||||||
6. You can also update the PAC file from GFWList. Note your modifications to the PAC
|
2. You can also update PAC file from GFWList (maintained by 3rd party)
|
||||||
file will be lost. However you can put your rules in the user rule file for GFWList.
|
3. You can also use online PAC URL
|
||||||
Don't forget to update from GFWList again after you've edited the user rule
|
|
||||||
|
|
||||||
### Develop
|
#### Server Auto Switching
|
||||||
|
|
||||||
Visual Studio Express 2012 is recommended.
|
1. Load balance: choosing server randomly
|
||||||
|
2. High availability: choosing the best server (low latency and packet loss)
|
||||||
|
3. Write your own strategy by implement IStrategy interface and send us a pull request!
|
||||||
|
|
||||||
|
#### UDP
|
||||||
|
|
||||||
|
For UDP, you need to use SocksCap or ProxyCap to force programs you want
|
||||||
|
to proxy to tunnel over Shadowsocks
|
||||||
|
|
||||||
#### License
|
#### License
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Debug(object o)
|
||||||
|
{
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine(o);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
public static void LogUsefulException(Exception e)
|
public static void LogUsefulException(Exception e)
|
||||||
{
|
{
|
||||||
// just log useful exceptions, not all of them
|
// just log useful exceptions, not all of them
|
||||||
@@ -55,6 +63,9 @@ namespace Shadowsocks.Controller
|
|||||||
Console.WriteLine(e);
|
Console.WriteLine(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (e is ObjectDisposedException)
|
||||||
|
{
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
Console.WriteLine(e);
|
||||||
|
|||||||
Executable → Regular
+1
-1
@@ -18,7 +18,7 @@ namespace Shadowsocks.Controller
|
|||||||
public class UDPState
|
public class UDPState
|
||||||
{
|
{
|
||||||
public byte[] buffer = new byte[4096];
|
public byte[] buffer = new byte[4096];
|
||||||
public EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 1);
|
public EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration _config;
|
Configuration _config;
|
||||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
+148
-12
@@ -5,16 +5,18 @@ using System.Net.Sockets;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using Shadowsocks.Encryption;
|
using Shadowsocks.Encryption;
|
||||||
using Shadowsocks.Model;
|
using Shadowsocks.Model;
|
||||||
|
using Shadowsocks.Controller.Strategy;
|
||||||
|
using System.Timers;
|
||||||
|
|
||||||
namespace Shadowsocks.Controller
|
namespace Shadowsocks.Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
class TCPRelay : Listener.Service
|
class TCPRelay : Listener.Service
|
||||||
{
|
{
|
||||||
private Configuration _config;
|
private ShadowsocksController _controller;
|
||||||
public TCPRelay(Configuration config)
|
public TCPRelay(ShadowsocksController controller)
|
||||||
{
|
{
|
||||||
this._config = config;
|
this._controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Handle(byte[] firstPacket, int length, Socket socket, object state)
|
public bool Handle(byte[] firstPacket, int length, Socket socket, object state)
|
||||||
@@ -30,9 +32,7 @@ namespace Shadowsocks.Controller
|
|||||||
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
|
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
handler.connection = socket;
|
handler.connection = socket;
|
||||||
Server server = _config.GetCurrentServer();
|
handler.controller = _controller;
|
||||||
handler.encryptor = EncryptorFactory.GetEncryptor(server.method, server.password);
|
|
||||||
handler.server = server;
|
|
||||||
|
|
||||||
handler.Start(firstPacket, length);
|
handler.Start(firstPacket, length);
|
||||||
return true;
|
return true;
|
||||||
@@ -47,6 +47,9 @@ namespace Shadowsocks.Controller
|
|||||||
// Client socket.
|
// Client socket.
|
||||||
public Socket remote;
|
public Socket remote;
|
||||||
public Socket connection;
|
public Socket connection;
|
||||||
|
public ShadowsocksController controller;
|
||||||
|
private int retryCount = 0;
|
||||||
|
private bool connected;
|
||||||
|
|
||||||
private byte command;
|
private byte command;
|
||||||
private byte[] _firstPacket;
|
private byte[] _firstPacket;
|
||||||
@@ -54,6 +57,10 @@ namespace Shadowsocks.Controller
|
|||||||
// Size of receive buffer.
|
// Size of receive buffer.
|
||||||
public const int RecvSize = 16384;
|
public const int RecvSize = 16384;
|
||||||
public const int BufferSize = RecvSize + 32;
|
public const int BufferSize = RecvSize + 32;
|
||||||
|
|
||||||
|
private int totalRead = 0;
|
||||||
|
private int totalWrite = 0;
|
||||||
|
|
||||||
// remote receive buffer
|
// remote receive buffer
|
||||||
private byte[] remoteRecvBuffer = new byte[RecvSize];
|
private byte[] remoteRecvBuffer = new byte[RecvSize];
|
||||||
// remote send buffer
|
// remote send buffer
|
||||||
@@ -71,6 +78,19 @@ namespace Shadowsocks.Controller
|
|||||||
private object encryptionLock = new object();
|
private object encryptionLock = new object();
|
||||||
private object decryptionLock = new object();
|
private object decryptionLock = new object();
|
||||||
|
|
||||||
|
private DateTime _startConnectTime;
|
||||||
|
|
||||||
|
public void CreateRemote()
|
||||||
|
{
|
||||||
|
Server server = controller.GetAServer(IStrategyCallerType.TCP, (IPEndPoint)connection.RemoteEndPoint);
|
||||||
|
if (server == null || server.server == "")
|
||||||
|
{
|
||||||
|
throw new ArgumentException("No server configured");
|
||||||
|
}
|
||||||
|
this.encryptor = EncryptorFactory.GetEncryptor(server.method, server.password);
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
public void Start(byte[] firstPacket, int length)
|
public void Start(byte[] firstPacket, int length)
|
||||||
{
|
{
|
||||||
this._firstPacket = firstPacket;
|
this._firstPacket = firstPacket;
|
||||||
@@ -115,7 +135,7 @@ namespace Shadowsocks.Controller
|
|||||||
remote.Shutdown(SocketShutdown.Both);
|
remote.Shutdown(SocketShutdown.Both);
|
||||||
remote.Close();
|
remote.Close();
|
||||||
}
|
}
|
||||||
catch (SocketException e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logging.LogUsefulException(e);
|
Logging.LogUsefulException(e);
|
||||||
}
|
}
|
||||||
@@ -124,7 +144,10 @@ namespace Shadowsocks.Controller
|
|||||||
{
|
{
|
||||||
lock (decryptionLock)
|
lock (decryptionLock)
|
||||||
{
|
{
|
||||||
((IDisposable)encryptor).Dispose();
|
if (encryptor != null)
|
||||||
|
{
|
||||||
|
((IDisposable)encryptor).Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,7 +229,7 @@ namespace Shadowsocks.Controller
|
|||||||
if (command == 1)
|
if (command == 1)
|
||||||
{
|
{
|
||||||
byte[] response = { 5, 0, 0, 1, 0, 0, 0, 0, 0, 0 };
|
byte[] response = { 5, 0, 0, 1, 0, 0, 0, 0, 0, 0 };
|
||||||
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(StartConnect), null);
|
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(ResponseCallback), null);
|
||||||
}
|
}
|
||||||
else if (command == 3)
|
else if (command == 3)
|
||||||
{
|
{
|
||||||
@@ -283,12 +306,37 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartConnect(IAsyncResult ar)
|
private void ResponseCallback(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
connection.EndSend(ar);
|
connection.EndSend(ar);
|
||||||
|
|
||||||
|
StartConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logging.LogUsefulException(e);
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ServerTimer : Timer
|
||||||
|
{
|
||||||
|
public Server Server;
|
||||||
|
|
||||||
|
public ServerTimer(int p) :base(p)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartConnect()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CreateRemote();
|
||||||
|
|
||||||
// TODO async resolving
|
// TODO async resolving
|
||||||
IPAddress ipAddress;
|
IPAddress ipAddress;
|
||||||
bool parsed = IPAddress.TryParse(server.server, out ipAddress);
|
bool parsed = IPAddress.TryParse(server.server, out ipAddress);
|
||||||
@@ -304,9 +352,17 @@ namespace Shadowsocks.Controller
|
|||||||
SocketType.Stream, ProtocolType.Tcp);
|
SocketType.Stream, ProtocolType.Tcp);
|
||||||
remote.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
|
remote.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
|
||||||
|
|
||||||
|
_startConnectTime = DateTime.Now;
|
||||||
|
ServerTimer connectTimer = new ServerTimer(3000);
|
||||||
|
connectTimer.AutoReset = false;
|
||||||
|
connectTimer.Elapsed += connectTimer_Elapsed;
|
||||||
|
connectTimer.Enabled = true;
|
||||||
|
connectTimer.Server = server;
|
||||||
|
|
||||||
|
connected = false;
|
||||||
// Connect to the remote endpoint.
|
// Connect to the remote endpoint.
|
||||||
remote.BeginConnect(remoteEP,
|
remote.BeginConnect(remoteEP,
|
||||||
new AsyncCallback(ConnectCallback), null);
|
new AsyncCallback(ConnectCallback), connectTimer);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -315,26 +371,84 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void connectTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
if (connected)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Server server = ((ServerTimer)sender).Server;
|
||||||
|
IStrategy strategy = controller.GetCurrentStrategy();
|
||||||
|
if (strategy != null)
|
||||||
|
{
|
||||||
|
strategy.SetFailure(server);
|
||||||
|
}
|
||||||
|
Console.WriteLine(String.Format("{0} timed out", server.FriendlyName()));
|
||||||
|
remote.Close();
|
||||||
|
RetryConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RetryConnect()
|
||||||
|
{
|
||||||
|
if (retryCount < 4)
|
||||||
|
{
|
||||||
|
Logging.Debug("Connection failed, retrying");
|
||||||
|
StartConnect();
|
||||||
|
retryCount++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ConnectCallback(IAsyncResult ar)
|
private void ConnectCallback(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
|
Server server = null;
|
||||||
if (closed)
|
if (closed)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
ServerTimer timer = (ServerTimer)ar.AsyncState;
|
||||||
|
server = timer.Server;
|
||||||
|
timer.Elapsed -= connectTimer_Elapsed;
|
||||||
|
timer.Enabled = false;
|
||||||
|
timer.Dispose();
|
||||||
|
|
||||||
// Complete the connection.
|
// Complete the connection.
|
||||||
remote.EndConnect(ar);
|
remote.EndConnect(ar);
|
||||||
|
|
||||||
|
connected = true;
|
||||||
|
|
||||||
//Console.WriteLine("Socket connected to {0}",
|
//Console.WriteLine("Socket connected to {0}",
|
||||||
// remote.RemoteEndPoint.ToString());
|
// remote.RemoteEndPoint.ToString());
|
||||||
|
|
||||||
|
var latency = DateTime.Now - _startConnectTime;
|
||||||
|
IStrategy strategy = controller.GetCurrentStrategy();
|
||||||
|
if (strategy != null)
|
||||||
|
{
|
||||||
|
strategy.UpdateLatency(server, latency);
|
||||||
|
}
|
||||||
|
|
||||||
StartPipe();
|
StartPipe();
|
||||||
}
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
if (server != null)
|
||||||
|
{
|
||||||
|
IStrategy strategy = controller.GetCurrentStrategy();
|
||||||
|
if (strategy != null)
|
||||||
|
{
|
||||||
|
strategy.SetFailure(server);
|
||||||
|
}
|
||||||
|
}
|
||||||
Logging.LogUsefulException(e);
|
Logging.LogUsefulException(e);
|
||||||
this.Close();
|
RetryConnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,6 +481,7 @@ namespace Shadowsocks.Controller
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
int bytesRead = remote.EndReceive(ar);
|
int bytesRead = remote.EndReceive(ar);
|
||||||
|
totalRead += bytesRead;
|
||||||
|
|
||||||
if (bytesRead > 0)
|
if (bytesRead > 0)
|
||||||
{
|
{
|
||||||
@@ -380,6 +495,12 @@ namespace Shadowsocks.Controller
|
|||||||
encryptor.Decrypt(remoteRecvBuffer, bytesRead, remoteSendBuffer, out bytesToSend);
|
encryptor.Decrypt(remoteRecvBuffer, bytesRead, remoteSendBuffer, out bytesToSend);
|
||||||
}
|
}
|
||||||
connection.BeginSend(remoteSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeConnectionSendCallback), null);
|
connection.BeginSend(remoteSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeConnectionSendCallback), null);
|
||||||
|
|
||||||
|
IStrategy strategy = controller.GetCurrentStrategy();
|
||||||
|
if (strategy != null)
|
||||||
|
{
|
||||||
|
strategy.UpdateLastRead(this.server);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -387,6 +508,13 @@ namespace Shadowsocks.Controller
|
|||||||
connection.Shutdown(SocketShutdown.Send);
|
connection.Shutdown(SocketShutdown.Send);
|
||||||
connectionShutdown = true;
|
connectionShutdown = true;
|
||||||
CheckClose();
|
CheckClose();
|
||||||
|
|
||||||
|
if (totalRead == 0)
|
||||||
|
{
|
||||||
|
// closed before anything received, reports as failure
|
||||||
|
// disable this feature
|
||||||
|
// controller.GetCurrentStrategy().SetFailure(this.server);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -405,6 +533,7 @@ namespace Shadowsocks.Controller
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
int bytesRead = connection.EndReceive(ar);
|
int bytesRead = connection.EndReceive(ar);
|
||||||
|
totalWrite += bytesRead;
|
||||||
|
|
||||||
if (bytesRead > 0)
|
if (bytesRead > 0)
|
||||||
{
|
{
|
||||||
@@ -418,6 +547,13 @@ namespace Shadowsocks.Controller
|
|||||||
encryptor.Encrypt(connetionRecvBuffer, bytesRead, connetionSendBuffer, out bytesToSend);
|
encryptor.Encrypt(connetionRecvBuffer, bytesRead, connetionSendBuffer, out bytesToSend);
|
||||||
}
|
}
|
||||||
remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null);
|
remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null);
|
||||||
|
|
||||||
|
|
||||||
|
IStrategy strategy = controller.GetCurrentStrategy();
|
||||||
|
if (strategy != null)
|
||||||
|
{
|
||||||
|
strategy.UpdateLastWrite(this.server);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
+5
-4
@@ -6,16 +6,17 @@ using Shadowsocks.Model;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using Shadowsocks.Controller.Strategy;
|
||||||
|
|
||||||
namespace Shadowsocks.Controller
|
namespace Shadowsocks.Controller
|
||||||
{
|
{
|
||||||
class UDPRelay : Listener.Service
|
class UDPRelay : Listener.Service
|
||||||
{
|
{
|
||||||
private Configuration _config;
|
private ShadowsocksController _controller;
|
||||||
private LRUCache<IPEndPoint, UDPHandler> _cache;
|
private LRUCache<IPEndPoint, UDPHandler> _cache;
|
||||||
public UDPRelay(Configuration config)
|
public UDPRelay(ShadowsocksController controller)
|
||||||
{
|
{
|
||||||
this._config = config;
|
this._controller = controller;
|
||||||
this._cache = new LRUCache<IPEndPoint, UDPHandler>(512); // todo: choose a smart number
|
this._cache = new LRUCache<IPEndPoint, UDPHandler>(512); // todo: choose a smart number
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ namespace Shadowsocks.Controller
|
|||||||
UDPHandler handler = _cache.get(remoteEndPoint);
|
UDPHandler handler = _cache.get(remoteEndPoint);
|
||||||
if (handler == null)
|
if (handler == null)
|
||||||
{
|
{
|
||||||
handler = new UDPHandler(socket, _config.GetCurrentServer(), remoteEndPoint);
|
handler = new UDPHandler(socket, _controller.GetAServer(IStrategyCallerType.UDP, remoteEndPoint), remoteEndPoint);
|
||||||
_cache.add(remoteEndPoint, handler);
|
_cache.add(remoteEndPoint, handler);
|
||||||
}
|
}
|
||||||
handler.Send(firstPacket, length);
|
handler.Send(firstPacket, length);
|
||||||
Executable → Regular
+2
-26
@@ -18,7 +18,7 @@ namespace Shadowsocks.Controller
|
|||||||
public string LatestVersionURL;
|
public string LatestVersionURL;
|
||||||
public event EventHandler NewVersionFound;
|
public event EventHandler NewVersionFound;
|
||||||
|
|
||||||
public const string Version = "2.4";
|
public const string Version = "2.5.2";
|
||||||
|
|
||||||
public void CheckUpdate(Configuration config)
|
public void CheckUpdate(Configuration config)
|
||||||
{
|
{
|
||||||
@@ -80,30 +80,6 @@ namespace Shadowsocks.Controller
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check dotnet 4.0
|
|
||||||
AssemblyName[] references = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
|
|
||||||
Version dotNetVersion = Environment.Version;
|
|
||||||
foreach (AssemblyName reference in references)
|
|
||||||
{
|
|
||||||
if (reference.Name == "mscorlib")
|
|
||||||
{
|
|
||||||
dotNetVersion = reference.Version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dotNetVersion.Major >= 4)
|
|
||||||
{
|
|
||||||
if (url.IndexOf("dotnet4.0") < 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (url.IndexOf("dotnet4.0") >= 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
string version = ParseVersionFromURL(url);
|
string version = ParseVersionFromURL(url);
|
||||||
if (version == null)
|
if (version == null)
|
||||||
{
|
{
|
||||||
@@ -154,7 +130,7 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.ToString());
|
Logging.Debug(ex.ToString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using Shadowsocks.Controller.Strategy;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
namespace Shadowsocks.Controller
|
namespace Shadowsocks.Controller
|
||||||
{
|
{
|
||||||
@@ -20,6 +22,7 @@ namespace Shadowsocks.Controller
|
|||||||
private Listener _listener;
|
private Listener _listener;
|
||||||
private PACServer _pacServer;
|
private PACServer _pacServer;
|
||||||
private Configuration _config;
|
private Configuration _config;
|
||||||
|
private StrategyManager _strategyManager;
|
||||||
private PolipoRunner polipoRunner;
|
private PolipoRunner polipoRunner;
|
||||||
private GFWListUpdater gfwListUpdater;
|
private GFWListUpdater gfwListUpdater;
|
||||||
private bool stopped = false;
|
private bool stopped = false;
|
||||||
@@ -49,6 +52,7 @@ namespace Shadowsocks.Controller
|
|||||||
public ShadowsocksController()
|
public ShadowsocksController()
|
||||||
{
|
{
|
||||||
_config = Configuration.Load();
|
_config = Configuration.Load();
|
||||||
|
_strategyManager = new StrategyManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
@@ -70,11 +74,48 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// always return copy
|
// always return copy
|
||||||
public Configuration GetConfiguration()
|
public Configuration GetConfigurationCopy()
|
||||||
{
|
{
|
||||||
return Configuration.Load();
|
return Configuration.Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// always return current instance
|
||||||
|
public Configuration GetCurrentConfiguration()
|
||||||
|
{
|
||||||
|
return _config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IList<IStrategy> GetStrategies()
|
||||||
|
{
|
||||||
|
return _strategyManager.GetStrategies();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IStrategy GetCurrentStrategy()
|
||||||
|
{
|
||||||
|
foreach (var strategy in _strategyManager.GetStrategies())
|
||||||
|
{
|
||||||
|
if (strategy.ID == this._config.strategy)
|
||||||
|
{
|
||||||
|
return strategy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint)
|
||||||
|
{
|
||||||
|
IStrategy strategy = GetCurrentStrategy();
|
||||||
|
if (strategy != null)
|
||||||
|
{
|
||||||
|
return strategy.GetAServer(type, localIPEndPoint);
|
||||||
|
}
|
||||||
|
if (_config.index < 0)
|
||||||
|
{
|
||||||
|
_config.index = 0;
|
||||||
|
}
|
||||||
|
return GetCurrentServer();
|
||||||
|
}
|
||||||
|
|
||||||
public void SaveServers(List<Server> servers, int localPort)
|
public void SaveServers(List<Server> servers, int localPort)
|
||||||
{
|
{
|
||||||
_config.configs = servers;
|
_config.configs = servers;
|
||||||
@@ -134,6 +175,14 @@ namespace Shadowsocks.Controller
|
|||||||
public void SelectServerIndex(int index)
|
public void SelectServerIndex(int index)
|
||||||
{
|
{
|
||||||
_config.index = index;
|
_config.index = index;
|
||||||
|
_config.strategy = null;
|
||||||
|
SaveConfig(_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SelectStrategy(string strategyID)
|
||||||
|
{
|
||||||
|
_config.index = -1;
|
||||||
|
_config.strategy = strategyID;
|
||||||
SaveConfig(_config);
|
SaveConfig(_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,10 +297,16 @@ namespace Shadowsocks.Controller
|
|||||||
polipoRunner.Stop();
|
polipoRunner.Stop();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var strategy = GetCurrentStrategy();
|
||||||
|
if (strategy != null)
|
||||||
|
{
|
||||||
|
strategy.ReloadServers();
|
||||||
|
}
|
||||||
|
|
||||||
polipoRunner.Start(_config);
|
polipoRunner.Start(_config);
|
||||||
|
|
||||||
TCPRelay tcpRelay = new TCPRelay(_config);
|
TCPRelay tcpRelay = new TCPRelay(this);
|
||||||
UDPRelay udpRelay = new UDPRelay(_config);
|
UDPRelay udpRelay = new UDPRelay(this);
|
||||||
List<Listener.Service> services = new List<Listener.Service>();
|
List<Listener.Service> services = new List<Listener.Service>();
|
||||||
services.Add(tcpRelay);
|
services.Add(tcpRelay);
|
||||||
services.Add(udpRelay);
|
services.Add(udpRelay);
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
using Shadowsocks.Controller;
|
||||||
|
using Shadowsocks.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Shadowsocks.Controller.Strategy
|
||||||
|
{
|
||||||
|
class BalancingStrategy : IStrategy
|
||||||
|
{
|
||||||
|
ShadowsocksController _controller;
|
||||||
|
Random _random;
|
||||||
|
|
||||||
|
public BalancingStrategy(ShadowsocksController controller)
|
||||||
|
{
|
||||||
|
_controller = controller;
|
||||||
|
_random = new Random();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return I18N.GetString("Load Balance"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ID
|
||||||
|
{
|
||||||
|
get { return "com.shadowsocks.strategy.balancing"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReloadServers()
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint)
|
||||||
|
{
|
||||||
|
var configs = _controller.GetCurrentConfiguration().configs;
|
||||||
|
int index;
|
||||||
|
if (type == IStrategyCallerType.TCP)
|
||||||
|
{
|
||||||
|
index = _random.Next();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index = localIPEndPoint.GetHashCode();
|
||||||
|
}
|
||||||
|
return configs[index % configs.Count];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateLatency(Model.Server server, TimeSpan latency)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateLastRead(Model.Server server)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateLastWrite(Model.Server server)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFailure(Model.Server server)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
using Shadowsocks.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Shadowsocks.Controller.Strategy
|
||||||
|
{
|
||||||
|
class HighAvailabilityStrategy : IStrategy
|
||||||
|
{
|
||||||
|
protected ServerStatus _currentServer;
|
||||||
|
protected Dictionary<Server, ServerStatus> _serverStatus;
|
||||||
|
ShadowsocksController _controller;
|
||||||
|
Random _random;
|
||||||
|
|
||||||
|
public class ServerStatus
|
||||||
|
{
|
||||||
|
// time interval between SYN and SYN+ACK
|
||||||
|
public TimeSpan latency;
|
||||||
|
public DateTime lastTimeDetectLatency;
|
||||||
|
|
||||||
|
// last time anything received
|
||||||
|
public DateTime lastRead;
|
||||||
|
|
||||||
|
// last time anything sent
|
||||||
|
public DateTime lastWrite;
|
||||||
|
|
||||||
|
// connection refused or closed before anything received
|
||||||
|
public DateTime lastFailure;
|
||||||
|
|
||||||
|
public Server server;
|
||||||
|
|
||||||
|
public double score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HighAvailabilityStrategy(ShadowsocksController controller)
|
||||||
|
{
|
||||||
|
_controller = controller;
|
||||||
|
_random = new Random();
|
||||||
|
_serverStatus = new Dictionary<Server, ServerStatus>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return I18N.GetString("High Availability"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ID
|
||||||
|
{
|
||||||
|
get { return "com.shadowsocks.strategy.ha"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReloadServers()
|
||||||
|
{
|
||||||
|
// make a copy to avoid locking
|
||||||
|
var newServerStatus = new Dictionary<Server, ServerStatus>(_serverStatus);
|
||||||
|
|
||||||
|
foreach (var server in _controller.GetCurrentConfiguration().configs)
|
||||||
|
{
|
||||||
|
if (!newServerStatus.ContainsKey(server))
|
||||||
|
{
|
||||||
|
var status = new ServerStatus();
|
||||||
|
status.server = server;
|
||||||
|
status.lastFailure = DateTime.MinValue;
|
||||||
|
status.lastRead = DateTime.Now;
|
||||||
|
status.lastWrite = DateTime.Now;
|
||||||
|
status.latency = new TimeSpan(0, 0, 0, 0, 10);
|
||||||
|
status.lastTimeDetectLatency = DateTime.Now;
|
||||||
|
newServerStatus[server] = status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// update settings for existing server
|
||||||
|
newServerStatus[server].server = server;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_serverStatus = newServerStatus;
|
||||||
|
|
||||||
|
ChooseNewServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server GetAServer(IStrategyCallerType type, System.Net.IPEndPoint localIPEndPoint)
|
||||||
|
{
|
||||||
|
if (type == IStrategyCallerType.TCP)
|
||||||
|
{
|
||||||
|
ChooseNewServer();
|
||||||
|
}
|
||||||
|
if (_currentServer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _currentServer.server;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* once failed, try after 5 min
|
||||||
|
* and (last write - last read) < 5s
|
||||||
|
* and (now - last read) < 5s // means not stuck
|
||||||
|
* and latency < 200ms, try after 30s
|
||||||
|
*/
|
||||||
|
public void ChooseNewServer()
|
||||||
|
{
|
||||||
|
ServerStatus oldServer = _currentServer;
|
||||||
|
List<ServerStatus> servers = new List<ServerStatus>(_serverStatus.Values);
|
||||||
|
DateTime now = DateTime.Now;
|
||||||
|
foreach (var status in servers)
|
||||||
|
{
|
||||||
|
// all of failure, latency, (lastread - lastwrite) normalized to 1000, then
|
||||||
|
// 100 * failure - 2 * latency - 0.5 * (lastread - lastwrite)
|
||||||
|
status.score =
|
||||||
|
100 * 1000 * Math.Min(5 * 60, (now - status.lastFailure).TotalSeconds)
|
||||||
|
-2 * 5 * (Math.Min(2000, status.latency.TotalMilliseconds) / (1 + (now - status.lastTimeDetectLatency).TotalSeconds / 30 / 10) +
|
||||||
|
-0.5 * 200 * Math.Min(5, (status.lastRead - status.lastWrite).TotalSeconds));
|
||||||
|
Logging.Debug(String.Format("server: {0} latency:{1} score: {2}", status.server.FriendlyName(), status.latency, status.score));
|
||||||
|
}
|
||||||
|
ServerStatus max = null;
|
||||||
|
foreach (var status in servers)
|
||||||
|
{
|
||||||
|
if (max == null)
|
||||||
|
{
|
||||||
|
max = status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (status.score >= max.score)
|
||||||
|
{
|
||||||
|
max = status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (max != null)
|
||||||
|
{
|
||||||
|
if (_currentServer == null || max.score - _currentServer.score > 200)
|
||||||
|
{
|
||||||
|
_currentServer = max;
|
||||||
|
Console.WriteLine("HA switching to server: {0}", _currentServer.server.FriendlyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateLatency(Model.Server server, TimeSpan latency)
|
||||||
|
{
|
||||||
|
Logging.Debug(String.Format("latency: {0} {1}", server.FriendlyName(), latency));
|
||||||
|
|
||||||
|
ServerStatus status;
|
||||||
|
if (_serverStatus.TryGetValue(server, out status))
|
||||||
|
{
|
||||||
|
status.latency = latency;
|
||||||
|
status.lastTimeDetectLatency = DateTime.Now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateLastRead(Model.Server server)
|
||||||
|
{
|
||||||
|
Logging.Debug(String.Format("last read: {0}", server.FriendlyName()));
|
||||||
|
|
||||||
|
ServerStatus status;
|
||||||
|
if (_serverStatus.TryGetValue(server, out status))
|
||||||
|
{
|
||||||
|
status.lastRead = DateTime.Now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateLastWrite(Model.Server server)
|
||||||
|
{
|
||||||
|
Logging.Debug(String.Format("last write: {0}", server.FriendlyName()));
|
||||||
|
|
||||||
|
ServerStatus status;
|
||||||
|
if (_serverStatus.TryGetValue(server, out status))
|
||||||
|
{
|
||||||
|
status.lastWrite = DateTime.Now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFailure(Model.Server server)
|
||||||
|
{
|
||||||
|
Logging.Debug(String.Format("failure: {0}", server.FriendlyName()));
|
||||||
|
|
||||||
|
ServerStatus status;
|
||||||
|
if (_serverStatus.TryGetValue(server, out status))
|
||||||
|
{
|
||||||
|
status.lastFailure = DateTime.Now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using Shadowsocks.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Shadowsocks.Controller.Strategy
|
||||||
|
{
|
||||||
|
public enum IStrategyCallerType
|
||||||
|
{
|
||||||
|
TCP,
|
||||||
|
UDP
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IStrategy
|
||||||
|
*
|
||||||
|
* Subclasses must be thread-safe
|
||||||
|
*/
|
||||||
|
public interface IStrategy
|
||||||
|
{
|
||||||
|
string Name { get; }
|
||||||
|
|
||||||
|
string ID { get; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called when servers need to be reloaded, i.e. new configuration saved
|
||||||
|
*/
|
||||||
|
void ReloadServers();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a new server to use in TCPRelay or UDPRelay
|
||||||
|
*/
|
||||||
|
Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TCPRelay will call this when latency of a server detected
|
||||||
|
*/
|
||||||
|
void UpdateLatency(Server server, TimeSpan latency);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TCPRelay will call this when reading from a server
|
||||||
|
*/
|
||||||
|
void UpdateLastRead(Server server);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TCPRelay will call this when writing to a server
|
||||||
|
*/
|
||||||
|
void UpdateLastWrite(Server server);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TCPRelay will call this when fatal failure detected
|
||||||
|
*/
|
||||||
|
void SetFailure(Server server);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using Shadowsocks.Controller;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Shadowsocks.Controller.Strategy
|
||||||
|
{
|
||||||
|
class StrategyManager
|
||||||
|
{
|
||||||
|
List<IStrategy> _strategies;
|
||||||
|
public StrategyManager(ShadowsocksController controller)
|
||||||
|
{
|
||||||
|
_strategies = new List<IStrategy>();
|
||||||
|
_strategies.Add(new BalancingStrategy(controller));
|
||||||
|
_strategies.Add(new HighAvailabilityStrategy(controller));
|
||||||
|
// TODO: load DLL plugins
|
||||||
|
}
|
||||||
|
public IList<IStrategy> GetStrategies()
|
||||||
|
{
|
||||||
|
return _strategies;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable → Regular
@@ -23,6 +23,8 @@ Show Logs...=显示日志...
|
|||||||
About...=关于...
|
About...=关于...
|
||||||
Quit=退出
|
Quit=退出
|
||||||
Edit Servers=编辑服务器
|
Edit Servers=编辑服务器
|
||||||
|
Load Balance=负载均衡
|
||||||
|
High Availability=高可用
|
||||||
|
|
||||||
# Config Form
|
# Config Form
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ namespace Shadowsocks.Model
|
|||||||
public class Configuration
|
public class Configuration
|
||||||
{
|
{
|
||||||
public List<Server> configs;
|
public List<Server> configs;
|
||||||
|
|
||||||
|
// when strategy is set, index is ignored
|
||||||
|
public string strategy;
|
||||||
public int index;
|
public int index;
|
||||||
public bool global;
|
public bool global;
|
||||||
public bool enabled;
|
public bool enabled;
|
||||||
@@ -52,6 +55,13 @@ namespace Shadowsocks.Model
|
|||||||
{
|
{
|
||||||
config.localPort = 1080;
|
config.localPort = 1080;
|
||||||
}
|
}
|
||||||
|
if (config.index == -1)
|
||||||
|
{
|
||||||
|
if (config.strategy == null)
|
||||||
|
{
|
||||||
|
config.index = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -79,9 +89,16 @@ namespace Shadowsocks.Model
|
|||||||
{
|
{
|
||||||
config.index = config.configs.Count - 1;
|
config.index = config.configs.Count - 1;
|
||||||
}
|
}
|
||||||
if (config.index < 0)
|
if (config.index < -1)
|
||||||
{
|
{
|
||||||
config.index = 0;
|
config.index = -1;
|
||||||
|
}
|
||||||
|
if (config.index == -1)
|
||||||
|
{
|
||||||
|
if (config.strategy == null)
|
||||||
|
{
|
||||||
|
config.index = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
config.isDefault = false;
|
config.isDefault = false;
|
||||||
try
|
try
|
||||||
@@ -118,6 +135,11 @@ namespace Shadowsocks.Model
|
|||||||
{
|
{
|
||||||
throw new ArgumentException(I18N.GetString("Port out of range"));
|
throw new ArgumentException(I18N.GetString("Port out of range"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CheckLocalPort(int port)
|
||||||
|
{
|
||||||
|
CheckPort(port);
|
||||||
if (port == 8123)
|
if (port == 8123)
|
||||||
{
|
{
|
||||||
throw new ArgumentException(I18N.GetString("Port can't be 8123"));
|
throw new ArgumentException(I18N.GetString("Port can't be 8123"));
|
||||||
|
|||||||
@@ -18,6 +18,17 @@ namespace Shadowsocks.Model
|
|||||||
public string method;
|
public string method;
|
||||||
public string remarks;
|
public string remarks;
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return server.GetHashCode() ^ server_port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
Server o2 = (Server)obj;
|
||||||
|
return this.server == o2.server && this.server_port == o2.server_port;
|
||||||
|
}
|
||||||
|
|
||||||
public string FriendlyName()
|
public string FriendlyName()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(server))
|
if (string.IsNullOrEmpty(server))
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.34209
|
// Runtime Version:4.0.30319.42000
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ namespace Shadowsocks.View
|
|||||||
};
|
};
|
||||||
int localPort = int.Parse(ProxyPortTextBox.Text);
|
int localPort = int.Parse(ProxyPortTextBox.Text);
|
||||||
Configuration.CheckServer(server);
|
Configuration.CheckServer(server);
|
||||||
Configuration.CheckPort(localPort);
|
Configuration.CheckLocalPort(localPort);
|
||||||
_modifiedConfiguration.configs[_oldSelectedIndex] = server;
|
_modifiedConfiguration.configs[_oldSelectedIndex] = server;
|
||||||
_modifiedConfiguration.localPort = localPort;
|
_modifiedConfiguration.localPort = localPort;
|
||||||
|
|
||||||
@@ -133,10 +133,14 @@ namespace Shadowsocks.View
|
|||||||
|
|
||||||
private void LoadCurrentConfiguration()
|
private void LoadCurrentConfiguration()
|
||||||
{
|
{
|
||||||
_modifiedConfiguration = controller.GetConfiguration();
|
_modifiedConfiguration = controller.GetConfigurationCopy();
|
||||||
LoadConfiguration(_modifiedConfiguration);
|
LoadConfiguration(_modifiedConfiguration);
|
||||||
_oldSelectedIndex = _modifiedConfiguration.index;
|
_oldSelectedIndex = _modifiedConfiguration.index;
|
||||||
ServersListBox.SelectedIndex = _modifiedConfiguration.index;
|
if (_oldSelectedIndex < 0)
|
||||||
|
{
|
||||||
|
_oldSelectedIndex = 0;
|
||||||
|
}
|
||||||
|
ServersListBox.SelectedIndex = _oldSelectedIndex;
|
||||||
LoadSelectedServer();
|
LoadSelectedServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
namespace Shadowsocks.View
|
||||||
|
{
|
||||||
|
partial class LogForm
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.components = new System.ComponentModel.Container();
|
||||||
|
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||||
|
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||||
|
this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
|
||||||
|
this.menuItem1 = new System.Windows.Forms.MenuItem();
|
||||||
|
this.menuItem2 = new System.Windows.Forms.MenuItem();
|
||||||
|
this.menuItem4 = new System.Windows.Forms.MenuItem();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// textBox1
|
||||||
|
//
|
||||||
|
this.textBox1.BackColor = System.Drawing.Color.Black;
|
||||||
|
this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.textBox1.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
|
this.textBox1.ForeColor = System.Drawing.Color.White;
|
||||||
|
this.textBox1.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.textBox1.MaxLength = 2147483647;
|
||||||
|
this.textBox1.Multiline = true;
|
||||||
|
this.textBox1.Name = "textBox1";
|
||||||
|
this.textBox1.ReadOnly = true;
|
||||||
|
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||||
|
this.textBox1.Size = new System.Drawing.Size(547, 382);
|
||||||
|
this.textBox1.TabIndex = 0;
|
||||||
|
this.textBox1.WordWrap = false;
|
||||||
|
//
|
||||||
|
// contextMenuStrip1
|
||||||
|
//
|
||||||
|
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||||
|
this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
|
||||||
|
//
|
||||||
|
// mainMenu1
|
||||||
|
//
|
||||||
|
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||||||
|
this.menuItem1});
|
||||||
|
//
|
||||||
|
// menuItem1
|
||||||
|
//
|
||||||
|
this.menuItem1.Index = 0;
|
||||||
|
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||||||
|
this.menuItem2,
|
||||||
|
this.menuItem4});
|
||||||
|
this.menuItem1.Text = "&File";
|
||||||
|
//
|
||||||
|
// menuItem2
|
||||||
|
//
|
||||||
|
this.menuItem2.Index = 0;
|
||||||
|
this.menuItem2.Text = "&Open Location";
|
||||||
|
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
|
||||||
|
//
|
||||||
|
// menuItem4
|
||||||
|
//
|
||||||
|
this.menuItem4.Index = 1;
|
||||||
|
this.menuItem4.Text = "E&xit";
|
||||||
|
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
|
||||||
|
//
|
||||||
|
// LogForm
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(547, 382);
|
||||||
|
this.Controls.Add(this.textBox1);
|
||||||
|
this.Menu = this.mainMenu1;
|
||||||
|
this.Name = "LogForm";
|
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
|
this.Text = "Log Viewer";
|
||||||
|
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.LogForm_FormClosing);
|
||||||
|
this.Load += new System.EventHandler(this.LogForm_Load);
|
||||||
|
this.Shown += new System.EventHandler(this.LogForm_Shown);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.TextBox textBox1;
|
||||||
|
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
|
||||||
|
private System.Windows.Forms.MainMenu mainMenu1;
|
||||||
|
private System.Windows.Forms.MenuItem menuItem1;
|
||||||
|
private System.Windows.Forms.MenuItem menuItem2;
|
||||||
|
private System.Windows.Forms.MenuItem menuItem4;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
using Shadowsocks.Properties;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Shadowsocks.View
|
||||||
|
{
|
||||||
|
public partial class LogForm : Form
|
||||||
|
{
|
||||||
|
FileSystemWatcher watcher;
|
||||||
|
long lastOffset;
|
||||||
|
string filename;
|
||||||
|
Timer timer;
|
||||||
|
const int BACK_OFFSET = 65536;
|
||||||
|
|
||||||
|
public LogForm(string filename)
|
||||||
|
{
|
||||||
|
this.filename = filename;
|
||||||
|
InitializeComponent();
|
||||||
|
this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Timer_Tick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
UpdateContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitContent()
|
||||||
|
{
|
||||||
|
using (StreamReader reader = new StreamReader(new FileStream(filename,
|
||||||
|
FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
|
||||||
|
{
|
||||||
|
if (reader.BaseStream.Length > BACK_OFFSET)
|
||||||
|
{
|
||||||
|
reader.BaseStream.Seek(-BACK_OFFSET, SeekOrigin.End);
|
||||||
|
reader.ReadLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
string line = "";
|
||||||
|
while ((line = reader.ReadLine()) != null)
|
||||||
|
textBox1.AppendText(line + "\r\n");
|
||||||
|
|
||||||
|
textBox1.ScrollToCaret();
|
||||||
|
|
||||||
|
lastOffset = reader.BaseStream.Position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateContent()
|
||||||
|
{
|
||||||
|
using (StreamReader reader = new StreamReader(new FileStream(filename,
|
||||||
|
FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
|
||||||
|
{
|
||||||
|
reader.BaseStream.Seek(lastOffset, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
string line = "";
|
||||||
|
bool changed = false;
|
||||||
|
while ((line = reader.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
textBox1.AppendText(line + "\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
textBox1.ScrollToCaret();
|
||||||
|
}
|
||||||
|
|
||||||
|
lastOffset = reader.BaseStream.Position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LogForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
InitContent();
|
||||||
|
timer = new Timer();
|
||||||
|
timer.Interval = 300;
|
||||||
|
timer.Tick += Timer_Tick;
|
||||||
|
timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LogForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
timer.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void menuItem2_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
string argument = @"/select, " + filename;
|
||||||
|
System.Diagnostics.Process.Start("explorer.exe", argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void menuItem3_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void menuItem4_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LogForm_Shown(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
textBox1.ScrollToCaret();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="mainMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>172, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
||||||
@@ -71,9 +71,9 @@ namespace Shadowsocks.View
|
|||||||
|
|
||||||
LoadCurrentConfiguration();
|
LoadCurrentConfiguration();
|
||||||
|
|
||||||
updateChecker.CheckUpdate(controller.GetConfiguration());
|
updateChecker.CheckUpdate(controller.GetConfigurationCopy());
|
||||||
|
|
||||||
if (controller.GetConfiguration().isDefault)
|
if (controller.GetConfigurationCopy().isDefault)
|
||||||
{
|
{
|
||||||
_isFirstRun = true;
|
_isFirstRun = true;
|
||||||
ShowConfigForm();
|
ShowConfigForm();
|
||||||
@@ -106,7 +106,7 @@ namespace Shadowsocks.View
|
|||||||
{
|
{
|
||||||
icon = Resources.ss24;
|
icon = Resources.ss24;
|
||||||
}
|
}
|
||||||
Configuration config = controller.GetConfiguration();
|
Configuration config = controller.GetConfigurationCopy();
|
||||||
bool enabled = config.enabled;
|
bool enabled = config.enabled;
|
||||||
bool global = config.global;
|
bool global = config.global;
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
@@ -124,12 +124,21 @@ namespace Shadowsocks.View
|
|||||||
}
|
}
|
||||||
_notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());
|
_notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());
|
||||||
|
|
||||||
|
string serverInfo = null;
|
||||||
|
if (controller.GetCurrentStrategy() != null)
|
||||||
|
{
|
||||||
|
serverInfo = controller.GetCurrentStrategy().Name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serverInfo = config.GetCurrentServer().FriendlyName();
|
||||||
|
}
|
||||||
// we want to show more details but notify icon title is limited to 63 characters
|
// we want to show more details but notify icon title is limited to 63 characters
|
||||||
string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" +
|
string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" +
|
||||||
(enabled ?
|
(enabled ?
|
||||||
I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) :
|
I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) :
|
||||||
String.Format(I18N.GetString("Running: Port {0}"), config.localPort)) // this feedback is very important because they need to know Shadowsocks is running
|
String.Format(I18N.GetString("Running: Port {0}"), config.localPort)) // this feedback is very important because they need to know Shadowsocks is running
|
||||||
+ "\n" + config.GetCurrentServer().FriendlyName();
|
+ "\n" + serverInfo;
|
||||||
_notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
|
_notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,18 +194,18 @@ namespace Shadowsocks.View
|
|||||||
|
|
||||||
private void controller_EnableStatusChanged(object sender, EventArgs e)
|
private void controller_EnableStatusChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
enableItem.Checked = controller.GetConfiguration().enabled;
|
enableItem.Checked = controller.GetConfigurationCopy().enabled;
|
||||||
modeItem.Enabled = enableItem.Checked;
|
modeItem.Enabled = enableItem.Checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
void controller_ShareOverLANStatusChanged(object sender, EventArgs e)
|
void controller_ShareOverLANStatusChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ShareOverLANItem.Checked = controller.GetConfiguration().shareOverLan;
|
ShareOverLANItem.Checked = controller.GetConfigurationCopy().shareOverLan;
|
||||||
}
|
}
|
||||||
|
|
||||||
void controller_EnableGlobalChanged(object sender, EventArgs e)
|
void controller_EnableGlobalChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
globalModeItem.Checked = controller.GetConfiguration().global;
|
globalModeItem.Checked = controller.GetConfigurationCopy().global;
|
||||||
PACModeItem.Checked = !globalModeItem.Checked;
|
PACModeItem.Checked = !globalModeItem.Checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +252,7 @@ namespace Shadowsocks.View
|
|||||||
|
|
||||||
private void LoadCurrentConfiguration()
|
private void LoadCurrentConfiguration()
|
||||||
{
|
{
|
||||||
Configuration config = controller.GetConfiguration();
|
Configuration config = controller.GetConfigurationCopy();
|
||||||
UpdateServersMenu();
|
UpdateServersMenu();
|
||||||
enableItem.Checked = config.enabled;
|
enableItem.Checked = config.enabled;
|
||||||
modeItem.Enabled = config.enabled;
|
modeItem.Enabled = config.enabled;
|
||||||
@@ -263,20 +272,33 @@ namespace Shadowsocks.View
|
|||||||
{
|
{
|
||||||
items.RemoveAt(0);
|
items.RemoveAt(0);
|
||||||
}
|
}
|
||||||
|
int i = 0;
|
||||||
Configuration configuration = controller.GetConfiguration();
|
foreach (var strategy in controller.GetStrategies())
|
||||||
for (int i = 0; i < configuration.configs.Count; i++)
|
{
|
||||||
|
MenuItem item = new MenuItem(strategy.Name);
|
||||||
|
item.Tag = strategy.ID;
|
||||||
|
item.Click += AStrategyItem_Click;
|
||||||
|
items.Add(i, item);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
int strategyCount = i;
|
||||||
|
Configuration configuration = controller.GetConfigurationCopy();
|
||||||
|
foreach (var server in configuration.configs)
|
||||||
{
|
{
|
||||||
Server server = configuration.configs[i];
|
|
||||||
MenuItem item = new MenuItem(server.FriendlyName());
|
MenuItem item = new MenuItem(server.FriendlyName());
|
||||||
item.Tag = i;
|
item.Tag = i - strategyCount;
|
||||||
item.Click += AServerItem_Click;
|
item.Click += AServerItem_Click;
|
||||||
items.Add(i, item);
|
items.Add(i, item);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configuration.index >= 0 && configuration.index < configuration.configs.Count)
|
foreach (MenuItem item in items)
|
||||||
{
|
{
|
||||||
items[configuration.index].Checked = true;
|
if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
|
||||||
|
{
|
||||||
|
item.Checked = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,11 +402,17 @@ namespace Shadowsocks.View
|
|||||||
controller.SelectServerIndex((int)item.Tag);
|
controller.SelectServerIndex((int)item.Tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AStrategyItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
MenuItem item = (MenuItem)sender;
|
||||||
|
controller.SelectStrategy((string)item.Tag);
|
||||||
|
}
|
||||||
|
|
||||||
private void ShowLogItem_Click(object sender, EventArgs e)
|
private void ShowLogItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string argument = Logging.LogFile;
|
string argument = Logging.LogFile;
|
||||||
|
|
||||||
System.Diagnostics.Process.Start("notepad.exe", argument);
|
new LogForm(argument).Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void QRCodeItem_Click(object sender, EventArgs e)
|
private void QRCodeItem_Click(object sender, EventArgs e)
|
||||||
@@ -511,11 +539,11 @@ namespace Shadowsocks.View
|
|||||||
{
|
{
|
||||||
if (!onlinePACItem.Checked)
|
if (!onlinePACItem.Checked)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(controller.GetConfiguration().pacUrl))
|
if (String.IsNullOrEmpty(controller.GetConfigurationCopy().pacUrl))
|
||||||
{
|
{
|
||||||
UpdateOnlinePACURLItem_Click(sender, e);
|
UpdateOnlinePACURLItem_Click(sender, e);
|
||||||
}
|
}
|
||||||
if (!String.IsNullOrEmpty(controller.GetConfiguration().pacUrl))
|
if (!String.IsNullOrEmpty(controller.GetConfigurationCopy().pacUrl))
|
||||||
{
|
{
|
||||||
localPACItem.Checked = false;
|
localPACItem.Checked = false;
|
||||||
onlinePACItem.Checked = true;
|
onlinePACItem.Checked = true;
|
||||||
@@ -527,7 +555,7 @@ namespace Shadowsocks.View
|
|||||||
|
|
||||||
private void UpdateOnlinePACURLItem_Click(object sender, EventArgs e)
|
private void UpdateOnlinePACURLItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string origPacUrl = controller.GetConfiguration().pacUrl;
|
string origPacUrl = controller.GetConfigurationCopy().pacUrl;
|
||||||
string pacUrl = Microsoft.VisualBasic.Interaction.InputBox(
|
string pacUrl = Microsoft.VisualBasic.Interaction.InputBox(
|
||||||
I18N.GetString("Please input PAC Url"),
|
I18N.GetString("Please input PAC Url"),
|
||||||
I18N.GetString("Edit Online PAC URL"),
|
I18N.GetString("Edit Online PAC URL"),
|
||||||
|
|||||||
Executable → Regular
+26
-14
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>Shadowsocks</RootNamespace>
|
<RootNamespace>Shadowsocks</RootNamespace>
|
||||||
<AssemblyName>Shadowsocks</AssemblyName>
|
<AssemblyName>Shadowsocks</AssemblyName>
|
||||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<StartupObject>
|
<StartupObject>
|
||||||
</StartupObject>
|
</StartupObject>
|
||||||
@@ -21,8 +21,7 @@
|
|||||||
<UpgradeBackupLocation>
|
<UpgradeBackupLocation>
|
||||||
</UpgradeBackupLocation>
|
</UpgradeBackupLocation>
|
||||||
<OldToolsVersion>3.5</OldToolsVersion>
|
<OldToolsVersion>3.5</OldToolsVersion>
|
||||||
<TargetFrameworkProfile>
|
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||||
</TargetFrameworkProfile>
|
|
||||||
<PublishUrl>publish\</PublishUrl>
|
<PublishUrl>publish\</PublishUrl>
|
||||||
<Install>true</Install>
|
<Install>true</Install>
|
||||||
<InstallFrom>Disk</InstallFrom>
|
<InstallFrom>Disk</InstallFrom>
|
||||||
@@ -124,15 +123,16 @@
|
|||||||
<Compile Include="3rd\zxing\ResultPoint.cs" />
|
<Compile Include="3rd\zxing\ResultPoint.cs" />
|
||||||
<Compile Include="3rd\zxing\ResultPointCallback.cs" />
|
<Compile Include="3rd\zxing\ResultPointCallback.cs" />
|
||||||
<Compile Include="3rd\zxing\WriterException.cs" />
|
<Compile Include="3rd\zxing\WriterException.cs" />
|
||||||
<Compile Include="Controller\AutoStartup.cs" />
|
<Compile Include="Controller\Strategy\HighAvailabilityStrategy.cs" />
|
||||||
|
<Compile Include="Controller\System\AutoStartup.cs" />
|
||||||
<Compile Include="Controller\FileManager.cs" />
|
<Compile Include="Controller\FileManager.cs" />
|
||||||
<Compile Include="Controller\GFWListUpdater.cs" />
|
<Compile Include="Controller\Service\GFWListUpdater.cs" />
|
||||||
<Compile Include="Controller\I18N.cs" />
|
<Compile Include="Controller\I18N.cs" />
|
||||||
<Compile Include="Controller\Listener.cs" />
|
<Compile Include="Controller\Service\Listener.cs" />
|
||||||
<Compile Include="Controller\Logging.cs" />
|
<Compile Include="Controller\Logging.cs" />
|
||||||
<Compile Include="Controller\PortForwarder.cs" />
|
<Compile Include="Controller\Service\PortForwarder.cs" />
|
||||||
<Compile Include="Controller\UDPRelay.cs" />
|
<Compile Include="Controller\Service\UDPRelay.cs" />
|
||||||
<Compile Include="Controller\UpdateChecker.cs" />
|
<Compile Include="Controller\Service\UpdateChecker.cs" />
|
||||||
<Compile Include="Encryption\EncryptorBase.cs" />
|
<Compile Include="Encryption\EncryptorBase.cs" />
|
||||||
<Compile Include="Encryption\EncryptorFactory.cs" />
|
<Compile Include="Encryption\EncryptorFactory.cs" />
|
||||||
<Compile Include="Encryption\IVEncryptor.cs" />
|
<Compile Include="Encryption\IVEncryptor.cs" />
|
||||||
@@ -142,7 +142,7 @@
|
|||||||
<Compile Include="Encryption\SodiumEncryptor.cs" />
|
<Compile Include="Encryption\SodiumEncryptor.cs" />
|
||||||
<Compile Include="Encryption\TableEncryptor.cs" />
|
<Compile Include="Encryption\TableEncryptor.cs" />
|
||||||
<Compile Include="Encryption\IEncryptor.cs" />
|
<Compile Include="Encryption\IEncryptor.cs" />
|
||||||
<Compile Include="Controller\PACServer.cs" />
|
<Compile Include="Controller\Service\PACServer.cs" />
|
||||||
<Compile Include="Model\Server.cs" />
|
<Compile Include="Model\Server.cs" />
|
||||||
<Compile Include="Model\Configuration.cs" />
|
<Compile Include="Model\Configuration.cs" />
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
@@ -150,6 +150,9 @@
|
|||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Controller\Strategy\BalancingStrategy.cs" />
|
||||||
|
<Compile Include="Controller\Strategy\StrategyManager.cs" />
|
||||||
|
<Compile Include="Controller\Strategy\IStrategy.cs" />
|
||||||
<Compile Include="Util\Util.cs" />
|
<Compile Include="Util\Util.cs" />
|
||||||
<Compile Include="View\ConfigForm.cs">
|
<Compile Include="View\ConfigForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
@@ -157,12 +160,18 @@
|
|||||||
<Compile Include="View\ConfigForm.Designer.cs">
|
<Compile Include="View\ConfigForm.Designer.cs">
|
||||||
<DependentUpon>ConfigForm.cs</DependentUpon>
|
<DependentUpon>ConfigForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Controller\TCPRelay.cs" />
|
<Compile Include="Controller\Service\TCPRelay.cs" />
|
||||||
<Compile Include="Controller\PolipoRunner.cs" />
|
<Compile Include="Controller\Service\PolipoRunner.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Controller\ShadowsocksController.cs" />
|
<Compile Include="Controller\ShadowsocksController.cs" />
|
||||||
<Compile Include="Controller\SystemProxy.cs" />
|
<Compile Include="Controller\System\SystemProxy.cs" />
|
||||||
|
<Compile Include="View\LogForm.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="View\LogForm.Designer.cs">
|
||||||
|
<DependentUpon>LogForm.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="View\MenuViewController.cs" />
|
<Compile Include="View\MenuViewController.cs" />
|
||||||
<Compile Include="View\QRCodeForm.cs">
|
<Compile Include="View\QRCodeForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
@@ -182,6 +191,9 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="View\LogForm.resx">
|
||||||
|
<DependentUpon>LogForm.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="View\QRCodeForm.resx">
|
<EmbeddedResource Include="View\QRCodeForm.resx">
|
||||||
<DependentUpon>QRCodeForm.cs</DependentUpon>
|
<DependentUpon>QRCodeForm.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
|||||||
Reference in New Issue
Block a user