ssb: Disabling room support only disables the ability to tunnel through ourselves, not receive tunneled connections.
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
This commit is contained in:
@ -349,11 +349,6 @@ static void _tf_ssb_rpc_tunnel_cleanup(tf_ssb_t* ssb, void* user_data)
|
|||||||
static void _tf_ssb_rpc_tunnel_connect(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_tunnel_connect(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);
|
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
|
||||||
if (!tf_ssb_is_room(ssb))
|
|
||||||
{
|
|
||||||
tf_ssb_connection_rpc_send_error_method_not_allowed(connection, flags, -request_number, "tunnel.connect");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSContext* context = tf_ssb_connection_get_context(connection);
|
JSContext* context = tf_ssb_connection_get_context(connection);
|
||||||
JSValue arg_array = JS_GetPropertyStr(context, args, "args");
|
JSValue arg_array = JS_GetPropertyStr(context, args, "args");
|
||||||
@ -364,54 +359,62 @@ static void _tf_ssb_rpc_tunnel_connect(tf_ssb_connection_t* connection, uint8_t
|
|||||||
|
|
||||||
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);
|
if (!tf_ssb_is_room(ssb))
|
||||||
|
|
||||||
tf_ssb_connection_t* target_connection = tf_ssb_connection_get(ssb, target_str);
|
|
||||||
if (target_connection)
|
|
||||||
{
|
{
|
||||||
int32_t tunnel_request_number = tf_ssb_connection_next_request_number(target_connection);
|
tf_ssb_connection_rpc_send_error_method_not_allowed(connection, flags, -request_number, "tunnel.connect");
|
||||||
const char* portal_str = JS_ToCString(context, portal);
|
|
||||||
|
|
||||||
JSValue message = JS_NewObject(context);
|
|
||||||
JSValue name = JS_NewArray(context);
|
|
||||||
JS_SetPropertyUint32(context, name, 0, JS_NewString(context, "tunnel"));
|
|
||||||
JS_SetPropertyUint32(context, name, 1, JS_NewString(context, "connect"));
|
|
||||||
JS_SetPropertyStr(context, message, "name", name);
|
|
||||||
JSValue arg_obj = JS_NewObject(context);
|
|
||||||
char origin_str[k_id_base64_len] = "";
|
|
||||||
tf_ssb_connection_get_id(connection, origin_str, sizeof(origin_str));
|
|
||||||
JS_SetPropertyStr(context, arg_obj, "origin", JS_NewString(context, origin_str));
|
|
||||||
JS_SetPropertyStr(context, arg_obj, "portal", JS_NewString(context, portal_str));
|
|
||||||
JS_SetPropertyStr(context, arg_obj, "target", JS_NewString(context, target_str));
|
|
||||||
JSValue arg_array = JS_NewArray(context);
|
|
||||||
JS_SetPropertyUint32(context, arg_array, 0, arg_obj);
|
|
||||||
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, "tunnel.connect", message, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
tunnel_t* data0 = tf_malloc(sizeof(tunnel_t));
|
|
||||||
*data0 = (tunnel_t) {
|
|
||||||
.connection = target_connection,
|
|
||||||
.request_number = tunnel_request_number,
|
|
||||||
};
|
|
||||||
tunnel_t* data1 = tf_malloc(sizeof(tunnel_t));
|
|
||||||
*data1 = (tunnel_t) {
|
|
||||||
.connection = connection,
|
|
||||||
.request_number = -request_number,
|
|
||||||
};
|
|
||||||
tf_ssb_connection_add_request(connection, -request_number, "tunnel.connect", _tf_ssb_rpc_tunnel_callback, _tf_ssb_rpc_tunnel_cleanup, data0, target_connection);
|
|
||||||
tf_ssb_connection_add_request(target_connection, tunnel_request_number, "tunnel.connect", _tf_ssb_rpc_tunnel_callback, _tf_ssb_rpc_tunnel_cleanup, data1, connection);
|
|
||||||
|
|
||||||
JS_FreeValue(context, message);
|
|
||||||
JS_FreeCString(context, portal_str);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tf_ssb_connection_rpc_send_error(connection, flags, -request_number, "Connection not found.");
|
const char* target_str = JS_ToCString(context, target);
|
||||||
|
|
||||||
|
tf_ssb_connection_t* target_connection = tf_ssb_connection_get(ssb, target_str);
|
||||||
|
if (target_connection)
|
||||||
|
{
|
||||||
|
int32_t tunnel_request_number = tf_ssb_connection_next_request_number(target_connection);
|
||||||
|
const char* portal_str = JS_ToCString(context, portal);
|
||||||
|
|
||||||
|
JSValue message = JS_NewObject(context);
|
||||||
|
JSValue name = JS_NewArray(context);
|
||||||
|
JS_SetPropertyUint32(context, name, 0, JS_NewString(context, "tunnel"));
|
||||||
|
JS_SetPropertyUint32(context, name, 1, JS_NewString(context, "connect"));
|
||||||
|
JS_SetPropertyStr(context, message, "name", name);
|
||||||
|
JSValue arg_obj = JS_NewObject(context);
|
||||||
|
char origin_str[k_id_base64_len] = "";
|
||||||
|
tf_ssb_connection_get_id(connection, origin_str, sizeof(origin_str));
|
||||||
|
JS_SetPropertyStr(context, arg_obj, "origin", JS_NewString(context, origin_str));
|
||||||
|
JS_SetPropertyStr(context, arg_obj, "portal", JS_NewString(context, portal_str));
|
||||||
|
JS_SetPropertyStr(context, arg_obj, "target", JS_NewString(context, target_str));
|
||||||
|
JSValue arg_array = JS_NewArray(context);
|
||||||
|
JS_SetPropertyUint32(context, arg_array, 0, arg_obj);
|
||||||
|
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, "tunnel.connect", message, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
tunnel_t* data0 = tf_malloc(sizeof(tunnel_t));
|
||||||
|
*data0 = (tunnel_t) {
|
||||||
|
.connection = target_connection,
|
||||||
|
.request_number = tunnel_request_number,
|
||||||
|
};
|
||||||
|
tunnel_t* data1 = tf_malloc(sizeof(tunnel_t));
|
||||||
|
*data1 = (tunnel_t) {
|
||||||
|
.connection = connection,
|
||||||
|
.request_number = -request_number,
|
||||||
|
};
|
||||||
|
tf_ssb_connection_add_request(connection, -request_number, "tunnel.connect", _tf_ssb_rpc_tunnel_callback, _tf_ssb_rpc_tunnel_cleanup, data0, target_connection);
|
||||||
|
tf_ssb_connection_add_request(
|
||||||
|
target_connection, tunnel_request_number, "tunnel.connect", _tf_ssb_rpc_tunnel_callback, _tf_ssb_rpc_tunnel_cleanup, data1, connection);
|
||||||
|
|
||||||
|
JS_FreeValue(context, message);
|
||||||
|
JS_FreeCString(context, portal_str);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tf_ssb_connection_rpc_send_error(connection, flags, -request_number, "Connection not found.");
|
||||||
|
}
|
||||||
|
JS_FreeCString(context, target_str);
|
||||||
}
|
}
|
||||||
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))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user