ams::mitm::p2p::P2pProxySession
ams::mitm::p2p::P2pProxySession
Section titled “ams::mitm::p2p::P2pProxySession”P2P Proxy Session.
Represents a single TCP connection from a P2P client. Handles protocol parsing and delegates to parent server.
Members
Section titled “Members”m_server
Section titled “m_server”Type: *
m_socket_fd
Section titled “m_socket_fd”Type: int
m_remote_ip
Section titled “m_remote_ip”Type: uint32_t
m_virtual_ip
Section titled “m_virtual_ip”Type: uint32_t
m_connected
Section titled “m_connected”Type: bool
m_authenticated
Section titled “m_authenticated”Type: bool
m_master_closed
Section titled “m_master_closed”Type: bool
m_recv_thread
Section titled “m_recv_thread”Type: os::ThreadType
m_recv_thread_stack
Section titled “m_recv_thread_stack”Type: uint8_t
m_recv_buffer
Section titled “m_recv_buffer”Type: uint8_t
Members
Section titled “Members”RECV_BUFFER_SIZE
Section titled “RECV_BUFFER_SIZE”Type: constexpr size_t
Methods
Section titled “Methods”P2pProxySession
Section titled “P2pProxySession”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)
~P2pProxySession
Section titled “~P2pProxySession”void ~P2pProxySession()Destructor.
Destructor - ensure disconnection.
P2pProxySession
Section titled “P2pProxySession”void P2pProxySession(const&)Parameters:
param(const&)
operator=
Section titled “operator=”& operator=(const&)Parameters:
param(const&)
Returns: &
GetVirtualIpAddress
Section titled “GetVirtualIpAddress”uint32_t GetVirtualIpAddress()Get assigned virtual IP.
Returns: uint32_t
SetVirtualIp
Section titled “SetVirtualIp”void SetVirtualIp(uint32_t ip)Set virtual IP (called after auth)
Parameters:
ip(uint32_t)
GetRemoteIp
Section titled “GetRemoteIp”uint32_t GetRemoteIp()Get remote (physical) IP.
Returns: uint32_t
IsAuthenticated
Section titled “IsAuthenticated”bool IsAuthenticated()Check if session is authenticated.
Returns: bool
SetAuthenticated
Section titled “SetAuthenticated”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
Disconnect
Section titled “Disconnect”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)
IsConnected
Section titled “IsConnected”bool IsConnected()Check if session is connected.
Returns: bool
Methods
Section titled “Methods”ReceiveLoop
Section titled “ReceiveLoop”void ReceiveLoop()Receive loop thread function.
Receive thread main loop.Continuously receives data from the socket and processes it. Exits when:
ProcessData
Section titled “ProcessData”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)
HandleExternalProxy
Section titled “HandleExternalProxy”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 &)
HandleProxyData
Section titled “HandleProxyData”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)
HandleProxyConnect
Section titled “HandleProxyConnect”void HandleProxyConnect(const ryu_ldn::protocol::ProxyConnectRequest & request)Handle ProxyConnect packet.
Parameters:
request(const ryu_ldn::protocol::ProxyConnectRequest &)
HandleProxyConnectReply
Section titled “HandleProxyConnectReply”void HandleProxyConnectReply(const ryu_ldn::protocol::ProxyConnectResponse & response)Handle ProxyConnectReply packet.
Parameters:
response(const ryu_ldn::protocol::ProxyConnectResponse &)
HandleProxyDisconnect
Section titled “HandleProxyDisconnect”void HandleProxyDisconnect(const ryu_ldn::protocol::ProxyDisconnectMessage & message)Handle ProxyDisconnect packet.
Parameters:
message(const ryu_ldn::protocol::ProxyDisconnectMessage &)