diff --git a/onionr/keymanager.py b/onionr/keymanager.py
index 080795ec..55f1511f 100755
--- a/onionr/keymanager.py
+++ b/onionr/keymanager.py
@@ -19,6 +19,7 @@
'''
from onionrutils import bytesconverter
from onionrcrypto import generate
+import os
import filepaths
class KeyManager:
def __init__(self):
@@ -35,6 +36,7 @@ class KeyManager:
raise ValueError('Pubkey already in list: %s' % (pubKey,))
except FileNotFoundError:
pass
+
with open(self.keyFile, "a") as keyFile:
keyFile.write(pubKey + ',' + privKey + '\n')
return (pubKey, privKey)
diff --git a/onionr/onionrcommands/__init__.py b/onionr/onionrcommands/__init__.py
index d6147309..e69de29b 100755
--- a/onionr/onionrcommands/__init__.py
+++ b/onionr/onionrcommands/__init__.py
@@ -1,162 +0,0 @@
-'''
- Onionr - Private P2P Communication
-
- This module defines commands for CLI usage
-'''
-'''
- 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 .
-'''
-'''
-import webbrowser, sys
-import logger
-from . import pubkeymanager, onionrstatistics, daemonlaunch, filecommands, plugincommands, keyadders
-from . import banblocks, exportblocks, openwebinterface, resettor, dopex
-from onionrutils import importnewblocks
-'''
-def show_help(o_inst, command):
-
- helpmenu = o_inst.getHelp()
-
- if command is None and len(sys.argv) >= 3:
- for cmd in sys.argv[2:]:
- o_inst.showHelp(cmd)
- elif not command is None:
- if command.lower() in helpmenu:
- logger.info(logger.colors.bold + command + logger.colors.reset + logger.colors.fg.blue + ' : ' + logger.colors.reset + helpmenu[command.lower()], timestamp = False)
- else:
- logger.warn(logger.colors.bold + command + logger.colors.reset + logger.colors.fg.blue + ' : ' + logger.colors.reset + 'No help menu entry was found', timestamp = False)
- else:
- o_inst.version(0)
- for command, helpmessage in helpmenu.items():
- o_inst.showHelp(command)
-
-def get_commands(onionr_inst):
- return {'': onionr_inst.showHelpSuggestion,
- 'help': onionr_inst.showHelp,
- 'start': onionr_inst.start,
- 'stop': onionr_inst.killDaemon,
- 'status': onionr_inst.showStats,
- 'statistics': onionr_inst.showStats,
- 'stats': onionr_inst.showStats,
- 'details' : onionr_inst.showDetails,
- 'detail' : onionr_inst.showDetails,
- 'show-details' : onionr_inst.showDetails,
- 'show-detail' : onionr_inst.showDetails,
- 'showdetails' : onionr_inst.showDetails,
- 'showdetail' : onionr_inst.showDetails,
- 'get-details' : onionr_inst.showDetails,
- 'get-detail' : onionr_inst.showDetails,
- 'getdetails' : onionr_inst.showDetails,
- 'getdetail' : onionr_inst.showDetails,
-
- 'enable-plugin': onionr_inst.enablePlugin,
- 'enplugin': onionr_inst.enablePlugin,
- 'enableplugin': onionr_inst.enablePlugin,
- 'enmod': onionr_inst.enablePlugin,
- 'disable-plugin': onionr_inst.disablePlugin,
- 'displugin': onionr_inst.disablePlugin,
- 'disableplugin': onionr_inst.disablePlugin,
- 'dismod': onionr_inst.disablePlugin,
- 'reload-plugin': onionr_inst.reloadPlugin,
- 'reloadplugin': onionr_inst.reloadPlugin,
- 'reload-plugins': onionr_inst.reloadPlugin,
- 'reloadplugins': onionr_inst.reloadPlugin,
- 'create-plugin': onionr_inst.createPlugin,
- 'createplugin': onionr_inst.createPlugin,
- 'plugin-create': onionr_inst.createPlugin,
-
- 'listkeys': onionr_inst.listKeys,
- 'list-keys': onionr_inst.listKeys,
-
- 'addpeer': onionr_inst.addPeer,
- 'add-peer': onionr_inst.addPeer,
- 'add-address': onionr_inst.addAddress,
- 'add-addr': onionr_inst.addAddress,
- 'addaddr': onionr_inst.addAddress,
- 'addaddress': onionr_inst.addAddress,
- 'list-peers': onionr_inst.listPeers,
-
- 'blacklist-block': onionr_inst.banBlock,
-
- 'add-file': onionr_inst.addFile,
- 'addfile': onionr_inst.addFile,
- 'addhtml': onionr_inst.addWebpage,
- 'add-html': onionr_inst.addWebpage,
- 'add-site': onionr_inst.addWebpage,
- 'addsite': onionr_inst.addWebpage,
-
- 'openhome': onionr_inst.openHome,
- 'open-home': onionr_inst.openHome,
-
- 'export-block': onionr_inst.exportBlock,
- 'exportblock': onionr_inst.exportBlock,
-
- 'get-file': onionr_inst.getFile,
- 'getfile': onionr_inst.getFile,
-
- 'listconn': onionr_inst.listConn,
- 'list-conn': onionr_inst.listConn,
-
- 'import-blocks': importnewblocks.import_new_blocks,
- 'importblocks': importnewblocks.import_new_blocks,
-
- 'pex': dopex.do_PEX,
-
- 'getpassword': onionr_inst.printWebPassword,
- 'get-password': onionr_inst.printWebPassword,
- 'getpwd': onionr_inst.printWebPassword,
- 'get-pwd': onionr_inst.printWebPassword,
- 'getpass': onionr_inst.printWebPassword,
- 'get-pass': onionr_inst.printWebPassword,
- 'getpasswd': onionr_inst.printWebPassword,
- 'get-passwd': onionr_inst.printWebPassword,
-
- 'friend': onionr_inst.friendCmd,
- 'addid': onionr_inst.addID,
- 'add-id': onionr_inst.addID,
- 'change-id': onionr_inst.changeID,
-
- 'reset-tor': resettor.reset_tor
- }
-
-cmd_help = {
- 'help': 'Displays this Onionr help menu',
- 'version': 'Displays the Onionr version',
- 'config': 'Configures something and adds it to the file',
-
- 'start': 'Starts the Onionr daemon',
- 'stop': 'Stops the Onionr daemon',
-
- 'stats': 'Displays node statistics',
- 'details': 'Displays the web password, public key, and human readable public key',
-
- 'enable-plugin': 'Enables and starts a plugin',
- 'disable-plugin': 'Disables and stops a plugin',
- 'reload-plugin': 'Reloads a plugin',
- 'create-plugin': 'Creates directory structure for a plugin',
-
- 'add-peer': 'Adds a peer to database',
- 'list-peers': 'Displays a list of peers',
- 'add-file': 'Create an Onionr block from a file',
- 'get-file': 'Get a file from Onionr blocks',
- 'import-blocks': 'import blocks from the disk (Onionr is transport-agnostic!)',
- 'listconn': 'list connected peers',
- 'pex': 'exchange addresses with peers (done automatically)',
- 'blacklist-block': 'deletes a block by hash and permanently removes it from your node',
- 'friend': '[add|remove] [public key/id]',
- 'add-id': 'Generate a new ID (key pair)',
- 'change-id': 'Change active ID',
- 'open-home': 'Open your node\'s home/info screen',
- 'reset-tor': 'Delete the Tor data directory. Only do this if Tor never starts.'
-}
diff --git a/onionr/onionrcommands/banblocks.py b/onionr/onionrcommands/banblocks.py
index 22bc5cf7..b4d8d82f 100755
--- a/onionr/onionrcommands/banblocks.py
+++ b/onionr/onionrcommands/banblocks.py
@@ -21,15 +21,17 @@ import sys
import logger
from onionrutils import stringvalidators
from onionrstorage import removeblock
-def ban_block(o_inst):
+import onionrblacklist
+def ban_block():
+ blacklist = onionrblacklist.OnionrBlackList()
try:
ban = sys.argv[2]
except IndexError:
ban = logger.readline('Enter a block hash:')
if stringvalidators.validate_hash(ban):
- if not o_inst.blacklist.inBlacklist(ban):
+ if not blacklist.inBlacklist(ban):
try:
- o_inst.blacklist.addToDB(ban)
+ blacklist.addToDB(ban)
removeblock.remove_block(ban)
except Exception as error:
logger.error('Could not blacklist block', error=error, terminal=True)
diff --git a/onionr/onionrcommands/dopex.py b/onionr/onionrcommands/dopex.py
deleted file mode 100644
index 76f24463..00000000
--- a/onionr/onionrcommands/dopex.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from coredb import daemonqueue
-def do_PEX():
- daemonqueue.daemon_queue_add('pex')
\ No newline at end of file
diff --git a/onionr/onionrcommands/filecommands.py b/onionr/onionrcommands/filecommands.py
index 5df0e9f8..11387b9c 100755
--- a/onionr/onionrcommands/filecommands.py
+++ b/onionr/onionrcommands/filecommands.py
@@ -23,7 +23,11 @@ import logger
from onionrblockapi import Block
from onionrutils import stringvalidators
from onionrblocks import insert
-def add_file(o_inst, singleBlock=False, blockType='bin'):
+
+def add_html(singleBlock=True, blockType='html'):
+ add_file(singleBlock, blockType)
+
+def add_file(singleBlock=False, blockType='bin'):
'''
Adds a file to the onionr network
'''
@@ -46,7 +50,7 @@ def add_file(o_inst, singleBlock=False, blockType='bin'):
else:
logger.error('%s add-file ' % sys.argv[0], timestamp = False, terminal=True)
-def getFile(o_inst):
+def get_file():
'''
Get a file from onionr blocks
'''
diff --git a/onionr/onionrcommands/keyadders.py b/onionr/onionrcommands/keyadders.py
index 9e55ca5b..8d08b61b 100755
--- a/onionr/onionrcommands/keyadders.py
+++ b/onionr/onionrcommands/keyadders.py
@@ -20,21 +20,6 @@
import sys
import logger
from coredb import keydb
-def add_peer(o_inst):
- try:
- newPeer = sys.argv[2]
- except IndexError:
- pass
- else:
- if newPeer in keydb.listkeys.list_peers():
- logger.info('We already have that key', terminal=True)
- return
- logger.info("Adding peer: " + logger.colors.underline + newPeer, terminal=True)
- try:
- if keydb.addkeys.add_peer(newPeer):
- logger.info('Successfully added key', terminal=True)
- except AssertionError:
- logger.error('Failed to add key', terminal=True)
def add_address():
try:
diff --git a/onionr/onionrcommands/onionrstatistics.py b/onionr/onionrcommands/onionrstatistics.py
index 89e7564a..b4c5c20b 100755
--- a/onionr/onionrcommands/onionrstatistics.py
+++ b/onionr/onionrcommands/onionrstatistics.py
@@ -21,13 +21,15 @@ import os, uuid, time
import logger
from onionrblockapi import Block
from onionrutils import checkcommunicator, mnemonickeys
-from utils import sizeutils, gethostname, getconsolewidth
+from utils import sizeutils, gethostname, getconsolewidth, identifyhome
from coredb import blockmetadb, daemonqueue, keydb
import onionrcrypto, config
-def show_stats(o_inst):
+from etc import onionrvalues
+def show_stats():
try:
# define stats messages here
totalBlocks = len(blockmetadb.get_block_list())
+ home = identifyhome.identify_home()
signedBlocks = len(Block.getBlocks(signed = True))
messages = {
# info about local client
@@ -35,14 +37,14 @@ def show_stats(o_inst):
# file and folder size stats
'div1' : True, # this creates a solid line across the screen, a div
- 'Total Block Size' : sizeutils.human_size(sizeutils.size(o_inst.dataDir + 'blocks/')),
- 'Total Plugin Size' : sizeutils.human_size(sizeutils.size(o_inst.dataDir + 'plugins/')),
- 'Log File Size' : sizeutils.human_size(sizeutils.size(o_inst.dataDir + 'output.log')),
+ 'Total Block Size' : sizeutils.human_size(sizeutils.size(home + 'blocks/')),
+ 'Total Plugin Size' : sizeutils.human_size(sizeutils.size(home + 'plugins/')),
+ 'Log File Size' : sizeutils.human_size(sizeutils.size(home + 'output.log')),
# count stats
'div2' : True,
'Known Peers' : str(max(len(keydb.listkeys.list_peers()) - 1, 0)),
- 'Enabled Plugins' : str(len(config.get('plugins.enabled', list()))) + ' / ' + str(len(os.listdir(o_inst.dataDir + 'plugins/'))),
+ 'Enabled Plugins' : str(len(config.get('plugins.enabled', list()))) + ' / ' + str(len(os.listdir(home + 'plugins/'))),
'Stored Blocks' : str(totalBlocks),
'Percent Blocks Signed' : str(round(100 * signedBlocks / max(totalBlocks, 1), 2)) + '%'
}
@@ -67,7 +69,7 @@ def show_stats(o_inst):
groupsize = width - prewidth - len('[+] ')
# generate stats table
- logger.info(colors['title'] + 'Onionr v%s Statistics' % onionr.ONIONR_VERSION + colors['reset'], terminal=True)
+ logger.info(colors['title'] + 'Onionr v%s Statistics' % onionrvalues.ONIONR_VERSION + colors['reset'], terminal=True)
logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset'], terminal=True)
for key, val in messages.items():
if not (type(val) is bool and val is True):
diff --git a/onionr/onionrcommands/parser/arguments.py b/onionr/onionrcommands/parser/arguments.py
index e9a1df3f..40557e03 100644
--- a/onionr/onionrcommands/parser/arguments.py
+++ b/onionr/onionrcommands/parser/arguments.py
@@ -1,15 +1,32 @@
from .. import onionrstatistics, version, daemonlaunch, keyadders, openwebinterface
+from .. import banblocks # Command to blacklist a block by its hash
+from .. import filecommands # commands to share files with onionr
+from .. import exportblocks # commands to export blocks
+from .. import pubkeymanager # commands to add or change id
+from .. import resettor # command to reset the tor data directory
import onionrexceptions
+from onionrutils import importnewblocks # func to import new blocks
import onionrevents as events
def get_arguments():
'''This is a function because we need to be able to dynamically modify them with plugins'''
args = {
+ ('blacklist', 'blacklist-block', 'remove-block', 'removeblock'): banblocks.ban_block,
('details', 'info'): onionrstatistics.show_details,
+ ('stats', 'statistics'): onionrstatistics.show_stats,
('version'): version.version,
('start', 'daemon'): daemonlaunch.start,
('stop', 'kill'): daemonlaunch.kill_daemon,
('add-address', 'addaddress', 'addadder'): keyadders.add_address,
- ('openhome', 'gui', 'openweb', 'open-home', 'open-web'): openwebinterface.open_home
+ ('openhome', 'gui', 'openweb', 'open-home', 'open-web'): openwebinterface.open_home,
+ ('add-site', 'addsite', 'addhtml', 'add-html'): filecommands.add_html,
+ ('addfile', 'add-file'): filecommands.add_file,
+ ('get-file', 'getfile'): filecommands.get_file,
+ ('export-block', 'exportblock'): exportblocks.export_block,
+ ('importblocks', 'import-blocks'): importnewblocks.import_new_blocks,
+ ('addid', 'add-id'): pubkeymanager.add_ID,
+ ('changeid', 'change-id'): pubkeymanager.change_ID,
+ ('resettor', 'reset-tor'): resettor.reset_tor
+
}
return args
diff --git a/onionr/onionrcommands/plugincommands.py b/onionr/onionrcommands/plugincommands.py
deleted file mode 100755
index 154bb6cf..00000000
--- a/onionr/onionrcommands/plugincommands.py
+++ /dev/null
@@ -1,87 +0,0 @@
-'''
- Onionr - Private P2P Communication
-
- plugin CLI commands
-'''
-'''
- 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 .
-'''
-
-import sys
-import logger, onionrplugins as plugins
-
-def enable_plugin(o_inst):
- if len(sys.argv) >= 3:
- plugin_name = sys.argv[2]
- logger.info('Enabling plugin "%s"...' % plugin_name, terminal=True)
- plugins.enable(plugin_name, o_inst)
- else:
- logger.info('%s %s ' % (sys.argv[0], sys.argv[1]), terminal=True)
-
-def disable_plugin(o_inst):
- if len(sys.argv) >= 3:
- plugin_name = sys.argv[2]
- logger.info('Disabling plugin "%s"...' % plugin_name, terminal=True)
- plugins.disable(plugin_name, o_inst)
- else:
- logger.info('%s %s ' % (sys.argv[0], sys.argv[1]), terminal=True)
-
-def reload_plugin(o_inst):
- '''
- Reloads (stops and starts) all plugins, or the given plugin
- '''
-
- if len(sys.argv) >= 3:
- plugin_name = sys.argv[2]
- logger.info('Reloading plugin "%s"...' % plugin_name, terminal=True)
- plugins.stop(plugin_name, o_inst)
- plugins.start(plugin_name, o_inst)
- else:
- logger.info('Reloading all plugins...', terminal=True)
- plugins.reload(o_inst)
-
-
-def create_plugin(o_inst):
- '''
- Creates the directory structure for a plugin name
- '''
-
- if len(sys.argv) >= 3:
- try:
- plugin_name = re.sub('[^0-9a-zA-Z_]+', '', str(sys.argv[2]).lower())
-
- if not plugins.exists(plugin_name):
- logger.info('Creating plugin "%s"...' % plugin_name, terminal=True)
-
- os.makedirs(plugins.get_plugins_folder(plugin_name))
- with open(plugins.get_plugins_folder(plugin_name) + '/main.py', 'a') as main:
- contents = ''
- with open('static-data/default_plugin.py', 'rb') as file:
- contents = file.read().decode()
-
- # TODO: Fix $user. os.getlogin() is B U G G Y
- main.write(contents.replace('$user', 'some random developer').replace('$date', datetime.datetime.now().strftime('%Y-%m-%d')).replace('$name', plugin_name))
-
- with open(plugins.get_plugins_folder(plugin_name) + '/info.json', 'a') as main:
- main.write(json.dumps({'author' : 'anonymous', 'description' : 'the default description of the plugin', 'version' : '1.0'}))
-
- logger.info('Enabling plugin "%s"...' % plugin_name, terminal=True)
- plugins.enable(plugin_name, o_inst)
- else:
- logger.warn('Cannot create plugin directory structure; plugin "%s" exists.' % plugin_name, terminal=True)
-
- except Exception as e:
- logger.error('Failed to create plugin directory structure.', e, terminal=True)
- else:
- logger.info('%s %s ' % (sys.argv[0], sys.argv[1]), terminal=True)
\ No newline at end of file
diff --git a/onionr/onionrcommands/pubkeymanager.py b/onionr/onionrcommands/pubkeymanager.py
index 325ad158..8936a772 100755
--- a/onionr/onionrcommands/pubkeymanager.py
+++ b/onionr/onionrcommands/pubkeymanager.py
@@ -22,12 +22,13 @@ import sys, getpass
import logger, onionrexceptions
from onionrutils import stringvalidators, bytesconverter
from onionrusers import onionrusers, contactmanager
+import config
from coredb import keydb
import keymanager, onionrcrypto
import unpaddedbase32
from etc import onionrvalues
DETERMINISTIC_REQUIREMENT = onionrvalues.PASSWORD_LENGTH
-def add_ID(o_inst):
+def add_ID():
key_manager = keymanager.KeyManager()
try:
sys.argv[2]
@@ -58,7 +59,7 @@ def add_ID(o_inst):
return
logger.info('Added ID: %s' % (bytesconverter.bytes_to_str(newID),), terminal=True)
-def change_ID(o_inst):
+def change_ID():
key_manager = keymanager.KeyManager()
try:
key = sys.argv[2]
@@ -68,48 +69,11 @@ def change_ID(o_inst):
else:
if stringvalidators.validate_pub_key(key):
if key in key_manager.getPubkeyList():
- o_inst.config.set('general.public_key', key)
- o_inst.config.save()
+ config.set('general.public_key', key)
+ config.save()
logger.info('Set active key to: %s' % (key,), terminal=True)
logger.info('Restart Onionr if it is running.', terminal=True)
else:
logger.warn('That key does not exist', terminal=True)
else:
logger.warn('Invalid key %s' % (key,), terminal=True)
-
-def friend_command(o_inst):
- friend = ''
- try:
- # Get the friend command
- action = sys.argv[2]
- except IndexError:
- logger.info('Syntax: friend add/remove/list [address]', terminal=True)
- else:
- action = action.lower()
- if action == 'list':
- # List out peers marked as our friend
- for friend in contactmanager.ContactManager.list_friends():
- logger.info(friend.publicKey + ' - ' + friend.get_info('name'), terminal=True)
- elif action in ('add', 'remove'):
- try:
- friend = sys.argv[3]
- if not stringvalidators.validate_pub_key(friend):
- raise onionrexceptions.InvalidPubkey('Public key is invalid')
- if friend not in keydb.listkeys.list_peers():
- raise onionrexceptions.KeyNotKnown
- friend = onionrusers.OnionrUser(friend)
- except IndexError:
- logger.warn('Friend ID is required.', terminal=True)
- action = 'error' # set to 'error' so that the finally block does not process anything
- except onionrexceptions.KeyNotKnown:
- o_inst.addPeer(friend)
- friend = onionrusers.OnionrUser(friend)
- finally:
- if action == 'add':
- friend.setTrust(1)
- logger.info('Added %s as friend.' % (friend.publicKey,), terminal=True)
- elif action == 'remove':
- friend.setTrust(0)
- logger.info('Removed %s as friend.' % (friend.publicKey,), terminal=True)
- else:
- logger.info('Syntax: friend add/remove/list [address]', terminal=True)
\ No newline at end of file
diff --git a/onionr/static-data/default-plugins/contactmanager/info.json b/onionr/static-data/default-plugins/contactmanager/info.json
deleted file mode 100755
index 60967d52..00000000
--- a/onionr/static-data/default-plugins/contactmanager/info.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name" : "contactmanager",
- "version" : "1.0",
- "author" : "onionr"
-}
diff --git a/onionr/static-data/default-plugins/contactmanager/main.py b/onionr/static-data/default-plugins/contactmanager/main.py
deleted file mode 100755
index d6c4499c..00000000
--- a/onionr/static-data/default-plugins/contactmanager/main.py
+++ /dev/null
@@ -1,39 +0,0 @@
-'''
- Onionr - Private P2P Communication
-
- This is an interactive menu-driven CLI interface for Onionr
-'''
-'''
- 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 .
-'''
-
-plugin_name = 'contactmanager'
-
-class OnionrContactManager:
- def __init__(self, api):
- return
-
-def on_init(api, data = None):
- '''
- This event is called after Onionr is initialized, but before the command
- inputted is executed. Could be called when daemon is starting or when
- just the client is running.
- '''
-
- # Doing this makes it so that the other functions can access the api object
- # by simply referencing the variable `pluginapi`.
- pluginapi = api
- ui = OnionrContactManager(api)
- #api.commands.register('interactive', ui.start)
- return
diff --git a/onionr/static-data/default-plugins/flow/main.py b/onionr/static-data/default-plugins/flow/main.py
index 0aeb7d94..52da5431 100755
--- a/onionr/static-data/default-plugins/flow/main.py
+++ b/onionr/static-data/default-plugins/flow/main.py
@@ -113,6 +113,8 @@ def on_init(api, data = None):
def on_processblocks(api, data=None):
b_hash = reconstructhash.deconstruct_hash(data['block'].hash) # Get the 0-truncated block hash
metadata = data['block'].bmetadata # Get the block metadata
+ if data['block'].bheader['type'] != 'brd':
+ return
# Validate the channel name is sane for caching
try:
@@ -120,9 +122,9 @@ def on_processblocks(api, data=None):
except KeyError:
ch = 'global'
ch_len = len(ch)
- if len(metadata['ch']) == 0:
+ if ch_len == 0:
ch = 'global'
- elif len(metadata['ch']) > 12:
+ elif ch_len > 12:
return
existing_posts = board_cache.get(ch)
diff --git a/onionr/tests/test_forward_secrecy.py b/onionr/tests/test_forward_secrecy.py
index 897dc1b6..e8db44d2 100755
--- a/onionr/tests/test_forward_secrecy.py
+++ b/onionr/tests/test_forward_secrecy.py
@@ -4,12 +4,16 @@ sys.path.append(".")
import unittest, uuid
TEST_DIR_1 = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
TEST_DIR_2 = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
-import onionr, time
+import time
+
+os.environ["ONIONR_HOME"] = TEST_DIR_1
+from utils import createdirs
+createdirs.create_dirs()
import onionrexceptions, onionrcrypto as crypto
from onionrusers import onionrusers
from onionrusers import contactmanager
-from utils import createdirs
+
class OnionrForwardSecrecyTests(unittest.TestCase):
'''
@@ -17,8 +21,6 @@ class OnionrForwardSecrecyTests(unittest.TestCase):
'''
def test_forward_encrypt(self):
- os.environ["ONIONR_HOME"] = TEST_DIR_1
- createdirs.create_dirs()
friend = crypto.generate()
diff --git a/onionr/tests/test_highlevelcrypto.py b/onionr/tests/test_highlevelcrypto.py
index a3995a4e..e214dc16 100755
--- a/onionr/tests/test_highlevelcrypto.py
+++ b/onionr/tests/test_highlevelcrypto.py
@@ -4,10 +4,12 @@ sys.path.append(".")
import unittest, uuid, hashlib, base64
import nacl.exceptions
import nacl.signing, nacl.hash, nacl.encoding
-from onionrutils import stringvalidators, mnemonickeys
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
+from utils import createdirs
+createdirs.create_dirs()
+from onionrutils import stringvalidators, mnemonickeys
import onionrcrypto as crypto, onionrexceptions
class OnionrCryptoTests(unittest.TestCase):
diff --git a/onionr/tests/test_keymanager.py b/onionr/tests/test_keymanager.py
index 34967536..4d477ba7 100644
--- a/onionr/tests/test_keymanager.py
+++ b/onionr/tests/test_keymanager.py
@@ -8,10 +8,10 @@ print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
from coredb import keydb
-import setupconfig, keymanager, filepaths
+import setup, keymanager, filepaths
from onionrutils import stringvalidators
createdirs.create_dirs()
-setupconfig.setup_config()
+setup.setup_config()
pub_key = keymanager.KeyManager().getPubkeyList()[0]
class KeyManagerTest(unittest.TestCase):
def test_sane_default(self):
diff --git a/onionr/tests/test_networkmerger.py b/onionr/tests/test_networkmerger.py
index 0054f697..386a6a5b 100644
--- a/onionr/tests/test_networkmerger.py
+++ b/onionr/tests/test_networkmerger.py
@@ -8,10 +8,10 @@ print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import networkmerger, createdirs
from coredb import keydb
-import setupconfig
+import setup
from utils import createdirs
createdirs.create_dirs()
-setupconfig.setup_config()
+setup.setup_config()
class NetworkMergerTest(unittest.TestCase):
def test_valid_merge(self):
adders = 'facebookcorewwwi.onion,mporbyyjhmz2c62shctbi3ngrslne5lpcyav6uzhxok45iblodhgjoad.onion'