Documentation ¶
Index ¶
- Constants
- func MakeBootstrapMultiaddr(bootstrap []string) (peersID []peer.ID, addrs []ma.Multiaddr, err error)
- func MakeMultiaddr(host string, port int) (ma.Multiaddr, error)
- type ApprovalProtocol
- type Node
- func (n *Node) GetApproval(object *storagetypes.ObjectInfo, expectedAccept int, timeout int64) (accept map[string]*types.GetApprovalResponse, ...)
- func (n *Node) Name() string
- func (n *Node) PeersProvider() *PeerProvider
- func (n *Node) Start(ctx context.Context) error
- func (n *Node) Stop(ctx context.Context) error
- type NodeConfig
- type Peer
- type PeerProvider
Constants ¶
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" )
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" )
const ( PingProtocol = "/ping/0.0.1" PongProtocol = "/pong/0.0.1" )
const GetApprovalRequest = "/approval/request/0.0.1"
pattern: /protocol-name/request-or-response-message/version
const GetApprovalResponse = "/approval/response/0.0.1"
const ResponseChannelSize = 9
ResponseChannelSize defines the approval response size
const ValidApprovalDuration = "1h"
ValidApprovalDuration defines the default approval validity period
Variables ¶
This section is empty.
Functions ¶
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) PeersProvider ¶
func (n *Node) PeersProvider() *PeerProvider
PeersProvider returns the p2p peers provider
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
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer defines the peer info in memory
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) 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