nodes

package
v0.0.0-...-476b4f6 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package nodes with domain node management

Package nodes with command to configure a discovered domain node

Package nodes with command to set a remote node's alias

Package nodes with handling of node configuration commands

Package nodes with receiving of the SetNodeId command

Package nodes with node management

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeNodeAddress

func MakeNodeAddress(domain string, publisherID string, nodeID string, messageType string) string

MakeNodeAddress generates the publication address of a node: domain/publisherID/nodeID[/messageType].

As per standard, the domain of the domain the node lives in; publisherID of the publisher for this node, unique for the domain; nodeID of the node itself, unique for the publisher; messageType is optional, use "" if it doesn't apply.

func MakeNodeConfigureAddress

func MakeNodeConfigureAddress(domain string, publisherID string, nodeID string) string

MakeNodeConfigureAddress generates the address to configure a node

func MakeNodeDiscoveryAddress

func MakeNodeDiscoveryAddress(domain string, publisherID string, nodeID string) string

MakeNodeDiscoveryAddress generates the address of a node: domain/publisherID/nodeID/$node.

func MakeSetNodeIDAddress

func MakeSetNodeIDAddress(domain string, publisherID string, nodeID string) string

MakeSetNodeIDAddress creates the address used to update a node's ID domain, publisherID, nodeID of the existing node

func NewNode

func NewNode(domain string, publisherID string, nodeHWID string, nodeType types.NodeType) *types.NodeDiscoveryMessage

NewNode returns a new instance of a node.

func NewNodeConfig

func NewNodeConfig(dataType types.DataType, description string, defaultValue string) *types.ConfigAttr

NewNodeConfig creates a new node configuration instance. Intended for updating additional attributes before updating the actual configuration Use UpdateNodeConfig to update the node with this configuration

dataType of the value. See also types.DataType for standard types. description of the value for humans defaultValue to use as default configuration value returns a new Configuration Attribute instance.

func PublishNodeConfigure

func PublishNodeConfigure(
	destinationAddress string, attr types.NodeAttrMap, sender string,
	messageSigner *messaging.MessageSigner, encryptionKey *ecdsa.PublicKey)

PublishNodeConfigure sends a command to update the configuration of a remote node. If an encryption key is given then the signed message will be encrypted, otherwise just signed.

func PublishRegisteredNodes

func PublishRegisteredNodes(
	updatedNodes []*types.NodeDiscoveryMessage,
	messageSigner *messaging.MessageSigner)

PublishRegisteredNodes publishes pending updates to registered nodes and saves their configuration to file the node configuration is saved in file <publisherID>-nodes.yaml

func PublishSetNodeID

func PublishSetNodeID(
	nodeAddress string, newNodeID string, sender string,
	messageSigner *messaging.MessageSigner, encryptionKey *ecdsa.PublicKey) error

PublishSetNodeID publishes the command to change a remote node ID using the existing node address. This signs and encrypts the message for the destination

Types

type DomainNodes

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

DomainNodes manages nodes discovered on the domain

func NewDomainNodes

func NewDomainNodes(messageSigner *messaging.MessageSigner) *DomainNodes

NewDomainNodes creates a new instance for domain node management.

messageSigner is used to receive signed node discovery messages

func (*DomainNodes) AddNode

func (domainNodes *DomainNodes) AddNode(node *types.NodeDiscoveryMessage)

AddNode adds or replaces a discovered node

func (*DomainNodes) GetAllNodes

func (domainNodes *DomainNodes) GetAllNodes() []*types.NodeDiscoveryMessage

GetAllNodes returns a list of all discovered nodes of the domain

func (*DomainNodes) GetNodeAttr

func (domainNodes *DomainNodes) GetNodeAttr(address string, attrName types.NodeAttr) string

GetNodeAttr returns a node attribute value

func (*DomainNodes) GetNodeByAddress

func (domainNodes *DomainNodes) GetNodeByAddress(address string) *types.NodeDiscoveryMessage

GetNodeByAddress returns a node by its address using the domain, publisherID and nodeID address must contain the domain, publisherID and nodeID. Any other fields are ignored. Returns nil if address has no known node

func (*DomainNodes) GetNodeConfigValue

