Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
config: add network scheduling limits
Quaylyn Rimer committed 3 months ago
commit b332c4bfc4c41a4a2d8d7e7dcf1be537342949cc
parent dd1af881731945840df147af94993168423545ee
1 file changed +248 -1
modified crates/radicle/src/node/config.rs
@@ -1,7 +1,7 @@
use std::collections::HashSet;
use std::ops::Deref;
use std::str::FromStr;
-
use std::{fmt, net};
+
use std::{fmt, net, time};

use cyphernet::addr::PeerAddr;
use localtime::LocalDuration;
@@ -137,6 +137,9 @@ pub struct Limits {
    /// Connection limits.
    pub connection: ConnectionLimits,

+
    /// Network scheduling limits.
+
    pub network: NetworkLimits,
+

    /// Channel limits.
    pub fetch_pack_receive: FetchPackSizeLimit,
}
@@ -263,6 +266,35 @@ pub struct RateLimits {
    pub outbound: LimitRateOutbound,
}

+
/// Network scheduling limits.
+
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
+
#[serde(default, rename_all = "camelCase")]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+
pub struct NetworkLimits {
+
    /// How often to run the "idle" task.
+
    pub idle_interval: LimitIdleInterval,
+
    /// How often to run the "gossip" task.
+
    pub gossip_interval: LimitGossipInterval,
+
    /// How often to run the "sync" task.
+
    pub sync_interval: LimitSyncInterval,
+
    /// How often to run the "announce" task.
+
    pub announce_interval: LimitAnnounceInterval,
+
    /// How often to run the "prune" task.
+
    pub prune_interval: LimitPruneInterval,
+
    /// How long before a keep-alive ping is sent.
+
    pub keep_alive_delta: LimitKeepAliveDelta,
+
    /// Fetch timeout, in seconds.
+
    pub fetch_timeout_secs: LimitFetchTimeoutSecs,
+
    /// Target number of outbound peers.
+
    pub target_outbound_peers: TargetOutboundPeers,
+
    /// Minimum amount of time to wait before reconnecting to a peer.
+
    pub min_reconnection_delta: LimitMinReconnectionDelta,
+
    /// Maximum amount of time to wait before reconnecting to a peer.
+
    pub max_reconnection_delta: LimitMaxReconnectionDelta,
+
    /// Connection retry delta used for peers that failed to connect previously.
+
    pub connection_retry_delta: LimitConnectionRetryDelta,
+
}
+

/// Full address used to connect to a remote node.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(
@@ -585,6 +617,213 @@ impl From<LimitGossipMaxAge> for LocalDuration {
    }
}

+
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
+
#[serde(transparent)]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+
pub struct LimitIdleInterval(localtime::LocalDuration);
+

+
impl Default for LimitIdleInterval {
+
    fn default() -> Self {
+
        Self(localtime::LocalDuration::from_secs(30))
+
    }
+
}
+

+
impl From<LimitIdleInterval> for LocalDuration {
+
    fn from(value: LimitIdleInterval) -> Self {
+
        value.0
+
    }
+
}
+

+
impl From<LocalDuration> for LimitIdleInterval {
+
    fn from(value: LocalDuration) -> Self {
+
        Self(value)
+
    }
+
}
+

+
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
+
#[serde(transparent)]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+
pub struct LimitGossipInterval(localtime::LocalDuration);
+

+
impl Default for LimitGossipInterval {
+
    fn default() -> Self {
+
        Self(localtime::LocalDuration::from_secs(6))
+
    }
+
}
+

+
impl From<LimitGossipInterval> for LocalDuration {
+
    fn from(value: LimitGossipInterval) -> Self {
+
        value.0
+
    }
+
}
+

+
impl From<LocalDuration> for LimitGossipInterval {
+
    fn from(value: LocalDuration) -> Self {
+
        Self(value)
+
    }
+
}
+

+
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
+
#[serde(transparent)]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+
pub struct LimitSyncInterval(localtime::LocalDuration);
+

+
impl Default for LimitSyncInterval {
+
    fn default() -> Self {
+
        Self(localtime::LocalDuration::from_secs(60))
+
    }
+
}
+

+
impl From<LimitSyncInterval> for LocalDuration {
+
    fn from(value: LimitSyncInterval) -> Self {
+
        value.0
+
    }
+
}
+

+
impl From<LocalDuration> for LimitSyncInterval {
+
    fn from(value: LocalDuration) -> Self {
+
        Self(value)
+
    }
+
}
+

