github.com/status-im/status-go@v1.1.0/mailserver/request.go (about) 1 package mailserver 2 3 import ( 4 "errors" 5 "time" 6 ) 7 8 const ( 9 maxMessagesRequestPayloadLimit = 1000 10 ) 11 12 // MessagesRequestPayload is a payload sent to the Mail Server. 13 type MessagesRequestPayload struct { 14 // Lower is a lower bound of time range for which messages are requested. 15 Lower uint32 16 // Upper is a lower bound of time range for which messages are requested. 17 Upper uint32 18 // Bloom is a bloom filter to filter envelopes. 19 Bloom []byte 20 // Topics is a list of topics to filter envelopes. 21 Topics [][]byte 22 // Limit is the max number of envelopes to return. 23 Limit uint32 24 // Cursor is used for pagination of the results. 25 Cursor []byte 26 // Batch set to true indicates that the client supports batched response. 27 Batch bool 28 } 29 30 func (r *MessagesRequestPayload) SetDefaults() { 31 if r.Limit == 0 { 32 r.Limit = maxQueryLimit 33 } 34 35 if r.Upper == 0 { 36 r.Upper = uint32(time.Now().Unix() + whisperTTLSafeThreshold) 37 } 38 } 39 40 func (r MessagesRequestPayload) Validate() error { 41 if r.Upper < r.Lower { 42 return errors.New("query range is invalid: lower > upper") 43 } 44 if len(r.Bloom) == 0 && len(r.Topics) == 0 { 45 return errors.New("bloom filter and topics is empty") 46 } 47 if r.Limit > maxMessagesRequestPayloadLimit { 48 return errors.New("limit exceeds the maximum allowed value") 49 } 50 return nil 51 }