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
This commit is contained in:
1 parent
a34035f41f
commit
985ed5c4b1
18 files changed
+34
-24
No files matched your search
+4
-4
@@ -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);
|
||||
|
||||
// Additional debug info for first few bytes
|
||||
if (len >= 2) {
|
||||
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]);
|
||||
}
|
||||
// if (len >= 2) {
|
||||
// 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]);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
+6
-7
@@ -117,7 +117,7 @@ void* queue_data_new(size_t data_size) {
|
||||
entry->ref_count = 1; // Единственная ссылка - на сам элемент
|
||||
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);
|
||||
}
|
||||
@@ -133,7 +133,7 @@ void* queue_data_new_from_pool(struct memory_pool* pool) {
|
||||
entry->ref_count = 1; // Единственная ссылка - на сам элемент
|
||||
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);
|
||||
}
|
||||
@@ -143,7 +143,7 @@ void queue_data_free(void* 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->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) {
|
||||
if (!q) return;
|
||||
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "check_waiters: checking waiters, count=%d, bytes=%zu",
|
||||
q->count, q->total_bytes);
|
||||
// DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "check_waiters: checking waiters, count=%d, bytes=%zu", q->count, q->total_bytes);
|
||||
|
||||
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 - элемент просто находится в очереди
|
||||
|
||||
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);
|
||||
|
||||
@@ -398,7 +397,7 @@ int queue_remove_data(struct ll_queue* q, void* data) {
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -546,6 +546,11 @@ static void etcp_connections_read_callback(int fd, void* arg) {
|
||||
char buf[128];
|
||||
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);
|
||||
// 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 если существующее подключение
|
||||
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 совпал а ключи разные.
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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));
|
||||
|
||||
// Check if there's any packet in output queue
|
||||
void* data = queue_data_get(conn->output_queue);
|
||||
if (data) {
|
||||
struct ETCP_FRAGMENT* pkt = queue_data_get(conn->output_queue);
|
||||
if (pkt) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check_packet_received: Found packet in output queue");
|
||||
|
||||
// В новом API размер данных нужно получать из структуры
|
||||
struct ll_entry* entry = (struct ll_entry*)data - 1;
|
||||
size_t size = entry->size;
|
||||
|
||||
|
||||
// ETCP_FRAGMENT содержит ll_entry в начале, данные в pkt_data
|
||||
size_t size = pkt->ll.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: First byte received=%02X, expected=%02X",
|
||||
((uint8_t*)data)[0], test_packet_data[0]);
|
||||
|
||||
if (size == PACKET_SIZE && memcmp(data, test_packet_data, PACKET_SIZE) == 0) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "check_packet_received: First byte received=%02X, expected=%02X",
|
||||
data[0], test_packet_data[0]);
|
||||
|
||||
// Проверяем только данные (первые PACKET_SIZE байт), размер может включать ETCP заголовки
|
||||
if (size >= PACKET_SIZE && memcmp(data, test_packet_data, PACKET_SIZE) == 0) {
|
||||
packet_received = 1;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "check_packet_received: SUCCESS - Packet received in server output queue (%zu bytes), data matches", size);
|
||||
} 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);
|
||||
}
|
||||
queue_data_free(data);
|
||||
|
||||
// Освобождаем ETCP_FRAGMENT и данные
|
||||
if (pkt->pkt_data) {
|
||||
memory_pool_free(conn->instance->data_pool, pkt->pkt_data);
|
||||
}
|
||||
queue_data_free(pkt);
|
||||
} else {
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "check_packet_received: No packet found in output queue");
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user