mailservers

package
v0.26.0-alpha.34 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoConnected returned when mail servers are not connected.
	ErrNoConnected = errors.New("no connected mail servers")
)

Functions

func EnsureUsedRecordsAddedFirst

func EnsureUsedRecordsAddedFirst(ps *PeerStore, conn NodesNotifee) error

EnsureUsedRecordsAddedFirst checks if any nodes were marked as connected before app went offline.

func GetFirstConnected

func GetFirstConnected(provider PeersProvider, store *PeerStore) (*enode.Node, error)

GetFirstConnected returns first connected peer that is also added to a peer store. Raises ErrNoConnected if no peers are added to a peer store.

Types

type Cache

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

Cache is wrapper for operations on disk with leveldb.

func NewCache

func NewCache(db *leveldb.DB) *Cache

NewCache returns pointer to a Cache instance.

func (*Cache) LoadAll

func (c *Cache) LoadAll() (rst []PeerRecord, err error)

LoadAll loads all records from persistent database.

func (*Cache) Replace

func (c *Cache) Replace(nodes []*enode.Node) error

Replace deletes old and adds new records in the persistent cache.

func (*Cache) UpdateRecord

func (c *Cache) UpdateRecord(record PeerRecord) error

UpdateRecord updates single record.

type ConnectionManager

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

ConnectionManager manages keeps target of peers connected.

func NewConnectionManager

func NewConnectionManager(server p2pServer, whisper EnvelopeEventSubscbriber, target, maxFailures int, timeout time.Duration) *ConnectionManager

NewConnectionManager creates an instance of ConnectionManager.

func (*ConnectionManager) Notify

func (ps *ConnectionManager) Notify(nodes []*enode.Node)

Notify sends a non-blocking notification about new nodes.

func (*ConnectionManager) Start

func (ps *ConnectionManager) Start()

Start subscribes to a p2p server and handles new peers and state updates for those peers.

func (*ConnectionManager) Stop

func (ps *ConnectionManager) Stop()

Stop gracefully closes all background goroutines and waits until they finish.

type EnvelopeEventSubscbriber

type EnvelopeEventSubscbriber interface {
	SubscribeEnvelopeEvents(chan<- whisper.EnvelopeEvent) event.Subscription
}

EnvelopeEventSubscbriber interface to subscribe for whisper.EnvelopeEvent's.

type LastUsedConnectionMonitor

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

LastUsedConnectionMonitor watches relevant events and reflects it in cache.

func NewLastUsedConnectionMonitor

func NewLastUsedConnectionMonitor(ps *PeerStore, cache *Cache, whisper EnvelopeEventSubscbriber) *LastUsedConnectionMonitor

NewLastUsedConnectionMonitor returns pointer to the instance of LastUsedConnectionMonitor.

func (*LastUsedConnectionMonitor) Start

func (mon *LastUsedConnectionMonitor) Start()

Start spins a separate goroutine to watch connections.

func (*LastUsedConnectionMonitor) Stop

func (mon *LastUsedConnectionMonitor) Stop()

Stop closes channel to signal a quit and waits until all goroutines are stoppped.

type NodesNotifee

type NodesNotifee interface {
	Notify([]*enode.Node)
}

NodesNotifee interface to be notified when new nodes are received.

type PeerAdderRemover

type PeerAdderRemover interface {
	AddPeer(node *enode.Node)
	RemovePeer(node *enode.Node)
}

PeerAdderRemover is an interface for adding or removing peers.

type PeerEventsSubscriber

type PeerEventsSubscriber interface {
	SubscribeEvents(chan *p2p.PeerEvent) event.Subscription
}

PeerEventsSubscriber interface to subscribe for p2p.PeerEvent's.

type PeerRecord

type PeerRecord struct {

	// last time it was used.
	LastUsed time.Time
	// contains filtered or unexported fields
}

PeerRecord is set data associated with each peer that is stored on disk. PeerRecord stored with a enode as a key in leveldb, and body marshalled as json.

func NewPeerRecord

func NewPeerRecord(node *enode.Node) PeerRecord

NewPeerRecord returns instance of the peer record.

func (PeerRecord) Encode

func (r PeerRecord) Encode() ([]byte, error)

Encode encodes PeerRecords to bytes.

func (PeerRecord) EncodeKey

func (r PeerRecord) EncodeKey() ([]byte, error)

EncodeKey returns bytes that will should be used as a key in persistent storage.

func (PeerRecord) ID

func (r PeerRecord) ID() enode.ID

ID returns enode identity of the node.

func (PeerRecord) Node

func (r PeerRecord) Node() *enode.Node

Node returs pointer to original object. enode.Node doensn't allow modification on the object.

type PeerStore

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

PeerStore stores list of selected mail servers and keeps N of them connected.

func NewPeerStore

func NewPeerStore(cache *Cache) *PeerStore

NewPeerStore returns an instance of PeerStore.

func (*PeerStore) Exist

func (ps *PeerStore) Exist(nodeID enode.ID) bool

Exist confirms that peers was added to a store.

func (*PeerStore) Get

func (ps *PeerStore) Get(nodeID enode.ID) *enode.Node

Get returns instance of the node with requested ID or nil if ID is not found.

func (*PeerStore) Update

func (ps *PeerStore) Update(nodes []*enode.Node) error

Update updates peers locally.

type PeersProvider

type PeersProvider interface {
	Peers() []*p2p.Peer
}

PeersProvider is an interface for requesting list of peers.

Jump to

Keyboard shortcuts

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