gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37274 - in gnunet/src: ats conversation include set util


From: gnunet
Subject: [GNUnet-SVN] r37274 - in gnunet/src: ats conversation include set util
Date: Sat, 18 Jun 2016 20:49:13 +0200

Author: grothoff
Date: 2016-06-18 20:49:13 +0200 (Sat, 18 Jun 2016)
New Revision: 37274

Modified:
   gnunet/src/ats/ats_api_scheduling.c
   gnunet/src/conversation/conversation_api.c
   gnunet/src/include/gnunet_client_lib.h
   gnunet/src/include/gnunet_mq_lib.h
   gnunet/src/include/gnunet_server_lib.h
   gnunet/src/set/set_api.c
   gnunet/src/util/mq.c
   gnunet/src/util/perf_crypto_asymmetric.c
Log:
partial refactoring, will cause FTBFS, to be completed ASAP

Modified: gnunet/src/ats/ats_api_scheduling.c
===================================================================
--- gnunet/src/ats/ats_api_scheduling.c 2016-06-18 18:16:22 UTC (rev 37273)
+++ gnunet/src/ats/ats_api_scheduling.c 2016-06-18 18:49:13 UTC (rev 37274)
@@ -357,16 +357,14 @@
  * message from the service.
  *
  * @param cls the `struct GNUNET_ATS_SchedulingHandle`
- * @param msg message received, NULL on timeout or fatal error
+ * @param srm message received
  */
 static void
-process_ats_session_release_message (void *cls,
-                                     const struct GNUNET_MessageHeader *msg)
+handle_ats_session_release (void *cls,
+                           const struct GNUNET_ATS_SessionReleaseMessage *srm)
 {
   struct GNUNET_ATS_SchedulingHandle *sh = cls;
-  const struct GNUNET_ATS_SessionReleaseMessage *srm;
 
-  srm = (const struct GNUNET_ATS_SessionReleaseMessage *) msg;
   /* Note: peer field in srm not necessary right now,
      but might be good to have in the future */
   release_session (sh,
@@ -379,18 +377,16 @@
  * message from the service.
  *
  * @param cls the `struct GNUNET_ATS_SchedulingHandle`
- * @param msg message received, NULL on timeout or fatal error
+ * @param m message received
  */
 static void
-process_ats_address_suggestion_message (void *cls,
-                                        const struct GNUNET_MessageHeader *msg)
+handle_ats_address_suggestion (void *cls,
+                              const struct AddressSuggestionMessage *m)
 {
   struct GNUNET_ATS_SchedulingHandle *sh = cls;
-  const struct AddressSuggestionMessage *m;
   struct GNUNET_ATS_AddressRecord *ar;
   uint32_t session_id;
 
-  m = (const struct AddressSuggestionMessage *) msg;
   session_id = ntohl (m->session_id);
   if (0 == session_id)
   {
@@ -528,14 +524,17 @@
 static void
 reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
 {
-  static const struct GNUNET_MQ_MessageHandler handlers[] =
-    { { &process_ats_session_release_message,
-        GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE,
-        sizeof (struct GNUNET_ATS_SessionReleaseMessage) },
-      { &process_ats_address_suggestion_message,
-        GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
-        sizeof (struct AddressSuggestionMessage) },
-      { NULL, 0, 0 } };
+  GNUNET_MQ_hd_fixed_size (ats_session_release,
+                          GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE,
+                          struct GNUNET_ATS_SessionReleaseMessage);
+  GNUNET_MQ_hd_fixed_size (ats_address_suggestion,
+                          GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
+                          struct AddressSuggestionMessage);
+  struct GNUNET_MQ_MessageHandler handlers[] = {
+    make_ats_session_release_handler (sh),
+    make_ats_address_suggestion_handler (sh),
+    GNUNET_MQ_handler_end ()
+  };
   struct GNUNET_MQ_Envelope *ev;
   struct ClientStartMessage *init;
   unsigned int i;

Modified: gnunet/src/conversation/conversation_api.c
===================================================================
--- gnunet/src/conversation/conversation_api.c  2016-06-18 18:16:22 UTC (rev 
37273)
+++ gnunet/src/conversation/conversation_api.c  2016-06-18 18:49:13 UTC (rev 
37274)
@@ -252,17 +252,15 @@
  * We received a `struct ClientPhoneRingMessage`
  *
  * @param cls the `struct GNUNET_CONVERSATION_Phone`
- * @param msg the message
+ * @param ring the message
  */
 static void
 handle_phone_ring (void *cls,
-                   const struct GNUNET_MessageHeader *msg)
+                   const struct ClientPhoneRingMessage *ring)
 {
   struct GNUNET_CONVERSATION_Phone *phone = cls;
-  const struct ClientPhoneRingMessage *ring;
   struct GNUNET_CONVERSATION_Caller *caller;
 
-  ring = (const struct ClientPhoneRingMessage *) msg;
   switch (phone->state)
   {
   case PS_REGISTER:
@@ -294,13 +292,11 @@
  */
 static void
 handle_phone_hangup (void *cls,
-                     const struct GNUNET_MessageHeader *msg)
+                     const struct ClientPhoneHangupMessage *hang)
 {
   struct GNUNET_CONVERSATION_Phone *phone = cls;
-  const struct ClientPhoneHangupMessage *hang;
   struct GNUNET_CONVERSATION_Caller *caller;
 
-  hang = (const struct ClientPhoneHangupMessage *) msg;
   for (caller = phone->caller_head; NULL != caller; caller = caller->next)
     if (hang->cid == caller->cid)
       break;
@@ -351,17 +347,15 @@
  * We received a `struct ClientPhoneSuspendMessage`.
  *
  * @param cls the `struct GNUNET_CONVERSATION_Phone`
- * @param msg the message
+ * @param suspend the message
  */
 static void
 handle_phone_suspend (void *cls,
-                     const struct GNUNET_MessageHeader *msg)
+                     const struct ClientPhoneSuspendMessage *suspend)
 {
   struct GNUNET_CONVERSATION_Phone *phone = cls;
   struct GNUNET_CONVERSATION_Caller *caller;
-  const struct ClientPhoneSuspendMessage *suspend;
 
-  suspend = (const struct ClientPhoneSuspendMessage *) msg;
   for (caller = phone->caller_head; NULL != caller; caller = caller->next)
     if (suspend->cid == caller->cid)
       break;
@@ -396,17 +390,15 @@
  * We received a `struct ClientPhoneResumeMessage`.
  *
  * @param cls the `struct GNUNET_CONVERSATION_Phone`
- * @param msg the message
+ * @param resume the message
  */
 static void
 handle_phone_resume (void *cls,
-                     const struct GNUNET_MessageHeader *msg)
+                    const struct ClientPhoneResumeMessage *resume)
 {
   struct GNUNET_CONVERSATION_Phone *phone = cls;
   struct GNUNET_CONVERSATION_Caller *caller;
-  const struct ClientPhoneResumeMessage *resume;
 
-  resume = (const struct ClientPhoneResumeMessage *) msg;
   for (caller = phone->caller_head; NULL != caller; caller = caller->next)
     if (resume->cid == caller->cid)
       break;
@@ -440,20 +432,34 @@
 
 
 /**
+ * We received a `struct ClientAudioMessage`, check it is well-formed.
+ *
+ * @param cls the `struct GNUNET_CONVERSATION_Phone`
+ * @param am the message
+ * @return #GNUNET_OK if @a am is well-formed
+ */
+static int
+check_phone_audio (void *cls,
+                  const struct ClientAudioMessage *am)
+{
+  /* any variable-size payload is OK */
+  return GNUNET_OK;
+}
+
+
+/**
  * We received a `struct ClientAudioMessage`
  *
  * @param cls the `struct GNUNET_CONVERSATION_Phone`
- * @param msg the message
+ * @param am the message
  */
 static void
-handle_phone_audio_message (void *cls,
-                            const struct GNUNET_MessageHeader *msg)
+handle_phone_audio (void *cls,
+                   const struct ClientAudioMessage *am)
 {
   struct GNUNET_CONVERSATION_Phone *phone = cls;
-  const struct ClientAudioMessage *am;
   struct GNUNET_CONVERSATION_Caller *caller;
 
-  am = (const struct ClientAudioMessage *) msg;
   for (caller = phone->caller_head; NULL != caller; caller = caller->next)
     if (am->cid == caller->cid)
       break;
@@ -466,7 +472,7 @@
     break;
   case CS_ACTIVE:
     caller->speaker->play (caller->speaker->cls,
-                           ntohs (msg->size) - sizeof (struct 
ClientAudioMessage),
+                           ntohs (am->header.size) - sizeof (struct 
ClientAudioMessage),
                            &am[1]);
     break;
   case CS_CALLEE_SUSPENDED:
@@ -531,24 +537,28 @@
 static void
 reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone)
 {
-  static struct GNUNET_MQ_MessageHandler handlers[] =
-  {
-    { &handle_phone_ring,
-      GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING,
-      sizeof (struct ClientPhoneRingMessage) },
-    { &handle_phone_hangup,
-      GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
-      sizeof (struct ClientPhoneHangupMessage) },
-    { &handle_phone_suspend,
-      GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND,
-      sizeof (struct ClientPhoneSuspendMessage) },
-    { &handle_phone_resume,
-      GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME,
-      sizeof (struct ClientPhoneResumeMessage) },
-    { &handle_phone_audio_message,
-      GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
-      0 },
-    { NULL, 0, 0 }
+  GNUNET_MQ_hd_fixed_size (phone_ring,
+                          GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING,
+                          struct ClientPhoneRingMessage);
+  GNUNET_MQ_hd_fixed_size (phone_hangup,
+                          GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
+                          struct ClientPhoneHangupMessage);
+  GNUNET_MQ_hd_fixed_size (phone_suspend,
+                          GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND,
+                          struct ClientPhoneSuspendMessage);
+  GNUNET_MQ_hd_fixed_size (phone_resume,
+                          GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME,
+                          struct ClientPhoneResumeMessage);
+  GNUNET_MQ_hd_var_size (phone_audio,
+                        GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
+                        struct ClientAudioMessage);
+  struct GNUNET_MQ_MessageHandler handlers[] = {
+    make_phone_ring_handler (phone),
+    make_phone_hangup_handler (phone),
+    make_phone_suspend_handler (phone),
+    make_phone_resume_handler (phone),
+    make_phone_audio_handler (phone),
+    GNUNET_MQ_handler_end ()
   };
   struct GNUNET_MQ_Envelope *e;
   struct ClientPhoneRegisterMessage *reg;

Modified: gnunet/src/include/gnunet_client_lib.h
===================================================================
--- gnunet/src/include/gnunet_client_lib.h      2016-06-18 18:16:22 UTC (rev 
37273)
+++ gnunet/src/include/gnunet_client_lib.h      2016-06-18 18:49:13 UTC (rev 
37274)
@@ -43,6 +43,7 @@
 #endif
 #endif
 
+#include "gnunet_mq_lib.h"
 
 /**
  * Opaque handle for a connection to a service.
@@ -49,12 +50,50 @@
  */
 struct GNUNET_CLIENT_Connection;
 
+
 /**
+ * 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
+ */
+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);
+
+
+/**
+ * Create a message queue for a GNUNET_CLIENT_Connection.
+ * If handlers are specfied, receive messages from the connection.
+ *
+ * @param connection the client connection
+ * @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
+ */
+struct GNUNET_MQ_Handle *
+GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection 
*connection,
+                                       const struct GNUNET_MQ_MessageHandler 
*handlers,
+                                       GNUNET_MQ_ErrorHandler error_handler,
+                                       void *error_handler_cls);
+
+
+/**
  * Get a connection with a service.
  *
  * @param service_name name of the service
  * @param cfg configuration to use
  * @return NULL on error (service unknown to configuration)
+ * @deprecated use #GNUNET_CLIENT_connect2
  */
 struct GNUNET_CLIENT_Connection *
 GNUNET_CLIENT_connect (const char *service_name,
@@ -73,6 +112,7 @@
  * which case the message may still be lost).
  *
  * @param client handle to the service connection
+ * @deprecated
  */
 void
 GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *client);
@@ -85,8 +125,9 @@
  * @param cls closure
  * @param msg message received, NULL on timeout or fatal error
  */
-typedef void (*GNUNET_CLIENT_MessageHandler) (void *cls,
-                                              const struct 
GNUNET_MessageHeader *msg);
+typedef void
+(*GNUNET_CLIENT_MessageHandler) (void *cls,
+                                const struct GNUNET_MessageHeader *msg);
 
 
 /**
@@ -96,10 +137,12 @@
  * @param handler function to call with the message
  * @param handler_cls closure for @a handler
  * @param timeout how long to wait until timing out
+ * @deprecated
  */
 void
 GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *client,
-                       GNUNET_CLIENT_MessageHandler handler, void *handler_cls,
+                       GNUNET_CLIENT_MessageHandler handler,
+                      void *handler_cls,
                        struct GNUNET_TIME_Relative timeout);
 
 
@@ -128,6 +171,7 @@
  * @return NULL if someone else is already waiting to be notified
  *         non-NULL if the notify callback was queued (can be used to cancel
  *         using #GNUNET_CONNECTION_notify_transmit_ready_cancel)
+ * @deprecated
  */
 struct GNUNET_CLIENT_TransmitHandle *
 GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *client,
@@ -142,6 +186,7 @@
  * Cancel a request for notification.
  *
  * @param th handle from the original request.
+ * @deprecated
  */
 void
 GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle
@@ -168,6 +213,7 @@
  * @param rn_cls closure for @a rn
  * @return #GNUNET_OK on success, #GNUNET_SYSERR if a request
  *         is already pending
+ * @deprecated
  */
 int
 GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection 
*client,
@@ -191,8 +237,9 @@
  *               #GNUNET_NO if the service is not running
  *               #GNUNET_SYSERR if the configuration is invalid
  */
-typedef void (*GNUNET_CLIENT_TestResultCallback)(void *cls,
-                                                int result);
+typedef void
+(*GNUNET_CLIENT_TestResultCallback)(void *cls,
+                                   int result);
 
 
 /**
@@ -207,6 +254,7 @@
  * @param cb function to call with the result
  * @param cb_cls closure for @a cb
  * @return handle to cancel the test
+ * @deprecated
  */
 struct GNUNET_CLIENT_TestHandle *
 GNUNET_CLIENT_service_test (const char *service,
@@ -219,6 +267,7 @@
  * Abort testing for service.
  *
  * @param th test handle
+ * @deprecated
  */
 void
 GNUNET_CLIENT_service_test_cancel (struct GNUNET_CLIENT_TestHandle *th);

Modified: gnunet/src/include/gnunet_mq_lib.h
===================================================================
--- gnunet/src/include/gnunet_mq_lib.h  2016-06-18 18:16:22 UTC (rev 37273)
+++ gnunet/src/include/gnunet_mq_lib.h  2016-06-18 18:49:13 UTC (rev 37274)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2012-2013 GNUnet e.V.
+     Copyright (C) 2012-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
@@ -20,6 +20,7 @@
 
 /**
  * @author Florian Dold
+ * @author Christian Grothoff
  *
  * @file
  * General-purpose message queue
@@ -117,7 +118,7 @@
 
 
 /**
- * Implementation of the GNUNET_MQ_msg_nested_mh macro.
+ * Implementation of the #GNUNET_MQ_msg_nested_mh macro.
  *
  * @param mhp pointer to the message header pointer that will be changed to 
allocate at
  *        the newly allocated space for the message.
@@ -132,14 +133,7 @@
                           const struct GNUNET_MessageHeader *nested_mh);
 
 
-
 /**
- * End-marker for the handlers array
- */
-#define GNUNET_MQ_HANDLERS_END {NULL, 0, 0}
-
-
-/**
  * Opaque handle to a message queue.
  */
 struct GNUNET_MQ_Handle;
@@ -156,7 +150,9 @@
 enum GNUNET_MQ_Error
 {
   /**
-   * FIXME: document!
+   * Failed to read message from the network.
+   * FIXME: Likely not properly distinguished
+   * from TIMEOUT case in the code!
    */
   GNUNET_MQ_ERROR_READ = 1,
 
@@ -168,7 +164,13 @@
   /**
    * FIXME: document!
    */
-  GNUNET_MQ_ERROR_TIMEOUT = 4
+  GNUNET_MQ_ERROR_TIMEOUT = 4,
+
+  /**
+   * We received a message that was malformed and thus
+   * could not be passed to its handler.
+   */
+  GNUNET_MQ_ERROR_MALFORMED = 8
 };
 
 
@@ -184,6 +186,19 @@
 
 
 /**
+ * Called when a message needs to be validated.
+ *
+ * @param cls closure
+ * @param msg the received message
+ * @return #GNUNET_OK if the message is well-formed,
+ *         #GNUNET_SYSERR if not
+ */
+typedef int
+(*GNUNET_MQ_MessageValidationCallback) (void *cls,
+                                       const struct GNUNET_MessageHeader *msg);
+
+
+/**
  * Signature of functions implementing the
  * sending functionality of a message queue.
  *
@@ -251,28 +266,138 @@
 struct GNUNET_MQ_MessageHandler
 {
   /**
+   * Callback to validate a message of the specified @e type.
+   * The closure given to @e mv will be this struct (not @e ctx).
+   * Using NULL means only size-validation using 
+   * @e expected_size.  In this case, @e expected_size must
+   * be non-zero.
+   */
+  GNUNET_MQ_MessageValidationCallback mv;
+  
+  /**
    * Callback, called every time a new message of
-   * the specified type has been receied.
+   * the specified @e type has been receied.
+   * The closure given to @e mv will be this struct (not @e ctx).
    */
   GNUNET_MQ_MessageCallback cb;
 
   /**
-   * Type of the message this handler covers.
+   * Closure for @e mv and @e cb.
    */
+  void *cls;
+  
+  /**
+   * Type of the message this handler covers, in host byte order.
+   */
   uint16_t type;
 
   /**
-   * Expected size of messages of this type.  Use 0 for
-   * variable-size.  If non-zero, messages of the given
-   * type will be discarded (and the connection closed)
-   * if they do not have the right size.
+   * Expected size of messages of this type.  Minimum size of the
+   * message if @e mv is non-NULL.  Messages of the given type will be
+   * discarded (and the connection closed with an error reported to
+   * the application) if they do not have the right size.
    */
   uint16_t expected_size;
 };
 
 
+/**
+ * End-marker for the handlers array
+ */
+#define GNUNET_MQ_handler_end() {NULL, NULL, NULL, 0, 0}
 
+
 /**
+ * Defines a static function @a name which takes as a single argument
+ * a message handler for fixed-sized messages of type @a code and with
+ * a message type argument of @a str.  Given such an argument, the
+ * function @name will return a `struct GNUNET_MQ_MessageHandler`
+ * for the given message type.
+ *
+ * The macro is to be used as follows:
+ * <code>
+ * struct GNUNET_MessageTest { ... }; // must be fixed size
+ * GNUNET_MQ_hd_fixed_size(test_message, 
+ *                         GNUNET_MESSAGE_TYPE_TEST, 
+ *                         struct GNUNET_MessageTest);
+ * static void
+ * handle_test_message (void *cls, // the struct GNUNET_MQ_MessageHandler
+ *                      const struct GNUNET_MessageTest *msg)
+ * { ... }
+ * 
+ * struct GNUNET_MQ_MessageHandler handlers[] = {
+ *   make_test_message_handler (),
+ *   GNUNET_MQ_handler_end()
+ * };
+ *
+ * @param name unique basename for the functions
+ * @param code message type constant
+ * @param str type of the message (a struct)
+ */
+#define GNUNET_MQ_hd_fixed_size(name,code,str)   \
+  struct GNUNET_MQ_MessageHandler                           \
+  make_##name##_handler (void *cls) {                        \
+    void (*cb)(void *cls, const str *msg) = &handle_##name;  \
+    struct GNUNET_MQ_MessageHandler mh = {                  \
+      NULL, (GNUNET_MQ_MessageCallback) cb,                  \
+      cls, code, sizeof (str) };                             \
+    return mh;                                               \
+  }
+
+
+/**
+ * Defines a static function @a name which takes two arguments and a
+ * context-pointer for validating and handling variable-sized messages
+ * of type @a code and with a message type argument of @a str.  Given
+ * such arguments, the function @name will return a `struct
+ * GNUNET_MQ_MessageHandler` for the given message type.
+ *
+ * The macro is to be used as follows:
+ * <code>
+ * struct GNUNET_MessageTest { ... }; // can be variable size
+ * GNUNET_MQ_hd_var_size(test_message, 
+ *                       GNUNET_MESSAGE_TYPE_TEST, 
+ *                       struct GNUNET_MessageTest);
+ * static int
+ * check_test (void *cls,
+ *             const struct GNUNET_MessageTest *msg)
+ * {
+ *   const char *ctx = cls;
+ *   GNUNET_assert (0 == strcmp ("context", ctx));
+ *   // ...
+ * }
+ * static void
+ * handle_test (void *cls,
+ *              const struct GNUNET_MessageTest *msg)
+ * {
+ *   const char *ctx = cls;
+ *   GNUNET_assert (0 == strcmp ("context", ctx));
+ *   // ...
+ * } 
+ * 
+ * struct GNUNET_MQ_MessageHandler handlers[] = {
+ *   make_test_message_handler ("context"),
+ *   GNUNET_MQ_handler_end()
+ * };
+ *
+ * @param name unique basename for the functions
+ * @param code message type constant
+ * @param str type of the message (a struct)
+ */
+#define GNUNET_MQ_hd_var_size(name,code,str)               \
+  struct GNUNET_MQ_MessageHandler                         \
+  make_##name##_handler (void *ctx) {                     \
+    int (*mv)(void *cls, const str *msg) = &check_##name;  \
+    void (*cb)(void *cls, const str *msg) = &handle_##name;\
+    struct GNUNET_MQ_MessageHandler mh =                   \
+      { (GNUNET_MQ_MessageValidationCallback) mv,          \
+       (GNUNET_MQ_MessageCallback) cb,                    \
+       ctx, code, sizeof (str) };                         \
+    return mh;                                             \
+  }
+
+
+/**
  * Create a new envelope.
  *
  * @param mhp message header to store the allocated message header in, can be 
NULL
@@ -321,17 +446,18 @@
 
 
 /**
- * Associate the assoc_data in mq with a unique request id.
+ * Associate the assoc_data in @a mq with a unique request id.
  *
  * @param mq message queue, id will be unique for the queue
  * @param assoc_data to associate
  */
 uint32_t
-GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data);
+GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
+                    void *assoc_data);
 
 
 /**
- * Get the data associated with a request id in a queue
+ * Get the data associated with a @a request_id in a queue
  *
  * @param mq the message queue with the association
  * @param request_id the request id we are interested in
@@ -343,7 +469,7 @@
 
 
 /**
- * Remove the association for a request id
+ * Remove the association for a @a request_id
  *
  * @param mq the message queue with the association
  * @param request_id the request id we want to remove
@@ -355,33 +481,6 @@
 
 
 /**
- * Create a message queue for a GNUNET_CLIENT_Connection.
- * If handlers are specfied, receive messages from the connection.
- *
- * @param connection the client connection
- * @param handlers handlers for receiving messages
- * @param error_handler error handler
- * @param cls closure for the handlers
- * @return the message queue
- */
-struct GNUNET_MQ_Handle *
-GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection 
*connection,
-                                       const struct GNUNET_MQ_MessageHandler 
*handlers,
-                                       GNUNET_MQ_ErrorHandler error_handler,
-                                       void *cls);
-
-
-/**
- * Create a message queue for a GNUNET_SERVER_Client.
- *
- * @param client the client
- * @return the message queue
- */
-struct GNUNET_MQ_Handle *
-GNUNET_MQ_queue_for_server_client (struct GNUNET_SERVER_Client *client);
-
-
-/**
  * Create a message queue for the specified handlers.
  *
  * @param send function the implements sending messages
@@ -404,24 +503,6 @@
 
 
 /**
- * Replace the handlers of a message queue with new handlers.  Takes
- * effect immediately, even for messages that already have been
- * received, but for with the handler has not been called.
- *
- * If the message queue does not support receiving messages,
- * this function has no effect.
- *
- * @param mq message queue
- * @param new_handlers new handlers
- * @param cls new closure for the handlers
- */
-void
-GNUNET_MQ_replace_handlers (struct GNUNET_MQ_Handle *mq,
-                            const struct GNUNET_MQ_MessageHandler 
*new_handlers,
-                            void *cls);
-
-
-/**
  * Call a callback once the envelope has been sent, that is,
  * sending it can not be canceled anymore.
  * There can be only one notify sent callback per envelope.
@@ -476,10 +557,9 @@
 
 
 /**
- * Call the send implementation for the next queued message,
- * if any.
- * Only useful for implementing message queues,
- * results in undefined behavior if not used carefully.
+ * Call the send implementation for the next queued message, if any.
+ * Only useful for implementing message queues, results in undefined
+ * behavior if not used carefully.
  *
  * @param mq message queue to send the next message with
  */
