GNUnet 0.27.0
 
Loading...
Searching...
No Matches
hello-uri.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022, 2026 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
37#include "gnunet_time_lib.h"
38#include "platform.h"
39#include "gnunet_util_lib.h"
40#include "gnunet_signatures.h"
42#include "gnunet_protocols.h"
43
44
46
68
73{
78
83
88
89 /* followed by a 'block' */
90};
91
92
114
115
121{
126
131
136
141
146
147 /* followed by the serialized addresses of the 'block' */
148};
149
150
152
153
158{
162 struct Address *next;
163
167 struct Address *prev;
168
172 const char *uri;
173
177 size_t uri_len;
178};
179
180
185{
190
195
199 unsigned int a_length;
200
201};
202
207{
212
216 const char *address_uri;
217
221 unsigned int found;
222
226 unsigned int merged;
227};
228
233{
238
243
248
252 unsigned int a_length;
253
258
263};
264
265
266static void
267hash_addresses (const struct Address *addr_start,
268 struct GNUNET_HashCode *hash)
269{
270 struct GNUNET_HashContext *hc;
271
273
274#if HELLO_DETERMINISTIC_PID_DERIVATION
275 for (const struct Address *a = addr_start;
276 NULL != a;
277 a = a->next)
278 {
280 "Hashing over %.*s\n",
281 (int) a->uri_len,
282 a->uri);
284 a->uri,
285 a->uri_len);
286 }
287#endif
289 hash);
290
291}
292
293
304verify_hello (const struct GNUNET_HELLO_Parser *parser,
305 struct GNUNET_TIME_Absolute et,
306 const struct GNUNET_CRYPTO_EddsaSignature *sig)
307{
308 struct PilsHelloSignaturePurpose hsp = {
309 .purpose.size = htonl (sizeof (hsp)),
310 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
311 .expiration_time = GNUNET_TIME_absolute_hton (et)
312 };
313
314 hash_addresses (parser->a_head,
315 &hsp.h_addrs);
316 if (GNUNET_OK !=
318 &hsp,
319 sig,
320 &parser->pid.public_key))
321 {
323 "HELLO signature invalid, rejecting.\n");
324 return GNUNET_SYSERR;
325 }
327 return GNUNET_NO;
328 return GNUNET_OK;
329}
330
331
332static struct GNUNET_HELLO_Parser *
334{
335 struct GNUNET_HELLO_Parser *p;
336
338 p->pid = *pid;
339 return p;
340}
341
342
351
352
353const struct GNUNET_PeerIdentity *
355{
356 return &parser->pid;
357}
358
359
362 struct GNUNET_PeerIdentity *pid)
363{
365 struct Address *a;
366
368 if (NULL != pid)
369 *pid = p->pid;
370 /* check for duplicates */
371 for (a = p->a_head;
372 NULL != a;
373 a = a->next)
375 return builder;
376}
377
378
379void
381{
382 struct Address *a;
383
384 while (NULL != (a = parser->a_head))
385 {
386 GNUNET_CONTAINER_DLL_remove (parser->a_head,
387 parser->a_tail,
388 a);
389 parser->a_length--;
390 GNUNET_free (a);
391 }
392 GNUNET_assert (0 == parser->a_length);
393 GNUNET_free (parser);
394}
395
396
397void
399{
400 struct Address *a;
401
402 while (NULL != (a = builder->a_head))
403 {
405 builder->a_tail,
406 a);
407 builder->a_length--;
408 GNUNET_free (a);
409 }
410 GNUNET_assert (0 == builder->a_length);
412}
413
414
415struct GNUNET_HELLO_Parser *
417 const struct GNUNET_PeerIdentity *pid)
418{
419 uint16_t size = ntohs (msg->size);
420
421 switch (ntohs (msg->type))
422 {
424 {
425 const struct HelloUriMessage *h;
426
427 if (sizeof (struct HelloUriMessage) > size)
428 {
429 GNUNET_break_op (0);
430 return NULL;
431 }
432
433 h = (const struct HelloUriMessage *) msg;
434 size -= sizeof (*h);
436 size);
437 }
439 {
440 struct GNUNET_TIME_Absolute block_expiration;
441 struct GNUNET_HELLO_Parser *p;
442 size_t block_size;
443 void *block;
444
445 if (sizeof (struct DhtHelloMessage) > size)
446 {
447 GNUNET_break_op (0);
448 return NULL;
449 }
450
452 msg,
453 pid,
454 &block,
455 &block_size,
456 &block_expiration))
457 {
458 GNUNET_break_op (0);
459 return NULL;
460 }
461
463 block_size);
464 GNUNET_free (block);
465 return p;
466 }
467 default:
468 GNUNET_break (0);
469 return NULL;
470 }
471}
472
473
476{
477 const char *e;
478
479 if (NULL == (e = strstr (address,
480 "://")))
481 {
482 GNUNET_break_op (0);
484 "Invalid address `%s'\n",
485 address);
486 return GNUNET_SYSERR;
487 }
488 if (e == address)
489 {
490 GNUNET_break_op (0);
491 return GNUNET_SYSERR;
492 }
493 for (const char *p = address; p != e; p++)
494 if ( (! isalpha ((unsigned char) *p)) &&
495 ('+' != *p) )
496 {
497 GNUNET_break_op (0);
498 return GNUNET_SYSERR;
499 }
500 return GNUNET_OK;
501}
502
503
512int
513static
514cmp_address (void*cls, struct Address *a, struct Address *b)
515{
516 return strcmp (a->uri, b->uri);
517}
518
519
522 const char *address)
523{
524 struct Address *a;
526 size_t alen = strlen (address) + 1;
527
529 if (GNUNET_OK != ret)
530 {
532 "Failed to add address to builder\n");
533 return ret;
534 }
535 /* check for duplicates */
536 for (a = parser->a_head;
537 NULL != a;
538 a = a->next)
539 if (0 == strcmp (address,
540 a->uri))
541 return GNUNET_NO;
542 a = GNUNET_malloc (sizeof (struct Address) + alen);
543 a->uri_len = alen;
544 memcpy (&a[1],
545 address,
546 alen);
547 a->uri = (const char *) &a[1];
550 NULL,
551 parser->a_head,
552 parser->a_tail,
553 a);
554 parser->a_length++;
555 return GNUNET_OK;
556}
557
558
559struct GNUNET_HELLO_Parser *
561 size_t block_size)
562{
564 block_size,
565 GNUNET_NO);
566}
567
568
569struct GNUNET_HELLO_Parser *
571 size_t block_size,
572 int noverify)
573{
574 const struct BlockHeader *bh = block;
575 struct GNUNET_HELLO_Parser *p;
576
577 if (block_size < sizeof (*bh))
578 {
579 GNUNET_break_op (0);
580 return NULL;
581 }
582 p = parser_new (&bh->pid);
583 block += sizeof (*bh);
584 block_size -= sizeof (*bh);
585 while (block_size > 0)
586 {
587 const void *end = memchr (block,
588 '\0',
589 block_size);
590
591 if (NULL == end)
592 {
593 GNUNET_break_op (0);
595 return NULL;
596 }
597 if (GNUNET_OK !=
599 block))
600 {
601 GNUNET_break_op (0);
603 return NULL;
604 }
605 end++;
606 block_size -= (end - block);
607 block = end;
608 }
609 {
610 struct GNUNET_TIME_Absolute et;
612 if (GNUNET_YES != noverify)
613 {
615 ret = verify_hello (p,
616 et,
617 &bh->sig);
619 if (GNUNET_OK != ret)
620 {
622 return NULL;
623 }
624 }
625 p->et = et;
626 p->sig = bh->sig;
627 }
628 return p;
629}
630
631
635{
636 struct GNUNET_TIME_Absolute et;
637 if (GNUNET_MESSAGE_TYPE_HELLO_URI == ntohs (msg->type))
638 {
639 const struct HelloUriMessage *h = (const struct HelloUriMessage *) msg;
640 const struct BlockHeader *bh = (const struct BlockHeader *) &h[1];
641
643 return et;
644 }
645 else if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO == ntohs (msg->type))
646 {
647 const struct DhtHelloMessage *dht_hello
648 = (const struct DhtHelloMessage *) msg;
649
651 return et;
652 }
653 else
654 GNUNET_break (0);
656}
657
658
661 const char *address)
662{
663 struct Address *a;
665 size_t alen = strlen (address) + 1;
666
668 if (GNUNET_OK != ret)
669 {
671 "Failed to add address to builder\n");
672 return ret;
673 }
674 /* check for duplicates */
675 for (a = builder->a_head;
676 NULL != a;
677 a = a->next)
678 if (0 == strcmp (address,
679 a->uri))
680 return GNUNET_NO;
681 a = GNUNET_malloc (sizeof (struct Address) + alen);
682 a->uri_len = alen;
683 memcpy (&a[1],
684 address,
685 alen);
686 a->uri = (const char *) &a[1];
689 NULL,
690 builder->a_head,
691 builder->a_tail,
692 a);
693 builder->a_length++;
694 return GNUNET_OK;
695}
696
697
698struct GNUNET_HELLO_Parser *
700{
701 const char *q;
702 const char *s1;
703 const char *s2;
705 struct GNUNET_TIME_Absolute et;
706 size_t len;
707 struct GNUNET_HELLO_Parser *p;
709
710 if (0 != strncasecmp (url,
711 "gnunet://hello/",
712 strlen ("gnunet://hello/")))
713 return NULL;
714 url += strlen ("gnunet://hello/");
715 s1 = strchr (url, '/');
716 if (NULL == s1)
717 {
718 GNUNET_break_op (0);
719 return NULL;
720 }
721 s2 = strchr (s1 + 1, '/');
722 if (NULL == s1)
723 {
724 GNUNET_break_op (0);
725 return NULL;
726 }
727 q = strchr (url, '?');
728 if (NULL == q)
729 q = url + strlen (url);
730 if (GNUNET_OK !=
732 s1 - url,
733 &pid,
734 sizeof(pid)))
735 {
736 GNUNET_break_op (0);
737 return NULL;
738 }
739 if (GNUNET_OK !=
741 s2 - (s1 + 1),
742 &sig,
743 sizeof(sig)))
744 {
745 GNUNET_break_op (0);
746 return NULL;
747 }
748 {
749 uint64_t sec;
750 char dummy = '?';
751
752 if ( (0 == sscanf (s2 + 1,
753 "%" PRIu64 "%c",
754 &sec,
755 &dummy)) ||
756 ('?' != dummy) )
757 {
758 GNUNET_break_op (0);
759 return NULL;
760 }
761 et.abs_value_us = sec;
762 }
763
764 p = parser_new (&pid);
765 p->et = et;
766 p->sig = sig;
767 len = strlen (q);
768 while (len > 0)
769 {
770 const char *eq;
771 const char *amp;
772 char *addr = NULL;
773 char *uri;
774
775 /* skip ?/& separator */
776 len--;
777 q++;
778 eq = strchr (q, '=');
779 if ( (eq == q) ||
780 (NULL == eq) )
781 {
782 GNUNET_break_op (0);
784 return NULL;
785 }
786 amp = strchr (eq, '&');
787 if (NULL == amp)
788 amp = &q[len];
790 amp - (eq + 1),
791 &addr);
792 if ( (NULL == addr) ||
793 (0 == strlen (addr)) )
794 {
795 GNUNET_free (addr);
796 GNUNET_break_op (0);
798 return NULL;
799 }
801 "%.*s://%s",
802 (int) (eq - q),
803 q,
804 addr);
805 GNUNET_free (addr);
806 if (GNUNET_OK !=
808 uri))
809 {
810 GNUNET_break_op (0);
813 return NULL;
814 }
816 /* move to next URL */
817 len -= (amp - q);
818 q = amp;
819 }
820
821 {
823
824 ret = verify_hello (p,
825 et,
826 &p->sig);
828 if (GNUNET_OK != ret)
829 {
831 return NULL;
832 }
833 }
834 return p;
835}
836
837
838char *
840{
841 char *result;
842 char *pids;
843 char *sigs;
844 const char *sep = "?";
845
846 pids = GNUNET_STRINGS_data_to_string_alloc (&parser->pid,
847 sizeof (parser->pid));
848 sigs = GNUNET_STRINGS_data_to_string_alloc (&parser->sig,
849 sizeof (parser->sig));
851 "gnunet://hello/%s/%s/%" PRIu64,
852 pids,
853 sigs,
854 parser->et.abs_value_us);
855 GNUNET_free (sigs);
856 GNUNET_free (pids);
857 for (struct Address *a = parser->a_head;
858 NULL != a;
859 a = a->next)
860 {
861 char *eou_url_encoded;
862 char *tmp;
863 int pfx_len;
864 const char *eou;
865
866 eou = strstr (a->uri,
867 "://");
868 if (NULL == eou)
869 {
870 GNUNET_break (0);
872 return NULL;
873 }
874 pfx_len = eou - a->uri;
875 eou += 3;
876 GNUNET_STRINGS_urlencode (a->uri_len - 4 - pfx_len,
877 eou,
878 &eou_url_encoded);
879 GNUNET_asprintf (&tmp,
880 "%s%s%.*s=%s",
881 result,
882 sep,
883 pfx_len,
884 a->uri,
885 eou_url_encoded);
886 GNUNET_free (eou_url_encoded);
888 result = tmp;
889 sep = "&";
890 }
891 return result;
892}
893
894
897 void *block,
898 size_t *block_size)
899{
900 struct BlockHeader bh;
901 size_t needed = sizeof (bh);
902 char *pos;
903
904 for (struct Address *a = parser->a_head;
905 NULL != a;
906 a = a->next)
907 {
908 GNUNET_assert (needed + a->uri_len > needed);
909 needed += a->uri_len;
910 }
911 if ( (NULL == block) ||
912 (needed < *block_size) )
913 {
914 *block_size = needed;
915 return GNUNET_NO;
916 }
917 bh.pid = parser->pid;
918 bh.sig = parser->sig;
920 memcpy (block,
921 &bh,
922 sizeof (bh));
923 pos = block + sizeof (bh);
924 for (struct Address *a = parser->a_head;
925 NULL != a;
926 a = a->next)
927 {
928 memcpy (pos,
929 a->uri,
930 a->uri_len);
931 pos += a->uri_len;
932 }
933 *block_size = needed;
934 return GNUNET_OK;
935}
936
937
938struct GNUNET_MQ_Envelope *
940{
941 struct GNUNET_MQ_Envelope *env;
942 struct HelloUriMessage *msg;
943 size_t blen;
944
945 if (parser->a_length > UINT16_MAX)
946 {
947 GNUNET_break (0);
948 return NULL;
949 }
950 blen = 0;
953 NULL,
954 &blen));
956 blen,
958 msg->url_counter = htons ((uint16_t) parser->a_length);
961 &msg[1],
962 &blen));
963 return env;
964}
965
966
969 const char *address)
970{
971 struct Address *a;
972
973 /* check for duplicates */
974 for (a = builder->a_head;
975 NULL != a;
976 a = a->next)
977 if (0 == strcmp (address,
978 a->uri))
979 break;
980 if (NULL == a)
981 return GNUNET_NO;
983 builder->a_tail,
984 a);
985 builder->a_length--;
986 GNUNET_free (a);
987 return GNUNET_OK;
988}
989
990
991void
994 void *uc_cls)
995{
996 struct Address *nxt;
997
998 for (struct Address *a = builder->a_head;
999 NULL != a;
1000 a = nxt)
1001 {
1002 nxt = a->next;
1003 uc (uc_cls,
1004 NULL,
1005 a->uri);
1006 }
1007}
1008
1009
1010const struct GNUNET_PeerIdentity*
1013 void *uc_cls)
1014{
1015 struct Address *nxt;
1016
1017 if (NULL == uc)
1018 return &parser->pid;
1019 for (struct Address *a = parser->a_head;
1020 NULL != a;
1021 a = nxt)
1022 {
1023 nxt = a->next;
1024 uc (uc_cls,
1025 &parser->pid,
1026 a->uri);
1027 }
1028 return &parser->pid;
1029}
1030
1031
1034 const struct GNUNET_PeerIdentity *pid,
1035 void **block,
1036 size_t *block_size,
1037 struct GNUNET_TIME_Absolute *block_expiration)
1038{
1039 const struct DhtHelloMessage *msg
1040 = (const struct DhtHelloMessage *) hello;
1041 uint16_t len = ntohs (hello->size);
1042 struct BlockHeader *bh;
1043 struct GNUNET_HELLO_Parser *b;
1045
1046 if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO != ntohs (hello->type))
1047 {
1048 GNUNET_break (0);
1049 return GNUNET_SYSERR;
1050 }
1051 if (len < sizeof (*msg))
1052 {
1053 GNUNET_break_op (0);
1054 return GNUNET_SYSERR;
1055 }
1056 len -= sizeof (*msg);
1057 *block_size = len + sizeof (*bh);
1058 *block = GNUNET_malloc (*block_size);
1059 bh = *block;
1060 bh->pid = *pid;
1061 bh->sig = msg->sig;
1062 bh->expiration_time = msg->expiration_time;
1063 *block_expiration = GNUNET_TIME_absolute_ntoh (msg->expiration_time);
1064 memcpy (&bh[1],
1065 &msg[1],
1066 len);
1068 *block_size);
1069 if (NULL == b)
1070 {
1071 GNUNET_break_op (0);
1072 GNUNET_free (*block);
1073 *block_size = 0;
1074 return GNUNET_SYSERR;
1075 }
1076 ret = verify_hello (b,
1077 *block_expiration,
1078 &msg->sig);
1080 if (GNUNET_SYSERR == ret)
1081 {
1082 GNUNET_free (*block);
1083 *block_size = 0;
1084 return GNUNET_SYSERR;
1085 }
1086 return ret;
1087}
1088
1089
1097char *
1099{
1100 const char *dash;
1101
1102 dash = strchr (address, '-');
1103 if (NULL == dash)
1104 return NULL;
1105 return GNUNET_strndup (address, dash - address);
1106}
1107
1108
1111 const struct GNUNET_PeerIdentity *pid,
1112 const struct GNUNET_CRYPTO_EddsaSignature *sig,
1114 char **result)
1115{
1116 char *pids;
1117 char *sigs;
1118 const char *sep = "?";
1119
1121 sizeof (*pid));
1123 sizeof (*sig));
1125 "gnunet://hello/%s/%s/%" PRIu64,
1126 pids,
1127 sigs,
1128 expiration.abs_value_us);
1129 GNUNET_free (sigs);
1130 GNUNET_free (pids);
1131 for (struct Address *a = builder->a_head;
1132 NULL != a;
1133 a = a->next)
1134 {
1135 char *eou_url_encoded;
1136 char *tmp;
1137 int pfx_len;
1138 const char *eou;
1139
1140 eou = strstr (a->uri,
1141 "://");
1142 if (NULL == eou)
1143 {
1144 GNUNET_break (0);
1146 return GNUNET_SYSERR;
1147 }
1148 pfx_len = eou - a->uri;
1149 eou += 3;
1150 GNUNET_STRINGS_urlencode (a->uri_len - 4 - pfx_len,
1151 eou,
1152 &eou_url_encoded);
1153 GNUNET_asprintf (&tmp,
1154 "%s%s%.*s=%s",
1155 *result,
1156 sep,
1157 pfx_len,
1158 a->uri,
1159 eou_url_encoded);
1160 GNUNET_free (eou_url_encoded);
1162 *result = tmp;
1163 sep = "&";
1164 }
1165 return GNUNET_OK;
1166}
1167
1168
1169void
1171 struct GNUNET_HashCode *hash)
1172{
1173 hash_addresses (builder->a_head, hash);
1174}
1175
1176
1177struct GNUNET_MQ_Envelope*
1179 const struct GNUNET_HELLO_Builder *builder,
1180 const struct GNUNET_PeerIdentity *pid,
1181 const struct GNUNET_CRYPTO_EddsaSignature *hello_sig,
1182 struct GNUNET_TIME_Absolute expiration_time)
1183{
1184 struct GNUNET_MQ_Envelope *env;
1185 struct HelloUriMessage *msg;
1186 size_t blen;
1187
1188 if (builder->a_length > UINT16_MAX)
1189 {
1190 GNUNET_break (0);
1191 return NULL;
1192 }
1195 blen,
1197 msg->url_counter = htons ((uint16_t) builder->a_length);
1199 pid,
1200 hello_sig,
1201 expiration_time,
1202 (char*) &msg[1]);
1203 return env;
1204}
1205
1206
1207struct GNUNET_MessageHeader *
1209{
1210 struct BlockHeader *block;
1211 struct DhtHelloMessage *msg;
1212 size_t block_size;
1213
1214
1215 block_size = 0;
1218 NULL,
1219 &block_size));
1220 msg = GNUNET_malloc (sizeof (*msg)
1221 + block_size);
1222 if (GNUNET_OK !=
1224 &msg[1],
1225 &block_size))
1226 {
1227 return NULL;
1228 }
1229 block = (struct BlockHeader*) &msg[1];
1230 msg->sig = block->sig;
1231 msg->expiration_time = block->expiration_time;
1232 memmove (&msg[1],
1233 (char*) block + sizeof (*block),
1234 block_size - sizeof (*block));
1235 msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO);
1236 msg->header.size = htons (sizeof (*msg)
1237 + block_size
1238 - sizeof (*block));
1239 msg->url_counter = htons ((uint16_t) parser->a_length);
1240 return &msg->header;
1241}
1242
1243
1244struct GNUNET_MessageHeader *
1246 const struct GNUNET_HELLO_Builder *builder,
1247 const struct GNUNET_PeerIdentity *pid,
1248 const struct GNUNET_CRYPTO_EddsaSignature *hello_sig,
1249 struct GNUNET_TIME_Absolute expiration_time)
1250{
1251 struct BlockHeader *block;
1252 struct DhtHelloMessage *msg;
1253 size_t block_size;
1254
1255
1257 msg = GNUNET_malloc (sizeof (*msg)
1258 + block_size);
1259 block = (struct BlockHeader*) &msg[1];
1261 pid,
1262 hello_sig,
1264 (char*) &msg[1]);
1265 msg->sig = block->sig;
1266 msg->expiration_time = block->expiration_time;
1267 memmove (&msg[1],
1268 (char*) block + sizeof (*block),
1269 block_size - sizeof (*block));
1270 msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO);
1271 msg->header.size = htons (sizeof (*msg)
1272 + block_size
1273 - sizeof (*block));
1274 msg->url_counter = htons ((uint16_t) builder->a_length);
1275 return &msg->header;
1276}
1277
1278
1279void
1281 const struct GNUNET_HELLO_Builder *builder,
1282 const struct GNUNET_PeerIdentity *pid,
1283 const struct GNUNET_CRYPTO_EddsaSignature *sig,
1285 char *block)
1286{
1287 struct BlockHeader bh = { 0 };
1288 char *pos;
1289 struct GNUNET_TIME_Absolute et;
1290
1291 if (NULL != pid)
1292 bh.pid = *pid;
1293 if (NULL != sig)
1294 bh.sig = *sig;
1295 if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == expiration_time.abs_value_us)
1297 else
1298 et = expiration_time;
1300 memcpy (block,
1301 &bh,
1302 sizeof (bh));
1303 pos = block + sizeof (bh);
1304 for (struct Address *a = builder->a_head; NULL != a; a = a->next)
1305 {
1306 memcpy (pos,
1307 a->uri,
1308 a->uri_len);
1309 pos += a->uri_len;
1310 }
1311}
1312
1313
1316 const struct GNUNET_PeerIdentity *pid,
1317 const struct GNUNET_CRYPTO_EddsaSignature *sig,
1318 struct GNUNET_TIME_Absolute validity,
1319 char **result)
1320{
1322 pid,
1323 sig,
1324 validity,
1325 result);
1326}
1327
1328
1331 const struct GNUNET_PeerIdentity *pid,
1332 const struct GNUNET_CRYPTO_EddsaSignature *sig,
1333 char **result)
1334{
1335 struct GNUNET_TIME_Absolute et;
1336
1338
1340 pid,
1341 sig,
1342 et,
1343 result);
1344}
1345
1346
1347size_t
1349 const struct GNUNET_HELLO_Builder *builder)
1350{
1351 struct BlockHeader bh;
1352 size_t needed = sizeof (bh);
1353
1354 for (struct Address *a = builder->a_head;
1355 NULL != a;
1356 a = a->next)
1357 {
1358 GNUNET_assert (needed + a->uri_len > needed);
1359 needed += a->uri_len;
1360 }
1361 return needed;
1362}
1363
1364
1367 abuilder,
1368 const struct GNUNET_HELLO_Builder *
1369 bbuilder)
1370{
1371 bool found = false;
1372 for (struct Address *a = abuilder->a_head; NULL != a; a = a->next)
1373 {
1374 for (struct Address *b = bbuilder->a_head; NULL != b; b = b->next)
1375 {
1376 if (0 != strcmp (b->uri, a->uri))
1377 continue;
1378 found = true;
1379 break;
1380 }
1381 if (! found)
1382 return GNUNET_NO;
1383 found = false;
1384 }
1385 return GNUNET_YES;
1386}
struct GNUNET_MessageHeader * msg
Definition 005.c:2
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
static int ret
Final status code.
Definition gnunet-arm.c:93
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
static char * address
GNS address for this phone.
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static int result
Global testing status.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_FS_UnindexContext * uc
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
Helper library for handling HELLO URIs.
Constants for network protocols.
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
Functions related to time.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
Definition hello-uri.c:380
void GNUNET_HELLO_builder_to_block(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, struct GNUNET_TIME_Absolute expiration_time, char *block)
Generate DHT block from a builder.
Definition hello-uri.c:1280
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition hello-uri.c:398
char * GNUNET_HELLO_parser_to_url(const struct GNUNET_HELLO_Parser *parser)
Generate GNUnet HELLO URI from a parser.
Definition hello-uri.c:839
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new()
Allocate builder.
Definition hello-uri.c:344
enum GNUNET_GenericReturnValue GNUNET_HELLO_dht_msg_to_block(const struct GNUNET_MessageHeader *hello, const struct GNUNET_PeerIdentity *pid, void **block, size_t *block_size, struct GNUNET_TIME_Absolute *block_expiration)
Convert a DHT hello message to a HELLO block.
Definition hello-uri.c:1033
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_block_(const void *block, size_t block_size, int noverify)
Parse block.
Definition hello-uri.c:570
void GNUNET_HELLO_builder_iterate(const struct GNUNET_HELLO_Builder *builder, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a builder.
Definition hello-uri.c:992
enum GNUNET_GenericReturnValue GNUNET_HELLO_parser_to_block(const struct GNUNET_HELLO_Parser *parser, void *block, size_t *block_size)
Generate DHT block from a parser.
Definition hello-uri.c:896
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_to_url(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, char **result)
Generate GNUnet HELLO URI from a builder.
Definition hello-uri.c:1330
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_parser(const struct GNUNET_HELLO_Parser *p, struct GNUNET_PeerIdentity *pid)
Allocate builder from parser.
Definition hello-uri.c:361
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_iterate(const struct GNUNET_HELLO_Parser *parser, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a parser.
Definition hello-uri.c:1011
struct GNUNET_MessageHeader * GNUNET_HELLO_parser_to_dht_hello_msg(const struct GNUNET_HELLO_Parser *parser)
Generate DHT HELLO message from a parser.
Definition hello-uri.c:1208
enum GNUNET_GenericReturnValue GNUNET_HELLO_build_url(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, struct GNUNET_TIME_Absolute expiration, char **result)
Definition hello-uri.c:1110
struct GNUNET_MQ_Envelope * GNUNET_HELLO_parser_to_env(const struct GNUNET_HELLO_Parser *parser)
Generate envelope with GNUnet HELLO message (including peer ID) from a parser.
Definition hello-uri.c:939
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_address_list_cmp(const struct GNUNET_HELLO_Builder *abuilder, const struct GNUNET_HELLO_Builder *bbuilder)
Compare address lists of two builders.
Definition hello-uri.c:1366
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_del_address(struct GNUNET_HELLO_Builder *builder, const char *address)
Remove individual address from the builder.
Definition hello-uri.c:968
struct GNUNET_TIME_Absolute GNUNET_HELLO_get_expiration_time_from_msg(const struct GNUNET_MessageHeader *msg)
Get the expiration time for this HELLO.
Definition hello-uri.c:633
size_t GNUNET_HELLO_get_builder_to_block_size(const struct GNUNET_HELLO_Builder *builder)
Get projected block size for builder.
Definition hello-uri.c:1348
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_get_id(const struct GNUNET_HELLO_Parser *parser)
Get the PeerIdentity for this builder.
Definition hello-uri.c:354
void(* GNUNET_HELLO_UriCallback)(void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
Callback function used to extract URIs from a builder.
#define GNUNET_HELLO_ADDRESS_EXPIRATION
For how long are HELLO signatures valid?
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_msg(const struct GNUNET_MessageHeader *msg, const struct GNUNET_PeerIdentity *pid)
Parse msg.
Definition hello-uri.c:416
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_add_address(struct GNUNET_HELLO_Builder *builder, const char *address)
Add individual address to the builder.
Definition hello-uri.c:660
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_url(const char *url)
Parse GNUnet HELLO url.
Definition hello-uri.c:699
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_to_url2(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, struct GNUNET_TIME_Absolute validity, char **result)
Generate GNUnet HELLO URI from a builder.
Definition hello-uri.c:1315
struct GNUNET_MessageHeader * GNUNET_HELLO_builder_to_dht_hello_msg(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *hello_sig, struct GNUNET_TIME_Absolute expiration_time)
Generate DHT HELLO message (without peer ID) from a builder.
Definition hello-uri.c:1245
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_block(const void *block, size_t block_size)
Parse block.
Definition hello-uri.c:560
char * GNUNET_HELLO_address_to_prefix(const char *address)
Given an address as a string, extract the prefix that identifies the communicator offering transmissi...
Definition hello-uri.c:1098
void GNUNET_HELLO_builder_hash_addresses(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
Compute hash over addresses in builder.
Definition hello-uri.c:1170
struct GNUNET_MQ_Envelope * GNUNET_HELLO_builder_to_env(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *hello_sig, struct GNUNET_TIME_Absolute expiration_time)
Generate envelope with GNUnet HELLO message (including peer ID) from a builder.
Definition hello-uri.c:1178
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE, comparator, comparator_cls, head, tail, element)
Insertion sort of element into DLL from head to tail sorted by comparator.
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.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
#define GNUNET_PACKED
gcc-ism to get packed structs.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#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.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#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.
#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_MESSAGE_TYPE_DHT_P2P_HELLO
HELLO advertising a neighbours addresses.
#define GNUNET_MESSAGE_TYPE_HELLO_URI
Latest HELLO messages used for communicating peer addresses.
size_t GNUNET_STRINGS_urlencode(size_t len, const char data[static len], char **out)
url/percent encode (RFC3986).
Definition strings.c:1887
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition strings.c:812
size_t GNUNET_STRINGS_urldecode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition strings.c:1832
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition strings.c:837
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition time.c:667
static enum GNUNET_GenericReturnValue verify_hello(const struct GNUNET_HELLO_Parser *parser, struct GNUNET_TIME_Absolute et, const struct GNUNET_CRYPTO_EddsaSignature *sig)
Verify HELLO signature.
Definition hello-uri.c:304
static void hash_addresses(const struct Address *addr_start, struct GNUNET_HashCode *hash)
Definition hello-uri.c:267
static struct GNUNET_HELLO_Parser * parser_new(const struct GNUNET_PeerIdentity *pid)
Definition hello-uri.c:333
static int cmp_address(void *cls, struct Address *a, struct Address *b)
Alphanumeric sorting for addresses.
Definition hello-uri.c:514
static enum GNUNET_GenericReturnValue check_address(const char *address)
Definition hello-uri.c:475
static enum GNUNET_GenericReturnValue parser_add_address(struct GNUNET_HELLO_Parser *parser, const char *address)
Definition hello-uri.c:521
static unsigned int size
Size of the "table".
Definition peer.c:68
Struct to wrap data to do the merge of to hello uris.
Definition hello-uri.c:207
unsigned int merged
Did we found at least one address to merge.
Definition hello-uri.c:226
struct GNUNET_HELLO_Builder * builder
The builder of the hello uri we merge with.
Definition hello-uri.c:211
unsigned int found
Did we found the actual address to check.
Definition hello-uri.c:221
const char * address_uri
The actual address to check, if it is already in the hello uri we merge with.
Definition hello-uri.c:216
Address of a peer.
Definition hello-uri.c:158
struct Address * next
Kept in a DLL.
Definition hello-uri.c:162
size_t uri_len
Length of uri including 0-terminator.
Definition hello-uri.c:177
struct Address * prev
Kept in a DLL.
Definition hello-uri.c:167
const char * uri
Actual URI, allocated at the end of this struct.
Definition hello-uri.c:172
Start of a 'block'.
Definition hello-uri.c:97
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the HELLO expire?
Definition hello-uri.c:111
struct GNUNET_CRYPTO_EddsaSignature sig
Signature over the block, of purpose GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition hello-uri.c:106
struct GNUNET_PeerIdentity pid
Public key of the peer.
Definition hello-uri.c:101
Message used when a DHT provides its HELLO to direct neighbours.
Definition hello-uri.c:121
uint16_t reserved
Reserved.
Definition hello-uri.c:130
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the HELLO expire?
Definition hello-uri.c:145
struct GNUNET_MessageHeader header
Type must be GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO.
Definition hello-uri.c:125
struct GNUNET_CRYPTO_EddsaSignature sig
Signature over the block, of purpose GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition hello-uri.c:140
uint16_t url_counter
Number of URLs encoded after the end of the struct, in NBO.
Definition hello-uri.c:135
an ECC signature using EdDSA.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
Context for building (or parsing) HELLO URIs.
Definition hello-uri.c:185
struct Address * a_tail
Tail of the addresses DLL.
Definition hello-uri.c:194
struct Address * a_head
Head of the addresses DLL.
Definition hello-uri.c:189
unsigned int a_length
Length of the a_head DLL.
Definition hello-uri.c:199
Context for parsing HELLOs.
Definition hello-uri.c:233
struct GNUNET_PeerIdentity pid
Public key of the peer.
Definition hello-uri.c:237
struct GNUNET_TIME_Absolute et
Expiration time parsed.
Definition hello-uri.c:262
struct GNUNET_CRYPTO_EddsaSignature sig
The signature (may have been provided)
Definition hello-uri.c:257
struct Address * a_tail
Tail of the addresses DLL.
Definition hello-uri.c:247
unsigned int a_length
Length of the a_head DLL.
Definition hello-uri.c:252
struct Address * a_head
Head of the addresses DLL.
Definition hello-uri.c:242
A 512-bit hashcode.
Header for all communications.
The identity of the host (wraps the signing key of the peer).
pid_t pid
PID of the process.
Definition os_process.c:94
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Message used when gossiping HELLOs between peers.
Definition hello-uri.c:73
uint16_t reserved
Reserved.
Definition hello-uri.c:82
uint16_t url_counter
Number of URLs encoded after the end of the struct, in NBO.
Definition hello-uri.c:87
struct GNUNET_MessageHeader header
Type must be GNUNET_MESSAGE_TYPE_HELLO_URI.
Definition hello-uri.c:77
Message signed as part of a HELLO block/URL.
Definition hello-uri.c:51
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Definition hello-uri.c:65
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the signature expire?
Definition hello-uri.c:60
struct GNUNET_CRYPTO_SignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition hello-uri.c:55