p2p

package
v0.1.2-fix-6 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PingPeriodMin defines the min value that the period of sending ping request
	PingPeriodMin = 1
	// DailTimeout defines default value that the timeout of dail other p2p node
	DailTimeout = 1
	// DefaultDataPath defines default value that the path of peer store
	DefaultDataPath = "./data"
	// P2PNode defines the p2p protocol node name
	P2PNode = "p2p_protocol_node"
)
View Source
const (
	// PeerFailureMax defines the threshold of setting node to fail
	PeerFailureMax = 1
	// PrunePeersNumberMax defines the threshold to trigger the prune p2p node
	PrunePeersNumberMax = 10
	// PeerSpUnspecified defines default sp operator address
	PeerSpUnspecified = "PEER_SP_UNSPECIFIED"
)
View Source
const (
	PingProtocol = "/ping/0.0.1"
	PongProtocol = "/pong/0.0.1"
)
View Source
const GetApprovalRequest = "/approval/request/0.0.1"

pattern: /protocol-name/request-or-response-message/version

View Source
const GetApprovalResponse = "/approval/response/0.0.1"
View Source
const ResponseChannelSize = 9

ResponseChannelSize defines the approval response size

View Source
const ValidApprovalDuration = "1h"

ValidApprovalDuration defines the default approval validity period

Variables

This section is empty.

Functions

func MakeBootstrapMultiaddr

func MakeBootstrapMultiaddr(bootstrap []string) (peersID []peer.ID, addrs []ma.Multiaddr, err error)

MakeBootstrapMultiaddr new bootstrap nodes multi addr

func MakeMultiaddr

func MakeMultiaddr(host string, port int) (ma.Multiaddr, error)

MakeMultiaddr new multi addr by address

Types

type ApprovalProtocol

type ApprovalProtocol struct {
	// contains filtered or unexported fields
}

ApprovalProtocol define the approval protocol and callback maintains requests for getting approvals in memory

func NewApprovalProtocol

func NewApprovalProtocol(host *Node) *ApprovalProtocol

NewApprovalProtocol return an instance of ApprovalProtocol

type Node

type Node struct {
	SpOperatorAddress string
	// contains filtered or unexported fields
}

Node defines the p2p protocol node, encapsulates the go-lib.p2p p2p protocol message interactive security based on storage provider operator private-public key pair signature, use leveldb as underlying DB.

func NewNode

func NewNode(config *NodeConfig, SPAddr string, signer *signerclient.SignerClient) (*Node, error)

NewNode return an instance of Node.

func (*Node) GetApproval

func (n *Node) GetApproval(object *storagetypes.ObjectInfo, expectedAccept int, timeout int64) (
	accept map[string]*types.GetApprovalResponse, refuse map[string]*types.GetApprovalResponse, err error)

GetApproval broadcast get approval request and blocking goroutine until timeout or collect expect accept approval response number

func (*Node) Name

func (n *Node) Name() string

Name return the p2p protocol node name

func (*Node) PeersProvider

func (n *Node) PeersProvider() *PeerProvider

PeersProvider returns the p2p peers provider

func (*Node) Start

func (n *Node) Start(ctx context.Context) error

Start runs background task that trigger broadcast ping request

func (*Node) Stop

func (n *Node) Stop(ctx context.Context) error

Stop recycle the resources and termination background goroutine

type NodeConfig

type NodeConfig struct {
	// ListenAddress defines the p2p listen address, used to make multiaddr
	ListenAddress string
	// P2PPrivateKey defines the p2p node private key, only support Secp256k1
	// if default value, creates random private-public key pairs
	// TODO::support more crypto algorithm for generating and verifying private-public key pairs
	P2PPrivateKey string
	// Bootstrap defines Bootstrap p2p node, cannot be empty
	// format: [node_id1@ip1:port1, node_id2@ip1:port2]
	Bootstrap []string
	// PingPeriod defines the period of ping other p2p nodes
	PingPeriod int
}

NodeConfig defines the p2p node config

func (*NodeConfig) ParseConfig added in v0.2.0

func (cfg *NodeConfig) ParseConfig() (privKey crypto.PrivKey, hostAddr ma.Multiaddr, bootstrapIDs []peer.ID, bootstrapAddrs []ma.Multiaddr, err error)

ParseConfig parsers the configuration into a format that go-libp2p can use

type Peer

type Peer struct {
	// contains filtered or unexported fields
}

Peer defines the peer info in memory

func (*Peer) Fail

func (p *Peer) Fail() bool

Fail return the indicator whether in fail state

func (*Peer) ID

func (p *Peer) ID() peer.ID

ID return the peer id

func (*Peer) IncrFail

func (p *Peer) IncrFail() int

IncrFail increase peer's fail counter and update last

func (*Peer) Reset

func (p *Peer) Reset()

Reset peer's fail counter and update last

func (*Peer) SP

func (p *Peer) SP() string

SP return the storage provider operator address of peer

type PeerProvider

type PeerProvider struct {
	// contains filtered or unexported fields
}

PeerProvider implements the pruning function of permanent nodes. Ping service only add permanent node, for zombie nodes, PeerProvider's pruning strategy takes into account the information of the storage provider dimension, and uses a very conservative pruning strategy. Nodes are only pruned if there are enough backups and multiple failed interactions, can try to keep each storage provider with enough nodes to try to connect, so that each sp has an equal opportunity to receive requests

func NewPeerProvider

func NewPeerProvider(store peerstore.Peerstore) *PeerProvider

NewPeerProvider return an instance of PeerProvider

func (*PeerProvider) AddPeer

func (pr *PeerProvider) AddPeer(peerID peer.ID, sp string, addr ma.Multiaddr)

AddPeer add a new peer or reset an old peer

func (*PeerProvider) DeletePeer

func (pr *PeerProvider) DeletePeer(peerID peer.ID)

DeletePeer increase the peer's fail counter and trigger prunePeers

func (*PeerProvider) UpdateSp

func (pr *PeerProvider) UpdateSp(SPs []string)

UpdateSp change the storage provider

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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