Module RelayModel.Communication

Expand source code
from RelayModel.RelayId import RelayId, RelayLayerId


class RelayParameter:
    """Holds every information needed for a replacement of a relay.

    This replacement has information set for another relay layer to establish a connection.

    Attributes:
        key (str): Holds the key that is needed for an authorized connection
        relay_id (RelayId): Holds the relay id defining the connection relay
        level (int): Holds the level of the connection
        rid (RelayLayerId): Holds the RelayLayerId of the sink rid of the connection
    """
    def __init__(self, key, relay_id: RelayId, level: int, rid: RelayLayerId):
        self.key = key
        self.relay_id = relay_id
        self.level = level
        self.rid = rid

    def __str__(self):
        return "Relay Parameter with key: {}, relay_id: {}, level: {}, rid: {}" \
            .format(self.key, self.relay_id, self.level, self.rid)


class SuccessMessage:
    """Holds a message and signaling a successful message transmission
    """
    def __init__(self, msg):
        """Creates a SuccessMessage object holding a message.

        Args:
              msg: Stores a message that can be transmitted.
        """
        self.message = msg


class FailureMessage:
    """Holds a message and signaling a failed message transmission
    """
    def __init__(self, msg):
        """Creates a FailureMessage object holding a message.

        Args:
              msg: Stores a message that can be transmitted.
        """
        self.message = msg


class Header:
    """Holds information needed for a message header.

    The header is needed to validate a transmission over a specific relay.

    Attributes:
        keys (Set): Holds a set of keys which can authenticate a transmission
        sender_rid (RelayLayerId): Holds the rid from a relay layer which transmitted this message
        out_id (RelayId): Holds the RelayId of a outgoing relay connection.
    """
    def __init__(self, keys, sender_rid, out_id):
        """Creates an Header object.

        The creation of the Header Object requires keys, sender_rid and out_id.

        Args:
            keys (list): The keys used for authenticating a message.
            sender_rid (RelayLayerId): The RelayLayerId of the RelayLayer that wants to send the message containing
                this header.
            out_id (RelayId): Defining the RelayId of the Relay that should transmit the Message
        """
        self.keys = keys
        self.sender_rid = sender_rid
        self.out_id = out_id

    def __str__(self):
        return "Header({}, {}, {})".format(self.keys, self.sender_rid, self.out_id)

    def __eq__(self, other):
        return self.__class__ == other.__class__ and self.keys == other.keys and self.sender_rid == other.sender_rid \
                and self.out_id == other.out_id


class Action:

    """Defines the main action class for calling actions in a node.

    This class holds all information needed to execute a action.

    Attributes:
        action_type (str): Holds the action_type or the action name as a string. For a sorted list e.g. "linearize"
        parameters (list): Holds a list of parameters the action needs for executing
        receiving_relay (RelayId): Holds a RelayId of the Relay which received this action. This is needed for reversing every receiving relay.
    """
    def __init__(self, action_type: str, parameters: list):
        """Creates an Action object for a specific method call or action execution.

        This object can be sent with a message object or a layer object.

        Example:
            Action("linearize", [relay]) -> executes a linearize method with the parameter relay

        Args:
            action_type (str): The name of the executable action.
            parameters (list): Stores the parameters for this specific action in a list.
        """
        self.action_type = action_type
        self.parameters = parameters
        self.receiving_relay = None

    def __str__(self):
        return "{} Action({})".format(self.action_type, ', '.join(map(str, self.parameters)))

    def check_has_key_as_parameter(self, key):
        """Checks the parameters of the action if there is a RelayParameter with the given key.

        This is needed for removing keys from a probing message if a relay has this key set in one RelayParameter.

        Args:
            key (str): Holds the key that should be checked
        Returns:
             bool: True if there is a RelayParameter with the given key, otherwise False
        """
        for parameter in self.parameters:
            if isinstance(parameter, RelayParameter) and parameter.key == key:
                return True
        return False

    def __eq__(self, other):

        if self.__class__ != other.__class__ or self.action_type != other.action_type:
            return False

        if len(self.parameters) != len(other.parameters):
            return False

        for index, parameter in enumerate(self.parameters):
            other_param = other.parameters[index]
            if other_param != parameter:
                return False
        return True


class ProbeAction(Action):
    """Defines the Probe Action and inherits the functionality of Action.

    The ProbeAction is used when trying to validate indirect connections.

    Attributes:
        control_keys (list): Holds a list of keys that needs to be checked in the probe message.
        key_sequence (list): Holds a list of key sets that define a route the probe message went.
    """
    def __init__(self, control_keys, key_sequence):
        """Creates a ProbeAction object with given controlKeys and keySequences.

        It sets the action_type of the Action to "Probe".

        Args:
            control_keys (list): The keys that should be checked in a probe message as a list of strings.
            key_sequence (list): The sequence the Probe message went through the connections as a list of str lists
        """
        super(ProbeAction, self).__init__("Probe", [control_keys, key_sequence])

    def __get_control_keys(self):
        """Handles the control keys of the Action from the parameters list stored on first index.
        """
        return self.parameters[0]

    def __set_control_keys(self, control_keys):
        self.parameters[0] = control_keys

    def __get_key_sequence(self):
        """Handles the key sequence list of the Action from the parameters list stored on second index
        """
        return self.parameters[1]

    def __set_key_sequence(self, key_sequence):
        self.parameters[1] = key_sequence

    control_keys = property(__get_control_keys, __set_control_keys)
    key_sequence = property(__get_key_sequence, __set_key_sequence)


