gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated (ac741e1dd -> 67f690896)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated (ac741e1dd -> 67f690896)
Date: Thu, 20 Sep 2018 01:16:49 +0200

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

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

    from ac741e1dd Log number of know peers to statistics service
     new c50386476 Remove redundant type definition
     new 69f439525 Be a little bit more consistent in style
     new 67f690896 Start changing architecture of rps service/client

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/include/gnunet_rps_service.h     |  22 +----
 src/rps/Makefile.am                  |   7 +-
 src/rps/gnunet-service-rps.c         |  20 ++---
 src/rps/gnunet-service-rps_sampler.c |  22 ++---
 src/rps/gnunet-service-rps_sampler.h |   8 +-
 src/rps/rps-test_util.c              |  36 ++++----
 src/rps/rps-test_util.h              |   2 +-
 src/rps/rps_api.c                    | 156 ++++++++++++++++++++++++++++++-----
 8 files changed, 191 insertions(+), 82 deletions(-)

diff --git a/src/include/gnunet_rps_service.h b/src/include/gnunet_rps_service.h
index eda012076..22e944d0f 100644
--- a/src/include/gnunet_rps_service.h
+++ b/src/include/gnunet_rps_service.h
@@ -63,24 +63,6 @@ typedef void (* GNUNET_RPS_NotifyReadyCB) (void *cls,
     uint64_t num_peers,
     const struct GNUNET_PeerIdentity *peers);
 
-/**
- * Callback called when view was updated
- *
- * @param num_peers the number of peers returned
- * @param peers array with num_peers PeerIDs
- */
-typedef void (* GNUNET_RPS_ViewUpdateCB) (void *cls,
-    uint64_t num_peers,
-    const struct GNUNET_PeerIdentity *peers);
-
-/**
- * Callback called when a peer from the biased stream was received
- *
- * @param peer The received peer
- */
-typedef void (* GNUNET_RPS_StreamInputCB) (void *cls,
-    uint64_t num_peers,
-    const struct GNUNET_PeerIdentity *peer);
 
 /**
  * Connect to the rps service
@@ -167,7 +149,7 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
 void
 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
                          uint32_t num_updates,
-                         GNUNET_RPS_ViewUpdateCB view_update_cb,
+                         GNUNET_RPS_NotifyReadyCB view_update_cb,
                          void *cls);
 
 
@@ -183,7 +165,7 @@ GNUNET_RPS_view_request (struct GNUNET_RPS_Handle 
*rps_handle,
 void
 GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle,
                            uint32_t num_updates,
-                           GNUNET_RPS_StreamInputCB stream_input_cb,
+                           GNUNET_RPS_NotifyReadyCB stream_input_cb,
                            void *cls);
 
 
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am
index d477ade92..2ed93ef7c 100644
--- a/src/rps/Makefile.am
+++ b/src/rps/Makefile.am
@@ -19,7 +19,11 @@ pkgcfg_DATA = \
 
 bin_PROGRAMS = gnunet-rps
 
-gnunet_rps_SOURCES = gnunet-rps.c
+gnunet_rps_SOURCES = \
+  gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \
+  gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \
+  gnunet-rps.c
+
 gnunet_rps_LDADD = \
   libgnunetrps.la \
   $(top_builddir)/src/util/libgnunetutil.la \
@@ -143,6 +147,7 @@ test_rps_churn_LDADD = $(ld_rps_test_lib)
 
 gnunet_rps_profiler_SOURCES = \
  gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \
+ gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \
  rps-test_util.h rps-test_util.c \
  gnunet-rps-profiler.c
 
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index ec6c651d9..40f576d3e 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -2347,9 +2347,9 @@ clients_notify_stream_peer (uint64_t num_peers,
  * Put random peer from sampler into the view as history update.
  */
 static void
