clang-format the source. Not exactly how I want it, but automated is better than perfect.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4845 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-02-15 23:35:01 +00:00
parent c8812b1add
commit fbc3cfeda4
37 changed files with 3141 additions and 1764 deletions

View File

@ -45,19 +45,12 @@ static int64_t _get_global_setting_int64(tf_ssb_t* ssb, const char* name, int64_
return result;
}
static void _tf_ssb_rpc_gossip_ping_callback(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
static void _tf_ssb_rpc_gossip_ping_callback(
tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
{
char buffer[256];
snprintf(buffer, sizeof(buffer), "%" PRId64, (int64_t)time(NULL) * 1000);
tf_ssb_connection_rpc_send(
connection,
flags,
-request_number,
(const uint8_t*)buffer,
strlen(buffer),
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send(connection, flags, -request_number, (const uint8_t*)buffer, strlen(buffer), NULL, NULL, NULL);
if (flags & k_ssb_rpc_flag_end_error)
{
tf_ssb_connection_remove_request(connection, request_number);
@ -69,7 +62,8 @@ static void _tf_ssb_rpc_gossip_ping(tf_ssb_connection_t* connection, uint8_t fla
tf_ssb_connection_add_request(connection, -request_number, _tf_ssb_rpc_gossip_ping_callback, NULL, NULL, NULL);
}
static void _tf_ssb_rpc_blobs_get_callback(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
static void _tf_ssb_rpc_blobs_get_callback(
tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
{
}
@ -107,15 +101,8 @@ static void _tf_ssb_rpc_blobs_get(tf_ssb_connection_t* connection, uint8_t flags
{
for (size_t offset = 0; offset < size; offset += k_send_max)
{
tf_ssb_connection_rpc_send(
connection,
k_ssb_rpc_flag_binary | k_ssb_rpc_flag_stream,
-request_number,
blob + offset,
offset + k_send_max <= size ? k_send_max : (size - offset),
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_binary | k_ssb_rpc_flag_stream, -request_number, blob + offset,
offset + k_send_max <= size ? k_send_max : (size - offset), NULL, NULL, NULL);
}
success = true;
tf_free(blob);
@ -124,15 +111,8 @@ static void _tf_ssb_rpc_blobs_get(tf_ssb_connection_t* connection, uint8_t flags
JS_FreeValue(context, arg);
}
JS_FreeValue(context, ids);
tf_ssb_connection_rpc_send(
connection,
k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error | k_ssb_rpc_flag_stream,
-request_number,
(const uint8_t*)(success ? "true" : "false"),
strlen(success ? "true" : "false"),
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error | k_ssb_rpc_flag_stream, -request_number,
(const uint8_t*)(success ? "true" : "false"), strlen(success ? "true" : "false"), NULL, NULL, NULL);
}
static void _tf_ssb_rpc_blobs_has(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
@ -146,15 +126,7 @@ static void _tf_ssb_rpc_blobs_has(tf_ssb_connection_t* connection, uint8_t flags
JS_FreeCString(context, id_str);
JS_FreeValue(context, id);
JS_FreeValue(context, ids);
tf_ssb_connection_rpc_send(
connection,
k_ssb_rpc_flag_json,
-request_number,
(const uint8_t*)(has ? "true" : "false"),
strlen(has ? "true" : "false"),
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json, -request_number, (const uint8_t*)(has ? "true" : "false"), strlen(has ? "true" : "false"), NULL, NULL, NULL);
}
static void _tf_ssb_rpc_blob_wants_added_callback(tf_ssb_t* ssb, const char* id, void* user_data)
@ -196,9 +168,8 @@ static void _tf_ssb_request_blob_wants_work(tf_ssb_connection_t* connection, voi
sqlite3_stmt* statement;
if (sqlite3_prepare(db, "SELECT id FROM blob_wants_view WHERE id > ? AND timestamp > ? ORDER BY id LIMIT ?", -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, blob_wants->last_id, -1, NULL) == SQLITE_OK &&
sqlite3_bind_int64(statement, 2, timestamp) == SQLITE_OK &&
sqlite3_bind_int(statement, 3, _countof(work->out_id)) == SQLITE_OK)
if (sqlite3_bind_text(statement, 1, blob_wants->last_id, -1, NULL) == SQLITE_OK && sqlite3_bind_int64(statement, 2, timestamp) == SQLITE_OK &&
sqlite3_bind_int(statement, 3, _countof(work->out_id)) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
@ -242,7 +213,8 @@ static void _tf_ssb_rpc_request_more_blobs(tf_ssb_connection_t* connection)
tf_ssb_connection_run_work(connection, _tf_ssb_request_blob_wants_work, _tf_ssb_request_blob_wants_after_work, work);
}
static void _tf_ssb_rpc_blobs_createWants(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
static void _tf_ssb_rpc_blobs_createWants(
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_blob_wants_t* blob_wants = tf_ssb_connection_get_blob_wants_state(connection);
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
@ -292,9 +264,7 @@ static void _tf_ssb_rpc_tunnel_connect(tf_ssb_connection_t* connection, uint8_t
JSValue portal = JS_GetPropertyStr(context, arg, "portal");
JSValue target = JS_GetPropertyStr(context, arg, "target");
if (JS_IsUndefined(origin) &&
!JS_IsUndefined(portal) &&
!JS_IsUndefined(target))
if (JS_IsUndefined(origin) && !JS_IsUndefined(portal) && !JS_IsUndefined(target))
{
const char* target_str = JS_ToCString(context, target);
@ -320,24 +290,15 @@ static void _tf_ssb_rpc_tunnel_connect(tf_ssb_connection_t* connection, uint8_t
JS_SetPropertyStr(context, message, "args", arg_array);
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "duplex"));
tf_ssb_connection_rpc_send_json(
target_connection,
k_ssb_rpc_flag_stream | k_ssb_rpc_flag_new_request,
tunnel_request_number,
message,
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send_json(target_connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_new_request, tunnel_request_number, message, NULL, NULL, NULL);
tunnel_t* data0 = tf_malloc(sizeof(tunnel_t));
*data0 = (tunnel_t)
{
*data0 = (tunnel_t) {
.connection = target_connection,
.request_number = tunnel_request_number,
};
tunnel_t* data1 = tf_malloc(sizeof(tunnel_t));
*data1 = (tunnel_t)
{
*data1 = (tunnel_t) {
.connection = connection,
.request_number = -request_number,
};
@ -353,9 +314,7 @@ static void _tf_ssb_rpc_tunnel_connect(tf_ssb_connection_t* connection, uint8_t
}
JS_FreeCString(context, target_str);
}
else if (!JS_IsUndefined(origin) &&
!JS_IsUndefined(portal) &&
!JS_IsUndefined(target))
else if (!JS_IsUndefined(origin) && !JS_IsUndefined(portal) && !JS_IsUndefined(target))
{
const char* origin_str = JS_ToCString(context, origin);
const char* portal_str = JS_ToCString(context, portal);
@ -389,14 +348,7 @@ static void _tf_ssb_rpc_room_meta(tf_ssb_connection_t* connection, uint8_t flags
JS_SetPropertyUint32(context, features, 2, JS_NewString(context, "room2"));
JS_SetPropertyStr(context, response, "features", features);
}
tf_ssb_connection_rpc_send_json(
connection,
flags,
-request_number,
response,
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send_json(connection, flags, -request_number, response, NULL, NULL, NULL);
JS_FreeValue(context, response);
}
@ -428,19 +380,11 @@ static void _tf_ssb_rpc_room_attendants(tf_ssb_connection_t* connection, uint8_t
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_get_id(connections[i], id, sizeof(id)))
if (tf_ssb_connection_is_attendant(connections[i]) && tf_ssb_connection_get_id(connections[i], id, sizeof(id)))
{
JS_SetPropertyUint32(context, ids, id_count++, JS_NewString(context, id));
tf_ssb_connection_rpc_send_json(
connections[i],
flags,
-tf_ssb_connection_get_attendant_request_number(connections[i]),
joined,
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send_json(connections[i], flags, -tf_ssb_connection_get_attendant_request_number(connections[i]), joined, NULL, NULL, NULL);
}
}
JS_SetPropertyStr(context, state, "ids", ids);
@ -472,7 +416,8 @@ static void _tf_ssb_rpc_blob_store_callback(const char* id, bool is_new, void* u
}
}
static void _tf_ssb_rpc_connection_blobs_get_callback(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
static void _tf_ssb_rpc_connection_blobs_get_callback(
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);
JSContext* context = tf_ssb_get_context(ssb);
@ -491,15 +436,8 @@ static void _tf_ssb_rpc_connection_blobs_get_callback(tf_ssb_connection_t* conne
}
/* TODO: Should we send the response in the callback? */
bool stored = true;
tf_ssb_connection_rpc_send(
connection,
k_ssb_rpc_flag_json | k_ssb_rpc_flag_stream | k_ssb_rpc_flag_end_error,
-request_number,
(const uint8_t*)(stored ? "true" : "false"),
strlen(stored ? "true" : "false"),
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_stream | k_ssb_rpc_flag_end_error, -request_number,
(const uint8_t*)(stored ? "true" : "false"), strlen(stored ? "true" : "false"), NULL, NULL, NULL);
}
}
@ -532,19 +470,14 @@ static void _tf_ssb_rpc_connection_blobs_get(tf_ssb_connection_t* connection, co
JS_SetPropertyUint32(context, args, 0, JS_NewString(context, blob_id));
JS_SetPropertyStr(context, message, "args", args);
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),
message,
_tf_ssb_rpc_connection_blobs_get_callback,
_tf_ssb_rpc_connection_blobs_get_cleanup,
get);
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), message,
_tf_ssb_rpc_connection_blobs_get_callback, _tf_ssb_rpc_connection_blobs_get_cleanup, get);
JS_FreeValue(context, message);
}
static void _tf_ssb_rpc_connection_blobs_createWants_callback(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
static void _tf_ssb_rpc_connection_blobs_createWants_callback(
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_blob_wants_t* blob_wants = tf_ssb_connection_get_blob_wants_state(connection);
if (!blob_wants)
@ -592,28 +525,14 @@ static void _tf_ssb_rpc_connection_blobs_createWants_callback(tf_ssb_connection_
{
JSValue message = JS_NewObject(context);
JS_SetPropertyStr(context, message, blob_id, JS_NewInt64(context, blob_size));
tf_ssb_connection_rpc_send_json(
connection,
k_ssb_rpc_flag_stream,
-blob_wants->request_number,
message,
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_stream, -blob_wants->request_number, message, NULL, NULL, NULL);
JS_FreeValue(context, message);
}
else if (size == -1LL)
{
JSValue message = JS_NewObject(context);
JS_SetPropertyStr(context, message, blob_id, JS_NewInt64(context, -2));
tf_ssb_connection_rpc_send_json(
connection,
k_ssb_rpc_flag_stream,
-blob_wants->request_number,
message,
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_stream, -blob_wants->request_number, message, NULL, NULL, NULL);
JS_FreeValue(context, message);
}
}
@ -633,7 +552,8 @@ static void _tf_ssb_rpc_connection_blobs_createWants_callback(tf_ssb_connection_
}
}
static void _tf_ssb_rpc_connection_room_attendants_callback(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
static void _tf_ssb_rpc_connection_room_attendants_callback(
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);
JSContext* context = tf_ssb_get_context(ssb);
@ -707,7 +627,8 @@ static bool _is_error(JSContext* context, JSValue message)
return is_error;
}
static void _tf_ssb_rpc_connection_tunnel_isRoom_callback(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
static void _tf_ssb_rpc_connection_tunnel_isRoom_callback(
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);
JSContext* context = tf_ssb_get_context(ssb);
@ -725,14 +646,8 @@ static void _tf_ssb_rpc_connection_tunnel_isRoom_callback(tf_ssb_connection_t* c
JS_SetPropertyStr(context, message, "name", name);
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "source"));
JS_SetPropertyStr(context, message, "args", JS_NewArray(context));
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),
message,
_tf_ssb_rpc_connection_room_attendants_callback,
NULL,
NULL);
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), message,
_tf_ssb_rpc_connection_room_attendants_callback, NULL, NULL);
JS_FreeValue(context, message);
}
}
@ -762,11 +677,13 @@ static void _tf_ssb_connection_send_history_stream_work(tf_ssb_connection_t* con
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
sqlite3_stmt* statement;
const int k_max = 32;
if (sqlite3_prepare(db, "SELECT previous, author, id, sequence, timestamp, hash, content, signature, sequence_before_author FROM messages WHERE author = ?1 AND sequence > ?2 AND sequence < ?3 ORDER BY sequence", -1, &statement, NULL) == SQLITE_OK)
if (sqlite3_prepare(db,
"SELECT previous, author, id, sequence, timestamp, hash, content, signature, sequence_before_author FROM messages WHERE author = ?1 AND sequence > ?2 AND sequence "
"< ?3 ORDER BY sequence",
-1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, request->author, -1, NULL) == SQLITE_OK &&
sqlite3_bind_int64(statement, 2, request->sequence) == SQLITE_OK &&
sqlite3_bind_int64(statement, 3, request->sequence + k_max) == SQLITE_OK)
if (sqlite3_bind_text(statement, 1, request->author, -1, NULL) == SQLITE_OK && sqlite3_bind_int64(statement, 2, request->sequence) == SQLITE_OK &&
sqlite3_bind_int64(statement, 3, request->sequence + k_max) == SQLITE_OK)
{
JSMallocFunctions funcs = { 0 };
tf_get_js_malloc_functions(&funcs);
@ -778,16 +695,9 @@ static void _tf_ssb_connection_send_history_stream_work(tf_ssb_connection_t* con
JSValue message = JS_UNDEFINED;
request->out_max_sequence_seen = sqlite3_column_int64(statement, 3);
JSValue formatted = tf_ssb_format_message(
context,
(const char*)sqlite3_column_text(statement, 0),
(const char*)sqlite3_column_text(statement, 1),
sqlite3_column_int64(statement, 3),
sqlite3_column_double(statement, 4),
(const char*)sqlite3_column_text(statement, 5),
(const char*)sqlite3_column_text(statement, 6),
(const char*)sqlite3_column_text(statement, 7),
sqlite3_column_int(statement, 8));
JSValue formatted = tf_ssb_format_message(context, (const char*)sqlite3_column_text(statement, 0), (const char*)sqlite3_column_text(statement, 1),
sqlite3_column_int64(statement, 3), sqlite3_column_double(statement, 4), (const char*)sqlite3_column_text(statement, 5),
(const char*)sqlite3_column_text(statement, 6), (const char*)sqlite3_column_text(statement, 7), sqlite3_column_int(statement, 8));
if (request->keys)
{
message = JS_NewObject(context);
@ -833,7 +743,8 @@ static void _tf_ssb_connection_send_history_stream_after_work(tf_ssb_connection_
{
for (int i = 0; i < request->out_messages_count; i++)
{
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_json, request->request_number, (const uint8_t*)request->out_messages[i], strlen(request->out_messages[i]), NULL, NULL, NULL);
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_json, request->request_number, (const uint8_t*)request->out_messages[i],
strlen(request->out_messages[i]), NULL, NULL, NULL);
}
if (!request->out_finished)
{
@ -841,15 +752,7 @@ static void _tf_ssb_connection_send_history_stream_after_work(tf_ssb_connection_
}
else if (!request->live)
{
tf_ssb_connection_rpc_send(
connection,
k_ssb_rpc_flag_json,
request->request_number,
(const uint8_t*)"false",
strlen("false"),
NULL,
NULL,
NULL);
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json, request->request_number, (const uint8_t*)"false", strlen("false"), NULL, NULL, NULL);
}
}
for (int i = 0; i < request->out_messages_count; i++)
@ -863,8 +766,7 @@ static void _tf_ssb_connection_send_history_stream_after_work(tf_ssb_connection_
static void _tf_ssb_connection_send_history_stream(tf_ssb_connection_t* connection, int32_t request_number, const char* author, int64_t sequence, bool keys, bool live)
{
tf_ssb_connection_send_history_stream_t* async = tf_malloc(sizeof(tf_ssb_connection_send_history_stream_t));
*async = (tf_ssb_connection_send_history_stream_t)
{
*async = (tf_ssb_connection_send_history_stream_t) {
.request_number = request_number,
.sequence = sequence,
.keys = keys,
@ -874,7 +776,8 @@ static void _tf_ssb_connection_send_history_stream(tf_ssb_connection_t* connecti
tf_ssb_connection_run_work(connection, _tf_ssb_connection_send_history_stream_work, _tf_ssb_connection_send_history_stream_after_work, async);
}
static void _tf_ssb_rpc_createHistoryStream(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
static void _tf_ssb_rpc_createHistoryStream(
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);
JSContext* context = tf_ssb_get_context(ssb);
@ -993,7 +896,8 @@ static void _tf_ssb_rpc_ebt_replicate_send_clock_after_work(tf_ssb_connection_t*
tf_free(work->clock);
if (work->out_clock)
{
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_json, -work->request_number, (const uint8_t*)work->out_clock, strlen(work->out_clock), NULL, NULL, NULL);
tf_ssb_connection_rpc_send(
connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_json, -work->request_number, (const uint8_t*)work->out_clock, strlen(work->out_clock), NULL, NULL, NULL);
tf_free(work->out_clock);
}
tf_free(work);
@ -1002,8 +906,7 @@ static void _tf_ssb_rpc_ebt_replicate_send_clock_after_work(tf_ssb_connection_t*
static void _tf_ssb_rpc_ebt_replicate_send_clock(tf_ssb_connection_t* connection, int32_t request_number, JSValue message)
{
ebt_replicate_send_clock_t* work = tf_malloc(sizeof(ebt_replicate_send_clock_t));
*work = (ebt_replicate_send_clock_t)
{
*work = (ebt_replicate_send_clock_t) {
.request_number = request_number,
};
JSContext* context = tf_ssb_connection_get_context(connection);
@ -1133,7 +1036,8 @@ static void _tf_ssb_rpc_ebt_replicate(tf_ssb_connection_t* connection, uint8_t f
JS_FreeValue(context, author);
}
static void _tf_ssb_rpc_ebt_replicate_client(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
static void _tf_ssb_rpc_ebt_replicate_client(
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_rpc_ebt_replicate(connection, flags, request_number, args, message, size, user_data);
}
@ -1155,14 +1059,7 @@ static void _tf_ssb_rpc_send_ebt_replicate(tf_ssb_connection_t* connection)
JS_SetPropertyStr(context, message, "args", args);
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "duplex"));
int32_t request_number = tf_ssb_connection_next_request_number(connection);
tf_ssb_connection_rpc_send_json(
connection,
k_ssb_rpc_flag_stream | k_ssb_rpc_flag_new_request,
request_number,
message,
_tf_ssb_rpc_ebt_replicate_client,
NULL,
NULL);
tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_new_request, request_number, message, _tf_ssb_rpc_ebt_replicate_client, NULL, NULL);
if (!tf_ssb_connection_get_ebt_request_number(connection))
{
tf_ssb_connection_set_ebt_request_number(connection, request_number);
@ -1170,7 +1067,8 @@ static void _tf_ssb_rpc_send_ebt_replicate(tf_ssb_connection_t* connection)
JS_FreeValue(context, message);
}
static void _tf_ssb_rpc_ebt_replicate_server(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
static void _tf_ssb_rpc_ebt_replicate_server(
tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
{
if (flags & k_ssb_rpc_flag_end_error)
{
@ -1192,14 +1090,8 @@ static void _tf_ssb_rpc_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_chang
JS_SetPropertyStr(context, message, "name", name);
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "source"));
JS_SetPropertyStr(context, message, "args", JS_NewArray(context));
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),
message,
_tf_ssb_rpc_connection_blobs_createWants_callback,
NULL,
NULL);
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), message,
_tf_ssb_rpc_connection_blobs_createWants_callback, NULL, NULL);
JS_FreeValue(context, message);
if (tf_ssb_connection_is_client(connection))
@ -1210,14 +1102,8 @@ static void _tf_ssb_rpc_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_chang
JS_SetPropertyUint32(context, name, 1, JS_NewString(context, "isRoom"));
JS_SetPropertyStr(context, message, "name", name);
JS_SetPropertyStr(context, message, "args", JS_NewArray(context));
tf_ssb_connection_rpc_send_json(
connection,
k_ssb_rpc_flag_new_request,
tf_ssb_connection_next_request_number(connection),
message,
_tf_ssb_rpc_connection_tunnel_isRoom_callback,
NULL,
NULL);
tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_new_request, tf_ssb_connection_next_request_number(connection), message,
_tf_ssb_rpc_connection_tunnel_isRoom_callback, NULL, NULL);
JS_FreeValue(context, message);
_tf_ssb_rpc_send_ebt_replicate(connection);
@ -1240,13 +1126,7 @@ static void _tf_ssb_rpc_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_chang
if (tf_ssb_connection_is_attendant(connections[i]))
{
tf_ssb_connection_rpc_send_json(
connections[i],
k_ssb_rpc_flag_stream,
-tf_ssb_connection_get_attendant_request_number(connections[i]),
left,
NULL,
NULL,
NULL);
connections[i], k_ssb_rpc_flag_stream, -tf_ssb_connection_get_attendant_request_number(connections[i]), left, NULL, NULL, NULL);
}
}
JS_FreeValue(context, left);
@ -1302,10 +1182,10 @@ static void _tf_ssb_rpc_delete_blobs_work(uv_work_t* work)
" JOIN messages_refs ON blobs.id = messages_refs.ref "
" JOIN messages ON messages.id = messages_refs.message "
" WHERE blobs.created < ?1 / 1000 "
" GROUP BY blobs.id HAVING MAX(messages.timestamp) < ?1 LIMIT ?2)", -1, &statement, NULL) == SQLITE_OK)
" GROUP BY blobs.id HAVING MAX(messages.timestamp) < ?1 LIMIT ?2)",
-1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_int64(statement, 1, timestamp) == SQLITE_OK &&
sqlite3_bind_int(statement, 2, k_limit) == SQLITE_OK)
if (sqlite3_bind_int64(statement, 1, timestamp) == SQLITE_OK && sqlite3_bind_int(statement, 2, k_limit) == SQLITE_OK)
{
int r = sqlite3_step(statement);
if (r != SQLITE_DONE)
@ -1341,7 +1221,7 @@ static void _tf_ssb_rpc_delete_blobs_after_work(uv_work_t* work, int status)
static void _tf_ssb_rpc_start_delete_callback(tf_ssb_t* ssb, void* user_data)
{
delete_blobs_work_t* work = tf_malloc(sizeof(delete_blobs_work_t));
*work = (delete_blobs_work_t) { .work = { .data = work}, .ssb = ssb };
*work = (delete_blobs_work_t) { .work = { .data = work }, .ssb = ssb };
tf_ssb_ref(ssb);
int r = uv_queue_work(tf_ssb_get_loop(ssb), &work->work, _tf_ssb_rpc_delete_blobs_work, _tf_ssb_rpc_delete_blobs_after_work);
if (r)