synch

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: ISC Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	UpdateGraphStateTime = time.Second / 2
	DefaultRateTaskTime  = time.Second * 2
)
View Source
const (
	UpdateGraphState = "UpdateGraphState"
	PeerUpdate       = "PeerUpdate"
	PeerUpdateOrphan = "PeerUpdateOrphan"
)
View Source
const BLOCKDATA_SSZ_HEAD_SIZE = 4
View Source
const HandleTimeout = 20 * time.Second

HandleTimeout is the maximum time for complete handler.

View Source
const MaxBlockLocatorsPerMsg = 2000

MaxBlockLocatorsPerMsg is the maximum number of block locator hashes allowed per message.

View Source
const (
	// MaxInvPerMsg is the maximum number of inventory vectors that can be in a
	// single inv message.
	MaxInvPerMsg = 20000
)
View Source
const (
	MaxPBGraphStateTips = 100
)
View Source
const (
	ReconnectionTime = time.Second * 30
)
View Source
const ReqTimeout = 20 * time.Second

ReqTimeout is the maximum time for complete request transfer.

View Source
const RespTimeout = 20 * time.Second

RespTimeout is the maximum time for complete response transfer.

View Source
const TXDATA_SSZ_HEAD_SIZE = 4
View Source
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

Functions

func DecodeMessage

func DecodeMessage(stream libp2pcore.Stream, rpc peers.P2PRPC, msg interface{}) error

func EncodeMessage

func EncodeMessage(stream libp2pcore.Stream, rpc peers.P2PRPC, msg interface{}) (int, error)

func EncodeResponseMsg

func EncodeResponseMsg(rpc peers.P2PRPC, stream libp2pcore.Stream, msg interface{}, retCode common.ErrorCode) *common.Error

func ErrDAGConsensus

func ErrDAGConsensus(err error) *common.Error

func ErrMessage

func ErrMessage(err error) *common.Error

func NewInvVect

func NewInvVect(typ InvType, hash *hash.Hash) *pb.InvVect

NewInvVect returns a new InvVect using the provided type and hash.

func ReadRspCode

func ReadRspCode(stream network.Stream, rpc peers.P2PRPC) *common.Error

ReadRspCode response from a RPC stream.

func RegisterRPC

func RegisterRPC(rpc peers.P2PRPC, basetopic string, base interface{}, handle rpcHandler)

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

func SetRPCStreamDeadlines(stream network.Stream)

SetRPCStreamDeadlines sets read and write deadlines for libp2p-based connection streams.

func SetStreamReadDeadline

func SetStreamReadDeadline(stream network.Stream, duration time.Duration)

SetStreamReadDeadline for reading from libp2p connection streams, deciding when to close a connection based on a particular duration.

func SetStreamWriteDeadline

func SetStreamWriteDeadline(stream network.Stream, duration time.Duration)

SetStreamWriteDeadline for writing to libp2p connection streams, deciding when to close a connection based on a particular duration.

func UseLogger

