aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-conversation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-06 08:43:16 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-06 08:43:16 +0000
commitaece72e29b041e2dfbc5b49d2fd0d49f8ab2124e (patch)
treecce216b507c99bf6723e15da5158e68a57a55f41 /src/conversation/gnunet-conversation.c
parent310f312557954662ffc32f74bbacdb63d76ede3d (diff)
downloadgnunet-aece72e29b041e2dfbc5b49d2fd0d49f8ab2124e.tar.gz
gnunet-aece72e29b041e2dfbc5b49d2fd0d49f8ab2124e.zip
addressing #3431
Diffstat (limited to 'src/conversation/gnunet-conversation.c')
-rw-r--r--src/conversation/gnunet-conversation.c86
1 files changed, 51 insertions, 35 deletions
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c
index 532107aca..11cad533b 100644
--- a/src/conversation/gnunet-conversation.c
+++ b/src/conversation/gnunet-conversation.c
@@ -127,9 +127,9 @@ struct CallList
127 struct GNUNET_CONVERSATION_Caller *caller; 127 struct GNUNET_CONVERSATION_Caller *caller;
128 128
129 /** 129 /**
130 * String identifying the caller. 130 * Public key identifying the caller.
131 */ 131 */
132 char *caller_id; 132 struct GNUNET_CRYPTO_EcdsaPublicKey caller_id;
133 133
134 /** 134 /**
135 * Unique number of the call. 135 * Unique number of the call.
@@ -193,7 +193,7 @@ static struct GNUNET_CONFIGURATION_Handle *cfg;
193/** 193/**
194 * Our ego. 194 * Our ego.
195 */ 195 */
196static struct GNUNET_IDENTITY_Ego *caller_id; 196static struct GNUNET_IDENTITY_Ego *my_caller_id;
197 197
198/** 198/**
199 * Handle to identity service. 199 * Handle to identity service.
@@ -206,7 +206,12 @@ static struct GNUNET_IDENTITY_Handle *id;
206static char *ego_name; 206static char *ego_name;
207 207
208/** 208/**
209 * Name of conversation partner (if any). 209 * Public key of active conversation partner (if any).
210 */
211static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key;
212
213/**
214 * Name of active conversation partner (if any).
210 */ 215 */
211static char *peer_name; 216static char *peer_name;
212 217
@@ -247,13 +252,13 @@ static int verbose;
247 * @param cls closure 252 * @param cls closure
248 * @param code type of the event 253 * @param code type of the event
249 * @param caller handle for the caller 254 * @param caller handle for the caller
250 * @param caller_id name of the caller in GNS 255 * @param caller_id public key of the caller (in GNS)
251 */ 256 */
252static void 257static void
253phone_event_handler (void *cls, 258phone_event_handler (void *cls,
254 enum GNUNET_CONVERSATION_PhoneEventCode code, 259 enum GNUNET_CONVERSATION_PhoneEventCode code,
255 struct GNUNET_CONVERSATION_Caller *caller, 260 struct GNUNET_CONVERSATION_Caller *caller,
256 const char *caller_id) 261 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id)
257{ 262{
258 struct CallList *cl; 263 struct CallList *cl;
259 264
@@ -262,12 +267,12 @@ phone_event_handler (void *cls,
262 case GNUNET_CONVERSATION_EC_PHONE_RING: 267 case GNUNET_CONVERSATION_EC_PHONE_RING:
263 FPRINTF (stdout, 268 FPRINTF (stdout,
264 _("Incoming call from `%s'. Please /accept #%u or /cancel %u the call.\n"), 269 _("Incoming call from `%s'. Please /accept #%u or /cancel %u the call.\n"),
265 caller_id, 270 GNUNET_GNSRECORD_pkey_to_zkey (caller_id),
266 caller_num_gen, 271 caller_num_gen,
267 caller_num_gen); 272 caller_num_gen);
268 cl = GNUNET_new (struct CallList); 273 cl = GNUNET_new (struct CallList);
269 cl->caller = caller; 274 cl->caller = caller;
270 cl->caller_id = GNUNET_strdup (caller_id); 275 cl->caller_id = *caller_id;
271 cl->caller_num = caller_num_gen++; 276 cl->caller_num = caller_num_gen++;
272 GNUNET_CONTAINER_DLL_insert (cl_head, 277 GNUNET_CONTAINER_DLL_insert (cl_head,
273 cl_tail, 278 cl_tail,
@@ -284,11 +289,10 @@ phone_event_handler (void *cls,
284 } 289 }
285 FPRINTF (stdout, 290 FPRINTF (stdout,
286 _("Call from `%s' terminated\n"), 291 _("Call from `%s' terminated\n"),
287 cl->caller_id); 292 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
288 GNUNET_CONTAINER_DLL_remove (cl_head, 293 GNUNET_CONTAINER_DLL_remove (cl_head,
289 cl_tail, 294 cl_tail,
290 cl); 295 cl);
291 GNUNET_free (cl->caller_id);
292 if (cl == cl_active) 296 if (cl == cl_active)
293 { 297 {
294 cl_active = NULL; 298 cl_active = NULL;
@@ -317,12 +321,12 @@ caller_event_handler (void *cls,
317 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: 321 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
318 FPRINTF (stdout, 322 FPRINTF (stdout,
319 _("Call from `%s' suspended by other user\n"), 323 _("Call from `%s' suspended by other user\n"),
320 cl->caller_id); 324 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
321 break; 325 break;
322 case GNUNET_CONVERSATION_EC_CALLER_RESUME: 326 case GNUNET_CONVERSATION_EC_CALLER_RESUME:
323 FPRINTF (stdout, 327 FPRINTF (stdout,
324 _("Call from `%s' resumed by other user\n"), 328 _("Call from `%s' resumed by other user\n"),
325 cl->caller_id); 329 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
326 break; 330 break;
327 } 331 }
328} 332}
@@ -336,7 +340,7 @@ start_phone ()
336{ 340{
337 struct GNUNET_GNSRECORD_Data rd; 341 struct GNUNET_GNSRECORD_Data rd;
338 342
339 if (NULL == caller_id) 343 if (NULL == my_caller_id)
340 { 344 {
341 FPRINTF (stderr, 345 FPRINTF (stderr,
342 _("Ego `%s' no longer available, phone is now down.\n"), 346 _("Ego `%s' no longer available, phone is now down.\n"),
@@ -346,7 +350,7 @@ start_phone ()
346 } 350 }
347 GNUNET_assert (NULL == phone); 351 GNUNET_assert (NULL == phone);
348 phone = GNUNET_CONVERSATION_phone_create (cfg, 352 phone = GNUNET_CONVERSATION_phone_create (cfg,
349 caller_id, 353 my_caller_id,
350 &phone_event_handler, NULL); 354 &phone_event_handler, NULL);
351 /* FIXME: get record and print full GNS record info later here... */ 355 /* FIXME: get record and print full GNS record info later here... */
352 if (NULL == phone) 356 if (NULL == phone)
@@ -402,13 +406,17 @@ call_event_handler (void *cls,
402 GNUNET_break (CS_RESOLVING == call_state); 406 GNUNET_break (CS_RESOLVING == call_state);
403 FPRINTF (stdout, 407 FPRINTF (stdout,
404 _("Failed to resolve `%s'\n"), 408 _("Failed to resolve `%s'\n"),
405 ego_name); 409 peer_name);
410 GNUNET_free (peer_name);
411 peer_name = NULL;
406 call = NULL; 412 call = NULL;
407 break; 413 break;
408 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: 414 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
409 FPRINTF (stdout, 415 FPRINTF (stdout,
410 "%s", 416 _("Call to `%s' terminated\n"),
411 _("Call terminated\n")); 417 peer_name);
418 GNUNET_free (peer_name);
419 peer_name = NULL;
412 call = NULL; 420 call = NULL;
413 break; 421 break;
414 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: 422 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
@@ -427,6 +435,7 @@ call_event_handler (void *cls,
427 FPRINTF (stdout, 435 FPRINTF (stdout,
428 _("Error with the call, restarting it\n")); 436 _("Error with the call, restarting it\n"));
429 call_state = CS_RESOLVING; 437 call_state = CS_RESOLVING;
438 // FIXME: is this correct?
430 break; 439 break;
431 } 440 }
432} 441}
@@ -505,7 +514,7 @@ do_unknown (const char *msg)
505static void 514static void
506do_call (const char *arg) 515do_call (const char *arg)
507{ 516{
508 if (NULL == caller_id) 517 if (NULL == my_caller_id)
509 { 518 {
510 FPRINTF (stderr, 519 FPRINTF (stderr,
511 _("Ego `%s' not available\n"), 520 _("Ego `%s' not available\n"),
@@ -531,13 +540,12 @@ do_call (const char *arg)
531 case PS_ACCEPTED: 540 case PS_ACCEPTED:
532 FPRINTF (stderr, 541 FPRINTF (stderr,
533 _("You are answering call from `%s', hang up or suspend that call first!\n"), 542 _("You are answering call from `%s', hang up or suspend that call first!\n"),
534 peer_name); 543 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
535 return; 544 return;
536 case PS_ERROR: 545 case PS_ERROR:
537 /* ok to call */ 546 /* ok to call */
538 break; 547 break;
539 } 548 }
540 GNUNET_free_non_null (peer_name);
541 if (NULL == arg) 549 if (NULL == arg)
542 { 550 {
543 FPRINTF (stderr, 551 FPRINTF (stderr,
@@ -549,7 +557,7 @@ do_call (const char *arg)
549 call_state = CS_RESOLVING; 557 call_state = CS_RESOLVING;
550 GNUNET_assert (NULL == call); 558 GNUNET_assert (NULL == call);
551 call = GNUNET_CONVERSATION_call_start (cfg, 559 call = GNUNET_CONVERSATION_call_start (cfg,
552 caller_id, 560 my_caller_id,
553 arg, 561 arg,
554 speaker, 562 speaker,
555 mic, 563 mic,
@@ -586,7 +594,7 @@ do_accept (const char *args)
586 case PS_ACCEPTED: 594 case PS_ACCEPTED:
587 FPRINTF (stderr, 595 FPRINTF (stderr,
588 _("You are answering call from `%s', hang up or suspend that call first!\n"), 596 _("You are answering call from `%s', hang up or suspend that call first!\n"),
589 peer_name); 597 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
590 return; 598 return;
591 case PS_ERROR: 599 case PS_ERROR:
592 GNUNET_break (0); 600 GNUNET_break (0);
@@ -621,8 +629,7 @@ do_accept (const char *args)
621 cl_tail, 629 cl_tail,
622 cl); 630 cl);
623 cl_active = cl; 631 cl_active = cl;
624 GNUNET_free_non_null (peer_name); 632 peer_key = cl->caller_id;
625 peer_name = GNUNET_strdup (cl->caller_id);
626 phone_state = PS_ACCEPTED; 633 phone_state = PS_ACCEPTED;
627 GNUNET_CONVERSATION_caller_pick_up (cl->caller, 634 GNUNET_CONVERSATION_caller_pick_up (cl->caller,
628 &caller_event_handler, 635 &caller_event_handler,
@@ -679,7 +686,7 @@ do_status (const char *args)
679 case PS_ACCEPTED: 686 case PS_ACCEPTED:
680 FPRINTF (stdout, 687 FPRINTF (stdout,
681 _("You are having a conversation with `%s'.\n"), 688 _("You are having a conversation with `%s'.\n"),
682 peer_name); 689 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));;
683 break; 690 break;
684 case PS_ERROR: 691 case PS_ERROR:
685 FPRINTF (stdout, 692 FPRINTF (stdout,
@@ -724,7 +731,7 @@ do_status (const char *args)
724 FPRINTF (stdout, 731 FPRINTF (stdout,
725 _("#%u: `%s'\n"), 732 _("#%u: `%s'\n"),
726 cl->caller_num, 733 cl->caller_num,
727 cl->caller_id); 734 GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
728 } 735 }
729 FPRINTF (stdout, 736 FPRINTF (stdout,
730 "%s", 737 "%s",
@@ -822,7 +829,7 @@ do_resume (const char *args)
822 case PS_ACCEPTED: 829 case PS_ACCEPTED:
823 FPRINTF (stderr, 830 FPRINTF (stderr,
824 _("Already talking with `%s', cannot resume a call right now.\n"), 831 _("Already talking with `%s', cannot resume a call right now.\n"),
825 peer_name); 832 GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
826 return; 833 return;
827 } 834 }
828 GNUNET_assert (NULL == cl_active); 835 GNUNET_assert (NULL == cl_active);
@@ -915,7 +922,6 @@ do_reject (const char *args)
915 GNUNET_CONTAINER_DLL_remove (cl_head, 922 GNUNET_CONTAINER_DLL_remove (cl_head,
916 cl_tail, 923 cl_tail,
917 cl); 924 cl);
918 GNUNET_free (cl->caller_id);
919 GNUNET_free (cl); 925 GNUNET_free (cl);
920 break; 926 break;
921 case PS_ACCEPTED: 927 case PS_ACCEPTED:
@@ -1046,11 +1052,20 @@ do_stop_task (void *cls,
1046 GNUNET_free (ego_name); 1052 GNUNET_free (ego_name);
1047 ego_name = NULL; 1053 ego_name = NULL;
1048 GNUNET_free_non_null (peer_name); 1054 GNUNET_free_non_null (peer_name);
1055 peer_name = NULL;
1049 phone_state = PS_ERROR; 1056 phone_state = PS_ERROR;
1050} 1057}
1051 1058
1059
1060/**
1061 * Handle user command.
1062 *
1063 * @param message command the user typed in
1064 * @param str_len number of bytes to process in @a message
1065 */
1052static void 1066static void
1053handle_command_string (char *message, size_t str_len) 1067handle_command_string (char *message,
1068 size_t str_len)
1054{ 1069{
1055 size_t i; 1070 size_t i;
1056 const char *ptr; 1071 const char *ptr;
@@ -1078,9 +1093,10 @@ handle_command_string (char *message, size_t str_len)
1078 1093
1079 1094
1080#ifdef WINDOWS 1095#ifdef WINDOWS
1081int 1096static int
1082console_reader_chars (void *cls, void *client, 1097console_reader_chars (void *cls,
1083 const struct GNUNET_MessageHeader *message) 1098 void *client,
1099 const struct GNUNET_MessageHeader *message)
1084{ 1100{
1085 char *chars; 1101 char *chars;
1086 size_t str_size; 1102 size_t str_size;
@@ -1144,7 +1160,7 @@ identity_cb (void *cls,
1144{ 1160{
1145 if (NULL == name) 1161 if (NULL == name)
1146 return; 1162 return;
1147 if (ego == caller_id) 1163 if (ego == my_caller_id)
1148 { 1164 {
1149 if (verbose) 1165 if (verbose)
1150 FPRINTF (stdout, 1166 FPRINTF (stdout,
@@ -1163,10 +1179,10 @@ identity_cb (void *cls,
1163 FPRINTF (stdout, 1179 FPRINTF (stdout,
1164 _("Our ego `%s' was deleted!\n"), 1180 _("Our ego `%s' was deleted!\n"),
1165 ego_name); 1181 ego_name);
1166 caller_id = NULL; 1182 my_caller_id = NULL;
1167 return; 1183 return;
1168 } 1184 }
1169 caller_id = ego; 1185 my_caller_id = ego;
1170 GNUNET_CONFIGURATION_set_value_number (cfg, 1186 GNUNET_CONFIGURATION_set_value_number (cfg,
1171 "CONVERSATION", 1187 "CONVERSATION",
1172 "LINE", 1188 "LINE",