Skip to content

Commit

Permalink
chore: Add rendezvous discovery interval config
Browse files Browse the repository at this point in the history
  • Loading branch information
bgins committed Oct 27, 2023
1 parent 2fc7ee8 commit 6dfed94
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
12 changes: 8 additions & 4 deletions homestar-runtime/src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ pub(crate) struct EventHandler<DB: Database> {
connected_peers_limit: u32,
discovered_peers: FnvHashMap<PeerId, PeerDiscoveryInfo>,
request_response_senders: FnvHashMap<RequestId, (RequestResponseKey, P2PSender)>,
rendezvous_ttl: Duration,
rendezvous_registration_ttl: Duration,
rendezvous_discovery_interval: Duration,
rendezvous_cookies: FnvHashMap<PeerId, Cookie>,
pubsub_enabled: bool,
ws_msg_sender: ws::Notifier,
Expand All @@ -86,7 +87,8 @@ pub(crate) struct EventHandler<DB: Database> {
connected_peers_limit: u32,
discovered_peers: FnvHashMap<PeerId, PeerDiscoveryInfo>,
request_response_senders: FnvHashMap<RequestId, (RequestResponseKey, P2PSender)>,
rendezvous_ttl: Duration,
rendezvous_registration_ttl: Duration,
rendezvous_discovery_interval: Duration,
rendezvous_cookies: FnvHashMap<PeerId, Cookie>,
pubsub_enabled: bool,
node_addresses: Vec<libp2p::Multiaddr>,
Expand Down Expand Up @@ -129,7 +131,8 @@ where
connected_peers: FnvHashMap::default(),
connected_peers_limit: settings.network.max_connected_peers,
discovered_peers: FnvHashMap::default(),
rendezvous_ttl: settings.network.rendezvous_ttl,
rendezvous_registration_ttl: settings.network.rendezvous_registration_ttl,
rendezvous_discovery_interval: settings.network.rendezvous_discovery_interval,
rendezvous_cookies: FnvHashMap::default(),
pubsub_enabled: settings.network.enable_pubsub,
ws_msg_sender,
Expand All @@ -156,7 +159,8 @@ where
connected_peers_limit: settings.network.max_connected_peers,
discovered_peers: FnvHashMap::default(),
request_response_senders: FnvHashMap::default(),
rendezvous_ttl: settings.network.rendezvous_ttl,
rendezvous_registration_ttl: settings.network.rendezvous_registration_ttl,
rendezvous_discovery_interval: settings.network.rendezvous_discovery_interval,
rendezvous_cookies: FnvHashMap::default(),
pubsub_enabled: settings.network.enable_pubsub,
node_addresses: settings.network.node_addresses.clone(),
Expand Down
2 changes: 1 addition & 1 deletion homestar-runtime/src/event_handler/swarm_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async fn handle_swarm_event<THandlerErr: fmt::Debug + Send, DB: Database>(
if let Err(err) = rendezvous_client.register(
Namespace::from_static(RENDEZVOUS_NAMESPACE),
peer_id,
Some(event_handler.rendezvous_ttl.as_secs()),
Some(event_handler.rendezvous_registration_ttl.as_secs()),
) {
warn!(
peer_id = peer_id.to_string(),
Expand Down
8 changes: 6 additions & 2 deletions homestar-runtime/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ pub struct Network {
pub(crate) enable_rendezvous_server: bool,
/// Rendezvous registration TTL.
#[serde_as(as = "DurationSeconds<u64>")]
pub(crate) rendezvous_ttl: Duration,
pub(crate) rendezvous_registration_ttl: Duration,
/// Rendezvous discovery interval.
#[serde_as(as = "DurationSeconds<u64>")]
pub(crate) rendezvous_discovery_interval: Duration,
/// Enable mDNS.
pub(crate) enable_mdns: bool,
/// mDNS IPv6 enable flag
Expand Down Expand Up @@ -195,7 +198,8 @@ impl Default for Network {
listen_address: Uri::from_static("/ip4/0.0.0.0/tcp/0"),
enable_rendezvous_client: true,
enable_rendezvous_server: false,
rendezvous_ttl: Duration::from_secs(2 * 60 * 60),
rendezvous_registration_ttl: Duration::from_secs(2 * 60 * 60),
rendezvous_discovery_interval: Duration::from_secs(10 * 60),
// TODO: we would like to enable this by default, however this breaks mdns on at least some linux distros. Requires further investigation.
enable_mdns: true,
mdns_enable_ipv6: false,
Expand Down

0 comments on commit 6dfed94

Please sign in to comment.