Browse Source

Fix ETCP test: server connection registration and packet handling

- etcp_connections.c: Add incoming server connections to instance->connections list
- test_etcp_simple_traffic.c: Fix ETCP_FRAGMENT handling in check_packet_received()
- test_etcp_simple_traffic.c: Fix packet size check (ETCP adds headers to payload)
- Reduced debug verbosity in ll_queue.c and debug_config.c
nodeinfo-routing-update
Evgeny 2 months ago
parent
commit
985ed5c4b1
  1. 8
      lib/debug_config.c
  2. 13
      lib/ll_queue.c
  3. 5
      src/etcp_connections.c
  4. BIN
      tests/test_config_debug
  5. BIN
      tests/test_crypto
  6. BIN
      tests/test_debug_categories
  7. BIN
      tests/test_ecc_encrypt
  8. BIN
      tests/test_etcp_crypto
  9. BIN
      tests/test_etcp_minimal
  10. BIN
      tests/test_etcp_simple_traffic
  11. 32
      tests/test_etcp_simple_traffic.c
  12. BIN
      tests/test_etcp_two_instances
  13. BIN
      tests/test_intensive_memory_pool
  14. BIN
      tests/test_ll_queue
  15. BIN
      tests/test_memory_pool_and_config
  16. BIN
      tests/test_packet_dump
  17. BIN
      tests/test_u_async_comprehensive
  18. BIN
      tests/test_u_async_performance

8
lib/debug_config.c

@ -38,10 +38,10 @@ void log_dump(const char* prefix, const uint8_t* data, size_t len) {
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "%s: len=%zu hex=%s", prefix, len, hex_buf); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "%s: len=%zu hex=%s", prefix, len, hex_buf);
// Additional debug info for first few bytes // Additional debug info for first few bytes
if (len >= 2) { // if (len >= 2) {
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "%s: first_bytes=%02x%02x last_bytes=%02x%02x", // DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "%s: first_bytes=%02x%02x last_bytes=%02x%02x",
prefix, data[0], data[1], data[len-2], data[len-1]); // prefix, data[0], data[1], data[len-2], data[len-1]);
} // }
} }

13
lib/ll_queue.c

@ -117,7 +117,7 @@ void* queue_data_new(size_t data_size) {
entry->ref_count = 1; // Единственная ссылка - на сам элемент entry->ref_count = 1; // Единственная ссылка - на сам элемент
entry->pool = NULL; // Выделено через malloc entry->pool = NULL; // Выделено через malloc
DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "queue_data_new: created entry %p, size=%zu", entry, data_size); // DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "queue_data_new: created entry %p, size=%zu", entry, data_size);
return (void*)(entry + xxx); return (void*)(entry + xxx);
} }
@ -133,7 +133,7 @@ void* queue_data_new_from_pool(struct memory_pool* pool) {
entry->ref_count = 1; // Единственная ссылка - на сам элемент entry->ref_count = 1; // Единственная ссылка - на сам элемент
entry->pool = pool; // Выделено из пула entry->pool = pool; // Выделено из пула
DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "queue_data_new_from_pool: created entry %p from pool %p", entry, pool); // DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "queue_data_new_from_pool: created entry %p from pool %p", entry, pool);
return (void*)(entry + xxx); return (void*)(entry + xxx);
} }
@ -143,7 +143,7 @@ void queue_data_free(void* data) {
struct ll_entry* entry = data_to_entry(data); struct ll_entry* entry = data_to_entry(data);
DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "queue_data_free: freeing entry %p, ref_count=%d", entry, entry->ref_count); // DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "queue_data_free: freeing entry %p, ref_count=%d", entry, entry->ref_count);
if (--entry->ref_count <= 0) { if (--entry->ref_count <= 0) {
if (entry->pool) { if (entry->pool) {
@ -185,8 +185,7 @@ static void remove_from_hash(struct ll_queue* q, struct ll_entry* entry) {
static void check_waiters(struct ll_queue* q) { static void check_waiters(struct ll_queue* q) {
if (!q) return; if (!q) return;
DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "check_waiters: checking waiters, count=%d, bytes=%zu", // DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "check_waiters: checking waiters, count=%d, bytes=%zu", q->count, q->total_bytes);
q->count, q->total_bytes);
struct queue_waiter* waiter = &q->waiter; struct queue_waiter* waiter = &q->waiter;
@ -230,7 +229,7 @@ int queue_data_put(struct ll_queue* q, void* data, uint32_t id) {
// ВАЖНО: НЕ увеличиваем ref_count - элемент просто находится в очереди // ВАЖНО: НЕ увеличиваем ref_count - элемент просто находится в очереди
size_t send_q_bytes = queue_total_bytes(q); size_t send_q_bytes = queue_total_bytes(q);
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "qqqq check total bytes: new_q_len=%d element_size:%d", send_q_bytes, entry->size); // DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check total bytes: new_q_len=%d element_size:%d", send_q_bytes, entry->size);
add_to_hash(q, entry); add_to_hash(q, entry);
@ -398,7 +397,7 @@ int queue_remove_data(struct ll_queue* q, void* data) {
remove_from_hash(q, entry); remove_from_hash(q, entry);
DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "queue_remove_data: removed entry %p (id=%u), count=%d", entry, entry->id, q->count); // DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "queue_remove_data: removed entry %p (id=%u), count=%d", entry, entry->id, q->count);
return 0; return 0;
} }

5
src/etcp_connections.c

@ -546,6 +546,11 @@ static void etcp_connections_read_callback(int fd, void* arg) {
char buf[128]; char buf[128];
addr_to_string(&addr, buf, sizeof(buf)); addr_to_string(&addr, buf, sizeof(buf));
DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "New connection from %s peer_id=%ld etcp=%p", buf, peer_id, conn); DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "New connection from %s peer_id=%ld etcp=%p", buf, peer_id, conn);
// Add connection to instance list
conn->next = e_sock->instance->connections;
e_sock->instance->connections = conn;
e_sock->instance->connections_count++;
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "Added incoming connection %p to instance, total count: %d", conn, e_sock->instance->connections_count);
} }
else {// check keys если существующее подключение else {// check keys если существующее подключение
if (memcmp(conn->crypto_ctx.peer_public_key, sc.peer_public_key, SC_PUBKEY_SIZE)) { errorcode=5; DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "etcp_connections_read_callback: peer key mismatch for node %llu", (unsigned long long)peer_id); goto ec_fr; }// коллизия - peer id совпал а ключи разные. if (memcmp(conn->crypto_ctx.peer_public_key, sc.peer_public_key, SC_PUBKEY_SIZE)) { errorcode=5; DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "etcp_connections_read_callback: peer key mismatch for node %llu", (unsigned long long)peer_id); goto ec_fr; }// коллизия - peer id совпал а ключи разные.

