Skip to content

Commit

Permalink
chore(p2p): follow-up nits (#2302)
Browse files Browse the repository at this point in the history
* handle p2p features properly

Signed-off-by: onur-ozkan <work@onurozkan.dev>

* use `PeerId` type for timestamp channel straight away

Signed-off-by: onur-ozkan <work@onurozkan.dev>

---------

Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan authored Dec 24, 2024
1 parent 87be260 commit 72bc73e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion mm2src/mm2_main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion mm2src/mm2_p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[features]
default = []
default = ["application"]
application = ["dep:mm2_number"]

[lib]
Expand Down
10 changes: 4 additions & 6 deletions mm2src/mm2_p2p/src/behaviours/atomicdex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub async fn get_relay_mesh(mut cmd_tx: AdexCmdTx) -> Vec<String> {
rx.await.expect("Tx should be present")
}

async fn validate_peer_time(peer: PeerId, mut response_tx: Sender<Option<PeerId>>, rp_sender: RequestResponseSender) {
async fn validate_peer_time(peer: PeerId, mut response_tx: Sender<PeerId>, 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.");
Expand All @@ -257,24 +257,22 @@ async fn validate_peer_time(peer: PeerId, mut response_tx: Sender<Option<PeerId>
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;
},
}

// 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<u8>, mut request_response_tx: RequestResponseSender) -> PeerResponse {
Expand Down Expand Up @@ -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.");
}
Expand Down

0 comments on commit 72bc73e

Please sign in to comment.