From a46972fdb7f805a2c7bc8ec454f69e33c08a3a50 Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 14 Mar 2022 11:28:34 +0200 Subject: [PATCH] limit ping duration to 30s so that ping streams cannot be squatted --- p2p/protocol/ping/ping.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/p2p/protocol/ping/ping.go b/p2p/protocol/ping/ping.go index 9a67715593..a846f40499 100644 --- a/p2p/protocol/ping/ping.go +++ b/p2p/protocol/ping/ping.go @@ -20,8 +20,9 @@ import ( var log = logging.Logger("ping") const ( - PingSize = 32 - pingTimeout = time.Second * 60 + PingSize = 32 + pingTimeout = 10 * time.Second + pingDuration = 30 * time.Second ID = "/ipfs/ping/1.0.0" @@ -52,6 +53,8 @@ func (p *PingService) PingHandler(s network.Stream) { } defer s.Scope().ReleaseMemory(PingSize) + s.SetDeadline(time.Now().Add(pingDuration)) + buf := pool.Get(PingSize) defer pool.Put(buf)