예제 #1
0
파일: wizard.py 프로젝트: tud-dud/panoramix
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
예제 #2
0
파일: wizard.py 프로젝트: tud-dud/panoramix
def check_compare_texts(orig_text, new_text):
    orig_body = orig_text["body"]
    new_body = new_text["body"]
    me = cfg.get("PEER_ID")
    orig_data = orig_body["data"].copy()
    new_data = new_body["data"].copy()
    orig_owners = orig_data.pop("owners")
    new_owners = new_data.pop("owners")
    orig_data.pop("key_data")
    orig_data.pop("peer_id")
    new_key_data = new_data.pop("key_data")
    new_peer_id = new_data.pop("peer_id")

    if orig_data != new_data:
        abort("Contribution data has changed.")
    if orig_owners[0] not in new_owners:
        abort("Coordinator missing from owners.")
    if mk_owner_d(me) not in new_owners:
        abort("Peer missing from owners.")
    new_owners_list = unpack_owners(new_owners)
    for owner in new_owners_list:
        client.peer_import(owner)
    combined_data = client.crypto_client.combine_keys(new_owners_list)
    combined_key = client.crypto_client.get_key_id_from_key_data(combined_data)
    if combined_data != new_key_data:
        abort("Wrong combined key data.")
    if combined_key != new_peer_id:
        abort("Wrong combined peer id.")
예제 #3
0
파일: wizard.py 프로젝트: tud-dud/panoramix
def process_own_endpoint(endpoint_id):
    peer_id = cfg.get("PEER_ID")
    messages, log = client.inbox_process(endpoint_id, peer_id, upload=True)
    params = client.record_process_prepare(endpoint_id, log)
    if params == "wrongstatus":
        abort("Wrong status")
    endpoint = client.with_self_consensus(client.endpoint_action, params)
    endpoint_id = endpoint["endpoint_id"]
    ui.inform("Processed endpoint %s" % endpoint_id)
    return endpoint_id
예제 #4
0
파일: wizard.py 프로젝트: tud-dud/panoramix
def create_provisional_peer_contrib(neg_id, name):
    peer_id = cfg.get("PEER_ID")
    next_neg = read_next_negotiation_id()
    is_contrib, d = client.peer_create(name,
                                       set_key=False,
                                       owners=[peer_id],
                                       negotiation_id=neg_id,
                                       next_negotiation_id=next_neg)
    assert is_contrib
    return d["data"]["id"]
예제 #5
0
파일: wizard.py 프로젝트: tud-dud/panoramix
def handle_endpoints_wizard(role):
    while True:
        cycle = on("CYCLE", lambda: 1)

        peer_id = cfg.get("PEER_ID")
        combined_peer_id = cfg.get("COMBINED_PEER_ID")

        if role == "create":
            endpoints = create_endpoint_wizard(cycle, combined_peer_id)
        elif role == "join":
            endpoints = join_endpoint_wizard(cycle)

        endpoint_ids = [e["endpoint_id"] for e in endpoints]
        remaining = endpoint_ids
        while remaining:
            ui.inform("Still need to handle endpoints %s." % remaining)
            remaining = operate(remaining, peer_id, combined_peer_id, role)
            time.sleep(3)
        get_restart_response(role)
        ui.inform("Starting a new cycle...")
        cfg.set_value("CYCLE", cycle + 1)
예제 #6
0
파일: wizard.py 프로젝트: tud-dud/panoramix
def check_negotiation_wizard(negotiation_id, invitations):
    invitations = list(invitations)
    me = cfg.get("PEER_ID")
    contributions = filter_data_only(client.contribution_list(negotiation_id))
    contributions = [c for c in contributions if c["latest"]]
    signers = [me]
    orig_body = None
    orig_next_negotiation_id = read_next_negotiation_id()
    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")
        meta = text["meta"]
        invitation_id = meta.get("invitation_id")
        if invitation_id is not None:
            check_invitation(invitations, invitation_id)
            client.peer_import(signer)
            signers.append(signer)
            # print "Imported peer %s" % signer
        elif signer != me:
            raise ValueError("uninvited contribution!")
        next_negotiation_id = meta.get("next_negotiation_id")
        if next_negotiation_id != orig_next_negotiation_id:
            raise ValueError("wrong next_negotiation_id")
    if invitations:
        raise Block("Invitations pending: %s" % invitations)
    ui.inform("All invited peers have joined. Sending accept contribution.")
    name = orig_body["data"]["name"]
    next_negotiation_id = orig_body["info"].get("next_negotiation_id")
    hashed_next_negotiation_id = utils.hash_string(orig_next_negotiation_id)
    is_contrib, d = client.peer_create(
        name,
        set_key=True,
        owners=signers,
        negotiation_id=negotiation_id,
        accept=True,
        next_negotiation_id=hashed_next_negotiation_id)
    assert is_contrib
    contrib_id = d["data"]["id"]
    ui.inform("Your new contribution id is: %s" % contrib_id)
    return contrib_id
예제 #7
0
파일: wizard.py 프로젝트: tud-dud/panoramix
def operate_on_closed_endpoint_coord(endpoint_id):
    setting = suffixed_setting(endpoint_id)
    neg_id = on(setting("PROCESS_NEGOTIATION_ID"),
                new_negotiation_id_from_stream)

    hashes = on(setting("LINKED_PROCESSBOX"),
                lambda: get_endpoint_input(endpoint_id, PROCESSBOX))

    if hashes is None:
        peer_id = cfg.get("PEER_ID")
        log = on(setting("PROCESSING"),
                 lambda: do_processing(endpoint_id, peer_id))
    else:
        log = client.mk_process_log(hashes, "", wrap=False)

    contrib = on(
        setting("PROCESS_CONTRIBUTION"),
        lambda: create_ep_record_contribution(endpoint_id, neg_id, log))
    on(setting("PROCESS_SECOND_CONTRIBUTION"),
       lambda: _check_ep_negotiation(neg_id, contrib))
    finished_neg = on(setting("PROCESS_FINISHED_NEGOTIATION"),
                      lambda: finished_negotiation(neg_id))
    on(setting("APPLY_PROCESS"),
       lambda: apply_endpoint_consensus(endpoint_id, finished_neg))
예제 #8
0
def inform_launch():
    catalog_url = cfg.get("CATALOG_URL")
    ui.inform("Start server with\n"
              " %s=%s panoramix-manage runserver %s" %
              (common.ENV_CONFIG, config_file, clean_url(catalog_url)))
예제 #9
0
파일: wizard.py 프로젝트: tud-dud/panoramix
def read_next_negotiation_id():
    return cfg.get("NEXT_NEGOTIATION_ID")
예제 #10
0
파일: wizard.py 프로젝트: tud-dud/panoramix
def prepare_output_file():
    cycle = cfg.get("CYCLE") - 1
    with open(output_cycle, "w") as f:
        f.write("%s" % cycle)
    ui.inform("Wrote cycle id: %s" % cycle)