Created
November 17, 2014 03:44
-
-
Save gubatron/ce044e57b1b3f172fcc8 to your computer and use it in GitHub Desktop.
testing_dht_alert.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import libtorrent | |
| from threading import Thread | |
| import time | |
| ERROR_NOTIFICATION_ALERT_MASK = 1 | |
| PORT_MAPPING_NOTIFICATION_ALERT_MASK = 4 | |
| DEBUG_NOTIFICATION_ALERT_MASK = 32 | |
| DHT_NOTIFICATION_ALERT_MASK = 1024 | |
| def dhtAlertListener(s): | |
| while s.is_dht_running(): | |
| alert = s.pop_alert() | |
| if alert is not None: | |
| print alert | |
| else: | |
| print "waiting until next alert..." | |
| s.wait_for_alert(30000) | |
| settings = libtorrent.session_settings() | |
| settings.use_dht_as_fallback = True | |
| s = libtorrent.session() | |
| s.set_settings(settings) | |
| # by default only error alerts are posted, unless we set the proper masks | |
| s.set_alert_mask(ERROR_NOTIFICATION_ALERT_MASK | DHT_NOTIFICATION_ALERT_MASK | PORT_MAPPING_NOTIFICATION_ALERT_MASK | DEBUG_NOTIFICATION_ALERT_MASK) | |
| s.listen_on(12345,123455) | |
| s.add_dht_router("router.bittorrent.com",6881) | |
| s.add_dht_router("dht.transmissionbt.com", 6881) | |
| s.start_lsd() | |
| s.start_natpmp() | |
| s.start_upnp() | |
| s.start_dht() | |
| if s.is_dht_running(): | |
| print "DHT is running" | |
| t = Thread(target=dhtAlertListener, args=(s,)) | |
| t.start() | |
| t.join() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: