add server/client (S/C) indicator based on ETCP_LINK.is_server in connection monitor, member detail, and Android JSON
This commit is contained in:
1 parent
cf956cf2f0
commit
496f0f7d2b
4 files changed
+29
-32
No files matched your search
+10
-30
@@ -16,9 +16,6 @@
|
||||
#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) {
|
||||
@@ -150,17 +147,9 @@ 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; }
|
||||
if (conn->links) {
|
||||
if (!conn->links->is_server) flags |= 4;
|
||||
else flags |= 8;
|
||||
}
|
||||
*p++ = flags;
|
||||
|
||||
@@ -213,21 +202,8 @@ 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";
|
||||
int is_server = conn->links ? conn->links->is_server : -1;
|
||||
const char* role_str = is_server < 0 ? "none" : (is_server ? "server" : "client");
|
||||
|
||||
/* Count links */
|
||||
int link_count = 0, links_up_count = 0;
|
||||
@@ -326,7 +302,7 @@ void chat_core_collect_conn_metrics_trampoline(void* arg) {
|
||||
|
||||
/* ── Live-снапшот для панели деталей участника ──
|
||||
* packet: [node_id:8][flags:1][own_tcp_active:2][link_count:1](link:24B)*[sock_count:1](sock:48B)*
|
||||
* flags: bit0=conn_present bit1=conn_up(links_up) bit2=conn_initialized
|
||||
* flags: bit0=conn_present bit1=conn_up(links_up) bit2=conn_initialized bit3=client bit4=server
|
||||
* link: [is_tcp:1][link_state:1][link_status:1][tcp_ready:1][family:1][addr_len:1][addr:16][port:2]
|
||||
* sock: [sock_id:4][port:2][link_count:4][ifname:38]
|
||||
* Собирается в worker-потоке — читает живые структуры UTUN_INSTANCE безопасно. */
|
||||
@@ -361,6 +337,10 @@ static void collect_member_detail(uint64_t node_id) {
|
||||
flags |= 1;
|
||||
if (conn->links_up) flags |= 2;
|
||||
if (conn->initialized) flags |= 4;
|
||||
if (conn->links) {
|
||||
if (!conn->links->is_server) flags |= 8;
|
||||
else flags |= 16;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t own_tcp_active = 0;
|
||||
|
||||
@@ -812,6 +812,14 @@ char* utun_bridge_get_member_detail_json(const char* channel_id, uint64_t node_i
|
||||
}
|
||||
|
||||
char peers_tbl[80]; peers_table_name(channel_id, peers_tbl, sizeof(peers_tbl));
|
||||
|
||||
{ /* server/client role */
|
||||
struct ETCP_CONN* detail_conn = NULL;
|
||||
if (g_cc.inst) detail_conn = instance_find_conn(g_cc.inst, node_id);
|
||||
const char* sc = (detail_conn && detail_conn->links)
|
||||
? (detail_conn->links->is_server ? "S" : "C") : "";
|
||||
pos += (size_t)snprintf(buf + pos, sizeof(buf) - pos, ",\"sc\":\"%s\"", sc);
|
||||
}
|
||||
snprintf(buf + pos, sizeof(buf) - pos, ",\"adr\":["); pos += strlen(buf + pos);
|
||||
|
||||
if (sqlite3_prepare_v2(db,
|
||||
|
||||
@@ -154,6 +154,8 @@ void AccountList::showMemberDetail(quint64 nodeId) {
|
||||
m_snapConnPresent = false;
|
||||
m_snapConnUp = false;
|
||||
m_snapConnInit = false;
|
||||
m_snapClient = false;
|
||||
m_snapServer = false;
|
||||
m_snapOwnTcpActive = 0;
|
||||
m_snapLinks.clear();
|
||||
m_snapSocks.clear();
|
||||
@@ -244,6 +246,8 @@ void AccountList::onMemberDetailData(uint64_t nodeId, const uint8_t* data, int l
|
||||
m_snapConnPresent = (flags & 1) != 0;
|
||||
m_snapConnUp = (flags & 2) != 0;
|
||||
m_snapConnInit = (flags & 4) != 0;
|
||||
m_snapClient = (flags & 8) != 0;
|
||||
m_snapServer = (flags & 16) != 0;
|
||||
uint16_t ownTcpActive;
|
||||
memcpy(&ownTcpActive, p, 2); p += 2;
|
||||
m_snapOwnTcpActive = ownTcpActive;
|
||||
@@ -302,8 +306,11 @@ void AccountList::updateDetailDisplay() {
|
||||
lines.append(QString("ID:0x%1").arg(m_detailNodeId, 16, 16, QChar('0')));
|
||||
|
||||
QString dotColor = m_detailOnline ? "#4CAF50" : "#9E9E9E";
|
||||
lines.append(QString("<span style='color:%1;'>●</span> %2")
|
||||
.arg(dotColor, m_detailName.toHtmlEscaped()));
|
||||
QString scLabel;
|
||||
if (m_snapClient) scLabel = " C";
|
||||
else if (m_snapServer) scLabel = " S";
|
||||
lines.append(QString("<span style='color:%1;'>●</span> %2%3")
|
||||
.arg(dotColor, m_detailName.toHtmlEscaped(), scLabel));
|
||||
|
||||
if (m_detailLastSeen > 0)
|
||||
lines.append(QString("⌛ %1").arg(relativeTimeStr(m_detailLastSeen)));
|
||||
|
||||
@@ -89,6 +89,8 @@ private:
|
||||
bool m_snapConnPresent = false;
|
||||
bool m_snapConnUp = false;
|
||||
bool m_snapConnInit = false;
|
||||
bool m_snapClient = false;
|
||||
bool m_snapServer = false;
|
||||
int m_snapOwnTcpActive = 0;
|
||||
QVector<MemberLinkSnap> m_snapLinks;
|
||||
QVector<MemberSockSnap> m_snapSocks;
|
||||
|
||||
Reference in new issue
Block a user