ams::mitm::ldn::ICommunicationService
ams::mitm::ldn::ICommunicationService
Section titled “ams::mitm::ldn::ICommunicationService”LDN Communication Service implementation.
This class implements the IUserLocalCommunicationService interface, handling all LDN operations and forwarding them to our RyuLdn server via the network client.State ManagementThe service maintains an LDN state machine:State changes are notified via the state change event.
Members
Section titled “Members”m_state_machine
Section titled “m_state_machine”Type: LdnStateMachine
Thread-safe state machine.
m_error_state
Section titled “m_error_state”Type: u64
Error state flag.
m_client_process_id
Section titled “m_client_process_id”Type: u64
Client game process ID.
m_network_info
Section titled “m_network_info”Type: NetworkInfo
Current network info.
m_disconnect_reason
Section titled “m_disconnect_reason”Type: DisconnectReason
Last disconnect reason.
m_ipv4_address
Section titled “m_ipv4_address”Type: u32
Assigned IPv4 address.
m_subnet_mask
Section titled “m_subnet_mask”Type: u32
Subnet mask.
m_server_client
Section titled “m_server_client”Type: ryu_ldn::network::RyuLdnClient
Server communication client.
m_server_connected
Section titled “m_server_connected”Type: bool
Server connection status.
m_node_mapper
Section titled “m_node_mapper”Type: LdnNodeMapper
Node ID to IP mapping.
m_proxy_buffer
Section titled “m_proxy_buffer”Type: LdnProxyBuffer
Incoming proxy data buffer.
m_response_event
Section titled “m_response_event”Type: os::Event
Signaled when any response received.
m_scan_event
Section titled “m_scan_event”Type: os::Event
Signaled when scan completes.
m_error_event
Section titled “m_error_event”Type: os::Event
Signaled on network error.
m_reject_event
Section titled “m_reject_event”Type: os::Event
Signaled when reject reply received.
m_last_response_id
Section titled “m_last_response_id”Type: ryu_ldn::protocol::PacketId
Last received packet ID.
m_scan_results
Section titled “m_scan_results”Type: NetworkInfo
Scan results buffer.
m_scan_result_count
Section titled “m_scan_result_count”Type: size_t
Number of scan results.
m_advertise_data
Section titled “m_advertise_data”Type: uint8_t
Stored advertise data.
m_advertise_data_size
Section titled “m_advertise_data_size”Type: size_t
Size of advertise data.
m_game_version
Section titled “m_game_version”Type: uint8_t
Game version string for CreateAccessPoint.
m_network_connected
Section titled “m_network_connected”Type: bool
True when in active network session.
m_prev_node_connected
Section titled “m_prev_node_connected”Type: bool
Previous connected state of each node.
m_last_network_error
Section titled “m_last_network_error”Type: ryu_ldn::protocol::NetworkErrorCode
Last error from server.
m_use_p2p_proxy
Section titled “m_use_p2p_proxy”Type: bool
True if P2P proxy enabled.
m_proxy_config
Section titled “m_proxy_config”Type: ryu_ldn::protocol::ProxyConfig
Current proxy configuration.
m_external_proxy_config
Section titled “m_external_proxy_config”Type: ryu_ldn::protocol::ExternalProxyConfig
External proxy config.
m_p2p_client
Section titled “m_p2p_client”Type: *
Connected P2P proxy client (joiner side)
m_p2p_server
Section titled “m_p2p_server”Type: *
Hosted P2P proxy server (host side)
m_inactivity_timeout
Section titled “m_inactivity_timeout”Type: NetworkTimeout
Auto-disconnect after idle period.
m_background_thread
Section titled “m_background_thread”Type: os::ThreadType
Background packet processing thread.
m_background_thread_running
Section titled “m_background_thread_running”Type: std::atomic< bool >
Thread running flag.
m_client_mutex
Section titled “m_client_mutex”Type: os::Mutex
Mutex for m_server_client access.
m_program_id
Section titled “m_program_id”Type: ncm::ProgramId
Client program ID (title ID)
m_local_communication_id
Section titled “m_local_communication_id”Type: u64
LocalCommunicationId from NACP (for LDN filtering)
Members
Section titled “Members”MAX_SCAN_RESULTS
Section titled “MAX_SCAN_RESULTS”Type: constexpr size_t
Max networks from scan (reduced from 24)
Methods
Section titled “Methods”ICommunicationService
Section titled “ICommunicationService”void ICommunicationService(ncm::ProgramId program_id)Constructor.
program_idProgram ID of the client process (used to replace LocalCommunicationId=-1)param
Parameters:
program_id(ncm::ProgramId)
~ICommunicationService
Section titled “~ICommunicationService”void ~ICommunicationService()Destructor.
GetState
Section titled “GetState”Result GetState(ams::sf::Out< u32 > state)Get current communication state.
stateOutput state valueparamResult codereturn
Parameters:
state(ams::sf::Out< u32 >)
Returns: Result
GetNetworkInfo
Section titled “GetNetworkInfo”Result GetNetworkInfo(ams::sf::Out<> buffer)Get current network information.
bufferOutput network infoparamResult codereturn
Parameters:
buffer(ams::sf::Out<>)
Returns: Result
GetIpv4Address
Section titled “GetIpv4Address”Result GetIpv4Address(ams::sf::Out< u32 > address, ams::sf::Out< u32 > mask)Get assigned IPv4 address.
addressOutput IP address (host byte order)maskOutput subnet mask (host byte order)paramResult codereturn
Parameters:
address(ams::sf::Out< u32 >)mask(ams::sf::Out< u32 >)
Returns: Result
GetDisconnectReason
Section titled “GetDisconnectReason”Result GetDisconnectReason(ams::sf::Out< u32 > reason)Get last disconnect reason.
reasonOutput disconnect reasonparamResult codereturn
Parameters:
reason(ams::sf::Out< u32 >)
Returns: Result
GetSecurityParameter
Section titled “GetSecurityParameter”Result GetSecurityParameter(ams::sf::Out<> out)Get security parameters.
outOutput security parameterparamResult codereturn
Parameters:
out(ams::sf::Out<>)
Returns: Result
GetNetworkConfig
Section titled “GetNetworkConfig”Result GetNetworkConfig(ams::sf::Out<> out)Get network configuration.
outOutput network configparamResult codereturn
Parameters:
out(ams::sf::Out<>)
Returns: Result
AttachStateChangeEvent
Section titled “AttachStateChangeEvent”Result AttachStateChangeEvent(ams::sf::Out< ams::sf::CopyHandle > handle)Attach to state change event.
handleOutput event handleparamResult codereturn
Parameters:
handle(ams::sf::Out< ams::sf::CopyHandle >)
Returns: Result
GetNetworkInfoLatestUpdate
Section titled “GetNetworkInfoLatestUpdate”Result GetNetworkInfoLatestUpdate(ams::sf::Out<> buffer, ams::sf::OutArray<> pUpdates)Get network info with node updates.
bufferOutput network infopUpdatesOutput node update arrayparamResult codereturn
Parameters:
buffer(ams::sf::Out<>)pUpdates(ams::sf::OutArray<>)
Returns: Result
Result Scan(ams::sf::Out< u32 > count, ams::sf::OutAutoSelectArray<> buffer, u16 channel, ScanFilter filter)Scan for available networks.
countOutput number of networks foundbufferOutput network info arraychannelChannel to scan (0 for all)filterScan filterparamResult codereturn
Parameters:
count(ams::sf::Out< u32 >)buffer(ams::sf::OutAutoSelectArray<>)channel(u16)filter(ScanFilter)
Returns: Result
OpenAccessPoint
Section titled “OpenAccessPoint”Result OpenAccessPoint()Open as access point (host mode)
Result codereturn
Returns: Result
CloseAccessPoint
Section titled “CloseAccessPoint”Result CloseAccessPoint()Close access point.
Result codereturn
Returns: Result
CreateNetwork
Section titled “CreateNetwork”Result CreateNetwork(CreateNetworkConfig data)Create a network.
dataNetwork creation configurationparamResult codereturn
Parameters:
data(CreateNetworkConfig)
Returns: Result
DestroyNetwork
Section titled “DestroyNetwork”Result DestroyNetwork()Destroy the network.
Result codereturn
Returns: Result
SetAdvertiseData
Section titled “SetAdvertiseData”Result SetAdvertiseData(ams::sf::InAutoSelectBuffer data)Set advertise data.
dataAdvertise data bufferparamResult codereturn
Parameters:
data(ams::sf::InAutoSelectBuffer)
Returns: Result
SetStationAcceptPolicy
Section titled “SetStationAcceptPolicy”Result SetStationAcceptPolicy(u8 policy)Set station accept policy.
policyAccept policyparamResult codereturn
Parameters:
policy(u8)
Returns: Result
OpenStation
Section titled “OpenStation”Result OpenStation()Open as station (client mode)
Result codereturn
Returns: Result
CloseStation
Section titled “CloseStation”Result CloseStation()Close station.
Result codereturn
Returns: Result
Connect
Section titled “Connect”Result Connect(ConnectNetworkData dat, const& data)Connect to a network.
datConnection datadataNetwork to connect toparamResult codereturn
Parameters:
dat(ConnectNetworkData)data(const&)
Returns: Result
Disconnect
Section titled “Disconnect”Result Disconnect()Disconnect from network.
Result codereturn
Returns: Result
Initialize
Section titled “Initialize”Result Initialize(const ams::sf::ClientProcessId & client_process_id)Initialize the service.
client_process_idClient process IDparamResult codereturn
Parameters:
client_process_id(const ams::sf::ClientProcessId &)
Returns: Result
Finalize
Section titled “Finalize”Result Finalize()Finalize the service.
Result codereturn
Returns: Result
InitializeSystem2
Section titled “InitializeSystem2”Result InitializeSystem2(u64 unk, const ams::sf::ClientProcessId & client_process_id)Initialize with system flags.
unkUnknown parameterclient_process_idClient process IDparamResult codereturn
Parameters:
unk(u64)client_process_id(const ams::sf::ClientProcessId &)
Returns: Result
ScanPrivate
Section titled “ScanPrivate”Result ScanPrivate(ams::sf::Out< u32 > count, ams::sf::OutAutoSelectArray<> buffer, u16 channel, ScanFilter filter)Scan for private networks.
Same asbut includes private networks in results.countOutput number of networks foundbufferOutput network info arraychannelChannel to scan (0 for all)filterScan filterparamResult codereturn
Parameters:
count(ams::sf::Out< u32 >)buffer(ams::sf::OutAutoSelectArray<>)channel(u16)filter(ScanFilter)
Returns: Result
CreateNetworkPrivate
Section titled “CreateNetworkPrivate”Result CreateNetworkPrivate(CreateNetworkPrivateConfig data, ams::sf::InPointerBuffer addressList)Create a private (password-protected) network.
dataNetwork configuration including security parameteraddressListAddress list bufferparamResult codereturn
Parameters:
data(CreateNetworkPrivateConfig)addressList(ams::sf::InPointerBuffer)
Returns: Result
ConnectPrivate
Section titled “ConnectPrivate”Result ConnectPrivate(ConnectPrivateData data)Connect to a private network.
dataConnection data including security parameterparamResult codereturn
Parameters:
data(ConnectPrivateData)
Returns: Result
SetWirelessControllerRestriction
Section titled “SetWirelessControllerRestriction”Result SetWirelessControllerRestriction()Set wireless controller restriction.
Result code (stub)return
Returns: Result
Reject
Section titled “Reject”Result Reject(u32 nodeId)Reject a node from the network.
nodeIdNode ID to rejectparamResult codereturn
Parameters:
nodeId(u32)
Returns: Result
AddAcceptFilterEntry
Section titled “AddAcceptFilterEntry”Result AddAcceptFilterEntry()Add entry to accept filter.
Result code (stub)return
Returns: Result
ClearAcceptFilter
Section titled “ClearAcceptFilter”Result ClearAcceptFilter()Clear accept filter.
Result code (stub)return
Returns: Result
SendProxyDataToServer
Section titled “SendProxyDataToServer”ryu_ldn::network::ClientOpResult SendProxyDataToServer(const ryu_ldn::protocol::ProxyDataHeader & header, const void * data, size_t data_len)Send ProxyData to server (for BSD MITM callback)
This method is called by the BSD MITM layer to send game socket data through the LDN server connection.headerProxyData header with addressing infodataPacket payloaddata_lenPayload lengthparamClientOpResult indicating success or failurereturn
Parameters:
header(const ryu_ldn::protocol::ProxyDataHeader &)data(const void *)data_len(size_t)
Returns: ryu_ldn::network::ClientOpResult
Methods
Section titled “Methods”ConnectToServer
Section titled “ConnectToServer”Result ConnectToServer()Connect to RyuLdn server.
Result codereturn
Returns: Result
DisconnectFromServer
Section titled “DisconnectFromServer”void DisconnectFromServer()Disconnect from RyuLdn server.
IsServerConnected
Section titled “IsServerConnected”bool IsServerConnected()Check if connected to server.
true if connected and readyreturn
Returns: bool
HandleServerPacket
Section titled “HandleServerPacket”void HandleServerPacket(ryu_ldn::protocol::PacketId id, const uint8_t * data, size_t size)Handle packet received from server.
idPacket typedataPacket payloadsizePayload sizeparam
Parameters:
id(ryu_ldn::protocol::PacketId)data(const uint8_t *)size(size_t)
WaitForResponse
Section titled “WaitForResponse”bool WaitForResponse(ryu_ldn::protocol::PacketId expected_id, uint64_t timeout_ms)Wait for a specific packet response from server.
expected_idExpected packet typetimeout_msTimeout in millisecondsparamtrue if packet received, false on timeoutreturn
Parameters:
expected_id(ryu_ldn::protocol::PacketId)timeout_ms(uint64_t)
Returns: bool
BackgroundThreadFunc
Section titled “BackgroundThreadFunc”void BackgroundThreadFunc()Background thread main loop - processes server pings.
FindLocalNodeId
Section titled “FindLocalNodeId”u8 FindLocalNodeId()Find our local node ID in the network info.
Searches through the nodes array to find the node matching our m_ipv4_address. Returns 0xFF if not found.Node ID (0-7) or 0xFF if not foundreturn
Returns: u8
SetGameVersion
Section titled “SetGameVersion”void SetGameVersion(const uint8_t * version)Set game version from local_communication_version.
Converts version number to string format for RyuNetworkConfig.versionVersion buffer (16 bytes)param
Parameters:
version(const uint8_t *)
ConsumeNetworkError
Section titled “ConsumeNetworkError”ryu_ldn::protocol::NetworkErrorCode ConsumeNetworkError()Consume last network error (like Ryujinx ConsumeNetworkError)
Returns the last error and resets it to None.Last network error codereturn
Returns: ryu_ldn::protocol::NetworkErrorCode
HandleExternalProxyConnect
Section titled “HandleExternalProxyConnect”void HandleExternalProxyConnect(const ryu_ldn::protocol::ExternalProxyConfig & config)Handle ExternalProxy packet - connect to P2P host.
Called when server sends ExternalProxyConfig indicating a P2P host is available. Creates P2pProxyClient and establishes direct connection.configExternalProxyConfig from master serverparam
Parameters:
config(const ryu_ldn::protocol::ExternalProxyConfig &)
DisconnectP2pProxy
Section titled “DisconnectP2pProxy”void DisconnectP2pProxy()Disconnect from P2P proxy if connected.
StartP2pProxyServer
Section titled “StartP2pProxyServer”bool StartP2pProxyServer()Start P2P proxy server for hosting.
Called when creating a network. Starts P2pProxyServer and attempts UPnP NAT punch to allow direct P2P connections.true if server started (UPnP may or may not succeed)return
Returns: bool
StopP2pProxyServer
Section titled “StopP2pProxyServer”void StopP2pProxyServer()Stop P2P proxy server if running.
HandleExternalProxyToken
Section titled “HandleExternalProxyToken”void HandleExternalProxyToken(const& token)Handle ExternalProxyToken from master server.
Called when master server notifies us a joiner is about to connect. Adds token to waiting list for authentication.tokenToken for the expected joinerparam
Parameters:
token(const&)
Methods
Section titled “Methods”BackgroundThreadEntry
Section titled “BackgroundThreadEntry”void BackgroundThreadEntry(void * arg)Background thread entry point.
argPointer toinstanceparam
Parameters:
arg(void *)
OnInactivityTimeout
Section titled “OnInactivityTimeout”void OnInactivityTimeout()Static callback for inactivity timeout.
Called when the timeout expires. Disconnects from server.Called when theexpires (no network activity for 6 seconds). Disconnects from the server to save resources. Like Ryujinx _timeout callback that calls DisconnectInternal().