gossip.util package

Submodule which contains different utility functions for usage all over Gossip.

Submodules

gossip.util.byte_formatting module

gossip.util.byte_formatting.bytes_to_short(higher_byte, lower_byte)[source]

Transforms two bytes into a short (Using Big-Endian!)

Parameters:
  • higher_byte – The byte at position 0 (Higher byte)
  • lower_byte – The byte at position 1 (Lower byte)
Returns:

The two bytes transformed into a short

gossip.util.byte_formatting.short_to_bytes(short_value)[source]

Transforms a short to a byte array (using Big-Endian!)

Parameters:short_value – Any integer that is greater than 0 and smaller than 65535
Returns:A bytes array with the highest byte at position 0 and the lowest at position 1

gossip.util.config_parser module

gossip.util.config_parser.read_config(config_path)[source]

Reads the INI configuration file and returns all settings as a dict

Parameters:config_path – File path of the INI file.
Returns:A dict in the form {<CONFIG SETTING>: <VALUE>, ...}
gossip.util.config_parser.split_host_address(host_address)[source]

Splits a host address into the host and the corresponding port (as int) in the form of a dictionary

Returns:A dict in the form {‘host’: <IP OR HOSTNAME> ‘port’: <PORT as int>}

gossip.util.exceptions module

exception gossip.util.exceptions.GossipClientDisconnectedException(msg)[source]

Bases: Exception

exception gossip.util.exceptions.GossipIdentifierNotFound(msg)[source]

Bases: Exception

exception gossip.util.exceptions.GossipMessageException(msg)[source]

Bases: Exception

exception gossip.util.exceptions.GossipMessageFormatException(msg)[source]

Bases: Exception

exception gossip.util.exceptions.GossipQueueException(msg)[source]

Bases: Exception

gossip.util.message module

class gossip.util.message.MessageGossip(code, data)[source]

Bases: object

Baseclass for gossip messages

C’tor

Parameters:code – the code of this message
encode()[source]

Encodes this message into a byte array

Returns:a byte array with the encoded header and payload
get_code()[source]

Method by which the code of this message is retrieved

Returns:the code of this message
get_values()[source]

Method by which the values of this message are retrieved

Returns:the values of this message
class gossip.util.message.MessageGossip51x(code, data)[source]

Bases: gossip.util.message.MessageGossip

Baseclass for gossip messages of code 510-519

C’Tor

Parameters:code – the code of this message
class gossip.util.message.MessageGossipAnnounce(data)[source]

Bases: gossip.util.message.MessageGossip

GossipAnnounceMessage This messages are received from api connections. If you want to implement an api client for gossip its messages need to be structured like that

C’Tor

Parameters:data (bytes) – the data of the message
get_values()[source]

Method by which the values of this message are retrieved

Returns:a dictionary with the values of this message (keys: code, message, TTL, type)
class gossip.util.message.MessageGossipNotification(data)[source]

Bases: gossip.util.message.MessageGossip

Message that is sent from gossip to api clients which was received from other peers

C’Tor

Parameters:data (bytes) – the data from this message
get_values()[source]

Method by which the values of this message are retrieved

Returns:a dictionary with the values of this message (keys: code, type, id, message)
class gossip.util.message.MessageGossipNotify(data)[source]

Bases: gossip.util.message.MessageGossip

This message is sent from the gossip instance to all apis that registered for this specific datatype An api client needs to implement this messageformat

C’Tor

Parameters:data (bytes) – the data of the message
get_values()[source]

Method by which the values of this message are retrieved

Returns:a dictionary with the values of this message (keys: code, type)
class gossip.util.message.MessageGossipPeerInit(data)[source]

Bases: gossip.util.message.MessageGossip51x

Initial message that is sent from the connection peer to the remote peer to inform that peer about his server adderss (especially the port)

C’Tor

Parameters:data – the data from this message
get_values()[source]

Method by which the values of this message are retrieved

Returns:a dictionary with the values of this message (keys: code, p2p_server_address)
class gossip.util.message.MessageGossipPeerRequest(data)[source]

Bases: gossip.util.message.MessageGossip51x

Message that is sent from one peer to another to get addresses of peers the other peer is connected to

C’Tor

