Documentation ¶
Index ¶
- Constants
- Variables
- func FromMultiAddr(targetAddr multiaddr.Multiaddr) (p2pcommon.PeerMeta, error)
- func GenerateKeyFile(dir, prefix string) (crypto.PrivKey, crypto.PubKey, error)
- func InitNodeInfo(baseCfg *config.BaseConfig, p2pCfg *config.P2PConfig, logger *log.Logger)
- func LoadKeyFile(keyFile string) (crypto.PrivKey, crypto.PubKey, error)
- func NewNetworkTransport(conf *cfg.P2PConfig, logger *log.Logger) *networkTransport
- func NewPeerManager(handlerFactory HandlerFactory, hsFactory HSHandlerFactory, ...) p2pcommon.PeerManager
- func NodeID() peer.ID
- func NodePrivKey() crypto.PrivKey
- func NodePubKey() crypto.PubKey
- func NodeSID() string
- func P2PTxHashArrToString(bbarray []types.TxID) string
- func P2PTxHashArrToStringWithLimit(bbarray []types.TxID, limit int) string
- func ParseMultiAddrString(str string) (p2pcommon.PeerMeta, error)
- func ParseMultiaddrWithResolve(str string) (multiaddr.Multiaddr, error)
- func PeerMetaToMultiAddr(m p2pcommon.PeerMeta) (multiaddr.Multiaddr, error)
- func ToMultiAddr(ipAddr net.IP, port uint32) (multiaddr.Multiaddr, error)
- type AncestorReceiver
- type BlockHashByNoReceiver
- type BlockHashesReceiver
- type BlocksChunkReceiver
- type HSHandler
- type HSHandlerFactory
- type HSHeader
- type HandlerFactory
- type InboundHSHandler
- type OutboundHSHandler
- type P2P
- func (p2ps *P2P) AfterStart()
- func (p2ps *P2P) BeforeStart()
- func (p2ps *P2P) BeforeStop()
- func (p2ps *P2P) CallRequest(actor string, msg interface{}, timeout time.Duration) (interface{}, error)
- func (p2ps *P2P) CallRequestDefaultTimeout(actor string, msg interface{}) (interface{}, error)
- func (p2ps *P2P) ChainID() *types.ChainID
- func (p2ps *P2P) CreateHSHandler(outbound bool, pm p2pcommon.PeerManager, actor p2pcommon.ActorService, ...) HSHandler
- func (p2ps *P2P) FutureRequest(actor string, msg interface{}, timeout time.Duration) *actor.Future
- func (p2ps *P2P) FutureRequestDefaultTimeout(actor string, msg interface{}) *actor.Future
- func (p2ps *P2P) GetAddresses(peerID peer.ID, size uint32) bool
- func (p2ps *P2P) GetBlockHashByNo(context actor.Context, msg *message.GetHashByNo)
- func (p2ps *P2P) GetBlockHashes(context actor.Context, msg *message.GetHashes)
- func (p2ps *P2P) GetBlockHeaders(msg *message.GetBlockHeaders) bool
- func (p2ps *P2P) GetBlocks(peerID peer.ID, blockHashes []message.BlockHash) bool
- func (p2ps *P2P) GetBlocksChunk(context actor.Context, msg *message.GetBlockChunks)
- func (p2ps *P2P) GetChainAccessor() types.ChainAccessor
- func (p2ps *P2P) GetNetworkTransport() p2pcommon.NetworkTransport
- func (p2ps *P2P) GetPeerAccessor() types.PeerAccessor
- func (p2ps *P2P) GetSyncAncestor(context actor.Context, msg *message.GetSyncAncestor)
- func (p2ps *P2P) GetTXs(peerID peer.ID, txHashes []message.TXHash) bool
- func (p2ps *P2P) NotifyBlockProduced(newBlock message.NotifyNewBlock) bool
- func (p2ps *P2P) NotifyNewBlock(newBlock message.NotifyNewBlock) bool
- func (p2ps *P2P) NotifyNewTX(newTXs message.NotifyNewTransactions) bool
- func (p2ps *P2P) Receive(context actor.Context)
- func (p2ps *P2P) SendRequest(actor string, msg interface{})
- func (p2ps *P2P) Statistics() *map[string]interface{}
- func (p2ps *P2P) TellRequest(actor string, msg interface{})
- type PeerEventListener
- type PeerHandshaker
- type V030HSMessage
- type V030Handshaker
- type V030Message
- type V030ReadWriter
- type V030Reader
- type V030Writer
Constants ¶
const ( // time to determine which the remote designated peer is not working. DesignatedNodeTTL = time.Minute * 60 // time to determine which the remote peer is not working. DefaultNodeTTL = time.Minute * 10 )
constants for peer communicating
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.
const ( DiscoveryQueryInterval = time.Minute * 5 MaxAddrListSizePolaris = 200 MaxAddrListSizePeer = 50 )
constants for node discovery
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
const ( DefaultPkKeyPrefix = "aergo-peer" DefaultPkKeyExt = ".key" DefaultPubKeyExt = ".pub" DefaultPeerIDExt = ".id" )
constants about private key
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
const ( // other actor DefaultActorMsgTTL = time.Second * 4 )
constants for inter-communication of aergosvr
Variables ¶
var InvalidArgument = fmt.Errorf("invalid argument")
var TimeoutError error
Functions ¶
func FromMultiAddr ¶ added in v0.9.4
func GenerateKeyFile ¶ added in v0.11.0
func InitNodeInfo ¶
InitNodeInfo initializes node-specific informations like node id. Caution: this must be called before all the goroutines are started.
func LoadKeyFile ¶ added in v0.11.0
func NewNetworkTransport ¶ added in v0.9.4
func NewPeerManager ¶
func NewPeerManager(handlerFactory HandlerFactory, hsFactory HSHandlerFactory, iServ p2pcommon.ActorService, cfg *cfg.Config, signer p2pcommon.MsgSigner, nt p2pcommon.NetworkTransport, mm metric.MetricsManager, logger *log.Logger, mf p2pcommon.MoFactory) p2pcommon.PeerManager
NewPeerManager creates a peer manager object.
func NodePrivKey ¶
NodePrivKey returns the private key of the node.
func P2PTxHashArrToString ¶
bytesArrToString converts array of byte array to json array of b58 encoded string.
func ParseMultiAddrString ¶ added in v0.10.0
func ParseMultiaddrWithResolve ¶ added in v0.9.4
ParseMultiaddrWithResolve parse string to multiaddr, additionally accept domain name with protocol /dns NOTE: this function is temporarilly use until go-multiaddr start to support dns.
func PeerMetaToMultiAddr ¶ added in v0.10.0
PeerMetaToMultiAddr make libp2p compatible Multiaddr object from peermeta
Types ¶
type AncestorReceiver ¶ added in v1.0.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 v1.0.0
func NewAncestorReceiver(actor p2pcommon.ActorService, peer p2pcommon.RemotePeer, seq uint64, hashes [][]byte, ttl time.Duration) *AncestorReceiver
func (*AncestorReceiver) ReceiveResp ¶ added in v1.0.0
ReceiveResp must be called just in read go routine
func (*AncestorReceiver) StartGet ¶ added in v1.0.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 proto.Message) (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
}
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 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
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
ReceiveResp must be called just in read go routine
func (*BlocksChunkReceiver) StartGet ¶ added in v0.8.1
func (br *BlocksChunkReceiver) StartGet()
type HSHandler ¶ added in v0.9.4
type HSHandler interface { // Handle peer handshake till ttl, and return msgrw for this connection, and status of remote peer. Handle(r io.Reader, w io.Writer, ttl time.Duration) (p2pcommon.MsgReadWriter, *types.Status, error) }
HSHandler will do handshake with remote peer
type HSHandlerFactory ¶ added in v0.9.4
type HSHandlerFactory interface {
CreateHSHandler(outbound bool, pm p2pcommon.PeerManager, actor p2pcommon.ActorService, log *log.Logger, pid peer.ID) HSHandler
}
HSHandlerFactory is creator of HSHandler
type HandlerFactory ¶
type HandlerFactory interface {
// contains filtered or unexported methods
}
type InboundHSHandler ¶ added in v0.9.4
type InboundHSHandler struct {
*PeerHandshaker
}
type OutboundHSHandler ¶ added in v0.9.4
type OutboundHSHandler struct {
*PeerHandshaker
}
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) 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 ¶
CallRequest implement interface method of ActorService
func (*P2P) CreateHSHandler ¶ added in v0.9.4
func (*P2P) FutureRequest ¶
FutureRequest implement interface method of ActorService
func (*P2P) FutureRequestDefaultTimeout ¶
FutureRequestDefaultTimeout implement interface method of ActorService
func (*P2P) GetAddresses ¶
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
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) 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.4
func (p2ps *P2P) GetNetworkTransport() p2pcommon.NetworkTransport
func (*P2P) GetPeerAccessor ¶ added in v1.0.0
func (p2ps *P2P) GetPeerAccessor() types.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) NotifyBlockProduced ¶ added in v0.9.4
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) SendRequest ¶
SendRequest implement interface method of ActorService
func (*P2P) Statistics ¶
Statistics show statistic information of p2p module. NOTE: It it not implemented yet
func (*P2P) TellRequest ¶
TellRequest implement interface method of ActorService
type PeerEventListener ¶
type PeerEventListener interface { // OnAddPeer is called just after the peer is added. OnAddPeer(peerID peer.ID) // OnRemovePeer is called just before the peer is removed OnRemovePeer(peerID peer.ID) }
PeerEventListener listen peer manage event
type PeerHandshaker ¶
type PeerHandshaker struct {
// contains filtered or unexported fields
}
PeerHandshaker works to handshake to just connected peer, it detect chain networks and protocol versions, and then select InnerHandshaker for that protocol version.
type V030HSMessage ¶
type V030Handshaker ¶
type V030Handshaker struct {
// contains filtered or unexported fields
}
V030Handshaker exchange status data over protocol version .0.3.0
func (*V030Handshaker) GetMsgRW ¶
func (h *V030Handshaker) GetMsgRW() p2pcommon.MsgReadWriter
type V030Message ¶
type V030Message struct {
// contains filtered or unexported fields
}
V030Message is basic form of p2p message v0.3
func NewV030Message ¶ added in v0.9.4
func NewV030Message(msgID, originalID p2pcommon.MsgID, timestamp int64, protocol p2pcommon.SubProtocol, payload []byte) *V030Message
NewV030Message create a new object
func (*V030Message) ID ¶
func (m *V030Message) ID() p2pcommon.MsgID
func (*V030Message) Length ¶
func (m *V030Message) Length() uint32
func (*V030Message) OriginalID ¶
func (m *V030Message) OriginalID() p2pcommon.MsgID
func (*V030Message) Payload ¶
func (m *V030Message) Payload() []byte
func (*V030Message) Subprotocol ¶
func (m *V030Message) Subprotocol() p2pcommon.SubProtocol
func (*V030Message) Timestamp ¶
func (m *V030Message) Timestamp() int64
type V030ReadWriter ¶
type V030ReadWriter struct {
// contains filtered or unexported fields
}
func NewV030ReadWriter ¶
func NewV030ReadWriter(r *bufio.Reader, w *bufio.Writer) *V030ReadWriter
type V030Reader ¶
type V030Reader struct {
// contains filtered or unexported fields
}
func NewV030Reader ¶
func NewV030Reader(rd *bufio.Reader) *V030Reader
type V030Writer ¶
type V030Writer struct {
// contains filtered or unexported fields
}
func NewV030Writer ¶
func NewV030Writer(wr *bufio.Writer) *V030Writer