Skip to content

eloylp/p2p-handshake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A CLI tool for making handshakes to p2p nodes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages