From 6763d6e74c631777d72f1ff75d85eb303d52114a Mon Sep 17 00:00:00 2001
From: HelloZeroNet <hello@noloop.me>
Date: Thu, 12 Nov 2015 23:01:35 +0100
Subject: [PATCH] Rev582, Fix my ip sending on findHashIds, Only start workers
 for optional files if peers found

---
 src/Config.py                                          |  2 +-
 src/File/FileRequest.py                                |  6 +++++-
 .../1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/content.json     | 10 +++++-----
 .../1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json    |  4 ++--
 .../1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json    |  4 ++--
 .../data/users/content.json                            |  4 ++--
 src/Worker/WorkerManager.py                            |  6 ++++--
 7 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/Config.py b/src/Config.py
index 7cd71225..043a003c 100644
--- a/src/Config.py
+++ b/src/Config.py
@@ -8,7 +8,7 @@ class Config(object):
 
     def __init__(self, argv):
         self.version = "0.3.3"
-        self.rev = 580
+        self.rev = 582
         self.argv = argv
         self.action = None
         self.createParser()
diff --git a/src/File/FileRequest.py b/src/File/FileRequest.py
index 39f0f793..41626ef5 100644
--- a/src/File/FileRequest.py
+++ b/src/File/FileRequest.py
@@ -293,11 +293,15 @@ class FileRequest(object):
         for hash_id, peers in found.iteritems():
             back[hash_id] = [helper.packAddress(peer.ip, peer.port) for peer in peers]
         # Check my hashfield
+        if config.ip_external:
+            my_ip = config.ip_external
+        else:
+            my_ip = self.server.ip
         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
+                back[hash_id].append(helper.packAddress(my_ip, self.server.port))  # Add myself
         self.log.debug(
             "Found: %s/%s" %
             (len(back), len(params["hash_ids"]))
diff --git a/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/content.json b/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/content.json
index 9c3e5cee..9b3dbab8 100644
--- a/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/content.json
+++ b/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/content.json
@@ -120,17 +120,17 @@
    "signers_required": 1
   }
  }, 
- "modified": 1445621835.637, 
+ "modified": 1447360051.327, 
  "optional": "(data/img/zero.*|data/optional.txt)", 
  "sign": [
-  47850243869989268528712520567298442290019403318054234291033274718437879648427, 
-  27185986573270415412620789926197549872389185391900755638388274126359800685380
+  56704502697521630823845805057259088854630715424341172278564490141452525844500, 
+  111213707061262926968239474633357178510296590563162180659113023094835495771512
  ], 
  "signers_sign": "HDNmWJHM2diYln4pkdL+qYOvgE7MdwayzeG+xEUZBgp1HtOjBJS+knDEVQsBkjcOPicDG2it1r6R1eQrmogqSP0=", 
  "signs": {
-  "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": "G84Wz60kiTpSJJYR9CFyIVHEQVzVB7bCXk+G+v6w2Mkv3a/2R+XNkV26qn7Tj4DHYGs5Xxi7jeXgPHTXzAhsQ+s="
+  "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": "G9Q5OVyYWlrvBX/s3AQTwchJr2ZefBwQdQEWyhkBJKsMDLZS6nt7o3hBsxm26FpKaBmpOfGpg2O1MQv6U0nUkiI="
  }, 
  "signs_required": 1, 
  "title": "ZeroBlog", 
- "zeronet_version": "0.3.2"
+ "zeronet_version": "0.3.3"
 }
\ No newline at end of file
diff --git a/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json b/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json
index dcdbc18f..cb343bb2 100644
--- a/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json
+++ b/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json
@@ -14,9 +14,9 @@
    "size": 1606
   }
  }, 
- "modified": 1445621840.488, 
+ "modified": 1447360055.489, 
  "optional": ".*\\.(jpg|png|gif)", 
  "signs": {
-  "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": "G/I/c+fbVkmv79Bcok+QZU9E5P4ruG5mxrfQqbc+KmUcf6kYKWM5L/dZERMRGl3dUiTe4ueHnSbgG8HsTz9UmHI="
+  "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": "HKdnxBP3KnBM57lsCFtqV2C2k60zWzD9hNVfvbY7uytzvGiFhFaV6VP4qcvhCWTBUnbuVzk3xPNFOctSdUCcoPk="
  }
 }
\ No newline at end of file
diff --git a/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json b/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json
index 1b12adf4..f14b89c3 100644
--- a/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json
+++ b/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json
@@ -8,8 +8,8 @@
    "size": 168
   }
  }, 
- "modified": 1445621840.892, 
+ "modified": 1447360055.88, 
  "signs": {
-  "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": "HDPcGHXKRufZx3eo1u0mH0xzaF+Uf05dNApdT2l+7GhZHXUqGv0VMShyeGGpiGOO9U55wEgPQNSoh9YY/S0WXI8="
+  "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": "G6HTP9PzwOM2Wee+FpXWBEHtj0MM+7qdBYvioW94ehZBjp8hUI1hQE4JGWSGm9ra+LIg5Cf6jPxLa8onQscn5z0="
  }
 }
\ No newline at end of file
diff --git a/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/content.json b/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/content.json
index ea4deb0c..d3531e04 100644
--- a/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/content.json
+++ b/src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT/data/users/content.json
@@ -1,9 +1,9 @@
 {
  "files": {}, 
  "ignore": ".*", 
- "modified": 1445621836.165, 
+ "modified": 1447360051.802, 
  "signs": {
-  "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": "G1CD1I6FDKfI5iCtu3s5gNQZJYuy60a5fCa/iFTEiyjF2LFLo3dhndpodVksrdgE0NVRfEmVa9sKYQf5MjPtFPM="
+  "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": "G9Io0btASe4xDPfiCMpP8TwNZ/35BTNlCQqIRpMtXtQjnNEEEJ5H4eFdDma+GMcnzT9SSxmQ07sG8fQL61r2H/o="
  }, 
  "user_contents": {
   "cert_signers": {
diff --git a/src/Worker/WorkerManager.py b/src/Worker/WorkerManager.py
index 87ff5743..379ac069 100644
--- a/src/Worker/WorkerManager.py
+++ b/src/Worker/WorkerManager.py
@@ -341,8 +341,10 @@ class WorkerManager:
 
             if optional_hash_id:
                 self.startFindOptional()
-
-            self.startWorkers(peers)
+                if peers:
+                    self.startWorkers(peers)
+            else:
+                self.startWorkers(peers)
             return evt
 
     # Find a task using inner_path