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
- type Message
- type Node
- func (n *Node) Broadcast(body interface{}) ([]string, error)
- func (n *Node) BroadcastRecipients() []string
- func (n *Node) Dial(addr string) error
- func (n *Node) Dot() string
- func (n *Node) GetDegree() uint
- func (n *Node) GetMSATimeout() time.Duration
- func (n *Node) Hangup(host string) error
- func (n *Node) MSA()
- func (n *Node) Mesh() mesh
- func (n *Node) Name() string
- func (n *Node) Send(m *Message) ([]string, error)
- func (n *Node) Set(recipients []string, body interface{}) ([]string, error)
- func (n *Node) SetDegree(degree uint)
- func (n *Node) SetMSATimeout(timeout uint)
Constants ¶
const ( ACK = iota MSA MESSAGE )
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 )
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.
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, 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) BroadcastRecipients ¶
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) Dot ¶
Dot returns a graphviz 'dotfile' string representing the topology known to the node.
func (*Node) GetMSATimeout ¶
Return the MSA period, in seconds.
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) Send ¶
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 ¶
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 ¶
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 ¶
Set the MSA period, in seconds.