Bad Response packet status
const Bad = 4
CmdSample count of received commands
const CmdSample = "um"
CmdSampleName the name of prometheus statistic
const CmdSampleName = "Commands_In"
Err Response packet status
const Err = 5
Ok Response packet status
const Ok = 1
PktSampleIn in bound packet sample node value name
const PktSampleIn = "ui"
PktSampleInName the name for prometheus statistic
const PktSampleInName = "UDP_Packets_In"
PktSampleOut out bound packet sample node value name
const PktSampleOut = "uo"
PktSampleOutName the name for prometheus statistic
const PktSampleOutName = "UDP_Packets_Out"
RetrySample count of retries of RSend Push RPush calls
const RetrySample = "ur"
RetrySampleName sample name of RUDP retry count
const RetrySampleName = "RUDP_Retries"
SendSample count of Send RSend Push RPush calls
const SendSample = "us"
SendSampleName the name of prometheus statistic
const SendSampleName = "Commands_Out"
SplitSampleIn count of in bound packet split
const SplitSampleIn = "si"
SplitSampleInName the name of prometheus statistic
const SplitSampleInName = "RUDP_Split_In"
SplitSampleOut count of out bound packet split
const SplitSampleOut = "so"
SplitSampleOutName the name of prometheus statistic
const SplitSampleOutName = "RUDP_Split_Out"
Type mesh network node type of UDP server
const Type = "UDP"
func Command(ver uint8, cmd uint16, handlerName string, handler func(*State, func(error)))
Command Registers a UDP packet handler as a command
func GetConnectionTTL() int64
GetConnectionTTL returns connection TTL
func GetEndPoint() string
GetEndPoint Returns its end point that is actually bound
func HookAllCommands(handlerName string, handler func(*State, func(error)))
HookAllCommands Registers a packet handler as a hook to all commands
func HookAllWrites(handler func(*State, []byte) ([]byte, error))
HookAllWrites Registers a handler function to all TCP socket writes: Receives the payload and returns a payload
func Init()
Init [INTERNAL USE ONLY] Flag the UDP server state to be initialized to prevent registration of commands and hooks BEFORE initialization by user package
func IsCommandDuplicate(ver uint8, commandID uint16) bool
IsCommandDuplicate returns true if ver and commandID are used elsewhere when this function is called
func IsEncryptionEnabled() bool
IsEncryptionEnabled returns true if encryption/decryption is enabled
func Offline()
Offline Sets its mesh network node status as offline
func OnDisconnect(callback func(string, string, string), last bool)
OnDisconnect Registers a callback function on RUDP disconnect
func OnEcho(handler func(*State, func(error)))
OnEcho Registers a handler to be executed on echo
func OnNewConnection(callback func(string) bool)
OnNewConnection [INTERNAL USE ONLY]
func Online()
Online Sets its mesh network node status as online
func SetPublicEndPoint(addr string)
SetPublicEndPoint sets public end point to be used by the client to connect
func Setup(confpath string)
Setup [INTERNAL USE ONLY] Loads a configuration file into memory - pass an empty string to load nothing
func ShutdownUDP()
ShutdownUDP Stops UDP server
Connection RUDP connection struct
type Connection struct {
// contains filtered or unexported fields
}
State Data structure of a client
type State struct { // UserID is set on decryptUDPPacket of user on every in coming packet UserID string SID string ClientAddr string ClientNetAddr net.Addr Version uint8 CommandID uint16 Payload []byte // copied from user package - encryption keys EncryptionKey []byte EncryptionIV []byte EncryptionMacKey []byte ClientKey string }
func (state *State) Disconnect()
Disconnect Disconnects UDP client (RUDP) from the server
func (state *State) GetConnection() *Connection
GetConnection returns RUDP connection struct
func (state *State) Push(ver uint8, cmd uint16, payload []byte) (int, error)
Push Sends a push packet to the client
func (state *State) RPush(conn *Connection, ver uint8, cmd uint16, payload []byte)
RPush Reliable UDP push from the server Same as RSend, we buffer the push packets and combine them into one packet at certain interval
func (state *State) RSend(conn *Connection, ver uint8, cmd uint16, payload []byte, status uint8)
RSend Reliable UDP send with status We turn outs bytes into one RUDP packet when we actually send it it means that all combined packets are considered "ONE" RUDP packet
func (state *State) Send(ver uint8, cmd uint16, payload []byte, status uint8) (int, error)
Send Sends a response packet to the client