p2pserver

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: LGPL-3.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	SYNC_MAX_HEADER_FORWARD_SIZE = 5000       //keep CurrentHeaderHeight - CurrentBlockHeight <= SYNC_MAX_HEADER_FORWARD_SIZE
	SYNC_MAX_FLIGHT_HEADER_SIZE  = 1          //Number of headers on flight
	SYNC_MAX_FLIGHT_BLOCK_SIZE   = 50         //Number of blocks on flight
	SYNC_MAX_BLOCK_CACHE_SIZE    = 500        //Cache size of block wait to commit to ledger
	SYNC_HEADER_REQUEST_TIMEOUT  = 2          //s, Request header timeout time. If header haven't receive after SYNC_HEADER_REQUEST_TIMEOUT second, retry
	SYNC_BLOCK_REQUEST_TIMEOUT   = 2          //s, Request block timeout time. If block haven't received after SYNC_BLOCK_REQUEST_TIMEOUT second, retry
	SYNC_NEXT_BLOCK_TIMES        = 3          //Request times of next height block
	SYNC_NEXT_BLOCKS_HEIGHT      = 2          //for current block height plus next
	SYNC_NODE_RECORD_SPEED_CNT   = 3          //Record speed count for accuracy
	SYNC_NODE_RECORD_TIME_CNT    = 3          //Record request time  for accuracy
	SYNC_NODE_SPEED_INIT         = 100 * 1024 //Init a big speed (100MB/s) for every node in first round
	SYNC_MAX_ERROR_RESP_TIMES    = 5          //Max error headers/blocks response times, if reaches, delete it
	SYNC_MAX_HEIGHT_OFFSET       = 5          //Offset of the max height and current height
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockInfo added in v1.0.2

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

BlockInfo is used for saving block information in cache

type BlockSyncMgr

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

BlockSyncMgr is the manager class to deal with block sync

func NewBlockSyncMgr

func NewBlockSyncMgr(server *P2PServer) *BlockSyncMgr

NewBlockSyncMgr return a BlockSyncMgr instance

func (*BlockSyncMgr) Close

func (this *BlockSyncMgr) Close()

Stop to sync

func (*BlockSyncMgr) OnAddNode

func (this *BlockSyncMgr) OnAddNode(nodeId uint64)

OnAddNode to node list when a new node added

func (*BlockSyncMgr) OnBlockReceive

func (this *BlockSyncMgr) OnBlockReceive(fromID uint64, blockSize uint32, block *types.Block,
	merkleRoot common.Uint256)

OnBlockReceive receive block from net

func (*BlockSyncMgr) OnDelNode

func (this *BlockSyncMgr) OnDelNode(nodeId uint64)

OnDelNode remove from node list. When the node disconnect

func (*BlockSyncMgr) OnHeaderReceive

func (this *BlockSyncMgr) OnHeaderReceive(fromID uint64, headers []*types.Header)

OnHeaderReceive receive header from net

func (*BlockSyncMgr) Start

func (this *BlockSyncMgr) Start()

Start to sync

type NodeWeight added in v1.0.2

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

NodeWeight record some params of node, using for sort

func NewNodeWeight added in v1.0.2

func NewNodeWeight(id uint64) *NodeWeight

NewNodeWeight new a nodeweight

func (*NodeWeight) AddErrorRespCnt added in v1.0.2

func (this *NodeWeight) AddErrorRespCnt()

AddErrorRespCnt incre receive error header/block count

func (*NodeWeight) AddTimeoutCnt added in v1.0.2

func (this *NodeWeight) AddTimeoutCnt()

AddTimeoutCnt incre timeout count

func (*NodeWeight) AppendNewReqtime added in v1.0.2

func (this *NodeWeight) AppendNewReqtime()

AppendNewReqTime append new request time

func (*NodeWeight) AppendNewSpeed added in v1.0.2

func (this *NodeWeight) AppendNewSpeed(s float32)

addNewSpeed apend the new speed to tail, remove the oldest one

func (*NodeWeight) GetErrorRespCnt added in v1.0.2

func (this *NodeWeight) GetErrorRespCnt() int

GetErrorRespCnt get the error response count

func (*NodeWeight) Weight added in v1.0.2

func (this *NodeWeight) Weight() float32

Weight calculate node's weight for sort. Highest weight node will be accessed first for next request.

type NodeWeights added in v1.0.2

type NodeWeights []*NodeWeight

NodeWeights implement sorting

func (NodeWeights) Len added in v1.0.2

func (nws NodeWeights) Len() int

func (NodeWeights) Less added in v1.0.2

func (nws NodeWeights) Less(i, j int) bool

func (NodeWeights) Swap added in v1.0.2

func (nws NodeWeights) Swap(i, j int)

type P2PServer

type P2PServer struct {
	ReconnectAddrs
	// contains filtered or unexported fields
}

P2PServer control all network activities

func NewServer

