work on processing blocks

master
Kevin Froman 2018-01-26 19:16:15 -06:00
parent 64b14720c1
commit cb63941fc9
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 24 additions and 14 deletions

View File

@ -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/>.
'''
import sqlite3, requests, hmac, hashlib, time, sys, os, logger
import core
import core, onionrutils
class OnionrCommunicate:
def __init__(self, debug, developmentMode):
''' OnionrCommunicate
@ -28,6 +28,7 @@ class OnionrCommunicate:
This class handles communication with nodes in the Onionr network.
'''
self._core = core.Core()
self._utils = onionrutils.OnionrUtils(self._core)
blockProcessTimer = 0
blockProcessAmount = 5
logger.debug('Communicator debugging enabled.')
@ -40,7 +41,7 @@ class OnionrCommunicate:
with open(fingerprintFile,'r') as f:
self.pgpOwnFingerprint = f.read()
logger.info('My PGP fingerprint is ' + logger.colors.underline + self.pgpOwnFingerprint + logger.colors.reset + logger.colors.fg.green + '.')
self._core.clearDaemonQueue()
while True:
command = self._core.daemonQueue()
@ -84,17 +85,17 @@ class OnionrCommunicate:
for i in peerList:
lastDB = self._core.getPeerInfo(i, 'blockDBHash')
currentDB = self.performGet('getDBHash', i)
if lastDB != currentDB:
blocks += self.performGet('getBlockHashes', i)
if currentDB != False:
if lastDB != currentDB:
blocks += self.performGet('getBlockHashes', i)
blockList = blocks.split('\n')
for i in blockList:
if not self._core.validateHash(i):
if not self._utils.validateHash(i):
# skip hash if it isn't valid
continue
else:
logger.debug('Adding ' + i + ' to hash database...')
self._core.addToBlockDB(i)
return
def performGet(self, action, peer, data=None, type='tor'):
@ -115,7 +116,7 @@ class OnionrCommunicate:
shouldRun = False
debug = False
debug = True
developmentMode = False
if os.path.exists('dev-enabled'):
developmentMode = True

View File

@ -228,6 +228,13 @@ class Core:
conn.commit()
conn.close()
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):
'''
@ -253,11 +260,8 @@ class Core:
Work with the block database and download any missing blocks
This is meant to be called from the communicator daemon on its timer.
'''
conn = sqlite3.connect(self.blockDB)
c = conn.cursor()
for i in blocks:
pass
conn.close()
for i in self.getBlockList(True):
print('UNSAVED BLOCK:', i)
return
def getPeerInfo(self, peer, info):
'''
@ -291,12 +295,16 @@ class Core:
conn.close()
return retVal
def getBlockList(self):
def getBlockList(self, unsaved=False):
'''get list of our blocks'''
conn = sqlite3.connect(self.blockDB)
c = conn.cursor()
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:
retData += i
return retData

View File

@ -70,6 +70,7 @@ class OnionrUtils:
sock.close()
return retVal
def checkIsIP(self, ip):
'''Check if a string is a valid ipv4 address'''
try:
socket.inet_aton(ip)
except: