From f39ab33517541f4ab555f6e1515f88d843def39b Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 22 Feb 2018 02:41:05 -0600 Subject: [PATCH] added hash validation test and cleaned up output --- onionr/api.py | 5 +++-- onionr/communicator.py | 5 +++-- onionr/tests.py | 12 +++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/onionr/api.py b/onionr/api.py index 666b7783..df5d2236 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -62,7 +62,8 @@ class API: bindPort = int(self.config['CLIENT']['PORT']) self.bindPort = bindPort self.clientToken = self.config['CLIENT']['CLIENT HMAC'] - logger.debug('Your HMAC token: ' + logger.colors.underline + self.clientToken) + if not os.environ.get("WERKZEUG_RUN_MAIN") == "true": + logger.debug('Your HMAC token: ' + logger.colors.underline + self.clientToken) if not debug and not self._developmentMode: hostNums = [random.randint(1, 255), random.randint(1, 255), random.randint(1, 255)] @@ -174,7 +175,7 @@ class API: return resp if not os.environ.get("WERKZEUG_RUN_MAIN") == "true": logger.info('Starting client on ' + self.host + ':' + str(bindPort) + '...') - logger.debug('Client token: ' + logger.colors.underline + self.clientToken) + #logger.debug('Client token: ' + logger.colors.underline + self.clientToken) app.run(host=self.host, port=bindPort, debug=True, threaded=True) diff --git a/onionr/communicator.py b/onionr/communicator.py index 4b6e49a8..b11d2b12 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -35,7 +35,7 @@ class OnionrCommunicate: blockProcessTimer = 0 blockProcessAmount = 5 heartBeatTimer = 0 - heartBeatRate = 10 + heartBeatRate = 100 logger.debug('Communicator debugging enabled.') torID = open('data/hs/hostname').read() @@ -87,7 +87,8 @@ class OnionrCommunicate: blocks += self.performGet('getBlockHashes', i) if self._utils.validateHash(currentDB): self._core.setPeerInfo(i, "blockDBHash", currentDB) - logger.debug('BLOCKS: \n' + blocks) + if len(blocks.strip()) != 0: + logger.debug('BLOCKS:' + blocks) blockList = blocks.split('\n') for i in blockList: if len(i.strip()) == 0: diff --git a/onionr/tests.py b/onionr/tests.py index 5728055c..e74c1c5b 100755 --- a/onionr/tests.py +++ b/onionr/tests.py @@ -105,5 +105,15 @@ class OnionrTests(unittest.TestCase): if command[0] == 'testCommand': if myCore.daemonQueue() == False: logger.info('Succesfully added and read command') - + + def testHashValidation(self): + logger.debug('--------------------------') + logger.info('Running hash validation test...') + import core + myCore = core.Core() + if not myCore._utils.validateHash("$324dfgfdg") and myCore._utils.validateHash("f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2") and not myCore._utils.validateHash("f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd$"): + self.assertTrue(True) + else: + self.assertTrue(False) + unittest.main()