tribler.core.database.serialization =================================== .. py:module:: tribler.core.database.serialization Attributes ---------- .. autoapisummary:: tribler.core.database.serialization.EPOCH tribler.core.database.serialization.SIGNATURE_SIZE tribler.core.database.serialization.NULL_SIG tribler.core.database.serialization.NULL_KEY tribler.core.database.serialization.TYPELESS tribler.core.database.serialization.CHANNEL_NODE tribler.core.database.serialization.METADATA_NODE tribler.core.database.serialization.COLLECTION_NODE tribler.core.database.serialization.JSON_NODE tribler.core.database.serialization.CHANNEL_DESCRIPTION tribler.core.database.serialization.BINARY_NODE tribler.core.database.serialization.CHANNEL_THUMBNAIL tribler.core.database.serialization.REGULAR_TORRENT tribler.core.database.serialization.CHANNEL_TORRENT tribler.core.database.serialization.DELETED tribler.core.database.serialization.SNIPPET tribler.core.database.serialization.METADATA_TYPE_TO_PAYLOAD_CLASS Exceptions ---------- .. autoapisummary:: tribler.core.database.serialization.UnknownBlobTypeException Classes ------- .. autoapisummary:: tribler.core.database.serialization.SignedPayload tribler.core.database.serialization.ChannelNodePayload tribler.core.database.serialization.MetadataNodePayload tribler.core.database.serialization.JsonNodePayload tribler.core.database.serialization.BinaryNodePayload tribler.core.database.serialization.CollectionNodePayload tribler.core.database.serialization.TorrentMetadataPayload tribler.core.database.serialization.ChannelMetadataPayload tribler.core.database.serialization.DeletedMetadataPayload tribler.core.database.serialization.HealthItemsPayload Functions --------- .. autoapisummary:: tribler.core.database.serialization.time2int tribler.core.database.serialization.int2time tribler.core.database.serialization.read_payload_with_offset Module Contents --------------- .. py:data:: EPOCH .. py:data:: SIGNATURE_SIZE :value: 64 .. py:data:: NULL_SIG :value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0... .. py:data:: NULL_KEY :value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0... .. py:data:: TYPELESS :value: 100 .. py:data:: CHANNEL_NODE :value: 200 .. py:data:: METADATA_NODE :value: 210 .. py:data:: COLLECTION_NODE :value: 220 .. py:data:: JSON_NODE :value: 230 .. py:data:: CHANNEL_DESCRIPTION :value: 231 .. py:data:: BINARY_NODE :value: 240 .. py:data:: CHANNEL_THUMBNAIL :value: 241 .. py:data:: REGULAR_TORRENT :value: 300 .. py:data:: CHANNEL_TORRENT :value: 400 .. py:data:: DELETED :value: 500 .. py:data:: SNIPPET :value: 600 .. py:function:: time2int(date_time: datetime.datetime, epoch: datetime.datetime = EPOCH) -> int Convert a datetime object to an int. :param date_time: The datetime object to convert. :param epoch: The epoch time, defaults to Jan 1, 1970. :return: The int representation of date_time. WARNING: TZ-aware timestamps are madhouse... .. py:function:: int2time(timestamp: int, epoch: datetime.datetime = EPOCH) -> datetime.datetime Convert an int into a datetime object. :param timestamp: The timestamp to be converted. :param epoch: The epoch time, defaults to Jan 1, 1970. :return: The datetime representation of timestamp. .. py:exception:: UnknownBlobTypeException Bases: :py:obj:`Exception` A block was received with an unknown blob type. We only support type: - 300, REGULAR_TORRENT .. py:function:: read_payload_with_offset(data: bytes, offset: int = 0) -> tuple[SignedPayload, int] Read the next payload from the data buffer (at the given offset). .. py:class:: SignedPayload Bases: :py:obj:`ipv8.messaging.lazy_payload.VariablePayload` A payload that captures a public key and metadata type and supports adding a signature over its contents. This payload can be extended to allow more data to be signed. .. py:attribute:: names :value: ['metadata_type', 'reserved_flags', 'public_key'] .. py:attribute:: format_list :value: ['H', 'H', '64s'] .. py:attribute:: signature :type: bytes :value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0... .. py:attribute:: metadata_type :type: int .. py:attribute:: reserved_flags :type: int .. py:attribute:: public_key :type: bytes .. py:method:: serialized() -> bytes Pack this serializable. .. py:method:: from_signed_blob(serialized: bytes) -> Self :classmethod: Read a SignedPayload from the given serialized form. .. py:method:: to_dict() -> dict Convert this payload to a dictionary. .. py:method:: from_dict(**kwargs) -> Self :classmethod: Create a payload from the given data (an unpacked dict). .. py:method:: add_signature(key: ipv8.keyvault.keys.PrivateKey) -> None Create a signature for this payload. .. py:method:: has_signature() -> bool Check if this payload has an attached signature already. .. py:method:: check_signature() -> bool Check if the signature attached to this payload is valid for this payload. .. py:class:: ChannelNodePayload Bases: :py:obj:`SignedPayload` A signed payload that also includes an id, origin id, and a timestamp. .. py:attribute:: names :value: ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp'] .. py:attribute:: format_list :value: ['H', 'H', '64s', 'Q', 'Q', 'Q'] .. py:attribute:: id_ :type: int .. py:attribute:: origin_id :type: int .. py:attribute:: timestamp :type: int .. py:class:: MetadataNodePayload Bases: :py:obj:`ChannelNodePayload` Deprecated, do not use. .. py:attribute:: names :value: ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp', 'title', 'tags'] .. py:attribute:: format_list :value: ['H', 'H', '64s', 'Q', 'Q', 'Q', 'varlenIutf8', 'varlenIutf8'] .. py:class:: JsonNodePayload Bases: :py:obj:`ChannelNodePayload` Deprecated, do not use. .. py:attribute:: names :value: ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp', 'json_text'] .. py:attribute:: format_list :value: ['H', 'H', '64s', 'Q', 'Q', 'Q', 'varlenIutf8'] .. py:class:: BinaryNodePayload Bases: :py:obj:`ChannelNodePayload` Deprecated, do not use. .. py:attribute:: names :value: ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp',... .. py:attribute:: format_list :value: ['H', 'H', '64s', 'Q', 'Q', 'Q', 'varlenI', 'varlenIutf8'] .. py:class:: CollectionNodePayload Bases: :py:obj:`MetadataNodePayload` Deprecated, do not use. .. py:attribute:: names :value: ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp', 'title',... .. py:attribute:: format_list :value: ['H', 'H', '64s', 'Q', 'Q', 'Q', 'varlenIutf8', 'varlenIutf8', 'Q'] .. py:class:: TorrentMetadataPayload Bases: :py:obj:`ChannelNodePayload` Payload for metadata that stores a torrent. .. py:attribute:: names :value: ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp', 'infohash',... .. py:attribute:: format_list :value: ['H', 'H', '64s', 'Q', 'Q', 'Q', '20s', 'Q', 'I', 'varlenIutf8', 'varlenIutf8', 'varlenIutf8'] .. py:attribute:: infohash :type: bytes .. py:attribute:: size :type: int .. py:attribute:: torrent_date :type: int .. py:attribute:: title :type: str .. py:attribute:: tags :type: str .. py:attribute:: tracker_info :type: str .. py:method:: fix_pack_torrent_date(value: datetime.datetime | int) -> int Auto-convert the torrent date to an integer if it is a ``datetime`` object. .. py:method:: fix_unpack_torrent_date(value: int) -> datetime.datetime :classmethod: Auto-convert the torrent data from the integer wire format to a ``datetime`` object. .. py:method:: get_magnet() -> str Create a magnet link for this payload. .. py:class:: ChannelMetadataPayload Bases: :py:obj:`TorrentMetadataPayload` Deprecated, do not use. .. py:attribute:: names :value: ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp', 'infohash',... .. py:attribute:: format_list :value: ['H', 'H', '64s', 'Q', 'Q', 'Q', '20s', 'Q', 'I', 'varlenIutf8', 'varlenIutf8', 'varlenIutf8', 'Q', 'Q'] .. py:class:: DeletedMetadataPayload Bases: :py:obj:`SignedPayload` Deprecated, do not use. .. py:attribute:: names :value: ['metadata_type', 'reserved_flags', 'public_key', 'delete_signature'] .. py:attribute:: format_list :value: ['H', 'H', '64s', '64s'] .. py:data:: METADATA_TYPE_TO_PAYLOAD_CLASS .. py:class:: HealthItemsPayload Bases: :py:obj:`ipv8.messaging.lazy_payload.VariablePayload` Payload for health item information. See the details of binary format in MetadataCompressor class description. .. py:attribute:: format_list :value: ['varlenI'] .. py:attribute:: names :value: ['data'] .. py:attribute:: data :type: bytes .. py:method:: serialize() -> bytes Convert this payload to bytes. .. py:method:: unpack(data: bytes) -> list[tuple[int, int, int]] :classmethod: Unpack this payload from the given data buffer. .. py:method:: parse_health_data_item(item: bytes) -> tuple[int, int, int] :classmethod: Convert the given bytes to ``(seeders, leechers, last_check)`` format.