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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. }
  17. // Different connection types which user requests from Telegram.
  18. const (
  19. ConnectionTypeUnknown ConnectionType = iota
  20. ConnectionTypeAbridged
  21. ConnectionTypeIntermediate
  22. )
  23. const (
  24. ConnectionProtocolIPv4 ConnectionProtocol = 1
  25. ConnectionProtocolIPv6 = ConnectionProtocolIPv4 << 1
  26. ConnectionProtocolAny = ConnectionProtocolIPv4 | ConnectionProtocolIPv6
  27. )
  28. // Connection tags for mtproto handshakes.
  29. var (
  30. ConnectionTagAbridged = []byte{0xef, 0xef, 0xef, 0xef}
  31. ConnectionTagIntermediate = []byte{0xee, 0xee, 0xee, 0xee}
  32. )
  33. // Tag maps connection type to the corresponding handshake tag.
  34. func (t ConnectionType) Tag() ([]byte, error) {
  35. switch t {
  36. case ConnectionTypeAbridged:
  37. return ConnectionTagAbridged, nil
  38. case ConnectionTypeIntermediate:
  39. return ConnectionTagIntermediate, nil
  40. default:
  41. return nil, errors.Errorf("Unknown connection type %d", t)
  42. }
  43. }
  44. // ConnectionTagFromHandshake maps magic bytes to the connection type.
  45. func ConnectionTagFromHandshake(magic []byte) (ConnectionType, error) {
  46. if bytes.Equal(magic, ConnectionTagIntermediate) {
  47. return ConnectionTypeIntermediate, nil
  48. }
  49. if bytes.Equal(magic, ConnectionTagAbridged) {
  50. return ConnectionTypeAbridged, nil
  51. }
  52. return ConnectionTypeUnknown, errors.New("Unknown handshake protocol")
  53. }