@@ -488,15 +568,14 @@
 
 
 /**
- * Get the message that should currently be sent.
- * The returned message is only valid until #GNUNET_MQ_impl_send_continue
- * is called.
- * Fails if there is no current message.
- * Only useful for implementing message queues,
- * results in undefined behavior if not used carefully.
+ * Get the message that should currently be sent.  The returned
+ * message is only valid until #GNUNET_MQ_impl_send_continue is
+ * called.  Fails if there is no current message.  Only useful for
+ * implementing message queues, results in undefined behavior if not
+ * used carefully.
  *
  * @param mq message queue with the current message, only valid
- *        until #GNUNET_MQ_impl_send_continue is called
+ *        until #GNUNET_MQ_impl_send_continue() is called
  * @return message to send, never NULL
  */
 const struct GNUNET_MessageHeader *
@@ -511,7 +590,7 @@
  * implementation state, continuations that are scheduled
  * by the implementation function often only have one closure
  * argument, with this function it is possible to get at the
- * implementation state when only passing the GNUNET_MQ_Handle
+ * implementation state when only passing the `struct GNUNET_MQ_Handle`
  * as closure.
  *
  * @param mq message queue with the current message

Modified: gnunet/src/include/gnunet_server_lib.h
===================================================================
--- gnunet/src/include/gnunet_server_lib.h      2016-06-18 18:16:22 UTC (rev 
37273)
+++ gnunet/src/include/gnunet_server_lib.h      2016-06-18 18:49:13 UTC (rev 
37274)
@@ -729,6 +729,16 @@
 
 
 /**
+ * Create a message queue for a server's client.
+ *
+ * @param client the client
+ * @return the message queue
+ */
+struct GNUNET_MQ_Handle *
+GNUNET_MQ_queue_for_server_client (struct GNUNET_SERVER_Client *client);
+
+
+/**
  * Handle to a message stream tokenizer.
  */
 struct GNUNET_SERVER_MessageStreamTokenizer;

