Handle cancellation of view updates
authorJulius Bünger <buenger@mytum.de>
Wed, 26 Sep 2018 19:15:01 +0000 (21:15 +0200)
committerJulius Bünger <buenger@mytum.de>
Wed, 26 Sep 2018 19:15:01 +0000 (21:15 +0200)
src/rps/gnunet-service-rps.c
src/rps/rps-sampler_client.c
src/rps/rps_api.c

index 3dd887d4788d5c02b3377b67c3b6c871db7a1d37..4e06f5a4936878bfd7e0883c744639d4e7df2379 100644 (file)
@@ -2733,6 +2733,27 @@ handle_client_view_request (void *cls,
 }
 
 
+static void
+handle_client_view_request_cancel (void *cls,
+                                   const struct GNUNET_MessageHeader *msg)
+{
+  struct ClientContext *cli_ctx = cls;
+  uint64_t num_updates;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Client does not want to receive updates of view any more.\n",
+       num_updates);
+
+  GNUNET_assert (NULL != cli_ctx);
+  cli_ctx->view_updates_left = 0;
+  if (GNUNET_YES == cli_ctx->stream_update)
+  {
+    destroy_cli_ctx (cli_ctx);
+  }
+  GNUNET_SERVICE_client_continue (cli_ctx->client);
+}
+
+
 /**
  * Handle RPS request for biased stream from the client.
  *
@@ -4079,6 +4100,10 @@ GNUNET_SERVICE_MAIN
    GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST,
    struct GNUNET_RPS_CS_DEBUG_ViewRequest,
    NULL),
+ GNUNET_MQ_hd_fixed_size (client_view_request_cancel,
+   GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL,
+   struct GNUNET_MessageHeader,
+   NULL),
  GNUNET_MQ_hd_fixed_size (client_stream_request,
    GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST,
    struct GNUNET_RPS_CS_DEBUG_StreamRequest,
index da832a32328e3d2a549889e2f19f02945ab0a40c..4904b9d43220f4184135ff2df458292c6d37e52a 100644 (file)
@@ -201,7 +201,6 @@ RPS_sampler_mod_init (size_t init_size,
   max_size = 1000; // TODO make input to _samplers_init()
 
   sampler = GNUNET_new (struct RPS_Sampler);
-
   sampler->max_round_interval = max_round_interval;
   sampler->get_peers = sampler_mod_get_rand_peer;
   //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity);
index 6e124644dbcb9cbf8f09476b97abd577eb6db2df..7d0674aff12d10ccb2240368bd93d6184421c29f 100644 (file)
@@ -344,6 +344,20 @@ GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
 }
 
 
+void
+GNUNET_RPS_view_request_cancel (struct GNUNET_RPS_Handle *rps_handle)
+{
+  struct GNUNET_MQ_Envelope *ev;
+
+  GNUNET_assert (NULL != rps_handle->view_update_cb);
+
+  rps_handle->view_update_cb = NULL;
+
+  ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL);
+  GNUNET_MQ_send (rps_handle->mq, ev);
+}
+
+
 /**
  * Request biased stream of peers that are being put into the sampler
  *
@@ -879,7 +893,12 @@ GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
   if (NULL != h->stream_requests_head)
   {
     LOG (GNUNET_ERROR_TYPE_WARNING,
-        "Still waiting for requests\n");
+        "Still waiting for replies\n");
+  }
+  if (NULL != h->view_update_cb)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+        "Still waiting for view updates\n");
   }
   GNUNET_free (h);
 }