move client listen call into transmit start callback, so we know service exists and...
authorNathan S. Evans <evans@in.tum.de>
Thu, 24 Jun 2010 14:39:48 +0000 (14:39 +0000)
committerNathan S. Evans <evans@in.tum.de>
Thu, 24 Jun 2010 14:39:48 +0000 (14:39 +0000)
src/dv/dv_api.c

index 8b92a703f47f35975cf376b8a00afda1e6bdc92f..dfc5a0fe9b5d035d50414204ebb116e7b739beb0 100644 (file)
@@ -178,7 +178,7 @@ try_connect (struct GNUNET_DV_Handle *ret)
   ret->client = GNUNET_CLIENT_connect (ret->sched, "dv", ret->cfg);
   if (ret->client != NULL)
     return GNUNET_YES;
-#if DEBUG_STATISTICS
+#if DEBUG_DV_MESSAGES
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               _("Failed to connect to the dv service!\n"));
 #endif
@@ -351,6 +351,9 @@ void handle_message_receipt (void *cls,
 
   if (msg == NULL)
   {
+#if DEBUG_DV_MESSAGES
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: connection closed\n");
+#endif
     return; /* Connection closed? */
   }
 
@@ -373,7 +376,7 @@ void handle_message_receipt (void *cls,
     packed_msg = GNUNET_malloc(packed_msg_len);
     memcpy(packed_msg, &packed_msg_start[sender_address_len], packed_msg_len);
 
-#if DEBUG_DV
+#if DEBUG_DV_MESSAGES
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: packed message type: %d or %d\n", ntohs(((struct GNUNET_MessageHeader *)packed_msg)->type), ((struct GNUNET_MessageHeader *)packed_msg)->type);
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: message sender reported as %s\n", GNUNET_i2s(&received_msg->sender));
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: distance is %u\n", ntohl(received_msg->distance));
@@ -496,7 +499,9 @@ transmit_start (void *cls, size_t size, void *buf)
   struct StartContext *start_context = cls;
   struct GNUNET_DV_Handle *handle = start_context->handle;
   size_t tsize;
-
+#if DEBUG_DV
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: sending start request to service\n");
+#endif
   if (buf == NULL)
     {
       GNUNET_free(start_context->message);
@@ -511,6 +516,11 @@ transmit_start (void *cls, size_t size, void *buf)
     memcpy(buf, start_context->message, tsize);
     GNUNET_free(start_context->message);
     GNUNET_free(start_context);
+    GNUNET_CLIENT_receive (handle->client,
+                           &handle_message_receipt,
+                           handle, GNUNET_TIME_UNIT_FOREVER_REL);
+
+
     return tsize;
   }
 
@@ -568,10 +578,6 @@ GNUNET_DV_connect (struct GNUNET_SCHEDULER_Handle *sched,
 
   handle->send_callbacks = GNUNET_CONTAINER_multihashmap_create(100);
 
-  GNUNET_CLIENT_receive (handle->client,
-                         &handle_message_receipt,
-                         handle, GNUNET_TIME_UNIT_FOREVER_REL);
-
   return handle;
 }