dxlclient.client_config module

Contains the DxlClientConfig class, which holds the information necessary to connect a dxlclient.client.DxlClient to the DXL fabric.

class dxlclient.client_config.DxlClientConfig(broker_ca_bundle, cert_file, private_key, brokers, websocket_brokers=None, **proxy_args)

Bases: dxlclient._BaseObject

The Data Exchange Layer (DXL) client configuration contains the information necessary to connect a dxlclient.client.DxlClient to the DXL fabric.

The configuration includes the required PKI information (client certificate, client private key, broker CA certificates) and the set of DXL message brokers that are available to connect to on the fabric.

The following sample shows creating a client configuration, instantiating a DXL client, and connecting to the fabric:

from dxlclient.broker import Broker
from dxlclient.client import DxlClient
from dxlclient.client_config import DxlClientConfig

# Create the client configuration
config = DxlClientConfig(
    broker_ca_bundle="c:\\certs\\brokercerts.crt",
    cert_file="c:\\certs\\client.crt",
    private_key="c:\\certs\\client.key",
    brokers=[Broker.parse("ssl://192.168.189.12")])

# Create the DXL client
with DxlClient(config) as dxl_client:

    # Connect to the fabric
    dxl_client.connect()

Constructor parameters:

Parameters:
  • broker_ca_bundle -- The file name of a bundle containing the broker CA certificates in PEM format
  • cert_file -- The file name of the client certificate in PEM format
  • private_key -- The file name of the client private key in PEM format
  • brokers -- A list of dxlclient.broker.Broker objects representing brokers on the DXL fabric supporting standard MQTT connections. When invoking the dxlclient.client.DxlClient.connect() method, the dxlclient.client.DxlClient will attempt to connect to the closest broker.
  • websocket_brokers -- A list of dxlclient.broker.Broker objects representing brokers on the DXL fabric supporting DXL connections over WebSockets.
  • proxy_args -- Websocket proxy arguments
broker_ca_bundle

The file name of a bundle containing the broker CA certificates in PEM format

brokers

A list of dxlclient.broker.Broker objects representing brokers on the DXL fabric. Brokers returned is dependent on the use_websockets flag. When invoking the dxlclient.client.DxlClient.connect() method, the dxlclient.client.DxlClient will attempt to connect to the closest broker.

cert_file

The file name of the client certificate in PEM format

connect_retries

The maximum number of connection attempts for each dxlclient.broker.Broker specified in the dxlclient.client_config.DxlClientConfig

A value of -1 indicates that the client will continue to retry without limit until it establishes a connection

static create_dxl_config_from_file(dxl_config_file)

This method allows creation of a DxlClientConfig object from a specified configuration file. The information contained in the file has a one-to-one correspondence with the DxlClientConfig constructor.

[General]
useWebSocketBrokers=no

[Certs]
BrokerCertChain=c:\\certs\\brokercerts.crt
CertFile=c:\\certs\\client.crt
PrivateKey=c:\\certs\\client.key

[Brokers]
mybroker=mybroker;8883;mybroker.mcafee.com;192.168.1.12
mybroker2=mybroker2;8883;mybroker2.mcafee.com;192.168.1.13

[BrokersWebSockets]
mybroker=mybroker;443;mybroker.mcafee.com;192.168.1.12
mybroker2=mybroker2;443;mybroker2.mcafee.com;192.168.1.13

The configuration file can be loaded as follows:

from dxlclient.client_config import DxlClientConfig

config = DxlClientConfig.create_dxl_config_from_file("c:\\certs\\dxlclient.cfg")
Parameters:dxl_config_file -- Path to the configuration file
Returns:A DxlClientConfig object corresponding to the specified configuration file
incoming_message_queue_size

The queue size for incoming messages (will block when queue is full).

Defaults to 1000

incoming_message_thread_pool_size

The thread pool size for incoming messages

Defaults to 1

keep_alive_interval

The maximum period in seconds between communications with a connected dxlclient.broker.Broker. If no other messages are being exchanged, this controls the rate at which the client will send ping messages to the dxlclient.broker.Broker.

Defaults to 1800 seconds (30 minutes)

private_key

The file name of the client private key in PEM format

proxy_addr

Get proxy address

proxy_password

Get proxy password

proxy_port

Get proxy port

proxy_rdns

Returns Proxy rdns enabled or not. Defaults to True

proxy_type

Get Type of Proxy. Defaults to 3 (HTTP)

proxy_username

Get proxy username

reconnect_back_off_multiplier

Multiples the current reconnect delay by this value on subsequent connect retries. For example, a current delay of 3 seconds with a multiplier of 2 would result in the next retry attempt being in 6 seconds.

Defaults to 2

reconnect_delay

The initial delay between retry attempts in seconds. The delay increases ("backs off") as subsequent connection attempts are made.

Defaults to 1 second

reconnect_delay_max

The maximum delay between connection retry attempts in seconds

Defaults to 60 seconds (1 minute)

reconnect_delay_random

Get the randomness delay percentage (between 0.0 and 1.0). The default value is 0.25

reconnect_when_disconnected

Whether the client will continuously attempt to reconnect to the fabric if it becomes disconnected

Defaults to True

use_websockets

Whether or not the client will use WebSockets. If false MQTT over tcp will be used. If only WebSocket brokers are specified this will default to true.

websocket_brokers

A list of dxlclient.broker.Broker objects representing brokers on the DXL fabric supporting DXL connections over WebSockets.

write(file_path)

Create a DXL client configuration file from the current object. If the current object was created from a call to create_dxl_config_from_file(), unchanged content should be preserved. For example, the original file may have the following:

[Certs]
BrokerCertChain=c:\\certs\\brokercerts.crt
CertFile=c:\\certs\\client.crt
PrivateKey=c:\\certs\\client.key

[Brokers]
mybroker=mybroker;8883;mybroker.mcafee.com;192.168.1.12
mybroker2=mybroker2;8883;mybroker2.mcafee.com;192.168.1.13

[BrokersWebSockets]
mybroker=mybroker;443;mybroker.mcafee.com;192.168.1.12
mybroker2=mybroker2;443;mybroker2.mcafee.com;192.168.1.13

The configuration could be loaded and changed as follows:

from dxlclient.client_config import DxlClientConfig

config = DxlClientConfig.create_dxl_config_from_file("c:\\certs\\dxlclient.config")
config.cert_file = "c:\\\\certs\\\\newclient.crt"
config.write("c:\\certs\\dxlclient.config")

The resulting configuration should then appear as follows:

[Certs]
BrokerCertChain=c:\\certs\\brokercerts.crt
CertFile=c:\\certs\\newclient.crt
PrivateKey=c:\\certs\\client.key

[Brokers]
mybroker=mybroker;8883;mybroker.mcafee.com;192.168.1.12
mybroker2=mybroker2;8883;mybroker2.mcafee.com;192.168.1.13

[BrokersWebSockets]
mybroker=mybroker;443;mybroker.mcafee.com;192.168.1.12
mybroker2=mybroker2;443;mybroker2.mcafee.com;192.168.1.13
Parameters:file_path -- File at which to write the configuration. An attempt will be made to create any directories in the path which may not exist before writing the file.