use timeouts in sqlite3
This commit is contained in:
parent
b5fecdf1e8
commit
761dc9eb95
@ -120,7 +120,7 @@ class Core:
|
|||||||
|
|
||||||
events.event('pubkey_add', data = {'key': peerID}, onionr = None)
|
events.event('pubkey_add', data = {'key': peerID}, onionr = None)
|
||||||
|
|
||||||
conn = sqlite3.connect(self.peerDB)
|
conn = sqlite3.connect(self.peerDB, timeout=10)
|
||||||
hashID = self._crypto.pubKeyHashID(peerID)
|
hashID = self._crypto.pubKeyHashID(peerID)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
t = (peerID, name, 'unknown', hashID, powID, 0)
|
t = (peerID, name, 'unknown', hashID, powID, 0)
|
||||||
@ -148,7 +148,7 @@ class Core:
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
if self._utils.validateID(address):
|
if self._utils.validateID(address):
|
||||||
conn = sqlite3.connect(self.addressDB)
|
conn = sqlite3.connect(self.addressDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
# check if address is in database
|
# check if address is in database
|
||||||
# this is safe to do because the address is validated above, but we strip some chars here too just in case
|
# this is safe to do because the address is validated above, but we strip some chars here too just in case
|
||||||
@ -180,7 +180,7 @@ class Core:
|
|||||||
Remove an address from the address database
|
Remove an address from the address database
|
||||||
'''
|
'''
|
||||||
if self._utils.validateID(address):
|
if self._utils.validateID(address):
|
||||||
conn = sqlite3.connect(self.addressDB)
|
conn = sqlite3.connect(self.addressDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
t = (address,)
|
t = (address,)
|
||||||
c.execute('Delete from adders where address=?;', t)
|
c.execute('Delete from adders where address=?;', t)
|
||||||
@ -199,7 +199,7 @@ class Core:
|
|||||||
**You may want blacklist.addToDB(blockHash)
|
**You may want blacklist.addToDB(blockHash)
|
||||||
'''
|
'''
|
||||||
if self._utils.validateHash(block):
|
if self._utils.validateHash(block):
|
||||||
conn = sqlite3.connect(self.blockDB)
|
conn = sqlite3.connect(self.blockDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
t = (block,)
|
t = (block,)
|
||||||
c.execute('Delete from hashes where hash=?;', t)
|
c.execute('Delete from hashes where hash=?;', t)
|
||||||
@ -246,7 +246,7 @@ class Core:
|
|||||||
raise Exception('Block db does not exist')
|
raise Exception('Block db does not exist')
|
||||||
if self._utils.hasBlock(newHash):
|
if self._utils.hasBlock(newHash):
|
||||||
return
|
return
|
||||||
conn = sqlite3.connect(self.blockDB)
|
conn = sqlite3.connect(self.blockDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
currentTime = self._utils.getEpoch()
|
currentTime = self._utils.getEpoch()
|
||||||
if selfInsert or dataSaved:
|
if selfInsert or dataSaved:
|
||||||
@ -305,7 +305,7 @@ class Core:
|
|||||||
blockFile = open(blockFileName, 'wb')
|
blockFile = open(blockFileName, 'wb')
|
||||||
blockFile.write(data)
|
blockFile.write(data)
|
||||||
blockFile.close()
|
blockFile.close()
|
||||||
conn = sqlite3.connect(self.blockDB)
|
conn = sqlite3.connect(self.blockDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("UPDATE hashes SET dataSaved=1 WHERE hash = '" + dataHash + "';")
|
c.execute("UPDATE hashes SET dataSaved=1 WHERE hash = '" + dataHash + "';")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
@ -363,7 +363,7 @@ class Core:
|
|||||||
if not os.path.exists(self.queueDB):
|
if not os.path.exists(self.queueDB):
|
||||||
self.makeDaemonDB()
|
self.makeDaemonDB()
|
||||||
else:
|
else:
|
||||||
conn = sqlite3.connect(self.queueDB)
|
conn = sqlite3.connect(self.queueDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
try:
|
try:
|
||||||
for row in c.execute('SELECT command, data, date, min(ID) FROM commands group by id'):
|
for row in c.execute('SELECT command, data, date, min(ID) FROM commands group by id'):
|
||||||
@ -383,7 +383,7 @@ class Core:
|
|||||||
|
|
||||||
def makeDaemonDB(self):
|
def makeDaemonDB(self):
|
||||||
'''generate the daemon queue db'''
|
'''generate the daemon queue db'''
|
||||||
conn = sqlite3.connect(self.queueDB)
|
conn = sqlite3.connect(self.queueDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
# Create table
|
# Create table
|
||||||
c.execute('''CREATE TABLE commands
|
c.execute('''CREATE TABLE commands
|
||||||
@ -398,7 +398,7 @@ class Core:
|
|||||||
retData = True
|
retData = True
|
||||||
# Intended to be used by the web server
|
# Intended to be used by the web server
|
||||||
date = self._utils.getEpoch()
|
date = self._utils.getEpoch()
|
||||||
conn = sqlite3.connect(self.queueDB)
|
conn = sqlite3.connect(self.queueDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
t = (command, data, date)
|
t = (command, data, date)
|
||||||
try:
|
try:
|
||||||
@ -416,7 +416,7 @@ class Core:
|
|||||||
'''
|
'''
|
||||||
Clear the daemon queue (somewhat dangerous)
|
Clear the daemon queue (somewhat dangerous)
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.queueDB)
|
conn = sqlite3.connect(self.queueDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
try:
|
try:
|
||||||
c.execute('DELETE FROM commands;')
|
c.execute('DELETE FROM commands;')
|
||||||
@ -432,7 +432,7 @@ class Core:
|
|||||||
'''
|
'''
|
||||||
Return a list of addresses
|
Return a list of addresses
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.addressDB)
|
conn = sqlite3.connect(self.addressDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
if randomOrder:
|
if randomOrder:
|
||||||
addresses = c.execute('SELECT * FROM adders ORDER BY RANDOM();')
|
addresses = c.execute('SELECT * FROM adders ORDER BY RANDOM();')
|
||||||
@ -451,7 +451,7 @@ class Core:
|
|||||||
randomOrder determines if the list should be in a random order
|
randomOrder determines if the list should be in a random order
|
||||||
trust sets the minimum trust to list
|
trust sets the minimum trust to list
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.peerDB)
|
conn = sqlite3.connect(self.peerDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
payload = ""
|
payload = ""
|
||||||
if trust not in (0, 1, 2):
|
if trust not in (0, 1, 2):
|
||||||
@ -495,7 +495,7 @@ class Core:
|
|||||||
hashID text 7
|
hashID text 7
|
||||||
pow text 8
|
pow text 8
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.peerDB)
|
conn = sqlite3.connect(self.peerDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
command = (peer,)
|
command = (peer,)
|
||||||
infoNumbers = {'id': 0, 'name': 1, 'adders': 2, 'dateSeen': 3, 'bytesStored': 4, 'trust': 5, 'pubkeyExchanged': 6, 'hashID': 7}
|
infoNumbers = {'id': 0, 'name': 1, 'adders': 2, 'dateSeen': 3, 'bytesStored': 4, 'trust': 5, 'pubkeyExchanged': 6, 'hashID': 7}
|
||||||
@ -517,7 +517,7 @@ class Core:
|
|||||||
'''
|
'''
|
||||||
Update a peer for a key
|
Update a peer for a key
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.peerDB)
|
conn = sqlite3.connect(self.peerDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
command = (data, peer)
|
command = (data, peer)
|
||||||
# TODO: validate key on whitelist
|
# TODO: validate key on whitelist
|
||||||
@ -541,7 +541,7 @@ class Core:
|
|||||||
failure int 6
|
failure int 6
|
||||||
lastConnect 7
|
lastConnect 7
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.addressDB)
|
conn = sqlite3.connect(self.addressDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
command = (address,)
|
command = (address,)
|
||||||
infoNumbers = {'address': 0, 'type': 1, 'knownPeer': 2, 'speed': 3, 'success': 4, 'DBHash': 5, 'failure': 6, 'lastConnect': 7}
|
infoNumbers = {'address': 0, 'type': 1, 'knownPeer': 2, 'speed': 3, 'success': 4, 'DBHash': 5, 'failure': 6, 'lastConnect': 7}
|
||||||
@ -562,7 +562,7 @@ class Core:
|
|||||||
'''
|
'''
|
||||||
Update an address for a key
|
Update an address for a key
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.addressDB)
|
conn = sqlite3.connect(self.addressDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
command = (data, address)
|
command = (data, address)
|
||||||
# TODO: validate key on whitelist
|
# TODO: validate key on whitelist
|
||||||
@ -578,7 +578,7 @@ class Core:
|
|||||||
'''
|
'''
|
||||||
Get list of our blocks
|
Get list of our blocks
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.blockDB)
|
conn = sqlite3.connect(self.blockDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
if unsaved:
|
if unsaved:
|
||||||
execute = 'SELECT hash FROM hashes WHERE dataSaved != 1 ORDER BY RANDOM();'
|
execute = 'SELECT hash FROM hashes WHERE dataSaved != 1 ORDER BY RANDOM();'
|
||||||
@ -595,7 +595,7 @@ class Core:
|
|||||||
'''
|
'''
|
||||||
Returns the date a block was received
|
Returns the date a block was received
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.blockDB)
|
conn = sqlite3.connect(self.blockDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
execute = 'SELECT dateReceived FROM hashes WHERE hash=?;'
|
execute = 'SELECT dateReceived FROM hashes WHERE hash=?;'
|
||||||
args = (blockHash,)
|
args = (blockHash,)
|
||||||
@ -609,7 +609,7 @@ class Core:
|
|||||||
'''
|
'''
|
||||||
Returns a list of blocks by the type
|
Returns a list of blocks by the type
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.blockDB)
|
conn = sqlite3.connect(self.blockDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
if orderDate:
|
if orderDate:
|
||||||
execute = 'SELECT hash FROM hashes WHERE dataType=? ORDER BY dateReceived;'
|
execute = 'SELECT hash FROM hashes WHERE dataType=? ORDER BY dateReceived;'
|
||||||
@ -628,7 +628,7 @@ class Core:
|
|||||||
Sets the type of block
|
Sets the type of block
|
||||||
'''
|
'''
|
||||||
|
|
||||||
conn = sqlite3.connect(self.blockDB)
|
conn = sqlite3.connect(self.blockDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("UPDATE hashes SET dataType='" + blockType + "' WHERE hash = '" + hash + "';")
|
c.execute("UPDATE hashes SET dataType='" + blockType + "' WHERE hash = '" + hash + "';")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
@ -653,7 +653,7 @@ class Core:
|
|||||||
if key not in ('dateReceived', 'decrypted', 'dataType', 'dataFound', 'dataSaved', 'sig', 'author', 'dateClaimed'):
|
if key not in ('dateReceived', 'decrypted', 'dataType', 'dataFound', 'dataSaved', 'sig', 'author', 'dateClaimed'):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
conn = sqlite3.connect(self.blockDB)
|
conn = sqlite3.connect(self.blockDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
args = (data, hash)
|
args = (data, hash)
|
||||||
c.execute("UPDATE hashes SET " + key + " = ? where hash = ?;", args)
|
c.execute("UPDATE hashes SET " + key + " = ? where hash = ?;", args)
|
||||||
|
@ -69,7 +69,7 @@ class OnionrUser:
|
|||||||
|
|
||||||
def _getLatestForwardKey(self):
|
def _getLatestForwardKey(self):
|
||||||
# Get the latest forward secrecy key for a peer
|
# Get the latest forward secrecy key for a peer
|
||||||
conn = sqlite3.connect(self._core.peerDB)
|
conn = sqlite3.connect(self._core.peerDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
for row in c.execute("SELECT forwardKey FROM forwardKeys WHERE peerKey = ? AND date=(SELECT max(date) FROM forwardKeys)", (self.publicKey,)):
|
for row in c.execute("SELECT forwardKey FROM forwardKeys WHERE peerKey = ? AND date=(SELECT max(date) FROM forwardKeys)", (self.publicKey,)):
|
||||||
@ -81,7 +81,7 @@ class OnionrUser:
|
|||||||
return key
|
return key
|
||||||
|
|
||||||
def _getForwardKeys(self):
|
def _getForwardKeys(self):
|
||||||
conn = sqlite3.connect(self._core.peerDB)
|
conn = sqlite3.connect(self._core.peerDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
keyList = []
|
keyList = []
|
||||||
for row in c.execute("SELECT forwardKey FROM forwardKeys WHERE peerKey = ?", (self.publicKey,)):
|
for row in c.execute("SELECT forwardKey FROM forwardKeys WHERE peerKey = ?", (self.publicKey,)):
|
||||||
@ -96,7 +96,7 @@ class OnionrUser:
|
|||||||
def generateForwardKey(self, expire=432000):
|
def generateForwardKey(self, expire=432000):
|
||||||
|
|
||||||
# Generate a forward secrecy key for the peer
|
# Generate a forward secrecy key for the peer
|
||||||
conn = sqlite3.connect(self._core.forwardKeysFile)
|
conn = sqlite3.connect(self._core.forwardKeysFile, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
# Prepare the insert
|
# Prepare the insert
|
||||||
time = self._core._utils.getEpoch()
|
time = self._core._utils.getEpoch()
|
||||||
@ -117,7 +117,7 @@ class OnionrUser:
|
|||||||
if not self._core._utils.validatePubKey(newKey):
|
if not self._core._utils.validatePubKey(newKey):
|
||||||
raise onionrexceptions.InvalidPubkey
|
raise onionrexceptions.InvalidPubkey
|
||||||
# Add a forward secrecy key for the peer
|
# Add a forward secrecy key for the peer
|
||||||
conn = sqlite3.connect(self._core.peerDB)
|
conn = sqlite3.connect(self._core.peerDB, timeout=10)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
# Prepare the insert
|
# Prepare the insert
|
||||||
time = self._core._utils.getEpoch()
|
time = self._core._utils.getEpoch()
|
||||||
|
Loading…
Reference in New Issue
Block a user