pstoremgr

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2018 License: MIT Imports: 13 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     = 2 * time.Second
	ConnectTimeout = 10 * time.Second
)

Timeouts for network operations triggered by the Manager

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(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) ImportPeer

func (pm *Manager) ImportPeer(addr ma.Multiaddr, connect bool) error

ImportPeer adds a new peer address to the host's peerstore, optionally dialing to it. It will resolve any DNS multiaddresses before adding them. The address is expected to include the /ipfs/<peerID> protocol part.

func (*Manager) ImportPeers

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

ImportPeers calls ImportPeer for every address in the given slice, using the given connect parameter.

func (*Manager) ImportPeersFromPeerstore

func (pm *Manager) ImportPeersFromPeerstore(connect bool) 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) PeersAddresses

func (pm *Manager) PeersAddresses(peers []peer.ID) []ma.Multiaddr

PeersAddresses returns the list of multiaddresses (encapsulating the /ipfs/<peerID> part) for the given set of peers. For peers for which we know DNS multiaddresses, we only return those. Otherwise, we return all the multiaddresses known for that peer.

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(addrs []ma.Multiaddr)

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

func (*Manager) SavePeerstoreForPeers

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

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

Jump to

Keyboard shortcuts

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