Parameters:data – the data from this message
get_values()[source]
class gossip.util.message.MessageGossipPeerResponse(data)[source]

Bases: gossip.util.message.MessageGossip51x

Message that is sent as an answer to a previously sent peer request. It contains a list of server identifiers (address:port)

C’Tor

Parameters:data – the data from this message
get_values()[source]

Method by which the values of this message are retrieved

Returns:a dictionary with the values of this message (keys: code, data)
class gossip.util.message.MessageGossipPeerUpdate(data)[source]

Bases: gossip.util.message.MessageGossip51x

Message that is sent recursively through the network as a respone to a new established connection

C’Tor

Parameters:data – the data from this message
get_values()[source]

Method by which the values of this message are retrieved

Returns:a dictionary with the values of this message (keys: code, address, ttl, update_type)
class gossip.util.message.MessageGossipValidation(data)[source]

Bases: gossip.util.message.MessageGossip

Message that is sent from gossip to api clients to know whether or not a received message is valid

C’Tor

Parameters:data – the data from this message
get_values()[source]

Method by which the values of this message are retrieved

Returns:a dictionary with the values of this message (keys: id, valid, code)
class gossip.util.message.MessageOther(message_code, message_data)[source]

Bases: object

If a message can’t be decoded properly a MessageOther will be returned.

C’Tor

Parameters:
  • message_code – the code of the message
  • message_data – the data of the message
encode()[source]
get_values()[source]

Method by which the values of this message are retrieved

Returns:a dictionary with the values of this message (keys: code, message)

gossip.util.message_code module

gossip.util.packing module

gossip.util.packing.pack_gossip_announce(ttl, data_type, msg_data)[source]

Method by which a message of type ‘GOSSIP ANNOUNCE’ is packed/encoded

Parameters:
  • ttl – the time to live
  • data_type – the data type of the message
  • msg_data – the data to pack
Returns:

dict, code and data

gossip.util.packing.pack_gossip_notification(msg_id, data_type, msg_data)[source]

Method by which a message of type ‘GOSSIP NOTIFICATION’ is packed/encoded

Parameters:
  • msg_id – the id of the message
  • data_type – the data type of the message
  • msg_data – the data to pack
Returns:

dict, code and data

gossip.util.packing.pack_gossip_notify(data_type)[source]

Method by which a message of type ‘GOSSIP NOTIFY’ is packed/encoded

Parameters:data_type – the data type of the message
Returns:dict, code and data
gossip.util.packing.pack_gossip_peer_init(identifier)[source]

Method by which a message of type MESSAGE_CODE_PEER_INIT is packed/encoded

Returns:dict, code and data
gossip.util.packing.pack_gossip_peer_request(address_port)[source]

Method by which a message of type MESSAGE_CODE_PEER_REQUEST is packed/encoded

Returns:dict, code and data
gossip.util.packing.pack_gossip_peer_response(local_connections)[source]

Method by which a message of type MESSAGE_CODE_PEER_RESPONSE is packed/encoded

Parameters:local_connections – list with all local connections
Returns:dict with format {‘code’: <message_code>, ‘data’: <data>}
gossip.util.packing.pack_gossip_peer_update(identifier, ttl, update_type)[source]

Method by which a message of type MESSAGE_CODE_PEER_UPDATE is packed/encoded

Returns:dict, code and data
gossip.util.packing.pack_gossip_validation(msg_id, valid_bit)[source]

Method by which a message of type ‘GOSSIP VALIDATION’ is packed/encoded

Parameters:
  • msg_id – the id of the message
  • valid_bit – set iff valid, unset else value may be 0 or 1
Returns:

dict, code and data

gossip.util.packing.pack_message_other(code, data)[source]

Method by which other modules messages are (re-)packed

Parameters:
  • code – the code of the message
  • data – the data to pack
Returns:

dict, code and data

gossip.util.packing.receive_msg(sock)[source]

Method by which a byte message is decoded

Parameters:sock – tcp socket to read from
Returns:a dict of the decoded values
gossip.util.packing.send_msg(sock, code, msg)[source]

Method by which a Message is encoded and sent

Parameters:
  • sock – the socket to send the message on
  • code – the code of the message
  • msg – the message to encode

gossip.util.queue_item_types module