p2p

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: MIT Imports: 39 Imported by: 8

README

Stuffs for p2p network

Documentation

Index

Constants

View Source
const (
	SyncWorkTTL        = time.Second * 30
	AddBlockCheckpoint = 100
	AddBlockWaitTime   = time.Second * 10
)

constants for legacy sync algorithm. DEPRECATED newer sync loging in syncer package is used now.

View Source
const (
	DiscoveryQueryInterval = time.Minute * 1

	MaxAddrListSizePolaris = 200
	MaxAddrListSizePeer    = 50
)

constants for node discovery

View Source
const (
	DefaultGlobalBlockCacheSize = 300
	DefaultPeerBlockCacheSize   = 100

	DefaultGlobalTxCacheSize = 50000
	DefaultPeerTxCacheSize   = 10000
	// DefaultPeerTxQueueSize is maximum size of hashes in a single tx notice message
	DefaultPeerTxQueueSize = 2000
)

constants for caching TODO this value better related to max peer and block produce interval, not constant

View Source
const (
	GapToSkipAll    = 86400
	GapToSkipHourly = 3600
	GapToSkip5Min   = 300

	HourlyInterval        = time.Hour
	TenMiniteInterval     = time.Minute * 10
	MinNewBlkNotiInterval = time.Second >> 2
)

constants for block notice tuning

View Source
const ClientVersion = "0.2.0"

ClientVersion is the version of p2p protocol to which this codes are built FIXME version should be defined in more general ways

Variables

View Source
var CancelError = errors.New("canceled")

CurrentSupported is list of versions this aergosvr supports. The first is the best recommended version.

View Source
var TimeoutError = errors.New("timeout")

Functions

func NewInbountHSHandler added in v0.9.0

func NewInbountHSHandler(pm p2pcommon.PeerManager, actor p2pcommon.ActorService, verManager p2pcommon.VersionedManager, log *log.Logger, chainID *types.ChainID, peerID types.PeerID) p2pcommon.HSHandler

func NewOutbountHSHandler added in v0.9.0

func NewOutbountHSHandler(pm p2pcommon.PeerManager, actor p2pcommon.ActorService, verManager p2pcommon.VersionedManager, log *log.Logger, chainID *types.ChainID, peerID types.PeerID) p2pcommon.HSHandler

func NewPeerFinder added in v0.9.0

func NewPeerFinder(logger *log.Logger, pm *peerManager, actorService p2pcommon.ActorService, maxCap int, useDiscover, usePolaris bool) p2pcommon.PeerFinder

func NewPeerManager

func NewPeerManager(handlerFactory p2pcommon.HandlerFactory, hsFactory p2pcommon.HSHandlerFactory, iServ p2pcommon.ActorService, cfg *cfg.Config, signer p2pcommon.MsgSigner, nt p2pcommon.NetworkTransport, mm metric.MetricsManager, logger *log.Logger, mf p2pcommon.MoFactory, skipHandshakeSync bool) p2pcommon.PeerManager

NewPeerManager creates a peer manager object.

func NewWaitingPeerManager added in v0.9.0

func NewWaitingPeerManager(logger *log.Logger, pm *peerManager, actorService p2pcommon.ActorService, maxCap int, useDiscover, usePolaris bool) p2pcommon.WaitingPeerManager

func P2PTxHashArrToString

func P2PTxHashArrToString(bbarray []types.TxID) string

bytesArrToString converts array of byte array to json array of b58 encoded string.

func P2PTxHashArrToStringWithLimit

func P2PTxHashArrToStringWithLimit(bbarray []types.TxID, limit int) string

Types

type AncestorReceiver added in v0.9.0

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

BlocksChunkReceiver is send p2p getBlocksRequest to target peer and receive p2p responses till all requestes blocks are received It will send response actor message if all blocks are received or failed to receive, but not send response if timeout expired.

func NewAncestorReceiver added in v0.9.0

func NewAncestorReceiver(actor p2pcommon.ActorService, peer p2pcommon.RemotePeer, seq uint64, hashes [][]byte, ttl time.Duration) *AncestorReceiver

func (*AncestorReceiver) ReceiveResp added in v0.9.0

func (br *AncestorReceiver) ReceiveResp(msg p2pcommon.Message, msgBody p2pcommon.MessageBody) (ret bool)

ReceiveResp must be called just in read go routine

func (*AncestorReceiver) StartGet added in v0.9.0

func (br *AncestorReceiver) StartGet()

type BlockHashByNoReceiver added in v0.8.2

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

BlocksChunkReceiver is send p2p getBlocksRequest to target peer and receive p2p responses till all requestes blocks are received It will send response actor message if all blocks are received or failed to receive, but not send response if timeout expired.

func NewBlockHashByNoReceiver added in v0.8.2

