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
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

direct.go 1.9KB

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