...

Package mesh

import "github.com/Diarkis/diarkis/mesh"
Overview
Index
Subdirectories

Overview ▾

Package mesh ▷

Mesh - Server to server internal communications

Mesh manages and controls all internal server to server communications.

Configurations

Mesh configurations are explained below.

{
  "address": "127.0.0.1",
  "nic": "eth0",
  "port": "8000",
  "marsAddress": "127.0.0.1",
  "marsPort": "6789",
  "strictCheckForExternal": false
}

▶︎ Configuration Values

address - Default is "127.0.0.1"

Address for mesh network server to bind with.

nic - Default is "eth0"

Name of a network interface to retrieve address from.

port - Default is "8000"

Port for mesh network server to bind with. Starts from the given port and scans to find an open poet to bind.

marsAddress - Default is "127.0.0.1"

MARS server address. Can be overwritten by env DIARKIS_MARS_ADDR.

marsPort - Default is "6789"

MARS server port. Can be overwritten by env DIARKIS_MARS_PORT.

NOTE - You may use either address or nic in your configurations. If none is used, the default is localhost.

strictCheckForExternal - Default is false

When this configuration is set to true, all in coming mesh messages will be validated to make sure the sender of each message comes from a node that is part of the cluster.

Index ▾

Constants
func Command(commandID uint16, callback func(map[string]interface{}) (map[string]interface{}, error))
func GetBool(data map[string]interface{}, name string) bool
func GetBytes(data map[string]interface{}, name string) []byte
func GetFloat64(data map[string]interface{}, name string) float64
func GetInt(data map[string]interface{}, name string) int
func GetInt16(data map[string]interface{}, name string) int16
func GetInt32(data map[string]interface{}, name string) int32
func GetInt64(data map[string]interface{}, name string) int64
func GetInt8(data map[string]interface{}, name string) int8
func GetMyEndPoint() string
func GetMyNodeEndPoint() string
func GetMyNodeType() string
func GetNodeAddresses(ignoreList []string) []string
func GetNodeAddressesByType(nodeType string) []string
func GetNodeEndPoint(nodeAddr string) string
func GetNodeTypes() []string
func GetNodeValue(nodeAddr string, name string) interface{}
func GetNodeValues(nodeAddr string) map[string]interface{}
func GetString(data map[string]interface{}, name string) string
func GetUint16(data map[string]interface{}, name string) uint16
func GetUint32(data map[string]interface{}, name string) uint32
func GetUint64(data map[string]interface{}, name string) uint64
func GetUint8(data map[string]interface{}, name string) uint8
func Guest(confpath string)
func IsCommandDuplicate(commandID uint16) bool
func IsMyNodeOnline() bool
func IsMyNodeTaken() bool
func IsNodeOnline(nodeAddr string) bool
func IsNodeTaken(nodeAddr string) bool
func OnUpdate(handler func())
func OnUpdated(handler func())
func Send(commandID uint16, addr string, data map[string]interface{})
func SendMany(commandID uint16, addrs []string, data map[string]interface{}, limit int)
func SendRequest(commandID uint16, addr string, data map[string]interface{}, callback func(error, map[string]interface{}))
func SetAppName(name string)
func SetEndPoint(endPoint string)
func SetNodeType(_nodeType string)
func SetNodeValue(name string, val interface{})
func SetStatus(status int)
func Setup(confpath string)
func StartAsMARS(confpath string)
func USend(commandID uint16, addr string, data map[string]interface{})
func USendMany(command uint16, addrs []string, data map[string]interface{}, limit int)
type Node
    func GetNode(nodeAddr string) *Node
    func GetNodeByEndPoint(endPoint string) *Node

Constants

PktSampleIn in bound packet sample node value name

const PktSampleIn = "mi"

PktSampleInName the name for metrics

const PktSampleInName = "Mesh_Packets_In"

PktSampleOut out bound packet sample node value name

const PktSampleOut = "mo"

PktSampleOutName the name for metrics

const PktSampleOutName = "Mesh_Packets_Out"

PktSampleRetry retry count sample node value name

const PktSampleRetry = "mr"

PktSampleRetryName the name for metrics

const PktSampleRetryName = "Mesh_Retry"

func Command

func Command(commandID uint16, callback func(map[string]interface{}) (map[string]interface{}, error))

Command Defines a handling function for a mesh network messsage as a command - Command messages are sent by SendRequest, SendMany, USend, USendMany

func GetBool

func GetBool(data map[string]interface{}, name string) bool

GetBool returns a bool from the mesh network request/response data

func GetBytes

func GetBytes(data map[string]interface{}, name string) []byte

GetBytes returns a byte array from the mesh network request/response data

func GetFloat64

func GetFloat64(data map[string]interface{}, name string) float64

GetFloat64 returns a float64 from the mesh network request/response data

func GetInt

func GetInt(data map[string]interface{}, name string) int

GetInt returns an int from the mesh network request/response data

func GetInt16

func GetInt16(data map[string]interface{}, name string) int16

GetInt16 returns an int16 from the mesh network request/response data

func GetInt32

func GetInt32(data map[string]interface{}, name string) int32

GetInt32 returns an int32 from the mesh network request/response data

func GetInt64

func GetInt64(data map[string]interface{}, name string) int64

GetInt64 returns an int64 from the mesh network request/response data

func GetInt8

func GetInt8(data map[string]interface{}, name string) int8

GetInt8 returns an int8 from the mesh network request/response data

func GetMyEndPoint

func GetMyEndPoint() string

GetMyEndPoint Returns its own mesh network end point