class ProbeFailAction(Action):
    """Defines the ProbeFail Action and inherits the functionality of Action.

    The action is sent when a probe action failed for a specific key. This class hold the key that failed the probe and the key sequence for
    recreating the route of the probe message.

    Attributes:
        key (str): Holds the key that caused the probe to fail.
        key_sequence (list): Holds a list of key sets that define a route the probe message went.
    """
    def __init__(self, key, key_sequence):
        """Creates a ProbeFailAction object with given key and keySequences.

        It sets the action_type of the Action to "ProbeFail".

        Args:
            key (str): Defining the key that failed a probe message.
            key_sequence (list): The sequence the Probe message went through the connections as a list of str lists
        """
        super(ProbeFailAction, self).__init__("ProbeFail", [key, key_sequence])

    def __get_key(self):
        """Handles the key attribute of the Action stored in the parameter list on first index.
        """
        return self.parameters[0]

    def __set_key(self, key):
        self.parameters[0] = key

    def __get_key_sequence(self):
        """Handles the key sequence attribute of the Action stored in the parameter list on second index.
        """
        return self.parameters[1]

    def __set_key_sequence(self, key_sequence):
        self.parameters[1] = key_sequence

    key = property(__get_key, __set_key)
    key_sequence = property(__get_key_sequence, __set_key_sequence)


class NotAuthorizedAction(Action):
    """Defines the NotAuthorized Action and inherits the functionality of Action.

    The action is used when a transmission over a relay is not authorized with the given keys.
    It holds the keys that a not authorized and the RelayId of the Relay the transmission was not allowed for.

    Attributes:
        keys (list): Holds a list of keys the transmission was not authorized for.
        out_id (RelayId): Holds a RelayId that defines the Relay which should have received the message.
    """
    def __init__(self, keys, out_id):
        """Creates a NotAuthorizedAction object with given keys and out_id.

        It sets the action_type of the Action to "NotAuthorized".

        Args:
            keys (list): Defining the list of keys that are not allowed.
            out_id (RelayId): Defining the Relay that has the not allowed incoming keys.
        """
        super(NotAuthorizedAction, self).__init__("NotAuthorized", [keys, out_id])

    def __get_keys(self):
        """Handles the keys attribute stored in the parameter list on first index.
        """
        return self.parameters[0]

    def __set_keys(self, keys):
        self.parameters[0] = keys

    def __get_out_id(self):
        """Handles the out id attribute stored in the parameter list on second index.
        """
        return self.parameters[1]

    def __set_out_id(self, out_id):
        self.parameters[1] = out_id

    keys = property(__get_keys, __set_keys)
    out_id = property(__get_out_id, __set_out_id)


class Ping:
    """
    Holds every Attribute needed for a Ping Aktion. This class is not an Action class itself. This class is rather
    a helper class for storing information.

    Attributes:
        relay_id (RelayId): Holds the RelayId of the relay which incoming connection should be ping checked.
        level (int): Holds the level information that should be checked for the ping.
        sink_rid (RelayLayerId): Holds the sink RID of the connection that should be checked in the ping.
        key (str): Holds the key of the incoming connection which should be checked.
    """
    def __init__(self, relay_id, level, sink_rid, key):
        """Creates a Ping object with given relay_id, level, sink_rid and key.

        Args:
            relay_id (RelayId): The relay that should be checked in the ping.
            level (int): The level of the connection.
            sink_rid (RelayLayerId): Defining the RelayLayer that stores the sinkrelay of the connection.
            key (str): The key that is used in the connection.
        """
        self.relay_id = relay_id
        self.level = level
        self.sink_rid = sink_rid
        self.key = key


class PingAction(Action):
    """Defines the Ping Action and inherits the functionality of Action.

    This class holds a list of ping objects.
    This action is sent to validate incoming connections of a relay.

    Attributes:
        pings (list): Holds a list of ping objects. This is compressed to one action because it reduces network traffic
         over the LinkLayer
    """
    def __init__(self, pings):
        """Creates a PingAction object with given pings.

        It sets the action_type of the Action to "Ping".

        Args:
            pings (list): Stores a list of ping object that needs to be checked on receiving the action.
        """
        super(PingAction, self).__init__("Ping", [pings])

    def __get_pings(self):
        """Handles the ping list stored in the parameter list on first index.
        """
        return self.parameters[0]

    def __set_pings(self, pings):
        self.parameters[0] = pings

    pings = property(__get_pings, __set_pings)


