feat(trunk): routable prefixes feed isSharedTG send/interest gate (* = zero-length)
This commit is contained in:
1 parent
4b55d69bd6
commit
1e1d477957
1 file changed
+24
-11
@@ -456,34 +456,47 @@ bool TrunkLink::isSharedTG(uint32_t tg) const
|
||||
{
|
||||
const std::string s = std::to_string(tg);
|
||||
|
||||
// Find the best (longest) matching remote prefix for this peer
|
||||
size_t best_remote_len = 0;
|
||||
// Best (longest) prefix THIS link claims: an owned remote prefix or an
|
||||
// explicit routable prefix. The "*" wildcard is a zero-length candidate
|
||||
// (lowest precedence), considered only when no real prefix matches.
|
||||
size_t best_link_len = 0;
|
||||
bool matched = false;
|
||||
for (const auto& prefix : m_remote_prefix)
|
||||
{
|
||||
if (s.size() >= prefix.size() &&
|
||||
s.compare(0, prefix.size(), prefix) == 0 &&
|
||||
prefix.size() > best_remote_len)
|
||||
prefix.size() > best_link_len)
|
||||
{
|
||||
best_remote_len = prefix.size();
|
||||
best_link_len = prefix.size();
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
if (best_remote_len == 0)
|
||||
for (const auto& prefix : m_routable_prefixes)
|
||||
{
|
||||
return false; // no remote prefix matches at all
|
||||
if (s.size() >= prefix.size() &&
|
||||
s.compare(0, prefix.size(), prefix) == 0 &&
|
||||
prefix.size() > best_link_len)
|
||||
{
|
||||
best_link_len = prefix.size();
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
if (!matched)
|
||||
{
|
||||
if (!m_routable_wildcard) return false;
|
||||
best_link_len = 0; // wildcard: zero-length, any real prefix beats it
|
||||
}
|
||||
|
||||
// Check if any prefix in the mesh is a longer match — if so, that other
|
||||
// reflector is more specific and this TG doesn't belong to this peer.
|
||||
// A longer prefix anywhere in the mesh is more specific — not ours.
|
||||
for (const auto& prefix : m_all_prefixes)
|
||||
{
|
||||
if (prefix.size() > best_remote_len &&
|
||||
if (prefix.size() > best_link_len &&
|
||||
s.size() >= prefix.size() &&
|
||||
s.compare(0, prefix.size(), prefix) == 0)
|
||||
{
|
||||
return false; // a longer prefix claims this TG
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} /* TrunkLink::isSharedTG */
|
||||
|
||||
|
||||
Reference in new issue
Block a user