gossipy.core module#

Module contents#

class gossipy.core.AntiEntropyProtocol(value)#

Bases: enum.Enum

The overall protocol of the gossip algorithm.

PULL = 2#

Pull the gossip model from the gossip node(s).

PUSH = 1#

Push the local model to the gossip node(s).

PUSH_PULL = 3#

Push the local model to the gossip node(s) and then pull the gossip model from the gossip node(s).

class gossipy.core.CreateModelMode(value)#

Bases: enum.Enum

The mode for creating/updating the gossip model.

MERGE_UPDATE = 2#

Merge the models and then make an update using the local data.

PASS = 4#

Do nothing.

UPDATE = 1#

Update the model with the local data.

UPDATE_MERGE = 3#

Update the models with the local data and then merge the models.

class gossipy.core.Delay#

Bases: abc.ABC

A class representing a delay.

The delay is a function of a message and returns the delay in simulation time units.

abstract get(msg)#

Returns the delay for the specified message.

Parameters

msg (Message) – The message for which the delay is computed.

Returns

The delay in time units.

Return type

int

class gossipy.core.LinearDelay(timexunit, overhead)#

Bases: gossipy.core.Delay

A class representing a linear delay.

The linear delay is computed as a fixed overhead plus a quantity proportional to
the message’s size. LinearDelay can mimic the behavior of
ConstantDelay, i.e., LinearDelay(0, x) is equivalent to ConstantDelay(x).
Parameters
  • timexunit (float) – The time unit delay per size unit.

  • overhead (int) – The overhead delay (in time units) to apply to each message.

get(msg)#

Returns the delay for the specified message.

The delay is linear with respect to the message’s size and it is computed as follows:
delay = floor(timexunit * size(msg)) + overhead.
This type of delay allows to simulate the transmission time which is a linear function
of the size of the message.
Parameters

msg (Message) – The message for which the delay is computed.

Returns

The delay in time units.

Return type

int

class gossipy.core.Message(timestamp, sender, receiver, type, value)#

Bases: gossipy.Sizeable

A class representing a message.

Parameters
  • timestamp (int) – The message’s timestamp with the respect to the simulation time. The timestamp refers to the moment when the message is sent.

  • sender (int) – The sender node id.

  • receiver (int) – The receiver node id.

  • type (MessageType) – The message type.

  • value (tuple[Any, ...] or None) – The message’s payload. The typical payload is a single item tuple containing the model (handler). If the value is None, the message represents an ACK.

get_size()#

Computes and returns the estimated size of the message.

The size is expressed in number of “atomic” values stored in the message. Atomic values are integers, floats, and booleans.

Note

Currently strings are not supported.

Returns

The estimated size of the message.

Return type

int

Raises

TypeError – If the message’s payload contains values that are not atomic.

class gossipy.core.MessageType(value)#

Bases: enum.Enum

The type of a message.

PULL = 2#

Asks for the model to the receiver.

PUSH = 1#

The message contains the model (and possibly additional information)

PUSH_PULL = 4#

The message contains the model (and possibly additional information) and also asks for the model to the receiver.

REPLY = 3#

The message is a response to a PULL message.

class gossipy.core.P2PNetwork(num_nodes, topology=None)#

Bases: abc.ABC

Abstract class representing a network topology.

Parameters
  • num_nodes (int) – The number of nodes in the network.

  • topology (Optional[Union[np.ndarray, csr_matrix]], default=None) – The adjacency matrix of the network topology. If None, the network is considered to be a fully connected network.

abstract get_peers(node_id)#

Abstract method to get the peers of a node.

Parameters

node_id (int) – The node identifier.

size(node=None)#
Return type

int

Parameters

node (Optional[int]) –

class gossipy.core.StaticP2PNetwork(num_nodes, topology=None)#

Bases: gossipy.core.P2PNetwork

A class representing a static network topology.

A static network topology is a network topology where the adjacency matrix is fixed.

Parameters
  • num_nodes (int) – The number of nodes in the network.

  • topology (Optional[Union[np.ndarray, csr_matrix]], default=None) – The adjacency matrix of the network topology. If None, the network is considered to be a fully connected network.

get_peers(node_id)#

Returns the peers of a node according to the static network topology.

Parameters

node_id (int) – The node identifier.

Return type

List[int]

class gossipy.core.UniformDelay(min_delay, max_delay)#

Bases: gossipy.core.Delay

A class representing a uniform delay.

Parameters
  • min_delay (int) – The minimum delay in time units.

  • max_delay (int) – The maximum delay in time units.

get(msg)#

Returns the delay for the specified message.

The delay is uniformly distributed between the minimum and maximum delay regardless of the specific message.

Parameters

msg (Message) – The message for which the delay is computed.

Returns

The delay in time units.

Return type

int