forked from cory/tildefriends
Add missing .clang-format, and fix some spaces that slipped through.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4856 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -46,7 +46,7 @@ static int64_t _get_global_setting_int64(tf_ssb_t* ssb, const char* name, int64_
|
||||
}
|
||||
|
||||
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)
|
||||
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);
|
||||
@ -63,7 +63,7 @@ static void _tf_ssb_rpc_gossip_ping(tf_ssb_connection_t* connection, uint8_t fla
|
||||
}
|
||||
|
||||
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)
|
||||
tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
|
||||
{
|
||||
}
|
||||
|
||||
@ -102,7 +102,7 @@ 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);
|
||||
offset + k_send_max <= size ? k_send_max : (size - offset), NULL, NULL, NULL);
|
||||
}
|
||||
success = true;
|
||||
tf_free(blob);
|
||||
@ -111,8 +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)
|
||||
@ -169,7 +169,7 @@ static void _tf_ssb_request_blob_wants_work(tf_ssb_connection_t* connection, voi
|
||||
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)
|
||||
sqlite3_bind_int(statement, 3, _countof(work->out_id)) == SQLITE_OK)
|
||||
{
|
||||
while (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
@ -214,7 +214,7 @@ static void _tf_ssb_rpc_request_more_blobs(tf_ssb_connection_t* connection)
|
||||
}
|
||||
|
||||
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_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);
|
||||
@ -417,7 +417,7 @@ 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)
|
||||
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);
|
||||
@ -436,8 +436,8 @@ static void _tf_ssb_rpc_connection_blobs_get_callback(
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,13 +471,13 @@ static void _tf_ssb_rpc_connection_blobs_get(tf_ssb_connection_t* connection, co
|
||||
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_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)
|
||||
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)
|
||||
@ -553,7 +553,7 @@ static void _tf_ssb_rpc_connection_blobs_createWants_callback(
|
||||
}
|
||||
|
||||
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_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);
|
||||
@ -628,7 +628,7 @@ static bool _is_error(JSContext* context, JSValue message)
|
||||
}
|
||||
|
||||
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_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);
|
||||
@ -647,7 +647,7 @@ static void _tf_ssb_rpc_connection_tunnel_isRoom_callback(
|
||||
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_rpc_connection_room_attendants_callback, NULL, NULL);
|
||||
JS_FreeValue(context, message);
|
||||
}
|
||||
}
|
||||
@ -678,12 +678,13 @@ static void _tf_ssb_connection_send_history_stream_work(tf_ssb_connection_t* con
|
||||
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)
|
||||
"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)
|
||||
sqlite3_bind_int64(statement, 3, request->sequence + k_max) == SQLITE_OK)
|
||||
{
|
||||
JSMallocFunctions funcs = { 0 };
|
||||
tf_get_js_malloc_functions(&funcs);
|
||||
@ -696,8 +697,8 @@ static void _tf_ssb_connection_send_history_stream_work(tf_ssb_connection_t* con
|
||||
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));
|
||||
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);
|
||||
@ -744,7 +745,7 @@ 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);
|
||||
strlen(request->out_messages[i]), NULL, NULL, NULL);
|
||||
}
|
||||
if (!request->out_finished)
|
||||
{
|
||||
@ -777,7 +778,7 @@ static void _tf_ssb_connection_send_history_stream(tf_ssb_connection_t* connecti
|
||||
}
|
||||
|
||||
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_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);
|
||||
@ -897,7 +898,7 @@ static void _tf_ssb_rpc_ebt_replicate_send_clock_after_work(tf_ssb_connection_t*
|
||||
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);
|
||||
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);
|
||||
@ -1037,7 +1038,7 @@ static void _tf_ssb_rpc_ebt_replicate(tf_ssb_connection_t* connection, uint8_t f
|
||||
}
|
||||
|
||||
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_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);
|
||||
}
|
||||
@ -1068,7 +1069,7 @@ static void _tf_ssb_rpc_send_ebt_replicate(tf_ssb_connection_t* connection)
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
{
|
||||
@ -1091,7 +1092,7 @@ static void _tf_ssb_rpc_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_chang
|
||||
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_rpc_connection_blobs_createWants_callback, NULL, NULL);
|
||||
JS_FreeValue(context, message);
|
||||
|
||||
if (tf_ssb_connection_is_client(connection))
|
||||
@ -1102,8 +1103,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);
|
||||
@ -1125,8 +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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
JS_FreeValue(context, left);
|
||||
@ -1177,13 +1177,13 @@ static void _tf_ssb_rpc_delete_blobs_work(uv_work_t* work)
|
||||
const int k_limit = 128;
|
||||
int deleted = 0;
|
||||
if (sqlite3_prepare(db,
|
||||
"DELETE FROM blobs WHERE blobs.id IN ("
|
||||
" SELECT blobs.id FROM blobs "
|
||||
" 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)
|
||||
"DELETE FROM blobs WHERE blobs.id IN ("
|
||||
" SELECT blobs.id FROM blobs "
|
||||
" 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)
|
||||
{
|
||||
if (sqlite3_bind_int64(statement, 1, timestamp) == SQLITE_OK && sqlite3_bind_int(statement, 2, k_limit) == SQLITE_OK)
|
||||
{
|
||||
|
Reference in New Issue
Block a user