events

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package events contains a simple p2p event system implementation, that simplifies asynchronous event flows in the p2p module. The event subscriptions allow for event filtering, which eases the load on the event notification flow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {
	// Type returns the type information for the event
	Type() EventType
}

Event is a generic p2p event

type EventFilter

type EventFilter func(Event) bool

EventFilter is the filter function used to filter incoming p2p events. A false flag will consider the event as irrelevant

type EventType

type EventType string
const (
	PeerConnected    EventType = "PeerConnected"    // emitted when a fresh peer connects
	PeerDisconnected EventType = "PeerDisconnected" // emitted when a peer disconnects
)

type Events

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

Events is the p2p event switch

func New

func New() *Events

New creates a new event subscription manager

func (*Events) Notify

func (es *Events) Notify(event Event)

Notify notifies all subscribers of an incoming event [BLOCKING]

func (*Events) Subscribe

func (es *Events) Subscribe(filterFn EventFilter) (<-chan Event, func())

Subscribe registers a new filtered event listener

type PeerConnectedEvent

type PeerConnectedEvent struct {
	PeerID  types.ID // the ID of the peer
	Address net.Addr // the remote address of the peer
}

func (PeerConnectedEvent) Type

func (p PeerConnectedEvent) Type() EventType

type PeerDisconnectedEvent

type PeerDisconnectedEvent struct {
	PeerID  types.ID // the ID of the peer
	Address net.Addr // the remote address of the peer
	Reason  error    // the disconnect reason, if any
}

func (PeerDisconnectedEvent) Type

Jump to

Keyboard shortcuts

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