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.

telegram.go 863B

123456789101112131415161718192021222324252627282930313233343536373839
  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) (net.Conn, error) {
  16. if dcIdx < 0 || dcIdx >= 5 {
  17. return nil, errors.New("Incorrect DC IDX")
  18. }
  19. tcpAddr, _ := net.ResolveTCPAddr("tcp", telegramDCIPs[dcIdx])
  20. conn, err := net.DialTCP("tcp", nil, tcpAddr)
  21. if err != nil {
  22. return nil, errors.Annotate(err, "Cannot dial")
  23. }
  24. if err := conn.SetKeepAlive(true); err != nil {
  25. return nil, errors.Annotate(err, "Cannot establish keepalive connection")
  26. }
  27. if err := conn.SetKeepAlivePeriod(telegramKeepAlive); err != nil {
  28. return nil, errors.Annotate(err, "Cannot set keepalive timeout")
  29. }
  30. return conn, nil
  31. }