- add underlay api implementation
[oweals/gnunet.git] / src / conversation / gnunet-service-conversation.c
index b12d0e193f96ae2594a7242dd8ec240d0be519b7..df8d4e9f24cf9bfdde73202854738f136e7edef3 100644 (file)
@@ -369,6 +369,8 @@ destroy_line_mesh_channels (struct Channel *ch)
   struct Line *line = ch->line;
   struct GNUNET_MESH_Channel *t;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Destroying mesh channels\n");
   if (NULL != ch->reliable_mq)
   {
     GNUNET_MQ_destroy (ch->reliable_mq);
@@ -699,8 +701,7 @@ handle_client_call_message (void *cls,
                                                      ch,
                                                      &msg->target,
                                                      GNUNET_APPLICATION_TYPE_CONVERSATION_CONTROL,
-                                                     GNUNET_NO,
-                                                     GNUNET_YES);
+                                                     GNUNET_MESH_OPTION_RELIABLE);
   ch->reliable_mq = GNUNET_MESH_mq_create (ch->channel_reliable);
   e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_RING);
   ring->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING);
@@ -755,8 +756,8 @@ transmit_line_audio (void *cls,
   GNUNET_free (ch->audio_data);
   ch->audio_data = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending %u bytes of audio data via mesh\n",
-              ch->audio_size);
+              "Sending %u bytes of audio data on line %u via mesh\n",
+              ch->audio_size, ch->remote_line);
   return sizeof (struct MeshAudioMessage) + ch->audio_size;
 }
 
@@ -933,6 +934,7 @@ handle_mesh_ring_message (void *cls,
   ch->channel_reliable = channel;
   ch->reliable_mq = GNUNET_MESH_mq_create (ch->channel_reliable);
   ch->cid = line->cid_gen++;
+  ch->target = msg->source;
   *channel_ctx = ch;
   cring.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING);
   cring.header.size = htons (sizeof (cring));
@@ -978,7 +980,7 @@ handle_mesh_hangup_message (void *cls,
   }
   line = ch->line;
   *channel_ctx = NULL;
-  hup.header.size = sizeof (hup);
+  hup.header.size = htons (sizeof (hup));
   hup.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
   hup.cid = ch->cid;
   status = ch->status;
@@ -1057,7 +1059,7 @@ handle_mesh_pickup_message (void *cls,
     mq_done_finish_caller_shutdown (ch);
     return GNUNET_SYSERR;
   }
-  pick.header.size = sizeof (pick);
+  pick.header.size = htons (sizeof (pick));
   pick.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP);
   pick.cid = ch->cid;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1070,8 +1072,7 @@ handle_mesh_pickup_message (void *cls,
                                                        ch,
                                                        &ch->target,
                                                        GNUNET_APPLICATION_TYPE_CONVERSATION_AUDIO,
-                                                       GNUNET_YES,
-                                                       GNUNET_NO);
+                                                       GNUNET_MESH_OPTION_DEFAULT);
   if (NULL == ch->channel_unreliable)
   {
     GNUNET_break (0);
@@ -1107,7 +1108,7 @@ handle_mesh_suspend_message (void *cls,
     return GNUNET_SYSERR;
   }
   line = ch->line;
-  suspend.header.size = sizeof (suspend);
+  suspend.header.size = htons (sizeof (suspend));
   suspend.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND);
   suspend.cid = ch->cid;
   GNUNET_MESH_receive_done (channel);
@@ -1165,7 +1166,7 @@ handle_mesh_resume_message (void *cls,
     return GNUNET_SYSERR;
   }
   line = ch->line;
-  resume.header.size = sizeof (resume);
+  resume.header.size = htons (sizeof (resume));
   resume.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME);
   resume.cid = ch->cid;
   GNUNET_MESH_receive_done (channel);
@@ -1237,7 +1238,7 @@ handle_mesh_audio_message (void *cls,
       GNUNET_break (0);
       return GNUNET_OK;
     }
-    sender = *(info->peer);
+    sender = info->peer;
     for (line = lines_head; NULL != line; line = line->next)
       if (line->local_line == ntohl (msg->remote_line))
       {
@@ -1270,7 +1271,7 @@ handle_mesh_audio_message (void *cls,
   cam->cid = ch->cid;
   memcpy (&cam[1], &msg[1], msize);
   GNUNET_SERVER_notification_context_unicast (nc,
-                                              line->client,
+                                              ch->line->client,
                                               &cam->header,
                                               GNUNET_YES);
   GNUNET_MESH_receive_done (channel);
@@ -1286,6 +1287,7 @@ handle_mesh_audio_message (void *cls,
  * @param channel new handle to the channel
  * @param initiator peer that started the channel
  * @param port port
+ * @param options channel option flags
  * @return initial channel context for the channel;
  *         (can be NULL -- that's not an error)
  */
@@ -1293,7 +1295,7 @@ static void *
 inbound_channel (void *cls,
                 struct GNUNET_MESH_Channel *channel,
                const struct GNUNET_PeerIdentity *initiator,
-                uint32_t port)
+                uint32_t port, enum GNUNET_MESH_ChannelOption options)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              _("Received incoming channel on port %u\n"),
@@ -1322,7 +1324,11 @@ inbound_end (void *cls,
   struct ClientPhoneHangupMessage hup;
 
   if (NULL == ch)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Mesh channel destroyed, but channel is unknown to us\n");
     return;
+  }
   line = ch->line;
   if (ch->channel_unreliable == channel)
   {
@@ -1332,16 +1338,21 @@ inbound_end (void *cls,
       ch->unreliable_mth = NULL;
     }
     ch->channel_unreliable = NULL;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Unreliable channel destroyed\n");
     return;
   }
   if (ch->channel_reliable != channel)
+  {
+    /* recursive call, I'm the one destroying 'ch' right now */
     return;
+  }
   ch->channel_reliable = NULL;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Mesh channel destroyed by mesh in state %d\n",
               ch->status);
-  hup.header.size = sizeof (hup);
+  hup.header.size = htons (sizeof (hup));
   hup.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
   hup.cid = ch->cid;
   switch (ch->status)