rev100, Revision numbering for sub-versions, Assign connection to peer on filerequest/pex, Pex count bugfix, Disable unnecessary topright button click animation, Topright burger utf8 character change to more supported one
This commit is contained in:
parent
f1a885b0ef
commit
60bfac63da
14 changed files with 206 additions and 201 deletions
|
@ -90,7 +90,7 @@ class UiRequestPlugin(object):
|
||||||
("%.0fkB", connection.bytes_recv/1024),
|
("%.0fkB", connection.bytes_recv/1024),
|
||||||
("%s", connection.last_cmd),
|
("%s", connection.last_cmd),
|
||||||
("%s", connection.waiting_requests.keys()),
|
("%s", connection.waiting_requests.keys()),
|
||||||
("%s", connection.handshake.get("version")),
|
("%s r%s", (connection.handshake.get("version"), connection.handshake.get("rev", "?")) ),
|
||||||
("%s", connection.handshake.get("peer_id")),
|
("%s", connection.handshake.get("peer_id")),
|
||||||
])
|
])
|
||||||
yield "</table>"
|
yield "</table>"
|
||||||
|
|
315
src/Config.py
315
src/Config.py
|
@ -1,157 +1,158 @@
|
||||||
import argparse, sys, os, time
|
import argparse, sys, os, time
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
class Config(object):
|
class Config(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.version = "0.2.9"
|
self.version = "0.2.9"
|
||||||
self.parser = self.createArguments()
|
self.rev = 100
|
||||||
argv = sys.argv[:] # Copy command line arguments
|
self.parser = self.createArguments()
|
||||||
argv = self.parseConfig(argv) # Add arguments from config file
|
argv = sys.argv[:] # Copy command line arguments
|
||||||
self.parseCommandline(argv) # Parse argv
|
argv = self.parseConfig(argv) # Add arguments from config file
|
||||||
self.setAttributes()
|
self.parseCommandline(argv) # Parse argv
|
||||||
|
self.setAttributes()
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return str(self.arguments).replace("Namespace", "Config") # Using argparse str output
|
def __str__(self):
|
||||||
|
return str(self.arguments).replace("Namespace", "Config") # Using argparse str output
|
||||||
|
|
||||||
# Create command line arguments
|
|
||||||
def createArguments(self):
|
# Create command line arguments
|
||||||
# Platform specific
|
def createArguments(self):
|
||||||
if sys.platform.startswith("win"):
|
# Platform specific
|
||||||
coffeescript = "type %s | tools\\coffee\\coffee.cmd"
|
if sys.platform.startswith("win"):
|
||||||
else:
|
coffeescript = "type %s | tools\\coffee\\coffee.cmd"
|
||||||
coffeescript = None
|
else:
|
||||||
|
coffeescript = None
|
||||||
# Create parser
|
|
||||||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
# Create parser
|
||||||
subparsers = parser.add_subparsers(title="Action to perform", dest="action")
|
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
|
subparsers = parser.add_subparsers(title="Action to perform", dest="action")
|
||||||
# Main
|
|
||||||
action = subparsers.add_parser("main", help='Start UiServer and FileServer (default)')
|
# Main
|
||||||
|
action = subparsers.add_parser("main", help='Start UiServer and FileServer (default)')
|
||||||
# SiteCreate
|
|
||||||
action = subparsers.add_parser("siteCreate", help='Create a new site')
|
# SiteCreate
|
||||||
|
action = subparsers.add_parser("siteCreate", help='Create a new site')
|
||||||
# SiteSign
|
|
||||||
action = subparsers.add_parser("siteSign", help='Update and sign content.json: address [privatekey]')
|
# SiteSign
|
||||||
action.add_argument('address', help='Site to sign')
|
action = subparsers.add_parser("siteSign", help='Update and sign content.json: address [privatekey]')
|
||||||
action.add_argument('privatekey', help='Private key (default: ask on execute)', nargs='?')
|
action.add_argument('address', help='Site to sign')
|
||||||
action.add_argument('--inner_path', help='File you want to sign (default: content.json)', default="content.json", metavar="inner_path")
|
action.add_argument('privatekey', help='Private key (default: ask on execute)', nargs='?')
|
||||||
|
action.add_argument('--inner_path', help='File you want to sign (default: content.json)', default="content.json", metavar="inner_path")
|
||||||
# SitePublish
|
|
||||||
action = subparsers.add_parser("sitePublish", help='Publish site to other peers: address')
|
# SitePublish
|
||||||
action.add_argument('address', help='Site to publish')
|
action = subparsers.add_parser("sitePublish", help='Publish site to other peers: address')
|
||||||
action.add_argument('peer_ip', help='Peer ip to publish (default: random peers ip from tracker)', default=None, nargs='?')
|
action.add_argument('address', help='Site to publish')
|
||||||
action.add_argument('peer_port', help='Peer port to publish (default: random peer port from tracker)', default=15441, nargs='?')
|
action.add_argument('peer_ip', help='Peer ip to publish (default: random peers ip from tracker)', default=None, nargs='?')
|
||||||
action.add_argument('--inner_path', help='Content.json you want to publish (default: content.json)', default="content.json", metavar="inner_path")
|
action.add_argument('peer_port', help='Peer port to publish (default: random peer port from tracker)', default=15441, nargs='?')
|
||||||
|
action.add_argument('--inner_path', help='Content.json you want to publish (default: content.json)', default="content.json", metavar="inner_path")
|
||||||
# SiteVerify
|
|
||||||
action = subparsers.add_parser("siteVerify", help='Verify site files using sha512: address')
|
# SiteVerify
|
||||||
action.add_argument('address', help='Site to verify')
|
action = subparsers.add_parser("siteVerify", help='Verify site files using sha512: address')
|
||||||
|
action.add_argument('address', help='Site to verify')
|
||||||
#dbRebuild
|
|
||||||
action = subparsers.add_parser("dbRebuild", help='Rebuild site database cache')
|
#dbRebuild
|
||||||
action.add_argument('address', help='Site to rebuild')
|
action = subparsers.add_parser("dbRebuild", help='Rebuild site database cache')
|
||||||
|
action.add_argument('address', help='Site to rebuild')
|
||||||
#dbQuery
|
|
||||||
action = subparsers.add_parser("dbQuery", help='Query site sql cache')
|
#dbQuery
|
||||||
action.add_argument('address', help='Site to query')
|
action = subparsers.add_parser("dbQuery", help='Query site sql cache')
|
||||||
action.add_argument('query', help='Sql query')
|
action.add_argument('address', help='Site to query')
|
||||||
|
action.add_argument('query', help='Sql query')
|
||||||
# PeerPing
|
|
||||||
action = subparsers.add_parser("peerPing", help='Send Ping command to peer')
|
# PeerPing
|
||||||
action.add_argument('peer_ip', help='Peer ip')
|
action = subparsers.add_parser("peerPing", help='Send Ping command to peer')
|
||||||
action.add_argument('peer_port', help='Peer port')
|
action.add_argument('peer_ip', help='Peer ip')
|
||||||
|
action.add_argument('peer_port', help='Peer port')
|
||||||
# PeerGetFile
|
|
||||||
action = subparsers.add_parser("peerGetFile", help='Request and print a file content from peer')
|
# PeerGetFile
|
||||||
action.add_argument('peer_ip', help='Peer ip')
|
action = subparsers.add_parser("peerGetFile", help='Request and print a file content from peer')
|
||||||
action.add_argument('peer_port', help='Peer port')
|
action.add_argument('peer_ip', help='Peer ip')
|
||||||
action.add_argument('site', help='Site address')
|
action.add_argument('peer_port', help='Peer port')
|
||||||
action.add_argument('filename', help='File name to request')
|
action.add_argument('site', help='Site address')
|
||||||
|
action.add_argument('filename', help='File name to request')
|
||||||
|
|
||||||
|
|
||||||
# Config parameters
|
|
||||||
parser.add_argument('--debug', help='Debug mode', action='store_true')
|
# Config parameters
|
||||||
parser.add_argument('--debug_socket', help='Debug socket connections', action='store_true')
|
parser.add_argument('--debug', help='Debug mode', action='store_true')
|
||||||
|
parser.add_argument('--debug_socket', help='Debug socket connections', action='store_true')
|
||||||
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_ip', help='Web interface bind address', default="127.0.0.1", metavar='ip')
|
||||||
parser.add_argument('--ui_restrict', help='Restrict web access', default=False, metavar='ip')
|
parser.add_argument('--ui_port', help='Web interface bind port', default=43110, type=int, metavar='port')
|
||||||
parser.add_argument('--open_browser', help='Open homepage in web browser automatically', nargs='?', const="default_browser", metavar='browser_name')
|
parser.add_argument('--ui_restrict', help='Restrict web access', default=False, metavar='ip')
|
||||||
parser.add_argument('--homepage', help='Web interface Homepage', default='1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr', metavar='address')
|
parser.add_argument('--open_browser', help='Open homepage in web browser automatically', nargs='?', const="default_browser", metavar='browser_name')
|
||||||
parser.add_argument('--size_limit', help='Default site size limit in MB', default=10, metavar='size_limit')
|
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')
|
||||||
parser.add_argument('--fileserver_ip', help='FileServer bind address', default="*", metavar='ip')
|
|
||||||
parser.add_argument('--fileserver_port',help='FileServer bind port', default=15441, type=int, metavar='port')
|
parser.add_argument('--fileserver_ip', help='FileServer bind address', default="*", metavar='ip')
|
||||||
parser.add_argument('--disable_zeromq', help='Disable compatibility with old clients', action='store_true')
|
parser.add_argument('--fileserver_port',help='FileServer bind port', default=15441, type=int, metavar='port')
|
||||||
parser.add_argument('--proxy', help='Socks proxy address', metavar='ip:port')
|
parser.add_argument('--disable_zeromq', help='Disable compatibility with old clients', action='store_true')
|
||||||
parser.add_argument('--disable_udp', help='Disable UDP connections', action='store_true')
|
parser.add_argument('--proxy', help='Socks proxy address', metavar='ip:port')
|
||||||
parser.add_argument('--ip_external', help='External ip (tested on start if None)', metavar='ip')
|
parser.add_argument('--disable_udp', help='Disable UDP connections', action='store_true')
|
||||||
|
parser.add_argument('--ip_external', help='External ip (tested on start if None)', metavar='ip')
|
||||||
parser.add_argument('--coffeescript_compiler', help='Coffeescript compiler for developing', default=coffeescript, metavar='executable_path')
|
|
||||||
|
parser.add_argument('--coffeescript_compiler', help='Coffeescript compiler for developing', default=coffeescript, metavar='executable_path')
|
||||||
parser.add_argument('--version', action='version', version='ZeroNet %s' % self.version)
|
|
||||||
|
parser.add_argument('--version', action='version', version='ZeroNet %s r%s' % (self.version, self.rev))
|
||||||
return parser
|
|
||||||
|
return parser
|
||||||
|
|
||||||
# Find arguments specificed for current action
|
|
||||||
def getActionArguments(self):
|
# Find arguments specificed for current action
|
||||||
back = {}
|
def getActionArguments(self):
|
||||||
arguments = self.parser._subparsers._group_actions[0].choices[self.action]._actions[1:] # First is --version
|
back = {}
|
||||||
for argument in arguments:
|
arguments = self.parser._subparsers._group_actions[0].choices[self.action]._actions[1:] # First is --version
|
||||||
back[argument.dest] = getattr(self, argument.dest)
|
for argument in arguments:
|
||||||
return back
|
back[argument.dest] = getattr(self, argument.dest)
|
||||||
|
return back
|
||||||
|
|
||||||
|
|
||||||
# Try to find action from sys.argv
|
|
||||||
def getAction(self, argv):
|
# Try to find action from sys.argv
|
||||||
actions = [action.choices.keys() for action in self.parser._actions if action.dest == "action"][0] # Valid actions
|
def getAction(self, argv):
|
||||||
found_action = False
|
actions = [action.choices.keys() for action in self.parser._actions if action.dest == "action"][0] # Valid actions
|
||||||
for action in actions: # See if any in sys.argv
|
found_action = False
|
||||||
if action in argv:
|
for action in actions: # See if any in sys.argv
|
||||||
found_action = action
|
if action in argv:
|
||||||
break
|
found_action = action
|
||||||
return found_action
|
break
|
||||||
|
return found_action
|
||||||
|
|
||||||
# Parse command line arguments
|
|
||||||
def parseCommandline(self, argv):
|
# Parse command line arguments
|
||||||
# Find out if action is specificed on start
|
def parseCommandline(self, argv):
|
||||||
action = self.getAction(argv)
|
# Find out if action is specificed on start
|
||||||
if len(argv) == 1 or not action: # If no action specificed set the main action
|
action = self.getAction(argv)
|
||||||
argv.append("main")
|
if len(argv) == 1 or not action: # If no action specificed set the main action
|
||||||
if "zeronet.py" in argv[0]:
|
argv.append("main")
|
||||||
self.arguments = self.parser.parse_args(argv[1:])
|
if "zeronet.py" in argv[0]:
|
||||||
else: # Silent errors if not started with zeronet.py
|
self.arguments = self.parser.parse_args(argv[1:])
|
||||||
self.arguments = self.parser.parse_args(argv[1:])
|
else: # Silent errors if not started with zeronet.py
|
||||||
|
self.arguments = self.parser.parse_args(argv[1:])
|
||||||
|
|
||||||
# Parse config file
|
|
||||||
def parseConfig(self, argv):
|
# Parse config file
|
||||||
if os.path.isfile("zeronet.conf"):
|
def parseConfig(self, argv):
|
||||||
config = ConfigParser.ConfigParser(allow_no_value=True)
|
if os.path.isfile("zeronet.conf"):
|
||||||
config.read('zeronet.conf')
|
config = ConfigParser.ConfigParser(allow_no_value=True)
|
||||||
for section in config.sections():
|
config.read('zeronet.conf')
|
||||||
for key, val in config.items(section):
|
for section in config.sections():
|
||||||
if section != "global": # If not global prefix key with section
|
for key, val in config.items(section):
|
||||||
key = section+"_"+key
|
if section != "global": # If not global prefix key with section
|
||||||
if val: argv.insert(1, val)
|
key = section+"_"+key
|
||||||
argv.insert(1, "--%s" % key)
|
if val: argv.insert(1, val)
|
||||||
return argv
|
argv.insert(1, "--%s" % key)
|
||||||
|
return argv
|
||||||
|
|
||||||
|
|
||||||
# Expose arguments as class attributes
|
|
||||||
def setAttributes(self):
|
# Expose arguments as class attributes
|
||||||
# Set attributes from arguments
|
def setAttributes(self):
|
||||||
args = vars(self.arguments)
|
# Set attributes from arguments
|
||||||
for key, val in args.items():
|
args = vars(self.arguments)
|
||||||
setattr(self, key, val)
|
for key, val in args.items():
|
||||||
|
setattr(self, key, val)
|
||||||
|
|
||||||
config = Config()
|
|
||||||
|
config = Config()
|
||||||
|
|
|
@ -183,7 +183,8 @@ class Connection:
|
||||||
"protocol": "v2",
|
"protocol": "v2",
|
||||||
"peer_id": self.server.peer_id,
|
"peer_id": self.server.peer_id,
|
||||||
"fileserver_port": config.fileserver_port,
|
"fileserver_port": config.fileserver_port,
|
||||||
"port_opened": self.server.port_opened
|
"port_opened": self.server.port_opened,
|
||||||
|
"rev": config.rev
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,10 @@ class FileRequest:
|
||||||
if config.debug_socket: self.log.debug("File %s sent" % file_path)
|
if config.debug_socket: self.log.debug("File %s sent" % file_path)
|
||||||
|
|
||||||
# Add peer to site if not added before
|
# Add peer to site if not added before
|
||||||
site.addPeer(self.connection.ip, self.connection.port)
|
connected_peer = site.addPeer(self.connection.ip, self.connection.port)
|
||||||
|
if connected_peer: # Just added
|
||||||
|
connected_peer.connect(self.connection) # Assign current connection to peer
|
||||||
|
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
self.log.debug("GetFile read error: %s" % Debug.formatException(err))
|
self.log.debug("GetFile read error: %s" % Debug.formatException(err))
|
||||||
self.response({"error": "File read error: %s" % Debug.formatException(err)})
|
self.response({"error": "File read error: %s" % Debug.formatException(err)})
|
||||||
|
@ -126,7 +129,11 @@ class FileRequest:
|
||||||
|
|
||||||
got_peer_keys = []
|
got_peer_keys = []
|
||||||
added = 0
|
added = 0
|
||||||
site.addPeer(self.connection.ip, self.connection.port) # Add requester peer to site
|
connected_peer = site.addPeer(self.connection.ip, self.connection.port) # Add requester peer to site
|
||||||
|
if connected_peer: # Just added
|
||||||
|
added +=1
|
||||||
|
connected_peer.connect(self.connection) # Assign current connection to peer
|
||||||
|
|
||||||
for peer in params["peers"]: # Add sent peers to site
|
for peer in params["peers"]: # Add sent peers to site
|
||||||
address = self.unpackAddress(peer)
|
address = self.unpackAddress(peer)
|
||||||
got_peer_keys.append("%s:%s" % address)
|
got_peer_keys.append("%s:%s" % address)
|
||||||
|
@ -134,6 +141,7 @@ class FileRequest:
|
||||||
# Send back peers that is not in the sent list and connectable (not port 0)
|
# Send back peers that is not in the sent list and connectable (not port 0)
|
||||||
packed_peers = [peer.packAddress() for peer in site.getConnectablePeers(params["need"], got_peer_keys)]
|
packed_peers = [peer.packAddress() for peer in site.getConnectablePeers(params["need"], got_peer_keys)]
|
||||||
if added:
|
if added:
|
||||||
|
site.worker_manager.onPeers()
|
||||||
self.log.debug("Added %s peers to %s using pex, sending back %s" % (added, site, len(packed_peers)))
|
self.log.debug("Added %s peers to %s using pex, sending back %s" % (added, site, len(packed_peers)))
|
||||||
self.response({"peers": packed_peers})
|
self.response({"peers": packed_peers})
|
||||||
|
|
||||||
|
|
|
@ -26,22 +26,25 @@ class Peer:
|
||||||
|
|
||||||
|
|
||||||
# Connect to host
|
# Connect to host
|
||||||
def connect(self):
|
def connect(self, connection = None):
|
||||||
if not self.log: self.log = logging.getLogger("Peer:%s:%s %s" % (self.ip, self.port, self.site))
|
if not self.log: self.log = logging.getLogger("Peer:%s:%s %s" % (self.ip, self.port, self.site))
|
||||||
if self.connection:
|
if self.connection:
|
||||||
self.log.debug("Getting connection (Closing %s)..." % self.connection)
|
self.log.debug("Getting connection (Closing %s)..." % self.connection)
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
else:
|
else:
|
||||||
self.log.debug("Getting connection...")
|
self.log.debug("Getting connection...")
|
||||||
|
|
||||||
self.connection = None
|
if connection: # Connection specificed
|
||||||
|
self.connection = connection
|
||||||
try:
|
else: # Try to find from connection pool or create new connection
|
||||||
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.connection = None
|
self.connection = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
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.connection = None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Peer %-12s" % self.ip
|
return "Peer %-12s" % self.ip
|
||||||
|
|
|
@ -282,6 +282,7 @@ class Site:
|
||||||
# Add or update a peer to site
|
# Add or update a peer to site
|
||||||
def addPeer(self, ip, port, return_peer = False):
|
def addPeer(self, ip, port, return_peer = False):
|
||||||
if not ip: return False
|
if not ip: return False
|
||||||
|
if (ip, port) in self.peer_blacklist: return False # Ignore blacklist (eg. myself)
|
||||||
key = "%s:%s" % (ip, port)
|
key = "%s:%s" % (ip, port)
|
||||||
if key in self.peers: # Already has this ip
|
if key in self.peers: # Already has this ip
|
||||||
#self.peers[key].found()
|
#self.peers[key].found()
|
||||||
|
@ -300,6 +301,7 @@ class Site:
|
||||||
def announcePex(self, query_num=2, need_num=5):
|
def announcePex(self, query_num=2, need_num=5):
|
||||||
peers = [peer for peer in self.peers.values() if peer.connection and peer.connection.connected] # Connected peers
|
peers = [peer for peer in self.peers.values() if peer.connection and peer.connection.connected] # Connected peers
|
||||||
if len(peers) == 0: # Small number of connected peers for this site, connect to any
|
if len(peers) == 0: # Small number of connected peers for this site, connect to any
|
||||||
|
self.log.debug("Small number of peers detected...query all of peers using pex")
|
||||||
peers = self.peers.values()
|
peers = self.peers.values()
|
||||||
need_num = 10
|
need_num = 10
|
||||||
|
|
||||||
|
@ -308,19 +310,20 @@ class Site:
|
||||||
added = 0
|
added = 0
|
||||||
for peer in peers:
|
for peer in peers:
|
||||||
if peer.connection: # Has connection
|
if peer.connection: # Has connection
|
||||||
if "port_opened" in peer.connection.handshake: # This field added recently, so probably has gas peer exchange
|
if "port_opened" in peer.connection.handshake: # This field added recently, so probably has has peer exchange
|
||||||
res = peer.pex(need_num=need_num)
|
res = peer.pex(need_num=need_num)
|
||||||
else:
|
else:
|
||||||
res = False
|
res = False
|
||||||
else: # No connection
|
else: # No connection
|
||||||
res = peer.pex(need_num=need_num)
|
res = peer.pex(need_num=need_num)
|
||||||
if res != False:
|
if type(res) == int: # We have result
|
||||||
done += 1
|
done += 1
|
||||||
added += res
|
added += res
|
||||||
if added:
|
if res:
|
||||||
self.worker_manager.onPeers()
|
self.worker_manager.onPeers()
|
||||||
self.updateWebsocket(peers_added=added)
|
self.updateWebsocket(peers_added=res)
|
||||||
if done == query_num: break
|
if done == query_num: break
|
||||||
|
self.log.debug("Queried pex from %s peers got %s new peers." % (done, added))
|
||||||
|
|
||||||
|
|
||||||
# Add myself and get other peers from tracker
|
# Add myself and get other peers from tracker
|
||||||
|
@ -336,7 +339,6 @@ class Site:
|
||||||
else: # Port not opened, report port 0
|
else: # Port not opened, report port 0
|
||||||
fileserver_port = 0
|
fileserver_port = 0
|
||||||
|
|
||||||
fileserver_port = config.fileserver_port
|
|
||||||
s = time.time()
|
s = time.time()
|
||||||
announced = 0
|
announced = 0
|
||||||
|
|
||||||
|
@ -385,8 +387,6 @@ class Site:
|
||||||
added = 0
|
added = 0
|
||||||
for peer in peers:
|
for peer in peers:
|
||||||
if not peer["port"]: continue # Dont add peers with port 0
|
if not peer["port"]: continue # Dont add peers with port 0
|
||||||
if (peer["addr"], peer["port"]) in self.peer_blacklist: # Ignore blacklist (eg. myself)
|
|
||||||
continue
|
|
||||||
if self.addPeer(peer["addr"], peer["port"]): added += 1
|
if self.addPeer(peer["addr"], peer["port"]): added += 1
|
||||||
if added:
|
if added:
|
||||||
self.worker_manager.onPeers()
|
self.worker_manager.onPeers()
|
||||||
|
@ -399,7 +399,7 @@ class Site:
|
||||||
self.saveSettings()
|
self.saveSettings()
|
||||||
|
|
||||||
if len(errors) < len(SiteManager.TRACKERS): # Less errors than total tracker nums
|
if len(errors) < len(SiteManager.TRACKERS): # Less errors than total tracker nums
|
||||||
self.log.debug("Announced to %s trackers in %.3fs, errors: %s" % (announced, time.time()-s, errors))
|
self.log.debug("Announced port %s to %s trackers in %.3fs, errors: %s" % (fileserver_port, announced, time.time()-s, errors))
|
||||||
else:
|
else:
|
||||||
self.log.error("Announced to %s trackers in %.3fs, failed" % (announced, time.time()-s))
|
self.log.error("Announced to %s trackers in %.3fs, failed" % (announced, time.time()-s))
|
||||||
|
|
||||||
|
@ -412,9 +412,7 @@ class Site:
|
||||||
|
|
||||||
# Keep connections to get the updates (required for passive clients)
|
# Keep connections to get the updates (required for passive clients)
|
||||||
def needConnections(self):
|
def needConnections(self):
|
||||||
need = min(len(self.peers)/2, 10) # Connect to half of total peers, but max 10
|
need = min(len(self.peers), 3) # Need 3 peer, but max total peers
|
||||||
need = max(need, 5) # But minimum 5 peers
|
|
||||||
need = min(len(self.peers), need) # Max total peers
|
|
||||||
|
|
||||||
connected = 0
|
connected = 0
|
||||||
for peer in self.peers.values(): # Check current connected number
|
for peer in self.peers.values(): # Check current connected number
|
||||||
|
|
|
@ -219,6 +219,7 @@ class UiWebsocket(object):
|
||||||
"ui_ip": config.ui_ip,
|
"ui_ip": config.ui_ip,
|
||||||
"ui_port": config.ui_port,
|
"ui_port": config.ui_port,
|
||||||
"version": config.version,
|
"version": config.version,
|
||||||
|
"rev": config.rev,
|
||||||
"debug": config.debug,
|
"debug": config.debug,
|
||||||
"plugins": PluginManager.plugin_manager.plugin_names
|
"plugins": PluginManager.plugin_manager.plugin_names
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,13 @@ class Sidebar
|
||||||
###
|
###
|
||||||
|
|
||||||
$(".fixbutton-bg").on "mousedown", ->
|
$(".fixbutton-bg").on "mousedown", ->
|
||||||
$(".fixbutton-burger").stop().animate({"scale": 0.7, "left": 0}, 300, "easeOutCubic")
|
# $(".fixbutton-burger").stop().animate({"scale": 0.7, "left": 0}, 300, "easeOutCubic")
|
||||||
#$("#inner-iframe").toggleClass("back")
|
#$("#inner-iframe").toggleClass("back")
|
||||||
#$(".wrapper-iframe").stop().animate({"scale": 0.9}, 600, "easeOutCubic")
|
#$(".wrapper-iframe").stop().animate({"scale": 0.9}, 600, "easeOutCubic")
|
||||||
#$("body").addClass("back")
|
#$("body").addClass("back")
|
||||||
|
|
||||||
$(".fixbutton-bg").on "mouseup", ->
|
$(".fixbutton-bg").on "mouseup", ->
|
||||||
$(".fixbutton-burger").stop().animate({"scale": 1, "left": 0}, 600, "easeOutElastic")
|
# $(".fixbutton-burger").stop().animate({"scale": 1, "left": 0}, 600, "easeOutElastic")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,9 @@ a { color: black }
|
||||||
/*box-shadow: inset 105px 260px 0px -200px rgba(0,0,0,0.1);*/ /* box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1); */
|
/*box-shadow: inset 105px 260px 0px -200px rgba(0,0,0,0.1);*/ /* box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1); */
|
||||||
}
|
}
|
||||||
.fixbutton-text { pointer-events: none; position: absolute; z-index: 999; width: 40px; backface-visibility: hidden; perspective: 1000px }
|
.fixbutton-text { pointer-events: none; position: absolute; z-index: 999; width: 40px; backface-visibility: hidden; perspective: 1000px }
|
||||||
.fixbutton-burger { pointer-events: none; position: absolute; z-index: 999; width: 40px; opacity: 0; left: -20px }
|
.fixbutton-burger { pointer-events: none; position: absolute; z-index: 999; width: 40px; opacity: 0; left: -20px; font-size: 48px; line-height: 32px }
|
||||||
.fixbutton-bg:hover { background-color: #AF3BFF }
|
.fixbutton-bg:hover { background-color: #AF3BFF }
|
||||||
|
.fixbutton-bg:active { background-color: #9E2FEA; top: 1px; transition: none }
|
||||||
|
|
||||||
|
|
||||||
/* Notification */
|
/* Notification */
|
||||||
|
|
|
@ -32,8 +32,9 @@ a { color: black }
|
||||||
/*box-shadow: inset 105px 260px 0px -200px rgba(0,0,0,0.1);*/ /* -webkit-box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1); -moz-box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1); -o-box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1); -ms-box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1); box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1) ; */
|
/*box-shadow: inset 105px 260px 0px -200px rgba(0,0,0,0.1);*/ /* -webkit-box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1); -moz-box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1); -o-box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1); -ms-box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1); box-shadow: inset -75px 183px 0px -200px rgba(0,0,0,0.1) ; */
|
||||||
}
|
}
|
||||||
.fixbutton-text { pointer-events: none; position: absolute; z-index: 999; width: 40px; backface-visibility: hidden; -webkit-perspective: 1000px ; -moz-perspective: 1000px ; -o-perspective: 1000px ; -ms-perspective: 1000px ; perspective: 1000px }
|
.fixbutton-text { pointer-events: none; position: absolute; z-index: 999; width: 40px; backface-visibility: hidden; -webkit-perspective: 1000px ; -moz-perspective: 1000px ; -o-perspective: 1000px ; -ms-perspective: 1000px ; perspective: 1000px }
|
||||||
.fixbutton-burger { pointer-events: none; position: absolute; z-index: 999; width: 40px; opacity: 0; left: -20px }
|
.fixbutton-burger { pointer-events: none; position: absolute; z-index: 999; width: 40px; opacity: 0; left: -20px; font-size: 48px; line-height: 32px }
|
||||||
.fixbutton-bg:hover { background-color: #AF3BFF }
|
.fixbutton-bg:hover { background-color: #AF3BFF }
|
||||||
|
.fixbutton-bg:active { background-color: #9E2FEA; top: 1px; -webkit-transition: none ; -moz-transition: none ; -o-transition: none ; -ms-transition: none ; transition: none }
|
||||||
|
|
||||||
|
|
||||||
/* Notification */
|
/* Notification */
|
||||||
|
|
|
@ -724,18 +724,8 @@ jQuery.extend( jQuery.easing,
|
||||||
/*$(".fixbutton-bg").on "click", ->
|
/*$(".fixbutton-bg").on "click", ->
|
||||||
return false
|
return false
|
||||||
*/
|
*/
|
||||||
$(".fixbutton-bg").on("mousedown", function() {
|
$(".fixbutton-bg").on("mousedown", function() {});
|
||||||
return $(".fixbutton-burger").stop().animate({
|
return $(".fixbutton-bg").on("mouseup", function() {});
|
||||||
"scale": 0.7,
|
|
||||||
"left": 0
|
|
||||||
}, 300, "easeOutCubic");
|
|
||||||
});
|
|
||||||
return $(".fixbutton-bg").on("mouseup", function() {
|
|
||||||
return $(".fixbutton-burger").stop().animate({
|
|
||||||
"scale": 1,
|
|
||||||
"left": 0
|
|
||||||
}, 600, "easeOutElastic");
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return Sidebar;
|
return Sidebar;
|
||||||
|
@ -747,6 +737,7 @@ jQuery.extend( jQuery.easing,
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/Wrapper.coffee ---- */
|
/* ---- src/Ui/media/Wrapper.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -1178,4 +1169,4 @@ jQuery.extend( jQuery.easing,
|
||||||
|
|
||||||
window.wrapper = new Wrapper(ws_url);
|
window.wrapper = new Wrapper(ws_url);
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
|
@ -18,7 +18,7 @@
|
||||||
<!-- Fixed button -->
|
<!-- Fixed button -->
|
||||||
<div class='fixbutton'>
|
<div class='fixbutton'>
|
||||||
<div class='fixbutton-text'>0</div>
|
<div class='fixbutton-text'>0</div>
|
||||||
<div class='fixbutton-burger'>☰</div>
|
<div class='fixbutton-burger'>≡</div>
|
||||||
<a class='fixbutton-bg' href="/{homepage}"></a>
|
<a class='fixbutton-bg' href="/{homepage}"></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -100,8 +100,8 @@ class WorkerManager:
|
||||||
|
|
||||||
# Start workers to process tasks
|
# Start workers to process tasks
|
||||||
def startWorkers(self, peers=None):
|
def startWorkers(self, peers=None):
|
||||||
if len(self.workers) >= MAX_WORKERS and not peers: return False # Workers number already maxed and no starting peers definied
|
|
||||||
if not self.tasks: return False # No task for workers
|
if not self.tasks: return False # No task for workers
|
||||||
|
if len(self.workers) >= MAX_WORKERS and not peers: return False # Workers number already maxed and no starting peers definied
|
||||||
if not peers: peers = self.site.peers.values() # No peers definied, use any from site
|
if not peers: peers = self.site.peers.values() # No peers definied, use any from site
|
||||||
random.shuffle(peers)
|
random.shuffle(peers)
|
||||||
for peer in peers: # One worker for every peer
|
for peer in peers: # One worker for every peer
|
||||||
|
|
|
@ -67,7 +67,7 @@ PluginManager.plugin_manager.loadPlugins()
|
||||||
class Actions:
|
class Actions:
|
||||||
# Default action: Start serving UiServer and FileServer
|
# Default action: Start serving UiServer and FileServer
|
||||||
def main(self):
|
def main(self):
|
||||||
logging.info("Version: %s, Python %s, Gevent: %s" % (config.version, sys.version, gevent.__version__))
|
logging.info("Version: %s r%s, Python %s, Gevent: %s" % (config.version, config.rev, sys.version, gevent.__version__))
|
||||||
global ui_server, file_server
|
global ui_server, file_server
|
||||||
from File import FileServer
|
from File import FileServer
|
||||||
from Ui import UiServer
|
from Ui import UiServer
|
||||||
|
|
Loading…
Reference in a new issue