gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r15217 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r15217 - gnunet/src/mesh
Date: Thu, 12 May 2011 16:01:29 +0200

Author: grothoff
Date: 2011-05-12 16:01:29 +0200 (Thu, 12 May 2011)
New Revision: 15217

Modified:
   gnunet/src/mesh/gnunet-service-mesh.c
   gnunet/src/mesh/mesh_api_new.c
   gnunet/src/mesh/test_mesh_api.c
Log:
fixes

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2011-05-12 13:46:15 UTC (rev 
15216)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2011-05-12 14:01:29 UTC (rev 
15217)
@@ -1297,6 +1297,27 @@
 
/******************************************************************************/
 
 /**
+ * Task run during shutdown.
+ *
+ * @param cls unused
+ * @param tc unused
+ */
+static void
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (core_handle != NULL)
+    {
+      GNUNET_CORE_disconnect (core_handle);
+      core_handle = NULL;
+    }
+ if (dht_handle != NULL)
+    {
+      GNUNET_DHT_disconnect (dht_handle);
+      dht_handle = NULL;
+    } 
+}
+
+/**
  * Process mesh requests.
  *
  * @param cls closure
@@ -1331,6 +1352,11 @@
     if (dht_handle == NULL) {
         GNUNET_break(0);
     }
+
+  /* Scheduled the task to clean up when shutdown is called */
+    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                 &shutdown_task, NULL);
+
 }
 
 /**

Modified: gnunet/src/mesh/mesh_api_new.c
===================================================================
--- gnunet/src/mesh/mesh_api_new.c      2011-05-12 13:46:15 UTC (rev 15216)
+++ gnunet/src/mesh/mesh_api_new.c      2011-05-12 14:01:29 UTC (rev 15217)
@@ -76,6 +76,9 @@
      */
     GNUNET_MESH_TunnelEndHandler                *cleaner;
 
+
+    struct GNUNET_CLIENT_TransmitHandle *th;
+
     /**
      * Closure for all the handlers given by the client
      */
@@ -127,26 +130,28 @@
  * @param buf where the callee should write the message
  * @return number of bytes written to buf
  */
-size_t 
+static size_t 
 send_connect_packet (void *cls, size_t size, void *buf) {
-    struct GNUNET_MESH_Handle           *h;
+    struct GNUNET_MESH_Handle           *h = cls;
     struct GNUNET_MESH_ClientConnect    *msg;
     uint16_t                            *types;
     int                                 ntypes;
     GNUNET_MESH_ApplicationType         *apps;
     int                                 napps;
 
-    if(0 == size || buf == NULL) {
+    h->th = NULL;
+    if (0 == size || buf == NULL) {
         GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size 0 or buffer 
invalid\n");
+       // FIXME: disconnect, reconnect, retry!
         return 0;
     }
-    if(sizeof(struct GNUNET_MessageHeader) > size) {
+    if (sizeof(struct GNUNET_MessageHeader) > size) {
         GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size too 
small\n");
+       // FIXME: disconnect, reconnect, retry!
         return 0;
     }
 
     msg = (struct GNUNET_MESH_ClientConnect *) buf;
-    h = (struct GNUNET_MESH_Handle *) cls;
     msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
 
     for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) {
@@ -219,7 +224,8 @@
                      void *cls,
                      GNUNET_MESH_TunnelEndHandler cleaner,
                      const struct GNUNET_MESH_MessageHandler *handlers,
-                     const GNUNET_MESH_ApplicationType *stypes) {
+                     const GNUNET_MESH_ApplicationType *stypes) 
+{
     struct GNUNET_MESH_Handle           *h;
     size_t                              size;
 
@@ -247,12 +253,12 @@
     size += h->n_handlers * sizeof(uint16_t);
     size += h->n_applications * sizeof(GNUNET_MESH_ApplicationType);
 
-    GNUNET_CLIENT_notify_transmit_ready(h->mesh,
-                                        size,
-                                        GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 10),
-                                        GNUNET_NO,
-                                        &send_connect_packet,
-                                        (void *)h);
+    h->th = GNUNET_CLIENT_notify_transmit_ready(h->mesh,
+                                               size,
+                                               GNUNET_TIME_UNIT_FOREVER_REL,
+                                               GNUNET_YES,
+                                               &send_connect_packet,
+                                               (void *)h);
 
     return h;
 }
@@ -263,10 +269,14 @@
  *
  * @param handle connection to mesh to disconnect
  */
-void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) {
-
-    GNUNET_free(handle);
-    return;
+void 
+GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) 
+{
+  if (NULL != handle->th) 
+    GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
+  if (NULL != handle->mesh)
+    GNUNET_CLIENT_disconnect (handle->mesh, GNUNET_NO);
+  GNUNET_free(handle);
 }
 
 

Modified: gnunet/src/mesh/test_mesh_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_api.c     2011-05-12 13:46:15 UTC (rev 15216)
+++ gnunet/src/mesh/test_mesh_api.c     2011-05-12 14:01:29 UTC (rev 15217)
@@ -7,16 +7,31 @@
     {NULL, 0, 0}
 };
 
+static struct GNUNET_OS_Process            *arm_pid;
 
+static struct GNUNET_MESH_Handle           *mesh;
+
+static struct GNUNET_DHT_Handle            *dht;
+
 static void
+  do_shutdown (void *cls,
+              const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (NULL != mesh)
+    GNUNET_MESH_disconnect (mesh);
+    if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
+        GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+    GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
+    GNUNET_OS_process_close (arm_pid);
+}
+
+
+static void
 run (void *cls,
      char *const *args,
      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) {
-    struct GNUNET_OS_Process            *arm_pid;
-    struct GNUNET_MESH_Handle           *mesh;
-    struct GNUNET_DHT_Handle            *dht;
     GNUNET_MESH_ApplicationType         app;
-    char                                buffer[2048];
+    // char                                buffer[2048];
 
 
     arm_pid = GNUNET_OS_start_process (NULL, NULL,
@@ -41,16 +56,15 @@
     }
 
     /* do real test work here */
-    if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
-        GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-    GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
-    GNUNET_OS_process_close (arm_pid);
-
-    return;
+    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                 &do_shutdown,
+                                 NULL);
 }
 
 
 
+
+
 int main (int argc, char *argv[]) {
     int ret;
     char *const argv2[] = {"test-mesh-api",




reply via email to

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