mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 09:45:31 +00:00
http_protocol: add AnnounceEvent::as_str, run cargo fmt
This commit is contained in:
parent
b9c029b5ed
commit
87223f7952
2 changed files with 18 additions and 3 deletions
|
|
@ -52,6 +52,17 @@ impl FromStr for AnnounceEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AnnounceEvent {
|
||||||
|
pub fn as_str(&self) -> Option<&str> {
|
||||||
|
match self {
|
||||||
|
Self::Started => Some("started"),
|
||||||
|
Self::Stopped => Some("stopped"),
|
||||||
|
Self::Completed => Some("completed"),
|
||||||
|
Self::Empty => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for InfoHash {
|
impl quickcheck::Arbitrary for InfoHash {
|
||||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ impl AnnounceRequest {
|
||||||
pub fn from_query_string(query_string: &str) -> anyhow::Result<Self> {
|
pub fn from_query_string(query_string: &str) -> anyhow::Result<Self> {
|
||||||
// -- Parse key-value pairs
|
// -- Parse key-value pairs
|
||||||
|
|
||||||
let mut opt_info_hash= None;
|
let mut opt_info_hash = None;
|
||||||
let mut opt_peer_id = None;
|
let mut opt_peer_id = None;
|
||||||
let mut opt_port = None;
|
let mut opt_port = None;
|
||||||
let mut opt_bytes_left = None;
|
let mut opt_bytes_left = None;
|
||||||
|
|
@ -283,9 +283,13 @@ impl Request {
|
||||||
let query_string = split_parts.next().with_context(|| "no query string")?;
|
let query_string = split_parts.next().with_context(|| "no query string")?;
|
||||||
|
|
||||||
if location == "/announce" {
|
if location == "/announce" {
|
||||||
Ok(Request::Announce(AnnounceRequest::from_query_string(query_string)?))
|
Ok(Request::Announce(AnnounceRequest::from_query_string(
|
||||||
|
query_string,
|
||||||
|
)?))
|
||||||
} else {
|
} else {
|
||||||
Ok(Request::Scrape(ScrapeRequest::from_query_string(query_string)?))
|
Ok(Request::Scrape(ScrapeRequest::from_query_string(
|
||||||
|
query_string,
|
||||||
|
)?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue