ssb: New incoming connections replace old ones for the same id.

This commit is contained in:
Cory McWilliams 2025-02-16 08:19:40 -05:00
parent 6932da69b3
commit 478bcd5d13

View File

@ -1404,7 +1404,7 @@ tf_ssb_connection_t* tf_ssb_connection_get_tunnel(tf_ssb_connection_t* connectio
return connection ? connection->tunnel_connection : NULL; return connection ? connection->tunnel_connection : NULL;
} }
static bool _tf_ssb_is_already_connected(tf_ssb_t* ssb, uint8_t* id, tf_ssb_connection_t* ignore_connection) static tf_ssb_connection_t* _tf_ssb_is_already_connected(tf_ssb_t* ssb, uint8_t* id, tf_ssb_connection_t* ignore_connection)
{ {
for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next) for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next)
{ {
@ -1412,15 +1412,15 @@ static bool _tf_ssb_is_already_connected(tf_ssb_t* ssb, uint8_t* id, tf_ssb_conn
{ {
if (memcmp(connection->serverpub, id, k_id_bin_len) == 0) if (memcmp(connection->serverpub, id, k_id_bin_len) == 0)
{ {
return true; return connection;
} }
else if (memcmp(ssb->pub, id, k_id_bin_len) == 0) else if (memcmp(ssb->pub, id, k_id_bin_len) == 0)
{ {
return true; return connection;
} }
} }
} }
return false; return NULL;
} }
static void _tf_ssb_connection_is_account_a_stranger_work(tf_ssb_connection_t* connection, void* user_data) static void _tf_ssb_connection_is_account_a_stranger_work(tf_ssb_connection_t* connection, void* user_data)
@ -1538,14 +1538,14 @@ static void _tf_ssb_connection_verify_client_identity(tf_ssb_connection_t* conne
} }
uint8_t* detached_signature_A = m; uint8_t* detached_signature_A = m;
if (_tf_ssb_is_already_connected(connection->ssb, m + 64, connection)) tf_ssb_connection_t* other_connection = NULL;
while ((other_connection = _tf_ssb_is_already_connected(connection->ssb, m + 64, connection)))
{ {
char id_base64[k_id_base64_len] = { 0 }; char id_base64[k_id_base64_len] = { 0 };
tf_ssb_id_bin_to_str(id_base64, sizeof(id_base64), m + 64); tf_ssb_id_bin_to_str(id_base64, sizeof(id_base64), m + 64);
char reason[256]; char reason[256];
snprintf(reason, sizeof(reason), "already connected: %s\n", id_base64); snprintf(reason, sizeof(reason), "Replacing connection: %s\n", id_base64);
tf_ssb_connection_close(connection, reason); tf_ssb_connection_close(other_connection, reason);
return;
} }
memcpy(connection->serverpub, m + 64, sizeof(connection->serverpub)); memcpy(connection->serverpub, m + 64, sizeof(connection->serverpub));