-hist_update (void *cls,
-             struct GNUNET_PeerIdentity *ids,
-             uint32_t num_peers)
+hist_update (const struct GNUNET_PeerIdentity *ids,
+             uint32_t num_peers,
+             void *cls)
 {
   unsigned int i;
   (void) cls;
@@ -2852,9 +2852,9 @@ nse_callback (void *cls,
  * Sends those to the requesting client.
  */
 static void
-client_respond (void *cls,
-                struct GNUNET_PeerIdentity *peer_ids,
-                uint32_t num_peers)
+client_respond (const struct GNUNET_PeerIdentity *peer_ids,
+                uint32_t num_peers,
+                void *cls)
 {
   struct ReplyCls *reply_cls = cls;
   uint32_t i;
@@ -2937,9 +2937,9 @@ handle_client_request (void *cls,
   reply_cls->id = ntohl (msg->id);
   reply_cls->cli_ctx = cli_ctx;
   reply_cls->req_handle = RPS_sampler_get_n_rand_peers (client_sampler,
+                                                        num_peers,
                                                         client_respond,
-                                                        reply_cls,
-                                                        num_peers);
+                                                        reply_cls);
 
   GNUNET_assert (NULL != cli_ctx);
   GNUNET_CONTAINER_DLL_insert (cli_ctx->rep_cls_head,
@@ -3894,9 +3894,9 @@ do_round (void *cls)
 
     /* Update view with peers from history */
     RPS_sampler_get_n_rand_peers (prot_sampler,
+                                  final_size - second_border,
                                   hist_update,
-                                  NULL,
-                                  final_size - second_border);
+                                  NULL);
     // TODO change the peer_flags accordingly
 
     for (i = 0; i < View_size (); i++)
diff --git a/src/rps/gnunet-service-rps_sampler.c 
b/src/rps/gnunet-service-rps_sampler.c
index fdd500aa1..0de15bbc0 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/rps/gnunet-service-rps_sampler.c
@@ -272,7 +272,7 @@ check_n_peers_ready (void *cls,
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "returning %" PRIX32 " peers to the client\n",
         req_handle->num_peers);
-    req_handle->callback (req_handle->cls, req_handle->ids, 
req_handle->num_peers);
+    req_handle->callback (req_handle->ids, req_handle->num_peers, 
req_handle->cls);
 
     RPS_sampler_request_cancel (req_handle);
   }
@@ -647,14 +647,14 @@ sampler_mod_get_rand_peer (void *cls)
   }
   /* More reasons to wait could be added here */
 
-  GNUNET_STATISTICS_set (stats,
-                         "# client sampler element input",
-                         s_elem->num_peers,
-                         GNUNET_NO);
-  GNUNET_STATISTICS_set (stats,
-                         "# client sampler element change",
-                         s_elem->num_change,
-                         GNUNET_NO);
+//  GNUNET_STATISTICS_set (stats,
+//                         "# client sampler element input",
+//                         s_elem->num_peers,
+//                         GNUNET_NO);
+//  GNUNET_STATISTICS_set (stats,
+//                         "# client sampler element change",
+//                         s_elem->num_change,
+//                         GNUNET_NO);
 
   RPS_sampler_elem_reinit (s_elem);
   s_elem->last_client_request = GNUNET_TIME_absolute_get ();
@@ -683,9 +683,9 @@ sampler_mod_get_rand_peer (void *cls)
  */
 struct RPS_SamplerRequestHandle *
 RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
+                              uint32_t num_peers,
                               RPS_sampler_n_rand_peers_ready_cb cb,
-                              void *cls,
-                              uint32_t num_peers)
+                              void *cls)
 {
   uint32_t i;
   struct RPS_SamplerRequestHandle *req_handle;
diff --git a/src/rps/gnunet-service-rps_sampler.h 
b/src/rps/gnunet-service-rps_sampler.h
index c44844f96..6b386596f 100644
--- a/src/rps/gnunet-service-rps_sampler.h
+++ b/src/rps/gnunet-service-rps_sampler.h
@@ -46,8 +46,9 @@ struct RPS_SamplerRequestHandle;
  *        to be freed
  */
   typedef void
-(*RPS_sampler_n_rand_peers_ready_cb) (void *cls,
-    struct GNUNET_PeerIdentity *ids, uint32_t num_peers);
+(*RPS_sampler_n_rand_peers_ready_cb) (const struct GNUNET_PeerIdentity *ids,
+                                      uint32_t num_peers,
+                                      void *cls);
 
 
 /**
@@ -135,8 +136,9 @@ RPS_sampler_reinitialise_by_value (struct RPS_Sampler 
*sampler,
  */
 struct RPS_SamplerRequestHandle *
 RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
+                              uint32_t num_peers,
                               RPS_sampler_n_rand_peers_ready_cb cb,
-                              void *cls, uint32_t num_peers);
+                              void *cls);
 
 /**
  * Cancle a request issued through #RPS_sampler_n_rand_peers_ready_cb.
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index ef39638bf..271c96648 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -379,23 +379,6 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key)
 }
 
 
-struct GNUNET_CRYPTO_AuthKey
-string_to_auth_key (const char *str)
-{
-  struct GNUNET_CRYPTO_AuthKey auth_key;
-
-  if (GNUNET_OK !=
-      GNUNET_STRINGS_string_to_data (str,
-                                     strlen (str),
-                                     &auth_key.key,
-                                     sizeof (struct GNUNET_CRYPTO_AuthKey)))
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n");
-  }
-
-  return auth_key;
-}
-
 
 char *
 create_file (const char *name)
@@ -435,6 +418,25 @@ create_file (const char *name)
 
 #endif /* TO_FILE */
 
