pydistsim.network.node.Node

class Node(network: NetworkType | None = None, commRange: None | int = None, sensors: None | tuple[type[Sensor] | str] = None, **kwargs)[source]

Bases: ObserverManagerMixin

Represents a node in a network.

Parameters:
  • network (NetworkType, optional) – Optional network object to which the node belongs.

  • commRange (int, optional) – Communication range of the node.

  • sensors (tuple[type[Sensor] | str], optional) – Tuple of sensor types or names.

  • kwargs – Additional keyword arguments.

Methods

__init__

add_observers

block_inbox

Block messages from being received by the node.

box_as_dic

Convert a message box to a dictionary representation.

clear_observers

get_dic

Get the node's information as a dictionary.

get_log

Get the log messages stored in the node's memory.

log

Insert a log message in the node's memory.

notify_observers

push_to_inbox

Push a message to the inbox of the node.

push_to_outbox

Push a message to the outbox of the node.

receive

Pop message from inbox but only if it has been there at least one step.

reset

Reset the node's state.

unblock_inbox

Unblock messages from being received by the node.

unbox

Attributes

commRange

Get the communication range of the node.

compositeSensor

Get the composite sensor of the node.

inbox

Get the inbox of the node.

next_node_id

sensors

Get the sensors of the node.

status

Get the status of the node.

network

The network to which the node belongs.

_compositeSensor

Object that collects the data from all available sensors.

_internal_id

Internal ID of the node. Only used for internal simulation purposes.

block_inbox(filter_func: Callable[[Message], bool]) Callable[[Message], bool][source]

Block messages from being received by the node.

Parameters:

filter_func (function) – The filter function to be used.

Returns:

The filter function.

box_as_dic(box: str)[source]

Convert a message box to a dictionary representation.

Parameters:

box (str) – The message box to be converted.

Returns:

The dictionary representation of the message box.

Return type:

dict

property commRange: int

Get the communication range of the node.

Returns:

The communication range of the node.

Return type:

int

property compositeSensor

Get the composite sensor of the node.

Returns:

The composite sensor of the node.

Return type:

CompositeSensor

get_dic()[source]

Get the node’s information as a dictionary.

Returns:

The node’s information.

Return type:

dict

get_log()[source]

Get the log messages stored in the node’s memory.

Returns:

The log messages.

Return type:

list[tuple[LogLevels, str, dict]]

property inbox

Get the inbox of the node.

Returns:

The inbox of the node.

Return type:

list[Message]

log(message: str, level: LogLevels = LogLevels.WARNING)[source]

Insert a log message in the node’s memory.

Parameters:
  • message (str) – The log message to be inserted.

  • level (LogLevels, optional) – The log level of the message.

network

The network to which the node belongs.

push_to_inbox(message: Message[Node])[source]

Push a message to the inbox of the node.

Parameters:

message (Message) – The message to be pushed to the inbox.

push_to_outbox(message: Message[Node], destination: Node)[source]

Push a message to the outbox of the node.

Parameters:
  • message (Message) – The message to be pushed to the outbox.

  • destination (Node) – The destination node of the message.

receive()[source]

Pop message from inbox but only if it has been there at least one step.

Messages should be delayed for one step for visualization purposes. Messages are processed without delay only if they are pushed into empty inbox. So if inbox is empty when push_to_inbox is called _inboxDelay is set to True.

This method is used only internally and is not supposed to be used inside algorithms.

Returns:

The received message, or None if no message is available.

Return type:

Message or None

reset()[source]

Reset the node’s state.

Clears the outbox, inbox, status, and memory of the node.

property sensors

Get the sensors of the node.

Returns:

The sensors of the node.

Return type:

list[Sensor]

property status

Get the status of the node.

Returns:

The status of the node.

Return type:

str

unblock_inbox(filter_func: Callable[[Message], bool])[source]

Unblock messages from being received by the node.

Parameters:

filter_func (function) – The filter function to be removed.