libp2p

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 43 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// DefaultPort is the default value for the connection port.
	DefaultPort = 3919
	// DefaultConnMgrHighWater is the default value for the connection managers
	// 'high water' mark
	DefaultConnMgrHighWater = 900

	// DefaultConnMgrLowWater is the default value for the connection managers 'low
	// water' mark
	DefaultConnMgrLowWater = 600

	// DefaultConnMgrGracePeriod is the default value for the connection managers
	// grace period
	DefaultConnMgrGracePeriod = time.Second * 20
)

Defaults from ipfs

View Source
const (
	// FirewallCheckTick is the amount of time between periodic checks of all
	// firewall rules against all peers connected to this one.
	FirewallCheckTick = time.Minute * 10
	// ConnectedPeersCheckTick is the amount of time between periodic checks of
	// the number of connected peers.
	ConnectedPeersCheckTick = time.Minute * 1
)

watchtower constants

View Source
const MaximumDisseminationTime = 90

MaximumDisseminationTime is the maximum dissemination time of messages in topics we are not subscribed to. By default courteous dissemination is disabled and it should be enabled only on selected fast bootstrap nodes. This value should never be higher than the lifetime of libp2p cache (120 sec) to prevent uncontrolled message propagation.

Variables

View Source
var DefaultBootstrapConfig = BootstrapConfig{
	Period:            30 * time.Second,
	ConnectionTimeout: (30 * time.Second) / 3,
}

DefaultBootstrapConfig specifies default sane parameters for bootstrapping.

View Source
var DefaultCurve elliptic.Curve = btcec.S256()

DefaultCurve is the default elliptic curve implementation used in the net/libp2p package. LibP2P network uses the secp256k1 curve and the specific implementation is provided by the btcec package.

View Source
var ErrNotEnoughBootstrapPeers = errors.New("not enough bootstrap peers to bootstrap")

ErrNotEnoughBootstrapPeers signals that we do not have enough bootstrap peers to bootstrap correctly.

Functions

func Bootstrap added in v1.21.0

func Bootstrap(
	id peer.ID,
	host host.Host,
	rt routing.Routing,
	cfg BootstrapConfig,
) (io.Closer, error)

Bootstrap kicks off bootstrapping. This function will periodically check the number of open connections and -- if there are too few -- initiate connections to well-known bootstrap peers. It also kicks off subsystem bootstrapping (i.e. routing).

func Connect

func Connect(
	ctx context.Context,
	config Config,
	operatorPrivateKey *operator.PrivateKey,
	firewall net.Firewall,
	ticker *retransmission.Ticker,
	options ...ConnectOption,
) (net.Provider, error)

Connect connects to a libp2p network based on the provided config. The connection is managed in part by the passed context, and provides access to the functionality specified in the net.Provider interface.

An error is returned if any part of the connection or bootstrap process fails.

func ExtractPeersPublicKeys added in v1.21.0

func ExtractPeersPublicKeys(peerAddresses []string) ([]*operator.PublicKey, error)

ExtractPeersPublicKeys returns a list of operator public keys based on the provided list of peer addresses. Peer addresses must be in the format: <endpoint>/ipfs/<cid>

Types

type BootstrapConfig added in v1.21.0

type BootstrapConfig struct {
	// Period governs the periodic interval at which the node will
	// attempt to bootstrap. The bootstrap process is not very expensive, so
	// this threshold can afford to be small (<=30s).
	Period time.Duration

	// ConnectionTimeout determines how long to wait for a bootstrap
	// connection attempt before cancelling it.
	ConnectionTimeout time.Duration

	// BootstrapPeers is a function that returns a set of bootstrap peers
	// for the bootstrap process to use. This makes it possible for clients
	// to control the peers the process uses at any moment.
	BootstrapPeers func() []peer.AddrInfo
}

BootstrapConfig specifies parameters used in the network bootstrapping process.

type Config

type Config struct {
	Bootstrap          bool
	Peers              []string
	Port               int
	AnnouncedAddresses []string
	DisseminationTime  int // TODO: Convert to time.Duration
}

Config defines the configuration for the libp2p network provider.

type ConnectOption

type ConnectOption func(options *ConnectOptions)

ConnectOption allows to set an options used by libp2p.

func WithRoutingTableRefreshPeriod

func WithRoutingTableRefreshPeriod(period time.Duration) ConnectOption

WithRoutingTableRefreshPeriod set a refresh period of the routing table.

type ConnectOptions

type ConnectOptions struct {
	RoutingTableRefreshPeriod time.Duration
}

ConnectOptions allows to set various options used by libp2p.

Jump to

Keyboard shortcuts

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