rev106, Allow check memory content in stats page, Fix Zeroname plugin incompatibility with Multiuser plugin, Zeroname updater sort keys, Allow multiple ui_restrict parameter, Peer using site's logger to save some memory, Also send not that good peers on initial pex
This commit is contained in:
parent
e7c0bd7621
commit
c8fe73f5c0
10 changed files with 255 additions and 19 deletions
|
@ -4,7 +4,7 @@ import ConfigParser
|
|||
class Config(object):
|
||||
def __init__(self):
|
||||
self.version = "0.2.9"
|
||||
self.rev = 102
|
||||
self.rev = 106
|
||||
self.parser = self.createArguments()
|
||||
argv = sys.argv[:] # Copy command line arguments
|
||||
argv = self.parseConfig(argv) # Add arguments from config file
|
||||
|
@ -80,7 +80,7 @@ class Config(object):
|
|||
|
||||
parser.add_argument('--ui_ip', help='Web interface bind address', default="127.0.0.1", metavar='ip')
|
||||
parser.add_argument('--ui_port', help='Web interface bind port', default=43110, type=int, metavar='port')
|
||||
parser.add_argument('--ui_restrict', help='Restrict web access', default=False, metavar='ip')
|
||||
parser.add_argument('--ui_restrict', help='Restrict web access', default=False, metavar='ip', nargs='*')
|
||||
parser.add_argument('--open_browser', help='Open homepage in web browser automatically', nargs='?', const="default_browser", metavar='browser_name')
|
||||
parser.add_argument('--homepage', help='Web interface Homepage', default='1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr', metavar='address')
|
||||
parser.add_argument('--size_limit', help='Default site size limit in MB', default=10, metavar='size_limit')
|
||||
|
|
|
@ -36,3 +36,20 @@ else:
|
|||
|
||||
gevent.Greenlet = gevent.greenlet.Greenlet = ErrorhookedGreenlet
|
||||
reload(gevent)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import time
|
||||
from gevent import monkey; monkey.patch_all(thread=False, ssl=False)
|
||||
import Debug
|
||||
def sleeper():
|
||||
print "started"
|
||||
time.sleep(3)
|
||||
print "stopped"
|
||||
thread1 = gevent.spawn(sleeper)
|
||||
thread2 = gevent.spawn(sleeper)
|
||||
time.sleep(1)
|
||||
print "killing..."
|
||||
thread1.throw(Exception("Hello"))
|
||||
thread2.throw(Debug.Notify("Throw"))
|
||||
print "killed"
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ class Peer:
|
|||
self.port = port
|
||||
self.site = site
|
||||
self.key = "%s:%s" % (ip, port)
|
||||
self.log = None
|
||||
self.connection_server = sys.modules["main"].file_server
|
||||
|
||||
self.connection = None
|
||||
|
@ -25,14 +24,20 @@ class Peer:
|
|||
self.download_time = 0 # Time spent to download
|
||||
|
||||
|
||||
def log(self, text):
|
||||
if self.site:
|
||||
self.site.log.debug("%s:%s %s" % (self.ip, self.port, text))
|
||||
else:
|
||||
logging.debug("%s:%s %s" % (self.ip, self.port, text))
|
||||
|
||||
|
||||
# Connect to host
|
||||
def connect(self, connection = None):
|
||||
if not self.log: self.log = logging.getLogger("Peer:%s:%s %s" % (self.ip, self.port, self.site))
|
||||
if self.connection:
|
||||
self.log.debug("Getting connection (Closing %s)..." % self.connection)
|
||||
self.log("Getting connection (Closing %s)..." % self.connection)
|
||||
self.connection.close()
|
||||
else:
|
||||
self.log.debug("Getting connection...")
|
||||
self.log("Getting connection...")
|
||||
|
||||
if connection: # Connection specificed
|
||||
self.connection = connection
|
||||
|
@ -43,7 +48,7 @@ class Peer:
|
|||
self.connection = self.connection_server.getConnection(self.ip, self.port)
|
||||
except Exception, err:
|
||||
self.onConnectionError()
|
||||
self.log.debug("Getting connection error: %s (connection_error: %s, hash_failed: %s)" % (Debug.formatException(err), self.connection_error, self.hash_failed))
|
||||
self.log("Getting connection error: %s (connection_error: %s, hash_failed: %s)" % (Debug.formatException(err), self.connection_error, self.hash_failed))
|
||||
self.connection = None
|
||||
|
||||
def __str__(self):
|
||||
|
@ -85,7 +90,7 @@ class Peer:
|
|||
if not response: raise Exception("Send error")
|
||||
#if config.debug_socket: self.log.debug("Got response to: %s" % cmd)
|
||||
if "error" in response:
|
||||
self.log.debug("%s error: %s" % (cmd, response["error"]))
|
||||
self.log("%s error: %s" % (cmd, response["error"]))
|
||||
self.onConnectionError()
|
||||
else: # Successful request, reset connection error num
|
||||
self.connection_error = 0
|
||||
|
@ -93,11 +98,11 @@ class Peer:
|
|||
return response
|
||||
except Exception, err:
|
||||
if type(err).__name__ == "Notify": # Greenlet kill by worker
|
||||
self.log.debug("Peer worker got killed: %s, aborting cmd: %s" % (err.message, cmd))
|
||||
self.log("Peer worker got killed: %s, aborting cmd: %s" % (err.message, cmd))
|
||||
break
|
||||
else:
|
||||
self.onConnectionError()
|
||||
self.log.debug("%s (connection_error: %s, hash_failed: %s, retry: %s)" % (Debug.formatException(err), self.connection_error, self.hash_failed, retry))
|
||||
self.log("%s (connection_error: %s, hash_failed: %s, retry: %s)" % (Debug.formatException(err), self.connection_error, self.hash_failed, retry))
|
||||
time.sleep(1*retry)
|
||||
self.connect()
|
||||
return None # Failed after 4 retry
|
||||
|
@ -141,9 +146,9 @@ class Peer:
|
|||
time.sleep(1)
|
||||
|
||||
if response_time:
|
||||
self.log.debug("Ping: %.3f" % response_time)
|
||||
self.log("Ping: %.3f" % response_time)
|
||||
else:
|
||||
self.log.debug("Ping failed")
|
||||
self.log("Ping failed")
|
||||
self.last_ping = response_time
|
||||
return response_time
|
||||
|
||||
|
@ -160,13 +165,13 @@ class Peer:
|
|||
address = self.unpackAddress(peer)
|
||||
if (site.addPeer(*address)): added += 1
|
||||
if added:
|
||||
self.log.debug("Added peers using pex: %s" % added)
|
||||
self.log("Added peers using pex: %s" % added)
|
||||
return added
|
||||
|
||||
|
||||
# Stop and remove from site
|
||||
def remove(self):
|
||||
self.log.debug("Removing peer...Connection error: %s, Hash failed: %s" % (self.connection_error, self.hash_failed))
|
||||
self.log("Removing peer...Connection error: %s, Hash failed: %s" % (self.connection_error, self.hash_failed))
|
||||
if self.key in self.site.peers: del(self.site.peers[self.key])
|
||||
if self.connection:
|
||||
self.connection.close()
|
||||
|
|
|
@ -445,8 +445,8 @@ class Site:
|
|||
found.append(peer)
|
||||
if len(found) >= need_num: break # Found requested number of peers
|
||||
|
||||
if not found and not ignore: # Not found any peer and the requester dont have any, return not that good peers
|
||||
found = [peer for peer in peers if not peer.key.endswith(":0") and peer.key not in ignore][0:need_num]
|
||||
if (not found and not ignore) or (need_num > 5 and need_num < 100 and len(found) < need_num): # Not found any peer and the requester dont have any, return not that good peers or Initial pex, but not /Stats page and we can't give enought peer
|
||||
found = [peer for peer in peers if not peer.key.endswith(":0") and peer.key not in ignore][0:need_num-len(found)]
|
||||
|
||||
return found
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class UiRequest(object):
|
|||
|
||||
# Call the request handler function base on path
|
||||
def route(self, path):
|
||||
if config.ui_restrict and self.env['REMOTE_ADDR'] != config.ui_restrict: # Restict Ui access by ip
|
||||
if config.ui_restrict and self.env['REMOTE_ADDR'] not in config.ui_restrict: # Restict Ui access by ip
|
||||
return self.error403()
|
||||
|
||||
if path == "/":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue