diff --git a/crates/mempool/src/communication.rs b/crates/mempool/src/communication.rs index ebd1c4338..18d749281 100644 --- a/crates/mempool/src/communication.rs +++ b/crates/mempool/src/communication.rs @@ -1,7 +1,7 @@ use async_trait::async_trait; use starknet_mempool_infra::component_definitions::ComponentRequestHandler; use starknet_mempool_infra::component_runner::ComponentStarter; -use starknet_mempool_infra::component_server::ComponentServer; +use starknet_mempool_infra::component_server::LocalComponentServer; use starknet_mempool_types::communication::{ MempoolRequest, MempoolRequestAndResponseSender, MempoolResponse, }; @@ -11,14 +11,14 @@ use tokio::sync::mpsc::Receiver; use crate::mempool::Mempool; pub type MempoolServer = - ComponentServer; + LocalComponentServer; pub fn create_mempool_server( mempool: Mempool, rx_mempool: Receiver, ) -> MempoolServer { let communication_wrapper = MempoolCommunicationWrapper::new(mempool); - ComponentServer::new(communication_wrapper, rx_mempool) + LocalComponentServer::new(communication_wrapper, rx_mempool) } /// Wraps the mempool to enable inbound async communication from other components. diff --git a/crates/mempool_infra/src/component_server.rs b/crates/mempool_infra/src/component_server.rs index e6ed57235..22529c226 100644 --- a/crates/mempool_infra/src/component_server.rs +++ b/crates/mempool_infra/src/component_server.rs @@ -19,7 +19,7 @@ use crate::component_definitions::{ }; use crate::component_runner::ComponentStarter; -/// The `ComponentServer` struct is a generic server that handles requests and responses for a +/// The `LocalComponentServer` struct is a generic server that handles requests and responses for a /// specified component. It receives requests, processes them using the provided component, and /// sends back responses. The server needs to be started using the `start` function, which runs /// indefinitely. @@ -43,7 +43,7 @@ use crate::component_runner::ComponentStarter; /// /// # Example /// ```rust -/// // Example usage of the ComponentServer +/// // Example usage of the LocalComponentServer /// use std::sync::mpsc::{channel, Receiver}; /// /// use async_trait::async_trait; @@ -54,7 +54,7 @@ use crate::component_runner::ComponentStarter; /// ComponentRequestAndResponseSender, ComponentRequestHandler, /// }; /// use crate::starknet_mempool_infra::component_server::{ -/// ComponentServer, ComponentServerStarter, +/// ComponentServerStarter, LocalComponentServer, /// }; /// /// // Define your component @@ -95,7 +95,7 @@ use crate::component_runner::ComponentStarter; /// let component = MyComponent {}; /// /// // Instantiate the server. -/// let mut server = ComponentServer::new(component, rx); +/// let mut server = LocalComponentServer::new(component, rx); /// /// // Start the server in a new task. /// task::spawn(async move { @@ -118,7 +118,7 @@ use crate::component_runner::ComponentStarter; /// assert!(response.content == "request example processed".to_string(), "Unexpected response"); /// } /// ``` -pub struct ComponentServer +pub struct LocalComponentServer where Component: ComponentRequestHandler + ComponentStarter, Request: Send + Sync, @@ -128,7 +128,7 @@ where rx: Receiver>, } -impl ComponentServer +impl LocalComponentServer where Component: ComponentRequestHandler + ComponentStarter, Request: Send + Sync, @@ -149,7 +149,7 @@ pub trait ComponentServerStarter: Send + Sync { #[async_trait] impl ComponentServerStarter - for ComponentServer + for LocalComponentServer where Component: ComponentRequestHandler + ComponentStarter + Send + Sync, Request: Send + Sync, @@ -182,7 +182,7 @@ where true } -pub struct ComponentServerHttp +pub struct RemoteComponentServer where Component: ComponentRequestHandler + Send + 'static, Request: for<'a> Deserialize<'a> + Send + 'static, @@ -194,7 +194,7 @@ where _res: PhantomData, } -impl ComponentServerHttp +impl RemoteComponentServer where Component: ComponentRequestHandler + Send + 'static, Request: for<'a> Deserialize<'a> + Send + 'static, @@ -242,7 +242,7 @@ where #[async_trait] impl ComponentServerStarter - for ComponentServerHttp + for RemoteComponentServer where Component: ComponentRequestHandler + Send + 'static, Request: for<'a> Deserialize<'a> + Send + Sync + 'static, diff --git a/crates/mempool_infra/tests/component_server_client_http_test.rs b/crates/mempool_infra/tests/component_server_client_http_test.rs index 345104dc7..ff8516827 100644 --- a/crates/mempool_infra/tests/component_server_client_http_test.rs +++ b/crates/mempool_infra/tests/component_server_client_http_test.rs @@ -19,7 +19,7 @@ use starknet_mempool_infra::component_client::remote_component_client::RemoteCom use starknet_mempool_infra::component_definitions::{ ComponentRequestHandler, ServerError, APPLICATION_OCTET_STREAM, }; -use starknet_mempool_infra::component_server::{ComponentServerHttp, ComponentServerStarter}; +use starknet_mempool_infra::component_server::{ComponentServerStarter, RemoteComponentServer}; use tokio::task; type ComponentAClient = RemoteComponentClient; @@ -157,12 +157,12 @@ async fn setup_for_tests(setup_value: ValueB, a_port: u16, b_port: u16) { let component_a = ComponentA::new(Box::new(b_client)); let component_b = ComponentB::new(setup_value, Box::new(a_client.clone())); - let mut component_a_server = ComponentServerHttp::< + let mut component_a_server = RemoteComponentServer::< ComponentA, ComponentARequest, ComponentAResponse, >::new(component_a, LOCAL_IP, a_port); - let mut component_b_server = ComponentServerHttp::< + let mut component_b_server = RemoteComponentServer::< ComponentB, ComponentBRequest, ComponentBResponse, diff --git a/crates/mempool_infra/tests/component_server_client_test.rs b/crates/mempool_infra/tests/component_server_client_test.rs index bc6c9e8c8..153263c0e 100644 --- a/crates/mempool_infra/tests/component_server_client_test.rs +++ b/crates/mempool_infra/tests/component_server_client_test.rs @@ -10,7 +10,7 @@ use starknet_mempool_infra::component_client::local_component_client::LocalCompo use starknet_mempool_infra::component_definitions::{ ComponentRequestAndResponseSender, ComponentRequestHandler, }; -use starknet_mempool_infra::component_server::{ComponentServer, ComponentServerStarter}; +use starknet_mempool_infra::component_server::{ComponentServerStarter, LocalComponentServer}; use tokio::sync::mpsc::channel; use tokio::task; @@ -99,8 +99,8 @@ async fn test_setup() { let component_a = ComponentA::new(Box::new(b_client.clone())); let component_b = ComponentB::new(setup_value, Box::new(a_client.clone())); - let mut component_a_server = ComponentServer::new(component_a, rx_a); - let mut component_b_server = ComponentServer::new(component_b, rx_b); + let mut component_a_server = LocalComponentServer::new(component_a, rx_a); + let mut component_b_server = LocalComponentServer::new(component_b, rx_b); task::spawn(async move { component_a_server.start().await;