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.

dialer.go 819B

12345678910111213141516171819202122232425262728293031323334353637383940
  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, sock string) (wrappers.ReadWriteCloserWithAddr, error) {
  25. conn, err := t.dial(addr)
  26. if err != nil {
  27. return nil, err
  28. }
  29. return wrappers.NewTimeoutRWC(conn, sock, t.conf.PublicIPv4, t.conf.PublicIPv6), nil
  30. }