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
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package telegram
  2. import (
  3. "context"
  4. "net"
  5. "github.com/juju/errors"
  6. "github.com/9seconds/mtg/config"
  7. "github.com/9seconds/mtg/mtproto"
  8. "github.com/9seconds/mtg/obfuscated2"
  9. "github.com/9seconds/mtg/wrappers"
  10. )
  11. var (
  12. directV4Addresses = map[int16][]string{
  13. 0: {"149.154.175.50:443"},
  14. 1: {"149.154.167.51:443"},
  15. 2: {"149.154.175.100:443"},
  16. 3: {"149.154.167.91:443"},
  17. 4: {"149.154.171.5:443"},
  18. }
  19. directV6Addresses = map[int16][]string{
  20. 0: {"[2001:b28:f23d:f001::a]:443"},
  21. 1: {"[2001:67c:04e8:f002::a]:443"},
  22. 2: {"[2001:b28:f23d:f003::a]:443"},
  23. 3: {"[2001:67c:04e8:f004::a]:443"},
  24. 4: {"[2001:b28:f23f:f005::a]:443"},
  25. }
  26. )
  27. type directTelegram struct {
  28. baseTelegram
  29. }
  30. func (t *directTelegram) Dial(ctx context.Context, cancel context.CancelFunc,
  31. connID string, connOpts *mtproto.ConnectionOpts) (wrappers.StreamReadWriteCloser, error) {
  32. dc := connOpts.DC
  33. if dc < 0 {
  34. dc = -dc
  35. } else if dc == 0 {
  36. dc = 1
  37. }
  38. return t.baseTelegram.dial(ctx, cancel, dc-1, connID, connOpts.ConnectionProto)
  39. }
  40. func (t *directTelegram) Init(connOpts *mtproto.ConnectionOpts,
  41. conn wrappers.StreamReadWriteCloser) (wrappers.Wrap, error) {
  42. obfs2, frame := obfuscated2.MakeTelegramObfuscated2Frame(connOpts)
  43. if _, err := conn.Write(frame); err != nil {
  44. return nil, errors.Annotate(err, "Cannot write hadnshake frame")
  45. }
  46. return wrappers.NewStreamCipher(conn, obfs2.Encryptor, obfs2.Decryptor), nil
  47. }
  48. // NewDirectTelegram returns Telegram instance which connects directly
  49. // to Telegram bypassing middleproxies.
  50. func NewDirectTelegram(conf *config.Config) Telegram {
  51. return &directTelegram{
  52. baseTelegram: baseTelegram{
  53. dialer: tgDialer{
  54. Dialer: net.Dialer{Timeout: telegramDialTimeout},
  55. conf: conf,
  56. },
  57. v4Addresses: directV4Addresses,
  58. v6Addresses: directV6Addresses,
  59. },
  60. }
  61. }