Rev377, Fix sidebar filetypes css class, Support running zeronet from Utf-8 directories, Fix multiuser plugin welcome message, Format Multiuser plugin to PEP8, Faster publish by using connected peers if possible, Prefix css backface-visibility
This commit is contained in:
parent
55d8e80729
commit
00940797c8
10 changed files with 175 additions and 153 deletions
|
@ -312,10 +312,19 @@ class Site:
|
|||
# Update content.json on peers
|
||||
@util.Noparallel()
|
||||
def publish(self, limit=5, inner_path="content.json"):
|
||||
self.log.info("Publishing to %s/%s peers..." % (min(len(self.peers), limit), len(self.peers)))
|
||||
published = [] # Successfully published (Peer)
|
||||
publishers = [] # Publisher threads
|
||||
peers = self.peers.values()
|
||||
|
||||
connected_peers = self.getConnectedPeers()
|
||||
if len(connected_peers) > limit * 2: # Publish to already connected peers if possible
|
||||
peers = connected_peers
|
||||
else:
|
||||
peers = self.peers.values()
|
||||
|
||||
self.log.info("Publishing to %s/%s peers (connected: %s)..." % (
|
||||
min(len(self.peers), limit), len(self.peers), len(connected_peers)
|
||||
))
|
||||
|
||||
if not peers:
|
||||
return 0 # No peers found
|
||||
|
||||
|
@ -336,13 +345,15 @@ class Site:
|
|||
peer for peer in peers
|
||||
if peer.connection and not peer.connection.closed and peer.key.endswith(":0") and peer not in published
|
||||
] # Every connected passive peer that we not published to
|
||||
for peer in passive_peers:
|
||||
gevent.spawn(self.publisher, inner_path, passive_peers, published, limit=10)
|
||||
|
||||
self.log.info(
|
||||
"Successfuly published to %s peers, publishing to %s more passive peers" %
|
||||
(len(published), len(passive_peers))
|
||||
)
|
||||
|
||||
for peer in passive_peers:
|
||||
gevent.spawn(self.publisher, inner_path, passive_peers, published, limit=10)
|
||||
|
||||
return len(published)
|
||||
|
||||
# Copy this site
|
||||
|
@ -664,6 +675,9 @@ class Site:
|
|||
|
||||
return found
|
||||
|
||||
def getConnectedPeers(self):
|
||||
return [peer for peer in self.peers.values() if peer.connection and peer.connection.connected]
|
||||
|
||||
# Cleanup probably dead peers
|
||||
def cleanupPeers(self):
|
||||
peers = self.peers.values()
|
||||
|
|
|
@ -3,6 +3,7 @@ import re
|
|||
import shutil
|
||||
import json
|
||||
import time
|
||||
import sys
|
||||
|
||||
import sqlite3
|
||||
import gevent.event
|
||||
|
@ -16,7 +17,9 @@ class SiteStorage:
|
|||
|
||||
def __init__(self, site, allow_create=True):
|
||||
self.site = site
|
||||
self.fs_encoding = sys.getfilesystemencoding()
|
||||
self.directory = "%s/%s" % (config.data_dir, self.site.address) # Site data diretory
|
||||
self.allowed_dir = os.path.abspath(self.directory) # Only serve/modify file within this dir
|
||||
self.log = site.log
|
||||
self.db = None # Db class
|
||||
self.db_checked = False # Checked db tables since startup
|
||||
|
@ -204,10 +207,10 @@ class SiteStorage:
|
|||
def getPath(self, inner_path):
|
||||
inner_path = inner_path.replace("\\", "/") # Windows separator fix
|
||||
inner_path = re.sub("^%s/" % re.escape(self.directory), "", inner_path) # Remove site directory if begins with it
|
||||
file_path = self.directory + "/" + inner_path
|
||||
allowed_dir = os.path.abspath(self.directory) # Only files within this directory allowed
|
||||
if ".." in file_path or not os.path.dirname(os.path.abspath(file_path)).startswith(allowed_dir):
|
||||
raise Exception("File not allowed: %s" % file_path)
|
||||
file_path = u"%s/%s" % (self.directory, inner_path)
|
||||
file_abspath = os.path.dirname(os.path.abspath(file_path))
|
||||
if ".." in file_path or not file_abspath.startswith(self.allowed_dir):
|
||||
raise Exception(u"File not allowed: %s" % file_path)
|
||||
return file_path
|
||||
|
||||
# Get site dir relative path
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue