|
|
|
|
@ -30,6 +30,7 @@
|
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#include "test_clock.h" |
|
|
|
|
#include "test_net.h" |
|
|
|
|
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
#include <windows.h> |
|
|
|
|
@ -78,9 +79,9 @@ static struct test_connection_loss loss_ab, loss_ac;
|
|
|
|
|
* Config generator |
|
|
|
|
* ================================================================ */ |
|
|
|
|
|
|
|
|
|
struct lnk { const char* local_srv; int remote_port; }; |
|
|
|
|
struct lnk { const char* local_srv; }; |
|
|
|
|
struct cli { const char* name; const char* peer_pubkey_hex; int lnk_cnt; struct lnk lnks[2]; }; |
|
|
|
|
struct srv { const char* name; int port; }; |
|
|
|
|
struct srv { const char* name; }; |
|
|
|
|
struct ncfg { |
|
|
|
|
uint64_t node_id; const char* tun_ip; const char* my_subnet; |
|
|
|
|
const char* priv_hex; const char* pub_hex; |
|
|
|
|
@ -105,13 +106,13 @@ static void build_node_config(char* buf, size_t size, const struct ncfg* c) {
|
|
|
|
|
c->priv_hex, c->pub_hex, c->tun_ip, c->my_subnet); |
|
|
|
|
for (int i = 0; i < c->srv_cnt; i++) |
|
|
|
|
off += snprintf(buf + off, size - off, |
|
|
|
|
"[server: %s]\naddr=127.0.0.1:%d\ntype=public\n\n", c->srvs[i].name, c->srvs[i].port); |
|
|
|
|
"[server: %s]\naddr=127.0.0.1:0\ntype=public\n\n", c->srvs[i].name); |
|
|
|
|
for (int i = 0; i < c->cli_cnt; i++) { |
|
|
|
|
off += snprintf(buf + off, size - off, |
|
|
|
|
"[client: %s]\nkeepalive=1\npeer_public_key=%s\n", c->clis[i].name, c->clis[i].peer_pubkey_hex); |
|
|
|
|
for (int j = 0; j < c->clis[i].lnk_cnt; j++) |
|
|
|
|
off += snprintf(buf + off, size - off, |
|
|
|
|
"link=%s:127.0.0.1:%d\n", c->clis[i].lnks[j].local_srv, c->clis[i].lnks[j].remote_port); |
|
|
|
|
"link=%s:127.0.0.1:0\n", c->clis[i].lnks[j].local_srv); |
|
|
|
|
off += snprintf(buf + off, size - off, "\n"); |
|
|
|
|
} |
|
|
|
|
off += snprintf(buf + off, size - off, "[allowed_keys]\nallow_all=1\n"); |
|
|
|
|
@ -275,57 +276,49 @@ int main(void) {
|
|
|
|
|
bytes_to_hex(keys[i].private_key, SC_PRIVKEY_SIZE, priv_hex[i], sizeof(priv_hex[i])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* ---------- Ports ---------- */ |
|
|
|
|
int base = 41000 + (getpid() % 15000); |
|
|
|
|
int p_ab_a = base++, p_ab_b = base++; // A↔B
|
|
|
|
|
int p_ac_a = base++, p_ac_c = base++; // A↔C
|
|
|
|
|
int p_bc_b = base++, p_bc_c = base++; // B↔C (C's second server for B)
|
|
|
|
|
int p_be_b = base++, p_be_e = base++; // B↔E
|
|
|
|
|
int p_cd_c = base++, p_cd_d = base++; // C↔D
|
|
|
|
|
|
|
|
|
|
/* ---------- Build config strings ---------- */ |
|
|
|
|
char cfg_a[2048], cfg_b[2048], cfg_c[2048], cfg_d[2048], cfg_e[2048]; |
|
|
|
|
|
|
|
|
|
build_node_config(cfg_a, sizeof(cfg_a), &(struct ncfg){ |
|
|
|
|
.node_id = g_node_id_a, .tun_ip = "10.100.0.1/24", .my_subnet = "192.168.10.0/24", |
|
|
|
|
.priv_hex = priv_hex[0], .pub_hex = pub_hex[0], |
|
|
|
|
.srv_cnt = 2, .srvs = {{"a_srv_b", p_ab_a}, {"a_srv_c", p_ac_a}}, |
|
|
|
|
.srv_cnt = 2, .srvs = {{"a_srv_b"}, {"a_srv_c"}}, |
|
|
|
|
.cli_cnt = 2, .clis = { |
|
|
|
|
{"to_b", pub_hex[1], 1, {{"a_srv_b", p_ab_b}}}, |
|
|
|
|
{"to_c", pub_hex[2], 1, {{"a_srv_c", p_ac_c}}}, |
|
|
|
|
{"to_b", pub_hex[1], 1, {{"a_srv_b"}}}, |
|
|
|
|
{"to_c", pub_hex[2], 1, {{"a_srv_c"}}}, |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
build_node_config(cfg_b, sizeof(cfg_b), &(struct ncfg){ |
|
|
|
|
.node_id = g_node_id_b, .tun_ip = "10.100.0.2/24", .my_subnet = "192.168.20.0/24", |
|
|
|
|
.priv_hex = priv_hex[1], .pub_hex = pub_hex[1], |
|
|
|
|
.srv_cnt = 3, .srvs = {{"b_srv", p_ab_b}, {"b_cli_c", p_bc_b}, {"b_cli_e", p_be_b}}, |
|
|
|
|
.srv_cnt = 3, .srvs = {{"b_srv"}, {"b_cli_c"}, {"b_cli_e"}}, |
|
|
|
|
.cli_cnt = 2, .clis = { |
|
|
|
|
{"to_c", pub_hex[2], 1, {{"b_cli_c", p_bc_c}}}, |
|
|
|
|
{"to_e", pub_hex[4], 1, {{"b_cli_e", p_be_e}}}, |
|
|
|
|
{"to_c", pub_hex[2], 1, {{"b_cli_c"}}}, |
|
|
|
|
{"to_e", pub_hex[4], 1, {{"b_cli_e"}}}, |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
build_node_config(cfg_c, sizeof(cfg_c), &(struct ncfg){ |
|
|
|
|
.node_id = g_node_id_c, .tun_ip = "10.100.0.3/24", .my_subnet = "192.168.30.0/24", |
|
|
|
|
.priv_hex = priv_hex[2], .pub_hex = pub_hex[2], |
|
|
|
|
.srv_cnt = 3, .srvs = {{"c_srv_a", p_ac_c}, {"c_srv_b", p_bc_c}, {"c_cli_d", p_cd_c}}, |
|
|
|
|
.srv_cnt = 3, .srvs = {{"c_srv_a"}, {"c_srv_b"}, {"c_cli_d"}}, |
|
|
|
|
.cli_cnt = 1, .clis = { |
|
|
|
|
{"to_d", pub_hex[3], 1, {{"c_cli_d", p_cd_d}}}, |
|
|
|
|
{"to_d", pub_hex[3], 1, {{"c_cli_d"}}}, |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
build_node_config(cfg_d, sizeof(cfg_d), &(struct ncfg){ |
|
|
|
|
.node_id = g_node_id_d, .tun_ip = "10.100.0.4/24", .my_subnet = "192.168.40.0/24", |
|
|
|
|
.priv_hex = priv_hex[3], .pub_hex = pub_hex[3], |
|
|
|
|
.srv_cnt = 1, .srvs = {{"d_srv", p_cd_d}}, |
|
|
|
|
.srv_cnt = 1, .srvs = {{"d_srv"}}, |
|
|
|
|
.cli_cnt = 0, .clis = {}, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
build_node_config(cfg_e, sizeof(cfg_e), &(struct ncfg){ |
|
|
|
|
.node_id = g_node_id_e, .tun_ip = "10.100.0.5/24", .my_subnet = "192.168.50.0/24", |
|
|
|
|
.priv_hex = priv_hex[4], .pub_hex = pub_hex[4], |
|
|
|
|
.srv_cnt = 1, .srvs = {{"e_srv", p_be_e}}, |
|
|
|
|
.srv_cnt = 1, .srvs = {{"e_srv"}}, |
|
|
|
|
.cli_cnt = 0, .clis = {}, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@ -338,6 +331,11 @@ int main(void) {
|
|
|
|
|
inst_c = utun_instance_create_from_str(ua, cfg_c); ASSERT(inst_c, "inst_c"); |
|
|
|
|
inst_d = utun_instance_create_from_str(ua, cfg_d); ASSERT(inst_d, "inst_d"); |
|
|
|
|
inst_e = utun_instance_create_from_str(ua, cfg_e); ASSERT(inst_e, "inst_e"); |
|
|
|
|
test_etcp_set_peer(inst_a, "to_b", inst_b, "b_srv"); |
|
|
|
|
test_etcp_set_peer(inst_a, "to_c", inst_c, "c_srv_a"); |
|
|
|
|
test_etcp_set_peer(inst_b, "to_c", inst_c, "c_srv_b"); |
|
|
|
|
test_etcp_set_peer(inst_b, "to_e", inst_e, "e_srv"); |
|
|
|
|
test_etcp_set_peer(inst_c, "to_d", inst_d, "d_srv"); |
|
|
|
|
|
|
|
|
|
ASSERT(utun_instance_init(inst_a) == 0, "init a"); |
|
|
|
|
ASSERT(utun_instance_init(inst_b) == 0, "init b"); |
|
|
|
|
|