GNUnet 0.21.2
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
152{
156 struct Sub *sub;
157
162
167
172
177
184
188 unsigned int num_pending_ops;
189
194
198 uint32_t peer_flags;
199
204
209
215
222};
223
228{
233
237 void *cls;
238};
239
244{
249
254
261};
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 valid_peers));
816 (void) GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
818 iterator_cls);
819 ret = iterator_cls->peer;
820 GNUNET_free (iterator_cls);
821 return ret;
822}
823
824
836static int
838 struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
839{
840 const struct GNUNET_PeerIdentity *rand_peer;
841 int ret;
842
843 ret = GNUNET_YES;
844 /* Remove random peers until there is space for a new one */
845 while (num_valid_peers_max <=
847 {
848 rand_peer = get_random_peer_from_peermap (valid_peers);
849 GNUNET_CONTAINER_multipeermap_remove_all (valid_peers, rand_peer);
850 ret = GNUNET_NO;
851 }
852 (void) GNUNET_CONTAINER_multipeermap_put (valid_peers, peer, NULL,
854 if (valid_peers == msub->valid_peers)
855 {
857 "# valid peers",
859 GNUNET_NO);
860 }
861 return ret;
862}
863
864
865static void
866remove_pending_message (struct PendingMessage *pending_msg, int cancel);
867
876static void
877set_peer_online (struct PeerContext *peer_ctx)
878{
879 struct GNUNET_PeerIdentity *peer;
880 unsigned int i;
881
882 peer = &peer_ctx->peer_id;
884 "Peer %s is online and valid, calling %i pending operations on it\n",
885 GNUNET_i2s (peer),
886 peer_ctx->num_pending_ops);
887
888 if (NULL != peer_ctx->online_check_pending)
889 {
891 "Removing pending online check for peer %s\n",
892 GNUNET_i2s (&peer_ctx->peer_id));
893 // TODO wait until cadet sets mq->cancel_impl
894 // GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev);
896 peer_ctx->online_check_pending = NULL;
897 }
898
899 SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
900
901 /* Call pending operations */
902 for (i = 0; i < peer_ctx->num_pending_ops; i++)
903 {
904 peer_ctx->pending_ops[i].op (peer_ctx->pending_ops[i].op_cls, peer);
905 }
906 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
907}
908
909
910static void
912 const struct GNUNET_CADET_Channel *channel);
913
914/* Declaration of handlers */
915static void
916handle_peer_check (void *cls,
917 const struct GNUNET_MessageHeader *msg);
918
919static void
920handle_peer_push (void *cls,
921 const struct GNUNET_MessageHeader *msg);
922
923static void
924handle_peer_pull_request (void *cls,
925 const struct GNUNET_MessageHeader *msg);
926
927static int
928check_peer_pull_reply (void *cls,
930
931static void
932handle_peer_pull_reply (void *cls,
934
935/* End declaration of handlers */
936
944static struct ChannelCtx *
946{
947 struct ChannelCtx *channel_ctx;
948
949 channel_ctx = GNUNET_new (struct ChannelCtx);
950 channel_ctx->peer_ctx = peer_ctx;
951 return channel_ctx;
952}
953
954
960static void
961remove_channel_ctx (struct ChannelCtx *channel_ctx)
962{
963 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
964
965 if (NULL != channel_ctx->destruction_task)
966 {
968 channel_ctx->destruction_task = NULL;
969 }
970
971 if (NULL == peer_ctx)
972 return;
973 if (channel_ctx == peer_ctx->send_channel_ctx)
974 {
975 peer_ctx->send_channel_ctx = NULL;
976 peer_ctx->mq = NULL;
977 }
978 else if (channel_ctx == peer_ctx->recv_channel_ctx)
979 {
980 peer_ctx->recv_channel_ctx = NULL;
981 }
982 GNUNET_free (channel_ctx);
983}
984
985
993get_channel (struct PeerContext *peer_ctx)
994{
995 /* There exists a copy-paste-clone in run() */
996 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
997 GNUNET_MQ_hd_fixed_size (peer_check,
1000 NULL),
1001 GNUNET_MQ_hd_fixed_size (peer_push,
1003 struct GNUNET_MessageHeader,
1004 NULL),
1005 GNUNET_MQ_hd_fixed_size (peer_pull_request,
1007 struct GNUNET_MessageHeader,
1008 NULL),
1009 GNUNET_MQ_hd_var_size (peer_pull_reply,
1012 NULL),
1014 };
1015
1016
1017 if (NULL == peer_ctx->send_channel_ctx)
1018 {
1020 "Trying to establish channel to peer %s\n",
1021 GNUNET_i2s (&peer_ctx->peer_id));
1022 peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx);
1023 peer_ctx->send_channel_ctx->channel =
1025 peer_ctx->send_channel_ctx, /* context */
1026 &peer_ctx->peer_id,
1027 &peer_ctx->sub->hash,
1028 NULL, /* WindowSize handler */
1029 &cleanup_destroyed_channel, /* Disconnect handler */
1030 cadet_handlers);
1031 }
1032 GNUNET_assert (NULL != peer_ctx->send_channel_ctx);
1033 GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel);
1034 return peer_ctx->send_channel_ctx->channel;
1035}
1036
1037
1047static struct GNUNET_MQ_Handle *
1048get_mq (struct PeerContext *peer_ctx)
1049{
1050 if (NULL == peer_ctx->mq)
1051 {
1052 peer_ctx->mq = GNUNET_CADET_get_mq (get_channel (peer_ctx));
1053 }
1054 return peer_ctx->mq;
1055}
1056
1057
1066static struct PendingMessage *
1068 struct GNUNET_MQ_Envelope *ev,
1069 const char *type)
1070{
1071 struct PendingMessage *pending_msg;
1072
1073 pending_msg = GNUNET_new (struct PendingMessage);
1074 pending_msg->ev = ev;
1075 pending_msg->peer_ctx = peer_ctx;
1076 pending_msg->type = type;
1079 pending_msg);
1080 return pending_msg;
1081}
1082
1083
1090static void
1091remove_pending_message (struct PendingMessage *pending_msg, int cancel)
1092{
1093 struct PeerContext *peer_ctx;
1094
1095 (void) cancel;
1096
1097 peer_ctx = pending_msg->peer_ctx;
1098 GNUNET_assert (NULL != peer_ctx);
1100 peer_ctx->pending_messages_tail,
1101 pending_msg);
1102 // TODO wait for the cadet implementation of message cancellation
1103 // if (GNUNET_YES == cancel)
1104 // {
1105 // GNUNET_MQ_send_cancel (pending_msg->ev);
1106 // }
1107 GNUNET_free (pending_msg);
1108}
1109
1110
1117static void
1119{
1120 struct PeerContext *peer_ctx = cls;
1121
1122 if (NULL != peer_ctx->online_check_pending)
1123 {
1125 "Online check for peer %s was successful\n",
1126 GNUNET_i2s (&peer_ctx->peer_id));
1128 peer_ctx->online_check_pending = NULL;
1129 set_peer_online (peer_ctx);
1130 (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers);
1131 }
1132}
1133
1134
1140static void
1142{
1144 "Get informed about peer %s getting online\n",
1145 GNUNET_i2s (&peer_ctx->peer_id));
1146
1147 struct GNUNET_MQ_Handle *mq;
1148 struct GNUNET_MQ_Envelope *ev;
1149
1151 peer_ctx->online_check_pending =
1152 insert_pending_message (peer_ctx, ev, "Check online");
1153 mq = get_mq (peer_ctx);
1156 peer_ctx);
1157 GNUNET_MQ_send (mq, ev);
1158 if (peer_ctx->sub == msub)
1159 {
1161 "# pending online checks",
1162 1,
1163 GNUNET_NO);
1164 }
1165}
1166
1167
1180static int
1182 const PeerOp peer_op)
1183{
1184 unsigned int i;
1185
1186 for (i = 0; i < peer_ctx->num_pending_ops; i++)
1187 if (peer_op == peer_ctx->pending_ops[i].op)
1188 return GNUNET_YES;
1189 return GNUNET_NO;
1190}
1191
1192
1198static void
1199destroy_channel (struct ChannelCtx *channel_ctx)
1200{
1201 struct GNUNET_CADET_Channel *channel;
1202
1203 if (NULL != channel_ctx->destruction_task)
1204 {
1206 channel_ctx->destruction_task = NULL;
1207 }
1208 GNUNET_assert (channel_ctx->channel != NULL);
1209 channel = channel_ctx->channel;
1210 channel_ctx->channel = NULL;
1212 remove_channel_ctx (channel_ctx);
1213}
1214
1215
1223static void
1225{
1226 struct ChannelCtx *channel_ctx = cls;
1227
1228 channel_ctx->destruction_task = NULL;
1229 destroy_channel (channel_ctx);
1230}
1231
1232
1243static void
1245{
1246 GNUNET_assert (NULL ==
1247 channel_ctx->destruction_task);
1248 GNUNET_assert (NULL !=
1249 channel_ctx->channel);
1250 channel_ctx->destruction_task =
1252 channel_ctx);
1253}
1254
1255
1269static int
1271{
1272 GNUNET_assert (NULL != peer_ctx);
1273 GNUNET_assert (NULL != peer_ctx->sub->peer_map);
1274 if (GNUNET_NO ==
1276 &peer_ctx->peer_id))
1277 {
1278 return GNUNET_NO;
1279 }
1282 "Going to remove peer %s\n",
1285
1286 /* Clear list of pending operations */
1287 // TODO this probably leaks memory
1288 // ('only' the cls to the function. Not sure what to do with it)
1291 0);
1292 /* Remove all pending messages */
1293 while (NULL != peer_ctx->pending_messages_head)
1294 {
1296 "Removing unsent %s\n",
1298 /* Cancel pending message, too */
1299 if ((NULL != peer_ctx->online_check_pending) &&
1300 (0 == memcmp (peer_ctx->pending_messages_head,
1302 sizeof(struct PendingMessage))))
1303 {
1305 if (peer_ctx->sub == msub)
1306 {
1308 "# pending online checks",
1309 -1,
1310 GNUNET_NO);
1311 }
1312 }
1314 GNUNET_YES);
1315 }
1316
1317 /* If we are still waiting for notification whether this peer is online
1318 * cancel the according task */
1319 if (NULL != peer_ctx->online_check_pending)
1320 {
1322 "Removing pending online check for peer %s\n",
1324 // TODO wait until cadet sets mq->cancel_impl
1325 // GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev);
1327 GNUNET_YES);
1329 }
1330
1331 if (NULL != peer_ctx->send_channel_ctx)
1332 {
1333 /* This is possibly called from within channel destruction */
1336 peer_ctx->send_channel_ctx = NULL;
1337 peer_ctx->mq = NULL;
1338 }
1339 if (NULL != peer_ctx->recv_channel_ctx)
1340 {
1341 /* This is possibly called from within channel destruction */
1344 peer_ctx->recv_channel_ctx = NULL;
1345 }
1346
1347 if (GNUNET_YES !=
1349 &peer_ctx->peer_id))
1350 {
1352 "removing peer from peer_ctx->sub->peer_map failed\n");
1353 }
1354 if (peer_ctx->sub == msub)
1355 {
1357 "# known peers",
1360 GNUNET_NO);
1361 }
1363 return GNUNET_YES;
1364}
1365
1366
1376static int
1378 const struct GNUNET_PeerIdentity *key,
1379 void *value)
1380{
1381 struct Sub *sub = cls;
1382
1383 (void) value;
1384
1386 return GNUNET_YES;
1387}
1388
1389
1397static void
1399{
1400 struct PendingMessage *pending_msg = (struct PendingMessage *) cls;
1401
1403 "%s was sent.\n",
1404 pending_msg->type);
1405 if (pending_msg->peer_ctx->sub == msub)
1406 {
1407 if (0 == strncmp ("PULL REPLY", pending_msg->type, 10))
1408 GNUNET_STATISTICS_update (stats, "# pull replies sent", 1, GNUNET_NO);
1409 if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12))
1410 GNUNET_STATISTICS_update (stats, "# pull requests sent", 1, GNUNET_NO);
1411 if (0 == strncmp ("PUSH", pending_msg->type, 4))
1412 GNUNET_STATISTICS_update (stats, "# pushes sent", 1, GNUNET_NO);
1413 if ((0 == strncmp ("PULL REQUEST", pending_msg->type, 12)) &&
1414 (NULL != map_single_hop) &&
1416 &pending_msg->
1417 peer_ctx->peer_id)) )
1419 "# pull requests sent (multi-hop peer)",
1420 1,
1421 GNUNET_NO);
1422 }
1423 /* Do not cancel message */
1424 remove_pending_message (pending_msg, GNUNET_NO);
1425}
1426
1427
1442static int
1444 const struct GNUNET_PeerIdentity *peer,
1445 void *value)
1446{
1447 const struct GNUNET_DISK_FileHandle *fh = cls;
1448 char peer_string[128];
1449 int size;
1450 ssize_t ret;
1451
1452 (void) value;
1453
1454 if (NULL == peer)
1455 {
1456 return GNUNET_YES;
1457 }
1458 size = GNUNET_snprintf (peer_string,
1459 sizeof(peer_string),
1460 "%s\n",
1461 GNUNET_i2s_full (peer));
1462 GNUNET_assert (53 == size);
1464 peer_string,
1465 size);
1466 GNUNET_assert (size == ret);
1467 return GNUNET_YES;
1468}
1469
1470
1476static void
1477store_valid_peers (const struct Sub *sub)
1478{
1479 struct GNUNET_DISK_FileHandle *fh;
1480 uint32_t number_written_peers;
1481 int ret;
1482
1483 if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7))
1484 {
1485 return;
1486 }
1487
1489 if (GNUNET_SYSERR == ret)
1490 {
1492 "Not able to create directory for file `%s'\n",
1494 GNUNET_break (0);
1495 }
1496 else if (GNUNET_NO == ret)
1497 {
1499 "Directory for file `%s' exists but is not writable for us\n",
1501 GNUNET_break (0);
1502 }
1508 if (NULL == fh)
1509 {
1511 "Not able to write valid peers to file `%s'\n",
1513 return;
1514 }
1516 "Writing %u valid peers to disk\n",
1518 number_written_peers =
1521 fh);
1523 GNUNET_assert (number_written_peers ==
1525}
1526
1527
1537static const struct GNUNET_PeerIdentity *
1538s2i_full (const char *string_repr)
1539{
1540 struct GNUNET_PeerIdentity *peer;
1541 size_t len;
1542 int ret;
1543
1544 peer = GNUNET_new (struct GNUNET_PeerIdentity);
1545 len = strlen (string_repr);
1546 if (52 > len)
1547 {
1549 "Not able to convert string representation of PeerID to PeerID\n"
1550 "String representation: %s (len %lu) - too short\n",
1551 string_repr,
1552 len);
1553 GNUNET_break (0);
1554 }
1555 else if (52 < len)
1556 {
1557 len = 52;
1558 }
1560 len,
1561 &peer->public_key);
1562 if (GNUNET_OK != ret)
1563 {
1565 "Not able to convert string representation of PeerID to PeerID\n"
1566 "String representation: %s\n",
1567 string_repr);
1568 GNUNET_break (0);
1569 }
1570 return peer;
1571}
1572
1573
1579static void
1580restore_valid_peers (const struct Sub *sub)
1581{
1582 off_t file_size;
1583 uint32_t num_peers;
1584 struct GNUNET_DISK_FileHandle *fh;
1585 char *buf;
1586 ssize_t size_read;
1587 char *iter_buf;
1588 char *str_repr;
1589 const struct GNUNET_PeerIdentity *peer;
1590
1591 if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7))
1592 {
1593 return;
1594 }
1595
1597 {
1598 return;
1599 }
1603 GNUNET_assert (NULL != fh);
1605 num_peers = file_size / 53;
1606 buf = GNUNET_malloc (file_size);
1607 size_read = GNUNET_DISK_file_read (fh, buf, file_size);
1608 GNUNET_assert (size_read == file_size);
1610 "Restoring %" PRIu32 " peers from file `%s'\n",
1611 num_peers,
1613 for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53)
1614 {
1615 str_repr = GNUNET_strndup (iter_buf, 53);
1616 peer = s2i_full (str_repr);
1617 GNUNET_free (str_repr);
1618 add_valid_peer (peer, sub->valid_peers);
1620 "Restored valid peer %s from disk\n",
1621 GNUNET_i2s_full (peer));
1622 }
1623 iter_buf = NULL;
1624 GNUNET_free (buf);
1626 "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n",
1627 num_peers,
1630 {
1632 "Number of restored peers does not match file size. Have probably duplicates.\n");
1633 }
1636 "Restored %u valid peers from disk\n",
1638}
1639
1640
1646static void
1648{
1649 if (GNUNET_SYSERR ==
1652 sub))
1653 {
1655 "Iteration destroying peers was aborted.\n");
1656 }
1658 sub->peer_map = NULL;
1659 store_valid_peers (sub);
1661 sub->filename_valid_peers = NULL;
1663 sub->valid_peers = NULL;
1664}
1665
1666
1677static int
1679 const struct GNUNET_PeerIdentity *peer,
1680 void *value)
1681{
1682 struct PeersIteratorCls *it_cls = cls;
1683
1684 (void) value;
1685
1686 return it_cls->iterator (it_cls->cls, peer);
1687}
1688
1689
1699static int
1702 void *it_cls)
1703{
1704 struct PeersIteratorCls *cls;
1705 int ret;
1706
1707 cls = GNUNET_new (struct PeersIteratorCls);
1708 cls->iterator = iterator;
1709 cls->cls = it_cls;
1712 cls);
1713 GNUNET_free (cls);
1714 return ret;
1715}
1716
1717
1730static int
1731insert_peer (struct Sub *sub,
1732 const struct GNUNET_PeerIdentity *peer)
1733{
1734 if (GNUNET_YES == check_peer_known (sub->peer_map, peer))
1735 {
1736 return GNUNET_NO; /* We already know this peer - nothing to do */
1737 }
1738 (void) create_peer_ctx (sub, peer);
1739 return GNUNET_YES;
1740}
1741
1742
1754static int
1756 const struct GNUNET_PeerIdentity *peer,
1757 enum Peers_PeerFlags flags)
1758{
1759 struct PeerContext *peer_ctx;
1760
1761 if (GNUNET_NO == check_peer_known (peer_map, peer))
1762 {
1763 return GNUNET_SYSERR;
1764 }
1765 peer_ctx = get_peer_ctx (peer_map, peer);
1766 return check_peer_flag_set (peer_ctx, flags);
1767}
1768
1769
1780static int
1782 const struct GNUNET_PeerIdentity *peer)
1783{
1784 struct PeerContext *peer_ctx;
1785
1786 (void) insert_peer (sub, peer); // TODO even needed?
1787 peer_ctx = get_peer_ctx (sub->peer_map, peer);
1788 if ((GNUNET_NO == check_peer_flag (sub->peer_map, peer, Peers_ONLINE)) &&
1789 (NULL == peer_ctx->online_check_pending))
1790 {
1791 check_peer_online (peer_ctx);
1792 return GNUNET_YES;
1793 }
1794 return GNUNET_NO;
1795}
1796
1797
1811static int
1812check_removable (const struct PeerContext *peer_ctx)
1813{
1815 peer_ctx->sub->peer_map,
1816 &peer_ctx->peer_id))
1817 {
1818 return GNUNET_SYSERR;
1819 }
1820
1821 if ((NULL != peer_ctx->recv_channel_ctx) ||
1822 (NULL != peer_ctx->pending_messages_head) ||
1824 {
1825 return GNUNET_NO;
1826 }
1827 return GNUNET_YES;
1828}
1829
1830
1842static int
1844 const struct GNUNET_PeerIdentity *peer)
1845{
1846 return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer);
1847}
1848
1849
1857static void
1859{
1861 &peer_ctx->peer_id));
1862 (void) get_channel (peer_ctx);
1863}
1864
1865
1875static int
1877{
1878 if (NULL != peer_ctx->recv_channel_ctx)
1879 {
1880 return GNUNET_YES;
1881 }
1882 return GNUNET_NO;
1883}
1884
1885
1896static void *
1898 struct GNUNET_CADET_Channel *channel,
1899 const struct GNUNET_PeerIdentity *initiator)
1900{
1901 struct PeerContext *peer_ctx;
1902 struct ChannelCtx *channel_ctx;
1903 struct Sub *sub = cls;
1904
1906 "New channel was established to us (Peer %s).\n",
1907 GNUNET_i2s (initiator));
1908 GNUNET_assert (NULL != channel); /* according to cadet API */
1909 /* Make sure we 'know' about this peer */
1910 peer_ctx = create_or_get_peer_ctx (sub, initiator);
1911 set_peer_online (peer_ctx);
1912 (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers);
1913 channel_ctx = add_channel_ctx (peer_ctx);
1914 channel_ctx->channel = channel;
1915 /* We only accept one incoming channel per peer */
1917 initiator)))
1918 {
1920 "Already got one receive channel. Destroying old one.\n");
1921 GNUNET_break_op (0);
1923 peer_ctx->recv_channel_ctx = channel_ctx;
1924 /* return the channel context */
1925 return channel_ctx;
1926 }
1927 peer_ctx->recv_channel_ctx = channel_ctx;
1928 return channel_ctx;
1929}
1930
1931
1940static int
1942{
1943 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
1944 &peer_ctx->peer_id))
1945 { /* If no such peer exists, there is no channel */
1946 return GNUNET_NO;
1947 }
1948 if (NULL == peer_ctx->send_channel_ctx)
1949 {
1950 return GNUNET_NO;
1951 }
1952 return GNUNET_YES;
1953}
1954
1955
1964static int
1966{
1967 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
1968 &peer_ctx->peer_id))
1969 {
1970 return GNUNET_NO;
1971 }
1972 if (NULL != peer_ctx->send_channel_ctx)
1973 {
1975 (void) check_connected (peer_ctx);
1976 return GNUNET_YES;
1977 }
1978 return GNUNET_NO;
1979}
1980
1981
1992static void
1993send_message (struct PeerContext *peer_ctx,
1994 struct GNUNET_MQ_Envelope *ev,
1995 const char *type)
1996{
1997 struct PendingMessage *pending_msg;
1998 struct GNUNET_MQ_Handle *mq;
1999
2001 "Sending message to %s of type %s\n",
2002 GNUNET_i2s (&peer_ctx->peer_id),
2003 type);
2004 pending_msg = insert_pending_message (peer_ctx, ev, type);
2005 mq = get_mq (peer_ctx);
2008 pending_msg);
2009 GNUNET_MQ_send (mq, ev);
2010}
2011
2012
2025static int
2027 const PeerOp peer_op,
2028 void *cls)
2029{
2030 struct PeerPendingOp pending_op;
2031
2033 &peer_ctx->peer_id));
2034
2035 // TODO if ONLINE execute immediately
2036
2037 if (GNUNET_NO == check_operation_scheduled (peer_ctx, peer_op))
2038 {
2039 pending_op.op = peer_op;
2040 pending_op.op_cls = cls;
2042 peer_ctx->num_pending_ops,
2043 pending_op);
2044 return GNUNET_YES;
2045 }
2046 return GNUNET_NO;
2047}
2048
2049
2050/***********************************************************************
2051* /Old gnunet-service-rps_peers.c
2052***********************************************************************/
2053
2054
2055/***********************************************************************
2056* Housekeeping with clients
2057***********************************************************************/
2058
2064{
2070
2074 uint32_t id;
2075
2080
2085};
2086
2087
2092{
2098
2103
2108
2114
2119
2123 struct Sub *sub;
2124};
2125
2131
2132/***********************************************************************
2133* /Housekeeping with clients
2134***********************************************************************/
2135
2136
2137/***********************************************************************
2138* Util functions
2139***********************************************************************/
2140
2141
2145static void
2147 unsigned int len)
2148{
2149 unsigned int i;
2150
2152 "Printing peer list of length %u at %p:\n",
2153 len,
2154 list);
2155 for (i = 0; i < len; i++)
2156 {
2158 "%u. peer: %s\n",
2159 i, GNUNET_i2s (&list[i]));
2160 }
2161}
2162
2163
2167static void
2169 unsigned int *list_size,
2170 const struct GNUNET_PeerIdentity *peer)
2171{
2172 unsigned int i;
2173 struct GNUNET_PeerIdentity *tmp;
2174
2175 tmp = *peer_list;
2176
2178 "Removing peer %s from list at %p\n",
2179 GNUNET_i2s (peer),
2180 tmp);
2181
2182 for (i = 0; i < *list_size; i++)
2183 {
2184 if (0 == GNUNET_memcmp (&tmp[i], peer))
2185 {
2186 if (i < *list_size - 1)
2187 { /* Not at the last entry -- shift peers left */
2188 memmove (&tmp[i], &tmp[i + 1],
2189 ((*list_size) - i - 1) * sizeof(struct GNUNET_PeerIdentity));
2190 }
2191 /* Remove last entry (should be now useless PeerID) */
2192 GNUNET_array_grow (tmp, *list_size, (*list_size) - 1);
2193 }
2194 }
2195 *peer_list = tmp;
2196}
2197
2198
2208static void
2209insert_in_view_op (void *cls,
2210 const struct GNUNET_PeerIdentity *peer);
2211
2223static int
2224insert_in_view (struct Sub *sub,
2225 const struct GNUNET_PeerIdentity *peer)
2226{
2227 struct PeerContext *peer_ctx;
2228 int online;
2229 int ret;
2230
2231 online = check_peer_flag (sub->peer_map, peer, Peers_ONLINE);
2232 peer_ctx = get_peer_ctx (sub->peer_map, peer); // TODO indirection needed?
2233 if ((GNUNET_NO == online) ||
2234 (GNUNET_SYSERR == online)) /* peer is not even known */
2235 {
2236 (void) issue_peer_online_check (sub, peer);
2237 (void) schedule_operation (peer_ctx, insert_in_view_op, sub);
2238 return GNUNET_NO;
2239 }
2240 /* Open channel towards peer to keep connection open */
2241 indicate_sending_intention (peer_ctx);
2242 ret = View_put (sub->view, peer);
2243 if (peer_ctx->sub == msub)
2244 {
2246 "view size",
2247 View_size (peer_ctx->sub->view),
2248 GNUNET_NO);
2249 }
2250 return ret;
2251}
2252
2253
2261static void
2262send_view (const struct ClientContext *cli_ctx,
2263 const struct GNUNET_PeerIdentity *view_array,
2264 uint64_t view_size)
2265{
2266 struct GNUNET_MQ_Envelope *ev;
2267 struct GNUNET_RPS_CS_DEBUG_ViewReply *out_msg;
2268 struct Sub *sub;
2269
2270 if (NULL == view_array)
2271 {
2272 if (NULL == cli_ctx->sub)
2273 sub = msub;
2274 else
2275 sub = cli_ctx->sub;
2276 view_size = View_size (sub->view);
2277 view_array = View_get_as_array (sub->view);
2278 }
2279
2280 ev = GNUNET_MQ_msg_extra (out_msg,
2281 view_size * sizeof(struct GNUNET_PeerIdentity),
2283 out_msg->num_peers = htonl (view_size);
2284
2285 GNUNET_memcpy (&out_msg[1],
2286 view_array,
2287 view_size * sizeof(struct GNUNET_PeerIdentity));
2288 GNUNET_MQ_send (cli_ctx->mq, ev);
2289}
2290
2291
2301static void
2302send_stream_peers (const struct ClientContext *cli_ctx,
2303 uint64_t num_peers,
2304 const struct GNUNET_PeerIdentity *peers)
2305{
2306 struct GNUNET_MQ_Envelope *ev;
2307 struct GNUNET_RPS_CS_DEBUG_StreamReply *out_msg;
2308
2309 GNUNET_assert (NULL != peers);
2310
2311 ev = GNUNET_MQ_msg_extra (out_msg,
2312 num_peers * sizeof(struct GNUNET_PeerIdentity),
2314 out_msg->num_peers = htonl (num_peers);
2315
2316 GNUNET_memcpy (&out_msg[1],
2317 peers,
2318 num_peers * sizeof(struct GNUNET_PeerIdentity));
2319 GNUNET_MQ_send (cli_ctx->mq, ev);
2320}
2321
2322
2328static void
2330{
2331 struct ClientContext *cli_ctx_iter;
2332 uint64_t num_peers;
2333 const struct GNUNET_PeerIdentity *view_array;
2334
2335 num_peers = View_size (sub->view);
2336 view_array = View_get_as_array (sub->view);
2337 /* check size of view is small enough */
2339 {
2341 "View is too big to send\n");
2342 return;
2343 }
2344
2345 for (cli_ctx_iter = cli_ctx_head;
2346 NULL != cli_ctx_iter;
2347 cli_ctx_iter = cli_ctx_iter->next)
2348 {
2349 if (1 < cli_ctx_iter->view_updates_left)
2350 {
2351 /* Client wants to receive limited amount of updates */
2352 cli_ctx_iter->view_updates_left -= 1;
2353 }
2354 else if (1 == cli_ctx_iter->view_updates_left)
2355 {
2356 /* Last update of view for client */
2357 cli_ctx_iter->view_updates_left = -1;
2358 }
2359 else if (0 > cli_ctx_iter->view_updates_left)
2360 {
2361 /* Client is not interested in updates */
2362 continue;
2363 }
2364 /* else _updates_left == 0 - infinite amount of updates */
2365
2366 /* send view */
2367 send_view (cli_ctx_iter, view_array, num_peers);
2368 }
2369}
2370
2371
2378static void
2380 uint64_t num_peers,
2381 const struct GNUNET_PeerIdentity *peers)
2382// TODO enum StreamPeerSource)
2383{
2384 struct ClientContext *cli_ctx_iter;
2385
2387 "Got peer (%s) from biased stream - update all clients\n",
2388 GNUNET_i2s (peers));
2389
2390 for (cli_ctx_iter = cli_ctx_head;
2391 NULL != cli_ctx_iter;
2392 cli_ctx_iter = cli_ctx_iter->next)
2393 {
2394 if ((GNUNET_YES == cli_ctx_iter->stream_update) &&
2395 ((sub == cli_ctx_iter->sub) || (sub == msub) ))
2396 {
2397 send_stream_peers (cli_ctx_iter, num_peers, peers);
2398 }
2399 }
2400}
2401
2402
2410static void
2412 uint32_t num_peers,
2413 void *cls)
2414{
2415 unsigned int i;
2416 struct Sub *sub = cls;
2417
2418 for (i = 0; i < num_peers; i++)
2419 {
2420 int inserted;
2421 if (GNUNET_YES != check_peer_known (sub->peer_map, &ids[i]))
2422 {
2424 "Peer in history update not known!\n");
2425 continue;
2426 }
2427 inserted = insert_in_view (sub, &ids[i]);
2428 if (GNUNET_OK == inserted)
2429 {
2430 clients_notify_stream_peer (sub, 1, &ids[i]);
2431 }
2432#ifdef TO_FILE_FULL
2433 to_file (sub->file_name_view_log,
2434 "+%s\t(history)",
2435 GNUNET_i2s_full (ids));
2436#endif /* TO_FILE_FULL */
2437 }
2439}
2440
2441
2451static void
2452resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size)
2453{
2454 unsigned int sampler_size;
2455
2456 // TODO statistics
2457 // TODO respect the min, max
2458 sampler_size = RPS_sampler_get_size (sampler);
2459 if (sampler_size > new_size * 4)
2460 { /* Shrinking */
2461 RPS_sampler_resize (sampler, sampler_size / 2);
2462 }
2463 else if (sampler_size < new_size)
2464 { /* Growing */
2465 RPS_sampler_resize (sampler, sampler_size * 2);
2466 }
2467 LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size);
2468}
2469
2470
2471#if ENABLE_MALICIOUS
2479static void
2480add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array,
2481 unsigned int num_peers,
2483{
2484 unsigned int i;
2485
2486 if (NULL == peer_map)
2487 {
2489 "Trying to add peers to non-existing peermap.\n");
2490 return;
2491 }
2492
2493 for (i = 0; i < num_peers; i++)
2494 {
2496 &peer_array[i],
2497 NULL,
2499 if (msub->peer_map == peer_map)
2500 {
2502 "# known peers",
2504 GNUNET_NO);
2505 }
2506 }
2507}
2508
2509
2510#endif /* ENABLE_MALICIOUS */
2511
2512
2520static void
2522 const struct GNUNET_PeerIdentity *peer_ids,
2523 unsigned int num_peer_ids)
2524{
2525 uint32_t send_size;
2526 struct GNUNET_MQ_Envelope *ev;
2527 struct GNUNET_RPS_P2P_PullReplyMessage *out_msg;
2528
2529 /* Compute actual size */
2530 send_size = sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)
2531 + num_peer_ids * sizeof(struct GNUNET_PeerIdentity);
2532
2534 /* Compute number of peers to send
2535 * If too long, simply truncate */
2536 // TODO select random ones via permutation
2537 // or even better: do good protocol design
2538 send_size =
2540 - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage))
2541 / sizeof(struct GNUNET_PeerIdentity);
2542 else
2543 send_size = num_peer_ids;
2544
2546 "Going to send PULL REPLY with %u peers to %s\n",
2547 send_size, GNUNET_i2s (&peer_ctx->peer_id));
2548
2549 ev = GNUNET_MQ_msg_extra (out_msg,
2550 send_size * sizeof(struct GNUNET_PeerIdentity),
2552 out_msg->num_peers = htonl (send_size);
2553 GNUNET_memcpy (&out_msg[1], peer_ids,
2554 send_size * sizeof(struct GNUNET_PeerIdentity));
2555
2556 send_message (peer_ctx, ev, "PULL REPLY");
2557 if (peer_ctx->sub == msub)
2558 {
2559 GNUNET_STATISTICS_update (stats, "# pull reply send issued", 1, GNUNET_NO);
2560 }
2561 // TODO check with send intention: as send_channel is used/opened we indicate
2562 // a sending intention without intending it.
2563 // -> clean peer afterwards?
2564 // -> use recv_channel?
2565}
2566
2567
2576static void
2578 const struct GNUNET_PeerIdentity *peer)
2579{
2580 struct Sub *sub = cls;
2581
2582 CustomPeerMap_put (sub->pull_map, peer);
2583}
2584
2585
2595static void
2597 const struct GNUNET_PeerIdentity *peer)
2598{
2599 struct Sub *sub = cls;
2600 int inserted;
2601
2602 inserted = insert_in_view (sub, peer);
2603 if (GNUNET_OK == inserted)
2604 {
2605 clients_notify_stream_peer (sub, 1, peer);
2606 }
2607}
2608
2609
2617static void
2619 const struct GNUNET_PeerIdentity *peer)
2620{
2621 struct Sub *sub = cls;
2622
2624 "Updating samplers with peer %s from insert_in_sampler()\n",
2625 GNUNET_i2s (peer));
2626 RPS_sampler_update (sub->sampler, peer);
2627 if (0 < RPS_sampler_count_id (sub->sampler, peer))
2628 {
2629 /* Make sure we 'know' about this peer */
2630 (void) issue_peer_online_check (sub, peer);
2631 /* Establish a channel towards that peer to indicate we are going to send
2632 * messages to it */
2633 // indicate_sending_intention (peer);
2634 }
2635 if (sub == msub)
2636 {
2638 "# observed peers in gossip",
2639 1,
2640 GNUNET_NO);
2641 }
2642#ifdef TO_FILE
2643 sub->num_observed_peers++;
2646 peer,
2647 NULL,
2649 uint32_t num_observed_unique_peers =
2652 "# unique peers in gossip",
2653 num_observed_unique_peers,
2654 GNUNET_NO);
2655#ifdef TO_FILE_FULL
2656 to_file (sub->file_name_observed_log,
2657 "%" PRIu32 " %" PRIu32 " %f\n",
2658 sub->num_observed_peers,
2659 num_observed_unique_peers,
2660 1.0 * num_observed_unique_peers / sub->num_observed_peers)
2661#endif /* TO_FILE_FULL */
2662#endif /* TO_FILE */
2663}
2664
2665
2676static void
2677got_peer (struct Sub *sub,
2678 const struct GNUNET_PeerIdentity *peer)
2679{
2680 /* If we did not know this peer already, insert it into sampler and view */
2681 if (GNUNET_YES == issue_peer_online_check (sub, peer))
2682 {
2684 &insert_in_sampler, sub);
2686 &insert_in_view_op, sub);
2687 }
2688 if (sub == msub)
2689 {
2691 "# learnd peers",
2692 1,
2693 GNUNET_NO);
2694 }
2695}
2696
2697
2705static int
2707{
2708 /* struct GNUNET_CADET_Channel *channel; */
2709 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
2710 &peer_ctx->peer_id))
2711 {
2712 return GNUNET_NO;
2713 }
2714 if (GNUNET_YES == check_sending_channel_exists (peer_ctx))
2715 {
2716 if ((0 < RPS_sampler_count_id (peer_ctx->sub->sampler,
2717 &peer_ctx->peer_id)) ||
2718 (GNUNET_YES == View_contains_peer (peer_ctx->sub->view,
2719 &peer_ctx->peer_id)) ||
2721 &peer_ctx->peer_id)) ||
2723 &peer_ctx->peer_id)) ||
2724 (GNUNET_YES == check_peer_flag (peer_ctx->sub->peer_map,
2725 &peer_ctx->peer_id,
2727 { /* If we want to keep the connection to peer open */
2728 return GNUNET_YES;
2729 }
2730 return GNUNET_NO;
2731 }
2732 return GNUNET_NO;
2733}
2734
2735
2743static void
2744remove_peer (struct Sub *sub,
2745 const struct GNUNET_PeerIdentity *peer)
2746{
2747 (void) View_remove_peer (sub->view,
2748 peer);
2750 peer);
2752 peer);
2754 peer);
2755 /* We want to destroy the peer now.
2756 * Sometimes, it just seems that it's already been removed from the peer_map,
2757 * so check the peer_map first. */
2759 peer))
2760 {
2762 peer));
2763 }
2764}
2765
2766
2775static void
2776clean_peer (struct Sub *sub,
2777 const struct GNUNET_PeerIdentity *peer)
2778{
2780 peer)))
2781 {
2783 "Going to remove send channel to peer %s\n",
2784 GNUNET_i2s (peer));
2785 #if ENABLE_MALICIOUS
2786 if (0 != GNUNET_memcmp (&attacked_peer,
2787 peer))
2789 peer));
2790 #else /* ENABLE_MALICIOUS */
2792 peer));
2793 #endif /* ENABLE_MALICIOUS */
2794 }
2795
2797 peer))
2798 {
2799 /* Peer was already removed by callback on destroyed channel */
2801 "Peer was removed from our knowledge during cleanup\n");
2802 return;
2803 }
2804
2806 peer))) &&
2807 (GNUNET_NO == View_contains_peer (sub->view, peer)) &&
2810 (0 == RPS_sampler_count_id (sub->sampler, peer)) &&
2811 (GNUNET_YES == check_removable (get_peer_ctx (sub->peer_map, peer))))
2812 { /* We can safely remove this peer */
2814 "Going to remove peer %s\n",
2815 GNUNET_i2s (peer));
2816 remove_peer (sub, peer);
2817 return;
2818 }
2819}
2820
2821
2833static void
2835 const struct GNUNET_CADET_Channel *channel)
2836{
2837 struct ChannelCtx *channel_ctx = cls;
2838 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
2839
2840 (void) channel;
2841
2842 channel_ctx->channel = NULL;
2843 if ((NULL != peer_ctx) &&
2844 (peer_ctx->send_channel_ctx == channel_ctx) &&
2846 {
2847 remove_channel_ctx (channel_ctx);
2848 remove_peer (peer_ctx->sub, &peer_ctx->peer_id);
2849 }
2850 else
2851 {
2852 /* We need this if-else construct because we need to make sure the channel
2853 * (context) is cleaned up before removing the peer, but still need to
2854 * compare it while checking the condition */
2855 remove_channel_ctx (channel_ctx);
2856 }
2857}
2858
2859
2860/***********************************************************************
2861* /Util functions
2862***********************************************************************/
2863
2864
2865/***********************************************************************
2866* Sub
2867***********************************************************************/
2868
2879struct Sub *
2881 uint32_t sampler_size,
2883{
2884 struct Sub *sub;
2885
2886 sub = GNUNET_new (struct Sub);
2887
2888 /* With the hash generated from the secret value this service only connects
2889 * to rps instances that share the value */
2890 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
2891 GNUNET_MQ_hd_fixed_size (peer_check,
2893 struct GNUNET_MessageHeader,
2894 NULL),
2895 GNUNET_MQ_hd_fixed_size (peer_push,
2897 struct GNUNET_MessageHeader,
2898 NULL),
2899 GNUNET_MQ_hd_fixed_size (peer_pull_request,
2901 struct GNUNET_MessageHeader,
2902 NULL),
2903 GNUNET_MQ_hd_var_size (peer_pull_reply,
2906 NULL),
2908 };
2909 sub->hash = *hash;
2910 sub->cadet_port =
2912 &sub->hash,
2913 &handle_inbound_channel, /* Connect handler */
2914 sub, /* cls */
2915 NULL, /* WindowSize handler */
2916 &cleanup_destroyed_channel, /* Disconnect handler */
2917 cadet_handlers);
2918 if (NULL == sub->cadet_port)
2919 {
2921 "Cadet port `%s' is already in use.\n",
2923 GNUNET_assert (0);
2924 }
2925
2926 /* Set up general data structure to keep track about peers */
2928 if (GNUNET_OK !=
2930 "rps",
2931 "FILENAME_VALID_PEERS",
2932 &sub->filename_valid_peers))
2933 {
2935 "rps",
2936 "FILENAME_VALID_PEERS");
2937 }
2938 if (0 != strncmp ("DISABLE", sub->filename_valid_peers, 7))
2939 {
2940 char *tmp_filename_valid_peers;
2941 char str_hash[105];
2942
2943 GNUNET_snprintf (str_hash,
2944 sizeof(str_hash), "%s",
2945 GNUNET_h2s_full (hash));
2946 tmp_filename_valid_peers = sub->filename_valid_peers;
2948 "%s%s",
2949 tmp_filename_valid_peers,
2950 str_hash);
2951 GNUNET_free (tmp_filename_valid_peers);
2952 }
2954
2955 /* Set up the sampler */
2956 sub->sampler_size_est_min = sampler_size;
2957 sub->sampler_size_est_need = sampler_size;;
2958 LOG (GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sub->sampler_size_est_min);
2959 GNUNET_assert (0 != round_interval.rel_value_us);
2960 sub->round_interval = round_interval;
2961 sub->sampler = RPS_sampler_init (sampler_size,
2962 round_interval);
2963
2964 /* Logging of internals */
2965#ifdef TO_FILE_FULL
2966 // FIXME: The service cannot know the index, which is required by this
2967 // function:
2968 // sub->file_name_view_log = store_prefix_file_name (&own_identity, "view");
2969#endif /* TO_FILE_FULL */
2970#ifdef TO_FILE
2971#ifdef TO_FILE_FULL
2972 // FIXME: The service cannot know the index, which is required by this
2973 // function:
2974 // sub->file_name_observed_log = store_prefix_file_name (&own_identity,
2975 // "observed");
2976#endif /* TO_FILE_FULL */
2977 sub->num_observed_peers = 0;
2979 GNUNET_NO);
2980#endif /* TO_FILE */
2981
2982 /* Set up data structures for gossip */
2983 sub->push_map = CustomPeerMap_create (4);
2984 sub->pull_map = CustomPeerMap_create (4);
2985 sub->view_size_est_min = sampler_size;;
2986 sub->view = View_create (sub->view_size_est_min);
2987 if (sub == msub)
2988 {
2990 "view size aim",
2991 sub->view_size_est_min,
2992 GNUNET_NO);
2993 }
2994
2995 /* Start executing rounds */
2997
2998 return sub;
2999}
3000
3001
3002#ifdef TO_FILE
3003// /**
3004// * @brief Write all numbers in the given array into the given file
3005// *
3006// * Single numbers divided by a newline
3007// *
3008// * FIXME: The call to store_prefix_file_name expects the index of the peer,
3009// * which cannot be known to the service.
3010// * Write a dedicated function that uses the peer id.
3011// *
3012// * @param hist_array[] the array to dump
3013// * @param file_name file to dump into
3014// */
3015// static void
3016// write_histogram_to_file (const uint32_t hist_array[],
3017// const char *file_name)
3018// {
3019// char collect_str[SIZE_DUMP_FILE + 1] = "";
3020// char *recv_str_iter;
3021// char *file_name_full;
3022//
3023// recv_str_iter = collect_str;
3024// file_name_full = store_prefix_file_name (&own_identity,
3025// file_name);
3026// for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++)
3027// {
3028// char collect_str_tmp[8];
3029//
3030// GNUNET_snprintf (collect_str_tmp,
3031// sizeof(collect_str_tmp),
3032// "%" PRIu32 "\n",
3033// hist_array[i]);
3034// recv_str_iter = stpncpy (recv_str_iter,
3035// collect_str_tmp,
3036// 6);
3037// }
3038// (void) stpcpy (recv_str_iter,
3039// "\n");
3040// LOG (GNUNET_ERROR_TYPE_DEBUG,
3041// "Writing push stats to disk\n");
3042// to_file_w_len (file_name_full,
3043// SIZE_DUMP_FILE, "%s",
3044// collect_str);
3045// GNUNET_free (file_name_full);
3046// }
3047
3048
3049#endif /* TO_FILE */
3050
3051
3057static void
3058destroy_sub (struct Sub *sub)
3059{
3060 GNUNET_assert (NULL != sub);
3061 GNUNET_assert (NULL != sub->do_round_task);
3063 sub->do_round_task = NULL;
3064
3065 /* Disconnect from cadet */
3067 sub->cadet_port = NULL;
3068
3069 /* Clean up data structures for peers */
3071 sub->sampler = NULL;
3072 View_destroy (sub->view);
3073 sub->view = NULL;
3075 sub->push_map = NULL;
3077 sub->pull_map = NULL;
3078 peers_terminate (sub);
3079
3080 /* Free leftover data structures */
3081#ifdef TO_FILE_FULL
3082 GNUNET_free (sub->file_name_view_log);
3083 sub->file_name_view_log = NULL;
3084#endif /* TO_FILE_FULL */
3085#ifdef TO_FILE
3086#ifdef TO_FILE_FULL
3087 GNUNET_free (sub->file_name_observed_log);
3088 sub->file_name_observed_log = NULL;
3089#endif /* TO_FILE_FULL */
3090
3091 // FIXME: Currently this calls malfunctionning code
3092 // /* Write push frequencies to disk */
3093 // write_histogram_to_file (sub->push_recv,
3094 // "push_recv");
3095
3096 // /* Write push deltas to disk */
3097 // write_histogram_to_file (sub->push_delta,
3098 // "push_delta");
3099
3100 // /* Write pull delays to disk */
3101 // write_histogram_to_file (sub->pull_delays,
3102 // "pull_delays");
3103
3105 sub->observed_unique_peers = NULL;
3106#endif /* TO_FILE */
3107
3108 GNUNET_free (sub);
3109}
3110
3111
3112/***********************************************************************
3113* /Sub
3114***********************************************************************/
3115
3116
3117/***********************************************************************
3118* Core handlers
3119***********************************************************************/
3120
3127void
3129 const struct GNUNET_PeerIdentity *my_identity)
3130{
3131 (void) cls;
3132 (void) my_identity;
3133
3135}
3136
3137
3146void *
3148 const struct GNUNET_PeerIdentity *peer,
3149 struct GNUNET_MQ_Handle *mq)
3150{
3151 (void) cls;
3152 (void) mq;
3153
3156 peer,
3157 NULL,
3159 return NULL;
3160}
3161
3162
3171void
3173 const struct GNUNET_PeerIdentity *peer,
3174 void *peer_cls)
3175{
3176 (void) cls;
3177 (void) peer_cls;
3178
3180}
3181
3182
3183/***********************************************************************
3184* /Core handlers
3185***********************************************************************/
3186
3187
3193static void
3195{
3196 GNUNET_assert (NULL != cli_ctx);
3199 cli_ctx);
3200 if (NULL != cli_ctx->sub)
3201 {
3202 destroy_sub (cli_ctx->sub);
3203 cli_ctx->sub = NULL;
3204 }
3205 GNUNET_free (cli_ctx);
3206}
3207
3208
3216static void
3217adapt_sizes (struct Sub *sub, double logestimate, double std_dev)
3218{
3219 double estimate;
3220
3221 // double scale; // TODO this might go global/config
3222
3224 "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n",
3225 logestimate, std_dev, RPS_sampler_get_size (sub->sampler));
3226 // scale = .01;
3227 estimate = GNUNET_NSE_log_estimate_to_n (logestimate);
3228 // GNUNET_NSE_log_estimate_to_n (logestimate);
3229 estimate = pow (estimate, 1.0 / 3);
3230 // TODO add if std_dev is a number
3231 // estimate += (std_dev * scale);
3232 if (sub->view_size_est_min < ceil (estimate))
3233 {
3234 LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate);
3235 sub->sampler_size_est_need = estimate;
3236 sub->view_size_est_need = estimate;
3237 }
3238 else
3239 {
3240 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate);
3241 // sub->sampler_size_est_need = sub->view_size_est_min;
3243 }
3244 if (sub == msub)
3245 {
3247 "view size aim",
3248 sub->view_size_est_need,
3249 GNUNET_NO);
3250 }
3251
3252 /* If the NSE has changed adapt the lists accordingly */
3255}
3256
3257
3271static void
3273 struct GNUNET_TIME_Absolute timestamp,
3274 double logestimate, double std_dev)
3275{
3276 (void) cls;
3277 (void) timestamp;
3278 struct ClientContext *cli_ctx_iter;
3279
3280 adapt_sizes (msub, logestimate, std_dev);
3281 for (cli_ctx_iter = cli_ctx_head;
3282 NULL != cli_ctx_iter;
3283 cli_ctx_iter = cli_ctx_iter->next)
3284 {
3285 if (NULL != cli_ctx_iter->sub)
3286 {
3287 adapt_sizes (cli_ctx_iter->sub, logestimate, std_dev);
3288 }
3289 }
3290}
3291
3292
3302static int
3304{
3305 struct ClientContext *cli_ctx = cls;
3306 uint16_t msize = ntohs (msg->header.size);
3307 uint32_t num_peers = ntohl (msg->num_peers);
3308
3309 msize -= sizeof(struct GNUNET_RPS_CS_SeedMessage);
3310 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
3311 (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
3312 {
3314 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
3315 ntohl (msg->num_peers),
3316 (msize / sizeof(struct GNUNET_PeerIdentity)));
3317 GNUNET_break (0);
3319 return GNUNET_SYSERR;
3320 }
3321 return GNUNET_OK;
3322}
3323
3324
3331static void
3333 const struct GNUNET_RPS_CS_SeedMessage *msg)
3334{
3335 struct ClientContext *cli_ctx = cls;
3336 struct GNUNET_PeerIdentity *peers;
3337 uint32_t num_peers;
3338 uint32_t i;
3339
3340 num_peers = ntohl (msg->num_peers);
3341 peers = (struct GNUNET_PeerIdentity *) &msg[1];
3342
3344 "Client seeded peers:\n");
3346
3347 for (i = 0; i < num_peers; i++)
3348 {
3350 "Updating samplers with seed %" PRIu32 ": %s\n",
3351 i,
3352 GNUNET_i2s (&peers[i]));
3353
3354 if (NULL != msub)
3355 got_peer (msub, &peers[i]); /* Condition needed? */
3356 if (NULL != cli_ctx->sub)
3357 got_peer (cli_ctx->sub, &peers[i]);
3358 }
3360}
3361
3362
3370static void
3373{
3374 struct ClientContext *cli_ctx = cls;
3375 uint64_t num_updates;
3376
3377 num_updates = ntohl (msg->num_updates);
3378
3380 "Client requested %" PRIu64 " updates of view.\n",
3381 num_updates);
3382
3383 GNUNET_assert (NULL != cli_ctx);
3384 cli_ctx->view_updates_left = num_updates;
3385 send_view (cli_ctx, NULL, 0);
3387}
3388
3389
3396static void
3398 const struct GNUNET_MessageHeader *msg)
3399{
3400 struct ClientContext *cli_ctx = cls;
3401
3402 (void) msg;
3403
3405 "Client does not want to receive updates of view any more.\n");
3406
3407 GNUNET_assert (NULL != cli_ctx);
3408 cli_ctx->view_updates_left = 0;
3410 if (GNUNET_YES == cli_ctx->stream_update)
3411 {
3412 destroy_cli_ctx (cli_ctx);
3413 }
3414}
3415
3416
3423static void
3425 const struct
3427{
3428 struct ClientContext *cli_ctx = cls;
3429
3430 (void) msg;
3431
3433 "Client requested peers from biased stream.\n");
3434 cli_ctx->stream_update = GNUNET_YES;
3435
3436 GNUNET_assert (NULL != cli_ctx);
3438}
3439
3440
3447static void
3449 const struct GNUNET_MessageHeader *msg)
3450{
3451 struct ClientContext *cli_ctx = cls;
3452
3453 (void) msg;
3454
3456 "Client canceled receiving peers from biased stream.\n");
3457 cli_ctx->stream_update = GNUNET_NO;
3458
3459 GNUNET_assert (NULL != cli_ctx);
3461}
3462
3463
3470static void
3472 const struct GNUNET_RPS_CS_SubStartMessage *msg)
3473{
3474 struct ClientContext *cli_ctx = cls;
3475
3476 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested start of a new sub.\n");
3477 if ((NULL != cli_ctx->sub) &&
3478 (0 != memcmp (&cli_ctx->sub->hash,
3479 &msg->hash,
3480 sizeof(struct GNUNET_HashCode))) )
3481 {
3483 "Already have a Sub with different share for this client. Remove old one, add new.\n");
3484 destroy_sub (cli_ctx->sub);
3485 cli_ctx->sub = NULL;
3486 }
3487 cli_ctx->sub = new_sub (&msg->hash,
3488 msub->sampler_size_est_min, // TODO make api input?
3489 GNUNET_TIME_relative_ntoh (msg->round_interval));
3491}
3492
3493
3500static void
3502 const struct GNUNET_RPS_CS_SubStopMessage *msg)
3503{
3504 struct ClientContext *cli_ctx = cls;
3505
3506 GNUNET_assert (NULL != cli_ctx->sub);
3507 if (0 != memcmp (&cli_ctx->sub->hash, &msg->hash, sizeof(struct
3509 {
3511 "Share of current sub and request differ!\n");
3512 }
3513 destroy_sub (cli_ctx->sub);
3514 cli_ctx->sub = NULL;
3516}
3517
3518
3528static void
3530 const struct GNUNET_MessageHeader *msg)
3531{
3532 const struct ChannelCtx *channel_ctx = cls;
3533 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3534
3535 (void) msg;
3536
3538 "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer));
3539 if (channel_ctx->peer_ctx->sub == msub)
3540 {
3542 "# pending online checks",
3543 -1,
3544 GNUNET_NO);
3545 }
3546
3547 GNUNET_CADET_receive_done (channel_ctx->channel);
3548}
3549
3550
3560static void
3562 const struct GNUNET_MessageHeader *msg)
3563{
3564 const struct ChannelCtx *channel_ctx = cls;
3565 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3566
3567 (void) msg;
3568
3569 // (check the proof of work (?))
3570
3572 "Received PUSH (%s)\n",
3573 GNUNET_i2s (peer));
3574 if (channel_ctx->peer_ctx->sub == msub)
3575 {
3576 GNUNET_STATISTICS_update (stats, "# push message received", 1, GNUNET_NO);
3577 if ((NULL != map_single_hop) &&
3579 peer)))
3580 {
3582 "# push message received (multi-hop peer)",
3583 1,
3584 GNUNET_NO);
3585 }
3586 }
3587
3588 #if ENABLE_MALICIOUS
3589 struct AttackedPeer *tmp_att_peer;
3590
3591 if ((1 == mal_type) ||
3592 (3 == mal_type))
3593 { /* Try to maximise representation */
3594 tmp_att_peer = GNUNET_new (struct AttackedPeer);
3595 tmp_att_peer->peer_id = *peer;
3596 if (NULL == att_peer_set)
3599 peer))
3600 {
3601 GNUNET_CONTAINER_DLL_insert (att_peers_head,
3602 att_peers_tail,
3603 tmp_att_peer);
3604 add_peer_array_to_set (peer, 1, att_peer_set);
3605 }
3606 else
3607 {
3608 GNUNET_free (tmp_att_peer);
3609 }
3610 }
3611
3612
3613 else if (2 == mal_type)
3614 {
3615 /* We attack one single well-known peer - simply ignore */
3616 }
3617 #endif /* ENABLE_MALICIOUS */
3618
3619 /* Add the sending peer to the push_map */
3620 CustomPeerMap_put (channel_ctx->peer_ctx->sub->push_map, peer);
3621
3623 &channel_ctx->peer_ctx->peer_id));
3624 GNUNET_CADET_receive_done (channel_ctx->channel);
3625}
3626
3627
3636static void
3638 const struct GNUNET_MessageHeader *msg)
3639{
3640 const struct ChannelCtx *channel_ctx = cls;
3641 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
3642 const struct GNUNET_PeerIdentity *peer = &peer_ctx->peer_id;
3643 const struct GNUNET_PeerIdentity *view_array;
3644
3645 (void) msg;
3646
3647 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (
3648 peer));
3649 if (peer_ctx->sub == msub)
3650 {
3652 "# pull request message received",
3653 1,
3654 GNUNET_NO);
3655 if ((NULL != map_single_hop) &&
3657 &peer_ctx->peer_id)))
3658 {
3660 "# pull request message received (multi-hop peer)",
3661 1,
3662 GNUNET_NO);
3663 }
3664 }
3665
3666 #if ENABLE_MALICIOUS
3667 if ((1 == mal_type)
3668 || (3 == mal_type))
3669 { /* Try to maximise representation */
3670 send_pull_reply (peer_ctx, mal_peers, num_mal_peers);
3671 }
3672
3673 else if (2 == mal_type)
3674 { /* Try to partition network */
3675 if (0 == GNUNET_memcmp (&attacked_peer, peer))
3676 {
3677 send_pull_reply (peer_ctx, mal_peers, num_mal_peers);
3678 }
3679 }
3680 #endif /* ENABLE_MALICIOUS */
3681
3683 &channel_ctx->peer_ctx->peer_id));
3684 GNUNET_CADET_receive_done (channel_ctx->channel);
3685 view_array = View_get_as_array (channel_ctx->peer_ctx->sub->view);
3686 send_pull_reply (peer_ctx,
3687 view_array,
3688 View_size (channel_ctx->peer_ctx->sub->view));
3689}
3690
3691
3699static int
3702{
3703 struct ChannelCtx *channel_ctx = cls;
3704 struct PeerContext *sender_ctx = channel_ctx->peer_ctx;
3705
3706 if (sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->header.size))
3707 {
3708 GNUNET_break_op (0);
3709 return GNUNET_SYSERR;
3710 }
3711
3712 if ((ntohs (msg->header.size) - sizeof(struct
3714 / sizeof(struct GNUNET_PeerIdentity) != ntohl (msg->num_peers))
3715 {
3717 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
3718 ntohl (msg->num_peers),
3719 (ntohs (msg->header.size) - sizeof(struct
3721 / sizeof(struct GNUNET_PeerIdentity));
3722 GNUNET_break_op (0);
3723 return GNUNET_SYSERR;
3724 }
3725
3726 if (GNUNET_YES != check_peer_flag (sender_ctx->sub->peer_map,
3727 &sender_ctx->peer_id,
3729 {
3731 "Received a pull reply from a peer (%s) we didn't request one from!\n",
3732 GNUNET_i2s (&sender_ctx->peer_id));
3733 if (sender_ctx->sub == msub)
3734 {
3736 "# unrequested pull replies",
3737 1,
3738 GNUNET_NO);
3739 }
3740 }
3741 return GNUNET_OK;
3742}
3743
3744
3751static void
3754{
3755 const struct ChannelCtx *channel_ctx = cls;
3756 const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id;
3757 const struct GNUNET_PeerIdentity *peers;
3758 struct Sub *sub = channel_ctx->peer_ctx->sub;
3759 uint32_t i;
3760
3761#if ENABLE_MALICIOUS
3762 struct AttackedPeer *tmp_att_peer;
3763#endif /* ENABLE_MALICIOUS */
3764
3765 sub->pull_delays[sub->num_rounds - channel_ctx->peer_ctx->round_pull_req]++;
3766 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (
3767 sender));
3768 if (channel_ctx->peer_ctx->sub == msub)
3769 {
3771 "# pull reply messages received",
3772 1,
3773 GNUNET_NO);
3774 if ((NULL != map_single_hop) &&
3776 &channel_ctx->
3777 peer_ctx->peer_id)) )
3778 {
3780 "# pull reply messages received (multi-hop peer)",
3781 1,
3782 GNUNET_NO);
3783 }
3784 }
3785
3786 #if ENABLE_MALICIOUS
3787 // We shouldn't even receive pull replies as we're not sending
3788 if (2 == mal_type)
3789 {
3790 }
3791 #endif /* ENABLE_MALICIOUS */
3792
3793 /* Do actual logic */
3794 peers = (const struct GNUNET_PeerIdentity *) &msg[1];
3795
3797 "PULL REPLY received, got following %u peers:\n",
3798 ntohl (msg->num_peers));
3799
3800 for (i = 0; i < ntohl (msg->num_peers); i++)
3801 {
3803 "%u. %s\n",
3804 i,
3805 GNUNET_i2s (&peers[i]));
3806
3807 #if ENABLE_MALICIOUS
3808 if ((NULL != att_peer_set) &&
3809 ((1 == mal_type) || (3 == mal_type) ))
3810 { /* Add attacked peer to local list */
3811 // TODO check if we sent a request and this was the first reply
3813 &peers[i]))
3815 &peers[i])) )
3816 {
3817 tmp_att_peer = GNUNET_new (struct AttackedPeer);
3818 tmp_att_peer->peer_id = peers[i];
3819 GNUNET_CONTAINER_DLL_insert (att_peers_head,
3820 att_peers_tail,
3821 tmp_att_peer);
3822 add_peer_array_to_set (&peers[i], 1, att_peer_set);
3823 }
3824 continue;
3825 }
3826 #endif /* ENABLE_MALICIOUS */
3827 /* Make sure we 'know' about this peer */
3828 (void) insert_peer (channel_ctx->peer_ctx->sub,
3829 &peers[i]);
3830
3831 if (GNUNET_YES == check_peer_valid (channel_ctx->peer_ctx->sub->valid_peers,
3832 &peers[i]))
3833 {
3834 CustomPeerMap_put (channel_ctx->peer_ctx->sub->pull_map,
3835 &peers[i]);
3836 }
3837 else
3838 {
3839 schedule_operation (channel_ctx->peer_ctx,
3841 channel_ctx->peer_ctx->sub); /* cls */
3842 (void) issue_peer_online_check (channel_ctx->peer_ctx->sub,
3843 &peers[i]);
3844 }
3845 }
3846
3848 sender),
3850 clean_peer (channel_ctx->peer_ctx->sub,
3851 sender);
3852
3854 sender));
3855 GNUNET_CADET_receive_done (channel_ctx->channel);
3856}
3857
3858
3869static struct GNUNET_TIME_Relative
3871 unsigned int spread)
3872{
3873 struct GNUNET_TIME_Relative half_interval;
3875 unsigned int rand_delay;
3876 unsigned int max_rand_delay;
3877
3878 if (0 == spread)
3879 {
3881 "Not accepting spread of 0\n");
3882 GNUNET_break (0);
3883 GNUNET_assert (0);
3884 }
3885 GNUNET_assert (0 != mean.rel_value_us);
3886
3887 /* Compute random time value between spread * mean and spread * mean */
3888 half_interval = GNUNET_TIME_relative_divide (mean, spread);
3889
3890 max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us
3891 / mean.rel_value_us * (2 / spread);
3897 max_rand_delay);
3898 ret = GNUNET_TIME_relative_saturating_multiply (mean, rand_delay);
3899 ret = GNUNET_TIME_relative_divide (ret, max_rand_delay);
3900 ret = GNUNET_TIME_relative_add (ret, half_interval);
3901
3902 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us)
3904 "Returning FOREVER_REL\n");
3905
3906 return ret;
3907}
3908
3909
3915static void
3917{
3918 struct GNUNET_MQ_Envelope *ev;
3919
3921 &peer_ctx->peer_id,
3923 SET_PEER_FLAG (peer_ctx,
3925 peer_ctx->round_pull_req = peer_ctx->sub->num_rounds;
3926
3928 "Going to send PULL REQUEST to peer %s.\n",
3929 GNUNET_i2s (&peer_ctx->peer_id));
3930
3932 send_message (peer_ctx,
3933 ev,
3934 "PULL REQUEST");
3935 if (peer_ctx->sub)
3936 {
3938 "# pull request send issued",
3939 1,
3940 GNUNET_NO);
3941 if ((NULL != map_single_hop) &&
3943 &peer_ctx->peer_id)))
3944 {
3946 "# pull request send issued (multi-hop peer)",
3947 1,
3948 GNUNET_NO);
3949 }
3950 }
3951}
3952
3953
3959static void
3960send_push (struct PeerContext *peer_ctx)
3961{
3962 struct GNUNET_MQ_Envelope *ev;
3963
3965 "Going to send PUSH to peer %s.\n",
3966 GNUNET_i2s (&peer_ctx->peer_id));
3967
3969 send_message (peer_ctx, ev, "PUSH");
3970 if (peer_ctx->sub)
3971 {
3973 "# push send issued",
3974 1,
3975 GNUNET_NO);
3976 if ((NULL != map_single_hop) &&
3978 &peer_ctx->peer_id)))
3979 {
3981 "# push send issued (multi-hop peer)",
3982 1,
3983 GNUNET_NO);
3984 }
3985 }
3986}
3987
3988
3989#if ENABLE_MALICIOUS
3990
3991
4000static int
4001check_client_act_malicious (void *cls,
4002 const struct GNUNET_RPS_CS_ActMaliciousMessage *msg)
4003{
4004 struct ClientContext *cli_ctx = cls;
4005 uint16_t msize = ntohs (msg->header.size);
4006 uint32_t num_peers = ntohl (msg->num_peers);
4007
4008 msize -= sizeof(struct GNUNET_RPS_CS_ActMaliciousMessage);
4009 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
4010 (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
4011 {
4013 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
4014 ntohl (msg->num_peers),
4015 (msize / sizeof(struct GNUNET_PeerIdentity)));
4016 GNUNET_break (0);
4018 return GNUNET_SYSERR;
4019 }
4020 return GNUNET_OK;
4021}
4022
4023
4031static void
4032handle_client_act_malicious (void *cls,
4033 const struct
4034 GNUNET_RPS_CS_ActMaliciousMessage *msg)
4035{
4036 struct ClientContext *cli_ctx = cls;
4037 struct GNUNET_PeerIdentity *peers;
4038 uint32_t num_mal_peers_sent;
4039 uint32_t num_mal_peers_old;
4040 struct Sub *sub = cli_ctx->sub;
4041
4042 if (NULL == sub)
4043 sub = msub;
4044 /* Do actual logic */
4045 peers = (struct GNUNET_PeerIdentity *) &msg[1];
4046 mal_type = ntohl (msg->type);
4047 if (NULL == mal_peer_set)
4049
4051 "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n",
4052 mal_type,
4053 ntohl (msg->num_peers));
4054
4055 if (1 == mal_type)
4056 { /* Try to maximise representation */
4057 /* Add other malicious peers to those we already know */
4058
4059 num_mal_peers_sent = ntohl (msg->num_peers);
4060 num_mal_peers_old = num_mal_peers;
4061 GNUNET_array_grow (mal_peers,
4062 num_mal_peers,
4063 num_mal_peers + num_mal_peers_sent);
4064 GNUNET_memcpy (&mal_peers[num_mal_peers_old],
4065 peers,
4066 num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity));
4067
4068 /* Add all mal peers to mal_peer_set */
4069 add_peer_array_to_set (&mal_peers[num_mal_peers_old],
4070 num_mal_peers_sent,
4071 mal_peer_set);
4072
4073 /* Substitute do_round () with do_mal_round () */
4074 GNUNET_assert (NULL != sub->do_round_task);
4076 sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub);
4077 }
4078
4079 else if ((2 == mal_type) ||
4080 (3 == mal_type))
4081 { /* Try to partition the network */
4082 /* Add other malicious peers to those we already know */
4083
4084 num_mal_peers_sent = ntohl (msg->num_peers) - 1;
4085 num_mal_peers_old = num_mal_peers;
4086 GNUNET_assert (GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent);
4087 GNUNET_array_grow (mal_peers,
4088 num_mal_peers,
4089 num_mal_peers + num_mal_peers_sent);
4090 if ((NULL != mal_peers) &&
4091 (0 != num_mal_peers) )
4092 {
4093 GNUNET_memcpy (&mal_peers[num_mal_peers_old],
4094 peers,
4095 num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity));
4096
4097 /* Add all mal peers to mal_peer_set */
4098 add_peer_array_to_set (&mal_peers[num_mal_peers_old],
4099 num_mal_peers_sent,
4100 mal_peer_set);
4101 }
4102
4103 /* Store the one attacked peer */
4104 GNUNET_memcpy (&attacked_peer,
4105 &msg->attacked_peer,
4106 sizeof(struct GNUNET_PeerIdentity));
4107 /* Set the flag of the attacked peer to valid to avoid problems */
4108 if (GNUNET_NO == check_peer_known (sub->peer_map, &attacked_peer))
4109 {
4110 (void) issue_peer_online_check (sub, &attacked_peer);
4111 }
4112
4114 "Attacked peer is %s\n",
4115 GNUNET_i2s (&attacked_peer));
4116
4117 /* Substitute do_round () with do_mal_round () */
4118 if (NULL != sub->do_round_task)
4119 {
4120 /* Probably in shutdown */
4122 sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub);
4123 }
4124 }
4125 else if (0 == mal_type)
4126 { /* Stop acting malicious */
4127 GNUNET_array_grow (mal_peers, num_mal_peers, 0);
4128
4129 /* Substitute do_mal_round () with do_round () */
4132 }
4133 else
4134 {
4135 GNUNET_break (0);
4137 }
4139}
4140
4141
4149static void
4150do_mal_round (void *cls)
4151{
4152 uint32_t num_pushes;
4153 uint32_t i;
4154 struct GNUNET_TIME_Relative time_next_round;
4155 struct AttackedPeer *tmp_att_peer;
4156 struct Sub *sub = cls;
4157
4159 "Going to execute next round maliciously type %" PRIu32 ".\n",
4160 mal_type);
4161 sub->do_round_task = NULL;
4162 GNUNET_assert (mal_type <= 3);
4163 /* Do malicious actions */
4164 if (1 == mal_type)
4165 { /* Try to maximise representation */
4166 /* The maximum of pushes we're going to send this round */
4167 num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit,
4168 num_attacked_peers),
4170
4172 "Going to send %" PRIu32 " pushes\n",
4173 num_pushes);
4174
4175 /* Send PUSHes to attacked peers */
4176 for (i = 0; i < num_pushes; i++)
4177 {
4178 if (att_peers_tail == att_peer_index)
4179 att_peer_index = att_peers_head;
4180 else
4181 att_peer_index = att_peer_index->next;
4182
4183 send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id));
4184 }
4185
4186 /* Send PULLs to some peers to learn about additional peers to attack */
4187 tmp_att_peer = att_peer_index;
4188 for (i = 0; i < num_pushes * alpha; i++)
4189 {
4190 if (att_peers_tail == tmp_att_peer)
4191 tmp_att_peer = att_peers_head;
4192 else
4193 att_peer_index = tmp_att_peer->next;
4194
4195 send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id));
4196 }
4197 }
4198
4199
4200 else if (2 == mal_type)
4201 {
4206 (void) issue_peer_online_check (sub, &attacked_peer);
4207 if (GNUNET_YES == check_peer_flag (sub->peer_map,
4208 &attacked_peer,
4209 Peers_ONLINE))
4210 send_push (get_peer_ctx (sub->peer_map, &attacked_peer));
4211 }
4212
4213
4214 if (3 == mal_type)
4215 { /* Combined attack */
4216 /* Send PUSH to attacked peers */
4217 if (GNUNET_YES == check_peer_known (sub->peer_map, &attacked_peer))
4218 {
4219 (void) issue_peer_online_check (sub, &attacked_peer);
4220 if (GNUNET_YES == check_peer_flag (sub->peer_map,
4221 &attacked_peer,
4222 Peers_ONLINE))
4223 {
4225 "Goding to send push to attacked peer (%s)\n",
4226 GNUNET_i2s (&attacked_peer));
4227 send_push (get_peer_ctx (sub->peer_map, &attacked_peer));
4228 }
4229 }
4230 (void) issue_peer_online_check (sub, &attacked_peer);
4231
4232 /* The maximum of pushes we're going to send this round */
4233 num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1,
4234 num_attacked_peers),
4236
4238 "Going to send %" PRIu32 " pushes\n",
4239 num_pushes);
4240
4241 for (i = 0; i < num_pushes; i++)
4242 {
4243 if (att_peers_tail == att_peer_index)
4244 att_peer_index = att_peers_head;
4245 else
4246 att_peer_index = att_peer_index->next;
4247
4248 send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id));
4249 }
4250
4251 /* Send PULLs to some peers to learn about additional peers to attack */
4252 tmp_att_peer = att_peer_index;
4253 for (i = 0; i < num_pushes * alpha; i++)
4254 {
4255 if (att_peers_tail == tmp_att_peer)
4256 tmp_att_peer = att_peers_head;
4257 else
4258 att_peer_index = tmp_att_peer->next;
4259
4260 send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id));
4261 }
4262 }
4263
4264 /* Schedule next round */
4265 time_next_round = compute_rand_delay (sub->round_interval, 2);
4266
4267 GNUNET_assert (NULL == sub->do_round_task);
4268 sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
4269 &do_mal_round, sub);
4270 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
4271}
4272
4273
4274#endif /* ENABLE_MALICIOUS */
4275
4276
4284static void
4285do_round (void *cls)
4286{
4287 unsigned int i;
4288 const struct GNUNET_PeerIdentity *view_array;
4289 unsigned int *permut;
4290 unsigned int a_peers; /* Number of peers we send pushes to */
4291 unsigned int b_peers; /* Number of peers we send pull requests to */
4292 uint32_t first_border;
4293 uint32_t second_border;
4294 struct GNUNET_PeerIdentity peer;
4295 struct GNUNET_PeerIdentity *update_peer;
4296 struct Sub *sub = cls;
4297
4298 sub->num_rounds++;
4300 "Going to execute next round.\n");
4301 if (sub == msub)
4302 {
4303 GNUNET_STATISTICS_update (stats, "# rounds", 1, GNUNET_NO);
4304 }
4305 sub->do_round_task = NULL;
4306#ifdef TO_FILE_FULL
4307 to_file (sub->file_name_view_log,
4308 "___ new round ___");
4309#endif /* TO_FILE_FULL */
4310 view_array = View_get_as_array (sub->view);
4311 for (i = 0; i < View_size (sub->view); i++)
4312 {
4314 "\t%s\n", GNUNET_i2s (&view_array[i]));
4315#ifdef TO_FILE_FULL
4316 to_file (sub->file_name_view_log,
4317 "=%s\t(do round)",
4318 GNUNET_i2s_full (&view_array[i]));
4319#endif /* TO_FILE_FULL */
4320 }
4321
4322
4323 /* Send pushes and pull requests */
4324 if (0 < View_size (sub->view))
4325 {
4327 View_size (sub->view));
4328
4329 /* Send PUSHes */
4330 a_peers = ceil (alpha * View_size (sub->view));
4331
4333 "Going to send pushes to %u (ceil (%f * %u)) peers.\n",
4334 a_peers, alpha, View_size (sub->view));
4335 for (i = 0; i < a_peers; i++)
4336 {
4337 peer = view_array[permut[i]];
4338 // FIXME if this fails schedule/loop this for later
4339 send_push (get_peer_ctx (sub->peer_map, &peer));
4340 }
4341
4342 /* Send PULL requests */
4343 b_peers = ceil (beta * View_size (sub->view));
4344 first_border = a_peers;
4345 second_border = a_peers + b_peers;
4346 if (second_border > View_size (sub->view))
4347 {
4348 first_border = View_size (sub->view) - b_peers;
4349 second_border = View_size (sub->view);
4350 }
4352 "Going to send pulls to %u (ceil (%f * %u)) peers.\n",
4353 b_peers, beta, View_size (sub->view));
4354 for (i = first_border; i < second_border; i++)
4355 {
4356 peer = view_array[permut[i]];
4357 if (GNUNET_NO == check_peer_flag (sub->peer_map,
4358 &peer,
4360 { // FIXME if this fails schedule/loop this for later
4361 send_pull_request (get_peer_ctx (sub->peer_map, &peer));
4362 }
4363 }
4364
4365 GNUNET_free (permut);
4366 permut = NULL;
4367 }
4368
4369
4370 /* Update view */
4371 /* TODO see how many peers are in push-/pull- list! */
4372
4373 if ((CustomPeerMap_size (sub->push_map) <= alpha * sub->view_size_est_need) &&
4374 (0 < CustomPeerMap_size (sub->push_map)) &&
4375 (0 < CustomPeerMap_size (sub->pull_map)))
4376 { /* If conditions for update are fulfilled, update */
4377 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n");
4378
4379 uint32_t final_size;
4380 uint32_t peers_to_clean_size;
4381 struct GNUNET_PeerIdentity *peers_to_clean;
4382
4383 peers_to_clean = NULL;
4384 peers_to_clean_size = 0;
4385 GNUNET_array_grow (peers_to_clean,
4386 peers_to_clean_size,
4387 View_size (sub->view));
4388 GNUNET_memcpy (peers_to_clean,
4389 view_array,
4390 View_size (sub->view) * sizeof(struct GNUNET_PeerIdentity));
4391
4392 /* Seems like recreating is the easiest way of emptying the peermap */
4393 View_clear (sub->view);
4394#ifdef TO_FILE_FULL
4395 to_file (sub->file_name_view_log,
4396 "--- emptied ---");
4397#endif /* TO_FILE_FULL */
4398
4399 first_border = GNUNET_MIN (ceil (alpha * sub->view_size_est_need),
4401 second_border = first_border
4402 + GNUNET_MIN (floor (beta * sub->view_size_est_need),
4404 final_size = second_border
4405 + ceil ((1 - (alpha + beta)) * sub->view_size_est_need);
4407 "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %"
4408 PRIu32 "\n",
4409 first_border,
4410 second_border,
4411 final_size);
4412
4413 /* Update view with peers received through PUSHes */
4416 for (i = 0; i < first_border; i++)
4417 {
4418 int inserted;
4419 inserted = insert_in_view (sub,
4421 permut[i]));
4422 if (GNUNET_OK == inserted)
4423 {
4425 1,
4427 sub->push_map, permut[i]));
4428 }
4429#ifdef TO_FILE_FULL
4430 to_file (sub->file_name_view_log,
4431 "+%s\t(push list)",
4432 GNUNET_i2s_full (&view_array[i]));
4433#endif /* TO_FILE_FULL */
4434 // TODO change the peer_flags accordingly
4435 }
4436 GNUNET_free (permut);
4437 permut = NULL;
4438
4439 /* Update view with peers received through PULLs */
4442 for (i = first_border; i < second_border; i++)
4443 {
4444 int inserted;
4445 inserted = insert_in_view (sub,
4447 permut[i
4448 -
4449 first_border
4450 ]));
4451 if (GNUNET_OK == inserted)
4452 {
4454 1,
4456 sub->pull_map,
4457 permut[i
4458 - first_border]));
4459 }
4460#ifdef TO_FILE_FULL
4461 to_file (sub->file_name_view_log,
4462 "+%s\t(pull list)",
4463 GNUNET_i2s_full (&view_array[i]));
4464#endif /* TO_FILE_FULL */
4465 // TODO change the peer_flags accordingly
4466 }
4467 GNUNET_free (permut);
4468 permut = NULL;
4469
4470 /* Update view with peers from history */
4472 final_size - second_border,
4474 sub);
4475 // TODO change the peer_flags accordingly
4476
4477 for (i = 0; i < View_size (sub->view); i++)
4478 rem_from_list (&peers_to_clean, &peers_to_clean_size, &view_array[i]);
4479
4480 /* Clean peers that were removed from the view */
4481 for (i = 0; i < peers_to_clean_size; i++)
4482 {
4483#ifdef TO_FILE_FULL
4484 to_file (sub->file_name_view_log,
4485 "-%s",
4486 GNUNET_i2s_full (&peers_to_clean[i]));
4487#endif /* TO_FILE_FULL */
4488 clean_peer (sub, &peers_to_clean[i]);
4489 }
4490
4491 GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0);
4493 }
4494 else
4495 {
4496 LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n");
4497 if (sub == msub)
4498 {
4499 GNUNET_STATISTICS_update (stats, "# rounds blocked", 1, GNUNET_NO);
4500 if ((CustomPeerMap_size (sub->push_map) > alpha
4501 * sub->view_size_est_need) &&
4502 ! (0 >= CustomPeerMap_size (sub->pull_map)))
4503 GNUNET_STATISTICS_update (stats, "# rounds blocked - too many pushes",
4504 1, GNUNET_NO);
4505 if ((CustomPeerMap_size (sub->push_map) > alpha
4506 * sub->view_size_est_need) &&
4507 (0 >= CustomPeerMap_size (sub->pull_map)))
4509 "# rounds blocked - too many pushes, no pull replies",
4510 1, GNUNET_NO);
4511 if ((0 >= CustomPeerMap_size (sub->push_map)) &&
4512 ! (0 >= CustomPeerMap_size (sub->pull_map)))
4513 GNUNET_STATISTICS_update (stats, "# rounds blocked - no pushes", 1,
4514 GNUNET_NO);
4515 if ((0 >= CustomPeerMap_size (sub->push_map)) &&
4516 (0 >= CustomPeerMap_size (sub->pull_map)))
4518 "# rounds blocked - no pushes, no pull replies",
4519 1, GNUNET_NO);
4520 if ((0 >= CustomPeerMap_size (sub->pull_map)) &&
4522 * sub->view_size_est_need) &&
4523 (0 >= CustomPeerMap_size (sub->push_map)) )
4524 GNUNET_STATISTICS_update (stats, "# rounds blocked - no pull replies",
4525 1, GNUNET_NO);
4526 }
4527 }
4528 // TODO independent of that also get some peers from CADET_get_peers()?
4530 {
4531 sub->push_recv[CustomPeerMap_size (sub->push_map)]++;
4532 }
4533 else
4534 {
4536 "Push map size too big for histogram (%u, %u)\n",
4539 }
4540 // FIXME check bounds of histogram
4541 sub->push_delta[(int32_t) (CustomPeerMap_size (sub->push_map)
4542 - (alpha * sub->view_size_est_need))
4543 + (HISTOGRAM_FILE_SLOTS / 2)]++;
4544 if (sub == msub)
4545 {
4547 "# peers in push map at end of round",
4549 GNUNET_NO);
4551 "# peers in pull map at end of round",
4553 GNUNET_NO);
4555 "# peers in view at end of round",
4556 View_size (sub->view),
4557 GNUNET_NO);
4559 "# expected pushes",
4561 GNUNET_NO);
4563 "delta expected - received pushes",
4565 * sub->
4566 view_size_est_need),
4567 GNUNET_NO);
4568 }
4569
4571 "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n",
4574 alpha,
4575 View_size (sub->view),
4576 alpha * View_size (sub->view));
4577
4578 /* Update samplers */
4579 for (i = 0; i < CustomPeerMap_size (sub->push_map); i++)
4580 {
4581 update_peer = CustomPeerMap_get_peer_by_index (sub->push_map, i);
4583 "Updating with peer %s from push list\n",
4584 GNUNET_i2s (update_peer));
4585 insert_in_sampler (sub, update_peer);
4586 clean_peer (sub, update_peer); /* This cleans only if it is not in the view */
4587 }
4588
4589 for (i = 0; i < CustomPeerMap_size (sub->pull_map); i++)
4590 {
4592 "Updating with peer %s from pull list\n",
4595 /* This cleans only if it is not in the view */
4597 }
4598
4599
4600 /* Empty push/pull lists */
4603
4604 if (sub == msub)
4605 {
4607 "view size",
4608 View_size (sub->view),
4609 GNUNET_NO);
4610 }
4611
4612 struct GNUNET_TIME_Relative time_next_round;
4613
4614 time_next_round = compute_rand_delay (sub->round_interval, 2);
4615
4616 /* Schedule next round */
4617 sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
4618 &do_round, sub);
4619 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
4620}
4621
4622
4638void
4639init_peer_cb (void *cls,
4640 const struct GNUNET_PeerIdentity *peer,
4641 int tunnel, /* "Do we have a tunnel towards this peer?" */
4642 unsigned int n_paths, /* "Number of known paths towards this peer" */
4643 unsigned int best_path) /* "How long is the best path?
4644 * (0 = unknown, 1 = ourselves, 2 = neighbor)" */
4645{
4646 struct Sub *sub = cls;
4647
4648 (void) tunnel;
4649 (void) n_paths;
4650 (void) best_path;
4651
4652 if (NULL != peer)
4653 {
4655 "Got peer_id %s from cadet\n",
4656 GNUNET_i2s (peer));
4657 got_peer (sub, peer);
4658 }
4659}
4660
4661
4673static int
4675 const struct GNUNET_PeerIdentity *peer)
4676{
4677 struct Sub *sub = cls;
4678
4679 if (NULL != peer)
4680 {
4682 "Got stored, valid peer %s\n",
4683 GNUNET_i2s (peer));
4684 got_peer (sub, peer);
4685 }
4686 return GNUNET_YES;
4687}
4688
4689
4698void
4700 const struct GNUNET_PEERSTORE_Record *record,
4701 const char *emsg)
4702{
4703 struct Sub *sub = cls;
4704 (void) emsg;
4705
4707 "Got peer_id %s from peerinfo\n",
4708 GNUNET_i2s (&record->peer));
4709 got_peer (sub, &record->peer);
4711}
4712
4713
4719static void
4720shutdown_task (void *cls)
4721{
4722 (void) cls;
4723 struct ClientContext *client_ctx;
4724
4726 "RPS service is going down\n");
4727
4728 /* Clean all clients */
4729 for (client_ctx = cli_ctx_head;
4730 NULL != cli_ctx_head;
4731 client_ctx = cli_ctx_head)
4732 {
4733 destroy_cli_ctx (client_ctx);
4734 }
4735 if (NULL != msub)
4736 {
4737 destroy_sub (msub);
4738 msub = NULL;
4739 }
4740
4741 /* Disconnect from other services */
4744 peerstore = NULL;
4746 if (NULL != map_single_hop)
4747 {
4748 /* core_init was called - core was initialised */
4749 /* disconnect first, so no callback tries to access missing peermap */
4751 core_handle = NULL;
4753 map_single_hop = NULL;
4754 }
4755
4756 if (NULL != stats)
4757 {
4759 GNUNET_NO);
4760 stats = NULL;
4761 }
4763 cadet_handle = NULL;
4764#if ENABLE_MALICIOUS
4765 struct AttackedPeer *tmp_att_peer;
4766 GNUNET_array_grow (mal_peers,
4767 num_mal_peers,
4768 0);
4769 if (NULL != mal_peer_set)
4771 if (NULL != att_peer_set)
4773 while (NULL != att_peers_head)
4774 {
4775 tmp_att_peer = att_peers_head;
4776 GNUNET_CONTAINER_DLL_remove (att_peers_head,
4777 att_peers_tail,
4778 tmp_att_peer);
4779 GNUNET_free (tmp_att_peer);
4780 }
4781#endif /* ENABLE_MALICIOUS */
4782 close_all_files ();
4783}
4784
4785
4794static void *
4796 struct GNUNET_SERVICE_Client *client,
4797 struct GNUNET_MQ_Handle *mq)
4798{
4799 struct ClientContext *cli_ctx;
4800
4801 (void) cls;
4802
4804 "Client connected\n");
4805 if (NULL == client)
4806 return client; /* Server was destroyed before a client connected. Shutting down */
4807 cli_ctx = GNUNET_new (struct ClientContext);
4808 cli_ctx->mq = mq;
4809 cli_ctx->view_updates_left = -1;
4810 cli_ctx->stream_update = GNUNET_NO;
4811 cli_ctx->client = client;
4814 cli_ctx);
4815 return cli_ctx;
4816}
4817
4818
4826static void
4829 void *internal_cls)
4830{
4831 struct ClientContext *cli_ctx = internal_cls;
4832
4833 (void) cls;
4834 GNUNET_assert (client == cli_ctx->client);
4835 if (NULL == client)
4836 { /* shutdown task - destroy all clients */
4837 while (NULL != cli_ctx_head)
4839 }
4840 else
4841 { /* destroy this client */
4843 "Client disconnected. Destroy its context.\n");
4844 destroy_cli_ctx (cli_ctx);
4845 }
4846}
4847
4848
4849static void
4850error_cb (void *cls)
4851{
4853 "Error in PEERSTORE monitoring\n");
4854}
4855
4856
4857static void
4858sync_cb (void *cls)
4859{
4861 "Done with initial PEERSTORE iteration during monitoring\n");
4862}
4863
4864
4872static void
4873run (void *cls,
4874 const struct GNUNET_CONFIGURATION_Handle *c,
4876{
4877 struct GNUNET_TIME_Relative round_interval;
4878 long long unsigned int sampler_size;
4879 char hash_port_string[] = GNUNET_APPLICATION_PORT_RPS;
4880 struct GNUNET_HashCode hash;
4881
4882 (void) cls;
4883 (void) service;
4884
4885 GNUNET_log_setup ("rps",
4887 NULL);
4888 cfg = c;
4889 /* Get own ID */
4891 &own_identity); // TODO check return value
4893 "STARTING SERVICE (rps) for peer [%s]\n",
4895#if ENABLE_MALICIOUS
4897 "Malicious execution compiled in.\n");
4898#endif /* ENABLE_MALICIOUS */
4899
4900 /* Get time interval from the configuration */
4901 if (GNUNET_OK !=
4903 "RPS",
4904 "ROUNDINTERVAL",
4905 &round_interval))
4906 {
4908 "RPS", "ROUNDINTERVAL");
4910 return;
4911 }
4912
4913 /* Get initial size of sampler/view from the configuration */
4914 if (GNUNET_OK !=
4916 "RPS",
4917 "MINSIZE",
4918 &sampler_size))
4919 {
4921 "RPS", "MINSIZE");
4923 return;
4924 }
4925
4927 GNUNET_assert (NULL != cadet_handle);
4929 NULL, /* cls */
4930 core_init, /* init */
4931 core_connects, /* connects */
4932 core_disconnects, /* disconnects */
4933 NULL); /* handlers */
4934 GNUNET_assert (NULL != core_handle);
4935
4936
4937 alpha = 0.45;
4938 beta = 0.45;
4939
4940
4941 /* Set up main Sub */
4942 GNUNET_CRYPTO_hash (hash_port_string,
4943 strlen (hash_port_string),
4944 &hash);
4945 msub = new_sub (&hash,
4946 sampler_size, /* Will be overwritten by config */
4947 round_interval);
4948
4949
4951
4952 /* connect to NSE */
4954
4955 // LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n");
4956 // GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, msub);
4957 // TODO send push/pull to each of those peers?
4958 LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n");
4961
4964 GNUNET_YES,
4965 "peerstore",
4966 NULL,
4968 &error_cb,
4969 NULL,
4970 &sync_cb,
4971 NULL,
4973 msub);
4974
4975 LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n");
4976
4979}
4980
4981
4986 ("rps",
4988 &run,
4991 NULL,
4992 GNUNET_MQ_hd_var_size (client_seed,
4995 NULL),
4997 GNUNET_MQ_hd_var_size (client_act_malicious,
4998 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS,
4999 struct GNUNET_RPS_CS_ActMaliciousMessage,
5000 NULL),
5001#endif /* ENABLE_MALICIOUS */
5002 GNUNET_MQ_hd_fixed_size (client_view_request,
5005 NULL),
5006 GNUNET_MQ_hd_fixed_size (client_view_cancel,
5008 struct GNUNET_MessageHeader,
5009 NULL),
5010 GNUNET_MQ_hd_fixed_size (client_stream_request,
5013 NULL),
5014 GNUNET_MQ_hd_fixed_size (client_stream_cancel,
5016 struct GNUNET_MessageHeader,
5017 NULL),
5018 GNUNET_MQ_hd_fixed_size (client_start_sub,
5021 NULL),
5022 GNUNET_MQ_hd_fixed_size (client_stop_sub,
5025 NULL),
5027
5028/* end of gnunet-service-rps.c */
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
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:69
static int ret
Final status code.
Definition: gnunet-arm.c:94
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
struct GNUNET_PeerIdentity my_identity
Our peer identity.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_FS_Handle * ctx
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 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.
GNUNET_SERVICE_MAIN("rps", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(client_seed, GNUNET_MESSAGE_TYPE_RPS_CS_SEED, struct GNUNET_RPS_CS_SeedMessage, NULL), GNUNET_MQ_hd_fixed_size(client_view_request, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST, struct GNUNET_RPS_CS_DEBUG_ViewRequest, NULL), GNUNET_MQ_hd_fixed_size(client_view_cancel, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_fixed_size(client_stream_request, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST, struct GNUNET_RPS_CS_DEBUG_StreamRequest, NULL), GNUNET_MQ_hd_fixed_size(client_stream_cancel, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_fixed_size(client_start_sub, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START, struct GNUNET_RPS_CS_SubStartMessage, NULL), GNUNET_MQ_hd_fixed_size(client_stop_sub, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP, struct GNUNET_RPS_CS_SubStopMessage, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
static struct PeerContext * create_or_get_peer_ctx(struct Sub *sub, const struct GNUNET_PeerIdentity *peer)
Create or get a PeerContext.
void * core_connects(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Callback for core.
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 shutdown_task(void *cls)
Task run during shutdown.
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.
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:894
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Indicate readiness to receive the next message on a channel.
Definition: cadet_api.c:872
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:830
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:1066
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:954
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:774
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port.
Definition: cadet_api.c:801
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:1015
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)
Connect to the core service.
Definition: core_api.c:691
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:729
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:1237
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:482
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:686
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
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:622
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:192
@ 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.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
Definition: gnunet_mq_lib.h:87
#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
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:567
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:1340
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
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:1305
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:1278
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2484
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2455
@ 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:628
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:531
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:585
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:550
static unsigned int size
Size of the "table".
Definition: peer.c:68
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.
Definition: rps-test_util.h:65
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
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.
Definition: peerstore_api.c:44
Context for a monitor.
Single PEERSTORE record.
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:136
Handle to a client that is connected to a service.
Definition: service.c:246
Handle to a service.
Definition: service.c:117
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.