teonet

package module
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: BSD-3-Clause Imports: 28 Imported by: 29

README

Teonet v5

Teonet v5 is pure Golang implementation of TRUdp and Teonet libraries and Teonet applications

GoDoc Go Report Card

Teonet is designed to create client-server systems and build networks for server applications operating within a microservice architecture. To do this, Teonet creates a network / cloud transport between its members. This transport uses UDP for communication between network peers. UDP packets are encrypted with unique keys. Teonet uses its own UDP-based protocol called Teonet Reliable UDP (TRU) for real-time communication, which allows low latency messages to be sent and protocol reliability features.

See more at main teonet-go page

License

BSD

Documentation

Overview

Teonet v4

Index

Constants

View Source
const (
	// Get server api command
	CmdServerAPI = 255
	// Get server api command
	CmdClientAPI = 254
)
View Source
const (
	ConfigDir = "teonet"
)
View Source
const (
	FmtMsgCommandNotCount = "command '%s' not found"
)
View Source
const IPv6Allow = true

Allow IPv6 connection between peers

View Source
const Version = "0.6.6"

Variables

View Source
var (
	ErrIncorrectServerKey = errors.New("incorrect server key received")
	ErrIncorrectPublicKey = errors.New("incorrect public key received")
	ErrTimeout            = errors.New("timeout")
)

Connet error

View Source
var ErrCommandTooShort = errors.New("command packet too short")

Error command packet too short

View Source
var ErrDoesNotConnectedToTeonet = errors.New("does not connected to teonet")
View Source
var ErrPeerDoesNotExists = errors.New("peer does not exists")
View Source
var ErrPeerNotConnected = errors.New("peer does not connected")

Error peer does not connected

View Source
var (
	ErrWoronCommand = errors.New("wrong command")
)

Functions

func CheckRequeredParams

func CheckRequeredParams(req ...string)

Check requered application parameters

func Log

func Log() *teolog.Teolog

Log get teonet log to use it in application and inside teonet

func Logfilter

func Logfilter(str string) teolog.Filter

Logfilter return string in teolog.Logfilter type

func Logo(title, ver string)

Logo print teonet logo

func LogoString

func LogoString(title, ver string) string

LogoString return teonet logo in string

func Nodes

func Nodes(url string) (ret *nodes, err error)

Nodes get auth nodes by URL

Types

type API

type API struct {
	*Teonet

	bslice.ByteSlice
	// contains filtered or unexported fields
}

API teonet api receiver

func (*API) Add

func (a *API) Add(cmds ...APInterface)

Add api command

func (*API) Cmd

func (a *API) Cmd(cmd byte) byte

Cmd return API command number and save this command to use in CmdNext

func (*API) CmdNext

func (a *API) CmdNext() byte

CmdNext return next API command number

func (API) Help

func (a API) Help(shorts ...bool) (str string)

String return strin with api commands

func (API) MarshalBinary

func (a API) MarshalBinary() (data []byte, err error)

MarshalBinary binary marshal API

func (API) Reader

func (a API) Reader() func(c *Channel, p *Packet, e *Event) (processed bool)

Reader process teonet commands as described in API

func (API) Reader2

func (a API) Reader2() func(data []byte, answer func(data []byte)) (processed bool)

Reader2 process not teonet (webrtc for example) commands as described in API

func (*API) SendAnswer

func (a *API) SendAnswer(cmd APInterface, c *Channel, data []byte, p *Packet) (id uint32, err error)

Send answer to request

func (*API) SendAnswer2

func (a *API) SendAnswer2(data []byte, answer func(data []byte)) (id uint32, err error)

Send answer to request

func (API) Short

func (a API) Short() string

Short get app short name

func (API) String

func (a API) String() (str string)

String is API stringlify, it return help text in string

type APIClient

type APIClient struct {
	APIDataAr
	// contains filtered or unexported fields
}

APIClient contains clients api data and receive methods

