From 38a8b45a37c8dd53c0fc3c102ac64742ae69550c Mon Sep 17 00:00:00 2001 From: Nikolay Komarevskiy Date: Wed, 17 Jul 2024 19:43:09 +0200 Subject: [PATCH] chore: reduce public APIs --- .../http_transport/dynamic_routing/health_check.rs | 4 ++-- .../src/agent/http_transport/dynamic_routing/mod.rs | 6 +++--- .../agent/http_transport/dynamic_routing/node.rs | 9 +++++---- .../http_transport/dynamic_routing/nodes_fetch.rs | 2 +- .../http_transport/dynamic_routing/test_utils.rs | 13 ++++++++----- .../http_transport/dynamic_routing/type_aliases.rs | 10 +++++----- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/ic-agent/src/agent/http_transport/dynamic_routing/health_check.rs b/ic-agent/src/agent/http_transport/dynamic_routing/health_check.rs index d45a480e..491f010b 100644 --- a/ic-agent/src/agent/http_transport/dynamic_routing/health_check.rs +++ b/ic-agent/src/agent/http_transport/dynamic_routing/health_check.rs @@ -157,12 +157,12 @@ impl HealthCheckActor { } /// The name of the health manager actor. -pub const HEALTH_MANAGER_ACTOR: &str = "HealthManagerActor"; +pub(super) const HEALTH_MANAGER_ACTOR: &str = "HealthManagerActor"; /// A struct managing the health checks of the nodes. /// It receives the fetched nodes from the `NodesFetchActor` and starts the health checks for them. /// It also receives the health status of the nodes from the `HealthCheckActor/s` and updates the routing snapshot. -pub struct HealthManagerActor { +pub(super) struct HealthManagerActor { /// The health checker. checker: Arc, /// The period of the health check. diff --git a/ic-agent/src/agent/http_transport/dynamic_routing/mod.rs b/ic-agent/src/agent/http_transport/dynamic_routing/mod.rs index 9b6b69de..07570f0f 100644 --- a/ic-agent/src/agent/http_transport/dynamic_routing/mod.rs +++ b/ic-agent/src/agent/http_transport/dynamic_routing/mod.rs @@ -3,7 +3,7 @@ pub mod dynamic_route_provider; /// Health check implementation. pub mod health_check; /// Messages used in dynamic routing. -pub mod messages; +pub(super) mod messages; /// Node implementation. pub mod node; /// Nodes fetch implementation. @@ -11,6 +11,6 @@ pub mod nodes_fetch; /// Routing snapshot implementation. pub mod snapshot; #[cfg(test)] -pub mod test_utils; +pub(super) mod test_utils; /// Type aliases used in dynamic routing. -pub mod type_aliases; +pub(super) mod type_aliases; diff --git a/ic-agent/src/agent/http_transport/dynamic_routing/node.rs b/ic-agent/src/agent/http_transport/dynamic_routing/node.rs index baf9d185..dd87116c 100644 --- a/ic-agent/src/agent/http_transport/dynamic_routing/node.rs +++ b/ic-agent/src/agent/http_transport/dynamic_routing/node.rs @@ -1,8 +1,9 @@ use url::Url; -use crate::agent::ApiBoundaryNode; - -use super::dynamic_route_provider::DynamicRouteProviderError; +use crate::agent::{ + http_transport::dynamic_routing::dynamic_route_provider::DynamicRouteProviderError, + ApiBoundaryNode, +}; /// Represents a node in the dynamic routing. #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -52,7 +53,7 @@ impl TryFrom<&ApiBoundaryNode> for Node { } /// Checks if the given domain is a valid URL. -pub fn is_valid_domain>(domain: S) -> bool { +fn is_valid_domain>(domain: S) -> bool { // Prepend scheme to make it a valid URL let url_string = format!("http://{}", domain.as_ref()); Url::parse(&url_string).is_ok() diff --git a/ic-agent/src/agent/http_transport/dynamic_routing/nodes_fetch.rs b/ic-agent/src/agent/http_transport/dynamic_routing/nodes_fetch.rs index 88fa372f..8cbdb474 100644 --- a/ic-agent/src/agent/http_transport/dynamic_routing/nodes_fetch.rs +++ b/ic-agent/src/agent/http_transport/dynamic_routing/nodes_fetch.rs @@ -83,7 +83,7 @@ impl Fetch for NodesFetcher { } /// A struct representing the actor responsible for fetching existing nodes and communicating it with the listener. -pub struct NodesFetchActor { +pub(super) struct NodesFetchActor { /// The fetcher object responsible for fetching the nodes. fetcher: Arc, /// Time period between fetches. diff --git a/ic-agent/src/agent/http_transport/dynamic_routing/test_utils.rs b/ic-agent/src/agent/http_transport/dynamic_routing/test_utils.rs index 92de4c78..60004d75 100644 --- a/ic-agent/src/agent/http_transport/dynamic_routing/test_utils.rs +++ b/ic-agent/src/agent/http_transport/dynamic_routing/test_utils.rs @@ -17,14 +17,17 @@ use crate::agent::http_transport::{ route_provider::RouteProvider, }; -pub fn route_n_times(n: usize, f: Arc) -> Vec { +pub(super) fn route_n_times(n: usize, f: Arc) -> Vec { (0..n) .map(|_| f.route().unwrap().domain().unwrap().to_string()) .collect() } -pub fn assert_routed_domains(actual: Vec, expected: Vec, expected_repetitions: usize) -where +pub(super) fn assert_routed_domains( + actual: Vec, + expected: Vec, + expected_repetitions: usize, +) where T: AsRef + Eq + Hash + Debug + Ord, { fn build_count_map(items: &[T]) -> HashMap<&T, usize> @@ -54,7 +57,7 @@ where } #[derive(Debug)] -pub struct NodesFetcherMock { +pub(super) struct NodesFetcherMock { // A set of nodes, existing in the topology. pub nodes: AtomicSwap>, } @@ -86,7 +89,7 @@ impl NodesFetcherMock { } #[derive(Debug)] -pub struct NodeHealthCheckerMock { +pub(super) struct NodeHealthCheckerMock { healthy_nodes: Arc>>, } diff --git a/ic-agent/src/agent/http_transport/dynamic_routing/type_aliases.rs b/ic-agent/src/agent/http_transport/dynamic_routing/type_aliases.rs index 04f32b66..6be931fb 100644 --- a/ic-agent/src/agent/http_transport/dynamic_routing/type_aliases.rs +++ b/ic-agent/src/agent/http_transport/dynamic_routing/type_aliases.rs @@ -3,16 +3,16 @@ use std::sync::Arc; use tokio::sync::{mpsc, watch}; /// A type alias for the sender end of a watch channel. -pub type SenderWatch = watch::Sender>; +pub(super) type SenderWatch = watch::Sender>; /// A type alias for the receiver end of a watch channel. -pub type ReceiverWatch = watch::Receiver>; +pub(super) type ReceiverWatch = watch::Receiver>; /// A type alias for the sender end of a multi-producer, single-consumer channel. -pub type SenderMpsc = mpsc::Sender; +pub(super) type SenderMpsc = mpsc::Sender; /// A type alias for the receiver end of a multi-producer, single-consumer channel. -pub type ReceiverMpsc = mpsc::Receiver; +pub(super) type ReceiverMpsc = mpsc::Receiver; /// A type alias for an atomic swap operation on a shared value. -pub type AtomicSwap = Arc>; +pub(super) type AtomicSwap = Arc>;