4 changed files with 160 additions and 1 deletions
@ -0,0 +1,132 @@ |
|||||||
|
// test_etcp_2instance.c - Simplified 2-instance ETCP connection test
|
||||||
|
#include "etcp.h" |
||||||
|
#include "etcp_connections.h" |
||||||
|
#include "secure_channel.h" |
||||||
|
#include "ll_queue.h" |
||||||
|
#include "memory_pool.h" |
||||||
|
#include "u_async.h" |
||||||
|
#include <stdio.h> |
||||||
|
#include <string.h> |
||||||
|
#include <stdlib.h> |
||||||
|
#include <assert.h> |
||||||
|
#include <sys/socket.h> |
||||||
|
#include <netinet/in.h> |
||||||
|
#include <arpa/inet.h> |
||||||
|
#include <unistd.h> |
||||||
|
#include <fcntl.h> |
||||||
|
#include <errno.h> |
||||||
|
|
||||||
|
#define ALICE_PORT 5001 |
||||||
|
#define BOB_PORT 5002 |
||||||
|
|
||||||
|
typedef struct { |
||||||
|
struct UTUN_INSTANCE* instance; |
||||||
|
struct ETCP_SOCKET* socket; |
||||||
|
const char* name; |
||||||
|
} test_instance_t; |
||||||
|
|
||||||
|
// Basic instance creation
|
||||||
|
static test_instance_t* create_test_instance(const char* name, uint64_t node_id, uint16_t port) { |
||||||
|
test_instance_t* test_inst = calloc(1, sizeof(test_instance_t)); |
||||||
|
assert(test_inst); |
||||||
|
|
||||||
|
test_inst->name = name; |
||||||
|
|
||||||
|
// Create uasync context
|
||||||
|
struct UASYNC* ua = uasync_create(); |
||||||
|
assert(ua); |
||||||
|
uasync_init_instance(ua); |
||||||
|
|
||||||
|
// Create minimal instance
|
||||||
|
struct UTUN_INSTANCE* instance = calloc(1, sizeof(struct UTUN_INSTANCE)); |
||||||
|
assert(instance); |
||||||
|
instance->ua = ua; |
||||||
|
instance->node_id = node_id; |
||||||
|
instance->running = 1; |
||||||
|
|
||||||
|
// Use fixed keys for testing
|
||||||
|
memset(&instance->my_keys, 0, sizeof(instance->my_keys)); |
||||||
|
for (int i = 0; i < SC_PRIVKEY_SIZE; i++) { |
||||||
|
instance->my_keys.private_key[i] = (i < 16) ? 0xAA : 0xBB; |
||||||
|
instance->my_keys.public_key[i] = i ^ 0x55; |
||||||
|
} |
||||||
|
|
||||||
|
// Create ETCP connection
|
||||||
|
struct ETCP_CONN* conn = etcp_connection_create(instance); |
||||||
|
assert(conn); |
||||||
|
|
||||||
|
test_inst->instance = instance; |
||||||
|
|
||||||
|
printf("✓ Created instance '%s' (node_id: 0x%llx)\n",
|
||||||
|
name, (unsigned long long)node_id); |
||||||
|
|
||||||
|
return test_inst; |
||||||
|
} |
||||||
|
|
||||||
|
int main(void) { |
||||||
|
printf("=== ETCP 2-Instance Connection Test ===\n\n"); |
||||||
|
|
||||||
|
// Create instances
|
||||||
|
test_instance_t* alice = create_test_instance("Alice", 0x1111222233334444ULL, ALICE_PORT); |
||||||
|
test_instance_t* bob = create_test_instance("Bob", 0x5555666677778888ULL, BOB_PORT); |
||||||
|
|
||||||
|
printf("\n=== ETCP crypto initialization test ===\n"); |
||||||
|
|
||||||
|
// Test 1: Verify crypto contexts were initialized
|
||||||
|
assert(alice->instance->connections->crypto_ctx.session_ready == 0); // Not ready yet (no peer key)
|
||||||
|
assert(bob->instance->connections->crypto_ctx.session_ready == 0); // Not ready yet
|
||||||
|
printf("✓ Both instances have crypto contexts initialized (session not ready - no peer key)\n"); |
||||||
|
|
||||||
|
// Test 2: Verify ETCP structures
|
||||||
|
assert(alice->instance->connections != NULL); |
||||||
|
assert(bob->instance->connections != NULL); |
||||||
|
assert(alice->instance->connections->input_queue != NULL); |
||||||
|
assert(bob->instance->connections->input_queue != NULL); |
||||||
|
printf("✓ Both instances have queues created\n"); |
||||||
|
|
||||||
|
// Test 3: Statistics
|
||||||
|
size_t packets_sent = 0, packets_recv = 0; |
||||||
|
etcp_get_stats(alice->instance->connections, &packets_sent, &packets_recv, NULL, NULL); |
||||||
|
printf("✓ Alice stats - sent: %zu, recv: %zu\n", packets_sent, packets_recv); |
||||||
|
|
||||||
|
etcp_get_stats(bob->instance->connections, &packets_sent, &packets_recv, NULL, NULL); |
||||||
|
printf("✓ Bob stats - sent: %zu, recv: %zu\n", packets_sent, packets_recv); |
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
printf("\n=== Cleanup ===\n"); |
||||||
|
|
||||||
|
if (alice) { |
||||||
|
if (alice->instance) { |
||||||
|
if (alice->instance->connections) |
||||||
|
etcp_destroy(alice->instance->connections); |
||||||
|
if (alice->instance->ua) |
||||||
|
uasync_destroy(alice->instance->ua); |
||||||
|
free(alice->instance); |
||||||
|
} |
||||||
|
free(alice); |
||||||
|
printf("✓ Alice cleaned up\n"); |
||||||
|
} |
||||||
|
|
||||||
|
if (bob) { |
||||||
|
if (bob->instance) { |
||||||
|
if (bob->instance->connections) |
||||||
|
etcp_destroy(bob->instance->connections); |
||||||
|
if (bob->instance->ua) |
||||||
|
uasync_destroy(bob->instance->ua); |
||||||
|
free(bob->instance); |
||||||
|
} |
||||||
|
free(bob); |
||||||
|
printf("✓ Bob cleaned up\n"); |
||||||
|
} |
||||||
|
|
||||||
|
printf("\n"); |
||||||
|
printf("\033[32m ██████╗ █████╗ ███████╗███████╗███████╗\033[0m\n"); |
||||||
|
printf("\033[32m ██╔════╝ ██╔══██╗██╔════╝██╔════╝██╔════╝\033[0m\n"); |
||||||
|
printf("\033[32m ██║ ███╗███████║███████╗█████╗ ███████╗\033[0m\n"); |
||||||
|
printf("\033[32m ██║ ██║██╔══██║╚════██║██╔══╝ ╚════██║\033[0m\n"); |
||||||
|
printf("\033[32m ╚██████╔╝██║ ██║███████║███████╗███████║\033[0m\n"); |
||||||
|
printf("\033[32m ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝\033[0m\n"); |
||||||
|
printf("\n"); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
Loading…
Reference in new issue