func (domainNodes *DomainNodes) GetNodeConfigValue(
	address string, attrName types.NodeAttr, defaultValue string) (value string, err error)

GetNodeConfigValue returns the attribute value of a node in this list This returns the provided default value if no value is set and no default is configured. An error is returned when the node or configuration doesn't exist.

func (*DomainNodes) GetPublisherNodes

func (domainNodes *DomainNodes) GetPublisherNodes(publisherAddress string) []*types.NodeDiscoveryMessage

GetPublisherNodes returns a list of all nodes of a publisher publisherAddress contains the domain/publisherID[/$identity]

func (*DomainNodes) LoadNodes

func (domainNodes *DomainNodes) LoadNodes(filename string) error

LoadNodes loads saved discovered nodes from file Existing nodes are retained but replaced if contained in the file

func (*DomainNodes) RemoveNode

func (domainNodes *DomainNodes) RemoveNode(address string)

RemoveNode removes a node using its address. If the node doesn't exist, this is ignored.

func (*DomainNodes) SaveNodes

func (domainNodes *DomainNodes) SaveNodes(filename string) error

SaveNodes saves previously discovered nodes to file

func (*DomainNodes) Subscribe

func (domainNodes *DomainNodes) Subscribe(domain string, publisherID string)

Subscribe to nodes discovery of the given domain publisher.

func (*DomainNodes) Unsubscribe

func (domainNodes *DomainNodes) Unsubscribe(domain string, publisherID string)

Unsubscribe from publisher

type NodeConfigureHandler

type NodeConfigureHandler func(nodeHWID string, params types.NodeAttrMap)

NodeConfigureHandler application handler when command to update a node's configuration is received The handler is only invoked if the node is confirmed to exist.

type ReceiveNodeConfigure

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

ReceiveNodeConfigure with handling of node configure commands aimed at nodes managed by this publisher. This decrypts incoming messages determines the sender and verifies the signature with the sender public key.

func NewReceiveNodeConfigure

func NewReceiveNodeConfigure(
	domain string,
	publisherID string,
	configHandler NodeConfigureHandler,
	messageSigner *messaging.MessageSigner,
	registeredNodes *RegisteredNodes,
	privateKey *ecdsa.PrivateKey) *ReceiveNodeConfigure

NewReceiveNodeConfigure returns a new instance of handling of node configuration commands.

func (*ReceiveNodeConfigure) SetConfigureNodeHandler

func (nodeConfigure *ReceiveNodeConfigure) SetConfigureNodeHandler(
	handler func(nodeHWID string, params types.NodeAttrMap))

SetConfigureNodeHandler set the handler for updating node inputs

func (*ReceiveNodeConfigure) Start

func (nodeConfigure *ReceiveNodeConfigure) Start()

Start listening for configure commands

func (*ReceiveNodeConfigure) Stop

func (nodeConfigure *ReceiveNodeConfigure) Stop()

Stop listening for commands

type ReceiveSetNodeID

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

ReceiveSetNodeID listener This decrypts incoming messages, determines the sender and verifies the signature with the sender public key.

func NewReceiveSetNodeID

func NewReceiveSetNodeID(
	domain string,
	publisherID string,
	setNodeIDHandler func(address string, message *types.SetNodeIDMessage),
	messageSigner *messaging.MessageSigner,
	privateKey *ecdsa.PrivateKey) *ReceiveSetNodeID

NewReceiveSetNodeID returns a new instance of handling of the setNodeId command.

func (*ReceiveSetNodeID) SetNodeIDHandler

func (setNodeID *ReceiveSetNodeID) SetNodeIDHandler(
	handler func(nodeAddress string, message *types.SetNodeIDMessage))

SetNodeIDHandler set the handler for updating node IDs

func (*ReceiveSetNodeID) Start

func (setNodeID *ReceiveSetNodeID) Start()

Start listening for set node ID commands

func (*ReceiveSetNodeID) Stop

func (setNodeID *ReceiveSetNodeID) Stop()

Stop listening for set node ID commands

type RegisteredNodes

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

