p2pgo

package module
v0.0.24 Latest Latest
Warning

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

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

README

Go p2p library for cess distributed storage system

GitHub license Go Reference Go Report Card

The go p2p library implementation of the CESS distributed storage network, which is customized based on go-libp2p, has many advantages, and at the same time abandons the bandwidth and space redundancy caused by multiple file backups, making nodes more focused on storage allocation Give yourself data to make it more in line with the needs of the CESS network.

Reporting a Vulnerability

If you find out any vulnerability, Please send an email to frode@cess.one, we are happy to communicate with you.

Installation

To get the package use the standard:

go get -u "github.com/CESSProject/p2p-go"

Using Go modules is recommended.

Documentation

Please refer to https://pkg.go.dev/github.com/CESSProject/p2p-go

Examples

Please refer to https://github.com/CESSProject/p2p-go/tree/main/examples

Usage

The following is an example of creating an p2p host:

p2phost, err := p2pgo.New(
    privatekeyPath,
    p2pgo.ListenAddrStrings(addr, port), // regular tcp connections
    p2pgo.Workspace(workspace),
)

Creating a p2p host requires you to configure some information, you can refer to options.go.

License

Licensed under Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBootPeers = func(cfg *Config) error {
	defaultBotPeers := []string{}

	return cfg.Apply(BootPeers(defaultBotPeers))
}

DefaultConnectionManager creates a default connection manager

View Source
var DefaultConnectionManager = func(cfg *Config) error {
	mgr, err := connmgr.NewConnManager(100, 1000, connmgr.WithGracePeriod(time.Minute))
	if err != nil {
		return err
	}

	return cfg.Apply(ConnectionManager(mgr))
}

DefaultConnectionManager creates a default connection manager

View Source
var DefaultDhtProtocolVersion = func(cfg *Config) error {
	defaultDhtProtocolVersion := "/kldr/kad/1.0"
	return cfg.Apply(DhtProtocolVersion(defaultDhtProtocolVersion))
}

DefaultConnectionManager creates a default connection manager

View Source
var DefaultListenPort = func(cfg *Config) error {
	port := 4001
	return cfg.Apply(ListenPort(port))
}

DefaultListenAddrs configures libp2p to use default listen address.

View Source
var DefaultProtocolVersion = func(cfg *Config) error {
	defaultProtocolVersion := "/kldr/1.0"
	return cfg.Apply(ProtocolVersion(defaultProtocolVersion))
}

DefaultConnectionManager creates a default connection manager

Functions

func New

func New(ctx context.Context, 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(ctx context.Context, 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 BootPeers added in v0.0.8

func BootPeers(bootpeers []string) Option

BootPeers configures bootstrap nodes

func ConnectionManager

func ConnectionManager(connman connmgr.ConnManager) Option

ConnectionManager configures libp2p to use the given connection manager

func DhtProtocolVersion added in v0.0.24

func DhtProtocolVersion(dhtProtocolVersion string) Option

BootPeers configures bootstrap nodes

func ListenPort added in v0.0.24

func ListenPort(port int) Option

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

func ProtocolVersion added in v0.0.24

func ProtocolVersion(protocolVersion string) Option

BootPeers configures bootstrap nodes

func Workspace

func Workspace(workspace string) Option

Workspace configuration working directory

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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