/p2p-handshake

A CLI tool for making handshakes to p2p nodes

Primary LanguageRustThe UnlicenseUnlicense

Architecture Decision Record

Hello ๐Ÿ‘‹ If you are interested in how this project was conceived, take a look to the ADR document.

p2p-handshake ๐Ÿค

A CLI tool for making handshakes to p2p nodes. Currently, supporting the Bitcoin network handshake.

Full example usage and output:

$ p2p-handshake -t 200 btc 192.168.1.10:8333 192.168.1.11:8333 192.168.1.12:8333 127.0.0.1:8333

โš ๏ธ  received message type not part of handshake: alert
โœ… - 192.168.1.10:8333 || version ๐Ÿ›ซ -- 34.999911ms --> version ๐Ÿ›ฌ (vers:70016 user-agent:/Satoshi:23.0.0/) -- 13.004ยตs --> verack ๐Ÿ›ฌ -- 121.845ยตs --> verack ๐Ÿ›ซ || total time 35.13476ms.
โœ… - 192.168.1.11:8333 || version ๐Ÿ›ซ -- 112.816965ms --> version ๐Ÿ›ฌ (vers:70016 user-agent:/Satoshi:23.0.0/) -- 48.267ยตs --> verack ๐Ÿ›ซ -- 15.745ยตs --> verack ๐Ÿ›ฌ || total time 112.880977ms.
โŒ ๐Ÿ• - 192.168.1.12:8333 || version ๐Ÿ›ซ -- 217.600713ms --> version ๐Ÿ›ฌ (vers:70016 user-agent:/Satoshi:23.0.0/) -- 239.585ยตs --> verack ๐Ÿ›ซ || total time 217.840298ms.
โŒ 127.0.0.1:8333: P2P error: Connection refused (os error 111)

Per each provided node, a time line of handshake messages is shown indicating the orientative time spent among handshake messages from the CLI point of view.

โœ… Indicates the operation was completed.

๐Ÿ›ฌ An incoming message.

๐Ÿ›ซ An outgoing message.

โŒ The operation failed.

โŒ ๐Ÿ• The operation timed out and may be incomplete.

โš ๏ธ Unexpected situations that should not affect the final result.

How to run

Currently, a rust installation its needed. There are 2 options:

Run from cargo

$ cargo run --release -- btc <ip_address:port> <ip_address:port> 

Install the CLI binary in your system

$ cargo install --path .
$ p2p-handshake btc <ip_address:port> <ip_address:port>

The help with all available options can be printed out with --help

$ p2p-handshake --help

Usage: p2p-handshake [OPTIONS] <COMMAND>

Commands:
  btc   
  help  Print this message or the help of the given subcommand(s)

Options:
  -t, --timeout <TIMEOUT>  maximum time per handshake operation in ms [default: 500]
  -h, --help               Print help information
  -V, --version            Print version information

Contributing

Checking the code

The code should be properly formatted and linted. This project makes use of clippy and cargo fmt for that. In order to enforce our development workflows, one could just configure the following cargo make check as a pre-commit hook:

cargo make --makefile workflow.toml code-check

How to run the tests

A node/s from the list of nodes should be elected. After that, just run:

TEST_NODES="<ip_addr:port> <ip_addr:port>" cargo test