Keep connection construction independent from link admission policy

This commit is contained in:
evgeny committed 2026-10-30 22:50:11 +01:00
1 parent 55699b15cf
commit 59ccd4a213
3 files changed
+11 -11

No files matched your search

+9 -9
View File
@@ -43,7 +43,7 @@ static void owner_cb(struct NODE_CONN_DIRECT* h, enum ncd_event event, void* arg
}
}
static struct ETCP_CONN* ready_conn(struct UTUN_INSTANCE* inst) {
struct ETCP_CONN* c = etcp_connection_create(inst,"ncd_lifecycle", 0); CHECK(c);
struct ETCP_CONN* c = etcp_connection_create(inst,"ncd_lifecycle"); CHECK(c);
c->peer_node_id = 42; c->links_up = 1; etcp_conn_ready(c);
queue_set_callback(c->send_input_q,NULL,NULL); // физического линка нет; проверяем lifecycle управляющих отправок
return c;
@@ -180,7 +180,7 @@ static void subscription_update(struct subscription_case *test, unsigned index,
static void subscription_fire(struct subscription_case *test) {
switch (test->kind) {
case 0: {
struct ETCP_CONN *created = etcp_connection_create(test->inst, "nested subscription", 0); CHECK(created);
struct ETCP_CONN *created = etcp_connection_create(test->inst, "nested subscription"); CHECK(created);
etcp_connection_close(created);
break;
}
@@ -213,7 +213,7 @@ static void subscription_socket(struct ETCP_SOCKET *socket, int event, void *arg
static void subscription_cases(struct UTUN_INSTANCE *inst) {
for (unsigned kind = 0; kind < 4; kind++) {
struct subscription_case test = {.inst = inst, .kind = kind};
test.conn = etcp_connection_create(inst, "subscription lifetime", 0); CHECK(test.conn);
test.conn = etcp_connection_create(inst, "subscription lifetime"); CHECK(test.conn);
if (kind == 2) { test.link = etcp_link_new(test.conn, NULL, NULL, 0); CHECK(test.link); }
test.socket.instance = inst;
for (unsigned i = 0; i < 3; i++) { test.args[i].test = &test; test.args[i].index = i; }
@@ -247,7 +247,7 @@ static void constructor_close_cases(struct UTUN_INSTANCE *inst) {
struct create_close_case test = {.status = status};
if (!status) etcp_add_new_conn_cbk(inst, cancel_created_connection, &test);
etcp_add_conn_status_cbk(inst, observe_created_connection, &test);
CHECK(etcp_connection_create(inst, "cancel creation", 0) == NULL);
CHECK(etcp_connection_create(inst, "cancel creation") == NULL);
CHECK(test.deleted == 1 && test.created == !status && test.published == status);
CHECK(!inst->connections->count);
if (!status) etcp_remove_new_conn_cbk(inst, cancel_created_connection, &test);
@@ -267,7 +267,7 @@ static void cancel_created_link(struct ETCP_CONN *conn, struct ETCP_LINK *link,
}
static void link_constructor_close_cases(struct UTUN_INSTANCE *inst) {
for (unsigned action = 1; action <= 2; action++) {
struct ETCP_CONN *conn = etcp_connection_create(inst, "cancel link", 0); CHECK(conn);
struct ETCP_CONN *conn = etcp_connection_create(inst, "cancel link"); CHECK(conn);
CHECK(etcp_conn_ref_take(conn) == 0);
etcp_add_link_status_cbk(inst, cancel_created_link, (void*)(uintptr_t)action);
CHECK(etcp_link_new(conn, NULL, NULL, 0) == NULL);
@@ -294,7 +294,7 @@ static void close_neighbor(struct ETCP_CONN *conn, struct ETCP_LINK *link, int o
}
}
static void neighbor_close_case(struct UTUN_INSTANCE *inst) {
struct ETCP_CONN *conn = etcp_connection_create(inst, "neighbor close", 0); CHECK(conn);
struct ETCP_CONN *conn = etcp_connection_create(inst, "neighbor close"); CHECK(conn);
CHECK(etcp_conn_ref_take(conn) == 0);
CHECK(etcp_link_new(conn, NULL, NULL, 0));
struct link_close_case test = {.neighbor = etcp_link_new(conn, NULL, NULL, 0)}; CHECK(test.neighbor);
@@ -308,8 +308,8 @@ static void neighbor_close_case(struct UTUN_INSTANCE *inst) {
}
static void registry_index_cases(struct UTUN_INSTANCE *inst) {
struct ETCP_CONN *first = etcp_connection_create(inst, "first indexed", 0); CHECK(first);
struct ETCP_CONN *second = etcp_connection_create(inst, "second indexed", 0); CHECK(second);
struct ETCP_CONN *first = etcp_connection_create(inst, "first indexed"); CHECK(first);
struct ETCP_CONN *second = etcp_connection_create(inst, "second indexed"); CHECK(second);
struct ll_entry *entry = first->conn_queue_entry, *other = second->conn_queue_entry;
first->peer_node_id = second->peer_node_id = 1;
size_t allocated = u_get_allocated_count();
@@ -344,7 +344,7 @@ int main(void) {
inst.connections = queue_new(inst.ua,16,0,8,"test_connections");
for (int scenario=0; scenario<4; scenario++) {
deleted = victim_called = 0; release_on_delete = scenario == 0;
struct ETCP_CONN* c = etcp_connection_create(&inst,"lifecycle", 0); CHECK(c);
struct ETCP_CONN* c = etcp_connection_create(&inst,"lifecycle"); CHECK(c);
etcp_conn_add_cbk(c,on_delete,NULL,ETCP_CBK_EVENT_DELETE);
if (scenario < 2) CHECK(etcp_conn_ref_take(c) == 0);
if (scenario == 2) {
+1 -1
View File
@@ -89,7 +89,7 @@ static void create(struct fixture* f, int device, int supernode) {
topo_node_sqlite_update_rtt(db, node->node_id, (uint16_t)(i + 1));
/* История нижнего класса не должна обходить суперузлы. */
if (i >= 3) assert(topo_node_sqlite_set_connected(db, "42", node->node_id, 1) == 0);
struct ETCP_CONN* conn = f->conns[i] = etcp_connection_create(f->inst, "connect_fixture", 0); assert(conn);
struct ETCP_CONN* conn = f->conns[i] = etcp_connection_create(f->inst, "connect_fixture"); assert(conn);
conn->peer_node_id = node->node_id;
assert(sc_init_ctx(&conn->crypto_ctx, &f->inst->my_keys) == SC_OK);
assert(sc_set_peer_public_key(&conn->crypto_ctx, node->public_key, SC_PEER_PUBKEY_BIN) == SC_OK);
+1 -1
View File
@@ -32,7 +32,7 @@ int main(void) {
test_window(); utun_instance_set_tun_init_enabled(0);
struct UASYNC *ua = uasync_create(); CHECK(ua);
struct UTUN_INSTANCE *inst = utun_instance_create_from_str(ua, "[global]\nauto_sockets=no\n"); CHECK(inst);
struct ETCP_CONN *a = etcp_connection_create(inst, "stats-a", 0), *b = etcp_connection_create(inst, "stats-b", 0); CHECK(a && b);
struct ETCP_CONN *a = etcp_connection_create(inst, "stats-a"), *b = etcp_connection_create(inst, "stats-b"); CHECK(a && b);
queue_set_callback(a->input_send_q, NULL, NULL); queue_set_callback(b->input_wait_ack, NULL, NULL);
packet(a, a->input_send_q, 1, 80); packet(b, b->input_wait_ack, 2, 120);
a->normalizer->data = memory_pool_alloc(inst->data_pool); CHECK(a->normalizer->data); a->normalizer->data_ptr = 10;