-
Notifications
You must be signed in to change notification settings - Fork 27
Repeat ping request periodically #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
base: master
Are you sure you want to change the base?
Changes from 3 commits
80e7fdd
d6b3909
9f8fe8c
f26e25c
9c535ed
2401ca7
fd0a305
b4e6a3b
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 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,26 +24,27 @@ use crate::{ | |||||||||||||||||||||||||||||
| error::{Error, SubstreamError}, | ||||||||||||||||||||||||||||||
| protocol::{Direction, TransportEvent, TransportService}, | ||||||||||||||||||||||||||||||
| substream::Substream, | ||||||||||||||||||||||||||||||
| types::SubstreamId, | ||||||||||||||||||||||||||||||
| PeerId, | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| use futures::{future::BoxFuture, stream::FuturesUnordered, StreamExt}; | ||||||||||||||||||||||||||||||
| use tokio::sync::mpsc::Sender; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| use futures::{SinkExt, StreamExt}; | ||||||||||||||||||||||||||||||
| use std::{ | ||||||||||||||||||||||||||||||
| collections::HashSet, | ||||||||||||||||||||||||||||||
| collections::HashMap, | ||||||||||||||||||||||||||||||
| time::{Duration, Instant}, | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| use bytes::Bytes; | ||||||||||||||||||||||||||||||
| use futures::stream::SplitSink; | ||||||||||||||||||||||||||||||
| use tokio::sync::mpsc; | ||||||||||||||||||||||||||||||
| use tokio_stream::StreamMap; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| pub use config::{Config, ConfigBuilder}; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| mod config; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // TODO: https://github.com/paritytech/litep2p/issues/132 let the user handle max failures | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /// Log target for the file. | ||||||||||||||||||||||||||||||
| const LOG_TARGET: &str = "litep2p::ipfs::ping"; | ||||||||||||||||||||||||||||||
| const PING_TIMEOUT: Duration = Duration::from_secs(10); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| const PING_TIMEOUT: Duration = Duration::from_secs(10); |
Since it is unused. However, we probably want to have a timeout for receiving pongs. Arguably out of scope for this PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep this TODO comment:
// TODO: https://github.com/paritytech/litep2p/issues/134 generate random payload and verify it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dharjeezy when I click on "Resolve comment", I get the error "Failed to resolve thread". Can you resolve it?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| self.ping_times.insert(*peer, Instant::now()); | |
| tracing::trace!(target: LOG_TARGET, ?peer, "sending ping"); | |
| if let Err(error) = sink.send(Bytes::from(payload)).await { | |
| tracing::debug!(target: LOG_TARGET, ?peer, ?error, "failed to send ping"); | |
| } | |
| tracing::trace!(target: LOG_TARGET, ?peer, "sending ping"); | |
| if let Err(error) = sink.send(Bytes::from(payload)).await { | |
| tracing::debug!(target: LOG_TARGET, ?peer, ?error, "failed to send ping"); | |
| } else { | |
| self.ping_times.insert(*peer, Instant::now()); | |
| } |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Ok(payload) => { | |
| Ok(_payload) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.