Skip to content

Commit

Permalink
limit ping duration to 30s
Browse files Browse the repository at this point in the history
so that ping streams cannot be squatted
  • Loading branch information
vyzo authored and MarcoPolo committed Jun 3, 2024
1 parent f52cec1 commit a46972f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions p2p/protocol/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit a46972f

Please sign in to comment.