2 This file is part of GNUnet.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
24 * @author Julius Bünger
27 #include "gnunet_util_lib.h"
29 #include "gnunet_rps_service.h"
30 #include "rps-sampler_client.h"
34 #define LOG(kind,...) GNUNET_log_from (kind, "rps-api",__VA_ARGS__)
37 * Handle for a request to get peers from biased stream of ids
39 struct GNUNET_RPS_StreamRequestHandle
42 * The client issuing the request.
44 struct GNUNET_RPS_Handle *rps_handle;
47 * The callback to be called when we receive an answer.
49 GNUNET_RPS_NotifyReadyCB ready_cb;
52 * The closure for the callback.
57 * @brief Scheduler task for scheduled callback
59 struct GNUNET_SCHEDULER_Task *callback_task;
62 * @brief Next element of the DLL
64 struct GNUNET_RPS_StreamRequestHandle *next;
67 * @brief Previous element of the DLL
69 struct GNUNET_RPS_StreamRequestHandle *prev;
74 * Handler to handle requests from a client.
76 struct GNUNET_RPS_Handle
79 * The handle to the client configuration.
81 const struct GNUNET_CONFIGURATION_Handle *cfg;
84 * The message queue to the client.
86 struct GNUNET_MQ_Handle *mq;
89 * @brief Callback called on each update of the view
91 GNUNET_RPS_NotifyReadyCB view_update_cb;
94 * @brief Closure to each requested update of the view
96 void *view_update_cls;
99 * @brief Closure to each requested peer from the biased stream
101 void *stream_input_cls;
104 * @brief Head of the DLL of stream requests
106 struct GNUNET_RPS_StreamRequestHandle *stream_requests_head;
109 * @brief Tail of the DLL of stream requests
111 struct GNUNET_RPS_StreamRequestHandle *stream_requests_tail;
116 * Handler for a single request from a client.
118 struct GNUNET_RPS_Request_Handle
121 * The client issuing the request.
123 struct GNUNET_RPS_Handle *rps_handle;
126 * The number of requested peers.
128 uint32_t num_requests;
131 * @brief The Sampler for the client request
133 struct RPS_Sampler *sampler;
136 * @brief Request handle of the request to the sampler - needed to cancel the request
138 struct RPS_SamplerRequestHandle *sampler_rh;
141 * @brief Request handle of the request of the biased stream of peers -
142 * needed to cancel the request
144 struct GNUNET_RPS_StreamRequestHandle *srh;
147 * The callback to be called when we receive an answer.
149 GNUNET_RPS_NotifyReadyCB ready_cb;
152 * The closure for the callback.
159 * Struct used to pack the callback, its closure (provided by the caller)
160 * and the connection handler to the service to pass it to a callback function.
165 * Callback provided by the client
167 GNUNET_RPS_NotifyReadyCB cb;
170 * Closure provided by the client
175 * Handle to the service connection
177 struct GNUNET_CLIENT_Connection *service_conn;
182 * @brief Peers received from the biased stream to be passed to all
185 static struct GNUNET_PeerIdentity *srh_callback_peers;
188 * @brief Number of peers in the biased stream that are to be passed to all
191 static uint64_t srh_callback_num_peers;
195 * @brief Create a new handle for a stream request
197 * @param rps_handle The rps handle
198 * @param num_peers The number of desired peers
199 * @param ready_cb The callback to be called, once all peers are ready
200 * @param cls The colsure to provide to the callback
202 * @return The handle to the stream request
204 static struct GNUNET_RPS_StreamRequestHandle *
205 new_stream_request (struct GNUNET_RPS_Handle *rps_handle,
206 GNUNET_RPS_NotifyReadyCB ready_cb,
209 struct GNUNET_RPS_StreamRequestHandle *srh;
211 srh = GNUNET_new (struct GNUNET_RPS_StreamRequestHandle);
212 srh->rps_handle = rps_handle;
213 srh->ready_cb = ready_cb;
214 srh->ready_cb_cls = cls;
215 GNUNET_CONTAINER_DLL_insert (rps_handle->stream_requests_head,
216 rps_handle->stream_requests_tail,
224 * @brief Remove the given stream request from the list of requests and memory
226 * @param srh The request to be removed
229 remove_stream_request (struct GNUNET_RPS_StreamRequestHandle *srh)
231 struct GNUNET_RPS_Handle *rps_handle = srh->rps_handle;
233 GNUNET_assert (NULL != srh);
234 if (NULL != srh->callback_task)
236 GNUNET_SCHEDULER_cancel (srh->callback_task);
237 srh->callback_task = NULL;
239 GNUNET_CONTAINER_DLL_remove (rps_handle->stream_requests_head,
240 rps_handle->stream_requests_tail,
247 * @brief Called once the sampler has collected all requested peers.
249 * Calls the callback provided by the client with the corresponding cls.
251 * @param peers The array of @a num_peers that has been returned.
252 * @param num_peers The number of peers that have been returned
253 * @param cls The #GNUNET_RPS_Request_Handle
256 peers_ready_cb (const struct GNUNET_PeerIdentity *peers,
260 struct GNUNET_RPS_Request_Handle *rh = cls;
262 rh->sampler_rh = NULL;
263 rh->ready_cb (rh->ready_cb_cls,
266 GNUNET_RPS_stream_cancel (rh->srh);
268 RPS_sampler_destroy (rh->sampler);
274 * @brief Callback to collect the peers from the biased stream and put those
277 * @param cls The #GNUNET_RPS_Request_Handle
278 * @param num_peers The number of peer that have been returned
279 * @param peers The array of @a num_peers that have been returned
282 collect_peers_cb (void *cls,
284 const struct GNUNET_PeerIdentity *peers)
286 struct GNUNET_RPS_Request_Handle *rh = cls;
288 LOG (GNUNET_ERROR_TYPE_DEBUG,
289 "Service sent %" PRIu64 " peers from stream\n",
291 for (uint64_t i = 0; i < num_peers; i++)
293 RPS_sampler_update (rh->sampler, &peers[i]);
298 /* Get internals for debugging/profiling purposes */
301 * Request updates of view
303 * @param rps_handle handle to the rps service
304 * @param num_req_peers number of peers we want to receive
305 * (0 for infinite updates)
306 * @param cls a closure that will be given to the callback
307 * @param ready_cb the callback called when the peers are available
310 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
311 uint32_t num_updates,
312 GNUNET_RPS_NotifyReadyCB view_update_cb,
315 struct GNUNET_MQ_Envelope *ev;
316 struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg;
318 LOG (GNUNET_ERROR_TYPE_DEBUG,
319 "Client requests %" PRIu32 " view updates\n",
321 rps_handle->view_update_cb = view_update_cb;
322 rps_handle->view_update_cls = cls;
324 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST);
325 msg->num_updates = htonl (num_updates);
326 GNUNET_MQ_send (rps_handle->mq, ev);
331 GNUNET_RPS_view_request_cancel (struct GNUNET_RPS_Handle *rps_handle)
333 struct GNUNET_MQ_Envelope *ev;
335 GNUNET_assert (NULL != rps_handle->view_update_cb);
337 rps_handle->view_update_cb = NULL;
339 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL);
340 GNUNET_MQ_send (rps_handle->mq, ev);
345 * Request biased stream of peers that are being put into the sampler
347 * @param rps_handle handle to the rps service
348 * @param cls a closure that will be given to the callback
349 * @param ready_cb the callback called when the peers are available
351 struct GNUNET_RPS_StreamRequestHandle *
352 GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle,
353 GNUNET_RPS_NotifyReadyCB stream_input_cb,
356 struct GNUNET_RPS_StreamRequestHandle *srh;
357 struct GNUNET_MQ_Envelope *ev;
358 struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg;
360 srh = new_stream_request (rps_handle,
363 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requests biased stream updates\n");
365 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST);
366 GNUNET_MQ_send (rps_handle->mq, ev);
372 * This function is called, when the service updates the view.
373 * It verifies that @a msg is well-formed.
375 * @param cls the closure
376 * @param msg the message
377 * @return #GNUNET_OK if @a msg is well-formed
380 check_view_update (void *cls,
381 const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
383 uint16_t msize = ntohs (msg->header.size);
384 uint32_t num_peers = ntohl (msg->num_peers);
387 msize -= sizeof (struct GNUNET_RPS_CS_DEBUG_ViewReply);
388 if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) ||
389 (msize % sizeof (struct GNUNET_PeerIdentity) != 0) )
392 return GNUNET_SYSERR;
399 * This function is called, when the service updated its view.
400 * It calls the callback the caller provided
401 * and disconnects afterwards.
403 * @param msg the message
406 handle_view_update (void *cls,
407 const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
409 struct GNUNET_RPS_Handle *h = cls;
410 struct GNUNET_PeerIdentity *peers;
412 /* Give the peers back */
413 LOG (GNUNET_ERROR_TYPE_DEBUG,
414 "New view of %" PRIu32 " peers:\n",
415 ntohl (msg->num_peers));
417 peers = (struct GNUNET_PeerIdentity *) &msg[1];
418 GNUNET_assert (NULL != h);
419 GNUNET_assert (NULL != h->view_update_cb);
420 h->view_update_cb (h->view_update_cls, ntohl (msg->num_peers), peers);
425 * @brief Send message to service that this client does not want to receive
426 * further updates from the biased peer stream
428 * @param rps_handle The handle representing the service to the client
431 cancel_stream (struct GNUNET_RPS_Handle *rps_handle)
433 struct GNUNET_MQ_Envelope *ev;
435 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL);
436 GNUNET_MQ_send (rps_handle->mq, ev);
441 * @brief Cancel a specific request for updates from the biased peer stream
443 * @param srh The request handle to cancel
446 GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh)
448 struct GNUNET_RPS_Handle *rps_handle;
450 rps_handle = srh->rps_handle;
451 remove_stream_request (srh);
452 if (NULL == rps_handle->stream_requests_head)
453 cancel_stream (rps_handle);
458 * This function is called, when the service sends another peer from the biased
460 * It calls the callback the caller provided
461 * and disconnects afterwards.
463 * TODO merge with check_view_update
465 * @param msg the message
468 check_stream_input (void *cls,
469 const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
471 uint16_t msize = ntohs (msg->header.size);
472 uint32_t num_peers = ntohl (msg->num_peers);
475 msize -= sizeof (struct GNUNET_RPS_CS_DEBUG_StreamReply);
476 if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) ||
477 (msize % sizeof (struct GNUNET_PeerIdentity) != 0) )
480 return GNUNET_SYSERR;
487 * @brief Called by the scheduler to call the callbacks of the srh handlers
489 * @param cls Stream request handle
492 srh_callback_scheduled (void *cls)
494 struct GNUNET_RPS_StreamRequestHandle *srh = cls;
496 srh->callback_task = NULL;
497 srh->ready_cb (srh->ready_cb_cls,
498 srh_callback_num_peers,
504 * This function is called, when the service sends another peer from the biased
506 * It calls the callback the caller provided
507 * and disconnects afterwards.
509 * @param msg the message
512 handle_stream_input (void *cls,
513 const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
515 struct GNUNET_RPS_Handle *h = cls;
516 //const struct GNUNET_PeerIdentity *peers;
518 struct GNUNET_RPS_StreamRequestHandle *srh_iter;
519 struct GNUNET_RPS_StreamRequestHandle *srh_next;
521 //peers = (struct GNUNET_PeerIdentity *) &msg[1];
522 num_peers = ntohl (msg->num_peers);
523 srh_callback_num_peers = num_peers;
524 GNUNET_free_non_null (srh_callback_peers);
525 srh_callback_peers = GNUNET_new_array (num_peers,
526 struct GNUNET_PeerIdentity);
527 GNUNET_memcpy (srh_callback_peers,
529 num_peers * sizeof (struct GNUNET_PeerIdentity));
530 LOG (GNUNET_ERROR_TYPE_DEBUG,
531 "Received %" PRIu64 " peer(s) from stream input.\n",
533 for (srh_iter = h->stream_requests_head;
537 LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n");
538 /* Store next pointer - srh might be removed/freed in callback */
539 srh_next = srh_iter->next;
540 if (NULL != srh_iter->callback_task)
541 GNUNET_SCHEDULER_cancel (srh_iter->callback_task);
542 srh_iter->callback_task =
543 GNUNET_SCHEDULER_add_now (&srh_callback_scheduled,
547 if (NULL == h->stream_requests_head)
555 * Reconnect to the service
558 reconnect (struct GNUNET_RPS_Handle *h);
562 * Error handler for mq.
564 * This function is called whan mq encounters an error.
565 * Until now mq doesn't provide useful error messages.
567 * @param cls the closure
568 * @param error error code without specyfied meaning
571 mq_error_handler (void *cls,
572 enum GNUNET_MQ_Error error)
574 struct GNUNET_RPS_Handle *h = cls;
576 LOG (GNUNET_ERROR_TYPE_WARNING, "Problem with message queue. error: %i\n\
580 // TODO: write GNUNET_MQ_strerror (error)
583 /* Resend all pending request as the service destroyed its knowledge
589 * @brief Create the hash value from the share value that defines the sub
592 * @param share_val Share value
593 * @param hash[out] Pointer to the location in which the hash will be stored.
596 hash_from_share_val (const char *share_val,
597 struct GNUNET_HashCode *hash)
599 GNUNET_CRYPTO_kdf (hash,
600 sizeof (struct GNUNET_HashCode),
610 * Reconnect to the service
613 reconnect (struct GNUNET_RPS_Handle *h)
615 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
616 GNUNET_MQ_hd_var_size (view_update,
617 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY,
618 struct GNUNET_RPS_CS_DEBUG_ViewReply,
620 GNUNET_MQ_hd_var_size (stream_input,
621 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY,
622 struct GNUNET_RPS_CS_DEBUG_StreamReply,
624 GNUNET_MQ_handler_end ()
628 GNUNET_MQ_destroy (h->mq);
629 h->mq = GNUNET_CLIENT_connect (h->cfg,
638 * Connect to the rps service
640 * @param cfg configuration to use
641 * @return a handle to the service
643 struct GNUNET_RPS_Handle *
644 GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
646 struct GNUNET_RPS_Handle *h;
648 h = GNUNET_new (struct GNUNET_RPS_Handle);
661 * @brief Start a sub with the given shared value
663 * @param h Handle to rps
664 * @param shared_value The shared value that defines the members of the sub (-gorup)
667 GNUNET_RPS_sub_start (struct GNUNET_RPS_Handle *h,
668 const char *shared_value)
670 struct GNUNET_RPS_CS_SubStartMessage *msg;
671 struct GNUNET_MQ_Envelope *ev;
673 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START);
674 hash_from_share_val (shared_value, &msg->hash);
675 msg->round_interval = GNUNET_TIME_relative_hton (// TODO read from config!
676 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30));
677 GNUNET_assert (0 != msg->round_interval.rel_value_us__);
679 GNUNET_MQ_send (h->mq, ev);
684 * @brief Stop a sub with the given shared value
686 * @param h Handle to rps
687 * @param shared_value The shared value that defines the members of the sub (-gorup)
690 GNUNET_RPS_sub_stop (struct GNUNET_RPS_Handle *h,
691 const char *shared_value)
693 struct GNUNET_RPS_CS_SubStopMessage *msg;
694 struct GNUNET_MQ_Envelope *ev;
696 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP);
697 hash_from_share_val (shared_value, &msg->hash);
699 GNUNET_MQ_send (h->mq, ev);
704 * Request n random peers.
706 * @param rps_handle handle to the rps service
707 * @param num_req_peers number of peers we want to receive
708 * @param ready_cb the callback called when the peers are available
709 * @param cls closure given to the callback
710 * @return a handle to cancel this request
712 struct GNUNET_RPS_Request_Handle *
713 GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
714 uint32_t num_req_peers,
715 GNUNET_RPS_NotifyReadyCB ready_cb,
718 struct GNUNET_RPS_Request_Handle *rh;
720 LOG (GNUNET_ERROR_TYPE_INFO,
721 "Client requested %" PRIu32 " peers\n",
723 rh = GNUNET_new (struct GNUNET_RPS_Request_Handle);
724 rh->rps_handle = rps_handle;
725 rh->num_requests = num_req_peers;
726 rh->sampler = RPS_sampler_mod_init (num_req_peers,
727 GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff
728 rh->sampler_rh = RPS_sampler_get_n_rand_peers (rh->sampler,
732 rh->srh = GNUNET_RPS_stream_request (rps_handle,
735 rh->ready_cb = ready_cb;
736 rh->ready_cb_cls = cls;
743 * Seed rps service with peerIDs.
745 * @param h handle to the rps service
746 * @param n number of peers to seed
747 * @param ids the ids of the peers seeded
750 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
752 const struct GNUNET_PeerIdentity *ids)
755 uint32_t num_peers_max;
756 const struct GNUNET_PeerIdentity *tmp_peer_pointer;
757 struct GNUNET_MQ_Envelope *ev;
758 struct GNUNET_RPS_CS_SeedMessage *msg;
760 LOG (GNUNET_ERROR_TYPE_DEBUG,
761 "Client wants to seed %" PRIu32 " peers:\n",
763 for (unsigned int i = 0 ; i < n ; i++)
764 LOG (GNUNET_ERROR_TYPE_DEBUG,
767 GNUNET_i2s (&ids[i]));
769 /* The actual size the message occupies */
770 size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
771 n * sizeof (struct GNUNET_PeerIdentity);
772 /* The number of peers that fits in one message together with
773 * the respective header */
774 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE -
775 sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
776 sizeof (struct GNUNET_PeerIdentity);
777 tmp_peer_pointer = ids;
779 while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
781 ev = GNUNET_MQ_msg_extra (msg,
782 num_peers_max * sizeof (struct GNUNET_PeerIdentity),
783 GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
784 msg->num_peers = htonl (num_peers_max);
785 GNUNET_memcpy (&msg[1],
787 num_peers_max * sizeof (struct GNUNET_PeerIdentity));
788 GNUNET_MQ_send (h->mq,
791 size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
792 n * sizeof (struct GNUNET_PeerIdentity);
793 /* Set pointer to beginning of next block of num_peers_max peers */
794 tmp_peer_pointer = &ids[num_peers_max];
797 ev = GNUNET_MQ_msg_extra (msg,
798 n * sizeof (struct GNUNET_PeerIdentity),
799 GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
800 msg->num_peers = htonl (n);
801 GNUNET_memcpy (&msg[1],
803 n * sizeof (struct GNUNET_PeerIdentity));
804 GNUNET_MQ_send (h->mq,
811 * Turn RPS service to act malicious.
813 * @param h handle to the rps service
814 * @param type which type of malicious peer to turn to.
815 * 0 Don't act malicious at all
816 * 1 Try to maximise representation
817 * 2 Try to partition the network
818 * (isolate one peer from the rest)
819 * @param n number of @a ids
820 * @param ids the ids of the malicious peers
821 * if @type is 2 the last id is the id of the
822 * peer to be isolated from the rest
825 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
828 const struct GNUNET_PeerIdentity *peer_ids,
829 const struct GNUNET_PeerIdentity *target_peer)
832 uint32_t num_peers_max;
833 const struct GNUNET_PeerIdentity *tmp_peer_pointer;
834 struct GNUNET_MQ_Envelope *ev;
835 struct GNUNET_RPS_CS_ActMaliciousMessage *msg;
839 LOG (GNUNET_ERROR_TYPE_DEBUG,
840 "Client turns malicious (type %" PRIu32 ") with %" PRIu32 " other peers:\n",
843 for (i = 0 ; i < num_peers ; i++)
844 LOG (GNUNET_ERROR_TYPE_DEBUG,
847 GNUNET_i2s (&peer_ids[i]));
849 /* The actual size the message would occupy */
850 size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
851 num_peers * sizeof (struct GNUNET_PeerIdentity);
852 /* The number of peers that fit in one message together with
853 * the respective header */
854 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE -
855 sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
856 sizeof (struct GNUNET_PeerIdentity);
857 tmp_peer_pointer = peer_ids;
859 while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
861 LOG (GNUNET_ERROR_TYPE_DEBUG,
862 "Too many peers to send at once, sending %" PRIu32 " (all we can so far)\n",
864 ev = GNUNET_MQ_msg_extra (msg,
865 num_peers_max * sizeof (struct GNUNET_PeerIdentity),
866 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
867 msg->type = htonl (type);
868 msg->num_peers = htonl (num_peers_max);
871 msg->attacked_peer = peer_ids[num_peers];
872 GNUNET_memcpy (&msg[1],
874 num_peers_max * sizeof (struct GNUNET_PeerIdentity));
876 GNUNET_MQ_send (h->mq, ev);
878 num_peers -= num_peers_max;
879 size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
880 num_peers * sizeof (struct GNUNET_PeerIdentity);
881 /* Set pointer to beginning of next block of num_peers_max peers */
882 tmp_peer_pointer = &peer_ids[num_peers_max];
885 ev = GNUNET_MQ_msg_extra (msg,
886 num_peers * sizeof (struct GNUNET_PeerIdentity),
887 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
888 msg->type = htonl (type);
889 msg->num_peers = htonl (num_peers);
892 msg->attacked_peer = *target_peer;
893 GNUNET_memcpy (&msg[1],
895 num_peers * sizeof (struct GNUNET_PeerIdentity));
897 GNUNET_MQ_send (h->mq, ev);
899 #endif /* ENABLE_MALICIOUS */
903 * Cancle an issued request.
905 * @param rh request handle of request to cancle
908 GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
910 struct GNUNET_RPS_Handle *h;
913 GNUNET_assert (NULL != rh);
914 GNUNET_assert (h == rh->srh->rps_handle);
915 GNUNET_RPS_stream_cancel (rh->srh);
917 if (NULL == h->stream_requests_head) cancel_stream(h);
918 if (NULL != rh->sampler_rh)
920 RPS_sampler_request_cancel (rh->sampler_rh);
922 RPS_sampler_destroy (rh->sampler);
928 * Disconnect from the rps service
930 * @param h the handle to the rps service
933 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
935 if (NULL != h->stream_requests_head)
937 struct GNUNET_RPS_StreamRequestHandle *srh_next;
939 LOG (GNUNET_ERROR_TYPE_WARNING,
940 "Still waiting for replies\n");
941 for (struct GNUNET_RPS_StreamRequestHandle *srh_iter = h->stream_requests_head;
945 srh_next = srh_iter->next;
946 GNUNET_RPS_stream_cancel (srh_iter);
949 if (NULL != srh_callback_peers)
951 GNUNET_free (srh_callback_peers);
952 srh_callback_peers = NULL;
954 if (NULL != h->view_update_cb)
956 LOG (GNUNET_ERROR_TYPE_WARNING,
957 "Still waiting for view updates\n");
958 GNUNET_RPS_view_request_cancel (h);
960 GNUNET_MQ_destroy (h->mq);
965 /* end of rps_api.c */