gossip.control package¶
Submodule which handles the incoming API and P2P messages/connections/sockets.
It is called from the API and P2P layer asynchronously.
Submodules¶
gossip.control.api_controller module¶
-
class
gossip.control.api_controller.
APIController
(from_api_queue, to_api_queue, to_p2p_queue, api_connection_pool, p2p_connection_pool, announce_message_cache, api_registration_handler)[source]¶ Bases:
multiprocessing.process.Process
This controller is responsible for all incoming messages from the API layer. If an API client sends any message, this controller handles it in various ways.
Parameters: - from_api_queue – Used by the API layer for incoming messages and commands
- to_api_queue – Messages and commands for the API layer are sent through this queue
- to_p2p_queue – Messages and commands for the P2P layer are sent through this queue
- api_connection_pool – Pool which contains all API connections/clients/sockets
- p2p_connection_pool – Pool which contains all P2P connections/clients/sockets
- announce_message_cache – Message cache which contains announce messages.
- api_registration_handler – Used for registrations (via NOTIFY message) from API clients
-
static
fetch_identifiers
(connection_pool, server_to_exclude)[source]¶ Collects server identifiers :param connection_pool: The connection pool to iterate through :param server_to_exclude: Server identifier to exclude
-
run
()[source]¶ Typical run method which is used to handle API messages and commands. It reacts on incoming messages with changing the state of Gossip internally or by sending new messages resp. establishing new connections.
-
spread_message_to_api
(notification_msg, senders_identifier)[source]¶ Spreads a message to all API clients which are registered for the containing message type.
Parameters: - notification_msg – This message will be spread through all desired API clients
- senders_identifier – This identifier will be excluded from the receivers list
gossip.control.api_registrations module¶
-
class
gossip.control.api_registrations.
APIRegistrationHandler
[source]¶ Bases:
object
Thread-safe implementation of an handler for API registrations.
Contructor.
-
get_registrations
(code)[source]¶ Provides all identifiers who registered for a specified code.
Parameters: code – The code for which the registrations are returned Returns: All identifiers who registered for this code
-
gossip.control.convert module¶
-
gossip.control.convert.
from_announce_to_notification
(msg_id, message)[source]¶ Method by which the values of an announce message are transferred into a notification message
Parameters: - msg_id – the message id of the new notification message
- message – the message to convert
Returns: the packed converted message object
gossip.control.message_cache module¶
-
class
gossip.control.message_cache.
GossipMessageCache
(message_cache_label, cache_size=30)[source]¶ Bases:
object
Thread-safe implementation of a message cache which maintains all currently known messages.
Contructor.
Parameters: cache_size – The maximum numbers of messages that can be hold by this cache: Default 30 -
DATE_ADDED
= 'DateAdded'¶
-
MAX_MSG_ID
= 65535¶
-
add_message
(message, valid=False)[source]¶ Adds new message to the cache.
Parameters: - message – The new message to cache
- valid – (optional) Flag which states whether this message is valid or not
Returns: The generated random message identifier for the cached message (None if message is already in cache)
-
get_message
(msg_id)[source]¶ Provides a cached message.
Parameters: msg_id – Identifier of the desired message Returns: The desired message (None if it does not exist)
-
is_valid
(msg_id)[source]¶ Returns True if the specified message is marked as valid
Parameters: msg_id – Message id Returns: True if the message is marked as valid, False if it is invalid or if it doesn’t exist in the cache
-
iterator
(exclude_id=True)[source]¶ Creates a generator for the message cache. Removes the outer dict with id and only returns message ordered by date (from oldest to newest)
Returns: An iterator over the ordered list of messages
-
gossip.control.p2p_controller module¶
-
class
gossip.control.p2p_controller.
P2PController
(from_p2p_queue, to_p2p_queue, to_api_queue, p2p_connection_pool, p2p_server_address, announce_message_cache, update_message_cache, api_registration_handler, max_ttl, bootstrapper_address=None)[source]¶ Bases:
multiprocessing.process.Process
This controller is responsible for all incoming messages from the P2P layer. If a P2P client sends any message, this controller handles it in various ways.
Parameters: - from_p2p_queue – Used by the P2P layer for incoming messages and commands
- to_p2p_queue – Messages and commands for the P2P layer are sent through this queue
- to_api_queue – Messages and commands for the API layer are sent through this queue
- p2p_connection_pool – Pool which contains all P2P connections/clients/sockets
- p2p_server_address – The P2P server address for this gossip instance
- announce_message_cache – Message cache which contains announce messages.
- update_message_cache – Message cache for peer update messages
- api_registration_handler – Used for registrations (via NOTIFY message) from API clients
- max_ttl – Max. amount of hops until messages will be dropped
- bootstrapper_address – (optional) dict to specify the bootstrapper {‘host’: <IPv4>: ‘port’: <int(port)>}
-
exchange_messages
(peer_identifier)[source]¶ Send messages to new connected peer.
Parameters: peer_identifier – Receiving peer
-
run
()[source]¶ Typical run method which is used to handle P2P messages and commands. It reacts on incoming messages with changing the state of Gossip internally or by sending new messages resp. establishing new connections.
-
send_peer_request
(peer_request_identifier)[source]¶ Sends a peer request
Parameters: peer_request_identifier – The identifier dict of the receiving peer
-
send_peer_update
(senders_identifier, senders_server_identifier, ttl)[source]¶ Sends peer updates to several peers.
Parameters: - senders_identifier – Identifier of the sender we received this update from
- senders_server_identifier – Server identifier of the changed peer
- ttl – ttl to set in the new update messages