HomePhabricator

Per-Peer Message Capture

Description

Per-Peer Message Capture

Summary:
The purpose and scope of this feature is intentionally limited. It answers a question anyone new to Bitcoin's P2P protocol has had: "Can I see what messages my node is sending and receiving?".

When a new debug-only command line argument capturemessages is set, any message that the node receives or sends is captured. The capture occurs in the MessageHandler thread. When receiving a message, it is captured as soon as the MessageHandler thread takes the message off of the vProcessMsg queue. When sending, the message is captured just before the message is pushed onto the vSendMsg queue.

The message capture is as minimal as possible to reduce the performance impact on the node. Messages are captured to a new message_capture folder in the datadir. Each node has their own subfolder named with their IP address and port. Inside, received and sent messages are captured into two binary files, msgs_recv.dat and msgs_sent.dat, like so:

message_capture/203.0.113.7:56072/msgs_recv.dat
message_capture/203.0.113.7:56072/msgs_sent.dat

Because the messages are raw binary dumps, included in this PR is a Python parsing tool to convert the binary files into human-readable JSON. This script has been placed on its own and out of the way in the new contrib/message-capture folder. Its usage is simple and easily discovered by the autogenerated -h option.

This is a backport of core#19509

Test Plan:
ninja all check-all
src/bitcoind -capturemessages
./contrib/message-capture/message-capture-parser.py -o out.json /bitcoinddata/message_capture/**/*.dat

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D12531

Details

Provenance
Troy Giorshev <troygiorshev@gmail.com>Authored on Jul 13 2020, 17:20
PiRKCommitted on Nov 18 2022, 15:34
PiRKPushed on Nov 18 2022, 15:34
Reviewer
Restricted Project
Differential Revision
D12531: Per-Peer Message Capture
Parents
rABC472e6c7dc426: init: Signal-safe instant shutdown
Branches
Unknown
Tags
Unknown

Event Timeline