GNUnet 0.22.2
gnunet-service-nse.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2011, 2012, 2013, 2016 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
38#include "platform.h"
39#include <math.h>
40#include "gnunet_util_lib.h"
41#include "gnunet_protocols.h"
42#include "gnunet_signatures.h"
44#include "gnunet_core_service.h"
45#if ENABLE_NSE_HISTOGRAM
46#include "gnunet_testbed_logger_service.h"
47#endif
48#include "nse.h"
49#include <gcrypt.h>
50
51
56#define USE_RANDOM_DELAYS GNUNET_YES
57
61#define DEBUG_NSE GNUNET_NO
62
66#define HISTORY_SIZE 64
67
72#define NSE_PRIORITY \
73 (GNUNET_MQ_PRIO_BACKGROUND | GNUNET_MQ_PREF_UNRELIABLE \
74 | GNUNET_MQ_PREF_CORK_ALLOWED)
75
76#ifdef BSD
77#define log2(a) (log (a) / log (2))
78#endif
79
83static unsigned long long nse_work_required;
84
89
94
95#if ENABLE_NSE_HISTOGRAM
96
100struct GNUNET_CLIENT_TestHandle *logger_test;
101
105static struct GNUNET_TESTBED_LOGGER_Handle *lh;
106
110static struct GNUNET_BIO_WriteHandle *histogram;
111
112#endif
113
117static struct GNUNET_CRYPTO_PowSalt salt = { "gnunet-nse-proof" };
118
119
124{
129
133 const struct GNUNET_PeerIdentity *id;
134
139
146
147#if ENABLE_NSE_HISTOGRAM
151 unsigned int received_messages;
152
156 unsigned int transmitted_messages;
157
161 unsigned int last_transmitted_size;
162#endif
163};
164
165
167
174{
179
184
189
195
202
207
212
217};
219
223static const struct GNUNET_CONFIGURATION_Handle *cfg;
224
229
234
239
245
250static double current_std_dev = NAN;
251
255static uint32_t hop_count_max;
256
261
266
270static unsigned int estimate_index;
271
275static unsigned int estimate_count;
276
281
286
291
296
301
306
311
315static uint64_t my_proof;
316
317
324static void
326{
327 double mean;
328 double sum;
329 double std_dev;
330 double variance;
331 double val;
332 double nsize;
333
334#define WEST 1
335 /* Weighted incremental algorithm for stddev according to West (1979) */
336#if WEST
337 double sumweight;
338 double weight;
339 double q;
340 double r;
341 double temp;
342
343 mean = 0.0;
344 sum = 0.0;
345 sumweight = 0.0;
346 variance = 0.0;
347 for (unsigned int i = 0; i < estimate_count; i++)
348 {
349 unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE;
350
351 val = htonl (size_estimate_messages[j].matching_bits);
352 weight = estimate_count + 1 - i;
353
354 temp = weight + sumweight;
355 q = val - mean;
356 r = q * weight / temp;
357 mean += r;
358 sum += sumweight * q * r;
359 sumweight = temp;
360 }
361 if (estimate_count > 0)
362 variance = (sum / sumweight) * estimate_count / (estimate_count - 1.0);
363#else
364 /* trivial version for debugging */
365 double vsq;
366
367 /* non-weighted trivial version */
368 sum = 0.0;
369 vsq = 0.0;
370 variance = 0.0;
371 mean = 0.0;
372
373 for (unsigned int i = 0; i < estimate_count; i++)
374 {
375 unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE;
376
377 val = htonl (size_estimate_messages[j].matching_bits);
378 sum += val;
379 vsq += val * val;
380 }
381 if (0 != estimate_count)
382 {
383 mean = sum / estimate_count;
384 variance = (vsq - mean * sum)
385 / (estimate_count - 1.0); // terrible for numerical stability...
386 }
387#endif
388 if (variance >= 0)
389 std_dev = sqrt (variance);
390 else
391 std_dev = variance; /* return NaN (due to estimate_count == 0 causing 0.0/0.0) */
392 current_std_dev = std_dev;
394
395 em->header.size = htons (sizeof(struct GNUNET_NSE_ClientMessage));
397 em->reserved = htonl (0);
399 {
400 double se = mean - 0.332747;
401 unsigned int j = GNUNET_CONTAINER_multipeermap_size (peers);
402 if (0 == j)
403 j = 1; /* Avoid log2(0); can only happen if CORE didn't report
404 connection to self yet */
405 nsize = log2 (j);
406 em->size_estimate = GNUNET_hton_double (GNUNET_MAX (se, nsize));
407 em->std_deviation = GNUNET_hton_double (std_dev);
409 "# nodes in the network (estimate)",
410 (uint64_t) pow (2, GNUNET_MAX (se, nsize)),
411 GNUNET_NO);
412 }
413}
414
415
425static void
426handle_start (void *cls, const struct GNUNET_MessageHeader *message)
427{
428 struct GNUNET_SERVICE_Client *client = cls;
429 struct GNUNET_MQ_Handle *mq;
430 struct GNUNET_NSE_ClientMessage em;
431 struct GNUNET_MQ_Envelope *env;
432
433 (void) message;
434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
441}
442
443
450static double
452{
453 /* Calculated as: S + f/2 - (f / pi) * (atan(x - p')) */
454 // S is next_timestamp (ignored in return value)
455 // f is frequency (gnunet_nse_interval)
456 // x is matching_bits
457 // p' is current_size_estimate
458 return ((double) gnunet_nse_interval.rel_value_us / (double) 2.0)
461}
462
463
470static struct GNUNET_TIME_Relative
472{
473#if USE_RANDOM_DELAYS
475 uint32_t i;
476 double d;
477
479 i = (uint32_t) (d / (double) (hop_count_max + 1));
480 ret.rel_value_us = i;
482 "Randomizing flood using latencies up to %s\n",
484 ret.rel_value_us =
486 return ret;
487#else
489#endif
490}
491
492
500static uint32_t
502 const struct GNUNET_PeerIdentity *id)
503{
504 struct GNUNET_HashCode timestamp_hash;
505 struct GNUNET_HashCode pid_hash;
506 struct GNUNET_HashCode xor;
507
508 GNUNET_CRYPTO_hash (&timestamp.abs_value_us,
509 sizeof(timestamp.abs_value_us),
510 &timestamp_hash);
512 sizeof(struct GNUNET_PeerIdentity),
513 &pid_hash);
514 GNUNET_CRYPTO_hash_xor (&pid_hash,
515 &timestamp_hash,
516 &xor);
518}
519
520
529static struct GNUNET_TIME_Relative
531{
533 struct GNUNET_TIME_Absolute tgt;
534 double dist_delay;
535 uint32_t matching_bits;
536
537 switch (round_offset)
538 {
539 case -1:
540 /* previous round is randomized between 0 and 50 ms */
541#if USE_RANDOM_DELAYS
542 ret.rel_value_us =
544#else
546#endif
548 "Transmitting previous round behind schedule in %s\n",
550 return ret;
551
552 case 0:
553 /* current round is based on best-known matching_bits */
558 ret.rel_value_us = (uint64_t) dist_delay;
560 "For round %s, delay for %u matching bits is %s\n",
562 (unsigned int) matching_bits,
564 /* now consider round start time and add delay to it */
567 }
568 GNUNET_break (0);
570}
571
572
578static void
580{
581 struct NSEPeerEntry *peer_entry = cls;
582 unsigned int idx;
583 struct GNUNET_MQ_Envelope *env;
584
585 peer_entry->transmit_task = NULL;
586 idx = estimate_index;
587 if (GNUNET_NO == peer_entry->previous_round)
588 {
589 idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE;
590 peer_entry->previous_round = GNUNET_YES;
591 peer_entry->transmit_task =
594 peer_entry);
595 }
596 if ((0 == ntohl (size_estimate_messages[idx].hop_count)) &&
597 (NULL != proof_task))
598 {
600 "# flood messages not generated (no proof yet)",
601 1,
602 GNUNET_NO);
603 return;
604 }
605 if (0 == ntohs (size_estimate_messages[idx].header.size))
606 {
608 "# flood messages not generated (lack of history)",
609 1,
610 GNUNET_NO);
611 return;
612 }
614 "In round %s, sending to `%s' estimate with %u bits\n",
618 GNUNET_i2s (peer_entry->id),
619 (unsigned int) ntohl (size_estimate_messages[idx].matching_bits));
620 if (0 == ntohl (size_estimate_messages[idx].hop_count))
621 GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO);
623 "# flood messages transmitted",
624 1,
625 GNUNET_NO);
626#if ENABLE_NSE_HISTOGRAM
627 peer_entry->transmitted_messages++;
628 peer_entry->last_transmitted_size =
630#endif
632 GNUNET_MQ_send (peer_entry->mq, env);
633}
634
635
642static void
644{
645 struct GNUNET_NSE_ClientMessage em;
646
649}
650
651
659static void
660setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts)
661{
662 struct GNUNET_NSE_FloodMessage *fm;
663 uint32_t matching_bits;
664
666 fm = &size_estimate_messages[slot];
667 fm->header.size = htons (sizeof(struct GNUNET_NSE_FloodMessage));
669 fm->hop_count = htonl (0);
671 fm->purpose.size =
672 htonl (sizeof(struct GNUNET_NSE_FloodMessage)
673 - sizeof(struct GNUNET_MessageHeader) - sizeof(uint32_t)
674 - sizeof(struct GNUNET_CRYPTO_EddsaSignature));
675 fm->matching_bits = htonl (matching_bits);
677 fm->origin = my_identity;
679 if (nse_work_required > 0)
682 &fm->purpose,
683 &fm->signature));
684 else
685 memset (&fm->signature, 0, sizeof(fm->signature));
686}
687
688
698static int
700 const struct GNUNET_PeerIdentity *key,
701 void *value)
702{
703 struct NSEPeerEntry *peer_entry = value;
704 struct GNUNET_TIME_Relative delay;
705
706 (void) cls;
707 (void) key;
708 if (NULL != peer_entry->transmit_task)
709 {
711 peer_entry->previous_round = GNUNET_NO;
712 }
713#if ENABLE_NSE_HISTOGRAM
714 if (peer_entry->received_messages > 1)
716 "# extra messages",
717 peer_entry->received_messages - 1,
718 GNUNET_NO);
719 peer_entry->transmitted_messages = 0;
720 peer_entry->last_transmitted_size = 0;
721 peer_entry->received_messages = 0;
722#endif
723 delay =
724 get_transmit_delay ((GNUNET_NO == peer_entry->previous_round) ? -1 : 0);
725 peer_entry->transmit_task =
727 return GNUNET_OK;
728}
729
730
736static void
738{
739 struct GNUNET_TIME_Relative offset;
740
741 (void) cls;
742 flood_task = NULL;
744 if (0 != offset.rel_value_us)
745 {
746 /* somehow run early, delay more */
747 flood_task =
749 return;
750 }
761 {
762 /* we received a message for this round way early, use it! */
765 htonl (1 + ntohl (next_message.hop_count));
766 }
767 else
769 next_message.matching_bits = htonl (0); /* reset for 'next' round */
770 hop_count_max = 0;
771 for (unsigned int i = 0; i < HISTORY_SIZE; i++)
773 GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max);
775 flood_task =
777}
778
779
790 uint64_t val)
791{
792 char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
793 + sizeof(val)] GNUNET_ALIGN;
794 struct GNUNET_HashCode result;
795
796 GNUNET_memcpy (buf, &val, sizeof(val));
797 GNUNET_memcpy (&buf[sizeof(val)],
798 pkey,
799 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey));
801 buf,
802 sizeof(buf),
803 &result);
806 ? GNUNET_YES
807 : GNUNET_NO;
808}
809
810
814static void
816{
817 char *proof;
818
819 if (GNUNET_OK !=
821 "NSE",
822 "PROOFFILE",
823 &proof))
824 return;
826 if (GNUNET_OK !=
828 &my_proof,
829 sizeof(my_proof),
833 "write",
834 proof);
836}
837
838
844static void
845find_proof (void *cls)
846{
847#define ROUND_SIZE 10
848 uint64_t counter;
849 char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
850 + sizeof(uint64_t)] GNUNET_ALIGN;
851 struct GNUNET_HashCode result;
852 unsigned int i;
853
854 (void) cls;
855 proof_task = NULL;
856 GNUNET_memcpy (&buf[sizeof(uint64_t)],
858 sizeof(struct GNUNET_PeerIdentity));
859 i = 0;
860 counter = my_proof;
861 while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
862 {
863 GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
865 buf,
866 sizeof(buf),
867 &result);
868 if (nse_work_required <=
870 {
871 my_proof = counter;
873 "Proof of work found: %llu!\n",
874 (unsigned long long) GNUNET_ntohll (counter));
875 write_proof ();
877 return;
878 }
879 counter++;
880 i++;
881 }
882 if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE))
883 {
885 "Testing proofs currently at %llu\n",
886 (unsigned long long) counter);
887 /* remember progress every 100 rounds */
888 my_proof = counter;
889 write_proof ();
890 }
891 else
892 {
893 my_proof = counter;
894 }
895 proof_task =
898 &find_proof,
899 NULL);
900}
901
902
912static int
913verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood)
914{
915 if (GNUNET_YES != check_proof_of_work (&incoming_flood->origin.public_key,
916 incoming_flood->proof_of_work))
917 {
919 "Proof of work invalid: %llu!\n",
920 (unsigned long long) GNUNET_ntohll (
921 incoming_flood->proof_of_work));
922 GNUNET_break_op (0);
923 return GNUNET_NO;
924 }
925 if ((nse_work_required > 0) &&
926 (GNUNET_OK !=
928 &incoming_flood->purpose,
929 &incoming_flood->signature,
930 &incoming_flood->origin.public_key)))
931 {
932 GNUNET_break_op (0);
933 return GNUNET_NO;
934 }
935 return GNUNET_YES;
936}
937
938
948static int
950 const struct GNUNET_PeerIdentity *key,
951 void *value)
952{
953 struct NSEPeerEntry *exclude = cls;
954 struct NSEPeerEntry *peer_entry = value;
955 struct GNUNET_TIME_Relative delay;
956
957 (void) key;
958 if (peer_entry == exclude)
959 return GNUNET_OK; /* trigger of the update */
960 if (GNUNET_NO == peer_entry->previous_round)
961 {
962 /* still stuck in previous round, no point to update, check that
963 * we are active here though... */
964 if (NULL == peer_entry->transmit_task)
965 {
966 GNUNET_break (0);
967 }
968 return GNUNET_OK;
969 }
970 if (NULL != peer_entry->transmit_task)
971 {
973 peer_entry->transmit_task = NULL;
974 }
975 delay = get_transmit_delay (0);
976 peer_entry->transmit_task =
978 return GNUNET_OK;
979}
980
981
988static void
990 const struct GNUNET_NSE_FloodMessage *incoming_flood)
991{
992 struct NSEPeerEntry *peer_entry = cls;
993 struct GNUNET_TIME_Absolute ts;
994 uint32_t matching_bits;
995 unsigned int idx;
996
997#if ENABLE_NSE_HISTOGRAM
998 {
999 uint64_t t;
1000
1002 if (NULL != lh)
1003 GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof(uint64_t));
1004 if (NULL != histogram)
1005 GNUNET_BIO_write_int64 (histogram, "histogram-time", t);
1006 }
1007#endif
1008 GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO);
1009 matching_bits = ntohl (incoming_flood->matching_bits);
1010#if DEBUG_NSE
1011 {
1012 char origin[5];
1013 char pred[5];
1014 struct GNUNET_PeerIdentity os;
1015
1017 sizeof(origin),
1018 "%s",
1019 GNUNET_i2s (&incoming_flood->origin));
1020 GNUNET_snprintf (pred, sizeof(pred), "%s", GNUNET_i2s (peer_entry->id));
1022 "Flood at %s from `%s' via `%s' at `%s' with bits %u\n",
1024 GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp)),
1025 origin,
1026 pred,
1028 (unsigned int) matching_bits);
1029 }
1030#endif
1031
1032#if ENABLE_NSE_HISTOGRAM
1033 peer_entry->received_messages++;
1034 if ((peer_entry->transmitted_messages > 0) &&
1035 (peer_entry->last_transmitted_size >= matching_bits) )
1036 GNUNET_STATISTICS_update (stats, "# cross messages", 1, GNUNET_NO);
1037#endif
1038
1039 ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp);
1041 idx = estimate_index;
1042 else if (ts.abs_value_us ==
1046 {
1048 return; /* ignore, simply too early/late */
1049 if (GNUNET_YES != verify_message_crypto (incoming_flood))
1050 {
1052 "Peer %s is likely ill-configured!\n",
1053 GNUNET_i2s (peer_entry->id));
1054 GNUNET_break_op (0);
1055 return;
1056 }
1057 next_message = *incoming_flood;
1058 return;
1059 }
1060 else
1061 {
1063 "# flood messages discarded (clock skew too large)",
1064 1,
1065 GNUNET_NO);
1066 return;
1067 }
1068 if (0 == (GNUNET_memcmp (peer_entry->id, &my_identity)))
1069 {
1070 /* send to self, update our own estimate IF this also comes from us! */
1071 if (0 == GNUNET_memcmp (&incoming_flood->origin, &my_identity))
1073 return;
1074 }
1076 {
1077 /* Cancel transmission in the other direction, as this peer clearly has
1078 up-to-date information already. Even if we didn't talk to this peer in
1079 the previous round, we should no longer send it stale information as it
1080 told us about the current round! */
1081 peer_entry->previous_round = GNUNET_YES;
1082 if (idx != estimate_index)
1083 {
1084 /* do not transmit information for the previous round to this peer
1085 anymore (but allow current round) */
1086 return;
1087 }
1088 /* got up-to-date information for current round, cancel transmission to
1089 * this peer altogether */
1090 if (NULL != peer_entry->transmit_task)
1091 {
1093 peer_entry->transmit_task = NULL;
1094 }
1095 return;
1096 }
1098 {
1099 if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES))
1100 {
1101 peer_entry->previous_round = GNUNET_NO;
1102 }
1103 /* push back our result now, that peer is spreading bad information... */
1104 if (NULL != peer_entry->transmit_task)
1106 peer_entry->transmit_task =
1108 /* Not closer than our most recent message, no need to do work here */
1110 "# flood messages ignored (had closer already)",
1111 1,
1112 GNUNET_NO);
1113 return;
1114 }
1115 if (GNUNET_YES != verify_message_crypto (incoming_flood))
1116 {
1117 GNUNET_break_op (0);
1118 return;
1119 }
1122 /* Cancel transmission in the other direction, as this peer clearly has
1123 * up-to-date information already.
1124 */
1125 peer_entry->previous_round = GNUNET_YES;
1126 if (idx == estimate_index)
1127 {
1128 /* cancel any activity for current round */
1129 if (NULL != peer_entry->transmit_task)
1130 {
1132 peer_entry->transmit_task = NULL;
1133 }
1134 }
1135 size_estimate_messages[idx] = *incoming_flood;
1137 htonl (ntohl (incoming_flood->hop_count) + 1);
1139 GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, hop_count_max);
1141 "# estimated network diameter",
1143 GNUNET_NO);
1144
1145 /* have a new, better size estimate, inform clients */
1147
1148 /* flood to rest */
1151 peer_entry);
1152}
1153
1154
1162static void *
1164 const struct GNUNET_PeerIdentity *peer,
1165 struct GNUNET_MQ_Handle *mq)
1166{
1167 struct NSEPeerEntry *peer_entry;
1168
1169 (void) cls;
1171 "Peer `%s' connected to us\n",
1172 GNUNET_i2s (peer));
1173 /* set our default transmission options */
1175 /* create our peer entry for this peer */
1176 peer_entry = GNUNET_new (struct NSEPeerEntry);
1177 peer_entry->id = peer;
1178 peer_entry->mq = mq;
1181 peers,
1182 peer_entry->id,
1183 peer_entry,
1185 peer_entry->transmit_task =
1188 peer_entry);
1189 GNUNET_STATISTICS_update (stats, "# peers connected", 1, GNUNET_NO);
1190 return peer_entry;
1191}
1192
1193
1202static void
1204 const struct GNUNET_PeerIdentity *peer,
1205 void *internal_cls)
1206{
1207 struct NSEPeerEntry *pos = internal_cls;
1208
1209 (void) cls;
1211 "Peer `%s' disconnected from us\n",
1212 GNUNET_i2s (peer));
1215 if (NULL != pos->transmit_task)
1216 {
1218 pos->transmit_task = NULL;
1219 }
1220 GNUNET_free (pos);
1221 GNUNET_STATISTICS_update (stats, "# peers connected", -1, GNUNET_NO);
1222}
1223
1224
1225#if ENABLE_NSE_HISTOGRAM
1233static void
1234flush_comp_cb (void *cls, size_t size)
1235{
1236 (void) cls;
1237 (void) size;
1238 GNUNET_TESTBED_LOGGER_disconnect (lh);
1239 lh = NULL;
1240}
1241
1242
1243#endif
1244
1245
1251static void
1252shutdown_task (void *cls)
1253{
1254 (void) cls;
1255 if (NULL != flood_task)
1256 {
1258 flood_task = NULL;
1259 }
1260 if (NULL != proof_task)
1261 {
1263 proof_task = NULL;
1264 write_proof (); /* remember progress */
1265 }
1266 if (NULL != nc)
1267 {
1269 nc = NULL;
1270 }
1271 if (NULL != core_api)
1272 {
1274 core_api = NULL;
1275 }
1276 if (NULL != stats)
1277 {
1279 stats = NULL;
1280 }
1281 if (NULL != peers)
1282 {
1284 peers = NULL;
1285 }
1286 if (NULL != my_private_key)
1287 {
1289 my_private_key = NULL;
1290 }
1291#if ENABLE_NSE_HISTOGRAM
1292 if (NULL != logger_test)
1293 {
1294 GNUNET_CLIENT_service_test_cancel (logger_test);
1295 logger_test = NULL;
1296 }
1297 if (NULL != lh)
1298 {
1299 GNUNET_TESTBED_LOGGER_flush (lh, &flush_comp_cb, NULL);
1300 }
1301 if (NULL != histogram)
1302 {
1303 GNUNET_BIO_write_close (histogram, NULL);
1304 histogram = NULL;
1305 }
1306#endif
1307}
1308
1309
1316static void
1317core_init (void *cls, const struct GNUNET_PeerIdentity *identity)
1318{
1319 struct GNUNET_TIME_Absolute now;
1320 struct GNUNET_TIME_Absolute prev_time;
1321
1322 (void) cls;
1323 if (NULL == identity)
1324 {
1325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n");
1327 return;
1328 }
1330 now = GNUNET_TIME_absolute_get ();
1337 estimate_count = 0;
1339 {
1340 int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE;
1341 prev_time.abs_value_us =
1343 setup_flood_message (idx, prev_time);
1346 }
1347 flood_task =
1349}
1350
1351
1352#if ENABLE_NSE_HISTOGRAM
1361static void
1362status_cb (void *cls, int status)
1363{
1364 (void) cls;
1365 logger_test = NULL;
1366 if (GNUNET_YES != status)
1367 {
1368 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed logger not running\n");
1369 return;
1370 }
1371 if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect (cfg)))
1372 {
1374 "Cannot connect to the testbed logger. Exiting.\n");
1376 }
1377}
1378
1379
1380#endif
1381
1382
1390static void
1391run (void *cls,
1392 const struct GNUNET_CONFIGURATION_Handle *c,
1394{
1395 struct GNUNET_MQ_MessageHandler core_handlers[] =
1396 { GNUNET_MQ_hd_fixed_size (p2p_estimate,
1399 NULL),
1401 char *proof;
1403
1404 (void) cls;
1405 (void) service;
1406 cfg = c;
1408 "NSE",
1409 "INTERVAL",
1411 {
1414 return;
1415 }
1417 "NSE",
1418 "WORKDELAY",
1420 {
1423 return;
1424 }
1426 "NSE",
1427 "WORKBITS",
1429 {
1432 return;
1433 }
1434 if (nse_work_required >= sizeof(struct GNUNET_HashCode) * 8)
1435 {
1437 "NSE",
1438 "WORKBITS",
1439 _ ("Value is too large.\n"));
1441 return;
1442 }
1443
1444#if ENABLE_NSE_HISTOGRAM
1445 {
1446 char *histogram_dir;
1447 char *histogram_fn;
1448
1450 "NSE",
1451 "HISTOGRAM_DIR",
1452 &histogram_dir))
1453 {
1455 0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", histogram_dir));
1456 GNUNET_free (histogram_dir);
1457 histogram = GNUNET_BIO_write_open_file (histogram_fn);
1458 if (NULL == histogram)
1460 "Unable to open histogram file `%s'\n",
1461 histogram_fn);
1462 GNUNET_free (histogram_fn);
1463 }
1464 logger_test = GNUNET_CLIENT_service_test ("testbed-logger",
1465 cfg,
1467 &status_cb,
1468 NULL);
1469 }
1470#endif
1471
1474 GNUNET_assert (NULL != pk);
1477 if (GNUNET_OK !=
1478 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof))
1479 {
1482 my_private_key = NULL;
1484 return;
1485 }
1487 (sizeof(my_proof) !=
1489 my_proof = 0;
1491 proof_task =
1493 &find_proof,
1494 NULL);
1495
1498 /* Connect to core service and register core handlers */
1499 core_api =
1500 GNUNET_CORE_connect (cfg, /* Main configuration */
1501 NULL, /* Closure passed to functions */
1502 &core_init, /* Call core_init once connected */
1503 &handle_core_connect, /* Handle connects */
1504 &handle_core_disconnect, /* Handle disconnects */
1505 core_handlers); /* Register these handlers */
1506 if (NULL == core_api)
1507 {
1509 return;
1510 }
1512}
1513
1514
1523static void *
1525 struct GNUNET_SERVICE_Client *c,
1526 struct GNUNET_MQ_Handle *mq)
1527{
1528 (void) cls;
1529 (void) mq;
1530 return c;
1531}
1532
1533
1541static void
1543 struct GNUNET_SERVICE_Client *c,
1544 void *internal_cls)
1545{
1546 (void) cls;
1547 GNUNET_assert (c == internal_cls);
1548}
1549
1550
1555 "nse",
1557 &run,
1560 NULL,
1563 struct GNUNET_MessageHeader,
1564 NULL),
1566
1567
1568#if defined(__linux__) && defined(__GLIBC__)
1569#include <malloc.h>
1570
1571void __attribute__ ((constructor))
1572GNUNET_NSE_memory_init (void);
1573
1577void __attribute__ ((constructor))
1578GNUNET_NSE_memory_init (void)
1579{
1580 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1581 mallopt (M_TOP_PAD, 1 * 1024);
1582 malloc_trim (0);
1583}
1584
1585
1586#endif
1587
1588
1589/* end of gnunet-service-nse.c */
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static mp_limb_t d[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:38
static int ret
Final status code.
Definition: gnunet-arm.c:93
static uint64_t timestamp(void)
Get current timestamp.
struct GNUNET_HashCode key
The key used in the DHT.
static ogg_stream_state os
Ogg stream state.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static char * pkey
Public key of the zone to look in, in ASCII.
static char origin[GNUNET_DNSPARSER_MAX_NAME_LENGTH]
Current origin.
static char * value
Value of the record to add/remove.
static int status
The program status; 0 for success.
Definition: gnunet-nse.c:39
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static int result
Global testing status.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static unsigned long long matching_bits
Number of matching bits required for revocation.
static uint64_t proof
Definition: gnunet-scrypt.c:49
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
static double current_std_dev
The standard deviation of the last HISTORY_SIZE network size estimates.
static struct GNUNET_NSE_FloodMessage size_estimate_messages[64]
Array of recent size estimate messages.
static void update_flood_message(void *cls)
Update our flood message to be sent (and our timestamps).
static void transmit_task_cb(void *cls)
Task that triggers a NSE P2P transmission.
static void core_init(void *cls, const struct GNUNET_PeerIdentity *identity)
Called on core init/fail.
static int update_flood_times(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Update transmissions for the given peer for the current round based on updated proximity information.
static double get_matching_bits_delay(uint32_t matching_bits)
How long should we delay a message to go the given number of matching bits?
static unsigned int estimate_index
Index of most recent estimate.
static struct GNUNET_TIME_Relative gnunet_nse_interval
Interval for sending network size estimation flood requests.
static struct GNUNET_PeerIdentity my_identity
The peer identity of this peer.
#define NSE_PRIORITY
Message priority to use.
#define HISTORY_SIZE
Over how many values do we calculate the weighted average?
static enum GNUNET_GenericReturnValue check_proof_of_work(const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, uint64_t val)
Check whether the given public key and integer are a valid proof of work.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static void setup_estimate_message(struct GNUNET_NSE_ClientMessage *em)
Initialize a message to clients with the current network size estimate.
static struct GNUNET_SCHEDULER_Task * proof_task
Task scheduled to compute our proof.
static struct GNUNET_TIME_Absolute current_timestamp
The current major time.
static struct GNUNET_NotificationContext * nc
Notification context, simplifies client broadcasts.
static void find_proof(void *cls)
Find our proof of work.
static unsigned int estimate_count
Number of valid entries in the history.
static void * handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a peer connects.
static void update_network_size_estimate()
We've sent on our flood message or one that we received which was validated and closer than ours.
static struct GNUNET_TIME_Relative proof_find_delay
Interval between proof find runs.
static void shutdown_task(void *cls)
Task run during shutdown.
static int verify_message_crypto(const struct GNUNET_NSE_FloodMessage *incoming_flood)
An incoming flood message has been received which claims to have more bits matching than any we know ...
static uint64_t my_proof
Proof of work for this peer.
static struct GNUNET_CORE_Handle * core_api
Handle to the core service.
static unsigned long long nse_work_required
Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Handle network size estimate clients.
static GNUNET_NETWORK_STRUCT_END const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
static void setup_flood_message(unsigned int slot, struct GNUNET_TIME_Absolute ts)
Setup a flood message in our history array at the given slot offset for the given timestamp.
static int schedule_current_round(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Schedule transmission for the given peer for the current round based on what we know about the desire...
static uint32_t hop_count_max
Current hop counter estimate (estimate for network diameter).
static struct GNUNET_TIME_Relative get_transmit_delay(int round_offset)
Get the transmission delay that should be applied for a particular round.
#define ROUND_SIZE
static void handle_start(void *cls, const struct GNUNET_MessageHeader *message)
Handler for START message from client, triggers an immediate current network estimate notification.
static struct GNUNET_NSE_FloodMessage next_message
Message for the next round, if we got any.
static struct GNUNET_SCHEDULER_Task * flood_task
Task scheduled to update our flood message for the next round.
static struct GNUNET_TIME_Absolute next_timestamp
The next major time.
GNUNET_SERVICE_MAIN(GNUNET_OS_project_data_gnunet(), "nse", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(start, GNUNET_MESSAGE_TYPE_NSE_START, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calculations.
static struct GNUNET_TIME_Relative get_delay_randomization(uint32_t matching_bits)
What delay randomization should we apply for a given number of matching bits?
static double current_size_estimate
The current network size estimate.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
Callback called when a client connects to the service.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
Callback called when a client disconnected from the service.
static void write_proof(void)
Write our current proof to disk.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
The private key of this peer.
static void handle_p2p_estimate(void *cls, const struct GNUNET_NSE_FloodMessage *incoming_flood)
Core handler for size estimate flooding messages.
static void handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a peer disconnects.
static uint32_t get_matching_bits(struct GNUNET_TIME_Absolute timestamp, const struct GNUNET_PeerIdentity *id)
Get the number of matching bits that the given timestamp has to the given peer ID.
static struct GNUNET_SCHEDULER_Task * t
Main task.
Core service; the main API for encrypted P2P communications.
struct GNUNET_PQ_ResultSpec __attribute__
Constants for network protocols.
#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND
Signature of a network size estimate message.
API to create, modify and access statistics.
enum GNUNET_GenericReturnValue GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:556
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:508
enum GNUNET_GenericReturnValue GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:865
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.
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
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:201
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:625
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:708
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
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:520
enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write(const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file atomically.
Definition: disk.c:737
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1080
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:674
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
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_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b
Definition: crypto_hash.c:132
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.
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.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
@ 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...
unsigned int GNUNET_CRYPTO_hash_count_leading_zeros(const struct GNUNET_HashCode *h)
Count the number of leading 0 bits in h.
Definition: crypto_hash.c:174
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
#define GNUNET_MAX(a, b)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
void GNUNET_CRYPTO_pow_hash(const struct GNUNET_CRYPTO_PowSalt *salt, const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
Calculate the 'proof-of-work' hash (an expensive hash).
Definition: crypto_pow.c:42
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
double GNUNET_hton_double(double d)
Convert double to network byte order.
Definition: common_endian.c:70
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_PACKED
gcc-ism to get packed structs.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
#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).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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_free(ptr)
Wrapper around free.
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
Definition: nc.c:138
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:550
void GNUNET_MQ_set_options(struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_PriorityPreferences pp)
Set application-specific options for this queue.
Definition: mq.c:888
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.
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Definition: nc.c:122
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
Definition: nc.c:190
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
Definition: nc.c:161
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define GNUNET_MESSAGE_TYPE_NSE_START
client->service message indicating start
#define GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD
P2P message sent from nearest peer.
#define GNUNET_MESSAGE_TYPE_NSE_ESTIMATE
service->client message indicating
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_at(struct GNUNET_TIME_Absolute at, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run at the specified time.
Definition: scheduler.c:1254
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:1339
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
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:1304
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:1277
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1207
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1231
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2500
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2389
@ 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".
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:406
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:579
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:452
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:640
Common type definitions for the network size estimation service and API.
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
Handle for buffered writing.
Definition: bio.c:466
Internal representation of the hash map.
Context for the core service connection.
Definition: core_api.c:78
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
an ECC signature using EdDSA.
Value for a salt for GNUNET_CRYPTO_pow_hash().
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
Network size estimate sent from the service to clients.
Definition: nse.h:43
uint32_t reserved
For alignment.
Definition: nse.h:52
double size_estimate
The current estimated network size.
Definition: nse.h:62
struct GNUNET_TIME_AbsoluteNBO timestamp
Timestamp at which the server received the message.
Definition: nse.h:57
double std_deviation
The standard deviation (rounded down to the nearest integer) of size estimations.
Definition: nse.h:69
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_NSE_ESTIMATE.
Definition: nse.h:47
Network size estimate reply; sent when "this" peer's timer has run out before receiving a valid reply...
uint32_t hop_count
Number of hops this message has taken so far.
uint32_t matching_bits
Number of matching bits between the hash of timestamp and the initiator's public key.
struct GNUNET_TIME_AbsoluteNBO timestamp
The current timestamp value (which all peers should agree on).
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD.
struct GNUNET_PeerIdentity origin
Public key of the originator.
uint64_t proof_of_work
Proof of work, causing leading zeros when hashed with pkey.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose.
struct GNUNET_CRYPTO_EddsaSignature signature
Signature (over range specified in purpose).
The notification context is the key datastructure for a convenience API used for transmission of noti...
Definition: nc.c:77
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Definition: scheduler.c:136
Handle to a client that is connected to a service.
Definition: service.c:249
Handle to a service.
Definition: service.c:116
Handle for the service.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Per-peer information.
struct GNUNET_MQ_Handle * mq
Core handle for sending messages to this peer.
struct GNUNET_SCHEDULER_Task * transmit_task
Task scheduled to send message to this peer.
const struct GNUNET_PeerIdentity * id
What is the identity of the peer?
int previous_round
Did we receive or send a message about the previous round to this peer yet? GNUNET_YES if the previou...