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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//! Torrent metainfo handling ([BEP-3], [BEP-9], [BEP-52]).
//!
//! This module provides types for working with torrent files and magnet links,
//! supporting both BitTorrent v1 and v2 torrents.
//!
//! # Overview
//!
//! A torrent file (`.torrent`) contains metadata about files to be shared:
//! - File names, sizes, and directory structure
//! - Piece hashes for data integrity verification
//! - Tracker URLs for peer discovery
//!
//! The [`Metainfo`] struct represents a parsed torrent file, while [`MagnetLink`]
//! handles magnet URIs which contain only an info hash and optional metadata.
//!
//! # Examples
//!
//! ## Parsing a torrent file
//!
//! ```no_run
//! use rbit::metainfo::Metainfo;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let data = std::fs::read("example.torrent")?;
//! let torrent = Metainfo::from_bytes(&data)?;
//!
//! println!("Name: {}", torrent.info.name);
//! println!("Info hash: {}", torrent.info_hash);
//! println!("Total size: {} bytes", torrent.info.total_length);
//! println!("Piece length: {} bytes", torrent.info.piece_length);
//! println!("Number of pieces: {}", torrent.info.piece_count());
//!
//! // List files in a multi-file torrent
//! for file in &torrent.info.files {
//! println!(" {} ({} bytes)", file.path.display(), file.length);
//! }
//!
//! // Get tracker URLs
//! for tracker in torrent.trackers() {
//! println!("Tracker: {}", tracker);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Parsing a magnet link
//!
//! ```
//! use rbit::metainfo::MagnetLink;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let magnet = MagnetLink::parse(
//! "magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a\
//! &dn=Example%20File&tr=http%3A%2F%2Ftracker.example.com%2Fannounce"
//! )?;
//!
//! println!("Info hash: {}", magnet.info_hash);
//! println!("Display name: {:?}", magnet.display_name);
//! println!("Trackers: {:?}", magnet.trackers);
//!
//! // Convert back to a magnet URI
//! let uri = magnet.to_uri();
//! # Ok(())
//! # }
//! ```
//!
//! ## Working with info hashes
//!
//! ```
//! use rbit::metainfo::InfoHash;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Parse from hex string
//! let hash = InfoHash::from_hex("c12fe1c06bba254a9dc9f519b335aa7c1367a88a")?;
//!
//! // Check version
//! assert!(hash.is_v1()); // 20-byte SHA1 hash
//!
//! // Convert to bytes
//! let bytes = hash.as_bytes();
//! assert_eq!(bytes.len(), 20);
//!
//! // Convert back to hex
//! let hex = hash.to_hex();
//! # Ok(())
//! # }
//! ```
//!
//! # Torrent Structure
//!
//! A torrent file contains:
//!
//! - **info** - Core torrent metadata (hashed to create the info hash)
//! - `name` - Suggested file/directory name
//! - `piece length` - Size of each piece in bytes
//! - `pieces` - Concatenated SHA1 hashes of each piece
//! - `length` - Total size (single-file) OR `files` list (multi-file)
//! - **announce** - Primary tracker URL
//! - **announce-list** - Additional tracker tiers (BEP-12)
//! - **creation date** - Unix timestamp when created
//! - **comment** - Optional comment
//! - **created by** - Client that created the torrent
//!
//! [BEP-3]: http://bittorrent.org/beps/bep_0003.html
//! [BEP-9]: http://bittorrent.org/beps/bep_0009.html
//! [BEP-52]: http://bittorrent.org/beps/bep_0052.html
pub use ;
pub use MetainfoError;
pub use ;
pub use ;
pub use MagnetLink;
pub use ;
pub use ;