class InRelayClosedAction(Action):
    """Defines the InRelayClosed Action and inherits the functionality of Action.

    This action is sent when a relay is closed and a relay layer wants to inform the relay layer the outgoing connection
    is going to.

    Attributes:
        keys (list): Holds a list of keys that a not used anymore and should be corrected in incoming connections
        sender_rid (RelayLayerId): Holds the RelayLayerId from the RelayLayer that is sending this Action
        relay_id (RelayId): Holds the RelayId of the Relay that has closing incoming connections
    """
    def __init__(self, keys, sender_rid, relay_id):
        """Creates a InRelayClosedAction object with given keys and out_id.

        It sets the action_type of the Action to "InRelayClosed".

        Args:
            keys (list): Defines the keys that used by the connection and should be closed.
            sender_rid (RelayLayerId): Defining the RelayLayer that sends this action.
            relay_id (RelayId): Defining the Relay that was closed.
        """
        super(InRelayClosedAction, self).__init__("InRelayClosed", [keys, sender_rid, relay_id])

    def __get_keys(self):
        """Handles the keys stored on the first index in the parameter list
        """
        return self.parameters[0]

    def __set_keys(self, keys):
        self.parameters[0] = keys

    def __get_sender_rid(self):
        """Handles the sender rid stored on the second index in the parameter list
        """
        return self.parameters[1]

    def __set_sender_rid(self, sender_rid):
        self.parameters[1] = sender_rid

    def __get_relay_id(self):
        """Handles the relay id stored on the third index in the parameter list
        """
        return self.parameters[2]

    def __set_relay_id(self, relay_id):
        self.parameters[2] = relay_id

    keys = property(__get_keys, __set_keys)
    sender_rid = property(__get_sender_rid, __set_sender_rid)
    relay_id = property(__get_relay_id, __set_relay_id)


class OutRelayClosedAction(Action):
    """Defines the OutRelayClosed Action and inherits the functionality of Action.

    This action is sent when an Relay is closed and it informs all incoming connections of this relay that it is closed.

    Attributes:
        relay_id (RelayId): Holds the RelayId of the Relay that got closed
    """
    def __init__(self, relay_id):
        """Creates a OutRelayClosedAction object with given keys and out_id.

        It sets the action_type of the Action to "OutRelayClosed".

        Args:
            relay_id (RelayId): Defines the Relay that is getting closed.
        """
        super(OutRelayClosedAction, self).__init__("OutRelayClosed", [relay_id])

    def __get_relay_id(self):
        """Handles the relay id that is stored on the first index in the paremeter list."""
        return self.parameters[0]

    def __set_relay_id(self, relay_id):
        self.parameters[0] = relay_id

    relay_id = property(__get_relay_id, __set_relay_id)


class Message:
    """Defines a wrapper class for a message.

    The message includes an action and a header.

    Attributes:
        header (Header): Holds the Header of the message which authenticates it
        action (Action): Holds the Action that should be executed on arrival of this message
    """
    def __init__(self, header: Header, action: Action):
        """Creates an Message object with a given header and action.

        Args:
            header (Header): Defines the header of the message as a Header object.
            action (Action): Defines the Action that should be executed on receiving of this message.
        """
        self.header = header
        self.action = action

    def __str__(self):
        return "Message: {} \n\tand action: {}".format(self.header, self.action)

    def __eq__(self, other):
        return self.__class__ == other.__class__ and self.header == other.header and self.action == other.action


class LayerMessage:
    """Defines a class that holds information for messages between RelayLayers.

    This class is used for communications between two RelayLayers.

    Attributes:
        layer_id (RelayLayerId): Holds the RelayLayerId of the RelayLayer the message should be sent to.
        action (Action): Holds the Action that should be executed when the relay layer receives the message.
    """
    def __init__(self, layer_id: RelayLayerId, action: Action):
        """Creates a LayerMessage object with the given RelayLayerId and Action.

        The Message should be transmitted to the RelayLayer defined by the given layer_id.

        Args:
            layer_id (RelayLayerId): Defining the RelayLayer that should receive this message.
            action (Action): Defining the action that should be executed on receiving.
        """
        self.layer_id = layer_id
        self.action = action

    def __str__(self):
        return "Layer Message with layer_id: {} \n\tand action: {}" \
            .format(str(self.layer_id), str(self.action))

    def __eq__(self, other):
        return self.__class__ == other.__class__ and self.layer_id == other.layer_id and self.action == other.action


class TransmitMessage:
    """Defines a class that holds information for a transmit message.

    This class is used for transmitting a message from one node to another.

    Attributes:
        message (Message): Holds the message that should be transmitted over relays
    """
    def __init__(self, message: Message):
        """Creates a TransmitMessage object with the given Message.

        Args:
            message (Message): Defining the message that should be transmitted over some Relays.
        """
        self.message = message

    def __str__(self):
        return "TransmitMessage including \n\t{}".format(str(self.message))

    def __eq__(self, other):
        return self.__class__ == other.__class__ and self.message == other.message

Classes

class Action (action_type: str, parameters: list)

Defines the main action class for calling actions in a node.

This class holds all information needed to execute a action.

Attributes

action_type : str
Holds the action_type or the action name as a string. For a sorted list e.g. "linearize"
parameters : list
Holds a list of parameters the action needs for executing
receiving_relay : RelayId
Holds a RelayId of the Relay which received this action. This is needed for reversing every receiving relay.

Creates an Action object for a specific method call or action execution.

This object can be sent with a message object or a layer object.

Example

