Exemplo n.º 1
0
def ban_block():
    """Deletes a block, permanently blacklisting it"""
    blacklist = onionrblacklist.OnionrBlackList()
    try:
        ban = sys.argv[2]
    except IndexError:
        # 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)
    if stringvalidators.validate_hash(ban):
        if not blacklist.inBlacklist(ban):
            try:
                blacklist.addToDB(ban)
                removeblock.remove_block(ban)
                deleteBlock(ban)
            except Exception as error:
                logger.error('Could not blacklist block',
                             error=error,
                             terminal=True)
            else:
                logger.info('Block blacklisted', terminal=True)
        else:
            logger.warn('That block is already blacklisted', terminal=True)
    else:
        logger.error('Invalid block hash', terminal=True)
Exemplo n.º 2
0
def delete_plaintext_no_blacklist():
    """Delete, but do not blacklist, plaintext blocks."""

    block_list = blockmetadb.get_block_list()

    for block in block_list:
        block = Block(hash=block)
        if not block.isEncrypted:
            remove_block(block.hash)
            onionrstorage.deleteBlock(block.hash)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def test_sneakernet_import(test_manager):
    in_db = lambda b: b in get_block_list()
    bl = insert(os.urandom(10))
    assert in_db(bl)
    export_block(bl)
    assert os.path.exists(export_location + bl + BLOCK_EXPORT_FILE_EXT)
    remove_block(bl)
    deleteBlock(bl)
    assert not in_db(bl)
    os.remove(data_nonce_file)
    move(export_location + bl + BLOCK_EXPORT_FILE_EXT, block_data_location)
    sleep(1)
    assert in_db(bl)
Exemplo n.º 5
0
    def delete(self):
        """
            Deletes the block's file and records, if they exist

            Outputs:
            - (bool): whether or not the operation was successful
        """

        if self.exists():
            try:
                os.remove(self.getBlockFile())
            except TypeError:
                pass
            b_hash = self.getHash()
            onionrstorage.deleteBlock(b_hash)
            removeblock.remove_block(b_hash)
            return True
        return False
Exemplo n.º 6
0
def clean_old_blocks(comm_inst):
    '''Delete old blocks if our disk allocation is full/near full, and also expired blocks'''
    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(comm_inst, bHash)
        logger.info('Deleted block: %s' % (bHash, ))

    while comm_inst.storage_counter.is_full():
        oldest = blockmetadb.get_block_list()[0]
        blacklist.addToDB(oldest)
        removeblock.remove_block(oldest)
        onionrstorage.deleteBlock(oldest)
        __remove_from_upload.remove(comm_inst, oldest)
        logger.info('Deleted block: %s' % (oldest, ))

    comm_inst.decrementThreadCount('clean_old_blocks')
Exemplo n.º 7
0
def clean_old_blocks(comm_inst):
    """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(comm_inst, bHash)
        logger.info('Deleted block: %s' % (bHash, ))

    while storage_counter.is_full():
        try:
            oldest = blockmetadb.get_block_list()[0]
        except IndexError:
            break
        else:
            blacklist.addToDB(oldest)
            removeblock.remove_block(oldest)
            onionrstorage.deleteBlock(oldest)
            __remove_from_upload(comm_inst, oldest)
            logger.info('Deleted block: %s' % (oldest, ))

    comm_inst.decrementThreadCount('clean_old_blocks')