events

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2019 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package events is the event notification subsystem of brig. It uses the backend's capabilities (in case of IPFS we use pubsub) to publish and subscribe to a topic of events. If an event was received it is forwarded to the caller side in order to react on it.

Index

Constants

View Source
const (
	// UnknownEvent should not happen in practice.
	UnknownEvent = EventType(1 << iota)
	// FsEvent tells other remotes that our filesystem changed.
	FsEvent
	// NetEvent indicates to other peers that our network status changed.
	NetEvent
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type   EventType
	Source string
}

Event is a event that can be published or received by the event subsystem.

type EventType

type EventType int

EventType is the type of a

func EventFromString

func EventFromString(ev string) (EventType, error)

EventFromString tries to parse `ev` as event type. If it fails, an error will be returned.

func (EventType) String

func (ev EventType) String() string

String returns a human readable representation of the event type

type Listener

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

Listener listens to incoming events from other remotes. For every event, a registered callback can be executed. It does not implement net.Listener and is only similar from a concept POV.

func NewListener

func NewListener(cfg *config.Config, bk backend.Backend, ownAddr string) *Listener

NewListener constructs a new listener. `cfg` is used to read the event subsystem config. `bk` is a events.Backend. `ownAddr` is the addr of our own node.

func (*Listener) Close

func (lst *Listener) Close() error

Close will close all open listeners and clean up internal resources.

func (*Listener) PublishEvent

func (lst *Listener) PublishEvent(ev Event) error

PublishEvent notifies other peers that something on our side changed. The "something" is defined by `ev`. PublishEvent does not block.

func (*Listener) RegisterEventHandler

func (lst *Listener) RegisterEventHandler(ev EventType, notifyOnOwn bool, hdl func(ev *Event))

RegisterEventHandler remembers that `hdl` should be called whenever a event of type `ev` is being received. If `notifyOnOwn` is true, the handler will only be called for changes that came from our own node. If it is `false` it will only be called for

func (*Listener) SetupListeners

func (lst *Listener) SetupListeners(ctx context.Context, addrs []string) error

SetupListeners sets up the listener to receive events from any of `addrs`. If `ctx` is being canceled, all listeners will stop. SetupListeners can be called several times, each time overwriting and stopping previous listeners.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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