+
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
+
#[serde(transparent)]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+
pub struct LimitAnnounceInterval(localtime::LocalDuration);
+

+
impl Default for LimitAnnounceInterval {
+
    fn default() -> Self {
+
        Self(localtime::LocalDuration::from_mins(60))
+
    }
+
}
+

+
impl From<LimitAnnounceInterval> for LocalDuration {
+
    fn from(value: LimitAnnounceInterval) -> Self {
+
        value.0
+
    }
+
}
+

+
impl From<LocalDuration> for LimitAnnounceInterval {
+
    fn from(value: LocalDuration) -> Self {
+
        Self(value)
+
    }
+
}
+

+
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
+
#[serde(transparent)]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+
pub struct LimitPruneInterval(localtime::LocalDuration);
+

+
impl Default for LimitPruneInterval {
+
    fn default() -> Self {
+
        Self(localtime::LocalDuration::from_mins(30))
+
    }
+
}
+

+
impl From<LimitPruneInterval> for LocalDuration {
+
    fn from(value: LimitPruneInterval) -> Self {
+
        value.0
+
    }
+
}
+

+
impl From<LocalDuration> for LimitPruneInterval {
+
    fn from(value: LocalDuration) -> Self {
+
        Self(value)
+
    }
+
}
+

+
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
+
#[serde(transparent)]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+
pub struct LimitKeepAliveDelta(localtime::LocalDuration);
+

+
impl Default for LimitKeepAliveDelta {
+
    fn default() -> Self {
+
        Self(localtime::LocalDuration::from_mins(1))
+
    }
+
}
+

+
impl From<LimitKeepAliveDelta> for LocalDuration {
+
    fn from(value: LimitKeepAliveDelta) -> Self {
+
        value.0
+
    }
+
}
+

+
impl From<LocalDuration> for LimitKeepAliveDelta {
+
    fn from(value: LocalDuration) -> Self {
+
        Self(value)
+
    }
+
}
+

+
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
+
#[serde(transparent)]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+
pub struct LimitMinReconnectionDelta(localtime::LocalDuration);
+

+
impl Default for LimitMinReconnectionDelta {
+
    fn default() -> Self {
+
        Self(localtime::LocalDuration::from_secs(3))
+
    }
+
}
+

+
impl From<LimitMinReconnectionDelta> for LocalDuration {
+
    fn from(value: LimitMinReconnectionDelta) -> Self {
+
        value.0
+
    }
+
}
+

+
impl From<LocalDuration> for LimitMinReconnectionDelta {
+
    fn from(value: LocalDuration) -> Self {
+
        Self(value)
+
    }
+
}
+

+
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
+
#[serde(transparent)]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+
pub struct LimitMaxReconnectionDelta(localtime::LocalDuration);
+

+
impl Default for LimitMaxReconnectionDelta {
+
    fn default() -> Self {
+
        Self(localtime::LocalDuration::from_mins(60))
+
    }
+
}
+

+
impl From<LimitMaxReconnectionDelta> for LocalDuration {
+
    fn from(value: LimitMaxReconnectionDelta) -> Self {
+
        value.0
+
    }
+
}
+

+
impl From<LocalDuration> for LimitMaxReconnectionDelta {
+
    fn from(value: LocalDuration) -> Self {
+
        Self(value)
+
    }
+
}
+

+
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
+
#[serde(transparent)]
+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+
pub struct LimitConnectionRetryDelta(localtime::LocalDuration);
+

+
impl Default for LimitConnectionRetryDelta {
+
    fn default() -> Self {
+
        Self(localtime::LocalDuration::from_mins(10))
+
    }
+
}
+

+
impl From<LimitConnectionRetryDelta> for LocalDuration {
+
    fn from(value: LimitConnectionRetryDelta) -> Self {
+
        value.0
+
    }
+
}
+

+
impl From<LocalDuration> for LimitConnectionRetryDelta {
+
    fn from(value: LocalDuration) -> Self {
+
        Self(value)
+
    }
+
}
+

/// Create a new type (`$name`) around a given type (`$type`), with a provided
/// default (`$default`).
///
@@ -642,6 +881,14 @@ wrapper!(
    },
    Copy
);
+
wrapper!(LimitFetchTimeoutSecs, u64, 3, Copy);
+
wrapper!(TargetOutboundPeers, usize, 8, Copy);
+

+
impl From<LimitFetchTimeoutSecs> for time::Duration {
+
    fn from(value: LimitFetchTimeoutSecs) -> Self {
+
        time::Duration::from_secs(value.0)
+
    }
+
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]