gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37285 - in gnunet/src: ats consensus conversation include


From: gnunet
Subject: [GNUnet-SVN] r37285 - in gnunet/src: ats consensus conversation include peerstore rps secretsharing set util
Date: Sun, 19 Jun 2016 20:50:00 +0200

Author: grothoff
Date: 2016-06-19 20:50:00 +0200 (Sun, 19 Jun 2016)
New Revision: 37285

Modified:
   gnunet/src/ats/ats_api_connectivity.c
   gnunet/src/ats/ats_api_scheduling.c
   gnunet/src/consensus/consensus_api.c
   gnunet/src/conversation/conversation_api.c
   gnunet/src/include/gnunet_client_lib.h
   gnunet/src/peerstore/peerstore_api.c
   gnunet/src/rps/rps_api.c
   gnunet/src/secretsharing/secretsharing_api.c
   gnunet/src/set/set_api.c
   gnunet/src/util/client.c
   gnunet/src/util/mq.c
   gnunet/src/util/test_mq_client.c
Log:
redefine GNUNET_MQ_queue_for_connection_client to capture client handle

Modified: gnunet/src/ats/ats_api_connectivity.c
===================================================================
--- gnunet/src/ats/ats_api_connectivity.c       2016-06-18 21:49:23 UTC (rev 
37284)
+++ gnunet/src/ats/ats_api_connectivity.c       2016-06-19 18:50:00 UTC (rev 
37285)
@@ -72,11 +72,6 @@
   struct GNUNET_CONTAINER_MultiPeerMap *sug_requests;
 
   /**
-   * Connection to ATS service.
-   */
-  struct GNUNET_CLIENT_Connection *client;
-
-  /**
    * Message queue for sending requests to the ATS service.
    */
   struct GNUNET_MQ_Handle *mq;
@@ -130,11 +125,6 @@
     GNUNET_MQ_destroy (ch->mq);
     ch->mq = NULL;
   }
-  if (NULL != ch->client)
-  {
-    GNUNET_CLIENT_disconnect (ch->client);
-    ch->client = NULL;
-  }
   ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
   ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff,
                                            &reconnect_task,
@@ -203,15 +193,16 @@
     { { NULL, 0, 0 } };
   struct GNUNET_MQ_Envelope *ev;
   struct ClientStartMessage *init;
+  struct GNUNET_CLIENT_Connection *client;
 
-  GNUNET_assert (NULL == ch->client);
-  ch->client = GNUNET_CLIENT_connect ("ats", ch->cfg);
-  if (NULL == ch->client)
+  GNUNET_assert (NULL == ch->mq);
+  client = GNUNET_CLIENT_connect ("ats", ch->cfg);
+  if (NULL == client)
   {
     force_reconnect (ch);
     return;
   }
-  ch->mq = GNUNET_MQ_queue_for_connection_client (ch->client,
+  ch->mq = GNUNET_MQ_queue_for_connection_client (client,
                                                   handlers,
                                                   &error_handler,
                                                   ch);
@@ -281,11 +272,6 @@
     GNUNET_MQ_destroy (ch->mq);
     ch->mq = NULL;
   }
-  if (NULL != ch->client)
-  {
-    GNUNET_CLIENT_disconnect (ch->client);
-    ch->client = NULL;
-  }
   if (NULL != ch->task)
   {
     GNUNET_SCHEDULER_cancel (ch->task);

Modified: gnunet/src/ats/ats_api_scheduling.c
===================================================================
--- gnunet/src/ats/ats_api_scheduling.c 2016-06-18 21:49:23 UTC (rev 37284)
+++ gnunet/src/ats/ats_api_scheduling.c 2016-06-19 18:50:00 UTC (rev 37285)
@@ -118,11 +118,6 @@
   void *suggest_cb_cls;
 
   /**
-   * Connection to ATS service.
-   */
-  struct GNUNET_CLIENT_Connection *client;
-
-  /**
    * Message queue for sending requests to the ATS service.
    */
   struct GNUNET_MQ_Handle *mq;
@@ -190,11 +185,6 @@
     GNUNET_MQ_destroy (sh->mq);
     sh->mq = NULL;
   }
