1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! A library for working with the BitTorrent protocol V1.
//!
//! This is the library created for Vincenzo, a BitTorrent client. It uses this
//! library to create both the daemon and ui binaries.
//!
//! This crate contains building blocks for developing software using this
//! protocol in a high-level manner.
//!
//! A few ideas that benefit from a distributed and decentralized protocol:
//!
//! * A program that synchronizes files between multiple peers.
//! * A fully encrypted chat client with files.
//!
//! # Example
//!
//! This is how you can download torrents using just the daemon,
//! we 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,
//! // ...
//! // }
//! }
//! ```