Categorygithub.com/CESSProject/p2p-go
modulepackage
0.4.0
Repository: https://github.com/cessproject/p2p-go.git
Documentation: pkg.go.dev

# README

Go p2p library for cess distributed storage system

GitHub license Go Reference build&test 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 system bugs or you have a better suggestions, please send an email to [email protected] or join CESS discord to communicate with us.

📢 Announcement

CESS test network rpc endpoints

wss://testnet-rpc0.cess.cloud/ws/
wss://testnet-rpc1.cess.cloud/ws/
wss://testnet-rpc2.cess.cloud/ws/

CESS test network bootstrap node

_dnsaddr.boot-kldr-testnet.cess.cloud

🏗 Usage

To get the package use the standard:

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

📖 Documentation

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

💡 Examples

The following code demonstrates how to create a p2p node and perform node discovery:

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"strconv"
	"time"

	p2pgo "github.com/CESSProject/p2p-go"
	"github.com/CESSProject/p2p-go/config"
	"github.com/CESSProject/p2p-go/core"
	"github.com/CESSProject/p2p-go/out"
	"golang.org/x/time/rate"
)

func main() {
	var ok bool
	var node = &core.Node{}
	ctx := context.Background()
	port, err := strconv.Atoi(os.Args[1])
	if err != nil {
		fmt.Println("please enter os.Args[1] as port")
		os.Exit(1)
	}

	h1, err := p2pgo.New(
		ctx,
		p2pgo.PrivatekeyFile(".private1"),
		p2pgo.ListenPort(port),
		p2pgo.Workspace("."),
		p2pgo.BootPeers([]string{
			"_dnsaddr.boot-kldr-testnet.cess.cloud",
		}),
		p2pgo.ProtocolPrefix(config.TestnetProtocolPrefix),
	)
	if err != nil {
		panic(err)
	}
	defer h1.Close()

	node, ok = h1.(*core.Node)
	if !ok {
		panic(err)
	}

	fmt.Println(node.Addrs(), node.ID())

	node.RouteTableFindPeers(0)

	tick := time.NewTicker(time.Second * 30)
	defer tick.Stop()

	var r = rate.Every(time.Second * 3)
	var limit = rate.NewLimiter(r, 1)

	for {
		select {
		case peer, ok := <-node.GetDiscoveredPeers():
			if !ok {
				break
			}
			if limit.Allow() {
				tick.Reset(time.Second * 30)
			}
			if len(peer.Responses) == 0 {
				break
			}
			for _, v := range peer.Responses {
				log.Println("found: ", v.ID.Pretty(), v.Addrs)
			}
		case <-tick.C:
			node.RouteTableFindPeers(0)
		}
	}
}

License

Licensed under Apache 2.0

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

BootPeers configuration bootstrap nodes.
BucketSize configuration bucket size.
ListenPort configuration listening port.
MaxConnection configuration max connection.
New constructs a new libp2p node with the given options, falling back on reasonable defaults.
NewWithoutDefaults constructs a new libp2p node with the given options but *without* falling back on reasonable defaults.
PrivatekeyFile configuration privatekey file.
PrivatekeyFile configuration privatekey file.
PrivatekeyFile configuration privatekey file.
Version configuration version.
Workspace configuration working directory.

# Variables

DefaultWorkSpace configures libp2p to use default work space.
DefaultConnectionManager creates a default connection manager.
DefaultListenPort configures libp2p to use default port.
DefaultWorkSpace configures libp2p to use default work space.
FallbackDefaults applies default options to the libp2p node if and only if no other relevant options have been applied.

# Type aliases

Config describes a set of settings for a p2p peer.
Option is a p2p config option that can be given to the p2p constructor.