gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated (6b6a96686 -> 94cf985af)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated (6b6a96686 -> 94cf985af)
Date: Mon, 20 Feb 2017 19:22:18 +0100

This is an automated email from the git hooks/post-receive script.

bart-polot pushed a change to branch master
in repository gnunet.

    from 6b6a96686 Update po files
     new ba5817a7d Refactor copying of handler arrays
     new 95737e244 - minor changes: doxygen, log, code order, code legibility
     new 94cf985af - doxygen

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/cadet/cadet_api_new.c       | 12 +-------
 src/cadet/gnunet-cadet.c        | 10 ++-----
 src/cadet/test_cadet_local_mq.c | 36 ++++++++++++------------
 src/core/core_api.c             | 16 ++---------
 src/include/gnunet_mq_lib.h     | 24 ++++++++++++++++
 src/util/mq.c                   | 61 ++++++++++++++++++++++++++++++++++-------
 6 files changed, 100 insertions(+), 59 deletions(-)

diff --git a/src/cadet/cadet_api_new.c b/src/cadet/cadet_api_new.c
index 673764813..7ed681a9d 100644
--- a/src/cadet/cadet_api_new.c
+++ b/src/cadet/cadet_api_new.c
@@ -1635,17 +1635,7 @@ GNUNET_CADET_open_porT (struct GNUNET_CADET_Handle *h,
   p->cls = connects_cls;
   p->window_changes = window_changes;
   p->disconnects = disconnects;
-  if (NULL != handlers)
-  {
-    unsigned int i;
-
-    for (i=0;NULL != handlers[i].cb; i++) ;
-    p->handlers = GNUNET_new_array (i + 1,
-                                    struct GNUNET_MQ_MessageHandler);
-    GNUNET_memcpy ((struct GNUNET_MQ_MessageHandler *) p->handlers,
-                   handlers,
-                   i * sizeof (struct GNUNET_MQ_MessageHandler));
-  }
+  p->handlers = GNUNET_MQ_copy_handlers (handlers);
 
   GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONTAINER_multihashmap_put (h->ports,
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index a08c178f4..c194a5bc1 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -381,14 +381,10 @@ request_dump (void *cls)
 
 
 /**
- * Function called whenever a message is received.
+ * Check data message sanity. Does nothing so far (all messages are OK).
  *
- * Each time the function must call #GNUNET_CADET_receive_done on the channel
- * in order to receive the next message. This doesn't need to be immediate:
- * can be delayed if some processing is done on the message.
- *
- * @param cls should match #ch
- * @param message The actual message.
+ * @param cls Closure (unused).
+ * @param message The message to check.
  * @return #GNUNET_OK to keep the channel open,
  *         #GNUNET_SYSERR to close it (signal serious error).
  */
diff --git a/src/cadet/test_cadet_local_mq.c b/src/cadet/test_cadet_local_mq.c
index d3917b94a..785a8844f 100644
--- a/src/cadet/test_cadet_local_mq.c
+++ b/src/cadet/test_cadet_local_mq.c
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2011 GNUnet e.V.
+     Copyright (C) 2017 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
@@ -189,7 +189,7 @@ handle_data_received (void *cls,
 
   payload = GNUNET_ntohll (msg->payload);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Data callback payload %llu with cls: %p! Shutting down.\n",
+              "Data callback payload %llu with cls: %p! Shutting down.\n",
               (unsigned long long) payload,
               cls);
   GNUNET_assert (42 == payload);
@@ -266,15 +266,22 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  struct GNUNET_TIME_Relative start_delay;
+  struct GNUNET_MQ_MessageHandler handlers[] = {
+    GNUNET_MQ_hd_fixed_size (data_received,
+                             TEST_MESSAGE_TYPE,
+                             struct GNUNET_CADET_TestMsg,
+                             cadet_peer_2),
+    GNUNET_MQ_handler_end ()
+  };
+  struct GNUNET_TIME_Relative delay;
+
   me = peer;
   GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
                                  NULL);
-  abort_task =
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                    (GNUNET_TIME_UNIT_SECONDS, 15),
-                                   &do_abort,
-                                    (void *) (long) __LINE__);
+  delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15);
+  abort_task = GNUNET_SCHEDULER_add_delayed (delay,
+                                             &do_abort,
+                                             (void *) (long) __LINE__);
   cadet_peer_1 = GNUNET_CADET_connecT (cfg);
   cadet_peer_2 = GNUNET_CADET_connecT (cfg);
 
@@ -282,20 +289,13 @@ run (void *cls,
        (NULL == cadet_peer_2) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-               "Couldn't connect to cadet\n");
+                "Couldn't connect to cadet\n");
     result = GNUNET_SYSERR;
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CADET 1: %p\n", cadet_peer_1);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CADET 2: %p\n", cadet_peer_2);
-  struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_hd_fixed_size (data_received,
-                             TEST_MESSAGE_TYPE,
-                             struct GNUNET_CADET_TestMsg,
-                             cadet_peer_2),
-    GNUNET_MQ_handler_end ()
-  };
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handlers 2: %p\n", handlers);
   GNUNET_CADET_open_porT (cadet_peer_2,          /* cadet handle */
                           GC_u2h (TEST_PORT_ID), /* port id */
@@ -304,9 +304,9 @@ run (void *cls,
                           NULL,                  /* window size handler */
                           &disconnected,         /* disconnect handler */
                           handlers);             /* traffic handlers */
-  start_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2);
+  delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2);
   if (NULL == connect_task)