func NewBlockHashByNoReceiver(actor p2pcommon.ActorService, peer p2pcommon.RemotePeer, seq uint64, blockNo types.BlockNo, ttl time.Duration) *BlockHashByNoReceiver

func (*BlockHashByNoReceiver) ReceiveResp added in v0.8.2

func (br *BlockHashByNoReceiver) ReceiveResp(msg p2pcommon.Message, msgBody p2pcommon.MessageBody) (ret bool)

ReceiveResp must be called just in read go routine

func (*BlockHashByNoReceiver) StartGet added in v0.8.2

func (br *BlockHashByNoReceiver) StartGet()

type BlockHashesReceiver added in v0.8.1

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

BlockHashesReceiver is send p2p GetHashesRequest to target peer and receive p2p responses till all requested hashes are received It will send response actor message if all hashes are received or failed to receive, but not send response if timeout expired.

func NewBlockHashesReceiver added in v0.8.1

func NewBlockHashesReceiver(actor p2pcommon.ActorService, peer p2pcommon.RemotePeer, seq uint64, req *message.GetHashes, ttl time.Duration) *BlockHashesReceiver

func (*BlockHashesReceiver) ReceiveResp added in v0.8.1

func (br *BlockHashesReceiver) ReceiveResp(msg p2pcommon.Message, msgBody p2pcommon.MessageBody) (ret bool)

ReceiveResp must be called just in read go routine

func (*BlockHashesReceiver) StartGet added in v0.8.1

func (br *BlockHashesReceiver) StartGet()

type BlocksChunkReceiver added in v0.8.1

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

BlocksChunkReceiver is send p2p getBlocksRequest to target peer and receive p2p responses till all requestes blocks are received It will send response actor message if all blocks are received or failed to receive, but not send response if timeout expired, since syncer actor already dropped wait before.

func NewBlockReceiver added in v0.8.1

func NewBlockReceiver(actor p2pcommon.ActorService, peer p2pcommon.RemotePeer, seq uint64, blockHashes []message.BlockHash, ttl time.Duration) *BlocksChunkReceiver

func (*BlocksChunkReceiver) ReceiveResp added in v0.8.1

func (br *BlocksChunkReceiver) ReceiveResp(msg p2pcommon.Message, msgBody p2pcommon.MessageBody) (ret bool)

ReceiveResp must be called just in read go routine

func (*BlocksChunkReceiver) StartGet added in v0.8.1

func (br *BlocksChunkReceiver) StartGet()

type ConnWork added in v0.9.0

type ConnWork struct {
	PeerID    types.PeerID
	Meta      p2pcommon.PeerMeta
	StartTime time.Time
}

type InboundWireHandshaker added in v0.9.0

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

func (*InboundWireHandshaker) Handle added in v0.9.0

type LegacyInboundHSHandler added in v0.9.0

type LegacyInboundHSHandler struct {
	*LegacyWireHandshaker
}

LegacyInboundHSHandler handshake handler for legacy version

func (*LegacyInboundHSHandler) Handle added in v0.9.0

type LegacyOutboundHSHandler added in v0.9.0

type LegacyOutboundHSHandler struct {
	*LegacyWireHandshaker
}

LegacyOutboundHSHandler handshake handler for legacy version

func (*LegacyOutboundHSHandler) Handle added in v0.9.0

type LegacyWireHandshaker added in v0.9.0

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

LegacyWireHandshaker works to handshake to just connected peer, it detect chain networks and protocol versions, and then select InnerHandshaker for that protocol version.

type OutboundWireHandshaker added in v0.9.0

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

func (*OutboundWireHandshaker) Handle added in v0.9.0

type P2P

type P2P struct {
	*component.BaseComponent
	// contains filtered or unexported fields
}

P2P is actor component for p2p

func NewP2P

func NewP2P(cfg *config.Config, chainsvc *chain.ChainService) *P2P

NewP2P create a new ActorService for p2p

func (*P2P) AfterStart

func (p2ps *P2P) AfterStart()

func (*P2P) BeforeStart

func (p2ps *P2P) BeforeStart()

BeforeStart starts p2p service.

func (*P2P) BeforeStop

func (p2ps *P2P) BeforeStop()

BeforeStop is called before actor hub stops. it finishes underlying peer manager

func (*P2P) CallRequest

func (p2ps *P2P) CallRequest(actor string, msg interface{}, timeout time.Duration) (interface{}, error)

CallRequest implement interface method of ActorService

func (*P2P) CallRequestDefaultTimeout

func (p2ps *P2P) CallRequestDefaultTimeout(actor string, msg interface{}) (interface{}, error)

CallRequest implement interface method of ActorService

func (*P2P) ChainID added in v0.9.0

func (p2ps *P2P) ChainID() *types.ChainID

func (*P2P) CreateHSHandler added in v0.9.0

func (p2ps *P2P) CreateHSHandler(p2pVersion p2pcommon.P2PVersion, outbound bool, pid types.PeerID) p2pcommon.HSHandler

