func Command(commandID uint16, callback func(map[string]interface{}) (map[string]interface{}, error))
Command [DEPRECATED] defines a handling function for a mesh network messsage as a command Command is replaced by HandleCommand - Command messages are sent by SendRequest, SendMany, USend, USendMany
func CreateReturnBytes(data map[string]interface{}) ([]byte, error)
CreateReturnBytes converts a map into a byte array for HandleCommand handler's return value
func GetBool(data map[string]interface{}, name string) bool
GetBool returns a bool from the mesh network request/response data
func GetBytes(data map[string]interface{}, name string) []byte
GetBytes returns a byte array from the mesh network request/response data
func GetFloat64(data map[string]interface{}, name string) float64
GetFloat64 returns a float64 from the mesh network request/response data
func GetInt(data map[string]interface{}, name string) int
GetInt returns an int from the mesh network request/response data
func GetInt16(data map[string]interface{}, name string) int16
GetInt16 returns an int16 from the mesh network request/response data
func GetInt32(data map[string]interface{}, name string) int32
GetInt32 returns an int32 from the mesh network request/response data
func GetInt64(data map[string]interface{}, name string) int64
GetInt64 returns an int64 from the mesh network request/response data
func GetInt8(data map[string]interface{}, name string) int8
GetInt8 returns an int8 from the mesh network request/response data
func GetMyEndPoint() string
GetMyEndPoint Returns its own mesh network end point
[NOTE] Uses mutex lock internally.
func GetMyNodeEndPoint() string
GetMyNodeEndPoint returns the server endpoint (internet) its own node
[NOTE] Uses mutex lock internally.
func GetMyNodeType() string
GetMyNodeType Returns the node type of itself
func GetNodeAddresses(ignoreList []string) []string
GetNodeAddresses Returns all node addresses
[NOTE] Uses mutex lock internally.
func GetNodeAddressesByRole(nRole string) []string
GetNodeAddressesByRole Return the addresses of nodes by type
[NOTE] Uses mutex lock internally.
func GetNodeAddressesByType(nType string) []string
GetNodeAddressesByType Return the addresses of nodes by type. The returned list of addresses contain offline and taken nodes as well. [NOTE] Uses mutex lock internally.
func GetNodeEndPoint(nodeAddr string) string
GetNodeEndPoint returns the server endpoint (internet) of a node by its mesh node address - only TCP, UDP, and HTTP
[NOTE] Uses mutex lock internally.
func GetNodeRoleByType(nType string) string
GetNodeRoleByType Returns node role by node type. Possible values are: HTTP, TCP, UDP, WS, and empty if node type is invalid
[NOTE] Uses mutex lock internally.
func GetNodeType() string
GetNodeType returns the server type of the server
func GetNodeTypeByAddress(addr string) string
GetNodeTypeByAddress returns the server type of the given node by mesh address
[NOTE] Uses mutex lock internally.
func GetNodeTypes() []string
GetNodeTypes returns all node types currently in the Diarkis cluster
[NOTE] Uses mutex lock internally.
func GetNodeValue(nodeAddr string, name string) interface{}
GetNodeValue Returns a metadata value of a node by its address
[NOTE] Uses mutex lock internally.
func GetNodeValues(nodeAddr string) map[string]interface{}
GetNodeValues Returns all metadata values of a node by its address
[NOTE] Uses mutex lock internally.
func GetString(data map[string]interface{}, name string) string
GetString returns a string from the mesh network request/response data
func GetUint16(data map[string]interface{}, name string) uint16
GetUint16 returns a uint16 from the mesh network request/response data
func GetUint32(data map[string]interface{}, name string) uint32
GetUint32 returns a uint32 from the mesh network request/response data
func GetUint64(data map[string]interface{}, name string) uint64
GetUint64 returns a uint64 from the mesh network request/response data
func GetUint8(data map[string]interface{}, name string) uint8
GetUint8 returns a uint8 from the mesh network request/response data
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 HandleCommand(cmd uint16, cb func(map[string]interface{}) ([]byte, error))
HandleCommand defines a handling function for a mesh network messsage as a command HandleCommand replaces Command - Command messages are sent by SendRequest, SendMany, USend, USendMany
func IsCommandDuplicate(commandID uint16) bool
IsCommandDuplicate returns true if commandID is used elsewhere
func IsMyNodeOnline() bool
IsMyNodeOnline returns false if the node is offline (received SIGTERM)
[NOTE] Uses mutex lock internally.
When the node is offline, the connected clients will be raising OnOffline event
func IsMyNodeTaken() bool
IsMyNodeTaken returns true if the node is taken ((mesh.SetStatus(util.MeshStatusTaken))
[NOTE] Uses mutex lock internally.
When a node is thaken, the taken node will not be returned by HTTP server as available server.
func IsNodeOnline(nodeAddr string) bool
IsNodeOnline Returns true if the given node is online
[NOTE] Uses mutex lock internally.
When the node is offline, the connected clients will be raising OnOffline event
func IsNodeTaken(nodeAddr string) bool
IsNodeTaken returns false if the node is taken (mesh.SetStatus(util.MeshStatusTaken))
[NOTE] Uses mutex lock internally.
When a node is thaken, the taken node will not be returned by HTTP server as available server.
func OnUpdate(handler func())
OnUpdate Registers a callback on announcer update event
[NOTE] Uses mutex lock internally.
func OnUpdated(handler func())
OnUpdated Registers a callback on announcer updated event
[NOTE] Uses mutex lock internally.
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(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(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
commandID - Pre-defined command ID that coresponds with user defined custom handler function(s) You may define multiple handler functions for a command ID. addr - Target node address (inernal) to send the request to. data - Request data to be sent to the handler function(s). callback - The callback function to be invoked when the response comes back.
func SetAppName(name string)
SetAppName creates a name space within the mars-server in order to have multiple diarkis clusters
func SetEndPoint(endPoint string)
SetEndPoint Sets its own end point
[NOTE] Uses mutex lock internally.
func SetNodeRole(role string)
SetNodeRole [INTERNAL USE ONLY]
func SetNodeType(_nodeType string)
SetNodeType Sets a type to a name
func SetNodeValue(name string, val interface{})
SetNodeValue Sets a metadata value to a node
[NOTE] Uses mutex lock internally.
func SetStatus(status int)
SetStatus Sets its status
func Setup(confpath string)
Setup Loads a configuration file into memory - pass an empty string to load nothing
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(commandID uint16, addr string, data map[string]interface{})
USend Sends an unreliable message to a given node - addr = <address>:<port>
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
Node a mesh network node data structure
type Node struct { Addr string Type string Role string Values map[string]interface{} Self bool }
func GetNode(nodeAddr string) *Node
GetNode Returns a node by its address
[NOTE] Uses mutex lock internally.
func GetNodeByEndPoint(endPoint string) *Node
GetNodeByEndPoint Returns a node by its server end point - only WebSocket, TCP, UDP, and HTTP
[NOTE] Uses mutex lock internally.