Skip to content

Commit

Permalink
add config for disabling mdns
Browse files Browse the repository at this point in the history
  • Loading branch information
cylewitruk committed Nov 18, 2024
1 parent c4a13c8 commit 56ac7ec
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docker/sbtc/signer/signer-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,12 @@ listen_on = []
# Required: false
# Environment: SIGNER_SIGNER__P2P__PUBLIC_ENDPOINTS
public_endpoints = []

# Enables/disables mDNS (multicast DNS) discovery. mDNS allows sBTC signers
# running on the same local network to discover each other without explicitly
# providing them as seed nodes.
#
# Default: false
# Required: false
# Environment: SIGNER_SIGNER__P2P__ENABLE_MDNS
enable_mdns = false
9 changes: 9 additions & 0 deletions signer/src/config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,12 @@ listen_on = ["tcp://0.0.0.0:4122", "quic-v1://0.0.0.0:4122"]
# Required: false
# Environment: SIGNER_SIGNER__P2P__PUBLIC_ENDPOINTS
public_endpoints = []

# Enables/disables mDNS (multicast DNS) discovery. mDNS allows sBTC signers
# running on the same local network to discover each other without explicitly
# providing them as seed nodes.
#
# Default: false
# Required: false
# Environment: SIGNER_SIGNER__P2P__ENABLE_MDNS
enable_mdns = true
4 changes: 4 additions & 0 deletions signer/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ pub struct P2PNetworkConfig {
/// public endpoint(s).
#[serde(deserialize_with = "p2p_multiaddr_deserializer_vec")]
pub public_endpoints: Vec<Multiaddr>,
/// Enable mDNS discovery for the P2P network. This is useful for local
/// testing and development.
#[serde(default)]
pub enable_mdns: bool,
}

impl Validatable for P2PNetworkConfig {
Expand Down
9 changes: 9 additions & 0 deletions signer/src/network/libp2p/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ fn handle_mdns_event(swarm: &mut Swarm<SignerBehavior>, ctx: &impl Context, even
// so this will never be raised for WAN peers which must otherwise
// be discovered via seed nodes.
Event::Discovered(peers) => {
// If we have disabled mDNS, we should not process this event.
if !ctx.config().signer.p2p.enable_mdns {
return;
}

for (peer_id, addr) in peers {
if !ctx.state().current_signer_set().is_allowed_peer(&peer_id) {
tracing::warn!(%peer_id, %addr, "Discovered peer via mDNS, however it is not a known signer; ignoring");
Expand All @@ -320,6 +325,10 @@ fn handle_mdns_event(swarm: &mut Swarm<SignerBehavior>, ctx: &impl Context, even
Event::Expired(peers) => {
for (peer_id, addr) in peers {
tracing::info!(%peer_id, %addr, "Expired peer via mDNS");
swarm
.behaviour_mut()
.gossipsub
.remove_explicit_peer(&peer_id);
}
}
}
Expand Down

0 comments on commit 56ac7ec

Please sign in to comment.