Crates.io | velnet |
lib.rs | velnet |
version | 0.1.0 |
created_at | 2025-08-30 21:56:10.60699+00 |
updated_at | 2025-08-30 21:56:10.60699+00 |
description | Networking abstractions built on Veilid API primitives |
homepage | https://codeberg.org/cmars/velnet |
repository | https://codeberg.org/cmars/velnet.git |
max_upload_size | |
id | 1817958 |
size | 183,361 |
Networking abstractions built on Veilid API primitives.
Velnet provides high-level networking capabilities using the Veilid distributed hash table and private routing system. It enables applications to communicate over the Veilid network without dealing directly with low-level Veilid APIs.
Add velnet to your Cargo.toml
:
[dependencies]
velnet = "0.1.0"
use velnet::{Connection, datagram::listener::Listener};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let conn = Connection::new().await?;
let mut listener = Listener::bind(conn, None, 8080).await?;
println!("Listening at: {}", listener.addr());
// Receive messages
loop {
let (sender_route, message) = listener.recv_from().await?;
println!("Received: {:?}", String::from_utf8_lossy(&message));
}
}
use velnet::{Connection, DHTAddr, datagram::dialer::Dialer};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let conn = Connection::new().await?;
let mut dialer = Dialer::new(conn).await?;
// Parse the listener's address
let addr: DHTAddr = "VLD0:abcd1234...efgh5678:8080".parse()?;
// Send a message
let route_id = dialer.resolve(addr).await?;
dialer.send_to(route_id, b"Hello, world!".to_vec()).await?;
Ok(())
}
The vcat
example demonstrates a simple netcat-like tool for Veilid networks:
# Terminal 1 - Start a listener
cargo run --example vcat
# Terminal 2 - Connect and send messages
cargo run --example vcat VLD0:abcd...efgh:0
Velnet is built around three core concepts:
The library handles the complexity of Veilid's routing system while providing familiar networking patterns. Messages are automatically encrypted and routed through the Veilid network's onion routing system.
Velnet provides comprehensive error handling primitives supporting automatic recovery for common network issues:
See the vcat
example for examples of handling these errors in practice.
MPL-2.0