Version 0.3.5, Rev830, Full Tor mode support with hidden services, Onion stats in Sidebar, GeoDB download fix using Tor, Gray out disabled sites in Stats page, Tor hidden service status in stat page, Benchmark sha256, Skyts tracker out expodie in, 2 new tracker using ZeroNet protocol, Keep SSL cert option between restarts, SSL Certificate pinning support for connections, Site lock support for connections, Certificate pinned connections using implicit SSL, Flood protection whitelist support, Foreign keys support for DB layer, Not support for SQL query helper, 0 length file get bugfix, Pex onion address support, Faster port testing, Faster uPnP port opening, Need connections more often on owned sites, Delay ZeroHello startup message if port check or Tor manager not ready yet, Use lockfiles to avoid double start, Save original socket on proxy monkey patching to get ability to connect localhost directly, Handle atomic write errors, Broken gevent https workaround helper, Rsa crypt functions, Plugin to Bootstrap using ZeroNet protocol

This commit is contained in:
HelloZeroNet 2016-01-05 00:20:52 +01:00
parent c9578e9037
commit e9d2cdfd37
99 changed files with 9476 additions and 267 deletions

View file

@ -22,7 +22,7 @@ def dbCleanup():
gevent.spawn(dbCleanup)
class Db:
class Db(object):
def __init__(self, schema, db_path):
self.db_path = db_path
@ -34,6 +34,7 @@ class Db:
self.log = logging.getLogger("Db:%s" % schema["db_name"])
self.table_names = None
self.collect_stats = False
self.foreign_keys = False
self.query_stats = {}
self.db_keyvalues = {}
self.last_query_time = time.time()
@ -59,6 +60,9 @@ class Db:
self.cur.execute("PRAGMA journal_mode = WAL")
self.cur.execute("PRAGMA journal_mode = MEMORY")
self.cur.execute("PRAGMA synchronous = OFF")
if self.foreign_keys:
self.execute("PRAGMA foreign_keys = ON")
# Execute query using dbcursor
def execute(self, query, params=None):

View file

@ -13,17 +13,23 @@ class DbCursor:
self.logging = False
def execute(self, query, params=None):
if isinstance(params, dict): # Make easier select and insert by allowing dict params
if query.startswith("SELECT") or query.startswith("DELETE"):
if isinstance(params, dict) and "?" in query: # Make easier select and insert by allowing dict params
if query.startswith("SELECT") or query.startswith("DELETE") or query.startswith("UPDATE"):
# Convert param dict to SELECT * FROM table WHERE key = ? AND key2 = ? format
query_wheres = []
values = []
for key, value in params.items():
if type(value) is list:
query_wheres.append(key+" IN ("+",".join(["?"]*len(value))+")")
if key.startswith("not__"):
query_wheres.append(key.replace("not__", "")+" NOT IN ("+",".join(["?"]*len(value))+")")
else:
query_wheres.append(key+" IN ("+",".join(["?"]*len(value))+")")
values += value
else:
query_wheres.append(key+" = ?")
if key.startswith("not__"):
query_wheres.append(key.replace("not__", "")+" != ?")
else:
query_wheres.append(key+" = ?")
values.append(value)
wheres = " AND ".join(query_wheres)
query = query.replace("?", wheres)
@ -41,7 +47,7 @@ class DbCursor:
if params: # Query has parameters
res = self.cursor.execute(query, params)
if self.logging:
self.db.log.debug((query.replace("?", "%s") % params) + " (Done in %.4f)" % (time.time() - s))
self.db.log.debug(query + " " + str(params) + " (Done in %.4f)" % (time.time() - s))
else:
res = self.cursor.execute(query)
if self.logging: