tribler.core.database.serialization

Attributes

EPOCH

SIGNATURE_SIZE

NULL_SIG

NULL_KEY

TYPELESS

CHANNEL_NODE

METADATA_NODE

COLLECTION_NODE

JSON_NODE

CHANNEL_DESCRIPTION

BINARY_NODE

CHANNEL_THUMBNAIL

REGULAR_TORRENT

CHANNEL_TORRENT

DELETED

SNIPPET

METADATA_TYPE_TO_PAYLOAD_CLASS

Exceptions

UnknownBlobTypeException

A block was received with an unknown blob type.

Classes

SignedPayload

A payload that captures a public key and metadata type and supports adding a signature over its contents.

ChannelNodePayload

A signed payload that also includes an id, origin id, and a timestamp.

MetadataNodePayload

Deprecated, do not use.

JsonNodePayload

Deprecated, do not use.

BinaryNodePayload

Deprecated, do not use.

CollectionNodePayload

Deprecated, do not use.

TorrentMetadataPayload

Payload for metadata that stores a torrent.

ChannelMetadataPayload

Deprecated, do not use.

DeletedMetadataPayload

Deprecated, do not use.

HealthItemsPayload

Payload for health item information. See the details of binary format in MetadataCompressor class description.

Functions

time2int(→ int)

Convert a datetime object to an int.

int2time(→ datetime.datetime)

Convert an int into a datetime object.

read_payload_with_offset(→ tuple[SignedPayload, int])

Read the next payload from the data buffer (at the given offset).

Module Contents

tribler.core.database.serialization.EPOCH
tribler.core.database.serialization.SIGNATURE_SIZE = 64
tribler.core.database.serialization.NULL_SIG = 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...
tribler.core.database.serialization.NULL_KEY = 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...
tribler.core.database.serialization.TYPELESS = 100
tribler.core.database.serialization.CHANNEL_NODE = 200
tribler.core.database.serialization.METADATA_NODE = 210
tribler.core.database.serialization.COLLECTION_NODE = 220
tribler.core.database.serialization.JSON_NODE = 230
tribler.core.database.serialization.CHANNEL_DESCRIPTION = 231
tribler.core.database.serialization.BINARY_NODE = 240
tribler.core.database.serialization.CHANNEL_THUMBNAIL = 241
tribler.core.database.serialization.REGULAR_TORRENT = 300
tribler.core.database.serialization.CHANNEL_TORRENT = 400
tribler.core.database.serialization.DELETED = 500
tribler.core.database.serialization.SNIPPET = 600
tribler.core.database.serialization.time2int(date_time: datetime.datetime, epoch: datetime.datetime = EPOCH) int

Convert a datetime object to an int.

Parameters:
  • date_time – The datetime object to convert.

  • epoch – The epoch time, defaults to Jan 1, 1970.

Returns:

The int representation of date_time.

WARNING: TZ-aware timestamps are madhouse…

tribler.core.database.serialization.int2time(timestamp: int, epoch: datetime.datetime = EPOCH) datetime.datetime

Convert an int into a datetime object.

Parameters:
  • timestamp – The timestamp to be converted.

  • epoch – The epoch time, defaults to Jan 1, 1970.

Returns:

The datetime representation of timestamp.

exception tribler.core.database.serialization.UnknownBlobTypeException

Bases: Exception

A block was received with an unknown blob type.

We only support type:

  • 300, REGULAR_TORRENT

tribler.core.database.serialization.read_payload_with_offset(data: bytes, offset: int = 0) tuple[SignedPayload, int]

Read the next payload from the data buffer (at the given offset).

class tribler.core.database.serialization.SignedPayload

Bases: 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.

names = ['metadata_type', 'reserved_flags', 'public_key']
format_list = ['H', 'H', '64s']
signature: bytes = 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...
metadata_type: int
reserved_flags: int
public_key: bytes
serialized() bytes

Pack this serializable.

classmethod from_signed_blob(serialized: bytes) Self

