ssb: Respond to tunnel.endpoints. Patchwork didn't seem to like that we responded to tunnel.isRoom but not this.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 28m4s

This commit is contained in:
2025-01-11 09:23:12 -05:00
parent 872201c886
commit e59a00922b
3 changed files with 101 additions and 0 deletions

View File

@ -435,6 +435,36 @@ static void _tf_ssb_rpc_room_meta(tf_ssb_connection_t* connection, uint8_t flags
JS_FreeValue(context, response);
}
static void _tf_ssb_rpc_send_endpoints(tf_ssb_t* ssb)
{
JSContext* context = tf_ssb_get_context(ssb);
JSValue endpoints = JS_NewArray(context);
tf_ssb_connection_t* connections[1024];
int count = tf_ssb_get_connections(ssb, connections, tf_countof(connections));
int id_count = 0;
for (int i = 0; i < count; i++)
{
char id[k_id_base64_len] = { 0 };
if ((tf_ssb_connection_is_attendant(connections[i]) || tf_ssb_connection_is_endpoint(connections[i])) &&
tf_ssb_connection_is_connected(connections[i]) &&
tf_ssb_connection_get_id(connections[i], id, sizeof(id)))
{
JS_SetPropertyUint32(context, endpoints, id_count++, JS_NewString(context, id));
}
}
for (int i = 0; i < count; i++)
{
if (tf_ssb_connection_is_endpoint(connections[i]) && tf_ssb_connection_is_connected(connections[i]))
{
int32_t request_number = tf_ssb_connection_get_ebt_request_number(connections[i]);
tf_ssb_connection_rpc_send_json(connections[i], k_ssb_rpc_flag_json | k_ssb_rpc_flag_stream, -request_number, NULL, endpoints, NULL, NULL, NULL);
}
}
JS_FreeValue(context, endpoints);
}
static void _tf_ssb_rpc_room_attendants(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
{
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
@ -460,6 +490,7 @@ static void _tf_ssb_rpc_room_attendants(tf_ssb_connection_t* connection, uint8_t
tf_ssb_connection_t* connections[1024];
int count = tf_ssb_get_connections(ssb, connections, tf_countof(connections));
bool have_endpoints = false;
for (int i = 0; i < count; i++)
{
char id[k_id_base64_len] = { 0 };
@ -469,15 +500,37 @@ static void _tf_ssb_rpc_room_attendants(tf_ssb_connection_t* connection, uint8_t
tf_ssb_connection_rpc_send_json(connections[i], flags, -tf_ssb_connection_get_attendant_request_number(connections[i]), NULL, joined, NULL, NULL, NULL);
}
if (tf_ssb_connection_is_endpoint(connections[i]))
{
have_endpoints = true;
}
}
JS_SetPropertyStr(context, state, "ids", ids);
tf_ssb_connection_rpc_send_json(connection, flags, -request_number, NULL, state, NULL, NULL, NULL);
JS_FreeValue(context, joined);
JS_FreeValue(context, state);
if (have_endpoints)
{
_tf_ssb_rpc_send_endpoints(ssb);
}
tf_ssb_connection_set_attendant(connection, true, request_number);
}
static void _tf_ssb_rpc_tunnel_endpoints(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
{
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
if (!tf_ssb_is_room(ssb))
{
tf_ssb_connection_rpc_send_error_method_not_allowed(connection, flags, -request_number, "room.attendants");
return;
}
tf_ssb_connection_set_endpoint(connection, true, request_number);
_tf_ssb_rpc_send_endpoints(ssb);
}
typedef struct _blobs_get_t
{
char id[k_blob_id_len];
@ -1213,6 +1266,11 @@ static void _tf_ssb_rpc_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_chang
}
}
JS_FreeValue(context, left);
if (tf_ssb_connection_is_endpoint(connection) || tf_ssb_connection_is_attendant(connection))
{
_tf_ssb_rpc_send_endpoints(ssb);
}
}
}
}
@ -1577,6 +1635,7 @@ void tf_ssb_rpc_register(tf_ssb_t* ssb)
tf_ssb_add_rpc_callback(ssb, "blobs.createWants", _tf_ssb_rpc_blobs_createWants, NULL, NULL); /* SOURCE */
tf_ssb_add_rpc_callback(ssb, "tunnel.connect", _tf_ssb_rpc_tunnel_connect, NULL, NULL); /* DUPLEX */
tf_ssb_add_rpc_callback(ssb, "tunnel.isRoom", _tf_ssb_rpc_room_meta, NULL, NULL); /* FAKE-ASYNC */
tf_ssb_add_rpc_callback(ssb, "tunnel.endpoints", _tf_ssb_rpc_tunnel_endpoints, NULL, NULL); /* SOURCE */
tf_ssb_add_rpc_callback(ssb, "room.metadata", _tf_ssb_rpc_room_meta, NULL, NULL); /* ASYNC */
tf_ssb_add_rpc_callback(ssb, "room.attendants", _tf_ssb_rpc_room_attendants, NULL, NULL); /* SOURCE */
tf_ssb_add_rpc_callback(ssb, "createHistoryStream", _tf_ssb_rpc_createHistoryStream, NULL, NULL); /* SOURCE */