2 releases

0.0.3 Nov 11, 2023
0.0.2 Nov 11, 2023

#38 in #torrent

MIT license

340KB
6K SLoC

image

Vincenzo

Vincenzo is a library for building programs powered by the BitTorrent protocol.

This crate offers the building blocks of the entire protocol, so users can build anything with it: libraries, binaries, or even new UIs.

Features

  • BitTorrent V1 protocol
  • Multi-platform
  • Support for magnet links
  • Async I/O with tokio
  • UDP connections with trackers
  • Daemon detached from UI

Example

To download a torrent, we can simply run the daemon and send messages to it.

    use vincenzo::daemon::Daemon;
    use vincenzo::daemon::DaemonMsg;
    use vincenzo::magnet::Magnet;
    use tokio::spawn;
    use tokio::sync::oneshot;

    #[tokio::main]
    async fn main() {
        let download_dir = "/home/gabriel/Downloads".to_string();

        let mut daemon = Daemon::new(download_dir);
        let tx = daemon.ctx.tx.clone();

        spawn(async move {
            daemon.run().await.unwrap();
        });

        let magnet = Magnet::new("magnet:?xt=urn:btih:ab6ad7ff24b5ed3a61352a1f1a7811a8c3cc6dde&dn=archlinux-2023.09.01-x86_64.iso").unwrap();

        // identifier of the torrent
        let info_hash = magnet.parse_xt();

        tx.send(DaemonMsg::NewTorrent(magnet)).await.unwrap();

        // get information about the torrent download
        let (otx, orx) = oneshot::channel();

        tx.send(DaemonMsg::RequestTorrentState(info_hash, otx)).await.unwrap();
        let torrent_state = orx.await.unwrap();

        // TorrentState {
        //     name: "torrent name",
        //     download_rate: 999999,
        //     ...
        // }
    }

Supported BEPs

  • BEP 0003 - The BitTorrent Protocol Specification
  • BEP 0009 - Extension for Peers to Send Metadata Files
  • BEP 0010 - Extension Protocol
  • BEP 0015 - UDP Tracker Protocol
  • BEP 0023 - Tracker Returns Compact Peer Lists

Dependencies

~11–24MB
~285K SLoC