forked from cory/tildefriends
ssb: Allow otherwise unrecognized incoming connections when not talking to strangers if they have a valid invite.
This commit is contained in:
parent
478bcd5d13
commit
1cfac3cae6
@ -1436,9 +1436,15 @@ static void _tf_ssb_connection_is_account_a_stranger_work(tf_ssb_connection_t* c
|
||||
{
|
||||
int64_t replication_hops = 2;
|
||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||
connection->is_stranger = !tf_ssb_db_has_invite(db, id);
|
||||
if (connection->is_stranger)
|
||||
{
|
||||
tf_ssb_db_get_global_setting_int64(db, "replication_hops", &replication_hops);
|
||||
}
|
||||
tf_ssb_release_db_reader(ssb, db);
|
||||
|
||||
if (connection->is_stranger)
|
||||
{
|
||||
const char** identities = tf_ssb_db_get_all_visible_identities(ssb, replication_hops);
|
||||
for (int i = 0; identities[i]; i++)
|
||||
{
|
||||
@ -1450,6 +1456,7 @@ static void _tf_ssb_connection_is_account_a_stranger_work(tf_ssb_connection_t* c
|
||||
}
|
||||
tf_free((void*)identities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void _tf_ssb_connection_is_account_a_stranger_after_work(tf_ssb_connection_t* connection, int status, void* user_data)
|
||||
|
16
src/ssb.db.c
16
src/ssb.db.c
@ -2269,3 +2269,19 @@ bool tf_ssb_db_use_invite(sqlite3* db, const char* id)
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
bool tf_ssb_db_has_invite(sqlite3* db, const char* id)
|
||||
{
|
||||
bool has = false;
|
||||
sqlite3_stmt* statement;
|
||||
if (sqlite3_prepare(db, "SELECT COUNT(*) FROM invites WHERE invite_public_key = ? AND (expires < 0 OR expires >= ?) AND (use_count > 0 OR use_count = -1)", -1, &statement,
|
||||
NULL) == SQLITE_OK)
|
||||
{
|
||||
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK && sqlite3_bind_int64(statement, 2, (int64_t)time(NULL)) == SQLITE_OK)
|
||||
{
|
||||
has = sqlite3_step(statement) == SQLITE_ROW && sqlite3_column_int(statement, 0) > 0;
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
return has;
|
||||
}
|
||||
|
@ -547,4 +547,12 @@ bool tf_ssb_db_is_account_familiar(sqlite3* db, const char* id, int depth);
|
||||
*/
|
||||
int tf_ssb_sqlite_authorizer(void* user_data, int action_code, const char* arg0, const char* arg1, const char* arg2, const char* arg3);
|
||||
|
||||
/**
|
||||
** Check if we have an invite for the given account.
|
||||
** @param db The database.
|
||||
** @param id The invite public key to check.
|
||||
** @return true If we have a valid invite for the address.
|
||||
*/
|
||||
bool tf_ssb_db_has_invite(sqlite3* db, const char* id);
|
||||
|
||||
/** @} */
|
||||
|
Loading…
x
Reference in New Issue
Block a user