added soft-reset command, fixed broken nonce cache, work on chat

master
Kevin Froman 2019-09-05 04:40:31 -05:00
parent cc66c3a896
commit 1f757679d9
13 changed files with 68 additions and 8 deletions

View File

@ -25,7 +25,7 @@ test:
soft-reset: soft-reset:
@echo "Soft-resetting Onionr..." @echo "Soft-resetting Onionr..."
rm -f onionr/$(ONIONR_HOME)/blocks/*.dat onionr/data/*.db onionr/$(ONIONR_HOME)/block-nonces.dat | true > /dev/null 2>&1 ./onionr.sh soft-reset
@./onionr.sh version | grep -v "Failed" --color=always @./onionr.sh version | grep -v "Failed" --color=always
reset: reset:

View File

@ -106,9 +106,9 @@ class OnionrCommunicatorDaemon:
OnionrCommunicatorTimers(self, self.runCheck, 2, maxThreads=1) OnionrCommunicatorTimers(self, self.runCheck, 2, maxThreads=1)
# Timers to periodically lookup new blocks and download them # Timers to periodically lookup new blocks and download them
OnionrCommunicatorTimers(self, lookupblocks.lookup_blocks_from_communicator, config.get('timers.lookupBlocks', 25), myArgs=[self], requiresPeer=True, maxThreads=1) lookup_blocks_timer = OnionrCommunicatorTimers(self, lookupblocks.lookup_blocks_from_communicator, config.get('timers.lookupBlocks', 25), myArgs=[self], requiresPeer=True, maxThreads=1)
# The block download timer is accessed by the block lookup function to trigger faster download starts # The block download timer is accessed by the block lookup function to trigger faster download starts
self.download_blocks_timer = OnionrCommunicatorTimers(self, self.getBlocks, config.get('timers.getBlocks', 30), requiresPeer=True, maxThreads=2) self.download_blocks_timer = OnionrCommunicatorTimers(self, self.getBlocks, config.get('timers.getBlocks', 30), requiresPeer=True, maxThreads=5)
# Timer to reset the longest offline peer so contact can be attempted again # Timer to reset the longest offline peer so contact can be attempted again
OnionrCommunicatorTimers(self, onlinepeers.clear_offline_peer, 58, myArgs=[self]) OnionrCommunicatorTimers(self, onlinepeers.clear_offline_peer, 58, myArgs=[self])
@ -166,6 +166,7 @@ class OnionrCommunicatorDaemon:
peerPoolTimer.count = (peerPoolTimer.frequency - 1) peerPoolTimer.count = (peerPoolTimer.frequency - 1)
cleanupTimer.count = (cleanupTimer.frequency - 60) cleanupTimer.count = (cleanupTimer.frequency - 60)
blockCleanupTimer.count = (blockCleanupTimer.frequency - 2) blockCleanupTimer.count = (blockCleanupTimer.frequency - 2)
lookup_blocks_timer = (lookup_blocks_timer.frequency - 2)
shared_state.add(self) shared_state.add(self)

View File

@ -29,7 +29,7 @@ def download_blocks_from_communicator(comm_inst):
assert isinstance(comm_inst, communicator.OnionrCommunicatorDaemon) assert isinstance(comm_inst, communicator.OnionrCommunicatorDaemon)
blacklist = onionrblacklist.OnionrBlackList() blacklist = onionrblacklist.OnionrBlackList()
storage_counter = storagecounter.StorageCounter() storage_counter = storagecounter.StorageCounter()
LOG_SKIP_COUNT = 10 # for how many iterations we skip logging the counter LOG_SKIP_COUNT = 50 # for how many iterations we skip logging the counter
count = 0 count = 0
# Iterate the block queue in the communicator # Iterate the block queue in the communicator
for blockHash in list(comm_inst.blockQueue): for blockHash in list(comm_inst.blockQueue):

View File

@ -184,7 +184,11 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort)
pass pass
except FileNotFoundError: except FileNotFoundError:
pass pass
time.sleep(TOR_KILL_WAIT)
try:
time.sleep(TOR_KILL_WAIT)
except KeyboardInterrupt:
pass
if 'windows' == platform.system().lower(): if 'windows' == platform.system().lower():
os.system('taskkill /PID %s /F' % (pidN,)) os.system('taskkill /PID %s /F' % (pidN,))

View File

@ -24,6 +24,7 @@ from .. import exportblocks # commands to export blocks
from .. import pubkeymanager # commands to add or change id from .. import pubkeymanager # commands to add or change id
from .. import resettor # commands to reset the tor data directory or transport keypair from .. import resettor # commands to reset the tor data directory or transport keypair
from .. import resetplugins # command to reinstall default plugins from .. import resetplugins # command to reinstall default plugins
from .. import softreset # command to delete onionr blocks
import onionrexceptions import onionrexceptions
from onionrutils import importnewblocks # func to import new blocks from onionrutils import importnewblocks # func to import new blocks
import onionrevents as events import onionrevents as events
@ -47,7 +48,8 @@ def get_arguments():
('changeid', 'change-id'): pubkeymanager.change_ID, ('changeid', 'change-id'): pubkeymanager.change_ID,
('resettor', 'reset-tor'): resettor.reset_tor, ('resettor', 'reset-tor'): resettor.reset_tor,
('resetplugins', 'reset-plugins'): resetplugins.reset, ('resetplugins', 'reset-plugins'): resetplugins.reset,
('reset-tor-node-transport'): resettor.reset_tor_key_pair ('reset-tor-node-transport',): resettor.reset_tor_key_pair,
('soft-reset', 'softreset'): softreset.soft_reset
} }
return args return args

View File

@ -0,0 +1,36 @@
"""
Onionr - Private P2P Communication
Command to soft-reset Onionr (deletes blocks)
"""
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 os
import shutil
from onionrutils import localcommand
from coredb import dbfiles
import filepaths
import logger
def soft_reset():
if localcommand.local_command('/ping') == 'pong!':
logger.warn('Cannot soft reset while Onionr is running', terminal=True)
return
path = filepaths.block_data_location
shutil.rmtree(path)
os.remove(dbfiles.block_meta_db)
logger.info("Soft reset Onionr", terminal=True)
soft_reset.onionr_help = "Deletes Onionr blocks and their associated metadata, except for any exported block files."

View File

@ -2,6 +2,7 @@ import sys, sqlite3
import onionrstorage, onionrexceptions, onionrcrypto as crypto import onionrstorage, onionrexceptions, onionrcrypto as crypto
import filepaths, storagecounter import filepaths, storagecounter
from coredb import dbfiles from coredb import dbfiles
from onionrutils import blockmetadata, bytesconverter
def set_data(data): def set_data(data):
''' '''
Set the data assciated with a hash Set the data assciated with a hash
@ -9,6 +10,8 @@ def set_data(data):
storage_counter = storagecounter.StorageCounter() storage_counter = storagecounter.StorageCounter()
data = data data = data
dataSize = sys.getsizeof(data) dataSize = sys.getsizeof(data)
nonce_hash = crypto.hashers.sha3_hash(bytesconverter.str_to_bytes(blockmetadata.fromdata.get_block_metadata_from_data(data)[2]))
nonce_hash = bytesconverter.bytes_to_str(nonce_hash)
if not type(data) is bytes: if not type(data) is bytes:
data = data.encode() data = data.encode()
@ -29,7 +32,7 @@ def set_data(data):
conn.commit() conn.commit()
conn.close() conn.close()
with open(filepaths.data_nonce_file, 'a') as nonceFile: with open(filepaths.data_nonce_file, 'a') as nonceFile:
nonceFile.write(dataHash + '\n') nonceFile.write(nonce_hash + '\n')
else: else:
raise onionrexceptions.DiskAllocationReached raise onionrexceptions.DiskAllocationReached
else: else:

View File

@ -29,6 +29,7 @@ def ping():
@flask_blueprint.route('/chatapi/send/<peer>', methods=['POST']) @flask_blueprint.route('/chatapi/send/<peer>', methods=['POST'])
def send_message(peer): def send_message(peer):
"""Send a message to the peer"""
data = request.get_json(force=True) data = request.get_json(force=True)
key_store.refresh() key_store.refresh()
existing = key_store.get('s' + peer) existing = key_store.get('s' + peer)
@ -41,6 +42,7 @@ def send_message(peer):
@flask_blueprint.route('/chatapi/gets/<peer>') @flask_blueprint.route('/chatapi/gets/<peer>')
def get_sent(peer): def get_sent(peer):
"""Get messages sent to peer"""
sent = key_store.get('s' + peer) sent = key_store.get('s' + peer)
if sent is None: if sent is None:
sent = [] sent = []
@ -48,6 +50,7 @@ def get_sent(peer):
@flask_blueprint.route('/chatapi/addrec/<peer>', methods=['POST']) @flask_blueprint.route('/chatapi/addrec/<peer>', methods=['POST'])
def add_rec(peer): def add_rec(peer):
"""Add a received message from the peer"""
data = request.get_json(force=True) data = request.get_json(force=True)
key_store.refresh() key_store.refresh()
existing = key_store.get('r' + peer) existing = key_store.get('r' + peer)
@ -60,6 +63,7 @@ def add_rec(peer):
@flask_blueprint.route('/chatapi/getrec/<peer>') @flask_blueprint.route('/chatapi/getrec/<peer>')
def get_messages(peer): def get_messages(peer):
"""Get received messages for the peer"""
key_store.refresh() key_store.refresh()
existing = key_store.get('r' + peer) existing = key_store.get('r' + peer)
if existing is None: if existing is None:

View File

@ -18,6 +18,7 @@
<script defer src='/chat/js/messages.js'></script> <script defer src='/chat/js/messages.js'></script>
<script defer src='/chat/js/message-feed.js'></script> <script defer src='/chat/js/message-feed.js'></script>
<script defer src='/chat/js/resizes.js'></script> <script defer src='/chat/js/resizes.js'></script>
<script defer src='/chat/js/change-convo.js'></script>
<script defer src='/chat/js/main.js'></script> <script defer src='/chat/js/main.js'></script>
</head> </head>

View File

@ -0,0 +1,6 @@
var conversationListElements = document.getElementsByClassName('conversationList')
for (i = 0; i < conversationListElements.length; i++){
conversationListElements[i].onclick = function(e){
}
}

View File

@ -19,6 +19,7 @@
friendList = {} friendList = {}
convoListElement = document.getElementsByClassName('conversationList')[0] convoListElement = document.getElementsByClassName('conversationList')[0]
firstConvoLoad = true firstConvoLoad = true
activeConvo = null;
function createConvoList(){ function createConvoList(){
convoListElement.innerHTML = "" convoListElement.innerHTML = ""

View File

@ -22,7 +22,9 @@
<li><a href="https://palletsprojects.com/p/flask/">Flask</a> - Lightweight Python web framework - 3-clause BSD license</li> <li><a href="https://palletsprojects.com/p/flask/">Flask</a> - Lightweight Python web framework - 3-clause BSD license</li>
<li><a href="http://gevent.org">Gevent</a> - For the thread-safe WSGI servers - MIT license</li> <li><a href="http://gevent.org">Gevent</a> - For the thread-safe WSGI servers - MIT license</li>
<li><a href="https://2.python-requests.org/en/master/">Requests</a> - HTTP requests for humans - Apache 2.0 license</li> <li><a href="https://2.python-requests.org/en/master/">Requests</a> - HTTP requests for humans - Apache 2.0 license</li>
<li><a href="https://github.com/pyca/pynacl/">PyNaCl</a> - Python libsodium binding - Apache 2.0 license</li>
<li><a href="https://download.libsodium.org/doc/">libsodium</a> - modern crypto library - ISC license</li>
<li><a href="https://fontawesome.com/license/free">Font Awesome</a> - Icon set and toolkit - MIT license & CC-By 4.0</li>
</ul> </ul>
<br> <br>