Rev542, Add files to hashfield on sign, Send my hashfield to connected peers on publish, Wait more time to checkModifications arrive, Test added files hashfield on sign
This commit is contained in:
parent
8e710beab1
commit
3764f98673
4 changed files with 18 additions and 4 deletions
|
@ -8,7 +8,7 @@ class Config(object):
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
self.version = "0.3.2"
|
self.version = "0.3.2"
|
||||||
self.rev = 536
|
self.rev = 542
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.createParser()
|
self.createParser()
|
||||||
|
|
|
@ -287,6 +287,7 @@ class ContentManager(object):
|
||||||
if optional:
|
if optional:
|
||||||
self.log.info("- [OPTIONAL] %s (SHA512: %s)" % (file_relative_path, sha512sum))
|
self.log.info("- [OPTIONAL] %s (SHA512: %s)" % (file_relative_path, sha512sum))
|
||||||
files_optional_node[file_relative_path] = {"sha512": sha512sum, "size": os.path.getsize(file_path)}
|
files_optional_node[file_relative_path] = {"sha512": sha512sum, "size": os.path.getsize(file_path)}
|
||||||
|
self.hashfield.appendHash(sha512sum)
|
||||||
else:
|
else:
|
||||||
self.log.info("- %s (SHA512: %s)" % (file_relative_path, sha512sum))
|
self.log.info("- %s (SHA512: %s)" % (file_relative_path, sha512sum))
|
||||||
files_node[file_relative_path] = {"sha512": sha512sum, "size": os.path.getsize(file_path)}
|
files_node[file_relative_path] = {"sha512": sha512sum, "size": os.path.getsize(file_path)}
|
||||||
|
|
|
@ -234,6 +234,10 @@ class Site:
|
||||||
updaters.append(gevent.spawn(self.updater, peers_try, queried, since))
|
updaters.append(gevent.spawn(self.updater, peers_try, queried, since))
|
||||||
|
|
||||||
gevent.joinall(updaters, timeout=10) # Wait 10 sec to workers done query modifications
|
gevent.joinall(updaters, timeout=10) # Wait 10 sec to workers done query modifications
|
||||||
|
if not queried:
|
||||||
|
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
|
||||||
|
@ -360,6 +364,9 @@ class Site:
|
||||||
for peer in passive_peers:
|
for peer in passive_peers:
|
||||||
gevent.spawn(self.publisher, inner_path, passive_peers, published, limit=10)
|
gevent.spawn(self.publisher, inner_path, passive_peers, published, limit=10)
|
||||||
|
|
||||||
|
# Send my hashfield to every connected peer if changed
|
||||||
|
gevent.spawn(self.sendMyHashfield, 100)
|
||||||
|
|
||||||
return len(published)
|
return len(published)
|
||||||
|
|
||||||
# Copy this site
|
# Copy this site
|
||||||
|
@ -744,8 +751,10 @@ class Site:
|
||||||
if peer.sendMyHashfield():
|
if peer.sendMyHashfield():
|
||||||
num_sent += 1
|
num_sent += 1
|
||||||
if num_sent >= num_send:
|
if num_sent >= num_send:
|
||||||
return True
|
break
|
||||||
return False
|
if num_sent:
|
||||||
|
self.log.debug("Sent my hashfield to %s peers" % num_sent)
|
||||||
|
return num_sent
|
||||||
|
|
||||||
# - Events -
|
# - Events -
|
||||||
|
|
||||||
|
|
|
@ -102,14 +102,18 @@ class TestContent:
|
||||||
)
|
)
|
||||||
|
|
||||||
def testSignOptionalFiles(self, site):
|
def testSignOptionalFiles(self, site):
|
||||||
|
assert len(site.content_manager.hashfield) == 0
|
||||||
|
|
||||||
site.content_manager.contents["content.json"]["optional"] = "((data/img/zero.*))"
|
site.content_manager.contents["content.json"]["optional"] = "((data/img/zero.*))"
|
||||||
content_optional = site.content_manager.sign(privatekey="5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv", filewrite=False)
|
content_optional = site.content_manager.sign(privatekey="5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv", filewrite=False)
|
||||||
|
|
||||||
|
|
||||||
del site.content_manager.contents["content.json"]["optional"]
|
del site.content_manager.contents["content.json"]["optional"]
|
||||||
content_nooptional = site.content_manager.sign(privatekey="5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv", filewrite=False)
|
content_nooptional = site.content_manager.sign(privatekey="5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv", filewrite=False)
|
||||||
|
|
||||||
assert len(content_nooptional.get("files_optional", {})) == 0
|
assert len(content_nooptional.get("files_optional", {})) == 0 # No optional files if no pattern
|
||||||
assert len(content_optional["files_optional"]) > 0
|
assert len(content_optional["files_optional"]) > 0
|
||||||
|
assert len(site.content_manager.hashfield) == len(content_optional["files_optional"]) # Hashed optional files should be added to hashfield
|
||||||
assert len(content_nooptional["files"]) > len(content_optional["files"])
|
assert len(content_nooptional["files"]) > len(content_optional["files"])
|
||||||
|
|
||||||
def testFileInfo(self, site):
|
def testFileInfo(self, site):
|
||||||
|
|
Loading…
Reference in a new issue