From bd25e4abfcf3bde8775c698cab095991daf2d7ca Mon Sep 17 00:00:00 2001 From: evgeny Date: Fri, 30 Oct 2026 22:38:36 +0100 Subject: [PATCH] Keep known-peer admission policy in the topology module --- src/routing_layer/topo_group.c | 20 ++++++++++++++++++++ src/routing_layer/topo_group.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/routing_layer/topo_group.c b/src/routing_layer/topo_group.c index 885926b0e..a2c8dbcf4 100644 --- a/src/routing_layer/topo_group.c +++ b/src/routing_layer/topo_group.c @@ -409,6 +409,26 @@ static int topo_group_peer_allowed(struct TOPO_GROUP* group, uint64_t node_id) { return db && group->channel_id[0] && topo_node_sqlite_member_allowed(db, group->channel_id, node_id); } +/* Политика знакомого пира принадлежит группам/БД; транспорт передаёт только ключ, без SQL и таблиц. */ +int topo_groups_peer_key_known(struct UTUN_INSTANCE* inst, const uint8_t key[32]) { + if (!inst || !key) { DEBUG_ERROR(DEBUG_CATEGORY_BGP, "known peer check: missing instance/key"); return 0; } + if (!inst->topo_groups || !inst->topo_groups->group_list || !inst->topo_sqlite_db) { + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "known peer check: topology/database unavailable"); return 0; + } + for (struct ll_entry* e = inst->topo_groups->group_list->head; e; e = e->next) { + struct TOPO_GROUP* g = (struct TOPO_GROUP*)e; + if (!g->stopping && g->group_type == TOPO_GROUP_TYPE_CHAT && g->channel_id[0] + && topo_node_sqlite_member_key_allowed(inst->topo_sqlite_db, g->channel_id, key)) { + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "known peer admitted node=%016llx group=%016llx", + (unsigned long long)sc_derive_node_id_from_pubkey(key), (unsigned long long)g->group_id); + return 1; + } + } + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "known peer denied node=%016llx reason=no active group membership", + (unsigned long long)sc_derive_node_id_from_pubkey(key)); + return 0; +} + /* Приёмник BGP-пакетов от ETCP: диспетчер по subcmd (NODEINFO/WITHDRAW/...). */ static void topo_group_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry* entry) { if (!entry) return; diff --git a/src/routing_layer/topo_group.h b/src/routing_layer/topo_group.h index ff554c17b..27a60f932 100644 --- a/src/routing_layer/topo_group.h +++ b/src/routing_layer/topo_group.h @@ -280,6 +280,9 @@ struct TOPO_GROUPS { * @return TOPO_GROUPS или NULL при ошибке */ struct TOPO_GROUPS* topo_groups_init(struct UTUN_INSTANCE* instance); +/* Только uasync. 1 — точный X25519-ключ действующего участника хотя бы одной своей CHAT-группы. + * Без БД/групп, при SQL-ошибке, заглушке, удалённом мембере — 0. Объявления/реестр nodes не дают допуска. */ +int topo_groups_peer_key_known(struct UTUN_INSTANCE* instance, const uint8_t key[32]); /** * @brief Обработчик события смены active mode (подписчик utun_add_activity_cbk).