func (APIClient) Address

func (api APIClient) Address() string

Address returns application address.

func (*APIClient) AnswerMode

func (api *APIClient) AnswerMode(command interface{}) (ret APIanswerMode, ok bool)

AnswerMode get answer mode parameter by cmd number or name.

func (APIClient) AppLong added in v0.6.5

func (api APIClient) AppLong() string

AppLong returns application long name (description).

func (APIClient) AppName added in v0.6.5

func (api APIClient) AppName() string

AppName returns application name.

func (APIClient) AppShort added in v0.6.5

func (api APIClient) AppShort() string

AppShort returns application short name.

func (*APIClient) Cmd

func (api *APIClient) Cmd(name string) (cmd byte, ok bool)

Cmd get command number by name.

func (*APIClient) DataserverIp added in v0.6.6

func (api *APIClient) DataserverIp() (ip string)

DataserverIp gets dataserver ip address

func (*APIClient) GetCmd added in v0.6.5

func (api *APIClient) GetCmd(command interface{}) (cmd byte, err error)

GetCmd check command type and return command number.

func (APIClient) Help

func (api APIClient) Help(short bool) (str string)

APIClient return APICient help in string.

func (*APIClient) Return

func (api *APIClient) Return(command interface{}) (ret string, ok bool)

Return get return parameter by cmd number or name.

func (*APIClient) SendTo

func (api *APIClient) SendTo(command interface{}, data []byte,
	waits ...func(data []byte, err error)) (id int, err error)

SendTo sends api command.

func (APIClient) String

func (api APIClient) String() (str string)

String stringlify APIClient, return same string as Help function.

func (*APIClient) WaitFrom

