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);