2 Commits

Author SHA1 Message Date
fb6e554e59 ssb: Respect blocks when getting blocks and accounts at the db level.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 8m59s
2025-11-29 12:14:34 -05:00
d200e361f7 docs: Mention flagging in the iOS agreement. 2025-11-29 11:47:59 -05:00
5 changed files with 24 additions and 37 deletions

View File

@@ -34,12 +34,15 @@
<p> <p>
If you encounter objectionable content, you can filter it from your view If you encounter objectionable content, you can filter it from your view
by blocking the user who posted it. This also makes it so that users by blocking the user who posted it. This also makes it so that users
following you will not see it as a consequence of following you. following you will not see it as a consequence of following you. You can
also flag a message to signal to operators of services to which you
connect that the content should be considered for blocking.
</p> </p>
<p> <p>
The <code>admin</code> app contains a variety of settings that control the The <code>admin</code> app contains a variety of settings that control the
types of connections Tilde Friends will make or accept, including whether types of connections Tilde Friends will make or accept, including whether
the app will even accept or make connections at all. the app will even accept or make connections at all. This is also where a
local blocklist can be managed.
</p> </p>
<h2>This app is not a service</h2> <h2>This app is not a service</h2>
<p> <p>
@@ -47,12 +50,6 @@
has no more ability to see or filter what you post or read than any other has no more ability to see or filter what you post or read than any other
user of the network. user of the network.
</p> </p>
<p>
If you believe objectionable content obtained from a service that is
running as part of the Secure Scuttlebutt network should be flagged,
report it to the operator of the service, generally by contacting the
email address listed when visiting the server address in a web browser.
</p>
<h2>Agreement</h2> <h2>Agreement</h2>
<p> <p>
If you do not accept these terms, do not use this app. You may close and If you do not accept these terms, do not use this app. You may close and

View File

@@ -23,7 +23,7 @@
#define YELLOW "\e[1;33m" #define YELLOW "\e[1;33m"
#define RESET "\e[0m" #define RESET "\e[0m"
static const int k_eula_version = 1; static const int k_eula_version = 2;
static JSClassID _httpd_request_class_id; static JSClassID _httpd_request_class_id;

View File

@@ -894,7 +894,7 @@ bool tf_ssb_db_blob_has(sqlite3* db, const char* id)
{ {
bool result = false; bool result = false;
sqlite3_stmt* statement; sqlite3_stmt* statement;
const char* query = "SELECT COUNT(*) FROM blobs WHERE id = ?1"; const char* query = "SELECT COUNT(*) FROM blobs LEFT OUTER JOIN blocks ON blobs.id = blocks.id WHERE blobs.id = ?1 AND blocks.id IS NULL";
if (sqlite3_prepare_v2(db, query, -1, &statement, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, query, -1, &statement, NULL) == SQLITE_OK)
{ {
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
@@ -911,7 +911,7 @@ bool tf_ssb_db_blob_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_
bool result = false; bool result = false;
sqlite3_stmt* statement; sqlite3_stmt* statement;
sqlite3* db = tf_ssb_acquire_db_reader(ssb); sqlite3* db = tf_ssb_acquire_db_reader(ssb);
const char* query = "SELECT content FROM blobs WHERE id = ?1"; const char* query = "SELECT content FROM blobs LEFT OUTER JOIN blocks ON blobs.id = blocks.id WHERE blobs.id = ?1 AND blocks.id IS NULL";
if (sqlite3_prepare_v2(db, query, -1, &statement, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, query, -1, &statement, NULL) == SQLITE_OK)
{ {
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
@@ -1169,7 +1169,8 @@ bool tf_ssb_db_get_latest_message_by_author(tf_ssb_t* ssb, const char* author, i
if (out_message_id) if (out_message_id)
{ {
const char* query = "SELECT id, sequence FROM messages WHERE author = ?1 ORDER BY sequence DESC LIMIT 1"; const char* query = "SELECT messages.id, messages.sequence FROM messages LEFT OUTER JOIN blocks ON messages.id = blocks.id WHERE author = ?1 AND blocks.id IS NULL ORDER "
"BY messages.sequence DESC LIMIT 1";
if (sqlite3_prepare_v2(db, query, -1, &statement, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, query, -1, &statement, NULL) == SQLITE_OK)
{ {
if (sqlite3_bind_text(statement, 1, author, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) if (sqlite3_bind_text(statement, 1, author, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
@@ -1193,7 +1194,8 @@ bool tf_ssb_db_get_latest_message_by_author(tf_ssb_t* ssb, const char* author, i
} }
else else
{ {
const char* query = "SELECT max_sequence FROM messages_stats WHERE author = ?1"; const char* query = "SELECT messages_stats.max_sequence FROM messages_stats LEFT OUTER JOIN blocks ON messages_stats.author = blocks.id WHERE messages_stats.author = ?1 "
"AND blocks.id IS NULL";
if (sqlite3_prepare_v2(db, query, -1, &statement, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, query, -1, &statement, NULL) == SQLITE_OK)
{ {
if (sqlite3_bind_text(statement, 1, author, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) if (sqlite3_bind_text(statement, 1, author, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
@@ -2946,5 +2948,6 @@ void tf_ssb_db_get_blocks(sqlite3* db, void (*callback)(const char* id, double t
{ {
callback((const char*)sqlite3_column_text(statement, 0), sqlite3_column_double(statement, 1), user_data); callback((const char*)sqlite3_column_text(statement, 0), sqlite3_column_double(statement, 1), user_data);
} }
sqlite3_finalize(statement);
} }
} }

View File

@@ -221,14 +221,6 @@ 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;
@@ -247,10 +239,7 @@ 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;
if (!_is_blocked(ssb, visible[i])) tf_ssb_db_get_latest_message_by_author(ssb, visible[i], &sequence, NULL, 0);
{
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;
} }
@@ -270,14 +259,11 @@ 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)))
{ {
if (!_is_blocked(ssb, id)) int32_t sequence = 0;
{ tf_ssb_db_get_latest_message_by_author(ssb, id, &sequence, NULL, 0);
int32_t sequence = 0; uv_mutex_lock(&work->ebt->mutex);
tf_ssb_db_get_latest_message_by_author(ssb, id, &sequence, NULL, 0); _ebt_add_to_clock(work, id, sequence, true, true);
uv_mutex_lock(&work->ebt->mutex); uv_mutex_unlock(&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. */
@@ -301,10 +287,7 @@ 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++)
{ {
if (!_is_blocked(ssb, requested[i].id)) tf_ssb_db_get_latest_message_by_author(ssb, requested[i].id, &requested[i].value, NULL, 0);
{
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

@@ -1903,12 +1903,15 @@ void tf_ssb_test_blocks(const tf_test_options_t* options)
} }
JS_FreeValue(context, obj); JS_FreeValue(context, obj);
assert(tf_ssb_db_blob_get(ssb, blob_id, NULL, NULL));
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)); assert(tf_ssb_db_is_blocked(db, message_id));
/* Blocked already, because the blocked message references it. */ /* Blocked already, because the blocked message references it. */
assert(tf_ssb_db_is_blocked(db, blob_id)); 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);
assert(!tf_ssb_db_blob_get(ssb, blob_id, NULL, NULL));
tf_ssb_db_add_block(db, id); tf_ssb_db_add_block(db, id);
assert(tf_ssb_db_is_blocked(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);
@@ -1918,6 +1921,7 @@ void tf_ssb_test_blocks(const tf_test_options_t* options)
assert(!tf_ssb_db_is_blocked(db, blob_id)); assert(!tf_ssb_db_is_blocked(db, blob_id));
assert(!tf_ssb_db_is_blocked(db, id)); assert(!tf_ssb_db_is_blocked(db, id));
tf_ssb_release_db_writer(ssb, db); tf_ssb_release_db_writer(ssb, db);
assert(tf_ssb_db_blob_get(ssb, blob_id, NULL, NULL));
tf_ssb_destroy(ssb); tf_ssb_destroy(ssb);