mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-21 15:11:20 +00:00
Allow multiple pings over one connection (#1416)
* Allow multiple pings over one connection This is so that pinging a rust-libp2p node from ipfs works even without passing -n 1 * Remove timeout
This commit is contained in:
parent
44b5e3e176
commit
dd0c5c37f6
@ -44,6 +44,8 @@ use wasm_timer::Instant;
|
|||||||
#[derive(Default, Debug, Copy, Clone)]
|
#[derive(Default, Debug, Copy, Clone)]
|
||||||
pub struct Ping;
|
pub struct Ping;
|
||||||
|
|
||||||
|
const PING_SIZE: usize = 32;
|
||||||
|
|
||||||
impl UpgradeInfo for Ping {
|
impl UpgradeInfo for Ping {
|
||||||
type Info = &'static [u8];
|
type Info = &'static [u8];
|
||||||
type InfoIter = iter::Once<Self::Info>;
|
type InfoIter = iter::Once<Self::Info>;
|
||||||
@ -63,10 +65,10 @@ where
|
|||||||
|
|
||||||
fn upgrade_inbound(self, mut socket: TSocket, _: Self::Info) -> Self::Future {
|
fn upgrade_inbound(self, mut socket: TSocket, _: Self::Info) -> Self::Future {
|
||||||
async move {
|
async move {
|
||||||
let mut payload = [0u8; 32];
|
let mut payload = [0u8; PING_SIZE];
|
||||||
socket.read_exact(&mut payload).await?;
|
while let Ok(_) = socket.read_exact(&mut payload).await {
|
||||||
socket.write_all(&payload).await?;
|
socket.write_all(&payload).await?;
|
||||||
socket.close().await?;
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}.boxed()
|
}.boxed()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user