starting to convert core tests to new MQ API
authorChristian Grothoff <christian@grothoff.org>
Sat, 30 Jul 2016 23:07:34 +0000 (23:07 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 30 Jul 2016 23:07:34 +0000 (23:07 +0000)
src/core/test_core_api.c
src/core/test_core_api_reliability.c
src/core/test_core_api_start_only.c

index 3f0b77bd19160027867fe163da20b47a4ef90b31..772ded991b8ae8dd7d84615186a476967d5509f4 100644 (file)
@@ -20,6 +20,7 @@
 /**
  * @file core/test_core_api.c
  * @brief testcase for core_api.c
+ * @author Christian Grothoff
  */
 #include "platform.h"
 #include "gnunet_arm_service.h"
@@ -91,7 +92,7 @@ terminate_peer (struct PeerContext *p)
 {
   if (NULL != p->ch)
   {
-    GNUNET_CORE_disconnect (p->ch);
+    GNUNET_CORE_disconnecT (p->ch);
     p->ch = NULL;
   }
   if (NULL != p->ghh)
@@ -140,35 +141,19 @@ terminate_task_error (void *cls)
 }
 
 
-static size_t
-transmit_ready (void *cls,
-               size_t size,
-               void *buf)
-{
-  struct PeerContext *p = cls;
-  struct GNUNET_MessageHeader *m;
-
-  GNUNET_assert (ok == 4);
-  OKPP;
-  GNUNET_assert (p == &p1);
-  GNUNET_assert (NULL != buf);
-  m = (struct GNUNET_MessageHeader *) buf;
-  m->type = htons (MTYPE);
-  m->size = htons (sizeof (struct GNUNET_MessageHeader));
-  return sizeof (struct GNUNET_MessageHeader);
-}
-
-
-static void
+static void *
 connect_notify (void *cls,
-                const struct GNUNET_PeerIdentity *peer)
+                const struct GNUNET_PeerIdentity *peer,
+               struct GNUNET_MQ_Handle *mq)
 {
   struct PeerContext *pc = cls;
+  struct GNUNET_MQ_Envelope *env;
+  struct GNUNET_MessageHeader *msg;
 
   if (0 == memcmp (&pc->id,
                   peer,
                   sizeof (struct GNUNET_PeerIdentity)))
-    return;
+    return (void *) peer;
   GNUNET_assert (pc->connect_status == 0);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Encrypted connection established to peer `%s'\n",
@@ -176,30 +161,35 @@ connect_notify (void *cls,
   pc->connect_status = 1;
   if (pc == &p1)
   {
+    uint64_t flags;
+    const void *extra;
+    
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Asking core (1) for transmission to peer `%s'\n",
                 GNUNET_i2s (&p2.id));
-    if (NULL ==
-        GNUNET_CORE_notify_transmit_ready (p1.ch,
-                                          GNUNET_YES,
-                                           GNUNET_CORE_PRIO_BEST_EFFORT,
-                                           GNUNET_TIME_relative_multiply
-                                           (GNUNET_TIME_UNIT_SECONDS, 145),
-                                           &p2.id,
-                                           sizeof (struct GNUNET_MessageHeader),
-                                           &transmit_ready, &p1))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "RECEIVED NULL when asking core (1) for transmission to peer `%s'\n",
-                  GNUNET_i2s (&p2.id));
-    }
+    env = GNUNET_MQ_msg (msg,
+                        MTYPE);
+    /* enable corking for this test */
+    extra = GNUNET_CORE_get_mq_options (GNUNET_YES,
+                                       GNUNET_CORE_PRIO_BEST_EFFORT,
+                                       &flags);
+    GNUNET_MQ_env_set_options (env,
+                              flags,
+                              extra);
+    /* now actually transmit message */
+    GNUNET_assert (ok == 4);
+    OKPP;
+    GNUNET_MQ_send (mq,
+                   env);
   }
