Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/typepayload #200

Merged
merged 19 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions src/config/opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,33 @@ char ** ksnet_optRead(int argc, char **argv, ksnet_cfg *conf,

int option_index = 0, opt;
struct option loptions[] = {
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
{ "app_name", no_argument, 0, 0 },
{ "app_description",no_argument, 0, 0 },
{ "uuid", no_argument, 0, 0 },
{ "port", required_argument, 0, 'p' },
{ "port_increment", no_argument, &conf->port_inc_f, 1 },
{ "r_port", required_argument, 0, 'r' },
{ "r_tcp_port", required_argument, 0, 't' },
{ "r_address", required_argument, 0, 'a' },
{ "r_tcp", no_argument, &conf->r_tcp_f, 1 },
{ "network", required_argument, 0, 'n' },
{ "key", required_argument, 0, 'e' },
{ "auth_secret", required_argument, 0, 'u' },
{ "tcp_allow", no_argument, &conf->tcp_allow_f, 1 },
{ "tcp_port", required_argument, 0, 'o' },
{ "l0_allow", no_argument, &conf->l0_allow_f, 1 },
{ "l0_tcp_port", required_argument, 0, 'l' },
{ "l0_tcp_ip_remote", required_argument, 0, 'I' },
{ "filter", required_argument, 0, 'f' },
{ "hot_keys", no_argument, &conf->hot_keys_f, 1 },
{ "show_debug", no_argument, &conf->show_debug_f, 1 },
{ "show_debug_vv", no_argument, &conf->show_debug_vv_f, 1 },
{ "show_debug_vvv", no_argument, &conf->show_debug_vvv_f, 1 },
{ "show_connect", no_argument, &conf->show_connect_f, 1 },
{ "show_peers", no_argument, &conf->show_peers_f, SHOW_PEER_CONTINUOSLY },
{ "show_trudp", no_argument, &conf->show_tr_udp_f, SHOW_PEER_CONTINUOSLY },
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
{ "app_name", no_argument, 0, 0 },
{ "app_description", no_argument, 0, 0 },
{ "uuid", no_argument, 0, 0 },
{ "port", required_argument, 0, 'p' },
{ "port_increment_disable", no_argument, &conf->port_inc_f, 0 },
{ "r_port", required_argument, 0, 'r' },
{ "r_tcp_port", required_argument, 0, 't' },
{ "r_address", required_argument, 0, 'a' },
{ "r_tcp", no_argument, &conf->r_tcp_f, 1 },
{ "network", required_argument, 0, 'n' },
{ "key", required_argument, 0, 'e' },
{ "auth_secret", required_argument, 0, 'u' },
{ "tcp_allow", no_argument, &conf->tcp_allow_f, 1 },
{ "tcp_port", required_argument, 0, 'o' },
{ "l0_allow", no_argument, &conf->l0_allow_f, 1 },
{ "l0_tcp_port", required_argument, 0, 'l' },
{ "l0_tcp_ip_remote", required_argument, 0, 'I' },
{ "filter", required_argument, 0, 'f' },
{ "hot_keys", no_argument, &conf->hot_keys_f, 1 },
{ "show_debug", no_argument, &conf->show_debug_f, 1 },
{ "show_debug_vv", no_argument, &conf->show_debug_vv_f, 1 },
{ "show_debug_vvv", no_argument, &conf->show_debug_vvv_f, 1 },
{ "show_connect", no_argument, &conf->show_connect_f, 1 },
{ "show_peers", no_argument, &conf->show_peers_f, SHOW_PEER_CONTINUOSLY },
{ "show_trudp", no_argument, &conf->show_tr_udp_f, SHOW_PEER_CONTINUOSLY },
#if M_ENAMBE_VPN
{ "vpn_start", no_argument, &conf->vpn_connect_f, 1 },
{ "vpn_ip", required_argument, 0, 'i' },
Expand Down
33 changes: 3 additions & 30 deletions src/ev_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,34 +707,7 @@ double ksnetEvMgrGetTime(ksnetEvMgrClass *ke) {
*
* @param ke Pointer to ksnetEvMgrClass
*/
void connect_r_host_cb(ksnetEvMgrClass *ke) {

// TODO: Posible this commente code don't need more. So it may be removed
// after some release versions.
//
// ksnet_arp_data *r_host_arp = (ksnet_arp_data *)ksnetArpGet(ke->kc->ka, ke->ksn_cfg.r_host_name);
// static int check_connection_f = 0; // Check r-host connection flag
//
// Reset r-host if connection is down
// *Note:* After host break with general protection failure
// and than restarted the r-host does not reconnect this host. In this case
// the triptime == 0.0. In this bloc we detect than r-hosts triptime not
// changed and send it disconnect command
// if(ke->ksn_cfg.r_host_addr[0] && ke->ksn_cfg.r_host_name[0] && r_host_arp->triptime == 0.00) {

// if(!check_connection_f) check_connection_f = 1;
// else {
// printf("not connected to r-host\n");
//
// // Send this host disconnect command to dead peer
// send_cmd_disconnect_cb(ke->kc->ka, NULL, r_host_arp, NULL);

// // Clear r-host name to reconnect at last loop
// ke->ksn_cfg.r_host_name[0] = '\0';
// }
// }
// else

void connect_r_host_cb(ksnetEvMgrClass *ke) {
// Connect to r-host
if(ke->ksn_cfg.r_host_addr[0] && !ke->ksn_cfg.r_host_name[0]) {

Expand All @@ -750,10 +723,10 @@ void connect_r_host_cb(ksnetEvMgrClass *ke) {

// Start TCP Proxy client connection if it is allowed and is not connected
if(ke->tp != NULL && ke->ksn_cfg.r_tcp_f) {

// Start TCP proxy client
if(!(ke->tp->fd_client > 0))
if(ke->tp->fd_client == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 - валидный дескриптор же, обычно он stdin. Не валидный fd == -1

ksnTCPProxyClientConnect(ke->tp);
}

// Create data with empty list of local IPs and port
data = malloc(sizeof(uint8_t));
Expand Down
2 changes: 1 addition & 1 deletion src/ev_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ ksnetArpClass* __arp_from_command_class(ksnCommandClass *X);
ksnCommandClass* : __ke_from_command_class, \
ksnLNullClass * : __ke_from_L0_class) (X)

#define ARP_TABLE_CLASS(X) _Generic((X), \
#define ARP_TABLE_OBJECT(X) _Generic((X), \
ksnCommandClass* : __arp_from_command_class) (X)

/**
Expand Down
16 changes: 8 additions & 8 deletions src/net_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ static int cmd_echo_unr_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {
static int cmd_peers_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {

ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco);
ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco);
ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco);

#ifdef DEBUG_KSNET
ksn_printf(ke, MODULE, DEBUG_VV, "process CMD_PEERS (cmd = %u) command, from %s (%s:%d)\n",
Expand Down Expand Up @@ -479,7 +479,7 @@ static int cmd_peers_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {
static int cmd_peers_num_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {

ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco);
ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco);
ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco);

#ifdef DEBUG_KSNET
ksn_printf(ke, MODULE, DEBUG_VV, "process CMD_GET_NUM_PEERS (cmd = %u) command, from %s (%s:%d)\n",
Expand Down Expand Up @@ -709,7 +709,7 @@ static int cmd_l0_stat_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {
static int cmd_host_info_answer_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {

ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco);
ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco);
ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco);

const int not_json = rd->data_len && ((char*)rd->data)[0] != '{' && ((char*)rd->data)[rd->data_len-1] != '}';

Expand Down Expand Up @@ -964,7 +964,7 @@ static int cmd_resend_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {
// If we resend command from sender, than sender don't know about the peer,
// try send connect command to peer to direct connect sender with peer
ksnet_arp_data *arp;
ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco);
ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco);
if((arp = (ksnet_arp_data *)ksnetArpGet(arp_class, to)) != NULL) {

// Send connect command request to peer
Expand Down Expand Up @@ -1061,7 +1061,7 @@ static int cmd_echo_answer_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {
ksnet_printf(&ke->ksn_cfg, DISPLAY_M, "%d bytes from %s: cmd=cmd_echo ttl=57 time=%.3f ms\n",
(int)rd->data_len, rd->from, triptime);

ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco);
ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco);
// Set monitor time
ksnet_arp_data_ext *arp = ksnetArpGet(arp_class, rd->from);
arp->data.monitor_time = time_got - time_send;
Expand Down Expand Up @@ -1130,7 +1130,7 @@ int send_cmd_connect_cb_b(ksnetArpClass *ka, char *peer_name,
static int cmd_connect_r_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {

ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco);
ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco);
ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco);

#ifdef DEBUG_KSNET
ksn_printf(ke, MODULE, DEBUG_VV,
Expand Down Expand Up @@ -1227,7 +1227,7 @@ static void cmd_connect_cque_cb(uint32_t id, int type, void *data) {
static int cmd_connect_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {

ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco);
ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco);
ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco);

/**
* KSNet CMD_PEER command data
Expand Down Expand Up @@ -1287,7 +1287,7 @@ static int cmd_connect_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {
int cmd_disconnected_cb(ksnCommandClass *kco, ksnCorePacketData *rd) {

ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco);
ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco);
ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco);

#ifdef DEBUG_KSNET
ksn_printf(ke, MODULE, DEBUG_VV, "process CMD_DISCONNECTED = %u command, from %s (%s:%d)\n",
Expand Down