BIN
tests/test_config_debug

Binary file not shown.

BIN
tests/test_crypto

Binary file not shown.

BIN
tests/test_debug_categories

Binary file not shown.

BIN
tests/test_ecc_encrypt

Binary file not shown.

BIN
tests/test_etcp_crypto

Binary file not shown.

BIN
tests/test_etcp_minimal

Binary file not shown.

BIN
tests/test_etcp_simple_traffic

Binary file not shown.

32
tests/test_etcp_simple_traffic.c

@ -155,25 +155,31 @@ static void check_packet_received(void) {
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check_packet_received: Server output_queue count: %d", queue_entry_count(conn->output_queue)); DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check_packet_received: Server output_queue count: %d", queue_entry_count(conn->output_queue));
// Check if there's any packet in output queue // Check if there's any packet in output queue
void* data = queue_data_get(conn->output_queue); struct ETCP_FRAGMENT* pkt = queue_data_get(conn->output_queue);
if (data) { if (pkt) {
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check_packet_received: Found packet in output queue"); DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check_packet_received: Found packet in output queue");
// В новом API размер данных нужно получать из структуры // ETCP_FRAGMENT содержит ll_entry в начале, данные в pkt_data
struct ll_entry* entry = (struct ll_entry*)data - 1; size_t size = pkt->ll.size;
size_t size = entry->size; uint8_t* data = pkt->pkt_data;
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check_packet_received: Packet size=%zu, expected=%d", size, PACKET_SIZE); DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check_packet_received: Packet size=%zu, expected=%d", size, PACKET_SIZE);
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check_packet_received: First byte received=%02X, expected=%02X", DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check_packet_received: First byte received=%02X, expected=%02X",
((uint8_t*)data)[0], test_packet_data[0]); data[0], test_packet_data[0]);
if (size == PACKET_SIZE && memcmp(data, test_packet_data, PACKET_SIZE) == 0) { // Проверяем только данные (первые PACKET_SIZE байт), размер может включать ETCP заголовки
if (size >= PACKET_SIZE && memcmp(data, test_packet_data, PACKET_SIZE) == 0) {
packet_received = 1; packet_received = 1;
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "check_packet_received: SUCCESS - Packet received in server output queue (%zu bytes), data matches", size); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "check_packet_received: SUCCESS - Packet received in server output queue (%zu bytes), data matches", size);
} else { } else {
DEBUG_WARN(DEBUG_CATEGORY_ETCP, "check_packet_received: Packet received but size mismatch or data differs (expected %d, got %zu)", PACKET_SIZE, size); DEBUG_WARN(DEBUG_CATEGORY_ETCP, "check_packet_received: Packet received but data differs (expected %d bytes, got %zu)", PACKET_SIZE, size);
}
// Освобождаем ETCP_FRAGMENT и данные
if (pkt->pkt_data) {
memory_pool_free(conn->instance->data_pool, pkt->pkt_data);
} }
queue_data_free(data); queue_data_free(pkt);
} else { } else {
DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "check_packet_received: No packet found in output queue"); DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "check_packet_received: No packet found in output queue");
} }

BIN
tests/test_etcp_two_instances

Binary file not shown.

BIN
tests/test_intensive_memory_pool

Binary file not shown.

BIN
tests/test_ll_queue

Binary file not shown.

BIN
tests/test_memory_pool_and_config

Binary file not shown.

BIN
tests/test_packet_dump

Binary file not shown.

BIN
tests/test_u_async_comprehensive

Binary file not shown.

BIN
tests/test_u_async_performance

Binary file not shown.
Loading…
Cancel
Save