Пример #1
0
 def test_deconstruct(self):
     h = b"0000e918d24999ad9b0ff00c1d414f36b74afc93871a0ece4bd452f82b56af87"
     h_no = b"e918d24999ad9b0ff00c1d414f36b74afc93871a0ece4bd452f82b56af87"
     self.assertEqual(reconstructhash.deconstruct_hash(h), h_no)
     h = "0000e918d24999ad9b0ff00c1d414f36b74afc93871a0ece4bd452f82b56af87"
     h_no = "e918d24999ad9b0ff00c1d414f36b74afc93871a0ece4bd452f82b56af87"
     self.assertEqual(reconstructhash.deconstruct_hash(h), h_no)
Пример #2
0
def on_processblocks(api, data=None):
    metadata = data['block'].bmetadata # Get the block metadata
    if data['type'] != 'brd':
        return

    b_hash = reconstructhash.deconstruct_hash(data['block'].hash) # Get the 0-truncated block hash
    board_cache = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/board-index.cache.json', flush_on_exit=False) # get the board index cache
    board_cache.refresh()
    # Validate the channel name is sane for caching
    try:
        ch = metadata['ch']
    except KeyError:
        ch = 'global'
    ch_len = len(ch)
    if ch_len == 0:
        ch = 'global'
    elif ch_len > 12:
        return
    
    existing_posts = board_cache.get(ch)
    if existing_posts is None:
        existing_posts = []
    existing_posts.append(data['block'].hash)
    board_cache.put(ch, existing_posts)
    board_cache.flush()
Пример #3
0
 def get_session(
     self, block_hash: Union(str, bytes)) -> session.UploadSession:
     block_hash = reconstructhash.deconstruct_hash(
         bytesconverter.bytes_to_str(block_hash))
     for session in self.sessions:
         if session.block_hash == block_hash: return session
     raise KeyError
Пример #4
0
 def removeSent(self, blockID):
     blockID = reconstructhash.deconstruct_hash(blockID)
     self.connect()
     args = (blockID, )
     self.cursor.execute('DELETE FROM sent where hash=?', args)
     self.conn.commit()
     self.close()
     return
Пример #5
0
 def addToSent(self, blockID, peer, message, subject=''):
     blockID = reconstructhash.deconstruct_hash(blockID)
     self.connect()
     args = (blockID, peer, message, subject, epoch.get_epoch())
     self.cursor.execute('INSERT INTO sent VALUES(?, ?, ?, ?, ?)', args)
     self.conn.commit()
     self.close()
     return
Пример #6
0
    def __init__(self, block_hash: Union[str, bytes]):
        block_hash = bytesconverter.bytes_to_str(block_hash)
        block_hash = reconstructhash.reconstruct_hash(block_hash)
        if not stringvalidators.validate_hash(block_hash): raise ValueError

        self.start_time = epoch.get_epoch()
        self.block_hash = reconstructhash.deconstruct_hash(block_hash)
        self.total_fail_count: int = 0
        self.total_success_count: int = 0
        self.peer_fails = {}
        self.peer_exists = {}
Пример #7
0
def mail_delete(block):
    if not stringvalidators.validate_hash(block):
        abort(504)
    block = reconstructhash.deconstruct_hash(block)
    existing = kv.get('deleted_mail')
    if existing is None:
        existing = []
    if block not in existing:
        existing.append(block)
    kv.put('deleted_mail', existing)
    kv.flush()
    return 'success'
Пример #8
0
def get_public_block_list(publicAPI, request):
    # Provide a list of our blocks, with a date offset
    dateAdjust = request.args.get('date')
    bList = blockmetadb.get_block_list(dateRec=dateAdjust)
    share_list = ''
    if config.get('general.hide_created_blocks', True):
        for b in publicAPI.hideBlocks:
            if b in bList:
                # Don't share blocks we created if they haven't been *uploaded* yet, makes it harder to find who created a block
                bList.remove(b)
    for b in bList:
        share_list += '%s\n' % (reconstructhash.deconstruct_hash(b), )
    return Response(share_list)
Пример #9
0
def load_inbox():
    inbox_list = []
    deleted = simplekv.DeadSimpleKV(identifyhome.identify_home() +
                                    '/mailcache.dat').get('deleted_mail')
    if deleted is None:
        deleted = []

    for blockHash in blockmetadb.get_blocks_by_type('pm'):
        block = onionrblockapi.Block(blockHash)
        block.decrypt()
        if block.decrypted and reconstructhash.deconstruct_hash(
                blockHash) not in deleted:
            inbox_list.append(blockHash)
    return inbox_list
Пример #10
0
def get_public_block_list(public_API, request):
    # Provide a list of our blocks, with a date offset
    date_adjust = request.args.get('date')
    type_filter = request.args.get('type')
    b_list = blockmetadb.get_block_list(date_rec=date_adjust)
    share_list = ''
    if config.get('general.hide_created_blocks', True):
        for b in public_API.hideBlocks:
            if b in b_list:
                # Don't share blocks we created if they haven't been *uploaded* yet, makes it harder to find who created a block
                b_list.remove(b)
    for b in b_list:
        if type_filter:
            if Block(b, decrypt=False).getType() != type_filter:
                continue
        share_list += '%s\n' % (reconstructhash.deconstruct_hash(b), )
    return Response(share_list)