gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r9398 - in gnunet/src: core fs hostlist include topology


From: gnunet
Subject: [GNUnet-SVN] r9398 - in gnunet/src: core fs hostlist include topology
Date: Wed, 4 Nov 2009 08:43:09 -0700

Author: grothoff
Date: 2009-11-04 08:43:09 -0700 (Wed, 04 Nov 2009)
New Revision: 9398

Modified:
   gnunet/src/core/core_api.c
   gnunet/src/fs/gnunet-service-fs.c
   gnunet/src/hostlist/gnunet-daemon-hostlist.c
   gnunet/src/include/gnunet_core_service.h
   gnunet/src/topology/gnunet-daemon-topology.c
Log:
fixing core API for early shutdown handling

Modified: gnunet/src/core/core_api.c
===================================================================
--- gnunet/src/core/core_api.c  2009-11-04 15:13:26 UTC (rev 9397)
+++ gnunet/src/core/core_api.c  2009-11-04 15:43:09 UTC (rev 9398)
@@ -804,7 +804,7 @@
  * @param timeout after how long should we give up trying to connect to the 
core service?
  * @param cls closure for the various callbacks that follow (including 
handlers in the handlers array)
  * @param init callback to call on timeout or once we have successfully
- *        connected to the core service
+ *        connected to the core service; note that timeout is only meaningful 
if init is not NULL
  * @param connects function to call on peer connect, can be NULL
  * @param disconnects function to call on peer disconnect / timeout, can be 
NULL
  * @param bfc function to call to fill up spare bandwidth, can be NULL
@@ -817,8 +817,10 @@
  *                GNUNET_MessageHeader and hence we do not need to give it the 
full message
  *                can be used to improve efficiency, ignored if 
outbound_notify is NULLL
  * @param handlers callbacks for messages we care about, NULL-terminated
+ * @return handle to the core service (only useful for disconnect until 'init' 
is called);
+ *                NULL on error (in this case, init is never called)
  */
-void
+struct GNUNET_CORE_Handle *
 GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
                      const struct GNUNET_CONFIGURATION_Handle *cfg,
                      struct GNUNET_TIME_Relative timeout,
@@ -835,7 +837,6 @@
 {
   struct GNUNET_CORE_Handle *h;
 
-  GNUNET_assert (init != NULL);
   h = GNUNET_malloc (sizeof (struct GNUNET_CORE_Handle));
   h->sched = sched;
   h->cfg = cfg;
@@ -852,9 +853,8 @@
   h->client = GNUNET_CLIENT_connect (sched, "core", cfg);
   if (h->client == NULL)
     {
-      init (cls, NULL, NULL, NULL);
       GNUNET_free (h);
-      return;
+      return NULL;
     }
   h->startup_timeout = GNUNET_TIME_relative_to_absolute (timeout);
   h->hcnt = 0;
@@ -874,6 +874,7 @@
                                          sizeof (uint16_t) * h->hcnt, timeout,
                                         GNUNET_YES,
                                          &transmit_start, h);
+  return h;
 }
 
 

Modified: gnunet/src/fs/gnunet-service-fs.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs.c   2009-11-04 15:13:26 UTC (rev 9397)
+++ gnunet/src/fs/gnunet-service-fs.c   2009-11-04 15:43:09 UTC (rev 9398)
@@ -792,6 +792,7 @@
  */
 static uint64_t max_pending_requests = 32;
 
+
 /**
  * Write the current index information list to disk.
  */ 
@@ -2326,10 +2327,16 @@
   struct IndexInfo *pos;  
 
   if (NULL != core)
-    GNUNET_CORE_disconnect (core);
-  GNUNET_DATASTORE_disconnect (dsh,
-                              GNUNET_NO);
-  dsh = NULL;
+    {
+      GNUNET_CORE_disconnect (core);
+      core = NULL;
+    }
+  if (NULL != dsh)
+    {
+      GNUNET_DATASTORE_disconnect (dsh,
+                                  GNUNET_NO);
+      dsh = NULL;
+    }
   GNUNET_CONTAINER_multihashmap_iterate (requests_by_query,
                                         &destroy_pending_request_cb,
                                         NULL);
