You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

107 lines
3.3 KiB

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include "../src/etcp.h"
#include "../src/etcp_connections.h"
#include "../src/config_parser.h"
#include "../src/utun_instance.h"
#include "../src/routing.h"
#include "../src/tun_if.h"
#include "../src/secure_channel.h"
#include "../lib/u_async.h"
#define TEST_TIMEOUT_MS 5000
int main() {
printf("=== ETCP Real Instance Test ===\n\n");
// Create config file
FILE* conf = fopen("test_real.conf", "w");
fprintf(conf, "[global]\n");
fprintf(conf, "my_node_id=0x1111111111111111\n");
fprintf(conf, "my_private_key=1313912e5d34768983b0e06530a48c77816d228a5b5605e1ab3dc443d107a3dc\n");
fprintf(conf, "my_public_key=dde6cec8a9023339a758f60883ef41534d24a1ffdc09bbb787a5c24ddfd891e3092461835a97d37944c681fc6b2c1f5acde8ad192f7d2cdc9920aa0d3ff78e99\n");
fprintf(conf, "tun_ip=10.99.0.1/24\n");
fprintf(conf, "tun_ifname=tun99\n");
fprintf(conf, "\n[server: test]\n");
fprintf(conf, "addr=127.0.0.1:9001\n");
fprintf(conf, "type=public\n");
fclose(conf);
// Create instance
printf("Creating UTUN instance...\n");
struct UASYNC* ua = uasync_create();
struct UTUN_INSTANCE* instance = utun_instance_create(ua, "test_real.conf", NULL);
if (!instance) {
printf("Failed to create instance\n");
return 1;
}
printf("Instance created (node_id=%llx)\n", (unsigned long long)instance->node_id);
// Initialize
printf("Initializing instance...\n");
if (utun_instance_init(instance) < 0) {
printf("Failed to initialize instance\n");
utun_instance_destroy(instance);
return 1;
}
// Register sockets
printf("Registering sockets...\n");
if (utun_instance_register_sockets(instance) < 0) {
printf("Failed to register sockets\n");
utun_instance_destroy(instance);
return 1;
}
// Initialize connections
printf("Initializing connections...\n");
if (init_connections(instance) < 0) {
printf("Failed to initialize connections\n");
utun_instance_destroy(instance);
return 1;
}
printf("Instance ready\n");
// Monitor for 5 seconds
printf("\nMonitoring connections for %d seconds...\n", TEST_TIMEOUT_MS/1000);
int elapsed = 0;
while (elapsed < TEST_TIMEOUT_MS) {
// Dump connection state
struct ETCP_CONN* conn = instance->connections;
while (conn) {
printf("Connection to node %llx:\n", (unsigned long long)conn->peer_node_id);
struct ETCP_LINK* link = conn->links;
while (link) {
printf(" Link: initialized=%d, is_server=%d, init_timer=%s, timeout=%dms, retry=%d\n",
link->initialized, link->is_server,
link->init_timer ? "active" : "null",
link->init_timeout, link->init_retry_count);
link = link->next;
}
conn = conn->next;
}
uasync_poll(ua, 100);
elapsed += 100;
}
// Cleanup
printf("Cleaning up...\n");
unlink("test_real.conf");
instance->running = 0;
utun_instance_destroy(instance);
printf("\n=== Test completed ===\n");
return 0;
}