I assume it's TCP, but is there some other software used to send and receive data? So how would I program a very simple C++ program that sends a test message to a node?
What protocol do bitcoin nodes use to talk to each other?
Most Bitcoin nodes will primarily use:
|Transport Control Protocol (TCP)
|Internet Protocol (IPV4 and/or IPV6), Internet Control Message Protocol (ICMP)
|Network Access Layer
|1000BASE-T / IEEE 802.3ab Ethernet
Obviously there are dependencies on other protocols which are not used directly by the Bitcoin node application itself (e.g. DNS via a name resolution service). The application will be using operating system libraries that manage the lower three layers. The principle APIs used will be those related to opening and closing TCP connections and writing to and reading from those connections. Perhaps using some variant of the Berkeley "sockets" API.
Here's an example network packet
how would I program a very simple C++ program that sends a test message to a node?
Although the protocol isn't especially complicated, I personally wouldn't characterise writing a client as "very simple". That is, I wouldn't choose it as my first network protocol to write a client for.
Bitcoin uses TCP-IP protocol. The structure of data follows 2 parts:
- Magic Bytes (4 bytes) which indicates the selected network by nodes.
- Command (12 bytes). You can see the command list here: https://github.com/bitcoin/bitcoin/blob/master/src/protocol.cpp#L14. Command field must be 12 bytes. So you can add null bytes to fullfill this field.
- Payload size (4 bytes)
- Checksum payload data (4 bytes). It is a double SHA256 of the payload data.
The payload depends on the command type. You can have an overview of it from https://developer.bitcoin.org/devguide/p2p_network.html.