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
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

telegram.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package telegram
  2. import (
  3. "math/rand"
  4. "github.com/juju/errors"
  5. "github.com/9seconds/mtg/mtproto"
  6. "github.com/9seconds/mtg/wrappers"
  7. )
  8. // Telegram is an interface for different Telegram work modes.
  9. type Telegram interface {
  10. Dial(string, *mtproto.ConnectionOpts) (wrappers.StreamReadWriteCloser, error)
  11. Init(*mtproto.ConnectionOpts, wrappers.StreamReadWriteCloser) (wrappers.Wrap, error)
  12. }
  13. type baseTelegram struct {
  14. dialer tgDialer
  15. v4Addresses map[int16][]string
  16. v6Addresses map[int16][]string
  17. }
  18. func (b *baseTelegram) dial(dcIdx int16, connID string,
  19. proto mtproto.ConnectionProtocol) (wrappers.StreamReadWriteCloser, error) {
  20. addrs := make([]string, 2)
  21. if proto&mtproto.ConnectionProtocolIPv6 != 0 {
  22. if addr, ok := b.v6Addresses[dcIdx]; ok && len(addr) > 0 {
  23. addrs = append(addrs, addr[rand.Intn(len(addr))])
  24. }
  25. }
  26. if proto&mtproto.ConnectionProtocolIPv4 != 0 {
  27. if addr, ok := b.v4Addresses[dcIdx]; ok && len(addr) > 0 {
  28. addrs = append(addrs, addr[rand.Intn(len(addr))])
  29. }
  30. }
  31. for _, addr := range addrs {
  32. if conn, err := b.dialer.dialRWC(addr, connID); err == nil {
  33. return conn, err
  34. }
  35. }
  36. return nil, errors.New("Cannot connect to Telegram")
  37. }