Skip to content

Commit

Permalink
refactor: rename component servers with the prefixes Local/Remote
Browse files Browse the repository at this point in the history
  • Loading branch information
uriel-starkware committed Jul 23, 2024
1 parent ef2a585 commit 088ce7f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions crates/mempool/src/communication.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand All @@ -11,14 +11,14 @@ use tokio::sync::mpsc::Receiver;
use crate::mempool::Mempool;

pub type MempoolServer =
ComponentServer<MempoolCommunicationWrapper, MempoolRequest, MempoolResponse>;
LocalComponentServer<MempoolCommunicationWrapper, MempoolRequest, MempoolResponse>;

pub fn create_mempool_server(
mempool: Mempool,
rx_mempool: Receiver<MempoolRequestAndResponseSender>,
) -> 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.
Expand Down
20 changes: 10 additions & 10 deletions crates/mempool_infra/src/component_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -118,7 +118,7 @@ use crate::component_runner::ComponentStarter;
/// assert!(response.content == "request example processed".to_string(), "Unexpected response");
/// }
/// ```
pub struct ComponentServer<Component, Request, Response>
pub struct LocalComponentServer<Component, Request, Response>
where
Component: ComponentRequestHandler<Request, Response> + ComponentStarter,
Request: Send + Sync,
Expand All @@ -128,7 +128,7 @@ where
rx: Receiver<ComponentRequestAndResponseSender<Request, Response>>,
}

impl<Component, Request, Response> ComponentServer<Component, Request, Response>
impl<Component, Request, Response> LocalComponentServer<Component, Request, Response>
where
Component: ComponentRequestHandler<Request, Response> + ComponentStarter,
Request: Send + Sync,
Expand All @@ -149,7 +149,7 @@ pub trait ComponentServerStarter: Send + Sync {

#[async_trait]
impl<Component, Request, Response> ComponentServerStarter
for ComponentServer<Component, Request, Response>
for LocalComponentServer<Component, Request, Response>
where
Component: ComponentRequestHandler<Request, Response> + ComponentStarter + Send + Sync,
Request: Send + Sync,
Expand Down Expand Up @@ -182,7 +182,7 @@ where
true
}

pub struct ComponentServerHttp<Component, Request, Response>
pub struct RemoteComponentServer<Component, Request, Response>
where
Component: ComponentRequestHandler<Request, Response> + Send + 'static,
Request: for<'a> Deserialize<'a> + Send + 'static,
Expand All @@ -194,7 +194,7 @@ where
_res: PhantomData<Response>,
}

impl<Component, Request, Response> ComponentServerHttp<Component, Request, Response>
impl<Component, Request, Response> RemoteComponentServer<Component, Request, Response>
where
Component: ComponentRequestHandler<Request, Response> + Send + 'static,
Request: for<'a> Deserialize<'a> + Send + 'static,
Expand Down Expand Up @@ -242,7 +242,7 @@ where

#[async_trait]
impl<Component, Request, Response> ComponentServerStarter
for ComponentServerHttp<Component, Request, Response>
for RemoteComponentServer<Component, Request, Response>
where
Component: ComponentRequestHandler<Request, Response> + Send + 'static,
Request: for<'a> Deserialize<'a> + Send + Sync + 'static,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComponentARequest, ComponentAResponse>;
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions crates/mempool_infra/tests/component_server_client_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 088ce7f

Please sign in to comment.