-
Notifications
You must be signed in to change notification settings - Fork 30
ping: Conform to the spec & exclude from connection keep-alive #416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
80e7fdd
d6b3909
9f8fe8c
f26e25c
9c535ed
2401ca7
fd0a305
b4e6a3b
0b5f3c9
4f32e97
51792f5
415029a
70c7848
fcbfc5a
d9529b3
a26c710
eda96c9
70cdbee
ef230ed
4070565
65b024d
938fbe6
e2151cd
d388dca
6b2e674
838542f
a6d81a1
622a349
b8d73cf
2ab2bf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ use crate::{ | |
| codec::ProtocolCodec, protocol::libp2p::ping::PingEvent, types::protocol::ProtocolName, | ||
| DEFAULT_CHANNEL_SIZE, | ||
| }; | ||
| use std::time::Duration; | ||
|
|
||
| use futures::Stream; | ||
| use tokio::sync::mpsc::{channel, Sender}; | ||
|
|
@@ -36,6 +37,11 @@ const PING_PAYLOAD_SIZE: usize = 32; | |
| /// Maximum PING failures. | ||
| const MAX_FAILURES: usize = 3; | ||
|
|
||
| /// Ping interval must be set to < 10 secs, because litep2p versions before | ||
| /// <https://github.com/paritytech/litep2p/pull/416> reset the inbound substream if not receive | ||
| /// the payload within 10 seconds of opening the substream. | ||
| pub const PING_INTERVAL: Duration = Duration::from_secs(5); | ||
|
|
||
| /// Ping configuration. | ||
| pub struct Config { | ||
| /// Protocol name. | ||
|
|
@@ -49,6 +55,8 @@ pub struct Config { | |
|
|
||
| /// TX channel for sending events to the user protocol. | ||
| pub(crate) tx_event: Sender<PingEvent>, | ||
|
|
||
| pub(crate) ping_interval: Duration, | ||
| } | ||
|
|
||
| impl Config { | ||
|
|
@@ -61,6 +69,7 @@ impl Config { | |
| ( | ||
| Self { | ||
| tx_event, | ||
| ping_interval: PING_INTERVAL, | ||
| max_failures: MAX_FAILURES, | ||
| protocol: ProtocolName::from(PROTOCOL_NAME), | ||
| codec: ProtocolCodec::Identity(PING_PAYLOAD_SIZE), | ||
|
|
@@ -80,6 +89,9 @@ pub struct ConfigBuilder { | |
|
|
||
| /// Maximum failures before the peer is considered unreachable. | ||
| max_failures: usize, | ||
|
|
||
| /// Interval between outbound pings. | ||
| ping_interval: Duration, | ||
| } | ||
|
|
||
| impl Default for ConfigBuilder { | ||
|
|
@@ -92,6 +104,7 @@ impl ConfigBuilder { | |
| /// Create new default [`Config`] which can be modified by the user. | ||
| pub fn new() -> Self { | ||
| Self { | ||
| ping_interval: PING_INTERVAL, | ||
| max_failures: MAX_FAILURES, | ||
| protocol: ProtocolName::from(PROTOCOL_NAME), | ||
| codec: ProtocolCodec::Identity(PING_PAYLOAD_SIZE), | ||
|
|
@@ -104,13 +117,19 @@ impl ConfigBuilder { | |
| self | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Is cargo doc check ignoring missings docs on public methods? We should also document this and state the defaults (same for above in public interfaces)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. litep2p doesn't have |
||
| pub fn with_ping_interval(mut self, ping_interval: Duration) -> Self { | ||
| self.ping_interval = ping_interval; | ||
| self | ||
| } | ||
|
|
||
| /// Build [`Config`]. | ||
| pub fn build(self) -> (Config, Box<dyn Stream<Item = PingEvent> + Send + Unpin>) { | ||
| let (tx_event, rx_event) = channel(DEFAULT_CHANNEL_SIZE); | ||
|
|
||
| ( | ||
| Config { | ||
| tx_event, | ||
| ping_interval: self.ping_interval, | ||
| max_failures: self.max_failures, | ||
| protocol: self.protocol, | ||
| codec: self.codec, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.