本文整理汇总了C#中Shadowsocks.Model.Server类的典型用法代码示例。如果您正苦于以下问题:C# Server类的具体用法?C# Server怎么用?C# Server使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Server类属于Shadowsocks.Model命名空间,在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckServer
public static void CheckServer(Server server)
{
CheckPort(server.server_port);
CheckPassword(server.password);
CheckServer(server.server);
CheckTimeout(server.timeout, Server.MaxServerTimeoutSec);
}
示例2: SaveOldSelectedServer
private bool SaveOldSelectedServer()
{
try
{
if (_lastSelectedIndex == -1 || _lastSelectedIndex >= _modifiedConfiguration.configs.Count)
{
return true;
}
Server server = new Server
{
server = IPTextBox.Text,
server_port = int.Parse(ServerPortTextBox.Text),
password = PasswordTextBox.Text,
method = EncryptionSelect.Text,
remarks = RemarksTextBox.Text
};
int localPort = int.Parse(ProxyPortTextBox.Text);
Configuration.CheckServer(server);
Configuration.CheckLocalPort(localPort);
_modifiedConfiguration.configs[_lastSelectedIndex] = server;
_modifiedConfiguration.localPort = localPort;
return true;
}
catch (FormatException)
{
MessageBox.Show(I18N.GetString("Illegal port number format"));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return false;
}
示例3: StatisticsStrategy
public StatisticsStrategy(ShadowsocksController controller)
{
_controller = controller;
var servers = controller.GetCurrentConfiguration().configs;
var randomIndex = new Random().Next() % servers.Count();
_currentServer = servers[randomIndex]; //choose a server randomly at first
_timer = new Timer(ReloadStatisticsAndChooseAServer);
}
示例4: AddServerBySSURL
public bool AddServerBySSURL(string ssURL)
{
try
{
var server = new Server(ssURL);
_config.configs.Add(server);
_config.index = _config.configs.Count - 1;
SaveConfig(_config);
return true;
}
catch (Exception e)
{
Logging.LogUsefulException(e);
return false;
}
}
示例5: ChooseNewServer
/**
* 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()
{
Server 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)
{
_currentServer = max.server;
if (_currentServer != oldServer)
{
Console.WriteLine("HA switching to server: {0}", _currentServer.FriendlyName());
}
Logging.Debug(String.Format("choosing server: {0}", _currentServer.FriendlyName()));
}
}
示例6: ConnectCallback
private void ConnectCallback(IAsyncResult ar)
{
Server server = null;
if (closed)
{
return;
}
try
{
ServerTimer timer = (ServerTimer)ar.AsyncState;
server = timer.Server;
timer.Elapsed -= connectTimer_Elapsed;
timer.Enabled = false;
timer.Dispose();
// Complete the connection.
remote.EndConnect(ar);
connected = true;
Logging.Debug($"Socket connected to {remote.RemoteEndPoint}");
var latency = DateTime.Now - _startConnectTime;
IStrategy strategy = controller.GetCurrentStrategy();
strategy?.UpdateLatency(server, latency);
tcprelay.UpdateLatency(server, latency);
StartPipe();
}
catch (ArgumentException)
{
}
catch (Exception e)
{
if (server != null)
{
IStrategy strategy = controller.GetCurrentStrategy();
if (strategy != null)
{
strategy.SetFailure(server);
}
}
Logging.LogUsefulException(e);
RetryConnect();
}
}
示例7: UpdateOutboundCounter
public void UpdateOutboundCounter(Server server, long n)
{
_controller.UpdateOutboundCounter(server, n);
}
示例8: UpdateLatency
public void UpdateLatency(Server server, int latency)
{
List<int> records;
_latencyRecords.TryGetValue(server.Identifier(), out records);
if (records == null)
{
records = new List<int>();
}
records.Add(latency);
_latencyRecords[server.Identifier()] = records;
}
示例9: CreateRemote
public void CreateRemote()
{
Server server = controller.GetAServer(IStrategyCallerType.TCP, (IPEndPoint)connection.RemoteEndPoint);
if (server == null || server.server == "")
{
throw new ArgumentException("No server configured");
}
encryptor = EncryptorFactory.GetEncryptor(server.method, server.password, server.auth, false);
this.server = server;
}
示例10: Clone
public Server Clone()
{
Server ret = new Server();
ret.server = (string)server.Clone();
ret.server_port = server_port;
ret.password = (string)password.Clone();
ret.method = (string)method.Clone();
ret.obfs = (string)obfs.Clone();
ret.remarks = (string)remarks.Clone();
ret.enable = enable;
ret.udp_over_tcp = udp_over_tcp;
ret.tcp_protocol = tcp_protocol;
ret.obfs_udp = obfs_udp;
return ret;
}
示例11: GetSSRemarksLinkForServer
public string GetSSRemarksLinkForServer(Server server)
{
string parts = server.method + ":" + server.password + "@" + server.server + ":" + server.server_port + "#" + server.remarks;
string base64 = System.Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
return "ss://" + base64;
}
示例12: GetSSLinkForServer
public string GetSSLinkForServer(Server server)
{
string parts = server.method + ":" + server.password + "@" + server.server + ":" + server.server_port;
if (server.obfs != "plain")
parts = server.obfs + ":" + parts;
string base64 = System.Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
return "ss://" + base64;
}
示例13: ReConnect
public void ReConnect()
{
ResetTimeout(0);
reconnectTimesRemain--;
reconnectTimes++;
lock (server)
{
server.ServerSpeedLog().AddDisconnectTimes();
server.GetConnections().DecRef(this.connection);
}
if (reconnectTimes < 2)
{
server = this.getCurrentServer(true);
}
else
{
server = this.getCurrentServer(true, true);
}
CloseSocket(ref remote);
CloseSocket(ref remoteUDP);
if (remoteTDP != null)
{
try
{
remoteTDP.Shutdown();
//remoteTDP.Close();
}
catch (Exception e)
{
Logging.LogUsefulException(e);
}
remoteTDP = null;
}
if (obfs != null)
{
obfs.Dispose();
obfs = null;
}
connectionShutdown = false;
remoteShutdown = false;
speedTester.sizeUpload = 0;
speedTester.sizeDownload = 0;
lastErrCode = 0;
obfs = ObfsFactory.GetObfs(server.obfs);
try
{
Connect();
}
catch (Exception e)
{
LogSocketException(e);
if (!Logging.LogSocketException(server.remarks, server.server, e))
Logging.LogUsefulException(e);
this.Close();
}
}
示例14: UpdateLatency
public void UpdateLatency(Server server, TimeSpan latency)
{
if (_config.availabilityStatistics)
{
new Task(() => availabilityStatistics.UpdateLatency(server, (int) latency.TotalMilliseconds)).Start();
}
}
示例15: UpdateOutboundCounter
public void UpdateOutboundCounter(Server server, long n)
{
Interlocked.Add(ref outboundCounter, n);
if (_config.availabilityStatistics)
{
new Task(() => availabilityStatistics.UpdateOutboundCounter(server, n)).Start();
}
}