Skip to content

Commit

Permalink
wip: some sdk stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
qti3e committed Jul 27, 2023
1 parent 87ad246 commit c389bda
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
32 changes: 32 additions & 0 deletions core/interfaces/src/connection.rs
Original file line number Diff line number Diff line change
@@ -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;
}
31 changes: 2 additions & 29 deletions core/interfaces/src/handshake.rs
Original file line number Diff line number Diff line change
@@ -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<Self>;
}

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;
}
4 changes: 4 additions & 0 deletions core/interfaces/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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::*;
Expand All @@ -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::*;
20 changes: 20 additions & 0 deletions core/interfaces/src/service.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit c389bda

Please sign in to comment.