|
BCNP 3.2.1
Batched Command Network Protocol
|
UDP transport adapter for BCNP over POSIX sockets. More...
#include <udp_posix.h>
Public Member Functions | |
| UdpPosixAdapter (uint16_t listenPort, const char *targetIp=nullptr, uint16_t targetPort=0) | |
| Construct UDP adapter. | |
| ~UdpPosixAdapter () override | |
| Destructor. Closes the socket. | |
| bool | SendBytes (const uint8_t *data, std::size_t length) override |
| Sends bytes to the current peer via UDP. | |
| std::size_t | ReceiveChunk (uint8_t *buffer, std::size_t maxLength) override |
| Receives a UDP datagram. | |
| bool | IsValid () const |
| void | SetPeerLockMode (bool locked) |
| Enables or disables peer locking. | |
| void | SetPairingToken (uint32_t token) |
| Sets the expected pairing token for handshake validation. | |
| void | UnlockPeer () |
| Resets pairing state to allow re-pairing with a new peer. | |
| bool | IsHandshakeComplete () const |
| bool | SendHandshake () |
| Sends the V3 protocol handshake to the current peer. | |
| uint32_t | GetRemoteSchemaHash () const |
Public Member Functions inherited from bcnp::DuplexAdapter | |
| ~DuplexAdapter () override=default | |
Public Member Functions inherited from bcnp::ByteWriter | |
| virtual | ~ByteWriter ()=default |
Public Member Functions inherited from bcnp::ByteStream | |
| virtual | ~ByteStream ()=default |
UDP transport adapter for BCNP over POSIX sockets.
Connectionless transport with optional peer locking for security. Supports pairing tokens and schema handshake validation.
Note: UDP does not guarantee delivery. Use TCP for reliable transport.
Definition at line 20 of file udp_posix.h.
|
explicit |
Construct UDP adapter.
Constructs a UDP adapter bound to the specified port.
| listenPort | Port to bind for receiving |
| targetIp | Fixed target IP (optional, can learn from first packet) |
| targetPort | Fixed target port (optional) |
| listenPort | Port to bind for receiving UDP datagrams. |
| targetIp | Optional fixed target IP (bypasses pairing). |
| targetPort | Optional fixed target port (requires targetIp). |
When a fixed target is configured, the adapter is automatically locked to that peer and skips the pairing handshake. Otherwise, pairing is required before sending data.
Definition at line 64 of file udp_posix.cpp.
|
override |
Destructor. Closes the socket.
Definition at line 116 of file udp_posix.cpp.
|
inline |
Definition at line 44 of file udp_posix.h.
|
inline |
Definition at line 42 of file udp_posix.h.
|
inline |
Definition at line 34 of file udp_posix.h.
|
overridevirtual |
Receives a UDP datagram.
Performs non-blocking receive. Handles peer locking and pairing: In locked mode, packets from non-paired sources are ignored Pairing packets are processed internally and not returned Automatic peer timeout triggers re-pairing after kPeerTimeout
| buffer | Destination buffer for received data. |
| maxLength | Maximum bytes to receive. |
Implements bcnp::ByteStream.
Definition at line 210 of file udp_posix.cpp.
|
overridevirtual |
Sends bytes to the current peer via UDP.
| data | Pointer to byte buffer to send. |
| length | Number of bytes to send. |
Implements bcnp::ByteWriter.
Definition at line 131 of file udp_posix.cpp.
| bool bcnp::UdpPosixAdapter::SendHandshake | ( | ) |
Sends the V3 protocol handshake to the current peer.
The handshake contains the protocol magic bytes and schema hash. Sent automatically as a response to receiving a valid pairing packet.
Definition at line 315 of file udp_posix.cpp.
| void bcnp::UdpPosixAdapter::SetPairingToken | ( | uint32_t | token | ) |
Sets the expected pairing token for handshake validation.
Both peers must use the same token for pairing to succeed. Changing the token resets pairing state (unless fixed peer is configured).
| token | 32-bit pairing token (default is "BCNP" = 0x42434E50). |
Definition at line 178 of file udp_posix.cpp.
| void bcnp::UdpPosixAdapter::SetPeerLockMode | ( | bool | locked | ) |
Enables or disables peer locking.
When locked, the adapter only accepts packets from the initial peer. This provides security against spoofing in multi-device environments.
| locked | true to lock to current/next peer, false to accept any source. |
Definition at line 151 of file udp_posix.cpp.
| void bcnp::UdpPosixAdapter::UnlockPeer | ( | ) |
Resets pairing state to allow re-pairing with a new peer.
No-op if a fixed peer is configured (must recreate adapter to change).
Definition at line 191 of file udp_posix.cpp.