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) Termini() []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 connection between two nodes. Data flows from x to y over the Link.
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 from -> to. See:
- RemoveLink
- PauseLink
- ResumeLink
func (*Network) AddNode ¶
AddNode adds a new Node in the network. Node key is retrieved from the provided Key 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 links. 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
func PreventCycles ¶
func PreventCycles() NetworkOpt
func StopGracetime ¶
func StopGracetime(t time.Duration) NetworkOpt
func Verbose ¶
func Verbose() NetworkOpt
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 terminus-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 terminus nodes.
- By default, a Node operates in "push-pull" mode: the Network pushes data to NodeFunc, and it waits for NodeFunc 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. In emitter mode, the Network pushes data to EmitFunc, and the Node emits data back to the Network through the supplied callback emit function.
type NodeOpt ¶
type NodeOpt func(*Node)
func Distributor ¶
func Distributor() NodeOpt
Distributor enables a Node to distribute incoming data among its outgoing links.
func EmitFunc ¶
EmitFunc handles processing incoming data on the Node. It provides a callback where output data can be optionally emitted. Emitted data is forwarded to downstream connected Node(s).