From 41aca51116190eab9c4c01c8e9a0c06976bc072e Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Thu, 7 Dec 2023 00:14:59 +0300 Subject: [PATCH] deprecate 7777 network Signed-off-by: onur-ozkan --- mm2src/mm2_main/src/lp_native_dex.rs | 11 ++++++++--- mm2src/mm2_main/src/lp_network.rs | 2 ++ mm2src/mm2_p2p/src/behaviours/atomicdex.rs | 10 +++++++--- mm2src/mm2_p2p/src/network.rs | 8 ++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/mm2src/mm2_main/src/lp_native_dex.rs b/mm2src/mm2_main/src/lp_native_dex.rs index c00ad9916f..a8d4019677 100644 --- a/mm2src/mm2_main/src/lp_native_dex.rs +++ b/mm2src/mm2_main/src/lp_native_dex.rs @@ -29,6 +29,7 @@ use mm2_core::mm_ctx::{MmArc, MmCtx}; use mm2_err_handle::common_errors::InternalError; use mm2_err_handle::prelude::*; use mm2_event_stream::behaviour::{EventBehaviour, EventInitStatus}; +use mm2_libp2p::behaviours::atomicdex::DEPRECATED_NETID_LIST; use mm2_libp2p::{spawn_gossipsub, AdexBehaviourError, NodeType, RelayAddress, RelayAddressError, SwarmRuntime, WssCerts}; use mm2_metrics::mm_gauge; @@ -68,7 +69,7 @@ cfg_wasm32! { pub mod init_metamask; } -const NETID_8762_SEEDNODES: [&str; 3] = [ +const DEFAULT_NETID_SEEDNODES: [&str; 3] = [ "streamseed1.komodo.earth", "streamseed2.komodo.earth", "streamseed3.komodo.earth", @@ -267,7 +268,7 @@ impl MmInitError { #[cfg(target_arch = "wasm32")] fn default_seednodes(netid: u16) -> Vec { if netid == 8762 { - NETID_8762_SEEDNODES + DEFAULT_NETID_SEEDNODES .iter() .map(|seed| RelayAddress::Dns(seed.to_string())) .collect() @@ -280,7 +281,7 @@ fn default_seednodes(netid: u16) -> Vec { fn default_seednodes(netid: u16) -> Vec { use crate::mm2::lp_network::addr_to_ipv4_string; if netid == 8762 { - NETID_8762_SEEDNODES + DEFAULT_NETID_SEEDNODES .iter() .filter_map(|seed| addr_to_ipv4_string(seed).ok()) .map(RelayAddress::IPv4) @@ -523,6 +524,10 @@ pub async fn init_p2p(ctx: MmArc) -> P2PResult<()> { let i_am_seed = ctx.conf["i_am_seed"].as_bool().unwrap_or(false); let netid = ctx.netid(); + if DEPRECATED_NETID_LIST.contains(&netid) { + return MmError::err(P2PInitError::InvalidNetId(NetIdError::Deprecated { netid })); + } + let seednodes = seednodes(&ctx)?; let ctx_on_poll = ctx.clone(); diff --git a/mm2src/mm2_main/src/lp_network.rs b/mm2src/mm2_main/src/lp_network.rs index 356da9e05c..717c76d3c1 100644 --- a/mm2src/mm2_main/src/lp_network.rs +++ b/mm2src/mm2_main/src/lp_network.rs @@ -464,6 +464,8 @@ pub fn addr_to_ipv4_string(address: &str) -> Result Result<(u16, u16, u16), MmError> { diff --git a/mm2src/mm2_p2p/src/behaviours/atomicdex.rs b/mm2src/mm2_p2p/src/behaviours/atomicdex.rs index c895466515..63e98e21e7 100644 --- a/mm2src/mm2_p2p/src/behaviours/atomicdex.rs +++ b/mm2src/mm2_p2p/src/behaviours/atomicdex.rs @@ -30,7 +30,7 @@ use super::peers_exchange::{PeerAddresses, PeersExchange, PeersExchangeRequest, use super::ping::AdexPing; use super::request_response::{build_request_response_behaviour, PeerRequest, PeerResponse, RequestResponseBehaviour, RequestResponseSender}; -use crate::network::{get_all_network_seednodes, NETID_8762}; +use crate::network::{get_all_network_seednodes, DEFAULT_NETID}; use crate::relay_address::{RelayAddress, RelayAddressError}; use crate::swarm_runtime::SwarmRuntime; use crate::{NetworkInfo, NetworkPorts, RequestResponseBehaviourEvent}; @@ -51,6 +51,10 @@ const ANNOUNCE_INTERVAL: Duration = Duration::from_secs(600); const ANNOUNCE_INITIAL_DELAY: Duration = Duration::from_secs(60); const CHANNEL_BUF_SIZE: usize = 1024 * 8; +pub const DEPRECATED_NETID_LIST: &[u16] = &[ + 7777, // TODO: keep it inaccessible until Q2 of 2024. +]; + /// The structure is the same as `PeerResponse`, /// but is used to prevent `PeerResponse` from being used outside the network implementation. #[derive(Debug, Eq, PartialEq)] @@ -641,7 +645,7 @@ fn start_gossipsub( let mut gossipsub = Gossipsub::new(MessageAuthenticity::Author(local_peer_id), gossipsub_config) .map_err(|e| AdexBehaviourError::InitializationError(e.to_owned()))?; - let floodsub = Floodsub::new(local_peer_id, netid != NETID_8762); + let floodsub = Floodsub::new(local_peer_id, netid != DEFAULT_NETID); let mut peers_exchange = PeersExchange::new(network_info); if !network_info.in_memory() { @@ -735,7 +739,7 @@ fn start_gossipsub( debug!("Swarm event {:?}", event); if let SwarmEvent::Behaviour(event) = event { - if swarm.behaviour_mut().netid != NETID_8762 { + if swarm.behaviour_mut().netid != DEFAULT_NETID { if let AdexBehaviourEvent::Floodsub(FloodsubEvent::Message(message)) = &event { for topic in &message.topics { if topic == &FloodsubTopic::new(PEERS_TOPIC) { diff --git a/mm2src/mm2_p2p/src/network.rs b/mm2src/mm2_p2p/src/network.rs index 364cee72cf..c3900bbc16 100644 --- a/mm2src/mm2_p2p/src/network.rs +++ b/mm2src/mm2_p2p/src/network.rs @@ -1,10 +1,10 @@ use crate::relay_address::RelayAddress; use libp2p::PeerId; -pub const NETID_8762: u16 = 8762; +pub const DEFAULT_NETID: u16 = 8762; #[cfg_attr(target_arch = "wasm32", allow(dead_code))] -const ALL_NETID_8762_SEEDNODES: &[(&str, &str)] = &[ +const ALL_DEFAULT_NETID_SEEDNODES: &[(&str, &str)] = &[ ( "12D3KooWHKkHiNhZtKceQehHhPqwU5W1jXpoVBgS1qst899GjvTm", "168.119.236.251", @@ -52,10 +52,10 @@ pub fn get_all_network_seednodes(_netid: u16) -> Vec<(PeerId, RelayAddress)> { V pub fn get_all_network_seednodes(netid: u16) -> Vec<(PeerId, RelayAddress)> { use std::str::FromStr; - if netid != NETID_8762 { + if netid != DEFAULT_NETID { return Vec::new(); } - ALL_NETID_8762_SEEDNODES + ALL_DEFAULT_NETID_SEEDNODES .iter() .map(|(peer_id, ipv4)| { let peer_id = PeerId::from_str(peer_id).expect("valid peer id");