gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 02/11: HELLO: Modify API to avoid unnecessary copies


From: gnunet
Subject: [gnunet] 02/11: HELLO: Modify API to avoid unnecessary copies
Date: Tue, 07 Nov 2023 19:06:36 +0100

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

t3sserakt pushed a commit to branch master
in repository gnunet.

commit 535a0f8d52a78cc3940540f15533146db2ddde0a
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Sat Nov 4 06:43:26 2023 +0100

    HELLO: Modify API to avoid unnecessary copies
---
 src/include/gnunet_hello_uri_lib.h               |  6 ++---
 src/lib/hello/hello-uri.c                        |  8 +++---
 src/lib/hello/test_hello-uri.c                   | 34 +++++++++++-------------
 src/plugin/dht/plugin_block_dht.c                | 33 +++++++++++------------
 src/service/dht/gnunet-service-dht_clients.c     |  7 ++---
 src/service/dht/gnunet-service-dht_neighbours.c  | 14 +++++-----
 src/service/dht/gnunet-service-dht_neighbours.h  |  4 ++-
 src/service/dhtu/plugin_dhtu_gnunet.c            |  3 +--
 src/service/transport/gnunet-service-transport.c | 26 +++++++++---------
 9 files changed, 63 insertions(+), 72 deletions(-)

diff --git a/src/include/gnunet_hello_uri_lib.h 
b/src/include/gnunet_hello_uri_lib.h
index 7ebf75a9e..aecda0885 100644
--- a/src/include/gnunet_hello_uri_lib.h
+++ b/src/include/gnunet_hello_uri_lib.h
@@ -220,6 +220,7 @@ GNUNET_HELLO_builder_del_address (struct 
GNUNET_HELLO_Builder *builder,
  */
 typedef void
 (*GNUNET_HELLO_UriCallback) (void *cls,
+                             const struct GNUNET_PeerIdentity* pid,
                              const char *uri);
 
 
@@ -227,13 +228,12 @@ typedef void
  * Iterate over URIs in a builder.
  *
  * @param builder builder to iterate over
- * @param[out] pid set to the peer the @a builder is for
  * @param uc callback invoked for each URI, can be NULL
  * @param uc_cls closure for @a addrgen
+ * @return pid of the peer the @a builder is for, can be NULL
  */
-void
+const struct GNUNET_PeerIdentity *
 GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder,
-                              struct GNUNET_PeerIdentity *pid,
                               GNUNET_HELLO_UriCallback uc,
                               void *uc_cls);
 
diff --git a/src/lib/hello/hello-uri.c b/src/lib/hello/hello-uri.c
index 4d0cb4ee0..2e99d701a 100644
--- a/src/lib/hello/hello-uri.c
+++ b/src/lib/hello/hello-uri.c
@@ -905,25 +905,25 @@ GNUNET_HELLO_builder_del_address (struct 
GNUNET_HELLO_Builder *builder,
 }
 
 
-void
+const struct GNUNET_PeerIdentity*
 GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder,
-                              struct GNUNET_PeerIdentity *pid,
                               GNUNET_HELLO_UriCallback uc,
                               void *uc_cls)
 {
   struct Address *nxt;
 
-  *pid = builder->pid;
   if (NULL == uc)
-    return;
+    return &builder->pid;
   for (struct Address *a = builder->a_head;
        NULL != a;
        a = nxt)
   {
     nxt = a->next;
     uc (uc_cls,
+        &builder->pid,
         a->uri);
   }
+  return &builder->pid;
 }
 
 
diff --git a/src/lib/hello/test_hello-uri.c b/src/lib/hello/test_hello-uri.c
index bebed671b..d1f40246a 100644
--- a/src/lib/hello/test_hello-uri.c
+++ b/src/lib/hello/test_hello-uri.c
@@ -37,6 +37,7 @@
  */
 static void
 check_uris (void *cls,
+            const struct GNUNET_PeerIdentity *pid,
             const char *uri)
 {
   unsigned int *found = cls;
@@ -89,7 +90,7 @@ main (int argc,
     void *block;
     size_t block_size = 0;
     struct GNUNET_HELLO_Builder *b2;
-    struct GNUNET_PeerIdentity p2;
+    const struct GNUNET_PeerIdentity *p2;
     unsigned int found;
 
     GNUNET_assert (GNUNET_NO ==
@@ -117,13 +118,12 @@ main (int argc,
     GNUNET_free (block);
     GNUNET_assert (NULL != b2);
     found = 0;
-    GNUNET_HELLO_builder_iterate (b2,
-                                  &p2,
-                                  &check_uris,
-                                  &found);
+    p2 = GNUNET_HELLO_builder_iterate (b2,
+                                       &check_uris,
+                                       &found);
     GNUNET_assert (3 == found);
     GNUNET_assert (0 ==
-                   GNUNET_memcmp (&p2,
+                   GNUNET_memcmp (p2,
                                   &pid));
     GNUNET_HELLO_builder_free (b2);
   }
@@ -131,7 +131,7 @@ main (int argc,
   {
     char *url;
     struct GNUNET_HELLO_Builder *b2;
-    struct GNUNET_PeerIdentity p2;
+    const struct GNUNET_PeerIdentity *p2;
     unsigned int found;
 
     url = GNUNET_HELLO_builder_to_url (b,
@@ -140,13 +140,12 @@ main (int argc,
     GNUNET_free (url);
     GNUNET_assert (NULL != b2);
     found = 0;
-    GNUNET_HELLO_builder_iterate (b2,
-                                  &p2,
-                                  &check_uris,
-                                  &found);
+    p2 = GNUNET_HELLO_builder_iterate (b2,
+                                       &check_uris,
+                                       &found);
     GNUNET_assert (3 == found);
     GNUNET_assert (0 ==
-                   GNUNET_memcmp (&p2,
+                   GNUNET_memcmp (p2,
                                   &pid));
     GNUNET_HELLO_builder_free (b2);
   }
@@ -154,7 +153,7 @@ main (int argc,
   {
     struct GNUNET_MQ_Envelope *env;
     struct GNUNET_HELLO_Builder *b2;
-    struct GNUNET_PeerIdentity p2;
+    const struct GNUNET_PeerIdentity *p2;
     unsigned int found;
 
     env = GNUNET_HELLO_builder_to_env (b,
@@ -164,13 +163,12 @@ main (int argc,
     GNUNET_free (env);
     GNUNET_assert (NULL != b2);
     found = 0;
-    GNUNET_HELLO_builder_iterate (b2,
-                                  &p2,
-                                  &check_uris,
-                                  &found);
+    p2 = GNUNET_HELLO_builder_iterate (b2,
+                                       &check_uris,
+                                       &found);
     GNUNET_assert (3 == found);
     GNUNET_assert (0 ==
-                   GNUNET_memcmp (&p2,
+                   GNUNET_memcmp (p2,
                                   &pid));
     GNUNET_HELLO_builder_free (b2);
   }
diff --git a/src/plugin/dht/plugin_block_dht.c 
b/src/plugin/dht/plugin_block_dht.c
index aa5ffc719..ede23ea57 100644
--- a/src/plugin/dht/plugin_block_dht.c
+++ b/src/plugin/dht/plugin_block_dht.c
@@ -138,7 +138,7 @@ block_plugin_dht_check_block (void *cls,
   case GNUNET_BLOCK_TYPE_DHT_HELLO:
     {
       struct GNUNET_HELLO_Builder *b;
-      struct GNUNET_PeerIdentity pid;
+      const struct GNUNET_PeerIdentity *pid;
       struct GNUNET_HashCode h_pid;
 
       b = GNUNET_HELLO_builder_from_block (block,
@@ -148,11 +148,10 @@ block_plugin_dht_check_block (void *cls,
         GNUNET_break (0);
         return GNUNET_NO;
       }
-      GNUNET_HELLO_builder_iterate (b,
-                                    &pid,
-                                    NULL, NULL);
-      GNUNET_CRYPTO_hash (&pid,
-                          sizeof (pid),
+      pid = GNUNET_HELLO_builder_iterate (b,
+                                          NULL, NULL);
+      GNUNET_CRYPTO_hash (pid,
+                          sizeof (*pid),
                           &h_pid);
       GNUNET_HELLO_builder_free (b);
       return GNUNET_OK;
@@ -196,17 +195,16 @@ block_plugin_dht_check_reply (
   case GNUNET_BLOCK_TYPE_DHT_HELLO:
     {
       struct GNUNET_HELLO_Builder *b;
-      struct GNUNET_PeerIdentity pid;
+      const struct GNUNET_PeerIdentity *pid;
       struct GNUNET_HashCode h_pid;
 
       b = GNUNET_HELLO_builder_from_block (reply_block,
                                            reply_block_size);
       GNUNET_assert (NULL != b);
-      GNUNET_HELLO_builder_iterate (b,
-                                    &pid,
-                                    NULL, NULL);
-      GNUNET_CRYPTO_hash (&pid,
-                          sizeof (pid),
+      pid = GNUNET_HELLO_builder_iterate (b,
+                                          NULL, NULL);
+      GNUNET_CRYPTO_hash (pid,
+                          sizeof (*pid),
                           &h_pid);
       GNUNET_HELLO_builder_free (b);
       if (GNUNET_YES ==
@@ -244,7 +242,7 @@ block_plugin_dht_get_key (void *cls,
   case GNUNET_BLOCK_TYPE_DHT_HELLO:
     {
       struct GNUNET_HELLO_Builder *b;
-      struct GNUNET_PeerIdentity pid;
+      const struct GNUNET_PeerIdentity *pid;
 
       b = GNUNET_HELLO_builder_from_block (block,
                                            block_size);
@@ -256,11 +254,10 @@ block_plugin_dht_get_key (void *cls,
                 sizeof (*key));
         return GNUNET_OK;
       }
-      GNUNET_HELLO_builder_iterate (b,
-                                    &pid,
-                                    NULL, NULL);
-      GNUNET_CRYPTO_hash (&pid,
-                          sizeof (pid),
+      pid = GNUNET_HELLO_builder_iterate (b,
+                                          NULL, NULL);
+      GNUNET_CRYPTO_hash (pid,
+                          sizeof (*pid),
                           key);
       GNUNET_HELLO_builder_free (b);
       return GNUNET_OK;
diff --git a/src/service/dht/gnunet-service-dht_clients.c 
b/src/service/dht/gnunet-service-dht_clients.c
index f2027888c..c666265fe 100644
--- a/src/service/dht/gnunet-service-dht_clients.c
+++ b/src/service/dht/gnunet-service-dht_clients.c
@@ -27,6 +27,7 @@
 #include "platform.h"
 #include "gnunet_constants.h"
 #include "gnunet_protocols.h"
+#include "gnunet_hello_uri_lib.h"
 #include "gnunet_statistics_service.h"
 #include "gnunet-service-dht.h"
 #include "gnunet-service-dht_datacache.h"
@@ -1203,7 +1204,6 @@ handle_dht_local_hello_offer (void *cls,
   struct ClientHandle *ch = cls;
   const char *url = (const char *) &msg[1];
   struct GNUNET_HELLO_Builder *b;
-  struct GNUNET_PeerIdentity *pid;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Local client provided HELLO URL %s\n",
@@ -1216,12 +1216,9 @@ handle_dht_local_hello_offer (void *cls,
     return;
   }
   GNUNET_SERVICE_client_continue (ch->client);
-  pid = GNUNET_new (struct GNUNET_PeerIdentity);
   GNUNET_HELLO_builder_iterate (b,
-                                pid,
                                 &GDS_try_connect,
-                                pid);
-  GNUNET_free (pid);
+                                NULL);
   GNUNET_HELLO_builder_free (b);
 }
 
diff --git a/src/service/dht/gnunet-service-dht_neighbours.c 
b/src/service/dht/gnunet-service-dht_neighbours.c
index dbbdf13eb..836b57a23 100644
--- a/src/service/dht/gnunet-service-dht_neighbours.c
+++ b/src/service/dht/gnunet-service-dht_neighbours.c
@@ -76,7 +76,7 @@
  * requests when we are 'perfectly' connected.
  */
 #define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply ( \
-    GNUNET_TIME_UNIT_MINUTES, 2)
+          GNUNET_TIME_UNIT_MINUTES, 2)
 
 
 /**
@@ -89,7 +89,7 @@
  * is half of the number given here.
  */
 #define DHT_AVG_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply (    \
-    GNUNET_TIME_UNIT_SECONDS, 6)
+          GNUNET_TIME_UNIT_SECONDS, 6)
 
 /**
  * How long at most to wait for transmission of a GET request to another peer?
@@ -1300,7 +1300,7 @@ get_target_peers (const struct GNUNET_HashCode *key,
 static void
 hello_check (const struct GNUNET_DATACACHE_Block *bd)
 {
-  struct GNUNET_PeerIdentity *pid;
+  const struct GNUNET_PeerIdentity *pid;
   struct GNUNET_HELLO_Builder *b;
 
   if (GNUNET_BLOCK_TYPE_DHT_HELLO != bd->type)
@@ -1310,12 +1310,9 @@ hello_check (const struct GNUNET_DATACACHE_Block *bd)
                                        bd->data_size);
   if (GNUNET_YES != disable_try_connect)
   {
-    pid = GNUNET_new (struct GNUNET_PeerIdentity);
     GNUNET_HELLO_builder_iterate (b,
-                                  pid,
                                   &GDS_try_connect,
-                                  pid);
-    GNUNET_free (pid);
+                                  NULL);
   }
   GNUNET_HELLO_builder_free (b);
 }
@@ -2888,9 +2885,10 @@ GDS_u_receive (void *cls,
  */
 void
 GDS_try_connect (void *cls,
+                 const struct GNUNET_PeerIdentity *pid,
                  const char *uri)
 {
-  const struct GNUNET_PeerIdentity *pid = cls;
+  (void) cls;
   struct GNUNET_HashCode phash;
   int peer_bucket;
   struct PeerBucket *bucket;
diff --git a/src/service/dht/gnunet-service-dht_neighbours.h 
b/src/service/dht/gnunet-service-dht_neighbours.h
index 85e18d46d..7a6788068 100644
--- a/src/service/dht/gnunet-service-dht_neighbours.h
+++ b/src/service/dht/gnunet-service-dht_neighbours.h
@@ -134,11 +134,13 @@ GDS_am_closest_peer (const struct GNUNET_HashCode *key,
  * Callback function used to extract URIs from a builder.
  * Called when we should consider connecting to a peer.
  *
- * @param cls closure pointing to a `struct GNUNET_PeerIdentity *`
+ * @param cls closure
+ * @param pid pointing to a `struct GNUNET_PeerIdentity *`
  * @param uri one of the URIs
  */
 void
 GDS_try_connect (void *cls,
+                 const struct GNUNET_PeerIdentity *pid,
                  const char *uri);
 
 
diff --git a/src/service/dhtu/plugin_dhtu_gnunet.c 
b/src/service/dhtu/plugin_dhtu_gnunet.c
index 247ab7090..1c56be0e5 100644
--- a/src/service/dhtu/plugin_dhtu_gnunet.c
+++ b/src/service/dhtu/plugin_dhtu_gnunet.c
@@ -374,6 +374,7 @@ core_disconnect_cb (void *cls,
 
 static void
 add_addr (void *cls,
+          const struct GNUNET_PeerIdentity *pid,
           const char *addr)
 {
   struct Plugin *plugin = cls;
@@ -408,7 +409,6 @@ peerinfo_cb (void *cls,
 {
   struct Plugin *plugin = cls;
   struct GNUNET_HELLO_Builder *builder;
-  struct GNUNET_PeerIdentity pid;
 
   if (NULL == hello)
     return;
@@ -420,7 +420,6 @@ peerinfo_cb (void *cls,
     return;
   builder = GNUNET_HELLO_builder_from_msg (hello);
   GNUNET_HELLO_builder_iterate (builder,
-                                &pid,
                                 add_addr,
                                 plugin);
   GNUNET_HELLO_builder_free (builder);
diff --git a/src/service/transport/gnunet-service-transport.c 
b/src/service/transport/gnunet-service-transport.c
index a4850fa26..9562c1f68 100644
--- a/src/service/transport/gnunet-service-transport.c
+++ b/src/service/transport/gnunet-service-transport.c
@@ -1774,7 +1774,7 @@ struct DistanceVector
   struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
 
   /**
-   * Master secret for the setup of the Key material for the backchannel. 
+   * Master secret for the setup of the Key material for the backchannel.
    */
   struct GNUNET_HashCode *km;
 };
@@ -3089,8 +3089,8 @@ free_pending_message (struct PendingMessage *pm)
     GNUNET_assert (pm == pm->qe->pm);
     pm->qe->pm = NULL;
     GNUNET_CONTAINER_DLL_remove (qe->queue->queue_head,
-                               qe->queue->queue_tail,
-                               qe);
+                                 qe->queue->queue_tail,
+                                 qe);
     GNUNET_free (qe);
   }
   if (NULL != pm->bpm)
@@ -3102,8 +3102,8 @@ free_pending_message (struct PendingMessage *pm)
 
       qe->pm = NULL;
       GNUNET_CONTAINER_DLL_remove (qe->queue->queue_head,
-                               qe->queue->queue_tail,
-                               qe);
+                                   qe->queue->queue_tail,
+                                   qe);
       GNUNET_free (qe);
     }
     GNUNET_free (pm->bpm);
@@ -8629,9 +8629,10 @@ start_address_validation (const struct 
GNUNET_PeerIdentity *pid,
 
 static void
 hello_for_incoming_cb (void *cls,
+                       const struct GNUNET_PeerIdentity *pid,
                        const char *uri)
 {
-  const struct GNUNET_PeerIdentity *peer = cls;
+  (void) cls;
   int pfx_len;
   const char *eou;
   char *address;
@@ -8650,7 +8651,7 @@ hello_for_incoming_cb (void *cls,
               "helo for client %s\n",
               address);
 
-  start_address_validation (peer, address);
+  start_address_validation (pid, address);
   GNUNET_free (address);
 }
 
@@ -8681,9 +8682,8 @@ handle_hello_for_incoming (void *cls,
     return;
   builder = GNUNET_HELLO_builder_from_msg (hello);
   GNUNET_HELLO_builder_iterate (builder,
-                                (struct GNUNET_PeerIdentity *) peer,
                                 hello_for_incoming_cb,
-                                (struct GNUNET_PeerIdentity *) peer);
+                                NULL);
   GNUNET_HELLO_builder_free (builder);
 }
 
@@ -11263,9 +11263,10 @@ handle_suggest_cancel (void *cls, const struct 
ExpressPreferenceMessage *msg)
 
 static void
 hello_for_client_cb (void *cls,
+                     const struct GNUNET_PeerIdentity *pid,
                      const char *uri)
 {
-  const struct GNUNET_PeerIdentity *peer = cls;
+  (void) cls;
   int pfx_len;
   const char *eou;
   char *address;
@@ -11284,7 +11285,7 @@ hello_for_client_cb (void *cls,
               "hello for client %s\n",
               address);
 
-  start_address_validation (peer, address);
+  start_address_validation (pid, address);
   GNUNET_free (address);
 }
 
@@ -11316,9 +11317,8 @@ handle_hello_for_client (void *cls,
     return;
   builder = GNUNET_HELLO_builder_from_msg (hello);
   GNUNET_HELLO_builder_iterate (builder,
-                                (struct GNUNET_PeerIdentity *) peer,
                                 hello_for_client_cb,
-                                (struct GNUNET_PeerIdentity *) peer);
+                                NULL);
   GNUNET_HELLO_builder_free (builder);
 }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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