ssb: Make blocks begin to do something.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 9m21s

This commit is contained in:
2025-11-27 16:43:15 -05:00
parent eecdbf6852
commit 4f2e0245d3
5 changed files with 58 additions and 8 deletions

View File

@@ -2918,3 +2918,21 @@ void tf_ssb_db_remove_block(sqlite3* db, const char* id)
sqlite3_finalize(statement); sqlite3_finalize(statement);
} }
} }
bool tf_ssb_db_is_blocked(sqlite3* db, const char* id)
{
bool is_blocked = false;
sqlite3_stmt* statement = NULL;
if (sqlite3_prepare_v2(db, "SELECT 1 FROM blocks WHERE id = ?", -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
is_blocked = true;
}
}
sqlite3_finalize(statement);
}
return is_blocked;
}

View File

@@ -631,4 +631,12 @@ void tf_ssb_db_add_block(sqlite3* db, const char* id);
*/ */
void tf_ssb_db_remove_block(sqlite3* db, const char* id); void tf_ssb_db_remove_block(sqlite3* db, const char* id);
/**
** Check if an ID is blocked on this instance.
** @param db The database.
** @param id The account, message, or blob ID to check.
** @return true if the id is blocked.
*/
bool tf_ssb_db_is_blocked(sqlite3* db, const char* id);
/** @} */ /** @} */

View File

@@ -221,6 +221,14 @@ static void _ebt_add_to_clock(ebt_get_clock_t* work, const char* id, int64_t val
} }
} }
static bool _is_blocked(tf_ssb_t* ssb, const char* id)
{
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
bool blocked = tf_ssb_db_is_blocked(db, id);
tf_ssb_release_db_reader(ssb, db);
return blocked;
}
static void _tf_ssb_ebt_get_send_clock_work(tf_ssb_connection_t* connection, void* user_data) static void _tf_ssb_ebt_get_send_clock_work(tf_ssb_connection_t* connection, void* user_data)
{ {
ebt_get_clock_t* work = user_data; ebt_get_clock_t* work = user_data;
@@ -239,7 +247,10 @@ static void _tf_ssb_ebt_get_send_clock_work(tf_ssb_connection_t* connection, voi
for (int i = 0; visible[i]; i++) for (int i = 0; visible[i]; i++)
{ {
int32_t sequence = 0; int32_t sequence = 0;
tf_ssb_db_get_latest_message_by_author(ssb, visible[i], &sequence, NULL, 0); if (!_is_blocked(ssb, visible[i]))
{
tf_ssb_db_get_latest_message_by_author(ssb, visible[i], &sequence, NULL, 0);
}
sequences = tf_resize_vec(sequences, (i + 1) * sizeof(int32_t)); sequences = tf_resize_vec(sequences, (i + 1) * sizeof(int32_t));
sequences[i] = sequence; sequences[i] = sequence;
} }
@@ -259,11 +270,14 @@ static void _tf_ssb_ebt_get_send_clock_work(tf_ssb_connection_t* connection, voi
char id[k_id_base64_len] = ""; char id[k_id_base64_len] = "";
if (tf_ssb_connection_get_id(connection, id, sizeof(id))) if (tf_ssb_connection_get_id(connection, id, sizeof(id)))
{ {
int32_t sequence = 0; if (!_is_blocked(ssb, id))
tf_ssb_db_get_latest_message_by_author(ssb, id, &sequence, NULL, 0); {
uv_mutex_lock(&work->ebt->mutex); int32_t sequence = 0;
_ebt_add_to_clock(work, id, sequence, true, true); tf_ssb_db_get_latest_message_by_author(ssb, id, &sequence, NULL, 0);
uv_mutex_unlock(&work->ebt->mutex); uv_mutex_lock(&work->ebt->mutex);
_ebt_add_to_clock(work, id, sequence, true, true);
uv_mutex_unlock(&work->ebt->mutex);
}
} }
/* Also respond with what we know about all requested identities. */ /* Also respond with what we know about all requested identities. */
@@ -287,7 +301,10 @@ static void _tf_ssb_ebt_get_send_clock_work(tf_ssb_connection_t* connection, voi
{ {
for (int i = 0; i < requested_count; i++) for (int i = 0; i < requested_count; i++)
{ {
tf_ssb_db_get_latest_message_by_author(ssb, requested[i].id, &requested[i].value, NULL, 0); if (!_is_blocked(ssb, requested[i].id))
{
tf_ssb_db_get_latest_message_by_author(ssb, requested[i].id, &requested[i].value, NULL, 0);
}
} }
uv_mutex_lock(&work->ebt->mutex); uv_mutex_lock(&work->ebt->mutex);

View File

@@ -155,7 +155,7 @@ static void _tf_ssb_rpc_blobs_has_work(tf_ssb_connection_t* connection, void* us
blobs_has_work_t* work = user_data; blobs_has_work_t* work = user_data;
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection); tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
sqlite3* db = tf_ssb_acquire_db_reader(ssb); sqlite3* db = tf_ssb_acquire_db_reader(ssb);
work->found = tf_ssb_db_blob_has(db, work->id); work->found = tf_ssb_db_blob_has(db, work->id) && !tf_ssb_db_is_blocked(db, work->id);
tf_ssb_release_db_reader(ssb, db); tf_ssb_release_db_reader(ssb, db);
} }

View File

@@ -1905,11 +1905,18 @@ void tf_ssb_test_blocks(const tf_test_options_t* options)
sqlite3* db = tf_ssb_acquire_db_writer(ssb); sqlite3* db = tf_ssb_acquire_db_writer(ssb);
tf_ssb_db_add_block(db, message_id); tf_ssb_db_add_block(db, message_id);
assert(tf_ssb_db_is_blocked(db, message_id));
/* Blocked already, because the blocked message references it. */
assert(tf_ssb_db_is_blocked(db, blob_id));
tf_ssb_db_add_block(db, blob_id); tf_ssb_db_add_block(db, blob_id);
tf_ssb_db_add_block(db, id); tf_ssb_db_add_block(db, id);
assert(tf_ssb_db_is_blocked(db, id));
tf_ssb_db_remove_block(db, blob_id); tf_ssb_db_remove_block(db, blob_id);
tf_ssb_db_remove_block(db, message_id); tf_ssb_db_remove_block(db, message_id);
tf_ssb_db_remove_block(db, id); tf_ssb_db_remove_block(db, id);
assert(!tf_ssb_db_is_blocked(db, message_id));
assert(!tf_ssb_db_is_blocked(db, blob_id));
assert(!tf_ssb_db_is_blocked(db, id));
tf_ssb_release_db_writer(ssb, db); tf_ssb_release_db_writer(ssb, db);
tf_ssb_destroy(ssb); tf_ssb_destroy(ssb);