Keep alive

Set to 5 seconds initially using Until.
Once we get a substream injected it is set to Yes.
Once we are done (in poll) is set to No.
This commit is contained in:
Daniel Karzel 2021-06-24 20:09:12 +10:00
parent 0e8c5ea918
commit 6b9f032afc
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E

View File

@ -13,6 +13,10 @@ use libp2p::swarm::{
ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, SubstreamProtocol,
};
use libp2p::{Multiaddr, PeerId};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::future;
use std::time::Instant;
use uuid::Uuid;
use void::Void;
@ -222,6 +226,7 @@ pub struct Handler<LR> {
resume_only: bool,
timeout: Duration,
keep_alive: KeepAlive,
}
impl<LR> Handler<LR> {
@ -241,6 +246,7 @@ impl<LR> Handler<LR> {
latest_rate,
resume_only,
timeout: Duration::from_secs(60),
keep_alive: KeepAlive::Until(Instant::now() + Duration::from_secs(5)),
}
}
}
@ -271,6 +277,8 @@ where
mut substream: NegotiatedSubstream,
_: Self::InboundOpenInfo,
) {
self.keep_alive = KeepAlive::Yes;
let (sender, receiver) = bmrng::channel_with_timeout::<bitcoin::Amount, WalletSnapshot>(
1,
Duration::from_secs(5),
@ -435,7 +443,7 @@ where
}
fn connection_keep_alive(&self) -> KeepAlive {
todo!()
self.keep_alive
}
fn poll(
@ -450,6 +458,7 @@ where
>,
> {
if let Some(result) = futures::ready!(self.inbound_stream.poll_unpin(cx)) {
self.keep_alive = KeepAlive::No;
return Poll::Ready(ProtocolsHandlerEvent::Custom(HandlerOutEvent::Completed(
result,
)));