ams::mitm::bsd::ProxySocket
ams::mitm::bsd::ProxySocket
Section titled “ams::mitm::bsd::ProxySocket”Proxy Socket for LDN Network Communication.
This class represents a virtual socket that routes traffic through the Ryujinx LDN server via ProxyData packets instead of using real network sockets.Key FeaturesMimics BSD socket API (bind, connect, send, recv)Routes data via ProxyData protocol to serverMaintains receive queue for incoming dataSupports both UDP and TCP semanticsThread-safe receive queue Usage//CreateandbindaUDPproxysocketnormalnormalautosocket=std::make_unique<ProxySocket>(SocketType::Dgram,ProtocolType::Udp);socket->Bind(local_addr);normalnormal//Senddatatoapeernormalsocket->SendTo(data,data_len,remote_addr);normalnormal//Receivedata(blockingifnodataavailable)normalsocket->RecvFrom(buffer,buffer_size,&from_addr);.cpp
Members
Section titled “Members”m_type
Section titled “m_type”Type: ryu_ldn::bsd::SocketType
Socket type (Stream or Dgram)
m_protocol
Section titled “m_protocol”Type: ryu_ldn::bsd::ProtocolType
Protocol type (Tcp or Udp)
m_state
Section titled “m_state”Type: ProxySocketState
Current socket state.
m_non_blocking
Section titled “m_non_blocking”Type: bool
Non-blocking mode flag.
m_shutdown_read
Section titled “m_shutdown_read”Type: bool
Shutdown flags.
m_shutdown_write
Section titled “m_shutdown_write”Type: bool
m_local_addr
Section titled “m_local_addr”Type: ryu_ldn::bsd::SockAddrIn
Local address (set by Bind)
m_remote_addr
Section titled “m_remote_addr”Type: ryu_ldn::bsd::SockAddrIn
Remote address (set by Connect)
m_queue_mutex
Section titled “m_queue_mutex”Type: os::Mutex
Receive queue mutex.
m_receive_queue
Section titled “m_receive_queue”Type: std::deque<>
Receive queue (incoming packets)
m_receive_event
Section titled “m_receive_event”Type: os::Event
Event signaled when data is available.
m_accept_queue
Section titled “m_accept_queue”Type: std::deque< std::unique_ptr<> >
TCP accept queue (pending connections)
m_accept_event
Section titled “m_accept_event”Type: os::Event
Event signaled when accept queue has connections.
m_connect_response_received
Section titled “m_connect_response_received”Type: bool
TCP connect response received flag.
m_connect_response
Section titled “m_connect_response”Type: ryu_ldn::protocol::ProxyConnectResponse
TCP connect response data (valid when m_connect_response_received is true)
m_connect_event
Section titled “m_connect_event”Type: os::Event
Event signaled when connect response is received.
m_broadcast
Section titled “m_broadcast”Type: bool
Broadcast flag (SO_BROADCAST)
m_broadcast_address
Section titled “m_broadcast_address”Type: uint32_t
Broadcast address for filtering.
m_socket_options
Section titled “m_socket_options”Type: std::unordered_map< uint32_t, s32 >
Socket options storage.
Methods
Section titled “Methods”ProxySocket
Section titled “ProxySocket”void ProxySocket(ryu_ldn::bsd::SocketType type, ryu_ldn::bsd::ProtocolType protocol)Construct a new proxy socket.
Creates an unbound, unconnected proxy socket of the specified type.typeSocket type (Stream for TCP, Dgram for UDP)protocolProtocol type (Tcp or Udp)param
Parameters:
type(ryu_ldn::bsd::SocketType)protocol(ryu_ldn::bsd::ProtocolType)
~ProxySocket
Section titled “~ProxySocket”void ~ProxySocket()Destructor.
Cleans up resources. Does NOT send ProxyDisconnect - callfirst.
ProxySocket
Section titled “ProxySocket”void ProxySocket(const&)Non-copyable (socket identity is unique)
Parameters:
param(const&)
operator=
Section titled “operator=”& operator=(const&)Parameters:
param(const&)
Returns: &
ProxySocket
Section titled “ProxySocket”void ProxySocket(&&)Move constructor.
Parameters:
param(&&)
operator=
Section titled “operator=”& operator=(&&)Parameters:
param(&&)
Returns: &
GetState
Section titled “GetState”ProxySocketState GetState()Get the current socket state.
Current state (Created, Bound, Connected, etc.)return
Returns: ProxySocketState
GetType
Section titled “GetType”ryu_ldn::bsd::SocketType GetType()Get the socket type.
Socket type (Stream or Dgram)return
Returns: ryu_ldn::bsd::SocketType
GetProtocol
Section titled “GetProtocol”ryu_ldn::bsd::ProtocolType GetProtocol()Get the protocol type.
Protocol type (Tcp or Udp)return
Returns: ryu_ldn::bsd::ProtocolType
IsNonBlocking
Section titled “IsNonBlocking”bool IsNonBlocking()Check if socket is non-blocking.
true if non-blocking mode is enabledreturn
Returns: bool
SetNonBlocking
Section titled “SetNonBlocking”void SetNonBlocking(bool non_blocking)Set non-blocking mode.
non_blockingtrue to enable non-blocking modeparam
Parameters:
non_blocking(bool)
Result Bind(const& addr)Bind the socket to a local address.
Assigns a local address and port to the socket. If the port is 0, the caller should allocate an ephemeral port before calling this.addrLocal address to bind to (must be in LDN network 10.114.x.x)paramSuccess or error (e.g., already bound, invalid address)returnDoes not validate that the address is actually ours - caller must checknote
Parameters:
addr(const&)
Returns: Result
Connect
Section titled “Connect”Result Connect(const& addr)Connect to a remote address.
For TCP, this initiates a connection to the remote peer. For UDP, this sets the default destination for.addrRemote address to connect toparamSuccess or errorreturnFor TCP, this should trigger sending ProxyConnect to the servernote
Parameters:
addr(const&)
Returns: Result
GetSockName
Section titled “GetSockName”Result GetSockName(* out_addr)Get the local address.
out_addrOutput: local addressparamSuccess or error if not boundreturn
Parameters:
out_addr(*)
Returns: Result
GetPeerName
Section titled “GetPeerName”Result GetPeerName(* out_addr)Get the remote address (connected sockets only)
out_addrOutput: remote addressparamSuccess or error if not connectedreturn
Parameters:
out_addr(*)
Returns: Result
GetLocalAddr
Section titled “GetLocalAddr”const& GetLocalAddr()Get the local address reference.
Reference to local address structurereturn
Returns: const&
GetRemoteAddr
Section titled “GetRemoteAddr”const& GetRemoteAddr()Get the remote address reference.
Reference to remote address structurereturn
Returns: const&
s32 Send(const void * data, size_t len, s32 flags)Send data (connected sockets only)
Sends data to the connected peer. Socket must be connected first.dataPointer to data to sendlenLength of dataflagsSend flags (currently ignored)paramBytes sent or negative errno on errorreturn
Parameters:
data(const void *)len(size_t)flags(s32)
Returns: s32
SendTo
Section titled “SendTo”s32 SendTo(const void * data, size_t len, s32 flags, const& dest)Send data to a specific address.
Sends data to the specified destination. Does not require connection.dataPointer to data to sendlenLength of dataflagsSend flags (currently ignored)destDestination addressparamBytes sent or negative errno on errorreturn
Parameters:
data(const void *)len(size_t)flags(s32)dest(const&)
Returns: s32
s32 Recv(void * buffer, size_t len, s32 flags)Receive data (connected sockets only)
Receives data from the connected peer.bufferBuffer to receive intolenBuffer sizeflagsReceive flags (currently supports MSG_PEEK, MSG_DONTWAIT)paramBytes received, 0 if connection closed, or negative errno on errorreturn
Parameters:
buffer(void *)len(size_t)flags(s32)
Returns: s32
RecvFrom
Section titled “RecvFrom”s32 RecvFrom(void * buffer, size_t len, s32 flags, * from)Receive data with source address.
Receives data and returns the source address.bufferBuffer to receive intolenBuffer sizeflagsReceive flagsfromOutput: source address (can be nullptr)paramBytes received, 0 if connection closed, or negative errno on errorreturn
Parameters:
buffer(void *)len(size_t)flags(s32)from(*)
Returns: s32
IncomingData
Section titled “IncomingData”void IncomingData(const void * data, size_t len, const& from)Queue incoming data from a ProxyData packet.
Called by thewhen a ProxyData packet arrives that matches this socket.dataPacket payloadlenPayload lengthfromSource addressparamThread-safe. Signals the receive event.note
Parameters:
data(const void *)len(size_t)from(const&)
SetSockOpt
Section titled “SetSockOpt”Result SetSockOpt(s32 level, s32 optname, const void * optval, size_t optlen)Set a socket option.
Most options are stored locally and don’t affect real network behavior since we’re proxying through the server.levelOption level (SOL_SOCKET, etc.)optnameOption nameoptvalOption valueoptlenOption value lengthparamSuccess or errorreturn
Parameters:
level(s32)optname(s32)optval(const void *)optlen(size_t)
Returns: Result
GetSockOpt
Section titled “GetSockOpt”Result GetSockOpt(s32 level, s32 optname, void * optval, size_t * optlen)Get a socket option.
levelOption leveloptnameOption nameoptvalOutput: option valueoptlenInput/Output: option value lengthparamSuccess or errorreturn
Parameters:
level(s32)optname(s32)optval(void *)optlen(size_t *)
Returns: Result
Listen
Section titled “Listen”Result Listen(s32 backlog)Start listening for connections (TCP only)
backlogMaximum pending connections (currently ignored)paramSuccess or error if not TCP or not boundreturn
Parameters:
backlog(s32)
Returns: Result
Accept
Section titled “Accept”std::unique_ptr<> Accept(* out_addr)Accept a connection (TCP only)
Blocks until a connection is available (unless non-blocking).out_addrOutput: connecting peer’s addressparamNew connectedor nullptr on errorreturnThe returned socket is owned by the callernote
Parameters:
out_addr(*)
Returns: std::unique_ptr<>
IncomingConnection
Section titled “IncomingConnection”void IncomingConnection(const ryu_ldn::protocol::ProxyConnectRequest & request)Queue an incoming connection request (TCP listen socket)
Called bywhen a ProxyConnect packet arrives for this listening socket.requestThe connection request infoparam
Parameters:
request(const ryu_ldn::protocol::ProxyConnectRequest &)
HandleConnectResponse
Section titled “HandleConnectResponse”void HandleConnectResponse(const ryu_ldn::protocol::ProxyConnectResponse & response)Handle connect response (for TCP connect handshake)
Called bywhen ProxyConnectReply arrives.responseThe connect responseparam
Parameters:
response(const ryu_ldn::protocol::ProxyConnectResponse &)
HasPendingConnections
Section titled “HasPendingConnections”bool HasPendingConnections()Check if accept queue has pending connections.
true if there are pending connectionsreturn
Returns: bool
IsBroadcastEnabled
Section titled “IsBroadcastEnabled”bool IsBroadcastEnabled()Get broadcast flag.
true if SO_BROADCAST is enabledreturn
Returns: bool
SetBroadcastEnabled
Section titled “SetBroadcastEnabled”void SetBroadcastEnabled(bool enabled)Set broadcast flag (SO_BROADCAST)
enabledtrue to enable broadcast receptionparam
Parameters:
enabled(bool)
SetBroadcastAddress
Section titled “SetBroadcastAddress”void SetBroadcastAddress(uint32_t addr)Set broadcast address for filtering.
addrBroadcast address (e.g., 10.114.255.255)param
Parameters:
addr(uint32_t)
Shutdown
Section titled “Shutdown”Result Shutdown(ryu_ldn::bsd::ShutdownHow how)Shutdown the socket.
howHow to shutdown (read, write, or both)paramSuccess or errorreturn
Parameters:
how(ryu_ldn::bsd::ShutdownHow)
Returns: Result
Result Close()Close the socket.
Marks the socket as closed and releases resources. For TCP, this may send ProxyDisconnect to the server.Success or errorreturn
Returns: Result
HasPendingData
Section titled “HasPendingData”bool HasPendingData()Check if data is available to read.
true if receive queue is not emptyreturn
Returns: bool
GetPendingDataSize
Section titled “GetPendingDataSize”size_t GetPendingDataSize()Get the number of bytes available to read.
Total bytes in receive queuereturn
Returns: size_t
WaitForData
Section titled “WaitForData”bool WaitForData(u64 timeout_ms)Wait for data to be available.
Blocks until data is available or timeout expires.timeout_msTimeout in milliseconds (0 = infinite)paramtrue if data is available, false if timeoutreturn
Parameters:
timeout_ms(u64)
Returns: bool
GetReceiveEvent
Section titled “GetReceiveEvent”os::Event & GetReceiveEvent()Get the receive event handle.
Can be used with poll/select to wait for data.Reference to the receive eventreturn
Returns: os::Event &
Methods
Section titled “Methods”PopFrontPacket
Section titled “PopFrontPacket”ReceivedPacket PopFrontPacket(bool peek)Pop the front packet from the receive queue.
peekIf true, don’t remove from queue (MSG_PEEK)paramThe front packet, or empty if queue is emptyreturnCaller must hold m_queue_mutexnote
Parameters:
peek(bool)
Returns: ReceivedPacket
Methods
Section titled “Methods”MakeOptionKey
Section titled “MakeOptionKey”constexpr uint32_t MakeOptionKey(s32 level, s32 optname)Helper to get option key from level and optname.
Parameters:
level(s32)optname(s32)
Returns: constexpr uint32_t