Skip to content

Commit

Permalink
Fixes after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Sep 8, 2023
1 parent 855b770 commit 1000bf0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libp2p/protocols/pubsub/floodsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ method unsubscribePeer*(f: FloodSub, peer: PeerId) =
method rpcHandler*(f: FloodSub,
peer: PubSubPeer,
data: seq[byte]) {.async.} =
let msgSize = len(data)

var rpcMsg = decodeRpcMsg(data).valueOr:
debug "failed to decode msg from peer", peer, err = error
raise newException(CatchableError, "")
Expand Down
8 changes: 4 additions & 4 deletions libp2p/protocols/pubsub/gossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ proc rateLimit*(g: GossipSub, peer: PubSubPeer, rpcMsgOpt: Opt[RPCMsg], msgSize:
else:
dataAndTopicsIdSize(rmsg.messages)

var uselessAppBytesNum = msgSize - usefulMsgBytesNum
var uselessAppBytesNum = msgSize - usefulMsgBytesNum
rmsg.control.withValue(control):
uselessAppBytesNum -= (byteSize(control.ihave) + byteSize(control.iwant))

Expand All @@ -416,9 +416,9 @@ proc rateLimit*(g: GossipSub, peer: PubSubPeer, rpcMsgOpt: Opt[RPCMsg], msgSize:
method rpcHandler*(g: GossipSub,
peer: PubSubPeer,
data: seq[byte]) {.async.} =

let msgSize = data.len
let rpcMsgResult = decodeRpcMsg(data)
var rpcMsg = rpcMsgResult.valueOr:
var rpcMsg = decodeRpcMsg(data).valueOr:
debug "failed to decode msg from peer", peer, err = error
rateLimit(g, peer, Opt.none(RPCMsg), msgSize)
return
Expand Down Expand Up @@ -729,4 +729,4 @@ method getOrCreatePeer*(

let peer = procCall PubSub(g).getOrCreatePeer(peerId, protos)
peer.uselessAppBytesRateOpt = Opt.some(TokenBucket.new(g.parameters.uselessAppBytesRate.bytes, g.parameters.uselessAppBytesRate.interval))
return peer
return peer
2 changes: 2 additions & 0 deletions tests/pubsub/testmessage.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ suite "Message":
key: @[1'u8], # 1 byte
topicIds: @["abc", "defgh"] # 3 + 5 = 8 bytes
)

check byteSize(msg) == 3 + 1 + 1 + 8 # Total: 13 bytes

0 comments on commit 1000bf0

Please sign in to comment.