func NewServer() *P2PServer

NewServer return a new p2pserver according to the pubkey

func (*P2PServer) GetConnectionCnt

func (this *P2PServer) GetConnectionCnt() uint32

GetConnectionCnt return the established connect count

func (*P2PServer) GetConnectionState

func (this *P2PServer) GetConnectionState() uint32

Todo: remove it if no use

func (*P2PServer) GetID

func (this *P2PServer) GetID() uint64

GetID returns local node id

func (*P2PServer) GetNeighborAddrs

func (this *P2PServer) GetNeighborAddrs() []common.PeerAddr

GetNeighborAddrs return all nbr`s address

func (*P2PServer) GetNetWork

func (this *P2PServer) GetNetWork() p2pnet.P2P

GetNetWork returns the low level netserver

func (*P2PServer) GetPID

func (this *P2PServer) GetPID() *evtActor.PID

GetPID returns p2p actor

func (*P2PServer) GetPort

func (this *P2PServer) GetPort() (uint16, uint16)

GetPort return two network port

func (*P2PServer) GetTime

func (this *P2PServer) GetTime() int64

GetTime return lastet contact time

func (*P2PServer) GetVersion

func (this *P2PServer) GetVersion() uint32

GetVersion return self version

func (*P2PServer) OnAddNode

func (this *P2PServer) OnAddNode(id uint64)

OnAddNode adds the peer id to the block sync mgr

func (*P2PServer) OnBlockReceive

func (this *P2PServer) OnBlockReceive(fromID uint64, blockSize uint32,
	block *types.Block, merkleRoot comm.Uint256)

OnBlockReceive adds the block from network

func (*P2PServer) OnDelNode

func (this *P2PServer) OnDelNode(id uint64)

OnDelNode removes the peer id from the block sync mgr

func (*P2PServer) OnHeaderReceive

func (this *P2PServer) OnHeaderReceive(fromID uint64, headers []*types.Header)

OnHeaderReceive adds the header list from network

func (*P2PServer) Send

func (this *P2PServer) Send(p *peer.Peer, msg msgtypes.Message,
	isConsensus bool) error

Send tranfer buffer to peer

func (*P2PServer) SetPID

func (this *P2PServer) SetPID(pid *evtActor.PID)

SetPID sets p2p actor

func (*P2PServer) Start

func (this *P2PServer) Start() error

Start create all services

func (*P2PServer) Stop

func (this *P2PServer) Stop()

Stop halt all service by send signal to channels

func (*P2PServer) WaitForPeersStart

func (this *P2PServer) WaitForPeersStart()

WaitForPeersStart check whether enough peer linked in loop

func (*P2PServer) WaitForSyncBlkFinish

func (this *P2PServer) WaitForSyncBlkFinish()

WaitForSyncBlkFinish compare the height of self and remote peer in loop

func (*P2PServer) Xmit

func (this *P2PServer) Xmit(message interface{}) error

Xmit called by other module to broadcast msg

type ReconnectAddrs

type ReconnectAddrs struct {
	sync.RWMutex
	RetryAddrs map[string]int
}

ReconnectAddrs contain addr need to reconnect

type SyncFlightInfo

type SyncFlightInfo struct {
	Height uint32 //BlockHeight of HeaderHeight
	// contains filtered or unexported fields
}

SyncFlightInfo record the info of fight object(header or block)

func NewSyncFlightInfo

func NewSyncFlightInfo(height uint32, nodeId uint64) *SyncFlightInfo

NewSyncFlightInfo return a new SyncFlightInfo instance

func (*SyncFlightInfo) GetFailedTimes

func (this *SyncFlightInfo) GetFailedTimes(nodeId uint64) int

GetFailedTimes return failed times of a node

func (*SyncFlightInfo) GetNodeId

func (this *SyncFlightInfo) GetNodeId() uint64

GetNodeId return current node id for sending msg

func (*SyncFlightInfo) GetStartTime

func (this *SyncFlightInfo) GetStartTime() time.Time

GetStartTime return the start time of request

func (*SyncFlightInfo) GetTotalFailedTimes

func (this *SyncFlightInfo) GetTotalFailedTimes() int

GetTotalFailedTimes return the total failed times of request

func (*SyncFlightInfo) MarkFailedNode

func (this *SyncFlightInfo) MarkFailedNode()

MarkFailedNode mark node failed, after request timeout

func (*SyncFlightInfo) ResetStartTime

func (this *SyncFlightInfo) ResetStartTime()

ResetStartTime

func (*SyncFlightInfo) SetNodeId

func (this *SyncFlightInfo) SetNodeId(nodeId uint64)

SetNodeId set a new node id

Directories

Path Synopsis
actor
req
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library.
* Copyright (C) 2021 The poly network Authors * This file is part of The poly network library.
message
net
protocol
Package p2p provides an network interface
Package p2p provides an network interface

Jump to

Keyboard shortcuts

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