return whole announcement so the caller knows the interval

This commit is contained in:
Victor Shyba 2022-03-05 03:08:43 -03:00
parent dc6f8c4fc4
commit 3989eef84b
2 changed files with 6 additions and 10 deletions

View file

@ -120,11 +120,7 @@ async def get_peer_list(info_hash, node_id, port, tracker_ip, tracker_port, stop
transport, _ = await asyncio.get_running_loop().create_datagram_endpoint(lambda: proto, local_addr=("0.0.0.0", 0))
try:
reply, _ = await proto.announce(info_hash, node_id, port, tracker_ip, tracker_port, stopped=stopped)
return reply.peers
except asyncio.CancelledError:
raise
except Exception as exc:
log.warning("Error fetching from tracker: %s", exc.args)
return []
return reply
finally:
transport.close()
if not transport.is_closing():
transport.close()

View file

@ -60,10 +60,10 @@ class UDPTrackerClientTestCase(AsyncioTestCase):
async def test_announce_using_helper_function(self):
info_hash = random.getrandbits(160).to_bytes(20, "big", signed=False)
peers = await get_peer_list(info_hash, None, 4444, "127.0.0.1", 59900)
announcemenet = await get_peer_list(info_hash, None, 4444, "127.0.0.1", 59900)
peers = announcemenet.peers
self.assertEqual(peers, [CompactIPv4Peer(int.from_bytes(bytes([127, 0, 0, 1]), "big", signed=False), 4444)])
peers = await get_peer_list(info_hash, None, 4444, "127.0.0.1", 59900, stopped=True)
self.assertEqual(peers, [])
self.assertEqual((await get_peer_list(info_hash, None, 4444, "127.0.0.1", 59900, stopped=True)).peers, [])
async def test_error(self):
info_hash = random.getrandbits(160).to_bytes(20, "big", signed=False)