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.

Legacy.cs 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Shadowsocks.Models;
  2. using Shadowsocks.Net;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace Shadowsocks.CLI.Client
  11. {
  12. public class Legacy
  13. {
  14. private TCPListener? _tcpListener;
  15. private UDPListener? _udpListener;
  16. public void Start(string listenSocks, string serverAddress, int serverPort, string method, string password, string? plugin, string? pluginOpts, string? pluginArgs)
  17. {
  18. var localEP = IPEndPoint.Parse(listenSocks);
  19. var server = new Server()
  20. {
  21. Host = serverAddress,
  22. Port = serverPort,
  23. Method = method,
  24. Password = password,
  25. Plugin = plugin,
  26. PluginOpts = pluginOpts,
  27. };
  28. if (!string.IsNullOrEmpty(plugin) && !string.IsNullOrEmpty(pluginArgs))
  29. {
  30. var processStartInfo = new ProcessStartInfo(plugin, pluginArgs);
  31. server.PluginArgs = processStartInfo.ArgumentList.ToList();
  32. }
  33. var tcpRelay = new TCPRelay(server);
  34. _tcpListener = new TCPListener(localEP, new List<IStreamService>()
  35. {
  36. tcpRelay,
  37. });
  38. _tcpListener.Start();
  39. var udpRelay = new UDPRelay(server);
  40. _udpListener = new UDPListener(localEP, new List<IDatagramService>()
  41. {
  42. udpRelay,
  43. });
  44. _udpListener.Start();
  45. }
  46. public void Stop()
  47. {
  48. _tcpListener?.Stop();
  49. _udpListener?.Stop();
  50. }
  51. }
  52. }