feat(trunk): parse ROUTABLE_PREFIXES (members + initialize + reload)

This commit is contained in:
Audric committed 2026-06-15 16:48:43 +02:00
1 parent 46979c1f8b
commit 4b55d69bd6
2 files changed
+54

No files matched your search

+49
View File
@@ -316,6 +316,23 @@ bool TrunkLink::initialize(void)
return false; return false;
} }
// ROUTABLE_PREFIXES — optional additional prefixes (or "*") reachable VIA
// this peer beyond what it owns. "*" is a default route (regional leaves);
// explicit prefixes enable backbone transit. See docs/PEER_PROTOCOL.md.
std::string routable_str;
if (m_cfg.getValue(m_section, "ROUTABLE_PREFIXES", routable_str)
&& !routable_str.empty())
{
for (const auto& p : splitPrefixes(routable_str))
{
if (p == "*") m_routable_wildcard = true;
else m_routable_prefixes.push_back(p);
}
geulog::info("trunk", m_section, ": Routable prefixes: ",
joinPrefixes(m_routable_prefixes),
(m_routable_wildcard ? " *(default route)" : ""));
}
// PEER_ID — name we advertise in our hello (defaults to section name). // PEER_ID — name we advertise in our hello (defaults to section name).
// Used by the receiving peer as the MQTT topic component for this link. // Used by the receiving peer as the MQTT topic component for this link.
if (!m_cfg.getValue(m_section, "PEER_ID", m_peer_id_config) if (!m_cfg.getValue(m_section, "PEER_ID", m_peer_id_config)
@@ -471,6 +488,22 @@ bool TrunkLink::isSharedTG(uint32_t tg) const
} /* TrunkLink::isSharedTG */ } /* TrunkLink::isSharedTG */
bool TrunkLink::matchesRoutable(uint32_t tg) const
{
if (m_routable_wildcard) return true;
const std::string s = std::to_string(tg);
for (const auto& prefix : m_routable_prefixes)
{
if (s.size() >= prefix.size() &&
s.compare(0, prefix.size(), prefix) == 0)
{
return true;
}
}
return false;
} /* TrunkLink::matchesRoutable */
bool TrunkLink::isOwnedTG(uint32_t tg) const bool TrunkLink::isOwnedTG(uint32_t tg) const
{ {
const std::string s = std::to_string(tg); const std::string s = std::to_string(tg);
@@ -1951,6 +1984,8 @@ void TrunkLink::reloadConfig(void)
m_allow_filter = TgFilter{}; m_allow_filter = TgFilter{};
m_tg_map_in.clear(); m_tg_map_in.clear();
m_tg_map_out.clear(); m_tg_map_out.clear();
m_routable_prefixes.clear();
m_routable_wildcard = false;
RedisStore* rs = m_reflector->redisStore(); RedisStore* rs = m_reflector->redisStore();
@@ -1976,6 +2011,20 @@ void TrunkLink::reloadConfig(void)
m_allow_filter = TgFilter::parse(allow_str); m_allow_filter = TgFilter::parse(allow_str);
} }
if (!rs)
{
std::string routable_str;
if (m_cfg.getValue(m_section, "ROUTABLE_PREFIXES", routable_str)
&& !routable_str.empty())
{
for (const auto& p : splitPrefixes(routable_str))
{
if (p == "*") m_routable_wildcard = true;
else m_routable_prefixes.push_back(p);
}
}
}
if (rs) { if (rs) {
auto tgmap = rs->loadTrunkTgMap(m_section); auto tgmap = rs->loadTrunkTgMap(m_section);
for (auto& kv : tgmap) { for (auto& kv : tgmap) {
+5
View File
@@ -101,6 +101,9 @@ class TrunkLink : public sigc::trackable
bool initialize(void); bool initialize(void);
bool isSharedTG(uint32_t tg) const; bool isSharedTG(uint32_t tg) const;
// True if tg matches an explicit ROUTABLE_PREFIXES entry on this link,
// or the "*" wildcard is set. Per-link; used by the inbound-accept gate.
bool matchesRoutable(uint32_t tg) const;
void setAllPrefixes(const std::vector<std::string>& all_prefixes) void setAllPrefixes(const std::vector<std::string>& all_prefixes)
{ {
m_all_prefixes = all_prefixes; m_all_prefixes = all_prefixes;
@@ -206,6 +209,8 @@ class TrunkLink : public sigc::trackable
std::string m_peer_id_received; // peer's hello id (set on hello rx) std::string m_peer_id_received; // peer's hello id (set on hello rx)
std::vector<std::string> m_local_prefix; // our authoritative TG prefixes std::vector<std::string> m_local_prefix; // our authoritative TG prefixes
std::vector<std::string> m_remote_prefix; // peer's authoritative TG prefixes std::vector<std::string> m_remote_prefix; // peer's authoritative TG prefixes
std::vector<std::string> m_routable_prefixes; // explicit ROUTABLE_PREFIXES (non-"*")
bool m_routable_wildcard = false; // "*" present
uint32_t m_priority; // our tie-break nonce (random, set once) uint32_t m_priority; // our tie-break nonce (random, set once)
uint32_t m_peer_priority; // peer's nonce, from MsgPeerHello uint32_t m_peer_priority; // peer's nonce, from MsgPeerHello
FramedTcpClient m_con; // outbound client connection FramedTcpClient m_con; // outbound client connection