+
+struct GNUNET_CRYPTO_AuthKey
+string_to_auth_key (const char *str)
+{
+  struct GNUNET_CRYPTO_AuthKey auth_key;
+
+  if (GNUNET_OK !=
+      GNUNET_STRINGS_string_to_data (str,
+                                     strlen (str),
+                                     &auth_key.key,
+                                     sizeof (struct GNUNET_CRYPTO_AuthKey)))
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n");
+  }
+
+  return auth_key;
+}
+
+
 /**
  * @brief Try to ensure that `/tmp/rps` exists.
  *
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h
index bb9b39713..def52a0ac 100644
--- a/src/rps/rps-test_util.h
+++ b/src/rps/rps-test_util.h
@@ -36,7 +36,7 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key);
 struct GNUNET_CRYPTO_AuthKey
 string_to_auth_key (const char *str);
 
-char * 
+char *
 create_file (const char *name);
 
 /**
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index 96660ded6..a558c8a35 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -25,6 +25,7 @@
 #include "gnunet_util_lib.h"
 #include "rps.h"
 #include "gnunet_rps_service.h"
+#include "gnunet-service-rps_sampler.h"
 
 #include <inttypes.h>
 
@@ -58,7 +59,7 @@ struct GNUNET_RPS_Handle
   /**
    * @brief Callback called on each update of the view
    */
-  GNUNET_RPS_ViewUpdateCB view_update_cb;
+  GNUNET_RPS_NotifyReadyCB view_update_cb;
 
   /**
    * @brief Closure to each requested update of the view
@@ -68,7 +69,7 @@ struct GNUNET_RPS_Handle
   /**
    * @brief Callback called on each peer of the biased input stream
    */