func (api *APIClient) WaitFrom(command interface{}, packetID ...interface{}) (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 omitted too.

type APIData

type APIData struct {
	bslice.ByteSlice
	// contains filtered or unexported fields
}

APIData is teonet API interface builder data

func MakeAPI2

func MakeAPI2() *APIData

MakeAPI2 is second teonet API interface builder

func (APIData) Cmd

func (a APIData) Cmd() byte

Cmd return APIData cmd number

func (APIData) ExecMode

func (a APIData) ExecMode() (APIconnectMode, APIanswerMode)

ExecMode return APIData exec mode

func (APIData) Long

func (a APIData) Long() string

Long return APIData long name

func (APIData) MarshalBinary

func (a APIData) MarshalBinary() (data []byte, err error)

MarshalBinary binary marshal APIData

func (APIData) Name

func (a APIData) Name() string

Name return APIData name

func (APIData) Reader

func (a APIData) Reader(c *Channel, p *Packet, data []byte) bool

Reader return APIData reader

func (APIData) Reader2

func (a APIData) Reader2(data []byte, answer func(data []byte)) bool

Reader2 return APIData second reader

func (APIData) Ret

func (a APIData) Ret() string

Ret return APIData return mode

func (*APIData) SetAnswerMode

func (a *APIData) SetAnswerMode(answerMode APIanswerMode) *APIData

SetAnswerMode set APIData answer mode (data|cmd|packet|none)

func (*APIData) SetCmd

func (a *APIData) SetCmd(cmd byte) *APIData

SetCmd set APIData command number

func (*APIData) SetConnectMode

func (a *APIData) SetConnectMode(connectMode APIconnectMode) *APIData

SetConnectMode set APIData connect mode ( server|client|client&server )

func (*APIData) SetLong

func (a *APIData) SetLong(long string) *APIData

SetLong set APIData long name (like description)

func (*APIData) SetName

func (a *APIData) SetName(name string) *APIData

SetName set APIData name

func (*APIData) SetReader

func (a *APIData) SetReader(reader func(c *Channel, p *Packet, data []byte) bool) *APIData

SetReader set APIData reader

func (*APIData) SetReader2

func (a *APIData) SetReader2(reader2 func(data []byte, answer func(data []byte)) bool) *APIData

SetReader2 set APIData second reader

func (*APIData) SetReturn

func (a *APIData) SetReturn(ret string) *APIData

SetReturn set APIData return description

func (*APIData) SetShort

func (a *APIData) SetShort(short string) *APIData

SetShort set APIData short name

func (*APIData) SetUsage

func (a *APIData) SetUsage(usage string) *APIData

SetUsage set APIData usage text

func (APIData) Short

func (a APIData) Short() string

Short return APIData short name

func (*APIData) UnmarshalBinary

func (a *APIData) UnmarshalBinary(buf *bytes.Buffer) (err error)

UnmarshalBinary binary unmarshal APIData

func (APIData) Usage

func (a APIData) Usage() string

Usage return APIData usage text

type APIDataAr

type APIDataAr struct {
	Apis      []APIData   // API commands data
	UserField interface{} // Some user field
	bslice.ByteSlice
	// contains filtered or unexported fields
}

func (*APIDataAr) UnmarshalBinary

func (a *APIDataAr) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary binary unmarshal APIDataAr

type APIanswerMode

type APIanswerMode byte

APIexecMode how to answer to this command will be send. Constan may be combined, f.e. answer with Command and ID and Data: answerMode = CmdAnswer | PacketIDAnswer | DataAnswer

const (
	// DataAnswer - send data in answer
	DataAnswer APIanswerMode = 1 << iota

	// CmdAnswer - send command in answer
	CmdAnswer

	// PacketIDAnswer - send received packet ID in answer
	PacketIDAnswer

	// NoAnswer - answer does not send
	NoAnswer APIanswerMode = 0
)

type APIconnectMode

type APIconnectMode byte

APIconnectMode connection type of received command:

Server: execute command if there is server connection;
Client: execute command if there is client connection;
Both: execute command if there is any server or client connection

Server connection mode: any Peer connected to this application with function ConnectTo (and Peer send commands to this application). Client connection mode: this application connected to Peer with function ConnectTo (and Peer send commands to this application)

const (
	// ServerMode - execute command if there is server connection
	ServerMode APIconnectMode = 1 << iota

	// ClientMode - execute command if there is client connection
	ClientMode

	// AnyMode - execute command if there is any server or client connection
	AnyMode = ClientMode & ServerMode
)

type APInterface

type APInterface interface {
	Name() string
	Short() string
	Long() string
	Usage() string
	Ret() string
	Cmd() byte
	ExecMode() (APIconnectMode, APIanswerMode)
	Reader(c *Channel, p *Packet, data []byte) bool
	Reader2(data []byte, answer func(data []byte)) bool
}

APInterface is teonet api interface

func MakeAPI

func MakeAPI(name, short, long, usage, ret string, cmd byte,
	execMode APIconnectMode, answerMode APIanswerMode,
	reader func(c *Channel, p *Packet, data []byte) bool,
	reader2 func(data []byte, answer func(data []byte)) bool,
) APInterface

MakeAPI is teonet API interface builder

type ApiInterface

type ApiInterface interface {
	ProcessPacket(p interface{})
}

ApiInterface

type AuthCmd

type AuthCmd byte

AuthCmd auth command type

const (
	// CmdConnect send <cmd byte, data ConnectData> to teonet auth server to
	// connect to teonet; receive <cmd byte, data ConnectData> from teonet auth
	// server when connection established
	CmdConnect AuthCmd = iota

	// CmdConnectTo send <cmd byte, data ConnectToData> to teonet auth server to
	// connect to peer
	CmdConnectTo

	// CmdConnectToPeer command send by teonet auth to server to receive
	// connection from client
	CmdConnectToPeer

	// CmdResendConnectTo need to resend CmdConnectTo data from rauth to auth servers
	// to find peer and send command data to it
	CmdResendConnectTo

	// CmdResendConnectToPeerto need to resend CmdConnectToPeer data from rauth
	// to auth servers to find client and send command data to it
	CmdResendConnectToPeer

	// CmdGetIP used in rauth and return channels IP:Port
	CmdGetIP
)

Teoauth commands

func (AuthCmd) String

func (c AuthCmd) String() string

String return string with command name

type Channel

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

Channel stract and method receiver

func (Channel) Address

func (c Channel) Address() string

Address eturn string with channel address

func (Channel) Channel

func (c Channel) Channel() *tru.Channel

Channel return return poiner to tru channel

func (Channel) ClientMode

func (c Channel) ClientMode() bool

ClientMode return true if channel in client mode

func (Channel) IsConn

func (c Channel) IsConn(data []byte) bool

IsConn return true if channel has 'connect' prefix

func (Channel) IsNew

func (c Channel) IsNew() bool

IsNew return true if channel has 'new' prefix

func (Channel) Send

func (c Channel) Send(data []byte, attr ...interface{}) (id int, err error)

Send data to channel

func (Channel) ServerMode

func (c Channel) ServerMode() bool

ServerMode return true if channel in server mode

func (Channel) String

func (c Channel) String() string

String is channel stringify and return string with channel address

func (Channel) Triptime

func (c Channel) Triptime() time.Duration

Triptime return channels triptime

type CheckDataFunc

type CheckDataFunc func(data []byte) (ok bool)

type Command

type Command struct {
	Cmd  byte
	Data []byte
	// contains filtered or unexported fields
}

Command struct and method receiver

func (Command) Bytes

func (c Command) Bytes() (data []byte)

Bytes binary marshal command struct and return byte slice

func (Command) MarshalBinary

func (c Command) MarshalBinary() (data []byte, err error)

MarshalBinary binary marshal command struct

func (Command) Send

func (c Command) Send(channel *Channel, attr ...interface{}) (id int, err error)

Send command to channel

func (Command) SendTo

func (c Command) SendTo(addr string, attr ...interface{}) (id int, err error)

SendTo send command to channel by address

func (*Command) UnmarshalBinary

func (c *Command) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary binary unmarshal command struct

type ConnectData

type ConnectData struct {
	PubliKey      []byte // Client public key (generated from private key)
	Address       []byte // Client address (received after connect if empty)
	ServerKey     []byte // Server public key (send if exists or received in connect if empty)
	ServerAddress []byte // Server address (received after connect)
	Err           []byte // Error of connect data processing
	bslice.ByteSlice
}

ConnectData teonet connect data

func (ConnectData) MarshalBinary

func (c ConnectData) MarshalBinary() (data []byte, err error)

MarshalBinary binary marshal ConnectData

func (ConnectData) String

func (c ConnectData) String() string

String return string with ConnectData

func (*ConnectData) UnmarshalBinary

func (c *ConnectData) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary binary unmarshal ConnectData

type ConnectIpPort

type ConnectIpPort struct {
	IP   string
	Port int
}

ConnectIpPort

type ConnectToData

type ConnectToData struct {
	ID        string   // Request id
	FromAddr  string   // Peer address
	ToAddr    string   // Client address
	IP        string   // Peer external ip address (sets by teonet auth)
	Port      uint32   // Peer external port (sets by teonet auth)
	LocalIPs  []string // List of local IPs (set by client or peer)
	LocalPort uint32   // Local port (set by client or peer)
	Err       []byte   // Error of connectTo processing
	Resend    bool     // Resend flag
	bslice.ByteSlice
}

ConnectToData teonet connect data

func (ConnectToData) MarshalBinary

func (c ConnectToData) MarshalBinary() (data []byte, err error)

MarshalBinary binary marshal ConnectToData structure

func (*ConnectToData) UnmarshalBinary

func (c *ConnectToData) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary binary unmarshal ConnectToData structure

type Event

type Event struct {
	Event TeonetEventType
	Err   error
}

Teonet event struct

func (Event) String

func (e Event) String() (str string)

Event to string

type ExcludeIPs

type ExcludeIPs struct {
	IPs []string
}

ExcludeIPs

type Hotkey

type Hotkey = tru.Hotkey

type IPs

type IPs struct {
	LocalIPs  []string
	LocalPort uint32
	IP        string
	Port      uint32
}

IPs struct contain peers local and global IPs and ports

type KeyData added in v0.6.2

type KeyData []byte

func (KeyData) String added in v0.6.2

func (k KeyData) String() string

type LogFilter

type LogFilter = teolog.Filter

type MaxDataLen added in v0.5.29

type MaxDataLen = tru.MaxDataLenType

type NodeAddr

type NodeAddr struct {
	IP   string
	Port uint32
}

NodeAddr is node address struct contained nodes IP and Port

type OsConfigDir

type OsConfigDir string

OsConfigDir used in teonet.New parameter to define os config directory

type Packet

type Packet struct {
	*tru.Packet
	// contains filtered or unexported fields
}

Packet is teonet Packet structure and methods receiver

func (Packet) Cmd

func (p Packet) Cmd() byte

Cmd return packets command number

func (Packet) Data

func (p Packet) Data() []byte

Data return packets data

func (Packet) From

func (p Packet) From() string

From return packets from address

func (*Packet) RemoveTrailingZero

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

RemoveTrailingZero used for compatibility with teoapi.Packet from teonet-go

type PuncherData

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

PuncherData is puncher data struct

type Stat

type Stat = tru.Stat

type Teonet

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

Teonet data structure and methods receiver

func New

func New(appName string, attr ...interface{}) (teo *Teonet, err error)

New create new teonet connection. The attr parameters:

int             port number to teonet listen
string          internal log Level to show teonet debug messages
Stat            set true to show tru statistic table
Hotkey          start hotkey meny
MaxDataLen      set max data length
*teolog.Teolog  teonet logger
ApiInterface    api interface
OsConfigDir     os directory to save config
func(c *Channel, p *Packet, e *Event) - message receiver
func(t *Teonet, c *Channel, p *Packet, e *Event) - message receiver

func (Teonet) AddReader

func (teo Teonet) AddReader(reader TreceivecbShort)

AddReader add teonet client reader

func (Teonet) Address

func (t Teonet) Address() (addr string)

Address get teonet address

func (Teonet) Channel

func (teo Teonet) Channel(addr string) (ch *Channel, exists bool)

Channel get teonet channel by address

func (Teonet) ChannelByIP

func (teo Teonet) ChannelByIP(addr string) (ch *Channel, exists bool)

Channel get teonet channel by ip address

func (*Teonet) Close

func (teo *Teonet) Close()

Close all channels

func (Teonet) CloseTo

func (teo Teonet) CloseTo(addr string) (err error)

CloseTo close connection to peere previously opened by ConnecTo

func (*Teonet) Command

func (teo *Teonet) Command(attr ...interface{}) (cmd *Command)

Command create command struct. Attr may contain 1 or 2 parameters:

1 parameter
    command & data slice - []byte

2 parameters
    command  - AuthCmd | byte | int
    data     - []byte | string | nil

func (Teonet) ConfigFile

func (teo Teonet) ConfigFile(appName string, file string) (res string, err error)

ConfigFile return full path to config file

func (*Teonet) Connect

func (teo *Teonet) Connect(attr ...interface{}) (err error)

Connect to Teonet. Attributes parameter by type:

type eExcludeIPs - struct with IPs slice to exclude from
type ConnectIpPort - struct with IP and Port
type string - RHost URL
type int - directConnectDelay in millisecond to execute direct connect to peers

func (Teonet) ConnectTo

func (teo Teonet) ConnectTo(addr string, readers ...interface{}) (err error)

ConnectTo connect to any teonet Peer(client or server) by address

func (*Teonet) Connected

func (teo *Teonet) Connected(addr string) (ok bool)

Connected return true if peer with selected address is connected now

func (Teonet) GetPrivateKey

func (teo Teonet) GetPrivateKey() (key KeyData)

GetPrivateKey get teonet private key

func (Teonet) GetPublicKey

func (t Teonet) GetPublicKey() []byte

GetPublicKey get teonet public key from private key

func (Teonet) Hotkey

func (teo Teonet) Hotkey() *hotkey.Hotkey

Hotkey return pointer to hotkey menu used in tru or nil if hotkey menu does not start

func (Teonet) Log

func (teo Teonet) Log() *teolog.Teolog

Log get teonet log

func (Teonet) MakeAddress

func (t Teonet) MakeAddress(keyData []byte) (addr string, err error)

MakeAddress make teonet address from key

func (*Teonet) MakeWaitAttr

func (teo *Teonet) MakeWaitAttr() *WaitAttr

MakeWaitAttr make wait attribute

func (*Teonet) MakeWaitReader

func (teo *Teonet) MakeWaitReader(attr ...interface{}) (wr *WaitReader)

MakeWaitReader create reader, wait channel and timeout from attr:

byte or int: wait command number in answer
uint32: wait packet id in answer
func([]byte)bool: check packet data with callback, data without command and id
time.Duration: wait timeout (default 5 sec)
bool: created wait channel and send data to channel if true

answer packet data structure: [cmd][id][data] it depend of service api

func (*Teonet) NewAPI

func (teo *Teonet) NewAPI(name, short, long, version string, cmdAPIs ...byte) (api *API)

NewAPI create new teonet api

func (*Teonet) NewAPIClient

func (teo *Teonet) NewAPIClient(address string, cmdAPIs ...byte) (apicli *APIClient, err error)

NewAPIClient create new APIClient object

func (Teonet) Nodes

func (teo Teonet) Nodes(attr ...NodeAddr) (n *nodes)

Nodes get list of channels IPs in nodes struct

func (Teonet) NumPeers

func (teo Teonet) NumPeers() int

NumPeers return number of connected peers

func (Teonet) Peers

func (teo Teonet) Peers() (p []string)

Peers get slice of channels address

func (Teonet) Port

func (teo Teonet) Port() int

Port get teonet local port

func (Teonet) RHost

func (teo Teonet) RHost() *Channel

RHost return current auth server

func (Teonet) ReconnectOff added in v0.5.23

func (teo Teonet) ReconnectOff(addr string) (err error)

ReconnectOff will stop reconnection when peer will be disconnected. By default all Teonet connections will forewer try automatic reconnect when peer disoconnected. To stop this reconnection call ReconnectOff any time after ConnetTo.

func (*Teonet) SendTo

func (teo *Teonet) SendTo(addr string, data []byte, attr ...interface{}) (id int, err error)

Send data to peer

func (*Teonet) SetConnected

func (teo *Teonet) SetConnected(c *Channel, addr string)

SetConnected set address to channel, add channel to channels list and send event to main teonet reader

func (Teonet) ShowTrudp

func (teo Teonet) ShowTrudp(set bool)

ShowTrudp show/stop tru statistic

func (Teonet) Subscribe

func (teo Teonet) Subscribe(address string, reader interface{}) (scr *subscribeData, err error)

Subscribe to receive packets from address. The reader attribute may be teonet.Treceivecb or teonet.TreceivecbShort type

func (Teonet) SubscribersNum added in v0.5.26

func (teo Teonet) SubscribersNum() int

SubscribersNum return number of subscribers

func (Teonet) Unsubscribe

func (teo Teonet) Unsubscribe(s *subscribeData)

Unsubscribe from channel data

func (*Teonet) WaitFrom

func (teo *Teonet) WaitFrom(from string, attr ...interface{}) (data []byte, err error)

WaitFrom wait answer from address. Attr is additional attributes by type:

byte or int: wait command number in answer
uint32: wait packet id in answer
func([]byte)bool: check packet data with callback, data without command and id
time.Duration: wait timeout (default 5 sec)

answer packet data structure: [cmd][id][data] it depend of service api

func (*Teonet) WaitReaderAnswer

func (teo *Teonet) WaitReaderAnswer(wait chan WaitData, timeout time.Duration) (data []byte, err error)

WaitReaderAnswer wait data from reader, return received data or error on timeout

func (*Teonet) WhenConnectedDisconnected

func (teo *Teonet) WhenConnectedDisconnected(f func(e byte))

WhenConnectedDisconnected call faunction f when connected or disconnected to any peer

func (*Teonet) WhenConnectedTo

func (teo *Teonet) WhenConnectedTo(address string, f func())

WhenConnectedTo call faunction f when connected to peer by address

type TeonetCommand

type TeonetCommand struct {
	*Teonet
}

TeonetCommand is teonet command interface methods receiver

func NewCommandInterface

func NewCommandInterface(appName string, attr ...interface{}) (teo *TeonetCommand, err error)

NewCommandInterface create teonet client with command interfeice connected

func (TeonetCommand) SendAnswer

func (teo TeonetCommand) SendAnswer(i interface{}, cmd byte, data []byte) (n int, err error)

SendAnswer send command answer

func (TeonetCommand) SendTo

func (teo TeonetCommand) SendTo(addr string, cmd byte, data []byte) (n int, err error)

SendTo send to address

func (TeonetCommand) WaitFrom

func (teo TeonetCommand) WaitFrom(addr string, cmd byte, attr ...interface{}) <-chan *struct {
	Data []byte
	Err  error
}

WaitFrom wait answer from address

type TeonetEventType

type TeonetEventType byte

Teonet event type

const (
	EventNone TeonetEventType = iota

	// Event when Teonet client initialized and start listen, Err = nil
	EventTeonetInit

	// Event when Connect to teonet r-host, Err = nil
	EventTeonetConnected

	// Event when Disconnect from teonet r-host, Err = dosconnect error
	EventTeonetDisconnected

	// Event when Connect to peer, Err = nil
	EventConnected

	// Event when Disconnect from peer, Err = dosconnect error
	EventDisconnected

	// Event when Data Received, Err = nil
	EventData
)

Teonet events

type Treceivecb

type Treceivecb func(teo *Teonet, c *Channel, p *Packet, e *Event) bool

type TreceivecbShort

type TreceivecbShort func(c *Channel, p *Packet, e *Event) bool

type WaitAttr

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

WaitAttr wait attribute

func (*WaitAttr) Cmd

func (w *WaitAttr) Cmd(cmd byte) *WaitAttr

Cmd append command to wait attribute

func (*WaitAttr) Func

func (w *WaitAttr) Func(f func([]byte) bool) *WaitAttr

Func append func to wait attribute

func (*WaitAttr) GetAttr

func (w *WaitAttr) GetAttr() []interface{}

GetAttr return wait attribute

func (*WaitAttr) ID

func (w *WaitAttr) ID(id uint32) *WaitAttr

ID append id to wait attribute

func (*WaitAttr) Timeout

func (w *WaitAttr) Timeout(t time.Duration) *WaitAttr

Timeout append timeout to wait attribute

type WaitData

type WaitData []byte

type WaitReader

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

WaitReader contain create reader, wait channel and timeout

func (WaitReader) Reader

func (wr WaitReader) Reader() func(c *Channel, p *Packet, e *Event) (processed bool)

Reader call wait reader

func (WaitReader) Timeout

func (wr WaitReader) Timeout() time.Duration

Timeout get timeout

func (WaitReader) Wait

func (wr WaitReader) Wait() chan WaitData

Wait data from wait channel

Directories

Path Synopsis
cmd
teoapicli
Teonet client connected to teonet server with api interface sample application
Teonet client connected to teonet server with api interface sample application
teoapi Module
teoecho Module
teonet Module

Jump to

Keyboard shortcuts

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