p2p

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func PubsubTopicID(networkID string) string

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 NewExchange[H header.Header](
	host host.Host,
	peers peer.IDSlice,
	connGater *conngater.BasicConnectionGater,
	opts ...Option[ClientParameters],
) (*Exchange[H], error)

func (*Exchange[H]) Get

func (ex *Exchange[H]) Get(ctx context.Context, hash header.Hash) (H, error)

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

func (ex *Exchange[H]) GetByHeight(ctx context.Context, height uint64) (H, error)

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

func (ex *Exchange[H]) GetRangeByHeight(ctx context.Context, from, amount uint64) ([]H, error)

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

func (ex *Exchange[H]) GetVerifiedRange(
	ctx context.Context,
	from H,
	amount uint64,
) ([]H, error)

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

func (ex *Exchange[H]) Head(ctx context.Context) (H, error)

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

func (ex *Exchange[H]) InitMetrics() error

func (*Exchange[H]) Start

func (ex *Exchange[H]) Start(context.Context) error

func (*Exchange[H]) Stop

func (ex *Exchange[H]) Stop(context.Context) error

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.

func (*ExchangeServer[H]) Start

func (serv *ExchangeServer[H]) Start(context.Context) error

Start sets the stream handler for inbound header-related requests.

func (*ExchangeServer[H]) Stop

func (serv *ExchangeServer[H]) Stop(context.Context) error

Stop removes the stream handler for serving 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

func WithNetworkID[T parameters](networkID string) Option[T]

WithNetworkID is a functional option that configures the `networkID` parameter.

func WithRangeRequestTimeout added in v0.7.0

func WithRangeRequestTimeout[T parameters](duration time.Duration) Option[T]

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

type Subscriber[H header.Header] 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](
	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]) Broadcast

func (p *Subscriber[H]) Broadcast(ctx context.Context, header H, opts ...pubsub.PubOpt) error

Broadcast broadcasts the given Header to 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL