Skip to content

Commit

Permalink
Fix #6875
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed May 13, 2022
1 parent f90fd14 commit 14e37a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
1 change: 1 addition & 0 deletions requirements-core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ yappi==1.3.3
yarl==1.7.2 # keep this dependency higher than 1.6.3. See: https://github.com/aio-libs/yarl/issues/517
Faker==9.8.2
sentry-sdk==1.5.0
bitarray==2.5.1
pyipv8==2.8.0
libtorrent==1.2.15
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from collections import defaultdict
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple

from bitarray import bitarray
from ipv8.taskmanager import TaskManager, task
from ipv8.util import int2byte, succeed
from ipv8.util import succeed

from tribler.core import notifications
from tribler.core.components.libtorrent.download_manager.download_config import DownloadConfig
Expand Down Expand Up @@ -225,14 +226,9 @@ def get_pieces_base64(self) -> bytes:
"""
Returns a base64 encoded bitmask of the pieces that we have.
"""
bitstr = b""
for bit in self.handle.status().pieces:
bitstr += b'1' if bit else b'0'

encoded_str = b""
for i in range(0, len(bitstr), 8):
encoded_str += int2byte(int(bitstr[i:i + 8].ljust(8, b'0'), 2))
return base64.b64encode(encoded_str)
binary_gen = (int(boolean) for boolean in self.handle.status().pieces)
bits = bitarray(binary_gen)
return base64.b64encode(bits.tobytes())

def post_alert(self, alert_type: str, alert_dict: Optional[Dict] = None):
alert_dict = alert_dict or {}
Expand Down

0 comments on commit 14e37a3

Please sign in to comment.