tribler.core.content_discovery.community

Attributes

HEALTH_REQUEST_POPULAR

HEALTH_REQUEST_RANDOM

Classes

ContentDiscoverySettings

The settings for the content discovery community.

ContentDiscoveryCommunity

Community for disseminating the content across the network.

Module Contents

tribler.core.content_discovery.community.HEALTH_REQUEST_RANDOM = 2
class tribler.core.content_discovery.community.ContentDiscoverySettings

Bases: ipv8.community.CommunitySettings

The settings for the content discovery community.

random_torrent_interval: float = 5
random_torrent_count: int = 10
max_query_peers: int = 20
maximum_payload_size: int = 1300
max_response_size: int = 100
binary_fields: collections.abc.Sequence[str] = ('infohash', 'channel_pk')
deprecated_parameters: collections.abc.Sequence[str] = ('subscribed', 'attribute_ranges', 'complete_channel')
metadata_store: tribler.core.database.store.MetadataStore
torrent_checker: tribler.core.torrent_checker.torrent_checker.TorrentChecker
notifier: tribler.core.notifier.Notifier | None = None
class tribler.core.content_discovery.community.ContentDiscoveryCommunity(settings: ContentDiscoverySettings)

Bases: ipv8.community.Community

Community for disseminating the content across the network.

community_id
settings_class
composition
request_cache
remote_queries_in_progress = 0
next_remote_query_num
health_history: collections.deque[tribler.core.torrent_checker.healthdataclasses.HealthInfo]
async unload() None

Shut down the request cache.

sanitize_dict(parameters: dict[str, Any], decode: bool = True) None

Convert the binary values in the given dictionary to (decode=True) and from (decode=False) hex format.

sanitize_query(query_dict: dict[str, Any], cap: int = 100) dict[str, Any]

Convert the values in a query to the appropriate format and supply missing values.

convert_to_json(parameters: dict[str, Any]) str

Sanitize and dump the given dictionary to a string using JSON.

get_alive_checked_torrents() list[tribler.core.torrent_checker.healthdataclasses.HealthInfo]

Get torrents that we know have seeders AND leechers.

gossip_random_torrents_health() None

Gossip random torrent health information to another peer.

process_torrents_health(health_list: list[tribler.core.torrent_checker.healthdataclasses.HealthInfo]) set[bytes]

Get the infohashes that we did not know about before from the given health list.

async on_health_request(peer: ipv8.peer.Peer, payload: tribler.core.content_discovery.payload.HealthRequestPayload) None

Callback for when we receive a request for torrent health.

async on_health(peer: ipv8.peer.Peer, payload: tribler.core.content_discovery.payload.HealthPayload) None

Callback for when we receive torrent health.

get_random_torrents() list[tribler.core.torrent_checker.healthdataclasses.HealthInfo]

Get torrent health info for torrents that were alive, last we know of.

Get torrent health info for the most popular torrent, last we know of.

get_random_peers(sample_size: int | None = None) list[ipv8.peer.Peer]

Randomly sample sample_size peers from the complete list of our peers.

send_search_request(**kwargs) tuple[uuid.UUID, list[ipv8.peer.Peer]]

Send a remote query request to multiple random peers to search for some terms.

async on_version_request(peer: ipv8.peer.Peer, _: tribler.core.content_discovery.payload.VersionRequest) None

Callback for when our Tribler version and Operating System is requested.

async on_version_response(peer: ipv8.peer.Peer, payload: tribler.core.content_discovery.payload.VersionResponse) None

Callback for when we receive a Tribler version and Operating System of a peer.

send_remote_select(peer: ipv8.peer.Peer, processing_callback: collections.abc.Callable[[tribler.core.content_discovery.cache.SelectRequest, list[tribler.core.database.store.ProcessingResult]], None] | None = None, **kwargs) tribler.core.content_discovery.cache.SelectRequest

Query a peer using an SQL statement descriptions (kwargs).

should_limit_rate_for_query(sanitized_parameters: dict[str, Any]) bool

Don’t allow too many queries with potentially heavy database load.

async process_rpc_query_rate_limited(sanitized_parameters: dict[str, Any]) list

Process the given query and return results.

async process_rpc_query(sanitized_parameters: dict[str, Any]) list

Retrieve the result of a database query from a third party, encoded as raw JSON bytes (through dumps).

Raises:
  • TypeError – if the JSON contains invalid keys.

  • ValueError – if no JSON could be decoded.

  • pony.orm.dbapiprovider.OperationalError – if an illegal query was performed.

send_db_results(peer: ipv8.peer.Peer, request_payload_id: int, db_results: list[tribler.core.database.orm_bindings.torrent_metadata.TorrentMetadata]) None

Send the given results to the given peer.

async on_remote_select(peer: ipv8.peer.Peer, request_payload: tribler.core.content_discovery.payload.RemoteSelectPayload) None

Callback for when another peer queries us.

parse_parameters(json_bytes: bytes) dict[str, Any]

Load a (JSON) dict from the given bytes and sanitize it to use as a database query.

async on_remote_select_response(peer: ipv8.peer.Peer, response_payload: tribler.core.content_discovery.payload.SelectResponsePayload) list[tribler.core.database.store.ProcessingResult] | None

Match the response that we received from the network to a query cache and process it by adding the corresponding entries to the MetadataStore database. This processes both direct responses and pushback (updates) responses.

_on_query_timeout(request_cache: tribler.core.content_discovery.cache.SelectRequest) None

Remove a peer if it failed to respond to our select request.

send_ping(peer: ipv8.peer.Peer) None

Send a ping to a peer to keep it alive.