Bootstrapper use python date functions instead of sqlite
This commit is contained in:
parent
f1c320dd22
commit
9f762a0230
2 changed files with 12 additions and 5 deletions
|
@ -20,8 +20,9 @@ class BootstrapperDb(Db):
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
while 1:
|
while 1:
|
||||||
self.execute("DELETE FROM peer WHERE date_announced < DATETIME('now', '-40 minute')")
|
|
||||||
time.sleep(4*60)
|
time.sleep(4*60)
|
||||||
|
timeout = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() - 60 * 40))
|
||||||
|
self.execute("DELETE FROM peer WHERE date_announced < ?", [timeout])
|
||||||
|
|
||||||
def updateHashCache(self):
|
def updateHashCache(self):
|
||||||
res = self.execute("SELECT * FROM hash")
|
res = self.execute("SELECT * FROM hash")
|
||||||
|
@ -96,14 +97,15 @@ class BootstrapperDb(Db):
|
||||||
res = self.execute("SELECT * FROM peer WHERE ? LIMIT 1", {"ip4": ip4, "port": port})
|
res = self.execute("SELECT * FROM peer WHERE ? LIMIT 1", {"ip4": ip4, "port": port})
|
||||||
|
|
||||||
user_row = res.fetchone()
|
user_row = res.fetchone()
|
||||||
|
now = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
if user_row:
|
if user_row:
|
||||||
peer_id = user_row["peer_id"]
|
peer_id = user_row["peer_id"]
|
||||||
self.execute("UPDATE peer SET date_announced = DATETIME('now') WHERE ?", {"peer_id": peer_id})
|
self.execute("UPDATE peer SET date_announced = ? WHERE peer_id = ?", (now, peer_id))
|
||||||
else:
|
else:
|
||||||
self.log.debug("New peer: %s %s signed: %s" % (ip4, onion, onion_signed))
|
self.log.debug("New peer: %s %s signed: %s" % (ip4, onion, onion_signed))
|
||||||
if onion and not onion_signed:
|
if onion and not onion_signed:
|
||||||
return len(hashes)
|
return len(hashes)
|
||||||
self.execute("INSERT INTO peer ?", {"ip4": ip4, "onion": onion, "port": port})
|
self.execute("INSERT INTO peer ?", {"ip4": ip4, "onion": onion, "port": port, "date_announced": now})
|
||||||
peer_id = self.cur.cursor.lastrowid
|
peer_id = self.cur.cursor.lastrowid
|
||||||
|
|
||||||
# Check user's hashes
|
# Check user's hashes
|
||||||
|
|
|
@ -163,8 +163,13 @@ class SiteStorage(object):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
# Open file object
|
# Open file object
|
||||||
def open(self, inner_path, mode="rb"):
|
def open(self, inner_path, mode="rb", create_dirs=False):
|
||||||
return open(self.getPath(inner_path), mode)
|
file_path = self.getPath(inner_path)
|
||||||
|
if create_dirs:
|
||||||
|
file_dir = os.path.dirname(file_path)
|
||||||
|
if not os.path.isdir(file_dir):
|
||||||
|
os.makedirs(file_dir)
|
||||||
|
return open(file_path, mode)
|
||||||
|
|
||||||
# Open file object
|
# Open file object
|
||||||
def read(self, inner_path, mode="r"):
|
def read(self, inner_path, mode="r"):
|
||||||
|
|
Loading…
Reference in a new issue