func GetMyNodeEndPoint

func GetMyNodeEndPoint() string

GetMyNodeEndPoint returns the server endpoint (internet) its own node

func GetMyNodeType

func GetMyNodeType() string

GetMyNodeType Returns the node type of itself

func GetNodeAddresses

func GetNodeAddresses(ignoreList []string) []string

GetNodeAddresses Returns all node addresses

func GetNodeAddressesByType

func GetNodeAddressesByType(nodeType string) []string

GetNodeAddressesByType Return the addresses of nodes by type

func GetNodeEndPoint

func GetNodeEndPoint(nodeAddr string) string

GetNodeEndPoint returns the server endpoint (internet) of a node by its mesh node address - only TCP, UDP, and HTTP

func GetNodeTypes

func GetNodeTypes() []string

GetNodeTypes returns all node types currently in the Diarkis cluster

func GetNodeValue

func GetNodeValue(nodeAddr string, name string) interface{}

GetNodeValue Returns a metadata value of a node by its address

func GetNodeValues

func GetNodeValues(nodeAddr string) map[string]interface{}

GetNodeValues Returns all metadata values of a node by its address

func GetString

func GetString(data map[string]interface{}, name string) string

GetString returns a string from the mesh network request/response data

func GetUint16

func GetUint16(data map[string]interface{}, name string) uint16

GetUint16 returns a uint16 from the mesh network request/response data

func GetUint32

func GetUint32(data map[string]interface{}, name string) uint32

GetUint32 returns a uint32 from the mesh network request/response data

func GetUint64

func GetUint64(data map[string]interface{}, name string) uint64

GetUint64 returns a uint64 from the mesh network request/response data

func GetUint8

func GetUint8(data map[string]interface{}, name string) uint8

GetUint8 returns a uint8 from the mesh network request/response data

func Guest

func Guest(confpath string)

Guest starts mesh network as a guest meaning that the process can only send and receive messages but does not become part of the mesh node

func IsCommandDuplicate

func IsCommandDuplicate(commandID uint16) bool

IsCommandDuplicate returns true if commandID is used elsewhere

func IsMyNodeOnline

func IsMyNodeOnline() bool

IsMyNodeOnline returns false if the node is offline (received SIGTERM)

When the node is offline, the connected clients will be raising OnOffline event

func IsMyNodeTaken

func IsMyNodeTaken() bool

IsMyNodeTaken returns true if the node is taken ((mesh.SetStatus(util.MeshStatusTaken))

When a node is thaken, the taken node will not be returned by HTTP server as available server.

func IsNodeOnline

func IsNodeOnline(nodeAddr string) bool

IsNodeOnline Returns true if the given node is online

When the node is offline, the connected clients will be raising OnOffline event

func IsNodeTaken

func IsNodeTaken(nodeAddr string) bool

IsNodeTaken returns false if the node is taken (mesh.SetStatus(util.MeshStatusTaken))

When a node is thaken, the taken node will not be returned by HTTP server as available server.

func OnUpdate

func OnUpdate(handler func())

OnUpdate Registers a callback on announcer update event

func OnUpdated

func OnUpdated(handler func())

OnUpdated Registers a callback on announcer updated event

func Send

func Send(commandID uint16, addr string, data map[string]interface{})

Send Sends a mesh network message to a given node - addr = <address>:<port>

func SendMany

func SendMany(commandID uint16, addrs []string, data map[string]interface{}, limit int)

SendMany Sends a mesh network message to multiple nodes

commandID - Mesh message command ID
addrs     - A list of mesh node addreses to send the message to
data      - Data map to be sent
limit     - Maximum number of node to send the message at a time

func SendRequest

func SendRequest(commandID uint16, addr string, data map[string]interface{}, callback func(error, map[string]interface{}))

SendRequest Sends a mesh network requesst to another node - addr = <address>:<port> and expects a response back from it

func SetAppName

func SetAppName(name string)

SetAppName creates a name space within the mars-server in order to have multiple diarkis clusters

func SetEndPoint

func SetEndPoint(endPoint string)

SetEndPoint Sets its own end point

func SetNodeType

func SetNodeType(_nodeType string)

SetNodeType Sets a type to a name

func SetNodeValue

func SetNodeValue(name string, val interface{})

SetNodeValue Sets a metadata value to a node

func SetStatus

func SetStatus(status int)

SetStatus Sets its status

func Setup

func Setup(confpath string)

Setup Loads a configuration file into memory - pass an empty string to load nothing

func StartAsMARS

func StartAsMARS(confpath string)

StartAsMARS Starts the server as MARS server - For now this is meant to be used for mars-server ONLY

func USend

func USend(commandID uint16, addr string, data map[string]interface{})

USend Sends an unreliable message to a given node - addr = <address>:<port>

func USendMany

func USendMany(command uint16, addrs []string, data map[string]interface{}, limit int)

USendMany Sends an unreliable mesh network message to multiple nodes

commandID - Mesh message command ID
addrs     - A list of mesh node addreses to send the message to
data      - Data map to be sent
limit     - Maximum number of node to send the message at a time

type Node

Node a mesh network node data structure

type Node struct {
    Addr   string
    Type   string
    Values map[string]interface{}
    Self   bool
}

func GetNode

func GetNode(nodeAddr string) *Node

GetNode Returns a node by its address

func GetNodeByEndPoint

func GetNodeByEndPoint(endPoint string) *Node

GetNodeByEndPoint Returns a node by its server end point - only WebSocket, TCP, UDP, and HTTP

Subdirectories