From c389bda22a99338b0092bf363a09f50e8badfbb9 Mon Sep 17 00:00:00 2001 From: Parsa Ghadimi Date: Wed, 26 Jul 2023 20:38:37 -0400 Subject: [PATCH] wip: some sdk stuff --- core/interfaces/src/connection.rs | 32 +++++++++++++++++++++++++++++++ core/interfaces/src/handshake.rs | 31 ++---------------------------- core/interfaces/src/lib.rs | 4 ++++ core/interfaces/src/service.rs | 20 +++++++++++++++++++ 4 files changed, 58 insertions(+), 29 deletions(-) create mode 100644 core/interfaces/src/connection.rs create mode 100644 core/interfaces/src/service.rs diff --git a/core/interfaces/src/connection.rs b/core/interfaces/src/connection.rs new file mode 100644 index 000000000..346db9762 --- /dev/null +++ b/core/interfaces/src/connection.rs @@ -0,0 +1,32 @@ +use fleek_crypto::ClientPublicKey; +use tokio::io::{AsyncRead, AsyncWrite}; + +use crate::CompressionAlgoSet; + +/// The connection type that is offered by the (HandshakeInterface)[crate::HandshakeInterface]. +pub trait ConnectionInterface: Send + Sync { + /// The writer half of this connection. + type Writer: AsyncWrite + Unpin + Send + Sync; + + /// The reader half of this connection. + type Reader: AsyncRead + Unpin + Send + Sync; + + /// Split the connection to the `writer` and `reader` half and returns a mutable reference to + /// both sides. + fn split(&mut self) -> (&mut Self::Writer, &mut Self::Reader); + + /// Returns a mutable reference to the writer half of this connection. + fn writer(&mut self) -> &mut Self::Writer; + + /// Returns a mutable reference to the reader half of this connection. + fn reader(&mut self) -> &mut Self::Reader; + + /// Returns the lane number associated with this connection. + fn get_lane(&self) -> u8; + + /// Returns the ID of the client that has established this connection. + fn get_client(&self) -> &ClientPublicKey; + + /// The compression algorithms the client does support. + fn get_compression_set(&self) -> CompressionAlgoSet; +} diff --git a/core/interfaces/src/handshake.rs b/core/interfaces/src/handshake.rs index 328342788..78a3eaa9a 100644 --- a/core/interfaces/src/handshake.rs +++ b/core/interfaces/src/handshake.rs @@ -1,39 +1,12 @@ use async_trait::async_trait; -use fleek_crypto::ClientPublicKey; -use tokio::io::{AsyncRead, AsyncWrite}; -use crate::{common::WithStartAndShutdown, config::ConfigConsumer, CompressionAlgoSet}; +use crate::{common::WithStartAndShutdown, config::ConfigConsumer, ConnectionInterface}; #[async_trait] pub trait HandshakeInterface: ConfigConsumer + WithStartAndShutdown + Sized + Send + Sync { + /// The connection type that this handshake implementation offers. type Connection: ConnectionInterface; /// Initialize a new delivery acknowledgment aggregator. async fn init(config: Self::Config) -> anyhow::Result; } - -pub trait ConnectionInterface: Send + Sync { - /// The writer half of this connection. - type Writer: AsyncWrite + Unpin + Send + Sync; - - /// The reader half of this connection. - type Reader: AsyncRead + Unpin + Send + Sync; - - /// Split the connection to the `writer` and `reader` half and returns a mutable reference to - /// both sides. - fn split(&mut self) -> (&mut Self::Writer, &mut Self::Reader); - - /// Returns a mutable reference to the writer half of this connection. - fn writer(&mut self) -> &mut Self::Writer; - - /// Returns a mutable reference to the reader half of this connection. - fn reader(&mut self) -> &mut Self::Reader; - - /// Returns the lane number associated with this connection. - fn get_lane(&self) -> u8; - - /// Returns the ID of the client that has established this connection. - fn get_client(&self) -> &ClientPublicKey; - - fn get_compression_set(&self) -> CompressionAlgoSet; -} diff --git a/core/interfaces/src/lib.rs b/core/interfaces/src/lib.rs index 2bd11a7e9..2a2e366b4 100644 --- a/core/interfaces/src/lib.rs +++ b/core/interfaces/src/lib.rs @@ -3,6 +3,7 @@ pub mod blockstore; pub mod common; pub mod compression; pub mod config; +pub mod connection; pub mod consensus; pub mod fs; pub mod gossip; @@ -14,6 +15,7 @@ pub mod origin; pub mod pod; pub mod reputation; pub mod rpc; +pub mod service; pub mod signer; pub mod topology; pub mod types; @@ -23,6 +25,7 @@ pub use blockstore::*; pub use common::*; pub use compression::*; pub use config::*; +pub use connection::*; pub use consensus::*; pub use fs::*; pub use gossip::*; @@ -34,5 +37,6 @@ pub use origin::*; pub use pod::*; pub use reputation::*; pub use rpc::*; +pub use service::*; pub use signer::*; pub use topology::*; diff --git a/core/interfaces/src/service.rs b/core/interfaces/src/service.rs new file mode 100644 index 000000000..451a35430 --- /dev/null +++ b/core/interfaces/src/service.rs @@ -0,0 +1,20 @@ +use crate::{types::ServiceId, ConfigConsumer, ConnectionInterface, WithStartAndShutdown}; + +pub trait ServiceExecutorInterface: WithStartAndShutdown + ConfigConsumer + Send + Sync { + /// The connector object that this service executor provides. + type Connector: ServiceConnectorInterface; + + /// Return the connector for this service executor. + fn get_connector(&self) -> Self::Connector; + + /// Register a core service, a core service is any service that we ship with this binary. + fn register_core_service(&self, service_id: ServiceId); +} + +pub trait ServiceConnectorInterface: Clone { + /// The connection specified. + type Connection: ConnectionInterface; + + /// Handle the connection to the service specified by the name. + fn handle(&self, service: ServiceId, connection: Self::Connection); +}