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 H, to uint64) ([]H, error)
- func (ex *Exchange[H]) Head(ctx context.Context, opts ...header.HeadOption[H]) (H, error)
- func (ex *Exchange[H]) Start(ctx context.Context) error
- func (ex *Exchange[H]) Stop(ctx context.Context) error
- type ExchangeServer
- type Option
- func WithChainID[T ClientParameters](chainID string) Option[T]
- func WithMaxHeadersPerRangeRequest[T ClientParameters](amount uint64) Option[T]
- func WithMetrics[T parameters]() Option[T]
- func WithNetworkID[T parameters](networkID string) Option[T]
- func WithParams[T parameters](params T) Option[T]
- func WithPeerIDStore[T ClientParameters](pidstore PeerIDStore) 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 PeerIDStore
- type ServerParameters
- type Subscriber
- func (s *Subscriber[H]) Broadcast(ctx context.Context, header H, opts ...pubsub.PubOpt) error
- func (s *Subscriber[H]) SetVerifier(val func(context.Context, H) error) error
- func (s *Subscriber[H]) Start(context.Context) (err error)
- func (s *Subscriber[H]) Stop(context.Context) error
- func (s *Subscriber[H]) Subscribe() (header.Subscription[H], error)
- type SubscriberOption
- type SubscriberParams
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.1.1
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 // 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[H]] 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 NewExchange[H header.Header[H]]( host host.Host, peers peer.IDSlice, gater *conngater.BasicConnectionGater, opts ...Option[ClientParameters], ) (*Exchange[H], error)
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 and ensures that returned headers are correct against the passed one.
type ExchangeServer ¶
type ExchangeServer[H header.Header[H]] 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[H]]( 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.1.1
func WithChainID[T ClientParameters](chainID string) Option[T]
WithChainID is a functional option that configures the `chainID` parameter.
func WithMaxHeadersPerRangeRequest ¶ added in v0.1.1
func WithMaxHeadersPerRangeRequest[T ClientParameters](amount uint64) Option[T]
WithMaxHeadersPerRangeRequest is a functional option that configures the `MaxRangeRequestSize` parameter.
func WithMetrics ¶ added in v0.4.0
func WithMetrics[T parameters]() Option[T]
func WithNetworkID ¶ added in v0.1.1
WithNetworkID is a functional option that configures the `networkID` parameter.
func WithParams ¶ added in v0.2.6
func WithParams[T parameters](params T) Option[T]
WithParams is a functional option that overrides Client/ServerParameters
func WithPeerIDStore ¶ added in v0.2.9
func WithPeerIDStore[T ClientParameters](pidstore PeerIDStore) Option[T]
WithPeerIDStore is a functional option that sets a peerIDStore to be used inside the peerTracker.
func WithRangeRequestTimeout ¶ added in v0.1.1
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 PeerIDStore ¶ added in v0.2.9
type PeerIDStore interface { // Put stores the given peer IDs. Put(ctx context.Context, peers []peer.ID) error // Load loads the peer IDs from the store. Load(ctx context.Context) ([]peer.ID, error) }
PeerIDStore is a utility for persisting peer IDs of good peers to a datastore.
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 ¶
type Subscriber[H header.Header[H]] 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[H header.Header[H]]( ps *pubsub.PubSub, msgID pubsub.MsgIdFunction, opts ...SubscriberOption, ) (*Subscriber[H], error)
NewSubscriber returns a Subscriber that manages the header Module's relationship with the "header-sub" gossipsub topic.
func (*Subscriber[H]) SetVerifier ¶ added in v0.3.0
func (s *Subscriber[H]) SetVerifier(val func(context.Context, H) error) error
SetVerifier set given verification func as Header PubSub topic validator Does not punish peers if *header.VerifyError is given with Uncertain set to true.
func (*Subscriber[H]) Start ¶
func (s *Subscriber[H]) Start(context.Context) (err error)
Start starts the Subscriber and joins the instance's topic. SetVerifier must be called separately to ensure a validator is mounted on the topic.
func (*Subscriber[H]) Stop ¶
func (s *Subscriber[H]) Stop(context.Context) error
Stop closes the topic and unregisters its validator.
func (*Subscriber[H]) Subscribe ¶
func (s *Subscriber[H]) Subscribe() (header.Subscription[H], error)
Subscribe returns a new subscription to the Subscriber's topic.
type SubscriberOption ¶ added in v0.4.0
type SubscriberOption func(*SubscriberParams)
SubscriberOption is a functional option for the Subscriber.
func WithSubscriberMetrics ¶ added in v0.4.0
func WithSubscriberMetrics() SubscriberOption
WithSubscriberMetrics enables metrics collection for the Subscriber.
func WithSubscriberNetworkID ¶ added in v0.4.0
func WithSubscriberNetworkID(networkID string) SubscriberOption
WithSubscriberNetworkID sets the network ID for the Subscriber.
type SubscriberParams ¶ added in v0.4.0
type SubscriberParams struct {
// contains filtered or unexported fields
}
SubscriberParams defines the parameters for the Subscriber configurable with SubscriberOption.