Add run check to node introduction function

master
Arinerron 2018-05-01 23:25:44 -07:00
parent c144bc40b3
commit cfb1986ad0
No known key found for this signature in database
GPG Key ID: 99383627861C62F0
2 changed files with 31 additions and 14 deletions

View File

@ -611,12 +611,15 @@ class Core:
''' '''
Inserts a block into the network Inserts a block into the network
''' '''
try: try:
data.decode() data.decode()
except AttributeError: except AttributeError:
data = data.encode() data = data.encode()
retData = '' retData = ''
metadata = {'type': header} metadata = {'type': header}
if sign: if sign:
signature = self._crypto.edSign(data, self._crypto.privKey, encodeResult=True) signature = self._crypto.edSign(data, self._crypto.privKey, encodeResult=True)
ourID = self._crypto.pubKeyHashID() ourID = self._crypto.pubKeyHashID()
@ -627,8 +630,10 @@ class Core:
pass pass
metadata['id'] = ourID metadata['id'] = ourID
metadata['sig'] = signature metadata['sig'] = signature
metadata = json.dumps(metadata) metadata = json.dumps(metadata)
metadata = metadata.encode() metadata = metadata.encode()
if len(data) == 0: if len(data) == 0:
logger.error('Will not insert empty block') logger.error('Will not insert empty block')
else: else:
@ -642,16 +647,28 @@ class Core:
''' '''
Introduces our node into the network by telling X many nodes our HS address Introduces our node into the network by telling X many nodes our HS address
''' '''
if(self._utils.isCommunicatorRunning()):
announceAmount = 2 announceAmount = 2
nodeList = self.listAdders() nodeList = self.listAdders()
if len(nodeList) == 0: if len(nodeList) == 0:
for i in self.bootstrapList: for i in self.bootstrapList:
if self._utils.validateID(i): if self._utils.validateID(i):
self.addAddress(i) self.addAddress(i)
nodeList.append(i) nodeList.append(i)
if announceAmount > len(nodeList): if announceAmount > len(nodeList):
announceAmount = len(nodeList) announceAmount = len(nodeList)
for i in range(announceAmount): for i in range(announceAmount):
self.daemonQueueAdd('announceNode', nodeList[i]) self.daemonQueueAdd('announceNode', nodeList[i])
events.event('introduction', onionr = None) events.event('introduction', onionr = None)
return True
else:
logger.error('Onionr daemon is not running.')
return False
return return

View File

@ -203,13 +203,13 @@ class Onionr:
'disable-plugin': 'Disables and stops a plugin', 'disable-plugin': 'Disables and stops a plugin',
'reload-plugin': 'Reloads a plugin', 'reload-plugin': 'Reloads a plugin',
'create-plugin': 'Creates directory structure for a plugin', 'create-plugin': 'Creates directory structure for a plugin',
'add-peer': 'Adds a peer (?)', 'add-peer': 'Adds a peer to database',
'list-peers': 'Displays a list of peers', 'list-peers': 'Displays a list of peers',
'add-msg': 'Broadcasts a message to the Onionr network', 'add-msg': 'Broadcasts a message to the Onionr network',
'pm': 'Adds a private message to block', 'pm': 'Adds a private message to block',
'get-pms': 'Shows private messages sent to you', 'get-pms': 'Shows private messages sent to you',
'addfile': 'Create an Onionr block from a file', 'addfile': 'Create an Onionr block from a file',
'introduce': 'Introduce your node to the public Onionr network (DAEMON MUST BE RUNNING)', 'introduce': 'Introduce your node to the public Onionr network',
} }
# initialize plugins # initialize plugins