added address add command and test

This commit is contained in:
Kevin Froman 2018-02-27 15:23:49 -06:00
parent 3033de1d9e
commit d0593ef300
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
5 changed files with 63 additions and 4 deletions

View File

@ -149,6 +149,11 @@ class API:
abort(404)
resp = ""
resp = Response(resp)
elif action == 'pex':
response = ','.join(self._core.listAdders())
if len(response) == 0:
response = 'none'
resp = Response(response)
else:
resp = Response("")

@ -1 +1 @@
Subproject commit 90d5edad0c017cec1a3b190d9b0cd08321840ed8
Subproject commit a74e826e9c69e643ead7950f9f76a05ab8664ddc

View File

@ -71,7 +71,33 @@ class Core:
conn.commit()
conn.close()
return True
def addAddress(self, address):
'''Add an address to the address database (only tor currently)'''
if self._utils.validateID(address):
conn = sqlite3.connect(self.addressDB)
c = conn.cursor()
t = (address, 1)
c.execute('INSERT INTO adders (address, type) VALUES(?, ?);', t)
conn.commit()
conn.close()
return True
else:
return False
def removeAddress(self, address):
'''Remove an address from the address database'''
if self._utils.validateID(address):
conn = sqlite3.connect(self.addressDB)
c = conn.cursor()
t = (address,)
c.execute('Delete from adders where address=?;', t)
conn.commit()
conn.close()
return True
else:
return False
def createAddressDB(self):
'''
Generate the address database

View File

@ -146,7 +146,10 @@ class Onionr:
'pm': self.sendEncrypt,
'gui': self.openGUI,
'addpeer': self.addPeer,
'add-peer': self.addPeer
'add-peer': self.addPeer,
'add-address': self.addAddress,
'connect': self.addAddress,
'addaddress': self.addAddress
}
def getHelp(self):
@ -251,6 +254,19 @@ class Onionr:
else:
logger.info("Adding peer: " + logger.colors.underline + newPeer)
self.onionrCore.addPeer(newPeer)
def addAddress(self):
'''Adds a Onionr node address'''
try:
newAddress = sys.argv[2]
except:
pass
else:
logger.info("Adding address: " + logger.colors.underline + newAddress)
if self.onionrCore.addAddress(newAddress):
logger.info("Successfully added address")
else:
logger.warn("Unable to add address")
def addMessage(self):
'''

View File

@ -115,5 +115,17 @@ class OnionrTests(unittest.TestCase):
self.assertTrue(True)
else:
self.assertTrue(False)
def testAddAdder(self):
logger.debug('--------------------------')
logger.info('Running address add+remove test')
import core
myCore = core.Core()
if myCore.addAddress('facebookcorewwwi.onion') and not myCore.removeAddress('invalid'):
if myCore.removeAddress('facebookcorewwwi.onion'):
self.assertTrue(True)
else:
self.assertTrue(False)
else:
self.assertTrue(False)
unittest.main()