@@ -3275,73 +3282,6 @@
 
 
 /**
- * Task that will try to initiate a connection with the
- * core service.
- * 
- * @param cls unused
- * @param tc unused
- */
-static void
-core_connect_task (void *cls,
-                  const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-/**
- * Function called by the core after we've
- * connected.
- *
- * @param cls closure, unused
- * @param server handle to the core service
- * @param my_identity our peer identity (unused)
- * @param publicKey our public key (unused)
- */
-static void
-core_start_cb (void *cls,
-              struct GNUNET_CORE_Handle * server,
-              const struct GNUNET_PeerIdentity *
-              my_identity,
-              const struct
-              GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
-              publicKey)
-{
-  if (server == NULL)
-    {
-      GNUNET_SCHEDULER_add_delayed (sched,
-                                   GNUNET_TIME_UNIT_SECONDS,
-                                   &core_connect_task,
-                                   NULL);
-      return;
-    }
-  core = server;
-}
-
-
-/**
- * Task that will try to initiate a connection with the
- * core service.
- * 
- * @param cls unused
- * @param tc unused
- */
-static void
-core_connect_task (void *cls,
-                  const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  GNUNET_CORE_connect (sched,
-                      cfg,
-                      GNUNET_TIME_UNIT_FOREVER_REL,
-                      NULL,
-                      &core_start_cb,
-                      &peer_connect_handler,
-                      &peer_disconnect_handler,
-                      NULL, 
-                      NULL, GNUNET_NO,
-                      NULL, GNUNET_NO,
-                      p2p_handlers);
-}
-
-
-/**
  * Process fs requests.
  *
  * @param cls closure
@@ -3366,21 +3306,42 @@
   read_index_list ();
   dsh = GNUNET_DATASTORE_connect (cfg,
                                  sched);
-  if (NULL == dsh)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                 _("Failed to connect to datastore service.\n"));
-      return;
-    }
+  core = GNUNET_CORE_connect (sched,
+                             cfg,
+                             GNUNET_TIME_UNIT_FOREVER_REL,
+                             NULL,
+                             NULL,
+                             &peer_connect_handler,
+                             &peer_disconnect_handler,
+                             NULL, 
+                             NULL, GNUNET_NO,
+                             NULL, GNUNET_NO,
+                             p2p_handlers);
+
   GNUNET_SERVER_disconnect_notify (server, 
                                   &handle_client_disconnect,
                                   NULL);
   GNUNET_SERVER_add_handlers (server, handlers);
-  core_connect_task (NULL, NULL);
   GNUNET_SCHEDULER_add_delayed (sched,
                                GNUNET_TIME_UNIT_FOREVER_REL,
                                &shutdown_task,
                                NULL);
+  if (NULL == dsh)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Failed to connect to `%s' service.\n"),
+                 "datastore");
+      GNUNET_SCHEDULER_shutdown (sched);
+      return;
+    }
+  if (NULL == core)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Failed to connect to `%s' service.\n"),
+                 "core");
+      GNUNET_SCHEDULER_shutdown (sched);
+      return;
+    }
 }
 
 

Modified: gnunet/src/hostlist/gnunet-daemon-hostlist.c
===================================================================
--- gnunet/src/hostlist/gnunet-daemon-hostlist.c        2009-11-04 15:13:26 UTC 
(rev 9397)
+++ gnunet/src/hostlist/gnunet-daemon-hostlist.c        2009-11-04 15:43:09 UTC 
(rev 9398)
@@ -71,6 +71,11 @@
 static struct GNUNET_STATISTICS_Handle *stats;
 
 /**
+ * Handle to the core service (NULL until we've connected to it).
+ */
+struct GNUNET_CORE_Handle *core;
+
+/**
  * gnunet-daemon-hostlist command line options.
  */
 static struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -119,6 +124,7 @@
                                 GNUNET_NO);
       stats = NULL;
     }
+  GNUNET_CORE_disconnect (core);
 }
 
 
@@ -167,18 +173,26 @@
     {      
       GNUNET_HOSTLIST_server_start (cfg, sched, stats);
     }
-  GNUNET_CORE_connect (sched, cfg,
-                      GNUNET_TIME_UNIT_FOREVER_REL,
-                      NULL,
-                      &core_init,
-                      ch, dh,
-                      NULL,
-                      NULL, GNUNET_NO,
-                      NULL, GNUNET_NO,
-                      handlers);
+  core = GNUNET_CORE_connect (sched, cfg,
+                             GNUNET_TIME_UNIT_FOREVER_REL,
+                             NULL,
+                             &core_init,
+                             ch, dh,
+                             NULL,
+                             NULL, GNUNET_NO,
+                             NULL, GNUNET_NO,
+                             handlers);
   GNUNET_SCHEDULER_add_delayed (sched,
                                 GNUNET_TIME_UNIT_FOREVER_REL,
                                 &cleaning_task, NULL);
