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

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package client
  2. import (
  3. "context"
  4. "net"
  5. "github.com/9seconds/mtg/antireplay"
  6. "github.com/9seconds/mtg/config"
  7. "github.com/9seconds/mtg/mtproto"
  8. "github.com/9seconds/mtg/wrappers"
  9. )
  10. // MiddleInit initializes client connection for proxy which has to
  11. // support promoted channels, connect to Telegram middle proxies etc.
  12. func MiddleInit(ctx context.Context, cancel context.CancelFunc, socket net.Conn,
  13. connID string, antiReplayCache antireplay.Cache,
  14. conf *config.Config) (wrappers.Wrap, *mtproto.ConnectionOpts, error) {
  15. conn, opts, err := DirectInit(ctx, cancel, socket, connID, antiReplayCache, conf)
  16. if err != nil {
  17. return nil, nil, err
  18. }
  19. connStream := conn.(wrappers.StreamReadWriteCloser)
  20. var newConn wrappers.PacketReadWriteCloser
  21. switch opts.ConnectionType {
  22. case mtproto.ConnectionTypeAbridged:
  23. newConn = wrappers.NewMTProtoAbridged(connStream, opts)
  24. case mtproto.ConnectionTypeIntermediate:
  25. newConn = wrappers.NewMTProtoIntermediate(connStream, opts)
  26. case mtproto.ConnectionTypeSecure:
  27. newConn = wrappers.NewMTProtoIntermediateSecure(connStream, opts)
  28. default:
  29. panic("Unknown connection type")
  30. }
  31. opts.ConnectionProto = mtproto.ConnectionProtocolIPv4
  32. if socket.LocalAddr().(*net.TCPAddr).IP.To4() == nil {
  33. opts.ConnectionProto = mtproto.ConnectionProtocolIPv6
  34. }
  35. return newConn, opts, err
  36. }