add load balancing
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
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 "Load Balance";
|
||||
}
|
||||
}
|
||||
|
||||
public string ID
|
||||
{
|
||||
get
|
||||
{
|
||||
return "com.shadowsocks.strategy.balancing";
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user