Bad Response packet status
const Bad = 4
Err Response packet status
const Err = 5
Ok Response packet status
const Ok = 1
Type Mesh network type for TCP server
const Type = "TCP"
func Command(ver uint8, cmd uint16, handlerName string, handler func(*State, func(error)))
Command Registers a packet handler as a command
func GetConnectionTTL() int64
GetConnectionTTL returns connection TTL
func GetEndPoint() string
GetEndPoint Returns TCP server 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 TCP 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 command ID are used elsewhere when this function is called
func IsEncryptionEnabled() bool
IsEncryptionEnabled returns true if encryption/decryption is enabled
func Offline()
Offline flag the serve to be offline to be deleted and will not take new users
func OnDisconnect(callback func(string, string, string, error), last bool)
OnDisconnect Registers a callback on connection disconnect
func OnHeartbeat(handler func(*State, func(error)))
OnHeartbeat Registers a handler to be executed on heartbeat
func OnNewConnection(callback func(*State))
OnNewConnection Registers a callback on new TCP connection w/ a client
func Online()
Online flag the server to be online to take new users
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 configuration file into memory - pass an empty string to load nothing
func ShutdownTCP(_ context.Context, next func(error))
ShutdownTCP Stops TCP server
func Taken()
Taken flag the server to be taken and will not take new users
State Client state data structure
type State struct { // UserID is set on ecryptTCPPacket of user on every in coming packet UserID string SID string Conn *net.TCPConn ClientAddr string TTLDuration int64 TTL int64 Connected bool // overwritten on every command Version uint8 // overwritten on every command CommandID uint16 // payload of a command Payload []byte // copied from user package - encryption keys EncryptionKey []byte EncryptionIV []byte EncryptionMacKey []byte ClientKey string // contains filtered or unexported fields }
func GetStateByAddr(addr string) *State
GetStateByAddr Returns a client state struct by client address
func (state *State) Disconnect()
Disconnect Disconnects the socket connection to the client
func (state *State) Kill(err error)
Kill Forcefully terminates the socket connection to the client
func (state *State) Push(ver uint8, cmd uint16, payload []byte) (int, error)
Push Sends a push packet to the client
func (state *State) Send(ver uint8, cmd uint16, payload []byte, status uint8) (int, error)
Send Sends a response packet to the client