diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-06 08:43:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-06 08:43:16 +0000 |
commit | aece72e29b041e2dfbc5b49d2fd0d49f8ab2124e (patch) | |
tree | cce216b507c99bf6723e15da5158e68a57a55f41 | |
parent | 310f312557954662ffc32f74bbacdb63d76ede3d (diff) |
addressing #3431
-rw-r--r-- | src/conversation/conversation_api.c | 91 | ||||
-rw-r--r-- | src/conversation/gnunet-conversation.c | 86 | ||||
-rw-r--r-- | src/conversation/test_conversation_api.c | 6 | ||||
-rw-r--r-- | src/conversation/test_conversation_api_reject.c | 9 | ||||
-rw-r--r-- | src/conversation/test_conversation_api_twocalls.c | 4 | ||||
-rw-r--r-- | src/include/gnunet_conversation_service.h | 6 | ||||
-rw-r--r-- | src/include/gnunet_namestore_service.h | 1 |
7 files changed, 73 insertions, 130 deletions
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c index 4e9901c81b..bc6d0f4601 100644 --- a/src/conversation/conversation_api.c +++ b/src/conversation/conversation_api.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - (C) 2013 Christian Grothoff (and other contributing authors) + (C) 2013, 2014 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -38,11 +38,6 @@ enum CallerState { /** - * We still need to reverse lookup the caller ID. - */ - CS_RESOLVE, - - /** * The phone is ringing (user knows about incoming call). */ CS_RINGING, @@ -112,21 +107,11 @@ struct GNUNET_CONVERSATION_Caller struct GNUNET_MICROPHONE_Handle *mic; /** - * Active NAMESTORE lookup (or NULL). - */ - struct GNUNET_NAMESTORE_QueueEntry *qe; - - /** * Identity of the person calling us. */ struct GNUNET_CRYPTO_EcdsaPublicKey caller_id; /** - * Caller ID of the person calling us as a string. - */ - char *caller_id_str; - - /** * Internal handle to identify the caller with the service. */ uint32_t cid; @@ -238,40 +223,6 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone); /** - * We have resolved the caller ID using our name service. - * - * @param cls the `struct GNUNET_CONVERSATION_Caller` - * @param zone our zone used for resolution - * @param label name of the caller - * @param rd_count number of records we have in @a rd - * @param rd records we have for the caller's label - */ -static void -handle_caller_name (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, - const char *label, - unsigned int rd_count, - const struct GNUNET_GNSRECORD_Data *rd) -{ - struct GNUNET_CONVERSATION_Caller *caller = cls; - struct GNUNET_CONVERSATION_Phone *phone = caller->phone; - char *name; - - caller->qe = NULL; - if (NULL == label) - name = GNUNET_strdup (GNUNET_GNSRECORD_pkey_to_zkey (&caller->caller_id)); - else - GNUNET_asprintf (&name, "%s.gnu", label); - caller->caller_id_str = name; - caller->state = CS_RINGING; - phone->event_handler (phone->event_handler_cls, - GNUNET_CONVERSATION_EC_PHONE_RING, - caller, - name); -} - - -/** * Process recorded audio data. * * @param cls closure with the `struct GNUNET_CONVERSATION_Caller` @@ -323,14 +274,13 @@ handle_phone_ring (void *cls, GNUNET_CONTAINER_DLL_insert (phone->caller_head, phone->caller_tail, caller); - caller->state = CS_RESOLVE; caller->caller_id = ring->caller_id; caller->cid = ring->cid; - caller->qe = GNUNET_NAMESTORE_zone_to_name (phone->ns, - &phone->my_zone, - &ring->caller_id, - &handle_caller_name, - caller); + caller->state = CS_RINGING; + phone->event_handler (phone->event_handler_cls, + GNUNET_CONVERSATION_EC_PHONE_RING, + caller, + &caller->caller_id); break; } } @@ -364,19 +314,14 @@ handle_phone_hangup (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received HANG_UP message, terminating call with `%s'\n", - caller->caller_id_str); + GNUNET_GNSRECORD_pkey_to_zkey (&caller->caller_id)); switch (caller->state) { - case CS_RESOLVE: - /* application doesn't even know about call yet */ - GNUNET_NAMESTORE_cancel (caller->qe); - caller->qe = NULL; - break; case CS_RINGING: phone->event_handler (phone->event_handler_cls, GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, caller, - caller->caller_id_str); + &caller->caller_id); break; case CS_ACTIVE: caller->speaker->disable_speaker (caller->speaker->cls); @@ -384,7 +329,7 @@ handle_phone_hangup (void *cls, phone->event_handler (phone->event_handler_cls, GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, caller, - caller->caller_id_str); + &caller->caller_id); break; case CS_CALLEE_SUSPENDED: case CS_CALLER_SUSPENDED: @@ -392,7 +337,7 @@ handle_phone_hangup (void *cls, phone->event_handler (phone->event_handler_cls, GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, caller, - caller->caller_id_str); + &caller->caller_id); break; } GNUNET_CONTAINER_DLL_remove (phone->caller_head, @@ -424,9 +369,6 @@ handle_phone_suspend (void *cls, return; switch (caller->state) { - case CS_RESOLVE: - GNUNET_break_op (0); - break; case CS_RINGING: GNUNET_break_op (0); break; @@ -472,9 +414,6 @@ handle_phone_resume (void *cls, return; switch (caller->state) { - case CS_RESOLVE: - GNUNET_break_op (0); - break; case CS_RINGING: GNUNET_break_op (0); break; @@ -522,9 +461,6 @@ handle_phone_audio_message (void *cls, return; switch (caller->state) { - case CS_RESOLVE: - GNUNET_break_op (0); - break; case CS_RINGING: GNUNET_break_op (0); break; @@ -581,7 +517,7 @@ clean_up_callers (struct GNUNET_CONVERSATION_Phone *phone) phone->event_handler (phone->event_handler_cls, GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, caller, - caller->caller_id_str); + &caller->caller_id); GNUNET_CONVERSATION_caller_hang_up (caller); } } @@ -781,10 +717,6 @@ GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller) switch (caller->state) { - case CS_RESOLVE: - GNUNET_NAMESTORE_cancel (caller->qe); - caller->qe = NULL; - break; case CS_ACTIVE: caller->speaker->disable_speaker (caller->speaker->cls); caller->mic->disable_microphone (caller->mic->cls); @@ -799,7 +731,6 @@ GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller) GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); hang->cid = caller->cid; GNUNET_MQ_send (phone->mq, e); - GNUNET_free_non_null (caller->caller_id_str); GNUNET_free (caller); } diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c index 532107aca5..11cad533b1 100644 --- a/src/conversation/gnunet-conversation.c +++ b/src/conversation/gnunet-conversation.c @@ -127,9 +127,9 @@ struct CallList struct GNUNET_CONVERSATION_Caller *caller; /** - * String identifying the caller. + * Public key identifying the caller. */ - char *caller_id; + struct GNUNET_CRYPTO_EcdsaPublicKey caller_id; /** * Unique number of the call. @@ -193,7 +193,7 @@ static struct GNUNET_CONFIGURATION_Handle *cfg; /** * Our ego. */ -static struct GNUNET_IDENTITY_Ego *caller_id; +static struct GNUNET_IDENTITY_Ego *my_caller_id; /** * Handle to identity service. @@ -206,7 +206,12 @@ static struct GNUNET_IDENTITY_Handle *id; static char *ego_name; /** - * Name of conversation partner (if any). + * Public key of active conversation partner (if any). + */ +static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key; + +/** + * Name of active conversation partner (if any). */ static char *peer_name; @@ -247,13 +252,13 @@ static int verbose; * @param cls closure * @param code type of the event * @param caller handle for the caller - * @param caller_id name of the caller in GNS + * @param caller_id public key of the caller (in GNS) */ static void phone_event_handler (void *cls, enum GNUNET_CONVERSATION_PhoneEventCode code, struct GNUNET_CONVERSATION_Caller *caller, - const char *caller_id) + const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) { struct CallList *cl; @@ -262,12 +267,12 @@ phone_event_handler (void *cls, case GNUNET_CONVERSATION_EC_PHONE_RING: FPRINTF (stdout, _("Incoming call from `%s'. Please /accept #%u or /cancel %u the call.\n"), - caller_id, + GNUNET_GNSRECORD_pkey_to_zkey (caller_id), caller_num_gen, caller_num_gen); cl = GNUNET_new (struct CallList); cl->caller = caller; - cl->caller_id = GNUNET_strdup (caller_id); + cl->caller_id = *caller_id; cl->caller_num = caller_num_gen++; GNUNET_CONTAINER_DLL_insert (cl_head, cl_tail, @@ -284,11 +289,10 @@ phone_event_handler (void *cls, } FPRINTF (stdout, _("Call from `%s' terminated\n"), - cl->caller_id); + GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl); - GNUNET_free (cl->caller_id); if (cl == cl_active) { cl_active = NULL; @@ -317,12 +321,12 @@ caller_event_handler (void *cls, case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: FPRINTF (stdout, _("Call from `%s' suspended by other user\n"), - cl->caller_id); + GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); break; case GNUNET_CONVERSATION_EC_CALLER_RESUME: FPRINTF (stdout, _("Call from `%s' resumed by other user\n"), - cl->caller_id); + GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); break; } } @@ -336,7 +340,7 @@ start_phone () { struct GNUNET_GNSRECORD_Data rd; - if (NULL == caller_id) + if (NULL == my_caller_id) { FPRINTF (stderr, _("Ego `%s' no longer available, phone is now down.\n"), @@ -346,7 +350,7 @@ start_phone () } GNUNET_assert (NULL == phone); phone = GNUNET_CONVERSATION_phone_create (cfg, - caller_id, + my_caller_id, &phone_event_handler, NULL); /* FIXME: get record and print full GNS record info later here... */ if (NULL == phone) @@ -402,13 +406,17 @@ call_event_handler (void *cls, GNUNET_break (CS_RESOLVING == call_state); FPRINTF (stdout, _("Failed to resolve `%s'\n"), - ego_name); + peer_name); + GNUNET_free (peer_name); + peer_name = NULL; call = NULL; break; case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: FPRINTF (stdout, - "%s", - _("Call terminated\n")); + _("Call to `%s' terminated\n"), + peer_name); + GNUNET_free (peer_name); + peer_name = NULL; call = NULL; break; case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: @@ -427,6 +435,7 @@ call_event_handler (void *cls, FPRINTF (stdout, _("Error with the call, restarting it\n")); call_state = CS_RESOLVING; + // FIXME: is this correct? break; } } @@ -505,7 +514,7 @@ do_unknown (const char *msg) static void do_call (const char *arg) { - if (NULL == caller_id) + if (NULL == my_caller_id) { FPRINTF (stderr, _("Ego `%s' not available\n"), @@ -531,13 +540,12 @@ do_call (const char *arg) case PS_ACCEPTED: FPRINTF (stderr, _("You are answering call from `%s', hang up or suspend that call first!\n"), - peer_name); + GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); return; case PS_ERROR: /* ok to call */ break; } - GNUNET_free_non_null (peer_name); if (NULL == arg) { FPRINTF (stderr, @@ -549,7 +557,7 @@ do_call (const char *arg) call_state = CS_RESOLVING; GNUNET_assert (NULL == call); call = GNUNET_CONVERSATION_call_start (cfg, - caller_id, + my_caller_id, arg, speaker, mic, @@ -586,7 +594,7 @@ do_accept (const char *args) case PS_ACCEPTED: FPRINTF (stderr, _("You are answering call from `%s', hang up or suspend that call first!\n"), - peer_name); + GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); return; case PS_ERROR: GNUNET_break (0); @@ -621,8 +629,7 @@ do_accept (const char *args) cl_tail, cl); cl_active = cl; - GNUNET_free_non_null (peer_name); - peer_name = GNUNET_strdup (cl->caller_id); + peer_key = cl->caller_id; phone_state = PS_ACCEPTED; GNUNET_CONVERSATION_caller_pick_up (cl->caller, &caller_event_handler, @@ -679,7 +686,7 @@ do_status (const char *args) case PS_ACCEPTED: FPRINTF (stdout, _("You are having a conversation with `%s'.\n"), - peer_name); + GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));; break; case PS_ERROR: FPRINTF (stdout, @@ -724,7 +731,7 @@ do_status (const char *args) FPRINTF (stdout, _("#%u: `%s'\n"), cl->caller_num, - cl->caller_id); + GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); } FPRINTF (stdout, "%s", @@ -822,7 +829,7 @@ do_resume (const char *args) case PS_ACCEPTED: FPRINTF (stderr, _("Already talking with `%s', cannot resume a call right now.\n"), - peer_name); + GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); return; } GNUNET_assert (NULL == cl_active); @@ -915,7 +922,6 @@ do_reject (const char *args) GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl); - GNUNET_free (cl->caller_id); GNUNET_free (cl); break; case PS_ACCEPTED: @@ -1046,11 +1052,20 @@ do_stop_task (void *cls, GNUNET_free (ego_name); ego_name = NULL; GNUNET_free_non_null (peer_name); + peer_name = NULL; phone_state = PS_ERROR; } + +/** + * Handle user command. + * + * @param message command the user typed in + * @param str_len number of bytes to process in @a message + */ static void -handle_command_string (char *message, size_t str_len) +handle_command_string (char *message, + size_t str_len) { size_t i; const char *ptr; @@ -1078,9 +1093,10 @@ handle_command_string (char *message, size_t str_len) #ifdef WINDOWS -int -console_reader_chars (void *cls, void *client, - const struct GNUNET_MessageHeader *message) +static int +console_reader_chars (void *cls, + void *client, + const struct GNUNET_MessageHeader *message) { char *chars; size_t str_size; @@ -1144,7 +1160,7 @@ identity_cb (void *cls, { if (NULL == name) return; - if (ego == caller_id) + if (ego == my_caller_id) { if (verbose) FPRINTF (stdout, @@ -1163,10 +1179,10 @@ identity_cb (void *cls, FPRINTF (stdout, _("Our ego `%s' was deleted!\n"), ego_name); - caller_id = NULL; + my_caller_id = NULL; return; } - caller_id = ego; + my_caller_id = ego; GNUNET_CONFIGURATION_set_value_number (cfg, "CONVERSATION", "LINE", diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c index 9714d5a81b..862b71e6b4 100644 --- a/src/conversation/test_conversation_api.c +++ b/src/conversation/test_conversation_api.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2013 Christian Grothoff (and other contributing authors) + (C) 2013, 2014 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -330,13 +330,11 @@ static void phone_event_handler (void *cls, enum GNUNET_CONVERSATION_PhoneEventCode code, struct GNUNET_CONVERSATION_Caller *caller, - const char *caller_id) + const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) { static enum GNUNET_CONVERSATION_PhoneEventCode expect = GNUNET_CONVERSATION_EC_PHONE_RING; - GNUNET_break (0 == strcmp (caller_id, - gns_caller_id)); GNUNET_break (code == expect); switch (code) { diff --git a/src/conversation/test_conversation_api_reject.c b/src/conversation/test_conversation_api_reject.c index 06e364ec58..8bfaabae9e 100644 --- a/src/conversation/test_conversation_api_reject.c +++ b/src/conversation/test_conversation_api_reject.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2013 Christian Grothoff (and other contributing authors) + (C) 2013, 2014 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -174,13 +174,11 @@ static void phone_event_handler (void *cls, enum GNUNET_CONVERSATION_PhoneEventCode code, struct GNUNET_CONVERSATION_Caller *caller, - const char *caller_id) + const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) { static enum GNUNET_CONVERSATION_PhoneEventCode expect = GNUNET_CONVERSATION_EC_PHONE_RING; - GNUNET_break (0 == strcmp (caller_id, - gns_caller_id)); GNUNET_break (code == expect); switch (code) { @@ -242,7 +240,8 @@ namestore_put_cont (void *cls, GNUNET_assert (GNUNET_YES == success); GNUNET_assert (NULL == emsg); GNUNET_assert (NULL == op); - op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL); + op = GNUNET_IDENTITY_create (id, "caller-ego", + &caller_ego_create_cont, NULL); } diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c index 3f461231d9..130edbc27a 100644 --- a/src/conversation/test_conversation_api_twocalls.c +++ b/src/conversation/test_conversation_api_twocalls.c @@ -406,12 +406,10 @@ static void phone_event_handler (void *cls, enum GNUNET_CONVERSATION_PhoneEventCode code, struct GNUNET_CONVERSATION_Caller *caller, - const char *caller_id) + const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) { const char *cid; - GNUNET_break (0 == strcmp (caller_id, - gns_caller_id)); switch (code) { case GNUNET_CONVERSATION_EC_PHONE_RING: diff --git a/src/include/gnunet_conversation_service.h b/src/include/gnunet_conversation_service.h index e8f941e45e..0f52db1df4 100644 --- a/src/include/gnunet_conversation_service.h +++ b/src/include/gnunet_conversation_service.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet - (C) 2013 Christian Grothoff (and other contributing authors) + (C) 2013, 2014 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -131,13 +131,13 @@ enum GNUNET_CONVERSATION_PhoneEventCode * @param cls closure * @param code type of the event * @param caller handle for the caller - * @param caller_id name of the caller in GNS + * @param caller_id public key of the caller (in GNS) */ typedef void (*GNUNET_CONVERSATION_PhoneEventHandler)(void *cls, enum GNUNET_CONVERSATION_PhoneEventCode code, struct GNUNET_CONVERSATION_Caller *caller, - const char *caller_id); + const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id); /** diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index 19c57c718d..c4c9bf783a 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h @@ -154,6 +154,7 @@ GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls); + /** * Lookup an item in the namestore. * |