renaming GNUNET_CRYPTO_get_host_identity to GNUNET_CRYPTO_get_peer_identity
[oweals/gnunet.git] / src / conversation / gnunet-service-conversation.c
index daf51b54ede2e74173bca828e511602b6a2f6fd2..85bbc04816dc3422015d1d288ea105c6eec1a7d1 100644 (file)
@@ -295,7 +295,7 @@ handle_client_pickup_message (void *cls,
   }
   line->status = LS_CALLEE_CONNECTED;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending PICK_UP message to client with meta data `%s'\n",
+              "Sending PICK_UP message to mesh with meta data `%s'\n",
               meta);
   e = GNUNET_MQ_msg_extra (mppm,
                            len,
@@ -527,7 +527,7 @@ handle_client_call_message (void *cls,
  * @param cls the `struct Line` we are transmitting for
  * @param size number of bytes available in @a buf
  * @param buf where to copy the data
- * @return number of bytes copied to @buf
+ * @return number of bytes copied to @buf
  */
 static size_t
 transmit_line_audio (void *cls,
@@ -585,6 +585,11 @@ handle_client_audio_message (void *cls,
   switch (line->status)
   {
   case LS_CALLEE_LISTEN:
+    /* could be OK if the line just was closed by the other side */
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Audio data dropped, channel is down\n");
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    break;
   case LS_CALLEE_RINGING:
   case LS_CALLER_CALLING:
     GNUNET_break (0);
@@ -596,14 +601,14 @@ handle_client_audio_message (void *cls,
     break;
   case LS_CALLEE_SHUTDOWN:
   case LS_CALLER_SHUTDOWN:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
                 "Mesh audio channel in shutdown; audio data dropped\n");
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
   if (NULL == line->tunnel_unreliable)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
                 _("Mesh audio channel not ready; audio data dropped\n"));
     GNUNET_SERVER_receive_done (client, GNUNET_OK);    
     return;
@@ -612,10 +617,12 @@ handle_client_audio_message (void *cls,
   {
     /* NOTE: we may want to not do this and instead combine the data */
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Dropping previous audio data segment with %u bytes\n",
-                line->audio_size);
+                "Bandwidth insufficient; dropping previous audio data segment with %u bytes\n",
+                (unsigned int) line->audio_size);
     GNUNET_MESH_notify_transmit_ready_cancel (line->unreliable_mth);
+    line->unreliable_mth = NULL;
     GNUNET_free (line->audio_data);
+    line->audio_data = NULL;
   }
   line->audio_size = size;
   line->audio_data = GNUNET_malloc (line->audio_size);
@@ -873,7 +880,7 @@ handle_mesh_pickup_message (void *cls,
   pick->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP);
   memcpy (&pick[1], metadata, len);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending PICK UP message via mesh with metadata `%s'\n",
+              "Sending PICKED UP message to client with metadata `%s'\n",
               metadata);
   GNUNET_SERVER_notification_context_unicast (nc,
                                               line->client,
@@ -885,6 +892,10 @@ handle_mesh_pickup_message (void *cls,
                                                        GNUNET_APPLICATION_TYPE_CONVERSATION_AUDIO,
                                                        GNUNET_YES,
                                                        GNUNET_NO);
+  if (NULL == line->tunnel_unreliable)
+  {
+    GNUNET_break (0);
+  } 
   return GNUNET_OK;
 }
 
@@ -976,12 +987,19 @@ handle_mesh_audio_message (void *cls,
   size_t msize = ntohs (message->size) - sizeof (struct MeshAudioMessage);
   char buf[msize + sizeof (struct ClientAudioMessage)];
   struct ClientAudioMessage *cam;
+  const union GNUNET_MESH_TunnelInfo *info;
   
   msg = (const struct MeshAudioMessage *) message;
   if (NULL == line)
   {
-    sender = *GNUNET_MESH_tunnel_get_info (tunnel,
-                                           GNUNET_MESH_OPTION_PEER)->peer;
+    info = GNUNET_MESH_tunnel_get_info (tunnel,
+                                        GNUNET_MESH_OPTION_PEER);
+    if (NULL == info)
+    {
+      GNUNET_break (0);
+      return GNUNET_OK;
+    }
+    sender = info->peer;
     for (line = lines_head; NULL != line; line = line->next)
       if ( (line->local_line == ntohl (msg->remote_line)) &&
            (LS_CALLEE_CONNECTED == line->status) &&
@@ -996,7 +1014,7 @@ handle_mesh_audio_message (void *cls,
                   "Received AUDIO data for non-existing line %u, dropping.\n",
                   ntohl (msg->remote_line));
       return GNUNET_SYSERR;
-    }
+    }    
     line->tunnel_unreliable = tunnel;
     *tunnel_ctx = line;
   }
@@ -1060,11 +1078,18 @@ inbound_end (void *cls,
     return;
   if (line->tunnel_unreliable == tunnel)
   {
+    if (NULL != line->unreliable_mth)
+    {
+      GNUNET_MESH_notify_transmit_ready_cancel (line->unreliable_mth);
+      line->unreliable_mth = NULL;
+    }
     line->tunnel_unreliable = NULL;
     return;
   }
-  GNUNET_assert (line->tunnel_reliable == tunnel);
+  if (line->tunnel_reliable != tunnel)
+    return;
   line->tunnel_reliable = NULL;
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Mesh tunnel destroyed by mesh\n");
   hup.header.size = sizeof (hup);
@@ -1073,7 +1098,7 @@ inbound_end (void *cls,
   {
   case LS_CALLEE_LISTEN:
     GNUNET_break (0);
-    return;
+    break;
   case LS_CALLEE_RINGING:
   case LS_CALLEE_CONNECTED:
     GNUNET_SERVER_notification_context_unicast (nc,
@@ -1084,7 +1109,6 @@ inbound_end (void *cls,
     break;
   case LS_CALLEE_SHUTDOWN:
     line->status = LS_CALLEE_LISTEN;
-    destroy_line_mesh_tunnels (line);
     break;
   case LS_CALLER_CALLING:
   case LS_CALLER_CONNECTED:
@@ -1092,12 +1116,11 @@ inbound_end (void *cls,
                                                 line->client,
                                                 &hup.header,
                                                 GNUNET_NO);
-    destroy_line_mesh_tunnels (line);
     break;
   case LS_CALLER_SHUTDOWN:
-    destroy_line_mesh_tunnels (line);
     break;
   }
+  destroy_line_mesh_tunnels (line);
 }
 
 
@@ -1208,7 +1231,7 @@ run (void *cls,
 
   cfg = c;
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CRYPTO_get_host_identity (cfg,
+                 GNUNET_CRYPTO_get_peer_identity (cfg,
                                                   &my_identity));
   mesh = GNUNET_MESH_connect (cfg,
                              NULL,