#transport-layer #experimental #secure #protocols #p2p #tokio

bin+lib bluefin

An experimental, secure, P2P, transport-layer protocol

7 releases

0.1.6 Dec 31, 2024
0.1.5 Sep 14, 2024
0.1.4 Apr 16, 2023
0.1.2 Mar 26, 2023

#1971 in Network programming

Download history 15/week @ 2024-09-24 7/week @ 2024-10-01 2/week @ 2024-10-08 2/week @ 2024-10-29 5/week @ 2024-11-05 116/week @ 2024-12-31 3/week @ 2025-01-07

119 downloads per month

MIT license

130KB
3K SLoC

Bluefin

Bluefin is an experimental, P2P, transport-layer protocol. Unlike TCP, Bluefin runs in user-space and can allow for faster development cycles, greater flexibility in new features and more performant resource management compared to kernel-space implementations. Bluefin is currently only supported on MacOs and Linux.

Latest Version Documentation Github Workflow License: MIT codecov

Example

Pack-leader

#[tokio::main]
async fn main() -> BluefinResult<()> {
    let mut server = BluefinServer::new(std::net::SocketAddr::V4(SocketAddrV4::new(
        Ipv4Addr::new(192, 168, 1, 38),
        1235,
    )));
    server.bind().await?;

    while let Ok(conn) = s.accept().await {
        let _ = spawn(async move {
            let mut recv_bytes = [0u8; 1024];
            loop {
                let size = conn.recv(&mut recv_bytes, 1024).await.unwrap();

                println!(
                    "({:x}_{:x}) >>> Received: {:?}",
                    conn.src_conn_id,
                    conn.dst_conn_id,
                    &recv_bytes[..size],
                );
            }
        });
    }

    // The spawned tasks are looping forever. This infinite loop will keep the
    // process up forever.
    loop {}
}

Client

#[tokio::main]
async fn main() -> BluefinResult<()> {
    let mut client = BluefinClient::new(std::net::SocketAddr::V4(SocketAddrV4::new(
        Ipv4Addr::new(192, 168, 1, 38),
        1234,
    )));
    let mut conn = client
        .connect(std::net::SocketAddr::V4(SocketAddrV4::new(
            Ipv4Addr::new(192, 168, 1, 38),
            1235,
        )))
        .await?;

    let bytes = [1, 2, 3, 4];
    let size = conn.send(&bytes);
    println!("Sent {} bytes", size);

    Ok(())
}

Dependencies

~13–23MB
~329K SLoC