Try to respond to tunnel errors I'm seeing instead of forwarding them over the tunnel, which obviously won't work. Allow creating multiple connections to the same ID if it's for the sake of a tunnel. I think this explains timeouts I'm seeing with tunnels. More error handling, too. C'mon, fix tunnels.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4409 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-08-20 18:25:15 +00:00
parent fef88e2032
commit d72ba81a67
2 changed files with 28 additions and 9 deletions

View File

@ -2477,17 +2477,27 @@ static void _tf_ssb_connection_tunnel_callback(
void* user_data) void* user_data)
{ {
tf_ssb_connection_t* tunnel = user_data; tf_ssb_connection_t* tunnel = user_data;
_tf_ssb_connection_on_tcp_recv_internal(tunnel, message, size); if (flags & k_ssb_rpc_flag_end_error)
{
tf_ssb_connection_rpc_send(
connection,
flags,
-request_number,
(const uint8_t*)"false",
strlen("false"),
NULL,
NULL,
NULL);
tf_ssb_connection_close(tunnel);
}
else
{
_tf_ssb_connection_on_tcp_recv_internal(tunnel, message, size);
}
} }
tf_ssb_connection_t* tf_ssb_connection_tunnel_create(tf_ssb_t* ssb, const char* portal_id, int32_t request_number, const char* target_id) tf_ssb_connection_t* tf_ssb_connection_tunnel_create(tf_ssb_t* ssb, const char* portal_id, int32_t request_number, const char* target_id)
{ {
if (tf_ssb_connection_get(ssb, target_id))
{
/* Already have a possibly more direct connection to target. */
return NULL;
}
tf_ssb_connection_t* connection = tf_ssb_connection_get(ssb, portal_id); tf_ssb_connection_t* connection = tf_ssb_connection_get(ssb, portal_id);
JSContext* context = ssb->context; JSContext* context = ssb->context;
@ -2975,6 +2985,11 @@ tf_ssb_connection_t* tf_ssb_connection_get(tf_ssb_t* ssb, const char* id)
tf_ssb_id_str_to_bin(pub, id); tf_ssb_id_str_to_bin(pub, id);
for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next) for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next)
{ {
if (connection->tunnel_connection)
{
continue;
}
if (memcmp(connection->serverpub, pub, k_id_bin_len) == 0) if (memcmp(connection->serverpub, pub, k_id_bin_len) == 0)
{ {
return connection; return connection;

View File

@ -322,7 +322,7 @@ static void _tf_ssb_rpc_tunnel_connect(tf_ssb_connection_t* connection, uint8_t
JSValue target = JS_GetPropertyStr(context, arg, "target"); JSValue target = JS_GetPropertyStr(context, arg, "target");
if (JS_IsUndefined(origin) && if (JS_IsUndefined(origin) &&
!JS_IsUndefined(portal) && !JS_IsUndefined(portal) &&
!JS_IsUndefined(target)) !JS_IsUndefined(target))
{ {
const char* target_str = JS_ToCString(context, target); const char* target_str = JS_ToCString(context, target);
@ -376,10 +376,14 @@ static void _tf_ssb_rpc_tunnel_connect(tf_ssb_connection_t* connection, uint8_t
JS_FreeValue(context, message); JS_FreeValue(context, message);
JS_FreeCString(context, portal_str); 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) && else if (!JS_IsUndefined(origin) &&
!JS_IsUndefined(portal) && !JS_IsUndefined(portal) &&
!JS_IsUndefined(target)) !JS_IsUndefined(target))
{ {
const char* origin_str = JS_ToCString(context, origin); const char* origin_str = JS_ToCString(context, origin);