Browse Source

add proxy server/client indicator (S/C) in connection monitor

topo_upd
evgeny 2 months ago
parent
commit
cf956cf2f0
  1. 33
      src/chat/chat_status.c
  2. 2
      src/proxy/icmp_proxy.c
  3. 2
      src/proxy/icmp_proxy.h
  4. 2
      src/proxy/udp_proxy.c
  5. 2
      src/proxy/udp_proxy.h
  6. 13
      tools/chatgui/src/connmonitorwindow.cpp

33
src/chat/chat_status.c

@ -16,6 +16,9 @@
#include "../transport_layer/etcp_connections.h"
#include "../transport_layer/stcp_link.h"
#include "../transport_layer/pkt_normalizer.h"
#include "../proxy/tcp_proxy_server.h"
#include "../proxy/udp_proxy.h"
#include "../proxy/icmp_proxy.h"
#include <string.h>
static const char* nat_type_str(uint8_t t) {
@ -147,6 +150,18 @@ static void collect_conn_list(void) {
uint8_t flags = 0;
if (conn->links_up) flags |= 1;
if (conn->initialized) flags |= 2;
if (g_cc.inst->tcp_proxy_client && ce->peer_node_id == g_cc.inst->config->global.tcp_proxy_client_via_node_id)
flags |= 4;
if (g_cc.inst->config->global.tcp_proxy_server_enabled) {
for (struct tcp_proxy_server_conn* sc = g_cc.inst->tcp_proxy_server.conns; sc; sc = sc->next)
if (sc->peer_node_id == ce->peer_node_id) { flags |= 8; break; }
if (!(flags & 8) && g_udp_ctx && g_udp_ctx->is_exit)
for (struct udp_flow* f = g_udp_ctx->flows; f; f = f->next)
if (f->client_node_id == ce->peer_node_id) { flags |= 8; break; }
if (!(flags & 8) && g_icmp_ctx && g_icmp_ctx->is_exit)
for (struct icmp_request* r = g_icmp_ctx->pending; r; r = r->next)
if (r->client_node_id == ce->peer_node_id) { flags |= 8; break; }
}
*p++ = flags;
uint8_t lc = 0;
@ -198,12 +213,29 @@ static void collect_conn_metrics(uint64_t peer_node_id) {
char peername[64]; get_node_name(peer_node_id, peername, sizeof(peername));
if (!peername[0]) snprintf(peername, sizeof(peername), "%016llX", (unsigned long long)peer_node_id);
int is_client = 0, is_server = 0;
if (g_cc.inst->tcp_proxy_client && peer_node_id == g_cc.inst->config->global.tcp_proxy_client_via_node_id)
is_client = 1;
if (g_cc.inst->config->global.tcp_proxy_server_enabled) {
for (struct tcp_proxy_server_conn* sc = g_cc.inst->tcp_proxy_server.conns; sc; sc = sc->next)
if (sc->peer_node_id == peer_node_id) { is_server = 1; break; }
if (!is_server && g_udp_ctx && g_udp_ctx->is_exit)
for (struct udp_flow* f = g_udp_ctx->flows; f; f = f->next)
if (f->client_node_id == peer_node_id) { is_server = 1; break; }
if (!is_server && g_icmp_ctx && g_icmp_ctx->is_exit)
for (struct icmp_request* r = g_icmp_ctx->pending; r; r = r->next)
if (r->client_node_id == peer_node_id) { is_server = 1; break; }
}
const char* role_str = is_client && is_server ? "proxy client+server" :
is_client ? "proxy client" : is_server ? "proxy server" : "none";
/* Count links */
int link_count = 0, links_up_count = 0;
struct ETCP_LINK* tl = conn->links; while (tl) { if (tl->link_status) links_up_count++; link_count++; tl = tl->next; }
off += snprintf(buf + off, sizeof(buf) - off,
"=== PEER: %04llX\u2192%04llX [%s] ===\n"
"Role: %s\n"
"Status: %s Links: %d/%d Initialized: %s Session: 0x%X MTU: %d\n"
"Reinit: %u Reset: %u Tx_state: %d Routing_exchange: %d\n"
"\n--- ETCP ---\n"
@ -214,6 +246,7 @@ static void collect_conn_metrics(uint64_t peer_node_id) {
"IDs: next_tx=%u last_rx=%u last_del=%u rx_ack_till=%u\n"
"\n--- Queues ---\n",
(unsigned long long)(my_id & 0xFFFF), (unsigned long long)(peer_node_id & 0xFFFF), peername,
role_str,
conn->links_up ? "UP" : "DOWN", links_up_count, link_count,
conn->initialized ? "yes" : "no", conn->session_id, conn->mtu,
conn->reinit_count, conn->reset_count, conn->tx_state, conn->routing_exchange_active,

2
src/proxy/icmp_proxy.c

@ -48,7 +48,7 @@ struct ip {
#define ICMP_DEF_TTL 64
#define ICMP_TIMEOUT_TB 50000 // 5s for echo reply
static struct icmp_proxy_ctx* g_icmp_ctx = NULL;
struct icmp_proxy_ctx* g_icmp_ctx = NULL;
static void req_expire_timer_cb(void* arg);
static void req_expire(struct icmp_proxy_ctx* ctx);

2
src/proxy/icmp_proxy.h

@ -50,6 +50,8 @@ struct icmp_proxy_ctx {
void* expire_timer; // периодический таймер очистки истёкших запросов
};
extern struct icmp_proxy_ctx* g_icmp_ctx;
int icmp_proxy_init(struct UTUN_INSTANCE* inst, struct UASYNC* ua);
void icmp_proxy_destroy(struct UTUN_INSTANCE* inst);

2
src/proxy/udp_proxy.c

@ -23,7 +23,7 @@
#define UDP_FLOW_TIMEOUT_TB 600000 // 60с
static struct udp_proxy_ctx* g_udp_ctx = NULL;
struct udp_proxy_ctx* g_udp_ctx = NULL;
static void flow_expire_timer_cb(void* arg);
static void flow_expire(struct udp_proxy_ctx* ctx);

2
src/proxy/udp_proxy.h

@ -48,6 +48,8 @@ struct udp_proxy_ctx {
void* expire_timer; // периодический таймер очистки истёкших потоков
};
extern struct udp_proxy_ctx* g_udp_ctx;
int udp_proxy_init(struct UTUN_INSTANCE* inst, struct UASYNC* ua);
void udp_proxy_destroy(struct UTUN_INSTANCE* inst);

13
tools/chatgui/src/connmonitorwindow.cpp

@ -146,15 +146,24 @@ void ConnMonitorWindow::onConnList(const uint8_t* data, int len) {
bool linksUp = (flags & 1) != 0;
bool initialized = (flags & 2) != 0;
bool proxyClient = (flags & 4) != 0;
bool proxyServer = (flags & 8) != 0;
QString color = linksUp ? "#2E7D32" : "#C62828";
QString status = linksUp ? "UP" : (initialized ? "init" : "DOWN");
QString proxyRole;
if (proxyClient && proxyServer) proxyRole = "CS";
else if (proxyClient) proxyRole = " C";
else if (proxyServer) proxyRole = " S";
QString nodeHex = QString("%1").arg(nodeId, 16, 16, QChar('0')).right(16).left(4);
QString rttStr = rtt > 0 ? QString::number(rtt / 10.0f, 'f', 1) : "-";
QString text = QString("[%1] %2 %3 rtt=%4ms")
QString text = QString("[%1] %2 %3%4 %5L rtt=%6ms")
.arg(nodeHex)
.arg(QString::fromUtf8(name).left(16), -16)
.arg(status + QString(" %1L").arg(linkCount), -10)
.arg(status, -4)
.arg(proxyRole, -2)
.arg(linkCount)
.arg(rttStr);
auto it = existing.find(nodeId);

Loading…
Cancel
Save