pstoremgr

package
v0.0.0-...-a52a6fd Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 15 Imported by: 0

Documentation

Overview

Package pstoremgr provides a Manager that simplifies handling addition, listing and removal of cluster peer multiaddresses from the libp2p Host. This includes resolving DNS addresses, decapsulating and encapsulating the /p2p/ (/ipfs/) protocol as needed, listing, saving and loading addresses.

Index

Constants

This section is empty.

Variables

View Source
var (
	DNSTimeout     = 5 * time.Second
	ConnectTimeout = 5 * time.Second
)

Timeouts for network operations triggered by the Manager.

View Source
var PriorityTag = "cluster"

PriorityTag is used to attach metadata to peers in the peerstore so they can be sorted.

Functions

This section is empty.

Types

type Manager

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

Manager provides utilities for handling cluster peer addresses and storing them in a libp2p Host peerstore.

func New

func New(ctx context.Context, h host.Host, peerstorePath string) *Manager

New creates a Manager with the given libp2p Host and peerstorePath. The path indicates the place to persist and read peer addresses from. If empty, these operations (LoadPeerstore, SavePeerstore) will no-op.

func (*Manager) Bootstrap

func (pm *Manager) Bootstrap(count int) []peer.ID

Bootstrap attempts to get up to "count" connected peers by trying those in the peerstore in priority order. It returns the list of peers it managed to connect to.

func (*Manager) HandlePeerFound

func (pm *Manager) HandlePeerFound(p peer.AddrInfo)

HandlePeerFound implements the Notifee interface for discovery (mdns).

func (*Manager) ImportPeer

func (pm *Manager) ImportPeer(addr ma.Multiaddr, connect bool, ttl time.Duration) (peer.ID, error)

ImportPeer adds a new peer address to the host's peerstore, optionally dialing to it. The address is expected to include the /p2p/<peerID> protocol part or to be a /dnsaddr/multiaddress Peers are added with the given ttl.

func (*Manager) ImportPeers

func (pm *Manager) ImportPeers(addrs []ma.Multiaddr, connect bool, ttl time.Duration) error

ImportPeers calls ImportPeer for every address in the given slice, using the given connect parameter. Peers are tagged with priority as given by their position in the list.

func (*Manager) ImportPeersFromPeerstore

func (pm *Manager) ImportPeersFromPeerstore(connect bool, ttl time.Duration) error

ImportPeersFromPeerstore reads the peerstore file and calls ImportPeers with the addresses obtained from it.

func (*Manager) LoadPeerstore

func (pm *Manager) LoadPeerstore() (addrs []ma.Multiaddr)

LoadPeerstore parses the peerstore file and returns the list of addresses read from it.

func (*Manager) PeerInfos

func (pm *Manager) PeerInfos(peers []peer.ID) []peer.AddrInfo

PeerInfos returns a slice of peerinfos for the given set of peers in order of priority. For peers for which we know DNS multiaddresses, we only include those. Otherwise, the AddrInfo includes all the multiaddresses known for that peer. Peers without addresses are not included.

func (*Manager) RmPeer

func (pm *Manager) RmPeer(pid peer.ID) error

RmPeer clear all addresses for a given peer ID from the host's peerstore.

func (*Manager) SavePeerstore

func (pm *Manager) SavePeerstore(pinfos []peer.AddrInfo) error

SavePeerstore stores a slice of multiaddresses in the peerstore file, one per line.

func (*Manager) SavePeerstoreForPeers

func (pm *Manager) SavePeerstoreForPeers(peers []peer.ID) error

SavePeerstoreForPeers calls PeerInfos and then saves the peerstore file using the result.

func (*Manager) SetPriority

func (pm *Manager) SetPriority(pid peer.ID, prio int) error

SetPriority attaches a priority to a peer. 0 means more priority than 1. 1 means more priority than 2 etc.

Jump to

Keyboard shortcuts

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