p2p

package
v0.3.1-dirty Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: Apache-2.0 Imports: 18 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

func MarshalExtendedHeaderRequest

func MarshalExtendedHeaderRequest(in *ExtendedHeaderRequest) ([]byte, error)

MarshalExtendedHeaderRequest serializes the given ExtendedHeaderRequest to bytes using protobuf. Paired with UnmarshalExtendedHeaderRequest.

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

func (ex *Exchange) RequestByHash(ctx context.Context, hash tmbytes.HexBytes) (*header.ExtendedHeader, error)

func (*Exchange) RequestHead

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

func (*Exchange) RequestHeader

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

func (*Exchange) RequestHeaders

func (ex *Exchange) RequestHeaders(ctx context.Context, from, amount uint64) ([]*header.ExtendedHeader, error)

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 ExtendedHeaderRequest

type ExtendedHeaderRequest struct {
	Origin uint64 // block height from which to request ExtendedHeaders
	Amount uint64 // amount of desired ExtendedHeaders starting from Origin, syncing in ascending order
}

ExtendedHeaderRequest is the packet format for nodes to request ExtendedHeaders from the network.

func UnmarshalExtendedHeaderRequest

func UnmarshalExtendedHeaderRequest(data []byte) (*ExtendedHeaderRequest, error)

UnmarshalExtendedHeaderRequest deserializes given data into a new ExtendedHeader using protobuf. Paired with MarshalExtendedHeaderRequest.

func (*ExtendedHeaderRequest) MarshalBinary

func (ehr *ExtendedHeaderRequest) MarshalBinary() ([]byte, error)

MarshalBinary marshals ExtendedHeaderRequest to binary.

func (*ExtendedHeaderRequest) ToProto

func (*ExtendedHeaderRequest) UnmarshalBinary

func (ehr *ExtendedHeaderRequest) UnmarshalBinary(data []byte) error

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