Clean up some error'd RPC requests. Don't send blobs.createWants if we're not replicating.

This commit is contained in:
Cory McWilliams 2024-08-24 10:39:47 -04:00
parent 8ac3c5ea22
commit f543cc642e

View File

@ -605,6 +605,7 @@ static void _tf_ssb_rpc_connection_blobs_createWants_callback(
if (!JS_IsUndefined(name)) if (!JS_IsUndefined(name))
{ {
/* { name: "Error" } */ /* { name: "Error" } */
tf_ssb_connection_remove_request(connection, -request_number);
JS_FreeValue(context, name); JS_FreeValue(context, name);
return; return;
} }
@ -1136,6 +1137,7 @@ static void _tf_ssb_rpc_ebt_replicate(tf_ssb_connection_t* connection, uint8_t f
if (_is_error(context, args)) if (_is_error(context, args))
{ {
/* TODO: Send createHistoryStream. */ /* TODO: Send createHistoryStream. */
tf_ssb_connection_remove_request(connection, -request_number);
return; return;
} }
@ -1222,21 +1224,24 @@ static void _tf_ssb_rpc_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_chang
JSContext* context = tf_ssb_get_context(ssb); JSContext* context = tf_ssb_get_context(ssb);
if (change == k_tf_ssb_change_connect) if (change == k_tf_ssb_change_connect)
{ {
JSValue message = JS_NewObject(context); if (tf_ssb_is_replicator(ssb))
JSValue name = JS_NewArray(context); {
JS_SetPropertyUint32(context, name, 0, JS_NewString(context, "blobs")); JSValue message = JS_NewObject(context);
JS_SetPropertyUint32(context, name, 1, JS_NewString(context, "createWants")); JSValue name = JS_NewArray(context);
JS_SetPropertyStr(context, message, "name", name); JS_SetPropertyUint32(context, name, 0, JS_NewString(context, "blobs"));
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "source")); JS_SetPropertyUint32(context, name, 1, JS_NewString(context, "createWants"));
JS_SetPropertyStr(context, message, "args", JS_NewArray(context)); JS_SetPropertyStr(context, message, "name", name);
tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_new_request, tf_ssb_connection_next_request_number(connection), "blobs.createWants", JS_SetPropertyStr(context, message, "type", JS_NewString(context, "source"));
message, _tf_ssb_rpc_connection_blobs_createWants_callback, NULL, NULL); JS_SetPropertyStr(context, message, "args", JS_NewArray(context));
JS_FreeValue(context, message); tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_new_request, tf_ssb_connection_next_request_number(connection), "blobs.createWants",
message, _tf_ssb_rpc_connection_blobs_createWants_callback, NULL, NULL);
JS_FreeValue(context, message);
}
if (tf_ssb_connection_is_client(connection)) if (tf_ssb_connection_is_client(connection))
{ {
message = JS_NewObject(context); JSValue message = JS_NewObject(context);
name = JS_NewArray(context); JSValue name = JS_NewArray(context);
JS_SetPropertyUint32(context, name, 0, JS_NewString(context, "tunnel")); JS_SetPropertyUint32(context, name, 0, JS_NewString(context, "tunnel"));
JS_SetPropertyUint32(context, name, 1, JS_NewString(context, "isRoom")); JS_SetPropertyUint32(context, name, 1, JS_NewString(context, "isRoom"));
JS_SetPropertyStr(context, message, "name", name); JS_SetPropertyStr(context, message, "name", name);