Modified: gnunet/src/set/set_api.c
===================================================================
--- gnunet/src/set/set_api.c    2016-06-18 18:16:22 UTC (rev 37273)
+++ gnunet/src/set/set_api.c    2016-06-18 18:49:13 UTC (rev 37274)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2012-2014 GNUnet e.V.
+     Copyright (C) 2012-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
@@ -243,7 +243,7 @@
 static struct GNUNET_SET_Handle *
 create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg,
                  enum GNUNET_SET_OperationType op,
-                 uint32_t *cookie);
+                 const uint32_t *cookie);
 
 
 /**
@@ -251,21 +251,17 @@
  * iterator and sends an acknowledgement to the service.
  *
  * @param cls the `struct GNUNET_SET_Handle *`
- * @param mh the message
+ * @param msg the message
  */
 static void
 handle_copy_lazy (void *cls,
-                  const struct GNUNET_MessageHeader *mh)
+                  const struct GNUNET_SET_CopyLazyResponseMessage *msg)
 {
-  struct GNUNET_SET_CopyLazyResponseMessage *msg;
   struct GNUNET_SET_Handle *set = cls;
   struct SetCopyRequest *req;
   struct GNUNET_SET_Handle *new_set;
 
-  msg = (struct GNUNET_SET_CopyLazyResponseMessage *) mh;
-
   req = set->copy_req_head;
-
   if (NULL == req)
   {
     /* Service sent us unsolicited lazy copy response */
@@ -275,23 +271,36 @@
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Handling response to lazy copy\n");
-
   GNUNET_CONTAINER_DLL_remove (set->copy_req_head,
                                set->copy_req_tail,
                                req);
-
-
   // We pass none as operation here, since it doesn't matter when
   // cloning.
-  new_set = create_internal (set->cfg, GNUNET_SET_OPERATION_NONE, 
&msg->cookie);
-
+  new_set = create_internal (set->cfg,
+                            GNUNET_SET_OPERATION_NONE,
+                            &msg->cookie);
   req->cb (req->cls, new_set);
-
   GNUNET_free (req);
 }
 
 
 /**
+ * Check that the given @a msg is well-formed.
+ *
+ * @param cls closure
+ * @param msg message to check
+ * @return #GNUNET_OK if message is well-formed
+ */
+static int
+check_iter_element (void *cls,
+                   const struct GNUNET_SET_IterResponseMessage *msg)
+{
+  /* 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.
  *
@@ -298,30 +307,18 @@
  * @param cls the `struct GNUNET_SET_Handle *`
  * @param mh the message
  */
-static void
-handle_iter_element (void *cls,
-                     const struct GNUNET_MessageHeader *mh)
+ static void
+ handle_iter_element (void *cls,
+                      const struct GNUNET_SET_IterResponseMessage *msg)
 {
   struct GNUNET_SET_Handle *set = cls;
   GNUNET_SET_ElementIterator iter = set->iterator;
-  struct GNUNET_SET_Element element;
-  const struct GNUNET_SET_IterResponseMessage *msg;
+  struct GNUNET_SET_Element element;  
   struct GNUNET_SET_IterAckMessage *ack_msg;
   struct GNUNET_MQ_Envelope *ev;
   uint16_t msize;
 
-  msize = ntohs (mh->size);
-  if (msize < sizeof (sizeof (struct GNUNET_SET_IterResponseMessage)))
-  {
-    /* message malformed */
-    GNUNET_break (0);
-    set->iterator = NULL;
-    set->iteration_id++;
-    iter (set->iterator_cls,
-          NULL);
-    iter = NULL;
-  }
-  msg = (const struct GNUNET_SET_IterResponseMessage *) mh;
+  msize = ntohs (msg->header.size);
   if (set->iteration_id != ntohs (msg->iteration_id))
   {
     /* element from a previous iteration, skip! */
@@ -366,6 +363,22 @@
 
 
 /**
+ * Check that the given @a msg is well-formed.
+ *
+ * @param cls closure
+ * @param msg message to check
+ * @return #GNUNET_OK if message is well-formed
+ */
+static int
+check_result (void *cls,
+             const struct GNUNET_SET_ResultMessage *msg)
+{
+  /* minimum size was already checked, everything else is OK! */
+  return GNUNET_OK;
+}
+
+
+/**
  * Handle result message for a set operation.
  *
  * @param cls the set
@@ -373,15 +386,13 @@
  */
 static void
 handle_result (void *cls,
-               const struct GNUNET_MessageHeader *mh)
+               const struct GNUNET_SET_ResultMessage *msg)
 {
   struct GNUNET_SET_Handle *set = cls;
-  const struct GNUNET_SET_ResultMessage *msg;
   struct GNUNET_SET_OperationHandle *oh;
   struct GNUNET_SET_Element e;
   enum GNUNET_SET_Status result_status;
 
-  msg = (const struct GNUNET_SET_ResultMessage *) mh;
   GNUNET_assert (NULL != set->mq);
   result_status = ntohs (msg->result_status);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -442,7 +453,7 @@
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Treating result as element\n");
   e.data = &msg[1];
-  e.size = ntohs (mh->size) - sizeof (struct GNUNET_SET_ResultMessage);
+  e.size = ntohs (msg->header.size) - sizeof (struct GNUNET_SET_ResultMessage);
   e.element_type = ntohs (msg->element_type);
   if (NULL != oh->result_cb)
     oh->result_cb (oh->result_cls,
@@ -522,7 +533,8 @@
                          enum GNUNET_MQ_Error error)
 {
   struct GNUNET_SET_Handle *set = cls;
-
+  GNUNET_SET_ElementIterator iter = set->iterator;
+  
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Handling client set error %d\n",
        error);
@@ -534,6 +546,11 @@
                                 GNUNET_SET_STATUS_FAILURE);
     set_operation_destroy (set->ops_head);
   }
+  set->iterator = NULL;
+  set->iteration_id++;
+  if (NULL != iter)
+    iter (set->iterator_cls,
+          NULL);
   set->invalid = GNUNET_YES;
   if (GNUNET_YES == set->destroy_requested)
   {
@@ -547,31 +564,34 @@
 static struct GNUNET_SET_Handle *
 create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg,
                  enum GNUNET_SET_OperationType op,
-                 uint32_t *cookie)
+                 const uint32_t *cookie)
 {
-  static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
-    { &handle_result,
-      GNUNET_MESSAGE_TYPE_SET_RESULT,
-      0 },
-    { &handle_iter_element,
-      GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT,
-      0 },
-    { &handle_iter_done,
-      GNUNET_MESSAGE_TYPE_SET_ITER_DONE,
-      sizeof (struct GNUNET_MessageHeader) },
-    { &handle_copy_lazy,
-      GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE,
-      sizeof (struct GNUNET_SET_CopyLazyResponseMessage) },
-    GNUNET_MQ_HANDLERS_END
+  GNUNET_MQ_hd_var_size (result,
+                        GNUNET_MESSAGE_TYPE_SET_RESULT,
+                        struct GNUNET_SET_ResultMessage);
+  GNUNET_MQ_hd_var_size (iter_element,
+                        GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT,
+                        struct GNUNET_SET_IterResponseMessage);
+  GNUNET_MQ_hd_fixed_size (iter_done,
+                          GNUNET_MESSAGE_TYPE_SET_ITER_DONE,
+                          struct GNUNET_MessageHeader);
+  GNUNET_MQ_hd_fixed_size (copy_lazy,
+                          GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE,
+                          struct GNUNET_SET_CopyLazyResponseMessage);
+  struct GNUNET_SET_Handle *set = GNUNET_new (struct GNUNET_SET_Handle);
+  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
+    make_result_handler (set),
+    make_iter_element_handler (set),
+    make_iter_done_handler (set),
+    make_copy_lazy_handler (set),
+    GNUNET_MQ_handler_end ()
   };
-  struct GNUNET_SET_Handle *set;
   struct GNUNET_MQ_Envelope *mqm;
   struct GNUNET_SET_CreateMessage *create_msg;
   struct GNUNET_SET_CopyLazyConnectMessage *copy_msg;
 
-  set = GNUNET_new (struct GNUNET_SET_Handle);
+  set->cfg = cfg;
   set->client = GNUNET_CLIENT_connect ("set", cfg);
-  set->cfg = cfg;
   if (NULL == set->client)
   {
     GNUNET_free (set);
@@ -796,41 +816,48 @@
 
 
 /**
+ * Check validity of request message for a listen operation
+ *
+ * @param cls the listen handle
+ * @param msg the message
+ * @return #GNUNET_OK if the message is well-formed
+ */
+static int
+check_request (void *cls,
+              const struct GNUNET_SET_RequestMessage *msg)
+{
+  const struct GNUNET_MessageHeader *context_msg;
+
+  context_msg = GNUNET_MQ_extract_nested_mh (msg);
+  if (NULL == context_msg)
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
+}
+
+
+/**
  * Handle request message for a listen operation
  *
  * @param cls the listen handle
- * @param mh the message
+ * @param msg the message
  */
 static void
 handle_request (void *cls,
-                const struct GNUNET_MessageHeader *mh)
+                const struct GNUNET_SET_RequestMessage *msg)
 {
   struct GNUNET_SET_ListenHandle *lh = cls;
-  const struct GNUNET_SET_RequestMessage *msg;
   struct GNUNET_SET_Request req;
   const struct GNUNET_MessageHeader *context_msg;
-  uint16_t msize;
   struct GNUNET_MQ_Envelope *mqm;
   struct GNUNET_SET_RejectMessage *rmsg;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Processing incoming operation request\n");
-  msize = ntohs (mh->size);
-  if (msize < sizeof (struct GNUNET_SET_RequestMessage))
-  {
-    GNUNET_break (0);
-    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,
-                                                       &listen_connect, lh);
-    lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff);
-    return;
-  }
   /* we got another valid request => reset the backoff */
   lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