Action("linearize", [relay]) -> executes a linearize method with the parameter relay

Args

action_type : str
The name of the executable action.
parameters : list
Stores the parameters for this specific action in a list.
Expand source code
class Action:

    """Defines the main action class for calling actions in a node.

    This class holds all information needed to execute a action.

    Attributes:
        action_type (str): Holds the action_type or the action name as a string. For a sorted list e.g. "linearize"
        parameters (list): Holds a list of parameters the action needs for executing
        receiving_relay (RelayId): Holds a RelayId of the Relay which received this action. This is needed for reversing every receiving relay.
    """
    def __init__(self, action_type: str, parameters: list):
        """Creates an Action object for a specific method call or action execution.

        This object can be sent with a message object or a layer object.

        Example:
            Action("linearize", [relay]) -> executes a linearize method with the parameter relay

        Args:
            action_type (str): The name of the executable action.
            parameters (list): Stores the parameters for this specific action in a list.
        """
        self.action_type = action_type
        self.parameters = parameters
        self.receiving_relay = None

    def __str__(self):
        return "{} Action({})".format(self.action_type, ', '.join(map(str, self.parameters)))

    def check_has_key_as_parameter(self, key):
        """Checks the parameters of the action if there is a RelayParameter with the given key.

        This is needed for removing keys from a probing message if a relay has this key set in one RelayParameter.

        Args:
            key (str): Holds the key that should be checked
        Returns:
             bool: True if there is a RelayParameter with the given key, otherwise False
        """
        for parameter in self.parameters:
            if isinstance(parameter, RelayParameter) and parameter.key == key:
                return True
        return False

    def __eq__(self, other):

        if self.__class__ != other.__class__ or self.action_type != other.action_type:
            return False

        if len(self.parameters) != len(other.parameters):
            return False

        for index, parameter in enumerate(self.parameters):
            other_param = other.parameters[index]
            if other_param != parameter:
                return False
        return True

Subclasses

Methods

def check_has_key_as_parameter(self, key)

Checks the parameters of the action if there is a RelayParameter with the given key.

This is needed for removing keys from a probing message if a relay has this key set in one RelayParameter.

Args

key : str
Holds the key that should be checked

Returns

bool
True if there is a RelayParameter with the given key, otherwise False
Expand source code
def check_has_key_as_parameter(self, key):
    """Checks the parameters of the action if there is a RelayParameter with the given key.

    This is needed for removing keys from a probing message if a relay has this key set in one RelayParameter.

    Args:
        key (str): Holds the key that should be checked
    Returns:
         bool: True if there is a RelayParameter with the given key, otherwise False
    """
    for parameter in self.parameters:
        if isinstance(parameter, RelayParameter) and parameter.key == key:
            return True
    return False
class FailureMessage (msg)

Holds a message and signaling a failed message transmission

Creates a FailureMessage object holding a message.

Args

msg
Stores a message that can be transmitted.
Expand source code
class FailureMessage:
    """Holds a message and signaling a failed message transmission
    """
    def __init__(self, msg):
        """Creates a FailureMessage object holding a message.

        Args:
              msg: Stores a message that can be transmitted.
        """
        self.message = msg
class Header (keys, sender_rid, out_id)

Holds information needed for a message header.

The header is needed to validate a transmission over a specific relay.

Attributes

keys : Set
Holds a set of keys which can authenticate a transmission
sender_rid : RelayLayerId
Holds the rid from a relay layer which transmitted this message
out_id : RelayId
Holds the RelayId of a outgoing relay connection.

Creates an Header object.

The creation of the Header Object requires keys, sender_rid and out_id.

Args

keys : list
The keys used for authenticating a message.
sender_rid : RelayLayerId
The RelayLayerId of the RelayLayer that wants to send the message containing this header.
out_id : RelayId
Defining the RelayId of the Relay that should transmit the Message
Expand source code
class Header:
    """Holds information needed for a message header.

    The header is needed to validate a transmission over a specific relay.

    Attributes:
        keys (Set): Holds a set of keys which can authenticate a transmission
        sender_rid (RelayLayerId): Holds the rid from a relay layer which transmitted this message
        out_id (RelayId): Holds the RelayId of a outgoing relay connection.
    """
    def __init__(self, keys, sender_rid, out_id):
        """Creates an Header object.

        The creation of the Header Object requires keys, sender_rid and out_id.

        Args:
            keys (list): The keys used for authenticating a message.
            sender_rid (RelayLayerId): The RelayLayerId of the RelayLayer that wants to send the message containing
                this header.
            out_id (RelayId): Defining the RelayId of the Relay that should transmit the Message
        """
        self.keys = keys
        self.sender_rid = sender_rid
        self.out_id = out_id

    def __str__(self):
        return "Header({}, {}, {})".format(self.keys, self.sender_rid, self.out_id)

    def __eq__(self, other):
        return self.__class__ == other.__class__ and self.keys == other.keys and self.sender_rid == other.sender_rid \
                and self.out_id == other.out_id
class InRelayClosedAction (keys, sender_rid, relay_id)

Defines the InRelayClosed Action and inherits the functionality of Action.

