gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated (dcb51caf6 -> 80588e7d5)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated (dcb51caf6 -> 80588e7d5)
Date: Thu, 18 Apr 2019 15:37:52 +0200

This is an automated email from the git hooks/post-receive script.

julius-buenger pushed a change to branch master
in repository gnunet.

    from dcb51caf6 gnunet-resolver.1
     new e5e34142c TNG testing: Correct parameter type
     new e65fe3319 TNG testing: Update Makefile.am
     new 80588e7d5 TNG testing: Cleanup and Structuring

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/transport/Makefile.am              |  10 +-
 src/transport/test_communicator_unix.c |   5 +
 src/transport/transport-testing2.c     | 194 +++++++++++++++++++++++++++------
 src/transport/transport-testing2.h     |   5 +-
 4 files changed, 175 insertions(+), 39 deletions(-)

diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index c9b23b6c4..b5e195d84 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -277,7 +277,7 @@ gnunet_transport_certificate_creation_LDADD = \
 gnunet_communicator_unix_SOURCES = \
  gnunet-communicator-unix.c
 gnunet_communicator_unix_LDADD = \
-  libgnunettransportcommunicator.la \
+  libgnunettransportcommunicator2.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/util/libgnunetutil.la
 
@@ -675,7 +675,7 @@ TESTS = \
  $(HTTPS_API_TIMEOUT_TEST) \
  $(WLAN_TIMEOUT_TEST) \
  $(BT_TIMEOUT_TEST) \
- test_communicator_udp
+ test_communicator_unix
 if HAVE_GETOPT_BINARY
 TESTS += \
 test_transport_api_slow_ats
@@ -789,9 +789,9 @@ test_plugin_udp_LDADD = \
  $(top_builddir)/src/util/libgnunetutil.la  \
  libgnunettransporttesting.la
 
-test_communicator_udp_SOURCES = \
- test_communicator_udp.c
-test_communicator_udp_LDADD = \
+test_communicator_unix_SOURCES = \
+ test_communicator_unix.c
+test_communicator_unix_LDADD = \
  libgnunettransporttesting2.la \
  $(top_builddir)/src/util/libgnunetutil.la
 
diff --git a/src/transport/test_communicator_unix.c 
b/src/transport/test_communicator_unix.c
index ef7ed32c0..fd189659c 100644
--- a/src/transport/test_communicator_unix.c
+++ b/src/transport/test_communicator_unix.c
@@ -63,6 +63,11 @@ run (void *cls)
       "test_communicator_1.conf",
       &communicator_available,
       NULL); /* cls */
+  GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
+      "transport",
+      "test_communicator_2.conf",
+      &communicator_available,
+      NULL); /* cls */
 }
 
 int
diff --git a/src/transport/transport-testing2.c 
b/src/transport/transport-testing2.c
index dbbc94c7f..51791e981 100644
--- a/src/transport/transport-testing2.c
+++ b/src/transport/transport-testing2.c
@@ -37,6 +37,57 @@
 #define LOG(kind,...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__)
 
 
+struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
+{
+  /**
+   * @brief Handle to the configuration
+   */
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+
+  /**
+   * @brief File name of configuration file
+   */
+  char *cfg_filename;
+
+  /**
+   * @brief Handle to the transport service
+   */
+  struct GNUNET_SERVICE_Handle *tsh;
+
+  /**
+   * @brief Task that will be run on shutdown to stop and clean transport
+   * service
+   */
+  struct GNUNET_SCHEDULER_Task *ts_shutdown_task;
+
+  /**
+   * @brief Handle to the client
+   */
+  struct GNUNET_SERVICE_Client *client;
+
+  /**
+   * @brief Process of the communicator
+   */
+  struct GNUNET_OS_Process *c_proc;
+
+  /**
+   * @brief Task that will be run on shutdown to stop and clean communicator
+   */
+  struct GNUNET_SCHEDULER_Task *c_shutdown_task;
+
+  /* Callbacks + Closures */
+  /**
+   * @brief Callback called when a new communicator connects
+   */
+  GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback 
communicator_available;
+
+  /**
+   * @brief Closure to the callback
+   */
+  void *communicator_available_cls;
+};
+
+
 /**
  * @brief Check whether incoming msg indicating available communicator is
  * correct
@@ -50,9 +101,13 @@ static int
 check_communicator_available (void *cls,
     const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
 {
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-      "check_communicator_available()\n");
-  return GNUNET_YES;
+  uint16_t size;
+
+  size = ntohs (msg->header.size) - sizeof (*msg);
+  if (0 == size)
+    return GNUNET_OK; /* receive-only communicator */
+  GNUNET_MQ_check_zero_termination (msg);
+  return GNUNET_OK;
 }
 
 
