Bad Response packet status
const Bad = 4
Err Response packet status
const Err = 5
Ok Response packet status
const Ok = 1
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 GetAddrByPingTryUser(sid string) (addr string)
GetAddrByPingTryUser gets the public IP address of the user who tries to Ping Try
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 command ID are used elsewhere when this function is called
func IsEncryptionEnabled() bool
IsEncryptionEnabled returns true if encryption/decryption is enabled
func IsP2PEnabled() bool
IsP2PEnabled returns true if P2P is enabled by the configuration
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), 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 flag the server to be online to take new users
func SendPingReply(addr net.Addr) error
SendPingReply sends a Ping Reply packet to the given address
func SendPingTry(addr net.Addr) error
SendPingTry sends a Ping Try packet to the given address
func SendTo(packets []byte, addr net.Addr) error
SendTo sends a packet to the client without a connection
func SendToWithHook(addr net.Addr, packets []byte, hook func(*State, []byte) ([]byte, error)) error
SendToWithHook sends a packet to passed address with a hook Note: callback does not return state.
func SendWithHook(state *State, packets []byte, hook func(*State, []byte) ([]byte, error)) error
SendWithHook sends a packet to the client with a hook
func SetAddrByPingTryUser(sid string, addr string)
SetAddrByPingTryUser sets the public IP address of the user who tries to hole punch
func SetOnPingReply(ttl int, addr string, callback func(error))
SetOnPingReply sets a callback when the server receives a hole punch ack
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
func Taken()
Taken flag the server to be taken and will not take new users
Connection RUDP connection struct
type Connection struct { sync.RWMutex // 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 P2PEnabled bool // byte array of the client local address list (packet.StringListToBytes) ClientLocalAddrListBytes []byte // contains filtered or unexported fields }
func (state *State) Disconnect()
Disconnect Disconnects UDP client (RUDP) from the server
func (state *State) GetClientAddr() string
GetClientAddr returns client public address. If it is UDP server and enableP2P is false, it returns 0.0.0.0:0 instead.
func (state *State) GetConnection() *Connection
GetConnection returns RUDP connection struct
func (state *State) GetSeqForDup() uint32
GetSeqForDup returns sequence for packet duplicate detection.
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