Skip to content

Commit 6e562f6

Browse files
committed
fix connection log issue due to version compat
1 parent e76a821 commit 6e562f6

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ default-members = ["compute"]
77

88
[workspace.package]
99
edition = "2021"
10-
version = "0.4.0"
10+
version = "0.4.1"
1111
license = "Apache-2.0"
1212
readme = "README.md"
1313

p2p/src/client.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -298,51 +298,60 @@ impl DriaP2PClient {
298298

299299
SwarmEvent::ConnectionEstablished {
300300
peer_id,
301-
num_established,
302301
connection_id,
303302
endpoint,
304303
..
305304
} => {
306-
log::info!(
307-
"Connection ({connection_id}) established with peer {peer_id} ({} connections) at {:?}",
308-
num_established,
309-
endpoint
310-
);
305+
if endpoint.is_dialer() {
306+
// we only care about logs about the ones that we have dialed
307+
log::info!(
308+
"Connection ({connection_id}) established with {peer_id} at {}",
309+
endpoint.get_remote_address()
310+
);
311+
} else {
312+
log::debug!(
313+
"Connection ({connection_id}) established with {peer_id} from {}",
314+
endpoint.get_remote_address()
315+
);
316+
}
311317
}
312318

313319
SwarmEvent::ConnectionClosed {
314320
peer_id,
315321
connection_id,
316322
endpoint,
317-
num_established,
318323
cause,
324+
..
319325
} => {
320-
log::warn!(
321-
"Connection ({connection_id}) closed for {peer_id} ({} connections)\nCause: {}",
322-
num_established,
323-
cause
324-
.map(|c| c.to_string())
325-
.unwrap_or("Unknown".to_string())
326-
);
327-
326+
let cause = cause
327+
.map(|c| c.to_string())
328+
.unwrap_or("Unknown".to_string());
328329
if endpoint.is_dialer() {
330+
// we only care about logs about the ones that we have dialed
331+
log::warn!("Connection ({connection_id}) closed for {peer_id}\nCause: {cause}");
332+
329333
let addr = endpoint.get_remote_address();
330334
log::info!("Dialing {} again at {}", peer_id, addr);
331-
if let Err(e) = self.swarm.dial(
335+
if let Err(err) = self.swarm.dial(
332336
DialOpts::peer_id(peer_id)
333337
.addresses(vec![addr.clone()])
334338
.condition(PeerCondition::DisconnectedAndNotDialing)
335339
.build(),
336340
) {
337-
log::error!("Could not dial peer {}: {:?}", peer_id, e);
341+
log::error!("Could not dial peer {peer_id}: {err:?}");
338342
}
343+
} else {
344+
log::debug!(
345+
"Connection ({connection_id}) closed for {peer_id}\nCause: {cause}"
346+
);
339347
}
340348
}
341349

342350
SwarmEvent::ExpiredListenAddr {
343351
address,
344352
listener_id,
345353
} => {
354+
// this may happen when your connection is lost, e.g. you turn off your machine / internet
346355
log::warn!("Listener ({listener_id}) expired: {address}");
347356
}
348357

p2p/tests/request_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async fn test_request_message() -> Result<()> {
2525
.try_init();
2626

2727
// prepare nodes
28-
let rpc_addr = "TODO: !!!".parse().unwrap();
28+
let rpc_addr = "your-rpc-here".parse().unwrap();
2929

3030
// spawn P2P client in another task
3131
let (client, mut commander, mut req_rx) = DriaP2PClient::new(

0 commit comments

Comments
 (0)