-  msg = (const struct GNUNET_SET_RequestMessage *) mh;
   req.accept_id = ntohl (msg->accept_id);
   req.accepted = GNUNET_NO;
   context_msg = GNUNET_MQ_extract_nested_mh (msg);
@@ -871,7 +898,8 @@
   GNUNET_MQ_destroy (lh->mq);
   lh->mq = NULL;
   lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff,
-                                                     &listen_connect, lh);
+                                                     &listen_connect,
+                                                    lh);
   lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff);
 }
 
@@ -883,12 +911,15 @@
  */
 static void
 listen_connect (void *cls)
-{
-  static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
-    { &handle_request, GNUNET_MESSAGE_TYPE_SET_REQUEST },
-    GNUNET_MQ_HANDLERS_END
+{ 
+  GNUNET_MQ_hd_var_size (request,
+                        GNUNET_MESSAGE_TYPE_SET_REQUEST,
+                        struct GNUNET_SET_RequestMessage);
+  struct GNUNET_SET_ListenHandle *lh = cls;
+  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
+    make_request_handler (lh),
+    GNUNET_MQ_handler_end ()
   };
-  struct GNUNET_SET_ListenHandle *lh = cls;
   struct GNUNET_MQ_Envelope *mqm;
   struct GNUNET_SET_ListenMessage *msg;
 
@@ -900,7 +931,8 @@
   GNUNET_assert (NULL == lh->mq);
   lh->mq = GNUNET_MQ_queue_for_connection_client (lh->client,
                                                   mq_handlers,
-                                                  
&handle_client_listener_error, lh);
+                                                  
&handle_client_listener_error,
+                                                 lh);
   mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_LISTEN);
   msg->operation = htonl (lh->operation);
   msg->app_id = lh->app_id;
