gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated (b4d534a55 -> 21494e968)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated (b4d534a55 -> 21494e968)
Date: Thu, 21 Feb 2019 22:06:34 +0100

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

julius-buenger pushed a change to branch master
in repository gnunet.

    from b4d534a55 RPS service: Adapt to coding guidelines (purely cosmetic)
     new 6a69e4041 RPS service: Use peermap only when non-NULL
     new 2911b37b4 RPS: Use stp(n)cpy instead of strncat in loop
     new 7ab9e38e6 RPS: Use #define instead of hardcoded numbers
     new 21494e968 RPS: Adapt to coding style (cosmetic only)

The 4 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/rps/gnunet-service-rps.c           | 49 +++++++++++++++++++---------------
 src/rps/gnunet-service-rps_custommap.c | 39 ++++++++++++++++++---------
 2 files changed, 54 insertions(+), 34 deletions(-)

diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index a06ed3907..05d5c91c3 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -2928,8 +2928,10 @@ static void
 destroy_sub (struct Sub *sub)
 {
 #ifdef TO_FILE
-  char push_recv_str[1536] = ""; /* 256 * 6 (1 whitespace, 1 comma, up to 4 
chars) */
-  char pull_delays_str[1536] = ""; /* 256 * 6 (1 whitespace, 1 comma, up to 4 
chars) */
+#define SIZE_DUMP_FILE 1536 /* 256 * 6 (1 whitespace, 1 comma, up to 4 chars) 
*/
+  char push_recv_str[SIZE_DUMP_FILE + 1] = "";
+  char pull_delays_str[SIZE_DUMP_FILE + 1] = "";
+  char *recv_str_iter;
 #endif /* TO_FILE */
   GNUNET_assert (NULL != sub);
   GNUNET_assert (NULL != sub->do_round_task);
@@ -2958,29 +2960,31 @@ destroy_sub (struct Sub *sub)
   sub->file_name_observed_log = NULL;
 
   /* Write push frequencies to disk */
+  recv_str_iter = push_recv_str;
   for (uint32_t i = 0; i < 256; i++)
   {
     char push_recv_str_tmp[8];
-    
+
     GNUNET_snprintf (push_recv_str_tmp,
                     sizeof (push_recv_str_tmp),
                     "%" PRIu32 "\n",
                     sub->push_recv[i]);
-    // FIXME: better use stpcpy!
-    (void) strncat (push_recv_str,
-                    push_recv_str_tmp,
-                    1535 - strnlen (push_recv_str, 1536));
-  }
-  (void) strncat (push_recv_str,
-                  "\n",
-                  1535 - strnlen (push_recv_str, 1536));
+    recv_str_iter = stpncpy (recv_str_iter,
+                             push_recv_str_tmp,
+                             6);
+  }
+  (void) stpcpy (recv_str_iter,
+                 "\n");
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Writing push stats to disk\n");
-  to_file_w_len (sub->file_name_push_recv, 1535, push_recv_str);
+  to_file_w_len (sub->file_name_push_recv,
+                 SIZE_DUMP_FILE,
+                 push_recv_str);
   GNUNET_free (sub->file_name_push_recv);
   sub->file_name_push_recv = NULL;
 
   /* Write pull delays to disk */
+  recv_str_iter = pull_delays_str;
   for (uint32_t i = 0; i < 256; i++)
   {
     char pull_delays_str_tmp[8];
@@ -2989,16 +2993,16 @@ destroy_sub (struct Sub *sub)
                     sizeof (pull_delays_str_tmp),
                     "%" PRIu32 "\n",
                     sub->pull_delays[i]);
-    // FIXME: better use stpcpy!
-    (void) strncat (pull_delays_str,
-                    pull_delays_str_tmp,
-                    1535 - strnlen (pull_delays_str, 1536));
-  }
-  (void) strncat (pull_delays_str,
-                  "\n",
-                  1535 - strnlen (pull_delays_str, 1536));
+    recv_str_iter = stpncpy (recv_str_iter,
+                             pull_delays_str_tmp,
+                             6);
+  }
+  (void) stpcpy (recv_str_iter,
+                 "\n");
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing pull delays to disk\n");
-  to_file_w_len (sub->file_name_pull_delays, 1535, pull_delays_str);
+  to_file_w_len (sub->file_name_pull_delays,
+                 SIZE_DUMP_FILE,
+                 pull_delays_str);
   GNUNET_free (sub->file_name_pull_delays);
   sub->file_name_pull_delays = NULL;
 
