Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Option
- type Protocol
- func (p *Protocol) Close()
- func (p *Protocol) GetBlockHashes(ctx context.Context, bns []uint64, opts ...Option) (hashes []common.Hash, stid sttypes.StreamID, err error)
- func (p *Protocol) GetBlocksByHashes(ctx context.Context, hs []common.Hash, opts ...Option) (blocks []*types.Block, stid sttypes.StreamID, err error)
- func (p *Protocol) GetBlocksByNumber(ctx context.Context, bns []uint64, opts ...Option) (blocks []*types.Block, stid sttypes.StreamID, err error)
- func (p *Protocol) GetCurrentBlockNumber(ctx context.Context, opts ...Option) (bn uint64, stid sttypes.StreamID, err error)
- func (p *Protocol) GetStreamManager() streammanager.StreamManager
- func (p *Protocol) HandleStream(raw libp2p_network.Stream)
- func (p *Protocol) Match(targetID string) bool
- func (p *Protocol) NumStreams() int
- func (p *Protocol) ProtoID() sttypes.ProtoID
- func (p *Protocol) RemoveStream(stID sttypes.StreamID)
- func (p *Protocol) Specifier() string
- func (p *Protocol) Start()
- func (p *Protocol) SubscribeAddStreamEvent(ch chan<- streammanager.EvtStreamAdded) event.Subscription
- func (p *Protocol) Version() *version.Version
Constants ¶
const ( // GetBlockHashesAmountCap is the cap of GetBlockHashes request GetBlockHashesAmountCap = 50 // GetBlocksByNumAmountCap is the cap of request of a single GetBlocksByNum request. // This number has an effect on maxMsgBytes as 20MB defined in github.com/astra-net/astra-network/p2p/stream/types. // Since we have an assumption that rlp encoded block size is smaller than 2MB (p2p.node.MaxMessageSize), // so the max size of a stream message is capped at 2MB * 10 = 20MB. GetBlocksByNumAmountCap = 10 // GetBlocksByHashesAmountCap is the cap of request of single GetBlocksByHashes request // This number has an effect on maxMsgBytes as 20MB defined in github.com/astra-net/astra-network/p2p/stream/types. // See comments for GetBlocksByNumAmountCap. GetBlocksByHashesAmountCap = 10 )
Variables ¶
var ( // MyVersion is the version of sync protocol of the local node MyVersion = version100 // MinVersion is the minimum version for matching function MinVersion = version100 )
var ( // WithHighPriority instruct the request manager to do the request with high // priority WithHighPriority = requestmanager.WithHighPriority // WithBlacklist instruct the request manager not to assign the request to the // given streamID WithBlacklist = requestmanager.WithBlacklist // WithWhitelist instruct the request manager only to assign the request to the // given streamID WithWhitelist = requestmanager.WithWhitelist )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Chain engine.ChainReader Host libp2p_host.Host Discovery discovery.Discovery ShardID nodeconfig.ShardID Network nodeconfig.NetworkType // stream manager config SmSoftLowCap int SmHardLowCap int SmHiCap int DiscBatch int }
Config is the sync protocol config
type Option ¶
type Option = requestmanager.RequestOption
Option is the additional option to do requests. Currently, two options are supported:
- WithHighPriority - do the request in high priority.
- WithBlacklist - do the request without the given stream ids as blacklist
- WithWhitelist - do the request only with the given stream ids
type Protocol ¶
type Protocol struct {
// contains filtered or unexported fields
}
Protocol is the protocol for sync streaming
func NewProtocol ¶
NewProtocol creates a new sync protocol
func (*Protocol) GetBlockHashes ¶
func (p *Protocol) GetBlockHashes(ctx context.Context, bns []uint64, opts ...Option) (hashes []common.Hash, stid sttypes.StreamID, err error)
GetBlockHashes do getBlockHashesRequest through sync stream protocol. Return the hash of the given block number. If a block is unknown, the hash will be emptyHash.
func (*Protocol) GetBlocksByHashes ¶
func (p *Protocol) GetBlocksByHashes(ctx context.Context, hs []common.Hash, opts ...Option) (blocks []*types.Block, stid sttypes.StreamID, err error)
GetBlocksByHashes do getBlocksByHashesRequest through sync stream protocol.
func (*Protocol) GetBlocksByNumber ¶
func (p *Protocol) GetBlocksByNumber(ctx context.Context, bns []uint64, opts ...Option) (blocks []*types.Block, stid sttypes.StreamID, err error)
GetBlocksByNumber do getBlocksByNumberRequest through sync stream protocol. Return the block as result, target stream id, and error
func (*Protocol) GetCurrentBlockNumber ¶
func (p *Protocol) GetCurrentBlockNumber(ctx context.Context, opts ...Option) (bn uint64, stid sttypes.StreamID, err error)
GetCurrentBlockNumber get the current block number from remote node
func (*Protocol) GetStreamManager ¶
func (p *Protocol) GetStreamManager() streammanager.StreamManager
GetStreamManager get the underlying stream manager for upper level stream operations
func (*Protocol) HandleStream ¶
func (p *Protocol) HandleStream(raw libp2p_network.Stream)
HandleStream is the stream handle function being registered to libp2p.
func (*Protocol) NumStreams ¶
NumStreams return the streams with minimum version. Note: nodes with sync version smaller than minVersion is not counted.
func (*Protocol) RemoveStream ¶
RemoveStream removes the stream of the given stream ID
func (*Protocol) SubscribeAddStreamEvent ¶
func (p *Protocol) SubscribeAddStreamEvent(ch chan<- streammanager.EvtStreamAdded) event.Subscription
SubscribeAddStreamEvent subscribe the stream add event