Documentation
¶
Index ¶
- Variables
- func DOT(n *Network) ([]byte, error)
- type Link
- type LinkOpt
- type Network
- func (n *Network) AddLink(from, to string, opt ...LinkOpt) error
- func (n *Network) AddNode(opt ...NodeOpt) (string, error)
- func (n *Network) Egress(key string) []*Link
- func (n *Network) Ingress(key string) []*Link
- func (n *Network) Keys() []string
- func (n *Network) Link(from, to string) (*Link, error)
- func (n *Network) Links() []*Link
- func (n *Network) Node(k string) (*Node, error)
- func (n *Network) Nodes() []*Node
- func (n *Network) PauseLink(from, to string) error
- func (n *Network) Purge() error
- func (n *Network) RemoveLink(from, to string) error
- func (n *Network) RemoveNode(k string) error
- func (n *Network) ResumeLink(from, to string) error
- func (n *Network) Seeds() []string
- func (n *Network) Start(ctx context.Context) error
- func (n *Network) Stop() error
- func (n *Network) Terminals() []string
- func (n *Network) Uptime() time.Duration
- type NetworkOpt
- type Node
- type NodeOpt
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyNetwork = errors.New("network is empty") ErrNetworkNeedPurging = errors.New("network needs purging") ErrNodeNotFound = errors.New("node not found") ErrBadNodeKey = errors.New("bad node key") ErrNodeAlreadyExists = errors.New("node already exists") ErrNodeIsConnected = errors.New("node is connected") ErrSeedingDone = errors.New("seeding is done") ErrNodeGoingAway = errors.New("node is going away") ErrIsolatedNodeFound = errors.New("isolated node found") ErrNodeFunctionMissing = errors.New("node function missing") ErrTooManyNodeFunction = errors.New("too many node functions") ErrLinkNotFound = errors.New("link not found") ErrLinkAlreadyExists = errors.New("link already exists") ErrCyclesNotAllowed = errors.New("cycles not allowed") ErrLinkAlreadyPaused = errors.New("link already paused") )
Functions ¶
Types ¶
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link captures the connection between two nodes. Data flows from x to y over the Link. A Link can have 3 states:
- Closed - The Link enters the closed state when the Link.From Node goes away. The Link remains in this state until a new session (Network.Start) or system restart.
- Paused - The Link enters the paused state when Network.PauseLink is called. The Link remains in this state until resumed (Network.ResumeLink) or system restart.
- Removed - The Link enters the removed state when Network.RemoveLink is called. The Link remains in this state until added back (Network.AddLink) or system restart.
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network represents nodes and their links.
func (*Network) AddLink ¶
AddLink connects from-node to to-node. Once Link is made, nodes are said to be communicating over the Link in the direction from -> to. See:
- RemoveLink
- PauseLink
- ResumeLink
func (*Network) AddNode ¶
AddNode adds a new Node in the Network. Node key is retrieved from the provided KeyFunc function if not given.
func (*Network) Keys ¶
Keys returns all the nodes as their unique keys in the Network. Network.Node should be called to get actual Node.
func (*Network) PauseLink ¶
PauseLink pauses communication from Node and to Node. See:
- AddLink
- ResumeLink
- RemoveLink
func (*Network) Purge ¶
Purge cleans up the Network by removing isolated Node(s) and removed Link(s).
func (*Network) RemoveLink ¶
RemoveLink disconnects "from" Node and "to" Node. See:
- AddLink
- PauseLink
- ResumeLink
func (*Network) RemoveNode ¶
RemoveNode removes a node with provided key. A node can't be removed if it is linked to any other node in the Network.
func (*Network) Seeds ¶
Seeds returns all the nodes that have only egress Link(s). Network.Node should be called to get actual Node.
func (*Network) Stop ¶
Stop signals the Network to cease all communications. If stop grace period is set, communications will terminate after that period.
type NetworkOpt ¶
type NetworkOpt func(*Network)
func IgnoreIsolatedNodes ¶
func IgnoreIsolatedNodes() NetworkOpt
IgnoreIsolatedNodes allows the Network to run even when there are isolated nodes.
func PreventCycles ¶
func PreventCycles() NetworkOpt
PreventCycles ensures the Network remains a Directed Acyclic Graph (DAG).
func StopGracetime ¶
func StopGracetime(t time.Duration) NetworkOpt
StopGracetime sets the grace period for which the Network waits for processes to finish before stopping.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a node within the Network.
Node types:
- With no Links, Node is considered an isolated-node.
- With only egress Links, Node is considered a seed-node.
- With only ingress Links, Node is considered a terminal-node.
- With both egress and ingress Links, Node is considered a transit-node.
Node operating modes:
- By default, a Node operates in broadcaster mode unless the distributor flag is set. In broadcaster mode, Node broadcasts all incoming data to all outgoing links. When the distributor flag is enabled, a Node distributes incoming data among its outgoing links. Distributor mode is not functional for isolated and terminal nodes.
- By default, a Node operates in "push-pull" mode: the Network pushes data to BasicFunc, and it waits for BasicFunc to return with output data, which is then forwarded to connected Node(s). This behavior can be changed to "push-push" by setting the EmitFunc for the Node. When EmitFunc is set, the Network pushes data to EmitFunc, and it emits zero or more data points back to the Network through the supplied callback emit function.
type NodeOpt ¶
type NodeOpt func(*Node)
func BasicFunc ¶ added in v0.3.0
BasicFunc is responsible for processing incoming data on the Node. Output from the Node is forwarded to downstream connected Node(s).
func Distributor ¶
func Distributor() NodeOpt
Distributor enables a Node to distribute incoming data among its outgoing links.