fix
[oweals/gnunet.git] / src / hostlist / test_gnunet_daemon_hostlist.c
index 443a0d17e8e498b926ef22b495371b6c1d909367..2c3647190e7963d34ce2f45466d3e2ee0649d22b 100644 (file)
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
-#include "gnunet_arm_lib.h"
+#include "gnunet_arm_service.h"
+#include "gnunet_transport_service.h"
 
 #define VERBOSE GNUNET_YES
 
 #define START_ARM GNUNET_YES
 
+
+/**
+ * How long until we give up on transmitting the message?
+ */
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
+
+static int ok;
+
+static struct GNUNET_SCHEDULER_Handle *sched;
+    
 struct PeerContext
 {
   struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -42,6 +53,37 @@ struct PeerContext
 #endif
 };
 
+static struct PeerContext p1;
+
+static struct PeerContext p2;
+
+
+
+static void
+process_hello (void *cls,
+               struct GNUNET_TIME_Relative latency,
+               const struct GNUNET_PeerIdentity *peer,
+               const struct GNUNET_MessageHeader *message)
+{
+  struct PeerContext *p = cls;
+
+  GNUNET_assert (peer != NULL);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received (my) `%s' from transport service of `%4s'\n",
+              "HELLO", GNUNET_i2s (peer));
+  GNUNET_assert (message != NULL);
+  p->hello = GNUNET_malloc (ntohs (message->size));
+  memcpy (p->hello, message, ntohs (message->size));
+  if ((p == &p1) && (p2.th != NULL))
+    GNUNET_TRANSPORT_offer_hello (p2.th, message);
+  if ((p == &p2) && (p1.th != NULL))
+    GNUNET_TRANSPORT_offer_hello (p1.th, message);
+
+  if ((p == &p1) && (p2.hello != NULL))
+    GNUNET_TRANSPORT_offer_hello (p1.th, p2.hello);
+  if ((p == &p2) && (p1.hello != NULL))
+    GNUNET_TRANSPORT_offer_hello (p2.th, p1.hello);
+}
 
 
 static void
@@ -58,7 +100,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
   sleep (1);                    /* allow ARM to start */
 #endif
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
-  GNUNET_ARM_start_service ("core", p->cfg, sched, TIMEOUT, NULL, NULL);
+  GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
   p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, NULL, NULL);
   GNUNET_assert (p->th != NULL);
   GNUNET_TRANSPORT_get_hello (p->th, TIMEOUT, &process_hello, p);
@@ -69,10 +111,11 @@ static void
 run (void *cls,
      struct GNUNET_SCHEDULER_Handle *s,
      char *const *args,
-     const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
+     const char *cfgfile, 
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   GNUNET_assert (ok == 1);
-  OKPP;
+  ok++;
   sched = s;
   setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
   setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
@@ -82,6 +125,7 @@ run (void *cls,
 static void
 stop_arm (struct PeerContext *p)
 {
+  GNUNET_ARM_stop_services (p->cfg, sched, "core", NULL);
 #if START_ARM
   if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
@@ -98,7 +142,7 @@ static int
 check ()
 {
   char *const argv[] = { "test-gnunet-daemon-hostlist",
-    "-c", "test_gnunet_daemon_hostlist.conf",
+    "-c", "test_gnunet_daemon_hostlist_data.conf",
 #if VERBOSE
     "-L", "DEBUG",
 #endif
@@ -131,5 +175,7 @@ main (int argc, char *argv[])
 #endif
                     NULL);
   ret = check ();
-  return 0
+  return ret
 }
+
+/* end of test_gnunet_daemon_hostlist.c */