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 символов.

telegram.go 935B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. type baseTelegram struct {
  9. dialer tgDialer
  10. v4Addresses map[int16][]string
  11. v6Addresses map[int16][]string
  12. }
  13. func (b *baseTelegram) dial(dcIdx int16, connID string, proto mtproto.ConnectionProtocol) (wrappers.WrapStreamReadWriteCloser, error) {
  14. addrs := make([]string, 2)
  15. if proto&mtproto.ConnectionProtocolIPv6 != 0 {
  16. if addr, ok := b.v6Addresses[dcIdx]; ok && len(addr) > 0 {
  17. addrs = append(addrs, addr[rand.Intn(len(addr))])
  18. }
  19. }
  20. if proto&mtproto.ConnectionProtocolIPv4 != 0 {
  21. if addr, ok := b.v4Addresses[dcIdx]; ok && len(addr) > 0 {
  22. addrs = append(addrs, addr[rand.Intn(len(addr))])
  23. }
  24. }
  25. for _, addr := range addrs {
  26. if conn, err := b.dialer.dialRWC(addr, connID); err == nil {
  27. return conn, err
  28. }
  29. }
  30. return nil, errors.New("Cannot connect to Telegram")
  31. }