|
|
|
|
@ -30,6 +30,7 @@
|
|
|
|
|
#include "../lib/socket_compat.h" |
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#include "test_net.h" |
|
|
|
|
|
|
|
|
|
#include <sqlite3.h> |
|
|
|
|
#define OPENSSL_API_COMPAT 0x10100000L |
|
|
|
|
@ -91,7 +92,6 @@ struct hs_shared {
|
|
|
|
|
uint8_t ch_x_pub[32], ch_ed_pub[32], ch_ed_priv[32], ch_sig[64]; |
|
|
|
|
uint64_t nid[2]; |
|
|
|
|
uint8_t x_pub[2][32], x_priv[2][32], ed_pub[2][32]; |
|
|
|
|
int port[2]; /* etcp-порты */ |
|
|
|
|
}; |
|
|
|
|
static struct hs_shared g_sh; |
|
|
|
|
|
|
|
|
|
@ -130,13 +130,12 @@ static int wf(const char* p, const char* f, ...) {
|
|
|
|
|
va_start(ap, f); vfprintf(fp, f, ap); va_end(ap); fclose(fp); return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void fill_shared(int base_port) { |
|
|
|
|
static void fill_shared(void) { |
|
|
|
|
memset(&g_sh, 0, sizeof(g_sh)); |
|
|
|
|
for (int i = 0; i < 2; 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); |
|
|
|
|
@ -164,17 +163,16 @@ static void write_configs(const char* dir) {
|
|
|
|
|
if (i == IDX_B) { |
|
|
|
|
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]); |
|
|
|
|
"[client: to_a]\npeer_public_key=%s\nlink=s1:127.0.0.1:0\n", apub); |
|
|
|
|
} |
|
|
|
|
wf(path, |
|
|
|
|
"[global]\ntun_ip=10.97.%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" : "b", |
|
|
|
|
priv, pub, g_sh.port[i], client); |
|
|
|
|
priv, pub, client); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -312,12 +310,12 @@ static void hs_tick(void* arg) {
|
|
|
|
|
case P_SETUP: |
|
|
|
|
do_setup(A, IDX_A); |
|
|
|
|
do_setup(B, IDX_B); |
|
|
|
|
if (chat_headless_control_init(A->ua, A, "127.0.0.1", 9700 + (int)(getpid() % 100)) != 0 |
|
|
|
|
|| chat_headless_control_init(B->ua, B, "127.0.0.1", 9800 + (int)(getpid() % 100)) != 0) { |
|
|
|
|
if (chat_headless_control_init(A->ua, A, "127.0.0.1", 0) != 0 |
|
|
|
|
|| chat_headless_control_init(B->ua, B, "127.0.0.1", 0) != 0) { |
|
|
|
|
fprintf(stderr, "headless control init failed\n"); t->result = 2; break; |
|
|
|
|
} |
|
|
|
|
if (call_headless_init(A->ua, A, "127.0.0.1", 9710 + (int)(getpid() % 100)) != 0 |
|
|
|
|
|| call_headless_init(B->ua, B, "127.0.0.1", 9810 + (int)(getpid() % 100)) != 0) { |
|
|
|
|
if (call_headless_init(A->ua, A, "127.0.0.1", 0) != 0 |
|
|
|
|
|| call_headless_init(B->ua, B, "127.0.0.1", 0) != 0) { |
|
|
|
|
fprintf(stderr, "call headless audio init failed\n"); t->result = 2; break; |
|
|
|
|
} |
|
|
|
|
t->phase = P_WAIT_BGP; |
|
|
|
|
@ -326,10 +324,10 @@ static void hs_tick(void* arg) {
|
|
|
|
|
if (bgp_has(A, nb) && bgp_has(B, na)) t->phase = P_CONNECT_CLIENTS; |
|
|
|
|
break; |
|
|
|
|
case P_CONNECT_CLIENTS: |
|
|
|
|
if (hs_connect(t, &t->ctl[IDX_A], 9700 + (int)(getpid() % 100)) != 0 |
|
|
|
|
|| hs_connect(t, &t->ctl[IDX_B], 9800 + (int)(getpid() % 100)) != 0 |
|
|
|
|
|| hs_connect(t, &t->aud[IDX_A], 9710 + (int)(getpid() % 100)) != 0 |
|
|
|
|
|| hs_connect(t, &t->aud[IDX_B], 9810 + (int)(getpid() % 100)) != 0) { |
|
|
|
|
if (hs_connect(t, &t->ctl[IDX_A], chat_headless_control_get_port(A)) != 0 |
|
|
|
|
|| hs_connect(t, &t->ctl[IDX_B], chat_headless_control_get_port(B)) != 0 |
|
|
|
|
|| hs_connect(t, &t->aud[IDX_A], call_headless_get_port(A)) != 0 |
|
|
|
|
|| hs_connect(t, &t->aud[IDX_B], call_headless_get_port(B)) != 0) { |
|
|
|
|
fprintf(stderr, "client connect failed\n"); t->result = 2; break; |
|
|
|
|
} |
|
|
|
|
t->phase = P_SUBSCRIBE; |
|
|
|
|
@ -460,7 +458,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(56000 + (getpid() % 2000)); |
|
|
|
|
fill_shared(); |
|
|
|
|
write_configs(dir); |
|
|
|
|
|
|
|
|
|
printf("=== test_call_headless ===\n"); fflush(stdout); |
|
|
|
|
@ -486,6 +484,7 @@ int main(int argc, char** argv) {
|
|
|
|
|
uasync_destroy(ua, 0); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
test_etcp_set_peer(t.inst[IDX_B], "to_a", t.inst[IDX_A], "s1"); |
|
|
|
|
utun_instance_init(t.inst[IDX_A]); |
|
|
|
|
utun_instance_init(t.inst[IDX_B]); |
|
|
|
|
|
|
|
|
|
|