Add API call to receive unbiased peer stream for debugging and profiling
[oweals/gnunet.git] / src / rps / rps_api.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C)
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @file rps/rps_api.c
21  * @brief API for rps
22  * @author Julius Bünger
23  */
24 #include "platform.h"
25 #include "gnunet_util_lib.h"
26 #include "rps.h"
27 #include "gnunet_rps_service.h"
28
29 #include <inttypes.h>
30
31 #define LOG(kind,...) GNUNET_log_from (kind, "rps-api",__VA_ARGS__)
32
33 /**
34  * Handler to handle requests from a client.
35  */
36 struct GNUNET_RPS_Handle
37 {
38   /**
39    * The handle to the client configuration.
40    */
41   const struct GNUNET_CONFIGURATION_Handle *cfg;
42
43   /**
44    * The message queue to the client.
45    */
46   struct GNUNET_MQ_Handle *mq;
47
48   /**
49    * Array of Request_Handles.
50    */
51   struct GNUNET_CONTAINER_MultiHashMap32 *req_handlers;
52
53   /**
54    * The id of the last request.
55    */
56   uint32_t current_request_id;
57
58   /**
59    * @brief Callback called on each update of the view
60    */
61   GNUNET_RPS_ViewUpdateCB view_update_cb;
62
63   /**
64    * @brief Closure to each requested update of the view
65    */
66   void *view_update_cls;
67
68   /**
69    * @brief Callback called on each peer of the biased input stream
70    */
71   GNUNET_RPS_StreamInputCB stream_input_cb;
72
73   /**
74    * @brief Closure to each requested peer from the biased stream
75    */
76   void *stream_input_cls;
77 };
78
79
80 /**
81  * Handler to single requests from the client.
82  */
83 struct GNUNET_RPS_Request_Handle
84 {
85   /**
86    * The client issuing the request.
87    */
88   struct GNUNET_RPS_Handle *rps_handle;
89
90   /**
91    * The id of the request.
92    */
93   uint32_t id;
94
95   /**
96    * The number of requested peers.
97    */
98   uint32_t num_peers;
99
100   /**
101    * The callback to be called when we receive an answer.
102    */
103   GNUNET_RPS_NotifyReadyCB ready_cb;
104
105   /**
106    * The closure for the callback.
107    */
108   void *ready_cb_cls;
109 };
110
111
112 /**
113  * Struct used to pack the callback, its closure (provided by the caller)
114  * and the connection handler to the service to pass it to a callback function.
115  */
116 struct cb_cls_pack
117 {
118   /**
119    * Callback provided by the client
120    */
121   GNUNET_RPS_NotifyReadyCB cb;
122
123   /**
124    * Closure provided by the client
125    */
126   void *cls;
127
128   /**
129    * Handle to the service connection
130    */
131  struct GNUNET_CLIENT_Connection *service_conn;
132 };
133
134 /**
135  * @brief Send a request to the service.
136  *
137  * @param h rps handle
138  * @param id id of the request
139  * @param num_req_peers number of peers
140  */
141 void
142 send_request (const struct GNUNET_RPS_Handle *h,
143               uint32_t id,
144               uint32_t num_req_peers)
145 {
146   struct GNUNET_MQ_Envelope *ev;
147   struct GNUNET_RPS_CS_RequestMessage *msg;
148
149   ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST);
150   msg->num_peers = htonl (num_req_peers);
151   msg->id = htonl (id);
152   GNUNET_MQ_send (h->mq, ev);
153 }
154
155 /**
156  * @brief Iterator function over pending requests
157  *
158  * Implements #GNUNET_CONTAINER_HashMapIterator32
159  *
160  * @param cls rps handle
161  * @param key id of the request
162  * @param value request handle
163  *
164  * @return GNUNET_YES to continue iteration
165  */
166 int
167 resend_requests_iterator (void *cls, uint32_t key, void *value)
168 {
169   const struct GNUNET_RPS_Handle *h = cls;
170   const struct GNUNET_RPS_Request_Handle *req_handle = value;
171   (void) key;
172
173   send_request (h, req_handle->id, req_handle->num_peers);
174   return GNUNET_YES; /* continue iterating */
175 }
176
177 /**
178  * @brief Resend all pending requests
179  *
180  * This is used to resend all pending requests after the client
181  * reconnected to the service, because the service cancels all
182  * pending requests after reconnection.
183  *
184  * @param h rps handle
185  */
186 void
187 resend_requests (struct GNUNET_RPS_Handle *h)
188 {
189   GNUNET_CONTAINER_multihashmap32_iterate (h->req_handlers,
190                                            resend_requests_iterator,
191                                            h);
192 }
193
194
195 /**
196  * This function is called, when the service replies to our request.
197  * It verifies that @a msg is well-formed.
198  *
199  * @param cls the closure
200  * @param msg the message
201  * @return #GNUNET_OK if @a msg is well-formed
202  */
203 static int
204 check_reply (void *cls,
205              const struct GNUNET_RPS_CS_ReplyMessage *msg)
206 {
207   uint16_t msize = ntohs (msg->header.size);
208   uint32_t num_peers = ntohl (msg->num_peers);
209   (void) cls;
210
211   msize -= sizeof (struct GNUNET_RPS_CS_ReplyMessage);
212   if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) ||
213        (msize % sizeof (struct GNUNET_PeerIdentity) != 0) )
214   {
215     GNUNET_break (0);
216     return GNUNET_SYSERR;
217   }
218   return GNUNET_OK;
219 }
220
221
222 /**
223  * This function is called, when the service replies to our request.
224  * It calls the callback the caller gave us with the provided closure
225  * and disconnects afterwards.
226  *
227  * @param cls the closure
228  * @param msg the message
229  */
230 static void
231 handle_reply (void *cls,
232               const struct GNUNET_RPS_CS_ReplyMessage *msg)
233 {
234   struct GNUNET_RPS_Handle *h = cls;
235   struct GNUNET_PeerIdentity *peers;
236   struct GNUNET_RPS_Request_Handle *rh;
237   uint32_t id;
238
239   /* Give the peers back */
240   id = ntohl (msg->id);
241   LOG (GNUNET_ERROR_TYPE_DEBUG,
242        "Service replied with %" PRIu32 " peers for id %" PRIu32 "\n",
243        ntohl (msg->num_peers),
244        id);
245
246   peers = (struct GNUNET_PeerIdentity *) &msg[1];
247   GNUNET_assert (GNUNET_YES ==
248       GNUNET_CONTAINER_multihashmap32_contains (h->req_handlers, id));
249   rh = GNUNET_CONTAINER_multihashmap32_get (h->req_handlers, id);
250   GNUNET_assert (NULL != rh);
251   GNUNET_assert (rh->num_peers == ntohl (msg->num_peers));
252   GNUNET_CONTAINER_multihashmap32_remove_all (h->req_handlers, id);
253   rh->ready_cb (rh->ready_cb_cls,
254                 ntohl (msg->num_peers),
255                 peers);
256 }
257
258
259 /* Get internals for debugging/profiling purposes */
260
261 /**
262  * Request updates of view
263  *
264  * @param rps_handle handle to the rps service
265  * @param num_req_peers number of peers we want to receive
266  *        (0 for infinite updates)
267  * @param cls a closure that will be given to the callback
268  * @param ready_cb the callback called when the peers are available
269  */
270 void
271 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
272                          uint32_t num_updates,
273                          GNUNET_RPS_ViewUpdateCB view_update_cb,
274                          void *cls)
275 {
276   struct GNUNET_MQ_Envelope *ev;
277   struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg;
278
279   LOG (GNUNET_ERROR_TYPE_DEBUG,
280        "Client requests %" PRIu32 " view updates\n",
281        num_updates);
282   rps_handle->view_update_cb = view_update_cb;
283   rps_handle->view_update_cls = cls;
284
285   ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST);
286   msg->num_updates = htonl (num_updates);
287   GNUNET_MQ_send (rps_handle->mq, ev);
288 }
289
290
291 /**
292  * Request biased stream of peers that are being put into the sampler
293  *
294  * @param rps_handle handle to the rps service
295  * @param num_req_peers number of peers we want to receive
296  *        (0 for infinite updates)
297  * @param cls a closure that will be given to the callback
298  * @param ready_cb the callback called when the peers are available
299  */
300 void
301 GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle,
302                            uint32_t num_peers,
303                            GNUNET_RPS_StreamInputCB stream_input_cb,
304                            void *cls)
305 {
306   struct GNUNET_MQ_Envelope *ev;
307   struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg;
308
309   LOG (GNUNET_ERROR_TYPE_DEBUG,
310        "Client requests %" PRIu32 " biased stream updates\n",
311        num_peers);
312   rps_handle->stream_input_cb = stream_input_cb;
313   rps_handle->stream_input_cls = cls;
314
315   ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST);
316   msg->num_peers = htonl (num_peers);
317   GNUNET_MQ_send (rps_handle->mq, ev);
318 }
319
320
321 /**
322  * This function is called, when the service updates the view.
323  * It verifies that @a msg is well-formed.
324  *
325  * @param cls the closure
326  * @param msg the message
327  * @return #GNUNET_OK if @a msg is well-formed
328  */
329 static int
330 check_view_update (void *cls,
331                    const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
332 {
333   uint16_t msize = ntohs (msg->header.size);
334   uint32_t num_peers = ntohl (msg->num_peers);
335   (void) cls;
336
337   msize -= sizeof (struct GNUNET_RPS_CS_DEBUG_ViewReply);
338   if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) ||
339        (msize % sizeof (struct GNUNET_PeerIdentity) != 0) )
340   {
341     GNUNET_break (0);
342     return GNUNET_SYSERR;
343   }
344   return GNUNET_OK;
345 }
346
347
348 /**
349  * This function is called, when the service updated its view.
350  * It calls the callback the caller provided
351  * and disconnects afterwards.
352  *
353  * @param msg the message
354  */
355 static void
356 handle_view_update (void *cls,
357                     const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
358 {
359   struct GNUNET_RPS_Handle *h = cls;
360   struct GNUNET_PeerIdentity *peers;
361
362   /* Give the peers back */
363   LOG (GNUNET_ERROR_TYPE_DEBUG,
364        "New view of %" PRIu32 " peers:\n",
365        ntohl (msg->num_peers));
366
367   peers = (struct GNUNET_PeerIdentity *) &msg[1];
368   GNUNET_assert (NULL != h);
369   GNUNET_assert (NULL != h->view_update_cb);
370   h->view_update_cb (h->view_update_cls, ntohl (msg->num_peers), peers);
371 }
372
373
374 /**
375  * This function is called, when the service sends another peer from the biased
376  * stream.
377  * It calls the callback the caller provided
378  * and disconnects afterwards.
379  *
380  * @param msg the message
381  */
382 static void
383 handle_stream_input (void *cls,
384                      const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
385 {
386   struct GNUNET_RPS_Handle *h = cls;
387
388   /* Give the peers back */
389   LOG (GNUNET_ERROR_TYPE_DEBUG,
390        "New peer of biased input stream\n");
391
392   GNUNET_assert (NULL != h);
393   GNUNET_assert (NULL != h->stream_input_cb);
394   h->stream_input_cb (h->stream_input_cb, &msg->peer);
395 }
396
397
398 /**
399  * Reconnect to the service
400  */
401 static void
402 reconnect (struct GNUNET_RPS_Handle *h);
403
404
405 /**
406  * Error handler for mq.
407  *
408  * This function is called whan mq encounters an error.
409  * Until now mq doesn't provide useful error messages.
410  *
411  * @param cls the closure
412  * @param error error code without specyfied meaning
413  */
414 static void
415 mq_error_handler (void *cls,
416                   enum GNUNET_MQ_Error error)
417 {
418   struct GNUNET_RPS_Handle *h = cls;
419   //TODO LOG
420   LOG (GNUNET_ERROR_TYPE_WARNING, "Problem with message queue. error: %i\n\
421        1: READ,\n\
422        2: WRITE,\n\
423        4: TIMEOUT\n",
424        error);
425   reconnect (h);
426   /* Resend all pending request as the service destroyed its knowledge
427    * about them */
428   resend_requests (h);
429 }
430
431
432 /**
433  * Reconnect to the service
434  */
435 static void
436 reconnect (struct GNUNET_RPS_Handle *h)
437 {
438   struct GNUNET_MQ_MessageHandler mq_handlers[] = {
439     GNUNET_MQ_hd_var_size (reply,
440                            GNUNET_MESSAGE_TYPE_RPS_CS_REPLY,
441                            struct GNUNET_RPS_CS_ReplyMessage,
442                            h),
443     GNUNET_MQ_hd_var_size (view_update,
444                            GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY,
445                            struct GNUNET_RPS_CS_DEBUG_ViewReply,
446                            h),
447     GNUNET_MQ_hd_fixed_size (stream_input,
448                              GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY,
449                              struct GNUNET_RPS_CS_DEBUG_StreamReply,
450                              h),
451     GNUNET_MQ_handler_end ()
452   };
453
454   if (NULL != h->mq)
455     GNUNET_MQ_destroy (h->mq);
456   h->mq = GNUNET_CLIENT_connect (h->cfg,
457                                  "rps",
458                                  mq_handlers,
459                                  &mq_error_handler,
460                                  h);
461 }
462
463
464 /**
465  * Connect to the rps service
466  *
467  * @param cfg configuration to use
468  * @return a handle to the service
469  */
470 struct GNUNET_RPS_Handle *
471 GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
472 {
473   struct GNUNET_RPS_Handle *h;
474
475   h = GNUNET_new (struct GNUNET_RPS_Handle);
476   h->current_request_id = 0;
477   h->cfg = cfg;
478   reconnect (h);
479   if (NULL == h->mq)
480   {
481     GNUNET_free (h);
482     return NULL;
483   }
484   h->req_handlers = GNUNET_CONTAINER_multihashmap32_create (4);
485   return h;
486 }
487
488
489 /**
490  * Request n random peers.
491  *
492  * @param rps_handle handle to the rps service
493  * @param num_req_peers number of peers we want to receive
494  * @param ready_cb the callback called when the peers are available
495  * @param cls closure given to the callback
496  * @return a handle to cancel this request
497  */
498 struct GNUNET_RPS_Request_Handle *
499 GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
500                           uint32_t num_req_peers,
501                           GNUNET_RPS_NotifyReadyCB ready_cb,
502                           void *cls)
503 {
504   struct GNUNET_RPS_Request_Handle *rh;
505
506   rh = GNUNET_new (struct GNUNET_RPS_Request_Handle);
507   rh->rps_handle = rps_handle;
508   rh->id = rps_handle->current_request_id++;
509   rh->num_peers = num_req_peers;
510   rh->ready_cb = ready_cb;
511   rh->ready_cb_cls = cls;
512
513   LOG (GNUNET_ERROR_TYPE_DEBUG,
514        "Requesting %" PRIu32 " peers with id %" PRIu32 "\n",
515        num_req_peers,
516        rh->id);
517
518   GNUNET_CONTAINER_multihashmap32_put (rps_handle->req_handlers, rh->id, rh,
519       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
520
521   send_request (rps_handle, rh->id, num_req_peers);
522   return rh;
523 }
524
525
526 /**
527  * Seed rps service with peerIDs.
528  *
529  * @param h handle to the rps service
530  * @param n number of peers to seed
531  * @param ids the ids of the peers seeded
532  */
533 void
534 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
535                      uint32_t n,
536                      const struct GNUNET_PeerIdentity *ids)
537 {
538   size_t size_needed;
539   uint32_t num_peers_max;
540   const struct GNUNET_PeerIdentity *tmp_peer_pointer;
541   struct GNUNET_MQ_Envelope *ev;
542   struct GNUNET_RPS_CS_SeedMessage *msg;
543
544   unsigned int i;
545
546   LOG (GNUNET_ERROR_TYPE_DEBUG,
547        "Client wants to seed %" PRIu32 " peers:\n",
548        n);
549   for (i = 0 ; i < n ; i++)
550     LOG (GNUNET_ERROR_TYPE_DEBUG,
551          "%u. peer: %s\n",
552          i,
553          GNUNET_i2s (&ids[i]));
554
555   /* The actual size the message occupies */
556   size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
557     n * sizeof (struct GNUNET_PeerIdentity);
558   /* The number of peers that fits in one message together with
559    * the respective header */
560   num_peers_max = (GNUNET_MAX_MESSAGE_SIZE -
561       sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
562     sizeof (struct GNUNET_PeerIdentity);
563   tmp_peer_pointer = ids;
564
565   while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
566   {
567     ev = GNUNET_MQ_msg_extra (msg, num_peers_max * sizeof (struct GNUNET_PeerIdentity),
568         GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
569     msg->num_peers = htonl (num_peers_max);
570     GNUNET_memcpy (&msg[1], tmp_peer_pointer, num_peers_max * sizeof (struct GNUNET_PeerIdentity));
571     GNUNET_MQ_send (h->mq, ev);
572
573     n -= num_peers_max;
574     size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
575                   n * sizeof (struct GNUNET_PeerIdentity);
576     /* Set pointer to beginning of next block of num_peers_max peers */
577     tmp_peer_pointer = &ids[num_peers_max];
578   }
579
580   ev = GNUNET_MQ_msg_extra (msg, n * sizeof (struct GNUNET_PeerIdentity),
581                             GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
582   msg->num_peers = htonl (n);
583   GNUNET_memcpy (&msg[1], tmp_peer_pointer, n * sizeof (struct GNUNET_PeerIdentity));
584
585   GNUNET_MQ_send (h->mq, ev);
586 }
587
588
589 #ifdef ENABLE_MALICIOUS
590 /**
591  * Turn RPS service to act malicious.
592  *
593  * @param h handle to the rps service
594  * @param type which type of malicious peer to turn to.
595  *             0 Don't act malicious at all
596  *             1 Try to maximise representation
597  *             2 Try to partition the network
598  *               (isolate one peer from the rest)
599  * @param n number of @a ids
600  * @param ids the ids of the malicious peers
601  *            if @type is 2 the last id is the id of the
602  *            peer to be isolated from the rest
603  */
604 void
605 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
606                           uint32_t type,
607                           uint32_t num_peers,
608                           const struct GNUNET_PeerIdentity *peer_ids,
609                           const struct GNUNET_PeerIdentity *target_peer)
610 {
611   size_t size_needed;
612   uint32_t num_peers_max;
613   const struct GNUNET_PeerIdentity *tmp_peer_pointer;
614   struct GNUNET_MQ_Envelope *ev;
615   struct GNUNET_RPS_CS_ActMaliciousMessage *msg;
616
617   unsigned int i;
618
619   LOG (GNUNET_ERROR_TYPE_DEBUG,
620        "Client turns malicious (type %" PRIu32 ") with %" PRIu32 " other peers:\n",
621        type,
622        num_peers);
623   for (i = 0 ; i < num_peers ; i++)
624     LOG (GNUNET_ERROR_TYPE_DEBUG,
625          "%u. peer: %s\n",
626          i,
627          GNUNET_i2s (&peer_ids[i]));
628
629   /* The actual size the message would occupy */
630   size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
631     num_peers * sizeof (struct GNUNET_PeerIdentity);
632   /* The number of peers that fit in one message together with
633    * the respective header */
634   num_peers_max = (GNUNET_MAX_MESSAGE_SIZE -
635       sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
636     sizeof (struct GNUNET_PeerIdentity);
637   tmp_peer_pointer = peer_ids;
638
639   while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
640   {
641     LOG (GNUNET_ERROR_TYPE_DEBUG,
642          "Too many peers to send at once, sending %" PRIu32 " (all we can so far)\n",
643          num_peers_max);
644     ev = GNUNET_MQ_msg_extra (msg,
645                               num_peers_max * sizeof (struct GNUNET_PeerIdentity),
646                               GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
647     msg->type = htonl (type);
648     msg->num_peers = htonl (num_peers_max);
649     if ( (2 == type) ||
650          (3 == type) )
651       msg->attacked_peer = peer_ids[num_peers];
652     GNUNET_memcpy (&msg[1],
653             tmp_peer_pointer,
654             num_peers_max * sizeof (struct GNUNET_PeerIdentity));
655
656     GNUNET_MQ_send (h->mq, ev);
657
658     num_peers -= num_peers_max;
659     size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
660                   num_peers * sizeof (struct GNUNET_PeerIdentity);
661     /* Set pointer to beginning of next block of num_peers_max peers */
662     tmp_peer_pointer = &peer_ids[num_peers_max];
663   }
664
665   ev = GNUNET_MQ_msg_extra (msg,
666                             num_peers * sizeof (struct GNUNET_PeerIdentity),
667                             GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
668   msg->type = htonl (type);
669   msg->num_peers = htonl (num_peers);
670   if ( (2 == type) ||
671        (3 == type) )
672     msg->attacked_peer = *target_peer;
673   GNUNET_memcpy (&msg[1], tmp_peer_pointer, num_peers * sizeof (struct GNUNET_PeerIdentity));
674
675   GNUNET_MQ_send (h->mq, ev);
676 }
677 #endif /* ENABLE_MALICIOUS */
678
679
680 /**
681  * Cancle an issued request.
682  *
683  * @param rh request handle of request to cancle
684  */
685 void
686 GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
687 {
688   struct GNUNET_RPS_Handle *h;
689   struct GNUNET_MQ_Envelope *ev;
690   struct GNUNET_RPS_CS_RequestCancelMessage*msg;
691
692   LOG (GNUNET_ERROR_TYPE_DEBUG,
693        "Cancelling request with id %" PRIu32 "\n",
694        rh->id);
695
696   h = rh->rps_handle;
697   GNUNET_assert (GNUNET_CONTAINER_multihashmap32_contains (h->req_handlers,
698         rh->id));
699   GNUNET_CONTAINER_multihashmap32_remove_all (h->req_handlers, rh->id);
700   ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST_CANCEL);
701   msg->id = htonl (rh->id);
702   GNUNET_MQ_send (rh->rps_handle->mq, ev);
703 }
704
705
706 /**
707  * Disconnect from the rps service
708  *
709  * @param h the handle to the rps service
710  */
711 void
712 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
713 {
714   GNUNET_MQ_destroy (h->mq);
715   if (0 < GNUNET_CONTAINER_multihashmap32_size (h->req_handlers))
716     LOG (GNUNET_ERROR_TYPE_WARNING,
717         "Still waiting for requests\n");
718   GNUNET_CONTAINER_multihashmap32_destroy (h->req_handlers);
719   GNUNET_free (h);
720 }
721
722
723 /* end of rps_api.c */