GNUnet 0.21.1
gnunet-service-dht_clients.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2011, 2016, 2017, 2022 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 "platform.h"
28#include "gnunet_constants.h"
29#include "gnunet_protocols.h"
32#include "gnunet-service-dht.h"
35#include "dht.h"
36
37
44#define SANITY_CHECKS 0
45
49#define LOG_TRAFFIC(kind, ...) GNUNET_log_from (kind, "dht-traffic", \
50 __VA_ARGS__)
51
52#define LOG(kind, ...) GNUNET_log_from (kind, "dht-clients", __VA_ARGS__)
53
54
60struct ClientHandle;
61
62
67{
72
77
82
87
91 const void *xquery;
92
97
102
108
113
117 uint64_t unique_id;
118
123
127 unsigned int seen_replies_count;
128
132 uint32_t replication;
133
138
143};
144
145
150{
155
160
165
170
175
179 int16_t get;
180
184 int16_t get_resp;
185
189 uint16_t put;
190
191};
192
193
200{
205
210
215
220};
221
222
227
232
237
242
247
252
257
262
267
268
274static void
276{
277 struct ClientHandle *ch = record->ch;
278
280 ch->cqr_tail,
281 record);
284 &record->key,
285 record));
286 if (NULL != record->hnode)
288 GNUNET_array_grow (record->seen_replies,
289 record->seen_replies_count,
290 0);
292}
293
294
304static void *
307 struct GNUNET_MQ_Handle *mq)
308{
309 struct ClientHandle *ch;
310
311 (void) cls;
312 ch = GNUNET_new (struct ClientHandle);
313 ch->client = client;
314 ch->mq = mq;
315 return ch;
316}
317
318
327static void
330 void *app_ctx)
331{
332 struct ClientHandle *ch = app_ctx;
333
334 (void) cls;
335 (void) client;
337 "Local client %p disconnects\n",
338 ch);
339 {
341
343 NULL != monitor;
344 monitor = next)
345 {
346 next = monitor->next;
347 if (monitor->ch != ch)
348 continue;
351 monitor);
353 }
354 }
355
356 {
357 struct ClientQueryRecord *cqr;
358
359 while (NULL != (cqr = ch->cqr_head))
361 }
362 GNUNET_free (ch);
363}
364
365
373static void
375{
376 struct GNUNET_BLOCK_Group *bg;
377 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
378
380 "# GET requests from clients injected",
381 1,
382 GNUNET_NO);
384 cqr->type,
385 NULL, /* raw data */
386 0, /* raw data size */
387 "seen-set-size",
389 NULL);
391 cqr->seen_replies,
392 cqr->seen_replies_count);
393 peer_bf
398 "Initiating GET for %s, replication %u, already have %u replies\n",
399 GNUNET_h2s (&cqr->key),
400 cqr->replication,
401 cqr->seen_replies_count);
403 cqr->msg_options,
404 cqr->replication,
405 0 /* hop count */,
406 &cqr->key,
407 cqr->xquery,
408 cqr->xquery_size,
409 bg,
410 peer_bf);
413
414 /* Exponential back-off for retries.
415 * max. is #GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */
418}
419
420
428static void
430{
431 struct ClientQueryRecord *cqr;
432
433 (void) cls;
434 retry_task = NULL;
435 while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
436 {
437 cqr->hnode = NULL;
439 {
440 cqr->hnode
442 cqr,
447 NULL);
448 return;
449 }
450 transmit_request (cqr);
451 cqr->hnode
453 cqr,
455 }
456}
457
458
468 const struct GNUNET_DHT_ClientPutMessage *dht_msg)
469{
470 uint32_t replication_level = ntohl (dht_msg->desired_replication_level);
471
472 (void) cls;
474 {
475 GNUNET_break_op (0);
476 return GNUNET_SYSERR;
477 }
478 return GNUNET_OK;
479}
480
481
488static void
490 const struct GNUNET_DHT_ClientPutMessage *dht_msg)
491{
492 struct ClientHandle *ch = cls;
493 uint16_t size = ntohs (dht_msg->header.size);
494 uint32_t replication_level
495 = ntohl (dht_msg->desired_replication_level);
496 struct GNUNET_DATACACHE_Block bd = {
497 .key = dht_msg->key,
498 .expiration_time = GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
499 .data = &dht_msg[1],
500 .data_size = size - sizeof (*dht_msg),
501 .type = ntohl (dht_msg->type),
502 .ro = (enum GNUNET_DHT_RouteOption) ntohl (dht_msg->options)
503 };
504
506 "Handling local PUT of %lu-bytes for query %s of type %u\n",
507 (unsigned long) (size - sizeof(struct GNUNET_DHT_ClientPutMessage)),
508 GNUNET_h2s (&dht_msg->key),
509 (unsigned int) bd.type);
510#if SANITY_CHECKS > 0
511 if (GNUNET_OK !=
513 bd.type,
514 bd.data,
515 bd.data_size))
516 {
517 GNUNET_break (0);
518 return;
519 }
520#endif
522 "# PUT requests received from clients",
523 1,
524 GNUNET_NO);
526 "CLIENT-PUT %s\n",
527 GNUNET_h2s_full (&dht_msg->key));
528 /* give to local clients */
530 &bd.key,
531 0, NULL /* get path */));
532
533 {
534 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
535
536 peer_bf
540 /* store locally */
541 if ( (0 != (bd.ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
542 (GDS_am_closest_peer (&dht_msg->key,
543 peer_bf)))
545 /* route to other peers */
546 if (GNUNET_OK !=
549 0 /* hop count */,
550 peer_bf))
551 {
553 "# Local PUT requests not routed",
554 1,
555 GNUNET_NO);
556 }
558 }
560 &bd,
561 0, /* hop count */
564}
565
566
573static void
575 const struct GNUNET_DATACACHE_Block *bd)
576{
578 "Datacache provided result for query key %s\n",
579 GNUNET_h2s (&bd->key));
581 &bd->key,
582 0, NULL /* get_path */));
583}
584
585
595 const struct GNUNET_DHT_ClientGetMessage *get)
596{
597 (void) cls;
598 (void) get;
599 /* always well-formed */
600 return GNUNET_OK;
601}
602
603
610static void
612 const struct GNUNET_DHT_ClientGetMessage *get)
613{
614 struct ClientHandle *ch = cls;
615 struct ClientQueryRecord *cqr;
616 uint16_t size = ntohs (get->header.size);
617 const char *xquery = (const char *) &get[1];
618 size_t xquery_size = size - sizeof(struct GNUNET_DHT_ClientGetMessage);
619
621 "Received GET request for %s from local client %p, xq: %.*s\n",
622 GNUNET_h2s (&get->key),
623 ch->client,
624 (int) xquery_size,
625 xquery);
627 "# GET requests received from clients",
628 1,
629 GNUNET_NO);
631 "CLIENT-GET %s\n",
632 GNUNET_h2s_full (&get->key));
633
634 cqr = GNUNET_malloc (sizeof(struct ClientQueryRecord) + xquery_size);
635 cqr->key = get->key;
636 cqr->ch = ch;
637 cqr->xquery = (const void *) &cqr[1];
638 GNUNET_memcpy (&cqr[1],
639 xquery,
640 xquery_size);
642 cqr,
643 0);
646 cqr->unique_id = get->unique_id;
647 cqr->xquery_size = xquery_size;
648 cqr->replication = ntohl (get->desired_replication_level);
649 cqr->msg_options = (enum GNUNET_DHT_RouteOption) ntohl (get->options);
650 cqr->type = ntohl (get->type);
652 ch->cqr_tail,
653 cqr);
655 &cqr->key,
656 cqr,
659 cqr->type,
660 0, /* hop count */
661 cqr->replication,
662 &get->key);
663 /* start remote requests */
664 if (NULL != retry_task)
667 NULL);
668 /* perform local lookup */
670 cqr->type,
671 cqr->xquery,
672 xquery_size,
673 NULL,
675 ch);
677}
678
679
684{
689
693 uint64_t unique_id;
694};
695
696
709 const struct GNUNET_HashCode *key,
710 void *value)
711{
712 struct FindByUniqueIdContext *fui_ctx = cls;
713 struct ClientQueryRecord *cqr = value;
714
715 if (cqr->unique_id != fui_ctx->unique_id)
716 return GNUNET_YES;
717 fui_ctx->cqr = cqr;
718 return GNUNET_NO;
719}
720
721
731 void *cls,
732 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
733{
734 uint16_t size = ntohs (seen->header.size);
735 unsigned int hash_count =
736 (size - sizeof(*seen))
737 / sizeof(struct GNUNET_HashCode);
738
739 if (size != sizeof(*seen) + hash_count * sizeof(struct GNUNET_HashCode))
740 {
741 GNUNET_break (0);
742 return GNUNET_SYSERR;
743 }
744 return GNUNET_OK;
745}
746
747
754static void
756 void *cls,
757 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
758{
759 struct ClientHandle *ch = cls;
760 uint16_t size = ntohs (seen->header.size);
761 unsigned int hash_count = (size - sizeof(*seen))
762 / sizeof(struct GNUNET_HashCode);
763 const struct GNUNET_HashCode *hc = (const struct GNUNET_HashCode*) &seen[1];
764 struct FindByUniqueIdContext fui_ctx = {
765 .unique_id = seen->unique_id
766 };
767 unsigned int old_count;
768 struct ClientQueryRecord *cqr;
769
771 &seen->key,
773 &fui_ctx);
774 if (NULL == (cqr = fui_ctx.cqr))
775 {
776 GNUNET_break (0);
778 return;
779 }
780 /* finally, update 'seen' list */
781 old_count = cqr->seen_replies_count;
784 cqr->seen_replies_count + hash_count);
785 GNUNET_memcpy (&cqr->seen_replies[old_count],
786 hc,
787 sizeof(struct GNUNET_HashCode) * hash_count);
788}
789
790
795{
800
804 uint64_t unique_id;
805};
806
807
819 const struct GNUNET_HashCode *key,
820 void *value)
821{
822 const struct RemoveByUniqueIdContext *ctx = cls;
823 struct ClientQueryRecord *cqr = value;
824
825 if (cqr->unique_id != ctx->unique_id)
826 return GNUNET_YES;
828 "Removing client %p's record for key %s (by unique id)\n",
829 ctx->ch->client,
830 GNUNET_h2s (key));
832 return GNUNET_YES;
833}
834
835
844static void
846 void *cls,
847 const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg)
848{
849 struct ClientHandle *ch = cls;
851
853 "# GET STOP requests received from clients",
854 1,
855 GNUNET_NO);
857 "Received GET STOP request for %s from local client %p\n",
858 GNUNET_h2s (&dht_stop_msg->key),
859 ch->client);
860 ctx.ch = ch;
861 ctx.unique_id = dht_stop_msg->unique_id;
863 &dht_stop_msg->key,
865 &ctx);
867}
868
869
874{
879
884
888 unsigned int get_path_length;
889
890};
891
892
905forward_reply (void *cls,
906 const struct GNUNET_HashCode *query_hash,
907 void *value)
908{
909 struct ForwardReplyContext *frc = cls;
911 const struct GNUNET_DATACACHE_Block *bd = frc->bd;
912 struct GNUNET_MQ_Envelope *env;
913 struct GNUNET_DHT_ClientResultMessage *reply;
915 bool do_free;
916 struct GNUNET_HashCode ch;
917 struct GNUNET_DHT_PathElement *paths;
918 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
919 size_t xsize = bd->data_size;
920
922 "CLIENT-RESULT %s\n",
923 GNUNET_h2s_full (&bd->key));
924 if ( (record->type != GNUNET_BLOCK_TYPE_ANY) &&
925 (record->type != bd->type) )
926 {
928 "Record type mismatch, not passing request for key %s to local client\n",
929 GNUNET_h2s (&bd->key));
931 "# Key match, type mismatches in REPLY to CLIENT",
932 1,
933 GNUNET_NO);
934 return GNUNET_YES; /* type mismatch */
935 }
936 if ( (0 == (record->msg_options & GNUNET_DHT_RO_FIND_APPROXIMATE)) &&
937 (0 != GNUNET_memcmp (&bd->key,
938 query_hash)) )
939 {
941 "# Inexact key match, but exact match required",
942 1,
943 GNUNET_NO);
944 return GNUNET_YES; /* type mismatch */
945 }
947 bd->data_size,
948 &ch);
949 for (unsigned int i = 0; i < record->seen_replies_count; i++)
950 if (0 ==
951 GNUNET_memcmp (&record->seen_replies[i],
952 &ch))
953 {
955 "Duplicate reply, not passing request for key %s to local client\n",
956 GNUNET_h2s (&bd->key));
958 "# Duplicate REPLIES to CLIENT request dropped",
959 1,
960 GNUNET_NO);
961 return GNUNET_YES; /* duplicate */
962 }
963 eval
965 record->type,
966 NULL,
967 &bd->key,
968 record->xquery,
969 record->xquery_size,
970 bd->data,
971 bd->data_size);
973 "Evaluation result is %d for key %s for local client's query\n",
974 (int) eval,
975 GNUNET_h2s (&bd->key));
976 switch (eval)
977 {
979 do_free = true;
980 break;
983 GNUNET_array_append (record->seen_replies,
984 record->seen_replies_count,
985 ch);
986 do_free = false;
987 break;
989 /* should be impossible to encounter here */
990 GNUNET_break (0);
991 return GNUNET_YES;
993 return GNUNET_YES;
994 default:
995 GNUNET_break (0);
996 return GNUNET_NO;
997 }
999 "# RESULTS queued for clients",
1000 1,
1001 GNUNET_NO);
1002 xsize += (frc->get_path_length + bd->put_path_length)
1003 * sizeof(struct GNUNET_DHT_PathElement);
1004 if (truncated)
1005 xsize += sizeof (struct GNUNET_PeerIdentity);
1006
1007#if SUPER_REDUNDANT_CHECK
1008 GNUNET_break (0 ==
1010 bd->data_size,
1011 bd->expiration_time,
1012 truncated
1013 ? &bd->trunc_peer
1014 : NULL,
1015 bd->put_path,
1016 bd->put_path_length,
1017 frc->get_path,
1018 frc->get_path_length,
1019 &GDS_my_identity));
1020#endif
1021
1022 env = GNUNET_MQ_msg_extra (reply,
1023 xsize,
1025 reply->type = htonl (bd->type);
1026 reply->options = htonl (bd->ro);
1027 reply->get_path_length = htonl (frc->get_path_length);
1028 reply->put_path_length = htonl (bd->put_path_length);
1029 reply->unique_id = record->unique_id;
1031 reply->key = *query_hash;
1032 if (truncated)
1033 {
1034 void *tgt = &reply[1];
1035
1036 GNUNET_memcpy (tgt,
1037 &bd->trunc_peer,
1038 sizeof (struct GNUNET_PeerIdentity));
1039 paths = (struct GNUNET_DHT_PathElement *)
1040 (tgt + sizeof (struct GNUNET_PeerIdentity));
1041 }
1042 else
1043 {
1044 paths = (struct GNUNET_DHT_PathElement *) &reply[1];
1045 }
1046 GNUNET_memcpy (paths,
1047 bd->put_path,
1048 sizeof(struct GNUNET_DHT_PathElement)
1049 * bd->put_path_length);
1050 GNUNET_memcpy (&paths[bd->put_path_length],
1051 frc->get_path,
1052 sizeof(struct GNUNET_DHT_PathElement)
1053 * frc->get_path_length);
1054 GNUNET_memcpy (&paths[frc->get_path_length + bd->put_path_length],
1055 bd->data,
1056 bd->data_size);
1058 "Sending reply to query %s for client %p\n",
1059 GNUNET_h2s (query_hash),
1060 record->ch->client);
1061 GNUNET_MQ_send (record->ch->mq,
1062 env);
1063 if (GNUNET_YES == do_free)
1065 return GNUNET_YES;
1066}
1067
1068
1069bool
1071 const struct GNUNET_HashCode *query_hash,
1072 unsigned int get_path_length,
1073 const struct GNUNET_DHT_PathElement *get_path)
1074{
1075 struct ForwardReplyContext frc;
1076 size_t msize = sizeof (struct GNUNET_DHT_ClientResultMessage)
1077 + bd->data_size
1079 * sizeof(struct GNUNET_DHT_PathElement);
1080#if SANITY_CHECKS > 1
1081 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1082#endif
1083
1084 if (msize >= GNUNET_MAX_MESSAGE_SIZE)
1085 {
1086 GNUNET_break (0);
1087 return false;
1088 }
1089#if SANITY_CHECKS > 1
1090 if (0 !=
1092 bd->data_size,
1093 bd->expiration_time,
1094 truncated
1095 ? &bd->trunc_peer
1096 : NULL,
1097 bd->put_path,
1098 bd->put_path_length,
1099 get_path,
1100 get_path_length,
1102 {
1103 GNUNET_break (0);
1104 return false;
1105 }
1106#endif
1107 frc.bd = bd;
1108 frc.get_path = get_path;
1109 frc.get_path_length = get_path_length;
1111 "Forwarding reply for query hash %s with GPL %u and PPL %u to client\n",
1112 GNUNET_h2s (query_hash),
1113 get_path_length,
1114 bd->put_path_length);
1115 if (0 ==
1117 query_hash,
1119 &frc))
1120 {
1122 "No matching client for reply for query %s\n",
1123 GNUNET_h2s (query_hash));
1125 "# REPLIES ignored for CLIENTS (no match)",
1126 1,
1127 GNUNET_NO);
1128 }
1129 return true;
1130}
1131
1132
1133/* **************** HELLO logic ***************** */
1134
1143static void
1145 const struct GNUNET_MessageHeader *msg)
1146{
1147 struct ClientHandle *ch = cls;
1150 size_t slen = strlen (url) + 1;
1151 struct GNUNET_MessageHeader *hdr;
1152 struct GNUNET_MQ_Envelope *env;
1153
1155 "Handling request from local client for my HELLO\n");
1156 env = GNUNET_MQ_msg_extra (hdr,
1157 slen,
1159 memcpy (&hdr[1],
1160 url,
1161 slen);
1162 GNUNET_free (url);
1164 env);
1166}
1167
1168
1176static enum GNUNET_GenericReturnValue
1178 const struct GNUNET_MessageHeader *hdr)
1179{
1180 uint16_t len = ntohs (hdr->size);
1181 const char *buf = (const char *) &hdr[1];
1182
1183 (void) cls;
1184 if ('\0' != buf[len - sizeof (*hdr) - 1])
1185 {
1186 GNUNET_break (0);
1187 return GNUNET_SYSERR;
1188 }
1189 return GNUNET_OK;
1190}
1191
1192
1200static void
1202 const struct GNUNET_MessageHeader *msg)
1203{
1204 struct ClientHandle *ch = cls;
1205 const char *url = (const char *) &msg[1];
1206 struct GNUNET_HELLO_Builder *b;
1207
1209 "Local client provided HELLO URL %s\n",
1210 url);
1212 if (NULL == b)
1213 {
1214 GNUNET_break (0);
1216 return;
1217 }
1221 NULL);
1223}
1224
1225
1226/* ************* logic for monitors ************** */
1227
1228
1236static void
1239{
1240 struct ClientHandle *ch = cls;
1241 struct ClientMonitorRecord *r;
1242
1243 r = GNUNET_new (struct ClientMonitorRecord);
1244 r->ch = ch;
1245 r->type = ntohl (msg->type);
1246 r->get = ntohs (msg->get);
1247 r->get_resp = ntohs (msg->get_resp);
1248 r->put = ntohs (msg->put);
1249 if (0 != ntohs (msg->filter_key))
1250 r->key = msg->key;
1253 r);
1255}
1256
1257
1264static void
1266 void *cls,
1268{
1269 struct ClientHandle *ch = cls;
1270
1272 for (struct ClientMonitorRecord *r = monitor_head;
1273 NULL != r;
1274 r = r->next)
1275 {
1276 bool keys_match;
1277
1278 keys_match =
1279 (GNUNET_is_zero (&r->key))
1280 ? (0 == ntohs (msg->filter_key))
1281 : ( (0 != ntohs (msg->filter_key)) &&
1282 (! GNUNET_memcmp (&r->key,
1283 &msg->key)) );
1284 if ( (ch == r->ch) &&
1285 (ntohl (msg->type) == r->type) &&
1286 (r->get == msg->get) &&
1287 (r->get_resp == msg->get_resp) &&
1288 (r->put == msg->put) &&
1289 keys_match)
1290 {
1293 r);
1294 GNUNET_free (r);
1295 return; /* Delete only ONE entry */
1296 }
1297 }
1298}
1299
1300
1307typedef void
1308(*MonitorAction)(void *cls,
1309 struct ClientMonitorRecord *m);
1310
1311
1321static void
1323 const struct GNUNET_HashCode *key,
1324 MonitorAction cb,
1325 void *cb_cls)
1326{
1327 struct ClientHandle **cl = NULL;
1328 unsigned int cl_size = 0;
1329
1330 for (struct ClientMonitorRecord *m = monitor_head;
1331 NULL != m;
1332 m = m->next)
1333 {
1334 bool found = false;
1335
1336 if ( (GNUNET_BLOCK_TYPE_ANY != m->type) &&
1337 (m->type != type) )
1338 continue;
1339 if ( (! GNUNET_is_zero (&m->key)) &&
1340 (0 ==
1342 &m->key)) )
1343 continue;
1344 /* Don't send duplicates */
1345 for (unsigned i = 0; i < cl_size; i++)
1346 if (cl[i] == m->ch)
1347 {
1348 found = true;
1349 break;
1350 }
1351 if (found)
1352 continue;
1354 cl_size,
1355 m->ch);
1356 cb (cb_cls,
1357 m);
1358 }
1359 GNUNET_free (cl);
1360}
1361
1362
1367{
1370 uint32_t hop_count;
1373 const struct GNUNET_HashCode *key;
1374};
1375
1376
1384static void
1385get_action (void *cls,
1386 struct ClientMonitorRecord *m)
1387{
1388 struct GetActionContext *gac = cls;
1389 struct GNUNET_MQ_Envelope *env;
1390 struct GNUNET_DHT_MonitorGetMessage *mmsg;
1391
1392 env = GNUNET_MQ_msg (mmsg,
1394 mmsg->options = htonl (gac->options);
1395 mmsg->type = htonl (gac->type);
1396 mmsg->hop_count = htonl (gac->hop_count);
1398 mmsg->key = *gac->key;
1399 GNUNET_MQ_send (m->ch->mq,
1400 env);
1401}
1402
1403
1404void
1407 uint32_t hop_count,
1409 const struct GNUNET_HashCode *key)
1410{
1411 struct GetActionContext gac = {
1412 .options = options,
1413 .type = type,
1414 .hop_count = hop_count,
1415 .desired_replication_level = desired_replication_level,
1416 .key = key
1417 };
1418
1420 key,
1421 &get_action,
1422 &gac);
1423}
1424
1425
1430{
1433 unsigned int get_path_length;
1434};
1435
1436
1444static void
1446 struct ClientMonitorRecord *m)
1447{
1448 const struct ResponseActionContext *resp_ctx = cls;
1449 const struct GNUNET_DATACACHE_Block *bd = resp_ctx->bd;
1450 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1451 struct GNUNET_MQ_Envelope *env;
1453 struct GNUNET_DHT_PathElement *path;
1454 size_t msize;
1455
1456 msize = bd->data_size;
1457 msize += (resp_ctx->get_path_length + bd->put_path_length)
1458 * sizeof(struct GNUNET_DHT_PathElement);
1459 if (truncated)
1460 msize += sizeof (struct GNUNET_PeerIdentity);
1461 env = GNUNET_MQ_msg_extra (mmsg,
1462 msize,
1464 mmsg->type = htonl (bd->type);
1465 mmsg->put_path_length = htonl (bd->put_path_length);
1466 mmsg->get_path_length = htonl (resp_ctx->get_path_length);
1468 mmsg->key = bd->key;
1469 if (truncated)
1470 {
1471 void *tgt = &mmsg[1];
1472
1473 GNUNET_memcpy (tgt,
1474 &bd->trunc_peer,
1475 sizeof (struct GNUNET_PeerIdentity));
1476 path = (struct GNUNET_DHT_PathElement *)
1477 (tgt + sizeof (struct GNUNET_PeerIdentity));
1478 }
1479 else
1480 {
1481 path = (struct GNUNET_DHT_PathElement *) &mmsg[1];
1482 }
1483 GNUNET_memcpy (path,
1484 bd->put_path,
1485 bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement));
1486 GNUNET_memcpy (path,
1487 resp_ctx->get_path,
1488 resp_ctx->get_path_length
1489 * sizeof(struct GNUNET_DHT_PathElement));
1490 GNUNET_memcpy (&path[resp_ctx->get_path_length],
1491 bd->data,
1492 bd->data_size);
1493 GNUNET_MQ_send (m->ch->mq,
1494 env);
1495}
1496
1497
1498void
1500 const struct GNUNET_DHT_PathElement *get_path,
1501 unsigned int get_path_length)
1502{
1503 struct ResponseActionContext rac = {
1504 .bd = bd,
1505 .get_path = get_path,
1506 .get_path_length = get_path_length
1507 };
1508
1510 &bd->key,
1512 &rac);
1513}
1514
1515
1520{
1522 uint32_t hop_count;
1524};
1525
1526
1534static void
1535put_action (void *cls,
1536 struct ClientMonitorRecord *m)
1537{
1538 const struct PutActionContext *put_ctx = cls;
1539 const struct GNUNET_DATACACHE_Block *bd = put_ctx->bd;
1540 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1541 struct GNUNET_MQ_Envelope *env;
1542 struct GNUNET_DHT_MonitorPutMessage *mmsg;
1543 struct GNUNET_DHT_PathElement *msg_path;
1544 size_t msize;
1545
1546 msize = bd->data_size
1547 + bd->put_path_length
1548 * sizeof(struct GNUNET_DHT_PathElement);
1549 if (truncated)
1550 msize += sizeof (struct GNUNET_PeerIdentity);
1551 env = GNUNET_MQ_msg_extra (mmsg,
1552 msize,
1554 mmsg->options = htonl (bd->ro);
1555 mmsg->type = htonl (bd->type);
1556 mmsg->hop_count = htonl (put_ctx->hop_count);
1558 mmsg->put_path_length = htonl (bd->put_path_length);
1559 mmsg->key = bd->key;
1561 if (truncated)
1562 {
1563 void *tgt = &mmsg[1];
1564
1565 GNUNET_memcpy (tgt,
1566 &bd->trunc_peer,
1567 sizeof (struct GNUNET_PeerIdentity));
1568 msg_path = (struct GNUNET_DHT_PathElement *)
1569 (tgt + sizeof (struct GNUNET_PeerIdentity));
1570 }
1571 else
1572 {
1573 msg_path = (struct GNUNET_DHT_PathElement *) &mmsg[1];
1574 }
1575 GNUNET_memcpy (msg_path,
1576 bd->put_path,
1577 bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement));
1578 GNUNET_memcpy (&msg_path[bd->put_path_length],
1579 bd->data,
1580 bd->data_size);
1581 GNUNET_MQ_send (m->ch->mq,
1582 env);
1583}
1584
1585
1586void
1588 uint32_t hop_count,
1589 uint32_t desired_replication_level)
1590{
1591 struct PutActionContext put_ctx = {
1592 .bd = bd,
1593 .hop_count = hop_count,
1594 .desired_replication_level = desired_replication_level
1595 };
1596
1598 &bd->key,
1599 &put_action,
1600 &put_ctx);
1601}
1602
1603
1604/* ********************** Initialization logic ***************** */
1605
1606
1610static void
1612{
1615 GNUNET_YES);
1618}
1619
1620
1624static void
1626{
1627 if (NULL != retry_task)
1628 {
1630 retry_task = NULL;
1631 }
1632}
1633
1634
1641#define GDS_DHT_SERVICE_INIT(name, run) \
1642 GNUNET_SERVICE_MAIN \
1643 (name, \
1644 GNUNET_SERVICE_OPTION_NONE, \
1645 run, \
1646 &client_connect_cb, \
1647 &client_disconnect_cb, \
1648 NULL, \
1649 GNUNET_MQ_hd_var_size (dht_local_put, \
1650 GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, \
1651 struct GNUNET_DHT_ClientPutMessage, \
1652 NULL), \
1653 GNUNET_MQ_hd_var_size (dht_local_get, \
1654 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, \
1655 struct GNUNET_DHT_ClientGetMessage, \
1656 NULL), \
1657 GNUNET_MQ_hd_fixed_size (dht_local_get_stop, \
1658 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, \
1659 struct GNUNET_DHT_ClientGetStopMessage, \
1660 NULL), \
1661 GNUNET_MQ_hd_fixed_size (dht_local_monitor, \
1662 GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, \
1663 struct GNUNET_DHT_MonitorStartStopMessage, \
1664 NULL), \
1665 GNUNET_MQ_hd_fixed_size (dht_local_monitor_stop, \
1666 GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP, \
1667 struct GNUNET_DHT_MonitorStartStopMessage, \
1668 NULL), \
1669 GNUNET_MQ_hd_var_size (dht_local_get_result_seen, \
1670 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, \
1671 struct GNUNET_DHT_ClientGetResultSeenMessage, \
1672 NULL), \
1673 GNUNET_MQ_hd_fixed_size (dht_local_hello_get, \
1674 GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_GET, \
1675 struct GNUNET_MessageHeader, \
1676 NULL), \
1677 GNUNET_MQ_hd_var_size (dht_local_hello_offer, \
1678 GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_URL, \
1679 struct GNUNET_MessageHeader, \
1680 NULL), \
1681 GNUNET_MQ_handler_end ())
1682
1683
1687void __attribute__ ((destructor))
1688GDS_CLIENTS_done ()
1689{
1690 if (NULL != retry_heap)
1691 {
1694 retry_heap = NULL;
1695 }
1696 if (NULL != forward_map)
1697 {
1700 forward_map = NULL;
1701 }
1702}
1703
1704
1705/* end of gnunet-service-dht_clients.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition: dht.h:34
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static int monitor
Monitor ARM activity.
Definition: gnunet-arm.c:64
static unsigned int replication_level
Replication level option to use for publishing.
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
struct GNUNET_HashCode key
The key used in the DHT.
static int get
Get DID Documement for DID Flag.
Definition: gnunet-did.c:63
static struct GNUNET_FS_Handle * ctx
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
struct GNUNET_PeerIdentity GDS_my_identity
Identity of this peer.
struct GNUNET_CRYPTO_EddsaPrivateKey GDS_my_private_key
Our private key.
struct GNUNET_HELLO_Builder * GDS_my_hello
Our HELLO.
GNUnet DHT globals.
static void transmit_request(struct ClientQueryRecord *cqr)
Route the given request via the DHT.
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.
static void handle_dht_local_get_stop(void *cls, const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg)
Handler for any generic DHT stop messages, calls the appropriate handler depending on message type (i...
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.
static struct ClientMonitorRecord * monitor_head
List of active monitoring requests.
static enum GNUNET_GenericReturnValue forward_reply(void *cls, const struct GNUNET_HashCode *query_hash, void *value)
Iterator over hash map entries that send a given reply to each of the matching clients.
static void handle_dht_local_get(void *cls, const struct GNUNET_DHT_ClientGetMessage *get)
Handler for DHT GET messages from the client.
static enum GNUNET_GenericReturnValue find_by_unique_id(void *cls, const struct GNUNET_HashCode *key, void *value)
Function called for each existing DHT record for the given query.
static enum GNUNET_GenericReturnValue remove_by_unique_id(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over hash map entries that frees all entries that match the given client and unique ID.
static void response_action(void *cls, struct ClientMonitorRecord *m)
Function called on monitors that match a response.
static struct GNUNET_CONTAINER_Heap * retry_heap
Heap with all of our client's request, sorted by retry time (earliest on top).
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
static struct GNUNET_SCHEDULER_Task * retry_task
Task that re-transmits requests (using retry_heap).
static void handle_dht_local_hello_get(void *cls, const struct GNUNET_MessageHeader *msg)
Handler for HELLO GET message.
static void handle_dht_local_monitor_stop(void *cls, const struct GNUNET_DHT_MonitorStartStopMessage *msg)
Handler for monitor stop messages.
static void handle_dht_local_get_result_seen(void *cls, const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
Handler for "GET result seen" messages from the client.
static struct GNUNET_CONTAINER_MultiHashMap * forward_map
Hashmap for fast key based lookup, maps keys to struct ClientQueryRecord entries.
static void handle_dht_local_monitor(void *cls, const struct GNUNET_DHT_MonitorStartStopMessage *msg)
Handler for monitor start messages.
static void handle_local_result(void *cls, const struct GNUNET_DATACACHE_Block *bd)
Handle a result from local datacache for a GET operation.
struct GNUNET_BLOCK_Context * GDS_block_context
Our handle to the BLOCK library.
struct GNUNET_SERVICE_Handle * GDS_service
Handle for the service.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
Functions with this signature are called whenever a local client is connects to us.
static void GDS_CLIENTS_init(void)
Initialize client subsystem.
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.
static enum GNUNET_GenericReturnValue check_dht_local_hello_offer(void *cls, const struct GNUNET_MessageHeader *hdr)
Process a client HELLO message received from the service.
static enum GNUNET_GenericReturnValue check_dht_local_put(void *cls, const struct GNUNET_DHT_ClientPutMessage *dht_msg)
Check DHT PUT messages from the client.
static void for_matching_monitors(enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, MonitorAction cb, void *cb_cls)
Call cb on all monitors that watch for blocks of type and key key.
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.
static void handle_dht_local_put(void *cls, const struct GNUNET_DHT_ClientPutMessage *dht_msg)
Handler for PUT messages.
static struct ClientMonitorRecord * monitor_tail
List of active monitoring requests.
static void GDS_CLIENTS_stop(void)
Shutdown client subsystem.
#define LOG(kind,...)
static enum GNUNET_GenericReturnValue check_dht_local_get(void *cls, const struct GNUNET_DHT_ClientGetMessage *get)
Check DHT GET messages from the client.
static void handle_dht_local_hello_offer(void *cls, const struct GNUNET_MessageHeader *msg)
Handler for HELLO OFFER message.
#define LOG_TRAFFIC(kind,...)
Should routing details be logged to stderr (for debugging)?
void __attribute__((destructor))
MINIMIZE heap size (way below 128k) since this process doesn't need much.
static enum GNUNET_GenericReturnValue check_dht_local_get_result_seen(void *cls, const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
Check "GET result seen" messages from the client.
static void transmit_next_request_task(void *cls)
Task that looks at the retry_heap and transmits all of the requests on the heap that are ready for tr...
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
Functions with this signature are called whenever a client is disconnected on the network level.
static void put_action(void *cls, struct ClientMonitorRecord *m)
Function called on monitors that match a PUT.
static void remove_client_query_record(struct ClientQueryRecord *record)
Free data structures associated with the given query.
static void get_action(void *cls, struct ClientMonitorRecord *m)
Function called on monitors that match a GET.
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
The configuration the DHT service is running with.
void(* MonitorAction)(void *cls, struct ClientMonitorRecord *m)
Function to call by for_matching_monitors().
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.
GNUnet DHT service's datacache integration.
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_put(const struct GNUNET_DATACACHE_Block *bd, uint16_t desired_replication_level, uint16_t hop_count, struct GNUNET_CONTAINER_BloomFilter *bf)
Perform a PUT operation.
void GDS_try_connect(void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
Callback function used to extract URIs from a builder.
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.
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.
GNUnet DHT routing code.
Helper library for handling HELLO URIs.
Constants for network protocols.
API to create, modify and access statistics.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
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:363
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:337
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:319
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:192
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:247
@ GNUNET_BLOCK_REPLY_OK_MORE
Valid result, and there may be more.
@ GNUNET_BLOCK_REPLY_OK_DUPLICATE
Valid result, but suppressed because it is a duplicate.
@ GNUNET_BLOCK_REPLY_OK_LAST
Last possible valid result.
@ GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED
Specified block type not supported by any plugin.
@ GNUNET_BLOCK_REPLY_IRRELEVANT
Block does not match xquery (valid result, not relevant for the request)
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_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...
#define GNUNET_CONSTANTS_BLOOMFILTER_K
K-value that must be used for the bloom filters in 'GET' queries.
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:1351
@ GNUNET_DHT_RO_TRUNCATED
Flag set if the path was truncated.
@ 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(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
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
void * GNUNET_CONTAINER_heap_remove_root(struct GNUNET_CONTAINER_Heap *heap)
Remove root of the heap.
struct GNUNET_CONTAINER_HeapNode * GNUNET_CONTAINER_heap_insert(struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost)
Inserts a new element into the heap.
unsigned int GNUNET_CONTAINER_heap_get_size(const struct GNUNET_CONTAINER_Heap *heap)
Get the current size of the heap.
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
@ GNUNET_CONTAINER_HEAP_ORDER_MIN
Heap with the minimum cost at the root.
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:373
const struct GNUNET_PeerIdentity * GNUNET_HELLO_builder_iterate(const struct GNUNET_HELLO_Builder *builder, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a builder.
Definition: hello-uri.c:909
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_url(const char *url)
Parse GNUnet HELLO url into builder.
Definition: hello-uri.c:493
char * GNUNET_HELLO_builder_to_url(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Generate GNUnet HELLO URI from a builder.
Definition: hello-uri.c:717
#define GNUNET_is_zero(a)
Check that memory in a is all zeros.
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ 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_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value 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_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET
Receive information about transiting GETs.
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP
Receive information about transiting GET responses.
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT
Receive information about transiting PUTs.
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT
Service returns result to client.
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_URL
HELLO URL send between client and service (in either direction).
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:1255
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1305
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2489
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2408
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_TIME_UNIT_SECONDS
One second.
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_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_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition: time.c:669
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static unsigned int size
Size of the "table".
Definition: peer.c:68
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.
Struct containing information about a client, handle to connect to it, and any pending messages that ...
struct ClientQueryRecord * cqr_tail
Linked list of active queries of this client.
struct GNUNET_SERVICE_Client * client
The handle to this client.
struct GNUNET_MQ_Handle * mq
The message queue to this client.
struct ClientQueryRecord * cqr_head
Linked list of active queries of this client.
Struct containing parameters of monitoring requests.
struct ClientMonitorRecord * next
Next element in DLL.
uint16_t put
Flag whether to notify about PUT messages.
struct ClientMonitorRecord * prev
Previous element in DLL.
struct ClientHandle * ch
Client to notify of these requests.
enum GNUNET_BLOCK_Type type
Type of blocks that are of interest.
int16_t get
Flag whether to notify about GET messages.
struct GNUNET_HashCode key
Key of data of interest.
int16_t get_resp
Flag whether to notify about GET_REPONSE messages.
Entry in the local forwarding map for a client's GET request.
unsigned int seen_replies_count
Number of entries in seen_replies.
size_t xquery_size
Number of bytes in xquery.
struct GNUNET_TIME_Relative retry_frequency
What's the delay between re-try operations that we currently use for this request?
struct ClientQueryRecord * prev
Kept in a DLL with client.
struct GNUNET_CONTAINER_HeapNode * hnode
Pointer to this nodes heap location in the retry-heap (for fast removal)
struct ClientHandle * ch
Client responsible for the request.
struct GNUNET_HashCode * seen_replies
Array of (hashes of) replies we have already seen for this request.
uint64_t unique_id
The unique identifier of this request.
enum GNUNET_DHT_RouteOption msg_options
Any message options for this request.
struct GNUNET_HashCode key
The key this request was about.
enum GNUNET_BLOCK_Type type
The type for the data for the GET request.
const void * xquery
Extended query (see gnunet_block_lib.h), allocated at the end of this struct.
struct GNUNET_TIME_Absolute retry_time
What's the next time we should re-try this request?
struct ClientQueryRecord * next
Kept in a DLL with client.
uint32_t replication
Desired replication level.
Closure for find_by_unique_id().
uint64_t unique_id
Unique ID to look for.
struct ClientQueryRecord * cqr
Where to store the result, if found.
Closure for forward_reply()
const struct GNUNET_DATACACHE_Block * bd
Block details.
const struct GNUNET_DHT_PathElement * get_path
GET path taken.
unsigned int get_path_length
Number of entries in get_path.
struct GNUNET_MQ_Handle * mq
Our control connection to the ARM service.
Handle to an initialized block library.
Definition: block.c:55
Block group data.
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition: cadet.h:142
Handle to a node in a heap.
Internal representation of the hash map.
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?
DHT GET message sent from clients to service.
Definition: dht.h:72
DHT GET RESULTS KNOWN message sent from clients to service.
Definition: dht.h:114
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN.
Definition: dht.h:118
struct GNUNET_HashCode key
The key we are searching for (to make it easy to find the corresponding GET inside the service).
Definition: dht.h:129
uint64_t unique_id
Unique ID identifying this request.
Definition: dht.h:134
Message which indicates the DHT should cancel outstanding requests and discard any state.
Definition: dht.h:44
uint64_t unique_id
Unique ID identifying this request.
Definition: dht.h:58
struct GNUNET_HashCode key
Key of this request.
Definition: dht.h:63
Message to insert data into the DHT, sent from clients to DHT service.
Definition: dht.h:200
struct GNUNET_HashCode key
The key to store the value under.
Definition: dht.h:229
uint32_t type
The type of data to insert.
Definition: dht.h:209
uint32_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
Definition: dht.h:214
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT.
Definition: dht.h:204
uint32_t desired_replication_level
Replication level for this message.
Definition: dht.h:219
struct GNUNET_TIME_AbsoluteNBO expiration
How long should this data persist?
Definition: dht.h:224
Reply to a GET send from the service to a client.
Definition: dht.h:144
uint32_t put_path_length
Number of peers recorded in the outgoing path from source to the storgage location of this message.
Definition: dht.h:169
uint64_t unique_id
Unique ID of the matching GET request.
Definition: dht.h:180
struct GNUNET_TIME_AbsoluteNBO expiration
When does this entry expire?
Definition: dht.h:185
struct GNUNET_HashCode key
The key that was searched for.
Definition: dht.h:190
uint32_t type
The type for the data.
Definition: dht.h:153
uint32_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
Definition: dht.h:163
uint32_t get_path_length
The number of peer identities recorded from the storage location to this peer.
Definition: dht.h:175
Message to monitor get requests going through peer, DHT service -> clients.
Definition: dht.h:334
uint32_t hop_count
Hop count.
Definition: dht.h:353
uint32_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
Definition: dht.h:343
uint32_t desired_replication_level
Replication level for this message.
Definition: dht.h:358
struct GNUNET_HashCode key
The key to store the value under.
Definition: dht.h:368
uint32_t type
The type of data in the request.
Definition: dht.h:348
Message to monitor get results going through peer, DHT service -> clients.
Definition: dht.h:377
struct GNUNET_HashCode key
The key of the corresponding GET request.
Definition: dht.h:416
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?
Definition: dht.h:411
uint32_t type
Content type.
Definition: dht.h:386
uint32_t get_path_length
Length of the GET path that follows (if tracked).
Definition: dht.h:406
uint32_t put_path_length
Length of the PUT path that follows (if tracked).
Definition: dht.h:401
Message to monitor put requests going through peer, DHT service -> clients.
Definition: dht.h:239
uint32_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
Definition: dht.h:248
struct GNUNET_TIME_AbsoluteNBO expiration_time
How long should this data persist?
Definition: dht.h:274
uint32_t desired_replication_level
Replication level for this message.
Definition: dht.h:263
struct GNUNET_HashCode key
The key to store the value under.
Definition: dht.h:279
uint32_t hop_count
Hop count so far.
Definition: dht.h:258
uint32_t type
The type of data in the request.
Definition: dht.h:253
uint32_t put_path_length
Number of peers recorded in the outgoing path from source to the storage location of this message.
Definition: dht.h:269
Message to request monitoring messages, clients -> DHT service.
Definition: dht.h:291
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
Context for building (or parsing) HELLO URIs.
Definition: hello-uri.c:205
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:136
Handle to a client that is connected to a service.
Definition: service.c:252
Handle to a service.
Definition: service.c:118
Handle for the service.
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.
Closure for get_action();.
const struct GNUNET_HashCode * key
enum GNUNET_DHT_RouteOption options
struct GNUNET_PeerIdentity trunc_peer
enum GNUNET_BLOCK_Type type
Closure for put_action().
const struct GNUNET_DATACACHE_Block * bd
Closure for remove_by_unique_id().
struct ClientHandle * ch
Client that issued the removal request.
uint64_t unique_id
Unique ID of the request.
Closure for response_action().
const struct GNUNET_DHT_PathElement * get_path
const struct GNUNET_DATACACHE_Block * bd