github.com/status-im/status-go@v1.1.0/eth-node/types/mailserver.go (about) 1 package types 2 3 import ( 4 "time" 5 ) 6 7 const ( 8 // MaxLimitInMessagesRequest represents the maximum number of messages 9 // that can be requested from the mailserver 10 MaxLimitInMessagesRequest = 1000 11 ) 12 13 // MessagesRequest contains details of a request of historic messages. 14 type MessagesRequest struct { 15 // ID of the request. The current implementation requires ID to be 32-byte array, 16 // however, it's not enforced for future implementation. 17 ID []byte `json:"id"` 18 // From is a lower bound of time range. 19 From uint32 `json:"from"` 20 // To is a upper bound of time range. 21 To uint32 `json:"to"` 22 // Limit determines the number of messages sent by the mail server 23 // for the current paginated request. 24 Limit uint32 `json:"limit"` 25 // Cursor is used as starting point for paginated requests. 26 Cursor []byte `json:"cursor"` 27 // StoreCursor is used as starting point for WAKUV2 paginatedRequests 28 StoreCursor StoreRequestCursor `json:"storeCursor"` 29 // Bloom is a filter to match requested messages. 30 Bloom []byte `json:"bloom"` 31 // PubsubTopic is the gossipsub topic on which the message was broadcasted 32 PubsubTopic string `json:"pubsubTopic"` 33 // ContentTopics is a list of topics. A returned message should 34 // belong to one of the topics from the list. 35 ContentTopics [][]byte `json:"contentTopics"` 36 } 37 38 type StoreRequestCursor []byte 39 40 // SetDefaults sets the From and To defaults 41 func (r *MessagesRequest) SetDefaults(now time.Time) { 42 // set From and To defaults 43 if r.To == 0 { 44 r.To = uint32(now.UTC().Unix()) 45 } 46 47 if r.From == 0 { 48 oneDay := uint32(86400) // -24 hours 49 if r.To < oneDay { 50 r.From = 0 51 } else { 52 r.From = r.To - oneDay 53 } 54 } 55 } 56 57 // MailServerResponse is the response payload sent by the mailserver. 58 type MailServerResponse struct { 59 LastEnvelopeHash Hash 60 Cursor []byte 61 Error error 62 } 63 64 // SyncMailRequest contains details which envelopes should be synced 65 // between Mail Servers. 66 type SyncMailRequest struct { 67 // Lower is a lower bound of time range for which messages are requested. 68 Lower uint32 69 // Upper is a lower bound of time range for which messages are requested. 70 Upper uint32 71 // Bloom is a bloom filter to filter envelopes. 72 Bloom []byte 73 // Limit is the max number of envelopes to return. 74 Limit uint32 75 // Cursor is used for pagination of the results. 76 Cursor []byte 77 } 78 79 // SyncEventResponse is a response from the Mail Server 80 // form which the peer received envelopes. 81 type SyncEventResponse struct { 82 Cursor []byte 83 Error string 84 }