p2pserver

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2018 License: LGPL-3.0 Imports: 25 Imported by: 10

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  = 10   //s, Request header timeout time. If header haven't receive after SYNC_HEADER_REQUEST_TIMEOUT second, retry
	SYNC_BLOCK_REQUEST_TIMEOUT   = 15   //s, Request block timeout time. If block haven't received after SYNC_BLOCK_REQUEST_TIMEOUT second, retry
)

Variables

This section is empty.

Functions

This section is empty.

Types

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(block *types.Block)

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(headers []*types.Header)

OnHeaderReceive receive header from net

func (*BlockSyncMgr) Start

func (this *BlockSyncMgr) Start()

Start to sync

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(block *types.Block)

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