p2pgo

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: Apache-2.0 Imports: 7 Imported by: 2

README

p2p-go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConnectionManager = func(cfg *Config) error {
	mgr, err := connmgr.NewConnManager(160, 192)
	if err != nil {
		return err
	}

	return cfg.Apply(ConnectionManager(mgr))
}

DefaultConnectionManager creates a default connection manager

View Source
var DefaultListenAddrs = func(cfg *Config) error {
	ip := "0.0.0.0"
	port := 80
	return cfg.Apply(ListenAddrStrings(ip, port))
}

DefaultListenAddrs configures libp2p to use default listen address.

View Source
var DefaultWorkspace = func(cfg *Config) error {
	workspace, err := os.Getwd()
	if err != nil {
		return err
	}
	return cfg.Apply(Workspace(workspace))
}

DefaultListenAddrs configures libp2p to use default listen address.

Functions

func New

func New(privatekeyPath string, opts ...Option) (core.P2P, error)

New constructs a new libp2p node with the given options, falling back on reasonable defaults. The defaults are:

- If no transport and listen addresses are provided, the node listens to the multiaddresses "/ip4/0.0.0.0/tcp/0" and "/ip6/::/tcp/0";

To stop/shutdown the returned p2p node, the user needs to cancel the passed context and call `Close` on the returned Host.

func NewWithoutDefaults

func NewWithoutDefaults(privatekeyPath string, opts ...Option) (core.P2P, error)

NewWithoutDefaults constructs a new libp2p node with the given options but *without* falling back on reasonable defaults.

Warning: This function should not be considered a stable interface. We may choose to add required services at any time and, by using this function, you opt-out of any defaults we may provide.

Types

type Config

type Config = config.Config

Config describes a set of settings for a p2p node.

type Option

type Option = config.Option

Option is a p2p config option that can be given to the p2p constructor

var FallbackDefaults Option = func(cfg *Config) error {
	for _, def := range defaults {
		if !def.fallback(cfg) {
			continue
		}
		if err := cfg.Apply(def.opt); err != nil {
			return err
		}
	}
	return nil
}

FallbackDefaults applies default options to the libp2p node if and only if no other relevant options have been applied. will be appended to the options passed into New.

func ConnectionManager

func ConnectionManager(connman connmgr.ConnManager) Option

ConnectionManager configures libp2p to use the given connection manager.

The current "standard" connection manager lives in github.com/libp2p/go-libp2p-connmgr. See https://pkg.go.dev/github.com/libp2p/go-libp2p-connmgr?utm_source=godoc#NewConnManager.

func ListenAddrStrings

func ListenAddrStrings(ip string, port int) Option

ListenAddrStrings configures libp2p to listen on the given (unparsed) addresses.

func ListenAddrs

func ListenAddrs(addrs ma.Multiaddr) Option

ListenAddrs configures libp2p to listen on the given addresses.

func Workspace

func Workspace(workspace string) Option

ListenAddrs configures libp2p to listen on the given addresses.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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