notify

package
v1.8.14 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// sent from requester to updater to request start of notifications
	MsgCodeStart = iota

	// sent from updater to requester, contains a notification plus a new symkey to replace the old
	MsgCodeNotifyWithKey

	// sent from updater to requester, contains a notification
	MsgCodeNotify

	// sent from requester to updater to request stop of notifications (currently unused)
	MsgCodeStop
	MsgCodeMax
)
View Source
const (
	DefaultAddressLength = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

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

Controller is the interface to control, add and remove notification services and subscriptions

func NewController

func NewController(ps *pss.Pss) *Controller

NewController creates a new Controller object

func (*Controller) Handler

func (c *Controller) Handler(smsg []byte, p *p2p.Peer, asymmetric bool, keyid string) error

Handler is the pss topic handler to be used to process notification service messages It should be registered in the pss of both to any notification service provides and clients using the service

func (*Controller) IsActive

func (c *Controller) IsActive(name string) bool

IsActive is used to check if a notification service exists for a specified id string Returns true if exists, false if not

func (*Controller) NewNotifier

func (c *Controller) NewNotifier(name string, threshold int, updateC <-chan []byte) (func(), error)

NewNotifier is used by a notification service provider to create a new notification service It takes a name as identifier for the resource, a threshold indicating the granularity of the subscription address bin It then starts an event loop which listens to the supplied update channel and executes notifications on channel receives Fails if a notifier already is registered on the name func (c *Controller) NewNotifier(name string, threshold int, contentFunc func(string) ([]byte, error)) error {

func (*Controller) RemoveNotifier

func (c *Controller) RemoveNotifier(name string) error

RemoveNotifier is used to stop a notification service. It cancels the event loop listening to the notification provider's update channel

func (*Controller) Subscribe

func (c *Controller) Subscribe(name string, pubkey *ecdsa.PublicKey, address pss.PssAddress, handler func(string, []byte) error) error

Subscribe is used by a client to request notifications from a notification service provider It will create a MsgCodeStart message and send asymmetrically to the provider using its public key and routing address The handler function is a callback that will be called when notifications are received Fails if the request pss cannot be sent or if the update message could not be serialized

func (*Controller) Unsubscribe

func (c *Controller) Unsubscribe(name string) error

Unsubscribe, perhaps unsurprisingly, undoes the effects of Subscribe Fails if the subscription does not exist, if the request pss cannot be sent or if the update message could not be serialized

type Msg

type Msg struct {
	Code    byte
	Name    []byte
	Payload []byte
	// contains filtered or unexported fields
}

when code is MsgCodeStart, Payload is address when code is MsgCodeNotifyWithKey, Payload is notification | symkey when code is MsgCodeNotify, Payload is notification when code is MsgCodeStop, Payload is address

func NewMsg

func NewMsg(code byte, name string, payload []byte) *Msg

NewMsg creates a new notification message object

func NewMsgFromPayload

func NewMsgFromPayload(payload []byte) (*Msg, error)

NewMsgFromPayload decodes a serialized message payload into a new notification message object

Jump to

Keyboard shortcuts

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