From 36e82b987340ab898b5fe6bd40e11f02d6802f53 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 8 Oct 2024 19:10:33 -0400 Subject: [PATCH] ssb: Sync now connects to room members one level deep. --- src/ssb.rpc.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/ssb.rpc.c b/src/ssb.rpc.c index 7927e2a0..da63ec22 100644 --- a/src/ssb.rpc.c +++ b/src/ssb.rpc.c @@ -1295,6 +1295,28 @@ static void _tf_ssb_rpc_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_chang } } +static void _tf_ssb_rpc_broadcasts_changed_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 && + (tf_ssb_connection_get_flags(tunnel) & k_tf_ssb_connect_flag_one_shot) != 0 && + !tf_ssb_connection_get_tunnel(tunnel)) + { + char target_id[k_id_base64_len] = { 0 }; + char portal_id[k_id_base64_len] = { 0 }; + if (tf_ssb_id_bin_to_str(target_id, sizeof(target_id), pub) && + 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); + } + } +} + +static void _tf_ssb_rpc_broadcasts_changed_callback(tf_ssb_t* ssb, void* user_data) +{ + tf_ssb_visit_broadcasts(ssb, _tf_ssb_rpc_broadcasts_changed_visit, ssb); +} + static void _tf_ssb_rpc_checkpoint(tf_ssb_t* ssb) { int64_t checkpoint_start_ms = uv_hrtime(); @@ -1520,6 +1542,7 @@ static void _tf_ssb_rpc_peers_exchange(tf_ssb_connection_t* connection, uint8_t void tf_ssb_rpc_register(tf_ssb_t* ssb) { tf_ssb_add_connections_changed_callback(ssb, _tf_ssb_rpc_connections_changed_callback, NULL, NULL); + tf_ssb_add_broadcasts_changed_callback(ssb, _tf_ssb_rpc_broadcasts_changed_callback, NULL, NULL); tf_ssb_add_rpc_callback(ssb, "gossip.ping", _tf_ssb_rpc_gossip_ping, NULL, NULL); /* DUPLEX */ tf_ssb_add_rpc_callback(ssb, "blobs.get", _tf_ssb_rpc_blobs_get, NULL, NULL); /* SOURCE */ tf_ssb_add_rpc_callback(ssb, "blobs.has", _tf_ssb_rpc_blobs_has, NULL, NULL); /* ASYNC */