Documentation
¶
Overview ¶
Teonet v4
Index ¶
- Constants
- Variables
- func CheckRequeredParams(req ...string)
- func Log() *teolog.Teolog
- func Logfilter(str string) teolog.Filter
- func Logo(title, ver string)
- func LogoString(title, ver string) string
- func Nodes(url string) (ret *nodes, err error)
- type API
- func (a *API) Add(cmds ...APInterface)
- func (a *API) Cmd(cmd byte) byte
- func (a *API) CmdNext() byte
- func (a API) Help(shorts ...bool) (str string)
- func (a API) MarshalBinary() (data []byte, err error)
- func (a API) Reader() func(c *Channel, p *Packet, e *Event) (processed bool)
- func (a API) Reader2() func(data []byte, answer func(data []byte)) (processed bool)
- func (a *API) SendAnswer(cmd APInterface, c *Channel, data []byte, p *Packet) (id uint32, err error)
- func (a *API) SendAnswer2(data []byte, answer func(data []byte)) (id uint32, err error)
- func (a API) Short() string
- func (a API) String() (str string)
- type APIClient
- func (api APIClient) Address() string
- func (api *APIClient) AnswerMode(command interface{}) (ret APIanswerMode, ok bool)
- func (api APIClient) AppLong() string
- func (api APIClient) AppName() string
- func (api APIClient) AppShort() string
- func (api *APIClient) Cmd(name string) (cmd byte, ok bool)
- func (api *APIClient) DataserverIp() (ip string)
- func (api *APIClient) GetCmd(command interface{}) (cmd byte, err error)
- func (api APIClient) Help(short bool) (str string)
- func (api *APIClient) Return(command interface{}) (ret string, ok bool)
- func (api *APIClient) SendTo(command interface{}, data []byte, waits ...func(data []byte, err error)) (id int, err error)
- func (api APIClient) String() (str string)
- func (api *APIClient) WaitFrom(command interface{}, packetID ...interface{}) (data []byte, err error)
- type APIData
- func (a APIData) Cmd() byte
- func (a APIData) ExecMode() (APIconnectMode, APIanswerMode)
- func (a APIData) Long() string
- func (a APIData) MarshalBinary() (data []byte, err error)
- func (a APIData) Name() string
- func (a APIData) Reader(c *Channel, p *Packet, data []byte) bool
- func (a APIData) Reader2(data []byte, answer func(data []byte)) bool
- func (a APIData) Ret() string
- func (a *APIData) SetAnswerMode(answerMode APIanswerMode) *APIData
- func (a *APIData) SetCmd(cmd byte) *APIData
- func (a *APIData) SetConnectMode(connectMode APIconnectMode) *APIData
- func (a *APIData) SetLong(long string) *APIData
- func (a *APIData) SetName(name string) *APIData
- func (a *APIData) SetReader(reader func(c *Channel, p *Packet, data []byte) bool) *APIData
- func (a *APIData) SetReader2(reader2 func(data []byte, answer func(data []byte)) bool) *APIData
- func (a *APIData) SetReturn(ret string) *APIData
- func (a *APIData) SetShort(short string) *APIData
- func (a *APIData) SetUsage(usage string) *APIData
- func (a APIData) Short() string
- func (a *APIData) UnmarshalBinary(buf *bytes.Buffer) (err error)
- func (a APIData) Usage() string
- type APIDataAr
- type APIanswerMode
- type APIconnectMode
- type APInterface
- type ApiInterface
- type AuthCmd
- type Channel
- func (c Channel) Address() string
- func (c Channel) Channel() *tru.Channel
- func (c Channel) ClientMode() bool
- func (c Channel) IsConn(data []byte) bool
- func (c Channel) IsNew() bool
- func (c Channel) Send(data []byte, attr ...interface{}) (id int, err error)
- func (c Channel) ServerMode() bool
- func (c Channel) String() string
- func (c Channel) Triptime() time.Duration
- type CheckDataFunc
- type Command
- func (c Command) Bytes() (data []byte)
- func (c Command) MarshalBinary() (data []byte, err error)
- func (c Command) Send(channel *Channel, attr ...interface{}) (id int, err error)
- func (c Command) SendTo(addr string, attr ...interface{}) (id int, err error)
- func (c *Command) UnmarshalBinary(data []byte) (err error)
- type ConnectData
- type ConnectIpPort
- type ConnectToData
- type Event
- type ExcludeIPs
- type Hotkey
- type IPs
- type KeyData
- type LogFilter
- type MaxDataLen
- type NodeAddr
- type OsConfigDir
- type Packet
- type PuncherData
- type Stat
- type Teonet
- func (teo Teonet) AddReader(reader TreceivecbShort)
- func (t Teonet) Address() (addr string)
- func (teo Teonet) Channel(addr string) (ch *Channel, exists bool)
- func (teo Teonet) ChannelByIP(addr string) (ch *Channel, exists bool)
- func (teo *Teonet) Close()
- func (teo Teonet) CloseTo(addr string) (err error)
- func (teo *Teonet) Command(attr ...interface{}) (cmd *Command)
- func (teo Teonet) ConfigFile(appName string, file string) (res string, err error)
- func (teo *Teonet) Connect(attr ...interface{}) (err error)
- func (teo Teonet) ConnectTo(addr string, readers ...interface{}) (err error)
- func (teo *Teonet) Connected(addr string) (ok bool)
- func (teo Teonet) GetPrivateKey() (key KeyData)
- func (t Teonet) GetPublicKey() []byte
- func (teo Teonet) Hotkey() *hotkey.Hotkey
- func (teo Teonet) Log() *teolog.Teolog
- func (t Teonet) MakeAddress(keyData []byte) (addr string, err error)
- func (teo *Teonet) MakeWaitAttr() *WaitAttr
- func (teo *Teonet) MakeWaitReader(attr ...interface{}) (wr *WaitReader)
- func (teo *Teonet) NewAPI(name, short, long, version string, cmdAPIs ...byte) (api *API)
- func (teo *Teonet) NewAPIClient(address string, cmdAPIs ...byte) (apicli *APIClient, err error)
- func (teo Teonet) Nodes(attr ...NodeAddr) (n *nodes)
- func (teo Teonet) NumPeers() int
- func (teo Teonet) Peers() (p []string)
- func (teo Teonet) Port() int
- func (teo Teonet) RHost() *Channel
- func (teo Teonet) ReconnectOff(addr string) (err error)
- func (teo *Teonet) SendTo(addr string, data []byte, attr ...interface{}) (id int, err error)
- func (teo *Teonet) SetConnected(c *Channel, addr string)
- func (teo Teonet) ShowTrudp(set bool)
- func (teo Teonet) Subscribe(address string, reader interface{}) (scr *subscribeData, err error)
- func (teo Teonet) SubscribersNum() int
- func (teo Teonet) Unsubscribe(s *subscribeData)
- func (teo *Teonet) WaitFrom(from string, attr ...interface{}) (data []byte, err error)
- func (teo *Teonet) WaitReaderAnswer(wait chan WaitData, timeout time.Duration) (data []byte, err error)
- func (teo *Teonet) WhenConnectedDisconnected(f func(e byte))
- func (teo *Teonet) WhenConnectedTo(address string, f func())
- type TeonetCommand
- type TeonetEventType
- type Treceivecb
- type TreceivecbShort
- type WaitAttr
- type WaitData
- type WaitReader
Constants ¶
const ( // Get server api command CmdServerAPI = 255 // Get server api command CmdClientAPI = 254 )
const (
ConfigDir = "teonet"
)
const (
FmtMsgCommandNotCount = "command '%s' not found"
)
const IPv6Allow = true
Allow IPv6 connection between peers
const Version = "0.6.6"
Variables ¶
var ( ErrIncorrectServerKey = errors.New("incorrect server key received") ErrIncorrectPublicKey = errors.New("incorrect public key received") ErrTimeout = errors.New("timeout") )
Connet error
var ErrCommandTooShort = errors.New("command packet too short")
Error command packet too short
var ErrDoesNotConnectedToTeonet = errors.New("does not connected to teonet")
var ErrPeerDoesNotExists = errors.New("peer does not exists")
var ErrPeerNotConnected = errors.New("peer does not connected")
Error peer does not connected
var (
ErrWoronCommand = errors.New("wrong command")
)
Functions ¶
func CheckRequeredParams ¶
func CheckRequeredParams(req ...string)
Check requered application parameters
Types ¶
type API ¶
API teonet api receiver
func (API) MarshalBinary ¶
MarshalBinary binary marshal 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 ¶
Send answer to request
type APIClient ¶
type APIClient struct { APIDataAr // contains filtered or unexported fields }
APIClient contains clients api data and receive methods
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) DataserverIp ¶ added in v0.6.6
DataserverIp gets dataserver ip address
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) 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 ¶
APIData is teonet API interface builder data
func (APIData) ExecMode ¶
func (a APIData) ExecMode() (APIconnectMode, APIanswerMode)
ExecMode return APIData exec mode
func (APIData) MarshalBinary ¶
MarshalBinary binary marshal APIData
func (*APIData) SetAnswerMode ¶
func (a *APIData) SetAnswerMode(answerMode APIanswerMode) *APIData
SetAnswerMode set APIData answer mode (data|cmd|packet|none)
func (*APIData) SetConnectMode ¶
func (a *APIData) SetConnectMode(connectMode APIconnectMode) *APIData
SetConnectMode set APIData connect mode ( server|client|client&server )
func (*APIData) SetReader2 ¶
SetReader2 set APIData second reader
func (*APIData) UnmarshalBinary ¶
UnmarshalBinary binary unmarshal APIData
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 ¶
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 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
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel stract and method receiver
func (Channel) ClientMode ¶
ClientMode return true if channel in client mode
func (Channel) ServerMode ¶
ServerMode return true if channel in server mode
type CheckDataFunc ¶
type Command ¶
Command struct and method receiver
func (Command) MarshalBinary ¶
MarshalBinary binary marshal command struct
func (*Command) UnmarshalBinary ¶
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 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 MaxDataLen ¶ added in v0.5.29
type MaxDataLen = tru.MaxDataLenType
type OsConfigDir ¶
type OsConfigDir string
OsConfigDir used in teonet.New parameter to define os config directory
type Packet ¶
Packet is teonet Packet structure and methods receiver
func (*Packet) RemoveTrailingZero ¶
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 Teonet ¶
type Teonet struct {
// contains filtered or unexported fields
}
Teonet data structure and methods receiver
func New ¶
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) ChannelByIP ¶
Channel get teonet channel by ip address
func (*Teonet) 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 ¶
ConfigFile return full path to config file
func (*Teonet) Connect ¶
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) GetPrivateKey ¶
GetPrivateKey get teonet private key
func (Teonet) GetPublicKey ¶
GetPublicKey get teonet public key from private key
func (Teonet) Hotkey ¶
Hotkey return pointer to hotkey menu used in tru or nil if hotkey menu does not start
func (Teonet) MakeAddress ¶
MakeAddress make teonet address from key
func (*Teonet) MakeWaitAttr ¶
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) NewAPIClient ¶
NewAPIClient create new APIClient object
func (Teonet) ReconnectOff ¶ added in v0.5.23
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) SetConnected ¶
SetConnected set address to channel, add channel to channels list and send event to main teonet reader
func (Teonet) Subscribe ¶
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
SubscribersNum return number of subscribers
func (Teonet) Unsubscribe ¶
func (teo Teonet) Unsubscribe(s *subscribeData)
Unsubscribe from channel data
func (*Teonet) WaitFrom ¶
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 ¶
WhenConnectedDisconnected call faunction f when connected or disconnected to any peer
func (*Teonet) WhenConnectedTo ¶
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
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 WaitAttr ¶
type WaitAttr struct {
// contains filtered or unexported fields
}
WaitAttr wait attribute
type WaitReader ¶
type WaitReader struct {
// contains filtered or unexported fields
}
WaitReader contain create reader, wait channel and timeout