func UseLogger(logger l.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BlockData

type BlockData struct {
	Hash  *hash.Hash
	Block *types.SerializedBlock
}

type ConnectedMsg

type ConnectedMsg struct {
	ID   peer.ID
	Conn network.Conn
}

type DisconnectedMsg

type DisconnectedMsg struct {
	ID   peer.ID
	Conn network.Conn
}

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.

func (InvType) String

func (invtype InvType) String() string

String returns the InvType in human-readable form.

func (InvType) Value

func (invtype InvType) Value() uint32

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 NewPeerSync(sy *Sync) *PeerSync

func (*PeerSync) Chain

func (ps *PeerSync) Chain() *blockchain.BlockChain

func (*PeerSync) Connected

func (ps *PeerSync) Connected(pid peer.ID, conn network.Conn)

func (*PeerSync) Connection

func (ps *PeerSync) Connection(pe *peers.Peer)

func (*PeerSync) Disconnect

func (ps *PeerSync) Disconnect(pe *peers.Peer)

func (*PeerSync) Disconnected

func (ps *PeerSync) Disconnected(pid peer.ID, conn network.Conn)

func (*PeerSync) EnforceNodeBloomFlag

func (ps *PeerSync) EnforceNodeBloomFlag(sp *peers.Peer) bool

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 (ps *PeerSync) HasSyncPeer() bool

func (*PeerSync) IntellectSyncBlocks

func (ps *PeerSync) IntellectSyncBlocks(refresh bool, pe *peers.Peer) *ProcessResult

func (*PeerSync) IsCompleteForSyncPeer

func (ps *PeerSync) IsCompleteForSyncPeer() bool

func (*PeerSync) IsCurrent

func (ps *PeerSync) IsCurrent() bool

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 (ps *PeerSync) IsInterrupt() bool

func (*PeerSync) IsNearlySynced added in v1.2.0

func (ps *PeerSync) IsNearlySynced() bool

func (*PeerSync) IsRunning

func (ps *PeerSync) IsRunning() bool

func (*PeerSync) LookupNode

func (ps *PeerSync) LookupNode(pe *peers.Peer, qnr string) error

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

func (ps *PeerSync) OnGetData(sp *peers.Peer, invList []*pb.InvVect) error

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 (ps *PeerSync) OnPeerConnected(pe *peers.Peer)

func (*PeerSync) OnPeerDisconnected

func (ps *PeerSync) OnPeerDisconnected(pe *peers.Peer)

func (*PeerSync) OnPeerUpdate

func (ps *PeerSync) OnPeerUpdate(pe *peers.Peer)

func (*PeerSync) Pause

func (ps *PeerSync) Pause() bool

func (*PeerSync) PeerUpdate

func (ps *PeerSync) PeerUpdate(pe *peers.Peer, immediately bool)

func (*PeerSync) ReConnect

func (ps *PeerSync) ReConnect(pe *peers.Peer) error

func (*PeerSync) RelayGraphState

func (ps *PeerSync) RelayGraphState()

func (*PeerSync) RelayInventory

func (ps *PeerSync) RelayInventory(nds []*notify.NotifyData)

func (*PeerSync) SetSyncPeer

func (ps *PeerSync) SetSyncPeer(pe *peers.Peer)

func (*PeerSync) Start

func (ps *PeerSync) Start() error

func (*PeerSync) Stop

func (ps *PeerSync) Stop() error

func (*PeerSync) SyncPeer

func (ps *PeerSync) SyncPeer() *peers.Peer

func (*PeerSync) SyncQNR

func (ps *PeerSync) SyncQNR(pe *peers.Peer, qnr string)

func (*PeerSync) TryAgainUpdateSyncPeer

func (ps *PeerSync) TryAgainUpdateSyncPeer(immediately bool)

func (*PeerSync) TryDisconnect

func (ps *PeerSync) TryDisconnect(pe *peers.Peer)

func (*PeerSync) UpdateGraphState

func (ps *PeerSync) UpdateGraphState(pe *peers.Peer)

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 NewSync

func NewSync(p2p peers.P2P) *Sync

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 (s *Sync) ConnectionGater(pid *peer.ID, addr ma.Multiaddr, dir network.Direction) bool

func (*Sync) EncodeResponseMsg

func (s *Sync) EncodeResponseMsg(stream libp2pcore.Stream, msg interface{}) *common.Error

func (*Sync) EncodeResponseMsgPro

func (s *Sync) EncodeResponseMsgPro(stream libp2pcore.Stream, msg interface{}, retCode common.ErrorCode) *common.Error

func (*Sync) Encoding

func (s *Sync) Encoding() encoder.NetworkEncoding

func (*Sync) GetDataHandler

func (s *Sync) GetDataHandler(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error

func (*Sync) HandlerFilterMsgAdd

func (s *Sync) HandlerFilterMsgAdd(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error

func (*Sync) HandlerFilterMsgClear

func (s *Sync) HandlerFilterMsgClear(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error

func (*Sync) HandlerFilterMsgLoad

func (s *Sync) HandlerFilterMsgLoad(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error

func (*Sync) HandlerMemPool

func (s *Sync) HandlerMemPool(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error

func (*Sync) IsInboundPeerAtLimit

func (s *Sync) IsInboundPeerAtLimit() bool

func (*Sync) IsPeerAtLimit

func (s *Sync) IsPeerAtLimit() bool

func (*Sync) IsWhitePeer

func (s *Sync) IsWhitePeer(pid peer.ID) bool

func (*Sync) LookupNode

func (s *Sync) LookupNode(pe *peers.Peer, peNode *qnode.Node)

func (*Sync) PeerSync

func (s *Sync) PeerSync() *PeerSync

func (*Sync) Peers

func (s *Sync) Peers() *peers.Status

Peers returns the peer status interface.

func (*Sync) QNRHandler

func (s *Sync) QNRHandler(ctx context.Context, msg interface{}, stream libp2pcore.Stream, pe *peers.Peer) *common.Error

func (*Sync) Send

func (s *Sync) Send(pe *peers.Peer, protocol string, message interface{}) (interface{}, error)

func (*Sync) SendMempoolRequest

func (s *Sync) SendMempoolRequest(stream network.Stream, pe *peers.Peer) *common.Error

func (*Sync) SendPingRequest

func (s *Sync) SendPingRequest(stream network.Stream, pe *peers.Peer) *common.Error

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) Start

func (s *Sync) Start() error

func (*Sync) Stop

func (s *Sync) Stop() error

func (*Sync) UpdateChainState

func (s *Sync) UpdateChainState(pe *peers.Peer, chainState *pb.ChainState, action bool)

type SyncQNRMsg

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

type UpdateGraphStateMsg

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

Jump to

Keyboard shortcuts

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