2018-12-11 10:23:47 +00:00
|
|
|
package mailserver
|
|
|
|
|
2020-01-08 11:12:23 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
maxMessagesRequestPayloadLimit = 1000
|
|
|
|
)
|
|
|
|
|
2018-12-11 10:23:47 +00:00
|
|
|
// MessagesRequestPayload is a payload sent to the Mail Server.
|
|
|
|
type MessagesRequestPayload 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
|
2020-01-21 07:11:24 +00:00
|
|
|
// Topics is a list of topics to filter envelopes.
|
|
|
|
Topics [][]byte
|
2018-12-11 10:23:47 +00:00
|
|
|
// Limit is the max number of envelopes to return.
|
|
|
|
Limit uint32
|
|
|
|
// Cursor is used for pagination of the results.
|
|
|
|
Cursor []byte
|
|
|
|
// Batch set to true indicates that the client supports batched response.
|
|
|
|
Batch bool
|
|
|
|
}
|
2020-01-08 11:12:23 +00:00
|
|
|
|
|
|
|
func (r *MessagesRequestPayload) SetDefaults() {
|
|
|
|
if r.Limit == 0 {
|
|
|
|
r.Limit = maxQueryLimit
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.Upper == 0 {
|
|
|
|
r.Upper = uint32(time.Now().Unix() + whisperTTLSafeThreshold)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r MessagesRequestPayload) Validate() error {
|
|
|
|
if r.Upper < r.Lower {
|
|
|
|
return errors.New("query range is invalid: lower > upper")
|
|
|
|
}
|
|
|
|
if len(r.Bloom) == 0 {
|
|
|
|
return errors.New("bloom filter is empty")
|
|
|
|
}
|
|
|
|
if r.Limit > maxMessagesRequestPayloadLimit {
|
|
|
|
return errors.New("limit exceeds the maximum allowed value")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|