Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeResponseMsg(rpc common.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 io.Reader, encoding encoder.NetworkEncoding) (common.ErrorCode, string, error)
- func RegisterRPC(rpc common.P2PRPC, basetopic string, base interface{}, handle rpcHandler)
- func Send(ctx context.Context, rpc common.P2PRPC, message interface{}, baseTopic string, ...) (network.Stream, 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 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) GetBlockDatas(pe *peers.Peer, blocks []*hash.Hash)
- func (ps *PeerSync) GetBlocks(pe *peers.Peer, blocks []*hash.Hash)
- func (ps *PeerSync) HasSyncPeer() bool
- func (ps *PeerSync) IntellectSyncBlocks(refresh bool, pe *peers.Peer)
- func (ps *PeerSync) IsCompleteForSyncPeer() bool
- func (ps *PeerSync) IsCurrent() 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)
- 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() chan<- struct{}
- func (ps *PeerSync) PeerUpdate(pe *peers.Peer, immediately bool)
- func (ps *PeerSync) RelayInventory(data interface{}, filters []peer.ID)
- 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) UpdateGraphState(pe *peers.Peer)
- type PeerUpdateMsg
- type Sync
- func (s *Sync) AddConnectionHandler()
- func (s *Sync) AddDisconnectionHandler()
- 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) *common.Error
- func (s *Sync) HandlerFilterMsgAdd(ctx context.Context, msg interface{}, stream libp2pcore.Stream) *common.Error
- func (s *Sync) HandlerFilterMsgClear(ctx context.Context, msg interface{}, stream libp2pcore.Stream) *common.Error
- func (s *Sync) HandlerFilterMsgLoad(ctx context.Context, msg interface{}, stream libp2pcore.Stream) *common.Error
- func (s *Sync) HandlerMemPool(ctx context.Context, msg interface{}, stream libp2pcore.Stream) *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) *common.Error
- func (s *Sync) Send(ctx context.Context, message interface{}, baseTopic string, pid peer.ID) (network.Stream, error)
- func (s *Sync) SendMempoolRequest(ctx context.Context, pe *peers.Peer) error
- func (s *Sync) SendPingRequest(ctx context.Context, id peer.ID) 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" // 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" )
const ( UpdateGraphStateTime = time.Second * 2 DefaultRateTaskTime = time.Second * 2 )
const ( UpdateGraphState = "UpdateGraphState" PeerUpdate = "PeerUpdate" PeerUpdateOrphan = "PeerUpdateOrphan" )
const BLOCKDATA_SSZ_HEAD_SIZE = 4
const HandleTimeout = 6 * 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 = 50000 )
const (
ReconnectionTime = time.Second * 30
)
const ReqTimeout = 10 * time.Second
ReqTimeout is the maximum time for complete request transfer.
const RespTimeout = 10 * time.Second
RespTimeout is the maximum time for complete response transfer.
const TtfbTimeout = 6 * 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 6 seconds.
Variables ¶
var (
ErrPeerUnknown = common.NewError(common.ErrPeerUnknown, peers.ErrPeerUnknown)
)
Functions ¶
func EncodeResponseMsg ¶
func ErrDAGConsensus ¶
func ErrMessage ¶
func NewInvVect ¶
NewInvVect returns a new InvVect using the provided type and hash.
func ReadRspCode ¶
func ReadRspCode(stream io.Reader, encoding encoder.NetworkEncoding) (common.ErrorCode, string, error)
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 common.P2PRPC, message interface{}, baseTopic string, pid peer.ID) (network.Stream, 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) GetBlockDatas ¶
func (*PeerSync) HasSyncPeer ¶
func (*PeerSync) IntellectSyncBlocks ¶
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) 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)
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) RelayInventory ¶
func (*PeerSync) SetSyncPeer ¶
func (*PeerSync) UpdateGraphState ¶
type PeerUpdateMsg ¶
type PeerUpdateMsg struct {
// contains filtered or unexported fields
}
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) EncodeResponseMsg ¶
func (s *Sync) EncodeResponseMsg(stream libp2pcore.Stream, msg interface{}) *common.Error
func (*Sync) EncodeResponseMsgPro ¶ added in v0.10.2
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 ¶ added in v0.10.4
func (*Sync) IsPeerAtLimit ¶ added in v0.10.4
func (*Sync) QNRHandler ¶
func (*Sync) Send ¶
func (s *Sync) Send(ctx context.Context, message interface{}, baseTopic string, pid peer.ID) (network.Stream, error)
Send a message to a specific peer. The returned stream may be used for reading, but has been closed for writing.
func (*Sync) SendMempoolRequest ¶ added in v0.10.5
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
}