|
|
|
|
@ -31,6 +31,7 @@
|
|
|
|
|
#include "../lib/mem.h" |
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#include "test_net.h" |
|
|
|
|
|
|
|
|
|
#include <sqlite3.h> |
|
|
|
|
#define OPENSSL_API_COMPAT 0x10100000L |
|
|
|
|
@ -86,7 +87,6 @@ struct mesh_shared {
|
|
|
|
|
uint8_t ch_x_pub[32], ch_ed_pub[32], ch_ed_priv[32], ch_sig[64]; |
|
|
|
|
uint64_t nid[4]; |
|
|
|
|
uint8_t x_pub[4][32], x_priv[4][32], ed_pub[4][32]; |
|
|
|
|
int port[4]; |
|
|
|
|
}; |
|
|
|
|
static struct mesh_shared g_sh; |
|
|
|
|
static struct rx_evt g_rx[4]; |
|
|
|
|
@ -128,13 +128,12 @@ static int wf(const char* p, const char* f, ...) {
|
|
|
|
|
|
|
|
|
|
/* ── данные сценария + конфиги (diamond A↔B, A↔D, B↔C, D↔C) ── */ |
|
|
|
|
|
|
|
|
|
static void fill_shared(int base_port) { |
|
|
|
|
static void fill_shared(void) { |
|
|
|
|
memset(&g_sh, 0, sizeof(g_sh)); |
|
|
|
|
for (int i = 0; i < 4; i++) { |
|
|
|
|
gen_x25519(g_sh.x_pub[i], g_sh.x_priv[i]); |
|
|
|
|
sc_derive_ed25519_pubkey(g_sh.x_priv[i], g_sh.ed_pub[i]); |
|
|
|
|
g_sh.nid[i] = sc_derive_node_id_from_pubkey(g_sh.x_pub[i]); |
|
|
|
|
g_sh.port[i] = base_port + i * 1000; |
|
|
|
|
} |
|
|
|
|
{ uint8_t ch_x_priv[32]; gen_x25519(g_sh.ch_x_pub, ch_x_priv); } |
|
|
|
|
gen_ed25519(g_sh.ch_ed_pub, g_sh.ch_ed_priv); |
|
|
|
|
@ -163,28 +162,27 @@ static void write_configs(const char* dir) {
|
|
|
|
|
char client[1024] = ""; |
|
|
|
|
if (i == IDX_B) { /* B → A */ |
|
|
|
|
char apub[65]; to_hex(g_sh.x_pub[IDX_A], 32, apub); |
|
|
|
|
snprintf(client, sizeof(client), "[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n", apub, g_sh.port[IDX_A]); |
|
|
|
|
snprintf(client, sizeof(client), "[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", apub); |
|
|
|
|
} else if (i == IDX_D) { /* D → A */ |
|
|
|
|
char apub[65]; to_hex(g_sh.x_pub[IDX_A], 32, apub); |
|
|
|
|
snprintf(client, sizeof(client), "[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n", apub, g_sh.port[IDX_A]); |
|
|
|
|
snprintf(client, sizeof(client), "[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", apub); |
|
|
|
|
} else if (i == IDX_C) { /* C → B и C → D */ |
|
|
|
|
char bpub[65], dpub[65]; |
|
|
|
|
to_hex(g_sh.x_pub[IDX_B], 32, bpub); |
|
|
|
|
to_hex(g_sh.x_pub[IDX_D], 32, dpub); |
|
|
|
|
snprintf(client, sizeof(client), |
|
|
|
|
"[client: to_b]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n" |
|
|
|
|
"[client: to_d]\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n", |
|
|
|
|
bpub, g_sh.port[IDX_B], dpub, g_sh.port[IDX_D]); |
|
|
|
|
"[client: to_b]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n" |
|
|
|
|
"[client: to_d]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", bpub, dpub); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wf(path, |
|
|
|
|
"[global]\ntun_ip=10.98.%d.1/24\ntun_ifname=tun%d0\ndb_path=%s/db%s\n" |
|
|
|
|
"my_private_key=%s\nmy_public_key=%s\n" |
|
|
|
|
"[server: s1]\naddr=127.0.0.1:%d\ntype=public\n" |
|
|
|
|
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n" |
|
|
|
|
"%s" |
|
|
|
|
"[chatserver]\nstorage_autoload=0\n[allowed_keys]\nallow_all=1\n", |
|
|
|
|
i, i, dir, i == IDX_A ? "a" : i == IDX_B ? "b" : i == IDX_D ? "d" : "c", |
|
|
|
|
priv, pub, g_sh.port[i], client); |
|
|
|
|
priv, pub, client); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -422,7 +420,7 @@ int main(int argc, char** argv) {
|
|
|
|
|
if (test_mkdtemp(dir) != 0) { fprintf(stderr, "mkdtemp failed\n"); return 1; } |
|
|
|
|
test_setenv("UTUN_TEST_DIR", dir, 1); |
|
|
|
|
|
|
|
|
|
fill_shared(59000 + (getpid() % 2000)); |
|
|
|
|
fill_shared(); |
|
|
|
|
write_configs(dir); |
|
|
|
|
|
|
|
|
|
printf("=== test_radio_mesh ===\n"); fflush(stdout); |
|
|
|
|
@ -444,6 +442,10 @@ int main(int argc, char** argv) {
|
|
|
|
|
t.inst[i] = utun_instance_create(ua, cfg[i]); |
|
|
|
|
if (!t.inst[i]) { FAIL("instance create failed i=%d", i); uasync_destroy(ua, 0); return 1; } |
|
|
|
|
} |
|
|
|
|
test_etcp_set_peer(t.inst[IDX_B], "to_a", t.inst[IDX_A], "s1"); |
|
|
|
|
test_etcp_set_peer(t.inst[IDX_D], "to_a", t.inst[IDX_A], "s1"); |
|
|
|
|
test_etcp_set_peer(t.inst[IDX_C], "to_b", t.inst[IDX_B], "s1"); |
|
|
|
|
test_etcp_set_peer(t.inst[IDX_C], "to_d", t.inst[IDX_D], "s1"); |
|
|
|
|
for (int i = 0; i < 4; i++) utun_instance_init(t.inst[i]); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) radio_set_frame_cb(t.inst[i], rx_frame_cb, &g_rx[i]); |
|
|
|
|
|