Skip to content

Commit

Permalink
Just measure at the beginning instead of disconnecting, for test purp…
Browse files Browse the repository at this point in the history
…oses
  • Loading branch information
diegomrsantos committed Aug 2, 2023
1 parent a599759 commit 9403349
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions libp2p/protocols/pubsub/gossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ proc rateLimit*(g: GossipSub, peer: PubSubPeer, rpcMsgOpt: Opt[RPCMsg], msgSize:
# In this way we count even ignored fields by protobuf
var rmsg = rpcMsgOpt.valueOr:
if not peer.uselessAppBytesRate.tryConsume(msgSize):
discard g.disconnectPeer(peer)
libp2p_gossipsub_peers_rate_limit_disconnections.inc(labelValues = [peer.getAgent()]) # let's just measure at the beginning for test purposes. # discard g.disconnectPeer(peer)
raise newException(PeerRateLimitError, "Peer sent too much useless data that couldn't be decoded")

Check warning on line 378 in libp2p/protocols/pubsub/gossipsub.nim

View check run for this annotation

Codecov / codecov/patch

libp2p/protocols/pubsub/gossipsub.nim#L378

Added line #L378 was not covered by tests

let usefulMsgBytesNum =
Expand All @@ -394,7 +394,7 @@ proc rateLimit*(g: GossipSub, peer: PubSubPeer, rpcMsgOpt: Opt[RPCMsg], msgSize:

if not peer.uselessAppBytesRate.tryConsume(uselessAppBytesNum):
debug "Peer sent too much useless application data", peer, msgSize, uselessAppBytesNum
discard g.disconnectPeer(peer)
libp2p_gossipsub_peers_rate_limit_disconnections.inc(labelValues = [peer.getAgent()]) # let's just measure at the beginning for test purposes. # discard g.disconnectPeer(peer)
raise newException(PeerRateLimitError, "Peer sent too much useless application data.")

Check warning on line 398 in libp2p/protocols/pubsub/gossipsub.nim

View check run for this annotation

Codecov / codecov/patch

libp2p/protocols/pubsub/gossipsub.nim#L397-L398

Added lines #L397 - L398 were not covered by tests

method rpcHandler*(g: GossipSub,
Expand Down
4 changes: 2 additions & 2 deletions libp2p/protocols/pubsub/gossipsub/scoring.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ declareGauge(libp2p_gossipsub_peers_score_invalidMessageDeliveries, "Detailed go
declareGauge(libp2p_gossipsub_peers_score_appScore, "Detailed gossipsub scoring metric", labels = ["agent"])
declareGauge(libp2p_gossipsub_peers_score_behaviourPenalty, "Detailed gossipsub scoring metric", labels = ["agent"])
declareGauge(libp2p_gossipsub_peers_score_colocationFactor, "Detailed gossipsub scoring metric", labels = ["agent"])
declareCounter(libp2p_gossipsub_peers_badTrafficScorePeerDisconnections, "The number of peer disconnections by gossipsub because of bad traffic", labels = ["agent"])
declarePublicCounter(libp2p_gossipsub_peers_rate_limit_disconnections, "The number of peer disconnections by gossipsub because of rate limit", labels = ["agent"])

proc init*(_: type[TopicParams]): TopicParams =
TopicParams(
Expand Down Expand Up @@ -242,7 +242,7 @@ proc scoringHeartbeat*(g: GossipSub) {.async.} =

proc punishInvalidMessage*(g: GossipSub, peer: PubSubPeer, msg: Message) =
if not peer.uselessAppBytesRate.tryConsume(len(msg.data)):
discard g.disconnectPeer(peer)
libp2p_gossipsub_peers_rate_limit_disconnections.inc(labelValues = [peer.getAgent()]) # let's just measure at the beginning for test purposes. # discard g.disconnectPeer(peer)

Check warning on line 246 in libp2p/protocols/pubsub/gossipsub/scoring.nim

View check run for this annotation

Codecov / codecov/patch

libp2p/protocols/pubsub/gossipsub/scoring.nim#L246

Added line #L246 was not covered by tests
for tt in msg.topicIds:
let t = tt
Expand Down

0 comments on commit 9403349

Please sign in to comment.