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 889B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package tlstypes
  2. import (
  3. "bytes"
  4. "io"
  5. "github.com/9seconds/mtg/utils"
  6. )
  7. type Handshake struct {
  8. Type HandshakeType
  9. Version Version
  10. Random [32]byte
  11. SessionID []byte
  12. Tail Byter
  13. }
  14. func (h *Handshake) WriteBytes(writer io.Writer) {
  15. packetBuf := bytes.Buffer{}
  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 := bytes.Buffer{}
  30. h.WriteBytes(&buf)
  31. return buf.Len()
  32. }