Exemple #1
0
def mixnet_url_process(mixnet_url):
    catalog_url, endpoint_id = split_mixnet_url(mixnet_url)
    cfg.set_value("CATALOG_URL", catalog_url)
    client.register_catalog_url(catalog_url)
    print endpoint_id
    endpoint = client.endpoint_info(endpoint_id)
    if endpoint["status"] != "OPEN":
        abort("Endpoint is not open.")
    if endpoint["endpoint_type"] != "SPHINXMIX_GATEWAY":
        abort("Not a SPHINXMIX_GATEWAY.")

    peer_id = endpoint["peer_id"]
    cfg.set_value("PEER_ID", peer_id)
    peer = client.peer_info(peer_id)

    assert peer["crypto_backend"] == TYPE
    backend = common.BACKENDS[TYPE]
    client.register_backend(backend)
    cfg.set_value("CRYPTO_BACKEND", backend)
    crypto_params = canonical.from_unicode_canonical(peer["crypto_params"])
    cfg.set_value("CRYPTO_PARAMS", crypto_params)

    description = {"gateway": endpoint,
                   "mixnet_peer": peer}
    cfg.set_value("MIXNET_DESCRIPTION", description)
Exemple #2
0
def _check_ep_negotiation(negotiation_id, initial_contrib):
    contributions = filter_data_only(client.contribution_list(negotiation_id))
    contributions = [c for c in contributions if c["latest"]]
    combined_peer_id = cfg.get("CREATE_COMBINED_PEER_ID")
    combined_peer = client.peer_info(combined_peer_id)
    owners = set(unpack_owners(combined_peer["owners"]))

    orig_body = None
    for contribution in contributions:
        signer = contribution["signer_key_id"]
        text = get_contribution_text(contribution)
        body = text["body"]
        if orig_body is None:
            orig_body = body
        if orig_body != body:
            raise ValueError("contribution texts differ")
        check_signer(owners, signer)
    if owners:
        raise Block("Contribution pending from: %s" % owners)
    ui.inform("All peer owners have agreed. Sending accept contribution.")
    text = get_contribution_text(initial_contrib)
    body = text["body"]
    meta = text["meta"]
    meta = hash_meta_next_negotiation(meta)
    r = client.run_contribution(negotiation_id,
                                body,
                                accept=True,
                                extra_meta=meta)
    d = r.json()
    contribution = d["data"]
    ui.inform("Sent contribution %s" % contribution["id"])
    return contribution
Exemple #3
0
def join_combined_peer(negotiation):
    text = get_negotiation_text(negotiation)
    peer_id = text["body"]["data"]["peer_id"]
    peer = client.peer_info(peer_id)
    if peer is not None:
        ui.inform("Combined peer %s is created." % peer_id)
        return peer_id
    raise Block("Waiting for the combined peer to be created.")
Exemple #4
0
def create_ep_contribution(cycle, negotiation_id, peer_id):
    peer = client.peer_info(peer_id)
    owners = sorted(unpack_owners(peer["owners"]))
    endpoint_id = get_endpoint_id(cycle)
    size_min = on("MIN_SIZE", get_min_size)
    size_max = on("MAX_SIZE", get_max_size)
    next_neg = read_next_negotiation_id()

    attrs = client.backend.make_description(endpoint_id, peer_id, owners,
                                            size_min, size_max)

    d = client.endpoints_create_contribution(attrs,
                                             negotiation_id,
                                             accept=False,
                                             next_negotiation_id=next_neg)
    return d["data"]
Exemple #5
0
def register_peer_with_owners(combined_peer_id):
    cfg.set_value("COMBINED_PEER_ID", combined_peer_id)
    peer = client.peer_info(combined_peer_id)
    client.peer_import(combined_peer_id)
    for owner in peer["owners"]:
        client.peer_import(owner["owner_key_id"])