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

connection_options.go 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package mtproto
  2. import (
  3. "bytes"
  4. "github.com/juju/errors"
  5. )
  6. // ConnectionType is a type of obfuscated2/mtproto connection requested
  7. // by the user.
  8. type ConnectionType uint8
  9. type ConnectionProtocol uint8
  10. // ConnectionOpts presents an options, metadata on connection requested
  11. // by the user on handshake.
  12. type ConnectionOpts struct {
  13. DC int16
  14. ConnectionType ConnectionType
  15. ConnectionProto ConnectionProtocol
  16. QuickAck bool
  17. SimpleAck bool
  18. }
  19. // Different connection types which user requests from Telegram.
  20. const (
  21. ConnectionTypeUnknown ConnectionType = iota
  22. ConnectionTypeAbridged
  23. ConnectionTypeIntermediate
  24. )
  25. const (
  26. ConnectionProtocolIPv4 ConnectionProtocol = 1
  27. ConnectionProtocolIPv6 = ConnectionProtocolIPv4 << 1
  28. ConnectionProtocolAny = ConnectionProtocolIPv4 | ConnectionProtocolIPv6
  29. )
  30. // Connection tags for mtproto handshakes.
  31. var (
  32. ConnectionTagAbridged = []byte{0xef, 0xef, 0xef, 0xef}
  33. ConnectionTagIntermediate = []byte{0xee, 0xee, 0xee, 0xee}
  34. )
  35. // Tag maps connection type to the corresponding handshake tag.
  36. func (t ConnectionType) Tag() ([]byte, error) {
  37. switch t {
  38. case ConnectionTypeAbridged:
  39. return ConnectionTagAbridged, nil
  40. case ConnectionTypeIntermediate:
  41. return ConnectionTagIntermediate, nil
  42. default:
  43. return nil, errors.Errorf("Unknown connection type %d", t)
  44. }
  45. }
  46. // ConnectionTagFromHandshake maps magic bytes to the connection type.
  47. func ConnectionTagFromHandshake(magic []byte) (ConnectionType, error) {
  48. if bytes.Equal(magic, ConnectionTagIntermediate) {
  49. return ConnectionTypeIntermediate, nil
  50. }
  51. if bytes.Equal(magic, ConnectionTagAbridged) {
  52. return ConnectionTypeAbridged, nil
  53. }
  54. return ConnectionTypeUnknown, errors.New("Unknown handshake protocol")
  55. }