|
|
|
|
@ -6,6 +6,7 @@
|
|
|
|
|
#include <time.h> |
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#include "test_net.h" |
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
#include <windows.h> |
|
|
|
|
#include <direct.h> |
|
|
|
|
@ -46,7 +47,6 @@ static char log_path[320];
|
|
|
|
|
static unsigned int g_seed; |
|
|
|
|
static char temp_dir[] = "/tmp/utun_chatsync_XXXXXX"; |
|
|
|
|
static char config_a[256], config_b[256]; |
|
|
|
|
static int port_a_srv, port_b_srv; |
|
|
|
|
|
|
|
|
|
static int write_file(const char* path, const char* fmt, ...) { |
|
|
|
|
va_list ap; FILE* f = fopen(path, "w"); if (!f) return -1; |
|
|
|
|
@ -58,8 +58,6 @@ static char* get_pubkey(const char* path) {
|
|
|
|
|
} |
|
|
|
|
static int create_temp_configs(void) { |
|
|
|
|
if (test_mkdtemp(temp_dir) != 0) { return -1; } |
|
|
|
|
int base = 42000 + (getpid() % 15000); |
|
|
|
|
port_a_srv = base; port_b_srv = base + 1; |
|
|
|
|
snprintf(config_a, sizeof(config_a), "%s/a.conf", temp_dir); |
|
|
|
|
snprintf(config_b, sizeof(config_b), "%s/b.conf", temp_dir); |
|
|
|
|
char db_path[320]; |
|
|
|
|
@ -69,17 +67,17 @@ static int create_temp_configs(void) {
|
|
|
|
|
if (write_file(config_a, |
|
|
|
|
"[global]\nmy_node_id=0xAAAAAAAAAAAAAAAA\ntun_ip=10.200.0.1/24\ntun_ifname=tun200\n" |
|
|
|
|
"db_path=%s/db_a\ndb_sync_enabled=1\n\n" |
|
|
|
|
"[server: srv_a]\naddr=127.0.0.1:%d\ntype=public\n\n[allowed_keys]\nallow_all=1\n", |
|
|
|
|
temp_dir, port_a_srv) != 0) return -1; |
|
|
|
|
"[server: srv_a]\naddr=127.0.0.1:0\ntype=public\n\n[allowed_keys]\nallow_all=1\n", |
|
|
|
|
temp_dir) != 0) return -1; |
|
|
|
|
if (config_ensure_keys_and_node_id(config_a) != 0) return -1; |
|
|
|
|
char* pub_a = get_pubkey(config_a); if (!pub_a) return -1; |
|
|
|
|
if (write_file(config_b, |
|
|
|
|
"[global]\nmy_node_id=0xBBBBBBBBBBBBBBBB\ntun_ip=10.200.0.2/24\ntun_ifname=tun201\n" |
|
|
|
|
"db_path=%s/db_b\ndb_sync_enabled=1\n\n" |
|
|
|
|
"[server: srv_b]\naddr=127.0.0.1:%d\ntype=public\n\n" |
|
|
|
|
"[client: to_a]\nkeepalive=1\npeer_public_key=%s\nlink=srv_b:127.0.0.1:%d\n\n" |
|
|
|
|
"[server: srv_b]\naddr=127.0.0.1:0\ntype=public\n\n" |
|
|
|
|
"[client: to_a]\nkeepalive=1\npeer_public_key=%s\nlink=srv_b:127.0.0.1:0\n\n" |
|
|
|
|
"[allowed_keys]\nallow_all=1\n", |
|
|
|
|
temp_dir, port_b_srv, pub_a, port_a_srv) != 0) { free(pub_a); return -1; } |
|
|
|
|
temp_dir, pub_a) != 0) { free(pub_a); return -1; } |
|
|
|
|
free(pub_a); |
|
|
|
|
if (config_ensure_keys_and_node_id(config_b) != 0) return -1; |
|
|
|
|
return 0; |
|
|
|
|
@ -162,6 +160,7 @@ int main(void) {
|
|
|
|
|
inst_a = utun_instance_create(ua, config_a); |
|
|
|
|
inst_b = utun_instance_create(ua, config_b); |
|
|
|
|
if (!inst_a || !inst_b) { DEBUG_ERROR(DEBUG_CATEGORY_DEBUG, "instance_create"); cleanup_temp_configs(); return 1; } |
|
|
|
|
test_etcp_set_peer(inst_b, "to_a", inst_a, "srv_a"); |
|
|
|
|
if (utun_instance_init(inst_a) != 0 || utun_instance_init(inst_b) != 0) { |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_DEBUG, "instance_init"); cleanup_temp_configs(); return 1; |
|
|
|
|
} |
|
|
|
|
|