Merge pull request #97 from anacrolix/option-announce
Make the announce info field optional
This commit is contained in:
commit
24feb60001
3 changed files with 5 additions and 7 deletions
|
|
@ -200,7 +200,7 @@ pub async fn create_torrent<'a>(
|
||||||
let info_hash = compute_info_hash(&info).context("error computing info hash")?;
|
let info_hash = compute_info_hash(&info).context("error computing info hash")?;
|
||||||
Ok(CreateTorrentResult {
|
Ok(CreateTorrentResult {
|
||||||
meta: TorrentMetaV1Owned {
|
meta: TorrentMetaV1Owned {
|
||||||
announce: b""[..].into(),
|
announce: None,
|
||||||
announce_list: Vec::new(),
|
announce_list: Vec::new(),
|
||||||
info,
|
info,
|
||||||
comment: None,
|
comment: None,
|
||||||
|
|
|
||||||
|
|
@ -721,10 +721,7 @@ impl Session {
|
||||||
.map(|t| ByteString(t.into_bytes()))
|
.map(|t| ByteString(t.into_bytes()))
|
||||||
.collect();
|
.collect();
|
||||||
let info = TorrentMetaV1Owned {
|
let info = TorrentMetaV1Owned {
|
||||||
announce: trackers
|
announce: trackers.first().cloned(),
|
||||||
.first()
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_else(|| ByteString(b"http://retracker.local/announce".to_vec())),
|
|
||||||
announce_list: vec![trackers],
|
announce_list: vec![trackers],
|
||||||
info: storrent.info,
|
info: storrent.info,
|
||||||
comment: None,
|
comment: None,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ pub fn torrent_from_bytes<'de, ByteBuf: Deserialize<'de>>(
|
||||||
/// A parsed .torrent file.
|
/// A parsed .torrent file.
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct TorrentMetaV1<BufType> {
|
pub struct TorrentMetaV1<BufType> {
|
||||||
pub announce: BufType,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub announce: Option<BufType>,
|
||||||
#[serde(
|
#[serde(
|
||||||
rename = "announce-list",
|
rename = "announce-list",
|
||||||
default = "Vec::new",
|
default = "Vec::new",
|
||||||
|
|
@ -59,7 +60,7 @@ impl<BufType> TorrentMetaV1<BufType> {
|
||||||
if self.announce_list.iter().flatten().next().is_some() {
|
if self.announce_list.iter().flatten().next().is_some() {
|
||||||
return itertools::Either::Left(self.announce_list.iter().flatten());
|
return itertools::Either::Left(self.announce_list.iter().flatten());
|
||||||
}
|
}
|
||||||
itertools::Either::Right(once(&self.announce))
|
itertools::Either::Right(self.announce.iter())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue