social: guest_talk test; multicast: fix member_to_origin_resume()
authorGabor X Toth <*@tg-x.net>
Thu, 24 Jul 2014 07:59:21 +0000 (07:59 +0000)
committerGabor X Toth <*@tg-x.net>
Thu, 24 Jul 2014 07:59:21 +0000 (07:59 +0000)
src/multicast/multicast_api.c
src/psyc/gnunet-service-psyc.c
src/social/gnunet-service-social.c
src/social/social_api.c
src/social/test_social.c

index fb263008133b07a3e50a43542e0c48fea98ca5f1..05c34241b43b89771f3ca5479af169347f1d9811 100644 (file)
@@ -980,7 +980,7 @@ GNUNET_MULTICAST_member_to_origin (struct GNUNET_MULTICAST_Member *mem,
 void
 GNUNET_MULTICAST_member_to_origin_resume (struct GNUNET_MULTICAST_MemberTransmitHandle *th)
 {
-
+  member_to_origin (th->member);
 }
 
 
index 8fc080bafcf21fb5822db602fbd80671d39b6f62..35579fcfc230e7dbb21a572afe675ca9e86daeca 100644 (file)
@@ -102,6 +102,12 @@ struct TransmitMessage
    */
   uint8_t state;
 
+  /**
+   * Whether a message ACK has already been sent to the client.
+   * #GNUNET_YES or #GNUNET_NO
+   */
+  uint8_t ack_sent;
+
   /* Followed by message */
 };
 
@@ -396,7 +402,7 @@ struct Slave
 };
 
 
-static inline void
+static void
 transmit_message (struct Channel *chn);
 
 
@@ -1689,7 +1695,8 @@ transmit_notify (void *cls, size_t *data_size, void *data)
   memcpy (data, &tmit_msg[1], *data_size);
 
   int ret = (MSG_STATE_END < chn->tmit_state) ? GNUNET_NO : GNUNET_YES;
-  if (NULL != tmit_msg->client)
+
+  if (NULL != tmit_msg->client && GNUNET_NO == tmit_msg->ack_sent)
     send_message_ack (chn, tmit_msg->client);
 
   GNUNET_CONTAINER_DLL_remove (chn->tmit_head, chn->tmit_tail, tmit_msg);
@@ -1781,7 +1788,7 @@ slave_transmit_message (struct Slave *slv)
 }
 
 
-static inline void
+static void
 transmit_message (struct Channel *chn)
 {
   chn->is_master
@@ -1849,7 +1856,7 @@ slave_queue_message (struct Slave *slv, struct TransmitMessage *tmit_msg,
  * @param first_ptype  First message part type in @a data.
  * @param last_ptype   Last message part type in @a data.
  */
-static void
+static struct TransmitMessage *
 queue_message (struct Channel *chn,
                struct GNUNET_SERVER_Client *client,
                size_t data_size,
@@ -1872,6 +1879,7 @@ queue_message (struct Channel *chn,
                             first_ptype, last_ptype)
     : slave_queue_message ((struct Slave *) chn, tmit_msg,
                            first_ptype, last_ptype);
+  return tmit_msg;
 }
 
 
@@ -1951,6 +1959,7 @@ client_recv_psyc_message (void *cls, struct GNUNET_SERVER_Client *client,
   queue_message (chn, client, size - sizeof (*msg), &msg[1],
                  first_ptype, last_ptype);
   transmit_message (chn);
+  /* FIXME: send a few ACKs even before transmit_notify is called */
 
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 };
index 90d12200da5a78328f82b7b00a209bf865bea095..de41637203c0d55c5f49e7fff8712046d6ffcd93 100644 (file)
@@ -857,11 +857,6 @@ psyc_transmit_queue_next_part (struct Place *plc,
                                struct FragmentTransmitQueue *tmit_frag)
 {
   uint16_t psize = ntohs (tmit_frag->next_part->size);
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              "%p psyc_transmit_queue_next_part: %x + %u - %x = %u < %u\n",
-              plc, tmit_frag->next_part, psize, &tmit_frag[1],
-              (char *) tmit_frag->next_part + psize - ((char *) &tmit_frag[1]),
-              tmit_frag->size);
   if ((char *) tmit_frag->next_part + psize - ((char *) &tmit_frag[1])
       < tmit_frag->size)
   {
@@ -952,11 +947,15 @@ psyc_transmit_notify_data (void *cls, uint16_t *data_size, void *data)
     break;
 
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END:
-  case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL:
     *data_size = 0;
     ret = GNUNET_YES;
     break;
 
+  case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL:
+    *data_size = 0;
+    ret = GNUNET_SYSERR;
+    break;
+
   default:
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "%p psyc_transmit_notify_data: unexpected message part of type %u.\n",
@@ -964,7 +963,7 @@ psyc_transmit_notify_data (void *cls, uint16_t *data_size, void *data)
     ret = GNUNET_SYSERR;
   }
 
-  if (GNUNET_SYSERR == ret)
+  if (GNUNET_SYSERR == ret && GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL != ptype)
   {
     *data_size = 0;
     tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg);
@@ -975,7 +974,27 @@ psyc_transmit_notify_data (void *cls, uint16_t *data_size, void *data)
   }
   else
   {
-    psyc_transmit_queue_next_part (plc, tmit_msg, tmit_frag);
+    tmit_frag = psyc_transmit_queue_next_part (plc, tmit_msg, tmit_frag);
+    if (NULL != tmit_frag)
+    {
+      struct GNUNET_MessageHeader *pmsg = tmit_frag->next_part;
+      ptype = ntohs (pmsg->type);
+      switch (ptype)
+      {
+      case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END:
+        ret = GNUNET_YES;
+        break;
+      case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL:
+        ret = GNUNET_SYSERR;
+        break;
+      }
+      switch (ptype)
+      {
+      case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END:
+      case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL:
+        tmit_frag = psyc_transmit_queue_next_part (plc, tmit_msg, tmit_frag);
+      }
+    }
 
     if (NULL == tmit_msg->frags_head
         && GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END <= ptype)
@@ -1060,12 +1079,6 @@ psyc_transmit_notify_mod (void *cls, uint16_t *data_size, void *data,
     *data_size = mod_size;
     memcpy (data, &pmod[1], mod_size);
     ret = GNUNET_NO;
-#if REMOVE // FIXME
-    ret = (mod_size - strnlen ((char *) &pmod[1], mod_size) - 1
-           == *full_value_size)
-      ? GNUNET_YES
-      : GNUNET_NO;
-#endif
     break;
   }
 
@@ -1120,7 +1133,8 @@ psyc_transmit_notify_mod (void *cls, uint16_t *data_size, void *data,
   }
   else
   {
-    psyc_transmit_queue_next_part (plc, tmit_msg, tmit_frag);
+    if (GNUNET_YES != ret)
+      psyc_transmit_queue_next_part (plc, tmit_msg, tmit_frag);
 
     if (NULL == tmit_msg->frags_head
         && GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END <= ptype)
@@ -1241,7 +1255,6 @@ psyc_transmit_queue_next_method (struct Place *plc,
 
   uint16_t psize = ntohs (pmsg->size);
   *pmeth = (struct GNUNET_PSYC_MessageMethod *) pmsg;
-
   if (psize < sizeof (**pmeth) + 1 || '\0' != *((char *) *pmeth + psize - 1))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1253,6 +1266,7 @@ psyc_transmit_queue_next_method (struct Place *plc,
     GNUNET_break (0);
     return GNUNET_SYSERR;
   }
+
   psyc_transmit_queue_next_part (plc, tmit_msg, tmit_frag);
   return GNUNET_OK;
 }
index d19f83e89cc134cc1c433e8832730794bcc1936f..76fd0f9f911171a052f0b0ef257e1ef6ef0dd2a5 100644 (file)
@@ -1458,14 +1458,17 @@ GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg
  *         otherwise handle to cancel the request.
  */
 struct GNUNET_SOCIAL_TalkRequest *
-GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *guest,
+GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *gst,
                           const char *method_name,
                           const struct GNUNET_ENV_Environment *env,
                           GNUNET_PSYC_TransmitNotifyData notify_data,
                           void *notify_data_cls,
                           enum GNUNET_SOCIAL_TalkFlags flags)
 {
-  return NULL;
+  if (GNUNET_OK ==
+      GNUNET_PSYC_transmit_message (gst->plc.tmit, method_name, env,
+                                    NULL, notify_data, notify_data_cls, flags));
+  return (struct GNUNET_SOCIAL_TalkRequest *) gst->plc.tmit;
 }
 
 
index 340c4482a4f1c09da768ef43ffcc6071b0d811a4..fa3ce6e6d14f38ed9ff6fcb188d552dcf95db981 100644 (file)
@@ -38,7 +38,7 @@
 
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 
-#define DEBUG_SERVICE 0
+#define DEBUG_SERVICE 1
 #define DATA2ARG(data) data, sizeof (data)
 
 /**
@@ -110,9 +110,8 @@ enum
   TEST_HOST_ANNOUNCE     = 5,
   TEST_HOST_ANNOUNCE_END = 6,
   TEST_GUEST_TALK        = 7,
-  TEST_GUEST_TALK_END    = 8,
-  TEST_GUEST_LEAVE       = 9,
-  TEST_HOST_LEAVE       = 10,
+  TEST_GUEST_LEAVE       = 8,
+  TEST_HOST_LEAVE        = 9,
 } test;
 
 
@@ -294,6 +293,8 @@ host_farewell (void *cls,
                size_t variable_count,
                struct GNUNET_ENV_Modifier *variables)
 {
+  // FIXME: this function is not called yet
+
   struct GNUNET_CRYPTO_EcdsaPublicKey *
     nym_key = GNUNET_SOCIAL_nym_get_key (nym);
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -319,7 +320,7 @@ guest_left (void *cls)
 
 
 void
-schedule_guest_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+guest_leave()
 {
   test = TEST_GUEST_LEAVE;
   /* FIXME test keep_active */
@@ -396,14 +397,6 @@ guest_recv_eom (void *cls,
     guest_talk ();
     break;
 
-  case TEST_GUEST_TALK:
-    test = TEST_GUEST_TALK_END;
-    break;
-
-  case TEST_GUEST_TALK_END:
-    GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
-    break;
-
   default:
     GNUNET_assert (0);
   }
@@ -480,11 +473,7 @@ host_recv_eom (void *cls,
     break;
 
   case TEST_GUEST_TALK:
-    test = TEST_GUEST_TALK_END;
-    break;
-
-  case TEST_GUEST_TALK_END:
-    GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
+    guest_leave ();
     break;
 
   default:
@@ -509,10 +498,10 @@ guest_talk ()
   tmit.data[2] = "testing ten nine eight";
   tmit.data_count = 3;
 
-  tmit.host_ann
-    = GNUNET_SOCIAL_host_announce (hst, "_message_guest", tmit.env,
-                                   &notify_data, &tmit,
-                                   GNUNET_SOCIAL_TALK_NONE);
+  tmit.guest_talk
+    = GNUNET_SOCIAL_guest_talk (gst, "_message_guest", tmit.env,
+                                &notify_data, &tmit,
+                                GNUNET_SOCIAL_TALK_NONE);
 }
 
 void