def send_message(text=None, recipient=None): if recipient is None: recipient = ui.ask_value("recipient", "Message recipient") if text is None: text = ui.ask_value("text", "Message text") payload = {"recipient": recipient, "message": text} r = requests.post(SEND_ADDRESS, data=payload) if r.status_code != requests.codes.ok: ui.inform("Failed with code: %s" % r.status_code) exit() ui.inform("Sent message with id %s" % r.content)
def set_catalog_url_wizard(): default = "http://127.0.0.1:8000/" response = ui.ask_value("CATALOG_URL", "Set CATALOG_URL (default: '%s')" % default) if not response: response = default return response
def join_mixnet_wizard(): inv = on( "JOIN_INVITATION", lambda: ui.ask_value( "JOIN_INVITATION", "Give invitation to create mix peer")) negotiation_id, invitation_id = split_invitation(inv) contrib = on("JOIN_COORD_INITIAL_CONTRIBUTION", lambda: _check_initial_contribution(negotiation_id)) initial_contribution_info(contrib) backend = on("JOIN_CRYPTO_BACKEND", lambda: join_backend_set(contrib)) register_crypto_backend(backend) crypto_params = on("JOIN_CRYPTO_PARAMS", lambda: join_crypto_params_set(contrib)) on("CRYPTO_PARAMS", lambda: crypto_params) key_and_peer_wizard() on("JOIN_CONTRIBUTION_ID", lambda: join_contribution(negotiation_id, contrib, invitation_id)) second_contrib = on( "JOIN_COORD_SECOND_CONTRIBUTION", retry( lambda: _join_coord_second_contribution(negotiation_id, contrib))) on("JOIN_SECOND_CONTRIBUTION_ID", lambda: _join_second_contribution(negotiation_id, second_contrib)) finished_neg = on("JOIN_FINISHED_NEGOTIATION", retry(lambda: finished_negotiation(negotiation_id))) combined_peer_id = on("COMBINED_PEER_ID", retry(lambda: join_combined_peer(finished_neg))) register_peer_with_owners(combined_peer_id)
def key_and_peer_wizard(): on("KEY", common.set_key_wizard) client.register_crypto_client(cfg) name = on( "PEER_NAME", lambda: utils.locale_to_unicode( ui.ask_value("PEER_NAME", "Specify name to register as peer"))) peer_id = on("PEER_ID", lambda: do_register_wizard(name)) client.peer_import(peer_id)
def main(text=None, recipient=None): import os ui.inform("Welcome to Panoramix sphinxmix agent!") ui.inform("Configuration file is: %s" % common.config_file) ui.inform("Set PANORAMIX_CONFIG environment variable to override") url = on("MIXNET_URL", lambda: ui.ask_value("MIXNET_URL", "Give sphinxmix mixnet URL")) mixnet_url_process(url) on("KEY", common.set_key_wizard) agent.main()
def get_join_response(): default = "yes" if autodefault: return default response = ui.ask_value( "response", "Send join contribution? (yes/no) (default: '%s')" % default) if not response: return default if response != "yes": abort()
def get_restart_response(role): if autodefault: return "yes" default = "yes" verb = role.capitalize() response = ui.ask_value( "RESTART", "%s a new cycle? (yes/no) (default: %s): " % (verb, default)) if not response: return "yes" if response != "yes": exit()
def main(): args = parser.parse_args() global autodefault autodefault = args.yes ui.inform("Welcome to Panoramix wizard!") ui.inform("Configuration file is: %s" % common.config_file) ui.inform("Set PANORAMIX_CONFIG environment variable to override") catalog_url = on("CATALOG_URL", set_catalog_url_wizard) client.register_catalog_url(catalog_url) role = on("SETUP_ROLE", lambda: ui.ask_value("role", "Choose 'create' or 'join' mixnet")) mixnet_creation_wizard(role) handle_endpoints_wizard(role)
def join_crypto_params_set(contrib): text = get_contribution_text(contrib) crypto_params = text["body"]["data"]["crypto_params"] crypto_params = canonical.from_unicode_canonical(crypto_params) default = "accept" response = ui.ask_value( "response", "Proposed crypto params: '%s'; " "'accept' or 'abort'? (default: '%s')" % (crypto_params, default)) if not response: response = default if response == "accept": return crypto_params elif response == "abort": abort()
def join_backend_set(contrib): text = get_contribution_text(contrib) crypto_backend = text["body"]["data"]["crypto_backend"] default = "accept" response = ui.ask_value( "response", "Proposed crypto backend: '%s'; " "'accept' or 'abort'? (default: '%s')" % (crypto_backend, default)) if not response: response = default if response == "accept": crypto_backend = BACKENDS[crypto_backend] return crypto_backend elif response == "abort": abort()
def set_catalog_url(): default = "http://127.0.0.1:8000/" description = "Set CATALOG_URL: (enter for default '%s')" % default value = ui.ask_value("CATALOG_URL", description) return value or default
def get_endpoint_name(): return utils.locale_to_unicode( ui.ask_value("ENDPOINT_NAME", "Specify endpoint name to create on combined peer"))
def get_max_size(): return int(ui.ask_value("MAX_SIZE", "Specify maximum size: "))
def get_min_size(): return int(ui.ask_value("MIN_SIZE", "Specify minimum size"))
def create_invitations(): num = int( ui.ask_value("invitations", "Give number of invitations to create")) return mk_invitations(num)
def create_contribution_id(negotiation_id): name = utils.locale_to_unicode( ui.ask_value("name", "Choose mixnet peer name")) return create_provisional_peer_contrib(negotiation_id, name)