Documentation ¶
Index ¶
- Variables
- func EnsureUsedRecordsAddedFirst(ps *PeerStore, conn NodesNotifee) error
- func GetFirstConnected(provider PeersProvider, store *PeerStore) (*enode.Node, error)
- type Cache
- type ConnectionManager
- type EnvelopeEventSubscbriber
- type LastUsedConnectionMonitor
- type NodesNotifee
- type PeerAdderRemover
- type PeerEventsSubscriber
- type PeerRecord
- type PeerStore
- type PeersProvider
Constants ¶
This section is empty.
Variables ¶
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 (*Cache) LoadAll ¶
func (c *Cache) LoadAll() (rst []PeerRecord, err error)
LoadAll loads all records from persistent database.
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 ¶
NodesNotifee interface to be notified when new nodes are received.
type PeerAdderRemover ¶
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) 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 ¶
NewPeerStore returns an instance of PeerStore.
type PeersProvider ¶
PeersProvider is an interface for requesting list of peers.