Read a SignedPayload from the given serialized form.

to_dict() dict

Convert this payload to a dictionary.

classmethod from_dict(**kwargs) Self

Create a payload from the given data (an unpacked dict).

add_signature(key: ipv8.keyvault.keys.PrivateKey) None

Create a signature for this payload.

has_signature() bool

Check if this payload has an attached signature already.

check_signature() bool

Check if the signature attached to this payload is valid for this payload.

class tribler.core.database.serialization.ChannelNodePayload

Bases: SignedPayload

A signed payload that also includes an id, origin id, and a timestamp.

names = ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp']
format_list = ['H', 'H', '64s', 'Q', 'Q', 'Q']
id_: int
origin_id: int
timestamp: int
class tribler.core.database.serialization.MetadataNodePayload

Bases: ChannelNodePayload

Deprecated, do not use.

names = ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp', 'title', 'tags']
format_list = ['H', 'H', '64s', 'Q', 'Q', 'Q', 'varlenIutf8', 'varlenIutf8']
class tribler.core.database.serialization.JsonNodePayload

Bases: ChannelNodePayload

Deprecated, do not use.

names = ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp', 'json_text']
format_list = ['H', 'H', '64s', 'Q', 'Q', 'Q', 'varlenIutf8']
class tribler.core.database.serialization.BinaryNodePayload

Bases: ChannelNodePayload

Deprecated, do not use.

names = ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp',...
format_list = ['H', 'H', '64s', 'Q', 'Q', 'Q', 'varlenI', 'varlenIutf8']
class tribler.core.database.serialization.CollectionNodePayload

Bases: MetadataNodePayload

Deprecated, do not use.

names = ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp', 'title',...
format_list = ['H', 'H', '64s', 'Q', 'Q', 'Q', 'varlenIutf8', 'varlenIutf8', 'Q']
class tribler.core.database.serialization.TorrentMetadataPayload

Bases: ChannelNodePayload

Payload for metadata that stores a torrent.

names = ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp', 'infohash',...
format_list = ['H', 'H', '64s', 'Q', 'Q', 'Q', '20s', 'Q', 'I', 'varlenIutf8', 'varlenIutf8', 'varlenIutf8']
infohash: bytes
size: int
torrent_date: int
title: str
tags: str
tracker_info: str
fix_pack_torrent_date(value: datetime.datetime | int) int

Auto-convert the torrent date to an integer if it is a datetime object.

classmethod fix_unpack_torrent_date(value: int) datetime.datetime

Auto-convert the torrent data from the integer wire format to a datetime object.

get_magnet() str

Create a magnet link for this payload.

class tribler.core.database.serialization.ChannelMetadataPayload

Bases: TorrentMetadataPayload

Deprecated, do not use.

names = ['metadata_type', 'reserved_flags', 'public_key', 'id_', 'origin_id', 'timestamp', 'infohash',...
format_list = ['H', 'H', '64s', 'Q', 'Q', 'Q', '20s', 'Q', 'I', 'varlenIutf8', 'varlenIutf8', 'varlenIutf8', 'Q', 'Q']
class tribler.core.database.serialization.DeletedMetadataPayload

Bases: SignedPayload

Deprecated, do not use.

names = ['metadata_type', 'reserved_flags', 'public_key', 'delete_signature']
format_list = ['H', 'H', '64s', '64s']
tribler.core.database.serialization.METADATA_TYPE_TO_PAYLOAD_CLASS
class tribler.core.database.serialization.HealthItemsPayload

Bases: ipv8.messaging.lazy_payload.VariablePayload

Payload for health item information. See the details of binary format in MetadataCompressor class description.

format_list = ['varlenI']
names = ['data']
data: bytes
serialize() bytes

Convert this payload to bytes.

classmethod unpack(data: bytes) list[tuple[int, int, int]]

Unpack this payload from the given data buffer.

classmethod parse_health_data_item(item: bytes) tuple[int, int, int]

Convert the given bytes to (seeders, leechers, last_check) format.