ssb: Tidy up some of the more common reasons for disconnect.
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled

This commit is contained in:
Cory McWilliams 2025-01-04 21:37:39 -05:00
parent 2f36db9142
commit aff98110e0
3 changed files with 45 additions and 6 deletions

View File

@ -1573,7 +1573,7 @@ static bool _tf_ssb_connection_recv_pop(tf_ssb_connection_t* connection, uint8_t
if (size >= sizeof(connection->recv_buffer))
{
char message[256];
snprintf(message, sizeof(message), "Trying to pop a message (%zd) larger than the connection's receive buffer (%zd).", size, sizeof(connection->recv_buffer));
snprintf(message, sizeof(message), "Message (%zd) larger than the connection's receive buffer (%zd)", size, sizeof(connection->recv_buffer));
tf_ssb_connection_close(connection, message);
}
if (connection->recv_size < size)
@ -1944,7 +1944,7 @@ static void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const ch
if (it->tunnel_connection == connection)
{
it->tunnel_connection = NULL;
tf_ssb_connection_close(it, "tunnel closed");
tf_ssb_connection_close(it, "Tunnel closed");
again = true;
break;
}
@ -2626,7 +2626,7 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
while (connection)
{
tf_ssb_connection_t* next = connection->next;
tf_ssb_connection_close(connection, "Shutting down.");
tf_ssb_connection_close(connection, "Shutting down");
connection = next;
}
uv_run(ssb->loop, UV_RUN_NOWAIT);
@ -2841,8 +2841,27 @@ static void _tf_ssb_connection_tunnel_callback(
tf_ssb_connection_remove_request(connection, -request_number);
tf_ssb_connection_rpc_send(connection, flags, -request_number, NULL, (const uint8_t*)"false", strlen("false"), NULL, NULL, NULL);
JSContext* context = tf_ssb_connection_get_context(connection);
JSValue message_val = JS_GetPropertyStr(context, args, "message");
JSValue stack_val = JS_GetPropertyStr(context, args, "stack");
char buffer[1024];
snprintf(buffer, sizeof(buffer), "tunnel error: %.*s", (int)size, message);
if (!JS_IsUndefined(message_val))
{
const char* message_string = JS_ToCString(context, message_val);
const char* stack_string = JS_ToCString(context, stack_val);
snprintf(buffer, sizeof(buffer), "Tunnel error: %s\n%s", message_string, stack_string);
JS_FreeCString(context, message_string);
JS_FreeCString(context, stack_string);
}
else
{
snprintf(buffer, sizeof(buffer), "Tunnel error: %.*s", (int)size, message);
}
JS_FreeValue(context, stack_val);
JS_FreeValue(context, message_val);
tf_ssb_connection_close(tunnel, buffer);
}
else

View File

@ -1198,7 +1198,7 @@ static JSValue _tf_ssb_closeConnection(JSContext* context, JSValueConst this_val
tf_ssb_connection_t* connection = tf_ssb_connection_get(ssb, id);
if (connection)
{
tf_ssb_connection_close(connection, "Close requested by user.");
tf_ssb_connection_close(connection, "Closed by user");
}
JS_FreeCString(context, id);
return connection ? JS_TRUE : JS_FALSE;

View File

@ -293,8 +293,28 @@ static void _tf_ssb_rpc_tunnel_callback(tf_ssb_connection_t* connection, uint8_t
if (flags & k_ssb_rpc_flag_end_error)
{
tf_ssb_connection_remove_request(connection, request_number);
JSContext* context = tf_ssb_connection_get_context(connection);
JSValue message_val = JS_GetPropertyStr(context, args, "message");
JSValue stack_val = JS_GetPropertyStr(context, args, "stack");
char buffer[1024];
snprintf(buffer, sizeof(buffer), "error from tunnel: %.*s", (int)size, message);
if (!JS_IsUndefined(message_val))
{
const char* message_string = JS_ToCString(context, message_val);
const char* stack_string = JS_ToCString(context, stack_val);
snprintf(buffer, sizeof(buffer), "Error from tunnel: %s\n%s", message_string, stack_string);
JS_FreeCString(context, message_string);
JS_FreeCString(context, stack_string);
}
else
{
snprintf(buffer, sizeof(buffer), "Error from tunnel: %.*s", (int)size, message);
}
JS_FreeValue(context, stack_val);
JS_FreeValue(context, message_val);
tf_ssb_connection_close(tun->connection, buffer);
}
else