From d1a8ea7a17d6199c1a2460ab8a3d360a968ea36c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Tue, 10 Sep 2024 09:26:03 +0300 Subject: [PATCH] chore(RPCs): rename `get_peers_info` RPC to `get_directly_connected_peers` (#2195) `get_peers_info` RPC had a misleading name, it only returns the directly connected peers, not all network peers. This commit renames the RPC to `get_directly_connected_peers` which causes a breaking change. --- mm2src/mm2_libp2p/src/atomicdex_behaviour.rs | 4 ++-- mm2src/mm2_main/src/rpc/dispatcher/dispatcher_legacy.rs | 2 +- .../mm2_main/src/rpc/lp_commands/lp_commands_legacy.rs | 4 ++-- mm2src/mm2_net/src/network_event.rs | 4 ++-- mm2src/mm2_p2p/src/behaviours/atomicdex.rs | 4 ++-- mm2src/mm2_p2p/src/lib.rs | 9 +++++---- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/mm2src/mm2_libp2p/src/atomicdex_behaviour.rs b/mm2src/mm2_libp2p/src/atomicdex_behaviour.rs index 482251fb93..c0f2c47725 100644 --- a/mm2src/mm2_libp2p/src/atomicdex_behaviour.rs +++ b/mm2src/mm2_libp2p/src/atomicdex_behaviour.rs @@ -46,8 +46,8 @@ const ANNOUNCE_INTERVAL: Duration = Duration::from_secs(600); const ANNOUNCE_INITIAL_DELAY: Duration = Duration::from_secs(60); const CHANNEL_BUF_SIZE: usize = 1024 * 8; -/// Returns info about connected peers -pub async fn get_peers_info(mut cmd_tx: AdexCmdTx) -> BTreeMap> { +/// Returns info about directly connected peers. +pub async fn get_directly_connected_peers(mut cmd_tx: AdexCmdTx) -> BTreeMap> { let (result_tx, rx) = oneshot::channel(); let cmd = AdexBehaviourCmd::GetPeersInfo { result_tx }; cmd_tx.send(cmd).await.expect("Rx should be present"); diff --git a/mm2src/mm2_main/src/rpc/dispatcher/dispatcher_legacy.rs b/mm2src/mm2_main/src/rpc/dispatcher/dispatcher_legacy.rs index bcb09c4d51..2415bc31ef 100644 --- a/mm2src/mm2_main/src/rpc/dispatcher/dispatcher_legacy.rs +++ b/mm2src/mm2_main/src/rpc/dispatcher/dispatcher_legacy.rs @@ -73,11 +73,11 @@ pub fn dispatcher(req: Json, ctx: MmArc) -> DispatcherRes { "electrum" => hyres(electrum(ctx, req)), "enable" => hyres(enable(ctx, req)), "get_enabled_coins" => hyres(get_enabled_coins(ctx)), + "get_directly_connected_peers" => hyres(get_directly_connected_peers(ctx)), "get_gossip_mesh" => hyres(get_gossip_mesh(ctx)), "get_gossip_peer_topics" => hyres(get_gossip_peer_topics(ctx)), "get_gossip_topic_peers" => hyres(get_gossip_topic_peers(ctx)), "get_my_peer_id" => hyres(get_my_peer_id(ctx)), - "get_peers_info" => hyres(get_peers_info(ctx)), "get_relay_mesh" => hyres(get_relay_mesh(ctx)), "get_trade_fee" => hyres(get_trade_fee(ctx, req)), // "fundvalue" => lp_fundvalue (ctx, req, false), diff --git a/mm2src/mm2_main/src/rpc/lp_commands/lp_commands_legacy.rs b/mm2src/mm2_main/src/rpc/lp_commands/lp_commands_legacy.rs index 2769539d9b..7db7c5b02b 100644 --- a/mm2src/mm2_main/src/rpc/lp_commands/lp_commands_legacy.rs +++ b/mm2src/mm2_main/src/rpc/lp_commands/lp_commands_legacy.rs @@ -316,10 +316,10 @@ pub fn version(ctx: MmArc) -> HyRes { } } -pub async fn get_peers_info(ctx: MmArc) -> Result>, String> { +pub async fn get_directly_connected_peers(ctx: MmArc) -> Result>, String> { let ctx = P2PContext::fetch_from_mm_arc(&ctx); let cmd_tx = ctx.cmd_tx.lock().clone(); - let result = mm2_libp2p::get_peers_info(cmd_tx).await; + let result = mm2_libp2p::get_directly_connected_peers(cmd_tx).await; let result = json!({ "result": result, }); diff --git a/mm2src/mm2_net/src/network_event.rs b/mm2src/mm2_net/src/network_event.rs index b88655f383..9ff7ae15f7 100644 --- a/mm2src/mm2_net/src/network_event.rs +++ b/mm2src/mm2_net/src/network_event.rs @@ -30,14 +30,14 @@ impl EventBehaviour for NetworkEvent { loop { let p2p_cmd_tx = p2p_ctx.cmd_tx.lock().clone(); - let peers_info = atomicdex::get_peers_info(p2p_cmd_tx.clone()).await; + let directly_connected_peers = atomicdex::get_directly_connected_peers(p2p_cmd_tx.clone()).await; let gossip_mesh = atomicdex::get_gossip_mesh(p2p_cmd_tx.clone()).await; let gossip_peer_topics = atomicdex::get_gossip_peer_topics(p2p_cmd_tx.clone()).await; let gossip_topic_peers = atomicdex::get_gossip_topic_peers(p2p_cmd_tx.clone()).await; let relay_mesh = atomicdex::get_relay_mesh(p2p_cmd_tx).await; let event_data = json!({ - "peers_info": peers_info, + "directly_connected_peers": directly_connected_peers, "gossip_mesh": gossip_mesh, "gossip_peer_topics": gossip_peer_topics, "gossip_topic_peers": gossip_topic_peers, diff --git a/mm2src/mm2_p2p/src/behaviours/atomicdex.rs b/mm2src/mm2_p2p/src/behaviours/atomicdex.rs index db907711ba..9d58da4e1e 100644 --- a/mm2src/mm2_p2p/src/behaviours/atomicdex.rs +++ b/mm2src/mm2_p2p/src/behaviours/atomicdex.rs @@ -162,8 +162,8 @@ pub enum AdexBehaviourCmd { }, } -/// Returns info about connected peers -pub async fn get_peers_info(mut cmd_tx: AdexCmdTx) -> HashMap> { +/// Returns info about directly connected peers. +pub async fn get_directly_connected_peers(mut cmd_tx: AdexCmdTx) -> HashMap> { let (result_tx, rx) = oneshot::channel(); let cmd = AdexBehaviourCmd::GetPeersInfo { result_tx }; cmd_tx.send(cmd).await.expect("Rx should be present"); diff --git a/mm2src/mm2_p2p/src/lib.rs b/mm2src/mm2_p2p/src/lib.rs index e9a8f78ad4..8e6e6db159 100644 --- a/mm2src/mm2_p2p/src/lib.rs +++ b/mm2src/mm2_p2p/src/lib.rs @@ -16,10 +16,11 @@ use sha2::{Digest, Sha256}; pub use crate::swarm_runtime::SwarmRuntime; // atomicdex related re-exports -pub use behaviours::atomicdex::{get_gossip_mesh, get_gossip_peer_topics, get_gossip_topic_peers, get_peers_info, - get_relay_mesh, spawn_gossipsub, AdexBehaviourCmd, AdexBehaviourError, - AdexBehaviourEvent, AdexCmdTx, AdexEventRx, AdexResponse, AdexResponseChannel, - GossipsubEvent, GossipsubMessage, MessageId, NodeType, TopicHash, WssCerts}; +pub use behaviours::atomicdex::{get_directly_connected_peers, get_gossip_mesh, get_gossip_peer_topics, + get_gossip_topic_peers, get_relay_mesh, spawn_gossipsub, AdexBehaviourCmd, + AdexBehaviourError, AdexBehaviourEvent, AdexCmdTx, AdexEventRx, AdexResponse, + AdexResponseChannel, GossipsubEvent, GossipsubMessage, MessageId, NodeType, TopicHash, + WssCerts}; // peers-exchange re-exports pub use behaviours::peers_exchange::PeerAddresses;