TrunkLink: parse PAIRED=1 + multi-host HOST list (no behavior yet)

This commit is contained in:
Audric committed 2026-04-15 21:41:51 +02:00
1 parent 6fb5aa4b91
commit adfe04e8b1
2 files changed
+63 -1

No files matched your search

+50 -1
View File
@@ -143,13 +143,43 @@ TrunkLink::~TrunkLink(void)
bool TrunkLink::initialize(void) bool TrunkLink::initialize(void)
{ {
// PAIRED — if set, HOST is a comma-separated list of twin partner hosts
std::string paired_str;
m_cfg.getValue(m_section, "PAIRED", paired_str);
m_paired = (paired_str == "1" || paired_str == "true");
// HOST // HOST
if (!m_cfg.getValue(m_section, "HOST", m_peer_host) || m_peer_host.empty()) std::string host_str;
if (!m_cfg.getValue(m_section, "HOST", host_str) || host_str.empty())
{ {
cerr << "*** ERROR[" << m_section << "]: Missing HOST" << endl; cerr << "*** ERROR[" << m_section << "]: Missing HOST" << endl;
return false; return false;
} }
if (m_paired)
{
// Comma-separated host list — one per twin partner.
std::istringstream iss(host_str);
std::string h;
while (std::getline(iss, h, ','))
{
h.erase(0, h.find_first_not_of(" \t"));
h.erase(h.find_last_not_of(" \t") + 1);
if (!h.empty()) m_peer_hosts.push_back(h);
}
if (m_peer_hosts.size() < 2)
{
cerr << "*** ERROR[" << m_section
<< "]: PAIRED=1 requires HOST to list at least 2 hosts, got '"
<< host_str << "'" << endl;
return false;
}
}
else
{
m_peer_host = host_str;
}
// PORT (optional, default 5302) // PORT (optional, default 5302)
m_cfg.getValue(m_section, "PORT", m_peer_port); m_cfg.getValue(m_section, "PORT", m_peer_port);
@@ -247,6 +277,25 @@ bool TrunkLink::initialize(void)
} }
} }
if (m_paired)
{
cout << m_section << ": PAIRED=1, " << m_peer_hosts.size()
<< " partner hosts:";
for (const auto& x : m_peer_hosts) cout << " " << x;
cout << " port=" << m_peer_port
<< " local_prefix=" << joinPrefixes(m_local_prefix)
<< " remote_prefix=" << joinPrefixes(m_remote_prefix)
<< (m_debug ? " [debug on]" : "")
<< (m_blacklist_filter.empty() ? "" : " [blacklist]")
<< (m_allow_filter.empty() ? "" : " [whitelist]")
<< (m_tg_map_in.empty() ? "" : " [tg_map]")
<< " [outbound deferred to D2]"
<< endl;
// Outbound connections for PAIRED mode are created in D2.
// For now, leave m_con unconnected and return successfully.
return true;
}
cout << m_section << ": Trunk to " << m_peer_host << ":" << m_peer_port cout << m_section << ": Trunk to " << m_peer_host << ":" << m_peer_port
<< " local_prefix=" << joinPrefixes(m_local_prefix) << " local_prefix=" << joinPrefixes(m_local_prefix)
<< " remote_prefix=" << joinPrefixes(m_remote_prefix) << " remote_prefix=" << joinPrefixes(m_remote_prefix)
+13
View File
@@ -119,6 +119,12 @@ class TrunkLink : public sigc::trackable
return m_remote_prefix; return m_remote_prefix;
} }
bool isPaired(void) const { return m_paired; }
bool hasInboundConnection(void) const
{
return m_paired ? !m_ib_cons.empty() : (m_inbound_con != nullptr);
}
// Accept an inbound connection from a peer that has already sent a hello // Accept an inbound connection from a peer that has already sent a hello
void acceptInboundConnection(Async::FramedTcpConnection* con, void acceptInboundConnection(Async::FramedTcpConnection* con,
const MsgTrunkHello& hello); const MsgTrunkHello& hello);
@@ -204,6 +210,13 @@ class TrunkLink : public sigc::trackable
static const time_t PEER_INTEREST_TIMEOUT_S = 600; // 10 minutes static const time_t PEER_INTEREST_TIMEOUT_S = 600; // 10 minutes
std::map<uint32_t, time_t> m_peer_interested_tgs; std::map<uint32_t, time_t> m_peer_interested_tgs;
// PAIRED mode: one logical peer backed by multiple physical hosts
bool m_paired = false;
std::vector<std::string> m_peer_hosts; // HOST=h1,h2,...
std::vector<FramedTcpClient*> m_ob_cons; // per-host outbound (D2)
std::vector<Async::FramedTcpConnection*> m_ib_cons; // per-host inbound (D3)
size_t m_sticky_ob_idx = 0; // sticky send socket (D4)
// Per-connection state // Per-connection state
bool m_ob_hello_received = false; bool m_ob_hello_received = false;
unsigned m_ob_hb_tx_cnt = 0; unsigned m_ob_hb_tx_cnt = 0;