aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-10-01 20:03:54 +0200
committerJulius Bünger <buenger@mytum.de>2018-10-01 23:15:31 +0200
commitb3aad5bef2e78487251ef7fc766a510f9fc731c9 (patch)
tree018276629058a2f5876d4c0f4bb4e55092961898 /src
parentc8e4a66007d1d904ccd78c0dbd0c101b43d83a14 (diff)
downloadgnunet-b3aad5bef2e78487251ef7fc766a510f9fc731c9.tar.gz
gnunet-b3aad5bef2e78487251ef7fc766a510f9fc731c9.zip
Change architecture of service (towards subsampling)
Diffstat (limited to 'src')
-rw-r--r--src/rps/gnunet-service-rps.c1114
1 files changed, 579 insertions, 535 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 389c6139b..3d9f9234c 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -51,30 +51,6 @@
51 51
52// hist_size_init, hist_size_max 52// hist_size_init, hist_size_max
53 53
54/**
55 * Our configuration.
56 */
57static const struct GNUNET_CONFIGURATION_Handle *cfg;
58
59/**
60 * Handle to the statistics service.
61 */
62struct GNUNET_STATISTICS_Handle *stats;
63
64/**
65 * Our own identity.
66 */
67static struct GNUNET_PeerIdentity own_identity;
68
69static int in_shutdown = GNUNET_NO;
70
71/**
72 * @brief Port used for cadet.
73 *
74 * Don't compute multiple times through making it global
75 */
76static struct GNUNET_HashCode port;
77
78/*********************************************************************** 54/***********************************************************************
79 * Old gnunet-service-rps_peers.c 55 * Old gnunet-service-rps_peers.c
80***********************************************************************/ 56***********************************************************************/
@@ -168,7 +144,7 @@ struct ChannelCtx;
168 * This is stored in a multipeermap. 144 * This is stored in a multipeermap.
169 * It contains information such as cadet channels, a message queue for sending, 145 * It contains information such as cadet channels, a message queue for sending,
170 * status about the channels, the pending operations on this peer and some flags 146 * status about the channels, the pending operations on this peer and some flags
171 * about the status of the peer itself. (online, valid, ...) 147 * about the status of the peer itself. (live, valid, ...)
172 */ 148 */
173struct PeerContext 149struct PeerContext
174{ 150{
@@ -197,7 +173,7 @@ struct PeerContext
197 * 173 *
198 * To be canceled on shutdown. 174 * To be canceled on shutdown.
199 */ 175 */
200 struct PendingMessage *online_check_pending; 176 struct PendingMessage *liveliness_check_pending;
201 177
202 /** 178 /**
203 * Number of pending operations. 179 * Number of pending operations.
@@ -276,31 +252,277 @@ struct ChannelCtx
276 struct GNUNET_SCHEDULER_Task *destruction_task; 252 struct GNUNET_SCHEDULER_Task *destruction_task;
277}; 253};
278 254
255
256#ifdef ENABLE_MALICIOUS
257
279/** 258/**
280 * @brief Hashmap of valid peers. 259 * If type is 2 This struct is used to store the attacked peers in a DLL
281 */ 260 */
282static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; 261struct AttackedPeer
262{
263 /**
264 * DLL
265 */
266 struct AttackedPeer *next;
267 struct AttackedPeer *prev;
268
269 /**
270 * PeerID
271 */
272 struct GNUNET_PeerIdentity peer_id;
273};
274
275#endif /* ENABLE_MALICIOUS */
283 276
284/** 277/**
285 * @brief Maximum number of valid peers to keep. 278 * @brief One SubSampler.
286 * TODO read from config 279 *
280 * Essentially one instance of brahms that only connects to other instances
281 * with the same (secret) value.
287 */ 282 */
288static uint32_t num_valid_peers_max = UINT32_MAX; 283struct SubSampler
284{
285 /**
286 * @brief Port used for cadet.
287 *
288 * Don't compute multiple times through making it global
289 */
290 struct GNUNET_HashCode port;
291
292 /**
293 * Handler to CADET.
294 */
295 struct GNUNET_CADET_Handle *cadet_handle;
296
297 /**
298 * @brief Port to communicate to other peers.
299 */
300 struct GNUNET_CADET_Port *cadet_port;
301
302 /**
303 * @brief Hashmap of valid peers.
304 */
305 struct GNUNET_CONTAINER_MultiPeerMap *valid_peers;
306
307 /**
308 * @brief Filename of the file that stores the valid peers persistently.
309 */
310 char *filename_valid_peers;
311
312 /**
313 * Set of all peers to keep track of them.
314 */
315 struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
316
317 /**
318 * @brief This is the minimum estimate used as sampler size.
319 *
320 * It is configured by the user.
321 */
322 unsigned int sampler_size_est_min;
323
324 /**
325 * The size of sampler we need to be able to satisfy the Brahms protocol's
326 * need of random peers.
327 *
328 * This is one minimum size the sampler grows to.
329 */
330 unsigned int sampler_size_est_need;
331
332 /**
333 * Time inverval the do_round task runs in.
334 */
335 struct GNUNET_TIME_Relative round_interval;
336
337 /**
338 * Sampler used for the Brahms protocol itself.
339 */
340 struct RPS_Sampler *sampler;
341
342 /**
343 * Name to log view to
344 */
345 char *file_name_view_log;
346
347#ifdef TO_FILE
348 /**
349 * Name to log number of observed peers to
350 */
351 char *file_name_observed_log;
352
353 /**
354 * @brief Count the observed peers
355 */
356 uint32_t num_observed_peers;
357
358 /**
359 * @brief Multipeermap (ab-) used to count unique peer_ids
360 */
361 struct GNUNET_CONTAINER_MultiPeerMap *observed_unique_peers;
362#endif /* TO_FILE */
363
364 /**
365 * List to store peers received through pushes temporary.
366 */
367 struct CustomPeerMap *push_map;
368
369 /**
370 * List to store peers received through pulls temporary.
371 */
372 struct CustomPeerMap *pull_map;
373
374 /**
375 * @brief This is the estimate used as view size.
376 *
377 * It is initialised with the minimum
378 */
379 unsigned int view_size_est_need;
380
381 /**
382 * @brief This is the minimum estimate used as view size.
383 *
384 * It is configured by the user.
385 */
386 unsigned int view_size_est_min;
387
388 /**
389 * Identifier for the main task that runs periodically.
390 */
391 struct GNUNET_SCHEDULER_Task *do_round_task;
392};
393
394
395/***********************************************************************
396 * Globals
397***********************************************************************/
289 398
290/** 399/**
291 * @brief Filename of the file that stores the valid peers persistently. 400 * Our configuration.
292 */ 401 */
293static char *filename_valid_peers; 402static const struct GNUNET_CONFIGURATION_Handle *cfg;
294 403
295/** 404/**
296 * Set of all peers to keep track of them. 405 * Handle to the statistics service.
297 */ 406 */
298static struct GNUNET_CONTAINER_MultiPeerMap *peer_map; 407struct GNUNET_STATISTICS_Handle *stats;
299 408
300/** 409/**
301 * Cadet handle. 410 * Our own identity.
302 */ 411 */
303static struct GNUNET_CADET_Handle *cadet_handle; 412static struct GNUNET_PeerIdentity own_identity;
413
414/**
415 * Percentage of total peer number in the view
416 * to send random PUSHes to
417 */
418static float alpha;
419
420/**
421 * Percentage of total peer number in the view
422 * to send random PULLs to
423 */
424static float beta;
425
426/**
427 * Handler to NSE.
428 */
429static struct GNUNET_NSE_Handle *nse;
430
431/**
432 * Handler to PEERINFO.
433 */
434static struct GNUNET_PEERINFO_Handle *peerinfo_handle;
435
436/**
437 * Handle for cancellation of iteration over peers.
438 */
439static struct GNUNET_PEERINFO_NotifyContext *peerinfo_notify_handle;
440
441
442#ifdef ENABLE_MALICIOUS
443/**
444 * Type of malicious peer
445 *
446 * 0 Don't act malicious at all - Default
447 * 1 Try to maximise representation
448 * 2 Try to partition the network
449 * 3 Combined attack
450 */
451static uint32_t mal_type;
452
453/**
454 * Other malicious peers
455 */
456static struct GNUNET_PeerIdentity *mal_peers;
457
458/**
459 * Hashmap of malicious peers used as set.
460 * Used to more efficiently check whether we know that peer.
461 */
462static struct GNUNET_CONTAINER_MultiPeerMap *mal_peer_set;
463
464/**
465 * Number of other malicious peers
466 */
467static uint32_t num_mal_peers;
468
469
470/**
471 * If type is 2 this is the DLL of attacked peers
472 */
473static struct AttackedPeer *att_peers_head;
474static struct AttackedPeer *att_peers_tail;
475
476/**
477 * This index is used to point to an attacked peer to
478 * implement the round-robin-ish way to select attacked peers.
479 */
480static struct AttackedPeer *att_peer_index;
481
482/**
483 * Hashmap of attacked peers used as set.
484 * Used to more efficiently check whether we know that peer.
485 */
486static struct GNUNET_CONTAINER_MultiPeerMap *att_peer_set;
487
488/**
489 * Number of attacked peers
490 */
491static uint32_t num_attacked_peers;
492
493/**
494 * If type is 1 this is the attacked peer
495 */
496static struct GNUNET_PeerIdentity attacked_peer;
497
498/**
499 * The limit of PUSHes we can send in one round.
500 * This is an assumption of the Brahms protocol and either implemented
501 * via proof of work
502 * or
503 * assumend to be the bandwidth limitation.
504 */
505static uint32_t push_limit = 10000;
506#endif /* ENABLE_MALICIOUS */
507
508/**
509 * @brief Main SubSampler.
510 *
511 * This is run in any case by all peers and connects to all peers without
512 * specifying a shared value.
513 */
514static struct SubSampler *mss;
515
516/**
517 * @brief Maximum number of valid peers to keep.
518 * TODO read from config
519 */
520static const uint32_t num_valid_peers_max = UINT32_MAX;
521
522
523/***********************************************************************
524 * /Globals
525***********************************************************************/
304 526
305 527
306/** 528/**
@@ -316,9 +538,9 @@ get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
316 struct PeerContext *ctx; 538 struct PeerContext *ctx;
317 int ret; 539 int ret;
318 540
319 ret = GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); 541 ret = GNUNET_CONTAINER_multipeermap_contains (mss->peer_map, peer);
320 GNUNET_assert (GNUNET_YES == ret); 542 GNUNET_assert (GNUNET_YES == ret);
321 ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer); 543 ctx = GNUNET_CONTAINER_multipeermap_get (mss->peer_map, peer);
322 GNUNET_assert (NULL != ctx); 544 GNUNET_assert (NULL != ctx);
323 return ctx; 545 return ctx;
324} 546}
@@ -336,9 +558,9 @@ get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
336static int 558static int
337check_peer_known (const struct GNUNET_PeerIdentity *peer) 559check_peer_known (const struct GNUNET_PeerIdentity *peer)
338{ 560{
339 if (NULL != peer_map) 561 if (NULL != mss->peer_map)
340 { 562 {
341 return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); 563 return GNUNET_CONTAINER_multipeermap_contains (mss->peer_map, peer);
342 } else 564 } else
343 { 565 {
344 return GNUNET_NO; 566 return GNUNET_NO;
@@ -363,12 +585,12 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer)
363 585
364 ctx = GNUNET_new (struct PeerContext); 586 ctx = GNUNET_new (struct PeerContext);
365 ctx->peer_id = *peer; 587 ctx->peer_id = *peer;
366 ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, 588 ret = GNUNET_CONTAINER_multipeermap_put (mss->peer_map, peer, ctx,
367 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 589 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
368 GNUNET_assert (GNUNET_OK == ret); 590 GNUNET_assert (GNUNET_OK == ret);
369 GNUNET_STATISTICS_set (stats, 591 GNUNET_STATISTICS_set (stats,
370 "# known peers", 592 "# known peers",
371 GNUNET_CONTAINER_multipeermap_size (peer_map), 593 GNUNET_CONTAINER_multipeermap_size (mss->peer_map),
372 GNUNET_NO); 594 GNUNET_NO);
373 return ctx; 595 return ctx;
374} 596}
@@ -496,7 +718,7 @@ get_random_peer_from_peermap (const struct
496 iterator_cls = GNUNET_new (struct GetRandPeerIteratorCls); 718 iterator_cls = GNUNET_new (struct GetRandPeerIteratorCls);
497 iterator_cls->index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 719 iterator_cls->index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
498 GNUNET_CONTAINER_multipeermap_size (peer_map)); 720 GNUNET_CONTAINER_multipeermap_size (peer_map));
499 (void) GNUNET_CONTAINER_multipeermap_iterate (valid_peers, 721 (void) GNUNET_CONTAINER_multipeermap_iterate (mss->valid_peers,
500 get_rand_peer_iterator, 722 get_rand_peer_iterator,
501 iterator_cls); 723 iterator_cls);
502 ret = iterator_cls->peer; 724 ret = iterator_cls->peer;
@@ -522,17 +744,18 @@ add_valid_peer (const struct GNUNET_PeerIdentity *peer)
522 int ret; 744 int ret;
523 745
524 ret = GNUNET_YES; 746 ret = GNUNET_YES;
525 while (GNUNET_CONTAINER_multipeermap_size (valid_peers) >= num_valid_peers_max) 747 while (GNUNET_CONTAINER_multipeermap_size (
748 mss->valid_peers) >= num_valid_peers_max)
526 { 749 {
527 rand_peer = get_random_peer_from_peermap (valid_peers); 750 rand_peer = get_random_peer_from_peermap (mss->valid_peers);
528 GNUNET_CONTAINER_multipeermap_remove_all (valid_peers, rand_peer); 751 GNUNET_CONTAINER_multipeermap_remove_all (mss->valid_peers, rand_peer);
529 ret = GNUNET_NO; 752 ret = GNUNET_NO;
530 } 753 }
531 (void) GNUNET_CONTAINER_multipeermap_put (valid_peers, peer, NULL, 754 (void) GNUNET_CONTAINER_multipeermap_put (mss->valid_peers, peer, NULL,
532 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 755 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
533 GNUNET_STATISTICS_set (stats, 756 GNUNET_STATISTICS_set (stats,
534 "# valid peers", 757 "# valid peers",
535 GNUNET_CONTAINER_multipeermap_size (valid_peers), 758 GNUNET_CONTAINER_multipeermap_size (mss->valid_peers),
536 GNUNET_NO); 759 GNUNET_NO);
537 return ret; 760 return ret;
538} 761}
@@ -700,10 +923,10 @@ get_channel (const struct GNUNET_PeerIdentity *peer)
700 *ctx_peer = *peer; 923 *ctx_peer = *peer;
701 peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx); 924 peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx);
702 peer_ctx->send_channel_ctx->channel = 925 peer_ctx->send_channel_ctx->channel =
703 GNUNET_CADET_channel_create (cadet_handle, 926 GNUNET_CADET_channel_create (mss->cadet_handle,
704 peer_ctx->send_channel_ctx, /* context */ 927 peer_ctx->send_channel_ctx, /* context */
705 peer, 928 peer,
706 &port, 929 &mss->port,
707 GNUNET_CADET_OPTION_RELIABLE, 930 GNUNET_CADET_OPTION_RELIABLE,
708 NULL, /* WindowSize handler */ 931 NULL, /* WindowSize handler */
709 &cleanup_destroyed_channel, /* Disconnect handler */ 932 &cleanup_destroyed_channel, /* Disconnect handler */
@@ -794,51 +1017,51 @@ remove_pending_message (struct PendingMessage *pending_msg, int cancel)
794 1017
795/** 1018/**
796 * @brief This is called in response to the first message we sent as a 1019 * @brief This is called in response to the first message we sent as a
797 * online check. 1020 * liveliness check.
798 * 1021 *
799 * @param cls #PeerContext of peer with pending online check 1022 * @param cls #PeerContext of peer with pending liveliness check
800 */ 1023 */
801static void 1024static void
802mq_online_check_successful (void *cls) 1025mq_liveliness_check_successful (void *cls)
803{ 1026{
804 struct PeerContext *peer_ctx = cls; 1027 struct PeerContext *peer_ctx = cls;
805 1028
806 if (NULL != peer_ctx->online_check_pending) 1029 if (NULL != peer_ctx->liveliness_check_pending)
807 { 1030 {
808 LOG (GNUNET_ERROR_TYPE_DEBUG, 1031 LOG (GNUNET_ERROR_TYPE_DEBUG,
809 "Online check for peer %s was successfull\n", 1032 "Liveliness check for peer %s was successfull\n",
810 GNUNET_i2s (&peer_ctx->peer_id)); 1033 GNUNET_i2s (&peer_ctx->peer_id));
811 remove_pending_message (peer_ctx->online_check_pending, GNUNET_YES); 1034 remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES);
812 peer_ctx->online_check_pending = NULL; 1035 peer_ctx->liveliness_check_pending = NULL;
813 set_peer_online (peer_ctx); 1036 set_peer_live (peer_ctx);
814 } 1037 }
815} 1038}
816 1039
817/** 1040/**
818 * Issue a check whether peer is online 1041 * Issue a check whether peer is live
819 * 1042 *
820 * @param peer_ctx the context of the peer 1043 * @param peer_ctx the context of the peer
821 */ 1044 */
822static void 1045static void
823check_peer_online (struct PeerContext *peer_ctx) 1046check_peer_live (struct PeerContext *peer_ctx)
824{ 1047{
825 LOG (GNUNET_ERROR_TYPE_DEBUG, 1048 LOG (GNUNET_ERROR_TYPE_DEBUG,
826 "Get informed about peer %s getting online\n", 1049 "Get informed about peer %s getting live\n",
827 GNUNET_i2s (&peer_ctx->peer_id)); 1050 GNUNET_i2s (&peer_ctx->peer_id));
828 1051
829 struct GNUNET_MQ_Handle *mq; 1052 struct GNUNET_MQ_Handle *mq;
830 struct GNUNET_MQ_Envelope *ev; 1053 struct GNUNET_MQ_Envelope *ev;
831 1054
832 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); 1055 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE);
833 peer_ctx->online_check_pending = 1056 peer_ctx->liveliness_check_pending =
834 insert_pending_message (&peer_ctx->peer_id, ev, "Check online"); 1057 insert_pending_message (&peer_ctx->peer_id, ev, "Check liveliness");
835 mq = get_mq (&peer_ctx->peer_id); 1058 mq = get_mq (&peer_ctx->peer_id);
836 GNUNET_MQ_notify_sent (ev, 1059 GNUNET_MQ_notify_sent (ev,
837 mq_online_check_successful, 1060 mq_liveliness_check_successful,
838 peer_ctx); 1061 peer_ctx);
839 GNUNET_MQ_send (mq, ev); 1062 GNUNET_MQ_send (mq, ev);
840 GNUNET_STATISTICS_update (stats, 1063 GNUNET_STATISTICS_update (stats,
841 "# pending online checks", 1064 "# pending liveliness checks",
842 1, 1065 1,
843 GNUNET_NO); 1066 GNUNET_NO);
844} 1067}
@@ -945,9 +1168,9 @@ static int
945destroy_peer (struct PeerContext *peer_ctx) 1168destroy_peer (struct PeerContext *peer_ctx)
946{ 1169{
947 GNUNET_assert (NULL != peer_ctx); 1170 GNUNET_assert (NULL != peer_ctx);
948 GNUNET_assert (NULL != peer_map); 1171 GNUNET_assert (NULL != mss->peer_map);
949 if (GNUNET_NO == 1172 if (GNUNET_NO ==
950 GNUNET_CONTAINER_multipeermap_contains (peer_map, 1173 GNUNET_CONTAINER_multipeermap_contains (mss->peer_map,
951 &peer_ctx->peer_id)) 1174 &peer_ctx->peer_id))
952 { 1175 {
953 return GNUNET_NO; 1176 return GNUNET_NO;
@@ -971,14 +1194,14 @@ destroy_peer (struct PeerContext *peer_ctx)
971 "Removing unsent %s\n", 1194 "Removing unsent %s\n",
972 peer_ctx->pending_messages_head->type); 1195 peer_ctx->pending_messages_head->type);
973 /* Cancle pending message, too */ 1196 /* Cancle pending message, too */
974 if ( (NULL != peer_ctx->online_check_pending) && 1197 if ( (NULL != peer_ctx->liveliness_check_pending) &&
975 (0 == memcmp (peer_ctx->pending_messages_head, 1198 (0 == memcmp (peer_ctx->pending_messages_head,
976 peer_ctx->online_check_pending, 1199 peer_ctx->liveliness_check_pending,
977 sizeof (struct PendingMessage))) ) 1200 sizeof (struct PendingMessage))) )
978 { 1201 {
979 peer_ctx->online_check_pending = NULL; 1202 peer_ctx->liveliness_check_pending = NULL;
980 GNUNET_STATISTICS_update (stats, 1203 GNUNET_STATISTICS_update (stats,
981 "# pending online checks", 1204 "# pending liveliness checks",
982 -1, 1205 -1,
983 GNUNET_NO); 1206 GNUNET_NO);
984 } 1207 }
@@ -986,18 +1209,18 @@ destroy_peer (struct PeerContext *peer_ctx)
986 GNUNET_YES); 1209 GNUNET_YES);
987 } 1210 }
988 1211
989 /* If we are still waiting for notification whether this peer is online 1212 /* If we are still waiting for notification whether this peer is live
990 * cancel the according task */ 1213 * cancel the according task */
991 if (NULL != peer_ctx->online_check_pending) 1214 if (NULL != peer_ctx->liveliness_check_pending)
992 { 1215 {
993 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
994 "Removing pending online check for peer %s\n", 1217 "Removing pending liveliness check for peer %s\n",
995 GNUNET_i2s (&peer_ctx->peer_id)); 1218 GNUNET_i2s (&peer_ctx->peer_id));
996 // TODO wait until cadet sets mq->cancel_impl 1219 // TODO wait until cadet sets mq->cancel_impl
997 //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); 1220 //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev);
998 remove_pending_message (peer_ctx->online_check_pending, 1221 remove_pending_message (peer_ctx->liveliness_check_pending,
999 GNUNET_YES); 1222 GNUNET_YES);
1000 peer_ctx->online_check_pending = NULL; 1223 peer_ctx->liveliness_check_pending = NULL;
1001 } 1224 }
1002 1225
1003 if (NULL != peer_ctx->send_channel_ctx) 1226 if (NULL != peer_ctx->send_channel_ctx)
@@ -1017,15 +1240,15 @@ destroy_peer (struct PeerContext *peer_ctx)
1017 } 1240 }
1018 1241
1019 if (GNUNET_YES != 1242 if (GNUNET_YES !=
1020 GNUNET_CONTAINER_multipeermap_remove_all (peer_map, 1243 GNUNET_CONTAINER_multipeermap_remove_all (mss->peer_map,
1021 &peer_ctx->peer_id)) 1244 &peer_ctx->peer_id))
1022 { 1245 {
1023 LOG (GNUNET_ERROR_TYPE_WARNING, 1246 LOG (GNUNET_ERROR_TYPE_WARNING,
1024 "removing peer from peer_map failed\n"); 1247 "removing peer from mss->peer_map failed\n");
1025 } 1248 }
1026 GNUNET_STATISTICS_set (stats, 1249 GNUNET_STATISTICS_set (stats,
1027 "# known peers", 1250 "# known peers",
1028 GNUNET_CONTAINER_multipeermap_size (peer_map), 1251 GNUNET_CONTAINER_multipeermap_size (mss->peer_map),
1029 GNUNET_NO); 1252 GNUNET_NO);
1030 GNUNET_free (peer_ctx); 1253 GNUNET_free (peer_ctx);
1031 return GNUNET_YES; 1254 return GNUNET_YES;
@@ -1130,27 +1353,27 @@ store_valid_peers ()
1130 uint32_t number_written_peers; 1353 uint32_t number_written_peers;
1131 int ret; 1354 int ret;
1132 1355
1133 if (0 == strncmp ("DISABLE", filename_valid_peers, 7)) 1356 if (0 == strncmp ("DISABLE", mss->filename_valid_peers, 7))
1134 { 1357 {
1135 return; 1358 return;
1136 } 1359 }
1137 1360
1138 ret = GNUNET_DISK_directory_create_for_file (filename_valid_peers); 1361 ret = GNUNET_DISK_directory_create_for_file (mss->filename_valid_peers);
1139 if (GNUNET_SYSERR == ret) 1362 if (GNUNET_SYSERR == ret)
1140 { 1363 {
1141 LOG (GNUNET_ERROR_TYPE_WARNING, 1364 LOG (GNUNET_ERROR_TYPE_WARNING,
1142 "Not able to create directory for file `%s'\n", 1365 "Not able to create directory for file `%s'\n",
1143 filename_valid_peers); 1366 mss->filename_valid_peers);
1144 GNUNET_break (0); 1367 GNUNET_break (0);
1145 } 1368 }
1146 else if (GNUNET_NO == ret) 1369 else if (GNUNET_NO == ret)
1147 { 1370 {
1148 LOG (GNUNET_ERROR_TYPE_WARNING, 1371 LOG (GNUNET_ERROR_TYPE_WARNING,
1149 "Directory for file `%s' exists but is not writable for us\n", 1372 "Directory for file `%s' exists but is not writable for us\n",
1150 filename_valid_peers); 1373 mss->filename_valid_peers);
1151 GNUNET_break (0); 1374 GNUNET_break (0);
1152 } 1375 }
1153 fh = GNUNET_DISK_file_open (filename_valid_peers, 1376 fh = GNUNET_DISK_file_open (mss->filename_valid_peers,
1154 GNUNET_DISK_OPEN_WRITE | 1377 GNUNET_DISK_OPEN_WRITE |
1155 GNUNET_DISK_OPEN_CREATE, 1378 GNUNET_DISK_OPEN_CREATE,
1156 GNUNET_DISK_PERM_USER_READ | 1379 GNUNET_DISK_PERM_USER_READ |
@@ -1159,19 +1382,19 @@ store_valid_peers ()
1159 { 1382 {
1160 LOG (GNUNET_ERROR_TYPE_WARNING, 1383 LOG (GNUNET_ERROR_TYPE_WARNING,
1161 "Not able to write valid peers to file `%s'\n", 1384 "Not able to write valid peers to file `%s'\n",
1162 filename_valid_peers); 1385 mss->filename_valid_peers);
1163 return; 1386 return;
1164 } 1387 }
1165 LOG (GNUNET_ERROR_TYPE_DEBUG, 1388 LOG (GNUNET_ERROR_TYPE_DEBUG,
1166 "Writing %u valid peers to disk\n", 1389 "Writing %u valid peers to disk\n",
1167 GNUNET_CONTAINER_multipeermap_size (valid_peers)); 1390 GNUNET_CONTAINER_multipeermap_size (mss->valid_peers));
1168 number_written_peers = 1391 number_written_peers =
1169 GNUNET_CONTAINER_multipeermap_iterate (valid_peers, 1392 GNUNET_CONTAINER_multipeermap_iterate (mss->valid_peers,
1170 store_peer_presistently_iterator, 1393 store_peer_presistently_iterator,
1171 fh); 1394 fh);
1172 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); 1395 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
1173 GNUNET_assert (number_written_peers == 1396 GNUNET_assert (number_written_peers ==
1174 GNUNET_CONTAINER_multipeermap_size (valid_peers)); 1397 GNUNET_CONTAINER_multipeermap_size (mss->valid_peers));
1175} 1398}
1176 1399
1177 1400
@@ -1236,16 +1459,16 @@ restore_valid_peers ()
1236 char *str_repr; 1459 char *str_repr;
1237 const struct GNUNET_PeerIdentity *peer; 1460 const struct GNUNET_PeerIdentity *peer;
1238 1461
1239 if (0 == strncmp ("DISABLE", filename_valid_peers, 7)) 1462 if (0 == strncmp ("DISABLE", mss->filename_valid_peers, 7))
1240 { 1463 {
1241 return; 1464 return;
1242 } 1465 }
1243 1466
1244 if (GNUNET_OK != GNUNET_DISK_file_test (filename_valid_peers)) 1467 if (GNUNET_OK != GNUNET_DISK_file_test (mss->filename_valid_peers))
1245 { 1468 {
1246 return; 1469 return;
1247 } 1470 }
1248 fh = GNUNET_DISK_file_open (filename_valid_peers, 1471 fh = GNUNET_DISK_file_open (mss->filename_valid_peers,
1249 GNUNET_DISK_OPEN_READ, 1472 GNUNET_DISK_OPEN_READ,
1250 GNUNET_DISK_PERM_NONE); 1473 GNUNET_DISK_PERM_NONE);
1251 GNUNET_assert (NULL != fh); 1474 GNUNET_assert (NULL != fh);
@@ -1257,7 +1480,7 @@ restore_valid_peers ()
1257 LOG (GNUNET_ERROR_TYPE_DEBUG, 1480 LOG (GNUNET_ERROR_TYPE_DEBUG,
1258 "Restoring %" PRIu32 " peers from file `%s'\n", 1481 "Restoring %" PRIu32 " peers from file `%s'\n",
1259 num_peers, 1482 num_peers,
1260 filename_valid_peers); 1483 mss->filename_valid_peers);
1261 for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53) 1484 for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53)
1262 { 1485 {
1263 str_repr = GNUNET_strndup (iter_buf, 53); 1486 str_repr = GNUNET_strndup (iter_buf, 53);
@@ -1271,10 +1494,10 @@ restore_valid_peers ()
1271 iter_buf = NULL; 1494 iter_buf = NULL;
1272 GNUNET_free (buf); 1495 GNUNET_free (buf);
1273 LOG (GNUNET_ERROR_TYPE_DEBUG, 1496 LOG (GNUNET_ERROR_TYPE_DEBUG,
1274 "num_peers: %" PRIu32 ", _size (valid_peers): %u\n", 1497 "num_peers: %" PRIu32 ", _size (mss->valid_peers): %u\n",
1275 num_peers, 1498 num_peers,
1276 GNUNET_CONTAINER_multipeermap_size (valid_peers)); 1499 GNUNET_CONTAINER_multipeermap_size (mss->valid_peers));
1277 if (num_peers != GNUNET_CONTAINER_multipeermap_size (valid_peers)) 1500 if (num_peers != GNUNET_CONTAINER_multipeermap_size (mss->valid_peers))
1278 { 1501 {
1279 LOG (GNUNET_ERROR_TYPE_WARNING, 1502 LOG (GNUNET_ERROR_TYPE_WARNING,
1280 "Number of restored peers does not match file size. Have probably duplicates.\n"); 1503 "Number of restored peers does not match file size. Have probably duplicates.\n");
@@ -1282,26 +1505,7 @@ restore_valid_peers ()
1282 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); 1505 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
1283 LOG (GNUNET_ERROR_TYPE_DEBUG, 1506 LOG (GNUNET_ERROR_TYPE_DEBUG,
1284 "Restored %u valid peers from disk\n", 1507 "Restored %u valid peers from disk\n",
1285 GNUNET_CONTAINER_multipeermap_size (valid_peers)); 1508 GNUNET_CONTAINER_multipeermap_size (mss->valid_peers));
1286}
1287
1288
1289/**
1290 * @brief Initialise storage of peers
1291 *
1292 * @param fn_valid_peers filename of the file used to store valid peer ids
1293 * @param cadet_h cadet handle
1294 * @param own_id own peer identity
1295 */
1296static void
1297initialise_peers (char* fn_valid_peers,
1298 struct GNUNET_CADET_Handle *cadet_h)
1299{
1300 filename_valid_peers = GNUNET_strdup (fn_valid_peers);
1301 cadet_handle = cadet_h;
1302 peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
1303 valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
1304 restore_valid_peers ();
1305} 1509}
1306 1510
1307 1511
@@ -1312,20 +1516,20 @@ static void
1312peers_terminate () 1516peers_terminate ()
1313{ 1517{
1314 if (GNUNET_SYSERR == 1518 if (GNUNET_SYSERR ==
1315 GNUNET_CONTAINER_multipeermap_iterate (peer_map, 1519 GNUNET_CONTAINER_multipeermap_iterate (mss->peer_map,
1316 &peermap_clear_iterator, 1520 &peermap_clear_iterator,
1317 NULL)) 1521 NULL))
1318 { 1522 {
1319 LOG (GNUNET_ERROR_TYPE_WARNING, 1523 LOG (GNUNET_ERROR_TYPE_WARNING,
1320 "Iteration destroying peers was aborted.\n"); 1524 "Iteration destroying peers was aborted.\n");
1321 } 1525 }
1322 GNUNET_CONTAINER_multipeermap_destroy (peer_map); 1526 GNUNET_CONTAINER_multipeermap_destroy (mss->peer_map);
1323 peer_map = NULL; 1527 mss->peer_map = NULL;
1324 store_valid_peers (); 1528 store_valid_peers ();
1325 GNUNET_free (filename_valid_peers); 1529 GNUNET_free (mss->filename_valid_peers);
1326 filename_valid_peers = NULL; 1530 mss->filename_valid_peers = NULL;
1327 GNUNET_CONTAINER_multipeermap_destroy (valid_peers); 1531 GNUNET_CONTAINER_multipeermap_destroy (mss->valid_peers);
1328 valid_peers = NULL; 1532 mss->valid_peers = NULL;
1329} 1533}
1330 1534
1331 1535
@@ -1370,7 +1574,7 @@ get_valid_peers (PeersIterator iterator,
1370 cls = GNUNET_new (struct PeersIteratorCls); 1574 cls = GNUNET_new (struct PeersIteratorCls);
1371 cls->iterator = iterator; 1575 cls->iterator = iterator;
1372 cls->cls = it_cls; 1576 cls->cls = it_cls;
1373 ret = GNUNET_CONTAINER_multipeermap_iterate (valid_peers, 1577 ret = GNUNET_CONTAINER_multipeermap_iterate (mss->valid_peers,
1374 valid_peer_iterator, 1578 valid_peer_iterator,
1375 cls); 1579 cls);
1376 GNUNET_free (cls); 1580 GNUNET_free (cls);
@@ -1430,21 +1634,21 @@ check_peer_flag (const struct GNUNET_PeerIdentity *peer,
1430 * 1634 *
1431 * If not known yet, insert into known peers 1635 * If not known yet, insert into known peers
1432 * 1636 *
1433 * @param peer the peer whose online is to be checked 1637 * @param peer the peer whose liveliness is to be checked
1434 * @return #GNUNET_YES if the check was issued 1638 * @return #GNUNET_YES if the check was issued
1435 * #GNUNET_NO otherwise 1639 * #GNUNET_NO otherwise
1436 */ 1640 */
1437static int 1641static int
1438issue_peer_online_check (const struct GNUNET_PeerIdentity *peer) 1642issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
1439{ 1643{
1440 struct PeerContext *peer_ctx; 1644 struct PeerContext *peer_ctx;
1441 1645
1442 (void) insert_peer (peer); 1646 (void) insert_peer (peer);
1443 peer_ctx = get_peer_ctx (peer); 1647 peer_ctx = get_peer_ctx (peer);
1444 if ( (GNUNET_NO == check_peer_flag (peer, Peers_ONLINE)) && 1648 if ( (GNUNET_NO == check_peer_flag (peer, Peers_ONLINE)) &&
1445 (NULL == peer_ctx->online_check_pending) ) 1649 (NULL == peer_ctx->liveliness_check_pending) )
1446 { 1650 {
1447 check_peer_online (peer_ctx); 1651 check_peer_live (peer_ctx);
1448 return GNUNET_YES; 1652 return GNUNET_YES;
1449 } 1653 }
1450 return GNUNET_NO; 1654 return GNUNET_NO;
@@ -1469,7 +1673,7 @@ check_removable (const struct GNUNET_PeerIdentity *peer)
1469{ 1673{
1470 struct PeerContext *peer_ctx; 1674 struct PeerContext *peer_ctx;
1471 1675
1472 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) 1676 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mss->peer_map, peer))
1473 { 1677 {
1474 return GNUNET_SYSERR; 1678 return GNUNET_SYSERR;
1475 } 1679 }
@@ -1498,7 +1702,7 @@ check_removable (const struct GNUNET_PeerIdentity *peer)
1498static int 1702static int
1499check_peer_valid (const struct GNUNET_PeerIdentity *peer) 1703check_peer_valid (const struct GNUNET_PeerIdentity *peer)
1500{ 1704{
1501 return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); 1705 return GNUNET_CONTAINER_multipeermap_contains (mss->valid_peers, peer);
1502} 1706}
1503 1707
1504 1708
@@ -1566,7 +1770,7 @@ handle_inbound_channel (void *cls,
1566 GNUNET_assert (NULL != channel); /* according to cadet API */ 1770 GNUNET_assert (NULL != channel); /* according to cadet API */
1567 /* Make sure we 'know' about this peer */ 1771 /* Make sure we 'know' about this peer */
1568 peer_ctx = create_or_get_peer_ctx (initiator); 1772 peer_ctx = create_or_get_peer_ctx (initiator);
1569 set_peer_online (peer_ctx); 1773 set_peer_live (peer_ctx);
1570 ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); 1774 ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity);
1571 *ctx_peer = *initiator; 1775 *ctx_peer = *initiator;
1572 channel_ctx = add_channel_ctx (peer_ctx); 1776 channel_ctx = add_channel_ctx (peer_ctx);
@@ -1675,8 +1879,7 @@ send_message (const struct GNUNET_PeerIdentity *peer,
1675 * 1879 *
1676 * Avoids scheduling an operation twice. 1880 * Avoids scheduling an operation twice.
1677 * 1881 *
1678 * @param peer the peer we want to schedule the operation for once it gets 1882 * @param peer the peer we want to schedule the operation for once it gets live
1679 * online
1680 * 1883 *
1681 * @return #GNUNET_YES if the operation was scheduled 1884 * @return #GNUNET_YES if the operation was scheduled
1682 * #GNUNET_NO otherwise 1885 * #GNUNET_NO otherwise
@@ -1690,7 +1893,7 @@ schedule_operation (const struct GNUNET_PeerIdentity *peer,
1690 1893
1691 GNUNET_assert (GNUNET_YES == check_peer_known (peer)); 1894 GNUNET_assert (GNUNET_YES == check_peer_known (peer));
1692 1895
1693 //TODO if ONLINE execute immediately 1896 //TODO if LIVE/ONLINE execute immediately
1694 1897
1695 if (GNUNET_NO == check_operation_scheduled (peer, peer_op)) 1898 if (GNUNET_NO == check_operation_scheduled (peer, peer_op))
1696 { 1899 {
@@ -1791,213 +1994,6 @@ struct ClientContext *cli_ctx_tail;
1791 1994
1792 1995
1793/*********************************************************************** 1996/***********************************************************************
1794 * Globals
1795***********************************************************************/
1796
1797/**
1798 * Sampler used for the Brahms protocol itself.
1799 */
1800static struct RPS_Sampler *prot_sampler;
1801
1802/**
1803 * Name to log view to
1804 */
1805static const char *file_name_view_log;
1806
1807#ifdef TO_FILE
1808/**
1809 * Name to log number of observed peers to
1810 */
1811static const char *file_name_observed_log;
1812
1813/**
1814 * @brief Count the observed peers
1815 */
1816static uint32_t num_observed_peers;
1817
1818/**
1819 * @brief Multipeermap (ab-) used to count unique peer_ids
1820 */
1821static struct GNUNET_CONTAINER_MultiPeerMap *observed_unique_peers;
1822#endif /* TO_FILE */
1823
1824/**
1825 * The size of sampler we need to be able to satisfy the Brahms protocol's
1826 * need of random peers.
1827 *
1828 * This is one minimum size the sampler grows to.
1829 */
1830static unsigned int sampler_size_est_need;
1831
1832/**
1833 * @brief This is the minimum estimate used as sampler size.
1834 *
1835 * It is configured by the user.
1836 */
1837static unsigned int sampler_size_est_min;
1838
1839/**
1840 * @brief This is the estimate used as view size.
1841 *
1842 * It is initialised with the minimum
1843 */
1844static unsigned int view_size_est_need;
1845
1846/**
1847 * @brief This is the minimum estimate used as view size.
1848 *
1849 * It is configured by the user.
1850 */
1851static unsigned int view_size_est_min;
1852
1853/**
1854 * Percentage of total peer number in the view
1855 * to send random PUSHes to
1856 */
1857static float alpha;
1858
1859/**
1860 * Percentage of total peer number in the view
1861 * to send random PULLs to
1862 */
1863static float beta;
1864
1865/**
1866 * Identifier for the main task that runs periodically.
1867 */
1868static struct GNUNET_SCHEDULER_Task *do_round_task;
1869
1870/**
1871 * Time inverval the do_round task runs in.
1872 */
1873static struct GNUNET_TIME_Relative round_interval;
1874
1875/**
1876 * List to store peers received through pushes temporary.
1877 */
1878static struct CustomPeerMap *push_map;
1879
1880/**
1881 * List to store peers received through pulls temporary.
1882 */
1883static struct CustomPeerMap *pull_map;
1884
1885/**
1886 * Handler to NSE.
1887 */
1888static struct GNUNET_NSE_Handle *nse;
1889
1890/**
1891 * Handler to CADET.
1892 */
1893static struct GNUNET_CADET_Handle *cadet_handle;
1894
1895/**
1896 * @brief Port to communicate to other peers.
1897 */
1898static struct GNUNET_CADET_Port *cadet_port;
1899
1900/**
1901 * Handler to PEERINFO.
1902 */
1903static struct GNUNET_PEERINFO_Handle *peerinfo_handle;
1904
1905/**
1906 * Handle for cancellation of iteration over peers.
1907 */
1908static struct GNUNET_PEERINFO_NotifyContext *peerinfo_notify_handle;
1909
1910
1911#ifdef ENABLE_MALICIOUS
1912/**
1913 * Type of malicious peer
1914 *
1915 * 0 Don't act malicious at all - Default
1916 * 1 Try to maximise representation
1917 * 2 Try to partition the network
1918 * 3 Combined attack
1919 */
1920static uint32_t mal_type;
1921
1922/**
1923 * Other malicious peers
1924 */
1925static struct GNUNET_PeerIdentity *mal_peers;
1926
1927/**
1928 * Hashmap of malicious peers used as set.
1929 * Used to more efficiently check whether we know that peer.
1930 */
1931static struct GNUNET_CONTAINER_MultiPeerMap *mal_peer_set;
1932
1933/**
1934 * Number of other malicious peers
1935 */
1936static uint32_t num_mal_peers;
1937
1938
1939/**
1940 * If type is 2 This struct is used to store the attacked peers in a DLL
1941 */
1942struct AttackedPeer
1943{
1944 /**
1945 * DLL
1946 */
1947 struct AttackedPeer *next;
1948 struct AttackedPeer *prev;
1949
1950 /**
1951 * PeerID
1952 */
1953 struct GNUNET_PeerIdentity peer_id;
1954};
1955
1956/**
1957 * If type is 2 this is the DLL of attacked peers
1958 */
1959static struct AttackedPeer *att_peers_head;
1960static struct AttackedPeer *att_peers_tail;
1961
1962/**
1963 * This index is used to point to an attacked peer to
1964 * implement the round-robin-ish way to select attacked peers.
1965 */
1966static struct AttackedPeer *att_peer_index;
1967
1968/**
1969 * Hashmap of attacked peers used as set.
1970 * Used to more efficiently check whether we know that peer.
1971 */
1972static struct GNUNET_CONTAINER_MultiPeerMap *att_peer_set;
1973
1974/**
1975 * Number of attacked peers
1976 */
1977static uint32_t num_attacked_peers;
1978
1979/**
1980 * If type is 1 this is the attacked peer
1981 */
1982static struct GNUNET_PeerIdentity attacked_peer;
1983
1984/**
1985 * The limit of PUSHes we can send in one round.
1986 * This is an assumption of the Brahms protocol and either implemented
1987 * via proof of work
1988 * or
1989 * assumend to be the bandwidth limitation.
1990 */
1991static uint32_t push_limit = 10000;
1992#endif /* ENABLE_MALICIOUS */
1993
1994
1995/***********************************************************************
1996 * /Globals
1997***********************************************************************/
1998
1999
2000/***********************************************************************
2001 * Util functions 1997 * Util functions
2002***********************************************************************/ 1998***********************************************************************/
2003 1999
@@ -2062,7 +2058,7 @@ rem_from_list (struct GNUNET_PeerIdentity **peer_list,
2062/** 2058/**
2063 * Insert PeerID in #view 2059 * Insert PeerID in #view
2064 * 2060 *
2065 * Called once we know a peer is online. 2061 * Called once we know a peer is live.
2066 * Implements #PeerOp 2062 * Implements #PeerOp
2067 * 2063 *
2068 * @return GNUNET_OK if peer was actually inserted 2064 * @return GNUNET_OK if peer was actually inserted
@@ -2075,7 +2071,7 @@ insert_in_view_op (void *cls,
2075/** 2071/**
2076 * Insert PeerID in #view 2072 * Insert PeerID in #view
2077 * 2073 *
2078 * Called once we know a peer is online. 2074 * Called once we know a peer is live.
2079 * 2075 *
2080 * @return GNUNET_OK if peer was actually inserted 2076 * @return GNUNET_OK if peer was actually inserted
2081 * GNUNET_NO if peer was not inserted 2077 * GNUNET_NO if peer was not inserted
@@ -2090,7 +2086,7 @@ insert_in_view (const struct GNUNET_PeerIdentity *peer)
2090 if ( (GNUNET_NO == online) || 2086 if ( (GNUNET_NO == online) ||
2091 (GNUNET_SYSERR == online) ) /* peer is not even known */ 2087 (GNUNET_SYSERR == online) ) /* peer is not even known */
2092 { 2088 {
2093 (void) issue_peer_online_check (peer); 2089 (void) issue_peer_liveliness_check (peer);
2094 (void) schedule_operation (peer, insert_in_view_op); 2090 (void) schedule_operation (peer, insert_in_view_op);
2095 return GNUNET_NO; 2091 return GNUNET_NO;
2096 } 2092 }
@@ -2254,7 +2250,7 @@ hist_update (const struct GNUNET_PeerIdentity *ids,
2254 { 2250 {
2255 clients_notify_stream_peer (1, &ids[i]); 2251 clients_notify_stream_peer (1, &ids[i]);
2256 } 2252 }
2257 to_file (file_name_view_log, 2253 to_file (mss->file_name_view_log,
2258 "+%s\t(hist)", 2254 "+%s\t(hist)",
2259 GNUNET_i2s_full (ids)); 2255 GNUNET_i2s_full (ids));
2260 } 2256 }
@@ -2377,7 +2373,7 @@ send_pull_reply (const struct GNUNET_PeerIdentity *peer_id,
2377/** 2373/**
2378 * Insert PeerID in #pull_map 2374 * Insert PeerID in #pull_map
2379 * 2375 *
2380 * Called once we know a peer is online. 2376 * Called once we know a peer is live.
2381 */ 2377 */
2382static void 2378static void
2383insert_in_pull_map (void *cls, 2379insert_in_pull_map (void *cls,
@@ -2391,7 +2387,7 @@ insert_in_pull_map (void *cls,
2391/** 2387/**
2392 * Insert PeerID in #view 2388 * Insert PeerID in #view
2393 * 2389 *
2394 * Called once we know a peer is online. 2390 * Called once we know a peer is live.
2395 * Implements #PeerOp 2391 * Implements #PeerOp
2396 */ 2392 */
2397static void 2393static void
@@ -2421,35 +2417,35 @@ insert_in_sampler (void *cls,
2421 LOG (GNUNET_ERROR_TYPE_DEBUG, 2417 LOG (GNUNET_ERROR_TYPE_DEBUG,
2422 "Updating samplers with peer %s from insert_in_sampler()\n", 2418 "Updating samplers with peer %s from insert_in_sampler()\n",
2423 GNUNET_i2s (peer)); 2419 GNUNET_i2s (peer));
2424 RPS_sampler_update (prot_sampler, peer); 2420 RPS_sampler_update (mss->sampler, peer);
2425 if (0 < RPS_sampler_count_id (prot_sampler, peer)) 2421 if (0 < RPS_sampler_count_id (mss->sampler, peer))
2426 { 2422 {
2427 /* Make sure we 'know' about this peer */ 2423 /* Make sure we 'know' about this peer */
2428 (void) issue_peer_online_check (peer); 2424 (void) issue_peer_liveliness_check (peer);
2429 /* Establish a channel towards that peer to indicate we are going to send 2425 /* Establish a channel towards that peer to indicate we are going to send
2430 * messages to it */ 2426 * messages to it */
2431 //indicate_sending_intention (peer); 2427 //indicate_sending_intention (peer);
2432 } 2428 }
2433 #ifdef TO_FILE 2429 #ifdef TO_FILE
2434 num_observed_peers++; 2430 mss->num_observed_peers++;
2435 GNUNET_CONTAINER_multipeermap_put 2431 GNUNET_CONTAINER_multipeermap_put
2436 (observed_unique_peers, 2432 (mss->observed_unique_peers,
2437 peer, 2433 peer,
2438 NULL, 2434 NULL,
2439 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 2435 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
2440 uint32_t num_observed_unique_peers = GNUNET_CONTAINER_multipeermap_size ( 2436 uint32_t num_observed_unique_peers =
2441 observed_unique_peers); 2437 GNUNET_CONTAINER_multipeermap_size (mss->observed_unique_peers);
2442 to_file (file_name_observed_log, 2438 to_file (mss->file_name_observed_log,
2443 "%" PRIu32 " %" PRIu32 " %f\n", 2439 "%" PRIu32 " %" PRIu32 " %f\n",
2444 num_observed_peers, 2440 mss->num_observed_peers,
2445 num_observed_unique_peers, 2441 num_observed_unique_peers,
2446 1.0*num_observed_unique_peers/num_observed_peers) 2442 1.0*num_observed_unique_peers/mss->num_observed_peers)
2447 #endif /* TO_FILE */ 2443 #endif /* TO_FILE */
2448} 2444}
2449 2445
2450/** 2446/**
2451 * @brief This is called on peers from external sources (cadet, peerinfo, ...) 2447 * @brief This is called on peers from external sources (cadet, peerinfo, ...)
2452 * If the peer is not known, online check is issued and it is 2448 * If the peer is not known, liveliness check is issued and it is
2453 * scheduled to be inserted in sampler and view. 2449 * scheduled to be inserted in sampler and view.
2454 * 2450 *
2455 * "External sources" refer to every source except the gossip. 2451 * "External sources" refer to every source except the gossip.
@@ -2460,7 +2456,7 @@ static void
2460got_peer (const struct GNUNET_PeerIdentity *peer) 2456got_peer (const struct GNUNET_PeerIdentity *peer)
2461{ 2457{
2462 /* If we did not know this peer already, insert it into sampler and view */ 2458 /* If we did not know this peer already, insert it into sampler and view */
2463 if (GNUNET_YES == issue_peer_online_check (peer)) 2459 if (GNUNET_YES == issue_peer_liveliness_check (peer))
2464 { 2460 {
2465 schedule_operation (peer, insert_in_sampler); 2461 schedule_operation (peer, insert_in_sampler);
2466 schedule_operation (peer, insert_in_view_op); 2462 schedule_operation (peer, insert_in_view_op);
@@ -2488,10 +2484,10 @@ check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer)
2488 } 2484 }
2489 if (GNUNET_YES == check_sending_channel_exists (peer)) 2485 if (GNUNET_YES == check_sending_channel_exists (peer))
2490 { 2486 {
2491 if ( (0 < RPS_sampler_count_id (prot_sampler, peer)) || 2487 if ( (0 < RPS_sampler_count_id (mss->sampler, peer)) ||
2492 (GNUNET_YES == View_contains_peer (peer)) || 2488 (GNUNET_YES == View_contains_peer (peer)) ||
2493 (GNUNET_YES == CustomPeerMap_contains_peer (push_map, peer)) || 2489 (GNUNET_YES == CustomPeerMap_contains_peer (mss->push_map, peer)) ||
2494 (GNUNET_YES == CustomPeerMap_contains_peer (pull_map, peer)) || 2490 (GNUNET_YES == CustomPeerMap_contains_peer (mss->pull_map, peer)) ||
2495 (GNUNET_YES == check_peer_flag (peer, Peers_PULL_REPLY_PENDING))) 2491 (GNUNET_YES == check_peer_flag (peer, Peers_PULL_REPLY_PENDING)))
2496 { /* If we want to keep the connection to peer open */ 2492 { /* If we want to keep the connection to peer open */
2497 return GNUNET_YES; 2493 return GNUNET_YES;
@@ -2511,9 +2507,9 @@ static void
2511remove_peer (const struct GNUNET_PeerIdentity *peer) 2507remove_peer (const struct GNUNET_PeerIdentity *peer)
2512{ 2508{
2513 (void) View_remove_peer (peer); 2509 (void) View_remove_peer (peer);
2514 CustomPeerMap_remove_peer (pull_map, peer); 2510 CustomPeerMap_remove_peer (mss->pull_map, peer);
2515 CustomPeerMap_remove_peer (push_map, peer); 2511 CustomPeerMap_remove_peer (mss->push_map, peer);
2516 RPS_sampler_reinitialise_by_value (prot_sampler, peer); 2512 RPS_sampler_reinitialise_by_value (mss->sampler, peer);
2517 destroy_peer (get_peer_ctx (peer)); 2513 destroy_peer (get_peer_ctx (peer));
2518} 2514}
2519 2515
@@ -2543,9 +2539,9 @@ clean_peer (const struct GNUNET_PeerIdentity *peer)
2543 2539
2544 if ( (GNUNET_NO == check_peer_send_intention (peer)) && 2540 if ( (GNUNET_NO == check_peer_send_intention (peer)) &&
2545 (GNUNET_NO == View_contains_peer (peer)) && 2541 (GNUNET_NO == View_contains_peer (peer)) &&
2546 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && 2542 (GNUNET_NO == CustomPeerMap_contains_peer (mss->push_map, peer)) &&
2547 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && 2543 (GNUNET_NO == CustomPeerMap_contains_peer (mss->push_map, peer)) &&
2548 (0 == RPS_sampler_count_id (prot_sampler, peer)) && 2544 (0 == RPS_sampler_count_id (mss->sampler, peer)) &&
2549 (GNUNET_NO != check_removable (peer)) ) 2545 (GNUNET_NO != check_removable (peer)) )
2550 { /* We can safely remove this peer */ 2546 { /* We can safely remove this peer */
2551 LOG (GNUNET_ERROR_TYPE_DEBUG, 2547 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2591,6 +2587,116 @@ cleanup_destroyed_channel (void *cls,
2591 * /Util functions 2587 * /Util functions
2592***********************************************************************/ 2588***********************************************************************/
2593 2589
2590
2591
2592/***********************************************************************
2593 * SubSampler
2594***********************************************************************/
2595
2596struct SubSampler *
2597new_subsampler (const char *shared_value,
2598 uint32_t sampler_size,
2599 struct GNUNET_TIME_Relative round_interval)
2600{
2601 struct SubSampler *ss;
2602 char hash_port_string[512] = GNUNET_APPLICATION_PORT_RPS;
2603
2604 ss = GNUNET_new (struct SubSampler);
2605
2606 /* With the hash generated from the secret value this service only connects
2607 * to rps instances that share the value */
2608 strcat (hash_port_string, shared_value);
2609 GNUNET_CRYPTO_hash (hash_port_string,
2610 strlen (hash_port_string),
2611 &ss->port);
2612 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
2613 GNUNET_MQ_hd_fixed_size (peer_check,
2614 GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE,
2615 struct GNUNET_MessageHeader,
2616 NULL),
2617 GNUNET_MQ_hd_fixed_size (peer_push,
2618 GNUNET_MESSAGE_TYPE_RPS_PP_PUSH,
2619 struct GNUNET_MessageHeader,
2620 NULL),
2621 GNUNET_MQ_hd_fixed_size (peer_pull_request,
2622 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
2623 struct GNUNET_MessageHeader,
2624 NULL),
2625 GNUNET_MQ_hd_var_size (peer_pull_reply,
2626 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY,
2627 struct GNUNET_RPS_P2P_PullReplyMessage,
2628 NULL),
2629 GNUNET_MQ_handler_end ()
2630 };
2631 ss->cadet_handle = GNUNET_CADET_connect (cfg);
2632 GNUNET_assert (NULL != ss->cadet_handle);
2633 ss->cadet_port =
2634 GNUNET_CADET_open_port (ss->cadet_handle,
2635 &ss->port,
2636 &handle_inbound_channel, /* Connect handler */
2637 NULL, /* cls */
2638 NULL, /* WindowSize handler */
2639 &cleanup_destroyed_channel, /* Disconnect handler */
2640 cadet_handlers);
2641 if (NULL == ss->cadet_port)
2642 {
2643 LOG (GNUNET_ERROR_TYPE_ERROR,
2644 "Cadet port `%s' is already in use.\n",
2645 GNUNET_APPLICATION_PORT_RPS);
2646 GNUNET_assert (0);
2647 }
2648
2649 /* Set up general data structure to keep track about peers */
2650 ss->valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
2651 if (GNUNET_OK !=
2652 GNUNET_CONFIGURATION_get_value_filename (cfg,
2653 "rps",
2654 "FILENAME_VALID_PEERS",
2655 &ss->filename_valid_peers))
2656 {
2657 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2658 "rps",
2659 "FILENAME_VALID_PEERS");
2660 }
2661 ss->peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
2662
2663 /* Set up the sampler */
2664 ss->sampler_size_est_min = sampler_size;
2665 ss->sampler_size_est_need = sampler_size;;
2666 LOG (GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", ss->sampler_size_est_min);
2667 ss->round_interval = round_interval;
2668 ss->sampler = RPS_sampler_init (sampler_size,
2669 round_interval);
2670
2671 /* Logging of internals */
2672 ss->file_name_view_log = store_prefix_file_name (&own_identity, "view");
2673 #ifdef TO_FILE
2674 ss->file_name_observed_log = store_prefix_file_name (&own_identity,
2675 "observed");
2676 ss->num_observed_peers = 0;
2677 ss->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1,
2678 GNUNET_NO);
2679 #endif /* TO_FILE */
2680
2681 /* Set up data structures for gossip */
2682 ss->push_map = CustomPeerMap_create (4);
2683 ss->pull_map = CustomPeerMap_create (4);
2684 ss->view_size_est_min = sampler_size;;
2685 View_create (ss->view_size_est_min);
2686 GNUNET_STATISTICS_set (stats,
2687 "view size aim",
2688 ss->view_size_est_min,
2689 GNUNET_NO);
2690
2691
2692 return ss;
2693}
2694
2695/***********************************************************************
2696 * /SubSampler
2697***********************************************************************/
2698
2699
2594static void 2700static void
2595destroy_cli_ctx (struct ClientContext *cli_ctx) 2701destroy_cli_ctx (struct ClientContext *cli_ctx)
2596{ 2702{
@@ -2620,29 +2726,29 @@ nse_callback (void *cls,
2620 2726
2621 LOG (GNUNET_ERROR_TYPE_DEBUG, 2727 LOG (GNUNET_ERROR_TYPE_DEBUG,
2622 "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n", 2728 "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n",
2623 logestimate, std_dev, RPS_sampler_get_size (prot_sampler)); 2729 logestimate, std_dev, RPS_sampler_get_size (mss->sampler));
2624 //scale = .01; 2730 //scale = .01;
2625 estimate = GNUNET_NSE_log_estimate_to_n (logestimate); 2731 estimate = GNUNET_NSE_log_estimate_to_n (logestimate);
2626 // GNUNET_NSE_log_estimate_to_n (logestimate); 2732 // GNUNET_NSE_log_estimate_to_n (logestimate);
2627 estimate = pow (estimate, 1.0 / 3); 2733 estimate = pow (estimate, 1.0 / 3);
2628 // TODO add if std_dev is a number 2734 // TODO add if std_dev is a number
2629 // estimate += (std_dev * scale); 2735 // estimate += (std_dev * scale);
2630 if (view_size_est_min < ceil (estimate)) 2736 if (mss->view_size_est_min < ceil (estimate))
2631 { 2737 {
2632 LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate); 2738 LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate);
2633 sampler_size_est_need = estimate; 2739 mss->sampler_size_est_need = estimate;
2634 view_size_est_need = estimate; 2740 mss->view_size_est_need = estimate;
2635 } else 2741 } else
2636 { 2742 {
2637 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate); 2743 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate);
2638 //sampler_size_est_need = view_size_est_min; 2744 //mss->sampler_size_est_need = mss->view_size_est_min;
2639 view_size_est_need = view_size_est_min; 2745 mss->view_size_est_need = mss->view_size_est_min;
2640 } 2746 }
2641 GNUNET_STATISTICS_set (stats, "view size aim", view_size_est_need, GNUNET_NO); 2747 GNUNET_STATISTICS_set (stats, "view size aim", mss->view_size_est_need, GNUNET_NO);
2642 2748
2643 /* If the NSE has changed adapt the lists accordingly */ 2749 /* If the NSE has changed adapt the lists accordingly */
2644 resize_wrapper (prot_sampler, sampler_size_est_need); 2750 resize_wrapper (mss->sampler, mss->sampler_size_est_need);
2645 View_change_len (view_size_est_need); 2751 View_change_len (mss->view_size_est_need);
2646} 2752}
2647 2753
2648 2754
@@ -2828,7 +2934,7 @@ handle_peer_check (void *cls,
2828 LOG (GNUNET_ERROR_TYPE_DEBUG, 2934 LOG (GNUNET_ERROR_TYPE_DEBUG,
2829 "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); 2935 "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer));
2830 GNUNET_STATISTICS_update (stats, 2936 GNUNET_STATISTICS_update (stats,
2831 "# pending online checks", 2937 "# pending liveliness checks",
2832 -1, 2938 -1,
2833 GNUNET_NO); 2939 GNUNET_NO);
2834 2940
@@ -2892,7 +2998,7 @@ handle_peer_push (void *cls,
2892 #endif /* ENABLE_MALICIOUS */ 2998 #endif /* ENABLE_MALICIOUS */
2893 2999
2894 /* Add the sending peer to the push_map */ 3000 /* Add the sending peer to the push_map */
2895 CustomPeerMap_put (push_map, peer); 3001 CustomPeerMap_put (mss->push_map, peer);
2896 3002
2897 GNUNET_break_op (check_peer_known (peer)); 3003 GNUNET_break_op (check_peer_known (peer));
2898 GNUNET_CADET_receive_done (channel_ctx->channel); 3004 GNUNET_CADET_receive_done (channel_ctx->channel);
@@ -3057,12 +3163,12 @@ handle_peer_pull_reply (void *cls,
3057 3163
3058 if (GNUNET_YES == check_peer_valid (&peers[i])) 3164 if (GNUNET_YES == check_peer_valid (&peers[i]))
3059 { 3165 {
3060 CustomPeerMap_put (pull_map, &peers[i]); 3166 CustomPeerMap_put (mss->pull_map, &peers[i]);
3061 } 3167 }
3062 else 3168 else
3063 { 3169 {
3064 schedule_operation (&peers[i], insert_in_pull_map); 3170 schedule_operation (&peers[i], insert_in_pull_map);
3065 (void) issue_peer_online_check (&peers[i]); 3171 (void) issue_peer_liveliness_check (&peers[i]);
3066 } 3172 }
3067 } 3173 }
3068 3174
@@ -3253,8 +3359,8 @@ handle_client_act_malicious (void *cls,
3253 mal_peer_set); 3359 mal_peer_set);
3254 3360
3255 /* Substitute do_round () with do_mal_round () */ 3361 /* Substitute do_round () with do_mal_round () */
3256 GNUNET_SCHEDULER_cancel (do_round_task); 3362 GNUNET_SCHEDULER_cancel (mss->do_round_task);
3257 do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, NULL); 3363 mss->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, NULL);
3258 } 3364 }
3259 3365
3260 else if ( (2 == mal_type) || 3366 else if ( (2 == mal_type) ||
@@ -3288,7 +3394,7 @@ handle_client_act_malicious (void *cls,
3288 /* Set the flag of the attacked peer to valid to avoid problems */ 3394 /* Set the flag of the attacked peer to valid to avoid problems */
3289 if (GNUNET_NO == check_peer_known (&attacked_peer)) 3395 if (GNUNET_NO == check_peer_known (&attacked_peer))
3290 { 3396 {
3291 (void) issue_peer_online_check (&attacked_peer); 3397 (void) issue_peer_liveliness_check (&attacked_peer);
3292 } 3398 }
3293 3399
3294 LOG (GNUNET_ERROR_TYPE_DEBUG, 3400 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -3296,16 +3402,16 @@ handle_client_act_malicious (void *cls,
3296 GNUNET_i2s (&attacked_peer)); 3402 GNUNET_i2s (&attacked_peer));
3297 3403
3298 /* Substitute do_round () with do_mal_round () */ 3404 /* Substitute do_round () with do_mal_round () */
3299 GNUNET_SCHEDULER_cancel (do_round_task); 3405 GNUNET_SCHEDULER_cancel (mss->do_round_task);
3300 do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, NULL); 3406 mss->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, NULL);
3301 } 3407 }
3302 else if (0 == mal_type) 3408 else if (0 == mal_type)
3303 { /* Stop acting malicious */ 3409 { /* Stop acting malicious */
3304 GNUNET_array_grow (mal_peers, num_mal_peers, 0); 3410 GNUNET_array_grow (mal_peers, num_mal_peers, 0);
3305 3411
3306 /* Substitute do_mal_round () with do_round () */ 3412 /* Substitute do_mal_round () with do_round () */
3307 GNUNET_SCHEDULER_cancel (do_round_task); 3413 GNUNET_SCHEDULER_cancel (mss->do_round_task);
3308 do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL); 3414 mss->do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL);
3309 } 3415 }
3310 else 3416 else
3311 { 3417 {
@@ -3333,7 +3439,7 @@ do_mal_round (void *cls)
3333 LOG (GNUNET_ERROR_TYPE_DEBUG, 3439 LOG (GNUNET_ERROR_TYPE_DEBUG,
3334 "Going to execute next round maliciously type %" PRIu32 ".\n", 3440 "Going to execute next round maliciously type %" PRIu32 ".\n",
3335 mal_type); 3441 mal_type);
3336 do_round_task = NULL; 3442 mss->do_round_task = NULL;
3337 GNUNET_assert (mal_type <= 3); 3443 GNUNET_assert (mal_type <= 3);
3338 /* Do malicious actions */ 3444 /* Do malicious actions */
3339 if (1 == mal_type) 3445 if (1 == mal_type)
@@ -3379,7 +3485,7 @@ do_mal_round (void *cls)
3379 * Send as many pushes to the attacked peer as possible 3485 * Send as many pushes to the attacked peer as possible
3380 * That is one push per round as it will ignore more. 3486 * That is one push per round as it will ignore more.
3381 */ 3487 */
3382 (void) issue_peer_online_check (&attacked_peer); 3488 (void) issue_peer_liveliness_check (&attacked_peer);
3383 if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE)) 3489 if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE))
3384 send_push (&attacked_peer); 3490 send_push (&attacked_peer);
3385 } 3491 }
@@ -3391,7 +3497,7 @@ do_mal_round (void *cls)
3391 /* Send PUSH to attacked peers */ 3497 /* Send PUSH to attacked peers */
3392 if (GNUNET_YES == check_peer_known (&attacked_peer)) 3498 if (GNUNET_YES == check_peer_known (&attacked_peer))
3393 { 3499 {
3394 (void) issue_peer_online_check (&attacked_peer); 3500 (void) issue_peer_liveliness_check (&attacked_peer);
3395 if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE)) 3501 if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE))
3396 { 3502 {
3397 LOG (GNUNET_ERROR_TYPE_DEBUG, 3503 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -3400,7 +3506,7 @@ do_mal_round (void *cls)
3400 send_push (&attacked_peer); 3506 send_push (&attacked_peer);
3401 } 3507 }
3402 } 3508 }
3403 (void) issue_peer_online_check (&attacked_peer); 3509 (void) issue_peer_liveliness_check (&attacked_peer);
3404 3510
3405 /* The maximum of pushes we're going to send this round */ 3511 /* The maximum of pushes we're going to send this round */
3406 num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, 3512 num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1,
@@ -3435,13 +3541,13 @@ do_mal_round (void *cls)
3435 } 3541 }
3436 3542
3437 /* Schedule next round */ 3543 /* Schedule next round */
3438 time_next_round = compute_rand_delay (round_interval, 2); 3544 time_next_round = compute_rand_delay (mss->round_interval, 2);
3439 3545
3440 //do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_mal_round, 3546 //mss->do_round_task = GNUNET_SCHEDULER_add_delayed (mss->round_interval, &do_mal_round,
3441 //NULL); 3547 //NULL);
3442 GNUNET_assert (NULL == do_round_task); 3548 GNUNET_assert (NULL == mss->do_round_task);
3443 do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, 3549 mss->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
3444 &do_mal_round, NULL); 3550 &do_mal_round, NULL);
3445 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); 3551 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
3446} 3552}
3447#endif /* ENABLE_MALICIOUS */ 3553#endif /* ENABLE_MALICIOUS */
@@ -3468,17 +3574,17 @@ do_round (void *cls)
3468 LOG (GNUNET_ERROR_TYPE_DEBUG, 3574 LOG (GNUNET_ERROR_TYPE_DEBUG,
3469 "Going to execute next round.\n"); 3575 "Going to execute next round.\n");
3470 GNUNET_STATISTICS_update(stats, "# rounds", 1, GNUNET_NO); 3576 GNUNET_STATISTICS_update(stats, "# rounds", 1, GNUNET_NO);
3471 do_round_task = NULL; 3577 mss->do_round_task = NULL;
3472 LOG (GNUNET_ERROR_TYPE_DEBUG, 3578 LOG (GNUNET_ERROR_TYPE_DEBUG,
3473 "Printing view:\n"); 3579 "Printing view:\n");
3474 to_file (file_name_view_log, 3580 to_file (mss->file_name_view_log,
3475 "___ new round ___"); 3581 "___ new round ___");
3476 view_array = View_get_as_array (); 3582 view_array = View_get_as_array ();
3477 for (i = 0; i < View_size (); i++) 3583 for (i = 0; i < View_size (); i++)
3478 { 3584 {
3479 LOG (GNUNET_ERROR_TYPE_DEBUG, 3585 LOG (GNUNET_ERROR_TYPE_DEBUG,
3480 "\t%s\n", GNUNET_i2s (&view_array[i])); 3586 "\t%s\n", GNUNET_i2s (&view_array[i]));
3481 to_file (file_name_view_log, 3587 to_file (mss->file_name_view_log,
3482 "=%s\t(do round)", 3588 "=%s\t(do round)",
3483 GNUNET_i2s_full (&view_array[i])); 3589 GNUNET_i2s_full (&view_array[i]));
3484 } 3590 }
@@ -3532,9 +3638,9 @@ do_round (void *cls)
3532 /* Update view */ 3638 /* Update view */
3533 /* TODO see how many peers are in push-/pull- list! */ 3639 /* TODO see how many peers are in push-/pull- list! */
3534 3640
3535 if ((CustomPeerMap_size (push_map) <= alpha * view_size_est_need) && 3641 if ((CustomPeerMap_size (mss->push_map) <= alpha * mss->view_size_est_need) &&
3536 (0 < CustomPeerMap_size (push_map)) && 3642 (0 < CustomPeerMap_size (mss->push_map)) &&
3537 (0 < CustomPeerMap_size (pull_map))) 3643 (0 < CustomPeerMap_size (mss->pull_map)))
3538 //if (GNUNET_YES) // disable blocking temporarily 3644 //if (GNUNET_YES) // disable blocking temporarily
3539 { /* If conditions for update are fulfilled, update */ 3645 { /* If conditions for update are fulfilled, update */
3540 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n"); 3646 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n");
@@ -3552,16 +3658,16 @@ do_round (void *cls)
3552 3658
3553 /* Seems like recreating is the easiest way of emptying the peermap */ 3659 /* Seems like recreating is the easiest way of emptying the peermap */
3554 View_clear (); 3660 View_clear ();
3555 to_file (file_name_view_log, 3661 to_file (mss->file_name_view_log,
3556 "--- emptied ---"); 3662 "--- emptied ---");
3557 3663
3558 first_border = GNUNET_MIN (ceil (alpha * view_size_est_need), 3664 first_border = GNUNET_MIN (ceil (alpha * mss->view_size_est_need),
3559 CustomPeerMap_size (push_map)); 3665 CustomPeerMap_size (mss->push_map));
3560 second_border = first_border + 3666 second_border = first_border +
3561 GNUNET_MIN (floor (beta * view_size_est_need), 3667 GNUNET_MIN (floor (beta * mss->view_size_est_need),
3562 CustomPeerMap_size (pull_map)); 3668 CustomPeerMap_size (mss->pull_map));
3563 final_size = second_border + 3669 final_size = second_border +
3564 ceil ((1 - (alpha + beta)) * view_size_est_need); 3670 ceil ((1 - (alpha + beta)) * mss->view_size_est_need);
3565 LOG (GNUNET_ERROR_TYPE_DEBUG, 3671 LOG (GNUNET_ERROR_TYPE_DEBUG,
3566 "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %"PRIu32 "\n", 3672 "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %"PRIu32 "\n",
3567 first_border, 3673 first_border,
@@ -3570,18 +3676,18 @@ do_round (void *cls)
3570 3676
3571 /* Update view with peers received through PUSHes */ 3677 /* Update view with peers received through PUSHes */
3572 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, 3678 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG,
3573 CustomPeerMap_size (push_map)); 3679 CustomPeerMap_size (mss->push_map));
3574 for (i = 0; i < first_border; i++) 3680 for (i = 0; i < first_border; i++)
3575 { 3681 {
3576 int inserted; 3682 int inserted;
3577 inserted = insert_in_view (CustomPeerMap_get_peer_by_index (push_map, 3683 inserted = insert_in_view (CustomPeerMap_get_peer_by_index (mss->push_map,
3578 permut[i])); 3684 permut[i]));
3579 if (GNUNET_OK == inserted) 3685 if (GNUNET_OK == inserted)
3580 { 3686 {
3581 clients_notify_stream_peer (1, 3687 clients_notify_stream_peer (1,
3582 CustomPeerMap_get_peer_by_index (push_map, permut[i])); 3688 CustomPeerMap_get_peer_by_index (mss->push_map, permut[i]));
3583 } 3689 }
3584 to_file (file_name_view_log, 3690 to_file (mss->file_name_view_log,
3585 "+%s\t(push list)", 3691 "+%s\t(push list)",
3586 GNUNET_i2s_full (&view_array[i])); 3692 GNUNET_i2s_full (&view_array[i]));
3587 // TODO change the peer_flags accordingly 3693 // TODO change the peer_flags accordingly
@@ -3591,19 +3697,19 @@ do_round (void *cls)
3591 3697
3592 /* Update view with peers received through PULLs */ 3698 /* Update view with peers received through PULLs */
3593 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, 3699 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG,
3594 CustomPeerMap_size (pull_map)); 3700 CustomPeerMap_size (mss->pull_map));
3595 for (i = first_border; i < second_border; i++) 3701 for (i = first_border; i < second_border; i++)
3596 { 3702 {
3597 int inserted; 3703 int inserted;
3598 inserted = insert_in_view (CustomPeerMap_get_peer_by_index (pull_map, 3704 inserted = insert_in_view (CustomPeerMap_get_peer_by_index (mss->pull_map,
3599 permut[i - first_border])); 3705 permut[i - first_border]));
3600 if (GNUNET_OK == inserted) 3706 if (GNUNET_OK == inserted)
3601 { 3707 {
3602 clients_notify_stream_peer (1, 3708 clients_notify_stream_peer (1,
3603 CustomPeerMap_get_peer_by_index (pull_map, 3709 CustomPeerMap_get_peer_by_index (mss->pull_map,
3604 permut[i - first_border])); 3710 permut[i - first_border]));
3605 } 3711 }
3606 to_file (file_name_view_log, 3712 to_file (mss->file_name_view_log,
3607 "+%s\t(pull list)", 3713 "+%s\t(pull list)",
3608 GNUNET_i2s_full (&view_array[i])); 3714 GNUNET_i2s_full (&view_array[i]));
3609 // TODO change the peer_flags accordingly 3715 // TODO change the peer_flags accordingly
@@ -3612,7 +3718,7 @@ do_round (void *cls)
3612 permut = NULL; 3718 permut = NULL;
3613 3719
3614 /* Update view with peers from history */ 3720 /* Update view with peers from history */
3615 RPS_sampler_get_n_rand_peers (prot_sampler, 3721 RPS_sampler_get_n_rand_peers (mss->sampler,
3616 final_size - second_border, 3722 final_size - second_border,
3617 hist_update, 3723 hist_update,
3618 NULL); 3724 NULL);
@@ -3624,7 +3730,7 @@ do_round (void *cls)
3624 /* Clean peers that were removed from the view */ 3730 /* Clean peers that were removed from the view */
3625 for (i = 0; i < peers_to_clean_size; i++) 3731 for (i = 0; i < peers_to_clean_size; i++)
3626 { 3732 {
3627 to_file (file_name_view_log, 3733 to_file (mss->file_name_view_log,
3628 "-%s", 3734 "-%s",
3629 GNUNET_i2s_full (&peers_to_clean[i])); 3735 GNUNET_i2s_full (&peers_to_clean[i]));
3630 clean_peer (&peers_to_clean[i]); 3736 clean_peer (&peers_to_clean[i]);
@@ -3635,31 +3741,31 @@ do_round (void *cls)
3635 } else { 3741 } else {
3636 LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); 3742 LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n");
3637 GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO); 3743 GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO);
3638 if (CustomPeerMap_size (push_map) > alpha * View_size () && 3744 if (CustomPeerMap_size (mss->push_map) > alpha * View_size () &&
3639 !(0 >= CustomPeerMap_size (pull_map))) 3745 !(0 >= CustomPeerMap_size (mss->pull_map)))
3640 GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes", 1, GNUNET_NO); 3746 GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes", 1, GNUNET_NO);
3641 if (CustomPeerMap_size (push_map) > alpha * View_size () && 3747 if (CustomPeerMap_size (mss->push_map) > alpha * View_size () &&
3642 (0 >= CustomPeerMap_size (pull_map))) 3748 (0 >= CustomPeerMap_size (mss->pull_map)))
3643 GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes, no pull replies", 1, GNUNET_NO); 3749 GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes, no pull replies", 1, GNUNET_NO);
3644 if (0 >= CustomPeerMap_size (push_map) && 3750 if (0 >= CustomPeerMap_size (mss->push_map) &&
3645 !(0 >= CustomPeerMap_size (pull_map))) 3751 !(0 >= CustomPeerMap_size (mss->pull_map)))
3646 GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes", 1, GNUNET_NO); 3752 GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes", 1, GNUNET_NO);
3647 if (0 >= CustomPeerMap_size (push_map) && 3753 if (0 >= CustomPeerMap_size (mss->push_map) &&
3648 (0 >= CustomPeerMap_size (pull_map))) 3754 (0 >= CustomPeerMap_size (mss->pull_map)))
3649 GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes, no pull replies", 1, GNUNET_NO); 3755 GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes, no pull replies", 1, GNUNET_NO);
3650 if (0 >= CustomPeerMap_size (pull_map) && 3756 if (0 >= CustomPeerMap_size (mss->pull_map) &&
3651 CustomPeerMap_size (push_map) > alpha * View_size () && 3757 CustomPeerMap_size (mss->push_map) > alpha * View_size () &&
3652 0 >= CustomPeerMap_size (push_map)) 3758 0 >= CustomPeerMap_size (mss->push_map))
3653 GNUNET_STATISTICS_update(stats, "# rounds blocked - no pull replies", 1, GNUNET_NO); 3759 GNUNET_STATISTICS_update(stats, "# rounds blocked - no pull replies", 1, GNUNET_NO);
3654 } 3760 }
3655 // TODO independent of that also get some peers from CADET_get_peers()? 3761 // TODO independent of that also get some peers from CADET_get_peers()?
3656 GNUNET_STATISTICS_set (stats, 3762 GNUNET_STATISTICS_set (stats,
3657 "# peers in push map at end of round", 3763 "# peers in push map at end of round",
3658 CustomPeerMap_size (push_map), 3764 CustomPeerMap_size (mss->push_map),
3659 GNUNET_NO); 3765 GNUNET_NO);
3660 GNUNET_STATISTICS_set (stats, 3766 GNUNET_STATISTICS_set (stats,
3661 "# peers in pull map at end of round", 3767 "# peers in pull map at end of round",
3662 CustomPeerMap_size (pull_map), 3768 CustomPeerMap_size (mss->pull_map),
3663 GNUNET_NO); 3769 GNUNET_NO);
3664 GNUNET_STATISTICS_set (stats, 3770 GNUNET_STATISTICS_set (stats,
3665 "# peers in view at end of round", 3771 "# peers in view at end of round",
@@ -3668,16 +3774,16 @@ do_round (void *cls)
3668 3774
3669 LOG (GNUNET_ERROR_TYPE_DEBUG, 3775 LOG (GNUNET_ERROR_TYPE_DEBUG,
3670 "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (%u) = %.2f)\n", 3776 "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (%u) = %.2f)\n",
3671 CustomPeerMap_size (push_map), 3777 CustomPeerMap_size (mss->push_map),
3672 CustomPeerMap_size (pull_map), 3778 CustomPeerMap_size (mss->pull_map),
3673 alpha, 3779 alpha,
3674 View_size (), 3780 View_size (),
3675 alpha * View_size ()); 3781 alpha * View_size ());
3676 3782
3677 /* Update samplers */ 3783 /* Update samplers */
3678 for (i = 0; i < CustomPeerMap_size (push_map); i++) 3784 for (i = 0; i < CustomPeerMap_size (mss->push_map); i++)
3679 { 3785 {
3680 update_peer = CustomPeerMap_get_peer_by_index (push_map, i); 3786 update_peer = CustomPeerMap_get_peer_by_index (mss->push_map, i);
3681 LOG (GNUNET_ERROR_TYPE_DEBUG, 3787 LOG (GNUNET_ERROR_TYPE_DEBUG,
3682 "Updating with peer %s from push list\n", 3788 "Updating with peer %s from push list\n",
3683 GNUNET_i2s (update_peer)); 3789 GNUNET_i2s (update_peer));
@@ -3685,20 +3791,20 @@ do_round (void *cls)
3685 clean_peer (update_peer); /* This cleans only if it is not in the view */ 3791 clean_peer (update_peer); /* This cleans only if it is not in the view */
3686 } 3792 }
3687 3793
3688 for (i = 0; i < CustomPeerMap_size (pull_map); i++) 3794 for (i = 0; i < CustomPeerMap_size (mss->pull_map); i++)
3689 { 3795 {
3690 LOG (GNUNET_ERROR_TYPE_DEBUG, 3796 LOG (GNUNET_ERROR_TYPE_DEBUG,
3691 "Updating with peer %s from pull list\n", 3797 "Updating with peer %s from pull list\n",
3692 GNUNET_i2s (CustomPeerMap_get_peer_by_index (pull_map, i))); 3798 GNUNET_i2s (CustomPeerMap_get_peer_by_index (mss->pull_map, i)));
3693 insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i)); 3799 insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (mss->pull_map, i));
3694 /* This cleans only if it is not in the view */ 3800 /* This cleans only if it is not in the view */
3695 clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i)); 3801 clean_peer (CustomPeerMap_get_peer_by_index (mss->pull_map, i));
3696 } 3802 }
3697 3803
3698 3804
3699 /* Empty push/pull lists */ 3805 /* Empty push/pull lists */
3700 CustomPeerMap_clear (push_map); 3806 CustomPeerMap_clear (mss->push_map);
3701 CustomPeerMap_clear (pull_map); 3807 CustomPeerMap_clear (mss->pull_map);
3702 3808
3703 GNUNET_STATISTICS_set (stats, 3809 GNUNET_STATISTICS_set (stats,
3704 "view size", 3810 "view size",
@@ -3707,11 +3813,11 @@ do_round (void *cls)
3707 3813
3708 struct GNUNET_TIME_Relative time_next_round; 3814 struct GNUNET_TIME_Relative time_next_round;
3709 3815
3710 time_next_round = compute_rand_delay (round_interval, 2); 3816 time_next_round = compute_rand_delay (mss->round_interval, 2);
3711 3817
3712 /* Schedule next round */ 3818 /* Schedule next round */
3713 do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, 3819 mss->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
3714 &do_round, NULL); 3820 &do_round, NULL);
3715 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); 3821 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
3716} 3822}
3717 3823
@@ -3811,10 +3917,8 @@ shutdown_task (void *cls)
3811 struct ClientContext *client_ctx; 3917 struct ClientContext *client_ctx;
3812 (void) cls; 3918 (void) cls;
3813 3919
3814 in_shutdown = GNUNET_YES;
3815
3816 LOG (GNUNET_ERROR_TYPE_DEBUG, 3920 LOG (GNUNET_ERROR_TYPE_DEBUG,
3817 "RPS is going down\n"); 3921 "RPS service is going down\n");
3818 3922
3819 /* Clean all clients */ 3923 /* Clean all clients */
3820 for (client_ctx = cli_ctx_head; 3924 for (client_ctx = cli_ctx_head;
@@ -3826,22 +3930,22 @@ shutdown_task (void *cls)
3826 GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle); 3930 GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle);
3827 GNUNET_PEERINFO_disconnect (peerinfo_handle); 3931 GNUNET_PEERINFO_disconnect (peerinfo_handle);
3828 peerinfo_handle = NULL; 3932 peerinfo_handle = NULL;
3829 if (NULL != do_round_task) 3933 if (NULL != mss->do_round_task)
3830 { 3934 {
3831 GNUNET_SCHEDULER_cancel (do_round_task); 3935 GNUNET_SCHEDULER_cancel (mss->do_round_task);
3832 do_round_task = NULL; 3936 mss->do_round_task = NULL;
3833 } 3937 }
3834 3938
3835 peers_terminate (); 3939 peers_terminate ();
3836 3940
3837 GNUNET_NSE_disconnect (nse); 3941 GNUNET_NSE_disconnect (nse);
3838 RPS_sampler_destroy (prot_sampler); 3942 RPS_sampler_destroy (mss->sampler);
3839 GNUNET_CADET_close_port (cadet_port); 3943 GNUNET_CADET_close_port (mss->cadet_port);
3840 GNUNET_CADET_disconnect (cadet_handle); 3944 GNUNET_CADET_disconnect (mss->cadet_handle);
3841 cadet_handle = NULL; 3945 mss->cadet_handle = NULL;
3842 View_destroy (); 3946 View_destroy ();
3843 CustomPeerMap_destroy (push_map); 3947 CustomPeerMap_destroy (mss->push_map);
3844 CustomPeerMap_destroy (pull_map); 3948 CustomPeerMap_destroy (mss->pull_map);
3845 if (NULL != stats) 3949 if (NULL != stats)
3846 { 3950 {
3847 GNUNET_STATISTICS_destroy (stats, 3951 GNUNET_STATISTICS_destroy (stats,
@@ -3851,10 +3955,10 @@ shutdown_task (void *cls)
3851#ifdef ENABLE_MALICIOUS 3955#ifdef ENABLE_MALICIOUS
3852 struct AttackedPeer *tmp_att_peer; 3956 struct AttackedPeer *tmp_att_peer;
3853 /* it is ok to free this const during shutdown: */ 3957 /* it is ok to free this const during shutdown: */
3854 GNUNET_free ((char *) file_name_view_log); 3958 GNUNET_free ((char *) mss->file_name_view_log);
3855#ifdef TO_FILE 3959#ifdef TO_FILE
3856 GNUNET_free ((char *) file_name_observed_log); 3960 GNUNET_free ((char *) mss->file_name_observed_log);
3857 GNUNET_CONTAINER_multipeermap_destroy (observed_unique_peers); 3961 GNUNET_CONTAINER_multipeermap_destroy (mss->observed_unique_peers);
3858#endif /* TO_FILE */ 3962#endif /* TO_FILE */
3859 GNUNET_array_grow (mal_peers, 3963 GNUNET_array_grow (mal_peers,
3860 num_mal_peers, 3964 num_mal_peers,
@@ -3949,9 +4053,12 @@ run (void *cls,
3949 struct GNUNET_SERVICE_Handle *service) 4053 struct GNUNET_SERVICE_Handle *service)
3950{ 4054{
3951 char *fn_valid_peers; 4055 char *fn_valid_peers;
4056 struct GNUNET_TIME_Relative round_interval;
4057 long long unsigned int sampler_size;
3952 4058
3953 (void) cls; 4059 (void) cls;
3954 (void) service; 4060 (void) service;
4061
3955 GNUNET_log_setup ("rps", 4062 GNUNET_log_setup ("rps",
3956 GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), 4063 GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG),
3957 NULL); 4064 NULL);
@@ -3982,17 +4089,16 @@ run (void *cls,
3982 4089
3983 /* Get initial size of sampler/view from the configuration */ 4090 /* Get initial size of sampler/view from the configuration */
3984 if (GNUNET_OK != 4091 if (GNUNET_OK !=
3985 GNUNET_CONFIGURATION_get_value_number (cfg, "RPS", "MINSIZE", 4092 GNUNET_CONFIGURATION_get_value_number (cfg,
3986 (long long unsigned int *) &sampler_size_est_min)) 4093 "RPS",
4094 "MINSIZE",
4095 &sampler_size))
3987 { 4096 {
3988 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 4097 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
3989 "RPS", "MINSIZE"); 4098 "RPS", "MINSIZE");
3990 GNUNET_SCHEDULER_shutdown (); 4099 GNUNET_SCHEDULER_shutdown ();
3991 return; 4100 return;
3992 } 4101 }
3993 sampler_size_est_need = sampler_size_est_min;
3994 view_size_est_min = sampler_size_est_min;
3995 LOG (GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sampler_size_est_min);
3996 4102
3997 if (GNUNET_OK != 4103 if (GNUNET_OK !=
3998 GNUNET_CONFIGURATION_get_value_filename (cfg, 4104 GNUNET_CONFIGURATION_get_value_filename (cfg,
@@ -4005,16 +4111,6 @@ run (void *cls,
4005 } 4111 }
4006 4112
4007 4113
4008 View_create (view_size_est_min);
4009 GNUNET_STATISTICS_set (stats, "view size aim", view_size_est_min, GNUNET_NO);
4010
4011 /* file_name_view_log */
4012 file_name_view_log = store_prefix_file_name (&own_identity, "view");
4013 #ifdef TO_FILE
4014 file_name_observed_log = store_prefix_file_name (&own_identity, "observed");
4015 observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO);
4016 #endif /* TO_FILE */
4017
4018 /* connect to NSE */ 4114 /* connect to NSE */
4019 nse = GNUNET_NSE_connect (cfg, nse_callback, NULL); 4115 nse = GNUNET_NSE_connect (cfg, nse_callback, NULL);
4020 4116
@@ -4023,72 +4119,20 @@ run (void *cls,
4023 beta = 0.45; 4119 beta = 0.45;
4024 4120
4025 4121
4026 /* Initialise cadet */ 4122 /* Set up main SubSampler */
4027 /* There exists a copy-paste-clone in get_channel() */ 4123 mss = new_subsampler ("", /* this is the main sampler - no shared value */
4028 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 4124 sampler_size, /* Will be overwritten by config */
4029 GNUNET_MQ_hd_fixed_size (peer_check, 4125 round_interval);
4030 GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE,
4031 struct GNUNET_MessageHeader,
4032 NULL),
4033 GNUNET_MQ_hd_fixed_size (peer_push,
4034 GNUNET_MESSAGE_TYPE_RPS_PP_PUSH,
4035 struct GNUNET_MessageHeader,
4036 NULL),
4037 GNUNET_MQ_hd_fixed_size (peer_pull_request,
4038 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
4039 struct GNUNET_MessageHeader,
4040 NULL),
4041 GNUNET_MQ_hd_var_size (peer_pull_reply,
4042 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY,
4043 struct GNUNET_RPS_P2P_PullReplyMessage,
4044 NULL),
4045 GNUNET_MQ_handler_end ()
4046 };
4047
4048 cadet_handle = GNUNET_CADET_connect (cfg);
4049 GNUNET_assert (NULL != cadet_handle);
4050 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS,
4051 strlen (GNUNET_APPLICATION_PORT_RPS),
4052 &port);
4053 cadet_port = GNUNET_CADET_open_port (cadet_handle,
4054 &port,
4055 &handle_inbound_channel, /* Connect handler */
4056 NULL, /* cls */
4057 NULL, /* WindowSize handler */
4058 &cleanup_destroyed_channel, /* Disconnect handler */
4059 cadet_handlers);
4060 if (NULL == cadet_port)
4061 {
4062 LOG (GNUNET_ERROR_TYPE_ERROR,
4063 "Cadet port `%s' is already in use.\n",
4064 GNUNET_APPLICATION_PORT_RPS);
4065 GNUNET_assert (0);
4066 }
4067 4126
4068 4127
4069 peerinfo_handle = GNUNET_PEERINFO_connect (cfg); 4128 peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
4070 initialise_peers (fn_valid_peers, cadet_handle);
4071 GNUNET_free (fn_valid_peers);
4072
4073 /* Initialise sampler */
4074 struct GNUNET_TIME_Relative half_round_interval;
4075 struct GNUNET_TIME_Relative max_round_interval;
4076
4077 half_round_interval = GNUNET_TIME_relative_divide (round_interval, 2);
4078 max_round_interval = GNUNET_TIME_relative_add (round_interval, half_round_interval);
4079
4080 prot_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval);
4081
4082 /* Initialise push and pull maps */
4083 push_map = CustomPeerMap_create (4);
4084 pull_map = CustomPeerMap_create (4);
4085
4086 4129
4087 //LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n"); 4130 //LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n");
4088 //GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, NULL); 4131 //GNUNET_CADET_get_peers (mss.cadet_handle, &init_peer_cb, NULL);
4089 // TODO send push/pull to each of those peers? 4132 // TODO send push/pull to each of those peers?
4090 // TODO read stored valid peers from last run 4133 // TODO read stored valid peers from last run
4091 LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); 4134 LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n");
4135 restore_valid_peers ();
4092 get_valid_peers (valid_peers_iterator, NULL); 4136 get_valid_peers (valid_peers_iterator, NULL);
4093 4137
4094 peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, 4138 peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg,
@@ -4098,7 +4142,7 @@ run (void *cls,
4098 4142
4099 LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n"); 4143 LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n");
4100 4144
4101 do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL); 4145 mss->do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL);
4102 LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n"); 4146 LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n");
4103 4147
4104 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 4148 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);