2019-11-23 17:57:05 +00:00
|
|
|
package types
|
2019-10-09 14:22:53 +00:00
|
|
|
|
2019-11-06 16:23:11 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-10-28 13:50:33 +00:00
|
|
|
// MaxLimitInMessagesRequest represents the maximum number of messages
|
|
|
|
// that can be requested from the mailserver
|
2019-11-06 16:23:11 +00:00
|
|
|
MaxLimitInMessagesRequest = 1000
|
|
|
|
)
|
|
|
|
|
|
|
|
// MessagesRequest contains details of a request of historic messages.
|
|
|
|
type MessagesRequest struct {
|
|
|
|
// ID of the request. The current implementation requires ID to be 32-byte array,
|
|
|
|
// however, it's not enforced for future implementation.
|
|
|
|
ID []byte `json:"id"`
|
|
|
|
// From is a lower bound of time range.
|
|
|
|
From uint32 `json:"from"`
|
|
|
|
// To is a upper bound of time range.
|
|
|
|
To uint32 `json:"to"`
|
|
|
|
// Limit determines the number of messages sent by the mail server
|
|
|
|
// for the current paginated request.
|
|
|
|
Limit uint32 `json:"limit"`
|
|
|
|
// Cursor is used as starting point for paginated requests.
|
|
|
|
Cursor []byte `json:"cursor"`
|
2021-07-21 19:02:50 +00:00
|
|
|
// StoreCursor is used as starting point for WAKUV2 paginatedRequests
|
|
|
|
StoreCursor *StoreRequestCursor `json:"storeCursor"`
|
2019-11-06 16:23:11 +00:00
|
|
|
// Bloom is a filter to match requested messages.
|
|
|
|
Bloom []byte `json:"bloom"`
|
2023-05-22 21:38:02 +00:00
|
|
|
// PubsubTopic is the gossipsub topic on which the message was broadcasted
|
2023-08-23 17:09:48 +00:00
|
|
|
PubsubTopic string `json:"pubsubTopic"`
|
2023-05-22 21:38:02 +00:00
|
|
|
// ContentTopics is a list of topics. A returned message should
|
2021-05-13 13:30:33 +00:00
|
|
|
// belong to one of the topics from the list.
|
2023-08-23 17:09:48 +00:00
|
|
|
ContentTopics [][]byte `json:"contentTopics"`
|
2019-11-06 16:23:11 +00:00
|
|
|
}
|
|
|
|
|
2021-07-21 19:02:50 +00:00
|
|
|
type StoreRequestCursor struct {
|
2022-02-24 13:45:14 +00:00
|
|
|
Digest []byte `json:"digest"`
|
|
|
|
ReceiverTime int64 `json:"receiverTime"`
|
|
|
|
SenderTime int64 `json:"senderTime"`
|
2022-03-03 12:28:09 +00:00
|
|
|
PubsubTopic string `json:"pubsubTopic"`
|
2021-07-21 19:02:50 +00:00
|
|
|
}
|
|
|
|
|
2019-10-28 13:50:33 +00:00
|
|
|
// SetDefaults sets the From and To defaults
|
2019-11-06 16:23:11 +00:00
|
|
|
func (r *MessagesRequest) SetDefaults(now time.Time) {
|
|
|
|
// set From and To defaults
|
|
|
|
if r.To == 0 {
|
|
|
|
r.To = uint32(now.UTC().Unix())
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.From == 0 {
|
|
|
|
oneDay := uint32(86400) // -24 hours
|
|
|
|
if r.To < oneDay {
|
|
|
|
r.From = 0
|
|
|
|
} else {
|
|
|
|
r.From = r.To - oneDay
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MailServerResponse is the response payload sent by the mailserver.
|
2019-10-09 14:22:53 +00:00
|
|
|
type MailServerResponse struct {
|
2019-11-23 17:57:05 +00:00
|
|
|
LastEnvelopeHash Hash
|
2019-10-09 14:22:53 +00:00
|
|
|
Cursor []byte
|
|
|
|
Error error
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyncMailRequest contains details which envelopes should be synced
|
|
|
|
// between Mail Servers.
|
|
|
|
type SyncMailRequest struct {
|
|
|
|
// Lower is a lower bound of time range for which messages are requested.
|
|
|
|
Lower uint32
|
|
|
|
// Upper is a lower bound of time range for which messages are requested.
|
|
|
|
Upper uint32
|
|
|
|
// Bloom is a bloom filter to filter envelopes.
|
|
|
|
Bloom []byte
|
|
|
|
// Limit is the max number of envelopes to return.
|
|
|
|
Limit uint32
|
|
|
|
// Cursor is used for pagination of the results.
|
|
|
|
Cursor []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyncEventResponse is a response from the Mail Server
|
|
|
|
// form which the peer received envelopes.
|
|
|
|
type SyncEventResponse struct {
|
|
|
|
Cursor []byte
|
|
|
|
Error string
|
|
|
|
}
|