-  GNUNET_RPS_StreamInputCB stream_input_cb;
+  GNUNET_RPS_NotifyReadyCB stream_input_cb;
 
   /**
    * @brief Closure to each requested peer from the biased stream
@@ -78,7 +79,7 @@ struct GNUNET_RPS_Handle
 
 
 /**
- * Handler to single requests from the client.
+ * Handler for a single request from a client.
  */
 struct GNUNET_RPS_Request_Handle
 {
@@ -95,7 +96,12 @@ struct GNUNET_RPS_Request_Handle
   /**
    * The number of requested peers.
    */
-  uint32_t num_peers;
+  uint32_t num_requests;
+
+  /**
+   * @brief The Sampler for the client request
+   */
+  struct RPS_Sampler *sampler;
 
   /**
    * The callback to be called when we receive an answer.
@@ -131,6 +137,7 @@ struct cb_cls_pack
  struct GNUNET_CLIENT_Connection *service_conn;
 };
 
+
 /**
  * @brief Send a request to the service.
  *
@@ -170,7 +177,7 @@ resend_requests_iterator (void *cls, uint32_t key, void 
*value)
   const struct GNUNET_RPS_Request_Handle *req_handle = value;
   (void) key;
 
-  send_request (h, req_handle->id, req_handle->num_peers);
+  send_request (h, req_handle->id, req_handle->num_requests);
   return GNUNET_YES; /* continue iterating */
 }
 
@@ -248,7 +255,7 @@ handle_reply (void *cls,
       GNUNET_CONTAINER_multihashmap32_contains (h->req_handlers, id));
   rh = GNUNET_CONTAINER_multihashmap32_get (h->req_handlers, id);
   GNUNET_assert (NULL != rh);
