Documentation ¶
Index ¶
- Constants
- type ClientParameters
- type Exchange
- func (ex *Exchange) Get(ctx context.Context, hash tmbytes.HexBytes) (*header.ExtendedHeader, error)
- func (ex *Exchange) GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error)
- func (ex *Exchange) GetRangeByHeight(ctx context.Context, from, amount uint64) ([]*header.ExtendedHeader, error)
- func (ex *Exchange) GetVerifiedRange(ctx context.Context, from *header.ExtendedHeader, amount uint64) ([]*header.ExtendedHeader, error)
- func (ex *Exchange) Head(ctx context.Context) (*header.ExtendedHeader, error)
- func (ex *Exchange) Start(context.Context) error
- func (ex *Exchange) 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 WithReadDeadline[T ServerParameters](deadline time.Duration) Option[T]
- func WithWriteDeadline[T ServerParameters](deadline time.Duration) Option[T]
- type ServerParameters
- type Subscriber
- func (p *Subscriber) AddValidator(val header.Validator) error
- func (p *Subscriber) Broadcast(ctx context.Context, header *header.ExtendedHeader, opts ...pubsub.PubOpt) error
- func (p *Subscriber) Start(context.Context) (err error)
- func (p *Subscriber) Stop(context.Context) error
- func (p *Subscriber) Subscribe() (header.Subscription, error)
Constants ¶
const PubSubTopic = "header-sub"
PubSubTopic hardcodes the name of the ExtendedHeader gossipsub topic.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientParameters ¶ added in v0.5.0
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 // MaxHeadersPerRequest defines the max amount of headers that can be requested per 1 request. MaxHeadersPerRequest uint64 // 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 // MaxTrackerSize specifies the max amount of peers that can be added to the peerTracker. MaxPeerTrackerSize int }
ClientParameters is the set of parameters that must be configured for the exchange.
func DefaultClientParameters ¶ added in v0.5.0
func DefaultClientParameters() ClientParameters
DefaultClientParameters returns the default params to configure the store.
func (*ClientParameters) Validate ¶ added in v0.5.0
func (p *ClientParameters) Validate() error
type Exchange ¶
type Exchange struct { Params ClientParameters // contains filtered or unexported fields }
Exchange enables sending outbound ExtendedHeaderRequests to the network as well as handling inbound ExtendedHeaderRequests from the network.
func NewExchange ¶
func (*Exchange) Get ¶
Get performs a request for the ExtendedHeader by the given hash corresponding to the RawHeader. Note that the ExtendedHeader must be verified thereafter.
func (*Exchange) GetByHeight ¶
GetByHeight performs a request for the ExtendedHeader at the given height to the network. Note that the ExtendedHeader must be verified thereafter.
func (*Exchange) GetRangeByHeight ¶
func (ex *Exchange) GetRangeByHeight(ctx context.Context, from, amount uint64) ([]*header.ExtendedHeader, error)
GetRangeByHeight performs a request for the given range of ExtendedHeaders to the network. Note that the ExtendedHeaders must be verified thereafter.
func (*Exchange) GetVerifiedRange ¶ added in v0.5.0
func (ex *Exchange) GetVerifiedRange( ctx context.Context, from *header.ExtendedHeader, amount uint64, ) ([]*header.ExtendedHeader, error)
GetVerifiedRange performs a request for the given range of ExtendedHeaders to the network and ensures that returned headers are correct against the passed one.
func (*Exchange) Head ¶
Head requests the latest ExtendedHeader. Note that the ExtendedHeader 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 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( host host.Host, store header.Store, protocolSuffix string, opts ...Option[ServerParameters], ) (*ExchangeServer, error)
NewExchangeServer returns a new P2P server that handles inbound header-related requests.
type Option ¶ added in v0.5.0
type Option[T parameters] func(*T)
Option is the functional option that is applied to the exchange instance to configure parameters.
func WithDefaultScore ¶ added in v0.5.0
func WithDefaultScore[T ClientParameters](score float32) Option[T]
WithDefaultScore is a functional option that configures the `DefaultScore` parameter.
func WithMaxAwaitingTime ¶ added in v0.5.0
func WithMaxAwaitingTime[T ClientParameters](duration time.Duration) Option[T]
WithMaxAwaitingTime is a functional option that configures the `MaxAwaitingTime` parameter.
func WithMaxHeadersPerRequest ¶ added in v0.5.0
func WithMaxHeadersPerRequest[T ClientParameters](amount uint64) Option[T]
WithMaxHeadersPerRequest is a functional option that configures the // `MaxRequestSize` parameter.
func WithMaxRequestSize ¶ added in v0.5.0
WithMaxRequestSize is a functional option that configures the `MaxRequestSize` parameter.
func WithMaxTrackerSize ¶ added in v0.5.0
func WithMaxTrackerSize[T ClientParameters](size int) Option[T]
WithMaxTrackerSize is a functional option that configures the `MaxTrackerSize` parameter.
func WithMinResponses ¶ added in v0.5.0
func WithMinResponses[T ClientParameters](responses int) Option[T]
WithMinResponses is a functional option that configures the `MinResponses` parameter.
func WithReadDeadline ¶ added in v0.5.0
func WithReadDeadline[T ServerParameters](deadline time.Duration) Option[T]
WithReadDeadline is a functional option that configures the `WithReadDeadline` parameter.
func WithWriteDeadline ¶ added in v0.5.0
func WithWriteDeadline[T ServerParameters](deadline time.Duration) Option[T]
WithWriteDeadline is a functional option that configures the `WriteDeadline` parameter.
type ServerParameters ¶ added in v0.5.0
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 }
ServerParameters is the set of parameters that must be configured for the exchange.
func DefaultServerParameters ¶ added in v0.5.0
func DefaultServerParameters() ServerParameters
DefaultServerParameters returns the default params to configure the store.
func (*ServerParameters) Validate ¶ added in v0.5.0
func (p *ServerParameters) Validate() error
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber manages the lifecycle and relationship of header Module with the "header-sub" gossipsub topic.
func NewSubscriber ¶
func NewSubscriber(ps *pubsub.PubSub) *Subscriber
NewSubscriber returns a Subscriber that manages the header Module's relationship with the "header-sub" gossipsub topic.
func (*Subscriber) AddValidator ¶
func (p *Subscriber) AddValidator(val header.Validator) error
AddValidator applies basic pubsub validator for the topic.
func (*Subscriber) Broadcast ¶
func (p *Subscriber) Broadcast(ctx context.Context, header *header.ExtendedHeader, opts ...pubsub.PubOpt) error
Broadcast broadcasts the given ExtendedHeader to the topic.
func (*Subscriber) Start ¶
func (p *Subscriber) Start(context.Context) (err error)
Start starts the Subscriber, registering a topic validator for the "header-sub" topic and joining it.
func (*Subscriber) Stop ¶
func (p *Subscriber) Stop(context.Context) error
Stop closes the topic and unregisters its validator.
func (*Subscriber) Subscribe ¶
func (p *Subscriber) Subscribe() (header.Subscription, error)
Subscribe returns a new subscription to the Subscriber's topic.