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

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package client
  2. import (
  3. "io"
  4. "net"
  5. "time"
  6. "github.com/juju/errors"
  7. "github.com/9seconds/mtg/config"
  8. "github.com/9seconds/mtg/mtproto"
  9. "github.com/9seconds/mtg/obfuscated2"
  10. "github.com/9seconds/mtg/wrappers"
  11. )
  12. const (
  13. handshakeTimeout = 10 * time.Second
  14. )
  15. // DirectInit initializes client to access Telegram bypassing middleproxies.
  16. func DirectInit(conn net.Conn, conf *config.Config) (*mtproto.ConnectionOpts, io.ReadWriteCloser, error) {
  17. if err := config.SetSocketOptions(conn); err != nil {
  18. return nil, nil, errors.Annotate(err, "Cannot set socket options")
  19. }
  20. conn.SetReadDeadline(time.Now().Add(handshakeTimeout)) // nolint: errcheck
  21. frame, err := obfuscated2.ExtractFrame(conn)
  22. conn.SetReadDeadline(time.Time{}) // nolint: errcheck
  23. if err != nil {
  24. return nil, nil, errors.Annotate(err, "Cannot extract frame")
  25. }
  26. defer obfuscated2.ReturnFrame(frame)
  27. obfs2, connOpts, err := obfuscated2.ParseObfuscated2ClientFrame(conf.Secret, frame)
  28. if err != nil {
  29. return nil, nil, errors.Annotate(err, "Cannot parse obfuscated frame")
  30. }
  31. connOpts.ConnectionProto = mtproto.ConnectionProtocolAny
  32. socket := wrappers.NewStreamCipherRWC(conn, obfs2.Encryptor, obfs2.Decryptor)
  33. return connOpts, socket, nil
  34. }