ryu_ldn::ldn::LdnProxyHandler
ryu_ldn::ldn::LdnProxyHandler
Section titled “ryu_ldn::ldn::LdnProxyHandler”LDN Proxy Handler.
Manages P2P connections tunneled through the RyuLDN server. Maintains a table of active virtual connections and provides callbacks for connection events and data reception.Thread SafetyNOT thread-safe. All methods should be called from the same thread.classryu__ldn_1_1ldn_1_1LdnProxyHandler_1Usage Exampleproxy;normalproxy.set_config_callback({printf(“ProxyIP:%08X\n”,cfg.proxy_ip);});normalproxy.set_data_callback({normal//Forwardtogamenormal});normalnormal//Handlerisconnectedtopacketdispatchernormaldispatcher.set_proxy_config_handler(&{proxy.handle_proxy_config(h,c);});.cppclassryu__ldn_1_1ldn_1_1LdnProxyHandler_1
Members
Section titled “Members”m_configured
Section titled “m_configured”Type: bool
Whether ProxyConfig received.
m_proxy_ip
Section titled “m_proxy_ip”Type: uint32_t
Configured proxy IP.
m_proxy_subnet_mask
Section titled “m_proxy_subnet_mask”Type: uint32_t
Configured subnet mask.
m_connections
Section titled “m_connections”Type: std::vector<>
Active connection table.
m_config_callback
Section titled “m_config_callback”Type: ProxyConfigCallback
m_connect_callback
Section titled “m_connect_callback”Type: ProxyConnectCallback
m_connect_reply_callback
Section titled “m_connect_reply_callback”Type: ProxyConnectReplyCallback
m_data_callback
Section titled “m_data_callback”Type: ProxyDataCallback
m_disconnect_callback
Section titled “m_disconnect_callback”Type: ProxyDisconnectCallback
Methods
Section titled “Methods”LdnProxyHandler
Section titled “LdnProxyHandler”void LdnProxyHandler()Default constructor.
Construct a new.Creates handler in unconfigured state with no connections.Initializes handler in unconfigured state with empty connection table. No callbacks are registered initially.
~LdnProxyHandler
Section titled “~LdnProxyHandler”void ~LdnProxyHandler()Destructor.
LdnProxyHandler
Section titled “LdnProxyHandler”void LdnProxyHandler(const&)Parameters:
param(const&)
operator=
Section titled “operator=”& operator=(const&)Parameters:
param(const&)
Returns: &
set_config_callback
Section titled “set_config_callback”void set_config_callback(ProxyConfigCallback callback)Set callback for proxy configuration.
The callback is invoked when ProxyConfig packet is received. Use this to initialize the virtual network interface.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(ProxyConfigCallback)
set_connect_callback
Section titled “set_connect_callback”void set_connect_callback(ProxyConnectCallback callback)Set callback for incoming connect requests.
Called when a peer initiates a P2P connection to us. The application should prepare to receive data from this peer.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(ProxyConnectCallback)
set_connect_reply_callback
Section titled “set_connect_reply_callback”void set_connect_reply_callback(ProxyConnectReplyCallback callback)Set callback for connect replies.
Called when a peer responds to our connect request. A successful reply means the connection is established.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(ProxyConnectReplyCallback)
set_data_callback
Section titled “set_data_callback”void set_data_callback(ProxyDataCallback callback)Set callback for proxy data.
Called when game data arrives through the proxy tunnel. This is the main data path for P2P communication.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(ProxyDataCallback)
set_disconnect_callback
Section titled “set_disconnect_callback”void set_disconnect_callback(ProxyDisconnectCallback callback)Set callback for disconnect events.
Called when a proxied connection is closed by peer or server. The application should clean up resources for this connection.callbackFunction pointer or nullptr to disableparam
Parameters:
callback(ProxyDisconnectCallback)
handle_proxy_config
Section titled “handle_proxy_config”void handle_proxy_config(const protocol::LdnHeader & header, const& config)Handle ProxyConfig packet.
Configures the proxy with virtual network settings. Marks the handler as configured.Server sends ProxyConfig when we join a session to tell us the virtual network settings:This information is used to configure the virtual network interface that the game communicates through.headerPacket header (unused but kept for consistency)configProxy configuration with network settingsparam
Parameters:
header(const protocol::LdnHeader &)config(const&)
handle_proxy_connect
Section titled “handle_proxy_connect”void handle_proxy_connect(const protocol::LdnHeader & header, const protocol::ProxyConnectRequest & req)Handle ProxyConnect packet.
Handles incoming P2P connection request from peer. Adds entry to connection table.Server sends ProxyConnect when a peer wants to establish a P2P connection to us. The info contains:We add this to our connection table to track the active connection.headerPacket header (unused)reqConnect request with connection infoparam
Parameters:
header(const protocol::LdnHeader &)req(const protocol::ProxyConnectRequest &)
handle_proxy_connect_reply
Section titled “handle_proxy_connect_reply”void handle_proxy_connect_reply(const protocol::LdnHeader & header, const protocol::ProxyConnectResponse & resp)Handle ProxyConnectReply packet.
Handles response to our connect request.Server sends ProxyConnectReply in response to our connect request. The info echoes back the connection details, confirming establishment.Note: We don’t add to connection table here because we already added it when we sent the connect request.headerPacket header (unused)respConnect response with connection infoparam
Parameters:
header(const protocol::LdnHeader &)resp(const protocol::ProxyConnectResponse &)
handle_proxy_data
Section titled “handle_proxy_data”void handle_proxy_data(const protocol::LdnHeader & header, const protocol::ProxyDataHeader & data_header, const uint8_t * payload, size_t payload_length)Handle ProxyData packet.
Handles game data received through proxy tunnel.Server relays game data from peers through ProxyData packets. Each packet contains:The application callback receives the raw payload to forward to the game’s virtual network interface.headerPacket header (unused)data_headerProxy data header with connection info and lengthpayloadPointer to game data (may be nullptr if length is 0)payload_lengthLength of payload in bytesparam
Parameters:
header(const protocol::LdnHeader &)data_header(const protocol::ProxyDataHeader &)payload(const uint8_t *)payload_length(size_t)
handle_proxy_disconnect
Section titled “handle_proxy_disconnect”void handle_proxy_disconnect(const protocol::LdnHeader & header, const protocol::ProxyDisconnectMessage & msg)Handle ProxyDisconnect packet.
Handles notification that a proxied connection was closed. Removes entry from connection table.Server sends ProxyDisconnect when a P2P connection is closed:We remove the connection from our table and notify the application.headerPacket header (unused)msgDisconnect message with connection info and reasonparam
Parameters:
header(const protocol::LdnHeader &)msg(const protocol::ProxyDisconnectMessage &)
is_configured
Section titled “is_configured”bool is_configured()Check if proxy is configured.
true if ProxyConfig has been receivedreturn
Returns: bool
get_proxy_ip
Section titled “get_proxy_ip”uint32_t get_proxy_ip()Get configured proxy IP.
Proxy server IP address (0 if not configured)return
Returns: uint32_t
get_proxy_subnet_mask
Section titled “get_proxy_subnet_mask”uint32_t get_proxy_subnet_mask()Get configured subnet mask.
Proxy subnet mask (0 if not configured)return
Returns: uint32_t
get_connection_count
Section titled “get_connection_count”size_t get_connection_count()Get number of active connections.
Count of entries in connection tablereturn
Returns: size_t
has_connection
Section titled “has_connection”bool has_connection(uint32_t src_ip, uint16_t src_port, uint32_t dest_ip, uint16_t dest_port, protocol::ProtocolType proto)Check if a connection exists.
Check if a connection exists in the table.Searches the connection table for an entry matching all parameters. Note that protocol type matters - TCP and UDP connections are distinct.src_ipSource IPv4 addresssrc_portSource portdest_ipDestination IPv4 addressdest_portDestination portprotoProtocol type (default UDP)paramtrue if a matching connection existsreturn
Parameters:
src_ip(uint32_t)src_port(uint16_t)dest_ip(uint32_t)dest_port(uint16_t)proto(protocol::ProtocolType)
Returns: bool
void reset()Reset handler to initial state.
Clears configuration and all connections. Does not clear callbacks.Clears:Does NOT clear callbacks - they persist across resets.
Methods
Section titled “Methods”add_connection
Section titled “add_connection”void add_connection(const protocol::ProxyInfo & info)Add a connection to the table.
Creates a newentry from the given ProxyInfo and appends it to the connection vector.Note: Does not check for duplicates. The server should not send duplicate connect requests, but if it does we’ll have duplicates.infoConnection info from ProxyConnect packetparam
Parameters:
info(const protocol::ProxyInfo &)
remove_connection
Section titled “remove_connection”void remove_connection(const protocol::ProxyInfo & info)Remove a connection from the table.
Searches for and removes the first matching connection entry. Uses std::remove_if with erase to efficiently remove from vector.If no matching connection is found, does nothing (no error).infoConnection info identifying which connection to removeparam
Parameters:
info(const protocol::ProxyInfo &)