|
Teonet library
0.4.7
|
#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include <stdbool.h>#include <string.h>#include "ev_mgr.h"#include "l0-server.h"#include "utils/rlutil.h"#include "jsmn.h"#include "teonet_l0_client_crypt.h"#include <openssl/md5.h>Macros | |
| #define | MODULE _ANSI_LIGHTCYAN "l0_server" _ANSI_NONE |
| File: l0-server.c Author: Kirill Scherba kirill@scherba.ru More... | |
| #define | TEO_AUTH "teo-auth" |
| #define | WG001 "wg001-" |
| #define | WG001_NEW "wg001-new-" |
| #define | kev ((ksnetEvMgrClass*)kl->ke) |
| Pointer to ksnetEvMgrClass. More... | |
| #define | L0_VERSION 0 |
| L0 Server version. More... | |
| #define | CHECK_TIMEOUT 10.00 |
| #define | SEND_PING_TIMEOUT 30.00 |
| #define | DISCONNECT_TIMEOUT 60.00 |
| #define | find_tag(VAR, KEY, TAG) |
| #define | BUFFER_SIZE_CLIENT 4096 |
Typedefs | |
| typedef struct string_view | string_view |
| typedef struct json_param | json_param |
| JSON request parameters structure. More... | |
Functions | |
| void * | ksnCoreCreatePacket (ksnCoreClass *kc, uint8_t cmd, const void *data, size_t data_len, size_t *packet_len) |
| Create ksnet packet. More... | |
| void | teoLNullPacketCheckMiscrypted (ksnLNullClass *kl, ksnLNullData *kld, teoLNullCPacket *packet) |
| ksnLNullClass * | ksnLNullInit (void *ke) |
| Initialize ksnLNull module class. More... | |
| void | ksnLNullDestroy (ksnLNullClass *kl) |
| Destroy ksnLNull module class. More... | |
| ksnLNullSStat * | ksnLNullStat (ksnLNullClass *kl) |
| Get L0 server statistic. More... | |
| int | ksnLNullSendToL0 (void *ke, char *addr, int port, char *cname, size_t cname_length, uint8_t cmd, void *data, size_t data_len) |
| Send data to L0 client. More... | |
| int | ksnLNullSendEchoToL0 (void *ke, char *addr, int port, char *cname, size_t cname_length, void *data, size_t data_len) |
| Send echo to L0 client. More... | |
| int | ksnLNullSendEchoToL0A (void *ke, char *addr, int port, char *cname, size_t cname_length, void *data, size_t data_len) |
| void | _send_subscribe_event_disconnected (ksnetEvMgrClass *ke, char *payload, size_t payload_length) |
| void | _send_subscribe_event_connected (ksnetEvMgrClass *ke, char *payload, size_t payload_length) |
| Send Connected event to all subscribers. More... | |
| void | _send_subscribe_event_newvisit (ksnetEvMgrClass *ke, const char *payload, size_t payload_length) |
| Send "new visit" event to all subscribers. More... | |
| ssize_t | ksnLNullPacketSend (ksnLNullClass *kl, int fd, void *pkg, size_t pkg_length) |
| Send packet to L0 client. More... | |
| void | ksnLNullClientDisconnect (ksnLNullClass *kl, int fd, int remove_f) |
| Disconnect l0 Server client. More... | |
| void | _check_connected (uint32_t id, int type, void *data) |
| int | cmd_l0_broadcast_cb (ksnetEvMgrClass *ke, ksnCorePacketData *rd) |
| Process CMD_L0_CLIENT_BROADCAST teonet command (from peer to l0) More... | |
| int | cmd_l0_cb (ksnetEvMgrClass *ke, ksnCorePacketData *rd) |
| Process CMD_L0 teonet command. More... | |
| int | ksnLNullClientIsConnected (ksnLNullClass *kl, char *client_name) |
| Check if L0 client is connected and return it FD. More... | |
| int | cmd_l0_to_cb (ksnetEvMgrClass *ke, ksnCorePacketData *rd) |
| Process CMD_L0_TO teonet command. More... | |
| int | cmd_l0_check_cb (ksnCommandClass *kco, ksnCorePacketData *rd) |
| Check l0 client answer from authentication application. More... | |
| int | cmd_l0_kick_client (ksnCommandClass *kco, ksnCorePacketData *rd) |
| Kick l0 client. More... | |
| teonet_client_data_ar * | ksnLNullClientsList (ksnLNullClass *kl) |
| Create list of clients. More... | |
| size_t | ksnLNullClientsListLength (teonet_client_data_ar *clients_data) |
| Return size of teonet_client_data_ar data. More... | |
| ssize_t | recvCheck (trudpChannelData *tcd, char *data, ssize_t data_length) |
| int | ksnLNulltrudpCheckPaket (ksnLNullClass *kl, ksnCorePacketData *rd) |
| Check and process L0 packet received through TR-UDP. More... | |
| teoLNullEncryptionContext * | ksnLNullClientGetCrypto (ksnLNullClass *kl, int fd) |
| Returns L0 client encryption context and return it if available. More... | |
Variables | |
| const char * | localhost |
| KSNet mesh core module. More... | |
| #define BUFFER_SIZE_CLIENT 4096 |
Referenced by recvCheck().
| #define CHECK_TIMEOUT 10.00 |
Referenced by _check_connected().
| #define DISCONNECT_TIMEOUT 60.00 |
Referenced by _check_connected().
| #define find_tag | ( | VAR, | |
| KEY, | |||
| TAG | |||
| ) |
| #define kev ((ksnetEvMgrClass*)kl->ke) |
Pointer to ksnetEvMgrClass.
| #define L0_VERSION 0 |
L0 Server version.
| #define MODULE _ANSI_LIGHTCYAN "l0_server" _ANSI_NONE |
File: l0-server.c Author: Kirill Scherba kirill@scherba.ru
L0 Server module
Created on October 8, 2015, 1:38 PM
Referenced by _check_connected(), cmd_l0_cb(), cmd_l0_check_cb(), cmd_l0_kick_client(), cmd_l0_to_cb(), ksnLNullClientDisconnect(), ksnLNullPacketSend(), ksnLNullSendToL0(), ksnLNulltrudpCheckPaket(), and teoLNullPacketCheckMiscrypted().
| #define SEND_PING_TIMEOUT 30.00 |
Referenced by _check_connected().
| #define TEO_AUTH "teo-auth" |
| #define WG001 "wg001-" |
| #define WG001_NEW "wg001-new-" |
| typedef struct json_param json_param |
JSON request parameters structure.
userId clientId username accessToken
| typedef struct string_view string_view |
| void _check_connected | ( | uint32_t | id, |
| int | type, | ||
| void * | data | ||
| ) |
References CHECK_TIMEOUT, CMD_ECHO, ksnLNullClass::cque, data, DEBUG, DISCONNECT_TIMEOUT, EVENT_MANAGER_OBJECT, free(), ksnLNullClass::ke, ksn_printf, ksnCommandEchoBuffer(), ksnCQueAdd(), ksnetEvMgrGetHostName(), ksnetEvMgrGetTime(), ksnLNullClientDisconnect(), ksnLNullPacketSend(), ksnLNullData::last_time, malloc(), ksnLNullClass::map, MODULE, ksnLNullData::name, and SEND_PING_TIMEOUT.
| void _send_subscribe_event_connected | ( | ksnetEvMgrClass * | ke, |
| char * | payload, | ||
| size_t | payload_length | ||
| ) |
Send Connected event to all subscribers.
References EV_K_L0_CONNECTED, ksnetEvMgrClass::kc, ksnCoreClass::kco, ksnetEvMgrClass::kl, ksnCommandClass::ksscr, ksnLNullClass::stat, and teoSScrSend().
| void _send_subscribe_event_disconnected | ( | ksnetEvMgrClass * | ke, |
| char * | payload, | ||
| size_t | payload_length | ||
| ) |
References EV_K_L0_DISCONNECTED, ksnetEvMgrClass::kc, ksnCoreClass::kco, ksnCommandClass::ksscr, and teoSScrSend().
Referenced by ksnLNullClientDisconnect().
| void _send_subscribe_event_newvisit | ( | ksnetEvMgrClass * | ke, |
| const char * | payload, | ||
| size_t | payload_length | ||
| ) |
Send "new visit" event to all subscribers.
References EV_K_L0_NEW_VISIT, free(), ksnetEvMgrClass::kc, ksnCoreClass::kco, ksnetEvMgrClass::kl, ksnCommandClass::ksscr, malloc(), ksnLNullClass::stat, and teoSScrSend().
| int cmd_l0_broadcast_cb | ( | ksnetEvMgrClass * | ke, |
| ksnCorePacketData * | rd | ||
| ) |
Process CMD_L0_CLIENT_BROADCAST teonet command (from peer to l0)
| ke | Pointer to ksnetEvMgrClass |
| rd | Pointer to ksnCorePacketData data |
References ksnCorePacketData::cmd, ksnCorePacketData::data, ksnCorePacketData::data_len, ksnetEvMgrClass::kl, teonet_cfg::l0_allow_f, and ksnetEvMgrClass::teo_cfg.
Referenced by ksnCommandCheck().
| int cmd_l0_cb | ( | ksnetEvMgrClass * | ke, |
| ksnCorePacketData * | rd | ||
| ) |
Process CMD_L0 teonet command.
| ke | Pointer to ksnetEvMgrClass |
| rd | Pointer to ksnCorePacketData data |
References ksnLNullSPacket::client_name_length, ksnLNullSPacket::cmd, ksnCorePacketData::cmd, CMD_192_RESERVED, CMD_ECHO, CMD_ECHO_ANSWER, CMD_ECHO_UNRELIABLE, CMD_ECHO_UNRELIABLE_ANSWER, CMD_GET_NUM_PEERS, CMD_HOST_INFO, CMD_L0_CLIENTS, CMD_L0_CLIENTS_N, CMD_L0_STAT, CMD_LAST, CMD_PEERS, CMD_RESET, CMD_SUBSCRIBE, CMD_SUBSCRIBE_RND, CMD_TRUDP_INFO, CMD_UNSUBSCRIBE, CMD_USER, CMD_USER_NR, ksnCorePacketData::data, ksnCorePacketData::data_len, ksnLNullSPacket::data_length, DEBUG_VV, ksnCorePacketData::from, ksnCorePacketData::from_len, ksnetEvMgrClass::kc, ksnCoreClass::kco, ksn_printf, ksnCommandCheck(), ksnCorePacketData::l0_f, MODULE, ksnLNullSPacket::payload, and rd.
Referenced by ksnCommandCheck().
| int cmd_l0_check_cb | ( | ksnCommandClass * | kco, |
| ksnCorePacketData * | rd | ||
| ) |
Check l0 client answer from authentication application.
| kco | Pointer to ksnCommandClass |
| rd | Pointer to ksnCorePacketData |
References DEBUG, EVENT_MANAGER_OBJECT, free(), ksnetEvMgrClass::kl, ksn_printf, ksnLNullClientIsConnected(), ksnLNullClass::map, and MODULE.
Referenced by ksnCommandCheck().
| int cmd_l0_kick_client | ( | ksnCommandClass * | kco, |
| ksnCorePacketData * | rd | ||
| ) |
Kick l0 client.
| kco | Pointer to ksnCommandClass |
| rd | Pointer to ksnCorePacketData |
References CMD_L0_CLIENT_RESET, ksnCorePacketData::data, ksnCorePacketData::data_len, DEBUG, EVENT_MANAGER_OBJECT, free(), ksnCorePacketData::from, ksnetEvMgrClass::kl, ksn_printf, ksnLNullClientDisconnect(), ksnLNullClientIsConnected(), ksnLNullClass::map, and MODULE.
Referenced by ksnCommandCheck().
| int cmd_l0_to_cb | ( | ksnetEvMgrClass * | ke, |
| ksnCorePacketData * | rd | ||
| ) |
Process CMD_L0_TO teonet command.
| ke | Pointer to ksnetEvMgrClass |
| rd | Pointer to ksnCorePacketData data |
References ksnLNullSPacket::client_name_length, ksnLNullSPacket::cmd, ksnCorePacketData::data, ksnLNullSPacket::data_length, DEBUG_VV, ERROR_M, free(), ksnCorePacketData::from, ksnCorePacketData::from_len, ksnetEvMgrClass::kl, ksn_printf, ksnLNullClientIsConnected(), ksnLNullPacketSend(), malloc(), MODULE, ksnLNullSPacket::payload, and ksnLNullClass::stat.
Referenced by ksnCommandCheck().
|
inline |
Create ksnet packet.
| kc | Pointer to ksnCore Class object | |
| cmd | Command ID | |
| data | Pointer to data | |
| data_len | Data length | |
| [out] | packet_len | Pointer to packet length |
References ksnCoreCreatePacketFrom(), ksnCoreClass::name, and ksnCoreClass::name_len.
Referenced by ksnCoreSendto().
| void ksnLNullClientDisconnect | ( | ksnLNullClass * | kl, |
| int | fd, | ||
| int | remove_f | ||
| ) |
Disconnect l0 Server client.
Called when client disconnected or when the L0 Server closing. Close TCP connections and remove data from L0 Server clients map.
| kl | Pointer to ksnLNullClass |
| fd | TCP client connection file descriptor |
| remove_f | If true than remove disconnected record from map |
References _send_subscribe_event_disconnected(), CONNECT, ksnetEvMgrClass::ev_loop, EVENT_MANAGER_OBJECT, free(), ksn_printf, malloc(), ksnLNullClass::map, ksnLNullClass::map_n, MODULE, ksnLNullData::name, ksnLNullData::name_length, pblMapRemoveFree(), ksnLNullData::read_buffer, ksnLNullData::read_buffer_ptr, ksnLNullData::read_buffer_size, ksnLNullData::server_crypt, ksnLNullClass::stat, ksnLNullData::t_addr, and ksnLNullData::w.
Referenced by _check_connected(), cmd_l0_kick_client(), ksnLNulltrudpCheckPaket(), and trudp_event_cb().
| teoLNullEncryptionContext* ksnLNullClientGetCrypto | ( | ksnLNullClass * | kl, |
| int | fd | ||
| ) |
Returns L0 client encryption context and return it if available.
| kl | Pointer to ksnLNullClass |
| fd | Client name connection fd |
References ksnLNullData::server_crypt.
| int ksnLNullClientIsConnected | ( | ksnLNullClass * | kl, |
| char * | client_name | ||
| ) |
Check if L0 client is connected and return it FD.
| kl | Pointer to ksnLNullClass |
| client_name | Client name |
References ksnLNullClass::map_n.
Referenced by cmd_l0_check_cb(), cmd_l0_kick_client(), cmd_l0_to_cb(), and ksnCoreSendCmdto().
| teonet_client_data_ar* ksnLNullClientsList | ( | ksnLNullClass * | kl | ) |
Create list of clients.
| kl |
References EVENT_MANAGER_OBJECT, ksnLNullClass::fd, teonet_cfg::l0_allow_f, malloc(), ksnLNullClass::map, ksnLNullData::name, and ksnetEvMgrClass::teo_cfg.
|
inline |
Return size of teonet_client_data_ar data.
| clients_data |
| void ksnLNullDestroy | ( | ksnLNullClass * | kl | ) |
Destroy ksnLNull module class.
| kl | Pointer to ksnLNullClass |
References free(), ksnLNullClass::map, and ksnLNullClass::map_n.
Referenced by modules_destroy().
| ksnLNullClass* ksnLNullInit | ( | void * | ke | ) |
Initialize ksnLNull module class.
| ke | Pointer to ksnetEvMgrClass |
References ksnLNullClass::fd_trudp, ksnLNullClass::ke, ke, malloc(), ksnLNullClass::map, ksnLNullClass::map_n, and ksnLNullClass::stat.
Referenced by modules_init().
| ssize_t ksnLNullPacketSend | ( | ksnLNullClass * | kl, |
| int | fd, | ||
| void * | pkg, | ||
| size_t | pkg_length | ||
| ) |
Send packet to L0 client.
| fd | L0 client socket |
| pkg | Package to send |
| pkg_length | Package length |
< Remote address
< Remote address length
References CMD_TRUDP_CHECK, dump_bytes(), EVENT_MANAGER_OBJECT, ksnLNullClass::ke, ksn_printf, ksnTRUDPsendto(), MODULE, ksnLNullData::server_crypt, ksnLNullClass::stat, ksnLNullData::t_addr, and ksnLNullData::t_port.
Referenced by _check_connected(), cmd_l0_to_cb(), and ksnCoreSendCmdto().
| int ksnLNullSendEchoToL0 | ( | void * | ke, |
| char * | addr, | ||
| int | port, | ||
| char * | cname, | ||
| size_t | cname_length, | ||
| void * | data, | ||
| size_t | data_len | ||
| ) |
Send echo to L0 client.
| ke | Pointer to ksnetEvMgrClass |
| addr | IP address of remote peer |
| port | Port of remote peer |
| cname | L0 client name (include trailing zero) |
| cname_length | Length of the L0 client name |
| data | Data |
| data_len | Data length |
References CMD_ECHO, free(), kc, ksnCommandEchoBuffer(), and ksnLNullSendToL0().
Referenced by teo::Teonet::sendEchoToL0().
| int ksnLNullSendEchoToL0A | ( | void * | ke, |
| char * | addr, | ||
| int | port, | ||
| char * | cname, | ||
| size_t | cname_length, | ||
| void * | data, | ||
| size_t | data_len | ||
| ) |
| int ksnLNullSendToL0 | ( | void * | ke, |
| char * | addr, | ||
| int | port, | ||
| char * | cname, | ||
| size_t | cname_length, | ||
| uint8_t | cmd, | ||
| void * | data, | ||
| size_t | data_len | ||
| ) |
Send data to L0 client.
Usually it is an answer to request from L0 client
| ke | Pointer to ksnetEvMgrClass |
| addr | IP address of remote peer |
| port | Port of remote peer |
| cname | L0 client name (include trailing zero) |
| cname_length | Length of the L0 client name |
| cmd | Command |
| data | Data |
| data_len | Data length |
References ksnLNullSPacket::client_name_length, ksnLNullSPacket::cmd, CMD_L0_TO, ksnLNullSPacket::data_length, DEBUG_VV, free(), kc, ksn_printf, ksnCoreSendto(), malloc(), MODULE, and ksnLNullSPacket::payload.
Referenced by ksnLNullSendEchoToL0(), sendCmdAnswerToBinaryA(), teo::Teonet::sendToL0(), and teoSScrSend().
| ksnLNullSStat* ksnLNullStat | ( | ksnLNullClass * | kl | ) |
Get L0 server statistic.
| kl | Pointer to ksnLNullClass |
References ksnLNullClass::stat.
Referenced by metric_teonet_count().
| int ksnLNulltrudpCheckPaket | ( | ksnLNullClass * | kl, |
| ksnCorePacketData * | rd | ||
| ) |
Check and process L0 packet received through TR-UDP.
| data | |
| data_len |
References ksnCorePacketData::addr, ksnCorePacketData::cmd, ksnCorePacketData::data, ksnCorePacketData::data_len, DEBUG_VV, EVENT_MANAGER_OBJECT, ksnLNullClass::fd, ksnetEvMgrClass::kc, ksn_printf, ksnLNullClientDisconnect(), ksnCoreClass::ku, MODULE, ksnCorePacketData::port, and recvCheck().
Referenced by ksnCoreProcessPacket().
| ssize_t recvCheck | ( | trudpChannelData * | tcd, |
| char * | data, | ||
| ssize_t | data_length | ||
| ) |
References BUFFER_SIZE_CLIENT.
Referenced by ksnLNulltrudpCheckPaket().
| void teoLNullPacketCheckMiscrypted | ( | ksnLNullClass * | kl, |
| ksnLNullData * | kld, | ||
| teoLNullCPacket * | packet | ||
| ) |
References _ANSI_LIGHTCYAN, _ANSI_NONE, _ANSI_RED, _ANSI_YELLOW, DEBUG, dump_bytes(), EVENT_MANAGER_OBJECT, get_byte_checksum(), ke, ksn_printf, MODULE, ksnLNullData::t_addr, and ksnLNullData::t_port.
| const char* localhost |
KSNet mesh core module.