Add bloom size check and no longer raise on sendMsg failures

This commit is contained in:
kdeme 2019-10-03 12:09:00 +02:00 committed by zah
parent 9dccfe27f4
commit 5bc7612e2f
1 changed files with 10 additions and 3 deletions

View File

@ -813,7 +813,8 @@ p2pProtocol Whisper(version = whisperVersion,
warn "Handshake not completed yet, discarding bloomFilterExchange" warn "Handshake not completed yet, discarding bloomFilterExchange"
return return
peer.state.bloom.bytesCopy(bloom) if bloom.len == bloomSize:
peer.state.bloom.bytesCopy(bloom)
nextID 126 nextID 126
@ -999,24 +1000,30 @@ proc filtersToBloom*(node: EthereumNode): Bloom =
proc setPowRequirement*(node: EthereumNode, powReq: float64) {.async.} = proc setPowRequirement*(node: EthereumNode, powReq: float64) {.async.} =
## Sets the PoW requirement for this node, will also send ## Sets the PoW requirement for this node, will also send
## this new PoW requirement to all connected peers ## this new PoW requirement to all connected peers
##
## Failures when sending messages to peers will not be reported.
# NOTE: do we need a tolerance of old PoW for some time? # NOTE: do we need a tolerance of old PoW for some time?
node.protocolState(Whisper).config.powRequirement = powReq node.protocolState(Whisper).config.powRequirement = powReq
var futures: seq[Future[void]] = @[] var futures: seq[Future[void]] = @[]
for peer in node.peers(Whisper): for peer in node.peers(Whisper):
futures.add(peer.powRequirement(cast[uint](powReq))) futures.add(peer.powRequirement(cast[uint](powReq)))
await all(futures) # Exceptions from sendMsg will not be raised
await allFutures(futures)
proc setBloomFilter*(node: EthereumNode, bloom: Bloom) {.async.} = proc setBloomFilter*(node: EthereumNode, bloom: Bloom) {.async.} =
## Sets the bloom filter for this node, will also send ## Sets the bloom filter for this node, will also send
## this new bloom filter to all connected peers ## this new bloom filter to all connected peers
##
## Failures when sending messages to peers will not be reported.
# NOTE: do we need a tolerance of old bloom filter for some time? # NOTE: do we need a tolerance of old bloom filter for some time?
node.protocolState(Whisper).config.bloom = bloom node.protocolState(Whisper).config.bloom = bloom
var futures: seq[Future[void]] = @[] var futures: seq[Future[void]] = @[]
for peer in node.peers(Whisper): for peer in node.peers(Whisper):
futures.add(peer.bloomFilterExchange(@bloom)) futures.add(peer.bloomFilterExchange(@bloom))
await all(futures) # Exceptions from sendMsg will not be raised
await allFutures(futures)
proc setMaxMessageSize*(node: EthereumNode, size: uint32): bool = proc setMaxMessageSize*(node: EthereumNode, size: uint32): bool =
## Set the maximum allowed message size ## Set the maximum allowed message size