Skip to content

Commit

Permalink
refactor: Rename network::Client trait and the in_memory::Client
Browse files Browse the repository at this point in the history
…implementation

Renamed to `MessageTransfer` and `MpmcBroadcaster`
  • Loading branch information
netrome committed May 13, 2024
1 parent b484c79 commit 63ae519
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions signer/src/network.rs
@@ -1,6 +1,6 @@
//! # Signer network interface
//!
//! This module provides the Client trait that the signer implementation
//! This module provides the MessageTransfer trait that the signer implementation
//! will rely on for inter-signer communication, along with an in-memory
//! implementation of this trait for testing purposes.

Expand All @@ -14,7 +14,7 @@ use crate::message;

pub type Msg = ecdsa::Signed<message::SignerMessage>;

pub trait Client {
pub trait MessageTransfer {
type Error;
/// Send `msg` to all other signers
fn broadcast(&mut self, msg: Msg) -> impl Future<Output = Result<(), Self::Error>> + Send;
Expand Down
8 changes: 4 additions & 4 deletions signer/src/network/in_memory.rs
Expand Up @@ -13,7 +13,7 @@ pub const BROADCAST_CHANNEL_CAPACITY: usize = 10_000;
type MsgId = [u8; 32];

#[derive(Debug)]
pub struct Client {
pub struct MpmcBroadcaster {
sender: broadcast::Sender<super::Msg>,
receiver: broadcast::Receiver<super::Msg>,
recently_sent: VecDeque<MsgId>,
Expand All @@ -33,20 +33,20 @@ impl Network {
}

/// Connect a new signer to this network
pub fn connect(&self) -> Client {
pub fn connect(&self) -> MpmcBroadcaster {
let sender = self.sender.clone();
let receiver = sender.subscribe();
let recently_sent = VecDeque::new();

Client {
MpmcBroadcaster {
sender,
receiver,
recently_sent,
}
}
}

impl super::Client for Client {
impl super::MessageTransfer for MpmcBroadcaster {
type Error = Error;
async fn broadcast(&mut self, msg: super::Msg) -> Result<(), Self::Error> {
self.recently_sent.push_back(msg.id());
Expand Down

0 comments on commit 63ae519

Please sign in to comment.