gossip.communication package

Submodule which contains communication functionalities for the P2P and API layer of Gossip.

Submodules

gossip.communication.client_receiver module

class gossip.communication.client_receiver.GossipClientReceiver(client_receiver_label, client_socket, ipv4_address, tcp_port, to_controller_queue, connection_pool)[source]

Bases: multiprocessing.process.Process

A client receiver is a process which receives data from a specified socket.

Constructor.

Parameters:
  • client_receiver_label – A label to derive the concrete functionality of this client receiver
  • client_socket – The socket from/to the affected the affected client
  • ipv4_address – The IPv4 address of the client
  • tcp_port – The TCP port of the client
  • to_controller_queue – The queue which connects this client receiver with the responsible controller
  • connection_pool – If the socket crashes, the connection will be removed in this connection pool
handle_client()[source]

Receives new messages until the client dies. It also kills connections to clients which send malformed messages. Therefor it informs the responsible controller as well.

run()[source]

This typical run method of the client receiver process is responsible for handling a connection for the Gossip instance. It handles incoming messages and forwards them to the controller. If a connection crashes, this method pushes a specified command to the responsible controller.

gossip.communication.client_sender module

class gossip.communication.client_sender.GossipSender(sender_label, from_controller_queue, to_controller_queue, connection_pool)[source]

Bases: multiprocessing.process.Process

The Gossip sender receives new commands from the responsible controller. The sender is responsible for sending new messages to specified receivers. It is able to establish new connections as well if the controller sends the appropriate command to do so.

Constructor.

Parameters:
  • sender_label – A label to derive the concrete functionality of this client sender
  • from_controller_queue – The client sender gets new commands via this queue from the responsible controller
  • to_controller_queue – This instance forwards the controller queue to new receiver instances
  • connection_pool – The connection pool which contains all connections/sockets
run()[source]

This is a typical run method for the sender process. It waits for commands from the controller to establish new connections or to send messages to established connections. The sender gets the appropriate connection/socket from the connection pool.

gossip.communication.connection module

class gossip.communication.connection.GossipConnectionPool(connection_pool_label, cache_size=30)[source]

Bases: object

Thread-safe implementation of a pool for Gossip connections.

Constructor.

Parameters:
  • connection_pool_label – A label to derive the concrete functionality of this connection pool
  • cache_size – (optional): The max. amount of connections in this connection pool.
CONNECTION = 'Connection'
SERVER_IDENTIFIER = 'ServerIdentifier'
add_connection(identifier, connection, server_identifier=None)[source]

Adds new identifier with its connection.

Parameters:
  • identifier – An object which identifies an unique connection
  • connection – A connection object
  • server_identifier – (optional) The server identifier of the peer
filter_new_server_identifiers(server_identifiers, identifier_to_exclude=None)[source]

Provides all given identifiers which are not known until now.

Parameters:
  • server_identifiers – Server identifiers to check against known ones
  • identifier_to_exclude – (optional) Server identifiers to exclude
Returns:

Identifiers which are not known as server identifiers in the connection pool until now

get_capacity()[source]

Provides the left capacity of the current connection pool.

Returns:The left capacity
get_connection(identifier)[source]

Gets a connection from the pool.

Parameters:identifier – Unique identifier to find the affected connection
get_identifiers()[source]

Gets a list of all identifiers.

Returns:List of all identifier strings
get_random_identifier(identifier_to_exclude)[source]

Provides a random identifier which represents an active connection in the pool at the moment.

Parameters:identifier_to_exclude – Identifier to exclude
Returns:Random identifier
get_server_identifier(identifier)[source]

Gets the server identifier for one connection.

Parameters:identifier – Unique identifier to find the affected server identifier
get_server_identifiers(identifier_to_exclude=None)[source]

Collects server identifiers

Parameters:identifier_to_exclude – (optional) Server identifiers to exclude
remove_connection(identifier)[source]

Removes an existing connection from the pool.

Parameters:identifier – Unique identifier to find the affected connection
update_connection(identifier, server_identifier)[source]

Updates an existing identifier with its connection.

Parameters:
  • identifier – An object which identifies an unique connection
  • server_identifier – The server identifier of the peer

gossip.communication.server module

class gossip.communication.server.GossipServer(server_label, client_receiver_label, bind_address, tcp_port, to_controller_queue, connection_pool)[source]

Bases: multiprocessing.process.Process

The Gossip server waits for new connections established by other clients. It also instantiates new receivers for incoming connections.

Parameters:
  • server_label – A label to derive the concrete functionality of this gossip server
  • client_receiver_label – This label is used for newly instantiated receivers
  • bind_address – IPv4 address which is used to listen for new connections
  • tcp_port – TCP port which is used to listen for new connections
  • to_controller_queue – Newly instantiated receivers need to know a queue to communicate with the controller
  • connection_pool – New connections will be added to the appropriate connection pool
run()[source]

Typical run method for the sender process. It waits for new connections, refers to newly instantiated receiver instances, and finally starts the new receivers.