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.

direct.go 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package telegram
  2. import (
  3. "io"
  4. "github.com/juju/errors"
  5. "github.com/9seconds/mtg/config"
  6. "github.com/9seconds/mtg/obfuscated2"
  7. "github.com/9seconds/mtg/wrappers"
  8. )
  9. var (
  10. directV4Addresses = map[int16][]string{
  11. 0: []string{"149.154.175.50:443"},
  12. 1: []string{"149.154.167.51:443"},
  13. 2: []string{"149.154.175.100:443"},
  14. 3: []string{"149.154.167.91:443"},
  15. 4: []string{"149.154.171.5:443"},
  16. }
  17. directV6Addresses = map[int16][]string{
  18. 0: []string{"[2001:b28:f23d:f001::a]:443"},
  19. 1: []string{"[2001:67c:04e8:f002::a]:443"},
  20. 2: []string{"[2001:b28:f23d:f003::a]:443"},
  21. 3: []string{"[2001:67c:04e8:f004::a]:443"},
  22. 4: []string{"[2001:b28:f23f:f005::a]:443"},
  23. }
  24. )
  25. type directTelegram struct {
  26. baseTelegram
  27. }
  28. func (t *directTelegram) Dial(dcIdx int16) (io.ReadWriteCloser, error) {
  29. if dcIdx < 0 {
  30. dcIdx = -dcIdx
  31. } else if dcIdx == 0 {
  32. dcIdx = 1
  33. }
  34. return t.baseTelegram.Dial(dcIdx - 1)
  35. }
  36. func (t *directTelegram) Init(conn io.ReadWriteCloser) (io.ReadWriteCloser, error) {
  37. obfs2, frame := obfuscated2.MakeTelegramObfuscated2Frame()
  38. if n, err := conn.Write(frame); err != nil || n != len(frame) {
  39. return nil, errors.Annotate(err, "Cannot write hadnshake frame")
  40. }
  41. return wrappers.NewStreamCipherRWC(conn, obfs2.Encryptor, obfs2.Decryptor), nil
  42. }
  43. func NewDirectTelegram(conf *config.Config) Telegram {
  44. return &directTelegram{baseTelegram{
  45. dialer: newDialer(conf),
  46. v4Addresses: directV4Addresses,
  47. v6Addresses: directV6Addresses,
  48. }}
  49. }