teonet

package
v0.0.0-...-2e4d9bc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2021 License: BSD-3-Clause Imports: 30 Imported by: 0

Documentation

Overview

Package teonet contain Teonet server functions and data structures.

Index

Constants

View Source
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

View Source
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

View Source
const Version = "3.0.1"

Version Teonet version

Variables

View Source
var BINARY = []byte("BINARY")

BINARY data prefix used in teonet requests

View Source
var JSON = []byte("JSON")

JSON data prefix used in teonet requests

View Source
var MODULE = teokeys.Color(teokeys.ANSILightCyan, "(teonet)")

MODULE Teonet module name for using in logging

Functions

func DataIsJSON

func DataIsJSON(data []byte) bool

DataIsJSON simple check that data is JSON string

func Logo(title, ver string)

Logo print teonet logo

func RemoveTrailingZero

func RemoveTrailingZero(data []byte) []byte

RemoveTrailingZero remove trailing zero in byte slice

Types

type ChanWaitFromData

type ChanWaitFromData chan *struct {
	Data []byte
	Err  error
}

ChanWaitFromData 'wait command from' return channel

type EventData

type EventData struct {
	Event int
	Data  *Packet
}

EventData teonet channel data structure

type L0PacketData

type L0PacketData struct {
	// contains filtered or unexported fields
}

L0PacketData is l0 data of Teonet packet

func (*L0PacketData) Addr

func (l *L0PacketData) Addr() string

Addr l0 address getter

func (*L0PacketData) Port

func (l *L0PacketData) Port() int

Port l0 port getter

type Packet

type Packet struct {
	// contains filtered or unexported fields
}

Packet is Teonet packet data and method receiver

func (*Packet) Cmd

func (pac *Packet) Cmd() byte

Cmd return packets cmd number

func (*Packet) Data

func (pac *Packet) Data() (data []byte)

Data return packets data

func (*Packet) DataLen

func (pac *Packet) DataLen() int

DataLen return packets data len

func (*Packet) From

func (pac *Packet) From() string

From return packets from

func (*Packet) FromLen

func (pac *Packet) FromLen() int

FromLen return packets from length

func (*Packet) GetL0

func (pac *Packet) GetL0() *L0PacketData

GetL0 return packets l0 structure

func (*Packet) L0

func (pac *Packet) L0() (addr string, port int, ok bool)

L0 return l0 server address, port and ok == true if packer recived from l0 client

func (*Packet) Len

func (pac *Packet) Len() int

Len return packet length

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

func (pac *Packet) RemoveTrailingZero(data []byte) []byte

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

func (teo *Teonet) AppVersion() string

AppVersion return this teonet application version

func (*Teonet) Close

func (teo *Teonet) Close()

Close stops Teonet running

func (*Teonet) Event

func (teo *Teonet) Event() <-chan *EventData

Event returns pointer to EventCH channel

func (*Teonet) Host

func (teo *Teonet) Host() []byte

Host return host name byte array with leading zerro

func (*Teonet) Menu

func (teo *Teonet) Menu() *teokeys.HotkeyMenu

Menu is Hotkey menu getter

func (*Teonet) PacketCreateNew

func (teo *Teonet) PacketCreateNew(from string, cmd byte, data []byte) (packet *Packet)

PacketCreateNew create teonet packet

func (*Teonet) Reconnect

func (teo *Teonet) Reconnect()

Reconnect reconnects Teonet

func (*Teonet) Run

func (teo *Teonet) Run(proccess func(*Teonet))

Run start Teonet event loop

func (*Teonet) SendAnswer

func (teo *Teonet) SendAnswer(ipac interface{}, cmd byte, data []byte) (length int,
	err error)

SendAnswer send (answer) command to Teonet peer by received Packet

func (*Teonet) SendTo

func (teo *Teonet) SendTo(to string, cmd byte, data []byte) (length int,
	err error)

SendTo send command to Teonet peer

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

func (teo *Teonet) SetLoglevel(loglevel int)

SetLoglevel set current log level

func (*Teonet) Type

func (teo *Teonet) Type() []string

Type return this teonet application type (array of types)

func (*Teonet) Version

func (teo *Teonet) Version() string

Version return teonet version

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL