added address add command and test
This commit is contained in:
parent
3033de1d9e
commit
d0593ef300
@ -149,6 +149,11 @@ class API:
|
|||||||
abort(404)
|
abort(404)
|
||||||
resp = ""
|
resp = ""
|
||||||
resp = Response(resp)
|
resp = Response(resp)
|
||||||
|
elif action == 'pex':
|
||||||
|
response = ','.join(self._core.listAdders())
|
||||||
|
if len(response) == 0:
|
||||||
|
response = 'none'
|
||||||
|
resp = Response(response)
|
||||||
else:
|
else:
|
||||||
resp = Response("")
|
resp = Response("")
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 90d5edad0c017cec1a3b190d9b0cd08321840ed8
|
Subproject commit a74e826e9c69e643ead7950f9f76a05ab8664ddc
|
@ -72,6 +72,32 @@ class Core:
|
|||||||
conn.close()
|
conn.close()
|
||||||
return True
|
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):
|
def createAddressDB(self):
|
||||||
'''
|
'''
|
||||||
Generate the address database
|
Generate the address database
|
||||||
|
@ -146,7 +146,10 @@ class Onionr:
|
|||||||
'pm': self.sendEncrypt,
|
'pm': self.sendEncrypt,
|
||||||
'gui': self.openGUI,
|
'gui': self.openGUI,
|
||||||
'addpeer': self.addPeer,
|
'addpeer': self.addPeer,
|
||||||
'add-peer': self.addPeer
|
'add-peer': self.addPeer,
|
||||||
|
'add-address': self.addAddress,
|
||||||
|
'connect': self.addAddress,
|
||||||
|
'addaddress': self.addAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
def getHelp(self):
|
def getHelp(self):
|
||||||
@ -252,6 +255,19 @@ class Onionr:
|
|||||||
logger.info("Adding peer: " + logger.colors.underline + newPeer)
|
logger.info("Adding peer: " + logger.colors.underline + newPeer)
|
||||||
self.onionrCore.addPeer(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):
|
def addMessage(self):
|
||||||
'''
|
'''
|
||||||
Broadcasts a message to the Onionr network
|
Broadcasts a message to the Onionr network
|
||||||
|
@ -116,4 +116,16 @@ class OnionrTests(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.assertTrue(False)
|
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()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user