Skip to content

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

Type: constexpr int

Timeout for authentication and ready wait (milliseconds)

Type: constexpr int

Connection timeout (milliseconds)

Type: os::Mutex

Type: int

Type: bool

Type: bool

Type: bool

Type: os::ConditionVariable

Type: ryu_ldn::protocol::ProxyConfig

Type: os::ThreadType

Type: uint8_t

Type: bool

Type: uint8_t

Type: ProxyPacketCallback

Type: constexpr size_t

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)
void ~P2pProxyClient()

Destructor - disconnects and cleans up.

Destructor.Ensures clean shutdown of socket and receive thread.

void P2pProxyClient(const&)

Parameters:

  • param (const&)
& operator=(const&)

Parameters:

  • param (const&)

Returns: &

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

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

void Disconnect()

Disconnect from the host.

Stops the receive thread and closes the socket. Safe to call multiple times.

bool IsConnected()

Check if connected to host.

Returns: bool

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

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

bool IsReady()

Check if proxy is ready (authenticated)

Check if proxy is ready.

Returns: bool

const& GetProxyConfig()

Get the received ProxyConfig.

ProxyConfig from host (valid after EnsureProxyReady returns true)return

Returns: const&

uint32_t GetVirtualIp()

Get our virtual IP address.

Virtual IP assigned by host (valid after ready)return

Returns: uint32_t

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

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

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

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

void ReceiveLoop()

Receive loop thread function.

Continuously receives data from the socket and processes packets. Runs untilis called or connection is lost.

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)
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&)
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)
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 &)
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 &)
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 &)