GNUnet 0.26.2-114-g7c6b613e3
 
Loading...
Searching...
No Matches
gnunet-service-dht_neighbours.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2017, 2021-2022, 2026 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
27#include "gnunet_common.h"
28#include "gnunet_constants.h"
30#include "gnunet_dht_service.h"
31#include "gnunet_protocols.h"
33#include "gnunet_pils_service.h"
34#include "gnunet-service-dht.h"
37#include "dht.h"
38#include "dht_helper.h"
40#include "gnunet_util_lib.h"
41
42#define LOG_TRAFFIC(kind, ...) GNUNET_log_from (kind, "dht-traffic", \
43 __VA_ARGS__)
44
56#define SANITY_CHECKS 2
57
61#define MAX_BUCKETS sizeof(struct GNUNET_HashCode) * 8
62
66#define DEFAULT_BUCKET_SIZE 8
67
71#define FIND_PEER_REPLICATION_LEVEL 4
72
76#define MAXIMUM_PENDING_PER_PEER 64
77
83#define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply ( \
84 GNUNET_TIME_UNIT_MINUTES, 2)
85
86
96#define DHT_AVG_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply ( \
97 GNUNET_TIME_UNIT_SECONDS, 6)
98
102#define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
103
104
106
107
112{
117
122
127
132
137
142
147
152
153 /* trunc_peer (if truncated) */
154
155 /* put path (if tracked) */
156
157 /* get path (if tracked) */
158
159 /* sender_sig (if path tracking is on) */
160
161 /* Payload */
162};
163
164
169{
174
179
184
189
194
199
204
209
210 /* result bloomfilter */
211
212 /* xquery */
213
214};
216
217
221struct PeerInfo;
222
223
227struct Target
228{
232 struct Target *next;
233
237 struct Target *prev;
238
243
248
252 struct PeerInfo *pi;
253
258
262 unsigned int load;
263
269
270};
271
272
277{
282
287
292
296 struct PeerInfo *next;
297
301 struct PeerInfo *prev;
302
306 struct Target *t_head;
307
311 struct Target *t_tail;
312
316 void *hello;
317
322
327};
328
329
334{
338 struct PeerInfo *head;
339
343 struct PeerInfo *tail;
344
348 unsigned int peers_size;
349};
350
351
355static int cache_results;
356
360static unsigned int closest_bucket;
361
366static unsigned int newly_found_peers;
367
372
377
383
387static unsigned int bucket_size = DEFAULT_BUCKET_SIZE;
388
393
394
402static void
403send_done_cb (void *cls)
404{
405 struct Target *t = cls;
406 struct PeerInfo *pi = t->pi; /* NULL if t->dropped! */
407
408 GNUNET_assert (t->load > 0);
409 t->load--;
410 if (0 < t->load)
411 return;
412 if (t->dropped)
413 {
414 GNUNET_free (t);
415 return;
416 }
417 /* move target back to the front */
419 pi->t_tail,
420 t);
422 pi->t_tail,
423 t);
424}
425
426
433static void
434do_send (struct PeerInfo *pi,
435 const struct GNUNET_MessageHeader *msg)
436{
437 struct Target *t;
438
439 for (t = pi->t_head;
440 NULL != t;
441 t = t->next)
442 if (t->load < MAXIMUM_PENDING_PER_PEER)
443 break;
444 if (NULL == t)
445 {
446 /* all targets busy, drop message */
448 "# messages dropped (underlays busy)",
449 1,
450 GNUNET_NO);
451 return;
452 }
453 t->load++;
454 /* rotate busy targets to the end */
455 if (MAXIMUM_PENDING_PER_PEER == t->load)
456 {
458 pi->t_tail,
459 t);
461 pi->t_tail,
462 t);
463 }
464 GDS_u_send (t->u,
465 t->utarget,
466 msg,
467 ntohs (msg->size),
469 t);
470}
471
472
480static int
481find_bucket (const struct GNUNET_HashCode *hc)
482{
483 const struct GNUNET_HashCode *my_identity_hash;
484 struct GNUNET_HashCode xor;
485 unsigned int bits;
486
487 my_identity_hash = GNUNET_PILS_get_identity_hash (GDS_pils);
488 GNUNET_assert (NULL != my_identity_hash);
489
491 my_identity_hash,
492 &xor);
494 if (bits == MAX_BUCKETS)
495 {
496 /* How can all bits match? Got my own ID? */
497 GNUNET_break (0);
498 return -1;
499 }
500 return MAX_BUCKETS - bits - 1;
501}
502
503
515 const struct GNUNET_PeerIdentity *key,
516 void *value)
517{
518 struct GNUNET_BLOCK_Group *bg = cls;
519 struct PeerInfo *pi = value;
520
522 &pi->phash,
523 1);
525 "Adding known peer (%s) to Bloom filter for FIND PEER\n",
526 GNUNET_i2s (key));
527 return GNUNET_YES;
528}
529
530
538static void
540{
541 (void) cls;
542
543 /* Compute when to do this again (and if we should
544 even send a message right now) */
545 {
546 struct GNUNET_TIME_Relative next_send_time;
547 bool done_early;
548
549 find_peer_task = NULL;
550 done_early = (newly_found_peers > bucket_size);
551 /* schedule next round, taking longer if we found more peers
552 in the last round. */
553 next_send_time.rel_value_us =
559 1 + 100 * (1 + newly_found_peers) / bucket_size).rel_value_us);
563 GNUNET_SCHEDULER_add_delayed (next_send_time,
565 NULL);
566 if (done_early)
567 return;
568 }
569
570 /* actually send 'find peer' request */
571 {
572 const struct GNUNET_HashCode *my_identity_hash;
573 struct GNUNET_BLOCK_Group *bg;
574 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
575
576 my_identity_hash = GNUNET_PILS_get_identity_hash (GDS_pils);
577 GNUNET_assert (NULL != my_identity_hash);
578
581 NULL,
582 0,
583 "seen-set-size",
586 NULL);
589 bg);
590 peer_bf
594 if (GNUNET_OK !=
599 0, /* hop count */
600 my_identity_hash,
601 NULL, 0, /* xquery */
602 bg,
603 peer_bf))
604 {
606 "# Failed to initiate FIND PEER lookup",
607 1,
608 GNUNET_NO);
609 }
610 else
611 {
613 "# FIND PEER messages initiated",
614 1,
615 GNUNET_NO);
616 }
619 }
620}
621
622
630static void
631update_hold (struct PeerBucket *bucket)
632{
633 unsigned int off = 0;
634
635 /* find the peer -- we just go over all of them, should
636 be hardly any more expensive than just finding the 'right'
637 one. */
638 for (struct PeerInfo *pos = bucket->head;
639 NULL != pos;
640 pos = pos->next)
641 {
642 if (off > bucket_size)
643 break; /* We only hold up to #bucket_size peers per bucket */
644 off++;
645 for (struct Target *tp = pos->t_head;
646 NULL != tp;
647 tp = tp->next)
648 if (NULL == tp->ph)
649 tp->ph = GDS_u_hold (tp->u,
650 tp->utarget);
651 }
652}
653
654
655void
656GDS_u_connect (void *cls,
657 struct GNUNET_DHTU_Target *target,
658 const struct GNUNET_PeerIdentity *pid,
659 void **ctx)
660{
661 const struct GNUNET_PeerIdentity *my_identity;
662 struct GDS_Underlay *u = cls;
663 struct PeerInfo *pi;
664 struct PeerBucket *bucket;
665 bool do_hold = false;
666
668 GNUNET_assert (NULL != my_identity);
669
670 /* Check for connect to self message */
671 if (0 == GNUNET_memcmp (my_identity, pid))
672 return;
674 "Connected to peer %s\n",
675 GNUNET_i2s (pid));
677 pid);
678 if (NULL == pi)
679 {
681 "# peers connected",
682 1,
683 GNUNET_NO);
684 pi = GNUNET_new (struct PeerInfo);
685 pi->id = *pid;
687 sizeof(*pid),
688 &pi->phash);
689 pi->peer_bucket = find_bucket (&pi->phash);
690 GNUNET_assert ( (pi->peer_bucket >= 0) &&
691 ((unsigned int) pi->peer_bucket < MAX_BUCKETS));
692 bucket = &k_buckets[pi->peer_bucket];
694 bucket->tail,
695 pi);
696 bucket->peers_size++;
698 (unsigned int) pi->peer_bucket + 1);
701 &pi->id,
702 pi,
704 if (bucket->peers_size <= bucket_size)
705 {
707 do_hold = true;
708 }
711 {
712 /* got a first connection, good time to start with FIND PEER requests... */
715 NULL);
716 }
717 }
718 {
719 struct Target *t;
720
721 t = GNUNET_new (struct Target);
722 t->u = u;
723 t->utarget = target;
724 t->pi = pi;
726 pi->t_tail,
727 t);
728 *ctx = t;
729
730 }
731 if (do_hold)
732 update_hold (bucket);
733}
734
735
736void
738{
739 struct Target *t = ctx;
740 struct PeerInfo *pi;
741 struct PeerBucket *bucket;
742 bool was_held = false;
743
744 /* Check for disconnect from self message (on shutdown) */
745 if (NULL == t)
746 return;
747 pi = t->pi;
749 pi->t_tail,
750 t);
751 if (NULL != t->ph)
752 {
753 GDS_u_drop (t->u,
754 t->ph);
755 t->ph = NULL;
756 was_held = true;
757 }
758 if (t->load > 0)
759 {
760 t->dropped = true;
761 t->pi = NULL;
762 }
763 else
764 {
765 GNUNET_free (t);
766 }
767 if (NULL != pi->t_head)
768 return; /* got other connections still */
770 "Disconnected from peer %s\n",
771 GNUNET_i2s (&pi->id));
773 "# peers connected",
774 -1,
775 GNUNET_NO);
778 &pi->id,
779 pi));
782 {
784 find_peer_task = NULL;
785 }
786 GNUNET_assert (pi->peer_bucket >= 0);
787 bucket = &k_buckets[pi->peer_bucket];
789 bucket->tail,
790 pi);
791 GNUNET_assert (bucket->peers_size > 0);
792 bucket->peers_size--;
793 if ( (was_held) &&
794 (bucket->peers_size >= bucket_size - 1) )
795 update_hold (bucket);
796 while ( (closest_bucket > 0) &&
799 GNUNET_free (pi->hello);
800 GNUNET_free (pi);
801}
802
803
812static unsigned int
813get_forward_count (uint16_t hop_count,
814 uint16_t target_replication)
815{
816 uint32_t random_value;
817 uint32_t forward_count;
818 float target_value;
819 double rm1;
820
821 if (hop_count > GDS_NSE_get () * 4.0)
822 {
823 /* forcefully terminate */
825 "# requests TTL-dropped",
826 1,
827 GNUNET_NO);
828 return 0;
829 }
830 if (hop_count > GDS_NSE_get () * 2.0)
831 {
832 /* Once we have reached our ideal number of hops, only forward to 1 peer */
833 return 1;
834 }
835 /* bound by system-wide maximum and minimum */
836 if (0 == target_replication)
837 target_replication = 1; /* 0 is verboten */
838 target_replication =
840 target_replication);
841 rm1 = target_replication - 1.0;
842 target_value =
843 1 + (rm1) / (GDS_NSE_get () + (rm1 * hop_count));
844
845 /* Set forward count to floor of target_value */
846 forward_count = (uint32_t) target_value;
847 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
848 target_value = target_value - forward_count;
850 UINT32_MAX);
851 if (random_value < (target_value * UINT32_MAX))
852 forward_count++;
853 return GNUNET_MIN (forward_count,
855}
856
857
870 const struct GNUNET_CONTAINER_BloomFilter *bloom)
871{
872 const struct GNUNET_HashCode *my_identity_hash;
873 int delta;
874 my_identity_hash = GNUNET_PILS_get_identity_hash (GDS_pils);
875 GNUNET_assert (NULL != my_identity_hash);
876 if (0 == GNUNET_memcmp (my_identity_hash, key))
877 return GNUNET_YES;
878 for (int bucket_num = find_bucket (key);
879 bucket_num < closest_bucket;
880 bucket_num++)
881 {
882 unsigned int count = 0;
883 GNUNET_assert (bucket_num >= 0);
884 for (struct PeerInfo *pos = k_buckets[bucket_num].head;
885 NULL != pos;
886 pos = pos->next)
887 {
888 if (count >= bucket_size)
889 break; /* we only consider first #bucket_size entries per bucket */
890 count++;
891 if ( (NULL != bloom) &&
892 (GNUNET_YES ==
894 &pos->phash)) )
895 continue; /* Ignore filtered peers */
896 /* All peers in this bucket must be closer than us, as
897 they mismatch with our PID on the pivotal bit. So
898 because an unfiltered peer exists, we are not the
899 closest. */
900 delta = GNUNET_CRYPTO_hash_xorcmp (&pos->phash,
901 my_identity_hash,
902 key);
903 switch (delta)
904 {
905 case -1: /* pos closer */
906 return GNUNET_NO;
907 case 0: /* identical, impossible! */
908 GNUNET_assert (0);
909 break;
910 case 1: /* I am closer */
911 break;
912 }
913 }
914 }
915 /* No closer (unfiltered) peers found; we must be the closest! */
916 return GNUNET_YES;
917}
918
919
941static struct PeerInfo *
943 const struct GNUNET_CONTAINER_BloomFilter *bloom,
944 uint32_t hops)
945{
946 if (0 == closest_bucket)
947 {
949 "# Peer selection failed",
950 1,
951 GNUNET_NO);
952 return NULL; /* we have zero connections */
953 }
954 if (hops >= GDS_NSE_get ())
955 {
956 /* greedy selection (closest peer that is not in Bloom filter) */
957 struct PeerInfo *chosen = NULL;
958 int best_bucket;
959 int bucket_offset;
960
961 {
962 const struct GNUNET_HashCode *my_identity_hash;
963 struct GNUNET_HashCode xor;
964 my_identity_hash = GNUNET_PILS_get_identity_hash (GDS_pils);
965 GNUNET_assert (NULL != my_identity_hash);
967 my_identity_hash,
968 &xor);
969 best_bucket = GNUNET_CRYPTO_hash_count_leading_zeros (&xor);
970 }
971 if (best_bucket >= closest_bucket)
972 bucket_offset = closest_bucket - 1;
973 else
974 bucket_offset = best_bucket;
975 while (-1 != bucket_offset)
976 {
977 struct PeerBucket *bucket = &k_buckets[bucket_offset];
978 unsigned int count = 0;
979
980 for (struct PeerInfo *pos = bucket->head;
981 NULL != pos;
982 pos = pos->next)
983 {
984 if (count >= bucket_size)
985 break; /* we only consider first #bucket_size entries per bucket */
986 count++;
987 if ( (NULL != bloom) &&
988 (GNUNET_YES ==
990 &pos->phash)) )
991 {
993 "Excluded peer `%s' due to BF match in greedy routing for %s\n",
994 GNUNET_i2s (&pos->id),
995 GNUNET_h2s (key));
996 continue;
997 }
998 if (NULL == chosen)
999 {
1000 /* First candidate */
1001 chosen = pos;
1002 }
1003 else
1004 {
1005 int delta = GNUNET_CRYPTO_hash_xorcmp (&pos->phash,
1006 &chosen->phash,
1007 key);
1008 switch (delta)
1009 {
1010 case -1: /* pos closer */
1011 chosen = pos;
1012 break;
1013 case 0: /* identical, impossible! */
1014 GNUNET_assert (0);
1015 break;
1016 case 1: /* chosen closer */
1017 break;
1018 }
1019 }
1020 count++;
1021 } /* for all (#bucket_size) peers in bucket */
1022 if (NULL != chosen)
1023 break;
1024
1025 /* If we chose nothing in first iteration, first go through deeper
1026 buckets (best chance to find a good match), and if we still found
1027 nothing, then to shallower buckets. Terminate on any match in the
1028 current bucket, as this search order guarantees that it can only get
1029 worse as we keep going. */
1030 if (bucket_offset > best_bucket)
1031 {
1032 /* Go through more deeper buckets */
1033 bucket_offset++;
1034 if (bucket_offset == closest_bucket)
1035 {
1036 /* Can't go any deeper, if nothing selected,
1037 go for shallower buckets */
1038 bucket_offset = best_bucket - 1;
1039 }
1040 }
1041 else
1042 {
1043 /* We're either at the 'best_bucket' or already moving
1044 on to shallower buckets. */
1045 if (bucket_offset == best_bucket)
1046 bucket_offset++; /* go for deeper buckets */
1047 else
1048 bucket_offset--; /* go for shallower buckets */
1049 }
1050 } /* for applicable buckets (starting at best match) */
1051 if (NULL == chosen)
1052 {
1054 "# Peer selection failed",
1055 1,
1056 GNUNET_NO);
1057 return NULL;
1058 }
1060 "Selected peer `%s' in greedy routing for %s\n",
1061 GNUNET_i2s (&chosen->id),
1062 GNUNET_h2s (key));
1063 return chosen;
1064 } /* end of 'greedy' peer selection */
1065
1066 /* select "random" peer */
1067 /* count number of peers that are available and not filtered,
1068 but limit to at most #bucket_size peers, starting with
1069 those 'furthest' from us. */
1070 {
1071 unsigned int total = 0;
1072 unsigned int selected;
1073
1074 for (unsigned int bc = 0; bc < closest_bucket; bc++)
1075 {
1076 struct PeerBucket *bucket = &k_buckets[bc];
1077 unsigned int count = 0;
1078
1079 for (struct PeerInfo *pos = bucket->head;
1080 NULL != pos;
1081 pos = pos->next)
1082 {
1083 count++;
1084 if (count > bucket_size)
1085 break; /* limits search to #bucket_size peers per bucket */
1086 if ( (NULL != bloom) &&
1087 (GNUNET_YES ==
1089 &pos->phash)) )
1090 {
1092 "Excluded peer `%s' due to BF match in random routing for %s\n",
1093 GNUNET_i2s (&pos->id),
1094 GNUNET_h2s (key));
1095 continue; /* Ignore filtered peers */
1096 }
1097 total++;
1098 } /* for all peers in bucket */
1099 } /* for all buckets */
1100 if (0 == total) /* No peers to select from! */
1101 {
1103 "# Peer selection failed",
1104 1,
1105 GNUNET_NO);
1106 return NULL;
1107 }
1108
1109 /* Now actually choose a peer */
1111 total);
1112 for (unsigned int bc = 0; bc < closest_bucket; bc++)
1113 {
1114 unsigned int count = 0;
1115
1116 for (struct PeerInfo *pos = k_buckets[bc].head;
1117 pos != NULL;
1118 pos = pos->next)
1119 {
1120 count++;
1121 if (count > bucket_size)
1122 break; /* limits search to #bucket_size peers per bucket */
1123
1124 if ( (NULL != bloom) &&
1125 (GNUNET_YES ==
1127 &pos->phash)) )
1128 continue; /* Ignore bloomfiltered peers */
1129 if (0 == selected--)
1130 {
1132 "Selected peer `%s' in random routing for %s\n",
1133 GNUNET_i2s (&pos->id),
1134 GNUNET_h2s (key));
1135 return pos;
1136 }
1137 } /* for peers in bucket */
1138 } /* for all buckets */
1139 } /* random peer selection scope */
1140 GNUNET_break (0);
1141 return NULL;
1142}
1143
1144
1158static unsigned int
1160 struct GNUNET_CONTAINER_BloomFilter *bloom,
1161 uint16_t hop_count,
1162 uint16_t target_replication,
1163 struct PeerInfo ***targets)
1164{
1165 unsigned int target;
1166 unsigned int off;
1167 struct PeerInfo **rtargets;
1168
1169 GNUNET_assert (NULL != bloom);
1170 target = get_forward_count (hop_count,
1171 target_replication);
1172 if (0 == target)
1173 {
1174 *targets = NULL;
1175 return 0;
1176 }
1177 rtargets = GNUNET_new_array (target,
1178 struct PeerInfo *);
1179 for (off = 0; off < target; off++)
1180 {
1181 struct PeerInfo *nxt;
1182
1183 nxt = select_peer (key,
1184 bloom,
1185 hop_count);
1186 if (NULL == nxt)
1187 break;
1188 rtargets[off] = nxt;
1189 }
1191 "Selected %u/%u peers at hop %u for %s (target was %u)\n",
1192 off,
1194 (unsigned int) hop_count,
1195 GNUNET_h2s (key),
1196 target);
1197 if (0 == off)
1198 {
1199 GNUNET_free (rtargets);
1200 *targets = NULL;
1201 return 0;
1202 }
1203 *targets = rtargets;
1205 "Forwarding query `%s' to %u peers (goal was %u peers)\n",
1206 GNUNET_h2s (key),
1207 off,
1208 target);
1209 return off;
1210}
1211
1212
1218static void
1220{
1221 struct GNUNET_HELLO_Parser *b;
1222
1224 return;
1225
1227 bd->data_size);
1229 {
1232 NULL);
1233 }
1235}
1236
1237
1239{
1240 unsigned int hop_count;
1241 unsigned int target_count;
1244 unsigned int index;
1245 unsigned int *queued;
1247 void *cb_cls;
1248};
1249
1250
1251static bool
1253 size_t msize,
1254 struct PeerPutMessage *ppm)
1255{
1256 struct GDS_RoutingPutCallbackData *gds_routing = cls;
1257 struct PeerInfo *target;
1258
1259 if (NULL == ppm)
1260 {
1261 *(gds_routing->queued) = *(gds_routing->queued) + 1;
1262 if (*(gds_routing->queued) >= gds_routing->target_count)
1263 {
1264 if (gds_routing->cb)
1265 gds_routing->cb (gds_routing->cb_cls, GNUNET_SYSERR);
1266
1267 GNUNET_free (gds_routing->targets);
1268 GNUNET_free (gds_routing->queued);
1269 }
1270
1271 return true;
1272 }
1273
1274 target = gds_routing->targets[gds_routing->index];
1275
1277 "Routing PUT for %s after %u hops to %s\n",
1278 GNUNET_h2s (&(gds_routing->key)),
1279 (unsigned int) gds_routing->hop_count,
1280 GNUNET_i2s (&target->id));
1281 do_send (target,
1282 &ppm->header);
1283 *(gds_routing->queued) = *(gds_routing->queued) + 1;
1284
1285 if (*(gds_routing->queued) >= gds_routing->target_count)
1286 {
1287 if (gds_routing->cb)
1288 gds_routing->cb (gds_routing->cb_cls, GNUNET_OK);
1289
1290 GNUNET_free (gds_routing->targets);
1292 "# PUT messages queued for transmission",
1293 gds_routing->target_count,
1294 GNUNET_NO);
1295 GNUNET_free (gds_routing->queued);
1296 }
1297
1298 return true;
1299}
1300
1301
1302void
1304 uint16_t desired_replication_level,
1305 uint16_t hop_count,
1308 void *cb_cls)
1309{
1310 const struct GNUNET_PeerIdentity *my_identity;
1311 const struct GNUNET_HashCode *my_identity_hash;
1312 struct GDS_RoutingPutCallbackData gds_routing;
1313 size_t msize;
1314 enum GNUNET_DHT_RouteOption ro = bd->ro;
1315 unsigned int put_path_length = bd->put_path_length;
1316 const struct GNUNET_DHT_PathElement *put_path = bd->put_path;
1317 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1318 const struct GNUNET_PeerIdentity *trunc_peer
1319 = truncated
1320 ? &bd->trunc_peer
1321 : NULL;
1322 struct GNUNET_PeerIdentity trunc_peer_out;
1324
1326 my_identity_hash = GNUNET_PILS_get_identity_hash (GDS_pils);
1327 GNUNET_assert (NULL != my_identity);
1328
1331 bd->ro, &ro,
1332 bd->expiration_time,
1333 bd->data, bd->data_size,
1334 put_path, put_path_length,
1335 &put_path_length,
1336 trunc_peer,
1337 &trunc_peer_out,
1338 &truncated);
1339 if (truncated)
1340 trunc_peer = &trunc_peer_out;
1341 /* Path may have been truncated by the call above */
1343 "Adding myself (%s) to PUT bloomfilter for %s with RO(%s/%s)\n",
1345 GNUNET_h2s (&bd->key),
1346 (bd->ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-",
1347 (bd->ro & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-");
1348
1349 /* if we got a HELLO, consider it for our own routing table */
1350 hello_check (bd);
1351 GNUNET_assert ((NULL != bf) && (NULL != my_identity_hash));
1352 GNUNET_CONTAINER_bloomfilter_add (bf, my_identity_hash);
1354 "# PUT requests routed",
1355 1,
1356 GNUNET_NO);
1357 if (GNUNET_OK != ret)
1358 {
1359 if (cb)
1360 cb (cb_cls, ret);
1361 return;
1362 }
1363 gds_routing.target_count
1364 = get_target_peers (&bd->key,
1365 bf,
1366 hop_count,
1367 desired_replication_level,
1368 &(gds_routing.targets));
1369 if (0 == gds_routing.target_count)
1370 {
1372 "Routing PUT for %s terminates after %u hops at %s\n",
1373 GNUNET_h2s (&bd->key),
1374 (unsigned int) hop_count,
1376 if (cb)
1377 cb (cb_cls, GNUNET_NO);
1378 if (gds_routing.targets)
1379 GNUNET_free (gds_routing.targets);
1380 return;
1381 }
1382 GNUNET_memcpy (&(gds_routing.key), &(bd->key),
1383 sizeof (gds_routing.key));
1384 for (unsigned int i = 0; i < gds_routing.target_count; i++)
1385 {
1386 struct PeerInfo *target = gds_routing.targets[i];
1387
1389 &target->phash);
1390 }
1391
1392 gds_routing.queued = GNUNET_new (unsigned int);
1393 *(gds_routing.queued) = 0;
1394
1395 gds_routing.cb = cb;
1396 gds_routing.cb_cls = cb_cls;
1397
1398 for (unsigned int i = 0; i < gds_routing.target_count; i++)
1399 {
1400 struct PeerInfo *target = gds_routing.targets[i];
1401 struct PeerPutMessage *ppm;
1402 char buf[msize] GNUNET_ALIGN;
1403
1404 gds_routing.index = i;
1405
1406 ppm = (struct PeerPutMessage *) buf;
1407 GDS_helper_make_put_message (ppm, msize,
1408 NULL,
1409 &target->id,
1410 &target->phash,
1411 bf,
1412 &bd->key,
1413 ro,
1414 bd->type,
1415 bd->expiration_time,
1416 bd->data, bd->data_size,
1417 put_path, put_path_length,
1418 hop_count,
1420 trunc_peer,
1422 sizeof (gds_routing),
1423 &gds_routing);
1424 }
1425}
1426
1427
1432 uint16_t hop_count,
1433 const struct GNUNET_HashCode *key,
1434 const void *xquery,
1435 size_t xquery_size,
1436 struct GNUNET_BLOCK_Group *bg,
1437 struct GNUNET_CONTAINER_BloomFilter *peer_bf)
1438{
1439 const struct GNUNET_PeerIdentity *my_identity;
1440 const struct GNUNET_HashCode *my_identity_hash;
1441 unsigned int target_count;
1442 struct PeerInfo **targets;
1443 size_t msize;
1444 size_t result_filter_size;
1445 void *result_filter;
1446
1448 my_identity_hash = GNUNET_PILS_get_identity_hash (GDS_pils);
1449
1450 if (NULL == my_identity_hash)
1451 return GNUNET_NO;
1452
1453 GNUNET_assert (NULL != peer_bf);
1455 "# GET requests routed",
1456 1,
1457 GNUNET_NO);
1458 target_count = get_target_peers (key,
1459 peer_bf,
1460 hop_count,
1461 desired_replication_level,
1462 &targets);
1464 "Adding myself (%s) to GET bloomfilter for %s with RO(%s/%s)\n",
1466 GNUNET_h2s (key),
1468 (options & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-");
1469 GNUNET_assert (NULL != my_identity_hash);
1470 GNUNET_CONTAINER_bloomfilter_add (peer_bf, my_identity_hash);
1471 if (0 == target_count)
1472 {
1474 "Routing GET for %s terminates after %u hops at %s\n",
1475 GNUNET_h2s (key),
1476 (unsigned int) hop_count,
1478 return GNUNET_NO;
1479 }
1480 if (GNUNET_OK !=
1482 &result_filter,
1483 &result_filter_size))
1484 {
1485 result_filter = NULL;
1486 result_filter_size = 0;
1487 }
1488 msize = xquery_size + result_filter_size;
1489 if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE)
1490 {
1491 GNUNET_break (0);
1492 GNUNET_free (result_filter);
1493 GNUNET_free (targets);
1494 return GNUNET_NO;
1495 }
1496 /* update BF */
1497 for (unsigned int i = 0; i < target_count; i++)
1498 {
1499 struct PeerInfo *target = targets[i];
1500
1502 &target->phash);
1503 }
1504 /* forward request */
1505 for (unsigned int i = 0; i < target_count; i++)
1506 {
1507 struct PeerInfo *target = targets[i];
1508 struct PeerGetMessage *pgm;
1509 char buf[sizeof (*pgm) + msize] GNUNET_ALIGN;
1510 char *rf;
1511
1513 "Routing GET for %s after %u hops to %s\n",
1514 GNUNET_h2s (key),
1515 (unsigned int) hop_count,
1516 GNUNET_i2s (&target->id));
1517 pgm = (struct PeerGetMessage *) buf;
1519 pgm->header.size = htons (sizeof (buf));
1520 pgm->type = htonl (type);
1521 pgm->options = htons (options);
1522 pgm->hop_count = htons (hop_count + 1);
1524 pgm->result_filter_size = htons ((uint16_t) result_filter_size);
1527 pgm->bloomfilter,
1529 pgm->key = *key;
1530 rf = (char *) &pgm[1];
1531 GNUNET_memcpy (rf,
1532 result_filter,
1535 xquery,
1536 xquery_size);
1537 do_send (target,
1538 &pgm->header);
1539 }
1541 "# GET messages queued for transmission",
1542 target_count,
1543 GNUNET_NO);
1544 GNUNET_free (targets);
1545 GNUNET_free (result_filter);
1546 return (0 < target_count) ? GNUNET_OK : GNUNET_NO;
1547}
1548
1549
1550struct PeerInfo *
1556
1557
1573
1574
1575static void
1577{
1578 if (reply->block_data)
1579 GNUNET_free (reply->block_data);
1580 if ((reply->bd.put_path_length > 0) && (reply->put_path))
1581 GNUNET_free (reply->put_path);
1582 if (reply->buf)
1583 GNUNET_free (reply->buf);
1584}
1585
1586
1587static void
1590 bool success)
1591{
1592 GNUNET_break (success);
1593 if (cb)
1594 cb (cls);
1595}
1596
1597
1598static bool
1600 const struct GNUNET_CRYPTO_EddsaSignature *sig)
1601{
1602 struct GDS_NeighboursReply *reply = cls;
1603 struct PeerResultMessage *prm = reply->prm;
1604 struct GNUNET_DHT_PathElement *paths = reply->paths;
1605 unsigned int ppl = ntohs (prm->put_path_length);
1606 unsigned int get_path_length = ntohs (prm->get_path_length);
1607 void *tgt = &paths[get_path_length + ppl];
1608 void *data;
1609
1610 if (! sig)
1611 {
1613 safe_neighbours_callback (reply->cb_cls, reply->cb, false);
1614 return true;
1615 }
1616
1617 memcpy (tgt,
1618 sig,
1619 sizeof (*sig));
1620 data = tgt + sizeof (*sig);
1622 "Signing GET PATH %u/%u of %s => %s\n",
1623 ppl,
1624 get_path_length,
1625 GNUNET_h2s (&prm->key),
1626 GNUNET_B2S (sig));
1627#if SANITY_CHECKS > 1
1628 {
1629 const struct GNUNET_PeerIdentity *my_identity;
1630 struct GNUNET_DHT_PathElement xpaths[get_path_length + 1];
1631 const struct GNUNET_PeerIdentity *trunc_peer = reply->trunc_peer_is_null?
1632 NULL : &reply->trunc_peer_id;
1633
1635 GNUNET_assert (NULL != my_identity);
1636
1637 memcpy (xpaths,
1638 &paths[ppl],
1639 get_path_length * sizeof (struct GNUNET_DHT_PathElement));
1640 xpaths[get_path_length].sig = *sig;
1641 xpaths[get_path_length].pred = *my_identity;
1642 if (0 !=
1644 reply->bd.data_size,
1645 reply->bd.expiration_time,
1646 trunc_peer,
1647 paths,
1648 ppl,
1649 xpaths,
1650 get_path_length + 1,
1651 &reply->pi->id))
1652 {
1653 GNUNET_break (0);
1655 safe_neighbours_callback (reply->cb_cls, reply->cb, false);
1656 return true;
1657 }
1658 }
1659#endif
1661 reply->bd.data,
1662 reply->bd.data_size);
1663 do_send (reply->pi,
1664 &prm->header);
1666 safe_neighbours_callback (reply->cb_cls, reply->cb, true);
1667 return true;
1668}
1669
1670
1671void
1673 const struct GNUNET_DATACACHE_Block *bd,
1674 const struct GNUNET_HashCode *query_hash,
1675 unsigned int get_path_length,
1676 const struct GNUNET_DHT_PathElement *get_path,
1678 void *cb_cls)
1679{
1680 struct GNUNET_DHT_PathElement *paths;
1681 size_t msize;
1682 unsigned int ppl = bd->put_path_length;
1683 const struct GNUNET_DHT_PathElement *put_path = bd->put_path;
1684 enum GNUNET_DHT_RouteOption ro = bd->ro;
1685 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
1686 const struct GNUNET_PeerIdentity *trunc_peer
1687 = truncated
1688 ? &bd->trunc_peer
1689 : NULL;
1690 bool tracking = (0 != (ro & GNUNET_DHT_RO_RECORD_ROUTE));
1691#if SANITY_CHECKS > 1
1692 const struct GNUNET_PeerIdentity *my_identity;
1693 unsigned int failure_offset;
1694
1696 GNUNET_assert (NULL != my_identity);
1697
1698 failure_offset
1700 bd->data_size,
1701 bd->expiration_time,
1702 trunc_peer,
1703 put_path,
1704 ppl,
1705 get_path,
1706 get_path_length,
1707 my_identity);
1708 if (0 != failure_offset)
1709 {
1710 GNUNET_assert (failure_offset <= ppl + get_path_length);
1711 GNUNET_break_op (0);
1712 if (failure_offset < ppl)
1713 {
1714 trunc_peer = &put_path[failure_offset - 1].pred;
1715 put_path += failure_offset;
1716 ppl -= failure_offset;
1717 truncated = true;
1719 }
1720 else
1721 {
1722 failure_offset -= ppl;
1723 if (0 == failure_offset)
1724 trunc_peer = &put_path[ppl - 1].pred;
1725 else
1726 trunc_peer = &get_path[failure_offset - 1].pred;
1727 ppl = 0;
1728 put_path = NULL;
1729 truncated = true;
1731 get_path += failure_offset;
1732 get_path_length -= failure_offset;
1733 }
1734 }
1735#endif
1736 msize = bd->data_size + sizeof (struct PeerResultMessage);
1737 if (msize > GNUNET_MAX_MESSAGE_SIZE)
1738 {
1739 GNUNET_break_op (0);
1740 safe_neighbours_callback (cb_cls, cb, false);
1741 return;
1742 }
1743 if (truncated)
1744 msize += sizeof (struct GNUNET_PeerIdentity);
1745 if (tracking)
1746 msize += sizeof (struct GNUNET_CRYPTO_EddsaSignature);
1747 if (msize < bd->data_size)
1748 {
1749 GNUNET_break_op (0);
1750 safe_neighbours_callback (cb_cls, cb, false);
1751 return;
1752 }
1753 if ( (GNUNET_MAX_MESSAGE_SIZE - msize)
1754 / sizeof(struct GNUNET_DHT_PathElement)
1755 < (get_path_length + ppl) )
1756 {
1757 get_path_length = 0;
1758 ppl = 0;
1759 }
1760 if ( (get_path_length > UINT16_MAX) ||
1761 (ppl > UINT16_MAX) )
1762 {
1763 GNUNET_break (0);
1764 get_path_length = 0;
1765 ppl = 0;
1766 }
1767 msize += (get_path_length + ppl)
1768 * sizeof(struct GNUNET_DHT_PathElement);
1770 "Forwarding reply for key %s to peer %s\n",
1771 GNUNET_h2s (query_hash),
1772 GNUNET_i2s (&pi->id));
1774 "# RESULT messages queued for transmission",
1775 1,
1776 GNUNET_NO);
1777 {
1778 struct PeerResultMessage *prm;
1779 char buf[msize] GNUNET_ALIGN;
1780
1781 prm = (struct PeerResultMessage *) buf;
1783 prm->header.size = htons (sizeof (buf));
1784 prm->type = htonl ((uint32_t) bd->type);
1785 prm->reserved = htons (0);
1786 prm->options = htons ((uint16_t) ro);
1787 prm->put_path_length = htons ((uint16_t) ppl);
1788 prm->get_path_length = htons ((uint16_t) get_path_length);
1790 prm->key = *query_hash;
1791 if (truncated)
1792 {
1793 void *tgt = &prm[1];
1794
1795 GNUNET_memcpy (tgt,
1796 trunc_peer,
1797 sizeof (struct GNUNET_PeerIdentity));
1798 paths = (struct GNUNET_DHT_PathElement *)
1799 (tgt + sizeof (struct GNUNET_PeerIdentity));
1800 }
1801 else
1802 {
1803 paths = (struct GNUNET_DHT_PathElement *) &prm[1];
1804 }
1805 if (NULL != put_path)
1806 {
1807 GNUNET_memcpy (paths,
1808 put_path,
1809 ppl * sizeof(struct GNUNET_DHT_PathElement));
1810 }
1811 else
1812 {
1813 GNUNET_assert (0 == ppl);
1814 }
1815 if (NULL != get_path)
1816 {
1817 GNUNET_memcpy (&paths[ppl],
1818 get_path,
1819 get_path_length * sizeof(struct GNUNET_DHT_PathElement));
1820 }
1821 else
1822 {
1823 GNUNET_assert (0 == get_path_length);
1824 }
1825 if (tracking)
1826 {
1827 struct GDS_NeighboursReply reply;
1828 const struct GNUNET_PeerIdentity *pred;
1829
1830 reply.pi = pi;
1831 GNUNET_memcpy (&reply.bd, bd, sizeof (reply.bd));
1832 reply.block_data = GNUNET_memdup (bd->data, bd->data_size);
1833 reply.put_path = GNUNET_memdup (bd->put_path,
1834 sizeof (struct GNUNET_DHT_PathElement)
1835 * bd->put_path_length);
1836
1837 reply.bd.data = reply.block_data;
1838 reply.bd.put_path = reply.put_path;
1839
1840 reply.buf = GNUNET_memdup (buf, msize);
1841 reply.prm = (struct PeerResultMessage*) reply.buf;
1842 reply.paths = (struct GNUNET_DHT_PathElement*) (reply.buf + (buf - (const
1843 char*)
1844 paths));
1845
1846 if (trunc_peer)
1847 {
1848 reply.trunc_peer_is_null = false;
1849 GNUNET_memcpy (&reply.trunc_peer_id, trunc_peer,
1850 sizeof (reply.trunc_peer_id));
1851 }
1852 else
1853 {
1854 reply.trunc_peer_is_null = true;
1855 }
1856
1857 reply.cb = cb;
1858 reply.cb_cls = cb_cls;
1859
1860 if (ppl + get_path_length > 0)
1861 pred = &paths[ppl + get_path_length - 1].pred;
1862 else if (truncated)
1863 pred = trunc_peer;
1864 else
1865 pred = NULL; /* we are first! */
1866 /* Note that the last signature in 'paths' was not initialized before,
1867 so this is crucial to avoid sending garbage. */
1869 bd->data_size,
1870 NULL,
1871 bd->expiration_time,
1872 pred,
1873 &pi->id,
1875 sizeof (reply),
1876 &reply);
1877 }
1878 else
1879 {
1880 void *data;
1881 data = &prm[1];
1883 bd->data,
1884 bd->data_size);
1885 do_send (pi,
1886 &prm->header);
1887 safe_neighbours_callback (cb_cls, cb, true);
1888 return;
1889 }
1890 }
1891}
1892
1893
1901static enum GNUNET_GenericReturnValue
1903 const struct PeerPutMessage *put)
1904{
1905 enum GNUNET_DHT_RouteOption ro = ntohs (put->options);
1906 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
1907 bool has_path = (0 != (ro & GNUNET_DHT_RO_RECORD_ROUTE));
1908 uint16_t msize = ntohs (put->header.size);
1909 uint16_t putlen = ntohs (put->put_path_length);
1910 size_t xsize = (has_path
1911 ? sizeof (struct GNUNET_CRYPTO_EddsaSignature)
1912 : 0)
1913 + (truncated
1914 ? sizeof (struct GNUNET_PeerIdentity)
1915 : 0);
1916 size_t var_meta_size
1917 = putlen * sizeof(struct GNUNET_DHT_PathElement)
1918 + xsize;
1919
1920 (void) cls;
1921 if ( (msize <
1922 sizeof (struct PeerPutMessage) + var_meta_size) ||
1923 (putlen >
1924 (GNUNET_MAX_MESSAGE_SIZE
1925 - sizeof (struct PeerPutMessage)
1926 - xsize)
1927 / sizeof(struct GNUNET_DHT_PathElement)) )
1928 {
1929 GNUNET_break_op (0);
1930 return GNUNET_SYSERR;
1931 }
1932 if (GNUNET_BLOCK_TYPE_ANY == htonl (put->type))
1933 {
1934 GNUNET_break_op (0);
1935 return GNUNET_SYSERR;
1936 }
1937 return GNUNET_OK;
1938}
1939
1940
1951
1952
1953static void
1955 enum GNUNET_GenericReturnValue forwarded)
1956{
1957 struct ForwardedDHTPut *put = cls;
1958
1959 /* notify monitoring clients */
1960 put->block.ro |= ((GNUNET_OK == forwarded)
1962 : 0);
1964 put->hop_count,
1966
1967 if (put->put_path)
1968 GNUNET_free (put->put_path);
1969 GNUNET_free (put->data);
1970 GNUNET_free (put);
1971}
1972
1973
1980static void
1982 const struct PeerPutMessage *put)
1983{
1984 struct Target *t = cls;
1985 struct PeerInfo *peer = t->pi;
1986 enum GNUNET_DHT_RouteOption ro = ntohs (put->options);
1987 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
1988 bool has_path = (0 != (ro & GNUNET_DHT_RO_RECORD_ROUTE));
1989 uint16_t msize = ntohs (put->header.size);
1990 uint16_t putlen = ntohs (put->put_path_length);
1991 const struct GNUNET_PeerIdentity *trunc_peer
1992 = truncated
1993 ? (const struct GNUNET_PeerIdentity *) &put[1]
1994 : NULL;
1995 const struct GNUNET_DHT_PathElement *put_path
1996 = truncated
1997 ? (const struct GNUNET_DHT_PathElement *) &trunc_peer[1]
1998 : (const struct GNUNET_DHT_PathElement *) &put[1];
1999 const struct GNUNET_CRYPTO_EddsaSignature *last_sig
2000 = has_path
2001 ? (const struct GNUNET_CRYPTO_EddsaSignature *) &put_path[putlen]
2002 : NULL;
2003 const char *data
2004 = has_path
2005 ? (const char *) &last_sig[1]
2006 : (const char *) &put_path[putlen];
2007 size_t var_meta_size
2008 = putlen * sizeof(struct GNUNET_DHT_PathElement)
2009 + (has_path ? sizeof (*last_sig) : 0)
2010 + (truncated ? sizeof (*trunc_peer) : 0);
2011 struct GNUNET_DATACACHE_Block bd = {
2012 .key = put->key,
2013 .expiration_time = GNUNET_TIME_absolute_ntoh (put->expiration_time),
2014 .type = ntohl (put->type),
2015 .ro = ro,
2016 .data_size = msize - sizeof(*put) - var_meta_size,
2017 .data = data
2018 };
2019
2020 if (NULL != trunc_peer)
2021 bd.trunc_peer = *trunc_peer;
2023 "PUT for `%s' from %s with RO (%s/%s)\n",
2024 GNUNET_h2s (&put->key),
2025 GNUNET_i2s (&peer->id),
2026 (bd.ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-",
2027 has_path ? "R" : "-");
2029 {
2031 "# Expired PUTs discarded",
2032 1,
2033 GNUNET_NO);
2034 return;
2035 }
2036 {
2037 /* Only call 'check_block' if that keeps our CPU load (from
2038 the cryptography) below 50% on average */
2039 static struct GNUNET_TIME_Relative avg_latency;
2040 static struct GNUNET_TIME_Absolute next_time;
2041
2042 if (GNUNET_TIME_absolute_is_past (next_time))
2043 {
2044 struct GNUNET_TIME_Absolute now
2046 struct GNUNET_TIME_Relative latency;
2048
2049 if (GNUNET_NO ==
2051 bd.type,
2052 bd.data,
2053 bd.data_size))
2054 {
2055 GNUNET_break_op (0);
2056 return;
2057 }
2058 latency = GNUNET_TIME_absolute_get_duration (now);
2059 /* Use *moving average* to estimate check_block latency */
2060 avg_latency
2063 GNUNET_TIME_relative_multiply (avg_latency,
2064 7),
2065 latency),
2066 8);
2067 /* average delay = 50% of avg_latency => 50% CPU load from crypto (at most) */
2070 avg_latency.rel_value_us > 0
2071 ? avg_latency.rel_value_us
2072 : 1LLU);
2074 }
2075 }
2076 if (! has_path)
2077 putlen = 0;
2079 "# P2P PUT requests received",
2080 1,
2081 GNUNET_NO);
2083 "# P2P PUT bytes received",
2084 msize,
2085 GNUNET_NO);
2086 {
2087 struct GNUNET_HashCode test_key;
2089
2091 bd.type,
2092 bd.data,
2093 bd.data_size,
2094 &test_key);
2095 switch (ret)
2096 {
2097 case GNUNET_YES:
2098 if (0 != GNUNET_memcmp (&test_key,
2099 &bd.key))
2100 {
2101 GNUNET_break_op (0);
2102 return;
2103 }
2104 break;
2105 case GNUNET_NO:
2106 /* cannot verify, good luck */
2107 break;
2108 case GNUNET_SYSERR:
2109 /* block type not supported, good luck */
2110 break;
2111 }
2112 }
2113
2114 {
2116 struct GNUNET_DHT_PathElement pp[putlen + 1];
2117
2123 &peer->phash));
2124 /* extend 'put path' by sender */
2125 bd.put_path = pp;
2126 bd.put_path_length = putlen + 1;
2127 if (has_path)
2128 {
2129 unsigned int failure_offset;
2130
2131 GNUNET_memcpy (pp,
2132 put_path,
2133 putlen * sizeof(struct GNUNET_DHT_PathElement));
2134 pp[putlen].pred = peer->id;
2135 pp[putlen].sig = *last_sig;
2136#if SANITY_CHECKS
2137 {
2138 const struct GNUNET_PeerIdentity *my_identity;
2140 GNUNET_assert (NULL != my_identity);
2141 /* TODO: might want to eventually implement probabilistic
2142 load-based path verification, but for now it is all or nothing */
2143 failure_offset
2145 bd.data_size,
2146 bd.expiration_time,
2147 trunc_peer,
2148 pp,
2149 putlen + 1,
2150 NULL, 0, /* get_path */
2151 my_identity);
2152 }
2153#else
2154 failure_offset = 0;
2155#endif
2156 if (0 != failure_offset)
2157 {
2158 GNUNET_break_op (0);
2160 "Recorded put path invalid at offset %u, truncating\n",
2161 failure_offset);
2162 GNUNET_assert (failure_offset <= putlen + 1);
2163 bd.put_path = &pp[failure_offset];
2164 bd.put_path_length = (putlen + 1) - failure_offset;
2166 bd.trunc_peer = pp[failure_offset - 1].pred;
2167 }
2168 }
2169 else
2170 {
2171 bd.put_path_length = 0;
2172 }
2173
2174 /* give to local clients */
2176 &bd.key,
2177 0, NULL /* get path */));
2178
2179 /* store locally */
2180 if ( (0 != (bd.ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
2181 (GDS_am_closest_peer (&put->key,
2182 bf)) )
2184
2185 {
2187 GNUNET_memcpy (&forward->block, &bd, sizeof (bd));
2188
2189 if (bd.put_path_length > 0)
2190 {
2191 forward->put_path = GNUNET_memdup (
2192 bd.put_path,
2193 sizeof (struct GNUNET_DHT_PathElement) * bd.put_path_length);
2194 forward->block.put_path = forward->put_path;
2195 }
2196
2197 forward->data = GNUNET_memdup (bd.data, bd.data_size);
2198 forward->block.data = forward->data;
2199
2200 forward->desired_replication_level = ntohs (put->desired_replication_level
2201 );
2202 forward->hop_count = ntohs (put->hop_count);
2203
2204 /* route to other peers */
2206 forward->desired_replication_level,
2207 forward->hop_count,
2208 bf,
2210 forward);
2211 }
2213 }
2214}
2215
2216
2218{
2219 struct PeerInfo *pi;
2222};
2223
2224
2233static void
2235 const struct GNUNET_HashCode *query_hash,
2236 struct GNUNET_BLOCK_Group *bg,
2238 void *cb_cls)
2239{
2240 const struct GNUNET_HashCode *my_identity_hash;
2241 const struct GNUNET_PeerIdentity *my_identity;
2242 struct GNUNET_TIME_Absolute block_expiration;
2243 size_t block_size;
2244 void *block;
2245
2246 my_identity_hash = GNUNET_PILS_get_identity_hash (GDS_pils);
2249 "Handle finding my own HELLO %s\n",
2250 GNUNET_h2s (my_identity_hash));
2251 if (NULL == GDS_my_hello)
2252 {
2254 "# FIND PEER requests ignored due to lack of HELLO",
2255 1,
2256 GNUNET_NO);
2257 if (cb)
2258 cb (cb_cls);
2259 return;
2260 }
2261
2264 &block,
2265 &block_size,
2266 &block_expiration))
2267 {
2268 if (cb)
2269 cb (cb_cls);
2270 return;
2271 }
2272
2276 bg,
2277 my_identity_hash,
2278 NULL, 0,
2279 block,
2280 block_size))
2281 {
2282 struct GNUNET_DATACACHE_Block bd = {
2284 .expiration_time
2287 .key = *my_identity_hash,
2288 .data = block,
2289 .data_size = block_size
2290 };
2291
2293 &bd,
2294 query_hash,
2295 0, NULL /* get path */,
2296 cb,
2297 cb_cls);
2298 }
2299 else
2300 {
2302 "# FIND PEER requests ignored due to Bloomfilter",
2303 1,
2304 GNUNET_NO);
2305 if (cb)
2306 cb (cb_cls);
2307 }
2308
2309 GNUNET_free (block);
2310}
2311
2312
2321static void
2323 const struct GNUNET_HashCode *query_hash,
2324 struct GNUNET_BLOCK_Group *bg,
2326 void *cb_cls)
2327{
2328 /* Force non-random selection by hop count */
2329 struct PeerInfo *peer;
2330
2331 peer = select_peer (query_hash,
2332 NULL,
2333 GDS_NSE_get () + 1);
2335 "Handle finding local HELLO %s\n",
2336 GNUNET_h2s (&peer->phash));
2337 if ( (NULL != peer->hello) &&
2343 bg,
2344 &peer->phash,
2345 NULL, 0, /* xquery */
2346 peer->hello,
2347 peer->hello_size)) )
2348 {
2349 struct GNUNET_DATACACHE_Block bd = {
2351 .expiration_time = peer->hello_expiration,
2352 .key = peer->phash,
2353 .data = peer->hello,
2354 .data_size = peer->hello_size
2355 };
2356
2358 &bd,
2359 query_hash,
2360 0, NULL /* get path */,
2361 cb,
2362 cb_cls);
2363 }
2364 else if (cb)
2365 cb (cb_cls);
2366}
2367
2368
2375
2376
2383static void
2385 const struct GNUNET_DATACACHE_Block *bd)
2386{
2387 struct HandleCallbackLocal *local = cls;
2388
2390 bd,
2391 &bd->key,
2392 0, NULL /* get path */,
2393 local->cb,
2394 local->cb_cls);
2395}
2396
2397
2405static enum GNUNET_GenericReturnValue
2407 const struct PeerGetMessage *get)
2408{
2409 uint16_t msize = ntohs (get->header.size);
2410 uint16_t result_filter_size = ntohs (get->result_filter_size);
2411
2412 (void) cls;
2413 if (msize < sizeof(*get) + result_filter_size)
2414 {
2415 GNUNET_break_op (0);
2416 return GNUNET_SYSERR;
2417 }
2418 return GNUNET_OK;
2419}
2420
2421
2430
2431
2432static void
2434{
2435 struct HandleCallbackGet *handle = cls;
2436 enum GNUNET_DHT_RouteOption options = ntohs (handle->get->options);
2437 enum GNUNET_BLOCK_Type type = ntohl (handle->get->type);
2438 const void *result_filter = (const void *) &handle->get[1];
2439 uint16_t msize = ntohs (handle->get->header.size);
2440 uint16_t result_filter_size = ntohs (handle->get->result_filter_size);
2441 const void *xquery = result_filter + result_filter_size;
2442 size_t xquery_size = msize - sizeof (*handle->get) - result_filter_size;
2443
2444 /* remember request for routing replies
2445 TODO: why should we do this if GNUNET_BLOCK_REPLY_OK_LAST == eval?
2446 */
2447 GDS_ROUTING_add (&handle->t->pi->id,
2448 type,
2449 handle->bg, /* bg now owned by routing, but valid at least until end of this function! */
2450 options,
2451 &handle->get->key,
2452 xquery,
2453 xquery_size);
2454
2455 /* P2P forwarding */
2456 {
2457 bool forwarded = false;
2458 uint16_t desired_replication_level = ntohs (
2459 handle->get->desired_replication_level);
2460 uint16_t hop_count = ntohs (handle->get->hop_count);
2461
2463 forwarded = (GNUNET_OK ==
2465 options,
2466 desired_replication_level,
2467 hop_count,
2468 &handle->get->key,
2469 xquery,
2470 xquery_size,
2471 handle->bg,
2472 handle->peer_bf));
2474 options
2475 | (forwarded
2476 ? 0
2478 type,
2479 hop_count,
2480 desired_replication_level,
2481 &handle->get->key);
2482 }
2483 /* clean up; note that 'bg' is owned by routing now! */
2485
2486 GNUNET_free (handle->get);
2488}
2489
2490
2491static void
2493{
2494 struct HandleCallbackGet *handle = cls;
2495 enum GNUNET_BLOCK_Type type = ntohl (handle->get->type);
2496
2498 "Handle getting local HELLO %s of type %u\n",
2499 GNUNET_h2s (&handle->get->key),
2500 type);
2501
2503 {
2504 enum GNUNET_DHT_RouteOption options = ntohs (handle->get->options);
2505 const void *result_filter = (const void *) &handle->get[1];
2506 uint16_t msize = ntohs (handle->get->header.size);
2507 uint16_t result_filter_size = ntohs (handle->get->result_filter_size);
2508 const void *xquery = result_filter + result_filter_size;
2509 size_t xquery_size = msize - sizeof (*handle->get) - result_filter_size;
2510 struct HandleCallbackLocal local;
2511 local.peer = handle->t->pi;
2513 local.cb_cls = handle;
2514
2516 handle->eval = GDS_DATACACHE_get_closest (&handle->get->key,
2517 type,
2518 xquery,
2519 xquery_size,
2520 handle->bg,
2522 &local);
2523 else
2524 handle->eval = GDS_DATACACHE_handle_get (&handle->get->key,
2525 type,
2526 xquery,
2527 xquery_size,
2528 handle->bg,
2530 &local);
2531 }
2532 else
2534}
2535
2536
2537static void
2539{
2540 struct HandleCallbackGet *handle = cls;
2541 enum GNUNET_DHT_RouteOption options = ntohs (handle->get->options);
2542
2545 &handle->get->key,
2546 handle->bg,
2548 handle);
2549 else
2551}
2552
2553
2560static void
2562 const struct PeerGetMessage *get)
2563{
2564 struct Target *t = cls;
2565 struct PeerInfo *peer = t->pi;
2566 uint16_t msize = ntohs (get->header.size);
2567 uint16_t result_filter_size = ntohs (get->result_filter_size);
2568 uint16_t hop_count = ntohs (get->hop_count);
2569 enum GNUNET_BLOCK_Type type = ntohl (get->type);
2570 enum GNUNET_DHT_RouteOption options = ntohs (get->options);
2571 const void *result_filter = (const void *) &get[1];
2572 const void *xquery = result_filter + result_filter_size;
2573 size_t xquery_size = msize - sizeof (*get) - result_filter_size;
2574
2575 /* parse and validate message */
2577 "# P2P GET requests received",
2578 1,
2579 GNUNET_NO);
2581 "# P2P GET bytes received",
2582 msize,
2583 GNUNET_NO);
2584 if (GNUNET_NO ==
2586 type,
2587 &get->key,
2588 xquery,
2589 xquery_size))
2590 {
2591 /* request invalid */
2592 GNUNET_break_op (0);
2593 return;
2594 }
2595
2596 {
2597 const struct GNUNET_PeerIdentity *my_identity;
2598 struct HandleCallbackGet *handle;
2599
2601 handle->t = t;
2602 handle->get = GNUNET_memdup (get, msize);
2604
2606 GNUNET_assert (NULL != my_identity);
2607
2608 handle->peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter,
2613 &peer->phash));
2615 type,
2616 result_filter,
2617 result_filter_size,
2618 "filter-size",
2619 result_filter_size,
2620 NULL);
2622 "GET for %s at %s after %u hops\n",
2623 GNUNET_h2s (&get->key),
2625 (unsigned int) hop_count);
2626 /* local lookup (this may update the bg) */
2628 (GDS_am_closest_peer (&get->key,
2629 handle->peer_bf)) )
2630 {
2633 {
2635 "# P2P HELLO lookup requests processed",
2636 1,
2637 GNUNET_NO);
2639 &get->key,
2640 handle->bg,
2642 handle);
2643 }
2644 else
2646 }
2647 else
2648 {
2650 "# P2P GET requests ONLY routed",
2651 1,
2652 GNUNET_NO);
2654 }
2655 }
2656}
2657
2658
2667static void
2669 const struct GNUNET_HashCode *query_hash,
2670 unsigned int get_path_length,
2671 const struct GNUNET_DHT_PathElement *get_path)
2672{
2673 /* forward to local clients */
2675 "Forwarding reply to local clients\n");
2676 if (! GDS_CLIENTS_handle_reply (bd,
2677 query_hash,
2678 get_path_length,
2679 get_path))
2680 {
2681 GNUNET_break (0);
2682 return;
2683 }
2685 get_path,
2686 get_path_length);
2688 {
2689 struct GNUNET_DHT_PathElement xput_path[GNUNET_NZL (get_path_length
2690 + bd->put_path_length)];
2691 struct GNUNET_DATACACHE_Block bdx = *bd;
2692
2693 if (NULL != bd->put_path)
2694 GNUNET_memcpy (xput_path,
2695 bd->put_path,
2696 bd->put_path_length * sizeof(struct
2698 GNUNET_memcpy (&xput_path[bd->put_path_length],
2699 get_path,
2700 get_path_length * sizeof(struct GNUNET_DHT_PathElement));
2701 bdx.put_path = xput_path;
2702 bdx.put_path_length += get_path_length;
2704 }
2705 /* forward to other peers */
2707 query_hash,
2708 get_path_length,
2709 get_path);
2710}
2711
2712
2720static enum GNUNET_GenericReturnValue
2722 const struct PeerResultMessage *prm)
2723{
2724 uint16_t msize = ntohs (prm->header.size) - sizeof (*prm);
2725 enum GNUNET_DHT_RouteOption ro = ntohs (prm->options);
2726 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
2727 bool tracked = (0 != (ro & GNUNET_DHT_RO_RECORD_ROUTE));
2728
2729 uint16_t get_path_length = ntohs (prm->get_path_length);
2730 uint16_t put_path_length = ntohs (prm->put_path_length);
2731 size_t vsize = (truncated ? sizeof (struct GNUNET_PeerIdentity) : 0)
2732 + (tracked ? sizeof (struct GNUNET_CRYPTO_EddsaSignature) : 0);
2733
2734 (void) cls;
2735 if ( (msize < vsize) ||
2736 (msize - vsize <
2737 (get_path_length + put_path_length)
2738 * sizeof(struct GNUNET_DHT_PathElement)) ||
2739 (get_path_length >
2740 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) ||
2741 (put_path_length >
2742 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) )
2743 {
2744 GNUNET_break_op (0);
2745 return GNUNET_SYSERR;
2746 }
2747 return GNUNET_OK;
2748}
2749
2750
2757static void
2759 const struct PeerResultMessage *prm)
2760{
2761 struct Target *t = cls;
2762 struct PeerInfo *peer = t->pi;
2763 uint16_t msize = ntohs (prm->header.size) - sizeof (*prm);
2764 enum GNUNET_DHT_RouteOption ro = ntohs (prm->options);
2765 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
2766 bool tracked = (0 != (ro & GNUNET_DHT_RO_RECORD_ROUTE));
2767 uint16_t get_path_length = ntohs (prm->get_path_length);
2768 uint16_t put_path_length = ntohs (prm->put_path_length);
2769 const struct GNUNET_PeerIdentity *trunc_peer
2770 = truncated
2771 ? (const struct GNUNET_PeerIdentity *) &prm[1]
2772 : NULL;
2773 const struct GNUNET_DHT_PathElement *put_path
2774 = truncated
2775 ? (const struct GNUNET_DHT_PathElement *) &trunc_peer[1]
2776 : (const struct GNUNET_DHT_PathElement *) &prm[1];
2777 const struct GNUNET_DHT_PathElement *get_path
2778 = &put_path[put_path_length];
2779 const struct GNUNET_CRYPTO_EddsaSignature *last_sig
2780 = tracked
2781 ? (const struct GNUNET_CRYPTO_EddsaSignature *) &get_path[get_path_length]
2782 : NULL;
2783 const void *data
2784 = tracked
2785 ? (const void *) &last_sig[1]
2786 : (const void *) &get_path[get_path_length];
2787 size_t vsize = (truncated ? sizeof (struct GNUNET_PeerIdentity) : 0)
2788 + (tracked ? sizeof (struct GNUNET_CRYPTO_EddsaSignature) : 0);
2789 struct GNUNET_DATACACHE_Block bd = {
2791 .put_path = put_path,
2792 .put_path_length = put_path_length,
2793 .key = prm->key,
2794 .type = ntohl (prm->type),
2795 .ro = ro,
2796 .data = data,
2797 .data_size = msize - vsize - (get_path_length + put_path_length)
2798 * sizeof(struct GNUNET_DHT_PathElement)
2799 };
2800
2801 /* parse and validate message */
2802 if (GNUNET_TIME_absolute_is_past (bd.expiration_time))
2803 {
2805 "# Expired results discarded",
2806 1,
2807 GNUNET_NO);
2808 return;
2809 }
2810 if (GNUNET_OK !=
2812 bd.type,
2813 bd.data,
2814 bd.data_size))
2815 {
2816 GNUNET_break_op (0);
2817 return;
2818 }
2820 "# P2P RESULTS received",
2821 1,
2822 GNUNET_NO);
2824 "# P2P RESULT bytes received",
2825 msize,
2826 GNUNET_NO);
2827 {
2829
2831 bd.type,
2832 bd.data,
2833 bd.data_size,
2834 &bd.key);
2835 if (GNUNET_NO == ret)
2836 bd.key = prm->key;
2837 }
2838
2839 /* if we got a HELLO, consider it for our own routing table */
2840 hello_check (&bd);
2841
2842 /* Need to append 'peer' to 'get_path' */
2843 if (tracked)
2844 {
2845 struct GNUNET_DHT_PathElement xget_path[get_path_length + 1];
2846 struct GNUNET_DHT_PathElement *gp = xget_path;
2847 unsigned int failure_offset;
2848
2849 GNUNET_memcpy (xget_path,
2850 get_path,
2851 get_path_length * sizeof(struct GNUNET_DHT_PathElement));
2852 xget_path[get_path_length].pred = peer->id;
2853 /* use memcpy(), as last_sig may not be aligned */
2854 memcpy (&xget_path[get_path_length].sig,
2855 last_sig,
2856 sizeof (*last_sig));
2857#if SANITY_CHECKS
2858 {
2859 const struct GNUNET_PeerIdentity *my_identity;
2861 GNUNET_assert (NULL != my_identity);
2862 /* TODO: might want to eventually implement probabilistic
2863 load-based path verification, but for now it is all or nothing */
2864 failure_offset
2865 = GNUNET_DHT_verify_path (bd.data,
2866 bd.data_size,
2867 bd.expiration_time,
2868 trunc_peer,
2869 put_path,
2870 put_path_length,
2871 gp,
2872 get_path_length + 1,
2873 my_identity);
2874 }
2875#else
2876 failure_offset = 0;
2877#endif
2878 if (0 != failure_offset)
2879 {
2881 "Recorded path invalid at offset %u, truncating\n",
2882 failure_offset);
2883 GNUNET_assert (failure_offset <= bd.put_path_length + get_path_length
2884 + 1);
2885 if (failure_offset < bd.put_path_length)
2886 {
2887 /* failure on put path */
2888 trunc_peer = &bd.put_path[failure_offset - 1].pred;
2889 bd.ro |= GNUNET_DHT_RO_TRUNCATED;
2890 bd.put_path = &bd.put_path[failure_offset];
2891 bd.put_path_length -= failure_offset;
2892 truncated = true;
2893 }
2894 else
2895 {
2896 /* failure on get path */
2897 failure_offset -= bd.put_path_length;
2898 if (0 == failure_offset)
2899 trunc_peer = &bd.put_path[bd.put_path_length - 1].pred;
2900 else
2901 trunc_peer = &gp[failure_offset - 1].pred;
2902 get_path_length -= failure_offset;
2903 gp = &gp[failure_offset];
2904 bd.put_path_length = 0;
2905 bd.put_path = NULL;
2906 bd.ro |= GNUNET_DHT_RO_TRUNCATED;
2907 truncated = true;
2908 }
2909 }
2911 "Extending GET path of length %u with %s\n",
2912 get_path_length,
2913 GNUNET_i2s (&peer->id));
2914 if (truncated)
2915 {
2916 GNUNET_assert (NULL != trunc_peer);
2917 bd.trunc_peer = *trunc_peer;
2918 }
2920 &prm->key,
2921 get_path_length + 1,
2922 gp);
2923 }
2924 else
2925 {
2926 if (truncated)
2927 {
2928 GNUNET_assert (NULL != trunc_peer);
2929 bd.trunc_peer = *trunc_peer;
2930 }
2932 &prm->key,
2933 0,
2934 NULL);
2935 }
2936}
2937
2938
2946static enum GNUNET_GenericReturnValue
2948 const struct GNUNET_MessageHeader *hello)
2949{
2950 struct Target *t = cls;
2951 struct PeerInfo *peer = t->pi;
2953 size_t hellob_size;
2954 void *hellob;
2956
2958 &peer->id,
2959 &hellob,
2960 &hellob_size,
2961 &expiration);
2962 GNUNET_free (hellob);
2963 return ret;
2964}
2965
2966
2973static void
2975 const struct GNUNET_MessageHeader *hello)
2976{
2977 struct Target *t = cls;
2978 struct PeerInfo *peer = t->pi;
2979
2980 GNUNET_free (peer->hello);
2981 peer->hello_size = 0;
2984 &peer->id,
2985 &peer->hello,
2986 &peer->hello_size,
2987 &peer->hello_expiration));
2988}
2989
2990
2991void
2992GDS_u_receive (void *cls,
2993 void **tctx,
2994 void **sctx,
2995 const void *message,
2996 size_t message_size)
2997{
2998 struct Target *t = *tctx;
2999 struct GNUNET_MQ_MessageHandler core_handlers[] = {
3000 GNUNET_MQ_hd_var_size (dht_p2p_get,
3002 struct PeerGetMessage,
3003 t),
3004 GNUNET_MQ_hd_var_size (dht_p2p_put,
3006 struct PeerPutMessage,
3007 t),
3008 GNUNET_MQ_hd_var_size (dht_p2p_result,
3010 struct PeerResultMessage,
3011 t),
3012 GNUNET_MQ_hd_var_size (dht_p2p_hello,
3014 struct GNUNET_MessageHeader,
3015 t),
3017 };
3018 const struct GNUNET_MessageHeader *mh = message;
3019
3020 (void) cls; /* the 'struct GDS_Underlay' */
3021 (void) sctx; /* our receiver address */
3022 if (NULL == t)
3023 {
3024 /* Received message claiming to originate from myself?
3025 Ignore! */
3026 GNUNET_break_op (0);
3027 return;
3028 }
3029 if (message_size < sizeof (*mh))
3030 {
3031 GNUNET_break_op (0);
3032 return;
3033 }
3034 if (message_size != ntohs (mh->size))
3035 {
3036 GNUNET_break_op (0);
3037 return;
3038 }
3040 "Handling message of type %u from peer %s\n",
3041 ntohs (mh->type),
3042 GNUNET_i2s (&t->pi->id));
3043 if (GNUNET_OK !=
3044 GNUNET_MQ_handle_message (core_handlers,
3045 mh))
3046 {
3047 GNUNET_break_op (0);
3048 return;
3049 }
3050}
3051
3052
3060void
3062 const struct GNUNET_PeerIdentity *pid,
3063 const char *uri)
3064{
3065 const struct GNUNET_PeerIdentity *my_identity;
3066 struct GNUNET_HashCode phash;
3067 int peer_bucket;
3068 struct PeerBucket *bucket;
3069 (void) cls;
3070
3072 GNUNET_assert (NULL != my_identity);
3073
3074 if (0 == GNUNET_memcmp (my_identity, pid))
3075 {
3077 "Got a HELLO for my own PID, ignoring it\n");
3078 return; /* that's us! */
3079 }
3081 sizeof(*pid),
3082 &phash);
3083 peer_bucket = find_bucket (&phash);
3084 GNUNET_assert ( (peer_bucket >= 0) &&
3085 ((unsigned int) peer_bucket < MAX_BUCKETS));
3086 bucket = &k_buckets[peer_bucket];
3087 for (struct PeerInfo *pi = bucket->head;
3088 NULL != pi;
3089 pi = pi->next)
3090 if (0 ==
3091 GNUNET_memcmp (&pi->id,
3092 pid))
3093 {
3094 /* already connected */
3096 uri);
3097 return;
3098 }
3099 if (bucket->peers_size >= bucket_size)
3100 return; /* do not care */
3102 "Discovered peer %s at %s suitable for bucket %d (%u/%u), trying to connect\n",
3103 GNUNET_i2s (pid),
3104 uri,
3105 peer_bucket,
3106 bucket->peers_size,
3107 bucket_size);
3108 /* new peer that we like! */
3110 uri);
3111}
3112
3113
3119void
3121{
3122 for (unsigned int bc = 0; bc<closest_bucket; bc++)
3123 {
3124 struct PeerBucket *bucket = &k_buckets[bc];
3125 unsigned int count = 0;
3126
3127 for (struct PeerInfo *pos = bucket->head;
3128 NULL != pos;
3129 pos = pos->next)
3130 {
3131 if (count >= bucket_size)
3132 break; /* we only consider first #bucket_size entries per bucket */
3133 count++;
3134 do_send (pos,
3135 msg);
3136 }
3137 }
3138}
3139
3140
3143{
3144
3145 unsigned long long temp_config_num;
3146
3149 "DHT",
3150 "DISABLE_TRY_CONNECT");
3151 if (GNUNET_OK ==
3153 "DHT",
3154 "bucket_size",
3155 &temp_config_num))
3156 bucket_size = (unsigned int) temp_config_num;
3159 "DHT",
3160 "CACHE_RESULTS");
3162 GNUNET_YES);
3163 return GNUNET_OK;
3164}
3165
3166
3167void
3178
3179
3180const struct GNUNET_PeerIdentity *
3185
3186
3187/* end of gnunet-service-dht_neighbours.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
struct GNUNET_MessageHeader * msg
Definition 005.c:2
static mp_limb_t u[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition dht.h:34
bool GDS_helper_make_put_message(struct PeerPutMessage *ppm, size_t msize, const struct GNUNET_CRYPTO_EddsaPrivateKey *sk, const struct GNUNET_PeerIdentity *target, const struct GNUNET_HashCode *target_hash, const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *block_key, enum GNUNET_DHT_RouteOption ro, enum GNUNET_BLOCK_Type block_type, struct GNUNET_TIME_Absolute block_expiration_time, const uint8_t *block_data, size_t block_data_len, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_len, size_t hop_count, uint32_t desired_replication_level, const struct GNUNET_PeerIdentity *trunc_peer, GDS_HelperMsgCallback cb, size_t cb_data_size, void *cb_data)
Definition dht_helper.c:326
bool GDS_helper_sign_path(const void *data, size_t data_size, const struct GNUNET_CRYPTO_EddsaPrivateKey *sk, struct GNUNET_TIME_Absolute exp_time, const struct GNUNET_PeerIdentity *pred, const struct GNUNET_PeerIdentity *succ, GDS_HelperCallback cb, size_t cb_data_size, void *cb_data)
Sign that we are routing a message from pred to succ.
Definition dht_helper.c:226
enum GNUNET_GenericReturnValue GDS_helper_put_message_get_size(size_t *msize_out, const struct GNUNET_PeerIdentity *my_identity, enum GNUNET_DHT_RouteOption ro_in, enum GNUNET_DHT_RouteOption *ro_out, struct GNUNET_TIME_Absolute block_expiration_time, const uint8_t *block_data, size_t block_data_len, const struct GNUNET_DHT_PathElement *put_path_in, unsigned int put_path_len_in, unsigned int *put_path_len_out, const struct GNUNET_PeerIdentity *trunc_peer, struct GNUNET_PeerIdentity *trunc_peer_out, bool *truncated)
Definition dht_helper.c:96
Helper functions for DHT.
struct GNUNET_PILS_Handle * GDS_pils
Handle for the pils service.
static int forward
Search direction: forward.
Definition gnunet-abd.c:163
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CADET_Handle * mh
Cadet handle.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
static int get
Get DID Documement for DID Flag.
Definition gnunet-did.c:63
static struct GNUNET_FS_Handle * ctx
static struct GNUNET_SCHEDULER_Task * t
Main task.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
double GDS_NSE_get(void)
Return the current NSE.
struct GNUNET_MessageHeader * GDS_my_hello
Our HELLO.
struct GNUNET_DHTU_PreferenceHandle * GDS_u_hold(struct GDS_Underlay *u, struct GNUNET_DHTU_Target *target)
Create a hold on target at underlay u.
void GDS_u_send(struct GDS_Underlay *u, struct GNUNET_DHTU_Target *target, const void *msg, size_t msg_size, GNUNET_SCHEDULER_TaskCallback finished_cb, void *finished_cb_cls)
Send message to some other participant over the network.
void GDS_u_drop(struct GDS_Underlay *u, struct GNUNET_DHTU_PreferenceHandle *ph)
Drop a hold ph from underlay u.
void GDS_u_try_connect(const struct GNUNET_PeerIdentity *pid, const char *address)
Ask all underlays to connect to peer pid at address.
GNUnet DHT globals.
void GDS_CLIENTS_process_get(enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, uint32_t hop_count, uint32_t desired_replication_level, const struct GNUNET_HashCode *key)
Check if some client is monitoring GET messages and notify them in that case.
void GDS_CLIENTS_process_get_resp(const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length)
Check if some client is monitoring GET RESP messages and notify them in that case.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
struct GNUNET_BLOCK_Context * GDS_block_context
Our handle to the BLOCK library.
void GDS_CLIENTS_process_put(const struct GNUNET_DATACACHE_Block *bd, uint32_t hop_count, uint32_t desired_replication_level)
Check if some client is monitoring PUT messages and notify them in that case.
bool GDS_CLIENTS_handle_reply(const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *get_path)
Handle a reply we've received from another peer.
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
enum GNUNET_BLOCK_ReplyEvaluationResult GDS_DATACACHE_get_closest(const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, const void *xquery, size_t xquery_size, struct GNUNET_BLOCK_Group *bg, GDS_DATACACHE_GetCallback cb, void *cb_cls)
Handle a request for data close to a key that we have received from another peer.
enum GNUNET_BLOCK_ReplyEvaluationResult GDS_DATACACHE_handle_get(const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, const void *xquery, size_t xquery_size, struct GNUNET_BLOCK_Group *bg, GDS_DATACACHE_GetCallback gc, void *gc_cls)
Handle a GET request we've received from another peer.
void GDS_DATACACHE_handle_put(const struct GNUNET_DATACACHE_Block *bd)
Handle a datum we've received from another peer.
static void send_find_peer_message(void *cls)
Task to send a find peer message for our own peer identifier so that we can find the closest peers in...
static void handle_dht_p2p_result(void *cls, const struct PeerResultMessage *prm)
Core handler for p2p result messages.
void GDS_NEIGHBOURS_handle_reply(struct PeerInfo *pi, const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *get_path, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Handle a reply (route to origin).
#define MAXIMUM_PENDING_PER_PEER
Maximum allowed number of pending messages per peer.
static int disable_try_connect
Option for testing that disables the 'connect' function of the DHT.
void GDS_try_connect(void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
Callback function used to extract URIs from a builder.
static void cleanup_neighbours_reply(struct GDS_NeighboursReply *reply)
struct PeerInfo * GDS_NEIGHBOURS_lookup_peer(const struct GNUNET_PeerIdentity *target)
Lookup peer by peer's identity.
static void handle_find_my_hello(struct PeerInfo *pi, const struct GNUNET_HashCode *query_hash, struct GNUNET_BLOCK_Group *bg, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
We have received a request for a HELLO.
static unsigned int newly_found_peers
How many peers have we added since we sent out our last find peer request?
static void send_done_cb(void *cls)
Function called whenever we finished sending to a target.
static struct PeerInfo * select_peer(const struct GNUNET_HashCode *key, const struct GNUNET_CONTAINER_BloomFilter *bloom, uint32_t hops)
Select a peer from the routing table that would be a good routing destination for sending a message f...
#define DEFAULT_BUCKET_SIZE
What is the maximum number of peers in a given bucket.
void GDS_NEIGHBOURS_done()
Shutdown neighbours subsystem.
void GDS_u_disconnect(void *ctx)
Function to call when we disconnected from a peer and can henceforth cannot transmit to that peer any...
static void handle_dht_p2p_hello(void *cls, const struct GNUNET_MessageHeader *hello)
Core handler for p2p HELLO messages.
static void cb_forwarded_dht_p2p_put(void *cls, enum GNUNET_GenericReturnValue forwarded)
static void handle_dht_p2p_get(void *cls, const struct PeerGetMessage *get)
Core handler for p2p get requests.
void GDS_NEIGHBOURS_broadcast(const struct GNUNET_MessageHeader *msg)
Send msg to all peers in our buckets.
#define FIND_PEER_REPLICATION_LEVEL
Desired replication level for FIND PEER requests.
static unsigned int get_forward_count(uint16_t hop_count, uint16_t target_replication)
To how many peers should we (on average) forward the request to obtain the desired target_replication...
static void do_send(struct PeerInfo *pi, const struct GNUNET_MessageHeader *msg)
Send msg to pi.
static int find_bucket(const struct GNUNET_HashCode *hc)
Find the optimal bucket for this key.
static enum GNUNET_GenericReturnValue check_dht_p2p_put(void *cls, const struct PeerPutMessage *put)
Check validity of a p2p put request.
static struct GNUNET_CONTAINER_MultiPeerMap * all_connected_peers
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect.
static void handle_local_result(void *cls, const struct GNUNET_DATACACHE_Block *bd)
Handle an exact result from local datacache for a GET operation.
static void cb_handle_dht_p2p_get_my_hello(void *cls)
#define DHT_MINIMUM_FIND_PEER_INTERVAL
How long at least to wait before sending another find peer request.
static int cache_results
Do we cache all results that we are routing in the local datacache?
void GDS_u_connect(void *cls, struct GNUNET_DHTU_Target *target, const struct GNUNET_PeerIdentity *pid, void **ctx)
Function to call when we connect to a peer and can henceforth transmit to that peer.
static enum GNUNET_GenericReturnValue check_dht_p2p_result(void *cls, const struct PeerResultMessage *prm)
Check validity of p2p result message.
static struct GNUNET_SCHEDULER_Task * find_peer_task
Task that sends FIND PEER requests.
static bool cb_routing_put_message(void *cls, size_t msize, struct PeerPutMessage *ppm)
#define MAX_BUCKETS
How many buckets will we allow in total.
static enum GNUNET_GenericReturnValue check_dht_p2p_get(void *cls, const struct PeerGetMessage *get)
Check validity of p2p get request.
static enum GNUNET_GenericReturnValue check_dht_p2p_hello(void *cls, const struct GNUNET_MessageHeader *hello)
Check validity of a p2p hello message.
static void cb_handle_dht_p2p_get_local_hello(void *cls)
static unsigned int get_target_peers(const struct GNUNET_HashCode *key, struct GNUNET_CONTAINER_BloomFilter *bloom, uint16_t hop_count, uint16_t target_replication, struct PeerInfo ***targets)
Compute the set of peers that the given request should be forwarded to.
static void hello_check(const struct GNUNET_DATACACHE_Block *bd)
If we got a HELLO, consider it for our own routing table.
static void safe_neighbours_callback(void *cls, GNUNET_SCHEDULER_TaskCallback cb, bool success)
static enum GNUNET_GenericReturnValue add_known_to_bloom(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Add each of the peers we already know to the Bloom filter of the request so that we don't get duplica...
static void handle_find_local_hello(struct PeerInfo *pi, const struct GNUNET_HashCode *query_hash, struct GNUNET_BLOCK_Group *bg, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
We have received a request for nearby HELLOs.
static unsigned int bucket_size
Maximum size for each bucket.
static void process_reply_with_path(const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *get_path)
Process a reply, after the get_path has been updated.
enum GNUNET_GenericReturnValue GDS_am_closest_peer(const struct GNUNET_HashCode *key, const struct GNUNET_CONTAINER_BloomFilter *bloom)
Check whether my identity is closer than any known peers.
static unsigned int closest_bucket
The lowest currently used bucket, initially 0 (for 0-bits matching bucket).
static bool cb_path_signed(void *cls, const struct GNUNET_CRYPTO_EddsaSignature *sig)
static struct PeerBucket k_buckets[sizeof(struct GNUNET_HashCode) *8]
The buckets.
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_init()
Initialize neighbours subsystem.
static void cb_handle_dht_p2p_get_local_result(void *cls)
static void update_hold(struct PeerBucket *bucket)
The list of the first bucket_size peers of bucket changed.
void GDS_u_receive(void *cls, void **tctx, void **sctx, const void *message, size_t message_size)
Function to call when we receive a message.
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type, enum GNUNET_DHT_RouteOption options, uint16_t desired_replication_level, uint16_t hop_count, const struct GNUNET_HashCode *key, const void *xquery, size_t xquery_size, struct GNUNET_BLOCK_Group *bg, struct GNUNET_CONTAINER_BloomFilter *peer_bf)
Perform a GET operation.
void GDS_NEIGHBOURS_handle_put(const struct GNUNET_DATACACHE_Block *bd, uint16_t desired_replication_level, uint16_t hop_count, struct GNUNET_CONTAINER_BloomFilter *bf, GDS_PutOperationCallback cb, void *cb_cls)
Perform a PUT operation.
const struct GNUNET_PeerIdentity * GDS_NEIGHBOURS_get_id()
Get the ID of the local node.
static void handle_dht_p2p_put(void *cls, const struct PeerPutMessage *put)
Core handler for p2p put requests.
#define DHT_AVG_FIND_PEER_INTERVAL
How long to additionally wait on average per bucket_size to send out the FIND PEER requests if we did...
GNUnet DHT routing code.
void(* GDS_PutOperationCallback)(void *cls, enum GNUNET_GenericReturnValue forwarded)
void GDS_ROUTING_add(const struct GNUNET_PeerIdentity *sender, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *bg, enum GNUNET_DHT_RouteOption options, const struct GNUNET_HashCode *key, const void *xquery, size_t xquery_size)
Add a new entry to our routing table.
void GDS_ROUTING_process(const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *get_path)
Handle a reply (route to origin).
GNUnet DHT tracking of requests for routing replies.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition gnunet-vpn.c:35
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
@ GNUNET_BLOCK_TYPE_DHT_HELLO
Type of a block that contains a DHT-NG HELLO for a peer.
API to the DHT service.
Helper library for handling HELLO URIs.
const struct GNUNET_HashCode * GNUNET_PILS_get_identity_hash(const struct GNUNET_PILS_Handle *handle)
Return the hash of the current peer identity from a given handle.
Definition pils_api.c:736
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
Constants for network protocols.
API to schedule computations using continuation passing style.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
enum GNUNET_GenericReturnValue GNUNET_BLOCK_group_set_seen(struct GNUNET_BLOCK_Group *bg, const struct GNUNET_HashCode *seen_results, unsigned int seen_results_count)
Update block group to filter out the given results.
Definition block.c:365
enum GNUNET_BLOCK_ReplyEvaluationResult GNUNET_BLOCK_check_reply(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *group, const struct GNUNET_HashCode *query, const void *xquery, size_t xquery_size, const void *reply_block, size_t reply_block_size)
Function called to validate if a reply is good for a particular query.
Definition block.c:339
enum GNUNET_GenericReturnValue GNUNET_BLOCK_check_block(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size)
Function called to validate a block.
Definition block.c:321
enum GNUNET_GenericReturnValue GNUNET_BLOCK_check_query(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *query, const void *xquery, size_t xquery_size)
Function called to validate a request.
Definition block.c:298
GNUNET_BLOCK_ReplyEvaluationResult
Possible ways for how a block may relate to a query.
void GNUNET_BLOCK_group_destroy(struct GNUNET_BLOCK_Group *bg)
Destroy resources used by a block group.
Definition block.c:194
enum GNUNET_GenericReturnValue GNUNET_BLOCK_group_serialize(struct GNUNET_BLOCK_Group *bg, void **raw_data, size_t *raw_data_size)
Serialize state of a block group.
Definition block.c:177
struct GNUNET_BLOCK_Group * GNUNET_BLOCK_group_create(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *raw_data, size_t raw_data_size,...)
Create a new block group.
Definition block.c:249
enum GNUNET_GenericReturnValue GNUNET_BLOCK_get_key(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size, struct GNUNET_HashCode *key)
Function called to obtain the key for a block.
Definition block.c:278
@ GNUNET_BLOCK_REPLY_OK_MORE
Valid result, and there may be more.
@ GNUNET_BLOCK_REPLY_OK_LAST
Last possible valid result.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
bool GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_get_raw_data(const struct GNUNET_CONTAINER_BloomFilter *bf, char *data, size_t size)
Copy the raw data of this Bloom filter into the given data array.
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associated with a filter in memory, flush to drive if needed (do not free the space on...
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_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
#define GNUNET_CONSTANTS_BLOOMFILTER_K
K-value that must be used for the bloom filters in 'GET' queries.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
GNUNET_DHT_RouteOption
Options for routing.
#define GNUNET_DHT_MAXIMUM_REPLICATION_LEVEL
Maximum allowed replication level for all requests.
unsigned int GNUNET_DHT_verify_path(const void *data, size_t data_size, struct GNUNET_TIME_Absolute exp_time, const struct GNUNET_PeerIdentity *trunc_peer, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_len, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_len, const struct GNUNET_PeerIdentity *me)
Verify signatures on a path consisting of put_path and get_path in reverse order (starting at the las...
Definition dht_api.c:1355
@ GNUNET_DHT_RO_TRUNCATED
Flag set if the path was truncated.
@ GNUNET_DHT_RO_RECORD_ROUTE
We should keep track of the route that the message took in the P2P network.
@ GNUNET_DHT_RO_LAST_HOP
Flag given to monitors if this was the last hop for a GET/PUT.
@ GNUNET_DHT_RO_FIND_APPROXIMATE
Approximate results are fine.
@ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
Each peer along the way should process the request (otherwise only peers locally closest to the key w...
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of 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_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b
int GNUNET_CRYPTO_hash_xorcmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2, const struct GNUNET_HashCode *target)
Find out which of the two GNUNET_CRYPTO_hash codes is closer to target in the XOR metric (Kademlia).
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.
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...
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
Definition hello-uri.c:380
enum GNUNET_GenericReturnValue GNUNET_HELLO_dht_msg_to_block(const struct GNUNET_MessageHeader *hello, const struct GNUNET_PeerIdentity *pid, void **block, size_t *block_size, struct GNUNET_TIME_Absolute *block_expiration)
Convert a DHT hello message to a HELLO block.
Definition hello-uri.c:1033
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_iterate(const struct GNUNET_HELLO_Parser *parser, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a parser.
Definition hello-uri.c:1011
#define GNUNET_HELLO_ADDRESS_EXPIRATION
For how long are HELLO signatures valid?
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_block(const void *block, size_t block_size)
Parse block.
Definition hello-uri.c:560
unsigned int GNUNET_CRYPTO_hash_count_leading_zeros(const struct GNUNET_HashCode *h)
Count the number of leading 0 bits in h.
#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_B2S(obj)
Convert a fixed-sized object to a string using GNUNET_b2s().
#define GNUNET_MAX(a, b)
#define GNUNET_NZL(l)
Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#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.
#define GNUNET_MIN(a, b)
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.
uint32_t bits[512/8/sizeof(uint32_t)]
@ 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).
#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.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
enum GNUNET_GenericReturnValue GNUNET_MQ_handle_message(const struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given h...
Definition mq.c:205
#define GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO
HELLO advertising a neighbours addresses.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
Data is returned to peer from DHT.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET
Peer tries to find data in DHT.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
Peer is storing data in DHT.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition time.c:438
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:737
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition time.c:583
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition time.c:486
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition time.c:548
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition time.c:667
static struct GNUNET_TIME_Relative delta
Definition speedup.c:36
const struct GNUNET_HashCode * query_hash
struct GNUNET_BLOCK_Group * bg
struct GNUNET_DATACACHE_Block block
struct GNUNET_DHT_PathElement * put_path
struct GNUNET_DHT_PathElement * paths
struct GNUNET_PeerIdentity trunc_peer_id
struct PeerResultMessage * prm
GNUNET_SCHEDULER_TaskCallback cb
struct GNUNET_DHT_PathElement * put_path
struct GNUNET_DATACACHE_Block bd
Information we keep per underlay.
Internal representation of the hash map.
an ECC signature using EdDSA.
Information about a block stored in the datacache.
const struct GNUNET_DHT_PathElement * put_path
PUT path taken by the block, array of peer identities.
enum GNUNET_BLOCK_Type type
Type of the block.
const void * data
Actual block data.
enum GNUNET_DHT_RouteOption ro
Options for routing for the block.
struct GNUNET_PeerIdentity trunc_peer
If the path was truncated, this is the peer ID at which the path was truncated.
struct GNUNET_HashCode key
Key of the block.
size_t data_size
Number of bytes in data.
unsigned int put_path_length
Length of the put_path array.
struct GNUNET_TIME_Absolute expiration_time
When does the block expire?
Opaque handle expressing a preference of the DHT to keep a particular target connected.
Opaque handle that the underlay offers for the target peer when sending messages to another peer.
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
struct GNUNET_PeerIdentity pred
Previous peer on the path (matches "pred" in the signed field).
struct GNUNET_CRYPTO_EddsaSignature sig
Signature affirming the hop of type GNUNET_SIGNATURE_PURPOSE_DHT_HOP.
Context for parsing HELLOs.
Definition hello-uri.c:233
A 512-bit hashcode.
Message handler for a specific message type.
Header for all communications.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition scheduler.c:141
struct GNUNET_SCHEDULER_Task * next
This is a linked list.
Definition scheduler.c:145
Time for absolute time used by GNUnet, in microseconds and in network byte order.
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.
struct GNUNET_CONTAINER_BloomFilter * peer_bf
struct GNUNET_BLOCK_Group * bg
enum GNUNET_BLOCK_ReplyEvaluationResult eval
GNUNET_SCHEDULER_TaskCallback cb
Peers are grouped into buckets.
struct PeerInfo * head
Head of DLL.
struct PeerInfo * tail
Tail of DLL.
unsigned int peers_size
Number of peers in the bucket.
uint16_t result_filter_size
Size of the result filter.
char bloomfilter[128]
Bloomfilter (for peer identities) to stop circular routes.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_P2P_GET.
uint16_t desired_replication_level
Desired replication level for this request.
uint16_t options
Processing options.
struct GNUNET_HashCode key
The key we are looking for.
uint32_t type
Desired content type.
Entry for a peer in a bucket.
struct GNUNET_TIME_Absolute hello_expiration
When does our HELLO from this peer expire?
size_t hello_size
Number of bytes in hello.
struct PeerInfo * next
Next peer entry (DLL)
struct GNUNET_PeerIdentity id
What is the identity of the peer?
struct Target * t_tail
Tail of DLL of targets for this peer.
struct PeerInfo * prev
Prev peer entry (DLL)
struct GNUNET_HashCode phash
Hash of id.
int peer_bucket
Which bucket is this peer in?
struct Target * t_head
Head of DLL of targets for this peer.
void * hello
Block with a HELLO of this peer.
P2P PUT message.
Definition dht.h:429
uint16_t desired_replication_level
Replication level for this message.
Definition dht.h:453
uint16_t hop_count
Hop count.
Definition dht.h:448
uint32_t type
Content type, must not be zero.
Definition dht.h:438
char bloomfilter[128]
Bloomfilter (for peer identities) to stop circular routes.
Definition dht.h:468
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_P2P_PUT.
Definition dht.h:433
struct GNUNET_HashCode key
The key we are storing under.
Definition dht.h:473
uint16_t options
Processing options.
Definition dht.h:443
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?
Definition dht.h:463
uint16_t put_path_length
Length of the PUT path that follows (if tracked).
Definition dht.h:458
uint16_t get_path_length
Length of the GET path that follows (if tracked).
uint16_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value in NBO.
struct GNUNET_HashCode key
The key of the corresponding GET request.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT.
uint16_t put_path_length
Length of the PUT path that follows (if tracked).
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?
List of targets that we can use to reach this peer.
struct Target * prev
Kept in a DLL.
struct PeerInfo * pi
Peer this is a target for.
struct Target * next
Kept in a DLL.
unsigned int load
Set to number of messages are waiting for the transmission to finish.
struct GNUNET_DHTU_PreferenceHandle * ph
Handle used to 'hold' the connection to this peer.
struct GDS_Underlay * u
Underlay providing this target.
struct GNUNET_DHTU_Target * utarget
Handle for sending messages to this peer.
bool dropped
Set to true if the target was dropped, but we could not clean up yet because busy was also true.