tests: use bound endpoints for CM and database synchronization
This commit is contained in:
1 parent
101266d1a7
commit
e25d5cc220
2 files changed
+26
-23
No files matched your search
+11
-11
@@ -7,6 +7,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include "../lib/platform_compat.h"
|
||||
#include "test_utils.h"
|
||||
#include "test_net.h"
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <direct.h>
|
||||
@@ -58,7 +59,6 @@ static void reset_done_flags(void) { g_done_a = g_done_b = g_done_c = 0; }
|
||||
|
||||
static char temp_dir[] = "/tmp/utun_dbsync_XXXXXX";
|
||||
static char config_a[256], config_b[256], config_c[256];
|
||||
static int port_a_srv, port_b_srv, port_c_srv;
|
||||
static uint32_t ca_target, cb_target, cc_target;
|
||||
|
||||
static int write_file(const char* path, const char* fmt, ...) {
|
||||
@@ -76,8 +76,6 @@ static char* get_pubkey(const char* path) {
|
||||
|
||||
static int create_temp_configs(void) {
|
||||
if (test_mkdtemp(temp_dir) != 0) { fprintf(stderr, "mkdtemp failed\n"); return -1; }
|
||||
int base = 42000 + (getpid() % 15000);
|
||||
port_a_srv = base; port_b_srv = base + 1; port_c_srv = base + 2;
|
||||
snprintf(config_a, sizeof(config_a), "%s/a.conf", temp_dir);
|
||||
snprintf(config_b, sizeof(config_b), "%s/b.conf", temp_dir);
|
||||
snprintf(config_c, sizeof(config_c), "%s/c.conf", temp_dir);
|
||||
@@ -89,24 +87,24 @@ static int create_temp_configs(void) {
|
||||
write_file(config_a,
|
||||
"[global]\nmy_node_id=0xAAAAAAAAAAAAAAAA\ntun_ip=10.200.0.1/24\n"
|
||||
"tun_ifname=tun200\nkeepalive_adaptive=0\ndb_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);
|
||||
"[server: srv_a]\naddr=127.0.0.1:0\ntype=public\n\n"
|
||||
"[allowed_keys]\nallow_all=1\n", temp_dir);
|
||||
config_ensure_keys_and_node_id(config_a);
|
||||
char* pub_a = get_pubkey(config_a); if (!pub_a) { fprintf(stderr, "pub_a fail\n"); return -1; }
|
||||
|
||||
write_file(config_b,
|
||||
"[global]\nmy_node_id=0xBBBBBBBBBBBBBBBB\ntun_ip=10.200.0.2/24\n"
|
||||
"tun_ifname=tun201\nkeepalive_adaptive=0\ndb_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"
|
||||
"[allowed_keys]\nallow_all=1\n", temp_dir, port_b_srv, pub_a, port_a_srv);
|
||||
"[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, pub_a);
|
||||
|
||||
write_file(config_c,
|
||||
"[global]\nmy_node_id=0xCCCCCCCCCCCCCCCC\ntun_ip=10.200.0.3/24\n"
|
||||
"tun_ifname=tun202\nkeepalive_adaptive=0\ndb_path=%s/db_c\ndb_sync_enabled=1\n\n"
|
||||
"[server: srv_c]\naddr=127.0.0.1:%d\ntype=public\n\n"
|
||||
"[client: to_a]\nkeepalive=1\npeer_public_key=%s\nlink=srv_c:127.0.0.1:%d\n\n"
|
||||
"[allowed_keys]\nallow_all=1\n", temp_dir, port_c_srv, pub_a, port_a_srv);
|
||||
"[server: srv_c]\naddr=127.0.0.1:0\ntype=public\n\n"
|
||||
"[client: to_a]\nkeepalive=1\npeer_public_key=%s\nlink=srv_c:127.0.0.1:0\n\n"
|
||||
"[allowed_keys]\nallow_all=1\n", temp_dir, pub_a);
|
||||
free(pub_a);
|
||||
config_ensure_keys_and_node_id(config_b);
|
||||
config_ensure_keys_and_node_id(config_c);
|
||||
@@ -231,6 +229,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) test_etcp_set_peer(inst_b, "to_a", inst_a, "srv_a");
|
||||
if (!inst_a || !inst_b || utun_instance_init(inst_a) != 0 || utun_instance_init(inst_b) != 0)
|
||||
{ fprintf(stderr, "init fail\n"); cleanup_temp_configs(); return 1; }
|
||||
seed_members(inst_a, &inst_b, 1);
|
||||
@@ -378,6 +377,7 @@ int main(void) {
|
||||
reset_done_flags();
|
||||
remove_si(&si_a); remove_si(&si_b);
|
||||
inst_c = utun_instance_create(ua, config_c);
|
||||
if (inst_c) test_etcp_set_peer(inst_c, "to_a", inst_a, "srv_a");
|
||||
if (!inst_c || utun_instance_init(inst_c) != 0) { fprintf(stderr, "inst_c fail\n"); test_phase = 2; goto done; }
|
||||
{ struct UTUN_INSTANCE* p_ab[2] = { inst_b, inst_c };
|
||||
struct UTUN_INSTANCE* p_ac[2] = { inst_a, inst_c };
|
||||
|
||||
Reference in new issue
Block a user