Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
Fixed ruff violations in content discovery folder
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink committed Apr 29, 2024
1 parent 623791e commit 27a0989
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 152 deletions.
31 changes: 27 additions & 4 deletions src/tribler/core/content_discovery/cache.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
from ipv8.requestcache import RandomNumberCache
from __future__ import annotations

from binascii import hexlify
from typing import TYPE_CHECKING, Callable

from ipv8.requestcache import RandomNumberCache, RequestCache
from typing_extensions import Self

if TYPE_CHECKING:
from ipv8.types import Peer

from tribler.core.database.store import ProcessingResult


class SelectRequest(RandomNumberCache):
def __init__(self, request_cache, prefix, request_kwargs, peer, processing_callback=None, timeout_callback=None):
super().__init__(request_cache, prefix)
"""
Keep track of the packets to a Peer during the answering of a select request.
"""

def __init__(self, request_cache: RequestCache, request_kwargs: dict, peer: Peer,
processing_callback: Callable[[Self, list[ProcessingResult]], None] | None = None,
timeout_callback: Callable[[Self], None] | None = None) -> None:
"""
Create a new select request cache.
"""
super().__init__(request_cache, hexlify(peer.mid).decode())
self.request_kwargs = request_kwargs
# The callback to call on results of processing of the response payload
self.processing_callback = processing_callback
Expand All @@ -17,6 +37,9 @@ def __init__(self, request_cache, prefix, request_kwargs, peer, processing_callb

self.timeout_callback = timeout_callback

def on_timeout(self):
def on_timeout(self) -> None:
"""
Call the timeout callback, if one is registered.
"""
if self.timeout_callback is not None:
self.timeout_callback(self)
Loading

0 comments on commit 27a0989

Please sign in to comment.