diff --git a/src/svxlink/reflector/TrunkLink.cpp b/src/svxlink/reflector/TrunkLink.cpp index f6ac5f3..ff7d367 100644 --- a/src/svxlink/reflector/TrunkLink.cpp +++ b/src/svxlink/reflector/TrunkLink.cpp @@ -143,13 +143,43 @@ TrunkLink::~TrunkLink(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 - 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; 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) 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 << " local_prefix=" << joinPrefixes(m_local_prefix) << " remote_prefix=" << joinPrefixes(m_remote_prefix) diff --git a/src/svxlink/reflector/TrunkLink.h b/src/svxlink/reflector/TrunkLink.h index 87f7bb3..d2c3961 100644 --- a/src/svxlink/reflector/TrunkLink.h +++ b/src/svxlink/reflector/TrunkLink.h @@ -119,6 +119,12 @@ class TrunkLink : public sigc::trackable 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 void acceptInboundConnection(Async::FramedTcpConnection* con, const MsgTrunkHello& hello); @@ -204,6 +210,13 @@ class TrunkLink : public sigc::trackable static const time_t PEER_INTEREST_TIMEOUT_S = 600; // 10 minutes std::map m_peer_interested_tgs; + // PAIRED mode: one logical peer backed by multiple physical hosts + bool m_paired = false; + std::vector m_peer_hosts; // HOST=h1,h2,... + std::vector m_ob_cons; // per-host outbound (D2) + std::vector m_ib_cons; // per-host inbound (D3) + size_t m_sticky_ob_idx = 0; // sticky send socket (D4) + // Per-connection state bool m_ob_hello_received = false; unsigned m_ob_hb_tx_cnt = 0;