ryu_ldn::ldn::LdnSessionHandler
ryu_ldn::ldn::LdnSessionHandler
Section titled “ryu_ldn::ldn::LdnSessionHandler”LDN Session Handler.
Manages LDN session state and processes incoming packets from the server. Maintains network info, node list, and provides callbacks for state changes.Thread SafetyNOT thread-safe. All methods should be called from the same thread.classryu__ldn_1_1ldn_1_1LdnSessionHandler_1
Members
Section titled “Members”m_state
Section titled “m_state”Type: LdnSessionState
Current session state.
m_is_host
Section titled “m_is_host”Type: bool
Whether we are the host.
m_local_node_id
Section titled “m_local_node_id”Type: int8_t
Our node ID (-1 if not assigned)
m_last_ping_id
Section titled “m_last_ping_id”Type: uint8_t
Last ping ID from server.
m_session_id
Section titled “m_session_id”Type: protocol::SessionId
Assigned session ID.
m_mac_address
Section titled “m_mac_address”Type: protocol::MacAddress
Assigned MAC address.
m_network_info
Section titled “m_network_info”Type: protocol::NetworkInfo
Current network info.
m_accept_policy
Section titled “m_accept_policy”Type: protocol::AcceptPolicy
Current accept policy.
m_state_callback
Section titled “m_state_callback”Type: SessionStateCallback
m_network_updated_callback
Section titled “m_network_updated_callback”Type: NetworkUpdatedCallback
m_scan_result_callback
Section titled “m_scan_result_callback”Type: ScanResultCallback
m_scan_completed_callback
Section titled “m_scan_completed_callback”Type: ScanCompletedCallback
m_disconnected_callback
Section titled “m_disconnected_callback”Type: DisconnectedCallback
m_error_callback
Section titled “m_error_callback”Type: ErrorCallback
m_rejected_callback
Section titled “m_rejected_callback”Type: RejectedCallback
m_accept_policy_changed_callback
Section titled “m_accept_policy_changed_callback”Type: AcceptPolicyChangedCallback
Methods
Section titled “Methods”LdnSessionHandler
Section titled “LdnSessionHandler”void LdnSessionHandler()Default constructor.
Construct a new.Creates handler in None state.Initializes all state to defaults:
~LdnSessionHandler
Section titled “~LdnSessionHandler”void ~LdnSessionHandler()Destructor.
LdnSessionHandler
Section titled “LdnSessionHandler”void LdnSessionHandler(const&)Parameters:
param(const&)
operator=
Section titled “operator=”& operator=(const&)Parameters:
param(const&)
Returns: &
set_state_callback
Section titled “set_state_callback”void set_state_callback(SessionStateCallback callback)Set callback for state changes.
The callback is invoked whenever the session state changes. Useful for updating UI or triggering application logic.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(SessionStateCallback)
set_network_updated_callback
Section titled “set_network_updated_callback”void set_network_updated_callback(NetworkUpdatedCallback callback)Set callback for network info updates.
Called when:callbackFunction pointer or nullptr to disableparam
Parameters:
callback(NetworkUpdatedCallback)
set_scan_result_callback
Section titled “set_scan_result_callback”void set_scan_result_callback(ScanResultCallback callback)Set callback for scan results.
Called once for each network found during scan operation. Application should collect these until scan_completed is called.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(ScanResultCallback)
set_scan_completed_callback
Section titled “set_scan_completed_callback”void set_scan_completed_callback(ScanCompletedCallback callback)Set callback for scan completion.
Called when ScanReplyEnd is received, indicating no more scan results will be sent for the current scan operation.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(ScanCompletedCallback)
set_disconnected_callback
Section titled “set_disconnected_callback”void set_disconnected_callback(DisconnectedCallback callback)Set callback for disconnection events.
Called when:callbackFunction pointer or nullptr to disableparam
Parameters:
callback(DisconnectedCallback)
set_error_callback
Section titled “set_error_callback”void set_error_callback(ErrorCallback callback)Set callback for errors.
Set callback for error events.Called when NetworkError packet is received from server. Application should check the error code and handle appropriately.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(ErrorCallback)
set_rejected_callback
Section titled “set_rejected_callback”void set_rejected_callback(RejectedCallback callback)Set callback for rejection events.
Called when a player is rejected/kicked from the session.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(RejectedCallback)
set_accept_policy_changed_callback
Section titled “set_accept_policy_changed_callback”void set_accept_policy_changed_callback(AcceptPolicyChangedCallback callback)Set callback for accept policy changes.
Called when accept policy is confirmed changed.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(AcceptPolicyChangedCallback)
handle_initialize
Section titled “handle_initialize”void handle_initialize(const protocol::LdnHeader & header, const protocol::InitializeMessage & msg)Handle Initialize response from server.
Called when server responds to our Initialize with assigned ID/MAC. Transitions to Initialized state.The server sends Initialize in response to our Initialize request. This response contains:After receiving this, we are ready to scan, create, or join networks.headerPacket header (unused but kept for consistency)msgInitialize message containing assigned ID and MACparam
Parameters:
header(const protocol::LdnHeader &)msg(const protocol::InitializeMessage &)
handle_connected
Section titled “handle_connected”void handle_connected(const protocol::LdnHeader & header, const protocol::NetworkInfo & info)Handle Connected packet (join success)
Called when successfully joined a network. Transitions to Station state.Server sends Connected when we successfully join a network. The packet contains full NetworkInfo with:headerPacket header (unused)infoComplete network informationparam
Parameters:
header(const protocol::LdnHeader &)info(const protocol::NetworkInfo &)
handle_sync_network
Section titled “handle_sync_network”void handle_sync_network(const protocol::LdnHeader & header, const protocol::NetworkInfo & info)Handle SyncNetwork packet.
Called when network state changes (player join/leave, etc.). Updates stored network info and notifies callback.Server broadcasts SyncNetwork to all clients when network state changes:This packet is also sent when we successfully create an access point, confirming we are now the host.headerPacket header (unused)infoUpdated network informationparam
Parameters:
header(const protocol::LdnHeader &)info(const protocol::NetworkInfo &)
handle_scan_reply
Section titled “handle_scan_reply”void handle_scan_reply(const protocol::LdnHeader & header, const protocol::NetworkInfo & info)Handle ScanReply packet.
Called for each network found during scan.Server sends one ScanReply for each network that matches the scan filter. Multiple ScanReply packets may be received before ScanReplyEnd.The application should collect these results until scan_completed is called.headerPacket header (unused)infoNetwork information for one found networkparam
Parameters:
header(const protocol::LdnHeader &)info(const protocol::NetworkInfo &)
handle_scan_reply_end
Section titled “handle_scan_reply_end”void handle_scan_reply_end(const protocol::LdnHeader & header)Handle ScanReplyEnd packet.
Called when scan is complete.Server sends this after all ScanReply packets to indicate the scan operation is complete. No more networks will be reported for this scan.headerPacket header (unused)param
Parameters:
header(const protocol::LdnHeader &)
handle_ping
Section titled “handle_ping”bool handle_ping(const protocol::LdnHeader & header, const protocol::PingMessage & msg)Handle Ping packet.
Processes ping from server or response to our ping.Ping packets serve two purposes:headerPacket header (unused)msgPing message with requester and IDparamtrue if we need to echo the ping back (server requested)return
Parameters:
header(const protocol::LdnHeader &)msg(const protocol::PingMessage &)
Returns: bool
handle_disconnect
Section titled “handle_disconnect”void handle_disconnect(const protocol::LdnHeader & header, const protocol::DisconnectMessage & msg)Handle Disconnect packet.
Called when a client disconnects from the session.Disconnect packets indicate a client left the session. The disconnect_ip field identifies who disconnected.If the disconnecting IP matches our IP, we’ve been kicked or the session was closed.headerPacket header (unused)msgDisconnect message with client IPparam
Parameters:
header(const protocol::LdnHeader &)msg(const protocol::DisconnectMessage &)
handle_network_error
Section titled “handle_network_error”void handle_network_error(const protocol::LdnHeader & header, const protocol::NetworkErrorMessage & msg)Handle NetworkError packet.
Called when server reports an error.Server sends NetworkError when something goes wrong:The application should check the error code and handle appropriately. Some errors are recoverable, others may require reconnection.headerPacket header (unused)msgError message with codeparam
Parameters:
header(const protocol::LdnHeader &)msg(const protocol::NetworkErrorMessage &)
handle_reject
Section titled “handle_reject”void handle_reject(const protocol::LdnHeader & header, const protocol::RejectRequest & req)Handle Reject packet.
Called when a player is rejected/kicked from the session. If we are the rejected player, we leave the session.Reject packets are sent when a player is kicked/rejected from the session. This can be initiated by the host or by the server.If the rejected node_id matches our local node ID, we have been kicked and should leave the session.headerPacket header (unused)reqReject request containing node_id and reasonparam
Parameters:
header(const protocol::LdnHeader &)req(const protocol::RejectRequest &)
handle_reject_reply
Section titled “handle_reject_reply”void handle_reject_reply(const protocol::LdnHeader & header)Handle RejectReply packet.
Called when server confirms a rejection was processed. Usually sent back to the host who initiated the rejection.RejectReply is sent by the server to confirm that a rejection request was processed. This is typically sent back to the host who initiated the rejection.headerPacket header (unused)param
Parameters:
header(const protocol::LdnHeader &)
handle_set_accept_policy
Section titled “handle_set_accept_policy”void handle_set_accept_policy(const protocol::LdnHeader & header, const protocol::SetAcceptPolicyRequest & req)Handle SetAcceptPolicy response.
Called when server confirms accept policy change.SetAcceptPolicy response confirms that the accept policy was changed. This is sent back to the host who changed the policy.headerPacket header (unused)reqAccept policy request containing new policyparam
Parameters:
header(const protocol::LdnHeader &)req(const protocol::SetAcceptPolicyRequest &)
get_state
Section titled “get_state”LdnSessionState get_state()Get current session state.
Current statereturn
Returns: LdnSessionState
is_in_session
Section titled “is_in_session”bool is_in_session()Check if in an active session.
true if in Station or AccessPoint statereturntrue if currently in a Station or AccessPoint statereturn
Returns: bool
is_host
Section titled “is_host”bool is_host()Check if we are the host.
true if we created the access pointreturn
Returns: bool
get_node_count
Section titled “get_node_count”uint8_t get_node_count()Get current node count.
Number of connected playersreturnNumber of connected players in current sessionreturn
Returns: uint8_t
get_max_nodes
Section titled “get_max_nodes”uint8_t get_max_nodes()Get maximum nodes for current session.
Maximum players allowedreturnMaximum players allowed, or 0 if not in sessionreturn
Returns: uint8_t
get_local_node_id
Section titled “get_local_node_id”int8_t get_local_node_id()Get our local node ID.
Our node ID (0-7), or -1 if not in sessionreturn
Returns: int8_t
set_local_node_id
Section titled “set_local_node_id”void set_local_node_id(int8_t node_id)Set our local node ID.
Called when we know our assigned node ID.Called when the server assigns us a node ID or when we determine our node ID from the network info.node_idOur node ID (0-7)param
Parameters:
node_id(int8_t)
get_network_info
Section titled “get_network_info”const protocol::NetworkInfo & get_network_info()Get current network info.
Reference to stored network info (may be stale if not in session)return
Returns: const protocol::NetworkInfo &
get_last_ping_id
Section titled “get_last_ping_id”uint8_t get_last_ping_id()Get last ping ID received from server.
Last ping ID for echo responsereturn
Returns: uint8_t
get_session_id
Section titled “get_session_id”const protocol::SessionId & get_session_id()Get assigned session ID.
Session ID assigned by serverreturn
Returns: const protocol::SessionId &
get_mac_address
Section titled “get_mac_address”const protocol::MacAddress & get_mac_address()Get assigned MAC address.
MAC address assigned by serverreturn
Returns: const protocol::MacAddress &
get_accept_policy
Section titled “get_accept_policy”protocol::AcceptPolicy get_accept_policy()Get current accept policy.
Current accept policy (only valid for host)return
Returns: protocol::AcceptPolicy
leave_session
Section titled “leave_session”void leave_session()Leave current session.
Transitions back to Initialized state.Clears session-specific state and returns to Initialized state. The application should send a Disconnect packet before calling this.
void reset()Reset handler to initial state.
Clears all state and returns to None.Clears all state and callbacks. Use this when disconnecting from the server entirely.
Methods
Section titled “Methods”set_state
Section titled “set_state”void set_state(LdnSessionState new_state)Set state and invoke callback.
Handles state transition and notifies registered callback.new_stateNew state to transition toparam
Parameters:
new_state(LdnSessionState)