Skip to content

Commit

Permalink
Plumb config to dial peers
Browse files Browse the repository at this point in the history
  • Loading branch information
ryardley committed Nov 23, 2024
1 parent d2eafea commit 5e8c884
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/ciphernode/config/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub struct AppConfig {
data_dir: PathBuf,
/// Ethereum Address for the node
address: Option<Address>,
/// A list of libp2p multiaddrs to dial to as peers when joining the network
peers: Vec<String>
}

impl Default for AppConfig {
Expand All @@ -83,6 +85,8 @@ impl Default for AppConfig {
data_dir: OsDirs::data_dir(), // ~/.config/enclave
config_file: PathBuf::from("config.yaml"), // ~/.config/enclave/config.yaml
cwd: env::current_dir().unwrap_or_default(),
peers: vec![], // NOTE: This should remain empty and we should look at config
// generation via ipns fetch for the latest nodes
address: None,
}
}
Expand Down Expand Up @@ -155,6 +159,11 @@ impl AppConfig {
pub fn cwd(&self) -> PathBuf {
self.cwd.to_owned()
}

pub fn peers(&self) -> Vec<String> {
self.peers.clone()
}

}

/// Load the config at the config_file or the default location if not provided
Expand Down
2 changes: 1 addition & 1 deletion packages/ciphernode/enclave_node/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub async fn setup_aggregator(
.build()
.await?;

let (_, join_handle, peer_id) = P2p::spawn_libp2p(bus.clone()).expect("Failed to setup libp2p");
let (_, join_handle, peer_id) = P2p::spawn_libp2p(bus.clone(), config.peers()).expect("Failed to setup libp2p");

if let Some(path) = pubkey_write_path {
PublicKeyWriter::attach(path, bus.clone());
Expand Down
2 changes: 1 addition & 1 deletion packages/ciphernode/enclave_node/src/ciphernode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn setup_ciphernode(
.build()
.await?;

let (_, join_handle, peer_id) = P2p::spawn_libp2p(bus.clone()).expect("Failed to setup libp2p");
let (_, join_handle, peer_id) = P2p::spawn_libp2p(bus.clone(), config.peers()).expect("Failed to setup libp2p");

let nm = format!("CIPHER({})", &address.to_string()[0..5]);
SimpleLogger::attach(&nm, bus.clone());
Expand Down
3 changes: 2 additions & 1 deletion packages/ciphernode/p2p/src/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl P2p {
/// Spawn a Libp2p instance. Calls spawn and listen
pub fn spawn_libp2p(
bus: Addr<EventBus>,
peers: Vec<String>
) -> Result<(Addr<Self>, tokio::task::JoinHandle<()>, String), Box<dyn Error>> {
let (mut libp2p, tx, rx) = EnclaveRouter::new()?;
let keypair = libp2p::identity::Keypair::generate_ed25519();
Expand All @@ -73,7 +74,7 @@ impl P2p {
libp2p.join_topic("enclave-keygen-01")?;

let p2p_addr = Self::spawn_and_listen(bus, tx, rx);
let handle = tokio::spawn(async move { libp2p.start(vec![]).await.unwrap() });
let handle = tokio::spawn(async move { libp2p.start(peers).await.unwrap() });
Ok((p2p_addr, handle, keypair.public().to_peer_id().to_string()))
}
}
Expand Down

0 comments on commit 5e8c884

Please sign in to comment.