shrexsub

package
v0.0.0-...-4e9d6c2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastFn

type BroadcastFn func(context.Context, Notification) error

BroadcastFn aliases the function that broadcasts the DataHash.

type Notification

type Notification struct {
	DataHash share.DataHash
	Height   uint64
}

Notification is the format of message sent by Broadcaster

type PubSub

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

PubSub manages receiving and propagating the EDS from/to the network over "eds-sub" subscription.

func NewPubSub

func NewPubSub(ctx context.Context, h host.Host, networkID string) (*PubSub, error)

NewPubSub creates a libp2p.PubSub wrapper.

func (*PubSub) AddValidator

func (s *PubSub) AddValidator(v ValidatorFn) error

AddValidator registers given ValidatorFn for EDS notifications. Any amount of Validators can be registered.

func (*PubSub) Broadcast

func (s *PubSub) Broadcast(ctx context.Context, notification Notification) error

Broadcast sends the EDS notification (DataHash) to every connected peer.

func (*PubSub) Start

func (s *PubSub) Start(context.Context) error

Start creates an instances of FloodSub and joins specified topic.

func (*PubSub) Stop

func (s *PubSub) Stop(context.Context) error

Stop completely stops the PubSub: * Unregisters all the added Validators * Closes the `ShrEx/Sub` topic

func (*PubSub) Subscribe

func (s *PubSub) Subscribe() (*Subscription, error)

Subscribe provides a new Subscription for EDS notifications.

type Subscription

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

Subscription is a wrapper over pubsub.Subscription that handles receiving an EDS DataHash from other peers.

func (*Subscription) Cancel

func (subs *Subscription) Cancel()

Cancel stops the subscription.

func (*Subscription) Next

func (subs *Subscription) Next(ctx context.Context) (Notification, error)

Next blocks the caller until any new EDS DataHash notification arrives. Returns only notifications which successfully pass validation.

type ValidatorFn

ValidatorFn is an injectable func and governs EDS notification msg validity. It receives the notification and sender peer and expects the validation result. ValidatorFn is allowed to be blocking for an indefinite time or until the context is canceled.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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