This action is sent when a relay is closed and a relay layer wants to inform the relay layer the outgoing connection is going to.

Attributes

keys : list
Holds a list of keys that a not used anymore and should be corrected in incoming connections
sender_rid : RelayLayerId
Holds the RelayLayerId from the RelayLayer that is sending this Action
relay_id : RelayId
Holds the RelayId of the Relay that has closing incoming connections

Creates a InRelayClosedAction object with given keys and out_id.

It sets the action_type of the Action to "InRelayClosed".

Args

keys : list
Defines the keys that used by the connection and should be closed.
sender_rid : RelayLayerId
Defining the RelayLayer that sends this action.
relay_id : RelayId
Defining the Relay that was closed.
Expand source code
class InRelayClosedAction(Action):
    """Defines the InRelayClosed Action and inherits the functionality of Action.

    This action is sent when a relay is closed and a relay layer wants to inform the relay layer the outgoing connection
    is going to.

    Attributes:
        keys (list): Holds a list of keys that a not used anymore and should be corrected in incoming connections
        sender_rid (RelayLayerId): Holds the RelayLayerId from the RelayLayer that is sending this Action
        relay_id (RelayId): Holds the RelayId of the Relay that has closing incoming connections
    """
    def __init__(self, keys, sender_rid, relay_id):
        """Creates a InRelayClosedAction object with given keys and out_id.

        It sets the action_type of the Action to "InRelayClosed".

        Args:
            keys (list): Defines the keys that used by the connection and should be closed.
            sender_rid (RelayLayerId): Defining the RelayLayer that sends this action.
            relay_id (RelayId): Defining the Relay that was closed.
        """
        super(InRelayClosedAction, self).__init__("InRelayClosed", [keys, sender_rid, relay_id])

    def __get_keys(self):
        """Handles the keys stored on the first index in the parameter list
        """
        return self.parameters[0]

    def __set_keys(self, keys):
        self.parameters[0] = keys

    def __get_sender_rid(self):
        """Handles the sender rid stored on the second index in the parameter list
        """
        return self.parameters[1]

    def __set_sender_rid(self, sender_rid):
        self.parameters[1] = sender_rid

    def __get_relay_id(self):
        """Handles the relay id stored on the third index in the parameter list
        """
        return self.parameters[2]

    def __set_relay_id(self, relay_id):
        self.parameters[2] = relay_id

    keys = property(__get_keys, __set_keys)
    sender_rid = property(__get_sender_rid, __set_sender_rid)
    relay_id = property(__get_relay_id, __set_relay_id)

Ancestors

Instance variables

var keys

Handles the keys stored on the first index in the parameter list

Expand source code
def __get_keys(self):
    """Handles the keys stored on the first index in the parameter list
    """
    return self.parameters[0]
var relay_id

Handles the relay id stored on the third index in the parameter list

Expand source code
def __get_relay_id(self):
    """Handles the relay id stored on the third index in the parameter list
    """
    return self.parameters[2]
var sender_rid

Handles the sender rid stored on the second index in the parameter list

Expand source code
def __get_sender_rid(self):
    """Handles the sender rid stored on the second index in the parameter list
    """
    return self.parameters[1]

Inherited members

class LayerMessage (layer_id: RelayLayerId, action: Action)

Defines a class that holds information for messages between RelayLayers.

This class is used for communications between two RelayLayers.

Attributes

layer_id : RelayLayerId
Holds the RelayLayerId of the RelayLayer the message should be sent to.
action : Action
Holds the Action that should be executed when the relay layer receives the message.

Creates a LayerMessage object with the given RelayLayerId and Action.

The Message should be transmitted to the RelayLayer defined by the given layer_id.

Args

layer_id : RelayLayerId
Defining the RelayLayer that should receive this message.
action : Action
Defining the action that should be executed on receiving.
Expand source code
class LayerMessage:
    """Defines a class that holds information for messages between RelayLayers.

    This class is used for communications between two RelayLayers.

    Attributes:
        layer_id (RelayLayerId): Holds the RelayLayerId of the RelayLayer the message should be sent to.
        action (Action): Holds the Action that should be executed when the relay layer receives the message.
    """
    def __init__(self, layer_id: RelayLayerId, action: Action):
        """Creates a LayerMessage object with the given RelayLayerId and Action.

        The Message should be transmitted to the RelayLayer defined by the given layer_id.

        Args:
            layer_id (RelayLayerId): Defining the RelayLayer that should receive this message.
            action (Action): Defining the action that should be executed on receiving.
        """
        self.layer_id = layer_id
        self.action = action

    def __str__(self):
        return "Layer Message with layer_id: {} \n\tand action: {}" \
            .format(str(self.layer_id), str(self.action))

    def __eq__(self, other):
        return self.__class__ == other.__class__ and self.layer_id == other.layer_id and self.action == other.action
class Message (header: Header, action: Action)

Defines a wrapper class for a message.

The message includes an action and a header.

Attributes

header : Header
Holds the Header of the message which authenticates it
action : Action
Holds the Action that should be executed on arrival of this message

Creates an Message object with a given header and action.

Args

header : Header
Defines the header of the message as a Header object.
action : Action
Defines the Action that should be executed on receiving of this message.
Expand source code
class Message:
    """Defines a wrapper class for a message.

    The message includes an action and a header.

    Attributes:
        header (Header): Holds the Header of the message which authenticates it
        action (Action): Holds the Action that should be executed on arrival of this message
    """
    def __init__(self, header: Header, action: Action):
        """Creates an Message object with a given header and action.

        Args:
            header (Header): Defines the header of the message as a Header object.
            action (Action): Defines the Action that should be executed on receiving of this message.
        """
        self.header = header
        self.action = action

    def __str__(self):
        return "Message: {} \n\tand action: {}".format(self.header, self.action)

    def __eq__(self, other):
        return self.__class__ == other.__class__ and self.header == other.header and self.action == other.action
class NotAuthorizedAction (keys, out_id)

Defines the NotAuthorized Action and inherits the functionality of Action.

The action is used when a transmission over a relay is not authorized with the given keys. It holds the keys that a not authorized and the RelayId of the Relay the transmission was not allowed for.

Attributes

keys : list
Holds a list of keys the transmission was not authorized for.
out_id : RelayId
Holds a RelayId that defines the Relay which should have received the message.

Creates a NotAuthorizedAction object with given keys and out_id.

It sets the action_type of the Action to "NotAuthorized".

Args

keys : list
Defining the list of keys that are not allowed.
out_id : RelayId
Defining the Relay that has the not allowed incoming keys.
Expand source code
class NotAuthorizedAction(Action):
    """Defines the NotAuthorized Action and inherits the functionality of Action.

    The action is used when a transmission over a relay is not authorized with the given keys.
    It holds the keys that a not authorized and the RelayId of the Relay the transmission was not allowed for.

    Attributes:
        keys (list): Holds a list of keys the transmission was not authorized for.
        out_id (RelayId): Holds a RelayId that defines the Relay which should have received the message.
    """
    def __init__(self, keys, out_id):
        """Creates a NotAuthorizedAction object with given keys and out_id.

        It sets the action_type of the Action to "NotAuthorized".

        Args:
            keys (list): Defining the list of keys that are not allowed.
            out_id (RelayId): Defining the Relay that has the not allowed incoming keys.
        """
        super(NotAuthorizedAction, self).__init__("NotAuthorized", [keys, out_id])

    def __get_keys(self):
        """Handles the keys attribute stored in the parameter list on first index.
        """
        return self.parameters[0]

    def __set_keys(self, keys):
        self.parameters[0] = keys

    def __get_out_id(self):
        """Handles the out id attribute stored in the parameter list on second index.
        """
        return self.parameters[1]

    def __set_out_id(self, out_id):
        self.parameters[1] = out_id

    keys = property(__get_keys, __set_keys)
    out_id = property(__get_out_id, __set_out_id)

Ancestors

Instance variables

var keys

Handles the keys attribute stored in the parameter list on first index.

Expand source code
def __get_keys(self):
    """Handles the keys attribute stored in the parameter list on first index.
    """
    return self.parameters[0]
var out_id

Handles the out id attribute stored in the parameter list on second index.

Expand source code
def __get_out_id(self):
    """Handles the out id attribute stored in the parameter list on second index.
    """
    return self.parameters[1]

Inherited members

class OutRelayClosedAction (relay_id)

Defines the OutRelayClosed Action and inherits the functionality of Action.

This action is sent when an Relay is closed and it informs all incoming connections of this relay that it is closed.

Attributes

relay_id : RelayId
Holds the RelayId of the Relay that got closed

Creates a OutRelayClosedAction object with given keys and out_id.

It sets the action_type of the Action to "OutRelayClosed".

Args

relay_id : RelayId
Defines the Relay that is getting closed.
Expand source code
class OutRelayClosedAction(Action):
    """Defines the OutRelayClosed Action and inherits the functionality of Action.

    This action is sent when an Relay is closed and it informs all incoming connections of this relay that it is closed.

    Attributes:
        relay_id (RelayId): Holds the RelayId of the Relay that got closed
    """
    def __init__(self, relay_id):
        """Creates a OutRelayClosedAction object with given keys and out_id.

        It sets the action_type of the Action to "OutRelayClosed".

        Args:
            relay_id (RelayId): Defines the Relay that is getting closed.
        """
        super(OutRelayClosedAction, self).__init__("OutRelayClosed", [relay_id])

    def __get_relay_id(self):
        """Handles the relay id that is stored on the first index in the paremeter list."""
        return self.parameters[0]

    def __set_relay_id(self, relay_id):
        self.parameters[0] = relay_id

    relay_id = property(__get_relay_id, __set_relay_id)

Ancestors

Instance variables

var relay_id

Handles the relay id that is stored on the first index in the paremeter list.

Expand source code
def __get_relay_id(self):
    """Handles the relay id that is stored on the first index in the paremeter list."""
    return self.parameters[0]

Inherited members

class Ping (relay_id, level, sink_rid, key)

Holds every Attribute needed for a Ping Aktion. This class is not an Action class itself. This class is rather a helper class for storing information.

Attributes

relay_id : RelayId
Holds the RelayId of the relay which incoming connection should be ping checked.
level : int
Holds the level information that should be checked for the ping.
sink_rid : RelayLayerId
Holds the sink RID of the connection that should be checked in the ping.
key : str
Holds the key of the incoming connection which should be checked.

Creates a Ping object with given relay_id, level, sink_rid and key.

Args

relay_id : RelayId
The relay that should be checked in the ping.
level : int
The level of the connection.
sink_rid : RelayLayerId
Defining the RelayLayer that stores the sinkrelay of the connection.
key : str
The key that is used in the connection.
Expand source code
class Ping:
    """
    Holds every Attribute needed for a Ping Aktion. This class is not an Action class itself. This class is rather
    a helper class for storing information.

    Attributes:
        relay_id (RelayId): Holds the RelayId of the relay which incoming connection should be ping checked.
        level (int): Holds the level information that should be checked for the ping.
        sink_rid (RelayLayerId): Holds the sink RID of the connection that should be checked in the ping.
        key (str): Holds the key of the incoming connection which should be checked.
    """
    def __init__(self, relay_id, level, sink_rid, key):
        """Creates a Ping object with given relay_id, level, sink_rid and key.

        Args:
            relay_id (RelayId): The relay that should be checked in the ping.
            level (int): The level of the connection.
            sink_rid (RelayLayerId): Defining the RelayLayer that stores the sinkrelay of the connection.
            key (str): The key that is used in the connection.
        """
        self.relay_id = relay_id
        self.level = level
        self.sink_rid = sink_rid
        self.key = key
class PingAction (pings)

Defines the Ping Action and inherits the functionality of Action.

This class holds a list of ping objects. This action is sent to validate incoming connections of a relay.

Attributes

pings : list
Holds a list of ping objects. This is compressed to one action because it reduces network traffic

over the LinkLayer Creates a PingAction object with given pings.

It sets the action_type of the Action to "Ping".

Args

pings : list
Stores a list of ping object that needs to be checked on receiving the action.
Expand source code
class PingAction(Action):
    """Defines the Ping Action and inherits the functionality of Action.

    This class holds a list of ping objects.
    This action is sent to validate incoming connections of a relay.

    Attributes:
        pings (list): Holds a list of ping objects. This is compressed to one action because it reduces network traffic
         over the LinkLayer
    """
    def __init__(self, pings):
        """Creates a PingAction object with given pings.

        It sets the action_type of the Action to "Ping".

        Args:
            pings (list): Stores a list of ping object that needs to be checked on receiving the action.
        """
        super(PingAction, self).__init__("Ping", [pings])

    def __get_pings(self):
        """Handles the ping list stored in the parameter list on first index.
        """
        return self.parameters[0]

    def __set_pings(self, pings):
        self.parameters[0] = pings

    pings = property(__get_pings, __set_pings)

Ancestors

Instance variables

var pings

Handles the ping list stored in the parameter list on first index.

Expand source code
def __get_pings(self):
    """Handles the ping list stored in the parameter list on first index.
    """
    return self.parameters[0]

Inherited members

class ProbeAction (control_keys, key_sequence)

Defines the Probe Action and inherits the functionality of Action.

The ProbeAction is used when trying to validate indirect connections.

Attributes

control_keys : list
Holds a list of keys that needs to be checked in the probe message.
key_sequence : list
Holds a list of key sets that define a route the probe message went.

Creates a ProbeAction object with given controlKeys and keySequences.

It sets the action_type of the Action to "Probe".

Args

control_keys : list
The keys that should be checked in a probe message as a list of strings.
key_sequence : list
The sequence the Probe message went through the connections as a list of str lists
Expand source code
class ProbeAction(Action):
    """Defines the Probe Action and inherits the functionality of Action.

    The ProbeAction is used when trying to validate indirect connections.

    Attributes:
        control_keys (list): Holds a list of keys that needs to be checked in the probe message.
        key_sequence (list): Holds a list of key sets that define a route the probe message went.
    """
    def __init__(self, control_keys, key_sequence):
        """Creates a ProbeAction object with given controlKeys and keySequences.

        It sets the action_type of the Action to "Probe".

        Args:
            control_keys (list): The keys that should be checked in a probe message as a list of strings.
            key_sequence (list): The sequence the Probe message went through the connections as a list of str lists
        """
        super(ProbeAction, self).__init__("Probe", [control_keys, key_sequence])

    def __get_control_keys(self):
        """Handles the control keys of the Action from the parameters list stored on first index.
        """
        return self.parameters[0]

    def __set_control_keys(self, control_keys):
        self.parameters[0] = control_keys

    def __get_key_sequence(self):
        """Handles the key sequence list of the Action from the parameters list stored on second index
        """
        return self.parameters[1]

    def __set_key_sequence(self, key_sequence):
        self.parameters[1] = key_sequence

    control_keys = property(__get_control_keys, __set_control_keys)
    key_sequence = property(__get_key_sequence, __set_key_sequence)

Ancestors

Instance variables

var control_keys

Handles the control keys of the Action from the parameters list stored on first index.

Expand source code
def __get_control_keys(self):
    """Handles the control keys of the Action from the parameters list stored on first index.
    """
    return self.parameters[0]
var key_sequence

