Documentation
¶
Index ¶
- Variables
- func PubsubTopicID(networkID string) string
- type ClientParameters
- type Exchange
- func (ex *Exchange[H]) Get(ctx context.Context, hash header.Hash) (H, error)
- func (ex *Exchange[H]) GetByHeight(ctx context.Context, height uint64) (H, error)
- func (ex *Exchange[H]) GetRangeByHeight(ctx context.Context, from, amount uint64) ([]H, error)
- func (ex *Exchange[H]) GetVerifiedRange(ctx context.Context, from H, amount uint64) ([]H, error)
- func (ex *Exchange[H]) Head(ctx context.Context) (H, error)
- func (ex *Exchange[H]) InitMetrics() error
- func (ex *Exchange[H]) Start(context.Context) error
- func (ex *Exchange[H]) Stop(context.Context) error
- type ExchangeServer
- type Option
- func WithChainID[T ClientParameters](chainID string) Option[T]
- func WithMaxHeadersPerRangeRequest[T ClientParameters](amount uint64) Option[T]
- func WithNetworkID[T parameters](networkID string) Option[T]
- func WithRangeRequestTimeout[T parameters](duration time.Duration) Option[T]
- func WithReadDeadline[T ServerParameters](deadline time.Duration) Option[T]
- func WithWriteDeadline[T ServerParameters](deadline time.Duration) Option[T]
- type ServerParameters
- type Subscriber
- func (p *Subscriber[H]) AddValidator(val func(context.Context, H) pubsub.ValidationResult) error
- func (p *Subscriber[H]) Broadcast(ctx context.Context, header H, opts ...pubsub.PubOpt) error
- func (p *Subscriber[H]) Start(context.Context) (err error)
- func (p *Subscriber[H]) Stop(context.Context) error
- func (p *Subscriber[H]) Subscribe() (header.Subscription[H], error)
Constants ¶
This section is empty.
Variables ¶
var GossibSubScore = pubsub.TopicScoreParams{ TopicWeight: 0.1, TimeInMeshWeight: 0.0002778, TimeInMeshQuantum: time.Second, TimeInMeshCap: 1, FirstMessageDeliveriesWeight: 5, FirstMessageDeliveriesDecay: pubsub.ScoreParameterDecay(time.Hour), FirstMessageDeliveriesCap: 100, InvalidMessageDeliveriesWeight: -1000, InvalidMessageDeliveriesDecay: pubsub.ScoreParameterDecay(time.Hour), }
GossibSubScore provides a set of recommended parameters for header GossipSub topic, a.k.a HeaderSub.
Functions ¶
func PubsubTopicID ¶ added in v0.7.0
Types ¶
type ClientParameters ¶
type ClientParameters struct { // MaxHeadersPerRangeRequest defines the max amount of headers that can be requested per 1 request. MaxHeadersPerRangeRequest uint64 // RangeRequestTimeout defines a timeout after which the session will try to re-request headers // from another peer. RangeRequestTimeout time.Duration // TrustedPeersRequestTimeout a timeout for any request to a trusted peer. TrustedPeersRequestTimeout time.Duration // contains filtered or unexported fields }
ClientParameters is the set of parameters that must be configured for the exchange.
func DefaultClientParameters ¶
func DefaultClientParameters() ClientParameters
DefaultClientParameters returns the default params to configure the store.
func (*ClientParameters) Validate ¶
func (p *ClientParameters) Validate() error
type Exchange ¶
type Exchange[H header.Header] struct { Params ClientParameters // contains filtered or unexported fields }
Exchange enables sending outbound HeaderRequests to the network as well as handling inbound HeaderRequests from the network.
func NewExchange ¶
func (*Exchange[H]) Get ¶
Get performs a request for the Header by the given hash corresponding to the RawHeader. Note that the Header must be verified thereafter.
func (*Exchange[H]) GetByHeight ¶
GetByHeight performs a request for the Header at the given height to the network. Note that the Header must be verified thereafter.
func (*Exchange[H]) GetRangeByHeight ¶
GetRangeByHeight performs a request for the given range of Headers to the network. Note that the Headers must be verified thereafter.
func (*Exchange[H]) GetVerifiedRange ¶
GetVerifiedRange performs a request for the given range of Headers to the network and ensures that returned headers are correct against the passed one.
func (*Exchange[H]) Head ¶
Head requests the latest Header. Note that the Header must be verified thereafter. NOTE: It is fine to continue handling head request if the timeout will be reached. As we are requesting head from multiple trusted peers, we may already have some headers when the timeout will be reached.
func (*Exchange[H]) InitMetrics ¶ added in v0.7.1
type ExchangeServer ¶
type ExchangeServer[H header.Header] struct { Params ServerParameters // contains filtered or unexported fields }
ExchangeServer represents the server-side component for responding to inbound header-related requests.
func NewExchangeServer ¶
func NewExchangeServer[H header.Header]( host host.Host, store header.Store[H], opts ...Option[ServerParameters], ) (*ExchangeServer[H], error)
NewExchangeServer returns a new P2P server that handles inbound header-related requests.
type Option ¶
type Option[T parameters] func(*T)
Option is the functional option that is applied to the exchange instance to configure parameters.
func WithChainID ¶ added in v0.7.0
func WithChainID[T ClientParameters](chainID string) Option[T]
WithChainID is a functional option that configures the `chainID` parameter.
func WithMaxHeadersPerRangeRequest ¶ added in v0.7.0
func WithMaxHeadersPerRangeRequest[T ClientParameters](amount uint64) Option[T]
WithMaxHeadersPerRangeRequest is a functional option that configures the // `MaxRangeRequestSize` parameter.
func WithNetworkID ¶ added in v0.7.0
WithNetworkID is a functional option that configures the `networkID` parameter.
func WithRangeRequestTimeout ¶ added in v0.7.0
WithRangeRequestTimeout is a functional option that configures the `RangeRequestTimeout` parameter.
func WithReadDeadline ¶
func WithReadDeadline[T ServerParameters](deadline time.Duration) Option[T]
WithReadDeadline is a functional option that configures the `WithReadDeadline` parameter.
func WithWriteDeadline ¶
func WithWriteDeadline[T ServerParameters](deadline time.Duration) Option[T]
WithWriteDeadline is a functional option that configures the `WriteDeadline` parameter.
type ServerParameters ¶
type ServerParameters struct { // WriteDeadline sets the timeout for sending messages to the stream WriteDeadline time.Duration // ReadDeadline sets the timeout for reading messages from the stream ReadDeadline time.Duration // RangeRequestTimeout defines a timeout after which the session will try to re-request headers // from another peer. RangeRequestTimeout time.Duration // contains filtered or unexported fields }
ServerParameters is the set of parameters that must be configured for the exchange.
func DefaultServerParameters ¶
func DefaultServerParameters() ServerParameters
DefaultServerParameters returns the default params to configure the store.
func (*ServerParameters) Validate ¶
func (p *ServerParameters) Validate() error
type Subscriber ¶
Subscriber manages the lifecycle and relationship of header Module with the "header-sub" gossipsub topic.
func NewSubscriber ¶
func NewSubscriber[H header.Header]( ps *pubsub.PubSub, msgID pubsub.MsgIdFunction, networkID string, ) *Subscriber[H]
NewSubscriber returns a Subscriber that manages the header Module's relationship with the "header-sub" gossipsub topic.
func (*Subscriber[H]) AddValidator ¶
func (p *Subscriber[H]) AddValidator(val func(context.Context, H) pubsub.ValidationResult) error
AddValidator applies basic pubsub validator for the topic.
func (*Subscriber[H]) Start ¶
func (p *Subscriber[H]) Start(context.Context) (err error)
Start starts the Subscriber, registering a topic validator for the "header-sub" topic and joining it.
func (*Subscriber[H]) Stop ¶
func (p *Subscriber[H]) Stop(context.Context) error
Stop closes the topic and unregisters its validator.
func (*Subscriber[H]) Subscribe ¶
func (p *Subscriber[H]) Subscribe() (header.Subscription[H], error)
Subscribe returns a new subscription to the Subscriber's topic.