Skip to content

Commit 9ff1e70

Browse files
authored
limit ping duration to 30s (#1358)
so that ping streams cannot be squatted
1 parent 8f315d9 commit 9ff1e70

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

p2p/protocol/ping/ping.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import (
2020
var log = logging.Logger("ping")
2121

2222
const (
23-
PingSize = 32
24-
pingTimeout = time.Second * 60
23+
PingSize = 32
24+
pingTimeout = 10 * time.Second
25+
pingDuration = 30 * time.Second
2526

2627
ID = "/ipfs/ping/1.0.0"
2728

@@ -52,6 +53,8 @@ func (p *PingService) PingHandler(s network.Stream) {
5253
}
5354
defer s.Scope().ReleaseMemory(PingSize)
5455

56+
s.SetDeadline(time.Now().Add(pingDuration))
57+
5558
buf := pool.Get(PingSize)
5659
defer pool.Put(buf)
5760

0 commit comments

Comments
 (0)