Generalize tracker logging
This commit is contained in:
parent
13e651c822
commit
64b4789bc1
2 changed files with 29 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
|||
import hashlib
|
||||
from Config import config
|
||||
import time
|
||||
|
||||
from Plugin import PluginManager
|
||||
|
@ -12,13 +12,13 @@ connection_pool = {} # Tracker address: Peer object
|
|||
|
||||
# We can only import plugin host clases after the plugins are loaded
|
||||
@PluginManager.afterLoad
|
||||
def importErrors():
|
||||
def importPeers():
|
||||
global Peer
|
||||
from Peer import Peer
|
||||
|
||||
|
||||
# Process result got back from tracker
|
||||
def processPeerRes(site, peers):
|
||||
def processPeerRes(tracker_address, site, peers):
|
||||
added = 0
|
||||
# Ip4
|
||||
found_ip4 = 0
|
||||
|
@ -38,7 +38,7 @@ def processPeerRes(site, peers):
|
|||
if added:
|
||||
site.worker_manager.onPeers()
|
||||
site.updateWebsocket(peers_added=added)
|
||||
site.log.debug("Found %s ip4, %s onion peers, new: %s" % (found_ip4, found_onion, added))
|
||||
return added
|
||||
|
||||
|
||||
@PluginManager.registerTo("Site")
|
||||
|
@ -89,16 +89,17 @@ class SitePlugin(object):
|
|||
res = tracker.request("announce", request)
|
||||
|
||||
if not res or "peers" not in res:
|
||||
self.log.debug("Announce to %s failed: %s" % (tracker_address, res))
|
||||
self.log.warning("Tracker error: zero://%s (%s)" % (tracker_address, res))
|
||||
if full_announce:
|
||||
time_full_announced[tracker_address] = 0
|
||||
return False
|
||||
|
||||
# Add peers from response to site
|
||||
site_index = 0
|
||||
peers_added = 0
|
||||
for site_res in res["peers"]:
|
||||
site = sites[site_index]
|
||||
processPeerRes(site, site_res)
|
||||
peers_added += processPeerRes(tracker_address, site, site_res)
|
||||
site_index += 1
|
||||
|
||||
# Check if we need to sign prove the onion addresses
|
||||
|
@ -115,7 +116,7 @@ class SitePlugin(object):
|
|||
request["onion_signs"][publickey] = sign
|
||||
res = tracker.request("announce", request)
|
||||
if not res or "onion_sign_this" in res:
|
||||
self.log.debug("Announce onion address to %s failed: %s" % (tracker_address, res))
|
||||
self.log.warning("Tracker error: %s (Announce onion address to failed: %s)" % (tracker_address, res))
|
||||
if full_announce:
|
||||
time_full_announced[tracker_address] = 0
|
||||
return False
|
||||
|
@ -123,4 +124,9 @@ class SitePlugin(object):
|
|||
if full_announce:
|
||||
tracker.remove() # Close connection, we don't need it in next 5 minute
|
||||
|
||||
self.log.debug(
|
||||
"Tracker result: zero://%s (sites: %s, new: %s)" %
|
||||
(tracker_address, site_index, peers_added)
|
||||
)
|
||||
|
||||
return time.time() - s
|
||||
|
|
|
@ -832,8 +832,12 @@ class Site(object):
|
|||
tracker.poll_once()
|
||||
tracker.announce(info_hash=hashlib.sha1(self.address).hexdigest(), num_want=50)
|
||||
back = tracker.poll_once()
|
||||
peers = back["response"]["peers"]
|
||||
if back:
|
||||
peers = back["response"]["peers"]
|
||||
else:
|
||||
raise Exception("No response")
|
||||
except Exception, err:
|
||||
self.log.warning("Tracker error: udp://%s:%s (%s)" % (ip, port, err))
|
||||
return False
|
||||
|
||||
elif tracker_protocol == "http": # Http tracker
|
||||
|
@ -854,7 +858,7 @@ class Site(object):
|
|||
req.close()
|
||||
req = None
|
||||
if not response:
|
||||
self.log.debug("Http tracker %s response error" % tracker_address)
|
||||
self.log.warning("Tracker error: http://%s (No response)" % tracker_address)
|
||||
return False
|
||||
# Decode peers
|
||||
peer_data = bencode.decode(response)["peers"]
|
||||
|
@ -867,7 +871,7 @@ class Site(object):
|
|||
addr, port = struct.unpack('!LH', peer)
|
||||
peers.append({"addr": socket.inet_ntoa(struct.pack('!L', addr)), "port": port})
|
||||
except Exception, err:
|
||||
self.log.debug("Http tracker %s error: %s" % (tracker_address, err))
|
||||
self.log.warning("Tracker error: http://%s (%s)" % (tracker_address, err))
|
||||
if req:
|
||||
req.close()
|
||||
req = None
|
||||
|
@ -885,7 +889,10 @@ class Site(object):
|
|||
if added:
|
||||
self.worker_manager.onPeers()
|
||||
self.updateWebsocket(peers_added=added)
|
||||
self.log.debug("%s: Found %s peers, new: %s, total: %s" % (tracker_address, len(peers), added, len(self.peers)))
|
||||
self.log.debug(
|
||||
"Tracker result: %s://%s (found %s peers, new: %s, total: %s)" %
|
||||
(tracker_protocol, tracker_address, len(peers), added, len(self.peers))
|
||||
)
|
||||
return time.time() - s
|
||||
|
||||
# Add myself and get other peers from tracker
|
||||
|
@ -955,10 +962,11 @@ class Site(object):
|
|||
announced_to = trackers[0]
|
||||
else:
|
||||
announced_to = "%s trackers" % announced
|
||||
self.log.debug(
|
||||
"Announced types %s in mode %s to %s in %.3fs, errors: %s, slow: %s" %
|
||||
(add_types, mode, announced_to, time.time() - s, errors, slow)
|
||||
)
|
||||
if config.verbose:
|
||||
self.log.debug(
|
||||
"Announced types %s in mode %s to %s in %.3fs, errors: %s, slow: %s" %
|
||||
(add_types, mode, announced_to, time.time() - s, errors, slow)
|
||||
)
|
||||
else:
|
||||
if mode != "update":
|
||||
self.log.error("Announce to %s trackers in %.3fs, failed" % (announced, time.time() - s))
|
||||
|
|
Loading…
Reference in a new issue