Skip to content

Commit

Permalink
Rename NetworkRelay -> NetworkManager
Browse files Browse the repository at this point in the history
  • Loading branch information
ryardley committed Dec 2, 2024
1 parent 221352d commit 0452bee
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/ciphernode/core/src/eventbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct ResetHistory;

/// Central EventBus for each node. Actors publish events to this bus by sending it EnclaveEvents.
/// All events sent to this bus are assumed to be published over the network via pubsub.
/// Other actors such as the NetworkRelay and Evm actor connect to outside services and control which events
/// Other actors such as the NetworkManager and Evm actor connect to outside services and control which events
/// actually get published as well as ensure that local events are not rebroadcast locally after
/// being published.
pub struct EventBus {
Expand Down
4 changes: 2 additions & 2 deletions packages/ciphernode/enclave_node/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use evm::{
CiphernodeRegistrySol, EnclaveSol, RegistryFilterSol,
};
use logger::SimpleLogger;
use net::NetworkRelay;
use net::NetworkManager;
use rand::SeedableRng;
use rand_chacha::{rand_core::OsRng, ChaCha20Rng};
use router::{
Expand Down Expand Up @@ -81,7 +81,7 @@ pub async fn setup_aggregator(
.build()
.await?;

let (_, join_handle, peer_id) = NetworkRelay::setup_with_peer(bus.clone(), config.peers(), &cipher, repositories.libp2pid()).await?;
let (_, join_handle, peer_id) = NetworkManager::setup_with_peer(bus.clone(), config.peers(), &cipher, repositories.libp2pid()).await?;

if let Some(path) = pubkey_write_path {
PublicKeyWriter::attach(path, bus.clone());
Expand Down
4 changes: 2 additions & 2 deletions packages/ciphernode/enclave_node/src/ciphernode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use evm::{
CiphernodeRegistrySol, EnclaveSolReader,
};
use logger::SimpleLogger;
use net::NetworkRelay;
use net::NetworkManager;
use rand::SeedableRng;
use rand_chacha::rand_core::OsRng;
use router::{
Expand Down Expand Up @@ -73,7 +73,7 @@ pub async fn setup_ciphernode(
.build()
.await?;

let (_, join_handle, peer_id) = NetworkRelay::setup_with_peer(bus.clone(), config.peers(), &cipher, repositories.libp2pid()).await?;
let (_, join_handle, peer_id) = NetworkManager::setup_with_peer(bus.clone(), config.peers(), &cipher, repositories.libp2pid()).await?;

let nm = format!("CIPHER({})", &address.to_string()[0..5]);
SimpleLogger::attach(&nm, bus.clone());
Expand Down
4 changes: 2 additions & 2 deletions packages/ciphernode/net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![crate_type = "lib"]

mod network_peer;
mod network_relay;
mod network_manager;

pub use network_peer::*;
pub use network_relay::*;
pub use network_manager::*;
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ use libp2p::identity::ed25519;
use tokio::sync::mpsc::{Receiver, Sender};
use tracing::{error, info, instrument, trace};

/// NetworkRelay Actor converts between EventBus events and Libp2p events forwarding them to a
/// NetworkManager Actor converts between EventBus events and Libp2p events forwarding them to a
/// NetworkPeer for propagation over the p2p network
pub struct NetworkRelay {
pub struct NetworkManager {
bus: Addr<EventBus>,
tx: Sender<Vec<u8>>,
sent_events: HashSet<EventId>,
}

impl Actor for NetworkRelay {
impl Actor for NetworkManager {
type Context = Context<Self>;
}

#[derive(Message, Clone, Debug, PartialEq, Eq)]
#[rtype(result = "anyhow::Result<()>")]
struct LibP2pEvent(pub Vec<u8>);

impl NetworkRelay {
/// Create a new NetworkRelay actor
impl NetworkManager {
/// Create a new NetworkManager actor
pub fn new(bus: Addr<EventBus>, tx: Sender<Vec<u8>>) -> Self {
Self {
bus,
Expand All @@ -45,7 +45,7 @@ impl NetworkRelay {
tx: Sender<Vec<u8>>,
mut rx: Receiver<Vec<u8>>,
) -> Addr<Self> {
let addr = NetworkRelay::new(bus.clone(), tx).start();
let addr = NetworkManager::new(bus.clone(), tx).start();

// Listen on all events
bus.do_send(Subscribe {
Expand Down Expand Up @@ -94,13 +94,13 @@ impl NetworkRelay {
let keypair: libp2p::identity::Keypair = ed25519_keypair.try_into()?;
let mut peer = NetworkPeer::new(&keypair, peers, None, "tmp-enclave-gossip-topic")?;
let rx = peer.rx().ok_or(anyhow!("Peer rx already taken"))?;
let p2p_addr = NetworkRelay::setup(bus, peer.tx(), rx);
let p2p_addr = NetworkManager::setup(bus, peer.tx(), rx);
let handle = tokio::spawn(async move { Ok(peer.start().await?) });
Ok((p2p_addr, handle, keypair.public().to_peer_id().to_string()))
}
}

impl Handler<LibP2pEvent> for NetworkRelay {
impl Handler<LibP2pEvent> for NetworkManager {
type Result = anyhow::Result<()>;
fn handle(&mut self, msg: LibP2pEvent, _: &mut Self::Context) -> Self::Result {
let LibP2pEvent(bytes) = msg;
Expand All @@ -115,7 +115,7 @@ impl Handler<LibP2pEvent> for NetworkRelay {
}
}

impl Handler<EnclaveEvent> for NetworkRelay {
impl Handler<EnclaveEvent> for NetworkManager {
type Result = ResponseFuture<()>;
fn handle(&mut self, event: EnclaveEvent, _: &mut Self::Context) -> Self::Result {
let sent_events = self.sent_events.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use enclave_core::{
};
use fhe::{setup_crp_params, ParamsWithCrp, SharedRng};
use logger::SimpleLogger;
use net::NetworkRelay;
use net::NetworkManager;
use router::{
CiphernodeSelector, E3RequestRouter, FheFeature, KeyshareFeature, PlaintextAggregatorFeature,
PublicKeyAggregatorFeature, RepositoriesFactory,
Expand Down Expand Up @@ -468,7 +468,7 @@ async fn test_p2p_actor_forwards_events_to_network() -> Result<()> {
let (tx, mut output) = channel(100); // Transmit byte events to the network
let (input, rx) = channel(100); // Receive byte events from the network
let bus = EventBus::new(true).start();
NetworkRelay::setup(bus.clone(), tx.clone(), rx);
NetworkManager::setup(bus.clone(), tx.clone(), rx);

// Capture messages from output on msgs vec
let msgs: Arc<Mutex<Vec<Vec<u8>>>> = Arc::new(Mutex::new(Vec::new()));
Expand Down Expand Up @@ -514,14 +514,14 @@ async fn test_p2p_actor_forwards_events_to_network() -> Result<()> {
assert_eq!(
*msgs.lock().await,
vec![evt_1.to_bytes()?, evt_2.to_bytes()?], // notice no local events
"NetworkRelay did not transmit correct events to the network"
"NetworkManager did not transmit correct events to the network"
);

assert_eq!(
history,
vec![evt_1, evt_2, local_evt_3], // all local events that have been broadcast but no
// events from the loopback
"NetworkRelay must not retransmit forwarded event to event bus"
"NetworkManager must not retransmit forwarded event to event bus"
);

Ok(())
Expand All @@ -535,7 +535,7 @@ async fn test_p2p_actor_forwards_events_to_bus() -> Result<()> {
let (tx, _) = channel(100); // Transmit byte events to the network
let (input, rx) = channel(100); // Receive byte events from the network
let bus = EventBus::new(true).start();
NetworkRelay::setup(bus.clone(), tx.clone(), rx);
NetworkManager::setup(bus.clone(), tx.clone(), rx);

// Capture messages from output on msgs vec
let event = EnclaveEvent::from(E3Requested {
Expand Down

0 comments on commit 0452bee

Please sign in to comment.