From dd0c5c37f620d924e23b20cd41c6bad06dbbf9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Klaehn?= Date: Tue, 4 Feb 2020 10:28:00 +0100 Subject: [PATCH] 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 --- protocols/ping/src/protocol.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/protocols/ping/src/protocol.rs b/protocols/ping/src/protocol.rs index f7e9b90b..9bd5682f 100644 --- a/protocols/ping/src/protocol.rs +++ b/protocols/ping/src/protocol.rs @@ -44,6 +44,8 @@ use wasm_timer::Instant; #[derive(Default, Debug, Copy, Clone)] pub struct Ping; +const PING_SIZE: usize = 32; + impl UpgradeInfo for Ping { type Info = &'static [u8]; type InfoIter = iter::Once; @@ -63,10 +65,10 @@ where fn upgrade_inbound(self, mut socket: TSocket, _: Self::Info) -> Self::Future { async move { - let mut payload = [0u8; 32]; - socket.read_exact(&mut payload).await?; - socket.write_all(&payload).await?; - socket.close().await?; + let mut payload = [0u8; PING_SIZE]; + while let Ok(_) = socket.read_exact(&mut payload).await { + socket.write_all(&payload).await?; + } Ok(()) }.boxed() }