refactored onionr commands and other small adjustments
This commit is contained in:
parent
7e85b4a995
commit
3322778ff4
7 changed files with 96 additions and 50 deletions
|
@ -1,5 +1,5 @@
|
|||
'''
|
||||
Onionr - P2P Anonymous Storage Network
|
||||
Onionr - Private P2P Communication
|
||||
|
||||
This module defines commands for CLI usage
|
||||
'''
|
||||
|
@ -20,7 +20,7 @@
|
|||
|
||||
import webbrowser, sys
|
||||
import logger
|
||||
from . import pubkeymanager, onionrstatistics, daemonlaunch, filecommands, plugincommands, keyadders
|
||||
from . import pubkeymanager, onionrstatistics, daemonlaunch, filecommands, plugincommands, keyadders, banblocks, exportblocks
|
||||
|
||||
def show_help(o_inst, command):
|
||||
|
||||
|
|
39
onionr/onionrcommands/banblocks.py
Normal file
39
onionr/onionrcommands/banblocks.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
'''
|
||||
Onionr - P2P Anonymous Storage Network
|
||||
|
||||
This file contains the command for banning blocks from the node
|
||||
'''
|
||||
'''
|
||||
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 sys
|
||||
import logger
|
||||
def ban_block(o_inst):
|
||||
try:
|
||||
ban = sys.argv[2]
|
||||
except IndexError:
|
||||
ban = logger.readline('Enter a block hash:')
|
||||
if o_inst.onionrUtils.validateHash(ban):
|
||||
if not o_inst.onionrCore._blacklist.inBlacklist(ban):
|
||||
try:
|
||||
o_inst.onionrCore._blacklist.addToDB(ban)
|
||||
o_inst.onionrCore.removeBlock(ban)
|
||||
except Exception as error:
|
||||
logger.error('Could not blacklist block', error=error)
|
||||
else:
|
||||
logger.info('Block blacklisted')
|
||||
else:
|
||||
logger.warn('That block is already blacklisted')
|
||||
else:
|
||||
logger.error('Invalid block hash')
|
42
onionr/onionrcommands/exportblocks.py
Normal file
42
onionr/onionrcommands/exportblocks.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
|
||||
This file handles the command for exporting blocks to disk
|
||||
'''
|
||||
'''
|
||||
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 sys
|
||||
import logger, onionrstorage
|
||||
def doExport(o_inst, bHash):
|
||||
exportDir = o_inst.dataDir + 'block-export/'
|
||||
if not os.path.exists(exportDir):
|
||||
if os.path.exists(o_inst.dataDir):
|
||||
os.mkdir(exportDir)
|
||||
else:
|
||||
logger.error('Onionr Not initialized')
|
||||
data = onionrstorage.getData(o_inst.onionrCore, bHash)
|
||||
with open('%s/%s.dat' % (exportDir, bHash), 'wb') as exportFile:
|
||||
exportFile.write(data)
|
||||
|
||||
def export_block(o_inst):
|
||||
exportDir = o_inst.dataDir + 'block-export/'
|
||||
try:
|
||||
assert o_inst.onionrUtils.validateHash(sys.argv[2])
|
||||
except (IndexError, AssertionError):
|
||||
logger.error('No valid block hash specified.')
|
||||
sys.exit(1)
|
||||
else:
|
||||
bHash = sys.argv[2]
|
||||
o_inst.doExport(bHash)
|
Loading…
Add table
Add a link
Reference in a new issue