+  if (NULL == core)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Failed to connect to `%s' service.\n"),
+                 "core");
+      GNUNET_SCHEDULER_shutdown (sched);
+      return;     
+    }
 }
 
 

Modified: gnunet/src/include/gnunet_core_service.h
===================================================================
--- gnunet/src/include/gnunet_core_service.h    2009-11-04 15:13:26 UTC (rev 
9397)
+++ gnunet/src/include/gnunet_core_service.h    2009-11-04 15:43:09 UTC (rev 
9398)
@@ -156,7 +156,7 @@
  * @param timeout after how long should we give up trying to connect to the 
core service?
  * @param cls closure for the various callbacks that follow (including 
handlers in the handlers array)
  * @param init callback to call on timeout or once we have successfully
- *        connected to the core service
+ *        connected to the core service; note that timeout is only meaningful 
if init is not NULL
  * @param connects function to call on peer connect, can be NULL
  * @param disconnects function to call on peer disconnect / timeout, can be 
NULL
  * @param bfc function to call to fill up spare bandwidth, can be NULL
@@ -169,8 +169,10 @@
  *                GNUNET_MessageHeader and hence we do not need to give it the 
full message
  *                can be used to improve efficiency, ignored if 
outbound_notify is NULLL
  * @param handlers callbacks for messages we care about, NULL-terminated
+ * @return handle to the core service (only useful for disconnect until 'init' 
is called),
+ *           NULL on error (in this case, init is never called)
  */
-void
+struct GNUNET_CORE_Handle *
 GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
                      const struct GNUNET_CONFIGURATION_Handle *cfg,
                      struct GNUNET_TIME_Relative timeout,

Modified: gnunet/src/topology/gnunet-daemon-topology.c
===================================================================
--- gnunet/src/topology/gnunet-daemon-topology.c        2009-11-04 15:13:26 UTC 
(rev 9397)
+++ gnunet/src/topology/gnunet-daemon-topology.c        2009-11-04 15:43:09 UTC 
(rev 9398)
@@ -809,6 +809,7 @@
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Failed to connect to core service, can not manage 
topology!\n"));
+      GNUNET_SCHEDULER_shutdown (sched);
       return;
     }
   handle = server;
@@ -1136,8 +1137,11 @@
 
   GNUNET_TRANSPORT_disconnect (transport);
   transport = NULL;
-  GNUNET_CORE_disconnect (handle);
-  handle = NULL;
+  if (handle != NULL)
+    {
+      GNUNET_CORE_disconnect (handle);
+      handle = NULL;
+    }
   while (NULL != (pl = friends))
     {
       friends = pl->next;
@@ -1208,21 +1212,36 @@
                                        NULL,
                                        NULL,
                                        NULL);
-  GNUNET_CORE_connect (sched,
-                      cfg,
-                      GNUNET_TIME_UNIT_FOREVER_REL,
-                      NULL,
-                      &core_init,
-                      &connect_notify,
-                      &disconnect_notify,
-                      &hello_advertising,
-                      NULL, GNUNET_NO,
-                      NULL, GNUNET_NO,
-                      handlers);
-
+  handle = GNUNET_CORE_connect (sched,
+                               cfg,
+                               GNUNET_TIME_UNIT_FOREVER_REL,
+                               NULL,
+                               &core_init,
+                               &connect_notify,
+                               &disconnect_notify,
+                               &hello_advertising,
+                               NULL, GNUNET_NO,
+                               NULL, GNUNET_NO,
+                               handlers);
   GNUNET_SCHEDULER_add_delayed (sched,
                                 GNUNET_TIME_UNIT_FOREVER_REL,
                                 &cleaning_task, NULL);
+  if (NULL == transport)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Failed to connect to `%s' service.\n"),
+                 "transport");
+      GNUNET_SCHEDULER_shutdown (sched);
+      return;
+    }
+  if (NULL == handle)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Failed to connect to `%s' service.\n"),
+                 "core");
+      GNUNET_SCHEDULER_shutdown (sched);
+      return;
+    }
 }
 
 





reply via email to

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