22 releases
| 0.3.2 | Jul 23, 2025 |
|---|---|
| 0.3.1 | Jun 27, 2025 |
| 0.3.0 | Apr 30, 2025 |
| 0.2.0 | Feb 21, 2025 |
| 0.1.6 | Sep 23, 2024 |
#164 in Cryptography
1,230 downloads per month
Used in 4 crates
(2 directly)
380KB
10K
SLoC
A decentralized p2p library powered by Rust, which is devoted to simple use.
Features
- UDP hole punching for both Cone and Symmetric Nat
- TCP hole punching for NAT1
- Enables reliable transport over KCP
- Enables secure encryption with AesGcm or ChaCha20Poly1305.
Description
For connecting two peers, all you need to do is to give the configuration as done in the example. In short, provide a peer named C, peer A and B can directly connect to C, then A and B will find each other by C, A and C can directly connect by hole-punching, the whole process is done by this library. If two peers D and F cannot directly connect via hole-punching, this library can find the best link for indirectly connection(i.e. through some middle nodes).
Example
use rustp2p::Builder;
use rustp2p::protocol::node_id::GroupCode;
use rustp2p::cipher::Algorithm;
use rustp2p::tunnel::PeerNodeAddress;
use std::net::Ipv4Addr;
use std::sync::Arc;
#[tokio::main]
async fn main() {
let node_id = Ipv4Addr::from([10, 0, 0, 1]);
let endpoint = Builder::new()
.node_id(node_id.into())
.tcp_port(8080)
.udp_port(8080)
.peers(vec![PeerNodeAddress::from_str("udp://127.0.0.1:9090").unwrap()])
.group_code(GroupCode::from(12345))
.encryption(Algorithm::AesGcm("password".to_string()))
.build()
.await?;
let endpoint = Arc::new(endpoint);
let receiver = endpoint.clone();
let h = tokio::spawn(async move {
while let Ok(peer) = receiver.recv_from().await {}
});
let peer_node_id = Ipv4Addr::from([10, 0, 0, 2]);
endpoint.send_to(b"hello", peer_node_id);
_ = h.await;
}
Dependencies
~8–39MB
~572K SLoC