shrexsub

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: Apache-2.0 Imports: 7 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, share.DataHash) error

BroadcastFn aliases the function that broadcasts the DataHash.

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(validate Validator) error

AddValidator registers given Validator for EDS notifications (DataHash). Any amount of Validators can be registered.

func (*PubSub) Broadcast

func (s *PubSub) Broadcast(ctx context.Context, data share.DataHash) 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) (share.DataHash, error)

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

type Validator

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

Jump to

Keyboard shortcuts

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