Add hook on newly added envelope (#423)

This commit is contained in:
Hanno Cornelius 2021-03-17 11:49:06 +02:00 committed by GitHub
parent 714bbebbc1
commit 0050f9da59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -87,11 +87,14 @@ type
P2PRequestHandler* = proc(peer: Peer, envelope: Envelope) {.gcsafe.}
EnvReceivedHandler* = proc(envelope: Envelope) {.gcsafe.}
WakuNetwork = ref object
queue*: ref Queue
filters*: Filters
config*: WakuConfig
p2pRequestHandler*: P2PRequestHandler
envReceivedHandler*: EnvReceivedHandler
RateLimits* = object
# TODO: uint or specifically uint32?
@ -321,6 +324,9 @@ p2pProtocol Waku(version = wakuVersion,
if peer.networkState.queue[].add(msg):
# notify filters of this message
peer.networkState.filters.notify(msg)
# trigger handler on received envelope, if registered
if not peer.networkState.envReceivedHandler.isNil():
peer.networkState.envReceivedHandler(envelope)
nextID 22
@ -645,6 +651,10 @@ proc registerP2PRequestHandler*(node: EthereumNode,
customHandler: P2PRequestHandler) =
node.protocolState(Waku).p2pRequestHandler = customHandler
proc registerEnvReceivedHandler*(node: EthereumNode,
customHandler: EnvReceivedHandler) =
node.protocolState(Waku).envReceivedHandler = customHandler
proc resetMessageQueue*(node: EthereumNode) =
## Full reset of the message queue.
##