A lightweight implementation of Ethereum's devp2p protocol. This project provides a minimal, educational implementation of peer-to-peer networking using the core concepts of Ethereum's network layer.
- Minimal devp2p implementation
- Node discovery and peer management
- Secure communication using ECDSA keys
- Configurable network parameters
- debug logging
- Bootnode supports
git clone https://github.com/devlongs/light-devp2p.git
cd light-devp2p
go mod tidy
- Start the first node:
go run main.go -addr :30303
- Start the second node:
go run main.go -addr :30304 -bootnode "enode://[public-key]@127.0.0.1:30303"
Available command-line options:
Flag | Description | Default |
---|---|---|
-addr |
Listen address | ":30303" |
-bootnode |
Bootnode enode URL | "" |
-maxpeers |
Maximum peer connections | 10 |
-nodename |
Node identifier | "MinimalP2PNode" |
-metrics |
Enable metrics collection | false |
light-devp2p/
├── main.go # Entry point
├── go.mod # Go module file
├── node/
│ ├── node.go # Core node implementation
│ ├── peer.go # Peer management
│ └── protocol.go # Protocol implementation
└── config/
└── config.go # Configuration handling
The implementation is organized around three main components:
- Node
- Manages the P2P server
- Handles peer connections
- Implements protocol communication
- Peer Manager
- Tracks active connections
- Manages peer lifecycle
- Handles peer state
- Protocol
- Defines message types
- Implements handshake
- Manages message exchange