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.

handshake.go 958B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package tlstypes
  2. import (
  3. "io"
  4. "github.com/9seconds/mtg/utils"
  5. )
  6. type Handshake struct {
  7. Type HandshakeType
  8. Version Version
  9. Random [32]byte
  10. SessionID []byte
  11. Tail Byter
  12. }
  13. func (h *Handshake) WriteBytes(writer io.Writer) {
  14. packetBuf := acquireBytesBuffer()
  15. defer releaseBytesBuffer(packetBuf)
  16. writer.Write([]byte{byte(h.Type)}) // nolint: errcheck
  17. packetBuf.Write(h.Version.Bytes())
  18. packetBuf.Write(h.Random[:])
  19. packetBuf.WriteByte(byte(len(h.SessionID)))
  20. packetBuf.Write(h.SessionID)
  21. h.Tail.WriteBytes(packetBuf)
  22. sizeUint24 := utils.ToUint24(uint32(packetBuf.Len()))
  23. sizeUint24Bytes := sizeUint24[:]
  24. sizeUint24Bytes[0], sizeUint24Bytes[2] = sizeUint24Bytes[2], sizeUint24Bytes[0]
  25. writer.Write(sizeUint24Bytes) // nolint: errcheck
  26. packetBuf.WriteTo(writer) // nolint: errcheck
  27. }
  28. func (h *Handshake) Len() int {
  29. buf := acquireBytesBuffer()
  30. defer releaseBytesBuffer(buf)
  31. h.WriteBytes(buf)
  32. return buf.Len()
  33. }