-  if (NULL != sh->client)
-  {
-    GNUNET_CLIENT_disconnect (sh->client);
-    sh->client = NULL;
-  }
   sh->suggest_cb (sh->suggest_cb_cls,
                   NULL, NULL, NULL,
                   GNUNET_BANDWIDTH_ZERO,
@@ -539,17 +529,18 @@
   struct ClientStartMessage *init;
   unsigned int i;
   struct GNUNET_ATS_AddressRecord *ar;
+  struct GNUNET_CLIENT_Connection *client;
 
-  GNUNET_assert (NULL == sh->client);
-  sh->client = GNUNET_CLIENT_connect ("ats",
-                                      sh->cfg);
-  if (NULL == sh->client)
+  GNUNET_assert (NULL == sh->mq);
+  client = GNUNET_CLIENT_connect ("ats",
+                                  sh->cfg);
+  if (NULL == client)
   {
     GNUNET_break (0);
     force_reconnect (sh);
     return;
   }
-  sh->mq = GNUNET_MQ_queue_for_connection_client (sh->client,
+  sh->mq = GNUNET_MQ_queue_for_connection_client (client,
                                                   handlers,
                                                   &error_handler,
                                                   sh);
@@ -614,11 +605,6 @@
     GNUNET_MQ_destroy (sh->mq);
     sh->mq = NULL;
   }
-  if (NULL != sh->client)
-  {
-    GNUNET_CLIENT_disconnect (sh->client);
-    sh->client = NULL;
-  }
   if (NULL != sh->task)
   {
     GNUNET_SCHEDULER_cancel (sh->task);

Modified: gnunet/src/consensus/consensus_api.c
===================================================================
--- gnunet/src/consensus/consensus_api.c        2016-06-18 21:49:23 UTC (rev 
37284)
+++ gnunet/src/consensus/consensus_api.c        2016-06-19 18:50:00 UTC (rev 
37285)
@@ -45,17 +45,12 @@
   const struct GNUNET_CONFIGURATION_Handle *cfg;
 
   /**
-   * Client connected to the consensus service, may be NULL if not connected.
-   */
-  struct GNUNET_CLIENT_Connection *client;
-
-  /**
    * Callback for new elements. Not called for elements added locally.
    */
   GNUNET_CONSENSUS_ElementCallback new_element_cb;
 
   /**
-   * Closure for new_element_cb
+   * Closure for @e new_element_cb
    */
   void *new_element_cls;
 
@@ -75,7 +70,7 @@
   GNUNET_CONSENSUS_ConcludeCallback conclude_cb;
 
   /**
-   * Closure for the conclude callback.
+   * Closure for the @e conclude_cb callback.
    */
   void *conclude_cls;
 
@@ -156,8 +151,6 @@
 
   GNUNET_MQ_destroy (consensus->mq);
   consensus->mq = NULL;
-  GNUNET_CLIENT_disconnect (consensus->client);
-  consensus->client = NULL;
   GNUNET_assert (NULL != (cc = consensus->conclude_cb));
   consensus->conclude_cb = NULL;
   cc (consensus->conclude_cls);
@@ -224,17 +217,22 @@
   };
   struct GNUNET_CONSENSUS_JoinMessage *join_msg;
   struct GNUNET_MQ_Envelope *ev;
+  struct GNUNET_CLIENT_Connection *client;
 
   consensus->cfg = cfg;
   consensus->new_element_cb = new_element_cb;
   consensus->new_element_cls = new_element_cls;
   consensus->session_id = *session_id;
-  consensus->client = GNUNET_CLIENT_connect ("consensus", cfg);
-  consensus->mq = GNUNET_MQ_queue_for_connection_client (consensus->client,
-                                                         mq_handlers, 
mq_error_handler, consensus);
-
-  GNUNET_assert (consensus->client != NULL);
-
+  client = GNUNET_CLIENT_connect ("consensus", cfg);
+  if (NULL == client)
+  {
+    GNUNET_free (consensus);
+    return NULL;
+  }
+  consensus->mq = GNUNET_MQ_queue_for_connection_client (client,
+                                                         mq_handlers,
+                                                         &mq_error_handler,
+                                                         consensus);
   ev = GNUNET_MQ_msg_extra (join_msg,
                             (num_peers * sizeof (struct GNUNET_PeerIdentity)),
                             GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN);
@@ -342,10 +340,7 @@
     GNUNET_MQ_destroy (consensus->mq);
     consensus->mq = NULL;
   }
