Skip to content

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

Type: bool

Whether ProxyConfig received.

Type: uint32_t

Configured proxy IP.

Type: uint32_t

Configured subnet mask.

Type: std::vector<>

Active connection table.

Type: ProxyConfigCallback

Type: ProxyConnectCallback

Type: ProxyConnectReplyCallback

Type: ProxyDataCallback

Type: ProxyDisconnectCallback

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.

void ~LdnProxyHandler()

Destructor.

void LdnProxyHandler(const&)

Parameters:

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

Parameters:

  • param (const&)

Returns: &

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)
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)
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)
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)
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)
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&)
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 &)
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 &)
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)
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 &)
bool is_configured()

Check if proxy is configured.

true if ProxyConfig has been receivedreturn

Returns: bool

uint32_t get_proxy_ip()

Get configured proxy IP.

Proxy server IP address (0 if not configured)return

Returns: uint32_t

uint32_t get_proxy_subnet_mask()

Get configured subnet mask.

Proxy subnet mask (0 if not configured)return

Returns: uint32_t

size_t get_connection_count()

Get number of active connections.

Count of entries in connection tablereturn

Returns: size_t

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.

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