Add trunk TCP server for bidirectional peer connections
Previously TrunkLink only connected outbound — there was no server listening on port 5302, so both reflectors got "Connection refused." Changes: - Reflector: add trunk TcpServer (default port 5302, configurable via TRUNK_LISTEN_PORT) that accepts inbound peer connections, authenticates via HMAC, and matches by secret + prefix - TrunkLink: support both outbound and inbound directions with automatic conflict resolution (lower priority keeps outbound) - Security: pre-auth frame size cap (4KB), max 5 pending connections, 10s hello timeout, log-injection sanitization - Docs: updated TRUNK_PROTOCOL.md, README.md, CLAUDE.md
This commit is contained in:
1 parent
53a9a6fc75
commit
b8d0dd19af
7 files changed
+563
-38
No files matched your search
@@ -60,6 +60,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
class Reflector;
|
||||
class ReflectorMsg;
|
||||
class MsgTrunkHello;
|
||||
class MsgUdpAudio;
|
||||
|
||||
|
||||
@@ -100,6 +101,20 @@ class TrunkLink : public sigc::trackable
|
||||
|
||||
Json::Value statusJson(void) const;
|
||||
|
||||
const std::string& secret(void) const { return m_secret; }
|
||||
const std::vector<std::string>& remotePrefix(void) const
|
||||
{
|
||||
return m_remote_prefix;
|
||||
}
|
||||
|
||||
// Accept an inbound connection from a peer that has already sent a hello
|
||||
void acceptInboundConnection(Async::FramedTcpConnection* con,
|
||||
const MsgTrunkHello& hello);
|
||||
|
||||
// Called by Reflector when the inbound connection disconnects
|
||||
void onInboundDisconnected(Async::FramedTcpConnection* con,
|
||||
Async::FramedTcpConnection::DisconnectReason reason);
|
||||
|
||||
// Called by Reflector when a local client starts/stops on a shared TG
|
||||
void onLocalTalkerStart(uint32_t tg, const std::string& callsign);
|
||||
void onLocalTalkerStop(uint32_t tg);
|
||||
@@ -114,6 +129,8 @@ class TrunkLink : public sigc::trackable
|
||||
static const unsigned HEARTBEAT_TX_CNT_RESET = 10;
|
||||
static const unsigned HEARTBEAT_RX_CNT_RESET = 15;
|
||||
|
||||
enum class ConDir { NONE, OUTBOUND, INBOUND };
|
||||
|
||||
using FramedTcpClient =
|
||||
Async::TcpPrioClient<Async::FramedTcpConnection>;
|
||||
|
||||
@@ -128,7 +145,9 @@ class TrunkLink : public sigc::trackable
|
||||
uint32_t m_priority; // our tie-break nonce (random)
|
||||
uint32_t m_peer_priority; // peer's nonce, from MsgTrunkHello
|
||||
bool m_hello_received;
|
||||
FramedTcpClient m_con;
|
||||
FramedTcpClient m_con; // outbound client connection
|
||||
Async::FramedTcpConnection* m_inbound_con = nullptr; // accepted inbound
|
||||
ConDir m_active_dir = ConDir::NONE;
|
||||
Async::Timer m_heartbeat_timer;
|
||||
unsigned m_hb_tx_cnt;
|
||||
unsigned m_hb_rx_cnt;
|
||||
@@ -141,6 +160,12 @@ class TrunkLink : public sigc::trackable
|
||||
TrunkLink(const TrunkLink&);
|
||||
TrunkLink& operator=(const TrunkLink&);
|
||||
|
||||
bool isActive(void) const;
|
||||
void pauseOutbound(void);
|
||||
void resumeOutbound(void);
|
||||
void resolveConnectionConflict(void);
|
||||
void cleanupTrunkState(void);
|
||||
|
||||
void onConnected(void);
|
||||
void onDisconnected(Async::TcpConnection* con,
|
||||
Async::TcpConnection::DisconnectReason reason);
|
||||
|
||||
Reference in new issue
Block a user