1 unstable release

new 0.1.0 Feb 17, 2025

#2 in #utp

50 downloads per month
Used in librqbit-utp

MIT license

170KB
3.5K SLoC

C++ 3K SLoC // 0.3% comments Rust 561 SLoC // 0.0% comments

Async Tokio library for uTP (uTorrent transport protocol) using C-based libutp under the hood.

Working and tested alternative to libutp-rs

Docs

Example


use libutp_rs2::UtpUdpContext;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Server
    let server_addr = "127.0.0.1:8001".parse()?;
    let listener = tokio::spawn(async move {
        let mut buf = String::new();
        UtpUdpContext::new_udp(server_addr)
            .await?
            .accept()
            .await?
            .read_to_string(&mut buf)
            .await?;
        Ok::<_, anyhow::Error>(buf)
    });

    // Client
    tokio::spawn(async move {
        UtpUdpContext::new_udp("127.0.0.1:8002".parse()?)
            .await?
            .connect(server_addr)
            .await?
            .write_all(b"hello")
            .await?;
        Ok::<_, anyhow::Error>(())
    });

    println!("{}", listener.await.unwrap().unwrap());

    Ok(())
}

Dependencies

~5–16MB
~200K SLoC