mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 22:26:30 +00:00
168 lines
4.7 KiB
Go
168 lines
4.7 KiB
Go
package shhext
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
)
|
|
|
|
const (
|
|
// defaultWorkTime is a work time reported in messages sent to MailServer nodes.
|
|
defaultWorkTime = 5
|
|
// defaultRequestTimeout is the default request timeout in seconds
|
|
defaultRequestTimeout = 10
|
|
|
|
// ensContractAddress is the address of the ENS resolver
|
|
ensContractAddress = "0x314159265dd8dbb310642f98f50c066173c1259b"
|
|
)
|
|
|
|
var (
|
|
// ErrInvalidMailServerPeer is returned when it fails to parse enode from params.
|
|
ErrInvalidMailServerPeer = errors.New("invalid mailServerPeer value")
|
|
// ErrInvalidSymKeyID is returned when it fails to get a symmetric key.
|
|
ErrInvalidSymKeyID = errors.New("invalid symKeyID value")
|
|
// ErrInvalidPublicKey is returned when public key can't be extracted
|
|
// from MailServer's nodeID.
|
|
ErrInvalidPublicKey = errors.New("can't extract public key")
|
|
// ErrPFSNotEnabled is returned when an endpoint PFS only is called but
|
|
// PFS is disabled
|
|
ErrPFSNotEnabled = errors.New("pfs not enabled")
|
|
)
|
|
|
|
// -----
|
|
// PAYLOADS
|
|
// -----
|
|
|
|
// MessagesRequest is a RequestMessages() request payload.
|
|
type MessagesRequest struct {
|
|
// MailServerPeer is MailServer's enode address.
|
|
MailServerPeer string `json:"mailServerPeer"`
|
|
|
|
// From is a lower bound of time range (optional).
|
|
// Default is 24 hours back from now.
|
|
From uint32 `json:"from"`
|
|
|
|
// To is a upper bound of time range (optional).
|
|
// Default is now.
|
|
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 string `json:"cursor"`
|
|
|
|
// Topic is a regular Whisper topic.
|
|
// DEPRECATED
|
|
Topic types.TopicType `json:"topic"`
|
|
|
|
// Topics is a list of Whisper topics.
|
|
Topics []types.TopicType `json:"topics"`
|
|
|
|
// SymKeyID is an ID of a symmetric key to authenticate to MailServer.
|
|
// It's derived from MailServer password.
|
|
SymKeyID string `json:"symKeyID"`
|
|
|
|
// Timeout is the time to live of the request specified in seconds.
|
|
// Default is 10 seconds
|
|
Timeout time.Duration `json:"timeout"`
|
|
|
|
// Force ensures that requests will bypass enforced delay.
|
|
Force bool `json:"force"`
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
if r.Timeout == 0 {
|
|
r.Timeout = defaultRequestTimeout
|
|
}
|
|
}
|
|
|
|
// MessagesResponse is a response for shhext_requestMessages2 method.
|
|
type MessagesResponse struct {
|
|
// Cursor from the response can be used to retrieve more messages
|
|
// for the previous request.
|
|
Cursor string `json:"cursor"`
|
|
|
|
// Error indicates that something wrong happened when sending messages
|
|
// to the requester.
|
|
Error error `json:"error"`
|
|
}
|
|
|
|
// SyncMessagesRequest is a SyncMessages() request payload.
|
|
type SyncMessagesRequest struct {
|
|
// MailServerPeer is MailServer's enode address.
|
|
MailServerPeer string `json:"mailServerPeer"`
|
|
|
|
// From is a lower bound of time range (optional).
|
|
// Default is 24 hours back from now.
|
|
From uint32 `json:"from"`
|
|
|
|
// To is a upper bound of time range (optional).
|
|
// Default is now.
|
|
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 string `json:"cursor"`
|
|
|
|
// FollowCursor if true loads messages until cursor is empty.
|
|
FollowCursor bool `json:"followCursor"`
|
|
|
|
// Topics is a list of Whisper topics.
|
|
// If empty, a full bloom filter will be used.
|
|
Topics []types.TopicType `json:"topics"`
|
|
}
|
|
|
|
// InitiateHistoryRequestParams type for initiating history requests from a peer.
|
|
type InitiateHistoryRequestParams struct {
|
|
Peer string
|
|
SymKeyID string
|
|
Requests []TopicRequest
|
|
Force bool
|
|
Timeout time.Duration
|
|
}
|
|
|
|
// SyncMessagesResponse is a response from the mail server
|
|
// to which SyncMessagesRequest was sent.
|
|
type SyncMessagesResponse struct {
|
|
// Cursor from the response can be used to retrieve more messages
|
|
// for the previous request.
|
|
Cursor string `json:"cursor"`
|
|
|
|
// Error indicates that something wrong happened when sending messages
|
|
// to the requester.
|
|
Error string `json:"error"`
|
|
}
|
|
|
|
type Author struct {
|
|
PublicKey types.HexBytes `json:"publicKey"`
|
|
Alias string `json:"alias"`
|
|
Identicon string `json:"identicon"`
|
|
}
|
|
|
|
type Metadata struct {
|
|
DedupID []byte `json:"dedupId"`
|
|
EncryptionID types.HexBytes `json:"encryptionId"`
|
|
MessageID types.HexBytes `json:"messageId"`
|
|
Author Author `json:"author"`
|
|
}
|