TIdTunnelMaster
Implements a TCP Server for IP encapsulation tunnels.
Unit
Description
TIdTunnelMaster is a
TIdTCPServer descendant that specifies a multithreaded server that acts as a controller for IP encapsulation "tunnels".
TIdTunnelMaster acts a Proxy for user connections. The IP encapsulation tunnels represent a User connection and the Server advocate used to process IP datagrams for the tunnel.
TIdTunnelMaster also allows construction of Virtual Private Networks through the IP encapsulation tunnel facilities for SOCKS authentication, tunnel management, data transformation, statistical logging, and IP header CRC calculation with optional IP header message types.
TIdTunnelMaster works in conjunction with an instance of TIdTunnelSlave that acts as the multithreaded server for managing the endpoint for the IP tunnel.
Indicates the active state of the server.
property Active: Boolean;
Description
Active is a Boolean property that indicates when the server is listening for new connections, and processing IP tunnel requests.
Indicates if the tunnel client host name must reflect the mapped host.
property LockDestinationHost: Boolean;
Description
LockDestinationHost is a Boolean property that indicates if the tunnel client host name must reflect the mapped host. When a TCP client for the tunnel connection, LockDestinationHost is used to determine if the host name of the client is the
MappedHost from the tunnel server or the local IP address for the client using the tunnel.
When LockDestinationHost is True, the tunnel server MappedHost property is used as the Host for TCP client connection. When LockDestinationHost is False, the local IP address for the tunnel client is used as the Host for TCP client connection.
Indicates if the tunnel client port number must reflect the mapped port.
property LockDestinationPort: Boolean;
Description
LockDestinationPort
LockDestinationPort is a Boolean property that indicates if the tunnel client port number must reflect the mapped port number. When a TCP client for the tunnel connection, LockDestinationPort is used to determine if the port number of the client is the MappedPort from the tunnel server or the local port number for the client using the tunnel.
When LockDestinationPort is True, the tunnel server MappedPort property is used as the Port for TCP client connection. When LockDestinationPort is False, the local port number for the tunnel client is used as the Port for TCP client connection.
Represents the activity logging component for the server.
Description
Logger is a
TLogger property that represents the activity logging component for the server. Logger provides the capability to write log messages to a text files, and uses the exposed LogEvent event handler to customize the information logging action.
Specifies the host name used for connections from the server.
property MappedHost: string;
Description
MappedHost is a String property that represents the default host name used for TCP client connections from the server.
Identifies the port number for new client connections.
property MappedPort: Integer;
Description
MappedPort is an Integer property that identifies the port number used for new client connections. MappedPort is used when a new TCP Client thread that represents the endpoint for the IP tunnel is created in Connect.
Number of service threads for the tunnel.
property NumServices: Integer;
Description
NumServices is a read-only Integer property that identifies the number of
MClientThread service threads currently running for the
TIdTunnelMaster.
NumServices is maintained by MClientThread when a new service thread is created or destroyed for the tunnel master. MClientThread service threads are used to associate a thread connection for the tunnel master with a TCP client connection that will service requests.
Number of slave connections for the tunnel.
property NumSlaves: Integer;
Description
NumSlaves is a read-only Integer property that identifies the current number of
TIdTunnelSlave connections for the
TIdTunnelMaster instance.
NumSlaves is maintained in DoConnect and DoDisconnect, when the TSlaveData container for the connection thread is created or destroyed.
Constructor for the object instance.
constructor Create(AOwner: TComponent); override;
Parameters
AOwner: TComponent
Owner of the object instance.
Description
Create is the constructor for the object instance. Create relies on the inherited Create method, and also initializes properties for the object instance. The following properties are initialized to their default value:
- Active - False
- ConnectedSlaves - 0
- ConnectedServices - 0
- NumberOfConnectionsValue - 0;
- NumberOfPacketsValue - 0;
- CompressionRatioValue - 0
- CompressedBytes - 0
- BytesRead - 0
- BytesWrite - 0
- LockDestinationHost - False;
- LockDestinationPort - False;
- OnlyOneThread - Critical Section
- LockSlavesNumber - Critical Section
- LockServicesNumber - Critical Section
- StatisticsLocker - Critical Section
Frees the object instance.
destructor Destroy; override;
Description
Destroy is the destructor for the object instance, and is responsible for disconnecting all users, as well as freeing and releasing object properties including:
- Logger
- Active
- Clients
- OnlyOneThread
- LockSlavesNumber
- LockServicesNumber
- StatisticsLocker
Destroy calls the inherited Destroy method prior to exiting from the destructor.
Gets statistical measurements for the server.
procedure GetStatistics(Module: Integer; var Value: Integer);
Parameters
Module: Integer
Statistic type requested.
var Value: Integer
Value for the requested statistic type.
Description
GetStatistics is a procedure used to retrieve statistical information for the
TIdTunnelMaster instance.
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 critical section to protect access to the server resources from multiple threads.
Updates statistics for connections to the server.
procedure SetStatistics(Module: Integer; Value: Integer);
Parameters
Module: Integer
Statistical category to update.
Value: Integer
Delta value for the statistical category.
Description
SetStatistics is a procedure that allows the tunnel master to update variables that track active connections, packets transmitted, compression ratio, total number of compressed bytes, total bytes read, and total bytes written for the connection.
SetStatistics is called when the number of service connections is updated, or during client thread execution.
Specifies the event handler for new client connections.
Parameters
Thread
Client connecting to the tunnel server.
Description
OnConnect is a
TIdServerThreadEvent event handler that allows the tunnel master server to respond to connection requests from the listening thread.
OnConnect is called from the DoConnect method after a TSlaveData container has been initialized for the client connection in Thread.
Applications must assign a procedure to the event handler to allow a response to the event notification.
Specifies the event handler for terminated client connections.
Parameters
Thread
Client closing a connection to the tunnel server.
Description
OnDisconnect is a
TIdServerThreadEvent event handler that allows the tunnel master server to respond to a request to close a connection for the client thread.
OnDisconnect is called from the DoDisconnect method after all service threads and the client connection in Thread have been closed.
Applications must assign a procedure to the OnDisconnect event handler to allow a response to the event notification.
Specifies message processing for tunnel connection sessions.
Parameters
CustomMsg
Thread
Client connection for the message.
Description
OnInterpretMsg is a
TSendMsgEvent event handler that allows the tunnel master server to respond to a notification that a message has been received that requires special processing.
OnInterpretMsg is provided to allow TSlaveThread instances to access data interpretation routines specific to the tunnel master server.
Use OnInterpretMsg to perform interpretation of message data for the client connection.
Thread is the client connection that is the recipient of the message.
CustomMsg is the data that needs to be interpreted before allowing transmission to the client connection.
Applications must assign a procedure to the event handler to allow a response to the event notification.
Specifies data transformation for a message from a tunnel slave.
Parameters
Thread
The tunnel slave receiver generated the event.
Description
OnTransformRead is a
TIdServerThreadEvent event handler that allows the tunnel master server to respond to a message from the tunnel slave that data has been received that requires transformation.
OnTransformRead is used by TIdTunnelSlave to access data transformation routines specific to the tunnel master server.
Thread represents the TReceiver for the message.
Applications must assign a procedure to the event handler to allow a response to the event notification.
Performs data transformation prior to transmission.
Parameters
CustomMsg
The message data to be transformed.
Header
Header structure for the custom message.
Thread
Client connection generating the event.
Description
OnTransformSend is a
TSendTrnEvent that allows the tunnel master server to perform data transformation before transmission to a tunnel slave. OnTransformSend is called in SendMsg to transform the message content into an acceptable format for transmission over the network connection.
OnTransformSend is responsible for updating the TIdHeader in Header to reflect the current values for CRC16, MsgType, and MsgLen.
CustomMsg will contain the modified contents of the message after transformation.
Applications must assign a procedure to the event handler to allow a response to the event notification.