@@ -1133,11 +1165,12 @@
  * Hash a set element.
  *
  * @param element the element that should be hashed
- * @param ret_hash a pointer to where the hash of @a element
+ * @param[out] ret_hash a pointer to where the hash of @a element
  *        should be stored
  */
 void
-GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element, struct 
GNUNET_HashCode *ret_hash)
+GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element,
+                        struct GNUNET_HashCode *ret_hash)
 {
   struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start ();
 

Modified: gnunet/src/util/mq.c
===================================================================
--- gnunet/src/util/mq.c        2016-06-18 18:16:22 UTC (rev 37273)
+++ gnunet/src/util/mq.c        2016-06-18 18:49:13 UTC (rev 37274)
@@ -74,15 +74,9 @@
   /**
    * Handlers array, or NULL if the queue should not receive messages
    */
-  const struct GNUNET_MQ_MessageHandler *handlers;
+  struct GNUNET_MQ_MessageHandler *handlers;
 
   /**
-   * Closure for the handler callbacks,
-   * as well as for the error handler.
-   */
-  void *handlers_cls;
-
-  /**
    * Actual implementation of message sending,
    * called when a message is added
    */
@@ -109,6 +103,11 @@
   GNUNET_MQ_ErrorHandler error_handler;
 
   /**
+   * Closure for the error handler.
+   */
+  void *error_handler_cls;
+
+  /**
    * Linked list of messages pending to be sent
    */
   struct GNUNET_MQ_Envelope *envelope_head;
@@ -133,7 +132,7 @@
   /**
    * Task scheduled during #GNUNET_MQ_impl_send_continue.
    */
-  struct GNUNET_SCHEDULER_Task * continue_task;
+  struct GNUNET_SCHEDULER_Task *continue_task;
 
   /**
    * Next id that should be used for the @e assoc_map,
@@ -206,23 +205,42 @@
 {
   const struct GNUNET_MQ_MessageHandler *handler;
   int handled = GNUNET_NO;
-
+  uint16_t ms = ntohs (mh->size);
+  
   if (NULL == mq->handlers)
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "No handler for message of type %d\n",
-         ntohs (mh->type));
-    return;
-  }
+    goto done;
   for (handler = mq->handlers; NULL != handler->cb; handler++)
   {
     if (handler->type == ntohs (mh->type))
     {
-      handler->cb (mq->handlers_cls, mh);
       handled = GNUNET_YES;
+      if ( (handler->expected_size > ms) ||
+          ( (handler->expected_size != ms) &&
+            (NULL == handler->mv) ) )
+      {
+       /* Too small, or not an exact size and
+          no 'mv' handler to check rest */
+       GNUNET_MQ_inject_error (mq,
+                               GNUNET_MQ_ERROR_MALFORMED);
+       break;
+      }
+      if ( (NULL == handler->mv) ||
+          (GNUNET_OK ==
+           handler->mv (handler->cls, mh)) )
+      {
+       /* message well-formed, pass to handler */
+       handler->cb (handler->cls, mh);
+      }
+      else
+      {
+       /* Message rejected by check routine */
+       GNUNET_MQ_inject_error (mq,
+                               GNUNET_MQ_ERROR_MALFORMED);
+      }
       break;
     }
   }
