2019-06-01 16:54:36 +00:00
|
|
|
'''
|
2019-06-12 20:12:56 +00:00
|
|
|
Onionr - Private P2P Communication
|
2019-06-01 16:54:36 +00:00
|
|
|
|
|
|
|
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
|
2019-06-25 23:07:35 +00:00
|
|
|
from onionrutils import stringvalidators
|
2019-07-19 04:59:44 +00:00
|
|
|
from onionrstorage import removeblock
|
2019-10-14 00:56:14 +00:00
|
|
|
from onionrstorage import deleteBlock
|
2019-09-21 23:49:24 +00:00
|
|
|
from onionrblocks import onionrblacklist
|
2019-10-14 00:56:14 +00:00
|
|
|
from utils import reconstructhash
|
2019-09-21 23:49:24 +00:00
|
|
|
|
2019-08-05 23:09:04 +00:00
|
|
|
def ban_block():
|
2019-10-14 00:56:14 +00:00
|
|
|
"""Deletes a block, permanently blacklisting it"""
|
2019-08-05 23:09:04 +00:00
|
|
|
blacklist = onionrblacklist.OnionrBlackList()
|
2019-06-01 16:54:36 +00:00
|
|
|
try:
|
|
|
|
ban = sys.argv[2]
|
|
|
|
except IndexError:
|
2019-10-14 00:56:14 +00:00
|
|
|
# Get the hash if its not provided as a CLI argument
|
|
|
|
ban = logger.readline('Enter a block hash:').strip()
|
|
|
|
# Make sure the hash has no truncated zeroes
|
|
|
|
ban = reconstructhash.reconstruct_hash(ban)
|
2019-06-25 23:07:35 +00:00
|
|
|
if stringvalidators.validate_hash(ban):
|
2019-08-05 23:09:04 +00:00
|
|
|
if not blacklist.inBlacklist(ban):
|
2019-06-01 16:54:36 +00:00
|
|
|
try:
|
2019-08-05 23:09:04 +00:00
|
|
|
blacklist.addToDB(ban)
|
2019-07-19 04:59:44 +00:00
|
|
|
removeblock.remove_block(ban)
|
2019-10-14 00:56:14 +00:00
|
|
|
deleteBlock(ban)
|
2019-06-01 16:54:36 +00:00
|
|
|
except Exception as error:
|
2019-06-19 20:29:27 +00:00
|
|
|
logger.error('Could not blacklist block', error=error, terminal=True)
|
2019-06-01 16:54:36 +00:00
|
|
|
else:
|
2019-06-19 20:29:27 +00:00
|
|
|
logger.info('Block blacklisted', terminal=True)
|
2019-06-01 16:54:36 +00:00
|
|
|
else:
|
2019-06-19 20:29:27 +00:00
|
|
|
logger.warn('That block is already blacklisted', terminal=True)
|
2019-06-01 16:54:36 +00:00
|
|
|
else:
|
2019-08-29 22:17:47 +00:00
|
|
|
logger.error('Invalid block hash', terminal=True)
|
|
|
|
|
2019-09-21 23:49:24 +00:00
|
|
|
ban_block.onionr_help = "<block hash>: deletes and blacklists a block"
|