-working on stream
authorChristian Grothoff <christian@grothoff.org>
Wed, 20 Jun 2012 12:41:35 +0000 (12:41 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 20 Jun 2012 12:41:35 +0000 (12:41 +0000)
src/include/gnunet_testing_lib-new.h
src/nse/Makefile.am
src/stream/Makefile.am
src/stream/stream_api.c
src/stream/test_stream_big.c
src/testing/testing.c

index 31bc2234ab4136f0e1dd1b6cb509cf1725a6f89e..7daa4ee7f1467ed0bf240fe8901c6683f7a6d35d 100644 (file)
@@ -176,6 +176,17 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
                               char **emsg);
 
 
+/**
+ * Obtain the peer identity from a peer handle.
+ *
+ * @param peer peer handle for which we want the peer's identity
+ * @param id identifier for the daemon, will be set
+ */
+void
+GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
+                                 struct GNUNET_PeerIdentity *id);
+
+
 /**
  * Start the peer. 
  *
@@ -224,10 +235,11 @@ typedef void (*GNUNET_TESTING_TestMain)(void *cls,
  * 
  * @param cls closure
  * @param cfg configuration of the peer that was started
+ * @param peer identity of the peer that was created
  */
 typedef void (*GNUNET_TESTING_RestartableTestMain)(void *cls,
-                                       const struct GNUNET_CONFIGURATION_Handle *cfg,
-                    const struct GNUNET_TESTING_Peer *peer);
+                                                  const struct GNUNET_CONFIGURATION_Handle *cfg,
+                                                  const struct GNUNET_TESTING_Peer *peer);
 
 
 /**
@@ -287,6 +299,10 @@ GNUNET_TESTING_service_run (const char *testdir,
  * The only difference is that we handle the GNUNET_TESTING_Peer to
  * the RestartableTestMain, so that the peer can be destroyed and re-created
  * to simulate failure in tests.
+ *
+ * FIXME: change 'GNUNET_TESTING_TestMain' to have the 'restartable' signature
+ * and remove this extra function (in some sense, make this the primary one,
+ * but keep the old name).
  */
 int
 GNUNET_TESTING_service_run_restartable (const char *testdir,
index 8dcb56fbd17e43c974bb5ae104e47a0c1eb9b1c0..5303b4cdb7ee295fb77b9e98a4eaf39488b194b8 100644 (file)
@@ -34,7 +34,7 @@ noinst_PROGRAMS = \
  gnunet-nse-profiler
 
 gnunet_nse_profiler_SOURCES = \
- gnunet-nse-profiler.c         
+ gnunet-nse-profiler.c
 gnunet_nse_profiler_LDADD = -lm \
   $(top_builddir)/src/nse/libgnunetnse.la \
   $(top_builddir)/src/util/libgnunetutil.la \
index 3a0e6835e5b21708f54da6937000b1875e4d3167..10d87f0425f676580d9df33ba62a3a7df4ea5431 100644 (file)
@@ -62,7 +62,7 @@ test_stream_big_SOURCES = \
 test_stream_big_LDADD = \
  $(top_builddir)/src/stream/libgnunetstream.la \
  $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/testing_old/libgnunettesting_old.la
+ $(top_builddir)/src/testing/libgnunettesting.la
 
 test_stream_sequence_wraparound_SOURCES = \
  test_stream_sequence_wraparound.c
index fda1810f60b715b3439974d80cef781fc96c899a..e27f4df1fab00f96498986d78084f25ed30286e0 100644 (file)
@@ -702,6 +702,7 @@ send_ack_notify (void *cls, size_t size, void *buf)
   return size;
 }
 
