Verify every NCD control ID byte and clarify new-socket scope

This commit is contained in:
evgeny committed 2026-10-24 20:27:57 +02:00
1 parent db0d7a1f47
commit b7d74d8f87
2 files changed
+6 -2

No files matched your search

+5 -1
View File
@@ -37,6 +37,7 @@ static void owner_cb(struct NODE_CONN_DIRECT* handle, enum ncd_event event, void
static void setup(void) {
memset(&inst, 0, sizeof(inst)); memset(&cfg, 0, sizeof(cfg)); memset(&sock, 0, sizeof(sock));
deleted = closed = down = 0; release_on_down = 0;
inst.node_id = UINT64_C(0x0123456789abcdef);
inst.ua = uasync_create(); CHECK(inst.ua); inst.config = &cfg;
cfg.global.bbr_max_cwnd = 100000; cfg.global.keepalive_interval = 200; cfg.global.keepalive_timeout = 2000;
inst.connections = queue_new(inst.ua, 16, 0, 8, "server lifecycle"); CHECK(inst.connections);
@@ -87,6 +88,7 @@ static void receive_control(struct ETCP_CONN* conn, uint8_t subcmd) {
struct ncd_control_msg msg = { ETCP_ID_NCD_CONTROL, subcmd, conn->peer_node_id };
struct ll_entry* entry = ll_alloc_lldgram(sizeof(msg)); CHECK(entry);
memcpy(entry->dgram, &msg, sizeof(msg)); entry->len = sizeof(msg);
for (unsigned i = 0; i < 8; i++) entry->dgram[2 + i] = (uint8_t)(conn->peer_node_id >> (8 * i));
inst.api_bindings.callbacks[ETCP_ID_NCD_CONTROL](conn, entry);
uasync_drain_immediate(inst.ua);
}
@@ -303,13 +305,15 @@ static void check_peer_wake_reordered(void) {
/* Мягкое закрытие работает без NCD entry; KEEP_ALIVE сохраняет транспорт дольше прежних 5 секунд. */
static void check_graceful(void) {
setup(); struct ETCP_CONN* conn = ready_conn(0);
conn->peer_node_id = UINT64_C(0xfedcba9876543210);
receive_control(conn, NCD_SUBCMD_CLOSE); CHECK(deleted == 1 && !inst.connections->count); teardown();
setup(); conn = ready_conn(0); struct NODE_CONN_DIRECT* handle = NULL;
CHECK(node_conn_direct_open(&inst, 42, NULL, NULL, &handle, NULL) == NCD_REUSED);
receive_control(conn, NCD_SUBCMD_CLOSE); CHECK(!deleted && !conn->fin_wait);
CHECK(conn->send_input_q->count == 1);
struct ncd_control_msg* response = (void*)conn->send_input_q->head->dgram;
CHECK(response->subcmd == NCD_SUBCMD_KEEP_ALIVE);
CHECK(conn->send_input_q->head->len == 10 && response->cmd == ETCP_ID_NCD_CONTROL && response->subcmd == NCD_SUBCMD_KEEP_ALIVE);
for (unsigned i = 0; i < 8; i++) CHECK(conn->send_input_q->head->dgram[2 + i] == (uint8_t)(inst.node_id >> (8 * i)));
node_conn_direct_close(handle); CHECK(conn->fin_wait);
receive_control(conn, NCD_SUBCMD_KEEP_ALIVE); CHECK(!conn->fin_wait);
test_clock_run_for(inst.ua, 70000); CHECK(!deleted && conn->links_up);