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.

connection_options.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // ConnectionOpts presents an options, metadata on connection requested
  10. // by the user on handshake.
  11. type ConnectionOpts struct {
  12. DC int16
  13. ConnectionType ConnectionType
  14. }
  15. // Different connection types which user requests from Telegram.
  16. const (
  17. ConnectionTypeUnknown ConnectionType = iota
  18. ConnectionTypeAbridged
  19. ConnectionTypeIntermediate
  20. )
  21. // Connection tags for mtproto handshakes.
  22. var (
  23. ConnectionTagAbridged = []byte{0xef, 0xef, 0xef, 0xef}
  24. ConnectionTagIntermediate = []byte{0xee, 0xee, 0xee, 0xee}
  25. )
  26. // Tag maps connection type to the corresponding handshake tag.
  27. func (t ConnectionType) Tag() ([]byte, error) {
  28. switch t {
  29. case ConnectionTypeAbridged:
  30. return ConnectionTagAbridged, nil
  31. case ConnectionTypeIntermediate:
  32. return ConnectionTagIntermediate, nil
  33. default:
  34. return nil, errors.Errorf("Unknown connection type %d", t)
  35. }
  36. }
  37. // ConnectionTagFromHandshake maps magic bytes to the connection type.
  38. func ConnectionTagFromHandshake(magic []byte) (ConnectionType, error) {
  39. if bytes.Equal(magic, ConnectionTagIntermediate) {
  40. return ConnectionTypeIntermediate, nil
  41. }
  42. if bytes.Equal(magic, ConnectionTagAbridged) {
  43. return ConnectionTypeAbridged, nil
  44. }
  45. return ConnectionTypeUnknown, errors.New("Unknown handshake protocol")
  46. }