meshage

package
v0.0.0-...-81ce8a9 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

meshage is a mesh based message passing protocol that supports auto-configuration and simple resiliency.

meshage is used by creating a node with a name, namespace, degree of connectivity, and a port. Other meshage nodes on the broadcast domain that have the same namespace and port will automatically connect in an arbitrary graph. Additionally, the user can direct nodes to connect to other nodes directly (without requiring they be on the same broadcast domain). Nodes must use the same port to communicate, but not necessarily the same namespace. Nodes will auto-configure only with other nodes with the same namespace, but direct dialing will ignore the namespace.

Messages are passed either as a set of connected nodes or as a broadcast to all nodes. A set message is a message sent to one or more nodes on the mesh. A broadcast is a message sent to all nodes on the mesh. Messages are automatically routed to their destination via the shortest path along the mesh. Messages that fail to complete return an error with no retry along an alternate route.

The state of the mesh is maintained automatically by connected nodes via mesh state announcements (MSA). MSA messages are periodically flooded to all nodes by all nodes to determine the mesh topology and routes. The user can set the MSA period, which defaults to 10 seconds. When nodes fail or leave the mesh unexpectedly, MSA processing will detect the lost node and recalculate the topology.

Index

Constants

View Source
const (
	ACK = iota
	MSA
	MESSAGE
)
View Source
const (
	DEFAULT_TIMEOUT     = 10
	RECEIVE_BUFFER      = 1024
	DEFAULT_MSA_TIMEOUT = 10
	SOLICIT_LIMIT       = 16 // If fewer than SOLICIT_LIMIT nodes exist in the mesh, everyone tries to connect on solicitations
	SOLICIT_RATIO       = 8  // If greater than SOLICIT_LIMIT nodes exist in the mesh, 1/SOLICIT_RATIO nodes try to connect
)
View Source
const (
	LOLLIPOP_LENGTH = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Recipients   []string    // list of client recipients, unused if broadcasting
	Source       string      // source node name
	Instance     uint64      // ID for the instance, new on restart
	CurrentRoute []string    // list of hops for an in-flight message
	ID           uint64      // sequence ID, uses lollipop sequence numbering
	Command      int         // mesh state announcement, message
	Body         interface{} // message body
}

A message is the payload for all message passing, and contains the user specified message in the body field.

func (*Message) String

func (m *Message) String() string

type Node

type Node struct {
	Snoop func(m *Message)
	// contains filtered or unexported fields
}

A Node object contains the network information for a given node. Creating a Node object with a non-zero degree will cause it to begin broadcasting for connections automatically.

func NewNode

func NewNode(name string, namespace string, degree uint, broadcastIP net.IP, port int, version string) (*Node, chan *Message)

NewNode returns a new node, receiver channel, and error channel with a given name and degree. If degree is non-zero, the node will automatically begin broadcasting for connections.

func (*Node) Broadcast

func (n *Node) Broadcast(body interface{}) ([]string, error)

Broadcast sends a message to all nodes on the mesh.

func (*Node) BroadcastRecipients

func (n *Node) BroadcastRecipients() []string

Determine all the nodes on the mesh that would receive a broadcast message from this node. This excludes the node itself as nodes cannot send messages to themselves.

func (*Node) Dial

func (n *Node) Dial(addr string) error

Dial connects a node to another, regardless of degree. Error is nil on success.

func (*Node) Dot

func (n *Node) Dot() string

Dot returns a graphviz 'dotfile' string representing the topology known to the node.

func (*Node) GetDegree

func (n *Node) GetDegree() uint

GetDegree returns the current degree for the node.

func (*Node) GetMSATimeout

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

Return the MSA period, in seconds.

func (*Node) Hangup

func (n *Node) Hangup(host string) error

Dicconnect from the specified host.

func (*Node) MSA

func (n *Node) MSA()

MSA issues a Meshage State Annoucement, which contains a list of all the nodes connected to the broadcaster

func (*Node) Mesh

func (n *Node) Mesh() mesh

Mesh returns the current known topology as an adjacency list.

func (*Node) Name

func (n *Node) Name() string

return the name of this node

func (*Node) Send

func (n *Node) Send(m *Message) ([]string, error)

Send a message according to the parameters set in the message. Users will generally use the Set and Broadcast functions instead of Send. The returned error is always nil if the message type is broadcast. If an error is encountered, Send returns immediately.

func (*Node) Set

func (n *Node) Set(recipients []string, body interface{}) ([]string, error)

Set sends a message to a set of nodes. Set blocks until an ACK is received from all recipient nodes, or until the timeout is reached.

func (*Node) SetDegree

func (n *Node) SetDegree(degree uint)

SetDegree sets the degree for the current node. If the degree increases beyond the current number of connected clients, it will begin broadcasting for connections.

func (*Node) SetMSATimeout

func (n *Node) SetMSATimeout(timeout uint)

Set the MSA period, in seconds.

Jump to

Keyboard shortcuts

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