Cleanup and fixes

This commit is contained in:
Kevin 2018-12-13 04:35:01 +00:00
parent c0bfe102d5
commit 993e5ae4c7
4 changed files with 26 additions and 41 deletions

View File

@ -513,17 +513,18 @@ class Core:
speed int, 3 speed int, 3
success int, 4 success int, 4
DBHash text, 5 DBHash text, 5
failure int 6 powValue 6
lastConnect 7 failure int 7
trust 8 lastConnect 8
introduced 9 trust 9
introduced 10
''' '''
conn = sqlite3.connect(self.addressDB, timeout=10) conn = sqlite3.connect(self.addressDB, timeout=10)
c = conn.cursor() c = conn.cursor()
command = (address,) command = (address,)
infoNumbers = {'address': 0, 'type': 1, 'knownPeer': 2, 'speed': 3, 'success': 4, 'DBHash': 5, 'failure': 6, 'lastConnect': 7, 'trust': 8, 'introduced': 9} infoNumbers = {'address': 0, 'type': 1, 'knownPeer': 2, 'speed': 3, 'success': 4, 'DBHash': 5, 'powValue': 6, 'failure': 7, 'lastConnect': 8, 'trust': 9, 'introduced': 10}
info = infoNumbers[info] info = infoNumbers[info]
iterCount = 0 iterCount = 0
retVal = '' retVal = ''
@ -549,7 +550,7 @@ class Core:
command = (data, address) command = (data, address)
if key not in ('address', 'type', 'knownPeer', 'speed', 'success', 'DBHash', 'failure', 'lastConnect', 'lastConnectAttempt', 'trust', 'introduced'): if key not in ('address', 'type', 'knownPeer', 'speed', 'success', 'DBHash', 'failure', 'powValue', 'lastConnect', 'lastConnectAttempt', 'trust', 'introduced'):
raise Exception("Got invalid database key when setting address info") raise Exception("Got invalid database key when setting address info")
else: else:
c.execute('UPDATE adders SET ' + key + ' = ? WHERE address=?', command) c.execute('UPDATE adders SET ' + key + ' = ? WHERE address=?', command)

View File

@ -182,7 +182,6 @@ class Onionr:
'introduce': self.onionrCore.introduceNode, 'introduce': self.onionrCore.introduceNode,
'connect': self.addAddress, 'connect': self.addAddress,
'kex': self.doKEX,
'pex': self.doPEX, 'pex': self.doPEX,
'ui' : self.openUI, 'ui' : self.openUI,
@ -227,7 +226,6 @@ class Onionr:
'get-file': 'Get a file from Onionr blocks', 'get-file': 'Get a file from Onionr blocks',
'import-blocks': 'import blocks from the disk (Onionr is transport-agnostic!)', 'import-blocks': 'import blocks from the disk (Onionr is transport-agnostic!)',
'listconn': 'list connected peers', 'listconn': 'list connected peers',
'kex': 'exchange keys with peers (done automatically)',
'pex': 'exchange addresses with peers (done automatically)', 'pex': 'exchange addresses with peers (done automatically)',
'blacklist-block': 'deletes a block by hash and permanently removes it from your node', 'blacklist-block': 'deletes a block by hash and permanently removes it from your node',
'introduce': 'Introduce your node to the public Onionr network', 'introduce': 'Introduce your node to the public Onionr network',
@ -495,11 +493,6 @@ class Onionr:
return return
def doKEX(self):
'''make communicator do kex'''
logger.info('Sending kex to command queue...')
self.onionrCore.daemonQueueAdd('kex')
def doPEX(self): def doPEX(self):
'''make communicator do pex''' '''make communicator do pex'''
logger.info('Sending pex to command queue...') logger.info('Sending pex to command queue...')
@ -694,7 +687,10 @@ class Onionr:
self.daemon() self.daemon()
self.running = False self.running = False
if not self.debug and not self._developmentMode: if not self.debug and not self._developmentMode:
try:
os.remove('.onionr-lock') os.remove('.onionr-lock')
except FileNotFoundError:
pass
def daemon(self): def daemon(self):
''' '''
@ -728,7 +724,7 @@ class Onionr:
Onionr.setupConfig('data/', self = self) Onionr.setupConfig('data/', self = self)
if self._developmentMode: if self._developmentMode:
logger.warn('DEVELOPMENT MODE ENABLED (THIS IS LESS SECURE!)', timestamp = False) logger.warn('DEVELOPMENT MODE ENABLED (LESS SECURE)', timestamp = False)
net = NetController(config.get('client.port', 59496), apiServerIP=apiHost) net = NetController(config.get('client.port', 59496), apiServerIP=apiHost)
logger.debug('Tor is starting...') logger.debug('Tor is starting...')
if not net.startTor(): if not net.startTor():

