Repository: mintlayer/mintlayer-core
Pull request #629 (2023-01-11 13:13:29)

Remove remains of references to mDNS
mDNS was only used with libp2p. And we are not going to use mDNS in the mock backend.


Patch:
diff --git a/node/src/config_files/mod.rs b/node/src/config_files/mod.rs
index 3c49f548e..e9b58625b 100644
--- a/node/src/config_files/mod.rs
+++ b/node/src/config_files/mod.rs
@@ -35,10 +35,8 @@ use serde::{Deserialize, Serialize};
 use crate::RunOptions;
 
 use self::{
-    chainstate::ChainstateConfigFile,
-    chainstate_launcher::ChainstateLauncherConfigFile,
-    p2p::{MdnsConfigFile, P2pConfigFile},
-    rpc::RpcConfigFile,
+    chainstate::ChainstateConfigFile, chainstate_launcher::ChainstateLauncherConfigFile,
+    p2p::P2pConfigFile, rpc::RpcConfigFile,
 };
 
 /// The node configuration.
@@ -141,7 +139,6 @@ fn p2p_config(config: P2pConfigFile, options: &RunOptions) -> P2pConfigFile {
         ban_threshold,
         ban_duration,
         outbound_connection_timeout,
-        mdns_config: _,
         node_type,
     } = config;
 
@@ -152,19 +149,12 @@ fn p2p_config(config: P2pConfigFile, options: &RunOptions) -> P2pConfigFile {
         options.p2p_outbound_connection_timeout.or(outbound_connection_timeout);
     let node_type = options.node_type.or(node_type);
 
-    let mdns_config = MdnsConfigFile::from_options(
-        options.p2p_enable_mdns,
-        options.p2p_mdns_query_interval,
-        options.p2p_enable_ipv6_mdns_discovery,
-    );
-
     P2pConfigFile {
         bind_addresses,
         added_nodes,
         ban_threshold,
         ban_duration,
         outbound_connection_timeout,
-        mdns_config,
         node_type,
     }
 }
diff --git a/node/src/config_files/p2p.rs b/node/src/config_files/p2p.rs
index aa7bc7dc3..e23ceab01 100644
--- a/node/src/config_files/p2p.rs
+++ b/node/src/config_files/p2p.rs
@@ -17,77 +17,7 @@ use std::{str::FromStr, time::Duration};
 
 use serde::{Deserialize, Serialize};
 
-use p2p::config::{MdnsConfig, NodeType, P2pConfig};
-
-/// Multicast DNS configuration.
-#[derive(Serialize, Deserialize, Debug)]
-#[serde(tag = "state")]
-pub enum MdnsConfigFile {
-    Enabled {
-        /// Interval (in milliseconds) at which to poll the network for new peers.
-        query_interval: Option<u64>,
-        /// Use IPv6 for multicast DNS
-        enable_ipv6_mdns_discovery: Option<bool>,
-    },
-    Disabled,
-}
-
-impl MdnsConfigFile {
-    pub fn from_options(
-        enable_mdns: Option<bool>,
-        query_interval: Option<u64>,
-        enable_ipv6_mdns_discovery: Option<bool>,
-    ) -> Option<Self> {
-        match enable_mdns {
-            Some(enable_mdns) => {
-                if enable_mdns {
-                    Some(MdnsConfigFile::Enabled {
-                        query_interval,
-                        enable_ipv6_mdns_discovery,
-                    })
-                } else {
-                    assert!(
-                        query_interval.is_none(),
-                        "mDNS is disabled but query interval is specified"
-                    );
-                    assert!(
-                        enable_ipv6_mdns_discovery.is_none(),
-                        "mDNS is disabled but transport over IPv6 is enabled"
-                    );
-
-                    Some(MdnsConfigFile::Disabled)
-                }
-            }
-            None => {
-                assert!(
-                    query_interval.is_none(),
-                    "mDNS enable state not specified but query interval is specified"
-                );
-                assert!(
-                    enable_ipv6_mdns_discovery.is_none(),
-                    "mDNS enable state not specified but transport over IPv6 is enabled"
-                );
-
-                None
-            }
-        }
-    }
-}
-
-impl From<MdnsConfigFile> for MdnsConfig {
-    fn from(c: MdnsConfigFile) -> Self {
-        match c {
-            MdnsConfigFile::Enabled {
-                query_interval,
-                enable_ipv6_mdns_discovery,
-            } => MdnsConfig::Enabled {
-                query_interval: query_interval.into(),
-                enable_ipv6_mdns_discovery: enable_ipv6_mdns_discovery.into(),
-            },
-            MdnsConfigFile::Disabled => MdnsConfig::Disabled,
-        }
-    }
-}
+use p2p::config::{NodeType, P2pConfig};
 
 /// A node type.
 #[derive(Debug, Serialize, Deserialize, Copy, Clone, Eq, PartialEq)]
