28 explicit UdpPosixAdapter(uint16_t listenPort,
const char* targetIp =
nullptr, uint16_t targetPort = 0);
31 bool SendBytes(
const uint8_t* data, std::size_t length)
override;
32 std::size_t
ReceiveChunk(uint8_t* buffer, std::size_t maxLength)
override;
34 bool IsValid()
const {
return m_socket >= 0; }
47 bool ProcessPairingPacket(
const uint8_t* buffer, std::size_t length,
const sockaddr_in& src);
51 sockaddr_in m_lastPeer{};
52 bool m_hasPeer{
false};
53 bool m_peerLocked{
false};
54 bool m_pairingComplete{
false};
55 bool m_schemaValidated{
false};
56 bool m_requirePairing{
false};
57 bool m_fixedPeerConfigured{
false};
58 uint32_t m_pairingToken{0x42434E50U};
59 uint32_t m_remoteSchemaHash{0};
60 sockaddr_in m_initialPeer{};
61 std::chrono::steady_clock::time_point m_lastPeerRx{};
62 static constexpr std::chrono::milliseconds kPeerTimeout{5000};
Combined send/receive interface for bidirectional transports.
UDP transport adapter for BCNP over POSIX sockets.
~UdpPosixAdapter() override
Destructor. Closes the socket.
UdpPosixAdapter(uint16_t listenPort, const char *targetIp=nullptr, uint16_t targetPort=0)
Construct UDP adapter.
std::size_t ReceiveChunk(uint8_t *buffer, std::size_t maxLength) override
Receives a UDP datagram.
void SetPairingToken(uint32_t token)
Sets the expected pairing token for handshake validation.
bool SendHandshake()
Sends the V3 protocol handshake to the current peer.
bool SendBytes(const uint8_t *data, std::size_t length) override
Sends bytes to the current peer via UDP.
uint32_t GetRemoteSchemaHash() const
bool IsHandshakeComplete() const
void UnlockPeer()
Resets pairing state to allow re-pairing with a new peer.
void SetPeerLockMode(bool locked)
Enables or disables peer locking.