func (*P2P) FutureRequest

func (p2ps *P2P) FutureRequest(actor string, msg interface{}, timeout time.Duration) *actor.Future

FutureRequest implement interface method of ActorService

func (*P2P) FutureRequestDefaultTimeout

func (p2ps *P2P) FutureRequestDefaultTimeout(actor string, msg interface{}) *actor.Future

FutureRequestDefaultTimeout implement interface method of ActorService

func (*P2P) GetAddresses

func (p2ps *P2P) GetAddresses(peerID types.PeerID, size uint32) bool

GetAddresses send getAddress request to other peer

func (*P2P) GetBlockHashByNo added in v0.8.2

func (p2ps *P2P) GetBlockHashByNo(context actor.Context, msg *message.GetHashByNo)

GetBlockHashes send request message to peer and make response message for block hashes

func (*P2P) GetBlockHashes added in v0.8.1

func (p2ps *P2P) GetBlockHashes(context actor.Context, msg *message.GetHashes)

GetBlockHashes send request message to peer and make response message for block hashes

func (*P2P) GetBlockHeaders

func (p2ps *P2P) GetBlockHeaders(msg *message.GetBlockHeaders) bool

GetBlockHeaders send request message to peer and

func (*P2P) GetBlocks

func (p2ps *P2P) GetBlocks(peerID types.PeerID, blockHashes []message.BlockHash) bool

GetBlocks send request message to peer and

func (*P2P) GetBlocksChunk added in v0.8.1

func (p2ps *P2P) GetBlocksChunk(context actor.Context, msg *message.GetBlockChunks)

GetBlocksChunk send request message to peer and

func (*P2P) GetChainAccessor

func (p2ps *P2P) GetChainAccessor() types.ChainAccessor

GetChainAccessor implment interface method of ActorService

func (*P2P) GetNetworkTransport added in v0.9.0

func (p2ps *P2P) GetNetworkTransport() p2pcommon.NetworkTransport

func (*P2P) GetPeerAccessor added in v0.9.0

func (p2ps *P2P) GetPeerAccessor() p2pcommon.PeerAccessor

func (*P2P) GetSyncAncestor added in v0.8.1

func (p2ps *P2P) GetSyncAncestor(context actor.Context, msg *message.GetSyncAncestor)

Syncer.finder request remote peer to find ancestor

func (*P2P) GetTXs

func (p2ps *P2P) GetTXs(peerID types.PeerID, txHashes []message.TXHash) bool

GetTXs send request message to peer and

func (*P2P) InsertHandlers added in v0.9.0

func (p2ps *P2P) InsertHandlers(peer p2pcommon.RemotePeer)

func (*P2P) NotifyBlockProduced added in v0.9.0

func (p2ps *P2P) NotifyBlockProduced(newBlock message.NotifyNewBlock) bool

NotifyNewBlock send notice message of new block to a peer

func (*P2P) NotifyNewBlock

func (p2ps *P2P) NotifyNewBlock(newBlock message.NotifyNewBlock) bool

NotifyNewBlock send notice message of new block to a peer

func (*P2P) NotifyNewTX

func (p2ps *P2P) NotifyNewTX(newTXs message.NotifyNewTransactions) bool

NotifyNewTX notice tx(s) id created

func (*P2P) Receive

func (p2ps *P2P) Receive(context actor.Context)

Receive got actor message and then handle it.

func (*P2P) SendRequest

func (p2ps *P2P) SendRequest(actor string, msg interface{})

SendRequest implement interface method of ActorService

func (*P2P) SetConsensusAccessor added in v0.9.0

func (p2ps *P2P) SetConsensusAccessor(ca consensus.ConsensusAccessor)

func (*P2P) Statistics

func (p2ps *P2P) Statistics() *map[string]interface{}

Statistics show statistic information of p2p module. NOTE: It it not implemented yet

func (*P2P) TellRequest

func (p2ps *P2P) TellRequest(actor string, msg interface{})

TellRequest implement interface method of ActorService

type PeerEventListener

type PeerEventListener interface {
	// OnAddPeer is called just after the peer is added.
	OnAddPeer(peerID types.PeerID)

	// OnRemovePeer is called just before the peer is removed
	OnRemovePeer(peerID types.PeerID)
}

PeerEventListener listen peer manage event

Directories

Path Synopsis
* @file * @copyright defined in aergo/LICENSE.txt
* @file * @copyright defined in aergo/LICENSE.txt
Package p2pmock is a generated GoMock package.
Package p2pmock is a generated GoMock package.
Package v030 is a collection of classes for p2p version 0.3.0 It contains IO, handshake, handlers, etc.
Package v030 is a collection of classes for p2p version 0.3.0 It contains IO, handshake, handlers, etc.

Jump to

Keyboard shortcuts

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