Documentation ¶
Overview ¶
Package teonet contain Teonet server functions and data structures.
Index ¶
- Constants
- Variables
- func DataIsJSON(data []byte) bool
- func Logo(title, ver string)
- func RemoveTrailingZero(data []byte) []byte
- type ChanWaitFromData
- type EventData
- type L0PacketData
- type Packet
- func (pac *Packet) Cmd() byte
- func (pac *Packet) Data() (data []byte)
- func (pac *Packet) DataLen() int
- func (pac *Packet) From() string
- func (pac *Packet) FromLen() int
- func (pac *Packet) GetL0() *L0PacketData
- func (pac *Packet) L0() (addr string, port int, ok bool)
- func (pac *Packet) Len() int
- func (pac *Packet) Parse() (rd *C.ksnCorePacketData, err error)
- func (pac *Packet) RemoveTrailingZero(data []byte) []byte
- type Parameters
- type Teonet
- func (teo *Teonet) AppVersion() string
- func (teo *Teonet) Close()
- func (teo *Teonet) Event() <-chan *EventData
- func (teo *Teonet) Host() []byte
- func (teo *Teonet) Menu() *teokeys.HotkeyMenu
- func (teo *Teonet) PacketCreateNew(from string, cmd byte, data []byte) (packet *Packet)
- func (teo *Teonet) Reconnect()
- func (teo *Teonet) Run(proccess func(*Teonet))
- func (teo *Teonet) SendAnswer(ipac interface{}, cmd byte, data []byte) (length int, err error)
- func (teo *Teonet) SendTo(to string, cmd byte, data []byte) (length int, err error)
- func (teo *Teonet) SendToClient(l0Peer string, client string, cmd byte, data []byte) (length int, err error)
- func (teo *Teonet) SendToClientAddr(l0 *L0PacketData, client string, cmd byte, data []byte) (length int, err error)
- func (teo *Teonet) SetLoglevel(loglevel int)
- func (teo *Teonet) Type() []string
- func (teo *Teonet) Version() string
- func (teo *Teonet) WaitFrom(from string, cmd byte, ii ...interface{}) ...
Constants ¶
const ( CmdNone = C.CMD_NONE // #00 Cmd none used as first peers command CmdConnectR = C.CMD_CONNECT_R // #04 A Peer want connect to r-host CmdConnect = C.CMD_CONNECT // #05 Inform peer about connected peer CmdDisconnect = C.CMD_DISCONNECTED // #06 Send to peers signal about disconnect CmdSplit = C.CMD_SPLIT // #68 Group of packets (Splited packets) CmdL0 = C.CMD_L0 // #70 Command from L0 Client CmdL0To = C.CMD_L0_TO // #71 Command to L0 Client CmdPeers = C.CMD_PEERS // #72 Get peers, allow JSON in request CmdPeersAnswer = C.CMD_PEERS_ANSWER // #73 Get peers answer CmdL0Clients = C.CMD_L0_CLIENTS // #79 Request clients list CmdL0ClientsAnswer = C.CMD_L0_CLIENTS_ANSWER // #80 Clients list CmdSubscribe = C.CMD_SUBSCRIBE // #81 Subscribe to event CmdUnsubscribe = C.CMD_UNSUBSCRIBE // #82 UnSubscribe from event CmdSubscribeAnswer = C.CMD_SUBSCRIBE_ANSWER // #83 Subscribe answer CmdL0ClientsNum = C.CMD_L0_CLIENTS_N // #84 Request clients number, allow JSON in request CmdL0ClientsNumAnswer = C.CMD_L0_CLIENTS_N_ANSWER // #85 Clients number CmdHostInfo = C.CMD_HOST_INFO // #90 Request host info, allow JSON in request CmdHostInfoAnswer = C.CMD_HOST_INFO_ANSWER // #91 Request host info, allow JSON in request CmdL0Auth = C.CMD_L0_AUTH // #96 L0 server auth request answer command CmdUser = C.CMD_USER // #129 User command )
Teonet commands
const ( EventStarted = C.EV_K_STARTED // #0 Calls immediately after event manager starts EventStoppedBefore = C.EV_K_STOPPED_BEFORE // #1 Calls before event manager stopped EventStopped = C.EV_K_STOPPED // #2 Calls after event manager stopped EventConnected = C.EV_K_CONNECTED // #3 New peer connected to this host EventDisconnected = C.EV_K_DISCONNECTED // #4 A peer was disconnected from this host EventReceived = C.EV_K_RECEIVED // #5 This host Received a data EventReceivedWrong = C.EV_K_RECEIVED_WRONG // #6 Wrong packet received )
Teonet events
const Version = "3.0.1"
Version Teonet version
Variables ¶
var BINARY = []byte("BINARY")
BINARY data prefix used in teonet requests
var JSON = []byte("JSON")
JSON data prefix used in teonet requests
var MODULE = teokeys.Color(teokeys.ANSILightCyan, "(teonet)")
MODULE Teonet module name for using in logging
Functions ¶
func DataIsJSON ¶
DataIsJSON simple check that data is JSON string
func RemoveTrailingZero ¶
RemoveTrailingZero remove trailing zero in byte slice
Types ¶
type ChanWaitFromData ¶
ChanWaitFromData 'wait command from' return channel
type L0PacketData ¶
type L0PacketData struct {
// contains filtered or unexported fields
}
L0PacketData is l0 data of Teonet packet
type Packet ¶
type Packet struct {
// contains filtered or unexported fields
}
Packet is Teonet packet data and method receiver
func (*Packet) L0 ¶
L0 return l0 server address, port and ok == true if packer recived from l0 client
func (*Packet) Parse ¶
func (pac *Packet) Parse() (rd *C.ksnCorePacketData, err error)
Parse parse teonet packet to 'rd' structure and return it
func (*Packet) RemoveTrailingZero ¶
RemoveTrailingZero remove trailing zero in byte slice
type Parameters ¶
type Parameters struct { Name string `json:"name"` // this host client name Port int `json:"port"` // local port RAddr string `json:"r-addr"` // remote host address RPort int `json:"r-port"` // remote host port RChan int `json:"r-ch"` // remote host channel(for TRUdp only) Network string `json:"network"` // teonet network name Loglevel string `json:"log-level"` // show log messages level LogFilter string `json:"log-filter"` // log messages filter LogToSyslogF bool `json:"log-to-syslog"` // forbid hotkeys menu ForbidHotkeysF bool `json:"forbid-hotkeys"` // forbid hotkeys menu ShowTrudpStatF bool `json:"show-trudp"` // show trudp statistic ShowPeersStatF bool `json:"show-peers"` // show peers table ShowClientsStatF bool `json:"show-clients"` // show clients table ShowParametersF bool `json:"show-params"` // show parameters SaveConfigF bool `json:"save-config"` // save current parameters to config ShowHelpF bool `json:"show-help"` // show usage IPv6Allow bool `json:"ipv6-allow"` // allow IPv6 support (not supported in Teonet-C) DisallowEncrypt bool `json:"disallow-encrypt"` // disable teonet packets encryption CtrlcF bool `json:"ctrlc"` // use Ctrl+C to gracefully exit from application L0allow bool `json:"l0-allow"` // allow l0 server L0tcpPort int `json:"l0-tcp-port"` // l0 Server tcp port number (default 9000) L0wsAllow bool `json:"l0-ws-allow"` // allow l0 WebSocket server L0wsPort int `json:"l0-ws-port"` // l0 Server websocket tcp port number (default 9080) }
Parameters Teonet parameters
func CreateParameters ¶
func CreateParameters() (param *Parameters)
CreateParameters create new Teonet parameters with default values
func Params ¶
func Params(apiiII ...interface{}) (param *Parameters)
Params read Teonet parameters from configuration file and parse application flars and arguments. If api parameter present than flag -api 'show teonet application api' with false by default added to the application parameters. Commands should be added before teonet connet to show with -api flag.
func (*Parameters) ReadConfig ¶
func (param *Parameters) ReadConfig()
ReadConfig read teonet configuration file
func (*Parameters) WriteConfig ¶
func (param *Parameters) WriteConfig()
WriteConfig write teonet configuration file
type Teonet ¶
type Teonet struct {
// contains filtered or unexported fields
}
Teonet teonet connection data structure
func Connect ¶
func Connect(param *Parameters, appType []string, appVersion string, apiII ...interface{}) (teo *Teonet)
Connect initialize Teonet Note: The forth parameter may be added to this function. There is value of '*teoapi.Teoapi'. If this api parammeter is set than api menu item adding to the hotkey menu. The api definition shoud be done before the 'teonet.Params(api)' calls.
func (*Teonet) AppVersion ¶
AppVersion return this teonet application version
func (*Teonet) PacketCreateNew ¶
PacketCreateNew create teonet packet
func (*Teonet) SendAnswer ¶
SendAnswer send (answer) command to Teonet peer by received Packet
func (*Teonet) SendToClient ¶
func (teo *Teonet) SendToClient(l0Peer string, client string, cmd byte, data []byte) (length int, err error)
SendToClient send command to Teonet L0 client
func (*Teonet) SendToClientAddr ¶
func (teo *Teonet) SendToClientAddr(l0 *L0PacketData, client string, cmd byte, data []byte) (length int, err error)
SendToClientAddr send command to Teonet L0 client by address
func (*Teonet) SetLoglevel ¶
SetLoglevel set current log level
func (*Teonet) WaitFrom ¶
func (teo *Teonet) WaitFrom(from string, cmd byte, ii ...interface{}) <-chan *struct { Data []byte Err error }
WaitFrom wait receiving data from peer. The third function parameter is timeout. It may be omitted or contain timeout time of time. Duration type. If timeout parameter is omitted than default timeout value sets to 2 second. Next parameter is checkDataFunc func([]byte) bool. This function calls to check packet data and returns true if packet data valid. This parameter may be ommited too.