From dd9a54f7c671dcdf089efcfbe193752a50ecbf2f Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 29 Jan 2018 01:05:02 -0600 Subject: [PATCH] added addpeer command and misc bug fixes --- onionr/communicator.py | 1 + onionr/core.py | 3 ++- onionr/onionr.py | 8 ++++++++ onionr/tests.py | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/onionr/communicator.py b/onionr/communicator.py index 3be47f31..cfd8588a 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -133,6 +133,7 @@ class OnionrCommunicate: return def downloadBlock(self, hash): + '''download a block from random order of peers''' peerList = self._core.listPeers() blocks = '' for i in peerList: diff --git a/onionr/core.py b/onionr/core.py index 6617f1e8..0627d365 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -329,7 +329,8 @@ class Core: c = conn.cursor() command = (data, peer) # TODO: validate key on whitelist - + if key not in ('id', 'text', 'name', 'pgpKey', 'hmacKey', 'blockDBHash', 'forwardKey', 'dateSeen', 'bytesStored', 'trust'): + raise Exception("Got invalid database key when setting peer info") c.execute('UPDATE peers SET ' + key + ' = ? where id=?', command) conn.commit() conn.close() diff --git a/onionr/onionr.py b/onionr/onionr.py index a3d2bd4e..1d5e7e06 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -109,6 +109,14 @@ class Onionr: os.remove('.onionr-lock') elif command == 'stop': self.killDaemon() + elif command == 'addpeer': + try: + newPeer = sys.argv[2] + except: + pass + else: + logger.info("Adding peer.") + self.onionrCore.addPeer(newPeer) elif command in ('listpeers', 'list-peers'): logger.info('Peer list:\n') for i in self.onionrCore.listPeers(): diff --git a/onionr/tests.py b/onionr/tests.py index 8bfa971e..d296d948 100755 --- a/onionr/tests.py +++ b/onionr/tests.py @@ -51,7 +51,7 @@ class OnionrTests(unittest.TestCase): myCore = core.Core() if not os.path.exists('data/peers.db'): myCore.createPeerDB() - if myCore.addPeer('facebookcorewwwi.onion') and not myCore.addPeer('invalidpeer.onion'): + if myCore.addPeer('2ks5c5bm6zk3ejqg.onion') and not myCore.addPeer('invalidpeer.onion'): self.assertTrue(True) else: self.assertTrue(False)