Skip to content

ams::mitm::p2p::P2pProxySession

P2P Proxy Session.

Represents a single TCP connection from a P2P client. Handles protocol parsing and delegates to parent server.

Type: *

Type: int

Type: uint32_t

Type: uint32_t

Type: bool

Type: bool

Type: bool

Type: os::ThreadType

Type: uint8_t

Type: uint8_t

Type: constexpr size_t

void P2pProxySession(* server, int socket_fd, uint32_t remote_ip)

Constructor.

Constructor - initialize session state.serverParent serversocket_fdConnected socket file descriptorremote_ipRemote IP addressserverParentsocket_fdConnected TCP socket file descriptorremote_ipClient’s IP address (host byte order)param

Parameters:

  • server (*)
  • socket_fd (int)
  • remote_ip (uint32_t)
void ~P2pProxySession()

Destructor.

Destructor - ensure disconnection.

void P2pProxySession(const&)

Parameters:

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

Parameters:

  • param (const&)

Returns: &

uint32_t GetVirtualIpAddress()

Get assigned virtual IP.

Returns: uint32_t

void SetVirtualIp(uint32_t ip)

Set virtual IP (called after auth)

Parameters:

  • ip (uint32_t)
uint32_t GetRemoteIp()

Get remote (physical) IP.

Returns: uint32_t

bool IsAuthenticated()

Check if session is authenticated.

Returns: bool

void SetAuthenticated(bool auth)

Mark as authenticated.

Parameters:

  • auth (bool)
void Start()

Start receive loop thread.

Start the receive thread.Creates and starts a thread that loops calling recv() on the socket. The thread processes received data and dispatches to appropriate handlers.

bool Send(const void * data, size_t size)

Send data to the client.

Uses blocking send(). TCP guarantees delivery order and reliability.

Parameters:

  • data (const void *)
  • size (size_t)

Returns: bool

void Disconnect(bool from_master)

Disconnect and stop.

Disconnect the session.Closes the socket and optionally notifies the parent server. If from_master is true, we skip the notification (already handled).

Parameters:

  • from_master (bool)
bool IsConnected()

Check if session is connected.

Returns: bool

void ReceiveLoop()

Receive loop thread function.

Receive thread main loop.Continuously receives data from the socket and processes it. Exits when:

void ProcessData(const uint8_t * data, size_t size)

Process received data.

Process received data as LDN packets.Parses the data as LDN protocol packets and dispatches to handlers. Each packet has:Multiple packets may be received in a single recv() call due to TCP streaming.

Parameters:

  • data (const uint8_t *)
  • size (size_t)
void HandleExternalProxy(const ryu_ldn::protocol::ExternalProxyConfig & config)

Handle ExternalProxy packet (client authentication)

Called when a client sends their auth token. Delegates to server’s TryRegisterUser() for validation.

Parameters:

  • config (const ryu_ldn::protocol::ExternalProxyConfig &)
void HandleProxyData(const ryu_ldn::protocol::ProxyDataHeader & header, const uint8_t * data, size_t data_len)

Handle ProxyData packet.

Only processed if session is authenticated. Delegates routing to server.

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 packet.

Parameters:

  • request (const ryu_ldn::protocol::ProxyConnectRequest &)
void HandleProxyConnectReply(const ryu_ldn::protocol::ProxyConnectResponse & response)

Handle ProxyConnectReply packet.

Parameters:

  • response (const ryu_ldn::protocol::ProxyConnectResponse &)
void HandleProxyDisconnect(const ryu_ldn::protocol::ProxyDisconnectMessage & message)

Handle ProxyDisconnect packet.

Parameters:

  • message (const ryu_ldn::protocol::ProxyDisconnectMessage &)