glow

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Computational Network Framework

GoDoc Go Report Card

The glow is an idiomatic general purpose computational network framework.

Examples

Examples

Wish List

  • Seed node
  • Terminal node
  • Transit node
  • Broadcaster mode
  • Distributor mode
  • Router mode
  • Emitter mode
    • Filter
  • Sessions
  • Signaling
  • Pause links
  • Network integrity checks
    • Avoid cycles
    • Isolated nodes
  • Link tally
  • Most & least used paths
  • Fastest & slowest paths
  • Network modifications while network is up (e.g. Remove link, Add Link)
  • ACK

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func DOT

func DOT(n *Network) ([]byte, error)

DOT describes the Network.

Types

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

Link captures connection between two nodes. Data flows from x to y over the Link.

func (*Link) From

func (l *Link) From() *Node

From returns the key of the "from" Node connected by this link.

func (*Link) Tally

func (l *Link) Tally() int

Tally returns the total count of data transmitted over the link thus far.

func (*Link) To

func (l *Link) To() *Node

To returns the key of the "to" Node connected by this link.

func (*Link) Uptime

func (l *Link) Uptime() time.Duration

type LinkOpt

type LinkOpt func(*Link)

func Size

func Size(k int) LinkOpt

Size sets bandwidth for the Link.

type Network

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

Network represents nodes and their links.

func New

func New(opt ...NetworkOpt) *Network

New creates a new Network.

func (n *Network) AddLink(from, to string, opt ...LinkOpt) error

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

func (n *Network) AddNode(opt ...NodeOpt) (string, error)

AddNode adds a new Node in the network. Node key is retrieved from the provided Key function if not given.

func (*Network) Egress

func (n *Network) Egress(key string) []*Link

Egress returns all the egress links for the Node.

func (*Network) Ingress

func (n *Network) Ingress(key string) []*Link

Ingress returns all the ingress links for the Node.

func (*Network) Keys

func (n *Network) Keys() []string

Keys returns all the nodes as their unique keys in the Network. Network.Node should be called to get actual Node.

func (n *Network) Link(from, to string) (*Link, error)

Link returns connection between from and to nodes if any.

func (n *Network) Links() []*Link

Links returns all the links in the Network.

func (*Network) Node

func (n *Network) Node(k string) (*Node, error)

Node returns the node identified by the provided key.

func (*Network) Nodes

func (n *Network) Nodes() []*Node

Nodes returns all the nodes in the Network.

func (n *Network) PauseLink(from, to string) error

PauseLink pauses communication from Node and to Node. See:

  • AddLink
  • ResumeLink
  • RemoveLink

func (*Network) Purge

func (n *Network) Purge() error

Purge cleans up the Network by removing isolated Node(s) and removed Link(s).

func (n *Network) RemoveLink(from, to string) error

RemoveLink disconnects "from" Node and "to" Node. See:

  • AddLink
  • PauseLink
  • ResumeLink

func (*Network) RemoveNode

func (n *Network) RemoveNode(k string) error

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 (n *Network) ResumeLink(from, to string) error

ResumeLink resumes communication from node and to node. See:

  • PauseLink

func (*Network) Seeds

func (n *Network) Seeds() []string

Seeds returns all the nodes that have only egress links. Network.Node should be called to get actual node.

func (*Network) Start

func (n *Network) Start(ctx context.Context) error

Start runs the Network.

func (*Network) Stop

func (n *Network) Stop() error

Stop signals the Network to cease all communications. If stop grace period is set, communications will terminate after that period.

func (*Network) Termini

func (n *Network) Termini() []string

Termini returns all the nodes that have only ingress links. Network.Node should be called to get actual node.

func (*Network) Uptime

func (n *Network) Uptime() time.Duration

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.

func (*Node) Key

func (n *Node) Key() string

func (*Node) Uptime

func (n *Node) Uptime() time.Duration

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

func EmitFunc(f func(ctx context.Context, data any, emit func(any)) error) NodeOpt

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).

func Key

func Key(k string) NodeOpt

Key sets the key for the Node.

func KeyFunc

func KeyFunc(f func() string) NodeOpt

KeyFunc sets function to generate unique keys for the Node.

func NodeFunc

func NodeFunc(f func(ctx context.Context, data any) (any, error)) NodeOpt

NodeFunc is responsible for processing incoming data on the Node. Output from the Node is forwarded to downstream connected Node(s).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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