Teonet library
0.4.7
|
#include <unistd.h>
#include <pthread.h>
#include <ev.h>
#include "config/opt.h"
#include "config/conf.h"
#include "utils/utils.h"
#include "hotkeys.h"
#include "modules/vpn.h"
#include "modules/cque.h"
#include "modules/teodb.h"
#include "modules/stream.h"
#include "modules/metric.h"
#include "modules/net_tcp.h"
#include "modules/net_tun.h"
#include "modules/net_term.h"
#include "modules/tcp_proxy.h"
#include "modules/l0-server.h"
#include "modules/log_reader.h"
#include "modules/async_calls.h"
#include "modules/logging_server.h"
#include "modules/logging_client.h"
Go to the source code of this file.
Data Structures | |
struct | ksnetEvMgrAppParam |
Application parameters user data. More... | |
struct | ksnetEvMgrClass |
KSNet event manager functions data. More... | |
struct | stdin_idle_data |
STDIN idle watcher data. More... | |
Macros | |
#define | NULL_STR (void*) null_str |
#define | CHECK_EVENTS_AFTER 11.5 |
#define | EVENT_MANAGER_OBJECT(X) |
#define | ARP_TABLE_OBJECT(X) |
Typedefs | |
typedef enum ksnetEvMgrEvents | ksnetEvMgrEvents |
KSNet event manager events. More... | |
typedef struct ksnetEvMgrAppParam | ksnetEvMgrAppParam |
Application parameters user data. More... | |
typedef struct ksnetEvMgrClass | ksnetEvMgrClass |
KSNet event manager functions data. More... | |
typedef void(* | event_cb_t )(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data) |
Event callback type. More... | |
typedef struct stdin_idle_data | stdin_idle_data |
STDIN idle watcher data. More... | |
typedef void(* | ksn_event_cb_type )(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data) |
Enumerations | |
enum | EventManagerStatus { kEventMgrStopped = 0, kEventMgrRunning = 1 } |
enum | ksnetEvMgrEvents { EV_K_STARTED, EV_K_STOPPED_BEFORE, EV_K_STOPPED, EV_K_CONNECTED, EV_K_DISCONNECTED, EV_K_RECEIVED, EV_K_RECEIVED_WRONG, EV_K_RECEIVED_ACK, EV_K_IDLE, EV_K_TIMER, EV_K_HOTKEY, EV_K_USER, EV_K_ASYNC, EV_K_TERM_STARTED, EV_K_CQUE_CALLBACK, EV_K_STREAM_CONNECTED, EV_K_STREAM_CONNECT_TIMEOUT, EV_K_STREAM_DISCONNECTED, EV_K_STREAM_DATA, EV_K_SUBSCRIBE, EV_K_SUBSCRIBED, EV_K_L0_CONNECTED, EV_K_L0_DISCONNECTED, EV_K_L0_NEW_VISIT, EV_H_HWS_EVENT, EV_U_RECEIVED, EV_D_SET, EV_A_INTERVAL, EV_K_LOGGING, EV_K_LOG_READER, EV_K_APP_USER = 0x8000 } |
KSNet event manager events. More... | |
Functions | |
ksnetEvMgrClass * | __ke_from_command_class (ksnCommandClass *X) |
ksnetEvMgrClass * | __ke_from_L0_class (ksnLNullClass *X) |
ksnetArpClass * | __arp_from_command_class (ksnCommandClass *X) |
ksnetEvMgrClass * | ksnetEvMgrInit (int argc, char **argv, ksn_event_cb_type event_cb, int options) |
Initialize KSNet Event Manager and network. More... | |
ksnetEvMgrClass * | ksnetEvMgrInitPort (int argc, char **argv, ksn_event_cb_type event_cb, int options, int port, void *user_data) |
Initialize KSNet Event Manager and network and set new default port. More... | |
int | ksnetEvMgrRun (ksnetEvMgrClass *ke) |
Start KSNet Event Manager and network communication. More... | |
int | ksnetEvMgrFree (ksnetEvMgrClass *ke, int free_async) |
Free ksnetEvMgrClass after run. More... | |
void | ksnetEvMgrStop (ksnetEvMgrClass *ke) |
Stop event manager. More... | |
int | ksnetEvMgrStatus (ksnetEvMgrClass *ke) |
int | ksnetEvMgrRestart (int argc, char **argv) |
Restart application. More... | |
void | ksnetEvMgrAsync (ksnetEvMgrClass *ke, void *data, size_t data_len, void *user_data) |
Async call to Event manager. More... | |
double | ksnetEvMgrGetTime (ksnetEvMgrClass *ke) |
Get KSNet event manager time. More... | |
char * | ksnetEvMgrGetHostName (ksnetEvMgrClass *ke) |
Return host name. More... | |
host_info_data * | teoGetHostInfo (ksnetEvMgrClass *ke, size_t *hd_len) |
Get host info data. More... | |
void | ksnetEvMgrSetCustomTimer (ksnetEvMgrClass *ke, double time_interval) |
Set custom timer interval. More... | |
const char * | teoGetLibteonetVersion () |
Get teonet library version. More... | |
void | teoSetAppType (ksnetEvMgrClass *ke, char *type) |
Set Teonet application type. More... | |
void | teoSetAppVersion (ksnetEvMgrClass *ke, char *version) |
Set Teonet application version. More... | |
const char * | teoGetAppType (ksnetEvMgrClass *ke) |
Get current application type. More... | |
char * | teoGetFullAppTypeFromHostInfo (host_info_data *hid) |
const char * | teoGetAppVersion (ksnetEvMgrClass *ke) |
Get current application version. More... | |
int | remove_peer_addr (ksnetEvMgrClass *ke, __CONST_SOCKADDR_ARG addr) |
Remove peer by address. More... | |
int | ksnetAllowAckEvent (ksnetEvMgrClass *ke, int allow) |
Allow or disallow send ACK event (EV_K_RECEIVED_ACK) to teonet event loop. More... | |
Variables | |
const char * | null_str |
File: ev_mgr.h Author: Kirill Scherba kiril l@sc herba .ruMore... | |
#define ARP_TABLE_OBJECT | ( | X | ) |
Referenced by cmd_disconnected_cb().
#define CHECK_EVENTS_AFTER 11.5 |
Referenced by check_connected_cb(), and timer_cb().
#define EVENT_MANAGER_OBJECT | ( | X | ) |
Referenced by _check_connected(), cmd_disconnected_cb(), cmd_l0_check_cb(), cmd_l0_kick_client(), cmd_reconnect_cb(), ksnCommandCheck(), ksnCommandEchoBuffer(), ksnCommandSendCmdConnect(), ksnCommandSendCmdConnectA(), ksnCommandSendCmdEcho(), ksnLNullClientDisconnect(), ksnLNullClientsList(), ksnLNullPacketSend(), ksnLNulltrudpCheckPaket(), and teoLNullPacketCheckMiscrypted().
#define NULL_STR (void*) null_str |
Referenced by open_local_port().
typedef void(* event_cb_t)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data) |
Event callback type.
typedef void(* ksn_event_cb_type)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data) |
typedef struct ksnetEvMgrAppParam ksnetEvMgrAppParam |
Application parameters user data.
typedef struct ksnetEvMgrClass ksnetEvMgrClass |
KSNet event manager functions data.
typedef enum ksnetEvMgrEvents ksnetEvMgrEvents |
KSNet event manager events.
typedef struct stdin_idle_data stdin_idle_data |
STDIN idle watcher data.
enum EventManagerStatus |
enum ksnetEvMgrEvents |
KSNet event manager events.
Enumerator | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
EV_K_STARTED |
#0 Calls immediately after event manager starts Parameters of Teonet Events callback function:
| ||||||||||
EV_K_STOPPED_BEFORE |
#1 Calls before event manager stopped Parameters of Teonet Events callback function:
| ||||||||||
EV_K_STOPPED |
#2 Calls after event manager stopped Parameters of Teonet Events callback function:
| ||||||||||
EV_K_CONNECTED |
#3 New peer connected to host event Parameters of Teonet Events callback function:
| ||||||||||
EV_K_DISCONNECTED |
#4 A peer was disconnected from host Parameters of Teonet Events callback function:
| ||||||||||
EV_K_RECEIVED |
#5 This host Received a data Parameters of Teonet Events callback function:
| ||||||||||
EV_K_RECEIVED_WRONG |
#6 Wrong packet received | ||||||||||
EV_K_RECEIVED_ACK |
#7 This host Received ACK to sent data Parameters of Teonet Events callback function:
| ||||||||||
EV_K_IDLE |
#8 Idle check host events (after 11.5 after last host send or receive data) | ||||||||||
EV_K_TIMER |
#9 Timer event | ||||||||||
EV_K_HOTKEY |
#10 Hotkey event Parameters of Teonet Events callback function:
| ||||||||||
EV_K_USER |
#11 User press A hotkey | ||||||||||
EV_K_ASYNC |
#12 Async event | ||||||||||
EV_K_TERM_STARTED |
#13 After terminal started (in place to define commands Parameters of Teonet Events callback function:
| ||||||||||
EV_K_CQUE_CALLBACK |
#14 Teonet Callback QUEUE event Parameters of Teonet Events callback function:
| ||||||||||
EV_K_STREAM_CONNECTED |
#15 After stream connected | ||||||||||
EV_K_STREAM_CONNECT_TIMEOUT |
#16 Connection timeout | ||||||||||
EV_K_STREAM_DISCONNECTED |
#17 After stream disconnected | ||||||||||
EV_K_STREAM_DATA |
#18 Input stream has a data | ||||||||||
EV_K_SUBSCRIBE |
#19 Subscribe answer command received | ||||||||||
EV_K_SUBSCRIBED |
#20 A peer subscribed to event at this host | ||||||||||
EV_K_L0_CONNECTED |
#21 New L0 client connected to L0 server | ||||||||||
EV_K_L0_DISCONNECTED |
#22 A L0 client was disconnected from L0 server | ||||||||||
EV_K_L0_NEW_VISIT |
#23 New clients visit event to all subscribers (equal to L0_CONNECTED but send number of visits) | ||||||||||
EV_H_HWS_EVENT |
#24 HTTP WebSocket server event, data - depends of event, user data - poiter to hws_event | ||||||||||
EV_U_RECEIVED |
#25 UNIX socket received data event, data - data received from unix socket, user_data - pointer to the usock_class | ||||||||||
EV_D_SET |
#26 Database updated | ||||||||||
EV_A_INTERVAL |
#27 Angular interval event happened This event sends by Angular Teonet Service running in Teonet Node Application when Angular interval tick happened Parameters of Teonet Events callback function:
| ||||||||||
EV_K_LOGGING |
#28 Logging server event, like EV_K_RECEIVED: data Pointer to ksnCorePacketData, data_len Size of ksnCorePacketData, , user_data NULL | ||||||||||
EV_K_LOG_READER |
#29 LogReader read data. | ||||||||||
EV_K_APP_USER |
#0x8000 Teonet based Applications events |
ksnetArpClass* __arp_from_command_class | ( | ksnCommandClass * | X | ) |
References ksnCommandClass::kc.
ksnetEvMgrClass* __ke_from_command_class | ( | ksnCommandClass * | X | ) |
References ksnCommandClass::kc.
ksnetEvMgrClass* __ke_from_L0_class | ( | ksnLNullClass * | X | ) |
References ksnLNullClass::ke.
|
inline |
Allow or disallow send ACK event (EV_K_RECEIVED_ACK) to teonet event loop.
ke | Pointer to ksnetEvMgrClass |
allow | Allow if true or disallow (set by default) |
References teonet_cfg::send_ack_event_f, and ksnetEvMgrClass::teo_cfg.
Referenced by main().
void ksnetEvMgrAsync | ( | ksnetEvMgrClass * | ke, |
void * | data, | ||
size_t | data_len, | ||
void * | user_data | ||
) |
Async call to Event manager.
ke | Pointer to ksnetEvMgrClass |
data | Pointer to data |
data_len | Data length |
user_data | Pointer to user data |
References ksnetEvMgrClass::async_mutex, ksnetEvMgrClass::async_queue, ksnetEvMgrClass::ev_loop, malloc(), and ksnetEvMgrClass::sig_async_w.
Referenced by teoLoggingClientSend().
int ksnetEvMgrFree | ( | ksnetEvMgrClass * | ke, |
int | free_async | ||
) |
Free ksnetEvMgrClass after run.
ke | Pointer to ksnetEvMgrClass |
free_async | 1 - free async queue data and destroy queue mutex; 0 - free basic class data; 2 - free all - async queue data and basic class data |
References ksnetEvMgrClass::app_type, ksnetEvMgrClass::app_version, ksnetEvMgrClass::argc, ksnetEvMgrClass::argv, ksnetEvMgrClass::async_mutex, ksnetEvMgrClass::async_queue, EV_K_STOPPED, EV_K_STOPPED_BEFORE, ksnetEvMgrClass::ev_loop, ksnetEvMgrClass::event_cb, free(), ksnetEvMgrClass::km, ksn_printf, ksnetEvMgrRestart(), MESSAGE, MODULE, modules_destroy(), ksnetEvMgrClass::net_idx, teonet_cfg::port, ksnetEvMgrClass::printf_mutex, run_file, ksnetEvMgrClass::sig_async_w, ksnetEvMgrClass::teo_cfg, and ksnetEvMgrClass::timer_w.
Referenced by ksnetEvMgrRun(), ksnMultiDestroy(), and teoMultiRemoveNet().
|
inline |
Return host name.
ke | Pointer to ksnetEvMgrClass |
References teonet_cfg::host_name, and ksnetEvMgrClass::teo_cfg.
Referenced by _check_connected(), event_cb(), teo::Teonet::getHostName(), ksnetEvMgrRun(), and teoGetHostInfo().
double ksnetEvMgrGetTime | ( | ksnetEvMgrClass * | ke | ) |
Get KSNet event manager time.
ke | Pointer to ksnetEvMgrClass |
References ksnetEvMgrClass::ev_loop, and ksnetEvMgrClass::runEventMgr.
Referenced by _check_connected(), check_connected_cb(), teo::Teonet::getTime(), ksnCommandEchoBuffer(), ksnCommandSendCmdEcho(), ksnCoreCheckNewPeer(), ksnCoreProcessPacket(), ksnet_printf(), ksnetArpShowData(), ksnetEvMgrSetCustomTimer(), ksnSplitCombine(), and timer_cb().
ksnetEvMgrClass* ksnetEvMgrInit | ( | int | argc, |
char ** | argv, | ||
ksn_event_cb_type | event_cb, | ||
int | options | ||
) |
Initialize KSNet Event Manager and network.
argc | Number of applications arguments (from main) |
argv | Applications arguments array (from main) |
event_cb | Events callback function called when an event happens |
options | Options set: READ_OPTIONS - read options from command line parameters; READ_CONFIGURATION - read options from configuration file |
References ksnetEvMgrInitPort().
ksnetEvMgrClass* ksnetEvMgrInitPort | ( | int | argc, |
char ** | argv, | ||
void(*)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data) | event_cb, | ||
int | options, | ||
int | port, | ||
void * | user_data | ||
) |
Initialize KSNet Event Manager and network and set new default port.
argc | Number of applications arguments (from main) |
argv | Applications arguments array (from main) |
event_cb | Events callback function called when an event happens |
options | Options set: READ_OPTIONS - read options from command line parameters; READ_CONFIGURATION - read options from configuration file |
port | Set default port number if non 0 |
user_data | Pointer to user data or NULL if absent |
References teonet_cfg::app_argc, teonet_cfg::app_argv, APP_PARAM, ksnetEvMgrClass::argc, ksnetEvMgrClass::argv, ksnetEvMgrClass::async_mutex, BLOCK_CLI_INPUT, teonet_cfg::block_cli_input_f, ksnetEvMgrClass::custom_timer_interval, ksnetEvMgrClass::ev_loop, ksnetEvMgrClass::event_cb, event_cb(), ke, ksnetEvMgrClass::kf, ksnetEvMgrClass::kl, ksnetEvMgrClass::km, ksnetEvMgrClass::ks, ksnet_configInit(), ksnet_optRead(), ksnet_optSetApp(), ksnetEvMgrClass::kt, ksnetEvMgrClass::last_custom_timer, malloc(), ksnetEvMgrClass::n_next, ksnetEvMgrClass::n_prev, ksnetEvMgrClass::net_count, ksnetEvMgrClass::net_idx, null_str, teonet_cfg::port, ksnetEvMgrClass::printf_mutex, read_config(), READ_CONFIGURATION, READ_OPTIONS, ksnetEvMgrClass::runEventMgr, teo_argc, teo_argv, ksnetEvMgrClass::teo_cfg, ksnetEvMgrClass::teo_class, ksnetEvMgrClass::tp, and ksnetEvMgrClass::user_data.
Referenced by ksnetEvMgrInit(), ksnMultiInit(), main(), teoMultiAddNet(), teo::Teonet::Teonet(), and teonet_t().
int ksnetEvMgrRestart | ( | int | argc, |
char ** | argv | ||
) |
Restart application.
argc | |
argv |
References free(), ksnet_formatMessage(), ksnet_stringArrSplit(), and usleep().
Referenced by ksnetEvMgrFree(), ksnMultiDestroy(), and sigusr2_cb().
int ksnetEvMgrRun | ( | ksnetEvMgrClass * | ke | ) |
Start KSNet Event Manager and network communication.
Start KSNet Event Manager and network communication
ke | Pointer to ksnetEvMgrClass |
References _ANSI_BROWN, _ANSI_NONE, ksnetEvMgrClass::async_queue, DEBUG_VV, ksnetEvMgrClass::ev_loop, free(), getDataPath(), idle_activity_cb(), ksnetEvMgrClass::idle_activity_count, ksnetEvMgrClass::idle_activity_w, idle_async_cb(), ksnetEvMgrClass::idle_async_w, idle_cb(), ksnetEvMgrClass::idle_count, ksnetEvMgrClass::idle_w, ksnetEvMgrClass::kc, ke, ksnetEvMgrClass::km, KSN_BUFFER_SIZE, ksn_printf, ksn_puts, KSNET_EVENT_MGR_TIMER, ksnetEvMgrFree(), ksnetEvMgrGetHostName(), MESSAGE, MODULE, modules_init(), ksnetEvMgrClass::net_idx, teonet_cfg::network, run_file, RUN_NAME, ksnetEvMgrClass::runEventMgr, sig_async_cb(), ksnetEvMgrClass::sig_async_w, teonet_cfg::sig_segv_f, ksnetEvMgrClass::sigabrt_w, sigint_cb(), ksnetEvMgrClass::sigint_w, ksnetEvMgrClass::sigkill_w, ksnetEvMgrClass::sigquit_w, ksnetEvMgrClass::sigstop_w, ksnetEvMgrClass::sigterm_w, sigusr2_cb(), ksnetEvMgrClass::teo_cfg, timer_cb(), ksnetEvMgrClass::timer_val, and ksnetEvMgrClass::timer_w.
Referenced by ksnMultiInit(), main(), teo::Teonet::run(), teoMultiAddNet(), teonet_t(), and test2().
void ksnetEvMgrSetCustomTimer | ( | ksnetEvMgrClass * | ke, |
double | time_interval | ||
) |
Set custom timer interval.
ke | Pointer to ksnetEvMgrClass |
time_interval |
References ksnetEvMgrClass::custom_timer_interval, ksnetEvMgrGetTime(), and ksnetEvMgrClass::last_custom_timer.
Referenced by event_cb(), main(), and teo::Teonet::setCustomTimer().
int ksnetEvMgrStatus | ( | ksnetEvMgrClass * | ke | ) |
References ksnetEvMgrClass::runEventMgr.
Referenced by ksnCoreProcessPacket(), and teo_recvfrom().
|
inline |
Stop event manager.
ke | Pointer to ksnetEvMgrClass |
References ksnetEvMgrClass::runEventMgr.
Referenced by event_cb(), hotkeys_cb(), ksnMultiDestroy(), main(), sigusr2_cb(), teo::Teonet::stop(), and teoMultiRemoveNet().
int remove_peer_addr | ( | ksnetEvMgrClass * | ke, |
__CONST_SOCKADDR_ARG | addr | ||
) |
Remove peer by address.
ke | Pointer to ksnetEvMgrClass |
addr |
0 | peer not found |
1 | peer removed |
-1 | peer not removed, this is this host |
References ksnCoreClass::ka, ksnetEvMgrClass::kc, and ksnetArpFindByAddr().
Referenced by trudp_event_cb().
|
inline |
Get current application type.
ke | Pointer to ksnetEvMgrClass |
References ksnetEvMgrClass::app_type.
Referenced by teoGetHostInfo().
|
inline |
Get current application version.
ke | Pointer to ksnetEvMgrClass |
References ksnetEvMgrClass::app_version.
Referenced by teoGetHostInfo().
char* teoGetFullAppTypeFromHostInfo | ( | host_info_data * | hid | ) |
References ksnet_sformatMessage(), and null_str.
Referenced by createCmdConnectPacket(), createCmdConnectRPacketUdp(), and ksnetArpAddHost().
host_info_data* teoGetHostInfo | ( | ksnetEvMgrClass * | ke, |
size_t * | hd_len | ||
) |
Get host info data.
ke | Pointer to ksnetEvMgrClass |
hd_len | Pointer to host_info_data length holder |
References ksnetEvMgrGetHostName(), teonet_cfg::l0_allow_f, malloc(), null_str, ksnetEvMgrClass::teo_cfg, teoGetAppType(), teoGetAppVersion(), VERSION, and teonet_cfg::vpn_connect_f.
Referenced by createCmdConnectPacket(), createCmdConnectRPacketUdp(), and ksnetArpAddHost().
|
inline |
Get teonet library version.
References VERSION.
Referenced by teo::Teonet::getTeonetVersion(), and main().
|
inline |
Set Teonet application type.
ke | Pointer to ksnetEvMgrClass |
type | Application type string |
References ksnetEvMgrClass::app_type.
Referenced by event_cb(), main(), and teo::Teonet::setAppType().
|
inline |
Set Teonet application version.
ke | Pointer to ksnetEvMgrClass |
version | Application version string |
References ksnetEvMgrClass::app_version.
Referenced by event_cb(), main(), and teo::Teonet::setAppVersion().