Skip to content
franklee26Public

About

Experimental, secure, p2p-oriented, transport-layer protocol

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

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(mut 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();
                // `recv` returns `Ok(0)` once the peer's `Fin` has been
                // observed and all buffered data has been delivered.
                if size == 0 {
                    println!(
                        "({:x}_{:x}) >>> peer closed (EOF)",
                        conn.src_conn_id, conn.dst_conn_id,
                    );
                    break;
                }

                println!(
                    "({:x}_{:x}) >>> Received: {:?}",
                    conn.src_conn_id,
                    conn.dst_conn_id,
                    &recv_bytes[..size],
                );
            }
            // The peer already FIN'd us, so its half of the connection
            // is closed; calling `close()` here would just time out
            // waiting for a `FinAck` that will never arrive. If you
            // initiated the shutdown (e.g. on Ctrl-C), call
            // `conn.close().await` to send your own `Fin` and wait for
            // the peer's `FinAck`.
        });
    }

    // 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);

    // Gracefully close the connection: flushes any pending data, sends a
    // `Fin` and waits for the peer's `FinAck` (with a small retransmit
    // budget). The peer's `recv` will return `Ok(0)` once our `Fin`
    // arrives. Skipping this leaves the peer to time out on its
    // recv-idle safety net.
    conn.close().await?;

    Ok(())
}

bluefintool

A netcat-like CLI for quick smoke-testing and interactive data transfer over Bluefin. Install with cargo install --path bluefintool, then:

bluefintool -l 9000            # listen
bluefintool 127.0.0.1 9000     # connect (in another shell)

Pass -d for diagnostics (hex dumps, packet numbers, ACK events). See bluefintool/README.md for full usage.

About

Experimental, secure, p2p-oriented, transport-layer protocol

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages