GNUnet 0.26.2-114-g7c6b613e3
 
Loading...
Searching...
No Matches
gnunet-service-rps.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "platform.h"
27#include "gnunet_applications.h"
28#include "gnunet_util_lib.h"
30#include "gnunet_core_service.h"
32#include "gnunet_nse_service.h"
34#include "rps.h"
35#include "rps-test_util.h"
39#include "gnunet_constants.h"
40
41#include <math.h>
42#include <inttypes.h>
43#include <string.h>
44
45#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
46
47// TODO check for overflows
48
49// TODO align message structs
50
51// TODO connect to friends
52
53// TODO blacklist? (-> mal peer detection on top of brahms)
54
55// hist_size_init, hist_size_max
56
57/***********************************************************************
58* Old gnunet-service-rps_peers.c
59***********************************************************************/
60
64#define SET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask))
65
69#define check_peer_flag_set(peer_ctx, mask) \
70 ((peer_ctx->peer_flags) & (mask) ? GNUNET_YES : GNUNET_NO)
71
75#define UNSET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask))
76
80#define check_channel_flag_set(channel_flags, mask) \
81 ((*channel_flags) & (mask) ? GNUNET_YES : GNUNET_NO)
82
86#define unset_channel_flag(channel_flags, mask) ((*channel_flags) &= ~(mask))
87
88
96{
101
105 void *op_cls;
106};
107
115{
121
126
131
135 const char *type;
136};
137
141struct ChannelCtx;
142
223
239
262
263
264#if ENABLE_MALICIOUS
265
269struct AttackedPeer
270{
274 struct AttackedPeer *next;
275 struct AttackedPeer *prev;
276
281};
282
283#endif /* ENABLE_MALICIOUS */
284
289#define HISTOGRAM_FILE_SLOTS 32
290
297#define SIZE_DUMP_FILE (HISTOGRAM_FILE_SLOTS * 5) + 1
298
305struct Sub
306{
311
316
321
326
331
338
346
351
356
357#ifdef TO_FILE_FULL
361 char *file_name_view_log;
362#endif /* TO_FILE_FULL */
363
364#ifdef TO_FILE
365#ifdef TO_FILE_FULL
369 char *file_name_observed_log;
370#endif /* TO_FILE_FULL */
371
376
381#endif /* TO_FILE */
382
387
392
398 unsigned int view_size_est_need;
399
405 unsigned int view_size_est_min;
406
410 struct View *view;
411
416
417 /* === stats === */
418
422 uint32_t num_rounds;
423
430
439
447};
448
449
450/***********************************************************************
451* Globals
452***********************************************************************/
453
457static const struct GNUNET_CONFIGURATION_Handle *cfg;
458
463
468
473
478
483
488static float alpha;
489
494static float beta;
495
499static struct GNUNET_NSE_Handle *nse;
500
505
511
512
513#if ENABLE_MALICIOUS
522static uint32_t mal_type;
523
527static struct GNUNET_PeerIdentity *mal_peers;
528
533static struct GNUNET_CONTAINER_MultiPeerMap *mal_peer_set;
534
538static uint32_t num_mal_peers;
539
540
544static struct AttackedPeer *att_peers_head;
545static struct AttackedPeer *att_peers_tail;
546
551static struct AttackedPeer *att_peer_index;
552
557static struct GNUNET_CONTAINER_MultiPeerMap *att_peer_set;
558
562static uint32_t num_attacked_peers;
563
567static struct GNUNET_PeerIdentity attacked_peer;
568
576static uint32_t push_limit = 10000;
577#endif /* ENABLE_MALICIOUS */
578
585static struct Sub *msub;
586
591static const uint32_t num_valid_peers_max = UINT32_MAX;
592
593/***********************************************************************
594* /Globals
595***********************************************************************/
596
597
598static void
599do_round (void *cls);
600
601#if ENABLE_MALICIOUS
602static void
603do_mal_round (void *cls);
604
605#endif /* ENABLE_MALICIOUS */
606
607
616static struct PeerContext *
618 const struct GNUNET_PeerIdentity *peer)
619{
620 struct PeerContext *ctx;
621 int ret;
622
625 ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer);
626 GNUNET_assert (NULL != ctx);
627 return ctx;
628}
629
630
642static int
644 const struct GNUNET_PeerIdentity *peer)
645{
646 if (NULL != peer_map)
647 {
648 return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
649 }
650 else
651 {
652 return GNUNET_NO;
653 }
654}
655
656
665static struct PeerContext *
667 const struct GNUNET_PeerIdentity *peer)
668{
669 struct PeerContext *ctx;
670 int ret;
671
673
674 ctx = GNUNET_new (struct PeerContext);
675 ctx->peer_id = *peer;
676 ctx->sub = sub;
680 if (sub == msub)
681 {
683 "# known peers",
685 GNUNET_NO);
686 }
687 return ctx;
688}
689
690
699static struct PeerContext *
701 const struct GNUNET_PeerIdentity *peer)
702{
703 if (GNUNET_NO == check_peer_known (sub->peer_map, peer))
704 {
705 return create_peer_ctx (sub, peer);
706 }
707 return get_peer_ctx (sub->peer_map, peer);
708}
709
710
721static int
722check_connected (struct PeerContext *peer_ctx)
723{
724 /* If we don't know about this peer we don't know whether it's online */
725 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
726 &peer_ctx->peer_id))
727 {
728 return GNUNET_NO;
729 }
730 /* Get the context */
731 peer_ctx = get_peer_ctx (peer_ctx->sub->peer_map, &peer_ctx->peer_id);
732 /* If we have no channel to this peer we don't know whether it's online */
733 if ((NULL == peer_ctx->send_channel_ctx) &&
734 (NULL == peer_ctx->recv_channel_ctx))
735 {
736 UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE);
737 return GNUNET_NO;
738 }
739 /* Otherwise (if we have a channel, we know that it's online */
740 SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
741 return GNUNET_YES;
742}
743
744
749{
755 uint32_t index;
756
761};
762
763
779static int
781 const struct GNUNET_PeerIdentity *peer,
782 void *value)
783{
784 struct GetRandPeerIteratorCls *iterator_cls = cls;
785
786 (void) value;
787
788 if (0 >= iterator_cls->index)
789 {
790 iterator_cls->peer = peer;
791 return GNUNET_NO;
792 }
793 iterator_cls->index--;
794 return GNUNET_YES;
795}
796
797
806static const struct GNUNET_PeerIdentity *
808{
809 struct GetRandPeerIteratorCls *iterator_cls;
810 const struct GNUNET_PeerIdentity *ret;
811
812 iterator_cls = GNUNET_new (struct GetRandPeerIteratorCls);
815 (
816 valid_peers));
817 (void) GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
819 iterator_cls);
820 ret = iterator_cls->peer;
821 GNUNET_free (iterator_cls);
822 return ret;
823}
824
825
837static int
839 struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
840{
841 const struct GNUNET_PeerIdentity *rand_peer;
842 int ret;
843
844 ret = GNUNET_YES;
845 /* Remove random peers until there is space for a new one */
846 while (num_valid_peers_max <=
848 {
849 rand_peer = get_random_peer_from_peermap (valid_peers);
850 GNUNET_CONTAINER_multipeermap_remove_all (valid_peers, rand_peer);
851 ret = GNUNET_NO;
852 }
853 (void) GNUNET_CONTAINER_multipeermap_put (valid_peers, peer, NULL,
855 if (valid_peers == msub->valid_peers)
856 {
858 "# valid peers",
860 GNUNET_NO);
861 }
862 return ret;
863}
864
865
866static void
867remove_pending_message (struct PendingMessage *pending_msg, int cancel);
868
877static void
878set_peer_online (struct PeerContext *peer_ctx)
879{
880 struct GNUNET_PeerIdentity *peer;
881 unsigned int i;
882
883 peer = &peer_ctx->peer_id;
885 "Peer %s is online and valid, calling %i pending operations on it\n",
886 GNUNET_i2s (peer),
887 peer_ctx->num_pending_ops);
888
889 if (NULL != peer_ctx->online_check_pending)
890 {
892 "Removing pending online check for peer %s\n",
893 GNUNET_i2s (&peer_ctx->peer_id));
894 // TODO wait until cadet sets mq->cancel_impl
895 // GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev);
897 peer_ctx->online_check_pending = NULL;
898 }
899
900 SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
901
902 /* Call pending operations */
903 for (i = 0; i < peer_ctx->num_pending_ops; i++)
904 {
905 peer_ctx->pending_ops[i].op (peer_ctx->pending_ops[i].op_cls, peer);
906 }
907 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
908}
909
910
911static void
913 const struct GNUNET_CADET_Channel *channel);
914
915/* Declaration of handlers */
916static void
917handle_peer_check (void *cls,
918 const struct GNUNET_MessageHeader *msg);
919
920static void
921handle_peer_push (void *cls,
922 const struct GNUNET_MessageHeader *msg);
923
924static void
925handle_peer_pull_request (void *cls,
926 const struct GNUNET_MessageHeader *msg);
927
928static int
929check_peer_pull_reply (void *cls,
931
932static void
933handle_peer_pull_reply (void *cls,
935
936/* End declaration of handlers */
937
945static struct ChannelCtx *
947{
948 struct ChannelCtx *channel_ctx;
949
950 channel_ctx = GNUNET_new (struct ChannelCtx);
951 channel_ctx->peer_ctx = peer_ctx;
952 return channel_ctx;
953}
954
955
961static void
962remove_channel_ctx (struct ChannelCtx *channel_ctx)
963{
964 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
965
966 if (NULL != channel_ctx->destruction_task)
967 {
969 channel_ctx->destruction_task = NULL;
970 }
971
972 if (NULL == peer_ctx)
973 return;
974 if (channel_ctx == peer_ctx->send_channel_ctx)
975 {
976 peer_ctx->send_channel_ctx = NULL;
977 peer_ctx->mq = NULL;
978 }
979 else if (channel_ctx == peer_ctx->recv_channel_ctx)
980 {
981 peer_ctx->recv_channel_ctx = NULL;
982 }
983 GNUNET_free (channel_ctx);
984}
985
986
994get_channel (struct PeerContext *peer_ctx)
995{
996 /* There exists a copy-paste-clone in run() */
997 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
998 GNUNET_MQ_hd_fixed_size (peer_check,
1000 struct GNUNET_MessageHeader,
1001 NULL),
1002 GNUNET_MQ_hd_fixed_size (peer_push,
1004 struct GNUNET_MessageHeader,
1005 NULL),
1006 GNUNET_MQ_hd_fixed_size (peer_pull_request,
1008 struct GNUNET_MessageHeader,
1009 NULL),
1010 GNUNET_MQ_hd_var_size (peer_pull_reply,
1013 NULL),
1015 };
1016
1017
1018 if (NULL == peer_ctx->send_channel_ctx)
1019 {
1021 "Trying to establish channel to peer %s\n",
1022 GNUNET_i2s (&peer_ctx->peer_id));
1023 peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx);
1024 peer_ctx->send_channel_ctx->channel =
1026 peer_ctx->send_channel_ctx, /* context */
1027 &peer_ctx->peer_id,
1028 &peer_ctx->sub->hash,
1029 NULL, /* WindowSize handler */
1030 &cleanup_destroyed_channel, /* Disconnect handler */
1031 cadet_handlers);
1032 }
1033 GNUNET_assert (NULL != peer_ctx->send_channel_ctx);
1034 GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel);
1035 return peer_ctx->send_channel_ctx->channel;
1036}
1037
1038
1048static struct GNUNET_MQ_Handle *
1049get_mq (struct PeerContext *peer_ctx)
1050{
1051 if (NULL == peer_ctx->mq)
1052 {
1053 peer_ctx->mq = GNUNET_CADET_get_mq (get_channel (peer_ctx));
1054 }
1055 return peer_ctx->mq;
1056}
1057
1058
1067static struct PendingMessage *
1069 struct GNUNET_MQ_Envelope *ev,
1070 const char *type)
1071{
1072 struct PendingMessage *pending_msg;
1073
1074 pending_msg = GNUNET_new (struct PendingMessage);
1075 pending_msg->ev = ev;
1076 pending_msg->peer_ctx = peer_ctx;
1077 pending_msg->type = type;
1080 pending_msg);
1081 return pending_msg;
1082}
1083
1084
1091static void
1092remove_pending_message (struct PendingMessage *pending_msg, int cancel)
1093{
1094 struct PeerContext *peer_ctx;
1095
1096 (void) cancel;
1097
1098 peer_ctx = pending_msg->peer_ctx;
1099 GNUNET_assert (NULL != peer_ctx);
1101 peer_ctx->pending_messages_tail,
1102 pending_msg);
1103 // TODO wait for the cadet implementation of message cancellation
1104 // if (GNUNET_YES == cancel)
1105 // {
1106 // GNUNET_MQ_send_cancel (pending_msg->ev);
1107 // }
1108 GNUNET_free (pending_msg);
1109}
1110
1111
1118static void
1120{
1121 struct PeerContext *peer_ctx = cls;
1122
1123 if (NULL != peer_ctx->online_check_pending)
1124 {
1126 "Online check for peer %s was successful\n",
1127 GNUNET_i2s (&peer_ctx->peer_id));
1129 peer_ctx->online_check_pending = NULL;
1130 set_peer_online (peer_ctx);
1131 (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers);
1132 }
1133}
1134
1135
1141static void
1143{
1145 "Get informed about peer %s getting online\n",
1146 GNUNET_i2s (&peer_ctx->peer_id));
1147
1148 struct GNUNET_MQ_Handle *mq;
1149 struct GNUNET_MQ_Envelope *ev;
1150
1152 peer_ctx->online_check_pending =
1153 insert_pending_message (peer_ctx, ev, "Check online");
1154 mq = get_mq (peer_ctx);
1157 peer_ctx);
1158 GNUNET_MQ_send (mq, ev);
1159 if (peer_ctx->sub == msub)
1160 {
1162 "# pending online checks",
1163 1,
1164 GNUNET_NO);
1165 }
1166}
1167
1168
1181static int
1183 const PeerOp peer_op)
1184{
1185 unsigned int i;
1186
1187 for (i = 0; i < peer_ctx->num_pending_ops; i++)
1188 if (peer_op == peer_ctx->pending_ops[i].op)
1189 return GNUNET_YES;
1190 return GNUNET_NO;
1191}
1192
1193
1199static void
1200destroy_channel (struct ChannelCtx *channel_ctx)
1201{
1202 struct GNUNET_CADET_Channel *channel;
1203
1204 if (NULL != channel_ctx->destruction_task)
1205 {
1207 channel_ctx->destruction_task = NULL;
1208 }
1209 GNUNET_assert (channel_ctx->channel != NULL);
1210 channel = channel_ctx->channel;
1211 channel_ctx->channel = NULL;
1213 remove_channel_ctx (channel_ctx);
1214}
1215
1216
1224static void
1226{
1227 struct ChannelCtx *channel_ctx = cls;
1228
1229 channel_ctx->destruction_task = NULL;
1230 destroy_channel (channel_ctx);
1231}
1232
1233
1244static void
1246{
1247 GNUNET_assert (NULL ==
1248 channel_ctx->destruction_task);
1249 GNUNET_assert (NULL !=
1250 channel_ctx->channel);
1251 channel_ctx->destruction_task =
1253 channel_ctx);
1254}
1255
1256
1270static int
1272{
1273 GNUNET_assert (NULL != peer_ctx);
1274 GNUNET_assert (NULL != peer_ctx->sub->peer_map);
1275 if (GNUNET_NO ==
1277 &peer_ctx->peer_id))
1278 {
1279 return GNUNET_NO;
1280 }
1283 "Going to remove peer %s\n",
1286
1287 /* Clear list of pending operations */
1288 // TODO this probably leaks memory
1289 // ('only' the cls to the function. Not sure what to do with it)
1292 0);
1293 /* Remove all pending messages */
1294 while (NULL != peer_ctx->pending_messages_head)
1295 {
1297 "Removing unsent %s\n",
1299 /* Cancel pending message, too */
1300 if ((NULL != peer_ctx->online_check_pending) &&
1301 (0 == memcmp (peer_ctx->pending_messages_head,
1303 sizeof(struct PendingMessage))))
1304 {
1306 if (peer_ctx->sub == msub)
1307 {
1309 "# pending online checks",
1310 -1,
1311 GNUNET_NO);
1312 }
1313 }
1315 GNUNET_YES);
1316 }
1317
1318 /* If we are still waiting for notification whether this peer is online
1319 * cancel the according task */
1320 if (NULL != peer_ctx->online_check_pending)
1321 {
1323 "Removing pending online check for peer %s\n",
1325 // TODO wait until cadet sets mq->cancel_impl
1326 // GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev);
1328 GNUNET_YES);
1330 }
1331
1332 if (NULL != peer_ctx->send_channel_ctx)
1333 {
1334 /* This is possibly called from within channel destruction */
1337 peer_ctx->send_channel_ctx = NULL;
1338 peer_ctx->mq = NULL;
1339 }
1340 if (NULL != peer_ctx->recv_channel_ctx)
1341 {
1342 /* This is possibly called from within channel destruction */
1345 peer_ctx->recv_channel_ctx = NULL;
1346 }
1347
1348 if (GNUNET_YES !=
1350 &peer_ctx->peer_id))
1351 {
1353 "removing peer from peer_ctx->sub->peer_map failed\n");
1354 }
1355 if (peer_ctx->sub == msub)
1356 {
1358 "# known peers",
1361 GNUNET_NO);
1362 }
1364 return GNUNET_YES;
1365}
1366
1367
1377static int
1379 const struct GNUNET_PeerIdentity *key,
1380 void *value)
1381{
1382 struct Sub *sub = cls;
1383
1384 (void) value;
1385
1387 return GNUNET_YES;
1388}
1389
1390
1398static void
1400{
1401 struct PendingMessage *pending_msg = (struct PendingMessage *) cls;
1402
1404 "%s was sent.\n",
1405 pending_msg->type);
1406 if (pending_msg->peer_ctx->sub == msub)
1407 {
1408 if (0 == strncmp ("PULL REPLY", pending_msg->type, 10))
1409 GNUNET_STATISTICS_update (stats, "# pull replies sent", 1, GNUNET_NO);
1410 if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12))
1411 GNUNET_STATISTICS_update (stats, "# pull requests sent", 1, GNUNET_NO);
1412 if (0 == strncmp ("PUSH", pending_msg->type, 4))
1413 GNUNET_STATISTICS_update (stats, "# pushes sent", 1, GNUNET_NO);
1414 if ((0 == strncmp ("PULL REQUEST", pending_msg->type, 12)) &&
1415 (NULL != map_single_hop) &&
1417 &pending_msg->
1419 ) )
1421 "# pull requests sent (multi-hop peer)",
1422 1,
1423 GNUNET_NO);
1424 }
1425 /* Do not cancel message */
1426 remove_pending_message (pending_msg, GNUNET_NO);
1427}
1428
1429
1444static int
1446 const struct GNUNET_PeerIdentity *peer,
1447 void *value)
1448{
1449 const struct GNUNET_DISK_FileHandle *fh = cls;
1450 char peer_string[128];
1451 int size;
1452 ssize_t ret;
1453
1454 (void) value;
1455
1456 if (NULL == peer)
1457 {
1458 return GNUNET_YES;
1459 }
1460 size = GNUNET_snprintf (peer_string,
1461 sizeof(peer_string),
1462 "%s\n",
1463 GNUNET_i2s_full (peer));
1464 GNUNET_assert (53 == size);
1466 peer_string,
1467 size);
1468 GNUNET_assert (size == ret);
1469 return GNUNET_YES;
1470}
1471
1472
1478static void
1479store_valid_peers (const struct Sub *sub)
1480{
1481 struct GNUNET_DISK_FileHandle *fh;
1482 uint32_t number_written_peers;
1483 int ret;
1484
1485 if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7))
1486 {
1487 return;
1488 }
1489
1491 if (GNUNET_SYSERR == ret)
1492 {
1494 "Not able to create directory for file `%s'\n",
1496 GNUNET_break (0);
1497 }
1498 else if (GNUNET_NO == ret)
1499 {
1501 "Directory for file `%s' exists but is not writable for us\n",
1503 GNUNET_break (0);
1504 }
1510 if (NULL == fh)
1511 {
1513 "Not able to write valid peers to file `%s'\n",
1515 return;
1516 }
1518 "Writing %u valid peers to disk\n",
1520 number_written_peers =
1523 fh);
1525 GNUNET_assert (number_written_peers ==
1527}
1528
1529
1539static const struct GNUNET_PeerIdentity *
1540s2i_full (const char *string_repr)
1541{
1542 struct GNUNET_PeerIdentity *peer;
1543 size_t len;
1544 int ret;
1545
1546 peer = GNUNET_new (struct GNUNET_PeerIdentity);
1547 len = strlen (string_repr);
1548 if (52 > len)
1549 {
1551 "Not able to convert string representation of PeerID to PeerID\n"
1552 "String representation: %s (len %lu) - too short\n",
1553 string_repr,
1554 len);
1555 GNUNET_break (0);
1556 }
1557 else if (52 < len)
1558 {
1559 len = 52;
1560 }
1562 len,
1563 &peer->public_key);
1564 if (GNUNET_OK != ret)
1565 {
1567 "Not able to convert string representation of PeerID to PeerID\n"
1568 "String representation: %s\n",
1569 string_repr);
1570 GNUNET_break (0);
1571 }
1572 return peer;
1573}
1574
1575
1581static void
1582restore_valid_peers (const struct Sub *sub)
1583{
1584 off_t file_size;
1585 uint32_t num_peers;
1586 struct GNUNET_DISK_FileHandle *fh;
1587 char *buf;
1588 ssize_t size_read;
1589 char *iter_buf;
1590 char *str_repr;
1591 const struct GNUNET_PeerIdentity *peer;
1592
1593 if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7))
1594 {
1595 return;
1596 }
1597
1599 {
1600 return;
1601 }
1605 GNUNET_assert (NULL != fh);
1607 num_peers = file_size / 53;
1608 buf = GNUNET_malloc (file_size);
1609 size_read = GNUNET_DISK_file_read (fh, buf, file_size);
1610 GNUNET_assert (size_read == file_size);
1612 "Restoring %" PRIu32 " peers from file `%s'\n",
1613 num_peers,
1615 for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53)
1616 {
1617 str_repr = GNUNET_strndup (iter_buf, 53);
1618 peer = s2i_full (str_repr);
1619 GNUNET_free (str_repr);
1620 add_valid_peer (peer, sub->valid_peers);
1622 "Restored valid peer %s from disk\n",
1623 GNUNET_i2s_full (peer));
1624 }
1625 iter_buf = NULL;
1626 GNUNET_free (buf);
1628 "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n",
1629 num_peers,
1632 {
1634 "Number of restored peers does not match file size. Have probably duplicates.\n");
1635 }
1638 "Restored %u valid peers from disk\n",
1640}
1641
1642
1648static void
1650{
1651 if (GNUNET_SYSERR ==
1654 sub))
1655 {
1657 "Iteration destroying peers was aborted.\n");
1658 }
1660 sub->peer_map = NULL;
1661 store_valid_peers (sub);
1663 sub->filename_valid_peers = NULL;
1665 sub->valid_peers = NULL;
1666}
1667
1668
1679static int
1681 const struct GNUNET_PeerIdentity *peer,
1682 void *value)
1683{
1684 struct PeersIteratorCls *it_cls = cls;
1685
1686 (void) value;
1687
1688 return it_cls->iterator (it_cls->cls, peer);
1689}
1690
1691
1701static int
1704 void *it_cls)
1705{
1706 struct PeersIteratorCls *cls;
1707 int ret;
1708
1709 cls = GNUNET_new (struct PeersIteratorCls);
1710 cls->iterator = iterator;
1711 cls->cls = it_cls;
1714 cls);
1715 GNUNET_free (cls);
1716 return ret;
1717}
1718
1719
1732static int
1733insert_peer (struct Sub *sub,
1734 const struct GNUNET_PeerIdentity *peer)
1735{
1736 if (GNUNET_YES == check_peer_known (sub->peer_map, peer))
1737 {
1738 return GNUNET_NO; /* We already know this peer - nothing to do */
1739 }
1740 (void) create_peer_ctx (sub, peer);
1741 return GNUNET_YES;
1742}
1743
1744
1756static int
1758 const struct GNUNET_PeerIdentity *peer,
1759 enum Peers_PeerFlags flags)
1760{
1761 struct PeerContext *peer_ctx;
1762
1763 if (GNUNET_NO == check_peer_known (peer_map, peer))
1764 {
1765 return GNUNET_SYSERR;
1766 }
1767 peer_ctx = get_peer_ctx (peer_map, peer);
1768 return check_peer_flag_set (peer_ctx, flags);
1769}
1770
1771
1782static int
1784 const struct GNUNET_PeerIdentity *peer)
1785{
1786 struct PeerContext *peer_ctx;
1787
1788 (void) insert_peer (sub, peer); // TODO even needed?
1789 peer_ctx = get_peer_ctx (sub->peer_map, peer);
1790 if ((GNUNET_NO == check_peer_flag (sub->peer_map, peer, Peers_ONLINE)) &&
1791 (NULL == peer_ctx->online_check_pending))
1792 {
1793 check_peer_online (peer_ctx);
1794 return GNUNET_YES;
1795 }
1796 return GNUNET_NO;
1797}
1798
1799
1813static int
1814check_removable (const struct PeerContext *peer_ctx)
1815{
1817 peer_ctx->sub->peer_map,
1818 &peer_ctx->peer_id))
1819 {
1820 return GNUNET_SYSERR;
1821 }
1822
1823 if ((NULL != peer_ctx->recv_channel_ctx) ||
1824 (NULL != peer_ctx->pending_messages_head) ||
1826 {
1827 return GNUNET_NO;
1828 }
1829 return GNUNET_YES;
1830}
1831
1832
1844static int
1846 const struct GNUNET_PeerIdentity *peer)
1847{
1848 return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer);
1849}
1850
1851
1859static void
1861{
1863 &peer_ctx->peer_id));
1864 (void) get_channel (peer_ctx);
1865}
1866
1867
1877static int
1879{
1880 if (NULL != peer_ctx->recv_channel_ctx)
1881 {
1882 return GNUNET_YES;
1883 }
1884 return GNUNET_NO;
1885}
1886
1887
1898static void *
1900 struct GNUNET_CADET_Channel *channel,
1901 const struct GNUNET_PeerIdentity *initiator)
1902{
1903 struct PeerContext *peer_ctx;
1904 struct ChannelCtx *channel_ctx;
1905 struct Sub *sub = cls;
1906
1908 "New channel was established to us (Peer %s).\n",
1909 GNUNET_i2s (initiator));
1910 GNUNET_assert (NULL != channel); /* according to cadet API */
1911 /* Make sure we 'know' about this peer */
1912 peer_ctx = create_or_get_peer_ctx (sub, initiator);
1913 set_peer_online (peer_ctx);
1914 (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers);
1915 channel_ctx = add_channel_ctx (peer_ctx);
1916 channel_ctx->channel = channel;
1917 /* We only accept one incoming channel per peer */
1919 initiator)))
1920 {
1922 "Already got one receive channel. Destroying old one.\n");
1923 GNUNET_break_op (0);
1925 peer_ctx->recv_channel_ctx = channel_ctx;
1926 /* return the channel context */
1927 return channel_ctx;
1928 }
1929 peer_ctx->recv_channel_ctx = channel_ctx;
1930 return channel_ctx;
1931}
1932
1933
1942static int
1944{
1945 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
1946 &peer_ctx->peer_id))
1947 { /* If no such peer exists, there is no channel */
1948 return GNUNET_NO;
1949 }
1950 if (NULL == peer_ctx->send_channel_ctx)
1951 {
1952 return GNUNET_NO;
1953 }
1954 return GNUNET_YES;
1955}
1956
1957
1966static int
1968{
1969 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
1970 &peer_ctx->peer_id))
1971 {
1972 return GNUNET_NO;
1973 }
1974 if (NULL != peer_ctx->send_channel_ctx)
1975 {
1977 (void) check_connected (peer_ctx);
1978 return GNUNET_YES;
1979 }
1980 return GNUNET_NO;
1981}
1982
1983
1994static void
1995send_message (struct PeerContext *peer_ctx,
1996 struct GNUNET_MQ_Envelope *ev,
1997 const char *type)
1998{
1999 struct PendingMessage *pending_msg;
2000 struct GNUNET_MQ_Handle *mq;
2001
2003 "Sending message to %s of type %s\n",
2004 GNUNET_i2s (&peer_ctx->peer_id),
2005 type);
2006 pending_msg = insert_pending_message (peer_ctx, ev, type);
2007 mq = get_mq (peer_ctx);
2010 pending_msg);
2011 GNUNET_MQ_send (mq, ev);
2012}
2013
2014
2027static int
2029 const PeerOp peer_op,
2030 void *cls)
2031{
2032 struct PeerPendingOp pending_op;
2033
2035 &peer_ctx->peer_id));
2036
2037 // TODO if ONLINE execute immediately
2038
2039 if (GNUNET_NO == check_operation_scheduled (peer_ctx, peer_op))
2040 {
2041 pending_op.op = peer_op;
2042 pending_op.op_cls = cls;
2044 peer_ctx->num_pending_ops,
2045 pending_op);
2046 return GNUNET_YES;
2047 }
2048 return GNUNET_NO;
2049}
2050
2051
2052/***********************************************************************
2053* /Old gnunet-service-rps_peers.c
2054***********************************************************************/
2055
2056
2057/***********************************************************************
2058* Housekeeping with clients
2059***********************************************************************/
2060
2066{
2072
2076 uint32_t id;
2077
2082
2087};
2088
2089
2094{
2100
2105
2110
2116
2121
2125 struct Sub *sub;
2126};
2127
2133
2134/***********************************************************************
2135* /Housekeeping with clients
2136***********************************************************************/
2137
2138
2139/***********************************************************************
2140* Util functions
2141***********************************************************************/
2142
2143
2147static void
2149 unsigned int len)
2150{
2151 unsigned int i;
2152
2154 "Printing peer list of length %u at %p:\n",
2155 len,
2156 list);
2157 for (i = 0; i < len; i++)
2158 {
2160 "%u. peer: %s\n",
2161 i, GNUNET_i2s (&list[i]));
2162 }
2163}
2164
2165
2169static void
2171 unsigned int *list_size,
2172 const struct GNUNET_PeerIdentity *peer)
2173{
2174 unsigned int i;
2175 struct GNUNET_PeerIdentity *tmp;
2176
2177 tmp = *peer_list;
2178
2180 "Removing peer %s from list at %p\n",
2181 GNUNET_i2s (peer),
2182 tmp);
2183
2184 for (i = 0; i < *list_size; i++)
2185 {
2186 if (0 == GNUNET_memcmp (&tmp[i], peer))
2187 {
2188 if (i < *list_size - 1)
2189 { /* Not at the last entry -- shift peers left */
2190 memmove (&tmp[i], &tmp[i + 1],
2191 ((*list_size) - i - 1) * sizeof(struct GNUNET_PeerIdentity));
2192 }
2193 /* Remove last entry (should be now useless PeerID) */
2194 GNUNET_array_grow (tmp, *list_size, (*list_size) - 1);
2195 }
2196 }
2197 *peer_list = tmp;
2198}
2199
2200
2210static void
2211insert_in_view_op (void *cls,
2212 const struct GNUNET_PeerIdentity *peer);
2213
2225static int
2226insert_in_view (struct Sub *sub,
2227 const struct GNUNET_PeerIdentity *peer)
2228{
2229 struct PeerContext *peer_ctx;
2230 int online;
2231 int ret;
2232
2233 online = check_peer_flag (sub->peer_map, peer, Peers_ONLINE);
2234 peer_ctx = get_peer_ctx (sub->peer_map, peer); // TODO indirection needed?
2235 if ((GNUNET_NO == online) ||
2236 (GNUNET_SYSERR == online)) /* peer is not even known */
2237 {
2238 (void) issue_peer_online_check (sub, peer);
2239 (void) schedule_operation (peer_ctx, insert_in_view_op, sub);
2240 return GNUNET_NO;
2241 }
2242 /* Open channel towards peer to keep connection open */
2243 indicate_sending_intention (peer_ctx);
2244 ret = View_put (sub->view, peer);
2245 if (peer_ctx->sub == msub)
2246 {
2248 "view size",
2249 View_size (peer_ctx->sub->view),
2250 GNUNET_NO);
2251 }
2252 return ret;
2253}
2254
2255
2263static void
2264send_view (const struct ClientContext *cli_ctx,
2265 const struct GNUNET_PeerIdentity *view_array,
2266 uint64_t view_size)
2267{
2268 struct GNUNET_MQ_Envelope *ev;
2269 struct GNUNET_RPS_CS_DEBUG_ViewReply *out_msg;
2270 struct Sub *sub;
2271
2272 if (NULL == view_array)
2273 {
2274 if (NULL == cli_ctx->sub)
2275 sub = msub;
2276 else
2277 sub = cli_ctx->sub;
2278 view_size = View_size (sub->view);
2279 view_array = View_get_as_array (sub->view);
2280 }
2281
2282 ev = GNUNET_MQ_msg_extra (out_msg,
2283 view_size * sizeof(struct GNUNET_PeerIdentity),
2285 out_msg->num_peers = htonl (view_size);
2286
2287 GNUNET_memcpy (&out_msg[1],
2288 view_array,
2289 view_size * sizeof(struct GNUNET_PeerIdentity));
2290 GNUNET_MQ_send (cli_ctx->mq, ev);
2291}
2292
2293
2303static void
2304send_stream_peers (const struct ClientContext *cli_ctx,
2305 uint64_t num_peers,
2306 const struct GNUNET_PeerIdentity *peers)
2307{
2308 struct GNUNET_MQ_Envelope *ev;
2309 struct GNUNET_RPS_CS_DEBUG_StreamReply *out_msg;
2310
2311 GNUNET_assert (NULL != peers);
2312
2313 ev = GNUNET_MQ_msg_extra (out_msg,
2314 num_peers * sizeof(struct GNUNET_PeerIdentity),
2316 out_msg->num_peers = htonl (num_peers);
2317
2318 GNUNET_memcpy (&out_msg[1],
2319 peers,
2320 num_peers * sizeof(struct GNUNET_PeerIdentity));
2321 GNUNET_MQ_send (cli_ctx->mq, ev);
2322}
2323
2324
2330static void
2332{
2333 struct ClientContext *cli_ctx_iter;
2334 uint64_t num_peers;
2335 const struct GNUNET_PeerIdentity *view_array;
2336
2337 num_peers = View_size (sub->view);
2338 view_array = View_get_as_array (sub->view);
2339 /* check size of view is small enough */
2341 {
2343 "View is too big to send\n");
2344 return;
2345 }
2346
2347 for (cli_ctx_iter = cli_ctx_head;
2348 NULL != cli_ctx_iter;
2349 cli_ctx_iter = cli_ctx_iter->next)
2350 {
2351 if (1 < cli_ctx_iter->view_updates_left)
2352 {
2353 /* Client wants to receive limited amount of updates */
2354 cli_ctx_iter->view_updates_left -= 1;
2355 }
2356 else if (1 == cli_ctx_iter->view_updates_left)
2357 {
2358 /* Last update of view for client */
2359 cli_ctx_iter->view_updates_left = -1;
2360 }
2361 else if (0 > cli_ctx_iter->view_updates_left)
2362 {
2363 /* Client is not interested in updates */
2364 continue;
2365 }
2366 /* else _updates_left == 0 - infinite amount of updates */
2367
2368 /* send view */
2369 send_view (cli_ctx_iter, view_array, num_peers);
2370 }
2371}
2372
2373
2380static void
2382 uint64_t num_peers,
2383 const struct GNUNET_PeerIdentity *peers)
2384// TODO enum StreamPeerSource)
2385{
2386 struct ClientContext *cli_ctx_iter;
2387
2389 "Got peer (%s) from biased stream - update all clients\n",
2390 GNUNET_i2s (peers));
2391
2392 for (cli_ctx_iter = cli_ctx_head;
2393 NULL != cli_ctx_iter;
2394 cli_ctx_iter = cli_ctx_iter->next)
2395 {
2396 if ((GNUNET_YES == cli_ctx_iter->stream_update) &&
2397 ((sub == cli_ctx_iter->sub) || (sub == msub) ))
2398 {
2399 send_stream_peers (cli_ctx_iter, num_peers, peers);
2400 }
2401 }
2402}
2403
2404
2412static void
2414 uint32_t num_peers,
2415 void *cls)
2416{
2417 unsigned int i;
2418 struct Sub *sub = cls;
2419
2420 for (i = 0; i < num_peers; i++)
2421 {
2422 int inserted;
2423 if (GNUNET_YES != check_peer_known (sub->peer_map, &ids[i]))
2424 {
2426 "Peer in history update not known!\n");
2427 continue;
2428 }
2429 inserted = insert_in_view (sub, &ids[i]);
2430 if (GNUNET_OK == inserted)
2431 {
2432 clients_notify_stream_peer (sub, 1, &ids[i]);
2433 }
2434#ifdef TO_FILE_FULL
2435 to_file (sub->file_name_view_log,
2436 "+%s\t(history)",
2437 GNUNET_i2s_full (ids));
2438#endif /* TO_FILE_FULL */
2439 }
2441}
2442
2443
2453static void
2454resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size)
2455{
2456 unsigned int sampler_size;
2457
2458 // TODO statistics
2459 // TODO respect the min, max
2460 sampler_size = RPS_sampler_get_size (sampler);
2461 if (sampler_size > new_size * 4)
2462 { /* Shrinking */
2463 RPS_sampler_resize (sampler, sampler_size / 2);
2464 }
2465 else if (sampler_size < new_size)
2466 { /* Growing */
2467 RPS_sampler_resize (sampler, sampler_size * 2);
2468 }
2469 LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size);
2470}
2471
2472
2473#if ENABLE_MALICIOUS
2481static void
2482add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array,
2483 unsigned int num_peers,
2485{
2486 unsigned int i;
2487
2488 if (NULL == peer_map)
2489 {
2491 "Trying to add peers to non-existing peermap.\n");
2492 return;
2493 }
2494
2495 for (i = 0; i < num_peers; i++)
2496 {
2498 &peer_array[i],
2499 NULL,
2501 if (msub->peer_map == peer_map)
2502 {
2504 "# known peers",
2506 GNUNET_NO);
2507 }
2508 }
2509}
2510
2511
2512#endif /* ENABLE_MALICIOUS */
2513
2514
2522static void
2524 const struct GNUNET_PeerIdentity *peer_ids,
2525 unsigned int num_peer_ids)
2526{
2527 uint32_t send_size;
2528 struct GNUNET_MQ_Envelope *ev;
2529 struct GNUNET_RPS_P2P_PullReplyMessage *out_msg;
2530
2531 /* Compute actual size */
2532 send_size = sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)
2533 + num_peer_ids * sizeof(struct GNUNET_PeerIdentity);
2534
2536 /* Compute number of peers to send
2537 * If too long, simply truncate */
2538 // TODO select random ones via permutation
2539 // or even better: do good protocol design
2540 send_size =
2542 - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage))
2543 / sizeof(struct GNUNET_PeerIdentity);
2544 else
2545 send_size = num_peer_ids;
2546
2548 "Going to send PULL REPLY with %u peers to %s\n",
2549 send_size, GNUNET_i2s (&peer_ctx->peer_id));
2550
2551 ev = GNUNET_MQ_msg_extra (out_msg,
2552 send_size * sizeof(struct GNUNET_PeerIdentity),
2554 out_msg->num_peers = htonl (send_size);
2555 GNUNET_memcpy (&out_msg[1], peer_ids,
2556 send_size * sizeof(struct GNUNET_PeerIdentity));
2557
2558 send_message (peer_ctx, ev, "PULL REPLY");
2559 if (peer_ctx->sub == msub)
2560 {
2561 GNUNET_STATISTICS_update (stats, "# pull reply send issued", 1, GNUNET_NO);
2562 }
2563 // TODO check with send intention: as send_channel is used/opened we indicate
2564 // a sending intention without intending it.
2565 // -> clean peer afterwards?
2566 // -> use recv_channel?
2567}
2568
2569
2578static void
2580 const struct GNUNET_PeerIdentity *peer)
2581{
2582 struct Sub *sub = cls;
2583
2584 CustomPeerMap_put (sub->pull_map, peer);
2585}
2586
2587
2597static void
2599 const struct GNUNET_PeerIdentity *peer)
2600{
2601 struct Sub *sub = cls;
2602 int inserted;
2603
2604 inserted = insert_in_view (sub, peer);
2605 if (GNUNET_OK == inserted)
2606 {
2607 clients_notify_stream_peer (sub, 1, peer);
2608 }
2609}
2610
2611
2619static void
2621 const struct GNUNET_PeerIdentity *peer)
2622{
2623 struct Sub *sub = cls;
2624
2626 "Updating samplers with peer %s from insert_in_sampler()\n",
2627 GNUNET_i2s (peer));
2628 RPS_sampler_update (sub->sampler, peer);
2629 if (0 < RPS_sampler_count_id (sub->sampler, peer))
2630 {
2631 /* Make sure we 'know' about this peer */
2632 (void) issue_peer_online_check (sub, peer);
2633 /* Establish a channel towards that peer to indicate we are going to send
2634 * messages to it */
2635 // indicate_sending_intention (peer);
2636 }
2637 if (sub == msub)
2638 {
2640 "# observed peers in gossip",
2641 1,
2642 GNUNET_NO);
2643 }
2644#ifdef TO_FILE
2645 sub->num_observed_peers++;
2648 peer,
2649 NULL,
2651 uint32_t num_observed_unique_peers =
2654 "# unique peers in gossip",
2655 num_observed_unique_peers,
2656 GNUNET_NO);
2657#ifdef TO_FILE_FULL
2658 to_file (sub->file_name_observed_log,
2659 "%" PRIu32 " %" PRIu32 " %f\n",
2660 sub->num_observed_peers,
2661 num_observed_unique_peers,
2662 1.0 * num_observed_unique_peers / sub->num_observed_peers)
2663#endif /* TO_FILE_FULL */
2664#endif /* TO_FILE */
2665}
2666
2667
2678static void
2679got_peer (struct Sub *sub,
2680 const struct GNUNET_PeerIdentity *peer)
2681{
2682 /* If we did not know this peer already, insert it into sampler and view */
2683 if (GNUNET_YES == issue_peer_online_check (sub, peer))
2684 {
2686 &insert_in_sampler, sub);
2688 &insert_in_view_op, sub);
2689 }
2690 if (sub == msub)
2691 {
2693 "# learnd peers",
2694 1,
2695 GNUNET_NO);
2696 }
2697}
2698
2699
2707static int
2709{
2710 /* struct GNUNET_CADET_Channel *channel; */
2711 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
2712 &peer_ctx->peer_id))
2713 {
2714 return GNUNET_NO;
2715 }
2716 if (GNUNET_YES == check_sending_channel_exists (peer_ctx))
2717 {
2718 if ((0 < RPS_sampler_count_id (peer_ctx->sub->sampler,
2719 &peer_ctx->peer_id)) ||
2720 (GNUNET_YES == View_contains_peer (peer_ctx->sub->view,
2721 &peer_ctx->peer_id)) ||
2723 &peer_ctx->peer_id)) ||
2725 &peer_ctx->peer_id)) ||
2726 (GNUNET_YES == check_peer_flag (peer_ctx->sub->peer_map,
2727 &peer_ctx->peer_id,
2729 { /* If we want to keep the connection to peer open */
2730 return GNUNET_YES;
2731 }
2732 return GNUNET_NO;
2733 }
2734 return GNUNET_NO;
2735}
2736
2737
2745static void
2746remove_peer (struct Sub *sub,
2747 const struct GNUNET_PeerIdentity *peer)
2748{
2749 (void) View_remove_peer (sub->view,
2750 peer);
2752 peer);
2754 peer);
2756 peer);
2757 /* We want to destroy the peer now.
2758 * Sometimes, it just seems that it's already been removed from the peer_map,
2759 * so check the peer_map first. */
2761 peer))
2762 {
2764 peer));
2765 }
2766}
2767
2768
2777static void
2778clean_peer (struct Sub *sub,
2779 const struct GNUNET_PeerIdentity *peer)
2780{
2782 peer)))
2783 {
2785 "Going to remove send channel to peer %s\n",
2786 GNUNET_i2s (peer));
2787 #if ENABLE_MALICIOUS
2788 if (0 != GNUNET_memcmp (&attacked_peer,
2789 peer))
2791 peer));
2792 #else /* ENABLE_MALICIOUS */
2794 peer));
2795 #endif /* ENABLE_MALICIOUS */
2796 }
2797
2799 peer))
2800 {
2801 /* Peer was already removed by callback on destroyed channel */
2803 "Peer was removed from our knowledge during cleanup\n");
2804 return;
2805 }
2806
2808 peer))) &&
2809 (GNUNET_NO == View_contains_peer (sub->view, peer)) &&
2812 (0 == RPS_sampler_count_id (sub->sampler, peer)) &&
2813 (GNUNET_YES == check_removable (get_peer_ctx (sub->peer_map, peer))))
2814 { /* We can safely remove this peer */
2816 "Going to remove peer %s\n",
2817 GNUNET_i2s (peer));
2818 remove_peer (sub, peer);
2819 return;
2820 }
2821}
2822
2823
2835static void
2837 const struct GNUNET_CADET_Channel *channel)
2838{
2839 struct ChannelCtx *channel_ctx = cls;
2840 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
2841
2842 (void) channel;
2843
2844 channel_ctx->channel = NULL;
2845 if ((NULL != peer_ctx) &&
2846 (peer_ctx->send_channel_ctx == channel_ctx) &&
2848 {
2849 remove_channel_ctx (channel_ctx);
2850 remove_peer (peer_ctx->sub, &peer_ctx->peer_id);
2851 }
2852 else
2853 {
2854 /* We need this if-else construct because we need to make sure the channel
2855 * (context) is cleaned up before removing the peer, but still need to
2856 * compare it while checking the condition */
2857 remove_channel_ctx (channel_ctx);
2858 }
2859}
2860
2861
2862/***********************************************************************
2863* /Util functions
2864***********************************************************************/
2865
2866
2867/***********************************************************************
2868* Sub
2869***********************************************************************/
2870
2881struct Sub *
2883 uint32_t sampler_size,
2885{
2886 struct Sub *sub;
2887
2888 sub = GNUNET_new (struct Sub);
2889
2890 /* With the hash generated from the secret value this service only connects
2891 * to rps instances that share the value */
2892 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
2893 GNUNET_MQ_hd_fixed_size (peer_check,
2895 struct GNUNET_MessageHeader,
2896 NULL),
2897 GNUNET_MQ_hd_fixed_size (peer_push,
2899 struct GNUNET_MessageHeader,
2900 NULL),
2901 GNUNET_MQ_hd_fixed_size (peer_pull_request,
2903 struct GNUNET_MessageHeader,
2904 NULL),
2905 GNUNET_MQ_hd_var_size (peer_pull_reply,
2908 NULL),
2910 };
2911 sub->hash = *hash;
2912 sub->cadet_port =
2914 &sub->hash,
2915 &handle_inbound_channel, /* Connect handler */
2916 sub, /* cls */
2917 NULL, /* WindowSize handler */
2918 &cleanup_destroyed_channel, /* Disconnect handler */
2919 cadet_handlers);
2920 if (NULL == sub->cadet_port)
2921 {
2923 "Cadet port `%s' is already in use.\n",
2925 GNUNET_assert (0);
2926 }
2927
2928 /* Set up general data structure to keep track about peers */
2930 if (GNUNET_OK !=
2932 "rps",
2933 "FILENAME_VALID_PEERS",
2934 &sub->filename_valid_peers))
2935 {
2937 "rps",
2938 "FILENAME_VALID_PEERS");
2939 }
2940 if (0 != strncmp ("DISABLE", sub->filename_valid_peers, 7))
2941 {
2942 char *tmp_filename_valid_peers;
2943 char str_hash[105];
2944
2945 GNUNET_snprintf (str_hash,
2946 sizeof(str_hash), "%s",
2947 GNUNET_h2s_full (hash));
2948 tmp_filename_valid_peers = sub->filename_valid_peers;
2950 "%s%s",
2951 tmp_filename_valid_peers,
2952 str_hash);
2953 GNUNET_free (tmp_filename_valid_peers);
2954 }
2956
2957 /* Set up the sampler */
2958 sub->sampler_size_est_min = sampler_size;
2959 sub->sampler_size_est_need = sampler_size;;
2960 LOG (GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sub->sampler_size_est_min);
2961 GNUNET_assert (0 != round_interval.rel_value_us);
2962 sub->round_interval = round_interval;
2963 sub->sampler = RPS_sampler_init (sampler_size,
2964 round_interval);
2965
2966 /* Logging of internals */
2967#ifdef TO_FILE_FULL
2968 // FIXME: The service cannot know the index, which is required by this
2969 // function:
2970 // sub->file_name_view_log = store_prefix_file_name (&own_identity, "view");
2971#endif /* TO_FILE_FULL */
2972#ifdef TO_FILE
2973#ifdef TO_FILE_FULL
2974 // FIXME: The service cannot know the index, which is required by this
2975 // function:
2976 // sub->file_name_observed_log = store_prefix_file_name (&own_identity,
2977 // "observed");
2978#endif /* TO_FILE_FULL */
2979 sub->num_observed_peers = 0;
2981 GNUNET_NO);
2982#endif /* TO_FILE */
2983
2984 /* Set up data structures for gossip */
2985 sub->push_map = CustomPeerMap_create (4);
2986 sub->pull_map = CustomPeerMap_create (4);
2987 sub->view_size_est_min = sampler_size;;
2988 sub->view = View_create (sub->view_size_est_min);
2989 if (sub == msub)
2990 {
2992 "view size aim",
2993 sub->view_size_est_min,
2994 GNUNET_NO);
2995 }
2996
2997 /* Start executing rounds */
2999
3000 return sub;
3001}
3002
3003
3004#ifdef TO_FILE
3005// /**
3006// * @brief Write all numbers in the given array into the given file
3007// *
3008// * Single numbers divided by a newline
3009// *
3010// * FIXME: The call to store_prefix_file_name expects the index of the peer,
3011// * which cannot be known to the service.
3012// * Write a dedicated function that uses the peer id.
3013// *
3014// * @param hist_array[] the array to dump
3015// * @param file_name file to dump into
3016// */
3017// static void
3018// write_histogram_to_file (const uint32_t hist_array[],
3019// const char *file_name)
3020// {
3021// char collect_str[SIZE_DUMP_FILE + 1] = "";
3022// char *recv_str_iter;
3023// char *file_name_full;
3024//
3025// recv_str_iter = collect_str;
3026// file_name_full = store_prefix_file_name (&own_identity,
3027// file_name);
3028// for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++)
3029// {
3030// char collect_str_tmp[8];
3031//
3032// GNUNET_snprintf (collect_str_tmp,
3033// sizeof(collect_str_tmp),
3034// "%" PRIu32 "\n",
3035// hist_array[i]);
3036// recv_str_iter = stpncpy (recv_str_iter,
3037// collect_str_tmp,
3038// 6);
3039// }
3040// (void) stpcpy (recv_str_iter,
3041// "\n");
3042// LOG (GNUNET_ERROR_TYPE_DEBUG,
3043// "Writing push stats to disk\n");
3044// to_file_w_len (file_name_full,
3045// SIZE_DUMP_FILE, "%s",
3046// collect_str);
3047// GNUNET_free (file_name_full);
3048// }
3049
3050
3051#endif /* TO_FILE */
3052
3053
3059static void
3060destroy_sub (struct Sub *sub)
3061{
3062 GNUNET_assert (NULL != sub);
3063 GNUNET_assert (NULL != sub->do_round_task);
3065 sub->do_round_task = NULL;
3066
3067 /* Disconnect from cadet */
3069 sub->cadet_port = NULL;
3070
3071 /* Clean up data structures for peers */
3073 sub->sampler = NULL;
3074 View_destroy (sub->view);
3075 sub->view = NULL;
3077 sub->push_map = NULL;
3079 sub->pull_map = NULL;
3080 peers_terminate (sub);
3081
3082 /* Free leftover data structures */
3083#ifdef TO_FILE_FULL
3084 GNUNET_free (sub->file_name_view_log);
3085 sub->file_name_view_log = NULL;
3086#endif /* TO_FILE_FULL */
3087#ifdef TO_FILE
3088#ifdef TO_FILE_FULL
3089 GNUNET_free (sub->file_name_observed_log);
3090 sub->file_name_observed_log = NULL;
3091#endif /* TO_FILE_FULL */
3092
3093 // FIXME: Currently this calls malfunctionning code
3094 // /* Write push frequencies to disk */
3095 // write_histogram_to_file (sub->push_recv,
3096 // "push_recv");
3097
3098 // /* Write push deltas to disk */
3099 // write_histogram_to_file (sub->push_delta,
3100 // "push_delta");
3101
3102 // /* Write pull delays to disk */
3103 // write_histogram_to_file (sub->pull_delays,
3104 // "pull_delays");
3105
3107 sub->observed_unique_peers = NULL;
3108#endif /* TO_FILE */
3109
3110 GNUNET_free (sub);
3111}
3112
3113
3114/***********************************************************************
3115* /Sub
3116***********************************************************************/
3117
3118
3119/***********************************************************************
3120* Core handlers
3121***********************************************************************/
3122
3129void
3131 const struct GNUNET_PeerIdentity *my_identity)
3132{
3133 (void) cls;
3134 (void) my_identity;
3135
3137}
3138
3139
3149void *
3151 const struct GNUNET_PeerIdentity *peer,
3152 struct GNUNET_MQ_Handle *mq,
3153 enum GNUNET_CORE_PeerClass class)
3154{
3155 (void) cls;
3156 (void) mq;
3157
3160 peer,
3161 NULL,
3163 return NULL;
3164}
3165
3166
3175void
3177 const struct GNUNET_PeerIdentity *peer,
3178 void *peer_cls)
3179{
3180 (void) cls;
3181 (void) peer_cls;
3182
3184}
3185
3186
3187/***********************************************************************
3188* /Core handlers
3189***********************************************************************/
3190
3191
3197static void
3199{
3200 GNUNET_assert (NULL != cli_ctx);
3203 cli_ctx);
3204 if (NULL != cli_ctx->sub)
3205 {
3206 destroy_sub (cli_ctx->sub);
3207 cli_ctx->sub = NULL;
3208 }
3209 GNUNET_free (cli_ctx);
3210}
3211
3212
3220static void
3221adapt_sizes (struct Sub *sub, double logestimate, double std_dev)
3222{
3223 double estimate;
3224
3225 // double scale; // TODO this might go global/config
3226
3228 "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n",
3229 logestimate, std_dev, RPS_sampler_get_size (sub->sampler));
3230 // scale = .01;
3231 estimate = GNUNET_NSE_log_estimate_to_n (logestimate);
3232 // GNUNET_NSE_log_estimate_to_n (logestimate);
3233 estimate = pow (estimate, 1.0 / 3);
3234 // TODO add if std_dev is a number
3235 // estimate += (std_dev * scale);
3236 if (sub->view_size_est_min < ceil (estimate))
3237 {
3238 LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate);
3239 sub->sampler_size_est_need = estimate;
3240 sub->view_size_est_need = estimate;
3241 }
3242 else
3243 {
3244 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate);
3245 // sub->sampler_size_est_need = sub->view_size_est_min;
3247 }
3248 if (sub == msub)
3249 {
3251 "view size aim",
3252 sub->view_size_est_need,
3253 GNUNET_NO);
3254 }
3255
3256 /* If the NSE has changed adapt the lists accordingly */
3259}
3260
3261
3275static void
3278 double logestimate, double std_dev)
3279{
3280 (void) cls;
3281 (void) timestamp;
3282 struct ClientContext *cli_ctx_iter;
3283
3284 adapt_sizes (msub, logestimate, std_dev);
3285 for (cli_ctx_iter = cli_ctx_head;
3286 NULL != cli_ctx_iter;
3287 cli_ctx_iter = cli_ctx_iter->next)
3288 {
3289 if (NULL != cli_ctx_iter->sub)
3290 {
3291 adapt_sizes (cli_ctx_iter->sub, logestimate, std_dev);
3292 }
3293 }
3294}
3295
3296
3306static int
3308{
3309 struct ClientContext *cli_ctx = cls;
3310 uint16_t msize = ntohs (msg->header.size);
3311 uint32_t num_peers = ntohl (msg->num_peers);
3312
3313 msize -= sizeof(struct GNUNET_RPS_CS_SeedMessage);
3314 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
3315 (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
3316 {
3318 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
3319 ntohl (msg->num_peers),
3320 (msize / sizeof(struct GNUNET_PeerIdentity)));
3321 GNUNET_break (0);
3323 return GNUNET_SYSERR;
3324 }
3325 return GNUNET_OK;
3326}
3327
3328
3335static void
3337 const struct GNUNET_RPS_CS_SeedMessage *msg)
3338{
3339 struct ClientContext *cli_ctx = cls;
3340 struct GNUNET_PeerIdentity *peers;
3341 uint32_t num_peers;
3342 uint32_t i;
3343
3344 num_peers = ntohl (msg->num_peers);
3345 peers = (struct GNUNET_PeerIdentity *) &msg[1];
3346
3348 "Client seeded peers:\n");
3350
3351 for (i = 0; i < num_peers; i++)
3352 {
3354 "Updating samplers with seed %" PRIu32 ": %s\n",
3355 i,
3356 GNUNET_i2s (&peers[i]));
3357
3358 if (NULL != msub)
3359 got_peer (msub, &peers[i]); /* Condition needed? */
3360 if (NULL != cli_ctx->sub)
3361 got_peer (cli_ctx->sub, &peers[i]);
3362 }
3364}
3365
3366
3374static void
3377{
3378 struct ClientContext *cli_ctx = cls;
3379 uint64_t num_updates;
3380
3381 num_updates = ntohl (msg->num_updates);
3382
3384 "Client requested %" PRIu64 " updates of view.\n",
3385 num_updates);
3386
3387 GNUNET_assert (NULL != cli_ctx);
3388 cli_ctx->view_updates_left = num_updates;
3389 send_view (cli_ctx, NULL, 0);
3391}
3392
3393
3400static void
3402 const struct GNUNET_MessageHeader *msg)
3403{
3404 struct ClientContext *cli_ctx = cls;
3405
3406 (void) msg;
3407
3409 "Client does not want to receive updates of view any more.\n");
3410
3411 GNUNET_assert (NULL != cli_ctx);
3412 cli_ctx->view_updates_left = 0;
3414 if (GNUNET_YES == cli_ctx->stream_update)
3415 {
3416 destroy_cli_ctx (cli_ctx);
3417 }
3418}
3419
3420
3427static void
3429 const struct
3431{
3432 struct ClientContext *cli_ctx = cls;
3433
3434 (void) msg;
3435
3437 "Client requested peers from biased stream.\n");
3438 cli_ctx->stream_update = GNUNET_YES;
3439
3440 GNUNET_assert (NULL != cli_ctx);
3442}
3443
3444
3451static void
3453 const struct GNUNET_MessageHeader *msg)
3454{
3455 struct ClientContext *cli_ctx = cls;
3456
3457 (void) msg;
3458
3460 "Client canceled receiving peers from biased stream.\n");
3461 cli_ctx->stream_update = GNUNET_NO;
3462
3463 GNUNET_assert (NULL != cli_ctx);
3465}
3466
3467
3474static void
3476 const struct GNUNET_RPS_CS_SubStartMessage *msg)
3477{
3478 struct ClientContext *cli_ctx = cls;
3479
3480 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested start of a new sub.\n");
3481 if ((NULL != cli_ctx->sub) &&
3482 (0 != memcmp (&cli_ctx->sub->hash,
3483 &msg->hash,
3484 sizeof(struct GNUNET_HashCode))) )
3485 {
3487 "Already have a Sub with different share for this client. Remove old one, add new.\n");
3488 destroy_sub (cli_ctx->sub);
3489 cli_ctx->sub = NULL;
3490 }
3491 cli_ctx->sub = new_sub (&msg->hash,
3492 msub->sampler_size_est_min, // TODO make api input?
3493 GNUNET_TIME_relative_ntoh (msg->round_interval));
3495}
3496
3497
3504static void
3506 const struct GNUNET_RPS_CS_SubStopMessage *msg)
3507{
3508 struct ClientContext *cli_ctx = cls;
3509
3510 GNUNET_assert (NULL != cli_ctx->sub);
3511 if (0 != memcmp (&cli_ctx->sub->hash, &msg->hash, sizeof(struct
3513 {
3515 "Share of current sub and request differ!\n");
3516 }
3517 destroy_sub (cli_ctx->sub);
3518 cli_ctx->sub = NULL;
3520}
3521
3522
3532static void
3534 const struct GNUNET_MessageHeader *msg)
3535{
3536 const struct ChannelCtx *channel_ctx = cls;
3537 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3538
3539 (void) msg;
3540
3542 "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer));
3543 if (channel_ctx->peer_ctx->sub == msub)
3544 {
3546 "# pending online checks",
3547 -1,
3548 GNUNET_NO);
3549 }
3550
3551 GNUNET_CADET_receive_done (channel_ctx->channel);
3552}
3553
3554
3564static void
3566 const struct GNUNET_MessageHeader *msg)
3567{
3568 const struct ChannelCtx *channel_ctx = cls;
3569 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3570
3571 (void) msg;
3572
3573 // (check the proof of work (?))
3574
3576 "Received PUSH (%s)\n",
3577 GNUNET_i2s (peer));
3578 if (channel_ctx->peer_ctx->sub == msub)
3579 {
3580 GNUNET_STATISTICS_update (stats, "# push message received", 1, GNUNET_NO);
3581 if ((NULL != map_single_hop) &&
3583 peer)))
3584 {
3586 "# push message received (multi-hop peer)",
3587 1,
3588 GNUNET_NO);
3589 }
3590 }
3591
3592 #if ENABLE_MALICIOUS
3593 struct AttackedPeer *tmp_att_peer;
3594
3595 if ((1 == mal_type) ||
3596 (3 == mal_type))
3597 { /* Try to maximise representation */
3598 tmp_att_peer = GNUNET_new (struct AttackedPeer);
3599 tmp_att_peer->peer_id = *peer;
3600 if (NULL == att_peer_set)
3603 peer))
3604 {
3605 GNUNET_CONTAINER_DLL_insert (att_peers_head,
3606 att_peers_tail,
3607 tmp_att_peer);
3608 add_peer_array_to_set (peer, 1, att_peer_set);
3609 }
3610 else
3611 {
3612 GNUNET_free (tmp_att_peer);
3613 }
3614 }
3615
3616
3617 else if (2 == mal_type)
3618 {
3619 /* We attack one single well-known peer - simply ignore */
3620 }
3621 #endif /* ENABLE_MALICIOUS */
3622
3623 /* Add the sending peer to the push_map */
3624 CustomPeerMap_put (channel_ctx->peer_ctx->sub->push_map, peer);
3625
3627 &channel_ctx->peer_ctx->peer_id));
3628 GNUNET_CADET_receive_done (channel_ctx->channel);
3629}
3630
3631
3640static void
3642 const struct GNUNET_MessageHeader *msg)
3643{
3644 const struct ChannelCtx *channel_ctx = cls;
3645 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
3646 const struct GNUNET_PeerIdentity *peer = &peer_ctx->peer_id;
3647 const struct GNUNET_PeerIdentity *view_array;
3648
3649 (void) msg;
3650
3651 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (
3652 peer));
3653 if (peer_ctx->sub == msub)
3654 {
3656 "# pull request message received",
3657 1,
3658 GNUNET_NO);
3659 if ((NULL != map_single_hop) &&
3661 &peer_ctx->peer_id
3662 )))
3663 {
3665 "# pull request message received (multi-hop peer)",
3666 1,
3667 GNUNET_NO);
3668 }
3669 }
3670
3671 #if ENABLE_MALICIOUS
3672 if ((1 == mal_type)
3673 || (3 == mal_type))
3674 { /* Try to maximise representation */
3675 send_pull_reply (peer_ctx, mal_peers, num_mal_peers);
3676 }
3677
3678 else if (2 == mal_type)
3679 { /* Try to partition network */
3680 if (0 == GNUNET_memcmp (&attacked_peer, peer))
3681 {
3682 send_pull_reply (peer_ctx, mal_peers, num_mal_peers);
3683 }
3684 }
3685 #endif /* ENABLE_MALICIOUS */
3686
3688 &channel_ctx->peer_ctx->peer_id));
3689 GNUNET_CADET_receive_done (channel_ctx->channel);
3690 view_array = View_get_as_array (channel_ctx->peer_ctx->sub->view);
3691 send_pull_reply (peer_ctx,
3692 view_array,
3693 View_size (channel_ctx->peer_ctx->sub->view));
3694}
3695
3696
3704static int
3707{
3708 struct ChannelCtx *channel_ctx = cls;
3709 struct PeerContext *sender_ctx = channel_ctx->peer_ctx;
3710
3711 if (sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->header.size))
3712 {
3713 GNUNET_break_op (0);
3714 return GNUNET_SYSERR;
3715 }
3716
3717 if ((ntohs (msg->header.size) - sizeof(struct
3719 / sizeof(struct GNUNET_PeerIdentity) != ntohl (msg->num_peers))
3720 {
3722 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
3723 ntohl (msg->num_peers),
3724 (ntohs (msg->header.size) - sizeof(struct
3726 / sizeof(struct GNUNET_PeerIdentity));
3727 GNUNET_break_op (0);
3728 return GNUNET_SYSERR;
3729 }
3730
3731 if (GNUNET_YES != check_peer_flag (sender_ctx->sub->peer_map,
3732 &sender_ctx->peer_id,
3734 {
3736 "Received a pull reply from a peer (%s) we didn't request one from!\n",
3737 GNUNET_i2s (&sender_ctx->peer_id));
3738 if (sender_ctx->sub == msub)
3739 {
3741 "# unrequested pull replies",
3742 1,
3743 GNUNET_NO);
3744 }
3745 }
3746 return GNUNET_OK;
3747}
3748
3749
3756static void
3759{
3760 const struct ChannelCtx *channel_ctx = cls;
3761 const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id;
3762 const struct GNUNET_PeerIdentity *peers;
3763 struct Sub *sub = channel_ctx->peer_ctx->sub;
3764 uint32_t i;
3765
3766#if ENABLE_MALICIOUS
3767 struct AttackedPeer *tmp_att_peer;
3768#endif /* ENABLE_MALICIOUS */
3769
3770 sub->pull_delays[sub->num_rounds - channel_ctx->peer_ctx->round_pull_req]++;
3771 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (
3772 sender));
3773 if (channel_ctx->peer_ctx->sub == msub)
3774 {
3776 "# pull reply messages received",
3777 1,
3778 GNUNET_NO);
3779 if ((NULL != map_single_hop) &&
3781 &channel_ctx->
3782 peer_ctx->peer_id)
3783 ) )
3784 {
3786 "# pull reply messages received (multi-hop peer)",
3787 1,
3788 GNUNET_NO);
3789 }
3790 }
3791
3792 #if ENABLE_MALICIOUS
3793 // We shouldn't even receive pull replies as we're not sending
3794 if (2 == mal_type)
3795 {
3796 }
3797 #endif /* ENABLE_MALICIOUS */
3798
3799 /* Do actual logic */
3800 peers = (const struct GNUNET_PeerIdentity *) &msg[1];
3801
3803 "PULL REPLY received, got following %u peers:\n",
3804 ntohl (msg->num_peers));
3805
3806 for (i = 0; i < ntohl (msg->num_peers); i++)
3807 {
3809 "%u. %s\n",
3810 i,
3811 GNUNET_i2s (&peers[i]));
3812
3813 #if ENABLE_MALICIOUS
3814 if ((NULL != att_peer_set) &&
3815 ((1 == mal_type) || (3 == mal_type) ))
3816 { /* Add attacked peer to local list */
3817 // TODO check if we sent a request and this was the first reply
3819 &peers[i]))
3821 &peers[i])) )
3822 {
3823 tmp_att_peer = GNUNET_new (struct AttackedPeer);
3824 tmp_att_peer->peer_id = peers[i];
3825 GNUNET_CONTAINER_DLL_insert (att_peers_head,
3826 att_peers_tail,
3827 tmp_att_peer);
3828 add_peer_array_to_set (&peers[i], 1, att_peer_set);
3829 }
3830 continue;
3831 }
3832 #endif /* ENABLE_MALICIOUS */
3833 /* Make sure we 'know' about this peer */
3834 (void) insert_peer (channel_ctx->peer_ctx->sub,
3835 &peers[i]);
3836
3837 if (GNUNET_YES == check_peer_valid (channel_ctx->peer_ctx->sub->valid_peers,
3838 &peers[i]))
3839 {
3840 CustomPeerMap_put (channel_ctx->peer_ctx->sub->pull_map,
3841 &peers[i]);
3842 }
3843 else
3844 {
3845 schedule_operation (channel_ctx->peer_ctx,
3847 channel_ctx->peer_ctx->sub); /* cls */
3848 (void) issue_peer_online_check (channel_ctx->peer_ctx->sub,
3849 &peers[i]);
3850 }
3851 }
3852
3854 sender),
3856 clean_peer (channel_ctx->peer_ctx->sub,
3857 sender);
3858
3860 sender));
3861 GNUNET_CADET_receive_done (channel_ctx->channel);
3862}
3863
3864
3875static struct GNUNET_TIME_Relative
3877 unsigned int spread)
3878{
3879 struct GNUNET_TIME_Relative half_interval;
3881 unsigned int rand_delay;
3882 unsigned int max_rand_delay;
3883
3884 if (0 == spread)
3885 {
3887 "Not accepting spread of 0\n");
3888 GNUNET_break (0);
3889 GNUNET_assert (0);
3890 }
3891 GNUNET_assert (0 != mean.rel_value_us);
3892
3893 /* Compute random time value between spread * mean and spread * mean */
3894 half_interval = GNUNET_TIME_relative_divide (mean, spread);
3895
3896 max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us
3897 / mean.rel_value_us * (2 / spread);
3903 max_rand_delay);
3904 ret = GNUNET_TIME_relative_saturating_multiply (mean, rand_delay);
3905 ret = GNUNET_TIME_relative_divide (ret, max_rand_delay);
3906 ret = GNUNET_TIME_relative_add (ret, half_interval);
3907
3908 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us)
3910 "Returning FOREVER_REL\n");
3911
3912 return ret;
3913}
3914
3915
3921static void
3923{
3924 struct GNUNET_MQ_Envelope *ev;
3925
3927 &peer_ctx->peer_id,
3929 SET_PEER_FLAG (peer_ctx,
3931 peer_ctx->round_pull_req = peer_ctx->sub->num_rounds;
3932
3934 "Going to send PULL REQUEST to peer %s.\n",
3935 GNUNET_i2s (&peer_ctx->peer_id));
3936
3938 send_message (peer_ctx,
3939 ev,
3940 "PULL REQUEST");
3941 if (peer_ctx->sub)
3942 {
3944 "# pull request send issued",
3945 1,
3946 GNUNET_NO);
3947 if ((NULL != map_single_hop) &&
3949 &peer_ctx->peer_id
3950 )))
3951 {
3953 "# pull request send issued (multi-hop peer)",
3954 1,
3955 GNUNET_NO);
3956 }
3957 }
3958}
3959
3960
3966static void
3967send_push (struct PeerContext *peer_ctx)
3968{
3969 struct GNUNET_MQ_Envelope *ev;
3970
3972 "Going to send PUSH to peer %s.\n",
3973 GNUNET_i2s (&peer_ctx->peer_id));
3974
3976 send_message (peer_ctx, ev, "PUSH");
3977 if (peer_ctx->sub)
3978 {
3980 "# push send issued",
3981 1,
3982 GNUNET_NO);
3983 if ((NULL != map_single_hop) &&
3985 &peer_ctx->peer_id
3986 )))
3987 {
3989 "# push send issued (multi-hop peer)",
3990 1,
3991 GNUNET_NO);
3992 }
3993 }
3994}
3995
3996
3997#if ENABLE_MALICIOUS
3998
3999
4008static int
4009check_client_act_malicious (void *cls,
4010 const struct GNUNET_RPS_CS_ActMaliciousMessage *msg)
4011{
4012 struct ClientContext *cli_ctx = cls;
4013 uint16_t msize = ntohs (msg->header.size);
4014 uint32_t num_peers = ntohl (msg->num_peers);
4015
4016 msize -= sizeof(struct GNUNET_RPS_CS_ActMaliciousMessage);
4017 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
4018 (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
4019 {
4021 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
4022 ntohl (msg->num_peers),
4023 (msize / sizeof(struct GNUNET_PeerIdentity)));
4024 GNUNET_break (0);
4026 return GNUNET_SYSERR;
4027 }
4028 return GNUNET_OK;
4029}
4030
4031
4039static void
4040handle_client_act_malicious (void *cls,
4041 const struct
4042 GNUNET_RPS_CS_ActMaliciousMessage *msg)
4043{
4044 struct ClientContext *cli_ctx = cls;
4045 struct GNUNET_PeerIdentity *peers;
4046 uint32_t num_mal_peers_sent;
4047 uint32_t num_mal_peers_old;
4048 struct Sub *sub = cli_ctx->sub;
4049
4050 if (NULL == sub)
4051 sub = msub;
4052 /* Do actual logic */
4053 peers = (struct GNUNET_PeerIdentity *) &msg[1];
4054 mal_type = ntohl (msg->type);
4055 if (NULL == mal_peer_set)
4057
4059 "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n",
4060 mal_type,
4061 ntohl (msg->num_peers));
4062
4063 if (1 == mal_type)
4064 { /* Try to maximise representation */
4065 /* Add other malicious peers to those we already know */
4066
4067 num_mal_peers_sent = ntohl (msg->num_peers);
4068 num_mal_peers_old = num_mal_peers;
4069 GNUNET_array_grow (mal_peers,
4070 num_mal_peers,
4071 num_mal_peers + num_mal_peers_sent);
4072 GNUNET_memcpy (&mal_peers[num_mal_peers_old],
4073 peers,
4074 num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity));
4075
4076 /* Add all mal peers to mal_peer_set */
4077 add_peer_array_to_set (&mal_peers[num_mal_peers_old],
4078 num_mal_peers_sent,
4079 mal_peer_set);
4080
4081 /* Substitute do_round () with do_mal_round () */
4082 GNUNET_assert (NULL != sub->do_round_task);
4084 sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub);
4085 }
4086
4087 else if ((2 == mal_type) ||
4088 (3 == mal_type))
4089 { /* Try to partition the network */
4090 /* Add other malicious peers to those we already know */
4091
4092 num_mal_peers_sent = ntohl (msg->num_peers) - 1;
4093 num_mal_peers_old = num_mal_peers;
4094 GNUNET_assert (GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent);
4095 GNUNET_array_grow (mal_peers,
4096 num_mal_peers,
4097 num_mal_peers + num_mal_peers_sent);
4098 if ((NULL != mal_peers) &&
4099 (0 != num_mal_peers) )
4100 {
4101 GNUNET_memcpy (&mal_peers[num_mal_peers_old],
4102 peers,
4103 num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity));
4104
4105 /* Add all mal peers to mal_peer_set */
4106 add_peer_array_to_set (&mal_peers[num_mal_peers_old],
4107 num_mal_peers_sent,
4108 mal_peer_set);
4109 }
4110
4111 /* Store the one attacked peer */
4112 GNUNET_memcpy (&attacked_peer,
4113 &msg->attacked_peer,
4114 sizeof(struct GNUNET_PeerIdentity));
4115 /* Set the flag of the attacked peer to valid to avoid problems */
4116 if (GNUNET_NO == check_peer_known (sub->peer_map, &attacked_peer))
4117 {
4118 (void) issue_peer_online_check (sub, &attacked_peer);
4119 }
4120
4122 "Attacked peer is %s\n",
4123 GNUNET_i2s (&attacked_peer));
4124
4125 /* Substitute do_round () with do_mal_round () */
4126 if (NULL != sub->do_round_task)
4127 {
4128 /* Probably in shutdown */
4130 sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub);
4131 }
4132 }
4133 else if (0 == mal_type)
4134 { /* Stop acting malicious */
4135 GNUNET_array_grow (mal_peers, num_mal_peers, 0);
4136
4137 /* Substitute do_mal_round () with do_round () */
4140 }
4141 else
4142 {
4143 GNUNET_break (0);
4145 }
4147}
4148
4149
4157static void
4158do_mal_round (void *cls)
4159{
4160 uint32_t num_pushes;
4161 uint32_t i;
4162 struct GNUNET_TIME_Relative time_next_round;
4163 struct AttackedPeer *tmp_att_peer;
4164 struct Sub *sub = cls;
4165
4167 "Going to execute next round maliciously type %" PRIu32 ".\n",
4168 mal_type);
4169 sub->do_round_task = NULL;
4170 GNUNET_assert (mal_type <= 3);
4171 /* Do malicious actions */
4172 if (1 == mal_type)
4173 { /* Try to maximise representation */
4174 /* The maximum of pushes we're going to send this round */
4175 num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit,
4176 num_attacked_peers),
4178
4180 "Going to send %" PRIu32 " pushes\n",
4181 num_pushes);
4182
4183 /* Send PUSHes to attacked peers */
4184 for (i = 0; i < num_pushes; i++)
4185 {
4186 if (att_peers_tail == att_peer_index)
4187 att_peer_index = att_peers_head;
4188 else
4189 att_peer_index = att_peer_index->next;
4190
4191 send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id));
4192 }
4193
4194 /* Send PULLs to some peers to learn about additional peers to attack */
4195 tmp_att_peer = att_peer_index;
4196 for (i = 0; i < num_pushes * alpha; i++)
4197 {
4198 if (att_peers_tail == tmp_att_peer)
4199 tmp_att_peer = att_peers_head;
4200 else
4201 att_peer_index = tmp_att_peer->next;
4202
4203 send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id));
4204 }
4205 }
4206
4207
4208 else if (2 == mal_type)
4209 {
4214 (void) issue_peer_online_check (sub, &attacked_peer);
4215 if (GNUNET_YES == check_peer_flag (sub->peer_map,
4216 &attacked_peer,
4217 Peers_ONLINE))
4218 send_push (get_peer_ctx (sub->peer_map, &attacked_peer));
4219 }
4220
4221
4222 if (3 == mal_type)
4223 { /* Combined attack */
4224 /* Send PUSH to attacked peers */
4225 if (GNUNET_YES == check_peer_known (sub->peer_map, &attacked_peer))
4226 {
4227 (void) issue_peer_online_check (sub, &attacked_peer);
4228 if (GNUNET_YES == check_peer_flag (sub->peer_map,
4229 &attacked_peer,
4230 Peers_ONLINE))
4231 {
4233 "Goding to send push to attacked peer (%s)\n",
4234 GNUNET_i2s (&attacked_peer));
4235 send_push (get_peer_ctx (sub->peer_map, &attacked_peer));
4236 }
4237 }
4238 (void) issue_peer_online_check (sub, &attacked_peer);
4239
4240 /* The maximum of pushes we're going to send this round */
4241 num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1,
4242 num_attacked_peers),
4244
4246 "Going to send %" PRIu32 " pushes\n",
4247 num_pushes);
4248
4249 for (i = 0; i < num_pushes; i++)
4250 {
4251 if (att_peers_tail == att_peer_index)
4252 att_peer_index = att_peers_head;
4253 else
4254 att_peer_index = att_peer_index->next;
4255
4256 send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id));
4257 }
4258
4259 /* Send PULLs to some peers to learn about additional peers to attack */
4260 tmp_att_peer = att_peer_index;
4261 for (i = 0; i < num_pushes * alpha; i++)
4262 {
4263 if (att_peers_tail == tmp_att_peer)
4264 tmp_att_peer = att_peers_head;
4265 else
4266 att_peer_index = tmp_att_peer->next;
4267
4268 send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id));
4269 }
4270 }
4271
4272 /* Schedule next round */
4273 time_next_round = compute_rand_delay (sub->round_interval, 2);
4274
4275 GNUNET_assert (NULL == sub->do_round_task);
4276 sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
4277 &do_mal_round, sub);
4278 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
4279}
4280
4281
4282#endif /* ENABLE_MALICIOUS */
4283
4284
4292static void
4293do_round (void *cls)
4294{
4295 unsigned int i;
4296 const struct GNUNET_PeerIdentity *view_array;
4297 unsigned int *permut;
4298 unsigned int a_peers; /* Number of peers we send pushes to */
4299 unsigned int b_peers; /* Number of peers we send pull requests to */
4300 uint32_t first_border;
4301 uint32_t second_border;
4302 struct GNUNET_PeerIdentity peer;
4303 struct GNUNET_PeerIdentity *update_peer;
4304 struct Sub *sub = cls;
4305
4306 sub->num_rounds++;
4308 "Going to execute next round.\n");
4309 if (sub == msub)
4310 {
4311 GNUNET_STATISTICS_update (stats, "# rounds", 1, GNUNET_NO);
4312 }
4313 sub->do_round_task = NULL;
4314#ifdef TO_FILE_FULL
4315 to_file (sub->file_name_view_log,
4316 "___ new round ___");
4317#endif /* TO_FILE_FULL */
4318 view_array = View_get_as_array (sub->view);
4319 for (i = 0; i < View_size (sub->view); i++)
4320 {
4322 "\t%s\n", GNUNET_i2s (&view_array[i]));
4323#ifdef TO_FILE_FULL
4324 to_file (sub->file_name_view_log,
4325 "=%s\t(do round)",
4326 GNUNET_i2s_full (&view_array[i]));
4327#endif /* TO_FILE_FULL */
4328 }
4329
4330
4331 /* Send pushes and pull requests */
4332 if (0 < View_size (sub->view))
4333 {
4335 View_size (sub->view));
4336
4337 /* Send PUSHes */
4338 a_peers = ceil (alpha * View_size (sub->view));
4339
4341 "Going to send pushes to %u (ceil (%f * %u)) peers.\n",
4342 a_peers, alpha, View_size (sub->view));
4343 for (i = 0; i < a_peers; i++)
4344 {
4345 peer = view_array[permut[i]];
4346 // FIXME if this fails schedule/loop this for later
4347 send_push (get_peer_ctx (sub->peer_map, &peer));
4348 }
4349
4350 /* Send PULL requests */
4351 b_peers = ceil (beta * View_size (sub->view));
4352 first_border = a_peers;
4353 second_border = a_peers + b_peers;
4354 if (second_border > View_size (sub->view))
4355 {
4356 first_border = View_size (sub->view) - b_peers;
4357 second_border = View_size (sub->view);
4358 }
4360 "Going to send pulls to %u (ceil (%f * %u)) peers.\n",
4361 b_peers, beta, View_size (sub->view));
4362 for (i = first_border; i < second_border; i++)
4363 {
4364 peer = view_array[permut[i]];
4365 if (GNUNET_NO == check_peer_flag (sub->peer_map,
4366 &peer,
4368 { // FIXME if this fails schedule/loop this for later
4369 send_pull_request (get_peer_ctx (sub->peer_map, &peer));
4370 }
4371 }
4372
4373 GNUNET_free (permut);
4374 permut = NULL;
4375 }
4376
4377
4378 /* Update view */
4379 /* TODO see how many peers are in push-/pull- list! */
4380
4381 if ((CustomPeerMap_size (sub->push_map) <= alpha * sub->view_size_est_need) &&
4382 (0 < CustomPeerMap_size (sub->push_map)) &&
4383 (0 < CustomPeerMap_size (sub->pull_map)))
4384 { /* If conditions for update are fulfilled, update */
4385 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n");
4386
4387 uint32_t final_size;
4388 uint32_t peers_to_clean_size;
4389 struct GNUNET_PeerIdentity *peers_to_clean;
4390
4391 peers_to_clean = NULL;
4392 peers_to_clean_size = 0;
4393 GNUNET_array_grow (peers_to_clean,
4394 peers_to_clean_size,
4395 View_size (sub->view));
4396 GNUNET_memcpy (peers_to_clean,
4397 view_array,
4398 View_size (sub->view) * sizeof(struct GNUNET_PeerIdentity));
4399
4400 /* Seems like recreating is the easiest way of emptying the peermap */
4401 View_clear (sub->view);
4402#ifdef TO_FILE_FULL
4403 to_file (sub->file_name_view_log,
4404 "--- emptied ---");
4405#endif /* TO_FILE_FULL */
4406
4407 first_border = GNUNET_MIN (ceil (alpha * sub->view_size_est_need),
4409 second_border = first_border
4410 + GNUNET_MIN (floor (beta * sub->view_size_est_need),
4412 final_size = second_border
4413 + ceil ((1 - (alpha + beta)) * sub->view_size_est_need);
4415 "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %"
4416 PRIu32 "\n",
4417 first_border,
4418 second_border,
4419 final_size);
4420
4421 /* Update view with peers received through PUSHes */
4424 for (i = 0; i < first_border; i++)
4425 {
4426 int inserted;
4427 inserted = insert_in_view (sub,
4429 permut[i]));
4430 if (GNUNET_OK == inserted)
4431 {
4433 1,
4435 sub->push_map, permut[i]));
4436 }
4437#ifdef TO_FILE_FULL
4438 to_file (sub->file_name_view_log,
4439 "+%s\t(push list)",
4440 GNUNET_i2s_full (&view_array[i]));
4441#endif /* TO_FILE_FULL */
4442 // TODO change the peer_flags accordingly
4443 }
4444 GNUNET_free (permut);
4445 permut = NULL;
4446
4447 /* Update view with peers received through PULLs */
4450 for (i = first_border; i < second_border; i++)
4451 {
4452 int inserted;
4453 inserted = insert_in_view (sub,
4455 permut[i
4456 -
4457 first_border
4458 ]));
4459 if (GNUNET_OK == inserted)
4460 {
4462 1,
4464 sub->pull_map,
4465 permut[i
4466 - first_border]));
4467 }
4468#ifdef TO_FILE_FULL
4469 to_file (sub->file_name_view_log,
4470 "+%s\t(pull list)",
4471 GNUNET_i2s_full (&view_array[i]));
4472#endif /* TO_FILE_FULL */
4473 // TODO change the peer_flags accordingly
4474 }
4475 GNUNET_free (permut);
4476 permut = NULL;
4477
4478 /* Update view with peers from history */
4480 final_size - second_border,
4482 sub);
4483 // TODO change the peer_flags accordingly
4484
4485 for (i = 0; i < View_size (sub->view); i++)
4486 rem_from_list (&peers_to_clean, &peers_to_clean_size, &view_array[i]);
4487
4488 /* Clean peers that were removed from the view */
4489 for (i = 0; i < peers_to_clean_size; i++)
4490 {
4491#ifdef TO_FILE_FULL
4492 to_file (sub->file_name_view_log,
4493 "-%s",
4494 GNUNET_i2s_full (&peers_to_clean[i]));
4495#endif /* TO_FILE_FULL */
4496 clean_peer (sub, &peers_to_clean[i]);
4497 }
4498
4499 GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0);
4501 }
4502 else
4503 {
4504 LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n");
4505 if (sub == msub)
4506 {
4507 GNUNET_STATISTICS_update (stats, "# rounds blocked", 1, GNUNET_NO);
4508 if ((CustomPeerMap_size (sub->push_map) > alpha
4509 * sub->view_size_est_need) &&
4510 ! (0 >= CustomPeerMap_size (sub->pull_map)))
4511 GNUNET_STATISTICS_update (stats, "# rounds blocked - too many pushes",
4512 1, GNUNET_NO);
4513 if ((CustomPeerMap_size (sub->push_map) > alpha
4514 * sub->view_size_est_need) &&
4515 (0 >= CustomPeerMap_size (sub->pull_map)))
4517 "# rounds blocked - too many pushes, no pull replies",
4518 1, GNUNET_NO);
4519 if ((0 >= CustomPeerMap_size (sub->push_map)) &&
4520 ! (0 >= CustomPeerMap_size (sub->pull_map)))
4521 GNUNET_STATISTICS_update (stats, "# rounds blocked - no pushes", 1,
4522 GNUNET_NO);
4523 if ((0 >= CustomPeerMap_size (sub->push_map)) &&
4524 (0 >= CustomPeerMap_size (sub->pull_map)))
4526 "# rounds blocked - no pushes, no pull replies",
4527 1, GNUNET_NO);
4528 if ((0 >= CustomPeerMap_size (sub->pull_map)) &&
4530 * sub->view_size_est_need) &&
4531 (0 >= CustomPeerMap_size (sub->push_map)) )
4532 GNUNET_STATISTICS_update (stats, "# rounds blocked - no pull replies",
4533 1, GNUNET_NO);
4534 }
4535 }
4536 // TODO independent of that also get some peers from CADET_get_peers()?
4538 {
4539 sub->push_recv[CustomPeerMap_size (sub->push_map)]++;
4540 }
4541 else
4542 {
4544 "Push map size too big for histogram (%u, %u)\n",
4547 }
4548 // FIXME check bounds of histogram
4549 sub->push_delta[(int32_t) (CustomPeerMap_size (sub->push_map)
4550 - (alpha * sub->view_size_est_need))
4551 + (HISTOGRAM_FILE_SLOTS / 2)]++;
4552 if (sub == msub)
4553 {
4555 "# peers in push map at end of round",
4557 GNUNET_NO);
4559 "# peers in pull map at end of round",
4561 GNUNET_NO);
4563 "# peers in view at end of round",
4564 View_size (sub->view),
4565 GNUNET_NO);
4567 "# expected pushes",
4569 GNUNET_NO);
4571 "delta expected - received pushes",
4573 * sub->
4574 view_size_est_need),
4575 GNUNET_NO);
4576 }
4577
4579 "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n",
4582 alpha,
4583 View_size (sub->view),
4584 alpha * View_size (sub->view));
4585
4586 /* Update samplers */
4587 for (i = 0; i < CustomPeerMap_size (sub->push_map); i++)
4588 {
4589 update_peer = CustomPeerMap_get_peer_by_index (sub->push_map, i);
4591 "Updating with peer %s from push list\n",
4592 GNUNET_i2s (update_peer));
4593 insert_in_sampler (sub, update_peer);
4594 clean_peer (sub, update_peer); /* This cleans only if it is not in the view */
4595 }
4596
4597 for (i = 0; i < CustomPeerMap_size (sub->pull_map); i++)
4598 {
4600 "Updating with peer %s from pull list\n",
4603 /* This cleans only if it is not in the view */
4605 }
4606
4607
4608 /* Empty push/pull lists */
4611
4612 if (sub == msub)
4613 {
4615 "view size",
4616 View_size (sub->view),
4617 GNUNET_NO);
4618 }
4619
4620 struct GNUNET_TIME_Relative time_next_round;
4621
4622 time_next_round = compute_rand_delay (sub->round_interval, 2);
4623
4624 /* Schedule next round */
4625 sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
4626 &do_round, sub);
4627 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
4628}
4629
4630
4646void
4647init_peer_cb (void *cls,
4648 const struct GNUNET_PeerIdentity *peer,
4649 int tunnel, /* "Do we have a tunnel towards this peer?" */
4650 unsigned int n_paths, /* "Number of known paths towards this peer" */
4651 unsigned int best_path) /* "How long is the best path?
4652 * (0 = unknown, 1 = ourselves, 2 = neighbor)" */
4653{
4654 struct Sub *sub = cls;
4655
4656 (void) tunnel;
4657 (void) n_paths;
4658 (void) best_path;
4659
4660 if (NULL != peer)
4661 {
4663 "Got peer_id %s from cadet\n",
4664 GNUNET_i2s (peer));
4665 got_peer (sub, peer);
4666 }
4667}
4668
4669
4681static int
4683 const struct GNUNET_PeerIdentity *peer)
4684{
4685 struct Sub *sub = cls;
4686
4687 if (NULL != peer)
4688 {
4690 "Got stored, valid peer %s\n",
4691 GNUNET_i2s (peer));
4692 got_peer (sub, peer);
4693 }
4694 return GNUNET_YES;
4695}
4696
4697
4706void
4708 const struct GNUNET_PEERSTORE_Record *record,
4709 const char *emsg)
4710{
4711 struct Sub *sub = cls;
4712 (void) emsg;
4713
4715 "Got peer_id %s from peerinfo\n",
4716 GNUNET_i2s (&record->peer));
4717 got_peer (sub, &record->peer);
4719}
4720
4721
4727static void
4728shutdown_task (void *cls)
4729{
4730 struct ClientContext *client_ctx;
4731
4732 (void) cls;
4734 "RPS service is going down\n");
4735
4736 /* Clean all clients */
4737 for (client_ctx = cli_ctx_head;
4738 NULL != cli_ctx_head;
4739 client_ctx = cli_ctx_head)
4740 {
4741 destroy_cli_ctx (client_ctx);
4742 }
4743 if (NULL != msub)
4744 {
4745 destroy_sub (msub);
4746 msub = NULL;
4747 }
4748
4749 /* Disconnect from other services */
4751 peerstore_notify = NULL;
4753 peerstore = NULL;
4755 nse = NULL;
4756 if (NULL != core_handle)
4757 {
4758 /* core_init was called - core was initialised */
4759 /* disconnect first, so no callback tries to access missing peermap */
4761 core_handle = NULL;
4762 }
4763 if (NULL != map_single_hop)
4764 {
4766 map_single_hop = NULL;
4767 }
4768
4769 if (NULL != stats)
4770 {
4772 GNUNET_NO);
4773 stats = NULL;
4774 }
4776 cadet_handle = NULL;
4777#if ENABLE_MALICIOUS
4778 {
4779 struct AttackedPeer *tmp_att_peer;
4780
4781 GNUNET_array_grow (mal_peers,
4782 num_mal_peers,
4783 0);
4784 if (NULL != mal_peer_set)
4786 if (NULL != att_peer_set)
4788 while (NULL != att_peers_head)
4789 {
4790 tmp_att_peer = att_peers_head;
4791 GNUNET_CONTAINER_DLL_remove (att_peers_head,
4792 att_peers_tail,
4793 tmp_att_peer);
4794 GNUNET_free (tmp_att_peer);
4795 }
4796 }
4797#endif /* ENABLE_MALICIOUS */
4798 close_all_files ();
4799}
4800
4801
4810static void *
4812 struct GNUNET_SERVICE_Client *client,
4813 struct GNUNET_MQ_Handle *mq)
4814{
4815 struct ClientContext *cli_ctx;
4816
4817 (void) cls;
4818
4820 "Client connected\n");
4821 if (NULL == client)
4822 return client; /* Server was destroyed before a client connected. Shutting down */
4823 cli_ctx = GNUNET_new (struct ClientContext);
4824 cli_ctx->mq = mq;
4825 cli_ctx->view_updates_left = -1;
4826 cli_ctx->stream_update = GNUNET_NO;
4827 cli_ctx->client = client;
4830 cli_ctx);
4831 return cli_ctx;
4832}
4833
4834
4842static void
4845 void *internal_cls)
4846{
4847 struct ClientContext *cli_ctx = internal_cls;
4848
4849 (void) cls;
4850 GNUNET_assert (client == cli_ctx->client);
4851 if (NULL == client)
4852 { /* shutdown task - destroy all clients */
4853 while (NULL != cli_ctx_head)
4855 }
4856 else
4857 { /* destroy this client */
4859 "Client disconnected. Destroy its context.\n");
4860 destroy_cli_ctx (cli_ctx);
4861 }
4862}
4863
4864
4865static void
4866error_cb (void *cls)
4867{
4869 "Error in PEERSTORE monitoring\n");
4870}
4871
4872
4873static void
4874sync_cb (void *cls)
4875{
4877 "Done with initial PEERSTORE iteration during monitoring\n");
4878}
4879
4880
4888static void
4889run (void *cls,
4890 const struct GNUNET_CONFIGURATION_Handle *c,
4892{
4893 struct GNUNET_TIME_Relative round_interval;
4894 long long unsigned int sampler_size;
4895 char hash_port_string[] = GNUNET_APPLICATION_PORT_RPS;
4896 struct GNUNET_HashCode hash;
4897 const struct GNUNET_CORE_ServiceInfo service_info = {
4899 .version = { 1, 0 },
4900 .version_max = { 1, 0 },
4901 .version_min = { 1, 0 },
4902 };
4903
4904 (void) cls;
4905 (void) service;
4906
4907 GNUNET_log_setup ("rps",
4909 NULL);
4910 cfg = c;
4911 /* Get own ID */
4913 &own_identity); // TODO check return value
4915 "STARTING SERVICE (rps) for peer [%s]\n",
4917#if ENABLE_MALICIOUS
4919 "Malicious execution compiled in.\n");
4920#endif /* ENABLE_MALICIOUS */
4921
4922 /* Get time interval from the configuration */
4923 if (GNUNET_OK !=
4925 "RPS",
4926 "ROUNDINTERVAL",
4927 &round_interval))
4928 {
4930 "RPS", "ROUNDINTERVAL");
4932 return;
4933 }
4934
4935 /* Get initial size of sampler/view from the configuration */
4936 if (GNUNET_OK !=
4938 "RPS",
4939 "MINSIZE",
4940 &sampler_size))
4941 {
4943 "RPS", "MINSIZE");
4945 return;
4946 }
4947
4949 GNUNET_assert (NULL != cadet_handle);
4951 NULL, /* cls */
4952 core_init, /* init */
4953 core_connects, /* connects */
4954 core_disconnects, /* disconnects */
4955 NULL,
4956 &service_info); /* handlers */
4957 GNUNET_assert (NULL != core_handle);
4958
4959
4960 alpha = 0.45;
4961 beta = 0.45;
4962
4963
4964 /* Set up main Sub */
4965 GNUNET_CRYPTO_hash (hash_port_string,
4966 strlen (hash_port_string),
4967 &hash);
4968 msub = new_sub (&hash,
4969 sampler_size, /* Will be overwritten by config */
4970 round_interval);
4971
4972
4974
4975 /* connect to NSE */
4977
4978 // LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n");
4979 // GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, msub);
4980 // TODO send push/pull to each of those peers?
4981 LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n");
4984
4987 GNUNET_YES,
4988 "peerstore",
4989 NULL,
4991 &error_cb,
4992 NULL,
4993 &sync_cb,
4994 NULL,
4996 msub);
4997
4998 LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n");
4999
5002}
5003
5004
5010 "rps",
5012 &run,
5015 NULL,
5016 GNUNET_MQ_hd_var_size (client_seed,
5019 NULL),
5021 GNUNET_MQ_hd_var_size (client_act_malicious,
5022 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS,
5023 struct GNUNET_RPS_CS_ActMaliciousMessage,
5024 NULL),
5025#endif /* ENABLE_MALICIOUS */
5026 GNUNET_MQ_hd_fixed_size (client_view_request,
5029 NULL),
5030 GNUNET_MQ_hd_fixed_size (client_view_cancel,
5032 struct GNUNET_MessageHeader,
5033 NULL),
5034 GNUNET_MQ_hd_fixed_size (client_stream_request,
5037 NULL),
5038 GNUNET_MQ_hd_fixed_size (client_stream_cancel,
5040 struct GNUNET_MessageHeader,
5041 NULL),
5042 GNUNET_MQ_hd_fixed_size (client_start_sub,
5045 NULL),
5046 GNUNET_MQ_hd_fixed_size (client_stop_sub,
5049 NULL),
5051
5052/* end of gnunet-service-rps.c */
struct GNUNET_MessageHeader * msg
Definition 005.c:2
static int list
Set if we should print a list of currently running services.
Definition gnunet-arm.c:68
static int ret
Final status code.
Definition gnunet-arm.c:93
static char * peer_id
Option –peer.
static uint64_t timestamp(void)
Get current timestamp.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
#define LOG(kind,...)
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_FS_Handle * ctx
struct GNUNET_SCHEDULER_Task * shutdown_task
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
struct GNUNET_CONTAINER_MultiPeerMap * peers
Map from PIDs to struct CadetPeer entries.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
static void remove_pending_message(struct PendingMessage *pending_msg, int cancel)
Remove a pending message from the respective DLL.
struct ClientContext * cli_ctx_tail
struct GNUNET_CONTAINER_MultiPeerMap * map_single_hop
PeerMap to keep track of connected peers.
static void clean_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Remove data that is not needed anymore.
static void send_pull_reply(struct PeerContext *peer_ctx, const struct GNUNET_PeerIdentity *peer_ids, unsigned int num_peer_ids)
Send a PULL REPLY to peer_id.
static void sync_cb(void *cls)
static void mq_online_check_successful(void *cls)
This is called in response to the first message we sent as a online check.
static int check_operation_scheduled(const struct PeerContext *peer_ctx, const PeerOp peer_op)
Check whether function of type PeerOp was already scheduled.
static void handle_client_stream_cancel(void *cls, const struct GNUNET_MessageHeader *msg)
Handles the cancellation of the stream of biased peer ids.
static int valid_peer_iterator(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Iterator over #valid_peers hash map entries.
void core_init(void *cls, const struct GNUNET_PeerIdentity *my_identity)
Callback on initialisation of Core.
static void destroy_channel_cb(void *cls)
Destroy a cadet channel.
struct ClientContext * cli_ctx_head
DLL with all clients currently connected to us.
static void handle_client_view_cancel(void *cls, const struct GNUNET_MessageHeader *msg)
Handle the cancellation of the view updates.
static void destroy_cli_ctx(struct ClientContext *cli_ctx)
Destroy the context for a (connected) client.
static void handle_client_view_request(void *cls, const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg)
Handle RPS request from the client.
static void handle_client_stream_request(void *cls, const struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg)
Handle RPS request for biased stream from the client.
static void handle_peer_push(void *cls, const struct GNUNET_MessageHeader *msg)
Handle a PUSH message from another peer.
static int check_sending_channel_needed(const struct PeerContext *peer_ctx)
Checks if there is a sending channel and if it is needed.
static struct GNUNET_PeerIdentity own_identity
Our own identity.
static int check_peer_pull_reply(void *cls, const struct GNUNET_RPS_P2P_PullReplyMessage *msg)
Check whether we sent a corresponding request and whether this reply is the first one.
static void store_valid_peers(const struct Sub *sub)
Store the peers currently in #valid_peers to disk.
static int add_valid_peer(const struct GNUNET_PeerIdentity *peer, struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
Add a given peer to valid peers.
static int get_rand_peer_iterator(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Iterator function for get_random_peer_from_peermap.
static void handle_client_start_sub(void *cls, const struct GNUNET_RPS_CS_SubStartMessage *msg)
Create and start a Sub.
static void adapt_sizes(struct Sub *sub, double logestimate, double std_dev)
Update sizes in sampler and view on estimate update from nse service.
#define SET_PEER_FLAG(peer_ctx, mask)
Set a peer flag of given peer context.
static void set_peer_online(struct PeerContext *peer_ctx)
Set the peer flag to living and call the pending operations on this peer.
static struct GNUNET_NSE_Handle * nse
Handler to NSE.
static struct GNUNET_PEERSTORE_Monitor * peerstore_notify
Our peerstore notification context.
void process_peerinfo_peers(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Iterator over peers from peerinfo.
static const struct GNUNET_PeerIdentity * s2i_full(const char *string_repr)
Convert string representation of peer id to peer id.
static struct PeerContext * create_or_get_peer_ctx(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Create or get a PeerContext.
static int peermap_clear_iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static struct Sub * msub
Main Sub.
static void handle_peer_pull_reply(void *cls, const struct GNUNET_RPS_P2P_PullReplyMessage *msg)
Handle PULL REPLY message from another peer.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void send_pull_request(struct PeerContext *peer_ctx)
Send single pull request.
#define HISTOGRAM_FILE_SLOTS
This number determines the number of slots for files that represent histograms.
static struct GNUNET_PEERSTORE_Handle * peerstore
Handle to the PEERSTORE service.
static int check_removable(const struct PeerContext *peer_ctx)
Check if peer is removable.
#define check_peer_flag_set(peer_ctx, mask)
Get peer flag of given peer context.
static int store_peer_presistently_iterator(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Iterator function for store_valid_peers.
void init_peer_cb(void *cls, const struct GNUNET_PeerIdentity *peer, int tunnel, unsigned int n_paths, unsigned int best_path)
This is called from GNUNET_CADET_get_peers().
static void send_push(struct PeerContext *peer_ctx)
Send single push.
static void destroy_channel(struct ChannelCtx *channel_ctx)
Callback for scheduler to destroy a channel.
static void insert_in_view_op(void *cls, const struct GNUNET_PeerIdentity *peer)
Insert PeerID in #view.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
Handle client connecting to the service.
static void send_message(struct PeerContext *peer_ctx, struct GNUNET_MQ_Envelope *ev, const char *type)
Send a message to another peer.
#define UNSET_PEER_FLAG(peer_ctx, mask)
Unset flag of given peer context.
static void handle_peer_check(void *cls, const struct GNUNET_MessageHeader *msg)
Handle a CHECK_LIVE message from another peer.
static void insert_in_pull_map(void *cls, const struct GNUNET_PeerIdentity *peer)
Insert PeerID in #pull_map.
static int check_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg)
This function is called, when the client seeds peers.
static struct GNUNET_TIME_Relative compute_rand_delay(struct GNUNET_TIME_Relative mean, unsigned int spread)
Compute a random delay.
static int check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
Check whether flags on a peer are set.
static const struct GNUNET_PeerIdentity * get_random_peer_from_peermap(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
Get a random peer from peer_map.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Handle random peer sampling clients.
struct GNUNET_CADET_Handle * cadet_handle
Handler to CADET.
static void nse_callback(void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
Function called by NSE.
static void peers_terminate(struct Sub *sub)
Delete storage of peers that was created with #initialise_peers ()
static int insert_in_view(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Insert PeerID in #view.
static int issue_peer_online_check(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Try connecting to a peer to see whether it is online.
static float beta
Percentage of total peer number in the view to send random PULLs to.
void * core_connects(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq, enum GNUNET_CORE_PeerClass class)
Callback for core.
static void remove_channel_ctx(struct ChannelCtx *channel_ctx)
Free memory and NULL pointers.
static void got_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
This is called on peers from external sources (cadet, peerinfo, ...) If the peer is not known,...
static int destroy_sending_channel(struct PeerContext *peer_ctx)
Destroy the send channel of a peer e.g.
static int check_peer_send_intention(const struct PeerContext *peer_ctx)
Check whether other peer has the intention to send/opened channel towars us.
static struct GNUNET_MQ_Handle * get_mq(struct PeerContext *peer_ctx)
Get the message queue (GNUNET_MQ_Handle) of a specific peer.
static float alpha
Percentage of total peer number in the view to send random PUSHes to.
static int check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether we have information about the given peer.
static void indicate_sending_intention(struct PeerContext *peer_ctx)
Indicate that we want to send to the other peer.
static void send_view(const struct ClientContext *cli_ctx, const struct GNUNET_PeerIdentity *view_array, uint64_t view_size)
Send view to client.
static int valid_peers_iterator(void *cls, const struct GNUNET_PeerIdentity *peer)
Iterator function over stored, valid peers.
static void handle_client_stop_sub(void *cls, const struct GNUNET_RPS_CS_SubStopMessage *msg)
Destroy the Sub.
struct Sub * new_sub(const struct GNUNET_HashCode *hash, uint32_t sampler_size, struct GNUNET_TIME_Relative round_interval)
Create a new Sub.
static void schedule_channel_destruction(struct ChannelCtx *channel_ctx)
Schedule the destruction of a channel for immediately afterwards.
static void clients_notify_view_update(const struct Sub *sub)
sends updates to clients that are interested
static void handle_peer_pull_request(void *cls, const struct GNUNET_MessageHeader *msg)
Handle PULL REQUEST request message from another peer.
static int insert_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Add peer to known peers.
static struct PeerContext * create_peer_ctx(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Create a new PeerContext and insert it into the peer map.
static void check_peer_online(struct PeerContext *peer_ctx)
Issue a check whether peer is online.
static void * handle_inbound_channel(void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *initiator)
Handle the channel a peer opens to us.
static struct PeerContext * get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_PeerIdentity *peer)
Get the PeerContext associated with a peer.
static void error_cb(void *cls)
static void hist_update(const struct GNUNET_PeerIdentity *ids, uint32_t num_peers, void *cls)
Put random peer from sampler into the view as history update.
void core_disconnects(void *cls, const struct GNUNET_PeerIdentity *peer, void *peer_cls)
Callback for core.
struct GNUNET_CADET_Channel * get_channel(struct PeerContext *peer_ctx)
Get the channel of a peer.
#define LOG(kind,...)
static struct PendingMessage * insert_pending_message(struct PeerContext *peer_ctx, struct GNUNET_MQ_Envelope *ev, const char *type)
Add an envelope to a message passed to mq to list of pending messages.
static struct ChannelCtx * add_channel_ctx(struct PeerContext *peer_ctx)
Allocate memory for a new channel context and insert it into DLL.
struct GNUNET_CORE_Handle * core_handle
Handle to CORE.
static int check_connected(struct PeerContext *peer_ctx)
Check whether we have a connection to this peer.
static int get_valid_peers(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, PeersIterator iterator, void *it_cls)
Get all currently known, valid peer ids.
static void send_stream_peers(const struct ClientContext *cli_ctx, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
Send peer from biased stream to client.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *internal_cls)
Callback called when a client disconnected from the service.
static void restore_valid_peers(const struct Sub *sub)
Restore the peers on disk to #valid_peers.
static void handle_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg)
Handle seed from the client.
static void resize_wrapper(struct RPS_Sampler *sampler, uint32_t new_size)
Wrapper around RPS_sampler_resize()
static void cleanup_destroyed_channel(void *cls, const struct GNUNET_CADET_Channel *channel)
This is called when a channel is destroyed.
static void mq_notify_sent_cb(void *cls)
This is called once a message is sent.
static void clients_notify_stream_peer(const struct Sub *sub, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
sends updates to clients that are interested
static void print_peer_list(struct GNUNET_PeerIdentity *list, unsigned int len)
Print peerlist to log.
static void rem_from_list(struct GNUNET_PeerIdentity **peer_list, unsigned int *list_size, const struct GNUNET_PeerIdentity *peer)
Remove peer from list.
static void destroy_sub(struct Sub *sub)
Destroy Sub.
static int schedule_operation(struct PeerContext *peer_ctx, const PeerOp peer_op, void *cls)
Schedule a operation on given peer.
static int check_sending_channel_exists(const struct PeerContext *peer_ctx)
Check whether a sending channel towards the given peer exists.
static const uint32_t num_valid_peers_max
Maximum number of valid peers to keep.
static void insert_in_sampler(void *cls, const struct GNUNET_PeerIdentity *peer)
Update sampler with given PeerID.
static void remove_peer(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
remove peer from our knowledge, the view, push and pull maps and samplers.
static int check_peer_valid(const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, const struct GNUNET_PeerIdentity *peer)
Check whether peer is actually a peer.
static int destroy_peer(struct PeerContext *peer_ctx)
Remove peer.
static void do_round(void *cls)
Send out PUSHes and PULLs, possibly update #view, samplers.
unsigned int CustomPeerMap_size(const struct CustomPeerMap *c_peer_map)
Get the size of the custom peer map.
int CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map, const struct GNUNET_PeerIdentity *peer)
Check whether custom peer map contains a peer.
int CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, const struct GNUNET_PeerIdentity *peer)
Insert peer into the custom peer map.
int CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map, const struct GNUNET_PeerIdentity *peer)
Remove peer from custom peer map.
void CustomPeerMap_destroy(struct CustomPeerMap *c_peer_map)
Destroy peermap.
void CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map)
Clear the custom peer map.
struct CustomPeerMap * CustomPeerMap_create(unsigned int len)
Create an empty peermap.
struct GNUNET_PeerIdentity * CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, uint32_t index)
Get a peer by index.
utilities for managing (information about) peers
struct RPS_Sampler * RPS_sampler_init(size_t init_size, struct GNUNET_TIME_Relative max_round_interval)
Initialise a tuple of sampler elements.
sampler implementation
void RPS_sampler_update(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Update every sampler element of this sampler with given peer.
void RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Reinitialise all previously initialised sampler elements with the given value.
void RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
Grow or shrink the size of the sampler.
void RPS_sampler_destroy(struct RPS_Sampler *sampler)
Cleans the samplers.
unsigned int RPS_sampler_get_size(struct RPS_Sampler *sampler)
Get the size of the sampler.
struct RPS_SamplerRequestHandle * RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, uint32_t num_peers, RPS_sampler_n_rand_peers_ready_cb cb, void *cls)
Get n random peers out of the sampled peers.
uint32_t RPS_sampler_count_id(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Counts how many Samplers currently hold a given PeerID.
void View_clear(struct View *view)
Clear the view.
int View_contains_peer(const struct View *view, const struct GNUNET_PeerIdentity *peer)
Check whether view contains a peer.
int View_put(struct View *view, const struct GNUNET_PeerIdentity *peer)
Insert peer into the view.
const struct GNUNET_PeerIdentity * View_get_as_array(const struct View *view)
Get the view as an array.
unsigned int View_size(const struct View *view)
Get the size of the view.
void View_destroy(struct View *view)
Destroy view.
void View_change_len(struct View *view, uint32_t len)
Change length of view.
int View_remove_peer(struct View *view, const struct GNUNET_PeerIdentity *peer)
Remove peer from view.
struct View * View_create(uint32_t len)
Create an empty view.
wrapper around the "local view"
Constants for network applications operating on top of the CADET service.
CADET service; establish channels to distant peers.
Core service; the main API for encrypted P2P communications.
static unsigned int num_peers
Number of peers.
API to retrieve the current network size estimate.
API to the peerstore service.
API to create, modify and access statistics.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
#define GNUNET_APPLICATION_PORT_RPS
Transfer of blocks for random peer sampling.
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition cadet_api.c:897
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Indicate readiness to receive the next message on a channel.
Definition cadet_api.c:875
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition cadet_api.c:833
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected channel.
Definition cadet_api.c:1081
struct GNUNET_CADET_Port * GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *port, GNUNET_CADET_ConnectEventHandler connects, void *connects_cls, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Open a port to receive incoming MQ-based channels.
Definition cadet_api.c:966
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition cadet_api.c:777
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port.
Definition cadet_api.c:804
struct GNUNET_CADET_Channel * GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h, void *channel_cls, const struct GNUNET_PeerIdentity *destination, const struct GNUNET_HashCode *port, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Create a new channel towards a remote peer.
Definition cadet_api.c:1030
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
#define GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE
Maximum message size that can be sent on CADET.
struct GNUNET_CORE_Handle * GNUNET_CORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, GNUNET_CORE_StartupCallback init, GNUNET_CORE_ConnectEventHandler connects, GNUNET_CORE_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_CORE_ServiceInfo *service_info)
Connect to the core service.
Definition core_api.c:698
GNUNET_CORE_PeerClass
The peer class gives a hint about the capabilities of a peer.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition core_api.c:744
@ GNUNET_CORE_SERVICE_RPS
Identifier for rps (random peer sampling) service.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
unsigned int * GNUNET_CRYPTO_random_permute(enum GNUNET_CRYPTO_Quality mode, unsigned int n)
Get an array with a random permutation of the numbers 0...n-1.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_get_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst)
Retrieve the identity of the host's peer.
@ GNUNET_CRYPTO_QUALITY_STRONG
High-quality operations are desired.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition disk.c:1308
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition disk.c:557
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition disk.c:745
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition disk.c:1386
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:664
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition disk.c:704
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition disk.c:206
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:41
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL).
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
int GNUNET_CONTAINER_multipeermap_remove_all(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Remove all entries for the given key from the map.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
void * cls
Closure for mv and cb.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition crypto_ecc.c:361
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MIN(a, b)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
const char * GNUNET_error_type_to_string(enum GNUNET_ErrorType kind)
Convert error type to string.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition mq.c:655
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h)
Disconnect from network size estimation service.
Definition nse_api.c:192
#define GNUNET_NSE_log_estimate_to_n(loge)
Convert the logarithmic estimated returned to the 'GNUNET_NSE_Callback' into an absolute estimate in ...
struct GNUNET_NSE_Handle * GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NSE_Callback func, void *func_cls)
Connect to the network size estimation service.
Definition nse_api.c:164
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
void GNUNET_PEERSTORE_monitor_stop(struct GNUNET_PEERSTORE_Monitor *zm)
Stop monitoring.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Monitor * GNUNET_PEERSTORE_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, int iterate_first, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Request watching a given key The monitoring can be filtered to contain only records matching peer and...
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
void GNUNET_PEERSTORE_monitor_next(struct GNUNET_PEERSTORE_Monitor *zm, uint64_t limit)
Calls the monitor processor specified in GNUNET_PEERSTORE_monitor_start for the next record(s).
#define GNUNET_PEERSTORE_HELLO_KEY
Key used for storing HELLO in the peerstore.
#define GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START
RPS client-service message to start a sub sampler.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL
Cancel getting biased stream.
#define ENABLE_MALICIOUS
#define GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE
RPS check liveliness message to check liveliness of other peer.
#define GNUNET_MESSAGE_TYPE_RPS_PP_PUSH
RPS PUSH message to push own ID to another peer.
#define GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP
RPS client-service message to stop a sub sampler.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL
Cancel getting updates of the view.
#define GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY
RPS PULL REPLY message which contains the view of the other peer.
#define GNUNET_MESSAGE_TYPE_RPS_CS_SEED
RPS CS SEED Message for the Client to seed peers into rps.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST
Request biased input stream.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY
Send update of the view.
#define GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST
RPS PULL REQUEST message to request the local view of another peer.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST
Request updates of the view.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY
Send peer of biased stream.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1345
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
#define GNUNET_SERVICE_MAIN(pd, service_name, service_options, init_cb, connect_cb, disconnect_cb, cls,...)
Creates the "main" function for a GNUnet service.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition service.c:2463
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition service.c:2434
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition time.c:626
struct GNUNET_TIME_Relative GNUNET_TIME_relative_saturating_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Saturating multiply relative time by a given factor.
Definition time.c:529
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition time.c:583
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition time.c:548
static unsigned int size
Size of the "table".
Definition peer.c:68
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
int close_all_files()
Close all files that were opened with get_file_handle.
Some utils facilitating the view into the internals for the sampler needed for evaluation.
#define to_file(file_name,...)
This function is used to facilitate writing important information to disk.
example IPC messages between RPS API and GNS service
int(* PeersIterator)(void *cls, const struct GNUNET_PeerIdentity *peer)
Iterator over valid peers.
Definition rps.h:329
void(* PeerOp)(void *cls, const struct GNUNET_PeerIdentity *peer)
Functions of this type can be used to be stored at a peer for later execution.
Definition rps.h:317
Peers_PeerFlags
Different flags indicating the status of another peer.
Definition rps.h:246
@ Peers_TO_DESTROY
We set this bit when we are going to destroy the channel to this peer.
Definition rps.h:266
@ Peers_ONLINE
We set this bit when we know the peer is online.
Definition rps.h:259
@ Peers_PULL_REPLY_PENDING
If we are waiting for a reply from that peer (sent a pull request).
Definition rps.h:250
Context for a channel.
struct PeerContext * peer_ctx
The peer context associated with the channel.
struct GNUNET_CADET_Channel * channel
The channel itself.
struct GNUNET_SCHEDULER_Task * destruction_task
When channel destruction needs to be delayed (because it is called from within the cadet routine of a...
Struct used to store the context of a connected client.
struct ClientContext * prev
struct ClientContext * next
DLL.
struct GNUNET_SERVICE_Client * client
The client handle to send the reply to.
struct Sub * sub
The Sub this context belongs to.
int8_t stream_update
Whether this client wants to receive stream updates.
struct GNUNET_MQ_Handle * mq
The message queue to communicate with the client.
int64_t view_updates_left
How many updates this client expects to receive.
Peer map to store peers with specialised use-cases (push_list, pull_list, view, .....
Opaque handle to a channel.
Definition cadet.h:116
Opaque handle to the service.
Definition cadet_api.c:39
Opaque handle to a port.
Definition cadet_api.c:80
Internal representation of the hash map.
Context for the core service connection.
Definition core_api.c:78
Gnunet service info - identifying compatibility with a range of version of a service communicating ov...
enum GNUNET_CORE_Service service
Identifier of the service on top of CORE.
Handle used to access files (and pipes).
A 512-bit hashcode.
Handle to a message queue.
Definition mq.c:87
Message handler for a specific message type.
Header for all communications.
Handle for talking with the NSE service.
Definition nse_api.c:40
Handle to the PEERSTORE service.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Message from service to client containing peer from biased stream.
Definition rps.h:220
uint64_t num_peers
Number of peers.
Definition rps.h:229
Message from client to service indicating that clients wants to get stream of biased peers.
Definition rps.h:209
Message from service to client containing current update of view.
Definition rps.h:186
uint64_t num_peers
Number of peers in the view.
Definition rps.h:200
Message from client to service indicating that clients wants to get updates of the view.
Definition rps.h:169
Message from client to service with seed of peers.
Definition rps.h:67
Message from client to service telling it to start a new sub.
Definition rps.h:122
Message from client to service telling it to stop a new sub.
Definition rps.h:149
P2P Message to send PeerIDs to other peer.
Definition rps.h:44
uint32_t num_peers
Number of PeerIDs sent.
Definition rps.h:53
Entry in list of pending tasks.
Definition scheduler.c:141
Handle to a client that is connected to a service.
Definition service.c:249
Handle to a service.
Definition service.c:116
Handle for the service.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
The closure to get_rand_peer_iterator.
uint32_t index
The index of the peer to return.
const struct GNUNET_PeerIdentity * peer
Pointer to peer to return.
Struct used to keep track of other peer's status.
uint32_t round_pull_req
This is pobably followed by 'statistical' data (when we first saw it, how did we get its ID,...
uint32_t peer_flags
Flags indicating status of peer.
struct GNUNET_TIME_Absolute last_keepalive
Last time we received a keepalive message.
struct PeerPendingOp * pending_ops
Array of pending operations on this peer.
struct GNUNET_TIME_Absolute last_message_recv
Last time we received something from that peer.
struct PendingMessage * pending_messages_tail
struct PendingMessage * online_check_pending
Handle to the callback given to cadet_ntfy_tmt_rdy()
struct ChannelCtx * send_channel_ctx
Channel open to client.
struct Sub * sub
The Sub this context belongs to.
struct ChannelCtx * recv_channel_ctx
Channel open from client.
unsigned int num_pending_ops
Number of pending operations.
struct GNUNET_MQ_Handle * mq
Message queue open to client.
struct PendingMessage * pending_messages_head
DLL with all messages that are yet to be sent.
struct GNUNET_PeerIdentity peer_id
Identity of the peer.
Pending operation on peer consisting of callback and closure.
void * op_cls
Closure.
PeerOp op
Callback.
Closure to valid_peer_iterator.
PeersIterator iterator
Iterator function.
void * cls
Closure to iterator.
List containing all messages that are yet to be send.
struct PendingMessage * next
DLL next, prev.
const char * type
The message type.
struct PendingMessage * prev
struct GNUNET_MQ_Envelope * ev
The envelope to the corresponding message.
struct PeerContext * peer_ctx
The corresponding context.
Closure to _get_n_rand_peers_ready_cb()
Sampler with its own array of SamplerElements.
Closure used to pass the client and the id to the callback that replies to a client's request.
struct ClientContext * cli_ctx
The client handle to send the reply to.
struct ReplyCls * next
DLL.
struct ReplyCls * prev
uint32_t id
The identifier of the request.
struct RPS_SamplerRequestHandle * req_handle
The handle to the request.
One Sub.
struct RPS_Sampler * sampler
Sampler used for the Brahms protocol itself.
uint32_t push_delta[32]
Histogram of deltas between the expected and actual number of received pushes.
struct GNUNET_HashCode hash
Hash of the shared value that defines Subs.
unsigned int view_size_est_need
This is the estimate used as view size.
struct GNUNET_CONTAINER_MultiPeerMap * valid_peers
Hashmap of valid peers.
uint32_t push_recv[32]
This array accumulates the number of received pushes per round.
struct CustomPeerMap * pull_map
List to store peers received through pulls temporary.
struct GNUNET_CONTAINER_MultiPeerMap * peer_map
Set of all peers to keep track of them.
uint32_t pull_delays[32]
Number of pull replies with this delay measured in rounds.
unsigned int sampler_size_est_need
The size of sampler we need to be able to satisfy the Brahms protocol's need of random peers.
uint32_t num_rounds
Counts the executed rounds.
struct GNUNET_SCHEDULER_Task * do_round_task
Identifier for the main task that runs periodically.
unsigned int view_size_est_min
This is the minimum estimate used as view size.
char * filename_valid_peers
Filename of the file that stores the valid peers persistently.
struct CustomPeerMap * push_map
List to store peers received through pushes temporary.
unsigned int sampler_size_est_min
This is the minimum estimate used as sampler size.
struct GNUNET_CONTAINER_MultiPeerMap * observed_unique_peers
Multipeermap (ab-) used to count unique peer_ids.
uint32_t num_observed_peers
Count the observed peers.
struct GNUNET_CADET_Port * cadet_port
Port to communicate to other peers.
struct View * view
The view.
struct GNUNET_TIME_Relative round_interval
Time interval the do_round task runs in.