#| #| #| #| #|
#| #| #| #| #|
5 components:
- a single byte protocol length
- a variable byte protocol string
- 8 reserved bytes (to indicate protocol changes)
- a 20-byte info hash
- a 20-byte peer id
Exactly what these are aren't important -- that they are constrained is.
#| #| #| #| #|
If you don't, you run the risk of sending garbage.
#| #| #| #| #|
#| #| #| #| #|
(bit-struct handshake
[len :byte]
[protocol :len/bytes]
[reserved :8/bytes]
[info-hash :20/bytes]
[peer-id :20/bytes])
#| #| #| #| #|
(encode handshake 19 "BitTorrent protocol" (reserved-bytes) info-hash
peer-id)
;; => Returns a ByteArray if the data meets the constraints
(encode handshake 5 "BitTorrent protocol" (reserved-bytes) info-hash
peer-id)
;; => Or throws an exception if it doesn't!
#| #| #| #| #|
#| #| #| #| #|