From f2fac6948ee522edb2ebc42e56c16bcfced7bcd8 Mon Sep 17 00:00:00 2001 From: Fred Stober Date: Sat, 28 May 2016 20:38:31 +0200 Subject: [PATCH] Fixed error reporting in tracker tests --- README.md | 2 +- tracker.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6a7b20c..bd3996f 100644 --- a/README.md +++ b/README.md @@ -87,5 +87,5 @@ either 'started', 'stopped', 'completed' or 'empty' (for regular queries). uploaded = 0, downloaded = 0, left = 0, event = 'started') - udp_get_peers(tracker_url, info_hash, peer_id, ip = '0.0.0.0', port = 0, uploaded = 0, downloaded = 0, left = 0, event = 'started', num_want = -1, key = 0) - With num_want it is possible to tell the tracker who many peers should be sent. The parameter key + With num_want it is possible to tell the tracker how many peers should be sent. The parameter key should be a unique key that is randomized by the client. diff --git a/tracker.py b/tracker.py index 74afb65..fabb1c3 100644 --- a/tracker.py +++ b/tracker.py @@ -129,8 +129,14 @@ def http_get_peers(tracker_url, info_hash, peer_id, ip = '0.0.0.0', port = 0, return list(decode_connections(decoded[b'peers'])) if __name__ == '__main__': - import os, binascii + import os, binascii, logging peer_id = os.urandom(20) info_hash = binascii.unhexlify('ae3fa25614b753118931373f8feae64f3c75f5cd') # Ubuntu 15.10 info hash - print(http_get_peers('http://torrent.ubuntu.com:6969/announce', info_hash, peer_id)) - print(udp_get_peers('udp://tracker.openbittorrent.com:80', info_hash, peer_id)) + try: + print(http_get_peers('http://torrent.ubuntu.com:6969/announce', info_hash, peer_id)) + except Exception: + logging.exception('Exception during http query') + try: + print(udp_get_peers('udp://tracker.coppersurfer.tk:6969', info_hash, peer_id)) + except Exception: + logging.exception('Exception during udp query')