version 0.1.3, tructate sha512 to 256bits, retry peer cmd only 3 times, ping peer before cmd to find stucked sockets, ping with timeout and retry, separate wrapper_key and auth_key, changed sha1 to sha512, backward compatibility to sha1, reduce websocket bw usage on events, removed wrapper hash from wrapper iframe url
This commit is contained in:
parent
b37e309eda
commit
014a79912f
12 changed files with 102 additions and 54 deletions
|
@ -122,7 +122,7 @@ class UiRequest:
|
|||
inner_path=inner_path,
|
||||
address=match.group("site"),
|
||||
title=title,
|
||||
auth_key=site.settings["auth_key"],
|
||||
wrapper_key=site.settings["wrapper_key"],
|
||||
permissions=json.dumps(site.settings["permissions"]),
|
||||
show_loadingscreen=json.dumps(not os.path.isfile(site.getPath(inner_path))),
|
||||
homepage=config.homepage
|
||||
|
@ -209,13 +209,13 @@ class UiRequest:
|
|||
def actionWebsocket(self):
|
||||
ws = self.env.get("wsgi.websocket")
|
||||
if ws:
|
||||
auth_key = self.get["auth_key"]
|
||||
# Find site by auth_key
|
||||
wrapper_key = self.get["wrapper_key"]
|
||||
# Find site by wraper_key
|
||||
site = None
|
||||
for site_check in self.server.sites.values():
|
||||
if site_check.settings["auth_key"] == auth_key: site = site_check
|
||||
if site_check.settings["wrapper_key"] == wrapper_key: site = site_check
|
||||
|
||||
if site: # Correct auth key
|
||||
if site: # Correct wrapper key
|
||||
ui_websocket = UiWebsocket(ws, site, self.server)
|
||||
site.websockets.append(ui_websocket) # Add to site websockets to allow notify on events
|
||||
ui_websocket.start()
|
||||
|
@ -223,8 +223,8 @@ class UiRequest:
|
|||
if ui_websocket in site_check.websockets:
|
||||
site_check.websockets.remove(ui_websocket)
|
||||
return "Bye."
|
||||
else: # No site found by auth key
|
||||
self.log.error("Auth key not found: %s" % auth_key)
|
||||
else: # No site found by wrapper key
|
||||
self.log.error("Wrapper key not found: %s" % wraper_key)
|
||||
return self.error403()
|
||||
else:
|
||||
start_response("400 Bad Request", [])
|
||||
|
|
|
@ -46,7 +46,7 @@ class UiWebsocket:
|
|||
if channel in self.channels: # We are joined to channel
|
||||
if channel == "siteChanged":
|
||||
site = params[0] # Triggerer site
|
||||
site_info = self.siteInfo(site)
|
||||
site_info = self.formatSiteInfo(site)
|
||||
if len(params) > 1 and params[1]: # Extra data
|
||||
site_info.update(params[1])
|
||||
self.cmd("setSiteInfo", site_info)
|
||||
|
@ -121,18 +121,24 @@ class UiWebsocket:
|
|||
|
||||
|
||||
# Format site info
|
||||
def siteInfo(self, site):
|
||||
def formatSiteInfo(self, site):
|
||||
content = site.content
|
||||
if content and "files" in content: # Remove unnecessary data transfer
|
||||
content = site.content.copy()
|
||||
content["files"] = len(content["files"])
|
||||
del(content["sign"])
|
||||
|
||||
ret = {
|
||||
"auth_id": self.site.settings["auth_key"][0:10],
|
||||
"auth_id_md5": hashlib.md5(self.site.settings["auth_key"][0:10]).hexdigest(),
|
||||
"auth_key": self.site.settings["auth_key"],
|
||||
"auth_key_sha512": hashlib.sha512(self.site.settings["auth_key"]).hexdigest()[0:64],
|
||||
"address": site.address,
|
||||
"settings": site.settings,
|
||||
"content_updated": site.content_updated,
|
||||
"bad_files": site.bad_files.keys(),
|
||||
"last_downloads": site.last_downloads,
|
||||
"bad_files": len(site.bad_files),
|
||||
"last_downloads": len(site.last_downloads),
|
||||
"peers": len(site.peers),
|
||||
"tasks": [task["inner_path"] for task in site.worker_manager.tasks],
|
||||
"content": site.content
|
||||
"tasks": len([task["inner_path"] for task in site.worker_manager.tasks]),
|
||||
"content": content
|
||||
}
|
||||
if site.settings["serving"] and site.content: ret["peers"] += 1 # Add myself if serving
|
||||
return ret
|
||||
|
@ -140,7 +146,7 @@ class UiWebsocket:
|
|||
|
||||
# Send site details
|
||||
def actionSiteInfo(self, to, params):
|
||||
ret = self.siteInfo(self.site)
|
||||
ret = self.formatSiteInfo(self.site)
|
||||
self.response(to, ret)
|
||||
|
||||
|
||||
|
@ -173,7 +179,7 @@ class UiWebsocket:
|
|||
SiteManager.load() # Reload sites
|
||||
for site in self.server.sites.values():
|
||||
if not site.content: continue # Broken site
|
||||
ret.append(self.siteInfo(site))
|
||||
ret.append(self.formatSiteInfo(site))
|
||||
self.response(to, ret)
|
||||
|
||||
|
||||
|
|
|
@ -118,8 +118,8 @@ class Wrapper
|
|||
setSiteInfo: (site_info) ->
|
||||
if site_info.event? # If loading screen visible add event to it
|
||||
# File started downloading
|
||||
if site_info.event[0] == "file_added" and site_info.bad_files.length
|
||||
@loading.printLine("#{site_info.bad_files.length} files needs to be downloaded")
|
||||
if site_info.event[0] == "file_added" and site_info.bad_files
|
||||
@loading.printLine("#{site_info.bad_files} files needs to be downloaded")
|
||||
# File finished downloading
|
||||
else if site_info.event[0] == "file_done"
|
||||
@loading.printLine("#{site_info.event[1]} downloaded")
|
||||
|
@ -148,5 +148,5 @@ class Wrapper
|
|||
console.log "[Wrapper]", args...
|
||||
|
||||
|
||||
ws_url = "ws://#{window.location.hostname}:#{window.location.port}/Websocket?auth_key=#{window.auth_key}"
|
||||
ws_url = "ws://#{window.location.hostname}:#{window.location.port}/Websocket?wrapper_key=#{window.wrapper_key}"
|
||||
window.wrapper = new Wrapper(ws_url)
|
||||
|
|
|
@ -852,8 +852,8 @@ jQuery.extend( jQuery.easing,
|
|||
|
||||
Wrapper.prototype.setSiteInfo = function(site_info) {
|
||||
if (site_info.event != null) {
|
||||
if (site_info.event[0] === "file_added" && site_info.bad_files.length) {
|
||||
this.loading.printLine("" + site_info.bad_files.length + " files needs to be downloaded");
|
||||
if (site_info.event[0] === "file_added" && site_info.bad_files) {
|
||||
this.loading.printLine("" + site_info.bad_files + " files needs to be downloaded");
|
||||
} else if (site_info.event[0] === "file_done") {
|
||||
this.loading.printLine("" + site_info.event[1] + " downloaded");
|
||||
if (site_info.event[1] === window.inner_path) {
|
||||
|
@ -890,7 +890,7 @@ jQuery.extend( jQuery.easing,
|
|||
|
||||
})();
|
||||
|
||||
ws_url = "ws://" + window.location.hostname + ":" + window.location.port + "/Websocket?auth_key=" + window.auth_key;
|
||||
ws_url = "ws://" + window.location.hostname + ":" + window.location.port + "/Websocket?wrapper_key=" + window.wrapper_key;
|
||||
|
||||
window.wrapper = new Wrapper(ws_url);
|
||||
|
||||
|
|
|
@ -35,12 +35,12 @@
|
|||
|
||||
|
||||
<!-- Site Iframe -->
|
||||
<iframe src='/media/{address}/{inner_path}#auth_key={auth_key}' id='inner-iframe' sandbox="allow-forms allow-scripts allow-top-navigation"></iframe>
|
||||
<iframe src='/media/{address}/{inner_path}' id='inner-iframe' sandbox="allow-forms allow-scripts allow-top-navigation"></iframe>
|
||||
|
||||
|
||||
<!-- Site info -->
|
||||
<script>address = "{address}"</script>
|
||||
<script>auth_key = "{auth_key}"</script>
|
||||
<script>wrapper_key = "{wrapper_key}"</script>
|
||||
<script>inner_path = "{inner_path}"</script>
|
||||
<script>permissions = {permissions}</script>
|
||||
<script>show_loadingscreen = {show_loadingscreen}</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue