Version 0.3.3, Rev580, DB recreate bugfix, Get empty hashfields, Better stat formatting, Query hashfield right after content.json downloaded
This commit is contained in:
parent
199e0e70b2
commit
ae98522855
7 changed files with 45 additions and 15 deletions
|
@ -143,8 +143,8 @@ class UiRequestPlugin(object):
|
|||
connection_id = peer.connection.id
|
||||
else:
|
||||
connection_id = None
|
||||
yield "Optional files: %s " % len(peer.hashfield)
|
||||
yield "(#%s, err: %s, found: %s min ago) %22s -<br>" % (connection_id, peer.connection_error, time_found, key)
|
||||
yield "Optional files: %4s " % len(peer.hashfield)
|
||||
yield "(#%4s, err: %s, found: %5s min ago) %22s -<br>" % (connection_id, peer.connection_error, time_found, key)
|
||||
yield "<br></td></tr>"
|
||||
yield "</table>"
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import ConfigParser
|
|||
class Config(object):
|
||||
|
||||
def __init__(self, argv):
|
||||
self.version = "0.3.2"
|
||||
self.rev = 571
|
||||
self.version = "0.3.3"
|
||||
self.rev = 580
|
||||
self.argv = argv
|
||||
self.action = None
|
||||
self.createParser()
|
||||
|
|
|
@ -159,6 +159,8 @@ class Db:
|
|||
|
||||
cur.execute("COMMIT")
|
||||
self.log.debug("Db check done in %.3fs, changed tables: %s" % (time.time() - s, changed_tables))
|
||||
if changed_tables:
|
||||
self.db_keyvalues = {} # Refresh table version cache
|
||||
|
||||
return changed_tables
|
||||
|
||||
|
|
|
@ -198,6 +198,7 @@ class FileServer(ConnectionServer):
|
|||
|
||||
if first_announce: # Send my optional files to peers
|
||||
site.sendMyHashfield()
|
||||
site.updateHashfield()
|
||||
|
||||
time.sleep(2) # Prevent too quick request
|
||||
|
||||
|
@ -211,7 +212,8 @@ class FileServer(ConnectionServer):
|
|||
config.loadTrackersFile()
|
||||
for address, site in self.sites.items():
|
||||
site.announce(num=1, pex=False)
|
||||
site.sendMyHashfield(num_send=1)
|
||||
site.sendMyHashfield(3)
|
||||
site.updateHashfield(1)
|
||||
time.sleep(2)
|
||||
|
||||
first_announce = False
|
||||
|
|
|
@ -131,6 +131,9 @@ class Site:
|
|||
file_threads.append(res) # Append evt
|
||||
|
||||
# Optionals files
|
||||
if inner_path == "content.json":
|
||||
gevent.spawn(self.updateHashfield)
|
||||
|
||||
if self.settings.get("autodownloadoptional"):
|
||||
for file_relative_path in self.content_manager.contents[inner_path].get("files_optional", {}).keys():
|
||||
file_inner_path = content_inner_dir + file_relative_path
|
||||
|
@ -225,7 +228,8 @@ class Site:
|
|||
for wait in range(10):
|
||||
time.sleep(5 + wait)
|
||||
self.log.debug("Waiting for peers...")
|
||||
if self.peers: break
|
||||
if self.peers:
|
||||
break
|
||||
|
||||
peers = self.peers.values()
|
||||
random.shuffle(peers)
|
||||
|
@ -247,7 +251,6 @@ class Site:
|
|||
if not queried:
|
||||
gevent.joinall(updaters, timeout=10) # Wait another 10 sec if none of updaters finished
|
||||
|
||||
|
||||
time.sleep(0.1)
|
||||
self.log.debug("Queried listModifications from: %s" % queried)
|
||||
return queried
|
||||
|
@ -751,19 +754,39 @@ class Site:
|
|||
self.log.debug("Cleanup peers result: Removed %s, left: %s" % (removed, len(self.peers)))
|
||||
|
||||
# Send hashfield to peers
|
||||
def sendMyHashfield(self, num_send=3):
|
||||
def sendMyHashfield(self, limit=3):
|
||||
if not self.content_manager.hashfield: # No optional files
|
||||
return False
|
||||
num_sent = 0
|
||||
|
||||
sent = 0
|
||||
connected_peers = self.getConnectedPeers()
|
||||
for peer in connected_peers:
|
||||
if peer.sendMyHashfield():
|
||||
num_sent += 1
|
||||
if num_sent >= num_send:
|
||||
sent += 1
|
||||
if sent >= limit:
|
||||
break
|
||||
if num_sent:
|
||||
self.log.debug("Sent my hashfield to %s peers" % num_sent)
|
||||
return num_sent
|
||||
if sent:
|
||||
self.log.debug("Sent my hashfield to %s peers" % sent)
|
||||
return sent
|
||||
|
||||
# Update hashfield
|
||||
def updateHashfield(self, limit=3):
|
||||
# Return if no optional files
|
||||
if not self.content_manager.hashfield and not self.content_manager.contents.get("content.json", {}).get("files_optional", {}):
|
||||
return False
|
||||
|
||||
queried = 0
|
||||
connected_peers = self.getConnectedPeers()
|
||||
for peer in connected_peers:
|
||||
if peer.time_hashfield:
|
||||
continue
|
||||
if peer.updateHashfield():
|
||||
queried += 1
|
||||
if queried >= limit:
|
||||
break
|
||||
if queried:
|
||||
self.log.debug("Queried hashfield from %s peers" % queried)
|
||||
return queried
|
||||
|
||||
# - Events -
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ class SiteManager(object):
|
|||
|
||||
# Lazy load sites
|
||||
def list(self):
|
||||
logging.debug("Loading sites...")
|
||||
if self.sites is None: # Not loaded yet
|
||||
self.load()
|
||||
return self.sites
|
||||
|
|
|
@ -244,6 +244,7 @@ class WorkerManager:
|
|||
gevent.joinall(threads, timeout=5)
|
||||
|
||||
found = self.findOptionalTasks(optional_tasks)
|
||||
self.log.debug("Found optional files after query hashtable connected peers: %s/%s" % (len(found), len(optional_hash_ids)))
|
||||
|
||||
if found:
|
||||
found_peers = set([peer for hash_id_peers in found.values() for peer in hash_id_peers])
|
||||
|
@ -265,6 +266,7 @@ class WorkerManager:
|
|||
|
||||
found_ips = helper.mergeDicts([thread.value for thread in threads if thread.value])
|
||||
found = self.addOptionalPeers(found_ips)
|
||||
self.log.debug("Found optional files after findhash connected peers: %s/%s" % (len(found), len(optional_hash_ids)))
|
||||
|
||||
if found:
|
||||
found_peers = set([peer for hash_id_peers in found.values() for peer in hash_id_peers])
|
||||
|
|
Loading…
Reference in a new issue