I'm writing a small p2p network and I don't know if I have to transmit message (between nodes) in clear text or in another format ? How is it for bitcoin protocol ?
1 Answer
in clear text or in another format? How is it for bitcoin protocol?
In binary. With numbers mostly in little-endian byte-order. Over TCP with a conventional target port number.
The details are at https://en.bitcoin.it/wiki/Protocol_documentation
For example:
Message structure
Field Size Description Data type Comments 4 magic uint32_t Magic value indicating message origin network, and used to seek to next message when stream state is unknown 12 command char[12] ASCII string identifying the packet content, NULL padded (non-NULL padding results in packet rejected) 4 length uint32_t Length of payload in number of bytes 4 checksum uint32_t First 4 bytes of sha256(sha256(payload)) ? payload uchar[] The actual data
Unless message size and volume is important, I would instead use JSON in UTF8 for any protocol I create. You should make your own evaluation.
You might also want to consider the Gossip protocol
-
Thank you ! What are the benefits of using binary instead of json/text ?– LukkyzApr 7, 2022 at 11:15
-