From 8956db2a81c3700b62c5208cff2ca4b0b124c328 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 12 Dec 2020 17:58:19 +0100 Subject: Make less things public --- src/rpc/lib.rs | 2 +- src/rpc/membership.rs | 47 ++++++++++++++++++++++++----------------------- src/rpc/rpc_client.rs | 6 +++--- 3 files changed, 28 insertions(+), 27 deletions(-) (limited to 'src/rpc') diff --git a/src/rpc/lib.rs b/src/rpc/lib.rs index 4c5f6e31..639ece15 100644 --- a/src/rpc/lib.rs +++ b/src/rpc/lib.rs @@ -5,4 +5,4 @@ pub mod consul; pub mod membership; pub mod rpc_client; pub mod rpc_server; -pub mod tls_util; +pub(crate) mod tls_util; diff --git a/src/rpc/membership.rs b/src/rpc/membership.rs index 697cddd0..6e573a61 100644 --- a/src/rpc/membership.rs +++ b/src/rpc/membership.rs @@ -46,13 +46,13 @@ impl RpcMessage for Message {} #[derive(Debug, Serialize, Deserialize)] pub struct PingMessage { - pub id: UUID, - pub rpc_port: u16, + id: UUID, + rpc_port: u16, - pub status_hash: Hash, - pub config_version: u64, + status_hash: Hash, + config_version: u64, - pub state_info: StateInfo, + state_info: StateInfo, } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -81,12 +81,13 @@ pub struct NetworkConfigEntry { pub struct System { pub id: UUID, - pub data_dir: PathBuf, - pub rpc_local_port: u16, - pub state_info: StateInfo, + metadata_dir: PathBuf, + rpc_local_port: u16, + + state_info: StateInfo, - pub rpc_http_client: Arc, + rpc_http_client: Arc, rpc_client: Arc>, pub status: watch::Receiver>, @@ -296,15 +297,15 @@ fn read_network_config(metadata_dir: &PathBuf) -> Result { impl System { pub fn new( - data_dir: PathBuf, + metadata_dir: PathBuf, rpc_http_client: Arc, background: Arc, rpc_server: &mut RpcServer, ) -> Arc { - let id = gen_node_id(&data_dir).expect("Unable to read or generate node ID"); + let id = gen_node_id(&metadata_dir).expect("Unable to read or generate node ID"); info!("Node ID: {}", hex::encode(&id)); - let net_config = match read_network_config(&data_dir) { + let net_config = match read_network_config(&metadata_dir) { Ok(x) => x, Err(e) => { info!( @@ -347,7 +348,7 @@ impl System { let sys = Arc::new(System { id, - data_dir, + metadata_dir, rpc_local_port: rpc_server.bind_addr.port(), state_info, rpc_http_client, @@ -388,7 +389,7 @@ impl System { } async fn save_network_config(self: Arc) -> Result<(), Error> { - let mut path = self.data_dir.clone(); + let mut path = self.metadata_dir.clone(); path.push("network_config"); let ring = self.ring.borrow().clone(); @@ -399,7 +400,7 @@ impl System { Ok(()) } - pub fn make_ping(&self) -> Message { + fn make_ping(&self) -> Message { let status = self.status.borrow().clone(); let ring = self.ring.borrow().clone(); Message::Ping(PingMessage { @@ -411,7 +412,7 @@ impl System { }) } - pub async fn broadcast(self: Arc, msg: Message, timeout: Duration) { + async fn broadcast(self: Arc, msg: Message, timeout: Duration) { let status = self.status.borrow().clone(); let to = status .nodes @@ -527,7 +528,7 @@ impl System { } } - pub async fn handle_ping( + async fn handle_ping( self: Arc, from: &SocketAddr, ping: &PingMessage, @@ -557,7 +558,7 @@ impl System { Ok(self.make_ping()) } - pub fn handle_pull_status(&self) -> Result { + fn handle_pull_status(&self) -> Result { let status = self.status.borrow().clone(); let mut mem = vec![]; for (node, status) in status.nodes.iter() { @@ -577,12 +578,12 @@ impl System { Ok(Message::AdvertiseNodesUp(mem)) } - pub fn handle_pull_config(&self) -> Result { + fn handle_pull_config(&self) -> Result { let ring = self.ring.borrow().clone(); Ok(Message::AdvertiseConfig(ring.config.clone())) } - pub async fn handle_advertise_nodes_up( + async fn handle_advertise_nodes_up( self: Arc, adv: &[AdvertisedNode], ) -> Result { @@ -635,7 +636,7 @@ impl System { Ok(Message::Ok) } - pub async fn handle_advertise_config( + async fn handle_advertise_config( self: Arc, adv: &NetworkConfig, ) -> Result { @@ -716,7 +717,7 @@ impl System { } } - pub fn pull_status( + fn pull_status( self: Arc, peer: UUID, ) -> impl futures::future::Future + Send + 'static { @@ -731,7 +732,7 @@ impl System { } } - pub async fn pull_config(self: Arc, peer: UUID) { + async fn pull_config(self: Arc, peer: UUID) { let resp = self .rpc_client .call(peer, Message::PullConfig, PING_TIMEOUT) diff --git a/src/rpc/rpc_client.rs b/src/rpc/rpc_client.rs index 6119696d..5183bb4b 100644 --- a/src/rpc/rpc_client.rs +++ b/src/rpc/rpc_client.rs @@ -61,7 +61,7 @@ pub struct RpcClient { local_handler: ArcSwapOption<(UUID, LocalHandlerFn)>, - pub rpc_addr_client: RpcAddrClient, + rpc_addr_client: RpcAddrClient, } impl RpcClient { @@ -215,8 +215,8 @@ impl RpcClient { pub struct RpcAddrClient { phantom: PhantomData, - pub http_client: Arc, - pub path: String, + http_client: Arc, + path: String, } impl RpcAddrClient { -- cgit v1.2.3