@@ -131,40 +61,19 @@ pub struct P2pConfigFile {
     pub ban_duration: Option<u64>,
     /// The outbound connection timeout value in seconds.
     pub outbound_connection_timeout: Option<u64>,
-    /// Multicast DNS configuration.
-    pub mdns_config: Option<MdnsConfigFile>,
     /// A node type.
     pub node_type: Option<NodeTypeConfigFile>,
 }
 
 impl From<P2pConfigFile> for P2pConfig {
     fn from(c: P2pConfigFile) -> Self {
-        let mdns_config: Option<MdnsConfig> = c.mdns_config.map(|v| v.into());
         P2pConfig {
             bind_addresses: c.bind_addresses.clone().unwrap_or_default(),
             added_nodes: c.added_nodes.clone().unwrap_or_default(),
             ban_threshold: c.ban_threshold.into(),
             ban_duration: c.ban_duration.map(Duration::from_secs).into(),
             outbound_connection_timeout: c.outbound_connection_timeout.into(),
-            mdns_config: mdns_config.into(),
             node_type: c.node_type.map(Into::into).into(),
         }
     }
 }
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-
-    #[test]
-    #[should_panic]
-    fn mdns_disabled_but_query_interval_specified() {
-        MdnsConfigFile::from_options(Some(false), Some(200), None);
-    }
-
-    #[test]
-    #[should_panic]
-    fn mdns_disabled_but_ipv6_enabled() {
-        MdnsConfigFile::from_options(Some(false), None, Some(true));
-    }
-}
diff --git a/node/src/options.rs b/node/src/options.rs
index 985307eee..e4b8c3f09 100644
--- a/node/src/options.rs
+++ b/node/src/options.rs
@@ -91,18 +91,6 @@ pub struct RunOptions {
     #[clap(long)]
     pub p2p_ban_threshold: Option<u32>,
 
-    /// Use IPv6 instead of IPv4 for mDNS.
-    #[clap(long)]
-    pub p2p_enable_ipv6_mdns_discovery: Option<bool>,
-
-    /// Enable multicast DNS peer discovery
-    #[clap(long)]
-    pub p2p_enable_mdns: Option<bool>,
-
-    /// Interval (in milliseconds) at which to poll the network for new peers.
-    #[clap(long)]
-    pub p2p_mdns_query_interval: Option<u64>,
-
     /// The p2p timeout value in seconds.
     #[clap(long)]
     pub p2p_outbound_connection_timeout: Option<u64>,
diff --git a/p2p/src/config.rs b/p2p/src/config.rs
index d04b922a0..28918b742 100644
--- a/p2p/src/config.rs
+++ b/p2p/src/config.rs
@@ -21,16 +21,9 @@ use crate::net::types::PubSubTopic;
 
 pub const DEFAULT_BIND_PORT: u16 = 3031;
 
-// TODO: does this constant make sense to be zero? Find the justification for it.
-pub const MDNS_DEFAULT_QUERY_INTERVAL: u64 = 0;
-pub const MDNS_DEFAULT_IPV6_STATE: bool = false;
-
 make_config_setting!(BanThreshold, u32, 100);
 make_config_setting!(BanDuration, Duration, Duration::from_secs(60 * 60 * 24));
 make_config_setting!(OutboundConnectionTimeout, u64, 10);
-make_config_setting!(MdnsConfigSetting, MdnsConfig, MdnsConfig::Disabled);
-make_config_setting!(MdnsQueryInterval, u64, MDNS_DEFAULT_QUERY_INTERVAL);
-make_config_setting!(MdnsEnableIpV6Discovery, bool, MDNS_DEFAULT_IPV6_STATE);
 make_config_setting!(
     AnnouncementSubscriptions,
     BTreeSet<PubSubTopic>,
@@ -38,24 +31,6 @@ make_config_setting!(
 );
 make_config_setting!(NodeTypeSetting, NodeType, NodeType::Full);
 
-/// Multicast DNS configuration.
-#[derive(Debug, Clone)]
-pub enum MdnsConfig {
-    Enabled {
-        /// Interval (in milliseconds) at which to poll the network for new peers.
-        query_interval: MdnsQueryInterval,
-        /// Use IPv6 for multicast DNS
-        enable_ipv6_mdns_discovery: MdnsEnableIpV6Discovery,
-    },
-    Disabled,
-}
-
-impl Default for MdnsConfig {
-    fn default() -> Self {
-        MdnsConfig::Disabled
-    }
-}
-
 /// A node type.
 #[derive(Debug, Copy, Clone)]
 pub enum NodeType {
@@ -94,8 +69,6 @@ pub struct P2pConfig {
     pub ban_duration: BanDuration,
     /// The outbound connection timeout value in seconds.
     pub outbound_connection_timeout: OutboundConnectionTimeout,
-    /// Multicast DNS configuration.
-    pub mdns_config: MdnsConfigSetting,
     /// A node type.
     pub node_type: NodeTypeSetting,
 }
diff --git a/p2p/src/net/types/mod.rs b/p2p/src/net/types/mod.rs
index a6d7b7fba..3bad7f91d 100644
--- a/p2p/src/net/types/mod.rs
+++ b/p2p/src/net/types/mod.rs
@@ -105,7 +105,7 @@ pub enum ConnectivityEvent<T: NetworkingService> {
         peer_id: T::PeerId,
     },
 
-    /// One or more peers discovered (libp2p defines discovering as finding new addresses through mDNS or otherwise)
+    /// One or more peers discovered
     Discovered {
         /// Address information
         addresses: Vec<T::Address>,


Test patch:
diff --git a/node/tests/cli.rs b/node/tests/cli.rs
index b845253c5..ae85cb75d 100644
--- a/node/tests/cli.rs
+++ b/node/tests/cli.rs
@@ -92,7 +92,6 @@ fn read_config_override_values() {
     let p2p_timeout = 10000;
     let http_rpc_addr = SocketAddr::from_str("127.0.0.1:5432").unwrap();
     let ws_rpc_addr = SocketAddr::from_str("127.0.0.1:5433").unwrap();
-    let enable_mdns = false;
     let backend_type = StorageBackendConfigFile::InMemory;
     let node_type = NodeTypeConfigFile::FullNode;
     let max_tip_age = 1000;
@@ -105,9 +104,6 @@ fn read_config_override_values() {
         p2p_add_node: Some(vec![p2p_add_node.to_owned()]),
         p2p_ban_threshold: Some(p2p_ban_threshold),
         p2p_outbound_connection_timeout: Some(p2p_timeout),
-        p2p_enable_mdns: Some(enable_mdns),
-        p2p_mdns_query_interval: None,
-        p2p_enable_ipv6_mdns_discovery: None,
         http_rpc_addr: Some(http_rpc_addr),
         http_rpc_enabled: Some(true),
         ws_rpc_addr: Some(ws_rpc_addr),
@@ -207,9 +203,6 @@ fn default_run_options() -> RunOptions {
         p2p_add_node: None,
         p2p_ban_threshold: None,
         p2p_outbound_connection_timeout: None,
-        p2p_enable_mdns: None,
-        p2p_mdns_query_interval: None,
-        p2p_enable_ipv6_mdns_discovery: None,
         http_rpc_addr: None,
         http_rpc_enabled: None,
         ws_rpc_addr: None,
diff --git a/p2p/backend-test-suite/src/block_announcement.rs b/p2p/backend-test-suite/src/block_announcement.rs
index 4d85197b4..ccb781818 100644
--- a/p2p/backend-test-suite/src/block_announcement.rs
+++ b/p2p/backend-test-suite/src/block_announcement.rs
@@ -144,7 +144,6 @@ where
         ban_threshold: Default::default(),
         ban_duration: Default::default(),
         outbound_connection_timeout: Default::default(),
-        mdns_config: Default::default(),
         node_type: NodeType::Inactive.into(),
     });
     let (mut conn1, mut sync1) = S::start(
diff --git a/p2p/src/peer_manager/peerdb/tests.rs b/p2p/src/peer_manager/peerdb/tests.rs
index f2e435e4f..ac0e6a751 100644
--- a/p2p/src/peer_manager/peerdb/tests.rs
+++ b/p2p/src/peer_manager/peerdb/tests.rs
@@ -100,7 +100,6 @@ where
         ban_threshold: 200.into(),
         ban_duration: Default::default(),
         outbound_connection_timeout: Default::default(),
-        mdns_config: Default::default(),
         node_type: Default::default(),
     };
     let mut peerdb = PeerDb::<S>::new(Arc::new(config)).unwrap();
@@ -139,7 +138,6 @@ where
         ban_threshold: 20.into(),
         ban_duration: Default::default(),
         outbound_connection_timeout: Default::default(),
-        mdns_config: Default::default(),
         node_type: Default::default(),
     };
     let mut peerdb = PeerDb::<S>::new(Arc::new(config)).unwrap();
@@ -177,7 +175,6 @@ where
         ban_threshold: Default::default(),
         ban_duration: Duration::from_secs(2).into(),
         outbound_connection_timeout: Default::default(),
-        mdns_config: Default::default(),
         node_type: Default::default(),
     }))
     .unwrap();
diff --git a/p2p/src/peer_manager/tests/connections.rs b/p2p/src/peer_manager/tests/connections.rs
index 2ba7abf85..6b3faa45f 100644
--- a/p2p/src/peer_manager/tests/connections.rs
+++ b/p2p/src/peer_manager/tests/connections.rs
@@ -639,7 +639,6 @@ where
         ban_threshold: Default::default(),
         ban_duration: Default::default(),
         outbound_connection_timeout: Default::default(),
-        mdns_config: Default::default(),
         node_type: Default::default(),
     });
     let tx1 = run_peer_manager::<T>(
diff --git a/p2p/src/sync/tests/mod.rs b/p2p/src/sync/tests/mod.rs
index b26a621fb..d0d4458ff 100644
--- a/p2p/src/sync/tests/mod.rs
+++ b/p2p/src/sync/tests/mod.rs
@@ -25,7 +25,7 @@ use tokio::sync::mpsc;
 use chainstate::{make_chainstate, ChainstateConfig, DefaultTransactionVerificationStrategy};
 
 use crate::{
-    config::{MdnsConfig, NodeType, P2pConfig},
+    config::{NodeType, P2pConfig},
     event::{PeerManagerEvent, SyncControlEvent},
     net::{mock::types::MockPeerId, ConnectivityService},
     sync::{peer, BlockSyncManager},
@@ -75,7 +75,6 @@ where
         ban_threshold: 100.into(),
         ban_duration: Default::default(),
         outbound_connection_timeout: 10.into(),
-        mdns_config: MdnsConfig::Disabled.into(),
         node_type: NodeType::Full.into(),
     });
     let (conn, sync) = T::start(
diff --git a/test/functional/test_framework/.mintlayer/config.toml b/test/functional/test_framework/.mintlayer/config.toml
index 1e510857f..ff309770a 100644
--- a/test/functional/test_framework/.mintlayer/config.toml
+++ b/test/functional/test_framework/.mintlayer/config.toml
@@ -9,8 +9,5 @@ bind_address = ["[::1]:3031"]
 ban_threshold = 100
 outbound_connection_timeout = 10
 
-[p2p.mdns_config]
-state = "Disabled"
-
 [rpc]
 bind_address = "127.0.0.1:3030"