From b184354c2f749a8145188582369201c9b66932cb Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 24 Mar 2024 18:27:08 +1100 Subject: [PATCH] Make the announce info field optional --- crates/librqbit/src/create_torrent_file.rs | 2 +- crates/librqbit/src/session.rs | 5 +---- crates/librqbit_core/src/torrent_metainfo.rs | 5 +++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/librqbit/src/create_torrent_file.rs b/crates/librqbit/src/create_torrent_file.rs index 4cddbc8a..fbb95401 100644 --- a/crates/librqbit/src/create_torrent_file.rs +++ b/crates/librqbit/src/create_torrent_file.rs @@ -200,7 +200,7 @@ pub async fn create_torrent<'a>( let info_hash = compute_info_hash(&info).context("error computing info hash")?; Ok(CreateTorrentResult { meta: TorrentMetaV1Owned { - announce: b""[..].into(), + announce: None, announce_list: Vec::new(), info, comment: None, diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index 131756d3..010376ed 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -721,10 +721,7 @@ impl Session { .map(|t| ByteString(t.into_bytes())) .collect(); let info = TorrentMetaV1Owned { - announce: trackers - .first() - .cloned() - .unwrap_or_else(|| ByteString(b"http://retracker.local/announce".to_vec())), + announce: trackers.first().cloned(), announce_list: vec![trackers], info: storrent.info, comment: None, diff --git a/crates/librqbit_core/src/torrent_metainfo.rs b/crates/librqbit_core/src/torrent_metainfo.rs index 3734e64a..0ec98c8d 100644 --- a/crates/librqbit_core/src/torrent_metainfo.rs +++ b/crates/librqbit_core/src/torrent_metainfo.rs @@ -29,7 +29,8 @@ pub fn torrent_from_bytes<'de, ByteBuf: Deserialize<'de>>( /// A parsed .torrent file. #[derive(Serialize, Deserialize, Debug, Clone)] pub struct TorrentMetaV1 { - pub announce: BufType, + #[serde(skip_serializing_if = "Option::is_none")] + pub announce: Option, #[serde( rename = "announce-list", default = "Vec::new", @@ -59,7 +60,7 @@ impl TorrentMetaV1 { if self.announce_list.iter().flatten().next().is_some() { return itertools::Either::Left(self.announce_list.iter().flatten()); } - itertools::Either::Right(once(&self.announce)) + itertools::Either::Right(self.announce.iter()) } }