示例#1
0
def matches_with_decrypt(triple, decrypt_fn):
    (sub, pre, obj) = triple
    logging.debug(f'Find matches for({sub}, {pre}, {obj})')

    # protect against bad requests for (None, None, None) or (?, None, ?)
    if not sub and not obj:
        raise RuntimeException(
            'Searching for (None, None, None) or (None, ?, None) is prohibited)'
        )

    # get matching pointer
    pointer_pattern = patterns.make_pattern(sub, pre, obj)
    pointers_raw = dht.get_pointers(pointer_pattern)

    # gotta see if we can decrypt these pointers
    pointers = map(lambda p: decrypt_fn(sub, pre, obj, p), pointers_raw)
    claims = {}

    for pointer in pointers:
        if pointer:
            claim = Claim.from_hex(dht.get_claim(pointer.id), pointer.key)
            logging.info(
                f'Claim found= {pointer.id[0:10]}...{pointer.id[-10:]}')
            claims[claim.get_id()] = claim

    # topgraphical sort + return
    return kahnsort(claims.values())
示例#2
0
def claim_get(id):
    logging.debug('----------------------------------------')

    key = request.values.get('key', None)
    data = dht.get_claim(id)
    if data:
        if key:
            claim = Claim.from_hex(data, key)  # FIXME key needs decoding.
            return Response(claim.to_json(False), mimetype='application/json')
        else:
            return Response(json.dumps({'data': data}),
                            mimetype='application/json')
    else:
        return abort(404)