View File

@ -49,9 +49,14 @@ class DaemonTools:
data = {'node': ourID} data = {'node': ourID}
combinedNodes = ourID + peer combinedNodes = ourID + peer
existingRand = self.daemon._core.getAddressInfo(peer, 'powValue')
if type(existingRand) is type(None):
existingRand = ''
if peer in self.announceCache: if peer in self.announceCache:
data['random'] = self.announceCache[peer] data['random'] = self.announceCache[peer]
elif len(existingRand) > 0:
data['random'] = existingRand
else: else:
proof = onionrproofs.DataPOW(combinedNodes, forceDifficulty=4) proof = onionrproofs.DataPOW(combinedNodes, forceDifficulty=4)
try: try:
@ -68,6 +73,7 @@ class DaemonTools:
logger.info('Successfully introduced node to ' + peer) logger.info('Successfully introduced node to ' + peer)
retData = True retData = True
self.daemon._core.setAddressInfo(peer, 'introduced', 1) self.daemon._core.setAddressInfo(peer, 'introduced', 1)
self.daemon._core.setAddressInfo(peer, 'powValue', data['random'])
self.daemon.decrementThreadCount('announceNode') self.daemon.decrementThreadCount('announceNode')
return retData return retData
@ -152,8 +158,8 @@ class DaemonTools:
self.daemon.decrementThreadCount('cooldownPeer') self.daemon.decrementThreadCount('cooldownPeer')
def runCheck(self): def runCheck(self):
if os.path.isfile('data/.runcheck'): if os.path.isfile(self.daemon._core.dataDir + '.runcheck'):
os.remove('data/.runcheck') os.remove(self.daemon._core.dataDir + '.runcheck')
return True return True
return False return False

View File

@ -34,7 +34,8 @@ class OnionrCLIUI:
def subCommand(self, command): def subCommand(self, command):
try: try:
#subprocess.run(["./onionr.py", command]) #subprocess.run(["./onionr.py", command])
subprocess.Popen(['./onionr.py', command], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) #subprocess.Popen(['./onionr.py', command], stdin=subprocess.STD, stdout=subprocess.STDOUT, stderr=subprocess.STDOUT)
subprocess.call(['./onionr.py', command])
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
@ -52,24 +53,17 @@ class OnionrCLIUI:
firstRun = False firstRun = False
while showMenu: while showMenu:
if firstRun:
logger.info('Please wait while Onionr starts...')
daemon = subprocess.Popen(["./onionr.py", "start"], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL)
time.sleep(30)
firstRun = False
if self.myCore._utils.localCommand('ping') == 'pong': if self.myCore._utils.localCommand('ping') == 'pong':
isOnline = "Yes" isOnline = "Yes"
else: else:
isOnline = "No" isOnline = "No"
logger.info('''Daemon Running: ''' + isOnline + ''' print('''Daemon Running: ''' + isOnline + '''
1. Flow (Anonymous public chat, use at your own risk) 1. Flow (Anonymous public chat, use at your own risk)
2. Mail (Secure email-like service) 2. Mail (Secure email-like service)
3. File Sharing 3. File Sharing
4. User Settings 4. User Settings
5. Start/Stop Daemon 5. Quit (Does not shutdown daemon)
6. Quit (Does not shutdown daemon)
''') ''')
try: try:
choice = input(">").strip().lower() choice = input(">").strip().lower()
@ -81,25 +75,13 @@ class OnionrCLIUI:
elif choice in ("2", "mail"): elif choice in ("2", "mail"):
self.subCommand("mail") self.subCommand("mail")
elif choice in ("3", "file sharing", "file"): elif choice in ("3", "file sharing", "file"):
logger.warn("Not supported yet") print("Not supported yet")
elif choice in ("4", "user settings", "settings"): elif choice in ("4", "user settings", "settings"):
try: try:
self.setName() self.setName()
except (KeyboardInterrupt, EOFError) as e: except (KeyboardInterrupt, EOFError) as e:
pass pass
elif choice in ("5", "daemon"): elif choice in ("5", "quit"):
if isOnline == "Yes":
logger.info("Onionr daemon will shutdown...")
self.myCore.daemonQueueAdd('shutdown')
try:
daemon.kill()
except UnboundLocalError:
pass
else:
logger.info("Starting Daemon...")
daemon = subprocess.Popen(["./onionr.py", "start"], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
elif choice in ("6", "quit"):
showMenu = False showMenu = False
elif choice == "": elif choice == "":
pass pass