Skip to content

Commit f049847

Browse files
committed
fix fmt
1 parent d46c0a1 commit f049847

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

p2p/p2p/src/inbound_server.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@
44
//! them to the handshaker service and then adds them to the client pool.
55
use std::{pin::pin, sync::Arc};
66

7-
use futures::{StreamExt, SinkExt};
7+
use futures::{SinkExt, StreamExt};
88
use tokio::{
9-
sync::Semaphore, task::JoinSet, time::{sleep, timeout}
9+
sync::Semaphore,
10+
task::JoinSet,
11+
time::{sleep, timeout},
1012
};
1113
use tower::{Service, ServiceExt};
1214
use tracing::{instrument, Instrument, Span};
1315

14-
use cuprate_wire::{
15-
admin::{PingResponse, PING_OK_RESPONSE_STATUS_TEXT},
16-
AdminRequestMessage, AdminResponseMessage, BucketError, Message
17-
};
1816
use cuprate_p2p_core::{
1917
client::{Client, DoHandshakeRequest, HandshakeError, InternalPeerID},
2018
services::{AddressBookRequest, AddressBookResponse},
2119
AddressBook, ConnectionDirection, NetworkZone,
2220
};
21+
use cuprate_wire::{
22+
admin::{PingResponse, PING_OK_RESPONSE_STATUS_TEXT},
23+
AdminRequestMessage, AdminResponseMessage, BucketError, Message,
24+
};
2325

2426
use crate::{
2527
client_pool::ClientPool,
26-
constants::{HANDSHAKE_TIMEOUT, INBOUND_CONNECTION_COOL_DOWN, PING_REQUEST_CONCURRENCY, PING_REQUEST_TIMEOUT},
28+
constants::{
29+
HANDSHAKE_TIMEOUT, INBOUND_CONNECTION_COOL_DOWN, PING_REQUEST_CONCURRENCY,
30+
PING_REQUEST_TIMEOUT,
31+
},
2732
P2PConfig,
2833
};
2934

@@ -46,7 +51,7 @@ where
4651
{
4752
// Copying the peer_id before borrowing for ping responses (Make us avoid a `clone()`).
4853
let our_peer_id = config.basic_node_data().peer_id;
49-
54+
5055
// Mandatory. Extract server config from P2PConfig
5156
let Some(server_config) = config.server_config else {
5257
tracing::warn!("No inbound server config provided, not listening for inbound connections.");
@@ -61,7 +66,7 @@ where
6166

6267
let mut listener = pin!(listener);
6368

64-
// Create semaphore for limiting to maximum inbound connections.
69+
// Create semaphore for limiting to maximum inbound connections.
6570
let semaphore = Arc::new(Semaphore::new(config.max_inbound_connections));
6671
// Create ping request handling JoinSet
6772
let mut ping_join_set = JoinSet::new();
@@ -94,7 +99,7 @@ where
9499
None => InternalPeerID::Unknown(rand::random()),
95100
};
96101

97-
// If we're still behind our maximum limit, Initiate handshake.
102+
// If we're still behind our maximum limit, Initiate handshake.
98103
if let Ok(permit) = semaphore.clone().try_acquire_owned() {
99104
tracing::debug!("Permit free for incoming connection, attempting handshake.");
100105

@@ -119,23 +124,19 @@ where
119124
} else {
120125
// Otherwise check if the node is simply pinging us.
121126
tracing::debug!("No permit free for incoming connection.");
122-
127+
123128
// We only handle 2 ping request conccurently. Otherwise we drop the connection immediately.
124129
if ping_join_set.len() < PING_REQUEST_CONCURRENCY {
125130
ping_join_set.spawn(
126131
async move {
127132
// Await first message from node. If it is a ping request we respond back, otherwise we drop the connection.
128133
let fut = timeout(PING_REQUEST_TIMEOUT, peer_stream.next());
129-
130134
#[allow(clippy::collapsible_match)]
131135
// Ok if timeout did not elapsed -> Some if there is a message -> Ok if it has been decoded
132136
if let Ok(Some(Result::<Message,BucketError>::Ok(command))) = fut.await {
133-
134137
if let Message::Request(AdminRequestMessage::Ping) = command {
135-
let _ = peer_sink
136-
.send(Message::Response(AdminResponseMessage::Ping(
137-
PingResponse {
138-
status: PING_OK_RESPONSE_STATUS_TEXT,
138+
let _ = peer_sink.send(Message::Response(AdminResponseMessage::Ping(PingResponse {
139+
status: PING_OK_RESPONSE_STATUS_TEXT,
139140
peer_id: our_peer_id
140141
}
141142
)).into())

0 commit comments

Comments
 (0)