Browse Source

reworked edge management port output (#623)

pull/628/head
Logan oos Even 4 years ago
committed by GitHub
parent
commit
fb827a843b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      include/n2n_define.h
  2. 51
      src/edge_utils.c
  3. 13
      src/sn_selection.c

2
include/n2n_define.h

@ -165,7 +165,7 @@ enum skip_add{SN_ADD = 0, SN_ADD_SKIP = 1, SN_ADD_ADDED = 2};
#endif #endif
#define SN_SELECTION_CRITERION_DATA_TYPE uint32_t #define SN_SELECTION_CRITERION_DATA_TYPE uint32_t
#define SN_SELECTION_CRITERION_BUF_SIZE 14 #define SN_SELECTION_CRITERION_BUF_SIZE 16
#define N2N_TRANSFORM_ID_USER_START 64 #define N2N_TRANSFORM_ID_USER_START 64
#define N2N_TRANSFORM_ID_MAX 65535 #define N2N_TRANSFORM_ID_MAX 65535

51
src/edge_utils.c

@ -839,7 +839,6 @@ void send_query_peer (n2n_edge_t * eee,
// skip a random number of supernodes between top and remaining // skip a random number of supernodes between top and remaining
n_o_skip_sn = HASH_COUNT(eee->conf.supernodes) - n_o_pings; n_o_skip_sn = HASH_COUNT(eee->conf.supernodes) - n_o_pings;
n_o_skip_sn = (n_o_skip_sn < 0) ? 0 : n2n_rand_sqr(n_o_skip_sn); n_o_skip_sn = (n_o_skip_sn < 0) ? 0 : n2n_rand_sqr(n_o_skip_sn);
HASH_ITER(hh, eee->conf.supernodes, peer, tmp) { HASH_ITER(hh, eee->conf.supernodes, peer, tmp) {
if(n_o_top_sn) { if(n_o_top_sn) {
n_o_top_sn--; n_o_top_sn--;
@ -1405,6 +1404,7 @@ static void readFromMgmtSocket (n2n_edge_t *eee, int *keep_running) {
time_t now; time_t now;
struct peer_info *peer, *tmpPeer; struct peer_info *peer, *tmpPeer;
macstr_t mac_buf; macstr_t mac_buf;
char time_buf[10]; /* 9 digits + 1 terminating zero */
/* dec_ip_bit_str_t ip_bit_str = {'\0'}; */ /* dec_ip_bit_str_t ip_bit_str = {'\0'}; */
/* dec_ip_str_t ip_str = {'\0'}; */ /* dec_ip_str_t ip_str = {'\0'}; */
in_addr_t net; in_addr_t net;
@ -1485,47 +1485,53 @@ static void readFromMgmtSocket (n2n_edge_t *eee, int *keep_running) {
msg_len = 0; msg_len = 0;
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
"community: %s\n", "COMMUNITY '%s'\n\n",
eee->conf.community_name); eee->conf.community_name);
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
" id tun_tap MAC edge hint last_seen\n"); " ### | TAP | MAC | EDGE | HINT | LAST SEEN\n");
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
"-----------------------------------------------------------------------------------------------\n"); "================================================================================================\n");
// dump nodes with forwarding through supernodes
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
"supernode_forward:\n"); "SUPERNODE FORWARD\n");
num = 0; num = 0;
HASH_ITER(hh, eee->pending_peers, peer, tmpPeer) { HASH_ITER(hh, eee->pending_peers, peer, tmpPeer) {
++num_pending_peers; ++num_pending_peers;
if(peer->dev_addr.net_addr == 0) continue;
net = htonl(peer->dev_addr.net_addr); net = htonl(peer->dev_addr.net_addr);
sprintf (time_buf, "%9u", now - peer->last_seen);
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
" %-4u %-15s %-17s %-21s %-15s %lu\n", "%4u | %-15s | %-17s | %-21s | %-15s | %9s\n",
++num, inet_ntoa(*(struct in_addr *) &net), ++num,
(peer->dev_addr.net_addr == 0) ? "" : inet_ntoa(*(struct in_addr *) &net),
macaddr_str(mac_buf, peer->mac_addr), macaddr_str(mac_buf, peer->mac_addr),
sock_to_cstr(sockbuf, &(peer->sock)), sock_to_cstr(sockbuf, &(peer->sock)),
peer->dev_desc, peer->dev_desc,
now - peer->last_seen); (peer->last_seen) ? time_buf : "");
sendto(eee->udp_mgmt_sock, udp_buf, msg_len, 0/*flags*/, sendto(eee->udp_mgmt_sock, udp_buf, msg_len, 0/*flags*/,
(struct sockaddr *) &sender_sock, sizeof(struct sockaddr_in)); (struct sockaddr *) &sender_sock, sizeof(struct sockaddr_in));
msg_len = 0; msg_len = 0;
} }
// dump peer-to-peer nodes
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
"------------------------------------------------------------------------------------------------\n");
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
"peer_to_peer:\n"); "PEER TO PEER\n");
num = 0; num = 0;
HASH_ITER(hh, eee->known_peers, peer, tmpPeer) { HASH_ITER(hh, eee->known_peers, peer, tmpPeer) {
++num_known_peers; ++num_known_peers;
if(peer->dev_addr.net_addr == 0) continue;
net = htonl(peer->dev_addr.net_addr); net = htonl(peer->dev_addr.net_addr);
sprintf (time_buf, "%9u", now - peer->last_seen);
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
" %-4u %-15s %-17s %-21s %-15s %lu\n", "%4u | %-15s | %-17s | %-21s | %-15s | %9s\n",
++num, inet_ntoa(*(struct in_addr *) &net), ++num,
(peer->dev_addr.net_addr == 0) ? "" : inet_ntoa(*(struct in_addr *) &net),
macaddr_str(mac_buf, peer->mac_addr), macaddr_str(mac_buf, peer->mac_addr),
sock_to_cstr(sockbuf, &(peer->sock)), sock_to_cstr(sockbuf, &(peer->sock)),
peer->dev_desc, peer->dev_desc,
now - peer->last_seen); (peer->last_seen) ? time_buf : "");
sendto(eee->udp_mgmt_sock, udp_buf, msg_len, 0/*flags*/, sendto(eee->udp_mgmt_sock, udp_buf, msg_len, 0/*flags*/,
(struct sockaddr *) &sender_sock, sizeof(struct sockaddr_in)); (struct sockaddr *) &sender_sock, sizeof(struct sockaddr_in));
@ -1534,30 +1540,31 @@ static void readFromMgmtSocket (n2n_edge_t *eee, int *keep_running) {
// dump supernodes // dump supernodes
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
"-----------------------------------------------------------------------------------------------\n"); "------------------------------------------------------------------------------------------------\n");
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
"supernodes:\n"); "SUPERNODES\n");
HASH_ITER(hh, eee->conf.supernodes, peer, tmpPeer) { HASH_ITER(hh, eee->conf.supernodes, peer, tmpPeer) {
net = htonl(peer->dev_addr.net_addr); net = htonl(peer->dev_addr.net_addr);
sprintf (time_buf, "%9u", now - peer->last_seen);
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
" %-4u %-15s %-17s %-21s %-14s %lu\n", "%4u | %-15s | %-17s | %-21s | %-15s | %9s\n",
++num, ++num,
(peer->purgeable == SN_UNPURGEABLE) ? "-l" : "", (peer->purgeable == SN_UNPURGEABLE) ? "-l" : "",
macaddr_str(mac_buf, peer->mac_addr), is_null_mac(peer->mac_addr) ? "" : macaddr_str(mac_buf, peer->mac_addr),
sock_to_cstr(sockbuf, &(peer->sock)), sock_to_cstr(sockbuf, &(peer->sock)),
sn_selection_criterion_str(sel_buf, peer), sn_selection_criterion_str(sel_buf, peer),
now - peer->last_seen); (peer->last_seen) ? time_buf : "");
sendto(eee->udp_mgmt_sock, udp_buf, msg_len, 0, sendto(eee->udp_mgmt_sock, udp_buf, msg_len, 0,
(struct sockaddr *) &sender_sock, sizeof(struct sockaddr_in)); (struct sockaddr *) &sender_sock, sizeof(struct sockaddr_in));
msg_len = 0; msg_len = 0;
} }
// end dump supernodes
// further stats
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
"-----------------------------------------------------------------------------------------------\n"); "================================================================================================\n");
msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len), msg_len += snprintf((char *) (udp_buf + msg_len), (N2N_PKT_BUF_SIZE - msg_len),
"uptime %lu | ", "uptime %lu | ",
@ -2199,7 +2206,7 @@ void readFromIPSocket (n2n_edge_t * eee, int in_sock) {
sprintf (sn->ip_addr, "%s:%u", sn->ip_addr, (uint16_t)(payload->sock.port)); sprintf (sn->ip_addr, "%s:%u", sn->ip_addr, (uint16_t)(payload->sock.port));
} }
sn_selection_criterion_default(&(sn->selection_criterion)); sn_selection_criterion_default(&(sn->selection_criterion));
sn->last_seen = now - LAST_SEEN_SN_NEW; sn->last_seen = 0; /* as opposed to payload handling in supernode */
traceEvent(TRACE_NORMAL, "Supernode '%s' added to the list of supernodes.", sn->ip_addr); traceEvent(TRACE_NORMAL, "Supernode '%s' added to the list of supernodes.", sn->ip_addr);
} }
// shift to next payload entry // shift to next payload entry

