Crates.io | vincenzo |
lib.rs | vincenzo |
version | 0.0.3 |
source | src |
created_at | 2023-11-11 18:46:52.500765 |
updated_at | 2023-11-11 19:50:52.257114 |
description | A BitTorrent protocol library that powers the Vincenzo client. |
homepage | https://vincenzo.rs |
repository | https://github.com/gabrieldemian/vincenzo |
max_upload_size | |
id | 1032243 |
size | 605,513 |
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.
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,
// ...
// }
}