Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Sep 8, 2023
1 parent 1000bf0 commit 3ffbb1c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libp2p/protocols/pubsub/gossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ proc init*(_: type[GossipSubParams]): GossipSubParams =
enablePX: false,
bandwidthEstimatebps: 100_000_000, # 100 Mbps or 12.5 MBps
iwantTimeout: 3 * GossipSubHeartbeatInterval,
uselessAppBytesRate: (1024, 500.milliseconds)
uselessAppBytesRate: (10000, 500.milliseconds)
)

proc validateParameters*(parameters: GossipSubParams): Result[void, cstring] =
Expand Down Expand Up @@ -406,9 +406,9 @@ proc rateLimit*(g: GossipSub, peer: PubSubPeer, rpcMsgOpt: Opt[RPCMsg], msgSize:
uselessAppBytesNum -= (byteSize(control.ihave) + byteSize(control.iwant))

peer.uselessAppBytesRateOpt.withValue(uselessAppBytesRate):
if not uselessAppBytesRate.tryConsume(msgSize):
if not uselessAppBytesRate.tryConsume(uselessAppBytesNum):
libp2p_gossipsub_peers_rate_limit_disconnections.inc(labelValues = [peer.getAgent()]) # let's just measure at the beginning for test purposes.
debug "Peer sent too much useless application data and it's above rate limit.", peer, msgSize, uselessAppBytesNum
debug "Peer sent too much useless application data and it's above rate limit.", peer, msgSize, uselessAppBytesNum, rmsg
# discard g.disconnectPeer(peer)
# debug "Peer disconnected", peer, msgSize, uselessAppBytesNum
# raise newException(PeerRateLimitError, "Peer sent too much useless application data and it's above rate limit.")
Expand Down
54 changes: 54 additions & 0 deletions libp2p/protocols/pubsub/rpc/messages.nim
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,57 @@ proc byteSize*(iwant: seq[ControlIWant]): int =
for msgId in item.messageIds:
total += msgId.len
return total

proc `$` (msg: PeerInfoMsg): string =
try:
return "PeerInfoMsg(peerId: " & $msg.peerId & ", signedPeerRecord: " & $msg.signedPeerRecord & ")"
except Exception:
return "PeerInfoMsg: exception raised"

proc `$` (msg: SubOpts): string =
try:
return "SubOpts(subscribe: " & $msg.subscribe & ", topic: " & $msg.topic & ")"
except Exception:
return "SubOpts: exception raised"

proc `$` (msg: Message): string =
try:
return "Message(fromPeer: " & $msg.fromPeer & ", data: " & $msg.data & ", seqno: " & $msg.seqno & ", topicIds: " & $msg.topicIds & ", signature: " & $msg.signature & ", key: " & $msg.key & ")"
except Exception:
return "Message: exception raised"

proc `$` (msg: ControlIHave): string =
try:
return "ControlIHave(topicId: " & $msg.topicId & ", messageIds: " & $msg.messageIds & ")"
except Exception:
return "ControlIHave: exception raised"

proc `$` (msg: ControlIWant): string =
try:
return "ControlIWant(messageIds: " & $msg.messageIds & ")"
except Exception:
return "ControlIWant: exception raised"

proc `$` (msg: ControlGraft): string =
try:
return "ControlGraft(topicId: " & $msg.topicId & ")"
except Exception:
return "ControlGraft: exception raised"

proc `$` (msg: ControlPrune): string =
try:
return "ControlPrune(topicId: " & $msg.topicId & ", peers: " & $msg.peers & ", backoff: " & $msg.backoff & ")"
except Exception:
return "ControlPrune: exception raised"

proc `$` (msg: ControlMessage): string =
try:
return "ControlMessage(ihave: " & $msg.ihave & ", iwant: " & $msg.iwant & ", graft: " & $msg.graft & ", prune: " & $msg.prune & ", idontwant: " & $msg.idontwant & ")"
except Exception:
return "ControlMessage: exception raised"

proc `$` (msg: RPCMsg): string =
try:
return "RPCMsg(subscriptions: " & $msg.subscriptions & ", messages: " & $msg.messages & ", control: " & $msg.control & ", ping: " & $msg.ping & ", pong: " & $msg.pong & ")"
except Exception:
return "RPCMsg: exception raised"

0 comments on commit 3ffbb1c

Please sign in to comment.