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
@@ -187,7 +187,9 @@ static void send_wtr_cb(struct ll_queue* q, void* arg) {
|
||||
|
||||
static void send_burst(struct test_ctx* ctx) {
|
||||
if (ctx->test_done) return;
|
||||
struct ETCP_CONN* conn = ctx->sender->connections;
|
||||
struct ETCP_CONN* conn = NULL;
|
||||
if (ctx->sender->connections && ctx->sender->connections->head)
|
||||
conn = ((struct conn_queue_entry*)ctx->sender->connections->head->data)->conn;
|
||||
if (!conn || !conn->initialized) return;
|
||||
|
||||
if (conn->normalizer && conn->normalizer->input) {
|
||||
@@ -241,9 +243,11 @@ static void print_metrics(struct test_ctx* ctx) {
|
||||
double pace_kbps = 0;
|
||||
double rtt_ms = 0;
|
||||
|
||||
if (ctx->sender->connections && ctx->sender->connections->links) {
|
||||
struct ETCP_LINK* l = ctx->sender->connections->links;
|
||||
struct ETCP_CONN* c = ctx->sender->connections;
|
||||
struct ETCP_CONN* c = NULL;
|
||||
if (ctx->sender->connections && ctx->sender->connections->head)
|
||||
c = ((struct conn_queue_entry*)ctx->sender->connections->head->data)->conn;
|
||||
if (c && c->links) {
|
||||
struct ETCP_LINK* l = c->links;
|
||||
lk_status = l->link_status ? " UP" : " DN";
|
||||
lk_reinit = c->reinit_count;
|
||||
lk_rtrns = l->total_retransmissions;
|
||||
@@ -376,11 +380,14 @@ int main(void) {
|
||||
|
||||
/* Wait for connection */
|
||||
printf("Waiting for connection...\n");
|
||||
struct ETCP_CONN* conn = NULL;
|
||||
uint64_t t0 = now_us();
|
||||
while ((now_us() - t0) < 10000000ULL) {
|
||||
uasync_poll(ctx.ua, 1);
|
||||
if (ctx.sender->connections && ctx.sender->connections->links) {
|
||||
struct ETCP_LINK* l = ctx.sender->connections->links;
|
||||
if (ctx.sender->connections && ctx.sender->connections->head)
|
||||
conn = ((struct conn_queue_entry*)ctx.sender->connections->head->data)->conn;
|
||||
if (conn && conn->links) {
|
||||
struct ETCP_LINK* l = conn->links;
|
||||
if (l->initialized && l->link_status == 1) break;
|
||||
}
|
||||
}
|
||||
@@ -388,9 +395,9 @@ int main(void) {
|
||||
t0 = now_us();
|
||||
while ((now_us() - t0) < 500000ULL) uasync_poll(ctx.ua, 1);
|
||||
|
||||
if (ctx.sender->connections && ctx.sender->connections->normalizer && ctx.sender->connections->normalizer->input) {
|
||||
queue_set_threshold(ctx.sender->connections->normalizer->input, 0, 0);
|
||||
queue_set_waiter_defer(ctx.sender->connections->normalizer->input, 1);
|
||||
if (conn && conn->normalizer && conn->normalizer->input) {
|
||||
queue_set_threshold(conn->normalizer->input, 0, 0);
|
||||
queue_set_waiter_defer(conn->normalizer->input, 1);
|
||||
}
|
||||
|
||||
/* Start test */
|
||||
@@ -416,10 +423,15 @@ int main(void) {
|
||||
const struct dummynet_stats* ds = dummynet_get_stats(ctx.dn, DUMMYNET_FORWARD);
|
||||
const char* lks = "?";
|
||||
uint32_t rein = 0, rtrns = 0;
|
||||
if (ctx.sender->connections && ctx.sender->connections->links) {
|
||||
lks = ctx.sender->connections->links->link_status ? "UP" : "DN";
|
||||
rein = ctx.sender->connections->reinit_count;
|
||||
rtrns = ctx.sender->connections->links->total_retransmissions;
|
||||
{
|
||||
struct ETCP_CONN* c = NULL;
|
||||
if (ctx.sender->connections && ctx.sender->connections->head)
|
||||
c = ((struct conn_queue_entry*)ctx.sender->connections->head->data)->conn;
|
||||
if (c && c->links) {
|
||||
lks = c->links->link_status ? "UP" : "DN";
|
||||
rein = c->reinit_count;
|
||||
rtrns = c->links->total_retransmissions;
|
||||
}
|
||||
}
|
||||
printf(" t=%lus Lk=%s Rein=%u Rtrns=%u recv=%lu dn_tx=%llu dn_lost=%llu\n",
|
||||
(unsigned long)elapsed, lks, rein, rtrns, (unsigned long)ctx.bytes_received,
|
||||
@@ -455,31 +467,35 @@ int main(void) {
|
||||
(unsigned long long)ds_bk->recv, (unsigned long long)ds_bk->sent,
|
||||
(unsigned long long)ds_bk->lost, (unsigned long long)ds_bk->dropped);
|
||||
|
||||
if (ctx.sender->connections) {
|
||||
struct ETCP_CONN* c = ctx.sender->connections;
|
||||
printf("ETCP: reinit=%u reset=%u links_up=%u\n",
|
||||
c->reinit_count, c->reset_count, c->links_up);
|
||||
if (c->links) {
|
||||
struct ETCP_LINK* l = c->links;
|
||||
int lnum = 0;
|
||||
while (l) {
|
||||
lnum++;
|
||||
printf(" Link%d: status=%s state=%u rKeep=%u sKeep=%u retrans=%lu"
|
||||
" inflight=%u/%u lim=%u kB rtt=%u ms\n",
|
||||
lnum, l->link_status ? "UP" : "DN", l->link_state,
|
||||
l->recv_keepalive, l->remote_keepalive,
|
||||
(unsigned long)l->total_retransmissions,
|
||||
l->inflight_bytes, l->inflight_packets, l->inflight_lim_bytes / 1024,
|
||||
l->rtt_last);
|
||||
if (l->bbr)
|
||||
printf(" BBR: mode=%d cycle=%d full_bw=%d loss_rnd=%d"
|
||||
" minrtt=%.1fms bw_hi=%.0fK bw_lo=%.0fK pace=%.0fK infl_hi=%.1fK infl_lo=%.1fK\n",
|
||||
l->bbr->mode, l->bbr->cycle_idx, l->bbr->full_bw_reached, l->bbr->loss_in_round,
|
||||
(double)l->bbr->min_rtt_us / 1000.0,
|
||||
(double)l->bbr->bw_hi[0] / 2097.152, (double)l->bbr->bw_lo / 2097.152,
|
||||
(double)l->bbr_pacing_rate / 125.0,
|
||||
(double)l->bbr->inflight_hi / 1024.0, (double)l->bbr->inflight_lo / 1024.0);
|
||||
l = l->next;
|
||||
{
|
||||
struct ETCP_CONN* c = NULL;
|
||||
if (ctx.sender->connections && ctx.sender->connections->head)
|
||||
c = ((struct conn_queue_entry*)ctx.sender->connections->head->data)->conn;
|
||||
if (c) {
|
||||
printf("ETCP: reinit=%u reset=%u links_up=%u\n",
|
||||
c->reinit_count, c->reset_count, c->links_up);
|
||||
if (c->links) {
|
||||
struct ETCP_LINK* l = c->links;
|
||||
int lnum = 0;
|
||||
while (l) {
|
||||
lnum++;
|
||||
printf(" Link%d: status=%s state=%u rKeep=%u sKeep=%u retrans=%lu"
|
||||
" inflight=%u/%u lim=%u kB rtt=%u ms\n",
|
||||
lnum, l->link_status ? "UP" : "DN", l->link_state,
|
||||
l->recv_keepalive, l->remote_keepalive,
|
||||
(unsigned long)l->total_retransmissions,
|
||||
l->inflight_bytes, l->inflight_packets, l->inflight_lim_bytes / 1024,
|
||||
l->rtt_last);
|
||||
if (l->bbr)
|
||||
printf(" BBR: mode=%d cycle=%d full_bw=%d loss_rnd=%d"
|
||||
" minrtt=%.1fms bw_hi=%.0fK bw_lo=%.0fK pace=%.0fK infl_hi=%.1fK infl_lo=%.1fK\n",
|
||||
l->bbr->mode, l->bbr->cycle_idx, l->bbr->full_bw_reached, l->bbr->loss_in_round,
|
||||
(double)l->bbr->min_rtt_us / 1000.0,
|
||||
(double)l->bbr->bw_hi[0] / 2097.152, (double)l->bbr->bw_lo / 2097.152,
|
||||
(double)l->bbr_pacing_rate / 125.0,
|
||||
(double)l->bbr->inflight_hi / 1024.0, (double)l->bbr->inflight_lo / 1024.0);
|
||||
l = l->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -505,8 +521,13 @@ int main(void) {
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
if (ctx.sender->connections && ctx.sender->connections->normalizer && ctx.sender->connections->normalizer->input)
|
||||
queue_waiter_cancel(ctx.sender->connections->normalizer->input, &ctx.waiter);
|
||||
{
|
||||
struct ETCP_CONN* cc = NULL;
|
||||
if (ctx.sender->connections && ctx.sender->connections->head)
|
||||
cc = ((struct conn_queue_entry*)ctx.sender->connections->head->data)->conn;
|
||||
if (cc && cc->normalizer && cc->normalizer->input)
|
||||
queue_waiter_cancel(cc->normalizer->input, &ctx.waiter);
|
||||
}
|
||||
dummynet_destroy(ctx.dn);
|
||||
utun_instance_destroy(ctx.sender);
|
||||
utun_instance_destroy(ctx.receiver);
|
||||
|
||||
Reference in new issue
Block a user