ryu_ldn::ldn::PacketDispatcher
ryu_ldn::ldn::PacketDispatcher
Section titled “ryu_ldn::ldn::PacketDispatcher”Packet dispatcher for routing received packets to handlers.
Routes incoming packets to registered callback handlers based on the packet type in the LdnHeader.Thread SafetyNOT thread-safe. Do not callfrom multiple threads simultaneously. Handler registration should be done before starting the receive loop.classryu__ldn_1_1ldn_1_1PacketDispatcher_1
Members
Section titled “Members”m_initialize_handler
Section titled “m_initialize_handler”Type: < protocol::InitializeMessage >
m_connected_handler
Section titled “m_connected_handler”Type: < protocol::NetworkInfo >
m_sync_network_handler
Section titled “m_sync_network_handler”Type: < protocol::NetworkInfo >
m_scan_reply_handler
Section titled “m_scan_reply_handler”Type: < protocol::NetworkInfo >
m_scan_reply_end_handler
Section titled “m_scan_reply_end_handler”Type: EmptyPacketHandler
m_disconnect_handler
Section titled “m_disconnect_handler”Type: < protocol::DisconnectMessage >
m_ping_handler
Section titled “m_ping_handler”Type: < protocol::PingMessage >
m_network_error_handler
Section titled “m_network_error_handler”Type: < protocol::NetworkErrorMessage >
m_proxy_config_handler
Section titled “m_proxy_config_handler”Type: <>
m_proxy_connect_handler
Section titled “m_proxy_connect_handler”Type: < protocol::ProxyConnectRequest >
m_proxy_connect_reply_handler
Section titled “m_proxy_connect_reply_handler”Type: < protocol::ProxyConnectResponse >
m_proxy_data_handler
Section titled “m_proxy_data_handler”Type: ProxyDataHandler
m_proxy_disconnect_handler
Section titled “m_proxy_disconnect_handler”Type: < protocol::ProxyDisconnectMessage >
m_reject_handler
Section titled “m_reject_handler”Type: < protocol::RejectRequest >
m_reject_reply_handler
Section titled “m_reject_reply_handler”Type: EmptyPacketHandler
m_accept_policy_handler
Section titled “m_accept_policy_handler”Type: < protocol::SetAcceptPolicyRequest >
Methods
Section titled “Methods”PacketDispatcher
Section titled “PacketDispatcher”void PacketDispatcher()Construct a newwith no handlers registered.
All handler pointers are initialized to nullptr. Packets received before handlers are registered will be silently ignored.
~PacketDispatcher
Section titled “~PacketDispatcher”void ~PacketDispatcher()PacketDispatcher
Section titled “PacketDispatcher”void PacketDispatcher(const&)Parameters:
param(const&)
operator=
Section titled “operator=”& operator=(const&)Parameters:
param(const&)
Returns: &
set_initialize_handler
Section titled “set_initialize_handler”void set_initialize_handler(< protocol::InitializeMessage > handler)Set handler for Initialize packets.
Register handler for Initialize packets (PacketId::Initialize)Initialize packets are sent by clients after TCP connection to identify themselves. Contains session ID and MAC address.handlerFunction to call when Initialize packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::InitializeMessage >)
set_connected_handler
Section titled “set_connected_handler”void set_connected_handler(< protocol::NetworkInfo > handler)Set handler for Connected packets (join success)
Register handler for Connected packets (PacketId::Connected)Connected packets are sent by server to confirm successful join. Contains full NetworkInfo with all session details.handlerFunction to call when Connected packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::NetworkInfo >)
set_sync_network_handler
Section titled “set_sync_network_handler”void set_sync_network_handler(< protocol::NetworkInfo > handler)Set handler for SyncNetwork packets.
Register handler for SyncNetwork packets (PacketId::SyncNetwork)SyncNetwork packets are broadcast to all clients when network state changes (player join/leave, host change, etc.).handlerFunction to call when SyncNetwork packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::NetworkInfo >)
set_scan_reply_handler
Section titled “set_scan_reply_handler”void set_scan_reply_handler(< protocol::NetworkInfo > handler)Set handler for ScanReply packets.
Register handler for ScanReply packets (PacketId::ScanReply)ScanReply packets are sent by server for each discovered network matching the scan filter. One packet per network.handlerFunction to call when ScanReply packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::NetworkInfo >)
set_scan_reply_end_handler
Section titled “set_scan_reply_end_handler”void set_scan_reply_end_handler(EmptyPacketHandler handler)Set handler for ScanReplyEnd packets.
Register handler for ScanReplyEnd packets (PacketId::ScanReplyEnd)ScanReplyEnd is sent after all ScanReply packets to indicate scan is complete. Has no payload.handlerFunction to call when ScanReplyEnd packet is received. Pass nullptr to unregister.param
Parameters:
handler(EmptyPacketHandler)
set_disconnect_handler
Section titled “set_disconnect_handler”void set_disconnect_handler(< protocol::DisconnectMessage > handler)Set handler for Disconnect packets.
Register handler for Disconnect packets (PacketId::Disconnect)Disconnect packets are sent when a client leaves the session. Contains the IP address of the disconnecting client.handlerFunction to call when Disconnect packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::DisconnectMessage >)
set_ping_handler
Section titled “set_ping_handler”void set_ping_handler(< protocol::PingMessage > handler)Set handler for Ping packets.
Register handler for Ping packets (PacketId::Ping)Ping packets are used for keepalive and latency measurement. Server sends Ping with requester=0, client must echo it back.handlerFunction to call when Ping packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::PingMessage >)
set_network_error_handler
Section titled “set_network_error_handler”void set_network_error_handler(< protocol::NetworkErrorMessage > handler)Set handler for NetworkError packets.
Register handler for NetworkError packets (PacketId::NetworkError)NetworkError packets report protocol or session errors. Contains error code indicating the failure type.handlerFunction to call when NetworkError packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::NetworkErrorMessage >)
set_proxy_config_handler
Section titled “set_proxy_config_handler”void set_proxy_config_handler(<> handler)Set handler for ProxyConfig packets.
Register handler for ProxyConfig packets (PacketId::ProxyConfig)ProxyConfig packets configure P2P proxy tunneling. Contains proxy IP and subnet mask for address assignment.handlerFunction to call when ProxyConfig packet is received. Pass nullptr to unregister.param
Parameters:
handler(<>)
set_proxy_connect_handler
Section titled “set_proxy_connect_handler”void set_proxy_connect_handler(< protocol::ProxyConnectRequest > handler)Set handler for ProxyConnect packets.
Register handler for ProxyConnect packets (PacketId::ProxyConnect)ProxyConnect requests establish P2P connections through the server. Contains source/destination addressing info.handlerFunction to call when ProxyConnect packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::ProxyConnectRequest >)
set_proxy_connect_reply_handler
Section titled “set_proxy_connect_reply_handler”void set_proxy_connect_reply_handler(< protocol::ProxyConnectResponse > handler)Set handler for ProxyConnectReply packets.
Register handler for ProxyConnectReply packets (PacketId::ProxyConnectReply)ProxyConnectReply confirms or denies P2P connection request.handlerFunction to call when ProxyConnectReply packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::ProxyConnectResponse >)
set_proxy_data_handler
Section titled “set_proxy_data_handler”void set_proxy_data_handler(ProxyDataHandler handler)Set handler for ProxyData packets.
Register handler for ProxyData packets (PacketId::ProxyData)ProxyData packets carry game traffic through the server proxy. Contains ProxyDataHeader (20 bytes) followed by variable-length data.handlerFunction to call when ProxyData packet is received. Pass nullptr to unregister.param
Parameters:
handler(ProxyDataHandler)
set_proxy_disconnect_handler
Section titled “set_proxy_disconnect_handler”void set_proxy_disconnect_handler(< protocol::ProxyDisconnectMessage > handler)Set handler for ProxyDisconnect packets.
Register handler for ProxyDisconnect packets (PacketId::ProxyDisconnect)ProxyDisconnect notifies that a proxied P2P connection was closed. Contains connection info and disconnect reason.handlerFunction to call when ProxyDisconnect packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::ProxyDisconnectMessage >)
set_reject_handler
Section titled “set_reject_handler”void set_reject_handler(< protocol::RejectRequest > handler)Set handler for Reject packets.
Register handler for Reject packets (PacketId::Reject)Reject packets are sent by host to kick/reject a player. Contains node ID and disconnect reason.handlerFunction to call when Reject packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::RejectRequest >)
set_reject_reply_handler
Section titled “set_reject_reply_handler”void set_reject_reply_handler(EmptyPacketHandler handler)Set handler for RejectReply packets.
Register handler for RejectReply packets (PacketId::RejectReply)RejectReply confirms that rejection was processed. Has no payload.handlerFunction to call when RejectReply packet is received. Pass nullptr to unregister.param
Parameters:
handler(EmptyPacketHandler)
set_accept_policy_handler
Section titled “set_accept_policy_handler”void set_accept_policy_handler(< protocol::SetAcceptPolicyRequest > handler)Set handler for SetAcceptPolicy packets.
Register handler for SetAcceptPolicy packets (PacketId::SetAcceptPolicy)SetAcceptPolicy changes who can join the session. Contains AcceptPolicy enum value.handlerFunction to call when SetAcceptPolicy packet is received. Pass nullptr to unregister.param
Parameters:
handler(< protocol::SetAcceptPolicyRequest >)
dispatch
Section titled “dispatch”void dispatch(const protocol::LdnHeader & header, const uint8_t * data, size_t data_size)Dispatch a received packet to the appropriate handler.
Parses the packet data and calls the registered handler for the packet type. If no handler is registered, the packet is silently ignored.Main dispatch entry point. Routes packets to handlers based on the packet type in header.type.Supported Packet TypesPacketIdyesHandler TypeyesPayload TypeyesInitializenoPacketHandlernoInitializeMessage (22B)noConnectednoPacketHandlernoNetworkInfo (0x480)noSyncNetworknoPacketHandlernoNetworkInfo (0x480)noScanReplynoPacketHandlernoNetworkInfo (0x480)noScanReplyEndnoEmptyHandlerno(none)noDisconnectnoPacketHandlernoDisconnectMessage (4B)noPingnoPacketHandlernoPingMessage (2B)noNetworkErrornoPacketHandlernoNetworkErrorMessage (4B)noProxyConfignoPacketHandlernoProxyConfig (8B)noProxyConnectnoPacketHandlernoProxyConnectRequest (16B)noProxyConnectReplynoPacketHandlernoProxyConnectResponse (16B)noProxyDatanoProxyDataHandlernoProxyDataHeader + datanoProxyDisconnectnoPacketHandlernoProxyDisconnectMessage(20B)noRejectnoPacketHandlernoRejectRequest (8B)noRejectReplynoEmptyHandlerno(none)noSetAcceptPolicynoPacketHandlernoSetAcceptPolicyRequest (4B)no173headerThe packet header (already parsed from wire format)dataPointer to payload data following headerdata_sizeSize of payload data in bytesparamUnknown packet types are silently ignorednotePackets with insufficient data are silently ignorednoteclassryu__ldn_1_1ldn_1_1PacketDispatcher_1
Parameters:
header(const protocol::LdnHeader &)data(const uint8_t *)data_size(size_t)
Methods
Section titled “Methods”dispatch_typed
Section titled “dispatch_typed”void dispatch_typed(const protocol::LdnHeader & header, const uint8_t * data, size_t data_size, < T > handler)Helper to safely parse and dispatch typed packets.
This template method handles the common pattern for most packet types:TThe payload struct type (e.g., PingMessage, NetworkInfo)templateparamheaderThe packet headerdataPointer to payload bytesdata_sizeSize of payload datahandlerFunction pointer to call (may be nullptr)paramIf handler is nullptr, returns immediately (no-op)noteIf data_size < sizeof(T), returns immediately (undersized packet)note
Parameters:
header(const protocol::LdnHeader &)data(const uint8_t *)data_size(size_t)handler(< T >)