Rev966, New Greenlet debug hook to support Gevent 1.1.0, Publish to 8 peers on external publish request, Dont try to download banned user files, Check user files even if its own site
This commit is contained in:
parent
48db062b49
commit
0897154584
7 changed files with 30 additions and 30 deletions
|
@ -302,7 +302,7 @@ class UiWebsocketPlugin(object):
|
|||
|
||||
body.append("""
|
||||
<li>
|
||||
<label>Identity address <small>(used: {used:.2f}kB / {quota:.2f}kB)</small></label>
|
||||
<label>Identity address <small>(limit used: {used:.2f}kB / {quota:.2f}kB)</small></label>
|
||||
<span class='input text disabled'>{auth_address}</span>
|
||||
<a href='#Change' class='button' id='button-identity'>Change</a>
|
||||
</li>
|
||||
|
|
|
@ -8,7 +8,7 @@ class Config(object):
|
|||
|
||||
def __init__(self, argv):
|
||||
self.version = "0.3.6"
|
||||
self.rev = 966
|
||||
self.rev = 986
|
||||
self.argv = argv
|
||||
self.action = None
|
||||
self.config_file = "zeronet.conf"
|
||||
|
|
|
@ -2,6 +2,7 @@ import sys
|
|||
import logging
|
||||
|
||||
import gevent
|
||||
import gevent.hub
|
||||
|
||||
from Config import config
|
||||
|
||||
|
@ -30,20 +31,19 @@ def handleErrorNotify(*args):
|
|||
sys.__excepthook__(*args)
|
||||
|
||||
|
||||
OriginalGreenlet = gevent.Greenlet
|
||||
|
||||
|
||||
class ErrorhookedGreenlet(OriginalGreenlet):
|
||||
def _report_error(self, exc_info):
|
||||
sys.excepthook(exc_info[0], exc_info[1], exc_info[2])
|
||||
|
||||
if config.debug:
|
||||
if config.debug: # Keep last error for /Debug
|
||||
sys.excepthook = handleError
|
||||
else:
|
||||
sys.excepthook = handleErrorNotify
|
||||
|
||||
gevent.Greenlet = gevent.greenlet.Greenlet = ErrorhookedGreenlet
|
||||
reload(gevent)
|
||||
|
||||
# Override default error handler to allow silent killing / custom logging
|
||||
gevent.hub.Hub._original_handle_error = gevent.hub.Hub.handle_error
|
||||
|
||||
def handleGreenletError(self, context, type, value, tb):
|
||||
sys.excepthook(type, value, tb)
|
||||
|
||||
gevent.hub.Hub.handle_error = handleGreenletError
|
||||
|
||||
if __name__ == "__main__":
|
||||
import time
|
||||
|
@ -51,14 +51,16 @@ if __name__ == "__main__":
|
|||
monkey.patch_all(thread=False, ssl=False)
|
||||
import Debug
|
||||
|
||||
def sleeper():
|
||||
print "started"
|
||||
def sleeper(num):
|
||||
print "started", num
|
||||
time.sleep(3)
|
||||
print "stopped"
|
||||
thread1 = gevent.spawn(sleeper)
|
||||
thread2 = gevent.spawn(sleeper)
|
||||
raise Exception("Error")
|
||||
print "stopped", num
|
||||
thread1 = gevent.spawn(sleeper, 1)
|
||||
thread2 = gevent.spawn(sleeper, 2)
|
||||
time.sleep(1)
|
||||
print "killing..."
|
||||
thread1.throw(Exception("Hello"))
|
||||
thread2.throw(Debug.Notify("Throw"))
|
||||
thread1.kill(exception=Debug.Notify("Worker stopped"))
|
||||
#thread2.throw(Debug.Notify("Throw"))
|
||||
print "killed"
|
||||
gevent.joinall([thread1,thread2])
|
||||
|
|
|
@ -364,7 +364,7 @@ class FileRequest(object):
|
|||
self.response({"error": "Only local host allowed"})
|
||||
|
||||
site = self.sites.get(params["site"])
|
||||
num = site.publish(inner_path=params.get("inner_path", "content.json"))
|
||||
num = site.publish(limit=8, inner_path=params.get("inner_path", "content.json"))
|
||||
|
||||
self.response({"ok": "Successfuly published to %s peers" % num})
|
||||
|
||||
|
|
|
@ -218,6 +218,9 @@ class Site(object):
|
|||
content = self.content_manager.contents.get(inner_path)
|
||||
if (not content or modified > content["modified"]) and inner_path not in self.bad_files:
|
||||
self.log.debug("New modified file from %s: %s" % (peer, inner_path))
|
||||
if inner_path != "content.json" and self.content_manager.getRules(inner_path) == False:
|
||||
self.log.debug("Banned user %s: %s, skipping." % (peer, inner_path))
|
||||
continue
|
||||
# We dont have this file or we have older
|
||||
self.bad_files[inner_path] = self.bad_files.get(inner_path, 0) + 1 # Mark as bad file
|
||||
gevent.spawn(self.downloadContent, inner_path) # Download the content.json + the changed files
|
||||
|
@ -273,10 +276,6 @@ class Site(object):
|
|||
|
||||
queried = self.checkModifications()
|
||||
|
||||
if not queried: # Not found any client that supports listModifications
|
||||
self.log.debug("Fallback to old-style update")
|
||||
self.redownloadContents()
|
||||
|
||||
self.storage.checkFiles(quick_check=True) # Quick check and mark bad files based on file size
|
||||
|
||||
changed, deleted = self.content_manager.loadContent("content.json")
|
||||
|
@ -363,8 +362,8 @@ class Site(object):
|
|||
threads = 5
|
||||
if limit == "default":
|
||||
if len(self.peers) > 50:
|
||||
limit = 3
|
||||
threads = 3
|
||||
limit = 4
|
||||
threads = 4
|
||||
else:
|
||||
limit = 5
|
||||
|
||||
|
|
|
@ -287,7 +287,7 @@ class SiteStorage:
|
|||
|
||||
if not ok:
|
||||
self.log.debug("[CHANGED] %s" % file_inner_path)
|
||||
if add_changed:
|
||||
if add_changed or content.get("cert_sign"): # If updating own site only add changed user files
|
||||
bad_files.append(file_inner_path)
|
||||
|
||||
# Optional files
|
||||
|
@ -338,7 +338,7 @@ class SiteStorage:
|
|||
if bad_files:
|
||||
for bad_file in bad_files:
|
||||
self.site.bad_files[bad_file] = 1
|
||||
self.log.debug("Checked files in %.2fs... Quick:%s" % (time.time() - s, quick_check))
|
||||
self.log.debug("Checked files in %.2fs... Found bad files: %s, Quick:%s" % (time.time() - s, len(bad_files), quick_check))
|
||||
|
||||
# Delete site's all file
|
||||
def deleteFiles(self):
|
||||
|
|
|
@ -6,6 +6,7 @@ import logging
|
|||
|
||||
# Third party modules
|
||||
import gevent
|
||||
|
||||
from gevent import monkey
|
||||
if "patch_subprocess" in dir(monkey): # New gevent
|
||||
monkey.patch_all(thread=False, subprocess=False)
|
||||
|
@ -66,7 +67,6 @@ else:
|
|||
logging.getLogger('').addHandler(console_log) # Add console logger
|
||||
logging.getLogger('').name = "-" # Remove root prefix
|
||||
|
||||
|
||||
# Debug dependent configuration
|
||||
from Debug import DebugHook
|
||||
if config.debug:
|
||||
|
@ -101,7 +101,6 @@ elif config.tor == "always":
|
|||
config.fileserver_ip = '127.0.0.1' # Do not accept connections anywhere but localhost
|
||||
SocksProxy.monkeyPatch(*config.tor_proxy.split(":"))
|
||||
config.disable_udp = True
|
||||
|
||||
# -- Actions --
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue