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

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package telegram
  2. import (
  3. "net"
  4. "time"
  5. "github.com/juju/errors"
  6. "github.com/9seconds/mtg/config"
  7. "github.com/9seconds/mtg/wrappers"
  8. )
  9. const telegramDialTimeout = 10 * time.Second
  10. type tgDialer struct {
  11. net.Dialer
  12. conf *config.Config
  13. }
  14. func (t *tgDialer) dial(addr string) (net.Conn, error) {
  15. conn, err := t.Dialer.Dial("tcp", addr)
  16. if err != nil {
  17. return nil, errors.Annotate(err, "Cannot connect to Telegram")
  18. }
  19. if err = config.SetSocketOptions(conn); err != nil {
  20. return nil, errors.Annotate(err, "Cannot set socket options")
  21. }
  22. return conn, nil
  23. }
  24. func (t *tgDialer) dialRWC(addr, connID string) (wrappers.StreamReadWriteCloser, error) {
  25. conn, err := t.dial(addr)
  26. if err != nil {
  27. return nil, err
  28. }
  29. tgConn := wrappers.NewConn(conn, connID, wrappers.ConnPurposeTelegram, t.conf.PublicIPv4, t.conf.PublicIPv6)
  30. return tgConn, nil
  31. }