synch

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: ISC Imports: 30 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"
	// 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"
)
View Source
const BLOCKDATA_SSZ_HEAD_SIZE = 4
View Source
const HandleTimeout = 5 * 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 = 50000
)
View Source
const (
	ReconnectionTime = time.Second * 30
)
View Source
const ReqTimeout = 10 * time.Second

ReqTimeout is the maximum time for complete request transfer.

View Source
const RespTimeout = 10 * time.Second

RespTimeout is the maximum time for complete response transfer.

View Source
const TtfbTimeout = 5 * 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 5 seconds.

Variables

Functions

func EncodeResponseMsg

func EncodeResponseMsg(rpc common.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 io.Reader, encoding encoder.NetworkEncoding) (common.ErrorCode, string, error)

ReadRspCode response from a RPC stream.

func RegisterRPC

func RegisterRPC(rpc common.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 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

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

func (ps *PeerSync) GetBlockDatas(pe *peers.Peer, blocks []*hash.Hash)

func (*PeerSync) GetBlocks

func (ps *PeerSync) GetBlocks(pe *peers.Peer, blocks []*hash.Hash)

func (*PeerSync) HasSyncPeer

func (ps *PeerSync) HasSyncPeer() bool

func (*PeerSync) IntellectSyncBlocks

func (ps *PeerSync) IntellectSyncBlocks(refresh bool)

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

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, orphan bool)

func (*PeerSync) Pause

func (ps *PeerSync) Pause() chan<- struct{}

func (*PeerSync) PeerUpdate

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

func (*PeerSync) RelayInventory

func (ps *PeerSync) RelayInventory(data interface{})

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

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

type PeerUpdateMsg

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

type Sync

type Sync struct {
	PeerInterval time.Duration
	// contains filtered or unexported fields
}

func NewSync

func NewSync(p2p common.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) EncodeResponseMsg

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

func (*Sync) EncodeResponseMsgPro added in v0.10.2

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) *common.Error

func (*Sync) HandlerFilterMsgAdd

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

func (*Sync) HandlerFilterMsgClear

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

func (*Sync) HandlerFilterMsgLoad

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

func (*Sync) HandlerMemPool

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

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) *common.Error

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

func (s *Sync) SendPingRequest(ctx context.Context, id peer.ID) 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