fix a crash

This commit is contained in:
clowwindy
2015-07-25 19:05:37 +08:00
parent 008e3544f2
commit dafe33f7ed
4 changed files with 40 additions and 8 deletions
@@ -82,7 +82,7 @@ namespace Shadowsocks.Controller
public void CreateRemote()
{
Server server = controller.GetCurrentStrategy().GetAServer(IStrategyCallerType.TCP, (IPEndPoint)connection.RemoteEndPoint);
Server server = controller.GetAServer(IStrategyCallerType.TCP, (IPEndPoint)connection.RemoteEndPoint);
this.encryptor = EncryptorFactory.GetEncryptor(server.method, server.password);
this.server = server;
}
@@ -373,7 +373,11 @@ namespace Shadowsocks.Controller
return;
}
Server server = ((ServerTimer)sender).Server;
controller.GetCurrentStrategy().SetFailure(server);
IStrategy strategy = controller.GetCurrentStrategy();
if (strategy != null)
{
strategy.SetFailure(server);
}
Console.WriteLine(String.Format("{0} timed out", server.FriendlyName()));
remote.Close();
RetryConnect();
@@ -417,7 +421,11 @@ namespace Shadowsocks.Controller
// remote.RemoteEndPoint.ToString());
var latency = DateTime.Now - _startConnectTime;
controller.GetCurrentStrategy().UpdateLatency(server, latency);
IStrategy strategy = controller.GetCurrentStrategy();
if (strategy != null)
{
strategy.UpdateLatency(server, latency);
}
StartPipe();
}
@@ -428,7 +436,11 @@ namespace Shadowsocks.Controller
{
if (server != null)
{
controller.GetCurrentStrategy().SetFailure(server);
IStrategy strategy = controller.GetCurrentStrategy();
if (strategy != null)
{
strategy.SetFailure(server);
}
}
Logging.LogUsefulException(e);
RetryConnect();
@@ -479,7 +491,11 @@ namespace Shadowsocks.Controller
}
connection.BeginSend(remoteSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeConnectionSendCallback), null);
controller.GetCurrentStrategy().UpdateLastRead(this.server);
IStrategy strategy = controller.GetCurrentStrategy();
if (strategy != null)
{
strategy.UpdateLastRead(this.server);
}
}
else
{
@@ -527,7 +543,12 @@ namespace Shadowsocks.Controller
}
remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null);
controller.GetCurrentStrategy().UpdateLastWrite(this.server);
IStrategy strategy = controller.GetCurrentStrategy();
if (strategy != null)
{
strategy.UpdateLastWrite(this.server);
}
}
else
{
@@ -35,7 +35,7 @@ namespace Shadowsocks.Controller
UDPHandler handler = _cache.get(remoteEndPoint);
if (handler == null)
{
handler = new UDPHandler(socket, _controller.GetCurrentStrategy().GetAServer(IStrategyCallerType.UDP, remoteEndPoint), remoteEndPoint);
handler = new UDPHandler(socket, _controller.GetAServer(IStrategyCallerType.UDP, remoteEndPoint), remoteEndPoint);
_cache.add(remoteEndPoint, handler);
}
handler.Send(firstPacket, length);
@@ -6,6 +6,7 @@ using System.Text;
using System.Threading;
using System.Net.Sockets;
using Shadowsocks.Controller.Strategy;
using System.Net;
namespace Shadowsocks.Controller
{
@@ -101,6 +102,16 @@ namespace Shadowsocks.Controller
return null;
}
public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint)
{
IStrategy strategy = GetCurrentStrategy();
if (strategy != null)
{
return strategy.GetAServer(type, localIPEndPoint);
}
return GetCurrentServer();
}
public void SaveServers(List<Server> servers, int localPort)
{
_config.configs = servers;
@@ -125,7 +125,7 @@ namespace Shadowsocks.View
_notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());
string serverInfo = null;
if (config.strategy != null)
if (controller.GetCurrentStrategy() != null)
{
serverInfo = controller.GetCurrentStrategy().Name;
}