use commonware_cryptography::PublicKey; use commonware_runtime::Spawner; use futures::{channel::mpsc, StreamExt}; use std::sync::{Arc, Mutex}; /// Message type for coordinator updates pub enum CoordinatorMsg
{ /// Update the peers list UpdatePeers(Vec
),
}
/// A coordinator that can be used for testing
#[derive(Clone)]
pub struct Coordinator ,
peer_set_id: u64,
}
impl {
/// Creates a new coordinator with the given initial peers
pub fn new(initial_peers: Vec ) -> Self {
let state = State {
peers: initial_peers,
peer_set_id: 0,
};
Self {
state: Arc::new(Mutex::new(state)),
}
}
/// Creates a channel for sending updates to this coordinator
pub fn create_update_channel ) {
let mut state = self.state.lock().unwrap();
state.peers = new_peers;
state.peer_set_id += 1;
}
// Helper to get a cloned vector to support the trait implementation
fn get_peers(&self) -> Vec {
let state = self.state.lock().unwrap();
state.peers.clone()
}
}
impl {
type PublicKey = P;
fn peers(&self) -> &Vec