A comprehensive Dart implementation of the libp2p networking stack, providing a modular and extensible foundation for building peer-to-peer applications.
- Modular Architecture: Pluggable transports, security protocols, and stream multiplexers
- Multiple Transports: TCP and custom UDX (UDP-based) transport support
- Security: Noise protocol for encrypted and authenticated connections
- Stream Multiplexing: Yamux for efficient multi-stream communication
- Peer Discovery: mDNS and routing-based peer discovery mechanisms
- Protocol Support: Built-in support for Ping, Identify, and other core libp2p protocols
- Resource Management: Built-in protection against resource exhaustion
- Event System: Comprehensive event bus for monitoring network activity
- NAT Traversal: Hole punching and relay support for NAT traversal
Add dart_libp2p to your pubspec.yaml:
Then run:
Here's a simple example of creating two libp2p nodes and connecting them:
Dart Libp2p follows a layered architecture where each component provides services to the layer above it:
- Host: Central entry point that ties all components together
- Network/Swarm: Manages connections, peers, and upgrade lifecycle
- Upgrader: Handles security and multiplexing negotiation
- Transport: Establishes raw connections (TCP, UDX)
- Security: Encrypts and authenticates connections (Noise)
- Multiplexer: Enables multiple streams over single connections (Yamux)
- Protocols: /ip4/tcp, /ip6/tcp
- Use Case: Reliable, widely available transport for most applications
- Best For: Data centers, servers with public IPs
- Protocols: /ip4/udp/udx, /ip6/udp/udx
- Use Case: Custom UDP-based transport with built-in reliability
- Best For: NAT traversal, hole punching, peer-to-peer connections
Note: This implementation does not support QUIC. Instead, we've opted for a custom dart-udx implementation that provides similar benefits for peer-to-peer networking.
Dart Libp2p uses the Noise protocol for securing connections:
- Encryption: All communication is encrypted
- Authentication: Remote peer identity is verified
- Perfect Forward Secrecy: Session keys are ephemeral
- Handshake: Efficient key exchange and authentication
For detailed documentation, visit the docs directory:
- Getting Started: Step-by-step setup guide
- Architecture: Detailed architecture overview
- Configuration: Configuration options
- Host: Host component documentation
- Transports: Transport layer details
- Security: Security protocol information
- Multiplexing: Stream multiplexing
- Protocols: Built-in protocol documentation
- Peerstore: Peer information management
- Event Bus: Event system documentation
- Resource Manager: Resource protection
- Cookbook: Practical examples and recipes
Check out the examples directory for working examples:
- Ping App: Basic ping/pong communication between nodes
- Chat Application: Simple peer-to-peer chat implementation
Run the test suite:
We welcome contributions! Please see our contributing guidelines and code of conduct.
This project is licensed under the MIT License - see the LICENSE file for details.