Implement separate transport and group membership admission checks

This commit is contained in:
evgeny committed 2026-11-03 16:29:22 +01:00
1 parent ced7a06ec8
commit 8f85ed9d17
1 file changed
+11 -2
+11 -2
View File
@@ -961,12 +961,13 @@ int topo_node_sqlite_member_in_channel(sqlite3* db, const char* channel_id, uint
return found;
}
int topo_node_sqlite_member_allowed(sqlite3* db, const char* channel_id, uint64_t node_id) {
static int member_access(sqlite3* db, const char* channel_id, uint64_t node_id, int admitted) {
if (!db || !channel_id || !channel_id[0] || !node_id) {
DEBUG_WARN(DEBUG_CATEGORY_BGP, "member admission: invalid channel/node"); return 0;
}
char table[80], sql[256]; peers_table_name(channel_id, table, sizeof(table));
snprintf(sql, sizeof(sql), "SELECT 1 FROM \"%s\" WHERE node_id=? AND source=0 AND deleted=0 AND admitted=1", table);
snprintf(sql, sizeof(sql), "SELECT 1 FROM \"%s\" WHERE node_id=? AND source=0 AND deleted=0%s",
table, admitted ? " AND admitted=1" : "");
sqlite3_stmt* statement = NULL;
int rc = sqlite3_prepare_v2(db, sql, -1, &statement, NULL);
if (rc == SQLITE_OK) rc = sqlite3_bind_int64(statement, 1, (sqlite3_int64)node_id);
@@ -978,6 +979,14 @@ int topo_node_sqlite_member_allowed(sqlite3* db, const char* channel_id, uint64_
sqlite3_finalize(statement); return allowed;
}
int topo_node_sqlite_member_allowed(sqlite3* db, const char* channel_id, uint64_t node_id) {
return member_access(db, channel_id, node_id, 1);
}
int topo_node_sqlite_member_transport_allowed(sqlite3* db, const char* channel_id, uint64_t node_id) {
return member_access(db, channel_id, node_id, 0);
}
int topo_node_sqlite_member_key_allowed(sqlite3* db, const char* channel_id, const uint8_t key[32]) {
if (!db || !channel_id || !channel_id[0] || !key) {
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "member key admission: invalid database/channel/key"); return 0;