+
 /**
  * Writes data using the given socket. The amount of data written is limited by
  * the receiver_window_size
@@ -711,6 +712,7 @@ send_ack_notify (void *cls, size_t size, void *buf)
 static void 
 write_data (struct GNUNET_STREAM_Socket *socket);
 
+
 /**
  * Task for retransmitting data messages if they aren't ACK before their ack
  * deadline 
@@ -1294,7 +1296,6 @@ set_state_established (void *cls,
   socket->write_offset = 0;
   socket->read_offset = 0;
   socket->state = STATE_ESTABLISHED;
-  /* FIXME: What if listen_cb is NULL */
   if (NULL != socket->lsocket)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1306,12 +1307,12 @@ set_state_established (void *cls,
                                     &socket->other_peer))
     {
       socket->state = STATE_CLOSED;
-      /* FIXME: We should close in a decent way */
+      /* FIXME: We should close in a decent way (send RST) */
       GNUNET_MESH_tunnel_destroy (socket->tunnel); /* Destroy the tunnel */
       GNUNET_free (socket);
     }
   }
-  else if (socket->open_cb)
+  else if (NULL != socket->open_cb)
     socket->open_cb (socket->open_cls, socket);
 }
 
@@ -1404,6 +1405,7 @@ set_state_closed (void *cls,
   socket->state = STATE_CLOSED;
 }
 
+
 /**
  * Returns a new HelloAckMessage. Also sets the write sequence number for the
  * socket
@@ -3068,7 +3070,6 @@ GNUNET_STREAM_shutdown_cancel (struct GNUNET_STREAM_ShutdownHandle *handle)
   if (GNUNET_SCHEDULER_NO_TASK != handle->close_msg_retransmission_task_id)
     GNUNET_SCHEDULER_cancel (handle->close_msg_retransmission_task_id);
   GNUNET_free (handle);
-  return;
 }
 
 
@@ -3180,6 +3181,7 @@ GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
   enum GNUNET_STREAM_Option option;
   va_list vargs;
 
+  GNUNET_assert (NULL != listen_cb);
   lsocket = GNUNET_malloc (sizeof (struct GNUNET_STREAM_ListenSocket));
   lsocket->cfg = GNUNET_CONFIGURATION_dup (cfg);
   lsocket->lockmanager = GNUNET_LOCKMANAGER_connect (lsocket->cfg);
@@ -3376,7 +3378,6 @@ GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket,
 }
 
 
-
 /**
  * Tries to read data from the stream.
  *
@@ -3479,7 +3480,6 @@ GNUNET_STREAM_io_write_cancel (struct GNUNET_STREAM_IOWriteHandle *ioh)
       
   GNUNET_free (socket->write_handle);
   socket->write_handle = NULL;
-  return;
 }
 
 
@@ -3491,5 +3491,7 @@ GNUNET_STREAM_io_write_cancel (struct GNUNET_STREAM_IOWriteHandle *ioh)
 void
 GNUNET_STREAM_io_read_cancel (struct GNUNET_STREAM_IOReadHandle *ioh)
 {
-  return;
+  // FIXME: do stuff
 }
+
+/* end of stream_api.c */
index 2ddfaff80a14b379c6a07ae456e9e4d1bba00dc1..03dec7c3d9a2747c34b4f1030f1d886231c3402d 100644 (file)
@@ -29,7 +29,7 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_stream_lib.h"
-#include "gnunet_testing_lib.h"
+#include "gnunet_testing_lib-new.h"
 
 #define LOG(kind, ...)                         \
   GNUNET_log (kind, __VA_ARGS__);
@@ -48,6 +48,8 @@ struct PeerData
    */
   struct GNUNET_STREAM_Socket *socket;
 
+  struct GNUNET_PeerIdentity self;
+
   /**
    * Peer's io write handle
    */
@@ -69,11 +71,10 @@ struct PeerData
   unsigned int bytes_read;
 };
 
-static struct GNUNET_OS_Process *arm_pid;
 static struct PeerData peer1;
 static struct PeerData peer2;
 static struct GNUNET_STREAM_ListenSocket *peer2_listen_socket;
-static struct GNUNET_CONFIGURATION_Handle *config;
+static const struct GNUNET_CONFIGURATION_Handle *config;
 
 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
 static GNUNET_SCHEDULER_TaskIdentifier test_task;
