Skip to content

Commit

Permalink
rename get_peers_info RPC to get_directly_connected_peers and upd…
Browse files Browse the repository at this point in the history
…ate its doc

Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Sep 10, 2024
1 parent 25fc412 commit f06f614
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions mm2src/mm2_libp2p/src/atomicdex_behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Vec<String>> {
/// Returns info about directly connected peers.
pub async fn get_directly_connected_peers(mut cmd_tx: AdexCmdTx) -> BTreeMap<String, Vec<String>> {
let (result_tx, rx) = oneshot::channel();
let cmd = AdexBehaviourCmd::GetPeersInfo { result_tx };
cmd_tx.send(cmd).await.expect("Rx should be present");
Expand Down
2 changes: 1 addition & 1 deletion mm2src/mm2_main/src/rpc/dispatcher/dispatcher_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ pub fn dispatcher(req: Json, ctx: MmArc) -> DispatcherRes {
"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_directly_connected_peers" => hyres(get_directly_connected_peers(ctx)),
"get_trade_fee" => hyres(get_trade_fee(ctx, req)),
// "fundvalue" => lp_fundvalue (ctx, req, false),
"help" => help(),
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_main/src/rpc/lp_commands/lp_commands_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ pub fn version(ctx: MmArc) -> HyRes {
}
}

pub async fn get_peers_info(ctx: MmArc) -> Result<Response<Vec<u8>>, String> {
pub async fn get_directly_connected_peers(ctx: MmArc) -> Result<Response<Vec<u8>>, 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,
});
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_net/src/network_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ 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 seeds_info = 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,
"gossip_mesh": gossip_mesh,
"gossip_peer_topics": gossip_peer_topics,
"gossip_topic_peers": gossip_topic_peers,
"relay_mesh": relay_mesh,
"seeds_info": seeds_info,
});

if previously_sent != event_data {
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_p2p/src/behaviours/atomicdex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ pub enum AdexBehaviourCmd {
},
}

/// Returns info about connected peers
pub async fn get_peers_info(mut cmd_tx: AdexCmdTx) -> HashMap<String, Vec<String>> {
/// Returns info about directly connected peers.
pub async fn get_directly_connected_peers(mut cmd_tx: AdexCmdTx) -> HashMap<String, Vec<String>> {
let (result_tx, rx) = oneshot::channel();
let cmd = AdexBehaviourCmd::GetPeersInfo { result_tx };
cmd_tx.send(cmd).await.expect("Rx should be present");
Expand Down
9 changes: 5 additions & 4 deletions mm2src/mm2_p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f06f614

Please sign in to comment.