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
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

middle.go 1.1KB

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