+  return (void *) peer;
 }
 
 
 static void
 disconnect_notify (void *cls,
-                  const struct GNUNET_PeerIdentity *peer)
+                  const struct GNUNET_PeerIdentity *peer,
+                  void *internal_cls)
 {
   struct PeerContext *pc = cls;
 
@@ -214,35 +204,12 @@ disconnect_notify (void *cls,
 }
 
 
-static int
-inbound_notify (void *cls,
-               const struct GNUNET_PeerIdentity *other,
-                const struct GNUNET_MessageHeader *message)
-{
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Core provides inbound data from `%s'.\n",
-             GNUNET_i2s (other));
-  return GNUNET_OK;
-}
-
-
-static int
-outbound_notify (void *cls,
-                const struct GNUNET_PeerIdentity *other,
-                 const struct GNUNET_MessageHeader *message)
-{
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Core notifies about outbound data for `%s'.\n",
-              GNUNET_i2s (other));
-  return GNUNET_OK;
-}
-
-
-static int
-process_mtype (void *cls,
-               const struct GNUNET_PeerIdentity *peer,
-               const struct GNUNET_MessageHeader *message)
+static void
+handle_test (void *cls,
+            const struct GNUNET_MessageHeader *message)
 {
+  const struct GNUNET_PeerIdentity *peer = cls;
+  
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Receiving message from `%s'.\n",
               GNUNET_i2s (peer));
@@ -251,21 +218,21 @@ process_mtype (void *cls,
   GNUNET_SCHEDULER_cancel (err_task);
   err_task = GNUNET_SCHEDULER_add_now (&terminate_task,
                                       NULL);
-  return GNUNET_OK;
 }
 
 
-static struct GNUNET_CORE_MessageHandler handlers[] = {
-  {&process_mtype, MTYPE, sizeof (struct GNUNET_MessageHeader)},
-  {NULL, 0, 0}
-};
-
-
 static void
 init_notify (void *cls,
              const struct GNUNET_PeerIdentity *my_identity)
 {
+  GNUNET_MQ_hd_fixed_size (test,
+                          MTYPE,
+                          struct GNUNET_MessageHeader);
   struct PeerContext *p = cls;
+  struct GNUNET_MQ_MessageHandler handlers[] = {
+    make_test_handler (NULL),
+    GNUNET_MQ_handler_end ()
+  };
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Core connection to `%s' established\n",
@@ -276,13 +243,11 @@ init_notify (void *cls,
     GNUNET_assert (ok == 2);
     OKPP;
     /* connect p2 */
-    p2.ch = GNUNET_CORE_connect (p2.cfg,
+    p2.ch = GNUNET_CORE_connecT (p2.cfg,
                                 &p2,
                                 &init_notify,
                                 &connect_notify,
                                 &disconnect_notify,
-                                &inbound_notify, GNUNET_YES,
-                                &outbound_notify, GNUNET_YES,
                                 handlers);
   }
   else
@@ -333,21 +298,30 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  GNUNET_MQ_hd_fixed_size (test,
+                          MTYPE,
+                          struct GNUNET_MessageHeader);
+  struct GNUNET_MQ_MessageHandler handlers[] = {
+    make_test_handler (NULL),
+    GNUNET_MQ_handler_end ()
+  };
+
   GNUNET_assert (ok == 1);
   OKPP;
-  setup_peer (&p1, "test_core_api_peer1.conf");
-  setup_peer (&p2, "test_core_api_peer2.conf");
+  setup_peer (&p1,
+             "test_core_api_peer1.conf");
+  setup_peer (&p2,
+             "test_core_api_peer2.conf");
   err_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_SECONDS, 300),
                                     &terminate_task_error, NULL);
   p1.ch =
-      GNUNET_CORE_connect (p1.cfg, &p1,
+      GNUNET_CORE_connecT (p1.cfg,
+                          &p1,
                            &init_notify,
                            &connect_notify,
                            &disconnect_notify,
-                           &inbound_notify, GNUNET_YES,
-                           &outbound_notify, GNUNET_YES,
                            handlers);
 }
 
@@ -355,11 +329,16 @@ run (void *cls,
 static void
 stop_arm (struct PeerContext *p)
 {
-  if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG))
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-  if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
+  if (0 != GNUNET_OS_process_kill (p->arm_proc,
+                                  GNUNET_TERM_SIG))
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+                        "kill");
+  if (GNUNET_OK !=
+      GNUNET_OS_process_wait (p->arm_proc))
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+                        "waitpid");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "ARM process %u stopped\n",
               GNUNET_OS_process_get_pid (p->arm_proc));
   GNUNET_OS_process_destroy (p->arm_proc);
   p->arm_proc = NULL;
index c5ee124780acf712775a6631f0089c3f3cd3aa34..7a3b53c537d113911ee1e67e08bbf2dbdbbf42e1 100644 (file)
@@ -20,6 +20,7 @@
 /**
  * @file core/test_core_api_reliability.c
  * @brief testcase for core_api.c focusing on reliable transmission (with TCP)
+ * @author Christian Grothoff
  */
 #include "platform.h"
 #include "gnunet_arm_service.h"
@@ -291,30 +292,6 @@ disconnect_notify (void *cls,
 }
 
 
-static int
-inbound_notify (void *cls,
-                const struct GNUNET_PeerIdentity *other,
-                const struct GNUNET_MessageHeader *message)
-{
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Core provides inbound data from `%s'.\n",
-              GNUNET_i2s (other));
-  return GNUNET_OK;
-}
-
-
-static int
-outbound_notify (void *cls,
-                 const struct GNUNET_PeerIdentity *other,
-                 const struct GNUNET_MessageHeader *message)
-{
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Core notifies about outbound data for `%s'.\n",
-              GNUNET_i2s (other));
-  return GNUNET_OK;
-}
-
-
 static size_t
 transmit_ready (void *cls,
                 size_t size,
@@ -413,9 +390,9 @@ init_notify (void *cls,
                                                 &init_notify,
                                                 &connect_notify,
                                                 &disconnect_notify,
-                                                &inbound_notify,
+                                                NULL,
                                                 GNUNET_YES,
-                                                &outbound_notify,
+                                                NULL,
                                                 GNUNET_YES,
                                                 handlers)));
   }
@@ -532,9 +509,9 @@ run (void *cls,
                                               &init_notify,
                                               &connect_notify,
                                               &disconnect_notify,
-                                              &inbound_notify,
+                                              NULL,
                                               GNUNET_YES,
-                                              &outbound_notify,
+                                              NULL,
                                               GNUNET_YES,
                                               handlers)));
 }
index 07a40218942348f61c8123d2e0741b3160d185d4..6abc3cc895efb9dc78ec96460a520e8ec5c1f8b2 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009 GNUnet e.V.
+     Copyright (C) 2009, 2016 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -21,6 +21,7 @@
  * @file transport/test_core_api_start_only.c
  * @brief testcase for core_api.c that only starts two peers,
  *        connects to the core service and shuts down again
+ * @author Christian Grothoff
  */
 #include "platform.h"
 #include "gnunet_arm_service.h"
@@ -48,49 +49,34 @@ static struct GNUNET_SCHEDULER_Task *timeout_task_id;
 static int ok;
 
 
-static void
+static void *
 connect_notify (void *cls,
-               const struct GNUNET_PeerIdentity *peer)
+               const struct GNUNET_PeerIdentity *peer,
+               struct GNUNET_MQ_Handle *mq)
 {
+  return NULL;
 }
 
 
 static void
 disconnect_notify (void *cls,
-                  const struct GNUNET_PeerIdentity *peer)
-{
-}
-
-
-static int
-inbound_notify (void *cls,
-               const struct GNUNET_PeerIdentity *other,
-                const struct GNUNET_MessageHeader *message)
-{
-  return GNUNET_OK;
-}
-
-
-static int
-outbound_notify (void *cls,
-                const struct GNUNET_PeerIdentity *other,
-                 const struct GNUNET_MessageHeader *message)
+                  const struct GNUNET_PeerIdentity *peer,
+                  void *internal_cls)
 {
-  return GNUNET_OK;
 }
 
 
-static struct GNUNET_CORE_MessageHandler handlers[] = {
-  {NULL, 0, 0}
+static struct GNUNET_MQ_MessageHandler handlers[] = {
+  GNUNET_MQ_handler_end ()
 };
 
 
 static void
 shutdown_task (void *cls)
 {
-  GNUNET_CORE_disconnect (p1.ch);
+  GNUNET_CORE_disconnecT (p1.ch);
   p1.ch = NULL;
-  GNUNET_CORE_disconnect (p2.ch);
+  GNUNET_CORE_disconnecT (p2.ch);
   p2.ch = NULL;
   ok = 0;
 }
@@ -105,15 +91,12 @@ init_notify (void *cls,
   if (p == &p1)
   {
     /* connect p2 */
-    p2.ch =
-        GNUNET_CORE_connect (p2.cfg,
-                            &p2,
-                            &init_notify,
-                            &connect_notify,
-                             &disconnect_notify,
-                            &inbound_notify, GNUNET_YES,
-                             &outbound_notify, GNUNET_YES,
-                            handlers);
+    p2.ch = GNUNET_CORE_connecT (p2.cfg,
+                                &p2,
+                                &init_notify,
+                                &connect_notify,
+                                &disconnect_notify,
+                                handlers);
   }
   else
   {
@@ -152,15 +135,17 @@ setup_peer (struct PeerContext *p,
 static void
 timeout_task (void *cls)
 {
-  FPRINTF (stderr, "%s",  "Timeout.\n");
+  FPRINTF (stderr,
+          "%s",
+          "Timeout.\n");
   if (NULL != p1.ch)
   {
-    GNUNET_CORE_disconnect (p1.ch);
+    GNUNET_CORE_disconnecT (p1.ch);
     p1.ch = NULL;
   }
   if (NULL != p2.ch)
   {
-    GNUNET_CORE_disconnect (p2.ch);
+    GNUNET_CORE_disconnecT (p2.ch);
     p2.ch = NULL;
   }
   ok = 42;
@@ -181,14 +166,13 @@ run (void *cls,
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_MINUTES,
                                     TIMEOUT),
-                                    &timeout_task, NULL);
-  p1.ch = GNUNET_CORE_connect (p1.cfg,
+                                    &timeout_task,
+                                   NULL);
+  p1.ch = GNUNET_CORE_connecT (p1.cfg,
                               &p1,
                               &init_notify,
                               &connect_notify,
                               &disconnect_notify,
-                              &inbound_notify, GNUNET_YES,
-                              &outbound_notify, GNUNET_YES,
                               handlers);
 }