From d72ba81a674ba49e17a53c6965bfccdfb67f545b Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 20 Aug 2023 18:25:15 +0000 Subject: [PATCH] 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 --- src/ssb.c | 29 ++++++++++++++++++++++------- src/ssb.rpc.c | 8 ++++++-- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/ssb.c b/src/ssb.c index ea1d4d60..284d05df 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -2477,17 +2477,27 @@ static void _tf_ssb_connection_tunnel_callback( void* 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) { - 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); 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); 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) { return connection; diff --git a/src/ssb.rpc.c b/src/ssb.rpc.c index 9fd3995f..e08252ce 100644 --- a/src/ssb.rpc.c +++ b/src/ssb.rpc.c @@ -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"); if (JS_IsUndefined(origin) && - !JS_IsUndefined(portal) && + !JS_IsUndefined(portal) && !JS_IsUndefined(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_FreeCString(context, portal_str); } + else + { + tf_ssb_connection_rpc_send_error(connection, flags, -request_number, "Connection not found."); + } JS_FreeCString(context, target_str); } else if (!JS_IsUndefined(origin) && - !JS_IsUndefined(portal) && + !JS_IsUndefined(portal) && !JS_IsUndefined(target)) { const char* origin_str = JS_ToCString(context, origin);