arvidn / libtorrent

an efficient feature complete C++ bittorrent implementation
http://libtorrent.org
Other
5.23k stars 992 forks source link

Empty tracker error message #1584

Closed cas-- closed 4 years ago

cas-- commented 7 years ago

So I was seeing the empty tracker messages again after changing some of the alert handling code. I know that you said for -1 status_code then the error message would be left empty as there was no additional message from the tracker. I now understand the issue and these particular errors are actually from boost.system.error_codes.

I have written an test example using a torrent that contains udp://tracker.publicbt.com:80/announce and udp://tracker.openbittorrent.com:80/announce and as you can see from the output a boost error_code message and value is received. Can these not be used to populate the lt error_message?

I still think it would be useful if status_code is -1 and there is no message (from tracker) to have something in alert.message()? e.g. 'unknown error from tracker'.

import libtorrent as lt
sess = lt.session()
sess.post_session_stats()
with open('error_code.torrent') as filedump:
    torrent_info = lt.torrent_info(lt.bdecode(filedump.read()))
sess.add_torrent({'ti':torrent_info, 'save_path':''})
while(1):
    alerts = sess.pop_alerts()
    if alerts:
        for alert in alerts:
            if alert.what() != 'tracker_error_alert':
                continue
            print '=== Start of Tracker Error Alert ==='
            for attr_name in dir(alert):
                if not attr_name.startswith('__'):
                    alert_attr = getattr(alert, attr_name)
                    if callable(alert_attr):
                        print 'alert.%s(): %s' % (attr_name, alert_attr())
                    else:
                        print 'alert.%s: %s' % (attr_name, alert_attr)
            print 'alert.error.value(): %s' % alert.error.value()
            print 'alert.error.message(): %s' % alert.error.message()
            print '=== End of Tracker Error Alert ===\n'
=== Tracker Error Alert ===
alert.category(): 17
alert.category_t(): 0
alert.error: <libtorrent.error_code object at 0x7f1075fe1b40>
alert.error_message(): 
alert.handle: <libtorrent.torrent_handle object at 0x7f1075fe1b40>
alert.message():  (udp://tracker.publicbt.com:80/announce) (-1) Host not found (authoritative) "" (0)
alert.msg: 
alert.severity(): warning
alert.severity_levels(): 0
alert.status_code: -1
alert.times_in_row: 0
alert.tracker_url(): udp://tracker.publicbt.com:80/announce
alert.url: udp://tracker.publicbt.com:80/announce
alert.what(): tracker_error_alert
alert.error.value(): 1
alert.error.message(): Host not found (authoritative)

=== Tracker Error Alert ===
alert.category(): 17
alert.category_t(): 0
alert.error: <libtorrent.error_code object at 0x7f1075fe1b40>
alert.error_message(): 
alert.handle: <libtorrent.torrent_handle object at 0x7f1075fe1b40>
alert.message():  (udp://tracker.openbittorrent.com:80/announce) (-1) timed out "" (1)
alert.msg: 
alert.severity(): warning
alert.severity_levels(): 0
alert.status_code: -1
alert.times_in_row: 1
alert.tracker_url(): udp://tracker.openbittorrent.com:80/announce
alert.url: udp://tracker.openbittorrent.com:80/announce
alert.what(): tracker_error_alert
alert.error.value(): 36
alert.error.message(): timed out

=== Tracker Error Alert ===
alert.category(): 17
alert.category_t(): 0
alert.error: <libtorrent.error_code object at 0x7f1075fe1b40>
alert.error_message(): 
alert.handle: <libtorrent.torrent_handle object at 0x7f1075fe1b40>
alert.message():  (udp://tracker.publicbt.com:80/announce) (-1) Host not found (authoritative) "" (1)
alert.msg: 
alert.severity(): warning
alert.severity_levels(): 0
alert.status_code: -1
alert.times_in_row: 1
alert.tracker_url(): udp://tracker.publicbt.com:80/announce
alert.url: udp://tracker.publicbt.com:80/announce
alert.what(): tracker_error_alert
alert.error.value(): 1
alert.error.message(): Host not found (authoritative)
aldenml commented 7 years ago

branch?

cas-- commented 7 years ago

All... but with error_message the test is for >=1.1

arvidn commented 7 years ago

error_message() (primarily) is meant to communicate the "failure_reason". Looking through the code, it appears to be used for HTTP status messages as well (on failures) and one case of an i2p error.

However, the majority of errors that have error codes, just report the error code. You suggest copying the error_code message into that field in case it's empty?

cas-- commented 7 years ago

You suggest copying the error_code message into that field in case it's empty?

Yes as that is what I had previously had to do, though there was no option to simply get just the message (without codes): https://github.com/deluge-torrent/deluge/blob/1.3-stable/deluge/core/torrentmanager.py#L1045

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.