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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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
  21. {
  22. return "Load Balance";
  23. }
  24. }
  25. public string ID
  26. {
  27. get
  28. {
  29. return "com.shadowsocks.strategy.balancing";
  30. }
  31. }
  32. public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint)
  33. {
  34. var configs = _controller.GetCurrentConfiguration().configs;
  35. int index;
  36. if (type == IStrategyCallerType.TCP)
  37. {
  38. index = _random.Next();
  39. }
  40. else
  41. {
  42. index = localIPEndPoint.GetHashCode();
  43. }
  44. return configs[index % configs.Count];
  45. }
  46. public void UpdateLatency(Model.Server server)
  47. {
  48. // do nothing
  49. }
  50. public void UpdateLastRead(Model.Server server)
  51. {
  52. // do nothing
  53. }
  54. public void UpdateLastWrite(Model.Server server)
  55. {
  56. // do nothing
  57. }
  58. public void SetFailure(Model.Server server)
  59. {
  60. // do nothing
  61. }
  62. }
  63. }