Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
Liuhaai committed Feb 1, 2025
1 parent f93fe5a commit fe5cc9f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ type Host struct {
peerManager *peerManager
}

var (
_count = uint64(0)
)

func p2pMessageInspector(h *Host) func(peerID peer.ID, msg *pubsub.RPC) error {
return func(peerID peer.ID, msg *pubsub.RPC) error {
allowed, err := h.allowSource(peerID)
Expand All @@ -285,7 +289,11 @@ func p2pMessageInspector(h *Host) func(peerID peer.ID, msg *pubsub.RPC) error {
return err
}
if !allowed {
Logger().Warn("message from p2p peer hit rate limit", zap.Any("id", peerID))
Logger().Debug("message from p2p peer hit rate limit", zap.Any("peer id", peerID))
_count = (_count + 1) % 200
if _count == 0 {
Logger().Warn("message from p2p peer hit rate limit", zap.Any("peer id", peerID))
}
return errors.New("drop message")
}

Expand Down

0 comments on commit fe5cc9f

Please sign in to comment.