+ done:
   if (GNUNET_NO == handled)
     LOG (GNUNET_ERROR_TYPE_WARNING,
          "No handler for message of type %d\n",
@@ -251,7 +269,7 @@
                 (int) error);
     return;
   }
-  mq->error_handler (mq->handlers_cls, error);
+  mq->error_handler (mq->error_handler_cls, error);
 }
 
 
@@ -355,7 +373,7 @@
  * @param impl_state for the queue, passed to 'send' and 'destroy'
  * @param handlers array of message handlers
  * @param error_handler handler for read and write errors
- * @param cls closure for message handlers and error handler
+ * @param error_handler_cls closure for @a error_handler
  * @return a new message queue
  */
 struct GNUNET_MQ_Handle *
@@ -365,16 +383,26 @@
                                void *impl_state,
                                const struct GNUNET_MQ_MessageHandler *handlers,
                                GNUNET_MQ_ErrorHandler error_handler,
-                               void *cls)
+                               void *error_handler_cls)
 {
   struct GNUNET_MQ_Handle *mq;
+  unsigned int i;
 
   mq = GNUNET_new (struct GNUNET_MQ_Handle);
   mq->send_impl = send;
   mq->destroy_impl = destroy;
   mq->cancel_impl = cancel;
-  mq->handlers = handlers;
-  mq->handlers_cls = cls;
+  if (NULL != handlers)
+  {
+    for (i=0;NULL != handlers[i].cb; i++) ;
+    mq->handlers = GNUNET_new_array (i,
+                                    struct GNUNET_MQ_MessageHandler);
+    memcpy (mq->handlers,
+           handlers,
+           i * sizeof (struct GNUNET_MQ_MessageHandler));
+  }
+  mq->error_handler = error_handler;
+  mq->error_handler_cls = error_handler_cls;
   mq->impl_state = impl_state;
 
   return mq;
@@ -572,7 +600,6 @@
   struct ClientConnectionState *state;
 
   state = mq->impl_state;
-
   if (NULL == msg)
   {
     GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ);
@@ -617,7 +644,9 @@
        (GNUNET_NO == state->receive_active) )
   {
     state->receive_active = GNUNET_YES;
-    GNUNET_CLIENT_receive (state->connection, handle_client_message, mq,
+    GNUNET_CLIENT_receive (state->connection,
+                          &handle_client_message,
+                          mq,
                            GNUNET_TIME_UNIT_FOREVER_REL);
   }
 
@@ -673,17 +702,24 @@
 GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection 
*connection,
                                        const struct GNUNET_MQ_MessageHandler 
*handlers,
                                        GNUNET_MQ_ErrorHandler error_handler,
-                                       void *cls)
+                                       void *error_handler_cls)
 {
   struct GNUNET_MQ_Handle *mq;
   struct ClientConnectionState *state;
+  unsigned int i;
 
-  GNUNET_assert (NULL != connection);
-
   mq = GNUNET_new (struct GNUNET_MQ_Handle);
-  mq->handlers = handlers;
+  if (NULL != handlers)
+  {
+    for (i=0;NULL != handlers[i].cb; i++) ;
+    mq->handlers = GNUNET_new_array (i,
+                                    struct GNUNET_MQ_MessageHandler);
+    memcpy (mq->handlers,
+           handlers,
+           i * sizeof (struct GNUNET_MQ_MessageHandler));
+  }
   mq->error_handler = error_handler;
-  mq->handlers_cls = cls;
+  mq->error_handler_cls = error_handler_cls;
   state = GNUNET_new (struct ClientConnectionState);
   state->connection = connection;
   mq->impl_state = state;
@@ -697,18 +733,6 @@
 }
 
 