-    connect_task = GNUNET_SCHEDULER_add_delayed (start_delay,
+    connect_task = GNUNET_SCHEDULER_add_delayed (delay,
                                                  &do_connect,
                                                  NULL);
 }
diff --git a/src/core/core_api.c b/src/core/core_api.c
index afae20850..c1cfdb62f 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -784,7 +784,6 @@ GNUNET_CORE_connect (const struct 
GNUNET_CONFIGURATION_Handle *cfg,
                      const struct GNUNET_MQ_MessageHandler *handlers)
 {
   struct GNUNET_CORE_Handle *h;
-  unsigned int hcnt;
 
   h = GNUNET_new (struct GNUNET_CORE_Handle);
   h->cfg = cfg;
@@ -794,18 +793,9 @@ GNUNET_CORE_connect (const struct 
GNUNET_CONFIGURATION_Handle *cfg,
   h->disconnects = disconnects;
   h->peers = GNUNET_CONTAINER_multipeermap_create (128,
                                                   GNUNET_NO);
-  hcnt = 0;
-  if (NULL != handlers)
-    while (NULL != handlers[hcnt].cb)
-      hcnt++;
-  h->handlers = GNUNET_new_array (hcnt + 1,
-                                  struct GNUNET_MQ_MessageHandler);
-  if (NULL != handlers)
-    GNUNET_memcpy (h->handlers,
-                  handlers,
-                  hcnt * sizeof (struct GNUNET_MQ_MessageHandler));
-  h->hcnt = hcnt;
-  GNUNET_assert (hcnt <
+  h->handlers = GNUNET_MQ_copy_handlers (handlers);
+  h->hcnt = GNUNET_MQ_count_handlers (handlers);
+  GNUNET_assert (h->hcnt <
                  (GNUNET_SERVER_MAX_MESSAGE_SIZE -
                   sizeof (struct InitMessage)) / sizeof (uint16_t));
   LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index b527b58e8..a50a59c49 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -305,6 +305,30 @@ GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head,
 
 
 /**
+ * Copy an array of handlers.
+ *
+ * Useful if the array has been delared in local memory and needs to be
+ * persisted for future use.
+ *
+ * @param handlers Array of handlers to be copied.
+ * @return A newly allocated array of handlers.
+ *         Needs to be freed with #GNUNET_free.
+ */
+struct GNUNET_MQ_MessageHandler *
+GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers);
+
+
+/**
+ * Count the handlers in a handler array.
+ *
+ * @param handlers Array of handlers to be counted.
+ * @return The number of handlers in the array.
+ */
+unsigned int
+GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers);
+
+
+/**
  * Message handler for a specific message type.
  */
 struct GNUNET_MQ_MessageHandler
diff --git a/src/util/mq.c b/src/util/mq.c
index 43926ed64..fe47f6ab4 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -515,21 +515,12 @@ GNUNET_MQ_queue_for_callbacks (GNUNET_MQ_SendImpl send,
                                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;
-  if (NULL != handlers)
-  {
-    for (i=0;NULL != handlers[i].cb; i++) ;
-    mq->handlers = GNUNET_new_array (i + 1,
-                                    struct GNUNET_MQ_MessageHandler);
-    GNUNET_memcpy (mq->handlers,
-           handlers,
-           i * sizeof (struct GNUNET_MQ_MessageHandler));
-  }
+  mq->handlers = GNUNET_MQ_copy_handlers (handlers);
   mq->error_handler = error_handler;
   mq->error_handler_cls = error_handler_cls;
   mq->impl_state = impl_state;
@@ -1184,4 +1175,54 @@ GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope 
**env_head,
 }
 
 
+/**
+ * Copy an array of handlers.
+ *
+ * Useful if the array has been delared in local memory and needs to be
+ * persisted for future use.
+ *
+ * @param handlers Array of handlers to be copied. Can be NULL (nothing done).
+ * @return A newly allocated array of handlers.
+ *         Needs to be freed with #GNUNET_free.
+ */
+struct GNUNET_MQ_MessageHandler *
+GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
+{
+  struct GNUNET_MQ_MessageHandler *copy;
+  unsigned int count;
+
+  if (NULL == handlers)
+    return NULL;
+
+  count = GNUNET_MQ_count_handlers (handlers);
+  copy = GNUNET_new_array (count + 1,
+                           struct GNUNET_MQ_MessageHandler);
+  GNUNET_memcpy (copy,
+                 handlers,
+                 count * sizeof (struct GNUNET_MQ_MessageHandler));
+  return copy;
+}
+
+
+/**
+ * Count the handlers in a handler array.
+ *
+ * @param handlers Array of handlers to be counted.
+ * @return The number of handlers in the array.
+ */
+unsigned int
+GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
+{
+  unsigned int i;
+
+  if (NULL == handlers)
+    return 0;
+
+  for (i=0; NULL != handlers[i].cb; i++) ;
+
+  return i;
+}
+
+
+
 /* end of mq.c */

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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