Adapt encrypted session and window fixtures to compact attempt fields

This commit is contained in:
evgeny committed 2026-10-23 19:20:49 +02:00
1 parent ccbd214c97
commit 0987d9dd04
2 files changed
+15 -14

No files matched your search

+7 -6
View File
@@ -43,7 +43,8 @@ static void capture_dump(int level, const char* category, const char* message) {
// ACK/payload должны корректно декодировать все 32 бита, включая границу знакового int.
static void debug_sequence_boundaries(void) {
const uint32_t values[] = {0, 1, 0x7f000000, 0x7fffffff, 0x80000000, 0xff000000, UINT32_MAX};
struct ETCP_DGRAM* pkt = u_calloc(1, sizeof(*pkt) + ETCP_PAYLOAD_HEADER_SIZE); CHECK(pkt);
unsigned capacity = ETCP_ACK_BASE_SIZE > ETCP_PAYLOAD_HEADER_SIZE ? ETCP_ACK_BASE_SIZE : ETCP_PAYLOAD_HEADER_SIZE;
struct ETCP_DGRAM* pkt = u_calloc(1, sizeof(*pkt) + capacity); CHECK(pkt);
debug_level_t saved = g_debug_config.category_levels[DEBUG_CATEGORY_DUMP];
int console = g_debug_config.console_enabled;
debug_set_category_level(DEBUG_CATEGORY_DUMP, DEBUG_LEVEL_DEBUG);
@@ -51,19 +52,18 @@ static void debug_sequence_boundaries(void) {
debug_set_log_hook(capture_dump);
for (unsigned i = 0; i < sizeof(values) / sizeof(values[0]); i++) {
for (int ack = 0; ack < 2; ack++) {
memset(pkt->data, 0, ETCP_PAYLOAD_HEADER_SIZE);
memset(pkt->data, 0, capacity);
pkt->data[0] = ack ? ETCP_SECTION_ACK : ETCP_SECTION_PAYLOAD;
pkt->data_len = ack ? ETCP_ACK_BASE_SIZE : ETCP_PAYLOAD_HEADER_SIZE;
for (int j = 0; j < 4; j++) pkt->data[1 + ack + j] = (uint8_t)(values[i] >> (8 * j));
const uint64_t attempt_id = UINT64_C(0xfedcba9876543210);
if (!ack) for (unsigned j = 0; j < 8; j++) pkt->data[5+j] = (uint8_t)(attempt_id >> (8*j));
const uint16_t attempt_no = UINT16_MAX;
if (!ack) for (unsigned j = 0; j < 2; j++) pkt->data[5+j] = (uint8_t)(attempt_no >> (8*j));
if (ack) pkt->data[6] = pkt->data[7] = 255;
dump_count = 0; dump_message[0] = 0;
etcp_dump_pkt_sections(pkt, NULL, 0);
char expected[80];
if (ack) snprintf(expected, sizeof(expected), " ack=%u/0 dup=65535", values[i]);
else snprintf(expected, sizeof(expected), " payload=0(seq=%u attempt=%llu)",
values[i], (unsigned long long)attempt_id);
else snprintf(expected, sizeof(expected), " payload=0(seq=%u attempt=%u)", values[i], attempt_no);
CHECK(dump_count == 1 && strstr(dump_message, expected));
}
}
@@ -386,6 +386,7 @@ static void receive_window_case(int wrap) {
struct ETCP_DGRAM* p = memory_pool_alloc(ep[0].inst.pkt_pool); CHECK(p);
p->link = &ep[0].links[0]; p->data_len = etcp_ack_section_size(!cumulative);
memset(p->data, 0, p->data_len); p->data[0] = ETCP_SECTION_ACK; p->data[1] = !cumulative;
if (!cumulative) p->data[ETCP_ACK_BASE_SIZE+4] = 1;
uint32_t ack = till + cumulative, selective = next - 1;
for (int i = 0; i < 4; i++) { p->data[2+i] = ack >> (8*i); p->data[8+i] = selective >> (8*i); }
etcp_conn_input(p); uasync_poll(ua, 0);
+8 -8
View File
@@ -238,7 +238,7 @@ static void boundaries_ack_burst(void) {
struct INFLIGHT_PACKET* waiting = enqueue(1); CHECK(!request() && a->cwnd_limited);
struct ACK_PACKET* confirmation = (struct ACK_PACKET*)queue_entry_new_from_pool(inst.ack_pool); CHECK(confirmation);
confirmation->seq = 777;
confirmation->attempt_id = 777;
confirmation->attempt_id = etcp_tx_attempt_id(777, 1);
CHECK(queue_data_put_with_index(a->ack_q, &confirmation->ll) == 0);
pkt = request(); CHECK(pkt && pkt->data[0] == ETCP_SECTION_ACK && pkt->data[1] == 1);
CHECK(waiting == (struct INFLIGHT_PACKET*)conn->input_send_q->head && a->inflight_bytes == 8192);
@@ -462,8 +462,8 @@ static void attempt_memory_limits(void) {
etcp_tx_ack(a, old.seq, old.attempt_id, UINT32_MAX, 0, 0);
CHECK(etcp_loadbalancer_select_link(conn, 1, NULL) == a);
CHECK(conn->active_attempts == 2 * MAX_INFLIGHT_SIZE - 1);
for (unsigned i = 0; i < MAX_INFLIGHT_SIZE; i++) CHECK(etcp_tx_queue_ack(a, i+1, i+1) == 0);
CHECK(etcp_tx_queue_ack(a, MAX_INFLIGHT_SIZE+1, MAX_INFLIGHT_SIZE+1) < 0);
for (unsigned i = 0; i < MAX_INFLIGHT_SIZE; i++) CHECK(etcp_tx_queue_ack(a, i+1, etcp_tx_attempt_id(i+1, 1)) == 0);
CHECK(etcp_tx_queue_ack(a, MAX_INFLIGHT_SIZE+1, etcp_tx_attempt_id(MAX_INFLIGHT_SIZE+1, 1)) < 0);
CHECK(a->ack_q->count == MAX_INFLIGHT_SIZE);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "Attempt limits: physical=%u path=%d ACK=%d ready_seq=%u",
conn->active_attempts, a->attempts->count, a->ack_q->count, pending->seq);
@@ -518,7 +518,7 @@ static void ack_without_data_pacing(void) {
uint64_t load = a->shaper_load_time_tb, fraction = a->shaper_sub_nanotime;
struct ACK_PACKET* confirmation = (struct ACK_PACKET*)queue_entry_new_from_pool(inst.ack_pool); CHECK(confirmation);
confirmation->seq = 777;
confirmation->attempt_id = 777;
confirmation->attempt_id = etcp_tx_attempt_id(777, 1);
CHECK(queue_data_put_with_index(a->ack_q, &confirmation->ll) == 0);
enqueue(100); uasync_drain_immediate(ua);
CHECK(sends == 1 && conn->input_send_q->count == 1 && !a->ack_q->count);
@@ -606,7 +606,7 @@ static void receive_fragment(struct ETCP_LINK* link, uint32_t seq, uint64_t id)
pkt->link = link; pkt->data_len = ETCP_PAYLOAD_HEADER_SIZE + 1;
memset(pkt->data, 0, pkt->data_len); pkt->data[0] = ETCP_SECTION_PAYLOAD;
for (unsigned i = 0; i < 4; i++) pkt->data[1 + i] = seq >> (8 * i);
for (unsigned i = 0; i < 8; i++) pkt->data[5 + i] = id >> (8 * i);
for (unsigned i = 0; i < 2; i++) pkt->data[5 + i] = id >> (8 * i);
pkt->data[ETCP_PAYLOAD_HEADER_SIZE] = 0x5a;
etcp_conn_input(pkt);
}
@@ -839,7 +839,7 @@ static void receiver_point_truncated(void) {
struct ETCP_DGRAM* pkt = memory_pool_alloc(inst.pkt_pool); CHECK(pkt);
pkt->link = a; pkt->data_len = len; memset(pkt->data,0,size); pkt->data[0] = ETCP_SECTION_ACK; pkt->data[1] = 1;
for (unsigned i = 0; i < 4; i++) pkt->data[ETCP_ACK_BASE_SIZE+i] = seq >> (8*i);
for (unsigned i = 0; i < 8; i++) pkt->data[ETCP_ACK_BASE_SIZE+4+i] = id >> (8*i);
for (unsigned i = 0; i < 2; i++) pkt->data[ETCP_ACK_BASE_SIZE+4+i] = id >> (8*i);
pkt->data[ETCP_ACK_BASE_SIZE+ETCP_ACK_ENTRY_SIZE] = 1;
pkt->data[ETCP_ACK_BASE_SIZE+ETCP_ACK_ENTRY_SIZE+8] = 1;
etcp_conn_input(pkt);
@@ -903,12 +903,12 @@ static void confirm_test_session(void) {
static void normalizer_rx_oom(void) {
for (unsigned nth = 1; nth <= 2; nth++) {
setup(); CHECK(etcp_bind(&inst, 253, normalizer_receive) == 0);
uint64_t epoch = conn->reset_id, attempt_id = conn->next_attempt_id;
uint64_t epoch = conn->reset_id;
fail_rx_message_at = nth; receive_messages(1, 3);
CHECK(!fail_rx_message_at && received == nth-1 && conn->reset_id != epoch);
CHECK(conn->reinit_pending && conn->session_required && conn->session_timer && !conn->initialized);
CHECK(!conn->last_delivered_id && !conn->recv_q->count && !conn->output_queue->count && !a->ack_q->count);
CHECK(!conn->normalizer->recvpart && !conn->normalizer->output->count && conn->next_attempt_id == attempt_id);
CHECK(!conn->normalizer->recvpart && !conn->normalizer->output->count && !conn->active_attempts);
CHECK(a->link_status && b->link_status && conn->links_up);
confirm_test_session(); receive_messages(1, 1);
CHECK(received == nth && received_values[nth-1] == 0x20 && !conn->reinit_pending);