aquatic_ws_protocol: refactor, moving code into submodules

This commit is contained in:
Joakim Frostegård 2021-10-16 01:46:32 +02:00
parent 7c833958d8
commit 71c43aca47
11 changed files with 345 additions and 304 deletions

View file

@ -0,0 +1,29 @@
use serde::{Deserialize, Serialize};
use crate::common::*;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ScrapeRequestInfoHashes {
Single(InfoHash),
Multiple(Vec<InfoHash>),
}
impl ScrapeRequestInfoHashes {
pub fn as_vec(self) -> Vec<InfoHash> {
match self {
Self::Single(info_hash) => vec![info_hash],
Self::Multiple(info_hashes) => info_hashes,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ScrapeRequest {
pub action: ScrapeAction,
// If omitted, scrape for all torrents, apparently
// There is some kind of parsing here too which accepts a single info hash
// and puts it into a vector
#[serde(rename = "info_hash")]
pub info_hashes: Option<ScrapeRequestInfoHashes>,
}