From 72bc73ec955de74e0687af44d0ca080e358c2821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Tue, 24 Dec 2024 10:24:42 +0300 Subject: [PATCH] chore(p2p): follow-up nits (#2302) * handle p2p features properly Signed-off-by: onur-ozkan * use `PeerId` type for timestamp channel straight away Signed-off-by: onur-ozkan --------- Signed-off-by: onur-ozkan --- mm2src/coins/Cargo.toml | 2 +- mm2src/mm2_main/Cargo.toml | 2 +- mm2src/mm2_p2p/Cargo.toml | 2 +- mm2src/mm2_p2p/src/behaviours/atomicdex.rs | 10 ++++------ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/mm2src/coins/Cargo.toml b/mm2src/coins/Cargo.toml index 290a0dd7f5..49616d1fa4 100644 --- a/mm2src/coins/Cargo.toml +++ b/mm2src/coins/Cargo.toml @@ -69,7 +69,7 @@ mm2_io = { path = "../mm2_io" } mm2_metrics = { path = "../mm2_metrics" } mm2_net = { path = "../mm2_net" } mm2_number = { path = "../mm2_number"} -mm2_p2p = { path = "../mm2_p2p" } +mm2_p2p = { path = "../mm2_p2p", default-features = false } mm2_rpc = { path = "../mm2_rpc" } mm2_state_machine = { path = "../mm2_state_machine" } mocktopus = "0.8.0" diff --git a/mm2src/mm2_main/Cargo.toml b/mm2src/mm2_main/Cargo.toml index 13d53b8eea..22bb3e705b 100644 --- a/mm2src/mm2_main/Cargo.toml +++ b/mm2src/mm2_main/Cargo.toml @@ -65,7 +65,7 @@ mm2_err_handle = { path = "../mm2_err_handle" } mm2_event_stream = { path = "../mm2_event_stream" } mm2_gui_storage = { path = "../mm2_gui_storage" } mm2_io = { path = "../mm2_io" } -mm2_libp2p = { path = "../mm2_p2p", package = "mm2_p2p", features = ["application"] } +mm2_libp2p = { path = "../mm2_p2p", package = "mm2_p2p" } mm2_metrics = { path = "../mm2_metrics" } mm2_net = { path = "../mm2_net" } mm2_number = { path = "../mm2_number" } diff --git a/mm2src/mm2_p2p/Cargo.toml b/mm2src/mm2_p2p/Cargo.toml index 85efa47879..41a82c3c16 100644 --- a/mm2src/mm2_p2p/Cargo.toml +++ b/mm2src/mm2_p2p/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [features] -default = [] +default = ["application"] application = ["dep:mm2_number"] [lib] diff --git a/mm2src/mm2_p2p/src/behaviours/atomicdex.rs b/mm2src/mm2_p2p/src/behaviours/atomicdex.rs index 943ad08126..6d3ccb9d69 100644 --- a/mm2src/mm2_p2p/src/behaviours/atomicdex.rs +++ b/mm2src/mm2_p2p/src/behaviours/atomicdex.rs @@ -237,7 +237,7 @@ pub async fn get_relay_mesh(mut cmd_tx: AdexCmdTx) -> Vec { rx.await.expect("Tx should be present") } -async fn validate_peer_time(peer: PeerId, mut response_tx: Sender>, rp_sender: RequestResponseSender) { +async fn validate_peer_time(peer: PeerId, mut response_tx: Sender, rp_sender: RequestResponseSender) { let request = P2PRequest::NetworkInfo(NetworkInfoRequest::GetPeerUtcTimestamp); let encoded_request = encode_message(&request) .expect("Static type `PeerInfoRequest::GetPeerUtcTimestamp` should never fail in serialization."); @@ -257,16 +257,14 @@ async fn validate_peer_time(peer: PeerId, mut response_tx: Sender debug!( "Peer '{peer}' is within the acceptable time gap ({MAX_TIME_GAP_FOR_CONNECTED_PEER} seconds); time difference is {diff} seconds." ); - response_tx.send(None).await.unwrap(); return; } }; }, other => { error!("Unexpected response `{other:?}` from peer `{peer}`"); - // TODO: Ideally, we should send `Some(peer)` to end the connection, + // TODO: Ideally, we should send `peer` to end the connection, // but we don't want to cause a breaking change yet. - response_tx.send(None).await.unwrap(); return; }, } @@ -274,7 +272,7 @@ async fn validate_peer_time(peer: PeerId, mut response_tx: Sender // If the function reaches this point, this means validation has failed. // Send the peer ID to disconnect from it. error!("Failed to validate the time for peer `{peer}`; disconnecting."); - response_tx.send(Some(peer)).await.unwrap(); + response_tx.send(peer).await.unwrap(); } async fn request_one_peer(peer: PeerId, req: Vec, mut request_response_tx: RequestResponseSender) -> PeerResponse { @@ -818,7 +816,7 @@ fn start_gossipsub( } } - while let Poll::Ready(Some(Some(peer_id))) = timestamp_rx.poll_next_unpin(cx) { + while let Poll::Ready(Some(peer_id)) = timestamp_rx.poll_next_unpin(cx) { if swarm.disconnect_peer_id(peer_id).is_err() { error!("Disconnection from `{peer_id}` failed unexpectedly, which should never happen."); }