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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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