GNUnet 0.21.0
dht_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2012, 2016, 2018, 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#include "platform.h"
29#include "gnunet_constants.h"
30#include "gnunet_signatures.h"
31#include "gnunet_arm_service.h"
32#include "gnunet_protocols.h"
33#include "gnunet_dht_service.h"
34#include "dht.h"
35
36#define LOG(kind, ...) GNUNET_log_from (kind, "dht-api", __VA_ARGS__)
37
38
43{
48
53
58
63
67 void *cont_cls;
68
73};
74
79{
84
88 void *iter_cls;
89
94
100
105
109 uint64_t unique_id;
110
115
120
125
130
135 unsigned int seen_results_size;
136
141 unsigned int seen_results_end;
142};
143
144
149{
154
159
164
169
174
179
184
189
193 void *cb_cls;
194};
195
196
201{
202
207
212
217
221 void *cb_cls;
222
227
228};
229
230
235{
240
245
250
255
260
265
270
275
281
286
292
296 uint64_t uid_gen;
297};
298
299
308
309
315static void
317{
318 struct GNUNET_DHT_Handle *h = gh->dht_handle;
319 struct GNUNET_MQ_Envelope *env;
320 struct GNUNET_DHT_ClientGetMessage *get_msg;
321
322 env = GNUNET_MQ_msg_extra (get_msg,
323 gh->xquery_size,
325 get_msg->options = htonl ((uint32_t) gh->options);
327 get_msg->type = htonl (gh->type);
328 get_msg->key = gh->key;
329 get_msg->unique_id = gh->unique_id;
330 GNUNET_memcpy (&get_msg[1],
331 &gh[1],
332 gh->xquery_size);
334 env);
335}
336
337
347static void
349 unsigned int transmission_offset_start)
350{
351 struct GNUNET_DHT_Handle *h = gh->dht_handle;
352 struct GNUNET_MQ_Envelope *env;
354 unsigned int delta;
355 unsigned int max;
356 unsigned int transmission_offset;
357
358 max = (GNUNET_MAX_MESSAGE_SIZE - sizeof(*msg))
359 / sizeof(struct GNUNET_HashCode);
360 transmission_offset = transmission_offset_start;
361 while (transmission_offset < gh->seen_results_end)
362 {
363 delta = gh->seen_results_end - transmission_offset;
364 if (delta > max)
365 delta = max;
367 delta * sizeof(struct GNUNET_HashCode),
369 msg->key = gh->key;
370 msg->unique_id = gh->unique_id;
371 GNUNET_memcpy (&msg[1],
372 &gh->seen_results[transmission_offset],
373 sizeof(struct GNUNET_HashCode) * delta);
375 env);
376 transmission_offset += delta;
377 }
378}
379
380
392 const struct GNUNET_HashCode *key,
393 void *value)
394{
395 struct GNUNET_DHT_Handle *handle = cls;
396 struct GNUNET_DHT_GetHandle *gh = value;
397
399 "Retransmitting request related to %s to DHT %p\n",
400 GNUNET_h2s (key),
401 handle);
402 send_get (gh);
404 return GNUNET_YES;
405}
406
407
413static void
415{
416 struct GNUNET_DHT_Handle *h = mh->dht_handle;
417 struct GNUNET_MQ_Envelope *env;
419
422 m->type = htonl (mh->type);
423 m->get = htons (NULL != mh->get_cb);
424 m->get_resp = htons (NULL != mh->get_resp_cb);
425 m->put = htons (NULL != mh->put_cb);
426 if (NULL != mh->key)
427 {
428 m->filter_key = htons (1);
429 m->key = *mh->key;
430 }
432 env);
433}
434
435
441static void
442try_reconnect (void *cls)
443{
444 struct GNUNET_DHT_Handle *h = cls;
446
448 "Reconnecting with DHT %p\n",
449 h);
450 h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time);
451 h->reconnect_task = NULL;
452 if (GNUNET_YES != try_connect (h))
453 {
455 "DHT reconnect failed!\n");
457 = GNUNET_SCHEDULER_add_delayed (h->retry_time,
459 h);
460 return;
461 }
464 h);
465 for (mh = h->monitor_head; NULL != mh; mh = mh->next)
467}
468
469
475static void
477{
478 struct GNUNET_DHT_PutHandle *ph;
480 void *cont_cls;
481
482 if (NULL == h->mq)
483 return;
485 h->mq = NULL;
487 "Disconnecting from DHT service, will try to reconnect in %s\n",
489 GNUNET_YES));
490 /* notify client about all PUTs that (may) have failed due to disconnect */
491 while (NULL != (ph = h->put_head))
492 {
493 cont = ph->cont;
494 cont_cls = ph->cont_cls;
495 ph->env = NULL;
497 if (NULL != cont)
498 cont (cont_cls);
499 }
500 GNUNET_assert (NULL == h->reconnect_task);
502 = GNUNET_SCHEDULER_add_delayed (h->retry_time,
504 h);
505}
506
507
516static void
518 enum GNUNET_MQ_Error error)
519{
520 struct GNUNET_DHT_Handle *h = cls;
521
523}
524
525
532static void
534 const struct GNUNET_DHT_MonitorGetMessage *msg)
535{
536 struct GNUNET_DHT_Handle *handle = cls;
538 = (enum GNUNET_DHT_RouteOption) ntohl (msg->options);
539
540 for (struct GNUNET_DHT_MonitorHandle *mh = handle->monitor_head;
541 NULL != mh;
542 mh = mh->next)
543 {
544 if (NULL == mh->get_cb)
545 continue;
546 if ( (GNUNET_BLOCK_TYPE_ANY != mh->type) &&
547 (mh->type != ntohl (msg->type)))
548 continue;
549 if ( (NULL != mh->key) &&
550 (0 != GNUNET_memcmp (mh->key,
551 &msg->key)) )
552 continue;
553 mh->get_cb (mh->cb_cls,
554 ro,
555 (enum GNUNET_BLOCK_Type) ntohl (msg->type),
556 ntohl (msg->hop_count),
557 ntohl (msg->desired_replication_level),
558 &msg->key);
559 }
560}
561
562
574{
575 size_t msize = ntohs (msg->header.size) - sizeof(*msg);
576 uint32_t getl = ntohl (msg->get_path_length);
577 uint32_t putl = ntohl (msg->put_path_length);
579 = (enum GNUNET_DHT_RouteOption) ntohl (msg->options);
580 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
581
582 if (truncated)
583 {
584 if (msize < sizeof (struct GNUNET_PeerIdentity))
585 {
586 GNUNET_break (0);
587 return GNUNET_SYSERR;
588 }
589 msize -= sizeof (struct GNUNET_PeerIdentity);
590 }
591 if ((getl + putl < getl) ||
592 ((msize / sizeof(struct GNUNET_DHT_PathElement)) < getl + putl))
593 {
594 GNUNET_break (0);
595 return GNUNET_SYSERR;
596 }
597 return GNUNET_OK;
598}
599
600
607static void
610{
611 struct GNUNET_DHT_Handle *handle = cls;
612 size_t msize = ntohs (msg->header.size) - sizeof(*msg);
614 = (enum GNUNET_DHT_RouteOption) ntohl (msg->options);
615 uint32_t getl = ntohl (msg->get_path_length);
616 uint32_t putl = ntohl (msg->put_path_length);
617 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
618 const struct GNUNET_PeerIdentity *trunc_peer
619 = truncated
620 ? (const struct GNUNET_PeerIdentity *) &msg[1]
621 : NULL;
622 const struct GNUNET_DHT_PathElement *path
623 = truncated
624 ? (const struct GNUNET_DHT_PathElement *) &trunc_peer[1]
625 : (const struct GNUNET_DHT_PathElement *) &msg[1];
626
627 if (truncated)
628 msize -= sizeof (struct GNUNET_PeerIdentity);
629 msize -= sizeof(struct GNUNET_DHT_PathElement) * (putl + getl);
630 for (struct GNUNET_DHT_MonitorHandle *mh = handle->monitor_head;
631 NULL != mh;
632 mh = mh->next)
633 {
634 if (NULL == mh->get_resp_cb)
635 continue;
636 if ( (GNUNET_BLOCK_TYPE_ANY != mh->type) &&
637 (mh->type != ntohl (msg->type)) )
638 continue;
639 if ( (NULL != mh->key) &&
640 (0 != GNUNET_memcmp (mh->key,
641 &msg->key)) )
642 continue;
643 mh->get_resp_cb (mh->cb_cls,
644 (enum GNUNET_BLOCK_Type) ntohl (msg->type),
645 trunc_peer,
646 &path[putl],
647 getl,
648 path,
649 putl,
650 GNUNET_TIME_absolute_ntoh (msg->expiration_time),
651 &msg->key,
652 (const void *) &path[getl + putl],
653 msize);
654 }
655}
656
657
668 const struct GNUNET_DHT_MonitorPutMessage *msg)
669{
670 size_t msize = ntohs (msg->header.size) - sizeof(*msg);
671 uint32_t putl = ntohl (msg->put_path_length);
673 = (enum GNUNET_DHT_RouteOption) ntohl (msg->options);
674 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
675
676 if (truncated)
677 {
678 if (msize < sizeof (struct GNUNET_PeerIdentity))
679 {
680 GNUNET_break (0);
681 return GNUNET_SYSERR;
682 }
683 msize -= sizeof (struct GNUNET_PeerIdentity);
684 }
685 if ((msize / sizeof(struct GNUNET_DHT_PathElement)) < putl)
686 {
687 GNUNET_break (0);
688 return GNUNET_SYSERR;
689 }
690 return GNUNET_OK;
691}
692
693
700static void
702 const struct GNUNET_DHT_MonitorPutMessage *msg)
703{
704 struct GNUNET_DHT_Handle *handle = cls;
705 size_t msize = ntohs (msg->header.size) - sizeof(*msg);
706 uint32_t putl = ntohl (msg->put_path_length);
708 = (enum GNUNET_DHT_RouteOption) ntohl (msg->options);
709 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
710 const struct GNUNET_PeerIdentity *trunc_peer
711 = truncated
712 ? (const struct GNUNET_PeerIdentity *) &msg[1]
713 : NULL;
714 const struct GNUNET_DHT_PathElement *path
715 = truncated
716 ? (const struct GNUNET_DHT_PathElement *) &trunc_peer[1]
717 : (const struct GNUNET_DHT_PathElement *) &msg[1];
718
719 if (truncated)
720 msize -= sizeof (struct GNUNET_PeerIdentity);
721 msize -= sizeof(struct GNUNET_DHT_PathElement) * putl;
722 for (struct GNUNET_DHT_MonitorHandle *mh = handle->monitor_head;
723 NULL != mh;
724 mh = mh->next)
725 {
726 if (NULL == mh->put_cb)
727 continue;
728 if ( (GNUNET_BLOCK_TYPE_ANY != mh->type) &&
729 (mh->type != ntohl (msg->type)) )
730 continue;
731 if ( (NULL != mh->key) &&
732 (0 != GNUNET_memcmp (mh->key,
733 &msg->key)) )
734 continue;
735 mh->put_cb (mh->cb_cls,
736 ro,
737 (enum GNUNET_BLOCK_Type) ntohl (msg->type),
738 ntohl (msg->hop_count),
739 ntohl (msg->desired_replication_level),
740 trunc_peer,
741 putl,
742 path,
743 GNUNET_TIME_absolute_ntoh (msg->expiration_time),
744 &msg->key,
745 (const void *) &path[putl],
746 msize);
747 }
748}
749
750
762{
763 size_t msize = ntohs (msg->header.size) - sizeof(*msg);
764 uint32_t put_path_length = ntohl (msg->put_path_length);
765 uint32_t get_path_length = ntohl (msg->get_path_length);
767 = (enum GNUNET_DHT_RouteOption) ntohl (msg->options);
768 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
769 size_t meta_length;
770
771 if (truncated)
772 {
773 if (msize < sizeof (struct GNUNET_PeerIdentity))
774 {
775 GNUNET_break (0);
776 return GNUNET_SYSERR;
777 }
778 msize -= sizeof (struct GNUNET_PeerIdentity);
779 }
780 meta_length = msize / sizeof(struct GNUNET_DHT_PathElement);
781 if ( (get_path_length + put_path_length >
782 meta_length) ||
783 (get_path_length + put_path_length <
784 get_path_length) )
785 {
786 GNUNET_break (0);
787 return GNUNET_SYSERR;
788 }
789 return GNUNET_OK;
790}
791
792
803 const struct GNUNET_HashCode *key,
804 void *value)
805{
806 const struct GNUNET_DHT_ClientResultMessage *crm = cls;
808 size_t msize = ntohs (crm->header.size) - sizeof(*crm);
809 uint16_t type = ntohl (crm->type);
811 = (enum GNUNET_DHT_RouteOption) ntohl (crm->options);
812 bool truncated
813 = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
814 uint32_t put_path_length
815 = ntohl (crm->put_path_length);
816 uint32_t get_path_length
817 = ntohl (crm->get_path_length);
818 const struct GNUNET_PeerIdentity *trunc_peer
819 = truncated
820 ? (const struct GNUNET_PeerIdentity *) &crm[1]
821 : NULL;
822 const struct GNUNET_DHT_PathElement *put_path
823 = truncated
824 ? (const struct GNUNET_DHT_PathElement *) &trunc_peer[1]
825 : (const struct GNUNET_DHT_PathElement *) &crm[1];
826 const struct GNUNET_DHT_PathElement *get_path
827 = &put_path[put_path_length];
828 const void *data
829 = &get_path[get_path_length];
830 size_t meta_length
831 = sizeof(struct GNUNET_DHT_PathElement)
832 * (get_path_length + put_path_length);
833 size_t data_length
834 = msize - meta_length;
835 struct GNUNET_HashCode hc;
836
837 if (truncated)
838 data_length -= sizeof (struct GNUNET_PeerIdentity);
839 if (crm->unique_id != get_handle->unique_id)
840 {
841 /* UID mismatch */
843 "Ignoring reply for %s: UID mismatch: %llu/%llu\n",
844 GNUNET_h2s (key),
845 (unsigned long long) crm->unique_id,
846 (unsigned long long) get_handle->unique_id);
847 return GNUNET_YES;
848 }
850 (get_handle->type != type) )
851 {
852 /* type mismatch */
853 GNUNET_break (0);
854 return GNUNET_YES;
855 }
856
857 {
858 char *pp;
859 char *gp;
860
861 gp = GNUNET_DHT_pp2s (get_path,
862 get_path_length);
863 pp = GNUNET_DHT_pp2s (put_path,
864 put_path_length);
866 "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n",
867 (unsigned int) data_length,
868 GNUNET_h2s (key),
869 gp,
870 pp);
871 GNUNET_free (gp);
872 GNUNET_free (pp);
873 }
874 /* remember that we've seen this result */
876 data_length,
877 &hc);
883 /* no need to block it explicitly, service already knows about it! */
886 key,
887 trunc_peer,
888 get_path,
889 get_path_length,
890 put_path,
891 put_path_length,
892 type,
893 data_length,
894 data);
895 return GNUNET_YES;
896}
897
898
905static void
908{
909 struct GNUNET_DHT_Handle *handle = cls;
910
912 &msg->key,
914 (void *) msg);
915}
916
917
927 const struct GNUNET_MessageHeader *hdr)
928{
929 uint16_t len = ntohs (hdr->size);
930 const char *buf = (const char *) &hdr[1];
931
932 (void) cls;
933 if ('\0' != buf[len - sizeof (*hdr) - 1])
934 {
935 GNUNET_break (0);
936 return GNUNET_SYSERR;
937 }
938 return GNUNET_OK;
939}
940
941
948static void
950 const struct GNUNET_MessageHeader *hdr)
951{
952 struct GNUNET_DHT_Handle *handle = cls;
953 const char *url = (const char *) &hdr[1];
954 struct GNUNET_DHT_HelloGetHandle *hgh;
955
956 while (NULL != (hgh = handle->hgh_head))
957 {
958 hgh->cb (hgh->cb_cls,
959 url);
961 }
962}
963
964
970static void
972{
973 struct GNUNET_DHT_PutHandle *ph = cls;
975 void *cont_cls;
976
977 cont = ph->cont;
978 cont_cls = ph->cont_cls;
979 ph->env = NULL;
981 if (NULL != cont)
982 cont (cont_cls);
983}
984
985
994{
996 GNUNET_MQ_hd_fixed_size (monitor_get,
999 h),
1000 GNUNET_MQ_hd_var_size (monitor_get_resp,
1003 h),
1004 GNUNET_MQ_hd_var_size (monitor_put,
1007 h),
1008 GNUNET_MQ_hd_var_size (client_result,
1011 h),
1012 GNUNET_MQ_hd_var_size (client_hello,
1014 struct GNUNET_MessageHeader,
1015 h),
1017 };
1018
1019 if (NULL != h->mq)
1020 return GNUNET_OK;
1022 "dht",
1023 handlers,
1025 h);
1026 if (NULL == h->mq)
1027 {
1029 "Failed to connect to the DHT service!\n");
1030 return GNUNET_NO;
1031 }
1032 return GNUNET_YES;
1033}
1034
1035
1036struct GNUNET_DHT_Handle *
1038 unsigned int ht_len)
1039{
1040 struct GNUNET_DHT_Handle *handle;
1041
1043 handle->cfg = cfg;
1044 handle->uid_gen
1046 UINT64_MAX);
1047 handle->active_requests
1049 GNUNET_YES);
1050 if (GNUNET_NO == try_connect (handle))
1051 {
1053 return NULL;
1054 }
1055 return handle;
1056}
1057
1058
1059void
1061{
1062 struct GNUNET_DHT_PutHandle *ph;
1063
1064 GNUNET_assert (0 ==
1065 GNUNET_CONTAINER_multihashmap_size (handle->active_requests));
1066 while (NULL != (ph = handle->put_head))
1067 {
1068 if (NULL != ph->cont)
1069 ph->cont (ph->cont_cls);
1071 }
1072 if (NULL != handle->mq)
1073 {
1075 handle->mq = NULL;
1076 }
1077 if (NULL != handle->reconnect_task)
1078 {
1079 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
1080 handle->reconnect_task = NULL;
1081 }
1084}
1085
1086
1087struct GNUNET_DHT_PutHandle *
1089 const struct GNUNET_HashCode *key,
1090 uint32_t desired_replication_level,
1093 size_t size,
1094 const void *data,
1095 struct GNUNET_TIME_Absolute exp,
1097 void *cont_cls)
1098{
1099 struct GNUNET_MQ_Envelope *env;
1100 struct GNUNET_DHT_ClientPutMessage *put_msg;
1101 size_t msize;
1102 struct GNUNET_DHT_PutHandle *ph;
1103
1104 msize = sizeof(struct GNUNET_DHT_ClientPutMessage) + size;
1105 if ((msize >= GNUNET_MAX_MESSAGE_SIZE) ||
1107 {
1108 GNUNET_break (0);
1109 return NULL;
1110 }
1111 if (NULL == handle->mq)
1112 return NULL;
1114 "Sending PUT for %s to DHT via %p\n",
1115 GNUNET_h2s (key),
1116 handle);
1117 ph = GNUNET_new (struct GNUNET_DHT_PutHandle);
1118 ph->dht_handle = handle;
1119 ph->cont = cont;
1120 ph->cont_cls = cont_cls;
1122 handle->put_tail,
1123 ph);
1124 env = GNUNET_MQ_msg_extra (put_msg,
1125 size,
1129 ph);
1130 ph->env = env;
1131 put_msg->type = htonl ((uint32_t) type);
1132 put_msg->options = htonl ((uint32_t) options);
1134 put_msg->expiration = GNUNET_TIME_absolute_hton (exp);
1135 put_msg->key = *key;
1136 GNUNET_memcpy (&put_msg[1],
1137 data,
1138 size);
1140 env);
1141 return ph;
1142}
1143
1144
1145void
1147{
1148 struct GNUNET_DHT_Handle *handle = ph->dht_handle;
1149
1150 if (NULL != ph->env)
1152 NULL,
1153 NULL);
1155 handle->put_tail,
1156 ph);
1157 GNUNET_free (ph);
1158}
1159
1160
1161struct GNUNET_DHT_GetHandle *
1164 const struct GNUNET_HashCode *key,
1167 const void *xquery,
1168 size_t xquery_size,
1170 void *iter_cls)
1171{
1172 struct GNUNET_DHT_GetHandle *gh;
1173 size_t msize;
1174
1175 msize = sizeof(struct GNUNET_DHT_ClientGetMessage) + xquery_size;
1176 if ((msize >= GNUNET_MAX_MESSAGE_SIZE) ||
1177 (xquery_size >= GNUNET_MAX_MESSAGE_SIZE))
1178 {
1179 GNUNET_break (0);
1180 return NULL;
1181 }
1183 "Sending query for %s to DHT %p\n",
1184 GNUNET_h2s (key),
1185 handle);
1186 gh = GNUNET_malloc (sizeof(struct GNUNET_DHT_GetHandle)
1187 + xquery_size);
1188 gh->iter = iter;
1189 gh->iter_cls = iter_cls;
1190 gh->dht_handle = handle;
1191 gh->key = *key;
1192 gh->unique_id = ++handle->uid_gen;
1193 gh->xquery_size = xquery_size;
1195 gh->type = type;
1196 gh->options = options;
1197 GNUNET_memcpy (&gh[1],
1198 xquery,
1199 xquery_size);
1200 GNUNET_CONTAINER_multihashmap_put (handle->active_requests,
1201 &gh->key,
1202 gh,
1204 if (NULL != handle->mq)
1205 send_get (gh);
1206 return gh;
1207}
1208
1209
1210void
1212 unsigned int num_results,
1213 const struct GNUNET_HashCode *results)
1214{
1215 unsigned int needed;
1216 unsigned int had;
1217
1219 needed = had + num_results;
1220 if (needed > get_handle->seen_results_size)
1223 needed);
1225 results,
1226 num_results * sizeof(struct GNUNET_HashCode));
1227 get_handle->seen_results_end += num_results;
1228 if (NULL != get_handle->dht_handle->mq)
1230 had);
1231}
1232
1233
1234void
1236{
1238
1240 "Sending STOP for %s to DHT via %p\n",
1242 handle);
1243 if (NULL != handle->mq)
1244 {
1245 struct GNUNET_MQ_Envelope *env;
1246 struct GNUNET_DHT_ClientGetStopMessage *stop_msg;
1247
1248 env = GNUNET_MQ_msg (stop_msg,
1250 stop_msg->reserved = htonl (0);
1251 stop_msg->unique_id = get_handle->unique_id;
1252 stop_msg->key = get_handle->key;
1254 env);
1255 }
1258 &get_handle->key,
1259 get_handle));
1262 0);
1264}
1265
1266
1270 const struct GNUNET_HashCode *key,
1274 void *cb_cls)
1275{
1277
1279 mh->get_cb = get_cb;
1280 mh->get_resp_cb = get_resp_cb;
1281 mh->put_cb = put_cb;
1282 mh->cb_cls = cb_cls;
1283 mh->type = type;
1284 mh->dht_handle = handle;
1285 if (NULL != key)
1286 {
1287 mh->key = GNUNET_new (struct GNUNET_HashCode);
1288 *mh->key = *key;
1289 }
1290 GNUNET_CONTAINER_DLL_insert (handle->monitor_head,
1291 handle->monitor_tail,
1292 mh);
1293 if (NULL != handle->mq)
1295 return mh;
1296}
1297
1298
1299void
1301{
1302 struct GNUNET_DHT_Handle *handle = mh->dht_handle;
1304 struct GNUNET_MQ_Envelope *env;
1305
1306 GNUNET_CONTAINER_DLL_remove (handle->monitor_head,
1307 handle->monitor_tail,
1308 mh);
1309 env = GNUNET_MQ_msg (m,
1311 m->type = htonl (mh->type);
1312 m->get = htons (NULL != mh->get_cb);
1313 m->get_resp = htons (NULL != mh->get_resp_cb);
1314 m->put = htons (NULL != mh->put_cb);
1315 if (NULL != mh->key)
1316 {
1317 m->filter_key = htons (1);
1318 m->key = *mh->key;
1319 }
1321 env);
1322 GNUNET_free (mh->key);
1323 GNUNET_free (mh);
1324}
1325
1326
1327char *
1329 unsigned int path_len)
1330{
1331 char *buf;
1332 size_t off;
1333 size_t plen = path_len * 5 + 1;
1334
1335 GNUNET_assert (path_len < UINT32_MAX / 5);
1336 off = 0;
1337 buf = GNUNET_malloc (plen);
1338 for (unsigned int i = 0; i < path_len; i++)
1339 {
1340 off += GNUNET_snprintf (&buf[off],
1341 plen - off,
1342 "%s%s",
1343 GNUNET_i2s (&path[i].pred),
1344 (i == path_len - 1) ? "" : "-");
1345 }
1346 return buf;
1347}
1348
1349
1350unsigned int
1352 size_t data_size,
1353 struct GNUNET_TIME_Absolute exp_time,
1354 const struct GNUNET_PeerIdentity *bpid,
1355 const struct GNUNET_DHT_PathElement *put_path,
1356 unsigned int put_path_len,
1357 const struct GNUNET_DHT_PathElement *get_path,
1358 unsigned int get_path_len,
1359 const struct GNUNET_PeerIdentity *me)
1360{
1361 static struct GNUNET_PeerIdentity zero;
1362 struct GNUNET_DHT_HopSignature hs = {
1364 .purpose.size = htonl (sizeof (hs)),
1365 .expiration_time = GNUNET_TIME_absolute_hton (exp_time)
1366 };
1367 unsigned int i;
1368
1369 if (0 == get_path_len + put_path_len)
1370 return 0;
1372 "%s is verifying signatures with GPL: %u PPL: %u!\n",
1373 GNUNET_i2s (me),
1374 get_path_len,
1375 put_path_len);
1376 for (unsigned int j = 0; j<put_path_len; j++)
1378 "PP%u=%s\n",
1379 j,
1380 GNUNET_i2s (&put_path[j].pred));
1381 for (unsigned int j = 0; j<get_path_len; j++)
1383 "GP%u=%s\n",
1384 j,
1385 GNUNET_i2s (&get_path[j].pred));
1387 data_size,
1388 &hs.h_data);
1389 i = put_path_len + get_path_len;
1390 while (i > 0)
1391 {
1392 const struct GNUNET_PeerIdentity *pred;
1393 const struct GNUNET_PeerIdentity *succ;
1394 const struct GNUNET_DHT_PathElement *pe;
1395
1396 i--;
1397 if (0 == i)
1398 {
1399 pred = (NULL == bpid) ? &zero : bpid;
1400 }
1401 else
1402 {
1403 unsigned int off = i - 1;
1404
1405 pred = (off >= put_path_len)
1406 ? &get_path[off - put_path_len].pred
1407 : &put_path[off].pred;
1408 }
1409 if (i == get_path_len + put_path_len - 1)
1410 {
1411 succ = me;
1412 }
1413 else
1414 {
1415 unsigned int off = i + 1;
1416
1417 succ = (off >= put_path_len)
1418 ? &get_path[off - put_path_len].pred
1419 : &put_path[off].pred;
1420 }
1421 hs.pred = *pred;
1422 hs.succ = *succ;
1423 pe = (i >= put_path_len)
1424 ? &get_path[i - put_path_len]
1425 : &put_path[i];
1426 if (GNUNET_OK !=
1429 &hs,
1430 &pe->sig,
1431 &pe->pred.public_key))
1432 {
1433 GNUNET_break_op (0);
1434 return i + 1;
1435 }
1436 }
1437 return i;
1438}
1439
1440
1444 void *cb_cls)
1445{
1446 struct GNUNET_DHT_HelloGetHandle *hgh;
1447 struct GNUNET_MessageHeader *hdr;
1448 struct GNUNET_MQ_Envelope *env;
1449
1451 hgh->cb = cb;
1452 hgh->cb_cls = cb_cls;
1453 hgh->dht_handle = dht_handle;
1455 dht_handle->hgh_tail,
1456 hgh);
1457 env = GNUNET_MQ_msg (hdr,
1460 env);
1461 return hgh;
1462}
1463
1464
1465void
1467{
1469
1471 dht_handle->hgh_tail,
1472 hgh);
1473 GNUNET_free (hgh);
1474}
1475
1476
1477void
1479 const char *url,
1481 void *cb_cls)
1482{
1483 struct GNUNET_MessageHeader *hdr;
1484 size_t slen = strlen (url) + 1;
1485 struct GNUNET_MQ_Envelope *env;
1486
1487 env = GNUNET_MQ_msg_extra (hdr,
1488 slen,
1490 memcpy (&hdr[1],
1491 url,
1492 slen);
1494 cb,
1495 cb_cls);
1497 env);
1498}
1499
1500
1501/* end of dht_api.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
dht_handle
Definition: 018.c:1
static void send_get(struct GNUNET_DHT_GetHandle *gh)
Send GET message for a get_handle to DHT.
Definition: dht_api.c:316
static void handle_monitor_get_resp(void *cls, const struct GNUNET_DHT_MonitorGetRespMessage *msg)
Process a get response monitor message from the service.
Definition: dht_api.c:608
static enum GNUNET_GenericReturnValue try_connect(struct GNUNET_DHT_Handle *h)
Try to (re)connect to the DHT service.
Definition: dht_api.c:993
static void handle_client_result(void *cls, const struct GNUNET_DHT_ClientResultMessage *msg)
Process a client result message received from the service.
Definition: dht_api.c:906
static void handle_client_hello(void *cls, const struct GNUNET_MessageHeader *hdr)
Process a client HELLO message received from the service.
Definition: dht_api.c:949
static void try_reconnect(void *cls)
Try reconnecting to the dht service.
Definition: dht_api.c:442
static enum GNUNET_GenericReturnValue process_client_result(void *cls, const struct GNUNET_HashCode *key, void *value)
Process a given reply that might match the given request.
Definition: dht_api.c:802
static enum GNUNET_GenericReturnValue check_monitor_get_resp(void *cls, const struct GNUNET_DHT_MonitorGetRespMessage *msg)
Validate a get response monitor message from the service.
Definition: dht_api.c:572
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: dht_api.c:517
static void handle_monitor_get(void *cls, const struct GNUNET_DHT_MonitorGetMessage *msg)
Process a get monitor message from the service.
Definition: dht_api.c:533
static enum GNUNET_GenericReturnValue check_client_result(void *cls, const struct GNUNET_DHT_ClientResultMessage *msg)
Verify that client result message received from the service is well-formed.
Definition: dht_api.c:760
static enum GNUNET_GenericReturnValue check_client_hello(void *cls, const struct GNUNET_MessageHeader *hdr)
Process a client HELLO message received from the service.
Definition: dht_api.c:926
static void do_disconnect(struct GNUNET_DHT_Handle *h)
Try reconnecting to the DHT service.
Definition: dht_api.c:476
static void handle_put_cont(void *cls)
Process a MQ PUT transmission notification.
Definition: dht_api.c:971
static enum GNUNET_GenericReturnValue add_get_request_to_pending(void *cls, const struct GNUNET_HashCode *key, void *value)
Add the GET request corresponding to the given route handle to the pending queue (if it is not alread...
Definition: dht_api.c:391
static void send_get_known_results(struct GNUNET_DHT_GetHandle *gh, unsigned int transmission_offset_start)
Send GET message(s) for indicating which results are already known for a get_handle to DHT.
Definition: dht_api.c:348
static void handle_monitor_put(void *cls, const struct GNUNET_DHT_MonitorPutMessage *msg)
Process a put monitor message from the service.
Definition: dht_api.c:701
#define LOG(kind,...)
Definition: dht_api.c:36
static enum GNUNET_GenericReturnValue check_monitor_put(void *cls, const struct GNUNET_DHT_MonitorPutMessage *msg)
Check validity of a put monitor message from the service.
Definition: dht_api.c:667
static void send_monitor_start(struct GNUNET_DHT_MonitorHandle *mh)
Send GNUNET_MESSAGE_TYPE_DHT_MONITOR_START message.
Definition: dht_api.c:414
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
static void get_cb(void *cls, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
Process a datum that was stored in the datastore.
static void put_cb(void *cls, int32_t success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
Continuation called to notify client about result of the operation.
static struct GNUNET_DHT_GetHandle * get_handle
Handle for the get request.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static unsigned int results
static const struct GNUNET_CRYPTO_PrivateKey zero
Public key of all zeros.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
API to the DHT service.
Constants for network protocols.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
void GNUNET_DHT_put_cancel(struct GNUNET_DHT_PutHandle *ph)
Cancels a DHT PUT operation.
Definition: dht_api.c:1146
GNUNET_DHT_RouteOption
Options for routing.
struct GNUNET_DHT_PutHandle * GNUNET_DHT_put(struct GNUNET_DHT_Handle *handle, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, size_t size, const void *data, struct GNUNET_TIME_Absolute exp, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Perform a PUT operation storing data in the DHT.
Definition: dht_api.c:1088
char * GNUNET_DHT_pp2s(const struct GNUNET_DHT_PathElement *path, unsigned int path_len)
Convert a peer path to a human-readable string.
Definition: dht_api.c:1328
struct GNUNET_DHT_Handle * GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
Initialize the connection with the DHT service.
Definition: dht_api.c:1037
void GNUNET_DHT_hello_get_cancel(struct GNUNET_DHT_HelloGetHandle *hgh)
Cancel hello get operation.
Definition: dht_api.c:1466
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition: dht_api.c:1235
void GNUNET_DHT_get_filter_known_results(struct GNUNET_DHT_GetHandle *get_handle, unsigned int num_results, const struct GNUNET_HashCode *results)
Tell the DHT not to return any of the following known results to this client.
Definition: dht_api.c:1211
void(* GNUNET_DHT_GetIterator)(void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *query_hash, const struct GNUNET_PeerIdentity *trunc_peer, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data)
Iterator called on each result obtained for a DHT operation that expects a reply.
void(* GNUNET_DHT_MonitorGetRespCB)(void *cls, enum GNUNET_BLOCK_Type type, const struct GNUNET_PeerIdentity *trunc_peer, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const void *data, size_t size)
Callback called on each GET reply going through the DHT.
void(* GNUNET_DHT_MonitorGetCB)(void *cls, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, uint32_t hop_count, uint32_t desired_replication_level, const struct GNUNET_HashCode *key)
Callback called on each GET request going through the DHT.
void(* GNUNET_DHT_HelloGetCallback)(void *cls, const char *hello_url)
Signature called with the result of a HELLO GET operation.
struct GNUNET_DHT_MonitorHandle * GNUNET_DHT_monitor_start(struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, GNUNET_DHT_MonitorGetCB get_cb, GNUNET_DHT_MonitorGetRespCB get_resp_cb, GNUNET_DHT_MonitorPutCB put_cb, void *cb_cls)
Start monitoring the local DHT service.
Definition: dht_api.c:1268
struct GNUNET_DHT_GetHandle * GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, const void *xquery, size_t xquery_size, GNUNET_DHT_GetIterator iter, void *iter_cls)
Perform an asynchronous GET operation on the DHT identified.
Definition: dht_api.c:1162
struct GNUNET_DHT_HelloGetHandle * GNUNET_DHT_hello_get(struct GNUNET_DHT_Handle *dht_handle, GNUNET_DHT_HelloGetCallback cb, void *cb_cls)
Obtain HELLO URL of the DHT identified by dht_handle.
Definition: dht_api.c:1442
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:1060
void GNUNET_DHT_hello_offer(struct GNUNET_DHT_Handle *dht_handle, const char *url, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Offer HELLO URL of the DHT identified by dht_handle.
Definition: dht_api.c:1478
void(* GNUNET_DHT_MonitorPutCB)(void *cls, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, uint32_t hop_count, uint32_t desired_replication_level, const struct GNUNET_PeerIdentity *trunc_peer, unsigned int path_length, const struct GNUNET_DHT_PathElement *path, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const void *data, size_t size)
Callback called on each PUT request going through the DHT.
unsigned int GNUNET_DHT_verify_path(const void *data, size_t data_size, struct GNUNET_TIME_Absolute exp_time, const struct GNUNET_PeerIdentity *bpid, 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
void GNUNET_DHT_monitor_stop(struct GNUNET_DHT_MonitorHandle *mh)
Stop monitoring.
Definition: dht_api.c:1300
@ GNUNET_DHT_RO_TRUNCATED
Flag set if the path was truncated.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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.
#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_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
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_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:638
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
#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_CLIENT_PUT
Client wants to store item in DHT.
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_START
Request information about transiting messages.
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN
Certain results are already known to the client, filter those.
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT
Receive information about transiting PUTs.
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP
Client wants to stop search in DHT.
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT
Service returns result to client.
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP
Stop information about transiting messages.
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_GET
Client requests DHT service's HELLO URL.
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_URL
HELLO URL send between client and service (in either direction).
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET
Client wants to lookup item in DHT.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1272
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
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_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
#define max(x, y)
static unsigned int size
Size of the "table".
Definition: peer.c:68
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:36
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.
#define GNUNET_SIGNATURE_PURPOSE_DHT_HOP
Signature by which a peer affirms that it forwarded a message in the DHT.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
Internal representation of the hash map.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
DHT GET message sent from clients to service.
Definition: dht.h:72
uint64_t unique_id
Unique ID identifying this request, if 0 then the client will not expect a response.
Definition: dht.h:103
uint32_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
Definition: dht.h:81
struct GNUNET_HashCode key
The key to search for.
Definition: dht.h:97
uint32_t type
The type for the data for the GET request; actually an 'enum GNUNET_BLOCK_Type'.
Definition: dht.h:92
uint32_t desired_replication_level
Replication level for this message.
Definition: dht.h:86
DHT GET RESULTS KNOWN message sent from clients to service.
Definition: dht.h:114
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
uint32_t reserved
Always zero.
Definition: dht.h:53
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
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_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT.
Definition: dht.h:148
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
Handle to a GET request.
Definition: dht_api.c:79
GNUNET_DHT_GetIterator iter
Iterator to call on data receipt.
Definition: dht_api.c:83
enum GNUNET_BLOCK_Type type
Type of the block we are looking for.
Definition: dht_api.c:124
void * iter_cls
Closure for iter.
Definition: dht_api.c:88
unsigned int seen_results_end
Offset into the seen_results array marking the end of the positions that are actually used.
Definition: dht_api.c:141
struct GNUNET_HashCode * seen_results
Array of hash codes over the results that we have already seen.
Definition: dht_api.c:99
size_t xquery_size
Size of the extended query, allocated at the end of this struct.
Definition: dht_api.c:114
uint32_t desired_replication_level
Desired replication level.
Definition: dht_api.c:119
struct GNUNET_HashCode key
Key that this get request is for.
Definition: dht_api.c:104
uint64_t unique_id
Unique identifier for this request (for key collisions).
Definition: dht_api.c:109
struct GNUNET_DHT_Handle * dht_handle
Main handle to this DHT api.
Definition: dht_api.c:93
enum GNUNET_DHT_RouteOption options
Routing options.
Definition: dht_api.c:129
unsigned int seen_results_size
Size of the seen_results array.
Definition: dht_api.c:135
Connection to the DHT service.
Definition: dht_api.c:235
struct GNUNET_CONTAINER_MultiHashMap * active_requests
Hash map containing the current outstanding unique GET requests (values are of type struct GNUNET_DHT...
Definition: dht_api.c:280
struct GNUNET_TIME_Relative retry_time
How quickly should we retry? Used for exponential back-off on connect-errors.
Definition: dht_api.c:291
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for trying to reconnect.
Definition: dht_api.c:285
struct GNUNET_DHT_PutHandle * put_tail
Tail of active PUT requests.
Definition: dht_api.c:264
struct GNUNET_DHT_MonitorHandle * monitor_tail
Tail of linked list of messages we would like to monitor.
Definition: dht_api.c:254
struct GNUNET_MQ_Handle * mq
Connection to DHT service.
Definition: dht_api.c:244
struct GNUNET_DHT_PutHandle * put_head
Head of active PUT requests.
Definition: dht_api.c:259
struct GNUNET_DHT_MonitorHandle * monitor_head
Head of linked list of messages we would like to monitor.
Definition: dht_api.c:249
struct GNUNET_DHT_HelloGetHandle * hgh_tail
DLL.
Definition: dht_api.c:274
uint64_t uid_gen
Generator for unique ids.
Definition: dht_api.c:296
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: dht_api.c:239
struct GNUNET_DHT_HelloGetHandle * hgh_head
DLL.
Definition: dht_api.c:269
Handle to get a HELLO URL from the DHT for manual bootstrapping.
Definition: dht_api.c:201
struct GNUNET_DHT_Handle * dht_handle
Connection to the DHT service.
Definition: dht_api.c:226
GNUNET_DHT_HelloGetCallback cb
Function to call with the result.
Definition: dht_api.c:216
void * cb_cls
Closure for cb.
Definition: dht_api.c:221
struct GNUNET_DHT_HelloGetHandle * prev
DLL.
Definition: dht_api.c:211
struct GNUNET_DHT_HelloGetHandle * next
DLL.
Definition: dht_api.c:206
Message signed by a peer when doing path tracking.
struct GNUNET_HashCode h_data
Hash over the payload of the block.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Must be GNUNET_SIGNATURE_PURPOSE_DHT_HOP.
struct GNUNET_PeerIdentity pred
Previous hop the message was received from.
struct GNUNET_PeerIdentity succ
Next hop the message was forwarded to.
Message to monitor get requests going through peer, DHT service -> clients.
Definition: dht.h:334
Message to monitor get results going through peer, DHT service -> clients.
Definition: dht.h:377
Handle to a monitoring request.
Definition: dht_api.c:149
GNUNET_DHT_MonitorGetRespCB get_resp_cb
Callback for each received message of type get response.
Definition: dht_api.c:183
struct GNUNET_HashCode * key
Key being looked for, NULL == all.
Definition: dht_api.c:173
struct GNUNET_DHT_MonitorHandle * prev
DLL.
Definition: dht_api.c:158
struct GNUNET_DHT_MonitorHandle * next
DLL.
Definition: dht_api.c:153
GNUNET_DHT_MonitorPutCB put_cb
Callback for each received message of type put.
Definition: dht_api.c:188
struct GNUNET_DHT_Handle * dht_handle
Main handle to this DHT api.
Definition: dht_api.c:163
GNUNET_DHT_MonitorGetCB get_cb
Callback for each received message of type get.
Definition: dht_api.c:178
void * cb_cls
Closure for get_cb, put_cb and get_resp_cb.
Definition: dht_api.c:193
enum GNUNET_BLOCK_Type type
Type of block looked for.
Definition: dht_api.c:168
Message to monitor put requests going through peer, DHT service -> clients.
Definition: dht.h:239
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,...
struct GNUNET_PeerIdentity pred
Previous peer on the path (matches "pred" in the signed field).
struct GNUNET_CRYPTO_EddsaSignature sig
Signature affirming the hop of type GNUNET_SIGNATURE_PURPOSE_DHT_HOP.
Handle to a PUT request.
Definition: dht_api.c:43
struct GNUNET_DHT_Handle * dht_handle
Main handle to this DHT api.
Definition: dht_api.c:62
struct GNUNET_DHT_PutHandle * prev
Kept in a DLL.
Definition: dht_api.c:52
void * cont_cls
Closure for cont.
Definition: dht_api.c:67
struct GNUNET_MQ_Envelope * env
Envelope from the PUT operation.
Definition: dht_api.c:72
struct GNUNET_DHT_PutHandle * next
Kept in a DLL.
Definition: dht_api.c:47
GNUNET_SCHEDULER_TaskCallback cont
Continuation to call when done.
Definition: dht_api.c:57
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
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).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition: vpn_api.c:39
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition: vpn_api.c:44