Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged Popularity, RemoteQuery and Version communities #7743

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/exit_node/run_exit_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def make_config(options) -> TriblerConfig:
config.ipv8.address = options.ipv8_address
config.dht.enabled = True
config.tunnel_community.exitnode_enabled = bool(options.exit)
config.popularity_community.enabled = False
config.content_discovery_community.enabled = False
config.tunnel_community.testnet = bool(options.testnet)
config.chant.enabled = False
config.bootstrap.enabled = False
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/components/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def tribler_config(tmp_path) -> TriblerConfig:
config.libtorrent.enabled = False
config.libtorrent.dht_readiness_timeout = 0
config.tunnel_community.enabled = False
config.popularity_community.enabled = False
config.content_discovery_community.enabled = False
config.dht.enabled = False
config.libtorrent.dht = False
config.chant.enabled = False
Expand Down
36 changes: 36 additions & 0 deletions src/tribler/core/components/content_discovery/community/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from asyncio import Future

from ipv8.requestcache import RandomNumberCache
from tribler.core.components.metadata_store.utils import RequestTimeoutException


class SelectRequest(RandomNumberCache):
def __init__(self, request_cache, prefix, request_kwargs, peer, processing_callback=None, timeout_callback=None):
super().__init__(request_cache, prefix)
self.request_kwargs = request_kwargs
# The callback to call on results of processing of the response payload
self.processing_callback = processing_callback
# The maximum number of packets to receive from any given peer from a single request.
# This limit is imposed as a safety precaution to prevent spam/flooding
self.packets_limit = 10

self.peer = peer
# Indicate if at least a single packet was returned by the queried peer.
self.peer_responded = False

self.timeout_callback = timeout_callback

def on_timeout(self):
if self.timeout_callback is not None:
self.timeout_callback(self)


class EvaSelectRequest(SelectRequest):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# For EVA transfer it is meaningless to send more than one message
self.packets_limit = 1

self.processing_results = Future()
self.register_future(self.processing_results, on_timeout=RequestTimeoutException())

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,51 @@ def create(cls, random_torrents_checked: List[HealthInfo], popular_torrents_chec
random_torrent_tuples, popular_torrent_tuples)


@dataclass(msg_id=2)
class PopularTorrentsRequest:
pass
@vp_compile
class PopularTorrentsRequest(VariablePayload):
msg_id=2


@vp_compile
class VersionRequest(VariablePayload):
msg_id = 101


@vp_compile
class VersionResponse(VariablePayload):
msg_id = 102
format_list = ['varlenI', 'varlenI']
names = ['version', 'platform']

def fix_pack_version(self, value):
return value.encode('utf-8')

def fix_pack_platform(self, value):
return value.encode('utf-8')

@classmethod
def fix_unpack_version(cls, value):
return value.decode('utf-8')

@classmethod
def fix_unpack_platform(cls, value):
return value.decode('utf-8')


@vp_compile
class RemoteSelectPayload(VariablePayload):
msg_id = 201
format_list = ['I', 'varlenH']
names = ['id', 'json']


@vp_compile
class RemoteSelectPayloadEva(RemoteSelectPayload):
msg_id = 209


@vp_compile
class SelectResponsePayload(VariablePayload):
msg_id = 202
format_list = ['I', 'raw']
names = ['id', 'raw_blob']
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import annotations

from typing import Sequence

from ipv8.community import CommunitySettings
from tribler.core.components.database.db.tribler_database import TriblerDatabase
from tribler.core.components.metadata_store.db.store import MetadataStore
from tribler.core.components.torrent_checker.torrent_checker.torrent_checker import TorrentChecker
from tribler.core.utilities.notifier import Notifier


class ContentDiscoverySettings(CommunitySettings):
random_torrent_interval: float = 5 # seconds
random_torrent_count: int = 10
max_query_peers: int = 20
maximum_payload_size: int = 1300
max_response_size: int = 100 # Max number of entries returned by SQL query

binary_fields: Sequence[str] = ("infohash", "channel_pk")
deprecated_parameters: Sequence[str] = ('subscribed', 'attribute_ranges', 'complete_channel')

metadata_store: MetadataStore
torrent_checker: TorrentChecker
tribler_db: TriblerDatabase | None = None
notifier: Notifier | None = None
Loading
Loading