* Increased heartbeat timer
* Tried to fix bug where wrong node was being reported as being announced to * Refactored core somewhat - Removed data dir encryption (TODO: just encrypt pub/priv key pair) - Removed simplecrypt dependencymaster
parent
8c63d6c205
commit
58aa8ce1cc
|
@ -83,7 +83,7 @@ class OnionrCommunicatorDaemon:
|
|||
self._chat = onionrchat.OnionrChat(self)
|
||||
|
||||
if debug or developmentMode:
|
||||
OnionrCommunicatorTimers(self, self.heartbeat, 10)
|
||||
OnionrCommunicatorTimers(self, self.heartbeat, 30)
|
||||
|
||||
# Set timers, function reference, seconds
|
||||
# requiresPeer True means the timer function won't fire if we have no connected peers
|
||||
|
@ -500,9 +500,7 @@ class OnionrCommunicatorDaemon:
|
|||
|
||||
def announce(self, peer):
|
||||
'''Announce to peers our address'''
|
||||
if self.daemonTools.announceNode():
|
||||
logger.info('Successfully introduced node to ' + peer)
|
||||
else:
|
||||
if self.daemonTools.announceNode() == False:
|
||||
logger.warn('Could not introduce node.')
|
||||
|
||||
def detectAPICrash(self):
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import sqlite3, os, sys, time, math, base64, tarfile, getpass, simplecrypt, hashlib, nacl, logger, json, netcontroller, math, config
|
||||
import sqlite3, os, sys, time, math, base64, tarfile, nacl, logger, json, netcontroller, math, config
|
||||
from onionrblockapi import Block
|
||||
|
||||
import onionrutils, onionrcrypto, onionrproofs, onionrevents as events, onionrexceptions, onionrvalues
|
||||
|
@ -276,14 +276,6 @@ class Core:
|
|||
|
||||
return data
|
||||
|
||||
def _getSha3Hash(self, data):
|
||||
hasher = hashlib.sha3_256()
|
||||
if not type(data) is bytes:
|
||||
data = data.encode()
|
||||
hasher.update(data)
|
||||
dataHash = hasher.hexdigest()
|
||||
return dataHash
|
||||
|
||||
def setData(self, data):
|
||||
'''
|
||||
Set the data assciated with a hash
|
||||
|
@ -294,7 +286,7 @@ class Core:
|
|||
if not type(data) is bytes:
|
||||
data = data.encode()
|
||||
|
||||
dataHash = self._getSha3Hash(data)
|
||||
dataHash = self._crypto.sha3Hash(data)
|
||||
|
||||
if type(dataHash) is bytes:
|
||||
dataHash = dataHash.decode()
|
||||
|
@ -319,42 +311,6 @@ class Core:
|
|||
|
||||
return dataHash
|
||||
|
||||
def dataDirEncrypt(self, password):
|
||||
'''
|
||||
Encrypt the data directory on Onionr shutdown
|
||||
'''
|
||||
if os.path.exists('data.tar'):
|
||||
os.remove('data.tar')
|
||||
tar = tarfile.open("data.tar", "w")
|
||||
for name in ['data']:
|
||||
tar.add(name)
|
||||
tar.close()
|
||||
tarData = open('data.tar', 'r', encoding = "ISO-8859-1").read()
|
||||
encrypted = simplecrypt.encrypt(password, tarData)
|
||||
open('data-encrypted.dat', 'wb').write(encrypted)
|
||||
os.remove('data.tar')
|
||||
|
||||
return
|
||||
|
||||
def dataDirDecrypt(self, password):
|
||||
'''
|
||||
Decrypt the data directory on startup
|
||||
'''
|
||||
if not os.path.exists('data-encrypted.dat'):
|
||||
return (False, 'encrypted archive does not exist')
|
||||
data = open('data-encrypted.dat', 'rb').read()
|
||||
try:
|
||||
decrypted = simplecrypt.decrypt(password, data)
|
||||
except simplecrypt.DecryptionException:
|
||||
return (False, 'wrong password (or corrupted archive)')
|
||||
else:
|
||||
open('data.tar', 'wb').write(decrypted)
|
||||
tar = tarfile.open('data.tar')
|
||||
tar.extractall()
|
||||
tar.close()
|
||||
|
||||
return (True, '')
|
||||
|
||||
def daemonQueue(self):
|
||||
'''
|
||||
Gives commands to the communication proccess/daemon by reading an sqlite3 database
|
||||
|
@ -363,7 +319,7 @@ class Core:
|
|||
'''
|
||||
retData = False
|
||||
if not os.path.exists(self.queueDB):
|
||||
self.makeDaemonDB()
|
||||
self.dbCreate.createDaemonDB()
|
||||
else:
|
||||
conn = sqlite3.connect(self.queueDB, timeout=10)
|
||||
c = conn.cursor()
|
||||
|
@ -372,7 +328,7 @@ class Core:
|
|||
retData = row
|
||||
break
|
||||
except sqlite3.OperationalError:
|
||||
self.makeDaemonDB()
|
||||
self.dbCreate.createDaemonDB()
|
||||
else:
|
||||
if retData != False:
|
||||
c.execute('DELETE FROM commands WHERE id=?;', (retData[3],))
|
||||
|
@ -383,16 +339,6 @@ class Core:
|
|||
|
||||
return retData
|
||||
|
||||
def makeDaemonDB(self):
|
||||
'''generate the daemon queue db'''
|
||||
conn = sqlite3.connect(self.queueDB, timeout=10)
|
||||
c = conn.cursor()
|
||||
# Create table
|
||||
c.execute('''CREATE TABLE commands
|
||||
(id integer primary key autoincrement, command text, data text, date text)''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def daemonQueueAdd(self, command, data=''):
|
||||
'''
|
||||
Add a command to the daemon queue, used by the communication daemon (communicator.py)
|
||||
|
|
|
@ -133,3 +133,15 @@ class DBCreator:
|
|||
conn.commit()
|
||||
conn.close()
|
||||
return
|
||||
|
||||
def createDaemonDB(self):
|
||||
'''
|
||||
Create the daemon queue database
|
||||
'''
|
||||
conn = sqlite3.connect(self.core.queueDB, timeout=10)
|
||||
c = conn.cursor()
|
||||
# Create table
|
||||
c.execute('''CREATE TABLE commands
|
||||
(id integer primary key autoincrement, command text, data text, date text)''')
|
||||
conn.commit()
|
||||
conn.close()
|
|
@ -103,16 +103,6 @@ class Onionr:
|
|||
|
||||
self.debug = False # Whole application debugging
|
||||
|
||||
if os.path.exists('data-encrypted.dat'):
|
||||
while True:
|
||||
print('Enter password to decrypt:')
|
||||
password = getpass.getpass()
|
||||
result = self.onionrCore.dataDirDecrypt(password)
|
||||
if os.path.exists(self.dataDir):
|
||||
break
|
||||
else:
|
||||
logger.error('Failed to decrypt: ' + result[1], timestamp = False)
|
||||
else:
|
||||
# If data folder does not exist
|
||||
if not data_exists:
|
||||
if not os.path.exists(self.dataDir + 'blocks/'):
|
||||
|
@ -265,11 +255,6 @@ class Onionr:
|
|||
finally:
|
||||
self.execute(command)
|
||||
|
||||
if not self._developmentMode:
|
||||
encryptionPassword = self.onionrUtils.getPassword('Enter password to encrypt directory: ')
|
||||
self.onionrCore.dataDirEncrypt(encryptionPassword)
|
||||
shutil.rmtree(self.dataDir)
|
||||
|
||||
return
|
||||
|
||||
'''
|
||||
|
|
|
@ -25,10 +25,10 @@ if sys.version_info[0] == 3 and sys.version_info[1] < 6:
|
|||
elif sys.version_info[0] == 3 and sys.version_info[1] >= 6:
|
||||
import secrets
|
||||
import config
|
||||
config.reload()
|
||||
|
||||
class OnionrCrypto:
|
||||
def __init__(self, coreInstance):
|
||||
config.reload()
|
||||
self._core = coreInstance
|
||||
self._keyFile = self._core.dataDir + 'keys.txt'
|
||||
self.keyPowFile = self._core.dataDir + 'keyPow.txt'
|
||||
|
|
|
@ -52,6 +52,7 @@ class DaemonTools:
|
|||
|
||||
logger.info('Announcing node to ' + url)
|
||||
if self.daemon._core._utils.doPostRequest(url, data) == 'Success':
|
||||
logger.info('Successfully introduced node to ' + peer)
|
||||
retData = True
|
||||
self.daemon.decrementThreadCount('announceNode')
|
||||
return retData
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
import nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, logger, sys, base64, json
|
||||
import core, config
|
||||
config.reload()
|
||||
|
||||
def getHashDifficulty(h):
|
||||
'''
|
||||
|
@ -37,6 +36,7 @@ def hashMeetsDifficulty(h):
|
|||
'''
|
||||
Return bool for a hash string to see if it meets pow difficulty defined in config
|
||||
'''
|
||||
config.reload()
|
||||
hashDifficulty = getHashDifficulty(h)
|
||||
expected = int(config.get('minimum_block_pow'))
|
||||
if hashDifficulty >= expected:
|
||||
|
|
|
@ -53,7 +53,7 @@ class OnionrCLIUI:
|
|||
|
||||
while showMenu:
|
||||
if firstRun:
|
||||
print("please wait while Onionr starts...")
|
||||
logger.info("please wait while Onionr starts...")
|
||||
daemon = subprocess.Popen(["./onionr.py", "start"], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL)
|
||||
time.sleep(30)
|
||||
firstRun = False
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
"general" : {
|
||||
"dev_mode": true,
|
||||
"display_header" : true,
|
||||
"minimum_block_pow": 6,
|
||||
"minimum_send_pow": 6,
|
||||
"minimum_block_pow": 5,
|
||||
"minimum_send_pow": 5,
|
||||
|
||||
"direct_connect" : {
|
||||
"respond" : true,
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import unittest, sys, os, base64, tarfile, shutil, simplecrypt, logger
|
||||
import unittest, sys, os, base64, tarfile, shutil, logger
|
||||
|
||||
class OnionrTests(unittest.TestCase):
|
||||
def testPython3(self):
|
||||
|
@ -61,36 +61,6 @@ class OnionrTests(unittest.TestCase):
|
|||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
def testData_b_Encrypt(self):
|
||||
self.assertTrue(True)
|
||||
return
|
||||
|
||||
logger.debug('-'*26 + '\n')
|
||||
logger.info('Running data dir encrypt test...')
|
||||
|
||||
import core
|
||||
myCore = core.Core()
|
||||
myCore.dataDirEncrypt('password')
|
||||
if os.path.exists('data-encrypted.dat'):
|
||||
self.assertTrue(True)
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
def testData_a_Decrypt(self):
|
||||
self.assertTrue(True)
|
||||
return
|
||||
|
||||
logger.debug('-'*26 + '\n')
|
||||
logger.info('Running data dir decrypt test...')
|
||||
|
||||
import core
|
||||
myCore = core.Core()
|
||||
myCore.dataDirDecrypt('password')
|
||||
if os.path.exists('data/'):
|
||||
self.assertTrue(True)
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
def testConfig(self):
|
||||
logger.debug('-'*26 + '\n')
|
||||
logger.info('Running simple configuration test...')
|
||||
|
|
|
@ -4,7 +4,6 @@ PyNaCl==1.2.1
|
|||
gevent==1.3.6
|
||||
sha3==0.2.1
|
||||
defusedxml==0.5.0
|
||||
simple_crypt==4.1.7
|
||||
Flask==1.0.2
|
||||
PySocks==1.6.8
|
||||
stem==1.6.0
|
||||
|
|
Loading…
Reference in New Issue