p2p

package
v0.3.1-fixed-account Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

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

type Exchange struct {
	// 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 NewExchange(host host.Host, peers peer.IDSlice) *Exchange

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

func (ex *Exchange) GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error)

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) Head

func (ex *Exchange) Head(ctx context.Context) (*header.ExtendedHeader, error)

Head requests the latest ExtendedHeader. Note that the ExtendedHeader must be verified thereafter.

type ExchangeServer

type ExchangeServer struct {
	// 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) *ExchangeServer

NewExchangeServer returns a new P2P server that handles inbound header-related requests.

func (*ExchangeServer) Start

func (serv *ExchangeServer) Start(context.Context) error

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

func (*ExchangeServer) Stop

func (serv *ExchangeServer) Stop(context.Context) error

Stop removes the stream handler for serving header-related requests.

type Subscriber

type Subscriber struct {
	// contains filtered or unexported fields
}

Subscriber manages the lifecycle and relationship of header Service with the "header-sub" gossipsub topic.

func NewSubscriber

func NewSubscriber(ps *pubsub.PubSub) *Subscriber

NewSubscriber returns a Subscriber that manages the header Service'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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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