mirror of https://github.com/waku-org/nwaku.git
Add hook on newly added envelope (#423)
This commit is contained in:
parent
714bbebbc1
commit
0050f9da59
|
@ -87,11 +87,14 @@ type
|
||||||
|
|
||||||
P2PRequestHandler* = proc(peer: Peer, envelope: Envelope) {.gcsafe.}
|
P2PRequestHandler* = proc(peer: Peer, envelope: Envelope) {.gcsafe.}
|
||||||
|
|
||||||
|
EnvReceivedHandler* = proc(envelope: Envelope) {.gcsafe.}
|
||||||
|
|
||||||
WakuNetwork = ref object
|
WakuNetwork = ref object
|
||||||
queue*: ref Queue
|
queue*: ref Queue
|
||||||
filters*: Filters
|
filters*: Filters
|
||||||
config*: WakuConfig
|
config*: WakuConfig
|
||||||
p2pRequestHandler*: P2PRequestHandler
|
p2pRequestHandler*: P2PRequestHandler
|
||||||
|
envReceivedHandler*: EnvReceivedHandler
|
||||||
|
|
||||||
RateLimits* = object
|
RateLimits* = object
|
||||||
# TODO: uint or specifically uint32?
|
# TODO: uint or specifically uint32?
|
||||||
|
@ -321,6 +324,9 @@ p2pProtocol Waku(version = wakuVersion,
|
||||||
if peer.networkState.queue[].add(msg):
|
if peer.networkState.queue[].add(msg):
|
||||||
# notify filters of this message
|
# notify filters of this message
|
||||||
peer.networkState.filters.notify(msg)
|
peer.networkState.filters.notify(msg)
|
||||||
|
# trigger handler on received envelope, if registered
|
||||||
|
if not peer.networkState.envReceivedHandler.isNil():
|
||||||
|
peer.networkState.envReceivedHandler(envelope)
|
||||||
|
|
||||||
nextID 22
|
nextID 22
|
||||||
|
|
||||||
|
@ -645,6 +651,10 @@ proc registerP2PRequestHandler*(node: EthereumNode,
|
||||||
customHandler: P2PRequestHandler) =
|
customHandler: P2PRequestHandler) =
|
||||||
node.protocolState(Waku).p2pRequestHandler = customHandler
|
node.protocolState(Waku).p2pRequestHandler = customHandler
|
||||||
|
|
||||||
|
proc registerEnvReceivedHandler*(node: EthereumNode,
|
||||||
|
customHandler: EnvReceivedHandler) =
|
||||||
|
node.protocolState(Waku).envReceivedHandler = customHandler
|
||||||
|
|
||||||
proc resetMessageQueue*(node: EthereumNode) =
|
proc resetMessageQueue*(node: EthereumNode) =
|
||||||
## Full reset of the message queue.
|
## Full reset of the message queue.
|
||||||
##
|
##
|
||||||
|
|
Loading…
Reference in New Issue