RegisteredNodes manages the publisher's node registration and publication for discovery Nodes are immutable. Any modifications made are applied to a new instance. The old node instance is discarded and replaced with the new instance. To make changes to a node directly, always Clone the node first and use UpdateNode to apply the change. A registered node is identified by its hwID which is immutable and relates to the hardware the node is attached to. Its nodeID is used for publication and can change.

func NewRegisteredNodes

func NewRegisteredNodes(domain string, publisherID string) *RegisteredNodes

NewRegisteredNodes creates a new instance for node management. onSetNodeID is the handler for changes in nodeID configuration. Use this to update input and output addresses

func (*RegisteredNodes) Clone

Clone returns a copy of the node with new Attr, Config and Status maps Intended for updating the node in a concurrent safe manner in combination with UpdateNode() This does clones map values. Any updates to the map must use new instances of the values

func (*RegisteredNodes) CreateNode

func (regNodes *RegisteredNodes) CreateNode(hwID string, nodeType types.NodeType) *types.NodeDiscoveryMessage

CreateNode creates a node instance for a device or service and adds it to the list. If the node exists it will remain unchanged. This returns the existing node instance or a newly created instance

func (*RegisteredNodes) CreateNodeConfig

func (regNodes *RegisteredNodes) CreateNodeConfig(
	hwID string, attrName types.NodeAttr, dataType types.DataType,
	description string, defaultValue string) *types.ConfigAttr

CreateNodeConfig creates a new node configuration instance and adds it to the node with the given ID. If the configuration already exists, its dataType, description and defaultValue are updated

attrName is the configuration attribute name. See also types.NodeAttr for standard IDs
dataType of the value. See also types.DataType for standard types.
description of the value for humans
defaultValue to use as default configuration value

returns a new Configuration Attribute instance.

func (*RegisteredNodes) DeleteNode

func (regNodes *RegisteredNodes) DeleteNode(hwAddress string)

DeleteNode deletes a node from the collection of registered nodes

func (*RegisteredNodes) GetAllNodes

func (regNodes *RegisteredNodes) GetAllNodes() []*types.NodeDiscoveryMessage

GetAllNodes returns a list of nodes

func (*RegisteredNodes) GetNodeAttr

func (regNodes *RegisteredNodes) GetNodeAttr(nodeHWID string, attrName types.NodeAttr) string

GetNodeAttr returns a node attribute value

func (*RegisteredNodes) GetNodeByAddress

func (regNodes *RegisteredNodes) GetNodeByAddress(address string) *types.NodeDiscoveryMessage

GetNodeByAddress returns a node by its address using the nodeID Returns nil if the nodeID is not registered

func (*RegisteredNodes) GetNodeByHWID

func (regNodes *RegisteredNodes) GetNodeByHWID(nodeHWID string) *types.NodeDiscoveryMessage

GetNodeByHWID returns a registered node by its device ID Returns nil if hwID does not exist

func (*RegisteredNodes) GetNodeByNodeID

func (regNodes *RegisteredNodes) GetNodeByNodeID(nodeID string) *types.NodeDiscoveryMessage

GetNodeByNodeID returns a nodes from the publisher Returns nil if address has no known node

func (*RegisteredNodes) GetNodeConfigBool

func (regNodes *RegisteredNodes) GetNodeConfigBool(
	nodeHWID string, attrName types.NodeAttr, defaultValue bool) (value bool, err error)

GetNodeConfigBool returns the node configuration value as a boolean address starts with the node's address This retuns the provided default value if no value is set or no default is configured, or the value is not an integer An error is returned when the node or configuration doesn't exist

func (*RegisteredNodes) GetNodeConfigFloat

func (regNodes *RegisteredNodes) GetNodeConfigFloat(
	nodeHWID string, attrName types.NodeAttr, defaultValue float32) (value float32, err error)

GetNodeConfigFloat returns the node configuration value as an floating point number address starts with the node's address This retuns the provided default value if no value is set or no default is configured, or the value is not an integer An error is returned when the node or configuration doesn't exist or is not an integer

func (*RegisteredNodes) GetNodeConfigInt

func (regNodes *RegisteredNodes) GetNodeConfigInt(
	nodeHWID string, attrName types.NodeAttr, defaultValue int) (value int, err error)

GetNodeConfigInt returns the node configuration value as an integer This retuns the provided default value if no value is set or no default is configured, or the value is not an integer An error is returned when the node or configuration doesn't exist or is not an integer

