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
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

connection_options.go 1.8KB

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