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ů.

dialer.go 747B

1234567891011121314151617181920212223242526272829303132333435363738
  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. }
  13. func (t *tgDialer) dial(addr string) (net.Conn, error) {
  14. conn, err := t.Dialer.Dial("tcp", addr)
  15. if err != nil {
  16. return nil, errors.Annotate(err, "Cannot connect to Telegram")
  17. }
  18. if err = config.SetSocketOptions(conn); err != nil {
  19. return nil, errors.Annotate(err, "Cannot set socket options")
  20. }
  21. return conn, nil
  22. }
  23. func (t *tgDialer) dialRWC(addr string) (wrappers.ReadWriteCloserWithAddr, error) {
  24. conn, err := t.dial(addr)
  25. if err != nil {
  26. return nil, err
  27. }
  28. return wrappers.NewTimeoutRWC(conn), nil
  29. }