make format
This commit is contained in:
parent
5231ec22e7
commit
17667b4cf8
18
src/ssb.c
18
src/ssb.c
@ -484,7 +484,8 @@ static void _tf_ssb_write(tf_ssb_connection_t* connection, void* data, size_t si
|
|||||||
}
|
}
|
||||||
else if (connection->tunnel_connection)
|
else if (connection->tunnel_connection)
|
||||||
{
|
{
|
||||||
tf_ssb_connection_rpc_send(connection->tunnel_connection, k_ssb_rpc_flag_binary | k_ssb_rpc_flag_stream, -connection->tunnel_request_number, NULL, data, size, NULL, NULL, NULL);
|
tf_ssb_connection_rpc_send(
|
||||||
|
connection->tunnel_connection, k_ssb_rpc_flag_binary | k_ssb_rpc_flag_stream, -connection->tunnel_request_number, NULL, data, size, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,8 +643,8 @@ static bool _tf_ssb_connection_get_request_callback(tf_ssb_connection_t* connect
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t request_number, const char* name, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data,
|
void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t request_number, const char* name, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup,
|
||||||
tf_ssb_connection_t* dependent_connection)
|
void* user_data, tf_ssb_connection_t* dependent_connection)
|
||||||
{
|
{
|
||||||
tf_ssb_request_t* existing =
|
tf_ssb_request_t* existing =
|
||||||
connection->requests_count ? bsearch(&request_number, connection->requests, connection->requests_count, sizeof(tf_ssb_request_t), _request_compare) : NULL;
|
connection->requests_count ? bsearch(&request_number, connection->requests, connection->requests_count, sizeof(tf_ssb_request_t), _request_compare) : NULL;
|
||||||
@ -745,8 +746,8 @@ void tf_ssb_connection_remove_request(tf_ssb_connection_t* connection, int32_t r
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const char* new_request_name, const uint8_t* message, size_t size, tf_ssb_rpc_callback_t* callback,
|
void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const char* new_request_name, const uint8_t* message, size_t size,
|
||||||
tf_ssb_callback_cleanup_t* cleanup, void* user_data)
|
tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data)
|
||||||
{
|
{
|
||||||
if (!connection)
|
if (!connection)
|
||||||
{
|
{
|
||||||
@ -795,14 +796,15 @@ void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tf_ssb_connection_rpc_send_json(
|
void tf_ssb_connection_rpc_send_json(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const char* new_request_name, JSValue message,
|
||||||
tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const char* new_request_name, JSValue message, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data)
|
tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data)
|
||||||
{
|
{
|
||||||
JSContext* context = connection->ssb->context;
|
JSContext* context = connection->ssb->context;
|
||||||
JSValue json = JS_JSONStringify(context, message, JS_NULL, JS_NULL);
|
JSValue json = JS_JSONStringify(context, message, JS_NULL, JS_NULL);
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
const char* json_string = JS_ToCStringLen(context, &size, json);
|
const char* json_string = JS_ToCStringLen(context, &size, json);
|
||||||
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | (flags & ~k_ssb_rpc_mask_type), request_number, new_request_name, (const uint8_t*)json_string, size, callback, cleanup, user_data);
|
tf_ssb_connection_rpc_send(
|
||||||
|
connection, k_ssb_rpc_flag_json | (flags & ~k_ssb_rpc_mask_type), request_number, new_request_name, (const uint8_t*)json_string, size, callback, cleanup, user_data);
|
||||||
JS_FreeCString(context, json_string);
|
JS_FreeCString(context, json_string);
|
||||||
JS_FreeValue(context, json);
|
JS_FreeValue(context, json);
|
||||||
}
|
}
|
||||||
|
12
src/ssb.h
12
src/ssb.h
@ -666,8 +666,8 @@ void tf_ssb_remove_rpc_callback(tf_ssb_t* ssb, const char** name, tf_ssb_rpc_cal
|
|||||||
** @param cleanup A callback to call if the callback is removed.
|
** @param cleanup A callback to call if the callback is removed.
|
||||||
** @param user_data User data to pass to the callback.
|
** @param user_data User data to pass to the callback.
|
||||||
*/
|
*/
|
||||||
void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const char* new_request_name, const uint8_t* message, size_t size, tf_ssb_rpc_callback_t* callback,
|
void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const char* new_request_name, const uint8_t* message, size_t size,
|
||||||
tf_ssb_callback_cleanup_t* cleanup, void* user_data);
|
tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Send a JSON MUXRPC message.
|
** Send a JSON MUXRPC message.
|
||||||
@ -680,8 +680,8 @@ void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags,
|
|||||||
** @param cleanup A callback to call if the callback is removed.
|
** @param cleanup A callback to call if the callback is removed.
|
||||||
** @param user_data User data to pass to the callback.
|
** @param user_data User data to pass to the callback.
|
||||||
*/
|
*/
|
||||||
void tf_ssb_connection_rpc_send_json(
|
void tf_ssb_connection_rpc_send_json(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const char* new_request_name, JSValue message,
|
||||||
tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const char* new_request_name, JSValue message, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data);
|
tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Send a MUXRPC error message.
|
** Send a MUXRPC error message.
|
||||||
@ -712,8 +712,8 @@ void tf_ssb_connection_rpc_send_error_method_not_allowed(tf_ssb_connection_t* co
|
|||||||
** @param user_data User data to pass to the callback.
|
** @param user_data User data to pass to the callback.
|
||||||
** @param dependent_connection A connection, which, if removed, invalidates this request.
|
** @param dependent_connection A connection, which, if removed, invalidates this request.
|
||||||
*/
|
*/
|
||||||
void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t request_number, const char* name, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data,
|
void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t request_number, const char* name, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup,
|
||||||
tf_ssb_connection_t* dependent_connection);
|
void* user_data, tf_ssb_connection_t* dependent_connection);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Remove a callback registered to be called when a message is received for the
|
** Remove a callback registered to be called when a message is received for the
|
||||||
|
@ -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, arg);
|
||||||
}
|
}
|
||||||
JS_FreeValue(context, ids);
|
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, NULL, (const uint8_t*)(success ? "true" : "false"),
|
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error | k_ssb_rpc_flag_stream, -request_number, NULL,
|
||||||
strlen(success ? "true" : "false"), NULL, NULL, NULL);
|
(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)
|
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)
|
||||||
@ -290,7 +290,8 @@ 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, "args", arg_array);
|
||||||
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "duplex"));
|
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, "tunnel.connect", 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, "tunnel.connect", message, NULL, NULL, NULL);
|
||||||
|
|
||||||
tunnel_t* data0 = tf_malloc(sizeof(tunnel_t));
|
tunnel_t* data0 = tf_malloc(sizeof(tunnel_t));
|
||||||
*data0 = (tunnel_t) {
|
*data0 = (tunnel_t) {
|
||||||
@ -436,8 +437,8 @@ static void _tf_ssb_rpc_connection_blobs_get_callback(
|
|||||||
}
|
}
|
||||||
/* TODO: Should we send the response in the callback? */
|
/* TODO: Should we send the response in the callback? */
|
||||||
bool stored = true;
|
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, NULL, (const uint8_t*)(stored ? "true" : "false"),
|
tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_stream | k_ssb_rpc_flag_end_error, -request_number, NULL,
|
||||||
strlen(stored ? "true" : "false"), NULL, NULL, NULL);
|
(const uint8_t*)(stored ? "true" : "false"), strlen(stored ? "true" : "false"), NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -646,8 +647,8 @@ static void _tf_ssb_rpc_connection_tunnel_isRoom_callback(
|
|||||||
JS_SetPropertyStr(context, message, "name", name);
|
JS_SetPropertyStr(context, message, "name", name);
|
||||||
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "source"));
|
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "source"));
|
||||||
JS_SetPropertyStr(context, message, "args", JS_NewArray(context));
|
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), "room.attendants", 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), "room.attendants",
|
||||||
_tf_ssb_rpc_connection_room_attendants_callback, NULL, NULL);
|
message, _tf_ssb_rpc_connection_room_attendants_callback, NULL, NULL);
|
||||||
JS_FreeValue(context, message);
|
JS_FreeValue(context, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1060,7 +1061,8 @@ static void _tf_ssb_rpc_send_ebt_replicate(tf_ssb_connection_t* connection)
|
|||||||
JS_SetPropertyStr(context, message, "args", args);
|
JS_SetPropertyStr(context, message, "args", args);
|
||||||
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "duplex"));
|
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "duplex"));
|
||||||
int32_t request_number = tf_ssb_connection_next_request_number(connection);
|
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, "ebt.replicate", 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, "ebt.replicate", message, _tf_ssb_rpc_ebt_replicate_client, NULL, NULL);
|
||||||
if (!tf_ssb_connection_get_ebt_request_number(connection))
|
if (!tf_ssb_connection_get_ebt_request_number(connection))
|
||||||
{
|
{
|
||||||
tf_ssb_connection_set_ebt_request_number(connection, request_number);
|
tf_ssb_connection_set_ebt_request_number(connection, request_number);
|
||||||
@ -1091,8 +1093,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, "name", name);
|
||||||
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "source"));
|
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "source"));
|
||||||
JS_SetPropertyStr(context, message, "args", JS_NewArray(context));
|
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), "blobs.createWants", 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",
|
||||||
_tf_ssb_rpc_connection_blobs_createWants_callback, NULL, NULL);
|
message, _tf_ssb_rpc_connection_blobs_createWants_callback, NULL, NULL);
|
||||||
JS_FreeValue(context, message);
|
JS_FreeValue(context, message);
|
||||||
|
|
||||||
if (tf_ssb_connection_is_client(connection))
|
if (tf_ssb_connection_is_client(connection))
|
||||||
@ -1103,8 +1105,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_SetPropertyUint32(context, name, 1, JS_NewString(context, "isRoom"));
|
||||||
JS_SetPropertyStr(context, message, "name", name);
|
JS_SetPropertyStr(context, message, "name", name);
|
||||||
JS_SetPropertyStr(context, message, "args", JS_NewArray(context));
|
JS_SetPropertyStr(context, message, "args", JS_NewArray(context));
|
||||||
tf_ssb_connection_rpc_send_json(
|
tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_new_request, tf_ssb_connection_next_request_number(connection), "tunnel.isRoom", message,
|
||||||
connection, k_ssb_rpc_flag_new_request, tf_ssb_connection_next_request_number(connection), "tunnel.isRoom", message, _tf_ssb_rpc_connection_tunnel_isRoom_callback, NULL, NULL);
|
_tf_ssb_rpc_connection_tunnel_isRoom_callback, NULL, NULL);
|
||||||
JS_FreeValue(context, message);
|
JS_FreeValue(context, message);
|
||||||
|
|
||||||
_tf_ssb_rpc_send_ebt_replicate(connection);
|
_tf_ssb_rpc_send_ebt_replicate(connection);
|
||||||
@ -1126,7 +1128,8 @@ static void _tf_ssb_rpc_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_chang
|
|||||||
{
|
{
|
||||||
if (tf_ssb_connection_is_attendant(connections[i]))
|
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]), NULL, 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]), NULL, left, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JS_FreeValue(context, left);
|
JS_FreeValue(context, left);
|
||||||
|
@ -715,8 +715,8 @@ static void _close_callback(uv_timer_t* timer)
|
|||||||
close_t* data = timer->data;
|
close_t* data = timer->data;
|
||||||
tf_printf("breaking %s %p\n", data->id, data->connection);
|
tf_printf("breaking %s %p\n", data->id, data->connection);
|
||||||
const char* message = "{\"name\":\"Error\",\"message\":\"whoops\",\"stack\":\"nah\"}";
|
const char* message = "{\"name\":\"Error\",\"message\":\"whoops\",\"stack\":\"nah\"}";
|
||||||
tf_ssb_connection_rpc_send(
|
tf_ssb_connection_rpc_send(data->connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error, data->request_number, NULL, (const uint8_t*)message,
|
||||||
data->connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error, data->request_number, NULL, (const uint8_t*)message, strlen(message), NULL, NULL, NULL);
|
strlen(message), NULL, NULL, NULL);
|
||||||
uv_close((uv_handle_t*)timer, _timer_close);
|
uv_close((uv_handle_t*)timer, _timer_close);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user