ibmfl.connection

FL Connection

class ibmfl.connection.connection.FLConnection[source]
RECEIVER_STATUS = None

Initialze sender and receiver

Parameters

kwargs – Dictionary of arguments required by each type of sender implementation

__weakref__

list of weak references to the object (if defined)

Flask Connection

Connection class which uses flask and request libraries to create a server client combo. All supported config combinations are shown below. connection:

name: FlaskConnection path: ibmfl.connection.flask_connection info:

ip: <ip> port: <port> headers:

‘Content-type’: ‘application/json’

tls_config:

enable: true cert: <server.crt> key: <server.key> ca_cert: <ca.pem>

Headers and tls config both are optional. By default Content-type and Accept header are sent for every request. Additional headers can be added by changing the header section of info. TLS is by default False and can be enabled by switching adding tls_config to info section and assigning True. If certificates are not provided, adhoc ssl_context is assigned which uses Flask adhoc feature to generate certificates for connections. CA certificate is optional and should be provided if mutual authentication is required on both server and client side.

class ibmfl.connection.flask_connection.FlaskConnection(config)[source]
__init__(config)[source]

Initialized the connection object and validates the config provided to this connection instance

Parameters

config (dict) – Dictionary of configuration provided to connection

get_connection_config()[source]

Provide a connection information such that a node can communicate to other nodes on how to communicate with it.

Returns

settings

Return type

dict

get_ssl_config(config)[source]

Loads tls config from connection config. Returns None when no config is provided :param config: Configuraiton sent from application :type config: dict

Returns

ssl config

Return type

dict

initialize(**kwargs)[source]

Initialize receiver and sender

initialize_receiver(router=None)[source]

Initialize flask server using the settings and handler.

Parameters

router (Router) – Router object describing the routes for each request which are passed down to PH

initialize_sender()[source]

Initialize simple http client using the settings provided during connection creation

process_config(config)[source]

Validates the configuration provided to flask connection and returns a settings dictionary with all the information extracted from config

Parameters

config (dict) – configuraiton sent from application

Returns

settings

Return type

dict

start()[source]

starts the receiver in a new thread

start_receiver()[source]

starts the receiver in a new thread

stop()[source]

Stop and cleanup the connection

Router

Module acting as a bridge between Server and ProtocolHandler Routes for all the requests received by the server are redirected to designated handler in PH using routers

class ibmfl.connection.router_handler.Router[source]

Container used to add and match a group of routes.

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

__weakref__

list of weak references to the object (if defined)

add_route(path, handler)[source]

Add path, handler combination in a dictionary. Throws DuplicateRouteException when route is repeated

Parameters
  • path – special pre defined /assigned identifier which will be used by the client to reach specific handler in the PH

  • handler – method which needs to handle the request carrying the special identifier

Raises

DuplicateRouteException – exception is raised when path is added multiple times

add_routes(routes)[source]

Add multiple path, handler combinations in routes dictionary. Throws DuplicateRouteException when route is repeated

Parameters

routes – list of path, handler combination

Raises

DuplicateRouteException – exception is raised when path is added multiple times

get_handler(request_path)[source]

Gets handler for path specified in the request

Parameters

request_path – path or identifier provided in the request message

Returns

a handler which was assigned when Router object was created