From a3f666fabc64538287ee56761d9780350452a791 Mon Sep 17 00:00:00 2001 From: Coda Date: Thu, 7 Oct 2021 21:02:12 -0700 Subject: [PATCH] client: allow announce custom port --- pybtracker/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pybtracker/client.py b/pybtracker/client.py index ecc8599..1f28843 100644 --- a/pybtracker/client.py +++ b/pybtracker/client.py @@ -107,7 +107,7 @@ async def connect(self): self.logger.info('No reply received.') async def announce(self, infohash, num_want, downloaded, left, uploaded, - event=0, ip=0): + event=0, ip=0, port=0): if not self.client.interval or not self.client.connid or \ datetime.now() > self.client.connid_timestamp + \ timedelta(seconds=self.client.connid_valid_period): @@ -121,7 +121,7 @@ async def announce(self, infohash, num_want, downloaded, left, uploaded, self.logger.info('Sending announce message.') action = 1 tid = self.get_tid() - port = self.transport._sock.getsockname()[1] + port = port or self.transport._sock.getsockname()[1] key = random.randint(0, 0xffffffff) ip = int.from_bytes(ip_address(ip).packed, byteorder='big') msg = struct.pack('!QII20s20sQQQIIIIH', self.client.connid, action, tid,