-  GNUNET_assert (rh->num_peers == ntohl (msg->num_peers));
+  GNUNET_assert (rh->num_requests == ntohl (msg->num_peers));
   GNUNET_CONTAINER_multihashmap32_remove_all (h->req_handlers, id);
   rh->ready_cb (rh->ready_cb_cls,
                 ntohl (msg->num_peers),
@@ -270,7 +277,7 @@ handle_reply (void *cls,
 void
 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
                          uint32_t num_updates,
-                         GNUNET_RPS_ViewUpdateCB view_update_cb,
+                         GNUNET_RPS_NotifyReadyCB view_update_cb,
                          void *cls)
 {
   struct GNUNET_MQ_Envelope *ev;
@@ -300,7 +307,7 @@ GNUNET_RPS_view_request (struct GNUNET_RPS_Handle 
*rps_handle,
 void
 GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle,
                            uint32_t num_peers,
-                           GNUNET_RPS_StreamInputCB stream_input_cb,
+                           GNUNET_RPS_NotifyReadyCB stream_input_cb,
                            void *cls)
 {
   struct GNUNET_MQ_Envelope *ev;
@@ -422,7 +429,7 @@ handle_stream_input (void *cls,
   peers = (struct GNUNET_PeerIdentity *) &msg[1];
   GNUNET_assert (NULL != h);
   GNUNET_assert (NULL != h->stream_input_cb);
-  h->stream_input_cb (h->stream_input_cb, ntohl (msg->num_peers), peers);
+  h->stream_input_cb (h->stream_input_cls, ntohl (msg->num_peers), peers);
 }
 
 
@@ -518,6 +525,39 @@ GNUNET_RPS_connect (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
 
 
 /**
+ * @brief Create new request handle
+ *
+ * @param rps_handle Handle to the service
+ * @param num_requests Number of requests
+ * @param ready_cb Callback
+ * @param cls Closure
+ *
+ * @return The newly created request handle
+ */
+static struct GNUNET_RPS_Request_Handle *
+new_request_handle (struct GNUNET_RPS_Handle *rps_handle,
+                    uint64_t num_requests,
+                    struct RPS_Sampler *sampler,
+                    GNUNET_RPS_NotifyReadyCB ready_cb,
+                    void *cls)
+{
+  struct GNUNET_RPS_Request_Handle *rh;
+
+  rh = GNUNET_new (struct GNUNET_RPS_Request_Handle);
+  rh->rps_handle = rps_handle;
+  rh->id = rps_handle->current_request_id++;
+  rh->num_requests = num_requests;
+  rh->sampler = sampler;
+  rh->ready_cb = ready_cb;
+  rh->ready_cb_cls = cls;
+  GNUNET_CONTAINER_multihashmap32_put (rps_handle->req_handlers, rh->id, rh,
+      GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+
+  return rh;
+}
+
+
+/**
  * Request n random peers.
  *
  * @param rps_handle handle to the rps service
@@ -527,34 +567,112 @@ GNUNET_RPS_connect (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
  * @return a handle to cancel this request
  */
 struct GNUNET_RPS_Request_Handle *
-GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
+GNUNET_RPS_request_peers_2 (struct GNUNET_RPS_Handle *rps_handle,
                           uint32_t num_req_peers,
                           GNUNET_RPS_NotifyReadyCB ready_cb,
                           void *cls)
 {
   struct GNUNET_RPS_Request_Handle *rh;
 
-  rh = GNUNET_new (struct GNUNET_RPS_Request_Handle);
-  rh->rps_handle = rps_handle;
-  rh->id = rps_handle->current_request_id++;
-  rh->num_peers = num_req_peers;
-  rh->ready_cb = ready_cb;
-  rh->ready_cb_cls = cls;
+  rh = new_request_handle (rps_handle,
+                           num_req_peers,
+                           NULL, /* no sampler needed */
+                           ready_cb,
+                           cls);
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Requesting %" PRIu32 " peers with id %" PRIu32 "\n",
        num_req_peers,
        rh->id);
 
-  GNUNET_CONTAINER_multihashmap32_put (rps_handle->req_handlers, rh->id, rh,
-      GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
-
   send_request (rps_handle, rh->id, num_req_peers);
   return rh;
 }
 
 
 /**
+ * @brief Callback to collect the peers from the biased stream and put those
+ * into the sampler.
+ *
+ * @param cls The #GNUNET_RPS_Request_Handle
+ * @param num_peers The number of peer that have been returned
+ * @param peers The array of @a num_peers that have been returned
+ */
+void
+collect_peers_cb (void *cls,
+                  uint64_t num_peers,
+                  const struct GNUNET_PeerIdentity *peers)
+{
+  struct GNUNET_RPS_Request_Handle *rh = cls;
+
+  for (uint64_t i = 0; i < num_peers; i++)
+  {
+    RPS_sampler_update (rh->sampler, &peers[i]);
+  }
+}
+
+
+/**
+ * @brief Called once the sampler has collected all requested peers.
+ *
+ * Calls the callback provided by the client with the corresponding cls.
+ *
+ * @param peers The array of @a num_peers that has been returned.
+ * @param num_peers The number of peers that have been returned
+ * @param cls The #GNUNET_RPS_Request_Handle
+ */
+void
+peers_ready_cb (const struct GNUNET_PeerIdentity *peers,
+                uint32_t num_peers,
+                void *cls)
+{
+  struct GNUNET_RPS_Request_Handle *rh = cls;
+
+  rh->ready_cb (rh->ready_cb_cls,
+                num_peers,
+                peers);
+  // TODO cleanup, sampler, rh, cancel stuff
+  // TODO screw this function. We can give the cb,cls directly to the sampler.
+}
+
+/**
+ * Request n random peers.
+ *
+ * @param rps_handle handle to the rps service
+ * @param num_req_peers number of peers we want to receive
+ * @param ready_cb the callback called when the peers are available
+ * @param cls closure given to the callback
+ * @return a handle to cancel this request
+ */
+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,
+                            void *cls)
+{
+  struct GNUNET_RPS_Request_Handle *rh;
+
+  rh = new_request_handle (rps_handle,
+                           num_req_peers,
+                           RPS_sampler_mod_init (num_req_peers,
+                                                 GNUNET_TIME_UNIT_SECONDS), // 
TODO remove this time-stuff
+                           ready_cb,
+                           cls);
+  RPS_sampler_get_n_rand_peers (rh->sampler,
+                                num_req_peers,
+                                peers_ready_cb,
+                                rh);
+
+  GNUNET_RPS_stream_request (rps_handle,
+                             0, /* infinite updates */
+                             collect_peers_cb,
+                             rh); /* cls */
+
+  return rh;
+}
+
+
+/**
  * Seed rps service with peerIDs.
  *
  * @param h handle to the rps service

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



reply via email to

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