From 77a847a0b707670db754df904786760c1939bc2f Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 9 Jun 2018 01:21:14 -0500 Subject: [PATCH] * fixed addpeer command to work with pow * improved stats screen to show pow token for your key --- onionr/api.py | 1 - onionr/onionr.py | 28 ++++++++++++++++++++++++---- onionr/onionrutils.py | 3 ++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/onionr/api.py b/onionr/api.py index 3a23c8d6..34a05419 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -214,7 +214,6 @@ class API: if not os.path.exists('data/blocks/' + data + '.db'): block = Block(data.encode(), core=self._core) resp = base64.b64encode(block.getRaw().encode()).decode() - if len(resp) == 0: abort(404) resp = "" diff --git a/onionr/onionr.py b/onionr/onionr.py index 3e386555..15bada6f 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -32,6 +32,7 @@ import onionrutils from onionrutils import OnionrUtils from netcontroller import NetController from onionrblockapi import Block +import onionrproofs try: from urllib3.contrib.socks import SOCKSProxyManager @@ -359,14 +360,31 @@ class Onionr: ''' Adds a peer (?) ''' - try: newPeer = sys.argv[2] except: pass else: + if self.onionrUtils.hasKey(newPeer): + logger.info('We already have that key') + return + if not '-' in newPeer: + logger.info('Since no POW token was supplied for that key, one is being generated') + proof = onionrproofs.POW(newPeer) + while True: + result = proof.getResult() + if result == False: + time.sleep(0.5) + else: + break + newPeer += '-' + base64.b64encode(result[1]).decode() + logger.info(newPeer) + logger.info("Adding peer: " + logger.colors.underline + newPeer) - self.onionrCore.addPeer(newPeer) + if self.onionrUtils.mergeKeys(newPeer): + logger.info('Successfully added key') + else: + logger.error('Failed to add key') return @@ -578,12 +596,14 @@ class Onionr: # define stats messages here totalBlocks = len(Block.getBlocks()) signedBlocks = len(Block.getBlocks(signed = True)) - + powToken = self.onionrCore._crypto.pubKeyPowToken messages = { # info about local client 'Onionr Daemon Status' : ((logger.colors.fg.green + 'Online') if self.onionrUtils.isCommunicatorRunning(timeout = 2) else logger.colors.fg.red + 'Offline'), 'Public Key' : self.onionrCore._crypto.pubKey, - 'Address' : self.get_hostname(), + 'POW Token' : powToken, + 'Combined' : self.onionrCore._crypto.pubKey + '-' + powToken, + 'Node Address' : self.get_hostname(), # file and folder size stats 'div1' : True, # this creates a solid line across the screen, a div diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 72c52c90..378cd0b3 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -122,8 +122,9 @@ class OnionrUtils: if not key[0] in self._core.listPeers(randomOrder=False) and type(key) != None and key[0] != self._core._crypto.pubKey: if self._core.addPeer(key[0], key[1]): retVal = True + else: + logger.warn("Failed to add key") else: - logger.warn(powHash) logger.warn('%s pow failed' % key[0]) return retVal except Exception as error: