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.

rpc_proxy_flags.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package rpc
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. "github.com/9seconds/mtg/mtproto"
  6. )
  7. type RPCProxyRequestFlags uint32
  8. const (
  9. RPCProxyRequestFlagsHasAdTag RPCProxyRequestFlags = 0x8
  10. RPCProxyRequestFlagsEncrypted = 0x2
  11. RPCProxyRequestFlagsMagic = 0x1000
  12. RPCProxyRequestFlagsExtMode2 = 0x20000
  13. RPCProxyRequestFlagsIntermediate = 0x20000000
  14. RPCProxyRequestFlagsAbdridged = 0x40000000
  15. RPCProxyRequestFlagsQuickAck = 0x80000000
  16. )
  17. var rpcProxyRequestFlagsEncryptedPrefix [8]byte
  18. func (r RPCProxyRequestFlags) Bytes() []byte {
  19. converted := make([]byte, 4)
  20. binary.LittleEndian.PutUint32(converted, uint32(r))
  21. return converted
  22. }
  23. func NewRPCRproxyRequestFlags(connectionType mtproto.ConnectionType, quickAck bool, message []byte) RPCProxyRequestFlags {
  24. flags := RPCProxyRequestFlagsHasAdTag
  25. flags |= RPCProxyRequestFlagsMagic
  26. flags |= RPCProxyRequestFlagsExtMode2
  27. switch connectionType {
  28. case mtproto.ConnectionTypeAbridged:
  29. flags |= RPCProxyRequestFlagsAbdridged
  30. case mtproto.ConnectionTypeIntermediate:
  31. flags |= RPCProxyRequestFlagsIntermediate
  32. }
  33. if quickAck {
  34. flags |= RPCProxyRequestFlagsQuickAck
  35. }
  36. if bytes.HasPrefix(message, rpcProxyRequestFlagsEncryptedPrefix[:]) {
  37. flags |= RPCProxyRequestFlagsEncrypted
  38. }
  39. return flags
  40. }