complete testcase template, currently functionally blocked by two issues in the testb...
[oweals/gnunet.git] / src / conversation / conversation_api.c
index 6e1cbe3fba34c5e85243db8b6d8dc088ad2b38ef..58945d447df43b012323843e3533593e666b06ba 100644 (file)
@@ -27,6 +27,7 @@
  */
 #include "platform.h"
 #include "gnunet_conversation_service.h"
+#include "gnunet_gnsrecord_lib.h"
 #include "gnunet_gns_service.h"
 #include "conversation.h"
 
@@ -124,12 +125,12 @@ struct GNUNET_CONVERSATION_Phone
   /**
    * My GNS zone.
    */
-  struct GNUNET_CRYPTO_EccPrivateKey my_zone;
+  struct GNUNET_CRYPTO_EcdsaPrivateKey my_zone;
 
   /**
    * Identity of the person calling us (valid while in state #PS_RINGING).
    */
-  struct GNUNET_CRYPTO_EccPublicSignKey caller_id;
+  struct GNUNET_CRYPTO_EcdsaPublicKey caller_id;
 
   /**
    * State machine for the phone.
@@ -159,17 +160,17 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone);
  */
 static void
 handle_caller_name (void *cls,
-                    const struct GNUNET_CRYPTO_EccPrivateKey *zone,
+                    const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
                     const char *label,
                     unsigned int rd_count,
-                    const struct GNUNET_NAMESTORE_RecordData *rd)
+                    const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct GNUNET_CONVERSATION_Phone *phone = cls;
   char *name;
 
   phone->qe = NULL;
   if (NULL == label)
-    name = GNUNET_strdup (GNUNET_NAMESTORE_pkey_to_zkey (&phone->caller_id));
+    name = GNUNET_strdup (GNUNET_GNSRECORD_pkey_to_zkey (&phone->caller_id));
   else
     GNUNET_asprintf (&name, "%.gnu", label);
   phone->event_handler (phone->event_handler_cls,
@@ -451,13 +452,13 @@ GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
  */
 void
 GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone,
-                                     struct GNUNET_NAMESTORE_RecordData *rd)
+                                     struct GNUNET_GNSRECORD_Data *rd)
 {
   rd->data = &phone->my_record;
   rd->expiration_time = 0;
   rd->data_size = sizeof (struct GNUNET_CONVERSATION_PhoneRecord);
-  rd->record_type = GNUNET_NAMESTORE_TYPE_PHONE;
-  rd->flags = GNUNET_NAMESTORE_RF_NONE;
+  rd->record_type = GNUNET_GNSRECORD_TYPE_PHONE;
+  rd->flags = GNUNET_GNSRECORD_RF_NONE;
 }
 
 
@@ -903,7 +904,7 @@ handle_call_audio_message (void *cls,
 static void
 handle_gns_response (void *cls,
                      uint32_t rd_count,
-                     const struct GNUNET_NAMESTORE_RecordData *rd)
+                     const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct GNUNET_CONVERSATION_Call *call = cls;
   uint32_t i;
@@ -913,7 +914,7 @@ handle_gns_response (void *cls,
   call->gns_lookup = NULL;
   for (i=0;i<rd_count;i++)
   {
-    if (GNUNET_NAMESTORE_TYPE_PHONE == rd[i].record_type)
+    if (GNUNET_GNSRECORD_TYPE_PHONE == rd[i].record_type)
     {
       if (rd[i].data_size != sizeof (struct GNUNET_CONVERSATION_PhoneRecord))
       {
@@ -985,7 +986,7 @@ reconnect_call (struct GNUNET_CONVERSATION_Call *call)
       0 },
     { NULL, 0, 0 }
   };
-  struct GNUNET_CRYPTO_EccPublicSignKey my_zone;
+  struct GNUNET_CRYPTO_EcdsaPublicKey my_zone;
 
   if (CS_ACTIVE == call->state)
   {
@@ -1016,7 +1017,7 @@ reconnect_call (struct GNUNET_CONVERSATION_Call *call)
   call->gns_lookup = GNUNET_GNS_lookup (call->gns,
                                         call->callee,
                                         &my_zone,
-                                        GNUNET_NAMESTORE_TYPE_PHONE,
+                                        GNUNET_GNSRECORD_TYPE_PHONE,
                                         GNUNET_NO,
                                         NULL /* FIXME: add shortening support */,
                                         &handle_gns_response, call);
@@ -1070,6 +1071,21 @@ GNUNET_CONVERSATION_call_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
 }
 
 
+/**
+ * We've sent the hang up message, now finish terminating the call.
+ *
+ * @param cls the `struct GNUNET_CONVERSATION_Call` to terminate
+ */
+static void
+finish_stop (void *cls)
+{
+  struct GNUNET_CONVERSATION_Call *call = cls;
+
+  GNUNET_assert (CS_SHUTDOWN == call->state);
+  GNUNET_CONVERSATION_call_stop (call, NULL);
+}
+
+
 /**
  * Terminate a call.  The call may be ringing or ready at this time.
  *
@@ -1081,23 +1097,25 @@ void
 GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call,
                               const char *reason)
 {
+  struct GNUNET_MQ_Envelope *e;
+  struct ClientPhoneHangupMessage *hang;
+  size_t slen;
+
+  if ( (NULL != call->speaker) &&
+       (CS_ACTIVE == call->state) )
+    call->speaker->disable_speaker (call->speaker->cls);
+  if ( (NULL != call->mic) &&
+       (CS_ACTIVE == call->state) )
+    call->mic->disable_microphone (call->mic->cls);
   if (NULL != reason)
   {
-    // FIXME: transmit reason to service... (not implemented!)
-    GNUNET_break (0);
-    // return;
-  }
-  if (NULL != call->speaker)
-  {
-    if (CS_ACTIVE == call->state)
-      call->speaker->disable_speaker (call->speaker->cls);
-    call->speaker = NULL;
-  }
-  if (NULL != call->mic)
-  {
-    if (CS_ACTIVE == call->state)
-      call->mic->disable_microphone (call->mic->cls);
-    call->mic =NULL;
+    slen = strlen (reason) + 1;
+    e = GNUNET_MQ_msg_extra (hang, slen, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
+    memcpy (&hang[1], reason, slen);
+    GNUNET_MQ_notify_sent (e, &finish_stop, call);
+    GNUNET_MQ_send (call->mq, e);
+    call->state = CS_SHUTDOWN;
+    return;
   }
   if (NULL != call->mq)
   {