-
Notifications
You must be signed in to change notification settings - Fork 249
/
request.go
51 lines (45 loc) · 1.26 KB
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package mailserver
import (
"errors"
"time"
)
const (
maxMessagesRequestPayloadLimit = 1000
)
// 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
// Topics is a list of topics to filter envelopes.
Topics [][]byte
// 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
}
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 && len(r.Topics) == 0 {
return errors.New("bloom filter and topics is empty")
}
if r.Limit > maxMessagesRequestPayloadLimit {
return errors.New("limit exceeds the maximum allowed value")
}
return nil
}