Skip to content

Commit

Permalink
bugfix: Added rate mutex in ProcRequestRate
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Oct 11, 2021
1 parent 252bfe6 commit f870481
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions p2p/protocol/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"math/big"
"runtime/debug"
"sync"
"time"

"github.com/libp2p/go-libp2p/core/network"
Expand Down Expand Up @@ -35,8 +36,12 @@ type rateTracker struct {
var inRateTrackers map[peer.ID]rateTracker
var outRateTrackers map[peer.ID]rateTracker

var requestRateMu sync.RWMutex

// Feed the request rate tracker, recomputing the rate, and returning an error if the rate limit is exceeded
func ProcRequestRate(peerId peer.ID, inbound bool) error {
requestRateMu.Lock()
defer requestRateMu.Unlock()
var rateTrackers *map[peer.ID]rateTracker
if inRateTrackers == nil {
inRateTrackers = make(map[peer.ID]rateTracker)
Expand Down

0 comments on commit f870481

Please sign in to comment.