@@ -66,16 +121,19 @@ static void
 handle_communicator_available (void *cls,
     const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
 {
-  GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback 
communicator_available = cls;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-      "handle_communicator_available()\n");
-  if (NULL != communicator_available)
+  struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
+  uint16_t size;
+
+  size = ntohs (msg->header.size) - sizeof (*msg);
+  if (0 == size)
+    return; /* receive-only communicator */
+  if (NULL != tc_h->communicator_available)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "calling communicator_available()\n");
-    communicator_available (NULL, msg);
+    tc_h->communicator_available (tc_h->communicator_available_cls, msg);
   }
-  //GNUNET_SERVICE_client_continue (client);
+  GNUNET_SERVICE_client_continue (tc_h->client);
 }
 
 
@@ -93,6 +151,49 @@ shutdown_service (void *cls)
 }
 
 
+/**
+ * @brief Callback called when new Client (Communicator) connects
+ *
+ * @param cls Closure - TransporCommmunicator Handle
+ * @param client Client
+ * @param mq Messagequeue
+ *
+ * @return TransportCommunicator Handle
+ */
+static void *
+connect_cb (void *cls,
+            struct GNUNET_SERVICE_Client *client,
+            struct GNUNET_MQ_Handle *mq)
+{
+  struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+      "Client connected.\n");
+  tc_h->client = client;
+  return tc_h;
+}
+
+
+/**
+ * @brief Callback called when Client disconnects
+ *
+ * @param cls Closure - TransportCommunicator Handle
+ * @param client Client
+ * @param internal_cls TransporCommmunicator Handle
+ */
+static void
+disconnect_cb (void *cls,
+               struct GNUNET_SERVICE_Client *client,
+               void *internal_cls)
+{
+  struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+      "Client disconnected.\n");
+  tc_h->client = NULL;
+}
+
+
 /**
  * @brief Start the communicator part of the transport service
  *
@@ -101,14 +202,13 @@ shutdown_service (void *cls)
  * @param cfg Configuration
  */
 static void
-transport_communicator_start 
(GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available,
-                              struct GNUNET_CONFIGURATION_Handle *cfg)
+transport_communicator_start (struct 
GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
 {
   struct GNUNET_MQ_MessageHandler mh[] = {
     GNUNET_MQ_hd_var_size (communicator_available,
         GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR,
         struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
-        &communicator_available),
+        &tc_h),
     //GNUNET_MQ_hd_var_size (communicator_backchannel,
     //    GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
     //    struct GNUNET_TRANSPORT_CommunicatorBackchannel,
@@ -149,10 +249,10 @@ transport_communicator_start 
(GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCall
   struct GNUNET_SERVICE_Handle *h;
 
   h = GNUNET_SERVICE_start ("transport",
-                            cfg,
-                            NULL,
-                            NULL,
-                            NULL,
+                            tc_h->cfg,
+                            &connect_cb,
+                            &disconnect_cb,
+                            tc_h,
                             mh);
   if (NULL == h)
     LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -161,48 +261,70 @@ transport_communicator_start 
(GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCall
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Started service\n");
-    GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h);
+    /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h);
   }
 }
 
 
