Base Module =========== This module contains common functions and classes used throughout the rest of the library .. c:macro:: CP2P_PROTOCOL_MAJOR_VERSION This macro defines the major version number. A change here indicates a major change or release, and may be breaking. In a scheme x.y.z, it would be x .. c:macro:: CP2P_PROTOCOL_MINOR_VERSION This macro defines the minor version number. It refers specifically to minor protocol revisions, and all changes here are API compatible (after 1.0), but not compatbile with other nodes. In a scheme x.y.z, it would be y .. c:macro:: CP2P_NODE_VERSION This macro defines the patch version number. It refers specifically to node policies, and all changes here are backwards compatible. In a scheme x.y.z, it would be z .. c:macro:: CP2P_VERSION This macro is a string literal. It combines all the above macros into a single string. It will generate whatever a string literal would normally be interpreted as in that context. .. c:macro:: CP2P_DEBUG_FLAG This macro indicates whether cp2p should generate debug prints. If you define this as anything it will print .. cpp:var:: static const unsigned char *flags::reserved_cstr This binary data string contains every reserved flag. .. note:: This will be refactored later to an array of :c:type:`unsigned char *` s, but for know just know that all flags are one char long. .. cpp:var:: static const size_t flags::reserved_len The length of the above string .. cpp:var:: static const unsigned char *flags::implemented_compressions_cstr This binary data string contains the flag of every implemented compression methods. .. note:: This will be refactored later to an array of :c:type:`unsigned char *` s, but for know just know that all flags are one char long. .. cpp:var:: static const size_t flags::compression_len The length of the above string .. cpp:var:: static const unsigned char flags::other_flags These are the flags currently reserved. They are guarunteed to be the same names and values as the flags within :py:class:`py2p.base.flags`. .. note:: This will be refactored later to an array of :c:type:`unsigned char *` s, but for know just know that all flags are one char long. .. cpp:function:: static std::string get_user_salt() This generates a uuid4 for use in this library .. cpp:var:: const static std::string user_salt A generated uuid4 for use in this library .. cpp:function:: unsigned long long unpack_value(std::string str) Unpacks a big-endian binary value into an unsigned long long :param str: The value you'd like to unpack :returns: The value this string contained .. warning:: Integer overflow will not be accounted for .. cpp:function:: std::string pack_value(size_t len, unsigned long long i) Packs an unsigned long long into a big-endian binary string of length len :param len: The length of the string you'd like to produce :param i: The value you'd like to pack :returns: A :cpp:class:`std::string` packed with the equivalent big-endian data .. warning:: Integer overflow will not be accounted for .. cpp:function:: std::string sanitize_string(std::string str, bool sizeless) This function takes in a string and removes metadata that the :cpp:class:`pathfinding_message` deserializer can't handle :param str: The string you would like to sanitize :param sizeless: A bool indicating if this string has a size header attached :returns: A :cpp:class:`std::string` which has the safe version of ``str`` .. cpp:function:: std::string decompress_string(std::string str, std::vector compressions) This function is currently an identity function which returns ``str``. In the future this function will decompress strings for the :cpp:class:`pathfinding_message` parser to deal with. :param str: The string you would like to decompress :param compressions: A :cpp:class:`std::vector\` which contains the list of possible compression methods :returns: A :cpp:class:`std::string` which has the decompressed version of ``str`` .. cpp:function:: std::vector process_string(std::string str) This deserializes a :cpp:class:`pathfinding_message` string into a :cpp:class:`std::vector\` of packets :param str: The :cpp:class`std::string` you would like to parse :returns: A :cpp:class:`std::vector\` which contains the packets serialized in this string .. cpp:class:: protocol This class is used as a subnet object. Its role is to reject undesired connections. If you connect to someone who has a different protocol object than you, this descrepency is detected, and you are silently disconnected. .. cpp:function:: protocol::protocol(std::string, std::string encryption) :param subnet: The subnet you'd like to use :param encryption: The encryption method you'd like to use .. cpp:function:: protocol::~protocol() An empty deconstructor .. cpp:function:: std::string protocol::id() :returns: A :cpp:class:`std::string` which contains the base_58 encoded, SHA256 based ID of this protocol object .. cpp:function:: std::string protocol::subnet .. cpp:function:: std::string protocol::encryption .. cpp:class:: pathfinding_message This is the message serialization/deserialization class. .. cpp:function:: pathfinding_message::pathfinding_message(std::string msg_type, std::string sender, std::vector payload) .. cpp:function:: pathfinding_message::pathfinding_message(std::string msg_type, std::string sender, std::vector payload, std::vector compressions) :param msg_type: This is the main flag checked by nodes, used for routing information :param sender: The ID of the person sending the message :param payload: A :cpp:class:`std::vector\` of "packets" that you want your peers to receive :param compression: A :cpp:class:`std::vector\` of compression methods that the receiver supports .. cpp:function:: static pathfinding_message *pathfinding_message::feed_string(std::string msg) .. cpp:function:: static pathfinding_message *pathfinding_message::feed_string(std::string msg, bool sizeless) .. cpp:function:: static pathfinding_message *pathfinding_message::feed_string(std::string msg, std::vector compressions) .. cpp:function:: static pathfinding_message *pathfinding_message::feed_string(std::string msg, bool sizeless, std::vector compressions) :param msg: A :cpp:class:`std::string` which contains the serialized message :param sizeless: A :c:type:`bool` which indicates if the message has a size header attached (default: it does) :param compressions: A :cpp:class:`std::vector\` which contains the possible compression methods this message may be using :returns: A pointer to the deserialized message .. cpp:function:: pathfinding_message::~pathfinding_message() An empty deconstructor .. cpp:var:: std::string pathfinding_message::msg_type .. cpp:var:: std::string pathfinding_message::sender .. cpp:var:: unsigned long pathfinding_message::timestamp .. cpp:var:: std::vector pathfinding_message::payload .. cpp:var:: std::vector pathfinding_message::compression .. cpp:var:: bool pathfinding_message::compression_fail .. cpp:function:: std::string pathfinding_message::compression_used() :returns: The compression method this message was sent under .. cpp:function:: std::string pathfinding_message::time_58() :returns: :cpp:var:`pathfinding_message::timestamp` encoded in base_58 .. cpp:function:: std::string pathfinding_message::id() :returns: A SHA384 hash of this message encoded in base_58 .. cpp:function:: std::vector pathfinding_message::packets() A copy of :cpp:var:`pathfinding_message::payload` with some additional metadata appended to the front. Specifically: 0. :cpp:var:`pathfinding_message::msg_type` #. :cpp:var:`pathfinding_message::sender` #. :cpp:func:`pathfinding_message::id()` #. :cpp:func:`pathfinding_message::time_58()` #. :cpp:var:`pathfinding_message::payload` from here on out :returns: A :cpp:class:`std::vector\` in the above format .. cpp:function:: std::string pathfinding_message::base_string() :returns: the serialized message, excepting the four byte size header at the beginning .. cpp:function:: std::string pathfinding_message::str() :returns: the serialized message, including the four byte size header at the beginning .. cpp:function:: unsigned long long pathfinding_message::length() :returns: the length of the serialized message, excepting the four byte size header at the beginning .. cpp:function:: std::string pathfinding_message::header() :returns: the four byte size header at the beginning of the serialized message