Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeMessage(stream libp2pcore.Stream, rpc peers.P2PRPC, msg interface{}) error
- func EncodeMessage(stream libp2pcore.Stream, rpc peers.P2PRPC, msg interface{}) (int, error)
- func EncodeResponseMsg(rpc peers.P2PRPC, stream libp2pcore.Stream, msg interface{}, ...) *common.Error
- func ErrDAGConsensus(err error) *common.Error
- func ErrMessage(err error) *common.Error
- func NewInvVect(typ InvType, hash *hash.Hash) *pb.InvVect
- func ReadRspCode(stream network.Stream, rpc peers.P2PRPC) *common.Error
- func RegisterRPC(rpc peers.P2PRPC, basetopic string, base interface{}, handle rpcHandler)
- func Send(ctx context.Context, rpc peers.P2PRPC, message interface{}, baseTopic string, ...) (network.Stream, *common.Error)
- func SetRPCStreamDeadlines(stream network.Stream)
- func SetStreamReadDeadline(stream network.Stream, duration time.Duration)
- func SetStreamWriteDeadline(stream network.Stream, duration time.Duration)
- func UseLogger(logger l.Logger)
- type BlockData
- type ConnectedMsg
- type DisconnectedMsg
- type GetBlockDatasMsg
- type GetBlocksMsg
- type GetDatasMsg
- type InvType
- type MsgMemPool
- type OnFilterAddMsg
- type OnFilterClearMsg
- type OnFilterLoadMsg
- type OnMsgMemPool
- type PeerSync
- func (ps *PeerSync) Chain() *blockchain.BlockChain
- func (ps *PeerSync) Connected(pid peer.ID, conn network.Conn)
- func (ps *PeerSync) Connection(pe *peers.Peer)
- func (ps *PeerSync) Disconnect(pe *peers.Peer)
- func (ps *PeerSync) Disconnected(pid peer.ID, conn network.Conn)
- func (ps *PeerSync) EnforceNodeBloomFlag(sp *peers.Peer) bool
- func (ps *PeerSync) HasSyncPeer() bool
- func (ps *PeerSync) IntellectSyncBlocks(refresh bool, pe *peers.Peer) *ProcessResult
- func (ps *PeerSync) IsCompleteForSyncPeer() bool
- func (ps *PeerSync) IsCurrent() bool
- func (ps *PeerSync) IsInterrupt() bool
- func (ps *PeerSync) IsNearlySynced() bool
- func (ps *PeerSync) IsRunning() bool
- func (ps *PeerSync) LookupNode(pe *peers.Peer, qnr string) error
- func (ps *PeerSync) OnFilterAdd(sp *peers.Peer, msg *types.MsgFilterAdd)
- func (ps *PeerSync) OnFilterClear(sp *peers.Peer, msg *types.MsgFilterClear)
- func (ps *PeerSync) OnFilterLoad(sp *peers.Peer, msg *types.MsgFilterLoad)
- func (ps *PeerSync) OnGetData(sp *peers.Peer, invList []*pb.InvVect) error
- func (ps *PeerSync) OnMemPool(sp *peers.Peer, msg *MsgMemPool) error
- func (ps *PeerSync) OnPeerConnected(pe *peers.Peer)
- func (ps *PeerSync) OnPeerDisconnected(pe *peers.Peer)
- func (ps *PeerSync) OnPeerUpdate(pe *peers.Peer)
- func (ps *PeerSync) Pause() bool
- func (ps *PeerSync) PeerUpdate(pe *peers.Peer, immediately bool)
- func (ps *PeerSync) ReConnect(pe *peers.Peer) error
- func (ps *PeerSync) RelayGraphState()
- func (ps *PeerSync) RelayInventory(nds []*notify.NotifyData)
- func (ps *PeerSync) SetSyncPeer(pe *peers.Peer)
- func (ps *PeerSync) Start() error
- func (ps *PeerSync) Stop() error
- func (ps *PeerSync) SyncPeer() *peers.Peer
- func (ps *PeerSync) SyncQNR(pe *peers.Peer, qnr string)
- func (ps *PeerSync) TryAgainUpdateSyncPeer(immediately bool)
- func (ps *PeerSync) TryDisconnect(pe *peers.Peer)
- func (ps *PeerSync) UpdateGraphState(pe *peers.Peer)
- type PeerUpdateMsg
- type ProcessResult
- type ProcessResultAction
- type Sync
- func (s *Sync) AddConnectionHandler()
- func (s *Sync) AddDisconnectionHandler()
- func (s *Sync) CheckConsistency(hashOrOrder *protocol.HashOrNumber) (string, error)
- func (s *Sync) ConnectionGater(pid *peer.ID, addr ma.Multiaddr, dir network.Direction) bool
- func (s *Sync) EncodeResponseMsg(stream libp2pcore.Stream, msg interface{}) *common.Error
- func (s *Sync) EncodeResponseMsgPro(stream libp2pcore.Stream, msg interface{}, retCode common.ErrorCode) *common.Error
- func (s *Sync) Encoding() encoder.NetworkEncoding
- func (s *Sync) GetDataHandler(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error
- func (s *Sync) HandlerFilterMsgAdd(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error
- func (s *Sync) HandlerFilterMsgClear(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error
- func (s *Sync) HandlerFilterMsgLoad(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error
- func (s *Sync) HandlerMemPool(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error
- func (s *Sync) IsInboundPeerAtLimit() bool
- func (s *Sync) IsPeerAtLimit() bool
- func (s *Sync) IsWhitePeer(pid peer.ID) bool
- func (s *Sync) LookupNode(pe *peers.Peer, peNode *qnode.Node)
- func (s *Sync) PeerSync() *PeerSync
- func (s *Sync) Peers() *peers.Status
- func (s *Sync) QNRHandler(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error
- func (s *Sync) Send(pe *peers.Peer, protocol string, message interface{}) (interface{}, error)
- func (s *Sync) SendMempoolRequest(stream network.Stream, pe *peers.Peer) *common.Error
- func (s *Sync) SendPingRequest(stream network.Stream, pe *peers.Peer) *common.Error
- func (s *Sync) SetStreamHandler(topic string, handler network.StreamHandler)
- func (s *Sync) Start() error
- func (s *Sync) Stop() error
- func (s *Sync) UpdateChainState(pe *peers.Peer, chainState *pb.ChainState, action bool)
- type SyncQNRMsg
- type UpdateGraphStateMsg
Constants ¶
const ( // RPCGoodByeTopic defines the topic for the goodbye rpc method. RPCGoodByeTopic = "/qitmeer/req/goodbye/1" // RPCPingTopic defines the topic for the ping rpc method. RPCPingTopic = "/qitmeer/req/ping/1" // RPCMetaDataTopic defines the topic for the metadata rpc method. RPCMetaDataTopic = "/qitmeer/req/metadata/1" // RPCChainState defines the topic for the chain state rpc method. RPCChainState = "/qitmeer/req/chainstate/1" // RPCGetBlocks defines the topic for the get blocks rpc method. RPCGetBlocks = "/qitmeer/req/getblocks/1" // RPCGetBlockDatas defines the topic for the get blocks rpc method. RPCGetBlockDatas = "/qitmeer/req/getblockdatas/1" // RPCGetBlocks defines the topic for the get blocks rpc method. RPCSyncDAG = "/qitmeer/req/syncdag/1" // RPCContinueSyncDAG defines the topic for the get blocks rpc method. RPCContinueSyncDAG = "/qitmeer/req/continuesyncdag/1" // RPCTransaction defines the topic for the transaction rpc method. RPCTransaction = "/qitmeer/req/transaction/1" // RPCInventory defines the topic for the inventory rpc method. RPCInventory = "/qitmeer/req/inventory/1" // RPCGraphState defines the topic for the graphstate rpc method. RPCGraphState = "/qitmeer/req/graphstate/1" // RPCSyncQNR defines the topic for the syncqnr rpc method. RPCSyncQNR = "/qitmeer/req/syncqnr/1" // RPCGetMerkleBlocks defines the topic for the get merkle blocks rpc method. RPCGetMerkleBlocks = "/qitmeer/req/getmerkles/1" // RPCFilterAdd defines the topic for the filter add rpc method. RPCFilterAdd = "/qitmeer/req/filteradd/1" // RPCFilterClear defines the topic for the filter add rpc method. RPCFilterClear = "/qitmeer/req/filterclear/1" // RPCFilterLoad defines the topic for the filter add rpc method. RPCFilterLoad = "/qitmeer/req/filterload/1" // RPCMemPool defines the topic for the mempool rpc method. RPCMemPool = "/qitmeer/req/mempool/1" // RPCMemPool defines the topic for the getdata rpc method. RPCGetData = "/qitmeer/req/getdata/1" // RPCStateRoot defines the topic for the stateroot rpc method. RPCStateRoot = "/qitmeer/req/stateroot/1" // RPCBroadcastBlock defines the topic for the broadcast block rpc method. RPCBroadcastBlock = "/qitmeer/req/broadcastblock/1" )
const ( UpdateGraphStateTime = time.Second / 2 DefaultRateTaskTime = time.Second * 2 )
const ( UpdateGraphState = "UpdateGraphState" PeerUpdate = "PeerUpdate" PeerUpdateOrphan = "PeerUpdateOrphan" )
const BLOCKDATA_SSZ_HEAD_SIZE = 4
const HandleTimeout = 20 * time.Second
HandleTimeout is the maximum time for complete handler.
const MaxBlockLocatorsPerMsg = 2000
MaxBlockLocatorsPerMsg is the maximum number of block locator hashes allowed per message.
const ( // MaxInvPerMsg is the maximum number of inventory vectors that can be in a // single inv message. MaxInvPerMsg = 20000 )
const (
MaxPBGraphStateTips = 100
)
const (
ReconnectionTime = time.Second * 30
)
const ReqTimeout = 20 * time.Second
ReqTimeout is the maximum time for complete request transfer.
const RespTimeout = 20 * time.Second
RespTimeout is the maximum time for complete response transfer.
const TXDATA_SSZ_HEAD_SIZE = 4
const TtfbTimeout = 20 * time.Second
Time to first byte timeout. The maximum time to wait for first byte of request response (time-to-first-byte). The client is expected to give up if they don't receive the first byte within 20 seconds.
Variables ¶
var (
ErrPeerUnknown = common.NewError(common.ErrPeerUnknown, peers.ErrPeerUnknown)
)
Functions ¶
func DecodeMessage ¶
func DecodeMessage(stream libp2pcore.Stream, rpc peers.P2PRPC, msg interface{}) error
func EncodeMessage ¶
func EncodeResponseMsg ¶
func ErrDAGConsensus ¶
func ErrMessage ¶
func NewInvVect ¶
NewInvVect returns a new InvVect using the provided type and hash.
func ReadRspCode ¶
ReadRspCode response from a RPC stream.
func RegisterRPC ¶
registerRPC for a given topic with an expected protobuf message type.
func Send ¶
func Send(ctx context.Context, rpc peers.P2PRPC, message interface{}, baseTopic string, pe *peers.Peer) (network.Stream, *common.Error)
Send a message to a specific peer. The returned stream may be used for reading, but has been closed for writing.
func SetRPCStreamDeadlines ¶
SetRPCStreamDeadlines sets read and write deadlines for libp2p-based connection streams.
func SetStreamReadDeadline ¶
SetStreamReadDeadline for reading from libp2p connection streams, deciding when to close a connection based on a particular duration.
func SetStreamWriteDeadline ¶
SetStreamWriteDeadline for writing to libp2p connection streams, deciding when to close a connection based on a particular duration.
Types ¶
type GetBlockDatasMsg ¶
type GetBlockDatasMsg struct {
// contains filtered or unexported fields
}
type GetBlocksMsg ¶
type GetBlocksMsg struct {
// contains filtered or unexported fields
}
type GetDatasMsg ¶
type GetDatasMsg struct {
// contains filtered or unexported fields
}
type InvType ¶
type InvType uint32
InvType represents the allowed types of inventory vectors. See InvVect.
const ( InvTypeError InvType = 0 InvTypeTx InvType = 1 InvTypeBlock InvType = 2 InvTypeFilteredBlock InvType = 3 )
These constants define the various supported inventory vector types.
type MsgMemPool ¶
type MsgMemPool struct{}
MsgMemPool implements the Message interface and represents a bitcoin mempool message. It is used to request a list of transactions still in the active memory pool of a relay.
This message has no payload and was not added until protocol versions
func (*MsgMemPool) MaxPayloadLength ¶
func (msg *MsgMemPool) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type OnFilterAddMsg ¶
type OnFilterAddMsg struct {
// contains filtered or unexported fields
}
type OnFilterClearMsg ¶
type OnFilterClearMsg struct {
// contains filtered or unexported fields
}
type OnFilterLoadMsg ¶
type OnFilterLoadMsg struct {
// contains filtered or unexported fields
}
type OnMsgMemPool ¶
type OnMsgMemPool struct {
// contains filtered or unexported fields
}
type PeerSync ¶
type PeerSync struct {
// contains filtered or unexported fields
}
func NewPeerSync ¶
func (*PeerSync) Chain ¶
func (ps *PeerSync) Chain() *blockchain.BlockChain
func (*PeerSync) Connection ¶
func (*PeerSync) Disconnect ¶
func (*PeerSync) EnforceNodeBloomFlag ¶
EnforceNodeBloomFlag disconnects the peer if the server is not configured to allow bloom filters. Additionally, if the peer has negotiated to a protocol version that is high enough to observe the bloom filter service support bit, it will be banned since it is intentionally violating the protocol.
func (*PeerSync) HasSyncPeer ¶
func (*PeerSync) IntellectSyncBlocks ¶
func (ps *PeerSync) IntellectSyncBlocks(refresh bool, pe *peers.Peer) *ProcessResult
func (*PeerSync) IsCompleteForSyncPeer ¶
func (*PeerSync) IsCurrent ¶
IsCurrent returns true if we believe we are synced with our peers, false if we still have blocks to check
func (*PeerSync) IsInterrupt ¶ added in v1.0.20
func (*PeerSync) IsNearlySynced ¶ added in v1.2.0
func (*PeerSync) OnFilterAdd ¶
func (ps *PeerSync) OnFilterAdd(sp *peers.Peer, msg *types.MsgFilterAdd)
OnFilterAdd is invoked when a peer receives a filteradd qitmeer message and is used by remote peers to add data to an already loaded bloom filter. The peer will be disconnected if a filter is not loaded when this message is received or the server is not configured to allow bloom filters.
func (*PeerSync) OnFilterClear ¶
func (ps *PeerSync) OnFilterClear(sp *peers.Peer, msg *types.MsgFilterClear)
OnFilterClear is invoked when a peer receives a filterclear qitmeer message and is used by remote peers to clear an already loaded bloom filter. The peer will be disconnected if a filter is not loaded when this message is received or the server is not configured to allow bloom filters.
func (*PeerSync) OnFilterLoad ¶
func (ps *PeerSync) OnFilterLoad(sp *peers.Peer, msg *types.MsgFilterLoad)
OnFilterLoad is invoked when a peer receives a filterload qitmeer message and it used to load a bloom filter that should be used for delivering merkle blocks and associated transactions that match the filter. The peer will be disconnected if the server is not configured to allow bloom filters.
func (*PeerSync) OnGetData ¶
handleGetData is invoked when a peer receives a getdata qitmeer message and is used to deliver block and transaction information.
func (*PeerSync) OnMemPool ¶
func (ps *PeerSync) OnMemPool(sp *peers.Peer, msg *MsgMemPool) error
OnMemPool is invoked when a peer receives a mempool qitmeer message. It creates and sends an inventory message with the contents of the memory pool up to the maximum inventory allowed per message. When the peer has a bloom filter loaded, the contents are filtered accordingly.
func (*PeerSync) OnPeerConnected ¶
func (*PeerSync) OnPeerDisconnected ¶
func (*PeerSync) OnPeerUpdate ¶
func (*PeerSync) RelayGraphState ¶
func (ps *PeerSync) RelayGraphState()
func (*PeerSync) RelayInventory ¶
func (ps *PeerSync) RelayInventory(nds []*notify.NotifyData)
func (*PeerSync) SetSyncPeer ¶
func (*PeerSync) TryAgainUpdateSyncPeer ¶
func (*PeerSync) TryDisconnect ¶
func (*PeerSync) UpdateGraphState ¶
type PeerUpdateMsg ¶
type PeerUpdateMsg struct {
// contains filtered or unexported fields
}
type ProcessResult ¶ added in v1.0.20
type ProcessResult struct {
// contains filtered or unexported fields
}
func NewProcessResult ¶ added in v1.0.20
func NewProcessResult() *ProcessResult
type ProcessResultAction ¶ added in v1.0.20
type ProcessResultAction int
const ( ProcessResultActionNull ProcessResultAction = iota ProcessResultActionContinue ProcessResultActionTryAgain )
func (ProcessResultAction) IsContinue ¶ added in v1.0.20
func (a ProcessResultAction) IsContinue() bool
func (ProcessResultAction) IsNothing ¶ added in v1.0.20
func (a ProcessResultAction) IsNothing() bool
func (ProcessResultAction) IsTryAgain ¶ added in v1.0.20
func (a ProcessResultAction) IsTryAgain() bool
func (ProcessResultAction) String ¶ added in v1.0.20
func (a ProcessResultAction) String() string
type Sync ¶
type Sync struct { PeerInterval time.Duration LANPeers map[peer.ID]struct{} // contains filtered or unexported fields }
func (*Sync) AddConnectionHandler ¶
func (s *Sync) AddConnectionHandler()
AddConnectionHandler adds a callback function which handles the connection with a newly added peer. It performs a handshake with that peer by sending a hello request and validating the response from the peer.
func (*Sync) AddDisconnectionHandler ¶
func (s *Sync) AddDisconnectionHandler()
AddDisconnectionHandler disconnects from peers. It handles updating the peer status. This also calls the handler responsible for maintaining other parts of the sync or p2p system.
func (*Sync) CheckConsistency ¶ added in v1.0.21
func (s *Sync) CheckConsistency(hashOrOrder *protocol.HashOrNumber) (string, error)
Check data consistency
func (*Sync) ConnectionGater ¶ added in v1.0.21
func (*Sync) EncodeResponseMsg ¶
func (s *Sync) EncodeResponseMsg(stream libp2pcore.Stream, msg interface{}) *common.Error
func (*Sync) EncodeResponseMsgPro ¶
func (*Sync) Encoding ¶
func (s *Sync) Encoding() encoder.NetworkEncoding
func (*Sync) GetDataHandler ¶
func (*Sync) HandlerFilterMsgAdd ¶
func (*Sync) HandlerFilterMsgClear ¶
func (*Sync) HandlerFilterMsgLoad ¶
func (*Sync) HandlerMemPool ¶
func (*Sync) IsInboundPeerAtLimit ¶
func (*Sync) IsPeerAtLimit ¶
func (*Sync) QNRHandler ¶
func (*Sync) SendMempoolRequest ¶
func (*Sync) SendPingRequest ¶
func (*Sync) SetStreamHandler ¶
func (s *Sync) SetStreamHandler(topic string, handler network.StreamHandler)
SetStreamHandler sets the protocol handler on the p2p host multiplexer. This method is a pass through to libp2pcore.Host.SetStreamHandler.
func (*Sync) UpdateChainState ¶
type SyncQNRMsg ¶
type SyncQNRMsg struct {
// contains filtered or unexported fields
}
type UpdateGraphStateMsg ¶
type UpdateGraphStateMsg struct {
// contains filtered or unexported fields
}
Source Files ¶
- blockdata.go
- chainstate.go
- consistency.go
- deadlines.go
- getblockdatas.go
- getblocks.go
- goodbye.go
- graphstate.go
- handshake.go
- inventory.go
- invvect.go
- log.go
- mempool.go
- metadata.go
- msg.go
- msgfilter.go
- msgmempool.go
- peersync.go
- ping.go
- protohelper.go
- result.go
- rspcode.go
- stateroot.go
- status.go
- sync.go
- syncdag.go
- syncqnr.go
- tx.go
- util.go