Skip to content

Commit cb38300

Browse files
chore: reduce public APIs
1 parent df7b557 commit cb38300

File tree

9 files changed

+41
-36
lines changed

9 files changed

+41
-36
lines changed

ic-agent/src/agent/http_transport/dynamic_routing/health_check.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ const CHANNEL_BUFFER: usize = 128;
2323

2424
/// A trait representing a health check of the node.
2525
#[async_trait]
26-
pub trait HealthCheck: Send + Sync + Debug {
26+
pub(crate) trait HealthCheck: Send + Sync + Debug {
2727
/// Checks the health of the node.
2828
async fn check(&self, node: &Node) -> Result<HealthCheckStatus, DynamicRouteProviderError>;
2929
}
3030

3131
/// A struct representing the health check status of the node.
3232
#[derive(Clone, PartialEq, Debug, Default)]
33-
pub struct HealthCheckStatus {
33+
pub(crate) struct HealthCheckStatus {
3434
latency: Option<Duration>,
3535
}
3636

@@ -53,7 +53,7 @@ impl HealthCheckStatus {
5353

5454
/// A struct implementing the `HealthCheck` for the nodes.
5555
#[derive(Debug)]
56-
pub struct HealthChecker {
56+
pub(crate) struct HealthChecker {
5757
http_client: Client,
5858
timeout: Duration,
5959
}
@@ -157,12 +157,12 @@ impl HealthCheckActor {
157157
}
158158

159159
/// The name of the health manager actor.
160-
pub const HEALTH_MANAGER_ACTOR: &str = "HealthManagerActor";
160+
pub(super) const HEALTH_MANAGER_ACTOR: &str = "HealthManagerActor";
161161

162162
/// A struct managing the health checks of the nodes.
163163
/// It receives the fetched nodes from the `NodesFetchActor` and starts the health checks for them.
164164
/// It also receives the health status of the nodes from the `HealthCheckActor/s` and updates the routing snapshot.
165-
pub struct HealthManagerActor<S> {
165+
pub(super) struct HealthManagerActor<S> {
166166
/// The health checker.
167167
checker: Arc<dyn HealthCheck>,
168168
/// The period of the health check.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//! Dynamic routing implementation.
2-
pub mod dynamic_route_provider;
2+
pub(crate) mod dynamic_route_provider;
33
/// Health check implementation.
4-
pub mod health_check;
4+
pub(super) mod health_check;
55
/// Messages used in dynamic routing.
6-
pub mod messages;
6+
pub(super) mod messages;
77
/// Node implementation.
8-
pub mod node;
8+
pub(crate) mod node;
99
/// Nodes fetch implementation.
10-
pub mod nodes_fetch;
10+
pub(super) mod nodes_fetch;
1111
/// Routing snapshot implementation.
12-
pub mod snapshot;
12+
pub(crate) mod snapshot;
1313
#[cfg(test)]
14-
pub mod test_utils;
14+
pub(super) mod test_utils;
1515
/// Type aliases used in dynamic routing.
16-
pub mod type_aliases;
16+
pub(super) mod type_aliases;

ic-agent/src/agent/http_transport/dynamic_routing/node.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use url::Url;
22

3-
use crate::agent::ApiBoundaryNode;
4-
5-
use super::dynamic_route_provider::DynamicRouteProviderError;
3+
use crate::agent::{
4+
http_transport::dynamic_routing::dynamic_route_provider::DynamicRouteProviderError,
5+
ApiBoundaryNode,
6+
};
67

78
/// Represents a node in the dynamic routing.
89
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9-
pub struct Node {
10+
pub(crate) struct Node {
1011
domain: String,
1112
}
1213

@@ -52,7 +53,7 @@ impl TryFrom<&ApiBoundaryNode> for Node {
5253
}
5354

5455
/// Checks if the given domain is a valid URL.
55-
pub fn is_valid_domain<S: AsRef<str>>(domain: S) -> bool {
56+
fn is_valid_domain<S: AsRef<str>>(domain: S) -> bool {
5657
// Prepend scheme to make it a valid URL
5758
let url_string = format!("http://{}", domain.as_ref());
5859
Url::parse(&url_string).is_ok()

ic-agent/src/agent/http_transport/dynamic_routing/nodes_fetch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ const NODES_FETCH_ACTOR: &str = "NodesFetchActor";
2626

2727
/// Fetcher of nodes in the topology.
2828
#[async_trait]
29-
pub trait Fetch: Sync + Send + Debug {
29+
pub(crate) trait Fetch: Sync + Send + Debug {
3030
/// Fetches the nodes from the topology.
3131
async fn fetch(&self, url: Url) -> Result<Vec<Node>, DynamicRouteProviderError>;
3232
}
3333

3434
/// A struct representing the fetcher of the nodes from the topology.
3535
#[derive(Debug)]
36-
pub struct NodesFetcher {
36+
pub(crate) struct NodesFetcher {
3737
http_client: Client,
3838
subnet_id: Principal,
3939
}
@@ -83,7 +83,7 @@ impl Fetch for NodesFetcher {
8383
}
8484

8585
/// A struct representing the actor responsible for fetching existing nodes and communicating it with the listener.
86-
pub struct NodesFetchActor<S> {
86+
pub(super) struct NodesFetchActor<S> {
8787
/// The fetcher object responsible for fetching the nodes.
8888
fetcher: Arc<dyn Fetch>,
8989
/// Time period between fetches.

ic-agent/src/agent/http_transport/dynamic_routing/snapshot/latency_based_routing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct WeightedNode {
3030
/// In this routing strategy, nodes are randomly selected based on their averaged latency of the last WINDOW_SIZE health checks.
3131
/// Nodes with smaller average latencies are preferred for routing.
3232
#[derive(Default, Debug, Clone)]
33-
pub struct LatencyRoutingSnapshot {
33+
pub(crate) struct LatencyRoutingSnapshot {
3434
weighted_nodes: Vec<WeightedNode>,
3535
existing_nodes: HashSet<Node>,
3636
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// Snapshot of the routing table.
2-
pub mod latency_based_routing;
2+
pub(crate) mod latency_based_routing;
33
/// Node implementation.
4-
pub mod round_robin_routing;
4+
pub(crate) mod round_robin_routing;
55
/// Routing snapshot implementation.
6-
pub mod routing_snapshot;
6+
pub(crate) mod routing_snapshot;

ic-agent/src/agent/http_transport/dynamic_routing/test_utils.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ use crate::agent::http_transport::{
1717
route_provider::RouteProvider,
1818
};
1919

20-
pub fn route_n_times(n: usize, f: Arc<impl RouteProvider + ?Sized>) -> Vec<String> {
20+
pub(super) fn route_n_times(n: usize, f: Arc<impl RouteProvider + ?Sized>) -> Vec<String> {
2121
(0..n)
2222
.map(|_| f.route().unwrap().domain().unwrap().to_string())
2323
.collect()
2424
}
2525

26-
pub fn assert_routed_domains<T>(actual: Vec<T>, expected: Vec<T>, expected_repetitions: usize)
27-
where
26+
pub(super) fn assert_routed_domains<T>(
27+
actual: Vec<T>,
28+
expected: Vec<T>,
29+
expected_repetitions: usize,
30+
) where
2831
T: AsRef<str> + Eq + Hash + Debug + Ord,
2932
{
3033
fn build_count_map<T>(items: &[T]) -> HashMap<&T, usize>
@@ -54,7 +57,7 @@ where
5457
}
5558

5659
#[derive(Debug)]
57-
pub struct NodesFetcherMock {
60+
pub(super) struct NodesFetcherMock {
5861
// A set of nodes, existing in the topology.
5962
pub nodes: AtomicSwap<Vec<Node>>,
6063
}
@@ -86,7 +89,7 @@ impl NodesFetcherMock {
8689
}
8790

8891
#[derive(Debug)]
89-
pub struct NodeHealthCheckerMock {
92+
pub(super) struct NodeHealthCheckerMock {
9093
healthy_nodes: Arc<ArcSwap<HashSet<Node>>>,
9194
}
9295

ic-agent/src/agent/http_transport/dynamic_routing/type_aliases.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ use std::sync::Arc;
33
use tokio::sync::{mpsc, watch};
44

55
/// A type alias for the sender end of a watch channel.
6-
pub type SenderWatch<T> = watch::Sender<Option<T>>;
6+
pub(super) type SenderWatch<T> = watch::Sender<Option<T>>;
77

88
/// A type alias for the receiver end of a watch channel.
9-
pub type ReceiverWatch<T> = watch::Receiver<Option<T>>;
9+
pub(super) type ReceiverWatch<T> = watch::Receiver<Option<T>>;
1010

1111
/// A type alias for the sender end of a multi-producer, single-consumer channel.
12-
pub type SenderMpsc<T> = mpsc::Sender<T>;
12+
pub(super) type SenderMpsc<T> = mpsc::Sender<T>;
1313

1414
/// A type alias for the receiver end of a multi-producer, single-consumer channel.
15-
pub type ReceiverMpsc<T> = mpsc::Receiver<T>;
15+
pub(super) type ReceiverMpsc<T> = mpsc::Receiver<T>;
1616

1717
/// A type alias for an atomic swap operation on a shared value.
18-
pub type AtomicSwap<T> = Arc<ArcSwap<T>>;
18+
pub(super) type AtomicSwap<T> = Arc<ArcSwap<T>>;

ic-agent/src/agent/http_transport/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ const ICP_API_SUB_DOMAIN: &str = ".icp-api.io";
3131
#[allow(dead_code)]
3232
const LOCALHOST_SUB_DOMAIN: &str = ".localhost";
3333
#[cfg(all(feature = "reqwest", not(target_family = "wasm")))]
34-
pub mod dynamic_routing;
34+
pub(crate) mod dynamic_routing;
35+
#[cfg(all(feature = "reqwest", not(target_family = "wasm")))]
3536
pub mod route_provider;

0 commit comments

Comments
 (0)