func (*RegisteredNodes) GetNodeConfigString

func (regNodes *RegisteredNodes) GetNodeConfigString(
	nodeHWID string, attrName types.NodeAttr, defaultValue string) (value string, err error)

GetNodeConfigString returns the attribute value of a node in this list This retuns the provided default value if no value is set and no default is configured. An error is returned when the node or configuration doesn't exist.

func (*RegisteredNodes) GetUpdatedNodes

func (regNodes *RegisteredNodes) GetUpdatedNodes(clearUpdates bool) []*types.NodeDiscoveryMessage

GetUpdatedNodes returns the list of nodes that have been updated clearUpdates clears the list of updates. Intended for publishing only updated nodes.

func (*RegisteredNodes) LoadNodes

func (regNodes *RegisteredNodes) LoadNodes(filename string) error

LoadNodes loads previously saved registered nodes. Intended to persist changes to node configuration.

func (*RegisteredNodes) SaveNodes

func (regNodes *RegisteredNodes) SaveNodes(filename string) error

SaveNodes saves the current registered nodes to a JSON file

func (*RegisteredNodes) SetNodeID

func (regNodes *RegisteredNodes) SetNodeID(node *types.NodeDiscoveryMessage, newNodeID string) bool

SetNodeID changes the nodeID and address of the node

Use an empty ID to restore the nodeID and address to the hwAddress.
This creates a new node instance and marks it as updated for publication. The existing

node publication remains unchanged.

Returns true if a new node is created, false if node not found or the nodeID is already in use

func (*RegisteredNodes) UpdateErrorStatus

func (regNodes *RegisteredNodes) UpdateErrorStatus(nodeHWID string, runState string, errorMsg string) (changed bool)

UpdateErrorStatus sets the device RunState to the given status with a lasterror message Use NodeRunStateError for errors and NodeRunStateReady to clear error This only updates the node if the status or lastError message changes

func (*RegisteredNodes) UpdateNodeAttr

func (regNodes *RegisteredNodes) UpdateNodeAttr(nodeHWID string, attrParams map[types.NodeAttr]string) (changed bool)

UpdateNodeAttr updates node's attributes and publishes the updated node. Node is marked as modified for publication only if one of the attrParams has changes Use when additional node attributes has been discovered. returns true when node has changed, false if node doesn't exist or attributes haven't changed

func (*RegisteredNodes) UpdateNodeConfig

func (regNodes *RegisteredNodes) UpdateNodeConfig(nodeHWID string, attrName types.NodeAttr, configAttr *types.ConfigAttr)

UpdateNodeConfig updates a node's configuration and publishes the updated node.

If a config already exists then its value is retained but its configuration parameters are replaced. Nodes are immutable. A new node is created and published and the old node instance is discarded.

func (*RegisteredNodes) UpdateNodeConfigValues

func (regNodes *RegisteredNodes) UpdateNodeConfigValues(nodeHWID string, params types.NodeAttrMap) (changed bool)

UpdateNodeConfigValues applies an update to a registered node configuration values. Nodes are immutable. If one or more configuration values have changed then a new node is created and published and the old node instance is discarded.

param is the map with key-value pairs of configuration values to update

returns true if configuration changes, false if configuration remains unchanged or doesn't exist

func (*RegisteredNodes) UpdateNodeStatus

func (regNodes *RegisteredNodes) UpdateNodeStatus(nodeHWID string, statusAttr map[types.NodeStatus]string) (changed bool)

UpdateNodeStatus updates one or more node's status attributes. Nodes are immutable. If one or more status values have changed then a new node is created and published. The old node instance is discarded.

statusAttr is the map with key-value pairs of updated node statusses

func (*RegisteredNodes) UpdateNodes

func (regNodes *RegisteredNodes) UpdateNodes(updates []*types.NodeDiscoveryMessage)

UpdateNodes updates a list of nodes.

Intended to update the list with nodes from persistent storage

type SetNodeIDHandler

type SetNodeIDHandler func(nodeAddress string, message *types.SetNodeIDMessage)

SetNodeIDHandler callback when command to change a node ID

Jump to

Keyboard shortcuts

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