Documentation
¶
Index ¶
- Constants
- Variables
- func AddrInfoCaller(handler interface{}, params ...interface{})
- func ManagerStateCaller(handler interface{}, params ...interface{})
- func PeerCaller(handler interface{}, params ...interface{})
- func PeerConnCaller(handler interface{}, params ...interface{})
- func PeerDurationCaller(handler interface{}, params ...interface{})
- func PeerOptErrorCaller(handler interface{}, params ...interface{})
- func PeerRelationCaller(handler interface{}, params ...interface{})
- func StreamCaller(handler interface{}, params ...interface{})
- type ConfigManager
- type DiscoveryService
- type DiscoveryServiceEvents
- type DiscoveryServiceOption
- func WithDiscoveryServiceAdvertiseInterval(interval time.Duration) DiscoveryServiceOption
- func WithDiscoveryServiceLogger(logger *logger.Logger) DiscoveryServiceOption
- func WithDiscoveryServiceMaxDiscoveredPeers(max int) DiscoveryServiceOption
- func WithDiscoveryServiceRendezvousPoint(rendezvousPoint string) DiscoveryServiceOption
- func WithDiscoveryServiceRoutingRefreshPeriod(period time.Duration) DiscoveryServiceOption
- type DiscoveryServiceOptions
- type Manager
- func (m *Manager) Call(peerID peer.ID, f PeerFunc)
- func (m *Manager) ConnectPeer(addrInfo *peer.AddrInfo, peerRelation PeerRelation, alias ...string) error
- func (m *Manager) ConnectedCount(relation ...PeerRelation) int
- func (m *Manager) DisconnectPeer(peerID peer.ID, disconnectReason ...error) error
- func (m *Manager) ForEach(f PeerForEachFunc, filter ...PeerRelation)
- func (m *Manager) IsConnected(peerID peer.ID) bool
- func (m *Manager) PeerInfoSnapshot(id peer.ID) *PeerInfoSnapshot
- func (m *Manager) PeerInfoSnapshots() []*PeerInfoSnapshot
- func (m *Manager) Start(shutdownSignal <-chan struct{})
- type ManagerEvents
- type ManagerOption
- type ManagerOptions
- type ManagerState
- type Peer
- type PeerConfig
- type PeerForEachFunc
- type PeerFunc
- type PeerInfoSnapshot
- type PeerOptError
- type PeerRelation
Constants ¶
const ( // KnownPeerConnectivityProtectionTag is the tag used by Manager to // protect known peer connectivity from getting trimmed via the // connmgr.ConnManager. KnownPeerConnectivityProtectionTag = "peering-manager" )
Variables ¶
var ( // Returned if the manager is supposed to create a connection // to itself (host wise). ErrCantConnectToItself = errors.New("the host can't connect to itself") // Returned if a peer is tried to be added to the manager which is already added. ErrPeerInManagerAlready = errors.New("peer is already in manager") // Returned if the manager is shutting down. ErrManagerShutdown = errors.New("manager is shutting down") )
Functions ¶
func AddrInfoCaller ¶
func AddrInfoCaller(handler interface{}, params ...interface{})
AddrInfoCaller gets called with a peer.AddrInfo.
func ManagerStateCaller ¶
func ManagerStateCaller(handler interface{}, params ...interface{})
ManagerStateCaller gets called with a ManagerState.
func PeerCaller ¶
func PeerCaller(handler interface{}, params ...interface{})
PeerCaller gets called with a Peer.
func PeerConnCaller ¶
func PeerConnCaller(handler interface{}, params ...interface{})
PeerConnCaller gets called with a Peer and its associated network.Conn.
func PeerDurationCaller ¶
func PeerDurationCaller(handler interface{}, params ...interface{})
PeerDurationCaller gets called with a Peer and a time.Duration.
func PeerOptErrorCaller ¶
func PeerOptErrorCaller(handler interface{}, params ...interface{})
PeerOptErrorCaller gets called with a Peer and an error.
func PeerRelationCaller ¶
func PeerRelationCaller(handler interface{}, params ...interface{})
PeerRelationCaller gets called with a Peer and its old PeerRelation.
func StreamCaller ¶
func StreamCaller(handler interface{}, params ...interface{})
StreamCaller gets called with a network.Stream.
Types ¶
type ConfigManager ¶
type ConfigManager struct {
// contains filtered or unexported fields
}
ConfigManager handles the list of peers that are stored in the peering config. It calls a function if the list changed.
func NewConfigManager ¶
func NewConfigManager(storeCallback func([]*PeerConfig) error) *ConfigManager
NewConfigManager creates a new config manager.
func (*ConfigManager) AddPeer ¶
func (pm *ConfigManager) AddPeer(multiAddress multiaddr.Multiaddr, alias string) error
AddPeer adds a peer to the config manager.
func (*ConfigManager) GetPeers ¶
func (pm *ConfigManager) GetPeers() []*PeerConfig
GetPeers returns all known peers.
func (*ConfigManager) RemovePeer ¶
func (pm *ConfigManager) RemovePeer(peerID peer.ID) error
RemovePeer removes a peer from the config manager.
func (*ConfigManager) StoreOnChange ¶
func (pm *ConfigManager) StoreOnChange(store bool)
StoreOnChange sets whether storing changes to the config is active or not.
type DiscoveryService ¶
type DiscoveryService struct { // Events happening around the DiscoveryService. Events DiscoveryServiceEvents // contains filtered or unexported fields }
DiscoveryService is a service which discovers to peer to.
func NewDiscoveryService ¶
func NewDiscoveryService(host host.Host, mng *Manager, opts ...DiscoveryServiceOption) *DiscoveryService
NewDiscoveryService creates a new DiscoveryService.
func (*DiscoveryService) Start ¶
func (ds *DiscoveryService) Start(shutdownSignal <-chan struct{})
Start starts the DiscoveryService. This function blocks until shutdownSignal is signaled.
type DiscoveryServiceEvents ¶
type DiscoveryServiceEvents struct { // Fired when a search is started. Searching *events.Event // Fired when a search has ended. Searched *events.Event // Fired when a peer has been discovered for peering. Discovered *events.Event // Fired when a Kademlia DHT stream is started. ProtocolStarted *events.Event // Fired when a Kademlia DHT stream is terminated ProtocolTerminated *events.Event // Fired when an error occurs. Error *events.Event }
DiscoveryServiceEvents are events happening around a DiscoveryService. No methods on DiscoveryService must be called from within the event handlers.
type DiscoveryServiceOption ¶
type DiscoveryServiceOption func(opts *DiscoveryServiceOptions)
DiscoveryServiceOption is a function setting a DiscoveryServiceOptions option.
func WithDiscoveryServiceAdvertiseInterval ¶
func WithDiscoveryServiceAdvertiseInterval(interval time.Duration) DiscoveryServiceOption
WithDiscoveryServiceAdvertiseInterval sets the interval in which the peer advertises itself via the DHT on the rendezvous point.
func WithDiscoveryServiceLogger ¶
func WithDiscoveryServiceLogger(logger *logger.Logger) DiscoveryServiceOption
WithDiscoveryServiceLogger enables logging within the DiscoveryService.
func WithDiscoveryServiceMaxDiscoveredPeers ¶
func WithDiscoveryServiceMaxDiscoveredPeers(max int) DiscoveryServiceOption
WithDiscoveryServiceMaxDiscoveredPeers sets the max. amount of discovered peers to retain a connection to.
func WithDiscoveryServiceRendezvousPoint ¶
func WithDiscoveryServiceRendezvousPoint(rendezvousPoint string) DiscoveryServiceOption
WithDiscoveryServiceRendezvousPoint sets the rendezvous point for peer discovery.
func WithDiscoveryServiceRoutingRefreshPeriod ¶
func WithDiscoveryServiceRoutingRefreshPeriod(period time.Duration) DiscoveryServiceOption
WithDiscoveryServiceRoutingRefreshPeriod sets the interval in which buckets are refreshed in the routing table.
type DiscoveryServiceOptions ¶
type DiscoveryServiceOptions struct { RendezvousPoint string AdvertiseInterval time.Duration RoutingTableRefreshPeriod time.Duration MaxDiscoveredPeers int Logger *logger.Logger }
DiscoveryServiceOptions define options for a DiscoveryService.
type Manager ¶
type Manager struct { // Events happening around the Manager. Events ManagerEvents // contains filtered or unexported fields }
Manager manages a set of known and other connected peers. It also provides the functionality to reconnect to known peers.
func NewManager ¶
func NewManager(host host.Host, opts ...ManagerOption) *Manager
NewManager creates a new Manager.
func (*Manager) Call ¶
Call calls the given PeerFunc synchronized within the Manager's event loop, if the peer exists. PeerFunc must not call any function on Manager.
func (*Manager) ConnectPeer ¶
func (m *Manager) ConnectPeer(addrInfo *peer.AddrInfo, peerRelation PeerRelation, alias ...string) error
ConnectPeer connects to the given peer. If the peer is considered "known", then its connection is protected from trimming. Optionally an alias for the peer can be defined to better identify it afterwards.
func (*Manager) ConnectedCount ¶
func (m *Manager) ConnectedCount(relation ...PeerRelation) int
ConnectedCount returns the count of connected peer. Optionally only including peers with the given relation.
func (*Manager) DisconnectPeer ¶
DisconnectPeer disconnects the given peer. If the peer is considered "known", then its connection is unprotected from future trimming.
func (*Manager) ForEach ¶
func (m *Manager) ForEach(f PeerForEachFunc, filter ...PeerRelation)
ForEach calls the given PeerForEachFunc on each Peer. Optionally only loops over the peers with the given filter relation.
func (*Manager) IsConnected ¶
IsConnected tells whether there is a connection to the given peer.
func (*Manager) PeerInfoSnapshot ¶
func (m *Manager) PeerInfoSnapshot(id peer.ID) *PeerInfoSnapshot
PeerInfoSnapshot returns a snapshot of information of a peer with given id. If the peer is not known to the Manager, result is nil.
func (*Manager) PeerInfoSnapshots ¶
func (m *Manager) PeerInfoSnapshots() []*PeerInfoSnapshot
PeerInfoSnapshots returns snapshots of information of peers known to the Manager.
type ManagerEvents ¶
type ManagerEvents struct { // Fired when the Manager is instructed to establish a connection to a peer. Connect *events.Event // Fired when the Manager is instructed to disconnect a peer. Disconnect *events.Event // Fired when a peer got connected. Connected *events.Event // Fired when a peer got disconnected. Disconnected *events.Event // Fired when a reconnect is scheduled. ScheduledReconnect *events.Event // Fired when the Manager tries to reconnect to a peer. Reconnecting *events.Event // Fired when a peer has been reconnected. Reconnected *events.Event // Fired when the relation to a peer has been updated. RelationUpdated *events.Event // Fired when the Manager's state changes. StateChange *events.Event // Fired when internal error happens. Error *events.Event }
ManagerEvents are events happening around a Manager. No methods on Manager must be called from within the event handlers.
type ManagerOption ¶
type ManagerOption func(opts *ManagerOptions)
ManagerOption is a function setting a ManagerOptions option.
func WithManagerLogger ¶
func WithManagerLogger(logger *logger.Logger) ManagerOption
WithManagerLogger enables logging within the Manager.
func WithManagerReconnectInterval ¶
func WithManagerReconnectInterval(interval time.Duration, jitter time.Duration) ManagerOption
WithManagerReconnectInterval defines the re-connect interval for peers to which the Manager wants to keep a connection open to.
type ManagerOptions ¶
type ManagerOptions struct { // The logger to use to log events. Logger *logger.Logger // The static reconnect interval. ReconnectInterval time.Duration // The randomized jitter applied to the reconnect interval. ReconnectIntervalJitter time.Duration }
ManagerOptions define options for a Manager.
type ManagerState ¶
type ManagerState string
ManagerState represents the state in which the Manager is in.
const ( // ManagerStateStarted means that the Manager has been started. ManagerStateStarted ManagerState = "started" // ManagerStateStopping means that the Manager is halting its operation. ManagerStateStopping ManagerState = "stopping" // ManagerStateStopped means tha the Manager has halted its operation. ManagerStateStopped ManagerState = "stopped" )
type Peer ¶
type Peer struct { // The ID of the peer. ID peer.ID // The relation to the peer. Relation PeerRelation // The addresses under which the peer was added. Addrs []multiaddr.Multiaddr // The alias of the peer for better recognizing it. Alias string // contains filtered or unexported fields }
Peer is a remote peer in the network.
func NewPeer ¶
func NewPeer(peerID peer.ID, relation PeerRelation, addrs []multiaddr.Multiaddr, alias string) *Peer
NewPeer creates a new Peer.
func (*Peer) InfoSnapshot ¶
func (p *Peer) InfoSnapshot() *PeerInfoSnapshot
InfoSnapshot returns a snapshot of the peer in time of calling Info().
type PeerConfig ¶
type PeerConfig struct { MultiAddress string `json:"multiAddress" koanf:"multiAddress"` Alias string `json:"alias" koanf:"alias"` }
PeerConfig holds the initial information about peers.
type PeerForEachFunc ¶
PeerForEachFunc is used in Manager.ForEach. Returning false indicates to stop looping. This function must not call any methods on Manager.
type PeerInfoSnapshot ¶
type PeerInfoSnapshot struct { // The instance of the peer. Peer *Peer `json:"-"` // The ID of the peer. ID string `json:"address"` // The addresses of the peer. Addresses []multiaddr.Multiaddr `json:"addresses"` // The alias of the peer. Alias string `json:"alias,omitempty"` // The amount of sent packets to the peer. SentPackets uint32 `json:"sentPackets"` // The amount of dropped packets. DroppedSentPackets uint32 `json:"droppedSentPackets"` // Whether the peer is connected. Connected bool `json:"connected"` // The relation to the peer. Relation string `json:"relation"` }
PeerInfoSnapshot acts as a static snapshot of information about a peer.
type PeerOptError ¶
PeerOptError holds a Peer and optionally an error.
type PeerRelation ¶
type PeerRelation string
PeerRelation defines the type of relation to a remote peer.
const ( // PeerRelationKnown is a relation to a peer which most // likely stems from knowing the operator of said peer. // Connections to such peers are subject to automatic reconnections. PeerRelationKnown PeerRelation = "known" // PeerRelationUnknown is a relation to an unknown peer. // Connections to such peers do not have to be retained. PeerRelationUnknown PeerRelation = "unknown" // PeerRelationDiscovered is a relation to a discovered peer. // Connections to such peers do not have to be retained. PeerRelationDiscovered PeerRelation = "discovered" )