-  if (NULL != consensus->client)
-  {
-    GNUNET_CLIENT_disconnect (consensus->client);
-    consensus->client = NULL;
-  }
   GNUNET_free (consensus);
 }
+
+/* end of consensus_api.c */

Modified: gnunet/src/conversation/conversation_api.c
===================================================================
--- gnunet/src/conversation/conversation_api.c  2016-06-18 21:49:23 UTC (rev 
37284)
+++ gnunet/src/conversation/conversation_api.c  2016-06-19 18:50:00 UTC (rev 
37285)
@@ -161,11 +161,6 @@
   const struct GNUNET_CONFIGURATION_Handle *cfg;
 
   /**
-   * Handle to talk with CONVERSATION service.
-   */
-  struct GNUNET_CLIENT_Connection *client;
-
-  /**
    * We keep all callers in a DLL.
    */
   struct GNUNET_CONVERSATION_Caller *caller_head;
@@ -562,6 +557,7 @@
   };
   struct GNUNET_MQ_Envelope *e;
   struct ClientPhoneRegisterMessage *reg;
+  struct GNUNET_CLIENT_Connection *client;
 
   clean_up_callers (phone);
   if (NULL != phone->mq)
@@ -569,16 +565,12 @@
     GNUNET_MQ_destroy (phone->mq);
     phone->mq = NULL;
   }
-  if (NULL != phone->client)
-  {
-    GNUNET_CLIENT_disconnect (phone->client);
-    phone->client = NULL;
-  }
   phone->state = PS_REGISTER;
-  phone->client = GNUNET_CLIENT_connect ("conversation", phone->cfg);
-  if (NULL == phone->client)
+  client = GNUNET_CLIENT_connect ("conversation",
+                                  phone->cfg);
+  if (NULL == client)
     return;
-  phone->mq = GNUNET_MQ_queue_for_connection_client (phone->client,
+  phone->mq = GNUNET_MQ_queue_for_connection_client (client,
                                                      handlers,
                                                      &phone_error_handler,
                                                      phone);
@@ -644,7 +636,7 @@
   phone->my_record.line = htonl ((uint32_t) line);
   phone->my_record.version = htonl (0);
   reconnect_phone (phone);
-  if ( (NULL == phone->client) ||
+  if ( (NULL == phone->mq) ||
        (NULL == phone->ns) )
   {
     GNUNET_break (0);
@@ -764,11 +756,6 @@
     GNUNET_MQ_destroy (phone->mq);
     phone->mq = NULL;
   }
-  if (NULL != phone->client)
-  {
-    GNUNET_CLIENT_disconnect (phone->client);
-    phone->client = NULL;
-  }
   GNUNET_free (phone);
 }
 

Modified: gnunet/src/include/gnunet_client_lib.h
===================================================================
--- gnunet/src/include/gnunet_client_lib.h      2016-06-18 21:49:23 UTC (rev 
37284)
+++ gnunet/src/include/gnunet_client_lib.h      2016-06-19 18:50:00 UTC (rev 
37285)
@@ -59,14 +59,14 @@
  * @param handlers handlers for receiving messages, can be NULL
  * @param error_handler error handler
  * @param error_handler_cls closure for the @a error_handler
- * @return the message queue
+ * @return the message queue, NULL on error
  */
 struct GNUNET_MQ_Handle *
-GNUNET_CLIENT_connect2 (const char *service_name,
-                       const struct GNUNET_CONFIGURATION_Handle *cfg,
-                       const struct GNUNET_MQ_MessageHandler *handlers,
-                       GNUNET_MQ_ErrorHandler error_handler,
-                       void *error_handler_cls);
+GNUNET_CLIENT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                       const char *service_name,
+                       const struct GNUNET_MQ_MessageHandler *handlers,
+                       GNUNET_MQ_ErrorHandler error_handler,
+                       void *error_handler_cls);
 
 
 /**
@@ -73,12 +73,12 @@
  * Create a message queue for a GNUNET_CLIENT_Connection.
  * If handlers are specfied, receive messages from the connection.
  *
- * @param connection the client connection
+ * @param connection the client connection, taken over and freed by the MQ
  * @param handlers handlers for receiving messages
  * @param error_handler error handler
  * @param error_handler_cls closure for the @a error_handler
  * @return the message queue
- * @deprecated use #GNUNET_CLIENT_connect2
+ * @deprecated use #GNUNET_CLIENT_connecT
  */
 struct GNUNET_MQ_Handle *
 GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection 
