Added rate-limiting to GUI. After 20 404 errors, server automatically stops (#238)

This commit is contained in:
Micah Lee 2016-04-12 16:49:46 -07:00
parent b47ef630d5
commit d35b5a9acd
3 changed files with 27 additions and 2 deletions

View file

@ -142,6 +142,10 @@ class OnionShareGui(QtWidgets.QMainWindow):
Start the onionshare server. This uses multiple threads to start the Tor hidden
server and the web app.
"""
# Reset web counters
web.download_count = 0
web.error404_count = 0
# start the hidden service
self.status_bar.showMessage(strings._('gui_starting_server1', True))
self.app.choose_port()
@ -214,6 +218,10 @@ class OnionShareGui(QtWidgets.QMainWindow):
elif event["type"] == web.REQUEST_DOWNLOAD:
self.downloads.add_download(event["data"]["id"], web.zip_filesize)
elif event["type"] == web.REQUEST_RATE_LIMIT:
self.stop_server()
alert(strings._('error_rate_limit'), QtWidgets.QMessageBox.Critical)
elif event["type"] == web.REQUEST_PROGRESS:
self.downloads.update_download(event["data"]["id"], event["data"]["bytes"])
@ -227,7 +235,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.downloads.cancel_download(event["data"]["id"])
elif event["path"] != '/favicon.ico':
self.status_bar.showMessage('{0:s}: {1:s}'.format(strings._('other_page_loaded', True), event["path"]))
self.status_bar.showMessage('[#{0:d}] {1:s}: {2:s}'.format(web.error404_count, strings._('other_page_loaded', True), event["path"]))
def copy_url(self):
"""