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.

middle.go 823B

123456789101112131415161718192021222324252627282930
  1. package client
  2. import (
  3. "context"
  4. "net"
  5. "github.com/9seconds/mtg/config"
  6. "github.com/9seconds/mtg/mtproto"
  7. "github.com/9seconds/mtg/wrappers"
  8. )
  9. func MiddleInit(ctx context.Context, cancel context.CancelFunc, socket net.Conn, connID string,
  10. conf *config.Config) (wrappers.WrapPacketReadWriteCloser, *mtproto.ConnectionOpts, error) {
  11. conn, opts, err := DirectInit(ctx, cancel, socket, connID, conf)
  12. if err != nil {
  13. return nil, nil, err
  14. }
  15. newConn := wrappers.NewMTProtoAbridged(conn, opts)
  16. if opts.ConnectionType != mtproto.ConnectionTypeAbridged {
  17. newConn = wrappers.NewMTProtoIntermediate(conn, opts)
  18. }
  19. opts.ConnectionProto = mtproto.ConnectionProtocolIPv4
  20. if socket.LocalAddr().(*net.TCPAddr).IP.To4() == nil {
  21. opts.ConnectionProto = mtproto.ConnectionProtocolIPv6
  22. }
  23. return newConn, opts, err
  24. }