Handles the key sequence list of the Action from the parameters list stored on second index

Expand source code
def __get_key_sequence(self):
    """Handles the key sequence list of the Action from the parameters list stored on second index
    """
    return self.parameters[1]

Inherited members

class ProbeFailAction (key, key_sequence)

Defines the ProbeFail Action and inherits the functionality of Action.

The action is sent when a probe action failed for a specific key. This class hold the key that failed the probe and the key sequence for recreating the route of the probe message.

Attributes

key : str
Holds the key that caused the probe to fail.
key_sequence : list
Holds a list of key sets that define a route the probe message went.

Creates a ProbeFailAction object with given key and keySequences.

It sets the action_type of the Action to "ProbeFail".

Args

key : str
Defining the key that failed a probe message.
key_sequence : list
The sequence the Probe message went through the connections as a list of str lists
Expand source code
class ProbeFailAction(Action):
    """Defines the ProbeFail Action and inherits the functionality of Action.

    The action is sent when a probe action failed for a specific key. This class hold the key that failed the probe and the key sequence for
    recreating the route of the probe message.

    Attributes:
        key (str): Holds the key that caused the probe to fail.
        key_sequence (list): Holds a list of key sets that define a route the probe message went.
    """
    def __init__(self, key, key_sequence):
        """Creates a ProbeFailAction object with given key and keySequences.

        It sets the action_type of the Action to "ProbeFail".

        Args:
            key (str): Defining the key that failed a probe message.
            key_sequence (list): The sequence the Probe message went through the connections as a list of str lists
        """
        super(ProbeFailAction, self).__init__("ProbeFail", [key, key_sequence])

    def __get_key(self):
        """Handles the key attribute of the Action stored in the parameter list on first index.
        """
        return self.parameters[0]

    def __set_key(self, key):
        self.parameters[0] = key

    def __get_key_sequence(self):
        """Handles the key sequence attribute of the Action stored in the parameter list on second index.
        """
        return self.parameters[1]

    def __set_key_sequence(self, key_sequence):
        self.parameters[1] = key_sequence

    key = property(__get_key, __set_key)
    key_sequence = property(__get_key_sequence, __set_key_sequence)

Ancestors

Instance variables

var key

Handles the key attribute of the Action stored in the parameter list on first index.

Expand source code
def __get_key(self):
    """Handles the key attribute of the Action stored in the parameter list on first index.
    """
    return self.parameters[0]
var key_sequence

Handles the key sequence attribute of the Action stored in the parameter list on second index.

Expand source code
def __get_key_sequence(self):
    """Handles the key sequence attribute of the Action stored in the parameter list on second index.
    """
    return self.parameters[1]

Inherited members

class RelayParameter (key, relay_id: RelayId, level: int, rid: RelayLayerId)

Holds every information needed for a replacement of a relay.

This replacement has information set for another relay layer to establish a connection.

Attributes

key : str
Holds the key that is needed for an authorized connection
relay_id : RelayId
Holds the relay id defining the connection relay
level : int
Holds the level of the connection
rid : RelayLayerId
Holds the RelayLayerId of the sink rid of the connection
Expand source code
class RelayParameter:
    """Holds every information needed for a replacement of a relay.

    This replacement has information set for another relay layer to establish a connection.

    Attributes:
        key (str): Holds the key that is needed for an authorized connection
        relay_id (RelayId): Holds the relay id defining the connection relay
        level (int): Holds the level of the connection
        rid (RelayLayerId): Holds the RelayLayerId of the sink rid of the connection
    """
    def __init__(self, key, relay_id: RelayId, level: int, rid: RelayLayerId):
        self.key = key
        self.relay_id = relay_id
        self.level = level
        self.rid = rid

    def __str__(self):
        return "Relay Parameter with key: {}, relay_id: {}, level: {}, rid: {}" \
            .format(self.key, self.relay_id, self.level, self.rid)
class SuccessMessage (msg)

Holds a message and signaling a successful message transmission

Creates a SuccessMessage object holding a message.

Args

msg
Stores a message that can be transmitted.
Expand source code
class SuccessMessage:
    """Holds a message and signaling a successful message transmission
    """
    def __init__(self, msg):
        """Creates a SuccessMessage object holding a message.

        Args:
              msg: Stores a message that can be transmitted.
        """
        self.message = msg
class TransmitMessage (message: Message)

Defines a class that holds information for a transmit message.

This class is used for transmitting a message from one node to another.

Attributes

message : Message
Holds the message that should be transmitted over relays

Creates a TransmitMessage object with the given Message.

Args

message : Message
Defining the message that should be transmitted over some Relays.
Expand source code
class TransmitMessage:
    """Defines a class that holds information for a transmit message.

    This class is used for transmitting a message from one node to another.

    Attributes:
        message (Message): Holds the message that should be transmitted over relays
    """
    def __init__(self, message: Message):
        """Creates a TransmitMessage object with the given Message.

        Args:
            message (Message): Defining the message that should be transmitted over some Relays.
        """
        self.message = message

    def __str__(self):
        return "TransmitMessage including \n\t{}".format(str(self.message))

    def __eq__(self, other):
        return self.__class__ == other.__class__ and self.message == other.message