From cf847c7470937fa160ccec6588acdc3c46c5e202 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20B=C3=BCnger?= Date: Wed, 26 Sep 2018 21:15:01 +0200 Subject: [PATCH] Handle cancellation of view updates --- src/rps/gnunet-service-rps.c | 25 +++++++++++++++++++++++++ src/rps/rps-sampler_client.c | 1 - src/rps/rps_api.c | 21 ++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 3dd887d47..4e06f5a49 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -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, diff --git a/src/rps/rps-sampler_client.c b/src/rps/rps-sampler_client.c index da832a323..4904b9d43 100644 --- a/src/rps/rps-sampler_client.c +++ b/src/rps/rps-sampler_client.c @@ -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); diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index 6e124644d..7d0674aff 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c @@ -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); } -- 2.25.1