@@ -100,16 +101,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   {
     GNUNET_SCHEDULER_cancel (abort_task);
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: arm\n");
-  if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
-  {
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-  }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
-  /* Free the duplicated configuration */
-  GNUNET_CONFIGURATION_destroy (config);
-  GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
-  GNUNET_OS_process_destroy (arm_pid);
 }
 
 
@@ -340,14 +332,10 @@ static void
 stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct PeerData *peer = cls;
-  struct GNUNET_PeerIdentity self;
 
-  GNUNET_assert (&peer1 == peer);
-  GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config,
-                                                                &self));
   /* Connect to stream */
   peer->socket = GNUNET_STREAM_open (config,
-                                     &self,         /* Null for local peer? */
+                                     &peer2.self,         /* Null for local peer? */
                                      10,           /* App port */
                                      &stream_open_cb,
                                      &peer1,
@@ -357,87 +345,45 @@ stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
 
 /**
- * Testing function
+ * Initialize framework and start test
  *
- * @param cls NULL
- * @param tc the task context
+ * @param cls closure
+ * @param cfg configuration of the peer that was started
+ * @param peer identity of the peer that was created
  */
 static void
-test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+run (void *cls, 
+     const struct GNUNET_CONFIGURATION_Handle *cfg,
+     const struct GNUNET_TESTING_Peer *peer)
 {
   struct GNUNET_PeerIdentity self;
-
-  test_task = GNUNET_SCHEDULER_NO_TASK;
-  /* Get our identity */
-  GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config,
-                                                                &self));
-
+  
+  GNUNET_TESTING_peer_get_identity (peer, &self);
+  config = cfg;
+  abort_task =
+    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                  (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort,
+                                  NULL);
   peer2_listen_socket = GNUNET_STREAM_listen (config,
                                               10, /* App port */
                                               &stream_listen_cb,
                                               NULL,
                                               GNUNET_STREAM_OPTION_END);
   GNUNET_assert (NULL != peer2_listen_socket);
+  peer1.self = self;
+  peer2.self = self;
   GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, &peer1);
 }
 
-
-/**
- * Initialize framework and start test
- */
-static void
-run (void *cls, char *const *args, const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  /* Duplicate the configuration */
-  config = GNUNET_CONFIGURATION_dup (cfg);
-  arm_pid =
-    GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
-                             "gnunet-service-arm",
-#if VERBOSE_ARM
-                             "-L", "DEBUG",
-#endif
-                             "-c", "test_stream_local.conf", NULL);
-  
-  abort_task =
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                  (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort,
-                                  NULL);
-  test_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(3), &test, NULL);  
-}
-
 /**
  * Main function
  */
 int main (int argc, char **argv)
 {
-  int ret;
-  
-  char *const argv2[] = { "test-stream-big",
-                          "-c", "test_stream_local.conf",
-                          "-L", "DEBUG",
-                          NULL
-  };
-  
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-  
-  ret =
-    GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
-                        "test-stream-big", "nohelp", options, &run, NULL);
-  
-  if (GNUNET_OK != ret)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
-                ret);
+  if (0 != GNUNET_TESTING_service_run_restartable ("test-stream-big",
+                                                  "arm",
+                                                  "test_stream_local.conf",                                               
+                                                  &run, NULL))
     return 1;
-  }
-  if (GNUNET_SYSERR == result)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
-    return 1;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n");
-  return 0;
+  return (GNUNET_SYSERR == result) ? 1 : 0;
 }
index 369bd4e51ffa089f3e3b925f7726796ada012125..3e6cbbb0ed9aec1a038a21a1b6553e022d95e821 100644 (file)
@@ -799,6 +799,21 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
 }
 
 
+/**
+ * Obtain the peer identity from a peer handle.
+ *
+ * @param peer peer handle for which we want the peer's identity
+ * @param id identifier for the daemon, will be set
+ */
+void
+GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
+                                 struct GNUNET_PeerIdentity *id)
+{
+  GNUNET_assert (0); // FIXME-SREE.
+  // *id = peer->id;
+}
+
+
 /**
  * Start the peer. 
  *