ProxyFactory.cs 635 B

12345678910111213141516171819202122232425262728293031
  1. using Microsoft;
  2. using Socks5.Models;
  3. using STUN.Enums;
  4. using System.Net;
  5. namespace STUN.Proxy
  6. {
  7. public static class ProxyFactory
  8. {
  9. public static IUdpProxy CreateProxy(ProxyType type, IPEndPoint local, Socks5CreateOption option)
  10. {
  11. switch (type)
  12. {
  13. case ProxyType.Plain:
  14. {
  15. return new NoneUdpProxy(local);
  16. }
  17. case ProxyType.Socks5:
  18. {
  19. Requires.NotNull(option, nameof(option));
  20. Requires.Argument(option.Address is not null, nameof(option), @"Proxy server is null");
  21. return new Socks5UdpProxy(local, option);
  22. }
  23. default:
  24. {
  25. throw Assumes.NotReachable();
  26. }
  27. }
  28. }
  29. }
  30. }