Skip to content

Commit

Permalink
Merge pull request #7651 from kozlovsky/fix/max_int_32
Browse files Browse the repository at this point in the history
Fix MAX_INT32 value (the previous value was actually for MAX_UINT16)
  • Loading branch information
kozlovsky committed Oct 27, 2023
2 parents cbf0056 + bbbe91f commit a4b8f20
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
TRACKER_ACTION_ANNOUNCE = 1
TRACKER_ACTION_SCRAPE = 2

MAX_INT32 = 2 ** 16 - 1
INT32_MAX = 2 ** 31 - 1

UDP_TRACKER_INIT_CONNECTION_ID = 0x41727101980

Expand Down Expand Up @@ -260,7 +260,7 @@ def generate_transaction_id(self):
"""
while True:
# make sure there is no duplicated transaction IDs
transaction_id = random.randint(0, MAX_INT32)
transaction_id = random.randint(0, INT32_MAX)
if transaction_id not in UdpTrackerSession._active_session_dict.items():
UdpTrackerSession._active_session_dict[self] = transaction_id
self.transaction_id = transaction_id
Expand Down
4 changes: 2 additions & 2 deletions src/tribler/core/tests/tools/tracker/udp_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import struct
from asyncio import DatagramProtocol, get_event_loop

from tribler.core.components.torrent_checker.torrent_checker.torrentchecker_session import MAX_INT32
from tribler.core.components.torrent_checker.torrent_checker.torrentchecker_session import INT32_MAX
from tribler.core.tests.tools.tracker.tracker_info import TrackerInfo

UDP_TRACKER_INIT_CONNECTION_ID = 0x41727101980
Expand Down Expand Up @@ -58,7 +58,7 @@ def send_connection_reply(self, host, port):
"""
Send a connection reply.
"""
self.connection_id = random.randint(0, MAX_INT32)
self.connection_id = random.randint(0, INT32_MAX)
response_msg = struct.pack('!iiq', TRACKER_ACTION_CONNECT, self.transaction_id, self.connection_id)
self.transport.sendto(response_msg, (host, port))

Expand Down

0 comments on commit a4b8f20

Please sign in to comment.