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.
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.
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
To get the package use the standard:
go get -u "github.com/CESSProject/p2p-go"
Please refer to https://pkg.go.dev/github.com/CESSProject/p2p-go
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)
}
}
}
Licensed under Apache 2.0