work on processing blocks
parent
64b14720c1
commit
cb63941fc9
|
@ -20,7 +20,7 @@ and code to operate as a daemon, getting commands from the command queue databas
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
import sqlite3, requests, hmac, hashlib, time, sys, os, logger
|
import sqlite3, requests, hmac, hashlib, time, sys, os, logger
|
||||||
import core
|
import core, onionrutils
|
||||||
class OnionrCommunicate:
|
class OnionrCommunicate:
|
||||||
def __init__(self, debug, developmentMode):
|
def __init__(self, debug, developmentMode):
|
||||||
''' OnionrCommunicate
|
''' OnionrCommunicate
|
||||||
|
@ -28,6 +28,7 @@ class OnionrCommunicate:
|
||||||
This class handles communication with nodes in the Onionr network.
|
This class handles communication with nodes in the Onionr network.
|
||||||
'''
|
'''
|
||||||
self._core = core.Core()
|
self._core = core.Core()
|
||||||
|
self._utils = onionrutils.OnionrUtils(self._core)
|
||||||
blockProcessTimer = 0
|
blockProcessTimer = 0
|
||||||
blockProcessAmount = 5
|
blockProcessAmount = 5
|
||||||
logger.debug('Communicator debugging enabled.')
|
logger.debug('Communicator debugging enabled.')
|
||||||
|
@ -40,7 +41,7 @@ class OnionrCommunicate:
|
||||||
with open(fingerprintFile,'r') as f:
|
with open(fingerprintFile,'r') as f:
|
||||||
self.pgpOwnFingerprint = f.read()
|
self.pgpOwnFingerprint = f.read()
|
||||||
logger.info('My PGP fingerprint is ' + logger.colors.underline + self.pgpOwnFingerprint + logger.colors.reset + logger.colors.fg.green + '.')
|
logger.info('My PGP fingerprint is ' + logger.colors.underline + self.pgpOwnFingerprint + logger.colors.reset + logger.colors.fg.green + '.')
|
||||||
|
self._core.clearDaemonQueue()
|
||||||
while True:
|
while True:
|
||||||
command = self._core.daemonQueue()
|
command = self._core.daemonQueue()
|
||||||
|
|
||||||
|
@ -84,17 +85,17 @@ class OnionrCommunicate:
|
||||||
for i in peerList:
|
for i in peerList:
|
||||||
lastDB = self._core.getPeerInfo(i, 'blockDBHash')
|
lastDB = self._core.getPeerInfo(i, 'blockDBHash')
|
||||||
currentDB = self.performGet('getDBHash', i)
|
currentDB = self.performGet('getDBHash', i)
|
||||||
if lastDB != currentDB:
|
if currentDB != False:
|
||||||
blocks += self.performGet('getBlockHashes', i)
|
if lastDB != currentDB:
|
||||||
|
blocks += self.performGet('getBlockHashes', i)
|
||||||
blockList = blocks.split('\n')
|
blockList = blocks.split('\n')
|
||||||
for i in blockList:
|
for i in blockList:
|
||||||
if not self._core.validateHash(i):
|
if not self._utils.validateHash(i):
|
||||||
# skip hash if it isn't valid
|
# skip hash if it isn't valid
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
logger.debug('Adding ' + i + ' to hash database...')
|
logger.debug('Adding ' + i + ' to hash database...')
|
||||||
self._core.addToBlockDB(i)
|
self._core.addToBlockDB(i)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def performGet(self, action, peer, data=None, type='tor'):
|
def performGet(self, action, peer, data=None, type='tor'):
|
||||||
|
@ -115,7 +116,7 @@ class OnionrCommunicate:
|
||||||
|
|
||||||
|
|
||||||
shouldRun = False
|
shouldRun = False
|
||||||
debug = False
|
debug = True
|
||||||
developmentMode = False
|
developmentMode = False
|
||||||
if os.path.exists('dev-enabled'):
|
if os.path.exists('dev-enabled'):
|
||||||
developmentMode = True
|
developmentMode = True
|
||||||
|
|
|
@ -228,6 +228,13 @@ class Core:
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return
|
return
|
||||||
|
def clearDaemonQueue(self):
|
||||||
|
'''clear the daemon queue (somewhat dangerousous)'''
|
||||||
|
conn = sqlite3.connect(self.queueDB)
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute('Delete from commands;')
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
def generateHMAC(self):
|
def generateHMAC(self):
|
||||||
'''
|
'''
|
||||||
|
@ -253,11 +260,8 @@ class Core:
|
||||||
Work with the block database and download any missing blocks
|
Work with the block database and download any missing blocks
|
||||||
This is meant to be called from the communicator daemon on its timer.
|
This is meant to be called from the communicator daemon on its timer.
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.blockDB)
|
for i in self.getBlockList(True):
|
||||||
c = conn.cursor()
|
print('UNSAVED BLOCK:', i)
|
||||||
for i in blocks:
|
|
||||||
pass
|
|
||||||
conn.close()
|
|
||||||
return
|
return
|
||||||
def getPeerInfo(self, peer, info):
|
def getPeerInfo(self, peer, info):
|
||||||
'''
|
'''
|
||||||
|
@ -291,12 +295,16 @@ class Core:
|
||||||
conn.close()
|
conn.close()
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def getBlockList(self):
|
def getBlockList(self, unsaved=False):
|
||||||
'''get list of our blocks'''
|
'''get list of our blocks'''
|
||||||
conn = sqlite3.connect(self.blockDB)
|
conn = sqlite3.connect(self.blockDB)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
retData = ''
|
retData = ''
|
||||||
for row in c.execute('SELECT hash FROM hashes;'):
|
if unsaved:
|
||||||
|
execute = 'SELECT hash FROM hashes where dataSaved != 1;'
|
||||||
|
else:
|
||||||
|
execute = 'SELECT hash FROM hashes;'
|
||||||
|
for row in c.execute(execute):
|
||||||
for i in row:
|
for i in row:
|
||||||
retData += i
|
retData += i
|
||||||
return retData
|
return retData
|
||||||
|
|
|
@ -70,6 +70,7 @@ class OnionrUtils:
|
||||||
sock.close()
|
sock.close()
|
||||||
return retVal
|
return retVal
|
||||||
def checkIsIP(self, ip):
|
def checkIsIP(self, ip):
|
||||||
|
'''Check if a string is a valid ipv4 address'''
|
||||||
try:
|
try:
|
||||||
socket.inet_aton(ip)
|
socket.inet_aton(ip)
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Reference in New Issue