tribler.core.content_discovery.community ======================================== .. py:module:: tribler.core.content_discovery.community Attributes ---------- .. autoapisummary:: tribler.core.content_discovery.community.HEALTH_REQUEST_POPULAR tribler.core.content_discovery.community.HEALTH_REQUEST_RANDOM Classes ------- .. autoapisummary:: tribler.core.content_discovery.community.ContentDiscoverySettings tribler.core.content_discovery.community.ContentDiscoveryCommunity Module Contents --------------- .. py:data:: HEALTH_REQUEST_POPULAR :value: 1 .. py:data:: HEALTH_REQUEST_RANDOM :value: 2 .. py:class:: ContentDiscoverySettings Bases: :py:obj:`ipv8.community.CommunitySettings` The settings for the content discovery community. .. py:attribute:: random_torrent_interval :type: float :value: 5 .. py:attribute:: random_torrent_count :type: int :value: 10 .. py:attribute:: max_query_peers :type: int :value: 20 .. py:attribute:: maximum_payload_size :type: int :value: 1300 .. py:attribute:: max_response_size :type: int :value: 100 .. py:attribute:: binary_fields :type: collections.abc.Sequence[str] :value: ('infohash', 'channel_pk') .. py:attribute:: deprecated_parameters :type: collections.abc.Sequence[str] :value: ('subscribed', 'attribute_ranges', 'complete_channel') .. py:attribute:: metadata_store :type: tribler.core.database.store.MetadataStore .. py:attribute:: torrent_checker :type: tribler.core.torrent_checker.torrent_checker.TorrentChecker .. py:attribute:: notifier :type: tribler.core.notifier.Notifier | None :value: None .. py:class:: ContentDiscoveryCommunity(settings: ContentDiscoverySettings) Bases: :py:obj:`ipv8.community.Community` Community for disseminating the content across the network. .. py:attribute:: community_id .. py:attribute:: settings_class .. py:attribute:: composition .. py:attribute:: request_cache .. py:attribute:: remote_queries_in_progress :value: 0 .. py:attribute:: next_remote_query_num .. py:attribute:: health_history :type: collections.deque[tribler.core.torrent_checker.healthdataclasses.HealthInfo] .. py:method:: unload() -> None :async: Shut down the request cache. .. py:method:: 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. .. py:method:: 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. .. py:method:: convert_to_json(parameters: dict[str, Any]) -> str Sanitize and dump the given dictionary to a string using JSON. .. py:method:: get_alive_checked_torrents() -> list[tribler.core.torrent_checker.healthdataclasses.HealthInfo] Get torrents that we know have seeders AND leechers. .. py:method:: gossip_random_torrents_health() -> None Gossip random torrent health information to another peer. .. py:method:: 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. .. py:method:: on_health_request(peer: ipv8.peer.Peer, payload: tribler.core.content_discovery.payload.HealthRequestPayload) -> None :async: Callback for when we receive a request for torrent health. .. py:method:: on_health(peer: ipv8.peer.Peer, payload: tribler.core.content_discovery.payload.HealthPayload) -> None :async: Callback for when we receive torrent health. .. py:method:: get_random_torrents() -> list[tribler.core.torrent_checker.healthdataclasses.HealthInfo] Get torrent health info for torrents that were alive, last we know of. .. py:method:: get_popular_torrents() -> list[tribler.core.torrent_checker.healthdataclasses.HealthInfo] Get torrent health info for the most popular torrent, last we know of. .. py:method:: get_random_peers(sample_size: int | None = None) -> list[ipv8.peer.Peer] Randomly sample sample_size peers from the complete list of our peers. .. py:method:: 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. .. py:method:: on_version_request(peer: ipv8.peer.Peer, _: tribler.core.content_discovery.payload.VersionRequest) -> None :async: Callback for when our Tribler version and Operating System is requested. .. py:method:: on_version_response(peer: ipv8.peer.Peer, payload: tribler.core.content_discovery.payload.VersionResponse) -> None :async: Callback for when we receive a Tribler version and Operating System of a peer. .. py:method:: 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). .. py:method:: should_limit_rate_for_query(sanitized_parameters: dict[str, Any]) -> bool Don't allow too many queries with potentially heavy database load. .. py:method:: process_rpc_query_rate_limited(sanitized_parameters: dict[str, Any]) -> list :async: Process the given query and return results. .. py:method:: process_rpc_query(sanitized_parameters: dict[str, Any]) -> list :async: 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. :raises ValueError: if no JSON could be decoded. :raises pony.orm.dbapiprovider.OperationalError: if an illegal query was performed. .. py:method:: 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. .. py:method:: on_remote_select(peer: ipv8.peer.Peer, request_payload: tribler.core.content_discovery.payload.RemoteSelectPayload) -> None :async: Callback for when another peer queries us. .. py:method:: 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. .. py:method:: on_remote_select_response(peer: ipv8.peer.Peer, response_payload: tribler.core.content_discovery.payload.SelectResponsePayload) -> list[tribler.core.database.store.ProcessingResult] | None :async: 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. .. py:method:: _on_query_timeout(request_cache: tribler.core.content_discovery.cache.SelectRequest) -> None Remove a peer if it failed to respond to our select request. .. py:method:: send_ping(peer: ipv8.peer.Peer) -> None Send a ping to a peer to keep it alive.