js-waku
js-waku copied to clipboard
Retrieve Store Messages when resuming connectivity
Problem
When a dApp using js-waku is offline, relay messages are not received. Same for filter messages.
Solution
To ensure that no message were missed, a store query should be done once a device resume connectivity.
Definition of Done
A guide that demonstrate how to watch loss of connectivity to then do a store query to retrieve any missed messages. Can start with filter as it may be easier to detected disconnectivity.
Notes
This guide may be accompanied by a set of helpful API to make it easier to enable/use.
The loss of connectivity refers to relay nodes, that forward messages.
From testing js-libp2p behaviour, it does not seem that the peer:disconnect
event on the connectManager
is triggered when there is a loss of connection.
Most likely, only a failed attempt to contact a peer allows the node to learn that the peer is not reachable anymore.
libp2p-interfaces/pubsub
handles this by calling _onPeerDisconnected
if a message is failed to send to a peer.
One could either hook this method or watch the number of available relay peers to know whether we are connected. Then, the start/end time field should be used in the store query to only retrieve messages in the timeframe where we are offline.
Inspire yourself to what status is doing: https://rfc.vac.dev/spec/27/#peer-connectivity
Card to write RFC for relay ping: https://github.com/status-im/js-waku/projects/1#card-65707839