The libp2p-peer-tracker is a Rust application that demonstrates basic peer-to-peer networking capabilities using the libp2p framework. It maintains connections with other peers in the network and tracks their connection status in real-time.
src/
└── main.rs
The solution uses several key dependencies:
libp2p: Core networking stack with features for TCP, Tokio async runtime, noise encryption, multiplexing, and Kademlia DHTtokio: Async runtime for handling concurrent operationsfutures: Utilities for working with asynchronous codeidna: International domain names handlingurl: URL parsing and manipulation
-
Network Behavior Implementation
- Custom
MyBehaviourstruct that implementsNetworkBehaviour - Tracks connected peers using a
HashSet - Implements keep-alive functionality to maintain connections
- Custom
-
Transport Configuration
- Uses TCP transport with noise encryption for secure communications
- Implements multiplexing using mplex protocol
- Configures authentication using XX handshake pattern
-
Connection Management
- Listens on all network interfaces
- Connects to Infura's libp2p node as a bootstrap peer
- Tracks peer connections and disconnections
- Periodically reports connected peers
- Generates ED25519 keypair for node identity
- Creates a TCP transport with:
- Node-to-node delay disabled
- Upgrade protocol version V1
- Noise protocol for encryption
- Mplex for stream multiplexing
The custom behavior tracks:
- Keep-alive connections
- Connected peer set
- Connection events
Processes several types of network events:
- New listen address establishment
- Peer connection establishment
- Peer connection closure
- Regular peer list updates
-
The system automatically:
- Generates a unique peer ID on startup
- Listens on an available TCP port
- Connects to Infura's IPFS node
- Maintains a list of connected peers
- Prints connection status updates
-
The implementation provides:
- Real-time peer tracking
- Connection event logging
- Periodic peer list updates
- Automatic connection maintenance
The implementation includes several security features:
- Noise protocol encryption for all communications
- XX handshake pattern for mutual authentication
- Unique ED25519 keypair for node identity
This peer tracking system provides a foundation for building more complex P2P applications, with robust connection handling and peer management capabilities.
- Rust
- Rust installed on your system
- Cargo (Rust's package manager)
- Clone the repository
git clone https://github.com/leny62/libp2p-peer-tracker- Navigate to the project directory
cd libp2p-peer-tracker- Build the project
cargo build- Run the project
cargo runcargo testThis is a personal project for PLDG application, but suggestions and feedback are welcome.
This project is open-source and available under the MIT License.
Leny Pascal IHIRWE
- The web3 community for inspiration