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
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

telegram.go 906B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package server
  2. import (
  3. "net"
  4. "time"
  5. "github.com/juju/errors"
  6. )
  7. var telegramDCIPs = [5]string{
  8. "149.154.175.50:443",
  9. "149.154.167.51:443",
  10. "149.154.175.100:443",
  11. "149.154.167.91:443",
  12. "149.154.171.5:443",
  13. }
  14. const telegramKeepAlive = 30 * time.Second
  15. func dialToTelegram(dcIdx int16, timeout time.Duration) (net.Conn, error) {
  16. if dcIdx < 0 || dcIdx >= 5 {
  17. return nil, errors.New("Incorrect DC IDX")
  18. }
  19. dialer := net.Dialer{Timeout: timeout}
  20. rawConn, err := dialer.Dial("tcp", telegramDCIPs[dcIdx])
  21. conn := rawConn.(*net.TCPConn)
  22. if err != nil {
  23. return nil, errors.Annotate(err, "Cannot dial")
  24. }
  25. if err := conn.SetKeepAlive(true); err != nil {
  26. return nil, errors.Annotate(err, "Cannot establish keepalive connection")
  27. }
  28. if err := conn.SetKeepAlivePeriod(telegramKeepAlive); err != nil {
  29. return nil, errors.Annotate(err, "Cannot set keepalive timeout")
  30. }
  31. return conn, nil
  32. }