From b6d34f12b3f60e59e5dd0f08a7736ced6f153c82 Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 28 Feb 2023 13:41:58 +0700 Subject: [PATCH 1/9] Fix method redefinitions --- .../components/libtorrent/download_manager/download.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/tribler/core/components/libtorrent/download_manager/download.py b/src/tribler/core/components/libtorrent/download_manager/download.py index 7462251610e..a00cff5cf18 100644 --- a/src/tribler/core/components/libtorrent/download_manager/download.py +++ b/src/tribler/core/components/libtorrent/download_manager/download.py @@ -751,14 +751,6 @@ def set_upload_mode(self, upload_mode): self.config.set_upload_mode(upload_mode) self.handle.set_upload_mode(upload_mode) - @check_handle() - def get_upload_mode(self): - return self.handle.status().upload_mode - - @require_handle - def set_upload_mode(self, upload_mode): - self.handle.set_upload_mode(upload_mode) - @require_handle def force_dht_announce(self): self.handle.force_dht_announce() From 2baf2762fb6f44eb29aebce7bcd399f1d22eec72 Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 28 Feb 2023 13:55:06 +0700 Subject: [PATCH 2/9] Use absolute WORKDIR --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index af35b8a6090..bc4441291d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,7 @@ RUN pip3 install -r requirements/core-requirements.txt # Copy the source code and set the working directory COPY ./ tribler -WORKDIR tribler +WORKDIR /home/user/tribler # Set the REST API port and expose it ENV CORE_API_PORT=20100 From 5fdcb11ae4addf6c554e2d7ba21067a09b9082c9 Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 28 Feb 2023 14:01:04 +0700 Subject: [PATCH 3/9] Fix "No value for argument 'message' in constructor call" error --- src/run_tribler_headless.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/run_tribler_headless.py b/src/run_tribler_headless.py index 07fa880a8ee..3380936c559 100644 --- a/src/run_tribler_headless.py +++ b/src/run_tribler_headless.py @@ -26,16 +26,16 @@ class IPPortAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): parsed = re.match(r"^([\d\.]+)\:(\d+)$", values) if not parsed: - raise argparse.ArgumentError("Invalid address:port") + raise argparse.ArgumentError(self, "Invalid address:port") ip, port = parsed.group(1), int(parsed.group(2)) try: inet_aton(ip) except: - raise argparse.ArgumentError("Invalid server address") + raise argparse.ArgumentError(self, "Invalid server address") if not (0 < port < 65535): - raise argparse.ArgumentError("Invalid server port") + raise argparse.ArgumentError(self, "Invalid server port") setattr(namespace, self.dest, values) From 02c2c0f82c044f35a701ae70e655e010e424b27c Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 28 Feb 2023 14:11:38 +0700 Subject: [PATCH 4/9] Fix "Undefined variable 'BandwidthAccountingCommunity'" error --- .../core/components/bandwidth_accounting/community/cache.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tribler/core/components/bandwidth_accounting/community/cache.py b/src/tribler/core/components/bandwidth_accounting/community/cache.py index 98b97b429c2..d3394b8614a 100644 --- a/src/tribler/core/components/bandwidth_accounting/community/cache.py +++ b/src/tribler/core/components/bandwidth_accounting/community/cache.py @@ -4,6 +4,8 @@ from ipv8.requestcache import RandomNumberCache +from tribler.core.components.bandwidth_accounting.community.bandwidth_accounting_community import \ + BandwidthAccountingCommunity from tribler.core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData @@ -12,7 +14,7 @@ class BandwidthTransactionSignCache(RandomNumberCache): This cache keeps track of pending bandwidth transaction signature requests. """ - def __init__(self, community: BandwidthAccountingCommunity, transaction: BandwidthTransactionData) -> None: # noqa: F821 + def __init__(self, community: BandwidthAccountingCommunity, transaction: BandwidthTransactionData) -> None: """ Initialize the cache. :param community: The bandwidth community associated with this cache. From 37d3aeb721612555b0649c4f63a6e1b618000a9e Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 28 Feb 2023 14:19:09 +0700 Subject: [PATCH 5/9] Fix " Undefined variable 'BandwidthTransaction'" error --- .../components/bandwidth_accounting/community/payload.py | 2 +- .../core/components/bandwidth_accounting/db/transaction.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tribler/core/components/bandwidth_accounting/community/payload.py b/src/tribler/core/components/bandwidth_accounting/community/payload.py index d9ed8d0b108..9dcb024facb 100644 --- a/src/tribler/core/components/bandwidth_accounting/community/payload.py +++ b/src/tribler/core/components/bandwidth_accounting/community/payload.py @@ -14,7 +14,7 @@ class BandwidthTransactionPayload(VariablePayload): "timestamp", "request_id"] @classmethod - def from_transaction(cls, transaction: BandwidthTransaction, request_id: int) -> BandwidthTransactionPayload: # noqa: F821 + def from_transaction(cls, transaction, request_id: int) -> BandwidthTransactionPayload: return BandwidthTransactionPayload( transaction.sequence_number, transaction.public_key_a, diff --git a/src/tribler/core/components/bandwidth_accounting/db/transaction.py b/src/tribler/core/components/bandwidth_accounting/db/transaction.py index 273dadaeaf7..f73c79fa2ab 100644 --- a/src/tribler/core/components/bandwidth_accounting/db/transaction.py +++ b/src/tribler/core/components/bandwidth_accounting/db/transaction.py @@ -88,7 +88,7 @@ def is_valid(self) -> bool: return True @classmethod - def from_payload(cls, payload: BandwidthTransactionPayload) -> BandwidthTransaction: # noqa: F821 + def from_payload(cls, payload: BandwidthTransactionPayload): """ Create a block according to a given payload. This method can be used when receiving a block from the network. @@ -99,10 +99,10 @@ def from_payload(cls, payload: BandwidthTransactionPayload) -> BandwidthTransact payload.signature_a, payload.signature_b, payload.amount, payload.timestamp) @classmethod - def from_db(cls, db_obj: BandwidthTransaction) -> BandwidthTransactionData: # noqa: F821 + def from_db(cls, db_obj) -> BandwidthTransactionData: """ Return a BandwidthTransaction object from a database object. - :param db_obj: The database object to convert. + :param db_obj: The BandwidthTransaction object to convert. :return A BandwidthTransaction object, based on the database object. """ return BandwidthTransactionData(db_obj.sequence_number, db_obj.public_key_a, db_obj.public_key_b, From 8b934e81680253353216b489e6ad00a74d5c8016 Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 28 Feb 2023 14:24:21 +0700 Subject: [PATCH 6/9] Fix "self.session_stats_callback is not callable" error --- .../libtorrent/download_manager/download_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tribler/core/components/libtorrent/download_manager/download_manager.py b/src/tribler/core/components/libtorrent/download_manager/download_manager.py index 7028869cf25..aff2c794182 100644 --- a/src/tribler/core/components/libtorrent/download_manager/download_manager.py +++ b/src/tribler/core/components/libtorrent/download_manager/download_manager.py @@ -11,7 +11,7 @@ from binascii import unhexlify from copy import deepcopy from shutil import rmtree -from typing import Dict, List, Optional +from typing import Callable, Dict, List, Optional from ipv8.taskmanager import TaskManager, task @@ -119,7 +119,7 @@ def __init__(self, self.default_alert_mask = lt.alert.category_t.error_notification | lt.alert.category_t.status_notification | \ lt.alert.category_t.storage_notification | lt.alert.category_t.performance_warning | \ lt.alert.category_t.tracker_notification | lt.alert.category_t.debug_notification - self.session_stats_callback = None + self.session_stats_callback: Optional[Callable] = None self.state_cb_count = 0 # Status of libtorrent session to indicate if it can safely close and no pending writes to disk exists. From 811d8cc938cd6ca1525521852d503434797af0a1 Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 28 Feb 2023 14:27:08 +0700 Subject: [PATCH 7/9] Fix "Undefined variable 'BandwidthTransaction'" error --- src/tribler/core/components/tunnel/community/payload.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tribler/core/components/tunnel/community/payload.py b/src/tribler/core/components/tunnel/community/payload.py index c5e4a8d4978..774be62ac8d 100644 --- a/src/tribler/core/components/tunnel/community/payload.py +++ b/src/tribler/core/components/tunnel/community/payload.py @@ -14,10 +14,10 @@ class BandwidthTransactionPayload(VariablePayload): "circuit_id", "base_amount"] @classmethod - def from_transaction(cls, transaction: BandwidthTransaction, circuit_id: int, base_amount: int): # noqa: F821 + def from_transaction(cls, transaction, circuit_id: int, base_amount: int): """ Create a transaction from the provided payload. - :param transaction: The transaction to convert to a payload. + :param transaction: The BandwidthTransaction to convert to a payload. :param circuit_id: The circuit identifier to include in the payload. :param base_amount: The base amount of bandwidth to payout. """ From c9e8e1687d838175f58eb9c89128cb6765175da2 Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 28 Feb 2023 14:28:21 +0700 Subject: [PATCH 8/9] Fix "self.reject_callback is not callable" error --- .../core/components/tunnel/community/tunnel_community.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tribler/core/components/tunnel/community/tunnel_community.py b/src/tribler/core/components/tunnel/community/tunnel_community.py index 97bf82e6c5d..8ba43713ad4 100644 --- a/src/tribler/core/components/tunnel/community/tunnel_community.py +++ b/src/tribler/core/components/tunnel/community/tunnel_community.py @@ -6,7 +6,7 @@ from binascii import unhexlify from collections import Counter from distutils.version import LooseVersion -from typing import List, Optional +from typing import Callable, List, Optional import async_timeout from ipv8.messaging.anonymization.caches import CreateRequestCache @@ -94,7 +94,8 @@ def __init__(self, *args, **kwargs): self.download_states = {} self.competing_slots = [(0, None)] * num_competing_slots # 1st tuple item = token balance, 2nd = circuit id self.random_slots = [None] * num_random_slots - self.reject_callback = None # This callback is invoked with a tuple (time, balance) when we reject a circuit + # This callback is invoked with a tuple (time, balance) when we reject a circuit + self.reject_callback: Optional[Callable] = None self.last_forced_announce = {} if self.socks_servers: From 5a3d5fa4f842e0773d1213a82062783c36140afb Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 28 Feb 2023 14:36:52 +0700 Subject: [PATCH 9/9] Fix tests --- .../components/bandwidth_accounting/community/cache.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tribler/core/components/bandwidth_accounting/community/cache.py b/src/tribler/core/components/bandwidth_accounting/community/cache.py index d3394b8614a..c58682b11b7 100644 --- a/src/tribler/core/components/bandwidth_accounting/community/cache.py +++ b/src/tribler/core/components/bandwidth_accounting/community/cache.py @@ -1,13 +1,16 @@ from __future__ import annotations from asyncio import Future +from typing import TYPE_CHECKING from ipv8.requestcache import RandomNumberCache -from tribler.core.components.bandwidth_accounting.community.bandwidth_accounting_community import \ - BandwidthAccountingCommunity from tribler.core.components.bandwidth_accounting.db.transaction import BandwidthTransactionData +if TYPE_CHECKING: + from tribler.core.components.bandwidth_accounting.community.bandwidth_accounting_community import \ + BandwidthAccountingCommunity + class BandwidthTransactionSignCache(RandomNumberCache): """