You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

BalancingStrategy.cs 1.7 kB

10 years ago
10 years ago
10 years ago
10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Shadowsocks.Controller;
  2. using Shadowsocks.Model;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Net;
  6. using System.Text;
  7. namespace Shadowsocks.Controller.Strategy
  8. {
  9. class BalancingStrategy : IStrategy
  10. {
  11. ShadowsocksController _controller;
  12. Random _random;
  13. public BalancingStrategy(ShadowsocksController controller)
  14. {
  15. _controller = controller;
  16. _random = new Random();
  17. }
  18. public string Name
  19. {
  20. get { return I18N.GetString("Load Balance"); }
  21. }
  22. public string ID
  23. {
  24. get { return "com.shadowsocks.strategy.balancing"; }
  25. }
  26. public void ReloadServers()
  27. {
  28. // do nothing
  29. }
  30. public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint)
  31. {
  32. var configs = _controller.GetCurrentConfiguration().configs;
  33. int index;
  34. if (type == IStrategyCallerType.TCP)
  35. {
  36. index = _random.Next();
  37. }
  38. else
  39. {
  40. index = localIPEndPoint.GetHashCode();
  41. }
  42. return configs[index % configs.Count];
  43. }
  44. public void UpdateLatency(Model.Server server, TimeSpan latency)
  45. {
  46. // do nothing
  47. }
  48. public void UpdateLastRead(Model.Server server)
  49. {
  50. // do nothing
  51. }
  52. public void UpdateLastWrite(Model.Server server)
  53. {
  54. // do nothing
  55. }
  56. public void SetFailure(Model.Server server)
  57. {
  58. // do nothing
  59. }
  60. }
  61. }