tests: isolate media delivery endpoints and scratch files
This commit is contained in:
1 parent
336b6871f3
commit
e4fe534382
3 files changed
+35
-30
No files matched your search
@@ -34,6 +34,7 @@
|
||||
#include "../lib/u_async.h"
|
||||
#include "../lib/debug_config.h"
|
||||
#include "../lib/mem.h"
|
||||
#include "test_net.h"
|
||||
|
||||
#include <sqlite3.h>
|
||||
#define OPENSSL_API_COMPAT 0x10100000L
|
||||
@@ -77,7 +78,6 @@ static uint64_t g_group_id = 0;
|
||||
static char g_tdir[256] = "/tmp/utun_mdc_XXXXXX";
|
||||
static char g_cfg[N_NODES][256];
|
||||
static char g_db_dir[N_NODES][320];
|
||||
static int g_port[N_NODES];
|
||||
static int g_connected = 0, g_result = 0;
|
||||
|
||||
/* опубликованное медиа (автор) — глобально для n2-загрузки и проверок */
|
||||
@@ -542,14 +542,13 @@ int main(void) {
|
||||
snprintf(g_cfg[i], sizeof(g_cfg[i]), "%s/n%d.conf", g_tdir, i);
|
||||
snprintf(g_db_dir[i], sizeof(g_db_dir[i]), "%s/db%d", g_tdir, i);
|
||||
utun_mkdir(g_db_dir[i], 0755);
|
||||
g_port[i] = 52000 + (getpid() % 5000) + i * 1000;
|
||||
}
|
||||
|
||||
g_ua = uasync_create();
|
||||
for (int i = 0; i < N_NODES; i++)
|
||||
wf(g_cfg[i], "[global]\ntun_ip=10.98.%d.1/24\ntun_ifname=tun%d0\ndb_path=%s\ndb_sync_enabled=1\n"
|
||||
"[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n",
|
||||
i, i, g_db_dir[i], g_port[i]);
|
||||
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n",
|
||||
i, i, g_db_dir[i]);
|
||||
for (int i = 0; i < N_NODES; i++) {
|
||||
config_ensure_keys_and_node_id(g_cfg[i]);
|
||||
struct utun_config* c = parse_config(g_cfg[i]); g_nid[i] = c->global.my_node_id; free_config(c);
|
||||
@@ -561,19 +560,23 @@ int main(void) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
char *pj_pu = gv(g_cfg[j], "pub");
|
||||
char link[256]; snprintf(link, sizeof(link),
|
||||
"[client: to_n%d]\nkeepalive=1\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n", j, pj_pu, g_port[j]);
|
||||
"[client: to_n%d]\nkeepalive=1\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", j, pj_pu);
|
||||
strncat(clients, link, sizeof(clients) - strlen(clients) - 1);
|
||||
u_free(pj_pu);
|
||||
}
|
||||
wf(g_cfg[i], "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.98.%d.1/24\ntun_ifname=tun%d0\n"
|
||||
"db_path=%s\ndb_sync_enabled=1\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n%s[allowed_keys]\nallow_all=1\n",
|
||||
pr, pu, i, i, g_db_dir[i], g_port[i], clients);
|
||||
"db_path=%s\ndb_sync_enabled=1\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n%s[allowed_keys]\nallow_all=1\n",
|
||||
pr, pu, i, i, g_db_dir[i], clients);
|
||||
u_free(pr); u_free(pu);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N_NODES; i++) {
|
||||
g_inst[i] = utun_instance_create(g_ua, g_cfg[i]);
|
||||
if (!g_inst[i]) { printf("FAIL: create n%d\n", i); goto done; }
|
||||
for (int j = 0; j < i; j++) {
|
||||
char peer[64]; snprintf(peer, sizeof(peer), "to_n%d", j);
|
||||
test_etcp_set_peer(g_inst[i], peer, g_inst[j], "s1");
|
||||
}
|
||||
utun_instance_init(g_inst[i]);
|
||||
media_delivery_init(g_inst[i]);
|
||||
member_sync_init(g_inst[i]);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "../lib/u_async.h"
|
||||
#include "../lib/debug_config.h"
|
||||
#include "../lib/mem.h"
|
||||
#include "test_net.h"
|
||||
|
||||
#include <sqlite3.h>
|
||||
#define OPENSSL_API_COMPAT 0x10100000L
|
||||
@@ -51,7 +52,6 @@ static uint8_t g_t2_mid[16], g_t2_bids[3][16];
|
||||
static char g_tdir[256] = "/tmp/utun_mdf_XXXXXX";
|
||||
static char g_cfg[N_NODES][256];
|
||||
static char g_db_dir[N_NODES][320];
|
||||
static int g_port[N_NODES];
|
||||
static int g_connected = 0, g_result = 0;
|
||||
|
||||
static int wf(const char* p, const char* f, ...) {
|
||||
@@ -381,7 +381,8 @@ static void phase_b2_truncated_last_block(void) {
|
||||
if (!dl) { FAIL("u_calloc dl"); return; }
|
||||
memcpy(dl->media_id, g_t2_mid, 16);
|
||||
dl->num_blocks = 1;
|
||||
snprintf(dl->dest_path, sizeof(dl->dest_path), "/tmp/utun_mdf_trunc.bin");
|
||||
char dest[sizeof(dl->dest_path)]; snprintf(dest, sizeof(dest), "%s/truncated.bin", g_tdir);
|
||||
snprintf(dl->dest_path, sizeof(dl->dest_path), "%s", dest);
|
||||
dl->blocks = u_calloc(1, sizeof(struct media_download_block));
|
||||
dl->block_sigs = u_calloc(1, 64);
|
||||
memcpy(dl->blocks[0].block_id, g_t2_bids[2], 16); /* блок 2 — усечённый */
|
||||
@@ -404,7 +405,6 @@ static void phase_b2_truncated_last_block(void) {
|
||||
msend(g_inst[1], g_nid[0], (const uint8_t*)&req, sizeof(req));
|
||||
|
||||
/* ждём сборки (блок валиден → num_blocks=1 → сразу ассемблируется) */
|
||||
const char* dest = "/tmp/utun_mdf_trunc.bin";
|
||||
int a = 0;
|
||||
while (a < 3000 && access(dest, F_OK) != 0) { uasync_poll(g_ua, POLL_MS); a++; }
|
||||
|
||||
@@ -433,14 +433,13 @@ int main(void) {
|
||||
snprintf(g_cfg[i], sizeof(g_cfg[i]), "%s/n%d.conf", g_tdir, i);
|
||||
snprintf(g_db_dir[i], sizeof(g_db_dir[i]), "%s/db%d", g_tdir, i);
|
||||
utun_mkdir(g_db_dir[i], 0755);
|
||||
g_port[i] = 51000 + (getpid() % 5000) + i * 1000;
|
||||
}
|
||||
|
||||
g_ua = uasync_create();
|
||||
for (int i = 0; i < N_NODES; i++)
|
||||
wf(g_cfg[i], "[global]\ntun_ip=10.99.%d.1/24\ntun_ifname=tun%d0\ndb_path=%s\n"
|
||||
"[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n",
|
||||
i, i, g_db_dir[i], g_port[i]);
|
||||
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n",
|
||||
i, i, g_db_dir[i]);
|
||||
for (int i = 0; i < N_NODES; i++) {
|
||||
config_ensure_keys_and_node_id(g_cfg[i]);
|
||||
struct utun_config* c = parse_config(g_cfg[i]); g_nid[i] = c->global.my_node_id; free_config(c);
|
||||
@@ -450,15 +449,15 @@ int main(void) {
|
||||
char *pr = gv(g_cfg[i], "priv"), *pu = gv(g_cfg[i], "pub");
|
||||
if (i == 0) {
|
||||
wf(g_cfg[i], "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.99.%d.1/24\ntun_ifname=tun%d0\n"
|
||||
"db_path=%s\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n[allowed_keys]\nallow_all=1\n",
|
||||
pr, pu, i, i, g_db_dir[i], g_port[i]);
|
||||
"db_path=%s\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n[allowed_keys]\nallow_all=1\n",
|
||||
pr, pu, i, i, g_db_dir[i]);
|
||||
} else {
|
||||
int prev = i - 1; char *pv_pu = gv(g_cfg[prev], "pub");
|
||||
char link[256]; snprintf(link, sizeof(link),
|
||||
"[client: to_n%d]\nkeepalive=1\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n", prev, pv_pu, g_port[prev]);
|
||||
"[client: to_n%d]\nkeepalive=1\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", prev, pv_pu);
|
||||
wf(g_cfg[i], "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.99.%d.1/24\ntun_ifname=tun%d0\n"
|
||||
"db_path=%s\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n%s[allowed_keys]\nallow_all=1\n",
|
||||
pr, pu, i, i, g_db_dir[i], g_port[i], link);
|
||||
"db_path=%s\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n%s[allowed_keys]\nallow_all=1\n",
|
||||
pr, pu, i, i, g_db_dir[i], link);
|
||||
u_free(pv_pu);
|
||||
}
|
||||
u_free(pr); u_free(pu);
|
||||
@@ -467,6 +466,10 @@ int main(void) {
|
||||
for (int i = 0; i < N_NODES; i++) {
|
||||
g_inst[i] = utun_instance_create(g_ua, g_cfg[i]);
|
||||
if (!g_inst[i]) { printf("FAIL: create n%d\n", i); goto done; }
|
||||
if (i) {
|
||||
char peer[64]; snprintf(peer, sizeof(peer), "to_n%d", i - 1);
|
||||
test_etcp_set_peer(g_inst[i], peer, g_inst[i - 1], "s1");
|
||||
}
|
||||
utun_instance_init(g_inst[i]);
|
||||
media_delivery_init(g_inst[i]);
|
||||
if (member_sync_init(g_inst[i]) < 0) { FAIL("member_sync_init n%d", i); goto done; }
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "../lib/u_async.h"
|
||||
#include "../lib/debug_config.h"
|
||||
#include "../lib/mem.h"
|
||||
#include "test_net.h"
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include <stdio.h>
|
||||
@@ -43,7 +44,6 @@ static int g_connected = 0, g_result = 0;
|
||||
static char g_tdir[] = "/tmp/utun_mdl_XXXXXX";
|
||||
static char g_ca[256], g_cb[256];
|
||||
static uint8_t g_a_pubkey[32], g_b_pubkey[32];
|
||||
static int g_pa = 0, g_pb = 0;
|
||||
|
||||
/* ── helpers ── */
|
||||
|
||||
@@ -243,12 +243,10 @@ int main(void) {
|
||||
debug_set_category_level(DEBUG_CATEGORY_SYS, DEBUG_LEVEL_WARN);
|
||||
debug_set_category_level(DEBUG_CATEGORY_DEBUG, DEBUG_LEVEL_TRACE);
|
||||
debug_set_category_level(DEBUG_CATEGORY_GENERAL, DEBUG_LEVEL_TRACE);
|
||||
debug_enable_file_output("/tmp/mdl_integration.log", 1);
|
||||
|
||||
utun_instance_set_tun_init_enabled(0);
|
||||
|
||||
test_mkdtemp(g_tdir);
|
||||
int base = 49000 + (getpid() % 10000); g_pa = base; g_pb = base + 1;
|
||||
char db_a[320], db_b[320];
|
||||
snprintf(db_a, sizeof(db_a), "%s/db_a", g_tdir); utun_mkdir(db_a, 0755);
|
||||
snprintf(db_b, sizeof(db_b), "%s/db_b", g_tdir); utun_mkdir(db_b, 0755);
|
||||
@@ -257,11 +255,11 @@ int main(void) {
|
||||
|
||||
/* create configs with db_path */
|
||||
wf(g_ca, "[global]\ntun_ip=10.98.1.1/24\ntun_ifname=tun90\ndb_path=%s\n"
|
||||
"[server: s1]\naddr=127.0.0.1:%d\ntype=public\n"
|
||||
"[allowed_keys]\nallow_all=1\n", db_a, g_pa);
|
||||
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n"
|
||||
"[allowed_keys]\nallow_all=1\n", db_a);
|
||||
wf(g_cb, "[global]\ntun_ip=10.98.1.2/24\ntun_ifname=tun91\ndb_path=%s\n"
|
||||
"[server: s1]\naddr=127.0.0.1:%d\ntype=public\n"
|
||||
"[allowed_keys]\nallow_all=1\n", db_b, g_pb);
|
||||
"[server: s1]\naddr=127.0.0.1:0\ntype=public\n"
|
||||
"[allowed_keys]\nallow_all=1\n", db_b);
|
||||
|
||||
/* generate keys */
|
||||
config_ensure_keys_and_node_id(g_ca); config_ensure_keys_and_node_id(g_cb);
|
||||
@@ -271,18 +269,19 @@ int main(void) {
|
||||
char *p0 = gv(g_ca,"pub"), *r0 = gv(g_ca,"priv");
|
||||
char *p1 = gv(g_cb,"pub"), *r1 = gv(g_cb,"priv");
|
||||
wf(g_ca, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.98.1.1/24\ntun_ifname=tun90\n"
|
||||
"db_path=%s\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n"
|
||||
"[client: to_b]\nkeepalive=1\npeer_public_key=%s\nlink=s1:127.0.0.1:%d\n"
|
||||
"[allowed_keys]\nallow_all=1\n", r0, p0, db_a, g_pa, p1, g_pb);
|
||||
"db_path=%s\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n"
|
||||
"[client: to_b]\nkeepalive=1\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n"
|
||||
"[allowed_keys]\nallow_all=1\n", r0, p0, db_a, p1);
|
||||
wf(g_cb, "[global]\nmy_private_key=%s\nmy_public_key=%s\ntun_ip=10.98.1.2/24\ntun_ifname=tun91\n"
|
||||
"db_path=%s\n[server: s1]\naddr=127.0.0.1:%d\ntype=public\n"
|
||||
"[allowed_keys]\nallow_all=1\n", r1, p1, db_b, g_pb);
|
||||
"db_path=%s\n[server: s1]\naddr=127.0.0.1:0\ntype=public\n"
|
||||
"[allowed_keys]\nallow_all=1\n", r1, p1, db_b);
|
||||
u_free(p0); u_free(r0); u_free(p1); u_free(r1);
|
||||
|
||||
/* create instances */
|
||||
g_ua = uasync_create();
|
||||
g_a = utun_instance_create(g_ua, g_ca); g_b = utun_instance_create(g_ua, g_cb);
|
||||
if (!g_a || !g_b) { printf("FAIL: instance create\n"); goto done; }
|
||||
test_etcp_set_peer(g_a, "to_b", g_b, "s1");
|
||||
utun_instance_init(g_a); utun_instance_init(g_b);
|
||||
media_delivery_init(g_a); media_delivery_init(g_b);
|
||||
|
||||
|
||||
Reference in new issue
Block a user