Documentation ¶
Index ¶
- Constants
- Variables
- func SendDiscoverySummary(peers []*p2p.PeerInfo)
- type Cache
- type Options
- type PeerPool
- type PoolEvent
- type Register
- type TopicPool
- func (t *TopicPool) AddPeerFromTable(server *p2p.Server) *discv5.Node
- func (t *TopicPool) BelowMin() bool
- func (t *TopicPool) ConfirmAdded(server *p2p.Server, nodeID discover.NodeID)
- func (t *TopicPool) ConfirmDropped(server *p2p.Server, nodeID discover.NodeID) bool
- func (t *TopicPool) MaxReached() bool
- func (t *TopicPool) SearchRunning() bool
- func (t *TopicPool) SetLimits(limits params.Limits)
- func (t *TopicPool) StartSearch(server *p2p.Server) error
- func (t *TopicPool) StopSearch(server *p2p.Server)
- func (t *TopicPool) Topic() discv5.Topic
- type TopicPoolInterface
- type Verifier
Constants ¶
const ( // DefaultFastSync is a recommended value for aggressive peers search. DefaultFastSync = 3 * time.Second // DefaultSlowSync is a recommended value for slow (background) peers search. DefaultSlowSync = 30 * time.Second // DefaultDiscV5Timeout is a timeout after which Discv5 is stopped. DefaultDiscV5Timeout = 3 * time.Minute // DefaultTopicFastModeTimeout is a timeout after which sync mode is switched to slow mode. DefaultTopicFastModeTimeout = 30 * time.Second // DefaultTopicStopSearchDelay is the default delay when stopping a topic search. DefaultTopicStopSearchDelay = 10 * time.Second )
const MailServerDiscoveryTopic = "whispermail"
MailServerDiscoveryTopic topic name for mailserver discovery.
Variables ¶
var ( // ErrDiscv5NotRunning returned when pool is started but discover v5 is not running or not enabled. ErrDiscv5NotRunning = errors.New("Discovery v5 is not running") )
var MailServerDiscoveryLimits = params.Limits{Min: 3, Max: 3}
MailServerDiscoveryLimits default mailserver discovery limits.
Functions ¶
func SendDiscoverySummary ¶
SendDiscoverySummary sends discovery.summary signal.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache maintains list of peers that were discovered.
func (*Cache) GetPeersRange ¶
GetPeersRange returns peers for a given topic with a limit.
type Options ¶
type Options struct { FastSync time.Duration SlowSync time.Duration // After this time, Discovery is stopped even if max peers is not reached. DiscServerTimeout time.Duration // AllowStop allows stopping Discovery when reaching max peers or after timeout. AllowStop bool // TopicStopSearchDelay time stopSearch will be waiting for max cached peers to be // filled before really stopping the search. TopicStopSearchDelay time.Duration // TrustedMailServers is a list of trusted nodes. TrustedMailServers []discover.NodeID // MailServerRegistryAddress is the MailServerRegistry contract address MailServerRegistryAddress string }
Options is a struct with PeerPool configuration.
func NewDefaultOptions ¶
func NewDefaultOptions() *Options
NewDefaultOptions returns a struct with default Options.
type PeerPool ¶
type PeerPool struct {
// contains filtered or unexported fields
}
PeerPool manages discovered peers and connects them to p2p server
func NewPeerPool ¶
func NewPeerPool(discovery discovery.Discovery, config map[discv5.Topic]params.Limits, cache *Cache, options *Options) *PeerPool
NewPeerPool creates instance of PeerPool
func (*PeerPool) Start ¶
Start creates topic pool for each topic in config and subscribes to server events.
type Register ¶
type Register struct {
// contains filtered or unexported fields
}
Register manages register topic queries
func NewRegister ¶
NewRegister creates instance of topic register
type TopicPool ¶
type TopicPool struct {
// contains filtered or unexported fields
}
TopicPool manages peers for topic.
func (*TopicPool) AddPeerFromTable ¶
AddPeerFromTable checks if there is a valid peer in local table and adds it to a server.
func (*TopicPool) ConfirmAdded ¶
ConfirmAdded called when peer was added by p2p Server.
- Skip a peer if it not in our peer table
- Add a peer to a cache.
- Disconnect a peer if it was connected after we reached max limit of peers. (we can't know in advance if peer will be connected, thats why we allow to overflow for short duration)
- Switch search to slow mode if it is running.
func (*TopicPool) ConfirmDropped ¶
ConfirmDropped called when server receives drop event. 1. Skip peer if it is not in our peer table. 2. If disconnect request - we could drop that peer ourselves. 3. If connected number will drop below min limit - switch to fast mode. 4. Delete a peer from cache and peer table. Returns false if peer is not in our table or we requested removal of this peer. Otherwise peer is removed and true is returned.
func (*TopicPool) MaxReached ¶
MaxReached returns true if we connected with max number of peers.
func (*TopicPool) SearchRunning ¶
SearchRunning returns true if search is running
func (*TopicPool) StartSearch ¶
StartSearch creates discv5 queries and runs a loop to consume found peers.
func (*TopicPool) StopSearch ¶
StopSearch stops the closes stop
type TopicPoolInterface ¶
type TopicPoolInterface interface { StopSearch(server *p2p.Server) BelowMin() bool SearchRunning() bool StartSearch(server *p2p.Server) error ConfirmDropped(server *p2p.Server, nodeID discover.NodeID) bool AddPeerFromTable(server *p2p.Server) *discv5.Node MaxReached() bool ConfirmAdded(server *p2p.Server, nodeID discover.NodeID) Topic() discv5.Topic SetLimits(limits params.Limits) // contains filtered or unexported methods }
TopicPoolInterface the TopicPool interface.