-void
-GNUNET_MQ_replace_handlers (struct GNUNET_MQ_Handle *mq,
-                            const struct GNUNET_MQ_MessageHandler 
*new_handlers,
-                            void *cls)
-{
-  /* FIXME: notify implementation? */
-  /* FIXME: what about NULL handlers? abort receive? */
-  mq->handlers = new_handlers;
-  mq->handlers_cls = cls;
-}
-
-
 /**
  * Associate the assoc_data in mq with a unique request id.
  *
@@ -784,6 +808,7 @@
   while (NULL != mq->envelope_head)
   {
     struct GNUNET_MQ_Envelope *ev;
+
     ev = mq->envelope_head;
     ev->parent_queue = NULL;
     GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
@@ -804,7 +829,7 @@
     GNUNET_CONTAINER_multihashmap32_destroy (mq->assoc_map);
     mq->assoc_map = NULL;
   }
-
+  GNUNET_free_non_null (mq->handlers);
   GNUNET_free (mq);
 }
 

Modified: gnunet/src/util/perf_crypto_asymmetric.c
===================================================================
--- gnunet/src/util/perf_crypto_asymmetric.c    2016-06-18 18:16:22 UTC (rev 
37273)
+++ gnunet/src/util/perf_crypto_asymmetric.c    2016-06-18 18:49:13 UTC (rev 
37274)
@@ -88,7 +88,7 @@
   start = GNUNET_TIME_absolute_get();
   for (i = 0; i < l; i++)
     GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]);
-  log_duration ("EdDSA", "get pubilc");
+  log_duration ("EdDSA", "get public");
 
   start = GNUNET_TIME_absolute_get();
   for (i = 0; i < l; i++)




reply via email to

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