Rev505, FindHashIds also checks in self hashfield, Fix optional file bug when task already finished, Reset peer last hashfield download time when found hashid using findHashIds

This commit is contained in:
HelloZeroNet 2015-10-28 01:28:29 +01:00
parent 5f0266ed8f
commit 9c5fda6ed2
4 changed files with 26 additions and 4 deletions

View File

@ -8,7 +8,7 @@ class Config(object):
def __init__(self, argv):
self.version = "0.3.2"
self.rev = 494
self.rev = 505
self.argv = argv
self.action = None
self.createParser()

View File

@ -281,9 +281,20 @@ class FileRequest(object):
return False
found = site.worker_manager.findOptionalHashIds(params["hash_ids"])
back = {}
for hash_id, peers in found.iteritems():
back[hash_id] = [helper.packAddress(peer.ip, peer.port) for peer in peers]
# Check my hashfield
for hash_id in params["hash_ids"]:
if hash_id in site.content_manager.hashfield:
if hash_id not in back:
back[hash_id] = []
back[hash_id].append(helper.packAddress(config.ip_external, config.fileserver_port)) # Add myself
self.log.debug(
"Found: %s/%s" %
(len(back), len(params["hash_ids"]))
)
self.response({"peers": back})
# Send a simple Pong! answer

View File

@ -137,8 +137,16 @@ class TestSiteDownload:
assert site_full.content_manager.hashfield.hasHash(optional_file_info["sha512"]) # Source full server he has the file
with Spy.Spy(FileRequest, "route") as requests:
site_temp.needFile("data/optional.txt")
print requests
# Request 2 file same time
threads = []
threads.append(site_temp.needFile("data/optional.txt", blocking=False))
threads.append(site_temp.needFile("data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/peanut-butter-jelly-time.gif", blocking=False))
gevent.joinall(threads)
assert len([request for request in requests if request[0] == "findHashIds"]) == 1 # findHashids should call only once
assert site_temp.storage.isFile("data/optional.txt")
assert site_temp.storage.isFile("data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/peanut-butter-jelly-time.gif")
assert site_temp.storage.deleteFiles()
file_server_full.stop()

View File

@ -186,6 +186,8 @@ class WorkerManager:
task = [task for task in self.tasks if task["optional_hash_id"] == hash_id]
if task: # Found task, lets take the first
task = task[0]
else:
continue
for peer_ip in peer_ips:
peer = self.site.addPeer(peer_ip[0], peer_ip[1], return_peer=True)
if not peer:
@ -194,7 +196,8 @@ class WorkerManager:
task["peers"] = []
if peer not in task["peers"]:
task["peers"].append(peer)
peer.hashfield.appendHashId(hash_id) # Peer has this file
if peer.hashfield.appendHashId(hash_id): # Peer has this file
peer.time_hashfield = None # Peer hashfield probably outdated
found[hash_id].append(peer)
return found