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.

12345678910111213141516171819202122232425262728293031
  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.Wrap, *mtproto.ConnectionOpts, error) {
  11. conn, opts, err := DirectInit(ctx, cancel, socket, connID, conf)
  12. if err != nil {
  13. return nil, nil, err
  14. }
  15. connStream := conn.(wrappers.WrapStreamReadWriteCloser)
  16. newConn := wrappers.NewMTProtoAbridged(connStream, opts)
  17. if opts.ConnectionType != mtproto.ConnectionTypeAbridged {
  18. newConn = wrappers.NewMTProtoIntermediate(connStream, opts)
  19. }
  20. opts.ConnectionProto = mtproto.ConnectionProtocolIPv4
  21. if socket.LocalAddr().(*net.TCPAddr).IP.To4() == nil {
  22. opts.ConnectionProto = mtproto.ConnectionProtocolIPv6
  23. }
  24. return newConn, opts, err
  25. }