p2pnode

package
v0.2.3-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: GPL-3.0 Imports: 37 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"
	// MinSecondaryApprovalExpiredHeight defines the min expired height for secondary
	// approval
	MinSecondaryApprovalExpiredHeight = 900
)
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 = 12

ResponseChannelSize defines the approval response size

Variables

This section is empty.

Functions

func MakeBootstrapMultiaddr

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

MakeBootstrapMultiaddr new bootstrap nodes multi addr.

func MakeMultiaddr

func MakeMultiaddr(address string) (ma.Multiaddr, error)

MakeMultiaddr new multi addr by address

func VerifySignature

func VerifySignature(spOpAddr string, signBytes []byte, sig []byte) error

VerifySignature verifier whether the signer address and signed msg match

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

func (*ApprovalProtocol) ComputeApprovalExpiredHeight

func (a *ApprovalProtocol) ComputeApprovalExpiredHeight(task coretask.ApprovalReplicatePieceTask) (uint64, error)

type Node

type Node struct {
	// 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(baseApp *gfspapp.GfSpBaseApp, privateKey string, address string,
	bootstrap []string, pingPeriod int, secondaryApprovalExpiredHeight uint64,
	p2pAntAddress string) (*Node, error)

NewNode return an instance of Node

func (*Node) Bootstrap

func (n *Node) Bootstrap() []string

func (*Node) GetSecondaryReplicatePieceApproval

func (n *Node) GetSecondaryReplicatePieceApproval(
	ctx context.Context,
	task coretask.ApprovalReplicatePieceTask,
	expectedAccept int, timeout int64) (
	accept []coretask.ApprovalReplicatePieceTask,
	err error)

GetSecondaryReplicatePieceApproval 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 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

Jump to

Keyboard shortcuts

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