Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

sni_check.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package cli
  2. import (
  3. "context"
  4. "fmt"
  5. "net"
  6. "sync"
  7. "github.com/9seconds/mtg/v2/internal/config"
  8. "github.com/9seconds/mtg/v2/mtglib"
  9. )
  10. type sniCheckResult struct {
  11. ResolvedIP4 []string
  12. ResolvedIP6 []string
  13. OurIP4 string
  14. OurIP6 string
  15. }
  16. func runSNICheck(
  17. ctx context.Context,
  18. conf *config.Config,
  19. resolver *net.Resolver,
  20. ntw mtglib.Network,
  21. ) (sniCheckResult, error) {
  22. res := sniCheckResult{}
  23. addrs, err := resolver.LookupIPAddr(ctx, conf.Secret.Host)
  24. if err != nil {
  25. return res, fmt.Errorf("cannot resolve addresses of %s: %w", conf.Secret.Host, err)
  26. }
  27. if len(addrs) == 0 {
  28. return res, fmt.Errorf("no known addresses for %s", conf.Secret.Host)
  29. }
  30. for _, addr := range addrs {
  31. if ip := addr.IP.To4(); ip == nil {
  32. res.ResolvedIP6 = append(res.ResolvedIP6, addr.IP.To16().String())
  33. } else {
  34. res.ResolvedIP4 = append(res.ResolvedIP4, ip.String())
  35. }
  36. }
  37. wg := &sync.WaitGroup{}
  38. if len(res.ResolvedIP4) > 0 {
  39. wg.Go(func() {
  40. ip := conf.PublicIPv4.Get(nil)
  41. if ip == nil {
  42. ip, _ = getIP(ctx, ntw, "tcp4")
  43. }
  44. if ip != nil {
  45. res.OurIP4 = ip.To4().String()
  46. }
  47. })
  48. }
  49. if len(res.ResolvedIP6) > 0 {
  50. wg.Go(func() {
  51. ip := conf.PublicIPv6.Get(nil)
  52. if ip == nil {
  53. ip, _ = getIP(ctx, ntw, "tcp6")
  54. }
  55. if ip != nil {
  56. res.OurIP6 = ip.To16().String()
  57. }
  58. })
  59. }
  60. wg.Wait()
  61. return res, nil
  62. }