1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use crate::behaviour::peer_store::store::Store;
use crate::task::ConnexaTask;
use libp2p::ping::Event as PingEvent;
use libp2p::swarm::NetworkBehaviour;
use std::fmt::Debug;
impl<X, C: NetworkBehaviour, S, T, K> ConnexaTask<X, C, S, T, K>
where
X: Default + Send + 'static,
C: Send,
C::ToSwarm: Debug,
S: Store,
{
pub fn process_ping_event(&mut self, event: PingEvent) {
let PingEvent {
peer,
connection,
result,
} = event;
match result {
Ok(duration) => {
tracing::info!("ping to {} at {} took {:?}", peer, connection, duration);
// #[cfg(feature = "relay")]
// if let Some(autorelay) = self
// .swarm
// .as_mut()
// .expect("swarm valid")
// .behaviour_mut()
// .autorelay
// .as_mut()
// {
// autorelay.set_peer_ping(peer, connection, duration);
// }
}
Err(e) => {
// TODO: Possibly disconnect peer since if there is an error?
tracing::error!("ping to {} at {} failed: {:?}", peer, connection, e);
}
}
}
}