5 releases
0.1.4 | Apr 16, 2023 |
---|---|
0.1.3 | Apr 15, 2023 |
0.1.2 | Mar 26, 2023 |
0.1.1 | Mar 18, 2023 |
0.1.0 | Mar 15, 2023 |
#21 in #transport-layer
78KB
1.5K
SLoC
Bluefin
Bluefin
is an experimental, P2P, transport-layer protocol.
Example
Pack-leader
use bluefin::hosts::pack_leader::BluefinPackLeaderBuilder;
#[tokio::main]
async fn main() {
// Bind and construct a pack-leader over an TUN device
let mut pack_leader = BluefinPackLeader::builder()
.name("utun3".to_string())
.bind_address("192.168.55.2".to_string())
.netmask("255.255.255.0".to_string())
.build();
loop {
let connection_res = pack_leader.accept().await;
tokio::spawn(async move {
match connection_res {
Ok(conn) => println!("Conn ready! {conn})"),
Err(err) => eprintln!("\nConnection attempt failed: {:?}", err),
}
});
sleep(Duration::from_secs(1)).await;
}
}
Client
#[tokio::main]
async fn main() -> std::io::Result<()> {
let mut client = BluefinClient::builder()
.name("test_client".to_string())
.build();
let port = rand::thread_rng().gen_range(10000..50000);
client
.bind("0.0.0.0", port)
.expect("Failed to bind client socket");
let mut conn = client
.connect("192.168.55.2", 31416)
.await
.expect("Failed to connect to host");
eprintln!("Conn ready! {conn}");
Ok(())
}
Dependencies
~6–13MB
~145K SLoC