*connection,
@@ -189,8 +189,7 @@
  * @deprecated
  */
 void
-GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle
-                                            *th);
+GNUNET_CLIENT_notify_transmit_ready_cancel (struct 
GNUNET_CLIENT_TransmitHandle *th);
 
 
 /**

Modified: gnunet/src/peerstore/peerstore_api.c
===================================================================
--- gnunet/src/peerstore/peerstore_api.c        2016-06-18 21:49:23 UTC (rev 
37284)
+++ gnunet/src/peerstore/peerstore_api.c        2016-06-19 18:50:00 UTC (rev 
37285)
@@ -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
@@ -46,11 +46,6 @@
   const struct GNUNET_CONFIGURATION_Handle *cfg;
 
   /**
-   * Connection to the service.
-   */
-  struct GNUNET_CLIENT_Connection *client;
-
-  /**
    * Message queue
    */
   struct GNUNET_MQ_Handle *mq;
@@ -385,11 +380,6 @@
     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 @@
   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;
 }
 
@@ -819,6 +807,7 @@
   void *icb_cls;
   struct GNUNET_PEERSTORE_StoreContext *sc;
   struct GNUNET_MQ_Envelope *ev;
+  struct GNUNET_CLIENT_Connection *client;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Reconnecting...\n");
@@ -841,15 +830,11 @@
     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,
