etcp: replace connections linked-list with indexed ll_queue, add state/ref_count lifecycle
- Remove ETCP_CONN.next linked-list, UTUN_INSTANCE.connections list/count
- Unified connections in single ll_queue indexed by peer_node_id (0=pending)
- struct conn_queue_entry { peer_node_id, conn* } for uniform queue data
- Connection lifecycle via etcp.c: create→pending, conn_ready→indexed, close→detach+deferred free
- Close split: phase1 detach from external world, phase2 deferred via uasync_call_soon
- etcp_conn_set_peer_node_id: reindex on ID change (WARN)
- etcp_conn_ref_take/free: blocking close until refcount returns to 0
- Remove chat_connections — use unified connections queue directly
- Update all iteration/search patterns across 40 files (src + tests + chatgui)
This commit is contained in:
1 parent
6902f5fd95
commit
a7ecee01f5
40 files changed
+650
-449
No files matched your search
+14
-16
@@ -885,10 +885,10 @@ static void send_conn_list(struct control_server* server, struct control_client*
|
||||
|
||||
/* Count connections */
|
||||
uint8_t count = 0;
|
||||
struct ETCP_CONN* conn = instance->connections;
|
||||
while (conn && count < ETCPMON_MAX_CONNECTIONS) {
|
||||
struct ll_entry* entry = instance->connections->head;
|
||||
while (entry && count < ETCPMON_MAX_CONNECTIONS) {
|
||||
count++;
|
||||
conn = conn->next;
|
||||
entry = entry->next;
|
||||
}
|
||||
|
||||
/* Build response */
|
||||
@@ -909,12 +909,13 @@ static void send_conn_list(struct control_server* server, struct control_client*
|
||||
rsp->count = count;
|
||||
|
||||
struct etcpmon_conn_info* info = (struct etcpmon_conn_info*)(buffer + sizeof(*hdr) + sizeof(*rsp));
|
||||
conn = instance->connections;
|
||||
for (uint8_t i = 0; i < count && conn; i++) {
|
||||
info[i].peer_node_id = conn->peer_node_id;
|
||||
strncpy(info[i].name, conn->log_name, ETCPMON_MAX_CONN_NAME - 1);
|
||||
entry = instance->connections->head;
|
||||
for (uint8_t i = 0; i < count && entry; i++) {
|
||||
struct conn_queue_entry* ce = (struct conn_queue_entry*)entry->data;
|
||||
info[i].peer_node_id = ce->conn->peer_node_id;
|
||||
strncpy(info[i].name, ce->conn->log_name, ETCPMON_MAX_CONN_NAME - 1);
|
||||
info[i].name[ETCPMON_MAX_CONN_NAME - 1] = '\0';
|
||||
conn = conn->next;
|
||||
entry = entry->next;
|
||||
}
|
||||
|
||||
/* Log and send response */
|
||||
@@ -1372,14 +1373,11 @@ static void send_debug_config(struct control_server* server, struct control_clie
|
||||
|
||||
static struct ETCP_CONN* find_connection_by_peer_id(struct UTUN_INSTANCE* instance,
|
||||
uint64_t peer_id) {
|
||||
struct ETCP_CONN* conn = instance->connections;
|
||||
while (conn) {
|
||||
if (conn->peer_node_id == peer_id) {
|
||||
return conn;
|
||||
}
|
||||
conn = conn->next;
|
||||
}
|
||||
return NULL;
|
||||
if (!instance || !instance->connections) return NULL;
|
||||
struct ll_entry* e = queue_find_data_by_index(instance->connections, (const uint8_t*)&peer_id);
|
||||
if (!e) return NULL;
|
||||
struct conn_queue_entry* ce = (struct conn_queue_entry*)e->data;
|
||||
return ce->conn;
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
|
||||
Reference in new issue
Block a user