Documentation ¶
Index ¶
- Constants
- func PeerIDMapToSlice(peerIDs map[peer.ID]struct{}) []peer.ID
- type BroadcastHandler
- type BroadcastNotif
- func (p *BroadcastNotif) ClosedStream(n network.Network, s network.Stream)
- func (p *BroadcastNotif) Connected(n network.Network, c network.Conn)
- func (p *BroadcastNotif) Disconnected(n network.Network, c network.Conn)
- func (p *BroadcastNotif) Listen(n network.Network, _ ma.Multiaddr)
- func (p *BroadcastNotif) ListenClose(n network.Network, _ ma.Multiaddr)
- func (p *BroadcastNotif) OpenedStream(n network.Network, s network.Stream)
- type Broadcaster
- type BroadcasterHook
- type BroadcasterOption
- type NoOpBroadcastHandler
- type NoOpBroadcaster
- type P2PBroadcaster
Constants ¶
const ( ProtocolID = "/fury-relayer/broadcast/1.0.0" ServiceName = "fury-relayer.broadcast" )
Variables ¶
This section is empty.
Functions ¶
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) 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 (h *NoOpBroadcastHandler) MismatchMessage(msg pending_store.MessageWithPeerMetadata)
func (*NoOpBroadcastHandler) RawMessage ¶
func (h *NoOpBroadcastHandler) RawMessage(msg pending_store.MessageWithPeerMetadata)
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.