Documentation ¶
Index ¶
- Constants
- Variables
- type HistoryRequestOption
- func DefaultOptions() []HistoryRequestOption
- func WithAutomaticPeerSelection(fromThesePeers ...peer.ID) HistoryRequestOption
- func WithAutomaticRequestId() HistoryRequestOption
- func WithCursor(c *pb.Index) HistoryRequestOption
- func WithFastestPeerSelection(ctx context.Context, fromThesePeers ...peer.ID) HistoryRequestOption
- func WithPaging(asc bool, pageSize uint64) HistoryRequestOption
- func WithPeer(p peer.ID) HistoryRequestOption
- func WithRequestId(requestId []byte) HistoryRequestOption
- type HistoryRequestParameters
- type MessageProvider
- type Query
- type Result
- type Store
- type WakuStore
- func (store *WakuStore) Find(ctx context.Context, query Query, cb criteriaFN, opts ...HistoryRequestOption) (*pb.WakuMessage, error)
- func (store *WakuStore) FindMessages(query *pb.HistoryQuery) *pb.HistoryResponse
- func (store *WakuStore) MessageChannel() chan *protocol.Envelope
- func (store *WakuStore) Next(ctx context.Context, r *Result) (*Result, error)
- func (store *WakuStore) Query(ctx context.Context, query Query, opts ...HistoryRequestOption) (*Result, error)
- func (store *WakuStore) Resume(ctx context.Context, pubsubTopic string, peerList []peer.ID) (int, error)
- func (store *WakuStore) SetMessageProvider(p MessageProvider)
- func (store *WakuStore) Start(ctx context.Context)
- func (store *WakuStore) Stop()
Constants ¶
const MaxContentFilters = 10
MaxContentFilters is the maximum number of allowed content filters in a query
const MaxPageSize = 100
MaxPageSize is the maximum number of waku messages to return per page
const MaxTimeVariance = time.Duration(20) * time.Second
MaxTimeVariance is the maximum duration in the future allowed for a message timestamp
const StoreID_v20beta4 = libp2pProtocol.ID("/vac/waku/store/2.0.0-beta4")
StoreID_v20beta4 is the current Waku Store protocol identifier
Variables ¶
var ( // ErrMaxContentFilters is returned when the number of content topics in the query // exceeds the limit ErrMaxContentFilters = errors.New("exceeds the maximum number of content filters allowed") // ErrNoPeersAvailable is returned when there are no store peers in the peer store // that could be used to retrieve message history ErrNoPeersAvailable = errors.New("no suitable remote peers") // ErrInvalidId is returned when no RequestID is given ErrInvalidId = errors.New("invalid request id") // ErrFailedToResumeHistory is returned when the node attempted to retrieve historic // messages to fill its own message history but for some reason it failed ErrFailedToResumeHistory = errors.New("failed to resume the history") // ErrFailedQuery is emitted when the query fails to return results ErrFailedQuery = errors.New("failed to resolve the query") ErrFutureMessage = errors.New("message timestamp in the future") ErrEmptyResponse = errors.New("empty store response") )
Functions ¶
This section is empty.
Types ¶
type HistoryRequestOption ¶
type HistoryRequestOption func(*HistoryRequestParameters)
func DefaultOptions ¶
func DefaultOptions() []HistoryRequestOption
Default options to be used when querying a store node for results
func WithAutomaticPeerSelection ¶
func WithAutomaticPeerSelection(fromThesePeers ...peer.ID) HistoryRequestOption
WithAutomaticPeerSelection is an option used to randomly select a peer from the peer store to request the message history. If a list of specific peers is passed, the peer will be chosen from that list assuming it supports the chosen protocol, otherwise it will chose a peer from the node peerstore
func WithAutomaticRequestId ¶
func WithAutomaticRequestId() HistoryRequestOption
func WithCursor ¶
func WithCursor(c *pb.Index) HistoryRequestOption
func WithFastestPeerSelection ¶
func WithFastestPeerSelection(ctx context.Context, fromThesePeers ...peer.ID) HistoryRequestOption
WithFastestPeerSelection is an option used to select a peer from the peer store with the lowest ping. If a list of specific peers is passed, the peer will be chosen from that list assuming it supports the chosen protocol, otherwise it will chose a peer from the node peerstore
func WithPaging ¶
func WithPaging(asc bool, pageSize uint64) HistoryRequestOption
WithPaging is an option used to specify the order and maximum number of records to return
func WithPeer ¶
func WithPeer(p peer.ID) HistoryRequestOption
WithPeer is an option used to specify the peerID to request the message history
func WithRequestId ¶
func WithRequestId(requestId []byte) HistoryRequestOption
type HistoryRequestParameters ¶
type HistoryRequestParameters struct {
// contains filtered or unexported fields
}
type MessageProvider ¶
type MessageProvider interface { GetAll() ([]persistence.StoredMessage, error) Query(query *pb.HistoryQuery) (*pb.Index, []persistence.StoredMessage, error) Put(env *protocol.Envelope) error MostRecentTimestamp() (int64, error) Stop() Count() (int, error) }
type Result ¶
type Result struct { Messages []*pb.WakuMessage // contains filtered or unexported fields }
Result represents a valid response from a store node
func (*Result) IsComplete ¶
func (*Result) Query ¶
func (r *Result) Query() *pb.HistoryQuery
type Store ¶
type Store interface { Start(ctx context.Context) Query(ctx context.Context, query Query, opts ...HistoryRequestOption) (*Result, error) Find(ctx context.Context, query Query, cb criteriaFN, opts ...HistoryRequestOption) (*pb.WakuMessage, error) Next(ctx context.Context, r *Result) (*Result, error) Resume(ctx context.Context, pubsubTopic string, peerList []peer.ID) (int, error) MessageChannel() chan *protocol.Envelope Stop() }
type WakuStore ¶
func NewWakuStore ¶
func NewWakuStore(host host.Host, swap *swap.WakuSwap, p MessageProvider, log *zap.Logger) *WakuStore
NewWakuStore creates a WakuStore using an specific MessageProvider for storing the messages
func (*WakuStore) Find ¶
func (store *WakuStore) Find(ctx context.Context, query Query, cb criteriaFN, opts ...HistoryRequestOption) (*pb.WakuMessage, error)
Find the first message that matches a criteria. criteriaCB is a function that will be invoked for each message and returns true if the message matches the criteria
func (*WakuStore) FindMessages ¶
func (store *WakuStore) FindMessages(query *pb.HistoryQuery) *pb.HistoryResponse
func (*WakuStore) MessageChannel ¶
func (*WakuStore) Next ¶
Next is used with to retrieve the next page of rows from a query response. If no more records are found, the result will not contain any messages. This function is useful for iterating over results without having to manually specify the cursor and pagination order and max number of results
func (*WakuStore) Resume ¶
func (store *WakuStore) Resume(ctx context.Context, pubsubTopic string, peerList []peer.ID) (int, error)
Resume retrieves the history of waku messages published on the default waku pubsub topic since the last time the waku store node has been online messages are stored in the store node's messages field and in the message db the offline time window is measured as the difference between the current time and the timestamp of the most recent persisted waku message an offset of 20 second is added to the time window to count for nodes asynchrony the history is fetched from one of the peers persisted in the waku store node's peer manager unit peerList indicates the list of peers to query from. The history is fetched from the first available peer in this list. Such candidates should be found through a discovery method (to be developed). if no peerList is passed, one of the peers in the underlying peer manager unit of the store protocol is picked randomly to fetch the history from. The history gets fetched successfully if the dialed peer has been online during the queried time window. the resume proc returns the number of retrieved messages if no error occurs, otherwise returns the error string
func (*WakuStore) SetMessageProvider ¶
func (store *WakuStore) SetMessageProvider(p MessageProvider)
SetMessageProvider allows switching the message provider used with a WakuStore