broadcast

package
v0.0.0-...-8cb8a38 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolID  = "/fury-relayer/broadcast/1.0.0"
	ServiceName = "fury-relayer.broadcast"
)

Variables

This section is empty.

Functions

func PeerIDMapToSlice

func PeerIDMapToSlice(peerIDs map[peer.ID]struct{}) []peer.ID

PeerIDMapToSlice converts a map of peer.ID to a slice of peer.ID.

Types

type BroadcastHandler

type BroadcastHandler interface {
	// RawMessage is called when a raw message from any peer is received.
	RawMessage(msg pending_store.MessageWithPeerMetadata)
	// ValidatedMessage is called when a message is confirmed to be the same
	// from all peers.
	ValidatedMessage(msg types.BroadcastMessage)
	// MismatchMessage is called when a message with the same message ID is
	// different from other peer messages, i.g. a faulty or malicious node.
	MismatchMessage(msg pending_store.MessageWithPeerMetadata)
}

BroadcastHandler defines the interface for handling broadcast messages.

type BroadcastNotif

type BroadcastNotif P2PBroadcaster

func (*BroadcastNotif) ClosedStream

func (p *BroadcastNotif) ClosedStream(n network.Network, s network.Stream)

func (*BroadcastNotif) Connected

func (p *BroadcastNotif) Connected(n network.Network, c network.Conn)

func (*BroadcastNotif) Disconnected

func (p *BroadcastNotif) Disconnected(n network.Network, c network.Conn)

func (*BroadcastNotif) Listen

func (p *BroadcastNotif) Listen(n network.Network, _ ma.Multiaddr)

func (*BroadcastNotif) ListenClose

func (p *BroadcastNotif) ListenClose(n network.Network, _ ma.Multiaddr)

func (*BroadcastNotif) OpenedStream

func (p *BroadcastNotif) OpenedStream(n network.Network, s network.Stream)

type Broadcaster

type Broadcaster interface {
	BroadcastMessage(
		ctx context.Context,
		pb types.PeerMessage,
		recipients []peer.ID,
		TTLSeconds uint64,
	) error
}

Broadcaster defines the interface that a reliable broadcaster must implement.

type BroadcasterHook

type BroadcasterHook interface {
	// Run before a raw message is broadcasted and can be used to modify the
	// message.
	BeforeBroadcastRawMessage(b *P2PBroadcaster, target peer.ID, pb *proto.Message)
}

BroadcasterHook defines the interface for broadcaster hooks. This is not exported as it should only be used for testing.

type BroadcasterOption

type BroadcasterOption func(*P2PBroadcaster) error

BroadcasterOption defines an option for the Broadcaster.

func WithHandler

func WithHandler(handler BroadcastHandler) BroadcasterOption

WithHandler sets the message handler for the BroadcasterOption.

func WithHook

func WithHook(hook BroadcasterHook) BroadcasterOption

WithHook sets the message broadcast hook for the BroadcasterOption.

type NoOpBroadcastHandler

type NoOpBroadcastHandler struct{}

NoOpBroadcastHandler is a BroadcastHandler that does nothing.

func (*NoOpBroadcastHandler) MismatchMessage

func (*NoOpBroadcastHandler) RawMessage

func (*NoOpBroadcastHandler) ValidatedMessage

func (h *NoOpBroadcastHandler) ValidatedMessage(msg types.BroadcastMessage)

type NoOpBroadcaster

type NoOpBroadcaster struct{}

func (*NoOpBroadcaster) BroadcastMessage

func (b *NoOpBroadcaster) BroadcastMessage(
	ctx context.Context,
	pb types.PeerMessage,
	recipients []peer.ID,
	TTLSeconds uint64,
) error

type P2PBroadcaster

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

P2PBroadcaster is a reliable broadcaster to ensure that all connected peers receive the same message.

func NewBroadcaster

func NewBroadcaster(
	ctx context.Context,
	host host.Host,
	options ...BroadcasterOption,
) (*P2PBroadcaster, error)

NewBroadcaster returns a new Broadcaster

func (*P2PBroadcaster) BroadcastMessage

func (b *P2PBroadcaster) BroadcastMessage(
	ctx context.Context,
	pb types.PeerMessage,
	recipients []peer.ID,
	TTLSeconds uint64,
) error

BroadcastMessage marshals the proto.Message as Any, wraps it in MessageData, and it to all connected peers.

func (*P2PBroadcaster) GetPeerCount

func (b *P2PBroadcaster) GetPeerCount() int

GetPeerCount returns the number of peers connected to the broadcaster. This does not include the current peer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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