mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
aquatic_http protocol: refactor into more submodules, other fixes
This commit is contained in:
parent
52cc7d8acb
commit
7419c51434
9 changed files with 303 additions and 290 deletions
56
aquatic_http/src/lib/protocol/common.rs
Normal file
56
aquatic_http/src/lib/protocol/common.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use super::utils::*;
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct PeerId(
|
||||
#[serde(
|
||||
serialize_with = "serialize_20_bytes",
|
||||
)]
|
||||
pub [u8; 20]
|
||||
);
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct InfoHash(
|
||||
#[serde(
|
||||
serialize_with = "serialize_20_bytes",
|
||||
)]
|
||||
pub [u8; 20]
|
||||
);
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum AnnounceEvent {
|
||||
Started,
|
||||
Stopped,
|
||||
Completed,
|
||||
Empty
|
||||
}
|
||||
|
||||
|
||||
impl Default for AnnounceEvent {
|
||||
fn default() -> Self {
|
||||
Self::Empty
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl FromStr for AnnounceEvent {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(value: &str) -> std::result::Result<Self, String> {
|
||||
match value {
|
||||
"started" => Ok(Self::Started),
|
||||
"stopped" => Ok(Self::Stopped),
|
||||
"completed" => Ok(Self::Completed),
|
||||
"empty" => Ok(Self::Empty),
|
||||
value => Err(format!("Unknown value: {}", value))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue