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
21
src/ssb.c
21
src/ssb.c
@ -1436,19 +1436,26 @@ static void _tf_ssb_connection_is_account_a_stranger_work(tf_ssb_connection_t* c
|
|||||||
{
|
{
|
||||||
int64_t replication_hops = 2;
|
int64_t replication_hops = 2;
|
||||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||||
tf_ssb_db_get_global_setting_int64(db, "replication_hops", &replication_hops);
|
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);
|
tf_ssb_release_db_reader(ssb, db);
|
||||||
|
|
||||||
const char** identities = tf_ssb_db_get_all_visible_identities(ssb, replication_hops);
|
if (connection->is_stranger)
|
||||||
for (int i = 0; identities[i]; i++)
|
|
||||||
{
|
{
|
||||||
if (strcmp(id, identities[i]) == 0)
|
const char** identities = tf_ssb_db_get_all_visible_identities(ssb, replication_hops);
|
||||||
|
for (int i = 0; identities[i]; i++)
|
||||||
{
|
{
|
||||||
connection->is_stranger = false;
|
if (strcmp(id, identities[i]) == 0)
|
||||||
break;
|
{
|
||||||
|
connection->is_stranger = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
tf_free((void*)identities);
|
||||||
}
|
}
|
||||||
tf_free((void*)identities);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
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);
|
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