diff --git a/src/Config.py b/src/Config.py index 5ae77188..7fbafb8a 100644 --- a/src/Config.py +++ b/src/Config.py @@ -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() diff --git a/src/File/FileRequest.py b/src/File/FileRequest.py index 8f1c79b4..216cbe86 100644 --- a/src/File/FileRequest.py +++ b/src/File/FileRequest.py @@ -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 diff --git a/src/Test/TestSiteDownload.py b/src/Test/TestSiteDownload.py index 70d5bfec..85ad9d7d 100644 --- a/src/Test/TestSiteDownload.py +++ b/src/Test/TestSiteDownload.py @@ -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() diff --git a/src/Worker/WorkerManager.py b/src/Worker/WorkerManager.py index 41ff5b53..36efb3e6 100644 --- a/src/Worker/WorkerManager.py +++ b/src/Worker/WorkerManager.py @@ -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