ams::mitm::p2p::P2pProxyClient
ams::mitm::p2p::P2pProxyClient
Section titled “ams::mitm::p2p::P2pProxyClient”P2P Proxy Client.
TCP client that connects to a P2P host for direct LDN multiplayer. When a Switch joins a network with P2P enabled, this client establishes a direct connection to the host instead of going through the relay server.Thread SafetyAll public methods are thread-safe. Internal state is protected by mutex. client with packet callbackConnect(address, port) - establish TCP connectionPerformAuth(config) - send authentication- wait for ProxyConfigSend/receive proxy messages- cleanup
Members
Section titled “Members”FAILURE_TIMEOUT_MS
Section titled “FAILURE_TIMEOUT_MS”Type: constexpr int
Timeout for authentication and ready wait (milliseconds)
CONNECT_TIMEOUT_MS
Section titled “CONNECT_TIMEOUT_MS”Type: constexpr int
Connection timeout (milliseconds)
Members
Section titled “Members”m_mutex
Section titled “m_mutex”Type: os::Mutex
m_socket_fd
Section titled “m_socket_fd”Type: int
m_connected
Section titled “m_connected”Type: bool
m_disposed
Section titled “m_disposed”Type: bool
m_ready
Section titled “m_ready”Type: bool
m_ready_cv
Section titled “m_ready_cv”Type: os::ConditionVariable
m_proxy_config
Section titled “m_proxy_config”Type: ryu_ldn::protocol::ProxyConfig
m_recv_thread
Section titled “m_recv_thread”Type: os::ThreadType
m_recv_thread_stack
Section titled “m_recv_thread_stack”Type: uint8_t
m_recv_thread_running
Section titled “m_recv_thread_running”Type: bool
m_recv_buffer
Section titled “m_recv_buffer”Type: uint8_t
m_packet_callback
Section titled “m_packet_callback”Type: ProxyPacketCallback
Members
Section titled “Members”RECV_BUFFER_SIZE
Section titled “RECV_BUFFER_SIZE”Type: constexpr size_t
Methods
Section titled “Methods”P2pProxyClient
Section titled “P2pProxyClient”void P2pProxyClient(ProxyPacketCallback packet_callback)Constructor.
Initializes client state but does not establish a connection. Callto connect to a host.packet_callbackCallback for forwarding received proxy packetsparam
Parameters:
packet_callback(ProxyPacketCallback)
~P2pProxyClient
Section titled “~P2pProxyClient”void ~P2pProxyClient()Destructor - disconnects and cleans up.
Destructor.Ensures clean shutdown of socket and receive thread.
P2pProxyClient
Section titled “P2pProxyClient”void P2pProxyClient(const&)Parameters:
param(const&)
operator=
Section titled “operator=”& operator=(const&)Parameters:
param(const&)
Returns: &
Connect
Section titled “Connect”bool Connect(const char * address, uint16_t port)Connect to a P2P host.
Connect to a P2P host using string address.Establishes a TCP connection to the P2P host server. Does not perform authentication - callafter connecting.addressHost IP address as dotted decimal string (e.g., “192.168.1.100”)portHost port numberparamtrue if connection established successfullyreturnImplementation NotesParse IP address using inet_pton()Create TCP socketSet socket options (TCP_NODELAY for low latency)Connect with timeoutStart receive thread
Parameters:
address(const char *)port(uint16_t)
Returns: bool
Connect
Section titled “Connect”bool Connect(const uint8_t * ip_bytes, size_t ip_len, uint16_t port)Connect to a P2P host using IP bytes.
This overload is used when we have the IP address from ExternalProxyConfig.
Parameters:
ip_bytes(const uint8_t *)ip_len(size_t)port(uint16_t)
Returns: bool
Disconnect
Section titled “Disconnect”void Disconnect()Disconnect from the host.
Stops the receive thread and closes the socket. Safe to call multiple times.
IsConnected
Section titled “IsConnected”bool IsConnected()Check if connected to host.
Returns: bool
PerformAuth
Section titled “PerformAuth”bool PerformAuth(const ryu_ldn::protocol::ExternalProxyConfig & config)Perform P2P authentication.
Sends the ExternalProxyConfig to the host for token validation. The host will respond with ProxyConfig if authentication succeeds.Sends the ExternalProxyConfig packet to the host. The host validates the authentication token and responds with ProxyConfig on success.configExternalProxyConfig received from master serverparamtrue if authentication packet was sent successfullyreturnRyujinx Referencepublicnormalbool(ExternalProxyConfigconfig){_connected.WaitOne(FailureTimeout);SendAsync(_protocol.Encode(.ExternalProxy,config));normalreturnnormaltrue;}.cs
Parameters:
config(const ryu_ldn::protocol::ExternalProxyConfig &)
Returns: bool
EnsureProxyReady
Section titled “EnsureProxyReady”bool EnsureProxyReady(int timeout_ms)Wait for proxy to be ready.
Blocks until the host sends ProxyConfig (authentication success) or timeout expires.Blocks until the host sends ProxyConfig (indicating successful authentication) or timeout expires.timeout_msTimeout in millisecondsparamtrue if ProxyConfig received within timeoutreturnRyujinx Referencepublicnormalbool(){normalreturn_ready.WaitOne(FailureTimeout);}.cs
Parameters:
timeout_ms(int)
Returns: bool
IsReady
Section titled “IsReady”bool IsReady()Check if proxy is ready (authenticated)
Check if proxy is ready.
Returns: bool
GetProxyConfig
Section titled “GetProxyConfig”const& GetProxyConfig()Get the received ProxyConfig.
ProxyConfig from host (valid after EnsureProxyReady returns true)return
Returns: const&
GetVirtualIp
Section titled “GetVirtualIp”uint32_t GetVirtualIp()Get our virtual IP address.
Virtual IP assigned by host (valid after ready)return
Returns: uint32_t
SendProxyData
Section titled “SendProxyData”bool SendProxyData(const ryu_ldn::protocol::ProxyDataHeader & header, const uint8_t * data, size_t data_len)Send ProxyData to the host.
Send ProxyData to host.headerProxyData header with routing infodataPayload datadata_lenPayload lengthparamtrue if sent successfullyreturn
Parameters:
header(const ryu_ldn::protocol::ProxyDataHeader &)data(const uint8_t *)data_len(size_t)
Returns: bool
SendProxyConnect
Section titled “SendProxyConnect”bool SendProxyConnect(const ryu_ldn::protocol::ProxyConnectRequest & request)Send ProxyConnect request to the host.
Send ProxyConnect request to host.requestConnect request with destination infoparamtrue if sent successfullyreturn
Parameters:
request(const ryu_ldn::protocol::ProxyConnectRequest &)
Returns: bool
SendProxyConnectReply
Section titled “SendProxyConnectReply”bool SendProxyConnectReply(const ryu_ldn::protocol::ProxyConnectResponse & response)Send ProxyConnectReply to the host.
Send ProxyConnectReply to host.responseConnect responseparamtrue if sent successfullyreturn
Parameters:
response(const ryu_ldn::protocol::ProxyConnectResponse &)
Returns: bool
SendProxyDisconnect
Section titled “SendProxyDisconnect”bool SendProxyDisconnect(const ryu_ldn::protocol::ProxyDisconnectMessage & message)Send ProxyDisconnect to the host.
Send ProxyDisconnect to host.messageDisconnect messageparamtrue if sent successfullyreturn
Parameters:
message(const ryu_ldn::protocol::ProxyDisconnectMessage &)
Returns: bool
bool Send(const void * data, size_t size)Send raw packet data.
Send raw packet data to host.dataEncoded packetsizePacket sizeparamtrue if sent successfullyreturn
Parameters:
data(const void *)size(size_t)
Returns: bool
Methods
Section titled “Methods”ReceiveLoop
Section titled “ReceiveLoop”void ReceiveLoop()Receive loop thread function.
Continuously receives data from the socket and processes packets. Runs untilis called or connection is lost.
ProcessData
Section titled “ProcessData”void ProcessData(const uint8_t * data, size_t size)Process received data.
Parses the received buffer and dispatches each complete packet to the appropriate handler.dataBuffer containing received datasizeNumber of bytes in bufferparam
Parameters:
data(const uint8_t *)size(size_t)
HandleProxyConfig
Section titled “HandleProxyConfig”void HandleProxyConfig(const& config)Handle ProxyConfig from host.
This packet indicates successful authentication. The ProxyConfig contains our assigned virtual IP and subnet mask.Ryujinx ReferenceprivatenormalvoidHandleProxyConfig(LdnHeaderheader,ProxyConfigconfig){=config;SocketHelpers.RegisterProxy(newLdnProxy(config,this,_protocol));_ready.Set();}.cs
Parameters:
config(const&)
HandleProxyData
Section titled “HandleProxyData”void HandleProxyData(const ryu_ldn::protocol::ProxyDataHeader & header, const uint8_t * data, size_t data_len)Handle ProxyData from host.
Forward to the BSD MITM layer via callback.
Parameters:
header(const ryu_ldn::protocol::ProxyDataHeader &)data(const uint8_t *)data_len(size_t)
HandleProxyConnect
Section titled “HandleProxyConnect”void HandleProxyConnect(const ryu_ldn::protocol::ProxyConnectRequest & request)Handle ProxyConnect from host.
Forward to the BSD MITM layer via callback.
Parameters:
request(const ryu_ldn::protocol::ProxyConnectRequest &)
HandleProxyConnectReply
Section titled “HandleProxyConnectReply”void HandleProxyConnectReply(const ryu_ldn::protocol::ProxyConnectResponse & response)Handle ProxyConnectReply from host.
Forward to the BSD MITM layer via callback.
Parameters:
response(const ryu_ldn::protocol::ProxyConnectResponse &)
HandleProxyDisconnect
Section titled “HandleProxyDisconnect”void HandleProxyDisconnect(const ryu_ldn::protocol::ProxyDisconnectMessage & message)Handle ProxyDisconnect from host.
Forward to the BSD MITM layer via callback.
Parameters:
message(const ryu_ldn::protocol::ProxyDisconnectMessage &)