From dcc304be9d388149d9e935ceb33992df08c74fda Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 2 Dec 2020 23:00:51 -0600 Subject: [PATCH 1/4] fix wsl apport breaking sitecreator --- src/bigbrother/ministry/ofexec.py | 3 ++- src/onionrcommands/sitecreator.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bigbrother/ministry/ofexec.py b/src/bigbrother/ministry/ofexec.py index b1ff5843..e1afbb0e 100644 --- a/src/bigbrother/ministry/ofexec.py +++ b/src/bigbrother/ministry/ofexec.py @@ -54,7 +54,8 @@ def block_exec(event, info): 'stem/response/getinfo.py', 'stem/response/getconf.py', 'stem/response/mapaddress.py', - 'stem/response/protocolinfo.py' + 'stem/response/protocolinfo.py', + 'apport/__init__.py' ] whitelisted_source = [] home = identifyhome.identify_home() diff --git a/src/onionrcommands/sitecreator.py b/src/onionrcommands/sitecreator.py index ac2033ee..29733105 100644 --- a/src/onionrcommands/sitecreator.py +++ b/src/onionrcommands/sitecreator.py @@ -55,7 +55,7 @@ If you want to update your site later you must remember the passphrase.''', if error_encountered: sys.exit(1) - + logger.info('Generating site...', terminal=True) results = onionrsitesapi.sitefiles.create_site( passphrase, directory=directory) results = (results[0].replace('=', ''), results[1]) From 9db9c495c88fdc3ac7873298cc779d22275eb782 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 2 Dec 2020 23:01:12 -0600 Subject: [PATCH 2/4] check block POW *before* syncning from lan --- src/lan/client/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lan/client/__init__.py b/src/lan/client/__init__.py index b2626b63..6b1dab66 100644 --- a/src/lan/client/__init__.py +++ b/src/lan/client/__init__.py @@ -12,6 +12,7 @@ from coredb.blockmetadb import get_block_list from onionrblocks.blockimporter import import_block_from_data import onionrexceptions from ..server import ports +from onionrproofs import hashMeetsDifficulty from threading import Thread """ @@ -37,7 +38,7 @@ def _lan_work(peer: LANIP): our_blocks = get_block_list() blocks = requests.get(url + 'blist/0').text.splitlines() for block in blocks: - if block not in our_blocks: + if block not in our_blocks and hashMeetsDifficulty(block): try: import_block_from_data( requests.get( From 01ed4d49d0403a7af8ce4817db1089f872c57448 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 3 Dec 2020 01:25:24 -0600 Subject: [PATCH 3/4] fix wsl apport breaking sites --- src/bigbrother/ministry/ofexec.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bigbrother/ministry/ofexec.py b/src/bigbrother/ministry/ofexec.py index e1afbb0e..cd4ccef8 100644 --- a/src/bigbrother/ministry/ofexec.py +++ b/src/bigbrother/ministry/ofexec.py @@ -55,7 +55,8 @@ def block_exec(event, info): 'stem/response/getconf.py', 'stem/response/mapaddress.py', 'stem/response/protocolinfo.py', - 'apport/__init__.py' + 'apport/__init__.py', + 'apport/report.py' ] whitelisted_source = [] home = identifyhome.identify_home() From e34b499044c006bc949e8f16426eddae4218b940 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 2 Dec 2020 20:46:36 -0600 Subject: [PATCH 4/4] purge old blocks if POW increases --- src/communicatorutils/housekeeping.py | 38 +++++++++++++++------ src/onionrcommands/daemonlaunch/__init__.py | 3 ++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/communicatorutils/housekeeping.py b/src/communicatorutils/housekeeping.py index 97024663..a36f8556 100755 --- a/src/communicatorutils/housekeeping.py +++ b/src/communicatorutils/housekeeping.py @@ -18,6 +18,7 @@ from onionrstorage import removeblock from onionrblocks import onionrblacklist from onionrblocks.storagecounter import StorageCounter from etc.onionrvalues import DATABASE_LOCK_TIMEOUT +from onionrproofs import hashMeetsDifficulty """ 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 @@ -44,16 +45,25 @@ def __remove_from_upload(shared_state, block_hash: str): pass +def __purge_block(shared_state, block_hash, add_to_blacklist = True): + blacklist = None + + removeblock.remove_block(block_hash) + onionrstorage.deleteBlock(block_hash) + __remove_from_upload(shared_state, block_hash) + + if add_to_blacklist: + blacklist = onionrblacklist.OnionrBlackList() + blacklist.addToDB(block_hash) + + def clean_old_blocks(shared_state): """Delete expired blocks + old blocks if disk allocation is near full""" blacklist = onionrblacklist.OnionrBlackList() # Delete expired blocks for bHash in blockmetadb.expiredblocks.get_expired_blocks(): - blacklist.addToDB(bHash) - removeblock.remove_block(bHash) - onionrstorage.deleteBlock(bHash) - __remove_from_upload(shared_state, bHash) - logger.info('Deleted block: %s' % (bHash,)) + __purge_block(shared_state, bHash, add_to_blacklist=True) + logger.info('Deleted expired block: %s' % (bHash,)) while storage_counter.is_full(): try: @@ -61,11 +71,8 @@ def clean_old_blocks(shared_state): except IndexError: break else: - blacklist.addToDB(oldest) - removeblock.remove_block(oldest) - onionrstorage.deleteBlock(oldest) - __remove_from_upload(shared_state, oldest) - logger.info('Deleted block: %s' % (oldest,)) + __purge_block(shared_state, bHash, add_to_blacklist=True) + logger.info('Deleted block because of full storage: %s' % (oldest,)) def clean_keys(): @@ -88,3 +95,14 @@ def clean_keys(): conn.close() onionrusers.deleteExpiredKeys() + + +def clean_blocks_not_meeting_pow(shared_state): + """Clean blocks not meeting min send/rec pow. Used if config.json POW changes""" + block_list = blockmetadb.get_block_list() + for block in block_list: + if not hashMeetsDifficulty(block): + logger.warn( + f"Deleting block {block} because it was stored" + + "with a POW level smaller than current.", terminal=True) + __purge_block(shared_state, block) diff --git a/src/onionrcommands/daemonlaunch/__init__.py b/src/onionrcommands/daemonlaunch/__init__.py index 2ea25726..9a980725 100755 --- a/src/onionrcommands/daemonlaunch/__init__.py +++ b/src/onionrcommands/daemonlaunch/__init__.py @@ -42,6 +42,7 @@ from lan.server import LANServer from sneakernet import sneakernet_import_thread from onionrstatistics.devreporting import statistics_reporter from setupkvvars import setup_kv +from communicatorutils.housekeeping import clean_blocks_not_meeting_pow from .spawndaemonthreads import spawn_client_threads """ This program is free software: you can redistribute it and/or modify @@ -222,6 +223,8 @@ def daemon(): 'proxyPort', net.socksPort) spawn_client_threads(shared_state) + clean_blocks_not_meeting_pow(shared_state) + communicator.startCommunicator(shared_state) clean_ephemeral_services()