Documentation ¶
Index ¶
- 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]) Start(context.Context) error
- func (ex *Exchange[H]) Stop(context.Context) error
- type ExchangeServer
- type Option
- func WithDefaultScore[T ClientParameters](score float32) Option[T]
- func WithMaxAwaitingTime[T ClientParameters](duration time.Duration) Option[T]
- func WithMaxHeadersPerRequest[T ClientParameters](amount uint64) Option[T]
- func WithMaxRequestSize[T parameters](size uint64) Option[T]
- func WithMaxTrackerSize[T ClientParameters](size int) Option[T]
- func WithMinResponses[T ClientParameters](responses int) Option[T]
- func WithProtocolSuffix[T parameters](protocolSuffix string) Option[T]
- func WithReadDeadline[T ServerParameters](deadline time.Duration) Option[T]
- func WithRequestTimeout[T parameters](duration 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 ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientParameters ¶
type ClientParameters struct { // the target minimum amount of responses with the same chain head MinResponses int // MaxRequestSize defines the max amount of headers that can be handled at once. MaxRequestSize uint64 // TODO: Rename to MaxRangeRequestSize // MaxHeadersPerRequest defines the max amount of headers that can be requested per 1 request. MaxHeadersPerRequest uint64 // TODO: Rename to MaxHeadersPerRangeRequest // MaxAwaitingTime specifies the duration that gives to the disconnected peer to be back online, // otherwise it will be removed on the next GC cycle. MaxAwaitingTime time.Duration // DefaultScore specifies the score for newly connected peers. DefaultScore float32 // RequestTimeout defines a timeout after which the session will try to re-request headers // from another peer. RequestTimeout time.Duration // TODO: Rename to RangeRequestTimeout // TrustedPeersRequestTimeout a timeout for any request to a trusted peer. TrustedPeersRequestTimeout time.Duration // MaxTrackerSize specifies the max amount of peers that can be added to the peerTracker. MaxPeerTrackerSize int // contains filtered or unexported fields }
ClientParameters is the set of parameters that must be configured for the exchange. TODO: #1667
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.
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 WithDefaultScore ¶
func WithDefaultScore[T ClientParameters](score float32) Option[T]
WithDefaultScore is a functional option that configures the `DefaultScore` parameter.
func WithMaxAwaitingTime ¶
func WithMaxAwaitingTime[T ClientParameters](duration time.Duration) Option[T]
WithMaxAwaitingTime is a functional option that configures the `MaxAwaitingTime` parameter.
func WithMaxHeadersPerRequest ¶
func WithMaxHeadersPerRequest[T ClientParameters](amount uint64) Option[T]
WithMaxHeadersPerRequest is a functional option that configures the // `MaxRequestSize` parameter.
func WithMaxRequestSize ¶
WithMaxRequestSize is a functional option that configures the `MaxRequestSize` parameter.
func WithMaxTrackerSize ¶
func WithMaxTrackerSize[T ClientParameters](size int) Option[T]
WithMaxTrackerSize is a functional option that configures the `MaxTrackerSize` parameter.
func WithMinResponses ¶
func WithMinResponses[T ClientParameters](responses int) Option[T]
WithMinResponses is a functional option that configures the `MinResponses` parameter.
func WithProtocolSuffix ¶
WithProtocolSuffix is a functional option that configures the `protocolSuffix` parameter.
func WithReadDeadline ¶
func WithReadDeadline[T ServerParameters](deadline time.Duration) Option[T]
WithReadDeadline is a functional option that configures the `WithReadDeadline` parameter.
func WithRequestTimeout ¶
WithRequestTimeout is a functional option that configures the `RequestTimeout` 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 // MaxRequestSize defines the max amount of headers that can be handled at once. MaxRequestSize uint64 // RequestTimeout defines a timeout after which the session will try to re-request headers // from another peer. RequestTimeout 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, protocolSuffix 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.