Skip to content

Commit

Permalink
dev: use aquatic instead of local one
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Jul 15, 2024
1 parent a76280c commit 330f72d
Show file tree
Hide file tree
Showing 26 changed files with 247 additions and 319 deletions.
2 changes: 1 addition & 1 deletion docs/media/flamegraph_generated_without_sudo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 0 additions & 44 deletions packages/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use std::collections::BTreeMap;
use std::time::Duration;

use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes};
use info_hash::InfoHash;
use serde::Serialize;

pub mod info_hash;
pub mod pagination;
Expand All @@ -20,48 +18,6 @@ pub mod torrent_metrics;
/// Duration since the Unix Epoch.
pub type DurationSinceUnixEpoch = Duration;

/// Serializes a `DurationSinceUnixEpoch` as a Unix timestamp in milliseconds.
/// # Errors
///
/// Will return `serde::Serializer::Error` if unable to serialize the `unix_time_value`.
pub fn ser_unix_time_value<S: serde::Serializer>(unix_time_value: &DurationSinceUnixEpoch, ser: S) -> Result<S::Ok, S::Error> {
#[allow(clippy::cast_possible_truncation)]
ser.serialize_u64(unix_time_value.as_millis() as u64)
}

#[derive(Serialize)]
pub enum AnnounceEventSer {
Started,
Stopped,
Completed,
None,
}

/// Serializes a `Announce Event` as a enum.
///
/// # Errors
///
/// If will return an error if the internal serializer was to fail.
pub fn ser_announce_event<S: serde::Serializer>(announce_event: &AnnounceEvent, ser: S) -> Result<S::Ok, S::Error> {
let event_ser = match announce_event {
AnnounceEvent::Started => AnnounceEventSer::Started,
AnnounceEvent::Stopped => AnnounceEventSer::Stopped,
AnnounceEvent::Completed => AnnounceEventSer::Completed,
AnnounceEvent::None => AnnounceEventSer::None,
};

ser.serialize_some(&event_ser)
}

/// Serializes a `Announce Event` as a i64.
///
/// # Errors
///
/// If will return an error if the internal serializer was to fail.
pub fn ser_number_of_bytes<S: serde::Serializer>(number_of_bytes: &NumberOfBytes, ser: S) -> Result<S::Ok, S::Error> {
ser.serialize_i64(number_of_bytes.0.get())
}

/// IP version used by the peer to connect to the tracker: IPv4 or IPv6
#[derive(PartialEq, Eq, Debug)]
pub enum IPVersion {
Expand Down
Loading

0 comments on commit 330f72d

Please sign in to comment.