Indy 9
|
TIdTunnelSlave = class(TIdTCPServer)
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:
+---+ +-----+ +-----+ +---+ | 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.
property Active: Boolean;
When Active is set to True, the server will attempt to create the TIdTCPClient that acts as the tunnel link to the TIdTunnelMaster identified in MasterHost and MasterPort. An RSTunnelConnectToMasterFailed exception will be raised if the connection to the master server cannot be opened.
When the connection is created, a TSlaveThread is created and started for the server to allow authentication of the TIdTunnelSlave connection to the TIdTunnelMaster. When the connection to the master server is complete, the TIdTunnelSlave is ready to begin accepting client connections.
When Active is set to False, the server will indicate that it is neither accepting new client connections or transmitting data for existing client connections. Existing client connections are closed, and the tunnel connection to TIdTunnelMaster is closed. Finally, the TSlaveThread instance for the server is terminated prior to completion of the change in the property state.
property Logger: TLogger;
property MasterHost: string;
MasterHost is used, with MasterPort, when creating the TCP connection that acts as the encapsulated tunnel to the master server in Create.
property MasterPort: Integer;
MasterPort is used, with MasterHost, when creating the TCP connection that acts as the encapsulated tunnel to the master server in Create.
property NumClients: Integer;
property Socks4: Boolean;
When Sock4 is True, a new client connection may contain the Socks version, OpCode, Port number and IP Address for the Socks proxy, as well as the null-terminated Socks user ID. A Socks response is written to the client connection using the Socks OpCode 90.
When Sock4 is False, the client connection uses the DefaultPort for the server.
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
Destroy closes the TCP connection that serves as the tunnel link to the TIdTunnelMaster server.
Destroy terminates the SlaveThread that listens for data on the tunnel connection.
Destroy will free and release the TCriticalSection instances uses to protect the resources of the TIdTunnelSlave server.
Destroy relies on the inherited Destroy method to complete destruction of the object instance.
procedure GetStatistics(Module: Integer; var Value: Integer);
Module is an Integer that represents one of the statistic type constant values from IdTunnelCommon.pas, and normally contains on of the following values:
CompressionRatioType returns a calculated value that represents the ratio of total number of bytes read to compressed bytes read.
Value is an Integer variable used to return the value for the selected statistic type.
GetStatistics uses the StatisticsLocker cortical section to protect access to the server resources from multiple threads.
procedure SetStatistics(Module: Integer; Value: Integer);
SetStatistics is called when the number of client connections is updated, or during SlaveThread execution.
property OnBeforeTunnelConnect: TSendTrnEventC;
OnBeforeTunnelConnect is signalled when SlaveThread is initialized for the server. Use OnBeforeTunnelConnect to override the UserID or message type in Header used to authenticate the server connection to TIdTunnelMaster, or to update user interface elements upon receipt of the notification.
Applications must assign a procedure to the event handler to allow the server to respond to the event notification.
property OnDisconnect: TIdServerThreadEvent;
OnDisconnect can be used to perform housekeeping and maintenance required to reflect the change in the connection state.
Application must assign a procedure to the event handler to allow a response to the event notification.
property OnInterpretMsg: TSendMsgEventC;
Applications must assign a procedure to the event handler to allow a response to the event notification.
property OnStatus: TIdStatusEvent;
property OnTransformRead: TTunnelEventC;
OnTransformRead is invoked from TSlaveThread.Run when a new message is received.
Applications must assign a procedure to the event handler to allow a response to the event notification.
property OnTransformSend: TSendTrnEventC;
Update CustomMsg to reflect the contents of the message after data transformation.
Applications must assign a procedure to the event handler to allow a response to the event notification.
property OnTunnelDisconnect: TTunnelEvent;
OnTunnelDisconnect is signalled when the server is no longer accepting connections and has stopped transmitted to existing client connections.
Applications must assign a procedure to the event handler to allow the server to respond to the event notification.