|
|
|
|
@ -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; } |
|
|
|
|
|