helpers

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultConnMgrHighWater   = 400
	DefaultConnMgrLowWater    = 100
	DefaultConnMgrGracePeriod = 2 * time.Minute
	DefaultDialPeerTimeout    = 3 * time.Second
)
View Source
var Libp2pLitePrivateNodeOptions = []libp2p.Option{
	func(cfg *p2pConfig.Config) error {
		mgr, err := connmgr.NewConnManager(DefaultConnMgrLowWater, DefaultConnMgrHighWater, connmgr.WithGracePeriod(DefaultConnMgrGracePeriod))
		if err != nil {
			return err
		}

		return libp2p.ConnectionManager(mgr)(cfg)
	},
	libp2p.EnableHolePunching(),
	libp2p.NATPortMap(),
}
View Source
var Libp2pOptionsBase = []libp2p.Option{
	libp2p.Ping(true),
	libp2p.EnableRelay(),
	libp2p.Security(libp2ptls.ID, libp2ptls.New),
	libp2p.NoTransports,
	libp2p.Transport(tcp.NewTCPTransport),
	libp2p.DefaultMuxers,
}
View Source
var Libp2pOptionsFullNode = []libp2p.Option{
	libp2p.EnableNATService(),
	libp2p.EnableRelayService(),
	func(cfg *p2pConfig.Config) error {
		mgr, err := connmgr.NewConnManager(DefaultConnMgrLowWater*4, DefaultConnMgrHighWater*8, connmgr.WithGracePeriod(DefaultConnMgrGracePeriod))
		if err != nil {
			return err
		}

		return libp2p.ConnectionManager(mgr)(cfg)
	},
}

Libp2pOptionsExtra provides some useful libp2p options to create a fully featured libp2p host. It can be used with SetupLibp2p.

View Source
var Libp2pOptionsLitePublicNode = []libp2p.Option{
	func(cfg *p2pConfig.Config) error {
		mgr, err := connmgr.NewConnManager(DefaultConnMgrLowWater, DefaultConnMgrHighWater, connmgr.WithGracePeriod(DefaultConnMgrGracePeriod))
		if err != nil {
			return err
		}

		return libp2p.ConnectionManager(mgr)(cfg)
	},
}
View Source
var Libp2pOptionsPublicNode = []libp2p.Option{
	libp2p.EnableNATService(),
	libp2p.EnableRelayService(),
	func(cfg *p2pConfig.Config) error {
		mgr, err := connmgr.NewConnManager(DefaultConnMgrLowWater*2, DefaultConnMgrHighWater*4, connmgr.WithGracePeriod(DefaultConnMgrGracePeriod))
		if err != nil {
			return err
		}

		return libp2p.ConnectionManager(mgr)(cfg)
	},
}
View Source
var Libp2pSimpleNodeOptions = []libp2p.Option{
	func(cfg *p2pConfig.Config) error {
		mgr, err := connmgr.NewConnManager(DefaultConnMgrLowWater, DefaultConnMgrHighWater, connmgr.WithGracePeriod(DefaultConnMgrGracePeriod))
		if err != nil {
			return err
		}

		return libp2p.ConnectionManager(mgr)(cfg)
	},
}

Functions

func Bootstrap

func Bootstrap(ctx context.Context, h host.Host, dht routing.Routing, peers []peer.AddrInfo) ([]peer.AddrInfo, error)

Bootstrap is an optional helper to connect to the given peers and bootstrap the Peer DHT (and Bitswap). This is a best-effort function. Errors are only logged and a warning is printed when less than half of the given peers could be contacted. It is fine to pass a list where some peers will not be reachable.

func NewDatastore

func NewDatastore(path string) (datastore.Batching, error)

func SetupLibp2p

func SetupLibp2p(
	ctx context.Context,
	hostKey crypto.PrivKey,
	secret pnet.PSK,
	listenAddrs []string,
	ds datastore.Batching,
	bootstrapPeerFunc func() []peer.AddrInfo,
	opts ...libp2p.Option,
) (host.Host, routing.Routing, error)

SetupLibp2p returns a routed host and DHT instances that can be used to easily create a ipfslite Peer. You may consider to use Peer.Bootstrap() after creating the IPFS-Lite Peer to connect to other peers. When the datastore parameter is nil, the DHT will use an in-memory datastore, so all provider records are lost on program shutdown.

Additional libp2p options can be passed. Note that the Identity, ListenAddrs and PrivateNetwork options will be setup automatically. Interesting options to pass: NATPortMap() EnableAutoRelay(), libp2p.EnableNATService(), DisableRelay(), ConnectionManager(...)... see https://godoc.org/github.com/libp2p/go-libp2p#Option for more info.

The secret should be a 32-byte pre-shared-key byte slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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