13
src/sn_selection.c

@ -147,14 +147,13 @@ extern char * sn_selection_criterion_str (selection_criterion_str_t out, peer_in
memset(out, 0, SN_SELECTION_CRITERION_BUF_SIZE); memset(out, 0, SN_SELECTION_CRITERION_BUF_SIZE);
#ifndef SN_SELECTION_RTT #ifndef SN_SELECTION_RTT
snprintf(out, SN_SELECTION_CRITERION_BUF_SIZE - 1, snprintf(out, SN_SELECTION_CRITERION_BUF_SIZE,
(int16_t)(peer->selection_criterion) != -1 ? "ld = %7d" : (int16_t)(peer->selection_criterion) != -1 ? "load = %8d" :
"ld = _______", peer->selection_criterion); "", peer->selection_criterion);
#else #else
snprintf(out, SN_SELECTION_CRITERION_BUF_SIZE - 1, snprintf(out, SN_SELECTION_CRITERION_BUF_SIZE,
(int16_t)(peer->selection_criterion) != -1 ? "rtt %5d ms" : (int16_t)(peer->selection_criterion) != -1 ? "rtt = %6d ms" :
"rtt _____ ms", peer->selection_criterion); "", peer->selection_criterion);
#endif #endif
return out; return out;

Loading…
Cancel
Save