gosh_dl/protocol/torrent.rs
1//! Torrent-specific protocol types
2//!
3//! Types for representing torrent metadata and peer information.
4
5use chrono::{DateTime, Utc};
6use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8
9/// Information about a file in a torrent
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct TorrentFile {
12 /// File index
13 pub index: usize,
14 /// File path within torrent
15 pub path: PathBuf,
16 /// File size in bytes
17 pub size: u64,
18 /// Whether this file is selected for download
19 pub selected: bool,
20 /// Bytes completed for this file
21 pub completed: u64,
22}
23
24/// Parsed torrent metadata
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct TorrentInfo {
27 /// Info hash (hex string)
28 pub info_hash: String,
29 /// Torrent name
30 pub name: String,
31 /// Total size in bytes
32 pub total_size: u64,
33 /// Piece length
34 pub piece_length: u64,
35 /// Number of pieces
36 pub num_pieces: usize,
37 /// Files in the torrent
38 pub files: Vec<TorrentFile>,
39 /// Announce URL
40 pub announce: Option<String>,
41 /// Announce list
42 pub announce_list: Vec<Vec<String>>,
43 /// Creation date
44 pub creation_date: Option<DateTime<Utc>>,
45 /// Comment
46 pub comment: Option<String>,
47 /// Created by
48 pub created_by: Option<String>,
49}
50
51/// Torrent status information embedded in DownloadStatus
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct TorrentStatusInfo {
54 /// Files in the torrent
55 pub files: Vec<TorrentFile>,
56 /// Piece length
57 pub piece_length: u64,
58 /// Number of pieces
59 pub pieces_count: usize,
60 /// Is private torrent
61 pub private: bool,
62}
63
64/// Peer information (for torrents)
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct PeerInfo {
67 /// Peer ID (if known)
68 pub id: Option<String>,
69 /// IP address
70 pub ip: String,
71 /// Port
72 pub port: u16,
73 /// Client name (if known)
74 pub client: Option<String>,
75 /// Download speed from this peer
76 pub download_speed: u64,
77 /// Upload speed to this peer
78 pub upload_speed: u64,
79 /// Progress of peer (0.0 - 1.0)
80 pub progress: f64,
81 /// Whether we're choking them
82 pub am_choking: bool,
83 /// Whether they're choking us
84 pub peer_choking: bool,
85}