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:
HelloZeroNet 2015-11-12 02:04:45 +01:00
parent 199e0e70b2
commit ae98522855
7 changed files with 45 additions and 15 deletions

View file

@ -143,8 +143,8 @@ class UiRequestPlugin(object):
connection_id = peer.connection.id connection_id = peer.connection.id
else: else:
connection_id = None connection_id = None
yield "Optional files: %s " % len(peer.hashfield) yield "Optional files: %4s " % len(peer.hashfield)
yield "(#%s, err: %s, found: %s min ago) %22s -<br>" % (connection_id, peer.connection_error, time_found, key) yield "(#%4s, err: %s, found: %5s min ago) %22s -<br>" % (connection_id, peer.connection_error, time_found, key)
yield "<br></td></tr>" yield "<br></td></tr>"
yield "</table>" yield "</table>"

View file

@ -7,8 +7,8 @@ import ConfigParser
class Config(object): class Config(object):
def __init__(self, argv): def __init__(self, argv):
self.version = "0.3.2" self.version = "0.3.3"
self.rev = 571 self.rev = 580
self.argv = argv self.argv = argv
self.action = None self.action = None
self.createParser() self.createParser()

View file

@ -159,6 +159,8 @@ class Db:
cur.execute("COMMIT") cur.execute("COMMIT")
self.log.debug("Db check done in %.3fs, changed tables: %s" % (time.time() - s, changed_tables)) 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 return changed_tables

View file

@ -198,6 +198,7 @@ class FileServer(ConnectionServer):
if first_announce: # Send my optional files to peers if first_announce: # Send my optional files to peers
site.sendMyHashfield() site.sendMyHashfield()
site.updateHashfield()
time.sleep(2) # Prevent too quick request time.sleep(2) # Prevent too quick request
@ -211,7 +212,8 @@ class FileServer(ConnectionServer):
config.loadTrackersFile() config.loadTrackersFile()
for address, site in self.sites.items(): for address, site in self.sites.items():
site.announce(num=1, pex=False) site.announce(num=1, pex=False)
site.sendMyHashfield(num_send=1) site.sendMyHashfield(3)
site.updateHashfield(1)
time.sleep(2) time.sleep(2)
first_announce = False first_announce = False

View file

@ -131,6 +131,9 @@ class Site:
file_threads.append(res) # Append evt file_threads.append(res) # Append evt
# Optionals files # Optionals files
if inner_path == "content.json":
gevent.spawn(self.updateHashfield)
if self.settings.get("autodownloadoptional"): if self.settings.get("autodownloadoptional"):
for file_relative_path in self.content_manager.contents[inner_path].get("files_optional", {}).keys(): for file_relative_path in self.content_manager.contents[inner_path].get("files_optional", {}).keys():
file_inner_path = content_inner_dir + file_relative_path file_inner_path = content_inner_dir + file_relative_path
@ -225,7 +228,8 @@ class Site:
for wait in range(10): for wait in range(10):
time.sleep(5 + wait) time.sleep(5 + wait)
self.log.debug("Waiting for peers...") self.log.debug("Waiting for peers...")
if self.peers: break if self.peers:
break
peers = self.peers.values() peers = self.peers.values()
random.shuffle(peers) random.shuffle(peers)
@ -247,7 +251,6 @@ class Site:
if not queried: if not queried:
gevent.joinall(updaters, timeout=10) # Wait another 10 sec if none of updaters finished gevent.joinall(updaters, timeout=10) # Wait another 10 sec if none of updaters finished
time.sleep(0.1) time.sleep(0.1)
self.log.debug("Queried listModifications from: %s" % queried) self.log.debug("Queried listModifications from: %s" % queried)
return queried return queried
@ -751,19 +754,39 @@ class Site:
self.log.debug("Cleanup peers result: Removed %s, left: %s" % (removed, len(self.peers))) self.log.debug("Cleanup peers result: Removed %s, left: %s" % (removed, len(self.peers)))
# Send hashfield to 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 if not self.content_manager.hashfield: # No optional files
return False return False
num_sent = 0
sent = 0
connected_peers = self.getConnectedPeers() connected_peers = self.getConnectedPeers()
for peer in connected_peers: for peer in connected_peers:
if peer.sendMyHashfield(): if peer.sendMyHashfield():
num_sent += 1 sent += 1
if num_sent >= num_send: if sent >= limit:
break break
if num_sent: if sent:
self.log.debug("Sent my hashfield to %s peers" % num_sent) self.log.debug("Sent my hashfield to %s peers" % sent)
return num_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 - # - Events -

View file

@ -77,6 +77,7 @@ class SiteManager(object):
# Lazy load sites # Lazy load sites
def list(self): def list(self):
logging.debug("Loading sites...")
if self.sites is None: # Not loaded yet if self.sites is None: # Not loaded yet
self.load() self.load()
return self.sites return self.sites

View file

@ -244,6 +244,7 @@ class WorkerManager:
gevent.joinall(threads, timeout=5) gevent.joinall(threads, timeout=5)
found = self.findOptionalTasks(optional_tasks) 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: if found:
found_peers = set([peer for hash_id_peers in found.values() for peer in hash_id_peers]) 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_ips = helper.mergeDicts([thread.value for thread in threads if thread.value])
found = self.addOptionalPeers(found_ips) 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: if found:
found_peers = set([peer for hash_id_peers in found.values() for peer in hash_id_peers]) found_peers = set([peer for hash_id_peers in found.values() for peer in hash_id_peers])