Description
TIdTunnelSlave is a TIdTCPServer descendant that implements a server for communicating with tunnel client connections. TIdTunnelSlave utilizes
TCP connections to establish an internal link to the tunnel master server that hosts connections to service threads for the client connections.
The following diagram is a general diagram of the relationship between client connection threads, the Tunnel Slave Server, the Tunnel Master Server, and service threads used to support encapsulated tunnel connections:
Code:
+---+ +-----+ +-----+ +---+
| C |<=====>| | | |<=====>| V |
+---+ | | | | +---+
+---+ | | | | +---+
| C |<=====>| S |<=====>| M |<=====>| V |
+---+ | | | | +---+
+---+ | | | | +---+
| C |<=====>| | | |<=====>| V |
+---+ +-----+ +-----+ +---+
C: Client connection thread
S: Tunnel Slave Server
M: TUnnel Master Server
V: Service Thread
TIdTunnelSlave provides event handlers that allow responses to changes in both server state and client connection state. TIdTunnelSlave also provides event handlers for data transformation and session link control of the tunnel for associated TIdTunnelMaster server.
When a TIdTunnelSlave becomes active, it initializes the Host and Port properties for the server's internal
TCP connection that will acts as the encapsulated tunnel link tot he TIdTunnelMaster server. The connection to the tunnel master server is opened.
TIdTunnelSlave maintains SlaveThread to listen for data from the TIdTunnelMaster server service threads. SlaveThread is also used to authenticate the tunnel connection to the master server. If no
exception is raised, then the TIdTunnelSlave server will begin to listen for client connections.
When a client requests a connection to TIdTunnelSlave, the server must indicate that AcceptConnections is allowed. When Socks4 indicates that client connection are using a Socks proxy, the server expects to read the
IP address and Socks authentication information from the client connection. Socks authentication data cannot exceed 255 characters, and must be zero-terminated. The server will write a Socks response to the client connection and forward the connection request to the tunnel master server.
When a client connection executes a request on a connection to the tunnel slave server, TIdTunnelSlave will prepare encapsulated tunnel headers for the request and write the encapsulated message to the connection for the tunnel master server. The client connection will be closed if an
exception is raised during execution of the request.
When a client connection request disconnect from the TIdTunnelSlave, the serve will prepare encapsulated tunnel headers for the request and send the message to the tunnel master server to allow closing of service threads for the client connection.