topo_group: migrate CONN_MGR entries to ll_queue, simplify TOPO_GROUP_NODE

- CONN_MGR entries: replace dynamic array with ll_queue (hash=256, key_size=8)
  cm_find_entry now O(1) via queue_find_data_by_index
  cm_ensure_entry uses queue_entry_new + queue_data_put_with_index
  cm_entry_cleanup removes from queue and frees entry

- TOPO_GROUP_NODE: replace handles** array with single CONN_MGR_HANDLE*
  remove topo_node_handle_register/unregister/count — dead indirection
  nq->handle = h / nq->handle = NULL in all call sites

- TOPO_GROUP_NODE: remove dead fields dirty, best_socket, tranzit_data/count
  dirty replaced with local variable in nat_detection.c
  tranzit_data removed from wire format (TOPOMSG_NODE), serialize, deserialize
  update struct layout: one field per line with comments
This commit is contained in:
evgeny committed 2026-08-02 16:45:52 +03:00
1 parent f5efaa495b
commit c35135cb52
11 files changed
+118 -108

No files matched your search

+7 -36
View File
@@ -87,8 +87,8 @@ void topo_nodeq_free_group_fields(struct TOPO_GROUPS* groups, struct TOPO_GROUP_
u_free(nq->subnets);
nq->subnets = NULL;
}
u_free(nq->tranzit_data); nq->tranzit_data = NULL; nq->tranzit_count = 0;
u_free(nq->hop_list); nq->hop_list = NULL; nq->hop_count = 0;
nq->handle = NULL;
}
// ===== глобальный реестр TOPO_NODE =====
@@ -145,9 +145,8 @@ int topo_node_dyn_size(const struct TOPOMSG_NODE* msg) {
+ msg->local_v6_sockets * sizeof(struct TOPOMSG_SOCKMETA6)
+ msg->local_v6_addrs * sizeof(struct TOPOMSG_ADDR6)
+ ((msg->flags & TOPO_FLAG_SEND_SUBNETS)
? (msg->local_v4_subnets * sizeof(struct TOPOMSG_SUBNET4) + msg->local_v6_subnets * sizeof(struct TOPOMSG_SUBNET6))
: 0)
+ msg->tranzit_nodes * sizeof(struct TOPOMSG_TRANZIT)
? (msg->local_v4_subnets * sizeof(struct TOPOMSG_SUBNET4) + msg->local_v6_subnets * sizeof(struct TOPOMSG_SUBNET6))
: 0)
+ msg->hop_count * 8;
}
@@ -170,7 +169,6 @@ int topo_node_serialize(struct TOPO_NODE* ni, struct TOPO_GROUP_NODE* nq, uint8_
msg.local_v6_addrs = topo_list_count((struct _topo_head*)ni->v6_addrs);
msg.local_v4_subnets = nq->subnets ? topo_list_count((struct _topo_head*)nq->subnets->v4_subnets) : 0;
msg.local_v6_subnets = nq->subnets ? topo_list_count((struct _topo_head*)nq->subnets->v6_subnets) : 0;
msg.tranzit_nodes = nq->tranzit_count;
msg.hop_count = nq->hop_count;
msg.cumulative_rtt = cumulative_rtt;
@@ -210,10 +208,6 @@ int topo_node_serialize(struct TOPO_NODE* ni, struct TOPO_GROUP_NODE* nq, uint8_
}}
}
}
if (msg.tranzit_nodes && nq->tranzit_data) {
size_t sz = msg.tranzit_nodes * sizeof(struct TOPOMSG_TRANZIT);
memcpy(dp, nq->tranzit_data, sz); dp += sz;
}
if (msg.hop_count && nq->hop_list) {
size_t sz = msg.hop_count * 8;
memcpy(dp, nq->hop_list, sz); dp += sz;
@@ -224,7 +218,6 @@ int topo_node_serialize(struct TOPO_NODE* ni, struct TOPO_GROUP_NODE* nq, uint8_
// ===== deserialization =====
int topo_node_deserialize(struct TOPO_GROUP* group, const uint8_t* data, size_t len, struct TOPO_NODE** out_ni, struct TOPO_NODESUBNETS** out_subnets,
struct TOPOMSG_TRANZIT** out_tranzit, uint8_t* out_tranzit_count,
uint64_t** out_hop_list, uint8_t* out_hop_count,
uint16_t* out_cumulative_rtt) {
if (!group || !data || len < TOPOMSG_NODE_HDR_SIZE || !out_ni) return -1;
@@ -307,13 +300,6 @@ int topo_node_deserialize(struct TOPO_GROUP* group, const uint8_t* data, size_t
if (out_subnets) *out_subnets = NULL;
}
if (out_tranzit && msg->tranzit_nodes > 0) {
size_t tsz = msg->tranzit_nodes * sizeof(struct TOPOMSG_TRANZIT);
*out_tranzit = u_malloc(tsz);
if (!*out_tranzit) { topo_node_free_raw(group->instance->topo_groups, ni); return -1; }
memcpy(*out_tranzit, dp, tsz); dp += tsz;
*out_tranzit_count = msg->tranzit_nodes;
}
if (out_hop_list && msg->hop_count > 0) {
size_t hsz = msg->hop_count * 8;
*out_hop_list = u_malloc(hsz);
@@ -419,12 +405,10 @@ void topo_node_dump_all(struct TOPO_GROUP* group) {
int is_local = (group->local_node == nq);
const char* name_s = ni->node_name ? ni->node_name : "";
DEBUG_INFO(DEBUG_CATEGORY_BGP, "--- Node #%d: id=%016llx name=\"%s\" ver=%u dirty=%u grp=%llu%s ---",
idx, (unsigned long long)ni->node_id, name_s, ni->ver, nq->dirty,
DEBUG_INFO(DEBUG_CATEGORY_BGP, "--- Node #%d: id=%016llx name=\"%s\" ver=%u grp=%llu%s ---",
idx, (unsigned long long)ni->node_id, name_s, ni->ver,
(unsigned long long)ni->group_id, is_local ? " [LOCAL]" : "");
if (nq->best_socket) DEBUG_INFO(DEBUG_CATEGORY_BGP, " best_socket=%p", (void*)nq->best_socket);
log_dump(DEBUG_LEVEL_INFO, DEBUG_CATEGORY_BGP, " pubkey ", ni->public_key, SC_PUBKEY_SIZE);
log_dump(DEBUG_LEVEL_INFO, DEBUG_CATEGORY_BGP, " ed25519", ni->ed25519_public_key, SC_PUBKEY_SIZE);
@@ -460,11 +444,6 @@ void topo_node_dump_all(struct TOPO_GROUP* group) {
sub6 = sub6->next;
}}
}
for (int i = 0; i < nq->tranzit_count; i++) {
DEBUG_INFO(DEBUG_CATEGORY_BGP, " tranzit[%d]: node=%016llx rtt=%u linkq=%u",
i, (unsigned long long)nq->tranzit_data[i].node_id, nq->tranzit_data[i].rtt, nq->tranzit_data[i].link_q);
}
int path_idx = 0;
if (nq->paths) {
struct ll_entry* pe = nq->paths->head;
@@ -517,12 +496,10 @@ int topo_node_format_all(struct TOPO_GROUP* group, char* buf, size_t buf_size) {
#define FMT_ADD(fmt, ...) pos += snprintf(buf + pos, buf_size > (size_t)pos ? buf_size - pos : 0, fmt, ##__VA_ARGS__)
FMT_ADD("--- Node #%d: id=%016llx name=\"%s\" ver=%u dirty=%u grp=%llu%s ---\n",
idx, (unsigned long long)ni->node_id, name_s, ni->ver, nq->dirty,
FMT_ADD("--- Node #%d: id=%016llx name=\"%s\" ver=%u grp=%llu%s ---\n",
idx, (unsigned long long)ni->node_id, name_s, ni->ver,
(unsigned long long)ni->group_id, is_local ? " [LOCAL]" : "");
if (nq->best_socket) FMT_ADD(" best_socket=%p\n", (void*)nq->best_socket);
FMT_ADD(" pubkey: "); for (int k = 0; k < SC_PUBKEY_SIZE; k++) FMT_ADD("%02x", ni->public_key[k]); FMT_ADD("\n");
FMT_ADD(" ed25519: "); for (int k = 0; k < SC_PUBKEY_SIZE; k++) FMT_ADD("%02x", ni->ed25519_public_key[k]); FMT_ADD("\n");
@@ -552,10 +529,6 @@ int topo_node_format_all(struct TOPO_GROUP* group, char* buf, size_t buf_size) {
FMT_ADD(" v6sub[%d]: %s/%d\n", r6i++, ip_to_str(sub6->addr, AF_INET6).str, sub6->prefix_length); sub6 = sub6->next;
}}
}
for (int i = 0; i < nq->tranzit_count; i++)
FMT_ADD(" tranzit[%d]: node=%016llx rtt=%u linkq=%u\n",
i, (unsigned long long)nq->tranzit_data[i].node_id, nq->tranzit_data[i].rtt, nq->tranzit_data[i].link_q);
if (nq->paths) {
struct ll_entry* pe = nq->paths->head; int pi = 0;
while (pe) {
@@ -686,7 +659,6 @@ int topo_group_update_my_nodeinfo(struct UTUN_INSTANCE* instance, struct TOPO_GR
topo_node_registry_store(instance->topo_groups, ni);
lq->node_id = ni->node_id;
lq->hop_count = 0;
lq->dirty = 1;
lq->last_ver = ni->ver;
e_sock = instance->etcp_sockets;
@@ -838,7 +810,6 @@ void topo_node_update_my_addresses(struct UTUN_INSTANCE* instance) {
while (ge) {
struct TOPO_GROUP* g = (struct TOPO_GROUP*)ge;
if (g->local_node) {
g->local_node->dirty = 1;
if (g->senders_list) {
struct ll_entry* se = g->senders_list->head;
while (se) {