ProxyFactory.cs 634 B

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