+/**
+ * @brief Task run at shutdown to kill communicator and clean up
+ *
+ * @param cls Closure - Process of communicator
+ */
+static void
+shutdown_communicator (void *cls)
+{
+  struct GNUNET_OS_Process *proc = cls;
+
+  if (GNUNET_OK != GNUNET_OS_process_kill (proc,
+                                           SIGTERM))
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+        "Error shutting down communicator with SIGERM, trying SIGKILL\n");
+    if (GNUNET_OK != GNUNET_OS_process_kill (proc,
+                                             SIGKILL))
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR,
+          "Error shutting down communicator with SIGERM and SIGKILL\n");
+    }
+  }
+  GNUNET_OS_process_destroy (proc);
+}
+
+
 /**
  * @brief Start the communicator
  *
  * @param cfgname Name of the communicator
  */
 static void
-communicator_start (const char *cfgname)
+communicator_start (struct 
GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
 {
   char *binary;
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-  struct GNUNET_OS_Process *proc;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
       "communicator_start\n");
   binary = GNUNET_OS_get_libexec_binary_path ("gnunet-communicator-unix");
-  cfg = GNUNET_CONFIGURATION_create ();
-  proc =
+  tc_h->c_proc =
     GNUNET_OS_start_process (GNUNET_YES,
                              GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
                              NULL, NULL, NULL,
                              binary,
                              "./gnunet-communicator-unix",
                              "-c",
-                             cfgname,
+                             tc_h->cfg_filename,
                              NULL);
-  if (NULL == proc)
+  if (NULL == tc_h->c_proc)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Failed to start communicator!");
     return;
   }
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_load (cfg,
-                                            cfgname));
   LOG (GNUNET_ERROR_TYPE_DEBUG,
       "started communicator\n");
   GNUNET_free (binary);
+  /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_communicator,
+                                            tc_h->c_proc);
 }
 
 
@@ -220,18 +342,20 @@ communicator_start (const char *cfgname)
 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
 GNUNET_TRANSPORT_TESTING_transport_communicator_service_start
   (const char *service_name,
-   struct GNUNET_CONFIGURATION_Handle *cfg_filename,
+   const char *cfg_filename,
    GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback 
communicator_available,
    //GNUNET_TRANSPORT_TESTING_Callback2 cb2,
    //GNUNET_TRANSPORT_TESTING_Callback3 cb3,
    //GNUNET_TRANSPORT_TESTING_Callback4 cb4,
    void *cb_cls)
 {
-  struct GNUNET_CONFIGURATION_Handle *cfg;
+  struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h;
 
-  cfg = GNUNET_CONFIGURATION_create ();
+  tc_h = GNUNET_new (struct 
GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle);
+  tc_h->cfg_filename = GNUNET_strdup (cfg_filename);
+  tc_h->cfg = GNUNET_CONFIGURATION_create ();
   if ( (GNUNET_SYSERR ==
-        GNUNET_CONFIGURATION_load (cfg,
+        GNUNET_CONFIGURATION_load (tc_h->cfg,
                                    cfg_filename)) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -239,11 +363,15 @@ 
GNUNET_TRANSPORT_TESTING_transport_communicator_service_start
                   cfg_filename);
     return NULL;
   }
+  tc_h->communicator_available = communicator_available;
+  tc_h->communicator_available_cls = cb_cls;
+
   /* Start communicator part of service */
-  transport_communicator_start (communicator_available, cfg);
+  transport_communicator_start (tc_h);
 
   /* Schedule start communicator */
-  communicator_start ("test_communicator_1.conf");
+  communicator_start (tc_h);
+  return tc_h;
 }
 
 //void
diff --git a/src/transport/transport-testing2.h 
b/src/transport/transport-testing2.h
index a6f0348ef..c5adda4eb 100644
--- a/src/transport/transport-testing2.h
+++ b/src/transport/transport-testing2.h
@@ -29,6 +29,9 @@
 #include "gnunet_ats_transport_service.h"
 #include "transport.h"
 
+
+struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle;
+
 /**
  * @brief Function signature for callbacks that are called when new 
communicators become available
  *
@@ -54,7 +57,7 @@ typedef void
 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
 GNUNET_TRANSPORT_TESTING_transport_communicator_service_start
   (const char *service_name,
-   struct GNUNET_CONFIGURATION_Handle *cfg,
+   const char *cfg_filename,
    GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback 
communicator_available,
    //GNUNET_TRANSPORT_TESTING_Callback2 cb2,
    //GNUNET_TRANSPORT_TESTING_Callback3 cb3,

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]