mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
udp: reorder declarations in common.rs
This commit is contained in:
parent
be5165bcf2
commit
c48a83b06a
1 changed files with 65 additions and 65 deletions
|
|
@ -16,6 +16,34 @@ use crate::config::Config;
|
||||||
|
|
||||||
pub const BUFFER_SIZE: usize = 8192;
|
pub const BUFFER_SIZE: usize = 8192;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub enum IpVersion {
|
||||||
|
V4,
|
||||||
|
V6,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "prometheus")]
|
||||||
|
impl IpVersion {
|
||||||
|
pub fn prometheus_str(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::V4 => "4",
|
||||||
|
Self::V6 => "6",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub struct SocketWorkerIndex(pub usize);
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||||
|
pub struct SwarmWorkerIndex(pub usize);
|
||||||
|
|
||||||
|
impl SwarmWorkerIndex {
|
||||||
|
pub fn from_info_hash(config: &Config, info_hash: InfoHash) -> Self {
|
||||||
|
Self(info_hash.0[0] as usize % config.swarm_workers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PendingScrapeRequest {
|
pub struct PendingScrapeRequest {
|
||||||
pub slab_key: usize,
|
pub slab_key: usize,
|
||||||
|
|
@ -41,18 +69,6 @@ pub enum ConnectedResponse {
|
||||||
Scrape(PendingScrapeResponse),
|
Scrape(PendingScrapeResponse),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct SocketWorkerIndex(pub usize);
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
|
||||||
pub struct SwarmWorkerIndex(pub usize);
|
|
||||||
|
|
||||||
impl SwarmWorkerIndex {
|
|
||||||
pub fn from_info_hash(config: &Config, info_hash: InfoHash) -> Self {
|
|
||||||
Self(info_hash.0[0] as usize % config.swarm_workers)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ConnectedRequestSender {
|
pub struct ConnectedRequestSender {
|
||||||
index: SocketWorkerIndex,
|
index: SocketWorkerIndex,
|
||||||
senders: Vec<Sender<(SocketWorkerIndex, ConnectedRequest, CanonicalSocketAddr)>>,
|
senders: Vec<Sender<(SocketWorkerIndex, ConnectedRequest, CanonicalSocketAddr)>>,
|
||||||
|
|
@ -155,11 +171,38 @@ impl ConnectedResponseSender {
|
||||||
|
|
||||||
pub type ConnectedResponseReceiver = Receiver<(CanonicalSocketAddr, ConnectedResponse)>;
|
pub type ConnectedResponseReceiver = Receiver<(CanonicalSocketAddr, ConnectedResponse)>;
|
||||||
|
|
||||||
pub enum StatisticsMessage {
|
#[derive(Clone)]
|
||||||
Ipv4PeerHistogram(Histogram<u64>),
|
pub struct Statistics {
|
||||||
Ipv6PeerHistogram(Histogram<u64>),
|
pub socket: Vec<CachePaddedArc<IpVersionStatistics<SocketWorkerStatistics>>>,
|
||||||
PeerAdded(PeerId),
|
pub swarm: Vec<CachePaddedArc<IpVersionStatistics<SwarmWorkerStatistics>>>,
|
||||||
PeerRemoved(PeerId),
|
}
|
||||||
|
|
||||||
|
impl Statistics {
|
||||||
|
pub fn new(config: &Config) -> Self {
|
||||||
|
Self {
|
||||||
|
socket: repeat_with(Default::default)
|
||||||
|
.take(config.socket_workers)
|
||||||
|
.collect(),
|
||||||
|
swarm: repeat_with(Default::default)
|
||||||
|
.take(config.swarm_workers)
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct IpVersionStatistics<T> {
|
||||||
|
pub ipv4: T,
|
||||||
|
pub ipv6: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IpVersionStatistics<T> {
|
||||||
|
pub fn by_ip_version(&self, ip_version: IpVersion) -> &T {
|
||||||
|
match ip_version {
|
||||||
|
IpVersion::V4 => &self.ipv4,
|
||||||
|
IpVersion::V6 => &self.ipv6,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -181,54 +224,11 @@ pub struct SwarmWorkerStatistics {
|
||||||
pub peers: AtomicUsize,
|
pub peers: AtomicUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
pub enum StatisticsMessage {
|
||||||
pub enum IpVersion {
|
Ipv4PeerHistogram(Histogram<u64>),
|
||||||
V4,
|
Ipv6PeerHistogram(Histogram<u64>),
|
||||||
V6,
|
PeerAdded(PeerId),
|
||||||
}
|
PeerRemoved(PeerId),
|
||||||
|
|
||||||
#[cfg(feature = "prometheus")]
|
|
||||||
impl IpVersion {
|
|
||||||
pub fn prometheus_str(&self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
Self::V4 => "4",
|
|
||||||
Self::V6 => "6",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct IpVersionStatistics<T> {
|
|
||||||
pub ipv4: T,
|
|
||||||
pub ipv6: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> IpVersionStatistics<T> {
|
|
||||||
pub fn by_ip_version(&self, ip_version: IpVersion) -> &T {
|
|
||||||
match ip_version {
|
|
||||||
IpVersion::V4 => &self.ipv4,
|
|
||||||
IpVersion::V6 => &self.ipv6,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Statistics {
|
|
||||||
pub socket: Vec<CachePaddedArc<IpVersionStatistics<SocketWorkerStatistics>>>,
|
|
||||||
pub swarm: Vec<CachePaddedArc<IpVersionStatistics<SwarmWorkerStatistics>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Statistics {
|
|
||||||
pub fn new(config: &Config) -> Self {
|
|
||||||
Self {
|
|
||||||
socket: repeat_with(Default::default)
|
|
||||||
.take(config.socket_workers)
|
|
||||||
.collect(),
|
|
||||||
swarm: repeat_with(Default::default)
|
|
||||||
.take(config.swarm_workers)
|
|
||||||
.collect(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue