Teonet library
0.4.7
|
#include <stdlib.h>
#include <string.h>
#include "ev_mgr.h"
#include "net_split.h"
#include "net_recon.h"
#include "utils/rlutil.h"
#include "utils/teo_memory.h"
#include "modules/subscribe.h"
#include "trudp_stat.h"
#include "commands_creator.h"
Macros | |
#define | MODULE _ANSI_LIGHTBLUE "net_command" _ANSI_NONE |
Typedefs | |
typedef struct cmd_connect_cque_cb_data | cmd_connect_cque_cb_data |
Functions | |
int | cmd_stream_cb (ksnStreamClass *ks, ksnCorePacketData *rd) |
Process CMD_STREAM teonet command. More... | |
int | cmd_l0_cb (ksnetEvMgrClass *ke, ksnCorePacketData *rd) |
Process CMD_L0 teonet command. More... | |
int | cmd_l0_to_cb (ksnetEvMgrClass *ke, ksnCorePacketData *rd) |
Process CMD_L0_TO teonet command. More... | |
int | cmd_l0_broadcast_cb (ksnetEvMgrClass *ke, ksnCorePacketData *rd) |
Process CMD_L0_CLIENT_BROADCAST teonet command (from peer to l0) More... | |
int | cmd_reconnect_cb (ksnCommandClass *kco, ksnCorePacketData *rd) |
Process CMD_RECONNECT command. More... | |
int | cmd_subscribe_cb (ksnCommandClass *kco, ksnCorePacketData *rd) |
Process CMD_SUBSCRIBE, CMD_UNSUBSCRIBE and CMD_SUBSCRIBE_ANSWER commands. 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... | |
ksnCommandClass * | ksnCommandInit (void *kc) |
Initialize ksnet command class. More... | |
void | ksnCommandDestroy (ksnCommandClass *kco) |
Destroy ksnet command class. More... | |
int | ksnCommandCheck (ksnCommandClass *kco, ksnCorePacketData *rd) |
Check and process command. More... | |
void * | ksnCommandEchoBuffer (ksnCommandClass *kco, void *data, size_t data_len, size_t *data_t_len) |
Create ECHO command buffer. More... | |
int | ksnCommandSendCmdEcho (ksnCommandClass *kco, char *to, void *data, size_t data_len) |
Send ECHO command to peer. More... | |
int | ksnCommandSendCmdConnect (ksnCommandClass *kco, char *to, char *name, char *addr, uint32_t port) |
Send CMD_CONNECT command to peer. More... | |
int | ksnCommandSendCmdConnectA (ksnCommandClass *kco, char *to_addr, uint32_t to_port, char *name, char *addr, uint32_t port) |
Send CONNECTED command to peer by address. More... | |
int | send_cmd_connect_cb (ksnetArpClass *ka, char *peer_name, ksnet_arp_data_ext *arp, void *data) |
Send connect command. More... | |
int | send_cmd_connect_cb_b (ksnetArpClass *ka, char *peer_name, ksnet_arp_data_ext *arp, void *data) |
Send connect command. More... | |
int | cmd_disconnected_cb (ksnCommandClass *kco, ksnCorePacketData *rd) |
Process CMD_DISCONNECTED command. More... | |
Variables | |
const char * | JSON = "JSON" |
const char * | BINARY = "BINARY" |
#define MODULE _ANSI_LIGHTBLUE "net_command" _ANSI_NONE |
typedef struct cmd_connect_cque_cb_data cmd_connect_cque_cb_data |
int cmd_disconnected_cb | ( | ksnCommandClass * | kco, |
ksnCorePacketData * | rd | ||
) |
Process CMD_DISCONNECTED command.
A peer send disconnect command
kco | Pointer to ksnCommandClass |
rd | Pointer to ksnCorePacketData |
References ksnCorePacketData::addr, ARP_TABLE_OBJECT, ksnCorePacketData::cmd, ksnCorePacketData::data, DEBUG_VV, EV_K_DISCONNECTED, ksnetEvMgrClass::event_cb, EVENT_MANAGER_OBJECT, free(), ksnCorePacketData::from, ksnCorePacketData::from_len, ksnCommandClass::kr, ksn_printf, ksnet_formatMessage(), ksnetArpRemove(), ksnCommandClass::ksscr, MODULE, ksnCorePacketData::port, teonet_cfg::r_host_name, ksnetEvMgrClass::teo_cfg, teoMetricGauge(), teoSScrSend(), and ksnetEvMgrClass::tm.
Referenced by ksnCommandCheck().
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 |
Process CMD_RECONNECT command.
kco | Pointer to ksnCommandClass |
rd | Pointer to ksnCorePacketData |
References ksnCorePacketData::addr, ksnCorePacketData::cmd, DEBUG_VV, EVENT_MANAGER_OBJECT, ksnCorePacketData::from, ksnCommandClass::kr, ksn_printf, MODULE, and ksnCorePacketData::port.
Referenced by ksnCommandCheck().
int cmd_stream_cb | ( | ksnStreamClass * | ks, |
ksnCorePacketData * | rd | ||
) |
Process CMD_STREAM teonet command.
ks | |
rd |
References stream_packet::cmd, CMD_ST_CLOSE, CMD_ST_CLOSE_GOT, CMD_ST_CREATE, CMD_ST_CREATE_GOT, CMD_ST_CREATED, CMD_ST_DATA, data, stream_packet::data, ksnCorePacketData::data, stream_packet::data_len, DEBUG_VV, ksnCorePacketData::from, kev, ksn_printf, ksnStreamClose(), ksnStreamCreate(), ksnStreamClass::map, MODULE, ksnStreamMapData::pipe_in, and stream_packet::stream_name_len.
Referenced by ksnCommandCheck().
int cmd_subscribe_cb | ( | ksnCommandClass * | kco, |
ksnCorePacketData * | rd | ||
) |
Process CMD_SUBSCRIBE, CMD_UNSUBSCRIBE and CMD_SUBSCRIBE_ANSWER commands.
kco | Pointer to ksnCommandClass |
rd | Pointer to ksnCorePacketData |
References ksnCorePacketData::arp, ksnCorePacketData::cmd, CMD_SUBSCRIBE, CMD_SUBSCRIBE_ANSWER, CMD_SUBSCRIBE_RND, CMD_UNSUBSCRIBE, ksnCorePacketData::data, ksnCorePacketData::data_len, EV_K_SUBSCRIBE, EV_K_SUBSCRIBED, ksnCorePacketData::from, kev, ksnCommandClass::ksscr, ksnCorePacketData::l0_f, teoSScrSubscription(), and teoSScrUnSubscription().
Referenced by ksnCommandCheck().
int ksnCommandCheck | ( | ksnCommandClass * | kco, |
ksnCorePacketData * | rd | ||
) |
Check and process command.
References ksnCorePacketData::addr, ksnCorePacketData::cmd, CMD_CONNECT, CMD_CONNECT_R, CMD_DISCONNECTED, cmd_disconnected_cb(), CMD_ECHO, CMD_ECHO_ANSWER, CMD_ECHO_UNRELIABLE, CMD_GET_NUM_PEERS, CMD_GET_PUBLIC_IP, CMD_HOST_INFO, CMD_HOST_INFO_ANSWER, CMD_L0, CMD_L0_AUTH, cmd_l0_broadcast_cb(), cmd_l0_cb(), cmd_l0_check_cb(), CMD_L0_CLIENT_BROADCAST, CMD_L0_CLIENT_RESET, CMD_L0_CLIENTS, CMD_L0_CLIENTS_N, CMD_L0_INFO, cmd_l0_kick_client(), CMD_L0_STAT, CMD_L0_TO, cmd_l0_to_cb(), CMD_NONE, CMD_PEERS, CMD_RECONNECT, CMD_RECONNECT_ANSWER, cmd_reconnect_cb(), CMD_RESEND, CMD_RESET, CMD_SPLIT, CMD_STREAM, cmd_stream_cb(), CMD_SUBSCRIBE, CMD_SUBSCRIBE_ANSWER, cmd_subscribe_cb(), CMD_SUBSCRIBE_RND, CMD_TRUDP_INFO, CMD_TUN, cmd_tun_cb(), CMD_UNSUBSCRIBE, CMD_VPN, cmd_vpn_cb(), ksnCorePacketData::data, ksnCorePacketData::data_len, DEBUG_VV, EVENT_MANAGER_OBJECT, ksnCorePacketData::from, ke, ksnetEvMgrClass::kl, ksnetEvMgrClass::ks, ksn_printf, ksnetEvMgrClass::ktun, ksnetEvMgrClass::kvpn, MODULE, and ksnCorePacketData::port.
Referenced by cmd_l0_cb(), and ksnCoreProcessPacket().
void ksnCommandDestroy | ( | ksnCommandClass * | kco | ) |
Destroy ksnet command class.
kco |
References free(), ksnCommandClass::kr, ksnCommandClass::ks, ksnSplitDestroy(), ksnCommandClass::ksscr, and teoSScrDestroy().
Referenced by ksnCoreDestroy().
void* ksnCommandEchoBuffer | ( | ksnCommandClass * | kco, |
void * | data, | ||
size_t | data_len, | ||
size_t * | data_t_len | ||
) |
Create ECHO command buffer.
kco | Pointer to ksnCommandClass |
data | Echo data |
data_len | Echo data length |
data_t_len | Pointer to hold ECHO buffer size |
References EVENT_MANAGER_OBJECT, ke, ksnetEvMgrGetTime(), and malloc().
Referenced by _check_connected(), ksnCommandSendCmdEcho(), ksnLNullSendEchoToL0(), and ksnLNullSendEchoToL0A().
ksnCommandClass* ksnCommandInit | ( | void * | kc | ) |
Initialize ksnet command class.
References kc, ksnCommandClass::kc, ke, ksnCommandClass::kr, ksnCommandClass::ks, ksnReconnectInit(), ksnSplitInit(), ksnCommandClass::ksscr, teo_malloc(), and teoSScrInit().
Referenced by ksnCoreInit().
int ksnCommandSendCmdConnect | ( | ksnCommandClass * | kco, |
char * | to, | ||
char * | name, | ||
char * | addr, | ||
uint32_t | port | ||
) |
Send CMD_CONNECT command to peer.
kco | Pointer to ksnCommandClass |
to | Send command to peer name |
name | Name of peer to connect |
addr | IP address of peer to connect |
port | Port of peer to connect |
References CMD_CONNECT, createCmdConnectPacket(), DEBUG_VV, EVENT_MANAGER_OBJECT, free(), ksnCommandClass::kc, ksn_printf, ksnCoreSendCmdto(), and MODULE.
Referenced by send_cmd_connect_cb(), and send_cmd_connected_cb().
int ksnCommandSendCmdConnectA | ( | ksnCommandClass * | kco, |
char * | to_addr, | ||
uint32_t | to_port, | ||
char * | name, | ||
char * | addr, | ||
uint32_t | port | ||
) |
Send CONNECTED command to peer by address.
kco | Pointer to ksnCommandClass |
to_addr | Send command to IP address |
to_port | Send command to Port |
name | Name of peer to connect |
addr | IP address of peer to connect |
port | Port of peer to connect |
References CMD_CONNECT, createCmdConnectPacket(), DEBUG_VV, EVENT_MANAGER_OBJECT, free(), ksnCommandClass::kc, ksn_printf, ksnCoreSendto(), and MODULE.
Referenced by send_cmd_connect_cb_b().
int ksnCommandSendCmdEcho | ( | ksnCommandClass * | kco, |
char * | to, | ||
void * | data, | ||
size_t | data_len | ||
) |
Send ECHO command to peer.
kco | Pointer to ksnCommandClass |
to | Send command to peer name |
data | Echo data |
data_len | Echo data length |
References CMD_ECHO, EVENT_MANAGER_OBJECT, free(), ksnCommandClass::kc, ke, ksnCommandEchoBuffer(), ksnCoreSendCmdto(), and ksnetEvMgrGetTime().
Referenced by check_connected_cb(), hotkeys_cb(), monitor_timer_one_cb(), ping_timer_cb(), and teo::Teonet::sendEchoTo().
int send_cmd_connect_cb | ( | ksnetArpClass * | ka, |
char * | peer_name, | ||
ksnet_arp_data_ext * | arp, | ||
void * | data | ||
) |
Send connect command.
ka | Pointer to ksnetArpClass |
peer_name | Peer name |
arp_data | Pointer to ARP data ksnet_arp_data |
data | Pointer to ksnCorePacketData |
References ksnCorePacketData::addr, data, ksnCorePacketData::from, ksnetArpClass::ke, ksnCommandSendCmdConnect(), and ksnCorePacketData::port.
Referenced by ksnCoreCheckNewPeer().
int send_cmd_connect_cb_b | ( | ksnetArpClass * | ka, |
char * | peer_name, | ||
ksnet_arp_data_ext * | arp, | ||
void * | data | ||
) |
Send connect command.
ka | Pointer to ksnetArpClass |
peer_name | Peer name |
arp_data | Pointer to ARP data ksnet_arp_data |
data | Pointer to ksnCorePacketData |
References ksnCorePacketData::addr, data, ksnCorePacketData::from, ksnetArpClass::ke, ksnCommandSendCmdConnectA(), and ksnCorePacketData::port.
Referenced by ksnCoreCheckNewPeer().
const char* BINARY = "BINARY" |
const char* JSON = "JSON" |