Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Oct 26, 2024
1 parent df002c7 commit 8ac3019
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions network/src/services/dump_peer_store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::NetworkState;
use ckb_logger::{debug, warn};
use futures::{Future, StreamExt};
use p2p::runtime::{Interval, MissedTickBehavior};
use futures::Future;
use std::{
pin::Pin,
sync::Arc,
Expand All @@ -14,7 +13,10 @@ const DEFAULT_DUMP_INTERVAL: Duration = Duration::from_secs(3600); // 1 hour
/// Save current peer store data regularly
pub struct DumpPeerStoreService {
network_state: Arc<NetworkState>,
interval: Option<Interval>,
#[cfg(not(target_family = "wasm"))]
interval: Option<tokio::time::Interval>,
#[cfg(target_family = "wasm")]
interval: Option<p2p::runtime::Interval>,
}

impl DumpPeerStoreService {
Expand Down Expand Up @@ -48,13 +50,35 @@ impl Drop for DumpPeerStoreService {
impl Future for DumpPeerStoreService {
type Output = ();

#[cfg(not(target_family = "wasm"))]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.interval.is_none() {
self.interval = {
let mut interval = Interval::new(DEFAULT_DUMP_INTERVAL);
let mut interval = tokio::time::interval_at(
tokio::time::Instant::now() + DEFAULT_DUMP_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);
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);
Some(interval)
}
}
while self.interval.as_mut().unwrap().poll_tick(cx).is_ready() {
self.dump_peer_store()
}
Poll::Pending
}

#[cfg(target_family = "wasm")]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
use futures::StreamExt;
if self.interval.is_none() {
self.interval = {
let mut interval = p2p::runtime::Interval::new(DEFAULT_DUMP_INTERVAL);
// The outbound service does not need to urgently compensate for the missed wake,
// just skip behavior is enough
interval.set_missed_tick_behavior(p2p::runtime::MissedTickBehavior::Skip);
Some(interval)
}
}
Expand Down

0 comments on commit 8ac3019

Please sign in to comment.