GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
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
28
35#define SANITY_CHECKS 0
36
40#define LOG_TRAFFIC(kind, ...) GNUNET_log_from (kind, "dht-traffic", \
41 __VA_ARGS__)
42
43#define LOG(kind, ...) GNUNET_log_from (kind, "dht-clients", __VA_ARGS__)
44
45
51struct ClientHandle;
52
53
135
136
141{
146
151
156
161
166
170 int16_t get;
171
175 int16_t get_resp;
176
180 uint16_t put;
181
182};
183
184
212
213
218
223
228
233
238
243
248
253
258
263
264
270static void
272{
273 struct ClientHandle *ch = record->ch;
274
276 ch->cqr_tail,
277 record);
280 &record->key,
281 record));
282 if (NULL != record->hnode)
284 GNUNET_array_grow (record->seen_replies,
285 record->seen_replies_count,
286 0);
288}
289
290
300static void *
303 struct GNUNET_MQ_Handle *mq)
304{
305 struct ClientHandle *ch;
306
307 (void) cls;
308 ch = GNUNET_new (struct ClientHandle);
309 ch->client = client;
310 ch->mq = mq;
311 return ch;
312}
313
314
323static void
326 void *app_ctx)
327{
328 struct ClientHandle *ch = app_ctx;
329
330 (void) cls;
331 (void) client;
333 "Local client %p disconnects\n",
334 ch);
335 {
337
339 NULL != monitor;
340 monitor = next)
341 {
342 next = monitor->next;
343 if (monitor->ch != ch)
344 continue;
347 monitor);
349 }
350 }
351
352 {
353 struct ClientQueryRecord *cqr;
354
355 while (NULL != (cqr = ch->cqr_head))
357 }
358 GNUNET_free (ch);
359}
360
361
369static void
371{
372 struct GNUNET_BLOCK_Group *bg;
373 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
374
376 "# GET requests from clients injected",
377 1,
378 GNUNET_NO);
380 cqr->type,
381 NULL, /* raw data */
382 0, /* raw data size */
383 "seen-set-size",
385 NULL);
387 cqr->seen_replies,
388 cqr->seen_replies_count);
389 peer_bf
394 "Initiating GET for %s, replication %u, already have %u replies\n",
395 GNUNET_h2s (&cqr->key),
396 cqr->replication,
397 cqr->seen_replies_count);
399 cqr->msg_options,
400 cqr->replication,
401 0 /* hop count */,
402 &cqr->key,
403 cqr->xquery,
404 cqr->xquery_size,
405 bg,
406 peer_bf);
409
410 /* Exponential back-off for retries.
411 * max. is #GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */
414}
415
416
424static void
426{
427 struct ClientQueryRecord *cqr;
428
429 (void) cls;
430 retry_task = NULL;
431 while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
432 {
433 cqr->hnode = NULL;
435 {
436 cqr->hnode
438 cqr,
443 NULL);
444 return;
445 }
446 transmit_request (cqr);
447 cqr->hnode
449 cqr,
451 }
452}
453
454
464 const struct GNUNET_DHT_ClientPutMessage *dht_msg)
465{
466 uint32_t replication_level = ntohl (dht_msg->desired_replication_level);
467
468 (void) cls;
470 {
471 GNUNET_break_op (0);
472 return GNUNET_SYSERR;
473 }
474 return GNUNET_OK;
475}
476
477
484static void
486 const struct GNUNET_DHT_ClientPutMessage *dht_msg)
487{
488 struct ClientHandle *ch = cls;
489 uint16_t size = ntohs (dht_msg->header.size);
490 uint32_t replication_level
491 = ntohl (dht_msg->desired_replication_level);
492 struct GNUNET_DATACACHE_Block bd = {
493 .key = dht_msg->key,
494 .expiration_time = GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
495 .data = &dht_msg[1],
496 .data_size = size - sizeof (*dht_msg),
497 .type = ntohl (dht_msg->type),
498 .ro = ntohl (dht_msg->options)
499 };
500
502 "Handling local PUT of %lu-bytes for query %s of type %u\n",
503 (unsigned long) (size - sizeof(struct GNUNET_DHT_ClientPutMessage)),
504 GNUNET_h2s (&dht_msg->key),
505 (unsigned int) bd.type);
506#if SANITY_CHECKS > 0
507 if (GNUNET_OK !=
509 bd.type,
510 bd.data,
511 bd.data_size))
512 {
513 GNUNET_break (0);
514 return;
515 }
516#endif
518 "# PUT requests received from clients",
519 1,
520 GNUNET_NO);
522 "CLIENT-PUT %s\n",
523 GNUNET_h2s_full (&dht_msg->key));
524 /* give to local clients */
526 &bd.key,
527 0, NULL /* get path */));
528
529 {
530 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
531
532 peer_bf
536 /* store locally */
537 if ( (0 != (bd.ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
538 (GDS_am_closest_peer (&dht_msg->key,
539 peer_bf)))
541 /* route to other peers */
542 if (GNUNET_OK !=
545 0 /* hop count */,
546 peer_bf))
547 {
549 "# Local PUT requests not routed",
550 1,
551 GNUNET_NO);
552 }
554 }
556 &bd,
557 0, /* hop count */
560}
561
562
569static void
571 const struct GNUNET_DATACACHE_Block *bd)
572{
574 "Datacache provided result for query key %s\n",
575 GNUNET_h2s (&bd->key));
577 &bd->key,
578 0, NULL /* get_path */));
579}
580
581
591 const struct GNUNET_DHT_ClientGetMessage *get)
592{
593 (void) cls;
594 (void) get;
595 /* always well-formed */
596 return GNUNET_OK;
597}
598
599
606static void
608 const struct GNUNET_DHT_ClientGetMessage *get)
609{
610 struct ClientHandle *ch = cls;
611 struct ClientQueryRecord *cqr;
612 uint16_t size = ntohs (get->header.size);
613 const char *xquery = (const char *) &get[1];
614 size_t xquery_size = size - sizeof(struct GNUNET_DHT_ClientGetMessage);
615
617 "Received GET request for %s from local client %p, xq: %.*s\n",
618 GNUNET_h2s (&get->key),
619 ch->client,
620 (int) xquery_size,
621 xquery);
623 "# GET requests received from clients",
624 1,
625 GNUNET_NO);
627 "CLIENT-GET %s\n",
628 GNUNET_h2s_full (&get->key));
629
630 cqr = GNUNET_malloc (sizeof(struct ClientQueryRecord) + xquery_size);
631 cqr->key = get->key;
632 cqr->ch = ch;
633 cqr->xquery = (const void *) &cqr[1];
634 GNUNET_memcpy (&cqr[1],
635 xquery,
636 xquery_size);
638 cqr,
639 0);
642 cqr->unique_id = get->unique_id;
643 cqr->xquery_size = xquery_size;
644 cqr->replication = ntohl (get->desired_replication_level);
645 cqr->msg_options = ntohl (get->options);
646 cqr->type = ntohl (get->type);
648 ch->cqr_tail,
649 cqr);
651 &cqr->key,
652 cqr,
655 cqr->type,
656 0, /* hop count */
657 cqr->replication,
658 &get->key);
659 /* start remote requests */
660 if (NULL != retry_task)
663 NULL);
664 /* perform local lookup */
666 cqr->type,
667 cqr->xquery,
668 xquery_size,
669 NULL,
671 ch);
673}
674
675
680{
685
689 uint64_t unique_id;
690};
691
692
705 const struct GNUNET_HashCode *key,
706 void *value)
707{
708 struct FindByUniqueIdContext *fui_ctx = cls;
709 struct ClientQueryRecord *cqr = value;
710
711 if (cqr->unique_id != fui_ctx->unique_id)
712 return GNUNET_YES;
713 fui_ctx->cqr = cqr;
714 return GNUNET_NO;
715}
716
717
727 void *cls,
728 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
729{
730 uint16_t size = ntohs (seen->header.size);
731 unsigned int hash_count =
732 (size - sizeof(*seen))
733 / sizeof(struct GNUNET_HashCode);
734
735 if (size != sizeof(*seen) + hash_count * sizeof(struct GNUNET_HashCode))
736 {
737 GNUNET_break (0);
738 return GNUNET_SYSERR;
739 }
740 return GNUNET_OK;
741}
742
743
750static void
752 void *cls,
753 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
754{
755 struct ClientHandle *ch = cls;
756 uint16_t size = ntohs (seen->header.size);
757 unsigned int hash_count = (size - sizeof(*seen))
758 / sizeof(struct GNUNET_HashCode);
759 const struct GNUNET_HashCode *hc = (const struct GNUNET_HashCode*) &seen[1];
760 struct FindByUniqueIdContext fui_ctx = {
761 .unique_id = seen->unique_id
762 };
763 unsigned int old_count;
764 struct ClientQueryRecord *cqr;
765
767 &seen->key,
769 &fui_ctx);
770 if (NULL == (cqr = fui_ctx.cqr))
771 {
772 GNUNET_break (0);
774 return;
775 }
776 /* finally, update 'seen' list */
777 old_count = cqr->seen_replies_count;
780 cqr->seen_replies_count + hash_count);
781 GNUNET_memcpy (&cqr->seen_replies[old_count],
782 hc,
783 sizeof(struct GNUNET_HashCode) * hash_count);
784}
785
786
791{
796
800 uint64_t unique_id;
801};
802
803
815 const struct GNUNET_HashCode *key,
816 void *value)
817{
818 const struct RemoveByUniqueIdContext *ctx = cls;
819 struct ClientQueryRecord *cqr = value;
820
821 if (cqr->unique_id != ctx->unique_id)
822 return GNUNET_YES;
824 "Removing client %p's record for key %s (by unique id)\n",
825 ctx->ch->client,
826 GNUNET_h2s (key));
828 return GNUNET_YES;
829}
830
831
840static void
842 void *cls,
843 const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg)
844{
845 struct ClientHandle *ch = cls;
847
849 "# GET STOP requests received from clients",
850 1,
851 GNUNET_NO);
853 "Received GET STOP request for %s from local client %p\n",
854 GNUNET_h2s (&dht_stop_msg->key),
855 ch->client);
856 ctx.ch = ch;
857 ctx.unique_id = dht_stop_msg->unique_id;
859 &dht_stop_msg->key,
861 &ctx);
863}
864
865
870{
875
880
884 unsigned int get_path_length;
885
886};
887
888
901forward_reply (void *cls,
902 const struct GNUNET_HashCode *query_hash,
903 void *value)
904{
905 struct ForwardReplyContext *frc = cls;
907 const struct GNUNET_DATACACHE_Block *bd = frc->bd;
908 struct GNUNET_MQ_Envelope *env;
909 struct GNUNET_DHT_ClientResultMessage *reply;
911 bool do_free;
912 struct GNUNET_HashCode ch;
913 struct GNUNET_DHT_PathElement *paths;
914 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
915 size_t xsize = bd->data_size;
916
918 "CLIENT-RESULT %s\n",
919 GNUNET_h2s_full (&bd->key));
920 if ( (record->type != GNUNET_BLOCK_TYPE_ANY) &&
921 (record->type != bd->type) )
922 {
924 "Record type mismatch, not passing request for key %s to local client\n",
925 GNUNET_h2s (&bd->key));
927 "# Key match, type mismatches in REPLY to CLIENT",
928 1,
929 GNUNET_NO);
930 return GNUNET_YES; /* type mismatch */
931 }
932 if ( (0 == (record->msg_options & GNUNET_DHT_RO_FIND_APPROXIMATE)) &&
933 (0 != GNUNET_memcmp (&bd->key,
934 query_hash)) )
935 {
937 "# Inexact key match, but exact match required",
938 1,
939 GNUNET_NO);
940 return GNUNET_YES; /* type mismatch */
941 }
943 bd->data_size,
944 &ch);
945 for (unsigned int i = 0; i < record->seen_replies_count; i++)
946 if (0 ==
947 GNUNET_memcmp (&record->seen_replies[i],
948 &ch))
949 {
951 "Duplicate reply, not passing request for key %s to local client\n",
952 GNUNET_h2s (&bd->key));
954 "# Duplicate REPLIES to CLIENT request dropped",
955 1,
956 GNUNET_NO);
957 return GNUNET_YES; /* duplicate */
958 }
959 eval
961 record->type,
962 NULL,
963 &bd->key,
964 record->xquery,
965 record->xquery_size,
966 bd->data,
967 bd->data_size);
969 "Evaluation result is %d for key %s for local client's query\n",
970 (int) eval,
971 GNUNET_h2s (&bd->key));
972 switch (eval)
973 {
975 do_free = true;
976 break;
979 GNUNET_array_append (record->seen_replies,
980 record->seen_replies_count,
981 ch);
982 do_free = false;
983 break;
985 /* should be impossible to encounter here */
986 GNUNET_break (0);
987 return GNUNET_YES;
989 return GNUNET_YES;
990 default:
991 GNUNET_break (0);
992 return GNUNET_NO;
993 }
995 "# RESULTS queued for clients",
996 1,
997 GNUNET_NO);
998 xsize += (frc->get_path_length + bd->put_path_length)
999 * sizeof(struct GNUNET_DHT_PathElement);
1000 if (truncated)
1001 xsize += sizeof (struct GNUNET_PeerIdentity);
1002
1003#if SUPER_REDUNDANT_CHECK
1004 GNUNET_break (0 ==
1006 bd->data_size,
1007 bd->expiration_time,
1008 truncated
1009 ? &bd->trunc_peer
1010 : NULL,
1011 bd->put_path,
1012 bd->put_path_length,
1013 frc->get_path,
1014 frc->get_path_length,
1015 &GDS_my_identity));
1016#endif
1017
1018 env = GNUNET_MQ_msg_extra (reply,
1019 xsize,
1021 reply->type = htonl (bd->type);
1022 reply->options = htonl (bd->ro);
1023 reply->get_path_length = htonl (frc->get_path_length);
1024 reply->put_path_length = htonl (bd->put_path_length);
1025 reply->unique_id = record->unique_id;
1027 reply->key = *query_hash;
1028 if (truncated)
1029 {
1030 void *tgt = &reply[1];
1031
1032 GNUNET_memcpy (tgt,
1033 &bd->trunc_peer,
1034 sizeof (struct GNUNET_PeerIdentity));
1035 paths = (struct GNUNET_DHT_PathElement *)
1036 (tgt + sizeof (struct GNUNET_PeerIdentity));
1037 }
1038 else
1039 {
1040 paths = (struct GNUNET_DHT_PathElement *) &reply[1];
1041 }
1042 GNUNET_memcpy (paths,
1043 bd->put_path,
1044 sizeof(struct GNUNET_DHT_PathElement)
1045 * bd->put_path_length);
1046 GNUNET_memcpy (&paths[bd->put_path_length],
1047 frc->get_path,
1048 sizeof(struct GNUNET_DHT_PathElement)
1049 * frc->get_path_length);
1050 GNUNET_memcpy (&paths[frc->get_path_length + bd->put_path_length],
1051 bd->data,
1052 bd->data_size);
1054 "Sending reply to query %s for client %p\n",
1055 GNUNET_h2s (query_hash),
1056 record->ch->client);
1057 GNUNET_MQ_send (record->ch->mq,
1058 env);
1059 if (GNUNET_YES == do_free)
1061 return GNUNET_YES;
1062}
1063
1064
1065bool
1067 const struct GNUNET_HashCode *query_hash,
1068 unsigned int get_path_length,
1069 const struct GNUNET_DHT_PathElement *get_path)
1070{
1071 struct ForwardReplyContext frc;
1072 size_t msize = sizeof (struct GNUNET_DHT_ClientResultMessage)
1073 + bd->data_size
1075 * sizeof(struct GNUNET_DHT_PathElement);
1076#if SANITY_CHECKS > 1
1077 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1078#endif
1079
1080 if (msize >= GNUNET_MAX_MESSAGE_SIZE)
1081 {
1082 GNUNET_break (0);
1083 return false;
1084 }
1085#if SANITY_CHECKS > 1
1086 if (0 !=
1088 bd->data_size,
1089 bd->expiration_time,
1090 truncated
1091 ? &bd->trunc_peer
1092 : NULL,
1093 bd->put_path,
1094 bd->put_path_length,
1095 get_path,
1096 get_path_length,
1098 {
1099 GNUNET_break (0);
1100 return false;
1101 }
1102#endif
1103 frc.bd = bd;
1104 frc.get_path = get_path;
1105 frc.get_path_length = get_path_length;
1107 "Forwarding reply for query hash %s with GPL %u and PPL %u to client\n",
1108 GNUNET_h2s (query_hash),
1109 get_path_length,
1110 bd->put_path_length);
1111 if (0 ==
1113 query_hash,
1115 &frc))
1116 {
1118 "No matching client for reply for query %s\n",
1119 GNUNET_h2s (query_hash));
1121 "# REPLIES ignored for CLIENTS (no match)",
1122 1,
1123 GNUNET_NO);
1124 }
1125 return true;
1126}
1127
1128
1129/* **************** HELLO logic ***************** */
1130
1131
1140static void
1142 const struct GNUNET_MessageHeader *msg)
1143{
1144 struct ClientHandle *ch = cls;
1145 struct GNUNET_HELLO_Parser *p;
1146 char *url;
1147 size_t slen;
1148 struct GNUNET_MessageHeader *hdr;
1149 struct GNUNET_MQ_Envelope *env;
1150
1152 GNUNET_assert (NULL != p);
1154 slen = strlen (url) + 1;
1156 "Handling request from local client for my HELLO\n");
1157 env = GNUNET_MQ_msg_extra (hdr,
1158 slen,
1160 memcpy (&hdr[1],
1161 url,
1162 slen);
1163 GNUNET_free (url);
1166 env);
1168}
1169
1170
1178static enum GNUNET_GenericReturnValue
1180 const struct GNUNET_MessageHeader *hdr)
1181{
1182 uint16_t len = ntohs (hdr->size);
1183 const char *buf = (const char *) &hdr[1];
1184
1185 (void) cls;
1186 if ('\0' != buf[len - sizeof (*hdr) - 1])
1187 {
1188 GNUNET_break (0);
1189 return GNUNET_SYSERR;
1190 }
1191 return GNUNET_OK;
1192}
1193
1194
1202static void
1204 const struct GNUNET_MessageHeader *msg)
1205{
1206 struct ClientHandle *ch = cls;
1207 const char *url = (const char *) &msg[1];
1208 struct GNUNET_HELLO_Parser *b;
1209
1211 "Local client provided HELLO URL %s\n",
1212 url);
1214 if (NULL == b)
1215 {
1216 GNUNET_break (0);
1218 return;
1219 }
1223 NULL);
1225}
1226
1227
1228/* ************* logic for monitors ************** */
1229
1230
1238static void
1241{
1242 struct ClientHandle *ch = cls;
1243 struct ClientMonitorRecord *r;
1244
1245 r = GNUNET_new (struct ClientMonitorRecord);
1246 r->ch = ch;
1247 r->type = ntohl (msg->type);
1248 r->get = ntohs (msg->get);
1249 r->get_resp = ntohs (msg->get_resp);
1250 r->put = ntohs (msg->put);
1251 if (0 != ntohs (msg->filter_key))
1252 r->key = msg->key;
1255 r);
1257}
1258
1259
1266static void
1268 void *cls,
1270{
1271 struct ClientHandle *ch = cls;
1272
1274 for (struct ClientMonitorRecord *r = monitor_head;
1275 NULL != r;
1276 r = r->next)
1277 {
1278 bool keys_match;
1279
1280 keys_match =
1281 (GNUNET_is_zero (&r->key))
1282 ? (0 == ntohs (msg->filter_key))
1283 : ( (0 != ntohs (msg->filter_key)) &&
1284 (! GNUNET_memcmp (&r->key,
1285 &msg->key)) );
1286 if ( (ch == r->ch) &&
1287 (ntohl (msg->type) == r->type) &&
1288 (r->get == msg->get) &&
1289 (r->get_resp == msg->get_resp) &&
1290 (r->put == msg->put) &&
1291 keys_match)
1292 {
1295 r);
1296 GNUNET_free (r);
1297 return; /* Delete only ONE entry */
1298 }
1299 }
1300}
1301
1302
1309typedef void
1310(*MonitorAction)(void *cls,
1311 struct ClientMonitorRecord *m);
1312
1313
1323static void
1325 const struct GNUNET_HashCode *key,
1326 MonitorAction cb,
1327 void *cb_cls)
1328{
1329 struct ClientHandle **cl = NULL;
1330 unsigned int cl_size = 0;
1331
1332 for (struct ClientMonitorRecord *m = monitor_head;
1333 NULL != m;
1334 m = m->next)
1335 {
1336 bool found = false;
1337
1338 if ( (GNUNET_BLOCK_TYPE_ANY != m->type) &&
1339 (m->type != type) )
1340 continue;
1341 if ( (! GNUNET_is_zero (&m->key)) &&
1342 (0 ==
1344 &m->key)) )
1345 continue;
1346 /* Don't send duplicates */
1347 for (unsigned i = 0; i < cl_size; i++)
1348 if (cl[i] == m->ch)
1349 {
1350 found = true;
1351 break;
1352 }
1353 if (found)
1354 continue;
1356 cl_size,
1357 m->ch);
1358 cb (cb_cls,
1359 m);
1360 }
1361 GNUNET_free (cl);
1362}
1363
1364
1377
1378
1386static void
1387get_action (void *cls,
1388 struct ClientMonitorRecord *m)
1389{
1390 struct GetActionContext *gac = cls;
1391 struct GNUNET_MQ_Envelope *env;
1392 struct GNUNET_DHT_MonitorGetMessage *mmsg;
1393
1394 env = GNUNET_MQ_msg (mmsg,
1396 mmsg->options = htonl (gac->options);
1397 mmsg->type = htonl (gac->type);
1398 mmsg->hop_count = htonl (gac->hop_count);
1400 mmsg->key = *gac->key;
1401 GNUNET_MQ_send (m->ch->mq,
1402 env);
1403}
1404
1405
1406void
1409 uint32_t hop_count,
1411 const struct GNUNET_HashCode *key)
1412{
1413 struct GetActionContext gac = {
1414 .options = options,
1415 .type = type,
1416 .hop_count = hop_count,
1417 .desired_replication_level = desired_replication_level,
1418 .key = key
1419 };
1420
1422 key,
1423 &get_action,
1424 &gac);
1425}
1426
1427
1437
1438
1446static void
1448 struct ClientMonitorRecord *m)
1449{
1450 const struct ResponseActionContext *resp_ctx = cls;
1451 const struct GNUNET_DATACACHE_Block *bd = resp_ctx->bd;
1452 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1453 struct GNUNET_MQ_Envelope *env;
1455 struct GNUNET_DHT_PathElement *path;
1456 size_t msize;
1457
1458 msize = bd->data_size;
1459 msize += (resp_ctx->get_path_length + bd->put_path_length)
1460 * sizeof(struct GNUNET_DHT_PathElement);
1461 if (truncated)
1462 msize += sizeof (struct GNUNET_PeerIdentity);
1463 env = GNUNET_MQ_msg_extra (mmsg,
1464 msize,
1466 mmsg->type = htonl (bd->type);
1467 mmsg->put_path_length = htonl (bd->put_path_length);
1468 mmsg->get_path_length = htonl (resp_ctx->get_path_length);
1470 mmsg->key = bd->key;
1471 if (truncated)
1472 {
1473 void *tgt = &mmsg[1];
1474
1475 GNUNET_memcpy (tgt,
1476 &bd->trunc_peer,
1477 sizeof (struct GNUNET_PeerIdentity));
1478 path = (struct GNUNET_DHT_PathElement *)
1479 (tgt + sizeof (struct GNUNET_PeerIdentity));
1480 }
1481 else
1482 {
1483 path = (struct GNUNET_DHT_PathElement *) &mmsg[1];
1484 }
1485 GNUNET_memcpy (path,
1486 bd->put_path,
1487 bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement));
1488 GNUNET_memcpy (path,
1489 resp_ctx->get_path,
1490 resp_ctx->get_path_length
1491 * sizeof(struct GNUNET_DHT_PathElement));
1492 GNUNET_memcpy (&path[resp_ctx->get_path_length],
1493 bd->data,
1494 bd->data_size);
1495 GNUNET_MQ_send (m->ch->mq,
1496 env);
1497}
1498
1499
1500void
1502 const struct GNUNET_DHT_PathElement *get_path,
1503 unsigned int get_path_length)
1504{
1505 struct ResponseActionContext rac = {
1506 .bd = bd,
1507 .get_path = get_path,
1508 .get_path_length = get_path_length
1509 };
1510
1512 &bd->key,
1514 &rac);
1515}
1516
1517
1527
1528
1536static void
1537put_action (void *cls,
1538 struct ClientMonitorRecord *m)
1539{
1540 const struct PutActionContext *put_ctx = cls;
1541 const struct GNUNET_DATACACHE_Block *bd = put_ctx->bd;
1542 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1543 struct GNUNET_MQ_Envelope *env;
1544 struct GNUNET_DHT_MonitorPutMessage *mmsg;
1545 struct GNUNET_DHT_PathElement *msg_path;
1546 size_t msize;
1547
1548 msize = bd->data_size
1549 + bd->put_path_length
1550 * sizeof(struct GNUNET_DHT_PathElement);
1551 if (truncated)
1552 msize += sizeof (struct GNUNET_PeerIdentity);
1553 env = GNUNET_MQ_msg_extra (mmsg,
1554 msize,
1556 mmsg->options = htonl (bd->ro);
1557 mmsg->type = htonl (bd->type);
1558 mmsg->hop_count = htonl (put_ctx->hop_count);
1560 mmsg->put_path_length = htonl (bd->put_path_length);
1561 mmsg->key = bd->key;
1563 if (truncated)
1564 {
1565 void *tgt = &mmsg[1];
1566
1567 GNUNET_memcpy (tgt,
1568 &bd->trunc_peer,
1569 sizeof (struct GNUNET_PeerIdentity));
1570 msg_path = (struct GNUNET_DHT_PathElement *)
1571 (tgt + sizeof (struct GNUNET_PeerIdentity));
1572 }
1573 else
1574 {
1575 msg_path = (struct GNUNET_DHT_PathElement *) &mmsg[1];
1576 }
1577 GNUNET_memcpy (msg_path,
1578 bd->put_path,
1579 bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement));
1580 GNUNET_memcpy (&msg_path[bd->put_path_length],
1581 bd->data,
1582 bd->data_size);
1583 GNUNET_MQ_send (m->ch->mq,
1584 env);
1585}
1586
1587
1588void
1590 uint32_t hop_count,
1591 uint32_t desired_replication_level)
1592{
1593 struct PutActionContext put_ctx = {
1594 .bd = bd,
1595 .hop_count = hop_count,
1596 .desired_replication_level = desired_replication_level
1597 };
1598
1600 &bd->key,
1601 &put_action,
1602 &put_ctx);
1603}
1604
1605
1606/* ********************** Initialization logic ***************** */
1607
1608
1612void
1621
1622
1626void
1628{
1629 if (NULL != retry_task)
1630 {
1632 retry_task = NULL;
1633 }
1634}
1635
1636
1643#define GDS_DHT_SERVICE_INIT(name, run) \
1644 GNUNET_SERVICE_MAIN \
1645 (GNUNET_OS_project_data_gnunet (), \
1646 name, \
1647 GNUNET_SERVICE_OPTION_NONE, \
1648 run, \
1649 &client_connect_cb, \
1650 &client_disconnect_cb, \
1651 NULL, \
1652 GNUNET_MQ_hd_var_size (dht_local_put, \
1653 GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, \
1654 struct GNUNET_DHT_ClientPutMessage, \
1655 NULL), \
1656 GNUNET_MQ_hd_var_size (dht_local_get, \
1657 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, \
1658 struct GNUNET_DHT_ClientGetMessage, \
1659 NULL), \
1660 GNUNET_MQ_hd_fixed_size (dht_local_get_stop, \
1661 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, \
1662 struct GNUNET_DHT_ClientGetStopMessage, \
1663 NULL), \
1664 GNUNET_MQ_hd_fixed_size (dht_local_monitor, \
1665 GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, \
1666 struct GNUNET_DHT_MonitorStartStopMessage, \
1667 NULL), \
1668 GNUNET_MQ_hd_fixed_size (dht_local_monitor_stop, \
1669 GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP, \
1670 struct GNUNET_DHT_MonitorStartStopMessage, \
1671 NULL), \
1672 GNUNET_MQ_hd_var_size (dht_local_get_result_seen, \
1673 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, \
1674 struct GNUNET_DHT_ClientGetResultSeenMessage, \
1675 NULL), \
1676 GNUNET_MQ_hd_fixed_size (dht_local_hello_get, \
1677 GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_GET, \
1678 struct GNUNET_MessageHeader, \
1679 NULL), \
1680 GNUNET_MQ_hd_var_size (dht_local_hello_offer, \
1681 GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_URL, \
1682 struct GNUNET_MessageHeader, \
1683 NULL), \
1684 GNUNET_MQ_handler_end ())
1685
1687
1691void __attribute__ ((destructor))
1692GDS_CLIENTS_done (void)
1693{
1694 if (NULL != retry_heap)
1695 {
1698 retry_heap = NULL;
1699 }
1700 if (NULL != forward_map)
1701 {
1704 forward_map = NULL;
1705 }
1706}
1707
1708
1709/* end of gnunet-service-dht_clients.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.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:103
static int monitor
Monitor ARM activity.
Definition gnunet-arm.c:63
static unsigned int replication_level
Replication level option to use for publishing.
static struct GNUNET_CADET_Channel * ch
Channel handle.
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_MessageHeader * GDS_my_hello
Our HELLO.
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...
struct GNUNET_PILS_Handle * GDS_pils
Handle for the pils service.
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.
void GDS_CLIENTS_init(void)
Initialize client subsystem.
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.
void GDS_CLIENTS_done(void)
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.
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.
#define LOG(kind,...)
void GDS_CLIENTS_stop(void)
Shutdown client subsystem.
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)?
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.
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.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition gnunet-uri.c:38
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 GNUNET_PQ_ResultSpec __attribute__
#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
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
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
@ 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:1349
@ 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_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
Definition hello-uri.c:379
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg.
Definition hello-uri.c:415
char * GNUNET_HELLO_parser_to_url(const struct GNUNET_HELLO_Parser *parser)
Generate GNUnet HELLO URI from a parser.
Definition hello-uri.c:803
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:975
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_url(const char *url)
Parse GNUnet HELLO url.
Definition hello-uri.c:663
#define GNUNET_is_zero(a)
Check that memory in a is all zeros.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#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.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_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:305
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#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:1254
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1304
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition service.c:2462
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition service.c:2433
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:741
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:640
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition time.c:671
#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
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
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
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 parsing HELLOs.
Definition hello-uri.c:232
A 512-bit hashcode.
Handle to a message queue.
Definition mq.c:87
Header for all communications.
A handle for the PILS service.
Definition pils_api.c:82
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:249
Handle to a service.
Definition service.c:116
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