Skip to content

Commit

Permalink
chore: debug dump peerstore
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Nov 19, 2024
1 parent 18d0d94 commit bbcb939
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions network/src/peer_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl PeerRegistry {
session_type: SessionType,
peer_store: &mut PeerStore,
) -> Result<Option<Peer>, Error> {
debug!("start accept peer {:?}", session_id);
if self.peers.contains_key(&session_id) {
return Err(PeerError::SessionExists(session_id).into());
}
Expand Down Expand Up @@ -112,6 +113,7 @@ impl PeerRegistry {
peer_store.add_connected_peer(remote_addr.clone(), session_type);
let peer = Peer::new(session_id, session_type, remote_addr, is_whitelist);
self.peers.insert(session_id, peer);
debug!("end accept peer {:?}", session_id);
Ok(evicted_peer)
}

Expand Down
7 changes: 2 additions & 5 deletions network/src/services/dump_peer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
task::{Context, Poll},
time::Duration,
};
use tokio::time::{Instant, Interval, MissedTickBehavior};
use tokio::time::{Interval, MissedTickBehavior};

const DEFAULT_DUMP_INTERVAL: Duration = Duration::from_secs(3600); // 1 hour

Expand Down Expand Up @@ -50,10 +50,7 @@ impl Future for DumpPeerStoreService {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.interval.is_none() {
self.interval = {
let mut interval = tokio::time::interval_at(
Instant::now() + DEFAULT_DUMP_INTERVAL,
DEFAULT_DUMP_INTERVAL,
);
let mut interval = tokio::time::interval(DEFAULT_DUMP_INTERVAL);
// The dump peer store service does not need to urgently compensate for the missed wake,
// just delay behavior is enough
interval.set_missed_tick_behavior(MissedTickBehavior::Delay);
Expand Down
6 changes: 5 additions & 1 deletion test/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ckb_app_config::NetworkConfig;
use ckb_async_runtime::{new_global_runtime, Runtime};
use ckb_chain_spec::consensus::Consensus;
use ckb_channel::{self as channel, unbounded, Receiver, RecvTimeoutError, Sender};
use ckb_logger::info;
use ckb_logger::{debug, info};
use ckb_network::{
async_trait, bytes::Bytes, extract_peer_id, CKBProtocol, CKBProtocolContext,
CKBProtocolHandler, Flags, NetworkController, NetworkService, NetworkState, PeerIndex,
Expand Down Expand Up @@ -217,6 +217,10 @@ impl CKBProtocolHandler for DummyProtocolHandler {
peer_index: PeerIndex,
_version: &str,
) {
debug!(
"DummyProtocolHandler connected peer_index: {:?}",
peer_index
);
let peer = nc.get_peer(peer_index).unwrap();
let node_id = extract_peer_id(&peer.connected_addr)
.map(|peer_id| peer_id.to_base58())
Expand Down

0 comments on commit bbcb939

Please sign in to comment.