ryu_ldn::network::RyuLdnClient
ryu_ldn::network::RyuLdnClient
Section titled “ryu_ldn::network::RyuLdnClient”High-level RyuLdn network client.
This is the main client class that applications should use to communicate withservers. It handles all the complexity of connection management, state tracking, and protocol handling.LifecycleCreate client with configurationSet up callbacks for state changes and packetsCallto initiate connectionCallregularly to process eventsSend packets whenreturns trueCallwhen doneclassryu__ldn_1_1network_1_1RyuLdnClient_1State TransitionsThe client maintains an internal state machine:: Initial state, callto start: TCP connection in progress: TCP connected, handshake starting: Protocol handshake in progress: Fully connected and operational: Waiting before retry after failure: Retry attempt in progress: Graceful disconnect in progress: Fatal error, calland retryclassryu__ldn_1_1network_1_1RyuLdnClient_1
Members
Section titled “Members”m_config
Section titled “m_config”Type: RyuLdnClientConfig
Client configuration.
m_tcp_client
Section titled “m_tcp_client”Type: TcpClient
Low-level TCP client.
m_state_machine
Section titled “m_state_machine”Type: ConnectionStateMachine
Connection state tracking.
m_reconnect_manager
Section titled “m_reconnect_manager”Type: ReconnectManager
Reconnection backoff logic.
m_state_callback
Section titled “m_state_callback”Type: ClientStateCallback
User callback for state changes.
m_packet_callback
Section titled “m_packet_callback”Type: ClientPacketCallback
User callback for packets.
m_packet_callback_user_data
Section titled “m_packet_callback_user_data”Type: void *
User data for packet callback.
m_last_ping_time_ms
Section titled “m_last_ping_time_ms”Type: uint64_t
Time of last ping sent.
m_backoff_start_time_ms
Section titled “m_backoff_start_time_ms”Type: uint64_t
Start of current backoff period.
m_current_backoff_delay_ms
Section titled “m_current_backoff_delay_ms”Type: uint32_t
Current backoff delay.
m_session_id
Section titled “m_session_id”Type: protocol::SessionId
Our session ID (from server)
m_mac_address
Section titled “m_mac_address”Type: protocol::MacAddress
Our MAC address.
m_handshake_sent
Section titled “m_handshake_sent”Type: bool
Whether Initialize has been sent.
m_initialized
Section titled “m_initialized”Type: bool
Whether socket system is initialized.
m_handshake_start_time_ms
Section titled “m_handshake_start_time_ms”Type: uint64_t
Time when handshake was initiated.
m_handshake_timeout_ms
Section titled “m_handshake_timeout_ms”Type: uint32_t
Handshake timeout (default: 5000ms)
m_last_error_code
Section titled “m_last_error_code”Type: protocol::NetworkErrorCode
Last error from server.
m_last_pong_time_ms
Section titled “m_last_pong_time_ms”Type: uint64_t
Time when last pong was received.
m_ping_timeout_ms
Section titled “m_ping_timeout_ms”Type: uint32_t
Ping response timeout (default: 10000ms)
m_pending_ping_count
Section titled “m_pending_ping_count”Type: uint32_t
Number of pings without response.
m_last_rtt_ms
Section titled “m_last_rtt_ms”Type: uint64_t
Last measured round-trip time.
m_ping_id
Section titled “m_ping_id”Type: uint8_t
Incrementing ping ID for tracking.
Methods
Section titled “Methods”RyuLdnClient
Section titled “RyuLdnClient”void RyuLdnClient()Constructor with default configuration.
Creates a client with default settings. Callbefore connecting to customize behavior.Creates a client ready to connect.initialization is deferred until first connection attempt.
RyuLdnClient
Section titled “RyuLdnClient”void RyuLdnClient(const& config)Constructor with custom configuration.
configClient configurationconfigClient configuration including server addressparam
Parameters:
config(const&)
~RyuLdnClient
Section titled “~RyuLdnClient”void ~RyuLdnClient()Destructor - ensures clean disconnect.
Disconnects from server if connected and cleans up resources.
RyuLdnClient
Section titled “RyuLdnClient”void RyuLdnClient(const&)Parameters:
param(const&)
operator=
Section titled “operator=”& operator=(const&)Parameters:
param(const&)
Returns: &
RyuLdnClient
Section titled “RyuLdnClient”void RyuLdnClient(&& other)Move constructor.
Transfers ownership of all resources from other client.otherSource client to move fromparam
Parameters:
other(&&)
operator=
Section titled “operator=”& operator=(&& other)Move assignment operator.
otherSource client to move fromparamReference to thisreturn
Parameters:
other(&&)
Returns: &
set_config
Section titled “set_config”void set_config(const& config)Update client configuration.
Can be called while disconnected to change settings.configNew configurationconfigNew configuration to useparam
Parameters:
config(const&)
get_config
Section titled “get_config”const& get_config()Get current configuration.
Reference to current configurationreturn
Returns: const&
set_state_callback
Section titled “set_state_callback”void set_state_callback(ClientStateCallback callback)Set callback for state changes.
callbackFunction to call on state change (nullptr to disable)callbackFunction to call when state changesparam
Parameters:
callback(ClientStateCallback)
set_packet_callback
Section titled “set_packet_callback”void set_packet_callback(ClientPacketCallback callback, void * user_data)Set callback for received packets.
callbackFunction to call on packet receive (nullptr to disable)user_dataUser-provided context pointer passed to callbackcallbackFunction to call for each received packetuser_dataUser-provided context pointer passed to callbackparam
Parameters:
callback(ClientPacketCallback)user_data(void *)
connect
Section titled “connect”ClientOpResult connect()Initiate connection to server.
Starts the connection process. The connection is asynchronous - callregularly and checkor use the state callback to know when connected.Uses host/port from configuration.ClientOpResult indicating success or failurereturn
Returns: ClientOpResult
connect
Section titled “connect”ClientOpResult connect(const char * host, uint16_t port)Initiate connection with specific host/port.
Overrides configuration for this connection attempt.Updates configuration and starts connection process.hostServer hostname or IP addressportServer port numberparamClientOpResult indicating success or failurereturn
Parameters:
host(const char *)port(uint16_t)
Returns: ClientOpResult
disconnect
Section titled “disconnect”void disconnect()Gracefully disconnect from server.
Disconnect from server.Sends disconnect message and closes connection.Sends disconnect message (if connected) and closes connection.
update
Section titled “update”void update(uint64_t current_time_ms)Update client - must be called regularly.
This method:Call this from your main loop, ideally every frame or tick.Handles all client maintenance tasks.current_time_msCurrent time in millisecondsparam
Parameters:
current_time_ms(uint64_t)
get_state
Section titled “get_state”ConnectionState get_state()Get current connection state.
Current statereturn
Returns: ConnectionState
is_connected
Section titled “is_connected”bool is_connected()Check if connected (TCP established)
true if TCP is connected (may not be ready for packets)returntrue if TCP is connectedreturn
Returns: bool
is_ready
Section titled “is_ready”bool is_ready()Check if fully ready (handshake complete)
Check if fully ready.true if ready to send/receive packetsreturn
Returns: bool
is_transitioning
Section titled “is_transitioning”bool is_transitioning()Check if in transitional state.
true if connecting, disconnecting, or in backoffreturn
Returns: bool
get_retry_count
Section titled “get_retry_count”uint32_t get_retry_count()Get retry count since last successful connection.
Get retry count.Number of connection attemptsreturn
Returns: uint32_t
get_last_error_code
Section titled “get_last_error_code”protocol::NetworkErrorCode get_last_error_code()Get last error code from server.
Returns the error code from the most recent NetworkError message. Useful for diagnosing connection failures.Last error code (NetworkErrorCode::None if no error)returnLast error code (NetworkErrorCode::None if no error)return
Returns: protocol::NetworkErrorCode
get_last_rtt_ms
Section titled “get_last_rtt_ms”uint64_t get_last_rtt_ms()Get last measured round-trip time.
Returns the RTT from the most recent ping/pong exchange. Useful for monitoring connection quality.RTT in milliseconds (0 if no ping completed yet)returnRTT in milliseconds (0 if no ping completed yet)return
Returns: uint64_t
send_scan
Section titled “send_scan”ClientOpResult send_scan(const protocol::ScanFilterFull & filter)Send a scan request to find networks.
Send scan request.filterScan filter parametersparamClientOpResult indicating success or failurereturn
Parameters:
filter(const protocol::ScanFilterFull &)
Returns: ClientOpResult
send_create_access_point
Section titled “send_create_access_point”ClientOpResult send_create_access_point(const protocol::CreateAccessPointRequest & request)Send request to create an access point.
Send create access point request.requestAccess point parametersparamClientOpResult indicating success or failurereturn
Parameters:
request(const protocol::CreateAccessPointRequest &)
Returns: ClientOpResult
send_connect
Section titled “send_connect”ClientOpResult send_connect(const protocol::ConnectRequest & request)Send request to connect to a network.
Send connect request.requestConnection parametersparamClientOpResult indicating success or failurereturn
Parameters:
request(const protocol::ConnectRequest &)
Returns: ClientOpResult
send_create_access_point_private
Section titled “send_create_access_point_private”ClientOpResult send_create_access_point_private(const protocol::CreateAccessPointPrivateRequest & request)Send request to create a private access point.
Send create access point private request.requestAccess point parameters with security settingsparamClientOpResult indicating success or failurereturn
Parameters:
request(const protocol::CreateAccessPointPrivateRequest &)
Returns: ClientOpResult
send_connect_private
Section titled “send_connect_private”ClientOpResult send_connect_private(const protocol::ConnectPrivateRequest & request)Send request to connect to a private network.
Send connect private request.requestConnection parameters with security settingsparamClientOpResult indicating success or failurereturn
Parameters:
request(const protocol::ConnectPrivateRequest &)
Returns: ClientOpResult
send_proxy_data
Section titled “send_proxy_data”ClientOpResult send_proxy_data(const protocol::ProxyDataHeader & header, const uint8_t * data, size_t size)Send proxy data to another client.
Send proxy data.headerProxy header with destination infodataData to sendsizeSize of dataparamheaderProxy headerdataData to sendsizeSize of dataparamClientOpResult indicating success or failurereturnClientOpResult indicating success or failurereturn
Parameters:
header(const protocol::ProxyDataHeader &)data(const uint8_t *)size(size_t)
Returns: ClientOpResult
send_ping
Section titled “send_ping”ClientOpResult send_ping()Send a ping to keep connection alive.
Send ping.Normally called automatically by, but can be called manually if needed.ClientOpResult indicating success or failurereturnClientOpResult indicating success or failurereturn
Returns: ClientOpResult
send_ping_response
Section titled “send_ping_response”ClientOpResult send_ping_response(uint8_t ping_id)Send a ping response to echo back a server ping.
ping_idThe ping ID from the server’s ping requestparamClientOpResult indicating success or failurereturn
Parameters:
ping_id(uint8_t)
Returns: ClientOpResult
send_disconnect_network
Section titled “send_disconnect_network”ClientOpResult send_disconnect_network()Send disconnect notification to server.
Notifies the server that we’re leaving the network.ClientOpResult indicating success or failurereturn
Returns: ClientOpResult
send_set_accept_policy
Section titled “send_set_accept_policy”ClientOpResult send_set_accept_policy(protocol::AcceptPolicy policy)Send SetAcceptPolicy request (host only)
Changes the accept policy for new connections.policyNew accept policyparamClientOpResult indicating success or failurereturn
Parameters:
policy(protocol::AcceptPolicy)
Returns: ClientOpResult
send_set_advertise_data
Section titled “send_set_advertise_data”ClientOpResult send_set_advertise_data(const uint8_t * data, size_t size)Send SetAdvertiseData request (host only)
Updates the advertise data for the network.dataAdvertise data buffersizeSize of data (max 384 bytes)paramClientOpResult indicating success or failurereturn
Parameters:
data(const uint8_t *)size(size_t)
Returns: ClientOpResult
send_reject
Section titled “send_reject”ClientOpResult send_reject(uint32_t node_id, protocol::DisconnectReason reason)Send Reject request (host only)
Rejects/kicks a player from the network.node_idNode ID of player to rejectreasonDisconnect reasonparamClientOpResult indicating success or failurereturn
Parameters:
node_id(uint32_t)reason(protocol::DisconnectReason)
Returns: ClientOpResult
send_raw_packet
Section titled “send_raw_packet”ClientOpResult send_raw_packet(const void * data, size_t size)Send raw pre-encoded packet.
Sends a packet that has already been encoded. Used by P2P components to forward notifications to the master server.dataEncoded packet datasizePacket sizeparamClientOpResult indicating success or failurereturn
Parameters:
data(const void *)size(size_t)
Returns: ClientOpResult
Methods
Section titled “Methods”state_machine_callback
Section titled “state_machine_callback”void state_machine_callback(ConnectionState old_state, ConnectionState new_state, ConnectionEvent event)Handle state machine callback.
Parameters:
old_state(ConnectionState)new_state(ConnectionState)event(ConnectionEvent)
Methods
Section titled “Methods”try_connect
Section titled “try_connect”void try_connect()Attempt TCP connection.
Called when state machine enters Connecting or Retrying state.
process_packets
Section titled “process_packets”void process_packets()Process received packets.
Polls TCP client for packets and handles each one.
handle_packet
Section titled “handle_packet”void handle_packet(protocol::PacketId id, const uint8_t * data, size_t size)Handle a single received packet.
idPacket typedataPacket payloadsizePayload sizeparam
Parameters:
id(protocol::PacketId)data(const uint8_t *)size(size_t)
send_initialize
Section titled “send_initialize”ClientOpResult send_initialize()Send Initialize handshake message.
ClientOpResult indicating success or failurereturn
Returns: ClientOpResult
process_handshake_response
Section titled “process_handshake_response”bool process_handshake_response(protocol::PacketId id, const uint8_t * data, size_t size)Process handshake response.
Process handshake response from server.Called when in Handshaking state to process server response.Handles the server’s response to our Initialize message. The RyuLDN server responds with an Initialize packet containing:This matches the official Ryujinx client behavior.idPacket ID receiveddataPacket datasizePacket sizeparamtrue if handshake completed (success or failure)return
Parameters:
id(protocol::PacketId)data(const uint8_t *)size(size_t)
Returns: bool
is_handshake_timeout
Section titled “is_handshake_timeout”bool is_handshake_timeout(uint64_t current_time_ms)Check if handshake has timed out.
current_time_msCurrent time in millisecondsparamtrue if handshake timeout has elapsedreturn
Parameters:
current_time_ms(uint64_t)
Returns: bool
generate_mac_address
Section titled “generate_mac_address”void generate_mac_address()Generate a unique MAC address.
Generates a locally administered MAC address. Format: X2:XX:XX:XX:XX:XX where X2 indicates locally administered.
start_backoff
Section titled “start_backoff”void start_backoff()Start backoff timer.
Records the current time and calculates backoff delay.
is_backoff_expired
Section titled “is_backoff_expired”bool is_backoff_expired(uint64_t current_time_ms)Check if backoff has expired.
current_time_msCurrent time in millisecondsparamtrue if backoff period has elapsedreturn
Parameters:
current_time_ms(uint64_t)
Returns: bool