added addpeer command and misc bug fixes

This commit is contained in:
Kevin Froman 2018-01-29 01:05:02 -06:00
parent 71bff27245
commit dd9a54f7c6
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
4 changed files with 12 additions and 2 deletions

View File

@ -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:

View File

@ -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()

View File

@ -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():

View File

@ -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)