mailserver

package
v0.88.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2021 License: MPL-2.0 Imports: 27 Imported by: 10

README

MailServer

This document is meant to collect various information about our MailServer implementation.

Syncing between mail servers

It might happen that one mail server is behind other due to various reasons like a machine being down for a few minutes etc.

There is an option to fix such a mail server:

  1. SSH to a machine where this broken mail server runs,
  2. Add a mail server from which you want to sync:
# sudo might be not needed in your setup
$ echo '{"jsonrpc":"2.0","method":"admin_addPeer", "params": ["enode://c42f368a23fa98ee546fd247220759062323249ef657d26d357a777443aec04db1b29a3a22ef3e7c548e18493ddaf51a31b0aed6079bd6ebe5ae838fcfaf3a49@206.189.243.162:30504"], "id":1}' | \
    sudo socat -d -d - UNIX-CONNECT:/docker/statusd-mail/data/geth.ipc
  1. Mark it as a trusted peer:
# sudo might be not needed in your setup
$ echo '{"jsonrpc":"2.0","method":"shh_markTrustedPeer", "params": ["enode://c42f368a23fa98ee546fd247220759062323249ef657d26d357a777443aec04db1b29a3a22ef3e7c548e18493ddaf51a31b0aed6079bd6ebe5ae838fcfaf3a49@206.189.243.162:30504"], "id":1}' | \
    sudo socat -d -d - UNIX-CONNECT:/docker/statusd-mail/data/geth.ipc
  1. Finally, trigger the sync command:
# sudo might be not needed in your setup
$ echo '{"jsonrpc":"2.0","method":"shhext_syncMessages","params":[{"mailServerPeer":"enode://c42f368a23fa98ee546fd247220759062323249ef657d26d357a777443aec04db1b29a3a22ef3e7c548e18493ddaf51a31b0aed6079bd6ebe5ae838fcfaf3a49@206.189.243.162:30504", "to": 1550479953, "from": 1550393583, "limit": 1000}],"id":1}' | \
    sudo socat -d -d - UNIX-CONNECT:/docker/statusd-mail/data/geth.ipc

You can add "followCursor": true if you want it to automatically download messages until the cursor is empty meaning all data was synced.

Debugging

To verify that your mail server received any responses, watch logs and seek for logs like this:

INFO [02-18|09:08:54.257] received sync response count=217 final=false err= cursor=[]

And it should finish with:

INFO [02-18|09:08:54.431] received sync response count=0 final=true err= cursor=[]

Documentation

Index

Constants

View Source
const (
	// DBKeyLength is a size of the envelope key.
	DBKeyLength  = types.HashLength + timestampLength + types.TopicLength
	CursorLength = types.HashLength + timestampLength
)

Variables

View Source
var (
	// ErrInvalidByteSize is returned when DBKey can't be created
	// from a byte slice because it has invalid length.
	ErrInvalidByteSize = errors.New("byte slice has invalid length")
)

Functions

This section is empty.

Types

type Config added in v0.39.0

type Config struct {
	// DataDir points to a directory where mailserver's data is stored.
	DataDir string
	// Password is used to create a symmetric key to decrypt requests.
	Password string
	// AsymKey is an asymmetric key to decrypt requests.
	AsymKey string
	// MininumPoW is a minimum PoW for requests.
	MinimumPoW float64
	// RateLimit is a maximum number of requests per second from a peer.
	RateLimit int
	// DataRetention specifies a number of days an envelope should be stored for.
	DataRetention   int
	PostgresEnabled bool
	PostgresURI     string
}

type CursorQuery added in v0.35.0

type CursorQuery struct {
	// contains filtered or unexported fields
}

type DB added in v0.35.0

type DB interface {
	Close() error
	// SaveEnvelope stores an envelope
	SaveEnvelope(types.Envelope) error
	// GetEnvelope returns an rlp encoded envelope from the datastore
	GetEnvelope(*DBKey) ([]byte, error)
	// Prune removes envelopes older than time
	Prune(time.Time, int) (int, error)
	// BuildIterator returns an iterator over envelopes
	BuildIterator(query CursorQuery) (Iterator, error)
}

DB is an interface to abstract interactions with the db so that the mailserver is agnostic to the underlying technology used

type DBKey

type DBKey struct {
	// contains filtered or unexported fields
}

DBKey key to be stored in a db.

func NewDBKey added in v0.35.0

func NewDBKey(timestamp uint32, topic types.TopicType, h types.Hash) *DBKey

NewDBKey creates a new DBKey with the given values.

func (*DBKey) Bytes added in v0.35.0

func (k *DBKey) Bytes() []byte

Bytes returns a bytes representation of the DBKey.

func (*DBKey) Cursor added in v0.35.0

func (k *DBKey) Cursor() []byte

func (*DBKey) EnvelopeHash added in v0.35.0

func (k *DBKey) EnvelopeHash() types.Hash

func (*DBKey) Topic added in v0.35.0

func (k *DBKey) Topic() types.TopicType

type Iterator added in v0.35.0

type Iterator interface {
	Next() bool
	DBKey() (*DBKey, error)
	Release() error
	Error() error
	GetEnvelopeByBloomFilter(bloom []byte) ([]byte, error)
	GetEnvelopeByTopicsMap(topics map[types.TopicType]bool) ([]byte, error)
}

type LevelDB added in v0.35.0

type LevelDB struct {
	// contains filtered or unexported fields
}

func NewLevelDB added in v0.35.0

func NewLevelDB(dataDir string) (*LevelDB, error)

func (*LevelDB) BuildIterator added in v0.35.0

func (db *LevelDB) BuildIterator(query CursorQuery) (Iterator, error)

Build iterator returns an iterator given a start/end and a cursor

func (*LevelDB) Close added in v0.35.0

func (db *LevelDB) Close() error

func (*LevelDB) GetEnvelope added in v0.35.0

func (db *LevelDB) GetEnvelope(key *DBKey) ([]byte, error)

GetEnvelope get an envelope by its key

func (*LevelDB) Prune added in v0.35.0

func (db *LevelDB) Prune(t time.Time, batchSize int) (int, error)

Prune removes envelopes older than time

func (*LevelDB) SaveEnvelope added in v0.35.0

func (db *LevelDB) SaveEnvelope(env types.Envelope) error

SaveEnvelope stores an envelope in leveldb and increments the metrics

type LevelDBIterator added in v0.35.0

type LevelDBIterator struct {
	iterator.Iterator
}

func (*LevelDBIterator) DBKey added in v0.35.0

func (i *LevelDBIterator) DBKey() (*DBKey, error)

func (*LevelDBIterator) GetEnvelopeByBloomFilter added in v0.84.0

func (i *LevelDBIterator) GetEnvelopeByBloomFilter(bloom []byte) ([]byte, error)

func (*LevelDBIterator) GetEnvelopeByTopicsMap added in v0.84.0

func (i *LevelDBIterator) GetEnvelopeByTopicsMap(topics map[types.TopicType]bool) ([]byte, error)

func (*LevelDBIterator) Release added in v0.39.10

func (i *LevelDBIterator) Release() error

type MessagesRequestPayload added in v0.35.0

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
}

MessagesRequestPayload is a payload sent to the Mail Server.

func (*MessagesRequestPayload) SetDefaults added in v0.39.0

func (r *MessagesRequestPayload) SetDefaults()

func (MessagesRequestPayload) Validate added in v0.39.0

func (r MessagesRequestPayload) Validate() error

type PostgresDB added in v0.35.0

type PostgresDB struct {
	// contains filtered or unexported fields
}

func NewPostgresDB added in v0.35.0

func NewPostgresDB(uri string) (*PostgresDB, error)

func (*PostgresDB) BuildIterator added in v0.35.0

func (i *PostgresDB) BuildIterator(query CursorQuery) (Iterator, error)

func (*PostgresDB) Close added in v0.35.0

func (i *PostgresDB) Close() error

func (*PostgresDB) GetEnvelope added in v0.35.0

func (i *PostgresDB) GetEnvelope(key *DBKey) ([]byte, error)

func (*PostgresDB) Prune added in v0.35.0

func (i *PostgresDB) Prune(t time.Time, batch int) (int, error)

func (*PostgresDB) SaveEnvelope added in v0.35.0

func (i *PostgresDB) SaveEnvelope(env types.Envelope) error

type WakuMailServer added in v0.39.0

type WakuMailServer struct {
	// contains filtered or unexported fields
}

func (*WakuMailServer) Archive added in v0.39.0

func (s *WakuMailServer) Archive(env *wakucommon.Envelope)

func (*WakuMailServer) Close added in v0.39.0

func (s *WakuMailServer) Close()

func (*WakuMailServer) Deliver added in v0.39.0

func (s *WakuMailServer) Deliver(peerID []byte, req wakucommon.MessagesRequest)

func (*WakuMailServer) DeliverMail added in v0.39.0

func (s *WakuMailServer) DeliverMail(peerID []byte, req *wakucommon.Envelope)

DEPRECATED; user Deliver instead

func (*WakuMailServer) Init added in v0.39.0

func (s *WakuMailServer) Init(waku *waku.Waku, cfg *params.WakuConfig) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL