mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-23 21:15:41 +00:00
Buffered connection management for collator-protocol (#6022)
* Extract metrics into a separate module * Introduce validators buffer * Integrate buffer into the subsystem * Only reconnect on new advertisements * Test * comma * doc comment * Make capacity buffer compile time non-zero * Add doc comments * nits * remove derives * review * better naming * check timeout * Extract interval stream into lib * Ensure collator disconnects after timeout * spellcheck * rename buf * Remove double interval * Add a log on timeout * Cleanup buffer on timeout
This commit is contained in:
@@ -21,9 +21,12 @@
|
||||
#![deny(unused_crate_dependencies)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use futures::{FutureExt, TryFutureExt};
|
||||
use futures::{
|
||||
stream::{FusedStream, StreamExt},
|
||||
FutureExt, TryFutureExt,
|
||||
};
|
||||
|
||||
use sp_keystore::SyncCryptoStorePtr;
|
||||
|
||||
@@ -134,3 +137,23 @@ async fn modify_reputation(
|
||||
|
||||
sender.send_message(NetworkBridgeTxMessage::ReportPeer(peer, rep)).await;
|
||||
}
|
||||
|
||||
/// Wait until tick and return the timestamp for the following one.
|
||||
async fn wait_until_next_tick(last_poll: Instant, period: Duration) -> Instant {
|
||||
let now = Instant::now();
|
||||
let next_poll = last_poll + period;
|
||||
|
||||
if next_poll > now {
|
||||
futures_timer::Delay::new(next_poll - now).await
|
||||
}
|
||||
|
||||
Instant::now()
|
||||
}
|
||||
|
||||
/// Returns an infinite stream that yields with an interval of `period`.
|
||||
fn tick_stream(period: Duration) -> impl FusedStream<Item = ()> {
|
||||
futures::stream::unfold(Instant::now(), move |next_check| async move {
|
||||
Some(((), wait_until_next_tick(next_check, period).await))
|
||||
})
|
||||
.fuse()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user