Skip to content

Commit

Permalink
Rev936, Fix Bootstrapper test without tormanager, Bootstrapper return…
Browse files Browse the repository at this point in the history
… latest announced peers, Only create 3 threads for passive peers
  • Loading branch information
shortcutme committed Mar 4, 2016
1 parent 6cbb6ad commit 0800549
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugins/AnnounceZero/AnnounceZeroPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def announceTracker(self, tracker_protocol, tracker_address, fileserver_port=0,
s = time.time()

need_types = ["ip4"]
if self.connection_server and self.connection_server.tor_manager.enabled:
if self.connection_server and self.connection_server.tor_manager and self.connection_server.tor_manager.enabled:
need_types.append("onion")

if mode == "start" or mode == "more": # Single: Announce only this site
Expand Down
1 change: 1 addition & 0 deletions plugins/disabled-Bootstrapper/BootstrapperDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def peerList(self, hash, ip4=None, onions=[], port=None, limit=30, need_types=["
FROM peer_to_hash
LEFT JOIN peer USING (peer_id)
WHERE %s
ORDER BY date_announced DESC
LIMIT :limit
""" % where
res = self.execute(query, {"hashid": hashid, "ip4": ip4, "onions": onions, "port": port, "limit": limit})
Expand Down
2 changes: 1 addition & 1 deletion src/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Config(object):

def __init__(self, argv):
self.version = "0.3.6"
self.rev = 932
self.rev = 936
self.argv = argv
self.action = None
self.config_file = "zeronet.conf"
Expand Down
2 changes: 1 addition & 1 deletion src/Site/Site.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def publish(self, limit="default", inner_path="content.json"):
inner_path, len(published), len(passive_peers)
))

for peer in passive_peers:
for peer in passive_peers[0:3]:
gevent.spawn(self.publisher, inner_path, passive_peers, published, limit=limit+3)

# Send my hashfield to every connected peer if changed
Expand Down
2 changes: 1 addition & 1 deletion src/Site/SiteStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,4 @@ def deleteFiles(self):
return False # Some files not deleted
else:
self.log.debug("Site data directory deleted: %s..." % self.directory)
return True # All clean
return True # All clean
20 changes: 20 additions & 0 deletions src/Worker/WorkerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,29 @@ def startFindOptional(self):
found_peers = set([peer for hash_id_peers in found.values() for peer in hash_id_peers])
self.startWorkers(found_peers)

if len(found) < len(optional_hash_ids):
self.log.debug("No findHash result, try random peers: %s" % (optional_hash_ids - set(found)))
# Try to query random peers
threads = []
peers = self.site.getConnectablePeers()

for peer in peers[0:5]:
threads.append(gevent.spawn(peer.findHashIds, list(optional_hash_ids)))

gevent.joinall(threads, timeout=15)

found_ips = helper.mergeDicts([thread.value for thread in threads if thread.value])
found = self.addOptionalPeers(found_ips)
self.log.debug("Found optional files after findhash random peers: %s/%s" % (len(found), len(optional_hash_ids)))

if found:
found_peers = set([peer for hash_id_peers in found.values() for peer in hash_id_peers])
self.startWorkers(found_peers)

if len(found) < len(optional_hash_ids):
self.log.debug("No findhash result for optional files: %s" % (optional_hash_ids - set(found)))


# Stop all worker
def stopWorkers(self):
for worker in self.workers.values():
Expand Down

0 comments on commit 0800549

Please sign in to comment.