Skip to content

Commit

Permalink
feat: actually dial addresses, use serde_as for deserializing addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
mriise committed Jul 17, 2023
1 parent c76158d commit 47e4e1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion homestar-runtime/fixtures/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ process_collector_interval = 10
[node.network]
events_buffer_len = 1000
websocket_port = 9999
bootstrap_addresses = ["/ip4/127.0.0.1/tcp/9998/ws/"]
bootstrap_addresses = ["/ip4/127.0.0.1/tcp/9998/ws"]
12 changes: 12 additions & 0 deletions homestar-runtime/src/network/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ pub(crate) async fn new(settings: &settings::Node) -> Result<Swarm<ComposedBehav
// Listen-on given address
swarm.listen_on(settings.network.listen_address.to_string().parse()?)?;

// Dial bootstrap nodes specified in settings. Failure here shouldn't halt node startup.
for bootstrap_addr in &settings.network.bootstrap_addresses {
swarm
.dial(bootstrap_addr.clone())
.map(|_| {
tracing::info!("Successfully dialed configured bootstrap node {bootstrap_addr}")
})
// log dial failure and continue
.map_err(|e| tracing::warn!("Failed to dial bootstrap node {e}"))
.ok();
}

// subscribe to `receipts` topic
swarm
.behaviour_mut()
Expand Down
5 changes: 3 additions & 2 deletions homestar-runtime/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ pub struct Network {
/// Pubkey setup configuration
pub(crate) keypair_config: PubkeyConfig,
/// Multiaddrs of the bootstrap nodes to connect to on startup
pub(crate) bootstrap_addresses: Vec<String>,
#[serde_as(as = "Vec<serde_with::DisplayFromStr>")]
pub(crate) bootstrap_addresses: Vec<libp2p::Multiaddr>,
}

/// Database-related settings for a homestar node.
Expand Down Expand Up @@ -327,7 +328,7 @@ mod test {
default_modded_settings.network.websocket_port = 9999;
default_modded_settings.shutdown_timeout = Duration::from_secs(20);
default_modded_settings.network.bootstrap_addresses =
vec!["/ip4/127.0.0.1/tcp/9998/ws/".into()];
vec!["/ip4/127.0.0.1/tcp/9998/ws".to_string().try_into().unwrap()];
assert_eq!(settings.node(), &default_modded_settings);
}

Expand Down

0 comments on commit 47e4e1d

Please sign in to comment.