correlater

class naz.correlater.BaseCorrelater[source]

Bases: abc.ABC

Interface that must be implemented to satisfy naz’s Correlater. User implementations should inherit this class and implement the get and put methods with the type signatures shown.

A Correlater is class that naz uses to store relations between SMPP sequence numbers and user applications’ log_id’s and/or hook_metadata.

Note: This correlation is on a BEST effort basis; it is not guaranteed to be reliable.
One reason, among others, is that the SMPP specifiation mandates sequence numbers to wrap around after ≈ 2billion.
Another reason is that we use receipted_message_id tag from deliver_sm to correlate a delivery notification with a submit_sm_resp. However receipted_message_id is an optional parameter that SMSC may omit.
abstract async get(smpp_command, sequence_number, smsc_message_id=None)[source]

called by naz to get the correlation of a given SMPP sequence number to log_id and/or hook_metadata.

Parameters
  • smpp_command (str) – any one of the SMSC commands eg submit_sm

  • sequence_number (int) – SMPP sequence_number

  • smsc_message_id (Union[None, str]) – a unique identifier of a particular message on the SMSC. It comes from SMSC

Return type

Tuple[str, str]

Returns

log_id and hook_metadata

abstract async put(smpp_command, sequence_number, log_id, hook_metadata, smsc_message_id=None)[source]

called by naz to put/store the correlation of a given SMPP sequence number to log_id and/or hook_metadata.

Parameters
  • smpp_command (str) – any one of the SMSC commands eg submit_sm

  • sequence_number (int) – SMPP sequence_number

  • log_id (str) – an ID that a user’s application had previously supplied to naz to track/correlate different messages.

  • hook_metadata (str) – a string that a user’s application had previously supplied to naz that it may want to be correlated with the log_id.

  • smsc_message_id (Union[None, str]) – a unique identifier of a particular message on the SMSC. It comes from SMSC

Return type

None

class naz.correlater.SimpleCorrelater(max_ttl=15.0)[source]

Bases: naz.correlater.BaseCorrelater

A simple implementation of BaseCorrelater. It stores the correlation/relation between a given SMPP sequence_number(and/or smsc_message_id) and a user supplied log_id and/or hook_metadata.

SimpleCorrelater also features an auto-expiration of dictionary keys(and their values) based on time.

The storage is done in memory using a python dictionary. The storage looks like:

{
     "sequence_number1": {
         "log_id": "log_id1",
         "hook_metadata": "hook_metadata1",
         "stored_at": 681.109023565
     },
     "smsc_message_id1": {
         "log_id": "log_id1",
         "hook_metadata": "hook_metadata1",
         "stored_at": 681.109023565
     },
    "sequence_number1": {
     "log_id": "log_id2",
     "hook_metadata": "hook_metadata2",
     "stored_at": 682.109023565
    }
    ...
 }
__init__(max_ttl=15.0)[source]
Parameters

max_ttl (float) – The time in seconds that an item is going to be stored. After the expiration of max_ttl seconds, that item will be deleted.

Return type

None

async get(smpp_command, sequence_number, smsc_message_id=None)[source]

called by naz to get the correlation of a given SMPP sequence number to log_id and/or hook_metadata.

Parameters
  • smpp_command (str) – any one of the SMSC commands eg submit_sm

  • sequence_number (int) – SMPP sequence_number

  • smsc_message_id (Union[None, str]) – a unique identifier of a particular message on the SMSC. It comes from SMSC

Return type

Tuple[str, str]

Returns

log_id and hook_metadata

async put(smpp_command, sequence_number, log_id, hook_metadata, smsc_message_id=None)[source]

called by naz to put/store the correlation of a given SMPP sequence number to log_id and/or hook_metadata.

Parameters
  • smpp_command (str) – any one of the SMSC commands eg submit_sm

  • sequence_number (int) – SMPP sequence_number

  • log_id (str) – an ID that a user’s application had previously supplied to naz to track/correlate different messages.

  • hook_metadata (str) – a string that a user’s application had previously supplied to naz that it may want to be correlated with the log_id.

  • smsc_message_id (Union[None, str]) – a unique identifier of a particular message on the SMSC. It comes from SMSC

Return type

None