+  client = GNUNET_CLIENT_connect ("peerstore",
+                                  h->cfg);
+  if (NULL == client)
+    return;
+  h->mq = GNUNET_MQ_queue_for_connection_client (client,
                                                  mq_handlers,
                                                  &handle_client_error, h);
   LOG (GNUNET_ERROR_TYPE_DEBUG,

Modified: gnunet/src/rps/rps_api.c
===================================================================
--- gnunet/src/rps/rps_api.c    2016-06-18 21:49:23 UTC (rev 37284)
+++ gnunet/src/rps/rps_api.c    2016-06-19 18:50:00 UTC (rev 37285)
@@ -40,14 +40,9 @@
   /**
    * The handle to the client configuration.
    */
-  struct GNUNET_CONFIGURATION_Handle *cfg;
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
 
   /**
-   * The connection to the client.
-   */
-  struct GNUNET_CLIENT_Connection *conn;
-
-  /**
    * The message queue to the client.
    */
   struct GNUNET_MQ_Handle *mq;
@@ -214,6 +209,8 @@
 static void
 reconnect (struct GNUNET_RPS_Handle *h)
 {
+  struct GNUNET_CLIENT_Connection *conn;
+
   GNUNET_MQ_hd_var_size (reply,
                          GNUNET_MESSAGE_TYPE_RPS_CS_REPLY,
                          struct GNUNET_RPS_CS_ReplyMessage);
@@ -224,11 +221,10 @@
 
   if (NULL != h->mq)
     GNUNET_MQ_destroy (h->mq);
-  if (NULL != h->conn)
-    GNUNET_CLIENT_disconnect (h->conn);
-  h->conn = GNUNET_CLIENT_connect ("rps", h->cfg);
-  GNUNET_assert (NULL != h->conn);
-  h->mq = GNUNET_MQ_queue_for_connection_client (h->conn,
+  conn = GNUNET_CLIENT_connect ("rps", h->cfg);
+  if (NULL == conn)
+    return;
+  h->mq = GNUNET_MQ_queue_for_connection_client (conn,
                                                  mq_handlers,
                                                  &mq_error_handler,
                                                  h);
@@ -241,15 +237,19 @@
  * @param cfg configuration to use
  * @return a handle to the service
  */
-  struct GNUNET_RPS_Handle *
+struct GNUNET_RPS_Handle *
 GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_RPS_Handle *h;
-  //struct GNUNET_RPS_Request_Handle *rh;
 
-  h = GNUNET_new(struct GNUNET_RPS_Handle);
-  h->cfg = GNUNET_CONFIGURATION_dup (cfg);
+  h = GNUNET_new (struct GNUNET_RPS_Handle);
+  h->cfg = cfg;
   reconnect (h);
+  if (NULL == h->mq)
+  {
+    GNUNET_free (h);
+    return NULL;
+  }
   h->req_handlers = GNUNET_CONTAINER_multihashmap32_create (4);
   return h;
 }
@@ -264,7 +264,7 @@
  * @param cls closure given to the callback
  * @return a handle to cancel this request
  */
-  struct GNUNET_RPS_Request_Handle *
+struct GNUNET_RPS_Request_Handle *
 GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
                           uint32_t num_req_peers,
                           GNUNET_RPS_NotifyReadyCB ready_cb,
@@ -304,7 +304,7 @@
  * @param n number of peers to seed
  * @param ids the ids of the peers seeded
  */
-  void
+void
 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
                      uint32_t n,
                      const struct GNUNET_PeerIdentity *ids)
@@ -375,7 +375,7 @@
  *            if @type is 2 the last id is the id of the
  *            peer to be isolated from the rest
  */
-  void
+void
 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
                           uint32_t type,
                           uint32_t num_peers,
@@ -456,7 +456,7 @@
  *
  * @param rh request handle of request to cancle
  */
-  void
+void
 GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
 {
   struct GNUNET_RPS_Handle *h;
@@ -482,12 +482,9 @@
  *
  * @param h the handle to the rps service
  */
-  void
+void
 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
 {
-  if (NULL != h->conn)
-    GNUNET_CLIENT_disconnect (h->conn);
-  GNUNET_CONFIGURATION_destroy (h->cfg);
   GNUNET_MQ_destroy (h->mq);
   if (0 < GNUNET_CONTAINER_multihashmap32_size (h->req_handlers))
     LOG (GNUNET_ERROR_TYPE_WARNING,

Modified: gnunet/src/secretsharing/secretsharing_api.c
===================================================================
--- gnunet/src/secretsharing/secretsharing_api.c        2016-06-18 21:49:23 UTC 
(rev 37284)
+++ gnunet/src/secretsharing/secretsharing_api.c        2016-06-19 18:50:00 UTC 
(rev 37285)
@@ -38,10 +38,6 @@
  */
 struct GNUNET_SECRETSHARING_Session
 {
-  /**
-   * Client connected to the secretsharing service.
-   */
-  struct GNUNET_CLIENT_Connection *client;
 
   /**
    * Message queue for @e client.
@@ -65,10 +61,6 @@
  */
 struct GNUNET_SECRETSHARING_DecryptionHandle
 {
-  /**
-   * Client connected to the secretsharing service.
-   */
-  struct GNUNET_CLIENT_Connection *client;
 
   /**
    * Message queue for @e client.
@@ -226,8 +218,6 @@
 {
   GNUNET_MQ_destroy (s->mq);
   s->mq = NULL;
-  GNUNET_CLIENT_disconnect (s->client);
-  s->client = NULL;
   GNUNET_free (s);
 }
 
@@ -270,9 +260,10 @@
   };
   struct GNUNET_MQ_Envelope *ev;
   struct GNUNET_SECRETSHARING_CreateMessage *msg;
+  struct GNUNET_CLIENT_Connection *client;
 
-  s->client = GNUNET_CLIENT_connect ("secretsharing", cfg);
-  if (NULL == s->client)
+  client = GNUNET_CLIENT_connect ("secretsharing", cfg);
+  if (NULL == client)
   {
     /* secretsharing not configured correctly */
     GNUNET_break (0);
@@ -281,7 +272,8 @@
   }
   s->secret_ready_cb = cb;
   s->secret_ready_cls = cls;
-  s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers,
+  s->mq = GNUNET_MQ_queue_for_connection_client (client,
+                                                 mq_handlers,
                                                  &handle_session_client_error,
                                                  s);
   GNUNET_assert (NULL != s->mq);
@@ -356,13 +348,16 @@
   struct GNUNET_MQ_Envelope *ev;
   struct GNUNET_SECRETSHARING_DecryptRequestMessage *msg;
   size_t share_size;
+  struct GNUNET_CLIENT_Connection *client;
 
-  s->client = GNUNET_CLIENT_connect ("secretsharing", cfg);
+  client = GNUNET_CLIENT_connect ("secretsharing", cfg);
+  if (NULL == client)
+    return NULL;
   s->decrypt_cb = decrypt_cb;
   s->decrypt_cls = decrypt_cb_cls;
-  GNUNET_assert (NULL != s->client);
 
-  s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers,
+  s->mq = GNUNET_MQ_queue_for_connection_client (client,
+                                                 mq_handlers,
                                                  &handle_decrypt_client_error,
                                                  s);
   GNUNET_assert (NULL != s->mq);
@@ -505,8 +500,6 @@
 {
   GNUNET_MQ_destroy (dh->mq);
   dh->mq = NULL;
-  GNUNET_CLIENT_disconnect (dh->client);
-  dh->client = NULL;
   GNUNET_free (dh);
 }
 

Modified: gnunet/src/set/set_api.c
===================================================================
--- gnunet/src/set/set_api.c    2016-06-18 21:49:23 UTC (rev 37284)
+++ gnunet/src/set/set_api.c    2016-06-19 18:50:00 UTC (rev 37285)
@@ -26,7 +26,6 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_protocols.h"
-#include "gnunet_client_lib.h"
 #include "gnunet_set_service.h"
 #include "set.h"
 
@@ -50,11 +49,6 @@
 struct GNUNET_SET_Handle
 {
   /**
-   * Client connected to the set service.
-   */
-  struct GNUNET_CLIENT_Connection *client;
-
-  /**
    * Message queue for @e client.
    */
   struct GNUNET_MQ_Handle *mq;
@@ -189,10 +183,6 @@
  */
 struct GNUNET_SET_ListenHandle
 {
-  /**
-   * Connection to the service.
-   */
-  struct GNUNET_CLIENT_Connection *client;
 
   /**
    * Message queue for the client.
@@ -298,8 +288,8 @@
   /* minimum size was already checked, everything else is OK! */
   return GNUNET_OK;
 }
- 
 
+
 /**
  * Handle element for iteration over the set.  Notifies the
  * iterator and sends an acknowledgement to the service.
@@ -313,7 +303,7 @@
 {
   struct GNUNET_SET_Handle *set = cls;
   GNUNET_SET_ElementIterator iter = set->iterator;
-  struct GNUNET_SET_Element element;  
+  struct GNUNET_SET_Element element;
   struct GNUNET_SET_IterAckMessage *ack_msg;
   struct GNUNET_MQ_Envelope *ev;
   uint16_t msize;
@@ -534,7 +524,7 @@
 {
   struct GNUNET_SET_Handle *set = cls;
   GNUNET_SET_ElementIterator iter = set->iterator;
-  
+
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Handling client set error %d\n",
        error);
@@ -589,15 +579,16 @@
   struct GNUNET_MQ_Envelope *mqm;
   struct GNUNET_SET_CreateMessage *create_msg;
   struct GNUNET_SET_CopyLazyConnectMessage *copy_msg;
+  struct GNUNET_CLIENT_Connection *client;
 
   set->cfg = cfg;
-  set->client = GNUNET_CLIENT_connect ("set", cfg);
-  if (NULL == set->client)
+  client = GNUNET_CLIENT_connect ("set", cfg);
+  if (NULL == client)
   {
     GNUNET_free (set);
     return NULL;
   }
-  set->mq = GNUNET_MQ_queue_for_connection_client (set->client,
+  set->mq = GNUNET_MQ_queue_for_connection_client (client,
                                                    mq_handlers,
                                                    &handle_client_set_error,
                                                    set);
@@ -750,11 +741,6 @@
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Really destroying set\n");
-  if (NULL != set->client)
-  {
-    GNUNET_CLIENT_disconnect (set->client);
-    set->client = NULL;
-  }
   if (NULL != set->mq)
   {
     GNUNET_MQ_destroy (set->mq);
@@ -893,8 +879,6 @@
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Listener broke down (%d), re-connecting\n",
        (int) error);
-  GNUNET_CLIENT_disconnect (lh->client);
-  lh->client = NULL;
   GNUNET_MQ_destroy (lh->mq);
   lh->mq = NULL;
   lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff,
@@ -911,7 +895,7 @@
  */
 static void
 listen_connect (void *cls)
-{ 
+{
   GNUNET_MQ_hd_var_size (request,
                         GNUNET_MESSAGE_TYPE_SET_REQUEST,
                         struct GNUNET_SET_RequestMessage);
@@ -922,14 +906,14 @@
   };
   struct GNUNET_MQ_Envelope *mqm;
   struct GNUNET_SET_ListenMessage *msg;
+  struct GNUNET_CLIENT_Connection *client;
 
   lh->reconnect_task = NULL;
-  GNUNET_assert (NULL == lh->client);
-  lh->client = GNUNET_CLIENT_connect ("set", lh->cfg);
-  if (NULL == lh->client)
+  GNUNET_assert (NULL == lh->mq);
+  client = GNUNET_CLIENT_connect ("set", lh->cfg);
+  if (NULL == client)
     return;
-  GNUNET_assert (NULL == lh->mq);
-  lh->mq = GNUNET_MQ_queue_for_connection_client (lh->client,
+  lh->mq = GNUNET_MQ_queue_for_connection_client (client,
                                                   mq_handlers,
                                                   
&handle_client_listener_error,
                                                  lh);
@@ -969,7 +953,7 @@
   lh->app_id = *app_id;
   lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
   listen_connect (lh);
-  if (NULL == lh->client)
+  if (NULL == lh->mq)
   {
     GNUNET_free (lh);
     return NULL;
@@ -993,11 +977,6 @@
     GNUNET_MQ_destroy (lh->mq);
     lh->mq = NULL;
   }
-  if (NULL != lh->client)
-  {
-    GNUNET_CLIENT_disconnect (lh->client);
-    lh->client = NULL;
-  }
   if (NULL != lh->reconnect_task)
   {
     GNUNET_SCHEDULER_cancel (lh->reconnect_task);

Modified: gnunet/src/util/client.c
===================================================================
--- gnunet/src/util/client.c    2016-06-18 21:49:23 UTC (rev 37284)
+++ gnunet/src/util/client.c    2016-06-19 18:50:00 UTC (rev 37285)
@@ -404,6 +404,36 @@
 
 
 /**
+ * Create a message queue to connect to a GNUnet service.
+ * If handlers are specfied, receive messages from the connection.
+ *
+ * @param connection the client connection
+ * @param handlers handlers for receiving messages, can be NULL
+ * @param error_handler error handler
+ * @param error_handler_cls closure for the @a error_handler
+ * @return the message queue, NULL on error
+ */
+struct GNUNET_MQ_Handle *
+GNUNET_CLIENT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                       const char *service_name,
+                       const struct GNUNET_MQ_MessageHandler *handlers,
+                       GNUNET_MQ_ErrorHandler error_handler,
+                       void *error_handler_cls)
+{
+  struct GNUNET_CLIENT_Connection *c;
+
+  c = GNUNET_CLIENT_connect (service_name,
+                             cfg);
+  if (NULL == c)
+    return NULL;
+  return GNUNET_MQ_queue_for_connection_client (c,
+                                                handlers,
+                                                error_handler,
+                                                error_handler_cls);
+}
+
+
+/**
  * Get a connection with a service.
  *
  * @param service_name name of the service

Modified: gnunet/src/util/mq.c
===================================================================
--- gnunet/src/util/mq.c        2016-06-18 21:49:23 UTC (rev 37284)
+++ gnunet/src/util/mq.c        2016-06-19 18:50:00 UTC (rev 37285)
@@ -206,7 +206,7 @@
   const struct GNUNET_MQ_MessageHandler *handler;
   int handled = GNUNET_NO;
   uint16_t ms = ntohs (mh->size);
-  
+
   if (NULL == mq->handlers)
     goto done;
   for (handler = mq->handlers; NULL != handler->cb; handler++)
@@ -665,6 +665,9 @@
 connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
                                 void *impl_state)
 {
+  struct ClientConnectionState *state = impl_state;
+
+  GNUNET_CLIENT_disconnect (state->connection);
   GNUNET_free (impl_state);
 }
 
@@ -692,6 +695,7 @@
                                void *impl_state)
 {
   struct ClientConnectionState *state = impl_state;
+
   GNUNET_assert (NULL != state->th);
   GNUNET_CLIENT_notify_transmit_ready_cancel (state->th);
   state->th = NULL;
@@ -723,9 +727,9 @@
   state = GNUNET_new (struct ClientConnectionState);
   state->connection = connection;
   mq->impl_state = state;
-  mq->send_impl = connection_client_send_impl;
-  mq->destroy_impl = connection_client_destroy_impl;
-  mq->cancel_impl = connection_client_cancel_impl;
+  mq->send_impl = &connection_client_send_impl;
+  mq->destroy_impl = &connection_client_destroy_impl;
+  mq->cancel_impl = &connection_client_cancel_impl;
   if (NULL != handlers)
     state->receive_requested = GNUNET_YES;
 

Modified: gnunet/src/util/test_mq_client.c
===================================================================
--- gnunet/src/util/test_mq_client.c    2016-06-18 21:49:23 UTC (rev 37284)
+++ gnunet/src/util/test_mq_client.c    2016-06-19 18:50:00 UTC (rev 37285)
@@ -32,8 +32,6 @@
 
 static struct GNUNET_SERVER_Handle *server;
 
-static struct GNUNET_CLIENT_Connection *client;
-
 static struct GNUNET_CONFIGURATION_Handle *cfg;
 
 static int ok;
@@ -44,13 +42,15 @@
 
 
 static void
-recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
+recv_cb (void *cls,
+         struct GNUNET_SERVER_Client *argclient,
          const struct GNUNET_MessageHeader *message)
 {
   received++;
   if (received == 2)
   {
-    GNUNET_SERVER_receive_done (argclient, GNUNET_NO);
+    GNUNET_SERVER_receive_done (argclient,
+                                GNUNET_NO);
     return;
   }
 
@@ -79,7 +79,8 @@
  * @param client identification of the client
  */
 static void
-notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
+notify_disconnect (void *cls,
+                   struct GNUNET_SERVER_Client *client)
 {
   if (client == NULL)
     return;
@@ -110,11 +111,15 @@
 
 
 static void
-test_mq (struct GNUNET_CLIENT_Connection *client)
+test_mq ()
 {
+  struct GNUNET_CLIENT_Connection *client;
   struct GNUNET_MQ_Handle *mq;
   struct GNUNET_MQ_Envelope *mqm;
 
+  client = GNUNET_CLIENT_connect ("test", cfg);
+  GNUNET_assert (client != NULL);
+
   /* FIXME: test handling responses */
   mq = GNUNET_MQ_queue_for_connection_client (client, NULL, NULL, NULL);
 
@@ -122,14 +127,13 @@
   GNUNET_MQ_send (mq, mqm);
 
   mqm = GNUNET_MQ_msg_header (MY_TYPE);
-  GNUNET_MQ_notify_sent (mqm, send_trap_cb, NULL);
+  GNUNET_MQ_notify_sent (mqm, &send_trap_cb, NULL);
   GNUNET_MQ_send (mq, mqm);
   GNUNET_MQ_send_cancel (mqm);
 
   mqm = GNUNET_MQ_msg_header (MY_TYPE);
-  GNUNET_MQ_notify_sent (mqm, send_cb, NULL);
+  GNUNET_MQ_notify_sent (mqm, &send_cb, NULL);
   GNUNET_MQ_send (mq, mqm);
-
 }
 
 
@@ -163,10 +167,7 @@
   GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost");
   GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
                                          "localhost");
-  client = GNUNET_CLIENT_connect ("test", cfg);
-  GNUNET_assert (client != NULL);
-
-  test_mq (client);
+  test_mq ();
 }
 
 




reply via email to

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