@@ -3645,7 +3649,8 @@ handle_peer_pull_reply (void *cls,
                               "# pull reply messages received",
                               1,
                               GNUNET_NO);
-    if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop,
+    if (NULL != map_single_hop &&
+        GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop,
           &channel_ctx->peer_ctx->peer_id))
     {
       GNUNET_STATISTICS_update (stats,
diff --git a/src/rps/gnunet-service-rps_custommap.c 
b/src/rps/gnunet-service-rps_custommap.c
index 18a433d6b..d3cc8d104 100644
--- a/src/rps/gnunet-service-rps_custommap.c
+++ b/src/rps/gnunet-service-rps_custommap.c
@@ -82,7 +82,8 @@ CustomPeerMap_create (unsigned int len)
 
   c_peer_map = GNUNET_new (struct CustomPeerMap);
   c_peer_map->hash_map = GNUNET_CONTAINER_multihashmap32_create (len);
-  c_peer_map->peer_map = GNUNET_CONTAINER_multipeermap_create (len, GNUNET_NO);
+  c_peer_map->peer_map = GNUNET_CONTAINER_multipeermap_create (len,
+                                                               GNUNET_NO);
   return c_peer_map;
 }
 
@@ -129,10 +130,16 @@ CustomPeerMap_put (const struct CustomPeerMap *c_peer_map,
     p = GNUNET_new (struct GNUNET_PeerIdentity);
     *p = *peer;
     GNUNET_assert (p != peer);
-    GNUNET_assert (0 == memcmp (p, peer, sizeof(struct GNUNET_PeerIdentity)));
-    GNUNET_CONTAINER_multipeermap_put (c_peer_map->peer_map, p, index,
+    GNUNET_assert (0 == memcmp (p,
+                                peer,
+                                sizeof(struct GNUNET_PeerIdentity)));
+    GNUNET_CONTAINER_multipeermap_put (c_peer_map->peer_map,
+                                       p,
+                                       index,
         GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
-    GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, *index, p,
+    GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map,
+                                         *index,
+                                         p,
         GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
     GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) 
==
                    GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map));
@@ -194,30 +201,38 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap 
*c_peer_map,
   uint32_t *last_index;
   struct GNUNET_PeerIdentity *last_p;
 
-  if (GNUNET_NO == CustomPeerMap_contains_peer (c_peer_map, peer))
+  if (GNUNET_NO == CustomPeerMap_contains_peer (c_peer_map,
+                                                peer))
   {
     return GNUNET_NO;
   }
-  index = CustomPeerMap_get_index_pointer (c_peer_map, peer);
+  index = CustomPeerMap_get_index_pointer (c_peer_map,
+                                           peer);
   GNUNET_assert (*index < CustomPeerMap_size (c_peer_map));
   /* Need to get the pointer stored in the hashmap to free it */
-  p = GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, *index);
+  p = GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map,
+                                           *index);
   GNUNET_assert (NULL != p);
-  GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *index);
+  GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map,
+                                              *index);
   // TODO wrong peerid?
-  GNUNET_CONTAINER_multipeermap_remove_all (c_peer_map->peer_map, peer);
+  GNUNET_CONTAINER_multipeermap_remove_all (c_peer_map->peer_map,
+                                            peer);
   if (*index != CustomPeerMap_size (c_peer_map))
   { /* fill 'gap' with peer at last index */
     last_p =
       GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map,
                                            CustomPeerMap_size (c_peer_map));
     GNUNET_assert (NULL != last_p);
-    last_index = GNUNET_CONTAINER_multipeermap_get (c_peer_map->peer_map, 
last_p);
+    last_index = GNUNET_CONTAINER_multipeermap_get (c_peer_map->peer_map,
+                                                    last_p);
     GNUNET_assert (NULL != last_index);
     GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index);
-    GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, *index, last_p,
+    GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map,
+                                         *index, last_p,
         GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
-    GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, 
*last_index);
+    GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map,
+                                                *last_index);
     *last_index = *index;
   }
   GNUNET_free (index);

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



reply via email to

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