2 This file is part of GNUnet.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file rps/gnunet-service-rps.c
23 * @brief rps service implementation
24 * @author Julius Bünger
27 #include "gnunet_util_lib.h"
28 #include "gnunet_cadet_service.h"
29 #include "gnunet_nse_service.h"
32 #include "gnunet-service-rps_sampler.h"
37 #define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__)
39 // TODO modify @brief in every file
41 // TODO check for overflows
43 // TODO align message structs
45 // TODO connect to friends
47 // TODO store peers somewhere persistent
49 // TODO blacklist? (-> mal peer detection on top of brahms)
51 // TODO API request_cancel
53 // hist_size_init, hist_size_max
58 static const struct GNUNET_CONFIGURATION_Handle *cfg;
63 static struct GNUNET_PeerIdentity own_identity;
66 struct GNUNET_PeerIdentity *
67 get_rand_peer_ignore_list (const struct GNUNET_PeerIdentity *peer_list, unsigned int size,
68 const struct GNUNET_PeerIdentity *ignore_list, unsigned int ignore_size);
71 /***********************************************************************
72 * Housekeeping with peers
73 ***********************************************************************/
76 * Struct used to store the context of a connected client.
81 * The message queue to communicate with the client.
83 struct GNUNET_MQ_Handle *mq;
87 * Used to keep track in what lists single peerIDs are.
91 PULL_REPLY_PENDING = 0x01,
92 IN_OTHER_GOSSIP_LIST = 0x02, // unneeded?
93 IN_OWN_SAMPLER_LIST = 0x04, // unneeded?
94 IN_OWN_GOSSIP_LIST = 0x08, // unneeded?
97 * We set this bit when we can be sure the other peer is/was live.
104 * Functions of this type can be used to be stored at a peer for later execution.
106 typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
109 * Outstanding operation on peer consisting of callback and closure
111 struct PeerOutstandingOp
126 * Struct used to keep track of other peer's status
128 * This is stored in a multipeermap.
133 * In own gossip/sampler list, in other's gossip/sampler list
138 * Message queue open to client
140 struct GNUNET_MQ_Handle *mq;
143 * Channel open to client.
145 struct GNUNET_CADET_Channel *send_channel;
148 * Channel open from client.
150 struct GNUNET_CADET_Channel *recv_channel; // unneeded?
153 * Array of outstanding operations on this peer.
155 struct PeerOutstandingOp *outstanding_ops;
158 * Number of outstanding operations.
160 unsigned int num_outstanding_ops;
161 //size_t num_outstanding_ops;
164 * Handle to the callback given to cadet_ntfy_tmt_rdy()
166 * To be canceled on shutdown.
168 struct GNUNET_CADET_TransmitHandle *is_live_task;
171 * Identity of the peer
173 struct GNUNET_PeerIdentity peer_id;
176 * This is pobably followed by 'statistical' data (when we first saw
177 * him, how did we get his ID, how many pushes (in a timeinterval),
182 /***********************************************************************
183 * /Housekeeping with peers
184 ***********************************************************************/
190 /***********************************************************************
192 ***********************************************************************/
195 * Sampler used for the Brahms protocol itself.
197 static struct RPS_Sampler *prot_sampler;
200 * Sampler used for the clients.
202 static struct RPS_Sampler *client_sampler;
205 * Set of all peers to keep track of them.
207 static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
211 * The gossiped list of peers.
213 static struct GNUNET_PeerIdentity *gossip_list;
216 * Size of the gossiped list
218 //static unsigned int gossip_list_size;
219 static uint32_t gossip_list_size;
223 * The size of sampler we need to be able to satisfy the client's need of
226 static unsigned int sampler_size_client_need;
229 * The size of sampler we need to be able to satisfy the Brahms protocol's
230 * need of random peers.
232 * This is directly taken as the #gossip_list_size on update of the
235 * This is one minimum size the sampler grows to.
237 static unsigned int sampler_size_est_need;
241 * Percentage of total peer number in the gossip list
242 * to send random PUSHes to
247 * Percentage of total peer number in the gossip list
248 * to send random PULLs to
253 * The percentage gamma of history updates.
254 * Simply 1 - alpha - beta
259 * Identifier for the main task that runs periodically.
261 static struct GNUNET_SCHEDULER_Task *do_round_task;
264 * Time inverval the do_round task runs in.
266 static struct GNUNET_TIME_Relative round_interval;
271 * List to store peers received through pushes temporary.
273 * TODO -> multipeermap
275 static struct GNUNET_PeerIdentity *push_list;
278 * Size of the push_list;
280 static unsigned int push_list_size;
281 //size_t push_list_size;
284 * List to store peers received through pulls temporary.
286 * TODO -> multipeermap
288 static struct GNUNET_PeerIdentity *pull_list;
291 * Size of the pull_list;
293 static unsigned int pull_list_size;
294 //size_t pull_list_size;
300 static struct GNUNET_NSE_Handle *nse;
305 static struct GNUNET_CADET_Handle *cadet_handle;
311 * Only needed in the beginning to check how many of the 64 deltas
314 static unsigned int req_counter;
317 * Time of the last request we received.
319 * Used to compute the expected request rate.
321 static struct GNUNET_TIME_Absolute last_request;
324 * Size of #request_deltas.
326 #define REQUEST_DELTAS_SIZE 64
327 static unsigned int request_deltas_size = REQUEST_DELTAS_SIZE;
330 * Last 64 deltas between requests
332 static struct GNUNET_TIME_Relative request_deltas[REQUEST_DELTAS_SIZE];
335 * The prediction of the rate of requests
337 static struct GNUNET_TIME_Relative request_rate;
341 * List with the peers we sent requests to.
343 struct GNUNET_PeerIdentity *pending_pull_reply_list;
346 * Size of #pending_pull_reply_list.
348 uint32_t pending_pull_reply_list_size;
352 * Number of history update tasks.
354 uint32_t num_hist_update_tasks;
358 * Closure used to pass the client and the id to the callback
359 * that replies to a client's request
364 * The identifier of the request
369 * The client handle to send the reply to
371 struct GNUNET_SERVER_Client *client;
375 #ifdef ENABLE_MALICIOUS
377 * Type of malicious peer
379 * 0 Don't act malicious at all - Default
380 * 1 Try to maximise representation
381 * 2 Try to partition the network
383 uint32_t mal_type = 0;
386 * Other malicious peers
388 static struct GNUNET_PeerIdentity *mal_peers = NULL;
391 * Hashmap of malicious peers used as set.
392 * Used to more efficiently check whether we know that peer.
394 static struct GNUNET_CONTAINER_MultiPeerMap *mal_peer_set = NULL;
397 * Number of other malicious peers
399 static uint32_t num_mal_peers = 0;
403 * If type is 2 This struct is used to store the attacked peers in a DLL
410 struct AttackedPeer *next;
411 struct AttackedPeer *prev;
416 struct GNUNET_PeerIdentity peer_id;
420 * If type is 2 this is the DLL of attacked peers
422 static struct AttackedPeer *att_peers_head = NULL;
423 static struct AttackedPeer *att_peers_tail = NULL;
426 * This index is used to point to an attacked peer to
427 * implement the round-robin-ish way to select attacked peers.
429 static struct AttackedPeer *att_peer_index = NULL;
432 * Hashmap of attacked peers used as set.
433 * Used to more efficiently check whether we know that peer.
435 static struct GNUNET_CONTAINER_MultiPeerMap *att_peer_set = NULL;
438 * Number of attacked peers
440 static uint32_t num_attacked_peers = 0;
444 * If type is 1 this is the attacked peer
446 static struct GNUNET_PeerIdentity attacked_peer;
449 * The limit of PUSHes we can send in one round.
450 * This is an assumption of the Brahms protocol and either implemented
453 * assumend to be the bandwidth limitation.
455 static uint32_t push_limit = 10000;
456 #endif /* ENABLE_MALICIOUS */
459 /***********************************************************************
461 ***********************************************************************/
468 /***********************************************************************
470 ***********************************************************************/
473 * Set a peer flag of given peer context.
475 #define set_peer_flag(peer_ctx, mask) (peer_ctx->peer_flags |= mask)
478 * Get peer flag of given peer context.
480 #define get_peer_flag(peer_ctx, mask) (peer_ctx->peer_flags & mask ? GNUNET_YES : GNUNET_NO)
483 * Unset flag of given peer context.
485 #define unset_peer_flag(peer_ctx, mask) (peer_ctx->peer_flags &= (~mask))
488 * Compute the minimum of two ints
490 #define min(x, y) ((x < y) ? x : y)
493 * Clean the send channel of a peer
496 peer_clean (const struct GNUNET_PeerIdentity *peer);
500 * Check if peer is already in peer array.
503 in_arr (const struct GNUNET_PeerIdentity *array,
504 unsigned int arr_size,
505 const struct GNUNET_PeerIdentity *peer)
507 GNUNET_assert (NULL != peer);
512 GNUNET_assert (NULL != array);
516 for (i = 0; i < arr_size ; i++)
517 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&array[i], peer))
524 * Print peerlist to log.
527 print_peer_list (struct GNUNET_PeerIdentity *list, unsigned int len)
531 LOG (GNUNET_ERROR_TYPE_DEBUG,
532 "Printing peer list of length %u at %p:\n",
535 for (i = 0 ; i < len ; i++)
537 LOG (GNUNET_ERROR_TYPE_DEBUG,
539 i, GNUNET_i2s (&list[i]));
545 * Remove peer from list.
548 rem_from_list (struct GNUNET_PeerIdentity **peer_list,
549 unsigned int *list_size,
550 const struct GNUNET_PeerIdentity *peer)
553 struct GNUNET_PeerIdentity *tmp;
557 LOG (GNUNET_ERROR_TYPE_DEBUG,
558 "Removing peer %s from list at %p\n",
562 for ( i = 0 ; i < *list_size ; i++ )
564 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&tmp[i], peer))
566 if (i < *list_size -1)
567 { /* Not at the last entry -- shift peers left */
568 memcpy (&tmp[i], &tmp[i +1],
569 ((*list_size) - i -1) * sizeof (struct GNUNET_PeerIdentity));
571 /* Remove last entry (should be now useless PeerID) */
572 GNUNET_array_grow (tmp, *list_size, (*list_size) -1);
579 * Get random peer from the given list but don't return one from the @a ignore_list.
581 struct GNUNET_PeerIdentity *
582 get_rand_peer_ignore_list (const struct GNUNET_PeerIdentity *peer_list,
584 const struct GNUNET_PeerIdentity *ignore_list,
585 uint32_t ignore_size)
589 struct GNUNET_PeerIdentity *tmp_peer_list;
590 struct GNUNET_PeerIdentity *peer;
592 GNUNET_assert (NULL != peer_list);
597 tmp_peer_list = NULL;
598 GNUNET_array_grow (tmp_peer_list, tmp_size, list_size);
599 memcpy (tmp_peer_list,
601 list_size * sizeof (struct GNUNET_PeerIdentity));
602 peer = GNUNET_new (struct GNUNET_PeerIdentity);
605 * Choose the r_index of the peer we want to return
606 * at random from the interval of the gossip list
608 r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
610 *peer = tmp_peer_list[r_index];
612 while (in_arr (ignore_list, ignore_size, peer))
614 rem_from_list (&tmp_peer_list, &tmp_size, peer);
616 print_peer_list (tmp_peer_list, tmp_size);
625 * Choose the r_index of the peer we want to return
626 * at random from the interval of the gossip list
628 r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
630 *peer = tmp_peer_list[r_index];
634 GNUNET_array_grow (tmp_peer_list, tmp_size, 0);
641 * Get the context of a peer. If not existing, create.
644 get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
645 const struct GNUNET_PeerIdentity *peer)
647 struct PeerContext *ctx;
649 if ( GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
651 ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer);
655 ctx = GNUNET_new (struct PeerContext);
658 ctx->send_channel = NULL;
659 ctx->recv_channel = NULL;
660 ctx->outstanding_ops = NULL;
661 ctx->num_outstanding_ops = 0;
662 ctx->is_live_task = NULL;
663 ctx->peer_id = *peer;
664 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx,
665 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
672 * Put random peer from sampler into the gossip list as history update.
675 hist_update (void *cls, struct GNUNET_PeerIdentity *ids, uint32_t num_peers)
677 GNUNET_assert (1 == num_peers);
679 if (gossip_list_size < sampler_size_est_need)
680 GNUNET_array_append (gossip_list, gossip_list_size, *ids);
682 if (0 < num_hist_update_tasks)
683 num_hist_update_tasks--;
688 * Set the peer flag to living and call the outstanding operations on this peer.
691 peer_is_live (struct PeerContext *peer_ctx)
693 struct GNUNET_PeerIdentity *peer;
695 /* Cancle is_live_task if still scheduled */
696 if (NULL != peer_ctx->is_live_task)
698 GNUNET_CADET_notify_transmit_ready_cancel (peer_ctx->is_live_task);
699 peer_ctx->is_live_task = NULL;
702 peer = &peer_ctx->peer_id;
703 set_peer_flag (peer_ctx, VALID);
705 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %s is live\n", GNUNET_i2s (peer));
707 if (0 < peer_ctx->num_outstanding_ops)
708 { /* Call outstanding operations */
711 for (i = 0 ; i < peer_ctx->num_outstanding_ops ; i++)
712 peer_ctx->outstanding_ops[i].op (peer_ctx->outstanding_ops[i].op_cls, peer);
713 GNUNET_array_grow (peer_ctx->outstanding_ops, peer_ctx->num_outstanding_ops, 0);
721 * Callback that is called when a channel was effectively established.
722 * This is given to ntfy_tmt_rdy and called when the channel was
723 * successfully established.
726 cadet_ntfy_tmt_rdy_cb (void *cls, size_t size, void *buf)
728 struct PeerContext *peer_ctx = (struct PeerContext *) cls;
730 peer_ctx->is_live_task = NULL;
731 LOG (GNUNET_ERROR_TYPE_DEBUG,
732 "Set ->is_live_task = NULL for peer %s\n",
733 GNUNET_i2s (&peer_ctx->peer_id));
738 peer_is_live (peer_ctx);
742 LOG (GNUNET_ERROR_TYPE_WARNING,
743 "Problems establishing a connection to peer %s in order to check liveliness\n",
744 GNUNET_i2s (&peer_ctx->peer_id));
745 // TODO reschedule? cleanup?
748 //if (NULL != peer_ctx->is_live_task)
750 // LOG (GNUNET_ERROR_TYPE_DEBUG,
751 // "Trying to cancle is_live_task for peer %s\n",
752 // GNUNET_i2s (&peer_ctx->peer_id));
753 // GNUNET_CADET_notify_transmit_ready_cancel (peer_ctx->is_live_task);
754 // peer_ctx->is_live_task = NULL;
762 * Get the channel of a peer. If not existing, create.
764 struct GNUNET_CADET_Channel *
765 get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
766 const struct GNUNET_PeerIdentity *peer)
768 struct PeerContext *peer_ctx;
770 peer_ctx = get_peer_ctx (peer_map, peer);
772 if (NULL == peer_ctx->send_channel)
774 LOG (GNUNET_ERROR_TYPE_DEBUG,
775 "Trying to establish channel to peer %s\n",
778 peer_ctx->send_channel =
779 GNUNET_CADET_channel_create (cadet_handle,
782 GNUNET_RPS_CADET_PORT,
783 GNUNET_CADET_OPTION_RELIABLE);
785 // do I have to explicitly put it in the peer_map?
786 (void) GNUNET_CONTAINER_multipeermap_put
790 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
792 return peer_ctx->send_channel;
797 * Get the message queue of a specific peer.
799 * If we already have a message queue open to this client,
800 * simply return it, otherways create one.
802 struct GNUNET_MQ_Handle *
803 get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
804 const struct GNUNET_PeerIdentity *peer_id)
806 struct PeerContext *peer_ctx;
808 peer_ctx = get_peer_ctx (peer_map, peer_id);
810 GNUNET_assert (NULL == peer_ctx->is_live_task);
812 if (NULL == peer_ctx->mq)
814 (void) get_channel (peer_map, peer_id);
815 peer_ctx->mq = GNUNET_CADET_mq_create (peer_ctx->send_channel);
816 //do I have to explicitly put it in the peer_map?
817 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer_id, peer_ctx,
818 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
825 * Issue check whether peer is live
827 * @param peer_ctx the context of the peer
830 check_peer_live (struct PeerContext *peer_ctx)
832 (void) get_channel (peer_map, &peer_ctx->peer_id);
833 LOG (GNUNET_ERROR_TYPE_DEBUG,
834 "Get informed about peer %s getting live\n",
835 GNUNET_i2s (&peer_ctx->peer_id));
836 if (NULL == peer_ctx->is_live_task)
838 peer_ctx->is_live_task =
839 GNUNET_CADET_notify_transmit_ready (peer_ctx->send_channel,
841 GNUNET_TIME_UNIT_FOREVER_REL,
842 sizeof (struct GNUNET_MessageHeader),
843 cadet_ntfy_tmt_rdy_cb,
848 LOG (GNUNET_ERROR_TYPE_DEBUG,
849 "Already waiting for notification\n");
855 * Sum all time relatives of an array.
857 struct GNUNET_TIME_Relative
858 T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint32_t arr_size)
860 struct GNUNET_TIME_Relative sum;
863 sum = GNUNET_TIME_UNIT_ZERO;
864 for ( i = 0 ; i < arr_size ; i++ )
866 sum = GNUNET_TIME_relative_add (sum, rel_array[i]);
873 * Compute the average of given time relatives.
875 struct GNUNET_TIME_Relative
876 T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint32_t arr_size)
878 return GNUNET_TIME_relative_divide (T_relative_sum (rel_array, arr_size), arr_size);
883 * Insert PeerID in #pull_list
885 * Called once we know a peer is live.
888 insert_in_pull_list (void *cls, const struct GNUNET_PeerIdentity *peer)
890 if (GNUNET_NO == in_arr (pull_list, pull_list_size, peer))
891 GNUNET_array_append (pull_list, pull_list_size, *peer);
897 * Check whether #insert_in_pull_list was already scheduled
900 insert_in_pull_list_scheduled (const struct PeerContext *peer_ctx)
904 for ( i = 0 ; i < peer_ctx->num_outstanding_ops ; i++ )
905 if (insert_in_pull_list == peer_ctx->outstanding_ops[i].op)
912 * Insert PeerID in #gossip_list
914 * Called once we know a peer is live.
917 insert_in_gossip_list (void *cls, const struct GNUNET_PeerIdentity *peer)
919 if (GNUNET_NO == in_arr (gossip_list, gossip_list_size, peer))
920 GNUNET_array_append (gossip_list, gossip_list_size, *peer);
922 (void) get_channel (peer_map, peer);
926 * Check whether #insert_in_gossip_list was already scheduled
929 insert_in_gossip_list_scheduled (const struct PeerContext *peer_ctx)
933 for ( i = 0 ; i < peer_ctx->num_outstanding_ops ; i++ )
934 if (insert_in_gossip_list == peer_ctx->outstanding_ops[i].op)
941 * Update sampler with given PeerID.
944 insert_in_sampler (void *cls, const struct GNUNET_PeerIdentity *peer)
946 LOG (GNUNET_ERROR_TYPE_DEBUG,
947 "Updating samplers with peer %s from insert_in_sampler()\n",
949 RPS_sampler_update (prot_sampler, peer);
950 RPS_sampler_update (client_sampler, peer);
955 * Check whether #insert_in_sampler was already scheduled
958 insert_in_sampler_scheduled (const struct PeerContext *peer_ctx)
962 for (i = 0 ; i < peer_ctx->num_outstanding_ops ; i++)
963 if (insert_in_sampler== peer_ctx->outstanding_ops[i].op)
970 * Wrapper around #RPS_sampler_resize()
972 * If we do not have enough sampler elements, double current sampler size
973 * If we have more than enough sampler elements, halv current sampler size
976 resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size)
978 unsigned int sampler_size;
981 // TODO respect the min, max
982 sampler_size = RPS_sampler_get_size (sampler);
983 if (sampler_size > new_size * 4)
985 RPS_sampler_resize (sampler, sampler_size / 2);
987 else if (sampler_size < new_size)
989 RPS_sampler_resize (sampler, sampler_size * 2);
991 LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size);
996 * Wrapper around #RPS_sampler_resize() resizing the client sampler
999 client_resize_wrapper ()
1001 uint32_t bigger_size;
1002 unsigned int sampler_size;
1006 sampler_size = RPS_sampler_get_size (client_sampler);
1008 if (sampler_size_est_need > sampler_size_client_need)
1009 bigger_size = sampler_size_est_need;
1011 bigger_size = sampler_size_client_need;
1013 // TODO respect the min, max
1014 resize_wrapper (client_sampler, bigger_size);
1015 LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size);
1020 * Estimate request rate
1022 * Called every time we receive a request from the client.
1027 struct GNUNET_TIME_Relative max_round_duration;
1029 if (request_deltas_size > req_counter)
1031 if ( 1 < req_counter)
1033 /* Shift last request deltas to the right */
1034 memcpy (&request_deltas[1],
1036 (req_counter - 1) * sizeof (struct GNUNET_TIME_Relative));
1038 /* Add current delta to beginning */
1040 GNUNET_TIME_absolute_get_difference (last_request,
1041 GNUNET_TIME_absolute_get ());
1042 request_rate = T_relative_avg (request_deltas, req_counter);
1044 /* Compute the duration a round will maximally take */
1045 max_round_duration =
1046 GNUNET_TIME_relative_add (round_interval,
1047 GNUNET_TIME_relative_divide (round_interval, 2));
1049 /* Set the estimated size the sampler has to have to
1050 * satisfy the current client request rate */
1051 sampler_size_client_need =
1052 max_round_duration.rel_value_us / request_rate.rel_value_us;
1054 /* Resize the sampler */
1055 client_resize_wrapper ();
1057 last_request = GNUNET_TIME_absolute_get ();
1062 * Add all peers in @a peer_array to @a peer_map used as set.
1064 * @param peer_array array containing the peers
1065 * @param num_peers number of peers in @peer_array
1066 * @param peer_map the peermap to use as set
1069 add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array,
1070 unsigned int num_peers,
1071 struct GNUNET_CONTAINER_MultiPeerMap *peer_map)
1074 if (NULL == peer_map)
1075 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers + 1,
1077 for (i = 0 ; i < num_peers ; i++)
1079 GNUNET_CONTAINER_multipeermap_put (peer_map,
1082 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1088 * Send a PULL REPLY to @a peer_id
1090 * @param peer_id the peer to send the reply to.
1091 * @param peer_ids the peers to send to @a peer_id
1092 * @param num_peer_ids the number of peers to send to @a peer_id
1095 send_pull_reply (const struct GNUNET_PeerIdentity *peer_id,
1096 const struct GNUNET_PeerIdentity *peer_ids,
1097 unsigned int num_peer_ids)
1100 struct GNUNET_MQ_Handle *mq;
1101 struct GNUNET_MQ_Envelope *ev;
1102 struct GNUNET_RPS_P2P_PullReplyMessage *out_msg;
1104 /* Compute actual size */
1105 send_size = sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) +
1106 num_peer_ids * sizeof (struct GNUNET_PeerIdentity);
1108 if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size)
1109 /* Compute number of peers to send
1110 * If too long, simply truncate */
1111 // TODO select random ones via permutation
1112 // or even better: do good protocol design
1114 (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE -
1115 sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) /
1116 sizeof (struct GNUNET_PeerIdentity);
1118 send_size = num_peer_ids;
1120 LOG (GNUNET_ERROR_TYPE_DEBUG,
1121 "PULL REQUEST from peer %s received, going to send %u peers\n",
1122 GNUNET_i2s (peer_id), send_size);
1124 mq = get_mq (peer_map, peer_id);
1126 ev = GNUNET_MQ_msg_extra (out_msg,
1127 send_size * sizeof (struct GNUNET_PeerIdentity),
1128 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY);
1129 out_msg->num_peers = htonl (send_size);
1130 memcpy (&out_msg[1], peer_ids,
1131 send_size * sizeof (struct GNUNET_PeerIdentity));
1133 GNUNET_MQ_send (mq, ev);
1138 * This function is called on new peer_ids from 'external' sources
1139 * (client seed, cadet get_peers(), ...)
1141 * @param peer_id the new peer_id
1144 new_peer_id (const struct GNUNET_PeerIdentity *peer_id)
1146 struct PeerOutstandingOp out_op;
1147 struct PeerContext *peer_ctx;
1150 && 0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, peer_id))
1152 LOG (GNUNET_ERROR_TYPE_DEBUG,
1153 "Got peer_id %s (at %p, gossip_list_size: %u)\n",
1154 GNUNET_i2s (peer_id),
1158 peer_ctx = get_peer_ctx (peer_map, peer_id);
1159 if (GNUNET_YES != get_peer_flag (peer_ctx, VALID))
1161 if (GNUNET_NO == insert_in_sampler_scheduled (peer_ctx))
1163 out_op.op = insert_in_sampler;
1164 out_op.op_cls = NULL;
1165 GNUNET_array_append (peer_ctx->outstanding_ops,
1166 peer_ctx->num_outstanding_ops,
1170 if (GNUNET_NO == insert_in_gossip_list_scheduled (peer_ctx))
1172 out_op.op = insert_in_gossip_list;
1173 out_op.op_cls = NULL;
1174 GNUNET_array_append (peer_ctx->outstanding_ops,
1175 peer_ctx->num_outstanding_ops,
1179 /* Trigger livelyness test on peer */
1180 check_peer_live (peer_ctx);
1184 // send push/pull to each of those peers?
1189 /***********************************************************************
1191 ***********************************************************************/
1198 * Function called by NSE.
1200 * Updates sizes of sampler list and gossip list and adapt those lists
1204 nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp,
1205 double logestimate, double std_dev)
1208 //double scale; // TODO this might go gloabal/config
1210 LOG (GNUNET_ERROR_TYPE_DEBUG,
1211 "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n",
1212 logestimate, std_dev, RPS_sampler_get_size (prot_sampler));
1214 estimate = GNUNET_NSE_log_estimate_to_n (logestimate);
1215 // GNUNET_NSE_log_estimate_to_n (logestimate);
1216 estimate = pow (estimate, 1.0 / 3);
1217 // TODO add if std_dev is a number
1218 // estimate += (std_dev * scale);
1219 if (2 < ceil (estimate))
1221 LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate);
1222 sampler_size_est_need = estimate;
1224 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate);
1226 /* If the NSE has changed adapt the lists accordingly */
1227 resize_wrapper (prot_sampler, sampler_size_est_need);
1228 client_resize_wrapper ();
1233 * Callback called once the requested PeerIDs are ready.
1235 * Sends those to the requesting client.
1237 void client_respond (void *cls,
1238 struct GNUNET_PeerIdentity *peer_ids, uint32_t num_peers)
1240 struct GNUNET_MQ_Envelope *ev;
1241 struct GNUNET_RPS_CS_ReplyMessage *out_msg;
1242 struct ReplyCls *reply_cls = (struct ReplyCls *) cls;
1243 uint32_t size_needed;
1244 struct ClientContext *cli_ctx;
1246 LOG (GNUNET_ERROR_TYPE_DEBUG,
1247 "sampler returned %" PRIu32 " peers\n",
1250 size_needed = sizeof (struct GNUNET_RPS_CS_ReplyMessage) +
1251 num_peers * sizeof (struct GNUNET_PeerIdentity);
1253 GNUNET_assert (GNUNET_SERVER_MAX_MESSAGE_SIZE >= size_needed);
1255 ev = GNUNET_MQ_msg_extra (out_msg,
1256 num_peers * sizeof (struct GNUNET_PeerIdentity),
1257 GNUNET_MESSAGE_TYPE_RPS_CS_REPLY);
1258 out_msg->num_peers = htonl (num_peers);
1259 out_msg->id = htonl (reply_cls->id);
1261 memcpy (&out_msg[1],
1263 num_peers * sizeof (struct GNUNET_PeerIdentity));
1264 GNUNET_free (peer_ids);
1266 cli_ctx = GNUNET_SERVER_client_get_user_context (reply_cls->client, struct ClientContext);
1267 if (NULL == cli_ctx) {
1268 cli_ctx = GNUNET_new (struct ClientContext);
1269 cli_ctx->mq = GNUNET_MQ_queue_for_server_client (reply_cls->client);
1270 GNUNET_SERVER_client_set_user_context (reply_cls->client, cli_ctx);
1273 GNUNET_free (reply_cls);
1275 GNUNET_MQ_send (cli_ctx->mq, ev);
1280 * Handle RPS request from the client.
1282 * @param cls closure
1283 * @param client identification of the client
1284 * @param message the actual message
1287 handle_client_request (void *cls,
1288 struct GNUNET_SERVER_Client *client,
1289 const struct GNUNET_MessageHeader *message)
1291 struct GNUNET_RPS_CS_RequestMessage *msg;
1293 uint32_t size_needed;
1294 struct ReplyCls *reply_cls;
1297 msg = (struct GNUNET_RPS_CS_RequestMessage *) message;
1299 num_peers = ntohl (msg->num_peers);
1300 size_needed = sizeof (struct GNUNET_RPS_CS_RequestMessage) +
1301 num_peers * sizeof (struct GNUNET_PeerIdentity);
1303 if (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed)
1305 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1309 for (i = 0 ; i < num_peers ; i++)
1312 LOG (GNUNET_ERROR_TYPE_DEBUG,
1313 "Client requested %" PRIu32 " random peer(s).\n",
1316 reply_cls = GNUNET_new (struct ReplyCls);
1317 reply_cls->id = ntohl (msg->id);
1318 reply_cls->client = client;
1320 RPS_sampler_get_n_rand_peers (client_sampler,
1326 GNUNET_SERVER_receive_done (client,
1332 * Handle seed from the client.
1334 * @param cls closure
1335 * @param client identification of the client
1336 * @param message the actual message
1339 handle_client_seed (void *cls,
1340 struct GNUNET_SERVER_Client *client,
1341 const struct GNUNET_MessageHeader *message)
1343 struct GNUNET_RPS_CS_SeedMessage *in_msg;
1344 struct GNUNET_PeerIdentity *peers;
1348 if (sizeof (struct GNUNET_RPS_CS_SeedMessage) > ntohs (message->size))
1350 GNUNET_break_op (0);
1351 GNUNET_SERVER_receive_done (client,
1355 in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message;
1356 num_peers = ntohl (in_msg->num_peers);
1357 peers = (struct GNUNET_PeerIdentity *) &in_msg[1];
1358 //peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
1359 //memcpy (peers, &in_msg[1], num_peers * sizeof (struct GNUNET_PeerIdentity));
1361 if ((ntohs (message->size) - sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
1362 sizeof (struct GNUNET_PeerIdentity) != num_peers)
1364 GNUNET_break_op (0);
1365 GNUNET_SERVER_receive_done (client,
1369 LOG (GNUNET_ERROR_TYPE_DEBUG,
1370 "Client seeded peers:\n");
1371 print_peer_list (peers, num_peers);
1373 for (i = 0 ; i < num_peers ; i++)
1375 LOG (GNUNET_ERROR_TYPE_DEBUG,
1376 "Updating samplers with seed %" PRIu32 ": %s\n",
1378 GNUNET_i2s (&peers[i]));
1380 new_peer_id (&peers[i]);
1382 //RPS_sampler_update (prot_sampler, &peers[i]);
1383 //RPS_sampler_update (client_sampler, &peers[i]);
1386 ////GNUNET_free (peers);
1388 GNUNET_SERVER_receive_done (client,
1394 * Handle a PUSH message from another peer.
1396 * Check the proof of work and store the PeerID
1397 * in the temporary list for pushed PeerIDs.
1399 * @param cls Closure
1400 * @param channel The channel the PUSH was received over
1401 * @param channel_ctx The context associated with this channel
1402 * @param msg The message header
1405 handle_peer_push (void *cls,
1406 struct GNUNET_CADET_Channel *channel,
1408 const struct GNUNET_MessageHeader *msg)
1410 const struct GNUNET_PeerIdentity *peer;
1412 // (check the proof of work)
1414 peer = (const struct GNUNET_PeerIdentity *)
1415 GNUNET_CADET_channel_get_info (channel, GNUNET_CADET_OPTION_PEER);
1416 // FIXME wait for cadet to change this function
1418 LOG (GNUNET_ERROR_TYPE_DEBUG, "PUSH received (%s)\n", GNUNET_i2s (peer));
1420 #ifdef ENABLE_MALICIOUS
1421 struct AttackedPeer *tmp_att_peer;
1423 tmp_att_peer = GNUNET_new (struct AttackedPeer);
1424 memcpy (&tmp_att_peer->peer_id, peer, sizeof (struct GNUNET_PeerIdentity));
1426 { /* Try to maximise representation */
1427 if (NULL == att_peer_set)
1428 att_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO);
1429 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set,
1432 GNUNET_CONTAINER_DLL_insert (att_peers_head,
1435 add_peer_array_to_set (peer, 1, att_peer_set);
1441 else if (2 == mal_type)
1442 { /* We attack one single well-known peer - simply ignore */
1446 #endif /* ENABLE_MALICIOUS */
1448 /* Add the sending peer to the push_list */
1449 if (GNUNET_NO == in_arr (push_list, push_list_size, peer))
1450 GNUNET_array_append (push_list, push_list_size, *peer);
1457 * Handle PULL REQUEST request message from another peer.
1459 * Reply with the gossip list of PeerIDs.
1461 * @param cls Closure
1462 * @param channel The channel the PUSH was received over
1463 * @param channel_ctx The context associated with this channel
1464 * @param msg The message header
1467 handle_peer_pull_request (void *cls,
1468 struct GNUNET_CADET_Channel *channel,
1470 const struct GNUNET_MessageHeader *msg)
1472 struct GNUNET_PeerIdentity *peer;
1474 peer = (struct GNUNET_PeerIdentity *)
1475 GNUNET_CADET_channel_get_info (channel,
1476 GNUNET_CADET_OPTION_PEER);
1477 // FIXME wait for cadet to change this function
1479 #ifdef ENABLE_MALICIOUS
1481 { /* Try to maximise representation */
1482 send_pull_reply (peer, mal_peers, num_mal_peers);
1486 else if (2 == mal_type)
1487 { /* Try to partition network */
1488 if (GNUNET_YES == GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer))
1490 send_pull_reply (peer, mal_peers, num_mal_peers);
1494 #endif /* ENABLE_MALICIOUS */
1496 send_pull_reply (peer, gossip_list, gossip_list_size);
1503 * Handle PULL REPLY message from another peer.
1505 * Check whether we sent a corresponding request and
1506 * whether this reply is the first one.
1508 * @param cls Closure
1509 * @param channel The channel the PUSH was received over
1510 * @param channel_ctx The context associated with this channel
1511 * @param msg The message header
1514 handle_peer_pull_reply (void *cls,
1515 struct GNUNET_CADET_Channel *channel,
1517 const struct GNUNET_MessageHeader *msg)
1519 struct GNUNET_RPS_P2P_PullReplyMessage *in_msg;
1520 struct GNUNET_PeerIdentity *peers;
1521 struct PeerContext *peer_ctx;
1522 struct GNUNET_PeerIdentity *sender;
1523 struct PeerContext *sender_ctx;
1524 struct PeerOutstandingOp out_op;
1526 #ifdef ENABLE_MALICIOUS
1527 struct AttackedPeer *tmp_att_peer;
1528 #endif /* ENABLE_MALICIOUS */
1530 /* Check for protocol violation */
1531 if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size))
1533 GNUNET_break_op (0);
1534 return GNUNET_SYSERR;
1537 in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg;
1538 if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) /
1539 sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers))
1541 LOG (GNUNET_ERROR_TYPE_ERROR,
1542 "message says it sends %" PRIu64 " peers, have space for %i peers\n",
1543 ntohl (in_msg->num_peers),
1544 (ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) /
1545 sizeof (struct GNUNET_PeerIdentity));
1546 GNUNET_break_op (0);
1547 return GNUNET_SYSERR;
1550 sender = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (
1551 (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER);
1552 // Guess simply casting isn't the nicest way...
1553 // FIXME wait for cadet to change this function
1554 sender_ctx = get_peer_ctx (peer_map, sender);
1556 if (GNUNET_YES == get_peer_flag (sender_ctx, PULL_REPLY_PENDING))
1558 GNUNET_break_op (0);
1563 #ifdef ENABLE_MALICIOUS
1564 // We shouldn't even receive pull replies as we're not sending
1567 #endif /* ENABLE_MALICIOUS */
1569 /* Do actual logic */
1570 peers = (struct GNUNET_PeerIdentity *) &msg[1];
1572 LOG (GNUNET_ERROR_TYPE_DEBUG,
1573 "PULL REPLY received, got following peers:\n");
1575 for (i = 0 ; i < ntohl (in_msg->num_peers) ; i++)
1577 LOG (GNUNET_ERROR_TYPE_DEBUG,
1580 GNUNET_i2s (&peers[i]));
1582 #ifdef ENABLE_MALICIOUS
1585 // TODO check if we sent a request and this was the first reply
1586 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set,
1588 && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set,
1590 && GNUNET_NO == GNUNET_CRYPTO_cmp_peer_identity (&peers[i],
1593 tmp_att_peer = GNUNET_new (struct AttackedPeer);
1594 tmp_att_peer->peer_id = peers[i];
1595 GNUNET_CONTAINER_DLL_insert (att_peers_head,
1598 add_peer_array_to_set (&peers[i], 1, att_peer_set);
1602 #endif /* ENABLE_MALICIOUS */
1603 peer_ctx = get_peer_ctx (peer_map, &peers[i]);
1604 if (GNUNET_YES == get_peer_flag (peer_ctx, VALID)
1605 || NULL != peer_ctx->send_channel
1606 || NULL != peer_ctx->recv_channel)
1608 if (GNUNET_NO == in_arr (pull_list, pull_list_size, &peers[i])
1609 && 0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peers[i]))
1610 GNUNET_array_append (pull_list, pull_list_size, peers[i]);
1612 else if (GNUNET_NO == insert_in_pull_list_scheduled (peer_ctx))
1614 out_op.op = insert_in_pull_list;
1615 out_op.op_cls = NULL;
1616 GNUNET_array_append (peer_ctx->outstanding_ops,
1617 peer_ctx->num_outstanding_ops,
1619 check_peer_live (peer_ctx);
1623 unset_peer_flag (sender_ctx, PULL_REPLY_PENDING);
1624 rem_from_list (&pending_pull_reply_list, &pending_pull_reply_list_size, sender);
1631 * Compute a random delay.
1632 * A uniformly distributed value between mean + spread and mean - spread.
1634 * For example for mean 4 min and spread 2 the minimum is (4 min - (1/2 * 4 min))
1635 * It would return a random value between 2 and 6 min.
1637 * @param mean the mean
1638 * @param spread the inverse amount of deviation from the mean
1640 static struct GNUNET_TIME_Relative
1641 compute_rand_delay (struct GNUNET_TIME_Relative mean, unsigned int spread)
1643 struct GNUNET_TIME_Relative half_interval;
1644 struct GNUNET_TIME_Relative ret;
1645 unsigned int rand_delay;
1646 unsigned int max_rand_delay;
1650 LOG (GNUNET_ERROR_TYPE_WARNING,
1651 "Not accepting spread of 0\n");
1655 /* Compute random time value between spread * mean and spread * mean */
1656 half_interval = GNUNET_TIME_relative_divide (mean, spread);
1658 max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us / mean.rel_value_us * (2/spread);
1660 * Compute random value between (0 and 1) * round_interval
1661 * via multiplying round_interval with a 'fraction' (0 to value)/value
1663 rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max_rand_delay);
1664 ret = GNUNET_TIME_relative_multiply (mean, rand_delay);
1665 ret = GNUNET_TIME_relative_divide (ret, max_rand_delay);
1666 ret = GNUNET_TIME_relative_add (ret, half_interval);
1668 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us)
1669 LOG (GNUNET_ERROR_TYPE_WARNING,
1670 "Returning FOREVER_REL\n");
1677 * Send single pull request
1679 * @param peer_id the peer to send the pull request to.
1682 send_pull_request (struct GNUNET_PeerIdentity *peer_id)
1684 struct GNUNET_MQ_Envelope *ev;
1685 struct GNUNET_MQ_Handle *mq;
1687 LOG (GNUNET_ERROR_TYPE_DEBUG,
1688 "Sending PULL request to peer %s of gossiped list.\n",
1689 GNUNET_i2s (peer_id));
1691 GNUNET_array_append (pending_pull_reply_list, pending_pull_reply_list_size, *peer_id);
1693 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST);
1694 mq = get_mq (peer_map, peer_id);
1695 GNUNET_MQ_send (mq, ev);
1702 * @param peer_id the peer to send the push to.
1705 send_push (struct GNUNET_PeerIdentity *peer_id)
1707 struct GNUNET_MQ_Envelope *ev;
1708 struct GNUNET_MQ_Handle *mq;
1710 LOG (GNUNET_ERROR_TYPE_DEBUG,
1711 "Sending PUSH to peer %s of gossiped list.\n",
1712 GNUNET_i2s (peer_id));
1714 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH);
1715 mq = get_mq (peer_map, peer_id);
1716 GNUNET_MQ_send (mq, ev);
1721 do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1724 do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1727 #ifdef ENABLE_MALICIOUS
1729 * Turn RPS service to act malicious.
1731 * @param cls Closure
1732 * @param channel The channel the PUSH was received over
1733 * @param channel_ctx The context associated with this channel
1734 * @param msg The message header
1737 handle_client_act_malicious (void *cls,
1738 struct GNUNET_SERVER_Client *client,
1739 const struct GNUNET_MessageHeader *msg)
1741 struct GNUNET_RPS_CS_ActMaliciousMessage *in_msg;
1742 struct GNUNET_PeerIdentity *peers;
1743 uint32_t num_mal_peers_sent;
1744 uint32_t num_mal_peers_old;
1746 /* Check for protocol violation */
1747 if (sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage) > ntohs (msg->size))
1749 GNUNET_break_op (0);
1752 in_msg = (struct GNUNET_RPS_CS_ActMaliciousMessage *) msg;
1753 if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) /
1754 sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers))
1756 LOG (GNUNET_ERROR_TYPE_ERROR,
1757 "message says it sends %" PRIu64 " peers, have space for %i peers\n",
1758 ntohl (in_msg->num_peers),
1759 (ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) /
1760 sizeof (struct GNUNET_PeerIdentity));
1761 GNUNET_break_op (0);
1765 /* Do actual logic */
1766 peers = (struct GNUNET_PeerIdentity *) &msg[1];
1767 mal_type = ntohl (in_msg->type);
1769 LOG (GNUNET_ERROR_TYPE_DEBUG,
1770 "Now acting malicious type %" PRIu32 "\n",
1774 { /* Try to maximise representation */
1775 /* Add other malicious peers to those we already know */
1777 num_mal_peers_sent = ntohl (in_msg->num_peers);
1778 num_mal_peers_old = num_mal_peers;
1779 GNUNET_array_grow (mal_peers,
1781 num_mal_peers + num_mal_peers_sent);
1782 memcpy (&mal_peers[num_mal_peers_old],
1784 num_mal_peers_sent * sizeof (struct GNUNET_PeerIdentity));
1786 /* Add all mal peers to mal_peer_set */
1787 add_peer_array_to_set (&mal_peers[num_mal_peers_old],
1791 /* Substitute do_round () with do_mal_round () */
1792 GNUNET_SCHEDULER_cancel (do_round_task);
1793 do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, NULL);
1796 else if (2 == mal_type)
1797 { /* Try to partition the network */
1798 /* Add other malicious peers to those we already know */
1799 num_mal_peers_sent = ntohl (in_msg->num_peers) - 1;
1800 num_mal_peers_old = num_mal_peers;
1801 GNUNET_array_grow (mal_peers,
1803 num_mal_peers + num_mal_peers_sent);
1804 memcpy (&mal_peers[num_mal_peers_old],
1806 num_mal_peers_sent * sizeof (struct GNUNET_PeerIdentity));
1808 /* Add all mal peers to mal_peer_set */
1809 add_peer_array_to_set (&mal_peers[num_mal_peers_old],
1813 /* Store the one attacked peer */
1814 memcpy (&attacked_peer,
1815 &in_msg->attacked_peer,
1816 sizeof (struct GNUNET_PeerIdentity));
1818 LOG (GNUNET_ERROR_TYPE_DEBUG,
1819 "Attacked peer is %s\n",
1820 GNUNET_i2s (&attacked_peer));
1822 /* Substitute do_round () with do_mal_round () */
1823 GNUNET_SCHEDULER_cancel (do_round_task);
1824 do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, NULL);
1826 else if (0 == mal_type)
1827 { /* Stop acting malicious */
1828 GNUNET_array_grow (mal_peers, num_mal_peers, 0);
1830 /* Substitute do_mal_round () with do_round () */
1831 GNUNET_SCHEDULER_cancel (do_round_task);
1832 do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL);
1839 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1844 * Send out PUSHes and PULLs maliciously.
1846 * This is executed regylary.
1849 do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1851 uint32_t num_pushes;
1853 struct GNUNET_TIME_Relative time_next_round;
1854 struct AttackedPeer *tmp_att_peer;
1856 LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round maliciously.\n");
1858 /* Do malicious actions */
1860 { /* Try to maximise representation */
1862 /* The maximum of pushes we're going to send this round */
1863 num_pushes = min (min (push_limit,
1864 num_attacked_peers),
1865 GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE);
1867 /* Send PUSHes to attacked peers */
1868 for (i = 0 ; i < num_pushes ; i++)
1870 if (att_peers_tail == att_peer_index)
1871 att_peer_index = att_peers_head;
1873 att_peer_index = att_peer_index->next;
1875 send_push (&att_peer_index->peer_id);
1878 /* Send PULLs to some peers to learn about additional peers to attack */
1879 for (i = 0 ; i < num_pushes * alpha ; i++)
1881 if (att_peers_tail == tmp_att_peer)
1882 tmp_att_peer = att_peers_head;
1884 att_peer_index = tmp_att_peer->next;
1886 send_pull_request (&tmp_att_peer->peer_id);
1891 else if (2 == mal_type)
1893 * Try to partition the network
1894 * Send as many pushes to the attacked peer as possible
1895 * That is one push per round as it will ignore more.
1897 send_push (&attacked_peer);
1901 /* Schedule next round */
1902 time_next_round = compute_rand_delay (round_interval, 2);
1904 //do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_mal_round, NULL);
1905 do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, &do_mal_round, NULL);
1906 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
1908 #endif /* ENABLE_MALICIOUS */
1912 * Send out PUSHes and PULLs, possibly update #gossip_list, samplers.
1914 * This is executed regylary.
1917 do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1919 LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round.\n");
1922 unsigned int *permut;
1923 unsigned int n_peers; /* Number of peers we send pushes/pulls to */
1924 struct GNUNET_PeerIdentity peer;
1925 struct GNUNET_PeerIdentity *tmp_peer;
1927 LOG (GNUNET_ERROR_TYPE_DEBUG,
1928 "Printing gossip list:\n");
1929 for (i = 0 ; i < gossip_list_size ; i++)
1930 LOG (GNUNET_ERROR_TYPE_DEBUG,
1931 "\t%s\n", GNUNET_i2s (&gossip_list[i]));
1932 // TODO log lists, ...
1934 /* Would it make sense to have one shuffeled gossip list and then
1935 * to send PUSHes to first alpha peers, PULL requests to next beta peers and
1936 * use the rest to update sampler?
1937 * in essence get random peers with consumption */
1940 if (0 < gossip_list_size)
1942 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG,
1943 (unsigned int) gossip_list_size);
1944 n_peers = ceil (alpha * gossip_list_size);
1945 LOG (GNUNET_ERROR_TYPE_DEBUG,
1946 "Going to send pushes to %u (ceil (%f * %u)) peers.\n",
1947 n_peers, alpha, gossip_list_size);
1948 for (i = 0 ; i < n_peers ; i++)
1950 peer = gossip_list[permut[i]];
1951 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) // TODO
1952 { // FIXME if this fails schedule/loop this for later
1956 GNUNET_free (permut);
1960 /* Send PULL requests */
1961 //permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, (unsigned int) sampler_list->size);
1962 n_peers = ceil (beta * gossip_list_size);
1963 LOG (GNUNET_ERROR_TYPE_DEBUG,
1964 "Going to send pulls to %u (ceil (%f * %u)) peers.\n",
1965 n_peers, beta, gossip_list_size);
1966 for (i = 0 ; i < n_peers ; i++)
1968 tmp_peer = get_rand_peer_ignore_list (gossip_list, gossip_list_size,
1969 pending_pull_reply_list, pending_pull_reply_list_size);
1970 if (NULL != tmp_peer)
1973 GNUNET_free (tmp_peer);
1975 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer))
1977 send_pull_request (&peer);
1983 /* Update gossip list */
1985 if (push_list_size <= alpha * gossip_list_size
1986 && push_list_size > 0
1987 && pull_list_size > 0)
1989 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the gossip list.\n");
1991 uint32_t first_border;
1992 uint32_t second_border;
1994 uint32_t peers_to_clean_size;
1995 struct GNUNET_PeerIdentity *peers_to_clean;
1997 peers_to_clean = NULL;
1998 peers_to_clean_size = 0;
1999 GNUNET_array_grow (peers_to_clean, peers_to_clean_size, gossip_list_size);
2000 memcpy (peers_to_clean,
2002 gossip_list_size * sizeof (struct GNUNET_PeerIdentity));
2004 first_border = ceil (alpha * sampler_size_est_need);
2005 second_border = first_border + ceil (beta * sampler_size_est_need);
2007 GNUNET_array_grow (gossip_list, gossip_list_size, second_border);
2009 for (i = 0 ; i < first_border ; i++)
2010 { // TODO use RPS_sampler_get_n_rand_peers
2011 /* Update gossip list with peers received through PUSHes */
2012 r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
2014 gossip_list[i] = push_list[r_index];
2015 // TODO change the peer_flags accordingly
2018 for (i = first_border ; i < second_border ; i++)
2020 /* Update gossip list with peers received through PULLs */
2021 r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
2023 gossip_list[i] = pull_list[r_index];
2024 // TODO change the peer_flags accordingly
2027 for (i = second_border ; i < sampler_size_est_need ; i++)
2029 /* Update gossip list with peers from history */
2030 RPS_sampler_get_n_rand_peers (prot_sampler, hist_update, NULL, 1, GNUNET_NO);
2031 num_hist_update_tasks++;
2032 // TODO change the peer_flags accordingly
2035 for (i = 0 ; i < gossip_list_size ; i++)
2036 rem_from_list (&peers_to_clean, &peers_to_clean_size, &gossip_list[i]);
2038 for (i = 0 ; i < peers_to_clean_size ; i++)
2039 peer_clean (&peers_to_clean[i]);
2041 GNUNET_free (peers_to_clean);
2045 LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the gossip list.\n");
2047 // TODO independent of that also get some peers from CADET_get_peers()?
2049 LOG (GNUNET_ERROR_TYPE_DEBUG,
2050 "Received %u pushes and %u pulls last round (alpha (%.2f) * gossip_list_size (%u) = %.2f)\n",
2055 alpha * gossip_list_size);
2057 /* Update samplers */
2058 for ( i = 0 ; i < push_list_size ; i++ )
2060 LOG (GNUNET_ERROR_TYPE_DEBUG,
2061 "Updating with peer %s from push list\n",
2062 GNUNET_i2s (&push_list[i]));
2063 RPS_sampler_update (prot_sampler, &push_list[i]);
2064 RPS_sampler_update (client_sampler, &push_list[i]);
2065 // TODO set in_flag?
2068 for ( i = 0 ; i < pull_list_size ; i++ )
2070 LOG (GNUNET_ERROR_TYPE_DEBUG,
2071 "Updating with peer %s from pull list\n",
2072 GNUNET_i2s (&pull_list[i]));
2073 RPS_sampler_update (prot_sampler, &pull_list[i]);
2074 RPS_sampler_update (client_sampler, &pull_list[i]);
2075 // TODO set in_flag?
2079 /* Empty push/pull lists */
2080 GNUNET_array_grow (push_list, push_list_size, 0);
2081 GNUNET_array_grow (pull_list, pull_list_size, 0);
2083 struct GNUNET_TIME_Relative time_next_round;
2085 time_next_round = compute_rand_delay (round_interval, 2);
2087 /* Schedule next round */
2088 //do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_round, NULL);
2089 do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, &do_round, NULL);
2090 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
2095 rps_start (struct GNUNET_SERVER_Handle *server);
2099 * This is called from GNUNET_CADET_get_peers().
2101 * It is called on every peer(ID) that cadet somehow has contact with.
2102 * We use those to initialise the sampler.
2105 init_peer_cb (void *cls,
2106 const struct GNUNET_PeerIdentity *peer,
2107 int tunnel, // "Do we have a tunnel towards this peer?"
2108 unsigned int n_paths, // "Number of known paths towards this peer"
2109 unsigned int best_path) // "How long is the best path?
2110 // (0 = unknown, 1 = ourselves, 2 = neighbor)"
2114 LOG (GNUNET_ERROR_TYPE_DEBUG,
2115 "Got peer_id %s from cadet\n",
2123 * Clean the send channel of a peer
2126 peer_clean (const struct GNUNET_PeerIdentity *peer)
2128 struct PeerContext *peer_ctx;
2129 struct GNUNET_CADET_Channel *channel;
2131 if (GNUNET_YES != in_arr (gossip_list, gossip_list_size, peer)
2132 && GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
2134 peer_ctx = get_peer_ctx (peer_map, peer);
2135 if (NULL != peer_ctx->send_channel)
2137 channel = peer_ctx->send_channel;
2138 peer_ctx->send_channel = NULL;
2139 GNUNET_CADET_channel_destroy (channel);
2146 * Callback used to remove peers from the multipeermap.
2149 peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2151 struct PeerContext *peer_ctx;
2152 const struct GNUNET_CADET_Channel *channel =
2153 (const struct GNUNET_CADET_Channel *) cls;
2154 struct GNUNET_CADET_Channel *recv;
2155 struct GNUNET_CADET_Channel *send;
2157 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, value))
2159 peer_ctx = (struct PeerContext *) value;
2161 if (0 != peer_ctx->num_outstanding_ops)
2162 GNUNET_array_grow (peer_ctx->outstanding_ops,
2163 peer_ctx->num_outstanding_ops,
2166 if (NULL != peer_ctx->mq)
2168 GNUNET_MQ_destroy (peer_ctx->mq);
2169 peer_ctx->mq = NULL;
2173 if (NULL != peer_ctx->is_live_task)
2175 LOG (GNUNET_ERROR_TYPE_DEBUG,
2176 "Trying to cancle is_live_task for peer %s\n",
2178 GNUNET_CADET_notify_transmit_ready_cancel (peer_ctx->is_live_task);
2179 peer_ctx->is_live_task = NULL;
2182 send = peer_ctx->send_channel;
2183 peer_ctx->send_channel = NULL;
2187 GNUNET_CADET_channel_destroy (send);
2190 recv = peer_ctx->send_channel;
2191 peer_ctx->recv_channel = NULL;
2195 GNUNET_CADET_channel_destroy (recv);
2198 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove_all (peer_map, key))
2199 LOG (GNUNET_ERROR_TYPE_WARNING, "removing peer from peer_map failed\n");
2201 GNUNET_free (peer_ctx);
2209 * Task run during shutdown.
2215 shutdown_task (void *cls,
2216 const struct GNUNET_SCHEDULER_TaskContext *tc)
2219 LOG (GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n");
2221 if (NULL != do_round_task)
2223 GNUNET_SCHEDULER_cancel (do_round_task);
2224 do_round_task = NULL;
2229 if (GNUNET_SYSERR ==
2230 GNUNET_CONTAINER_multipeermap_iterate (peer_map, peer_remove_cb, NULL))
2231 LOG (GNUNET_ERROR_TYPE_WARNING,
2232 "Iterating over peers to disconnect from them was cancelled\n");
2235 GNUNET_NSE_disconnect (nse);
2236 GNUNET_CADET_disconnect (cadet_handle);
2237 RPS_sampler_destroy (prot_sampler);
2238 RPS_sampler_destroy (client_sampler);
2239 LOG (GNUNET_ERROR_TYPE_DEBUG,
2240 "Size of the peermap: %u\n",
2241 GNUNET_CONTAINER_multipeermap_size (peer_map));
2242 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (peer_map));
2243 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
2244 GNUNET_array_grow (gossip_list, gossip_list_size, 0);
2245 GNUNET_array_grow (push_list, push_list_size, 0);
2246 GNUNET_array_grow (pull_list, pull_list_size, 0);
2247 #ifdef ENABLE_MALICIOUS
2248 struct AttackedPeer *tmp_att_peer;
2249 GNUNET_array_grow (mal_peers, num_mal_peers, 0);
2250 if (NULL != mal_peer_set)
2251 GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set);
2252 if (NULL != att_peer_set)
2253 GNUNET_CONTAINER_multipeermap_destroy (att_peer_set);
2254 while (NULL != att_peers_head)
2256 tmp_att_peer = att_peers_head;
2257 GNUNET_CONTAINER_DLL_remove (att_peers_head, att_peers_tail, tmp_att_peer);
2259 #endif /* ENABLE_MALICIOUS */
2264 * A client disconnected. Remove all of its data structure entries.
2266 * @param cls closure, NULL
2267 * @param client identification of the client
2270 handle_client_disconnect (void *cls,
2271 struct GNUNET_SERVER_Client * client)
2277 * Handle the channel a peer opens to us.
2279 * @param cls The closure
2280 * @param channel The channel the peer wants to establish
2281 * @param initiator The peer's peer ID
2282 * @param port The port the channel is being established over
2283 * @param options Further options
2286 handle_inbound_channel (void *cls,
2287 struct GNUNET_CADET_Channel *channel,
2288 const struct GNUNET_PeerIdentity *initiator,
2290 enum GNUNET_CADET_ChannelOption options)
2292 struct PeerContext *peer_ctx;
2293 struct GNUNET_PeerIdentity peer;
2296 LOG (GNUNET_ERROR_TYPE_DEBUG,
2297 "New channel was established to us (Peer %s).\n",
2298 GNUNET_i2s (&peer));
2300 GNUNET_assert (NULL != channel);
2302 // we might not even store the recv_channel
2304 peer_ctx = get_peer_ctx (peer_map, &peer);
2305 // FIXME what do we do if a channel is established twice?
2306 // overwrite? Clean old channel? ...?
2307 //if (NULL != peer_ctx->recv_channel)
2309 // peer_ctx->recv_channel = channel;
2311 peer_ctx->recv_channel = channel;
2313 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, &peer, peer_ctx,
2314 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
2316 peer_is_live (peer_ctx);
2318 return NULL; // TODO
2323 * This is called when a remote peer destroys a channel.
2325 * @param cls The closure
2326 * @param channel The channel being closed
2327 * @param channel_ctx The context associated with this channel
2330 cleanup_channel (void *cls,
2331 const struct GNUNET_CADET_Channel *channel,
2334 struct GNUNET_PeerIdentity *peer;
2335 struct PeerContext *peer_ctx;
2337 peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (
2338 (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER);
2339 // Guess simply casting isn't the nicest way...
2340 // FIXME wait for cadet to change this function
2342 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
2344 peer_ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer);
2346 if (NULL == peer_ctx) /* It could have been removed by shutdown_task */
2349 if (channel == peer_ctx->send_channel)
2350 { /* Peer probably went down */
2351 LOG (GNUNET_ERROR_TYPE_DEBUG,
2352 "Peer %s destroyed send channel - probably went down, cleaning up\n",
2354 rem_from_list (&gossip_list, &gossip_list_size, peer);
2355 rem_from_list (&pending_pull_reply_list, &pending_pull_reply_list_size, peer);
2357 peer_ctx->send_channel = NULL;
2358 /* Somwewhat {ab,re}use the iterator function */
2359 /* Cast to void is ok, because it's used as void in peer_remove_cb */
2360 (void) peer_remove_cb ((void *) channel, peer, peer_ctx);
2362 else if (channel == peer_ctx->recv_channel)
2363 { /* Other peer doesn't want to send us messages anymore */
2364 LOG (GNUNET_ERROR_TYPE_DEBUG,
2365 "Peer %s destroyed recv channel - cleaning up channel\n",
2367 peer_ctx->recv_channel = NULL;
2374 * Actually start the service.
2377 rps_start (struct GNUNET_SERVER_Handle *server)
2379 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
2380 {&handle_client_request, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST,
2381 sizeof (struct GNUNET_RPS_CS_RequestMessage)},
2382 {&handle_client_seed, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_SEED, 0},
2383 #ifdef ENABLE_MALICIOUS
2384 {&handle_client_act_malicious, NULL, GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS , 0},
2385 #endif /* ENABLE_MALICIOUS */
2389 GNUNET_SERVER_add_handlers (server, handlers);
2390 GNUNET_SERVER_disconnect_notify (server,
2391 &handle_client_disconnect,
2393 LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n");
2396 do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL);
2397 LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n");
2399 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
2406 * Process statistics requests.
2408 * @param cls closure
2409 * @param server the initialized server
2410 * @param c configuration to use
2414 struct GNUNET_SERVER_Handle *server,
2415 const struct GNUNET_CONFIGURATION_Handle *c)
2417 // TODO check what this does -- copied from gnunet-boss
2418 // - seems to work as expected
2419 GNUNET_log_setup ("rps", GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), NULL);
2424 GNUNET_CRYPTO_get_peer_identity (cfg, &own_identity); // TODO check return value
2425 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2426 "STARTING SERVICE (rps) for peer [%s]\n",
2427 GNUNET_i2s (&own_identity));
2428 #ifdef ENABLE_MALICIOUS
2429 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2430 "Malicious execution compiled in.\n");
2431 #endif /* ENABLE_MALICIOUS */
2435 /* Get time interval from the configuration */
2436 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "RPS",
2440 LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to read ROUNDINTERVAL from config\n");
2441 GNUNET_SCHEDULER_shutdown ();
2445 /* Get initial size of sampler/gossip list from the configuration */
2446 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "RPS",
2448 (long long unsigned int *) &sampler_size_est_need))
2450 LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to read INITSIZE from config\n");
2451 GNUNET_SCHEDULER_shutdown ();
2454 LOG (GNUNET_ERROR_TYPE_DEBUG, "INITSIZE is %" PRIu64 "\n", sampler_size_est_need);
2460 /* connect to NSE */
2461 nse = GNUNET_NSE_connect (cfg, nse_callback, NULL);
2467 peer_map = GNUNET_CONTAINER_multipeermap_create (sampler_size_est_need, GNUNET_NO);
2470 /* Initialise cadet */
2471 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
2472 {&handle_peer_push , GNUNET_MESSAGE_TYPE_RPS_PP_PUSH ,
2473 sizeof (struct GNUNET_MessageHeader)},
2474 {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
2475 sizeof (struct GNUNET_MessageHeader)},
2476 {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0},
2480 const uint32_t ports[] = {GNUNET_RPS_CADET_PORT, 0}; // _PORT specified in src/rps/rps.h
2481 cadet_handle = GNUNET_CADET_connect (cfg,
2483 &handle_inbound_channel,
2489 /* Initialise sampler */
2490 struct GNUNET_TIME_Relative half_round_interval;
2491 struct GNUNET_TIME_Relative max_round_interval;
2493 half_round_interval = GNUNET_TIME_relative_multiply (round_interval, .5);
2494 max_round_interval = GNUNET_TIME_relative_add (round_interval, half_round_interval);
2496 prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval);
2497 client_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval);
2499 /* Initialise push and pull maps */
2504 pending_pull_reply_list = NULL;
2505 pending_pull_reply_list_size = 0;
2508 num_hist_update_tasks = 0;
2511 LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n");
2512 GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, NULL);
2513 // TODO send push/pull to each of those peers?
2521 * The main function for the rps service.
2523 * @param argc number of arguments from the command line
2524 * @param argv command line arguments
2525 * @return 0 ok, 1 on error
2528 main (int argc, char *const *argv)
2530 return (GNUNET_OK ==
2531 GNUNET_SERVICE_run (argc,
2534 GNUNET_SERVICE_OPTION_NONE,
2535 &run, NULL)) ? 0 : 1;
2538 /* end of gnunet-service-rps.c */