allow empty/NULL context message
[oweals/gnunet.git] / src / peerstore / peerstore_api.c
index b1f4695ec0614e0c12cc8c55e0baad5e2b870117..a288e74d2df162c279929a67aa5807294b4d1194 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2013-2014 GNUnet e.V.
+     Copyright (C) 2013-2016 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -45,11 +45,6 @@ struct GNUNET_PEERSTORE_Handle
    */
   const struct GNUNET_CONFIGURATION_Handle *cfg;
 
-  /**
-   * Connection to the service.
-   */
-  struct GNUNET_CLIENT_Connection *client;
-
   /**
    * Message queue
    */
@@ -385,11 +380,6 @@ do_disconnect (struct GNUNET_PEERSTORE_Handle *h)
     GNUNET_MQ_destroy (h->mq);
     h->mq = NULL;
   }
-  if (NULL != h->client)
-  {
-    GNUNET_CLIENT_disconnect (h->client);
-    h->client = NULL;
-  }
   GNUNET_free (h);
 }
 
@@ -406,16 +396,14 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
   struct GNUNET_PEERSTORE_Handle *h;
 
   h = GNUNET_new (struct GNUNET_PEERSTORE_Handle);
-
-  h->client = GNUNET_CLIENT_connect ("peerstore", cfg);
-  if (NULL == h->client)
+  h->cfg = cfg;
+  h->disconnecting = GNUNET_NO;
+  reconnect (h);
+  if (NULL == h->mq)
   {
     GNUNET_free (h);
     return NULL;
   }
-  h->cfg = cfg;
-  h->disconnecting = GNUNET_NO;
-  reconnect (h);
   return h;
 }
 
@@ -841,17 +829,13 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h)
     GNUNET_MQ_destroy (h->mq);
     h->mq = NULL;
   }
-  if (NULL != h->client)
-  {
-    GNUNET_CLIENT_disconnect (h->client);
-    h->client = NULL;
-  }
-  h->client = GNUNET_CLIENT_connect ("peerstore",
-                                     h->cfg);
-  GNUNET_assert (NULL != h->client);
-  h->mq = GNUNET_MQ_queue_for_connection_client (h->client,
-                                                 mq_handlers,
-                                                 &handle_client_error, h);
+  h->mq = GNUNET_CLIENT_connecT (h->cfg,
+                                 "peerstore",
+                                 mq_handlers,
+                                 &handle_client_error,
+                                 h);
+  if (NULL == h->mq)
+    return;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Resending pending requests after reconnect.\n");
   if (NULL != h->watches)