forked from cory/tildefriends
ssb: Work in progress invite support. We can generate them. We can connect using an invite code. We can't yet invite.use().
This commit is contained in:
163
src/ssb.tests.c
163
src/ssb.tests.c
@ -767,7 +767,7 @@ void tf_ssb_test_bench(const tf_test_options_t* options)
|
||||
|
||||
static void _ssb_test_room_connections_changed(tf_ssb_t* ssb, tf_ssb_change_t change, tf_ssb_connection_t* connection, void* user_data)
|
||||
{
|
||||
const char* changes[] = { "create", "connect", "remove" };
|
||||
const char* changes[] = { "create", "connect", "remove", "update" };
|
||||
tf_printf("change=%s %p connection=%s:%d\n", changes[change], connection, tf_ssb_connection_get_host(connection), tf_ssb_connection_get_port(connection));
|
||||
}
|
||||
|
||||
@ -1221,4 +1221,165 @@ void tf_ssb_test_replicate(const tf_test_options_t* options)
|
||||
uv_loop_close(&loop);
|
||||
}
|
||||
|
||||
void tf_ssb_test_connect_str(const tf_test_options_t* options)
|
||||
{
|
||||
tf_printf("Testing connect string.\n");
|
||||
|
||||
uv_loop_t loop = { 0 };
|
||||
uv_loop_init(&loop);
|
||||
|
||||
unlink("out/test_db0.sqlite");
|
||||
tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, "file:out/test_db0.sqlite", NULL);
|
||||
tf_ssb_register(tf_ssb_get_context(ssb0), ssb0);
|
||||
unlink("out/test_db1.sqlite");
|
||||
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, "file:out/test_db1.sqlite", NULL);
|
||||
tf_ssb_register(tf_ssb_get_context(ssb1), ssb1);
|
||||
|
||||
test_t test = {
|
||||
.ssb0 = ssb0,
|
||||
.ssb1 = ssb1,
|
||||
};
|
||||
|
||||
tf_ssb_add_connections_changed_callback(ssb0, _ssb_test_connections_changed, NULL, &test);
|
||||
tf_ssb_add_connections_changed_callback(ssb1, _ssb_test_connections_changed, NULL, &test);
|
||||
|
||||
uint8_t priv0[crypto_sign_SECRETKEYBYTES] = { 0 };
|
||||
uint8_t priv1[crypto_sign_SECRETKEYBYTES] = { 0 };
|
||||
tf_ssb_get_private_key(ssb0, priv0, sizeof(priv0));
|
||||
tf_ssb_get_private_key(ssb1, priv1, sizeof(priv1));
|
||||
|
||||
char id0[k_id_base64_len] = { 0 };
|
||||
char id1[k_id_base64_len] = { 0 };
|
||||
bool b = tf_ssb_whoami(ssb0, id0, sizeof(id0));
|
||||
(void)b;
|
||||
assert(b);
|
||||
b = tf_ssb_whoami(ssb1, id1, sizeof(id1));
|
||||
assert(b);
|
||||
tf_printf("ID %s and %s\n", id0, id1);
|
||||
|
||||
char priv0_str[512] = { 0 };
|
||||
char priv1_str[512] = { 0 };
|
||||
tf_base64_encode(priv0, sizeof(priv0), priv0_str, sizeof(priv0_str));
|
||||
tf_base64_encode(priv1, sizeof(priv0), priv1_str, sizeof(priv1_str));
|
||||
tf_ssb_db_identity_add(ssb0, "test", id0 + 1, priv0_str);
|
||||
tf_ssb_db_identity_add(ssb1, "test", id1 + 1, priv1_str);
|
||||
|
||||
tf_ssb_server_open(ssb0, 12347);
|
||||
|
||||
char connect[1024] = { 0 };
|
||||
snprintf(connect, sizeof(connect), "net:127.0.0.1:12347~shs:%.44s", id0 + 1);
|
||||
tf_printf("connect string: %s\n", connect);
|
||||
tf_ssb_connect_str(ssb1, connect, 0, NULL, NULL);
|
||||
|
||||
tf_printf("Waiting for connection.\n");
|
||||
while (test.connection_count0 != 1 || test.connection_count1 != 1)
|
||||
{
|
||||
tf_ssb_set_main_thread(ssb0, true);
|
||||
tf_ssb_set_main_thread(ssb1, true);
|
||||
uv_run(&loop, UV_RUN_ONCE);
|
||||
tf_ssb_set_main_thread(ssb0, false);
|
||||
tf_ssb_set_main_thread(ssb1, false);
|
||||
}
|
||||
tf_ssb_server_close(ssb0);
|
||||
|
||||
tf_ssb_send_close(ssb1);
|
||||
|
||||
tf_printf("final run\n");
|
||||
tf_ssb_set_main_thread(ssb0, true);
|
||||
tf_ssb_set_main_thread(ssb1, true);
|
||||
uv_run(&loop, UV_RUN_DEFAULT);
|
||||
tf_ssb_set_main_thread(ssb0, false);
|
||||
tf_ssb_set_main_thread(ssb1, false);
|
||||
tf_printf("done\n");
|
||||
|
||||
tf_printf("destroy 0\n");
|
||||
tf_ssb_destroy(ssb0);
|
||||
tf_printf("destroy 1\n");
|
||||
tf_ssb_destroy(ssb1);
|
||||
|
||||
tf_printf("close\n");
|
||||
uv_loop_close(&loop);
|
||||
}
|
||||
|
||||
void tf_ssb_test_invite(const tf_test_options_t* options)
|
||||
{
|
||||
tf_printf("Testing invites.\n");
|
||||
|
||||
uv_loop_t loop = { 0 };
|
||||
uv_loop_init(&loop);
|
||||
|
||||
unlink("out/test_db0.sqlite");
|
||||
tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, "file:out/test_db0.sqlite", NULL);
|
||||
tf_ssb_register(tf_ssb_get_context(ssb0), ssb0);
|
||||
unlink("out/test_db1.sqlite");
|
||||
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, "file:out/test_db1.sqlite", NULL);
|
||||
tf_ssb_register(tf_ssb_get_context(ssb1), ssb1);
|
||||
|
||||
test_t test = {
|
||||
.ssb0 = ssb0,
|
||||
.ssb1 = ssb1,
|
||||
};
|
||||
|
||||
tf_ssb_add_connections_changed_callback(ssb0, _ssb_test_connections_changed, NULL, &test);
|
||||
tf_ssb_add_connections_changed_callback(ssb1, _ssb_test_connections_changed, NULL, &test);
|
||||
|
||||
uint8_t priv0[crypto_sign_SECRETKEYBYTES] = { 0 };
|
||||
uint8_t priv1[crypto_sign_SECRETKEYBYTES] = { 0 };
|
||||
tf_ssb_get_private_key(ssb0, priv0, sizeof(priv0));
|
||||
tf_ssb_get_private_key(ssb1, priv1, sizeof(priv1));
|
||||
|
||||
char id0[k_id_base64_len] = { 0 };
|
||||
char id1[k_id_base64_len] = { 0 };
|
||||
bool b = tf_ssb_whoami(ssb0, id0, sizeof(id0));
|
||||
(void)b;
|
||||
assert(b);
|
||||
b = tf_ssb_whoami(ssb1, id1, sizeof(id1));
|
||||
assert(b);
|
||||
tf_printf("ID %s and %s\n", id0, id1);
|
||||
|
||||
char priv0_str[512] = { 0 };
|
||||
char priv1_str[512] = { 0 };
|
||||
tf_base64_encode(priv0, sizeof(priv0), priv0_str, sizeof(priv0_str));
|
||||
tf_base64_encode(priv1, sizeof(priv0), priv1_str, sizeof(priv1_str));
|
||||
|
||||
tf_ssb_server_open(ssb0, 12347);
|
||||
|
||||
sqlite3* writer = tf_ssb_acquire_db_writer(ssb0);
|
||||
char invite[1024];
|
||||
tf_ssb_db_generate_invite(writer, id0, "127.0.0.1", 12347, 1, 60 * 60, invite, sizeof(invite));
|
||||
tf_ssb_release_db_writer(ssb0, writer);
|
||||
tf_printf("invite: %s\n", invite);
|
||||
|
||||
tf_ssb_connect_str(ssb1, invite, 0, NULL, NULL);
|
||||
|
||||
tf_printf("Waiting for connection.\n");
|
||||
while (test.connection_count0 != 1 || test.connection_count1 != 1)
|
||||
{
|
||||
tf_ssb_set_main_thread(ssb0, true);
|
||||
tf_ssb_set_main_thread(ssb1, true);
|
||||
uv_run(&loop, UV_RUN_ONCE);
|
||||
tf_ssb_set_main_thread(ssb0, false);
|
||||
tf_ssb_set_main_thread(ssb1, false);
|
||||
}
|
||||
|
||||
tf_ssb_server_close(ssb0);
|
||||
tf_ssb_send_close(ssb1);
|
||||
|
||||
tf_printf("final run\n");
|
||||
tf_ssb_set_main_thread(ssb0, true);
|
||||
tf_ssb_set_main_thread(ssb1, true);
|
||||
uv_run(&loop, UV_RUN_DEFAULT);
|
||||
tf_ssb_set_main_thread(ssb0, false);
|
||||
tf_ssb_set_main_thread(ssb1, false);
|
||||
tf_printf("done\n");
|
||||
|
||||
tf_printf("destroy 0\n");
|
||||
tf_ssb_destroy(ssb0);
|
||||
tf_printf("destroy 1\n");
|
||||
tf_ssb_destroy(ssb1);
|
||||
|
||||
tf_printf("close\n");
|
||||
uv_loop_close(&loop);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user