ssb: Beginnings of a "sync now" mode for mobile.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 19m52s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 19m52s
This commit is contained in:
@ -106,7 +106,7 @@ static void _tf_ssb_connections_get_next_after_work(tf_ssb_t* ssb, int status, v
|
||||
uint8_t key_bin[k_id_bin_len];
|
||||
if (tf_ssb_id_str_to_bin(key_bin, next->key))
|
||||
{
|
||||
tf_ssb_connect(ssb, next->host, next->port, key_bin);
|
||||
tf_ssb_connect(ssb, next->host, next->port, key_bin, 0);
|
||||
}
|
||||
}
|
||||
tf_free(next);
|
||||
@ -267,3 +267,83 @@ void tf_ssb_connections_set_succeeded(tf_ssb_connections_t* connections, const c
|
||||
snprintf(update->key, sizeof(update->key), "%s", key);
|
||||
_tf_ssb_connections_queue_update(connections, update);
|
||||
}
|
||||
|
||||
static void _tf_ssb_connections_sync_broadcast_visit(
|
||||
const char* host, const struct sockaddr_in* addr, tf_ssb_broadcast_origin_t origin, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data)
|
||||
{
|
||||
tf_ssb_t* ssb = user_data;
|
||||
if (tunnel)
|
||||
{
|
||||
char target_id[k_id_base64_len] = { 0 };
|
||||
if (tf_ssb_id_bin_to_str(target_id, sizeof(target_id), pub))
|
||||
{
|
||||
char portal_id[k_id_base64_len] = { 0 };
|
||||
if (tf_ssb_connection_get_id(tunnel, portal_id, sizeof(portal_id)))
|
||||
{
|
||||
tf_ssb_tunnel_create(ssb, portal_id, target_id, k_tf_ssb_connect_flag_one_shot);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_ssb_connect(ssb, host, ntohs(addr->sin_port), pub, k_tf_ssb_connect_flag_one_shot);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct _tf_ssb_connections_get_all_work_t
|
||||
{
|
||||
char** connections;
|
||||
int connections_count;
|
||||
} tf_ssb_connections_get_all_work_t;
|
||||
|
||||
static void _tf_ssb_connections_get_all_work(tf_ssb_t* ssb, void* user_data)
|
||||
{
|
||||
tf_ssb_connections_get_all_work_t* work = user_data;
|
||||
sqlite3_stmt* statement;
|
||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||
if (sqlite3_prepare(db, "SELECT host, port, key FROM connections ORDER BY last_attempt", -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
while (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
const char* host = (const char*)sqlite3_column_text(statement, 0);
|
||||
int port = sqlite3_column_int(statement, 1);
|
||||
const char* key = (const char*)sqlite3_column_text(statement, 2);
|
||||
char connection[1024] = { 0 };
|
||||
snprintf(connection, sizeof(connection), "net:%s:%d~shs:%s", host, port, key);
|
||||
char* dot = strrchr(connection, '.');
|
||||
if (dot && strcmp(dot, ".ed25519") == 0)
|
||||
{
|
||||
*dot = '\0';
|
||||
}
|
||||
work->connections = tf_resize_vec(work->connections, sizeof(char*) * (work->connections_count + 1));
|
||||
work->connections[work->connections_count++] = tf_strdup(connection);
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("prepare: %s\n", sqlite3_errmsg(db));
|
||||
}
|
||||
tf_ssb_release_db_reader(ssb, db);
|
||||
}
|
||||
|
||||
static void _tf_ssb_connections_get_all_after_work(tf_ssb_t* ssb, int status, void* user_data)
|
||||
{
|
||||
tf_ssb_connections_get_all_work_t* work = user_data;
|
||||
for (int i = 0; i < work->connections_count; i++)
|
||||
{
|
||||
tf_printf("connections[%d] = %s\n", i, work->connections[i]);
|
||||
tf_ssb_connect_str(ssb, work->connections[i], k_tf_ssb_connect_flag_one_shot);
|
||||
tf_free(work->connections[i]);
|
||||
}
|
||||
tf_free(work->connections);
|
||||
tf_free(work);
|
||||
}
|
||||
|
||||
void tf_ssb_connections_sync_start(tf_ssb_connections_t* connections)
|
||||
{
|
||||
tf_ssb_connections_get_all_work_t* work = tf_malloc(sizeof(tf_ssb_connections_get_all_work_t));
|
||||
*work = (tf_ssb_connections_get_all_work_t) { 0 };
|
||||
tf_ssb_run_work(connections->ssb, _tf_ssb_connections_get_all_work, _tf_ssb_connections_get_all_after_work, work);
|
||||
tf_ssb_visit_broadcasts(connections->ssb, _tf_ssb_connections_sync_broadcast_visit, connections->ssb);
|
||||
}
|
||||
|
Reference in New Issue
Block a user