Skip to content

Commit bc912e2

Browse files
authored
add listener log (#23)
* add listener log * network_bootstrap 0.2.1
1 parent 528b740 commit bc912e2

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "network_bootstrap"
3-
version = "0.2.0-beta1"
3+
version = "0.2.1"
44
edition = "2021"
55

66
[dependencies]

src/mod_libp2p/network.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use once_cell::sync::Lazy;
2222
use serde_json::{json, Value};
2323
use std::{collections::HashSet, error::Error, time::Duration};
2424
use tokio::sync::Mutex;
25-
use tracing::{error, info};
25+
use tracing::{error, info, warn};
2626

2727
pub const TEST_BOOSTNODE_PEER_ID_LIST: [&str; 3] = [
2828
"16Uiu2HAm5SPUotukayoKUZG5jQQ9zAGgjAXXz4Tg62kzZMbikLdQ",
@@ -76,6 +76,7 @@ impl EventLoop {
7676
pub(crate) async fn run(&mut self) {
7777
let mut interval1 = tokio::time::interval(tokio::time::Duration::from_secs(60));
7878
let mut interval2 = tokio::time::interval(tokio::time::Duration::from_secs(60));
79+
let mut interval3 = tokio::time::interval(tokio::time::Duration::from_secs(60));
7980
loop {
8081
tokio::select! {
8182
event = self.swarm.select_next_some() => self.handle_event(event).await,
@@ -91,6 +92,10 @@ impl EventLoop {
9192
}
9293
info!("\n------ 60 secs, local_peer_id is {:?}, swarm peer list is {:?}\n\n", self.swarm.local_peer_id(), peer_list);
9394
}
95+
96+
_ = interval3.tick() => {
97+
info!("------ 60 secs, Listeners: {:?}", self.swarm.listeners().collect::<Vec<_>>());
98+
}
9499
}
95100
}
96101
}
@@ -111,6 +116,28 @@ impl EventLoop {
111116
_ = self.swarm.disconnect_peer_id(peer_id);
112117
}
113118
}
119+
SwarmEvent::ListenerClosed {
120+
reason,
121+
addresses,
122+
listener_id,
123+
} => {
124+
warn!(
125+
"Listener closed: {:?}, addresses: {:?}, listener_id is {:?}",
126+
reason, addresses, listener_id
127+
);
128+
for addr in addresses {
129+
warn!("Attempting to re-listen on: {:?}", addr);
130+
if let Err(e) = self.swarm.listen_on(addr.clone()) {
131+
warn!("Failed to re-listen on {:?}: {:?}", addr, e);
132+
}
133+
}
134+
}
135+
SwarmEvent::ListenerError { error, listener_id } => {
136+
warn!(
137+
"Listener error: {:?}, listener_id: {:?}",
138+
error, listener_id
139+
);
140+
}
114141
SwarmEvent::Behaviour(AgentEvent::Identify(sub_event)) => {
115142
self.handle_identify_event(sub_event).await
116143
}

0 commit comments

Comments
 (0)