GNUnet 0.22.2
hello-uri.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 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
37#include "platform.h"
38#include "gnunet_util_lib.h"
39#include "gnunet_signatures.h"
41#include "gnunet_protocols.h"
42
43
45
50{
55
60
65};
66
71{
76
81
86
87};
88
93{
98
103
108
109 /* followed by a 'block' */
110};
111
112
117{
122
127
132
133};
134
135
141{
146
151
156
161
166
167 /* followed by the serialized addresses of the 'block' */
168};
169
170
172
173
178{
182 struct Address *next;
183
187 struct Address *prev;
188
192 const char *uri;
193
197 size_t uri_len;
198};
199
200
205{
210
215
220
224 unsigned int a_length;
225
226};
227
232{
237
241 const char *address_uri;
242
246 unsigned int found;
247
251 unsigned int merged;
252};
253
258{
263
268
273
277 unsigned int a_length;
278
283
288};
289
296static void
298 struct GNUNET_HashCode *hash)
299{
300 struct GNUNET_HashContext *hc;
301
303 for (const struct Address *a = a_head;
304 NULL != a;
305 a = a->next)
306 {
308 "Hashing over %.*s\n",
309 (int) a->uri_len,
310 a->uri);
312 a->uri,
313 a->uri_len);
314 }
316 hash);
317
318}
319
320
329static void
331 struct GNUNET_TIME_Absolute et,
332 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
334{
335 struct HelloSignaturePurpose hsp = {
336 .purpose.size = htonl (sizeof (hsp)),
337 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
338 .expiration_time = GNUNET_TIME_absolute_hton (et)
339 };
340
341 hash_addresses (builder->a_head,
342 &hsp.h_addrs);
344 "Address hash is %s\n",
345 GNUNET_h2s_full (&hsp.h_addrs));
347 &hsp,
348 sig);
349}
350
351
363 struct GNUNET_TIME_Absolute et,
364 const struct GNUNET_CRYPTO_EddsaSignature *sig)
365{
366 struct HelloSignaturePurpose hsp = {
367 .purpose.size = htonl (sizeof (hsp)),
368 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
369 .expiration_time = GNUNET_TIME_absolute_hton (et)
370 };
371
372 hash_addresses (parser->a_head,
373 &hsp.h_addrs);
374 if (GNUNET_OK !=
376 &hsp,
377 sig,
378 &parser->pid.public_key))
379 {
380 GNUNET_break_op (0);
381 return GNUNET_SYSERR;
382 }
384 return GNUNET_NO;
385 return GNUNET_OK;
386}
387
388
389static struct GNUNET_HELLO_Parser *
391{
392 struct GNUNET_HELLO_Parser *p;
393
395 p->pid = *pid;
396 return p;
397}
398
399
402{
404
406 builder->pid = *pid;
407 return builder;
408}
409
410
411const struct GNUNET_PeerIdentity *
413{
414 return &parser->pid;
415}
416
417
420{
422 struct Address *a;
423
425 /* check for duplicates */
426 for (a = p->a_head;
427 NULL != a;
428 a = a->next)
430 return builder;
431}
432
433
434void
436{
437 struct Address *a;
438
439 while (NULL != (a = parser->a_head))
440 {
442 parser->a_tail,
443 a);
444 parser->a_length--;
445 GNUNET_free (a);
446 }
447 GNUNET_assert (0 == parser->a_length);
449}
450
451
452void
454{
455 struct Address *a;
456
457 while (NULL != (a = builder->a_head))
458 {
460 builder->a_tail,
461 a);
462 builder->a_length--;
463 GNUNET_free (a);
464 }
465 GNUNET_assert (0 == builder->a_length);
467}
468
469
470struct GNUNET_HELLO_Parser *
472{
473 const struct HelloUriMessage *h;
474 uint16_t size = ntohs (msg->size);
475
476 if (GNUNET_MESSAGE_TYPE_HELLO_URI != ntohs (msg->type))
477 {
478 GNUNET_break (0);
479 return NULL;
480 }
481 if (sizeof (struct HelloUriMessage) > size)
482 {
483 GNUNET_break_op (0);
484 return NULL;
485 }
486 h = (const struct HelloUriMessage *) msg;
487 size -= sizeof (*h);
489 size);
490}
491
492
495{
496 const char *e;
497
498 if (NULL == (e = strstr (address,
499 "://")))
500 {
501 GNUNET_break_op (0);
503 "Invalid address `%s'\n",
504 address);
505 return GNUNET_SYSERR;
506 }
507 if (e == address)
508 {
509 GNUNET_break_op (0);
510 return GNUNET_SYSERR;
511 }
512 for (const char *p = address; p != e; p++)
513 if ( (! isalpha ((unsigned char) *p)) &&
514 ('+' != *p) )
515 {
516 GNUNET_break_op (0);
517 return GNUNET_SYSERR;
518 }
519 return GNUNET_OK;
520}
521
524 const char *address)
525{
526 struct Address *a;
528 size_t alen = strlen (address) + 1;
529
531 if (GNUNET_OK != ret)
532 {
534 "Failed to add address to builder\n");
535 return ret;
536 }
537 /* check for duplicates */
538 for (a = parser->a_head;
539 NULL != a;
540 a = a->next)
541 if (0 == strcmp (address,
542 a->uri))
543 return GNUNET_NO;
544 a = GNUNET_malloc (sizeof (struct Address) + alen);
545 a->uri_len = alen;
546 memcpy (&a[1],
547 address,
548 alen);
549 a->uri = (const char *) &a[1];
551 parser->a_tail,
552 a);
553 parser->a_length++;
554 return GNUNET_OK;
555}
556
557
558struct GNUNET_HELLO_Parser *
560 size_t block_size)
561{
562 const struct BlockHeader *bh = block;
563 struct GNUNET_HELLO_Parser *p;
564
565 if (block_size < sizeof (*bh))
566 {
567 GNUNET_break_op (0);
568 return NULL;
569 }
570 p = parser_new (&bh->pid);
571 block += sizeof (*bh);
572 block_size -= sizeof (*bh);
573 while (block_size > 0)
574 {
575 const void *end = memchr (block,
576 '\0',
577 block_size);
578
579 if (NULL == end)
580 {
581 GNUNET_break_op (0);
583 return NULL;
584 }
585 if (GNUNET_OK !=
587 block))
588 {
589 GNUNET_break_op (0);
591 return NULL;
592 }
593 end++;
594 block_size -= (end - block);
595 block = end;
596 }
597 {
599 struct GNUNET_TIME_Absolute et;
600
602 ret = verify_hello (p,
603 et,
604 &bh->sig);
606 if (GNUNET_OK != ret)
607 {
609 return NULL;
610 }
612 p->sig = bh->sig;
613 }
614 return p;
615}
616
617
621{
622 struct GNUNET_TIME_Absolute et;
623 if (GNUNET_MESSAGE_TYPE_HELLO_URI == ntohs (msg->type))
624 {
625 const struct HelloUriMessage *h = (const struct HelloUriMessage *) msg;
626 const struct BlockHeader *bh = (const struct BlockHeader *) &h[1];
627
629 return et;
630 }
631 else if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO == ntohs (msg->type))
632 {
633 const struct DhtHelloMessage *dht_hello
634 = (const struct DhtHelloMessage *) msg;
635
637 return et;
638 }
639 else
640 GNUNET_break (0);
642}
643
644
647 const char *address)
648{
649 struct Address *a;
651 size_t alen = strlen (address) + 1;
652
654 if (GNUNET_OK != ret)
655 {
657 "Failed to add address to builder\n");
658 return ret;
659 }
660 /* check for duplicates */
661 for (a = builder->a_head;
662 NULL != a;
663 a = a->next)
664 if (0 == strcmp (address,
665 a->uri))
666 return GNUNET_NO;
667 a = GNUNET_malloc (sizeof (struct Address) + alen);
668 a->uri_len = alen;
669 memcpy (&a[1],
670 address,
671 alen);
672 a->uri = (const char *) &a[1];
674 builder->a_tail,
675 a);
676 builder->a_length++;
677 return GNUNET_OK;
678}
679
680
681struct GNUNET_HELLO_Parser *
683{
684 const char *q;
685 const char *s1;
686 const char *s2;
688 struct GNUNET_TIME_Absolute et;
689 size_t len;
690 struct GNUNET_HELLO_Parser *p;
692
693 if (0 != strncasecmp (url,
694 "gnunet://hello/",
695 strlen ("gnunet://hello/")))
696 return NULL;
697 url += strlen ("gnunet://hello/");
698 s1 = strchr (url, '/');
699 if (NULL == s1)
700 {
701 GNUNET_break_op (0);
702 return NULL;
703 }
704 s2 = strchr (s1 + 1, '/');
705 if (NULL == s1)
706 {
707 GNUNET_break_op (0);
708 return NULL;
709 }
710 q = strchr (url, '?');
711 if (NULL == q)
712 q = url + strlen (url);
713 if (GNUNET_OK !=
715 s1 - url,
716 &pid,
717 sizeof(pid)))
718 {
719 GNUNET_break_op (0);
720 return NULL;
721 }
722 if (GNUNET_OK !=
724 s2 - (s1 + 1),
725 &sig,
726 sizeof(sig)))
727 {
728 GNUNET_break_op (0);
729 return NULL;
730 }
731 {
732 uint64_t sec;
733 char dummy = '?';
734
735 if ( (0 == sscanf (s2 + 1,
736 "%" PRIu64 "%c",
737 &sec,
738 &dummy)) ||
739 ('?' != dummy) )
740 {
741 GNUNET_break_op (0);
742 return NULL;
743 }
744 et.abs_value_us = sec;
745 }
746
747 p = parser_new (&pid);
748 p->et = et;
749 p->sig = sig;
750 len = strlen (q);
751 while (len > 0)
752 {
753 const char *eq;
754 const char *amp;
755 char *addr = NULL;
756 char *uri;
757
758 /* skip ?/& separator */
759 len--;
760 q++;
761 eq = strchr (q, '=');
762 if ( (eq == q) ||
763 (NULL == eq) )
764 {
765 GNUNET_break_op (0);
767 return NULL;
768 }
769 amp = strchr (eq, '&');
770 if (NULL == amp)
771 amp = &q[len];
773 amp - (eq + 1),
774 &addr);
775 if ( (NULL == addr) ||
776 (0 == strlen (addr)) )
777 {
778 GNUNET_free (addr);
779 GNUNET_break_op (0);
781 return NULL;
782 }
784 "%.*s://%s",
785 (int) (eq - q),
786 q,
787 addr);
788 GNUNET_free (addr);
789 if (GNUNET_OK !=
791 uri))
792 {
793 GNUNET_break_op (0);
796 return NULL;
797 }
799 /* move to next URL */
800 len -= (amp - q);
801 q = amp;
802 }
803
804 {
806
807 ret = verify_hello (p,
808 et,
809 &p->sig);
811 if (GNUNET_OK != ret)
812 {
814 return NULL;
815 }
816 }
817 return p;
818}
819
820
823 const struct GNUNET_HELLO_Builder *builder,
824 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
825 struct GNUNET_TIME_Relative expiration_time)
826{
827 struct DhtHelloMessage *msg;
828 size_t blen;
829
830 if (builder->a_length > UINT16_MAX)
831 {
832 GNUNET_break (0);
833 return NULL;
834 }
835 blen = 0;
838 priv,
839 NULL,
840 &blen,
842 GNUNET_assert (blen < UINT16_MAX);
843 GNUNET_assert (blen >= sizeof (struct BlockHeader));
844 {
845 char buf[blen] GNUNET_ALIGN;
846 const struct BlockHeader *block = (const struct BlockHeader *) buf;
847
850 priv,
851 buf,
852 &blen,
854 msg = GNUNET_malloc (sizeof (*msg)
855 + blen
856 - sizeof (*block));
858 msg->header.size = htons (sizeof (*msg)
859 + blen
860 - sizeof (*block));
861 memcpy (&msg[1],
862 &block[1],
863 blen - sizeof (*block));
864 msg->sig = block->sig;
865 msg->expiration_time = block->expiration_time;
866 }
867 msg->url_counter = htons ((uint16_t) builder->a_length);
868 return &msg->header;
869}
870
871
872char *
874 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
875 struct GNUNET_TIME_Relative validity)
876{
878 struct GNUNET_TIME_Absolute et;
879 char *result;
880 char *pids;
881 char *sigs;
882 const char *sep = "?";
883
884 et = GNUNET_TIME_relative_to_absolute (validity);
885 GNUNET_assert (NULL != priv);
887 et,
888 priv,
889 &sig);
891 sizeof (builder->pid));
893 sizeof (sig));
895 "gnunet://hello/%s/%s/%" PRIu64,
896 pids,
897 sigs,
898 et.abs_value_us);
899 GNUNET_free (sigs);
900 GNUNET_free (pids);
901 for (struct Address *a = builder->a_head;
902 NULL != a;
903 a = a->next)
904 {
905 char *ue;
906 char *tmp;
907 int pfx_len;
908 const char *eou;
909
910 eou = strstr (a->uri,
911 "://");
912 if (NULL == eou)
913 {
914 GNUNET_break (0);
916 return NULL;
917 }
918 pfx_len = eou - a->uri;
919 eou += 3;
920 GNUNET_STRINGS_urlencode (a->uri_len - 4 - pfx_len,
921 eou,
922 &ue);
923 GNUNET_asprintf (&tmp,
924 "%s%s%.*s=%s",
925 result,
926 sep,
927 pfx_len,
928 a->uri,
929 ue);
930 GNUNET_free (ue);
932 result = tmp;
933 sep = "&";
934 }
935 return result;
936}
937
938
939char *
941{
942 char *result;
943 char *pids;
944 char *sigs;
945 const char *sep = "?";
946
948 sizeof (parser->pid));
950 sizeof (parser->sig));
952 "gnunet://hello/%s/%s/%" PRIu64,
953 pids,
954 sigs,
955 parser->et.abs_value_us);
956 GNUNET_free (sigs);
957 GNUNET_free (pids);
958 for (struct Address *a = parser->a_head;
959 NULL != a;
960 a = a->next)
961 {
962 char *ue;
963 char *tmp;
964 int pfx_len;
965 const char *eou;
966
967 eou = strstr (a->uri,
968 "://");
969 if (NULL == eou)
970 {
971 GNUNET_break (0);
973 return NULL;
974 }
975 pfx_len = eou - a->uri;
976 eou += 3;
977 GNUNET_STRINGS_urlencode (a->uri_len - 4 - pfx_len,
978 eou,
979 &ue);
980 GNUNET_asprintf (&tmp,
981 "%s%s%.*s=%s",
982 result,
983 sep,
984 pfx_len,
985 a->uri,
986 ue);
987 GNUNET_free (ue);
989 result = tmp;
990 sep = "&";
991 }
992 return result;
993}
994
995
996char *
998 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
999{
1002}
1003
1004
1007 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1008 void *block,
1009 size_t *block_size,
1010 struct GNUNET_TIME_Relative expiration_time)
1011{
1012 struct BlockHeader bh;
1013 size_t needed = sizeof (bh);
1014 char *pos;
1015 struct GNUNET_TIME_Absolute et;
1016
1017 GNUNET_assert (NULL != priv);
1018 for (struct Address *a = builder->a_head;
1019 NULL != a;
1020 a = a->next)
1021 {
1022 GNUNET_assert (needed + a->uri_len > needed);
1023 needed += a->uri_len;
1024 }
1025 if ( (NULL == block) ||
1026 (needed < *block_size) )
1027 {
1028 *block_size = needed;
1029 return GNUNET_NO;
1030 }
1031 bh.pid = builder->pid;
1032 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == expiration_time.rel_value_us)
1034 else
1035 et = GNUNET_TIME_relative_to_absolute (expiration_time);
1038 et,
1039 priv,
1040 &bh.sig);
1041 memcpy (block,
1042 &bh,
1043 sizeof (bh));
1044 pos = block + sizeof (bh);
1045 for (struct Address *a = builder->a_head;
1046 NULL != a;
1047 a = a->next)
1048 {
1049 memcpy (pos,
1050 a->uri,
1051 a->uri_len);
1052 pos += a->uri_len;
1053 }
1054 *block_size = needed;
1055 return GNUNET_OK;
1056}
1057
1058
1061 void *block,
1062 size_t *block_size)
1063{
1064 struct BlockHeader bh;
1065 size_t needed = sizeof (bh);
1066 char *pos;
1067
1068 for (struct Address *a = parser->a_head;
1069 NULL != a;
1070 a = a->next)
1071 {
1072 GNUNET_assert (needed + a->uri_len > needed);
1073 needed += a->uri_len;
1074 }
1075 if ( (NULL == block) ||
1076 (needed < *block_size) )
1077 {
1078 *block_size = needed;
1079 return GNUNET_NO;
1080 }
1081 bh.pid = parser->pid;
1082 bh.sig = parser->sig;
1084 memcpy (block,
1085 &bh,
1086 sizeof (bh));
1087 pos = block + sizeof (bh);
1088 for (struct Address *a = parser->a_head;
1089 NULL != a;
1090 a = a->next)
1091 {
1092 memcpy (pos,
1093 a->uri,
1094 a->uri_len);
1095 pos += a->uri_len;
1096 }
1097 *block_size = needed;
1098 return GNUNET_OK;
1099}
1100
1101
1102struct GNUNET_MQ_Envelope *
1104{
1105 struct GNUNET_MQ_Envelope *env;
1106 struct HelloUriMessage *msg;
1107 size_t blen;
1108
1109 if (parser->a_length > UINT16_MAX)
1110 {
1111 GNUNET_break (0);
1112 return NULL;
1113 }
1114 blen = 0;
1117 NULL,
1118 &blen));
1120 blen,
1122 msg->url_counter = htons ((uint16_t) parser->a_length);
1125 &msg[1],
1126 &blen));
1127 return env;
1128}
1129
1130
1131static struct GNUNET_MQ_Envelope *
1133 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1134 struct GNUNET_TIME_Relative expiration_time,
1135 const struct GNUNET_CRYPTO_EddsaSignature *sig)
1136{
1137 struct GNUNET_MQ_Envelope *env;
1138 struct HelloUriMessage *msg;
1139 size_t blen;
1140
1141 if (builder->a_length > UINT16_MAX)
1142 {
1143 GNUNET_break (0);
1144 return NULL;
1145 }
1146 blen = 0;
1149 priv,
1150 NULL,
1151 &blen,
1152 expiration_time));
1154 blen,
1156 msg->url_counter = htons ((uint16_t) builder->a_length);
1159 priv,
1160 &msg[1],
1161 &blen,
1162 expiration_time));
1163 return env;
1164}
1165
1166
1167struct GNUNET_MQ_Envelope *
1169 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1170 struct GNUNET_TIME_Relative expiration_time)
1171{
1172 return GNUNET_HELLO_builder_to_env_ (builder, priv, expiration_time, NULL);
1173}
1174
1175
1178 const char *address)
1179{
1180 struct Address *a;
1181
1182 /* check for duplicates */
1183 for (a = builder->a_head;
1184 NULL != a;
1185 a = a->next)
1186 if (0 == strcmp (address,
1187 a->uri))
1188 break;
1189 if (NULL == a)
1190 return GNUNET_NO;
1192 builder->a_tail,
1193 a);
1194 builder->a_length--;
1195 GNUNET_free (a);
1196 return GNUNET_OK;
1197}
1198
1199
1200const struct GNUNET_PeerIdentity*
1203 void *uc_cls)
1204{
1205 struct Address *nxt;
1206
1207 if (NULL == uc)
1208 return &parser->pid;
1209 for (struct Address *a = parser->a_head;
1210 NULL != a;
1211 a = nxt)
1212 {
1213 nxt = a->next;
1214 uc (uc_cls,
1215 &parser->pid,
1216 a->uri);
1217 }
1218 return &parser->pid;
1219}
1220
1221
1224 const struct GNUNET_PeerIdentity *pid,
1225 void **block,
1226 size_t *block_size,
1227 struct GNUNET_TIME_Absolute *block_expiration)
1228{
1229 const struct DhtHelloMessage *msg
1230 = (const struct DhtHelloMessage *) hello;
1231 uint16_t len = ntohs (hello->size);
1232 struct BlockHeader *bh;
1233 struct GNUNET_HELLO_Parser *b;
1235
1236 if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO != ntohs (hello->type))
1237 {
1238 GNUNET_break (0);
1239 return GNUNET_SYSERR;
1240 }
1241 if (len < sizeof (*msg))
1242 {
1243 GNUNET_break_op (0);
1244 return GNUNET_SYSERR;
1245 }
1246 len -= sizeof (*msg);
1247 *block_size = len + sizeof (*bh);
1248 *block = GNUNET_malloc (*block_size);
1249 bh = *block;
1250 bh->pid = *pid;
1251 bh->sig = msg->sig;
1252 bh->expiration_time = msg->expiration_time;
1253 *block_expiration = GNUNET_TIME_absolute_ntoh (msg->expiration_time);
1254 memcpy (&bh[1],
1255 &msg[1],
1256 len);
1258 *block_size);
1259 if (NULL == b)
1260 {
1261 GNUNET_break_op (0);
1262 GNUNET_free (*block);
1263 *block_size = 0;
1264 return GNUNET_SYSERR;
1265 }
1266 ret = verify_hello (b,
1267 *block_expiration,
1268 &msg->sig);
1270 if (GNUNET_SYSERR == ret)
1271 {
1272 GNUNET_free (*block);
1273 *block_size = 0;
1274 return GNUNET_SYSERR;
1275 }
1276 return ret;
1277}
1278
1279
1287char *
1289{
1290 const char *dash;
1291
1292 dash = strchr (address, '-');
1293 if (NULL == dash)
1294 return NULL;
1295 return GNUNET_strndup (address, dash - address);
1296}
1297
1298
1309void
1311 const char *address,
1313 struct GNUNET_TIME_Absolute mono_time,
1314 const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key,
1315 void **result,
1316 size_t *result_size)
1317{
1318 struct SignedAddress sa;
1320 char *sig_str;
1321
1323 sa.purpose.size = htonl (sizeof(sa));
1324 sa.mono_time = GNUNET_TIME_absolute_hton (mono_time);
1326 GNUNET_CRYPTO_eddsa_sign (private_key, &sa, &sig);
1327 sig_str = NULL;
1328 (void) GNUNET_STRINGS_base64_encode (&sig, sizeof(sig), &sig_str);
1329 *result_size =
1330 1 + GNUNET_asprintf ((char **) result,
1331 "%s;%llu;%u;%s",
1332 sig_str,
1333 (unsigned long long) mono_time.abs_value_us,
1334 (unsigned int) nt,
1335 address);
1336 GNUNET_free (sig_str);
1337}
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 in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
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 MyAddress * a_head
Head of addresses of this peer.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_FS_UnindexContext * uc
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
Helper library for handling HELLO URIs.
Constants for network protocols.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
#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.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail 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
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_parser(const struct GNUNET_HELLO_Parser *p)
Allocate builder from parser.
Definition: hello-uri.c:419
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
Definition: hello-uri.c:435
void GNUNET_HELLO_sign_address(const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Absolute mono_time, const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, void **result, size_t *result_size)
Build address record by signing raw information with private key.
Definition: hello-uri.c:1310
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg.
Definition: hello-uri.c:471
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:453
char * GNUNET_HELLO_parser_to_url(const struct GNUNET_HELLO_Parser *parser)
Generate GNUnet HELLO URI from a parser.
Definition: hello-uri.c:940
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:1223
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new(const struct GNUNET_PeerIdentity *pid)
Allocate builder.
Definition: hello-uri.c:401
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:1060
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:1201
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:1103
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:1177
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:619
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_to_block(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, void *block, size_t *block_size, struct GNUNET_TIME_Relative expiration_time)
Generate DHT block from a builder.
Definition: hello-uri.c:1006
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:412
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?
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:646
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_url(const char *url)
Parse GNUnet HELLO url.
Definition: hello-uri.c:682
char * GNUNET_HELLO_builder_to_url(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Generate GNUnet HELLO URI from a builder.
Definition: hello-uri.c:997
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_block(const void *block, size_t block_size)
Parse block.
Definition: hello-uri.c:559
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:1288
struct GNUNET_MessageHeader * GNUNET_HELLO_builder_to_dht_hello_msg(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative expiration_time)
Generate DHT HELLO message (without peer ID) from a builder.
Definition: hello-uri.c:822
struct GNUNET_MQ_Envelope * GNUNET_HELLO_builder_to_env(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative expiration_time)
Generate envelope with GNUnet HELLO message (including peer ID) from a builder.
Definition: hello-uri.c:1168
char * GNUNET_HELLO_builder_to_url2(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative validity)
Generate GNUnet HELLO URI from a builder.
Definition: hello-uri.c:873
#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.
Definition: crypto_hash.c:363
#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.
Definition: crypto_hash.c:387
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
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.
Definition: crypto_hash.c:347
#define GNUNET_PACKED
gcc-ism to get packed structs.
@ GNUNET_OK
@ 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.
@ 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.
Definition: gnunet_mq_lib.h:61
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:44
#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:1863
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:787
size_t GNUNET_STRINGS_urldecode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1808
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:812
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1599
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
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
#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: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
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:362
static void sign_hello(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_TIME_Absolute et, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaSignature *sig)
Create HELLO signature.
Definition: hello-uri.c:330
static struct GNUNET_HELLO_Parser * parser_new(const struct GNUNET_PeerIdentity *pid)
Definition: hello-uri.c:390
static void hash_addresses(const struct Address *a_head, struct GNUNET_HashCode *hash)
Compute hash over addresses in builder.
Definition: hello-uri.c:297
static enum GNUNET_GenericReturnValue check_address(const char *address)
Definition: hello-uri.c:494
static enum GNUNET_GenericReturnValue parser_add_address(struct GNUNET_HELLO_Parser *parser, const char *address)
Definition: hello-uri.c:523
static struct GNUNET_MQ_Envelope * GNUNET_HELLO_builder_to_env_(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative expiration_time, const struct GNUNET_CRYPTO_EddsaSignature *sig)
Definition: hello-uri.c:1132
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS
Signature by a peer affirming that this is one of its addresses for the given time period.
Struct to wrap data to do the merge of to hello uris.
Definition: hello-uri.c:232
unsigned int merged
Did we found at least one address to merge.
Definition: hello-uri.c:251
struct GNUNET_HELLO_Builder * builder
The builder of the hello uri we merge with.
Definition: hello-uri.c:236
unsigned int found
Did we found the actual address to check.
Definition: hello-uri.c:246
const char * address_uri
The actual address to check, if it is already in the hello uri we merge with.
Definition: hello-uri.c:241
Address of a peer.
Definition: hello-uri.c:178
struct Address * next
Kept in a DLL.
Definition: hello-uri.c:182
size_t uri_len
Length of uri including 0-terminator.
Definition: hello-uri.c:197
struct Address * prev
Kept in a DLL.
Definition: hello-uri.c:187
const char * uri
Actual URI, allocated at the end of this struct.
Definition: hello-uri.c:192
Start of a 'block'.
Definition: hello-uri.c:117
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the HELLO expire?
Definition: hello-uri.c:131
struct GNUNET_CRYPTO_EddsaSignature sig
Signature over the block, of purpose GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition: hello-uri.c:126
struct GNUNET_PeerIdentity pid
Public key of the peer.
Definition: hello-uri.c:121
Message used when a DHT provides its HELLO to direct neighbours.
Definition: hello-uri.c:141
uint16_t reserved
Reserved.
Definition: hello-uri.c:150
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the HELLO expire?
Definition: hello-uri.c:165
struct GNUNET_MessageHeader header
Type must be GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO.
Definition: hello-uri.c:145
struct GNUNET_CRYPTO_EddsaSignature sig
Signature over the block, of purpose GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition: hello-uri.c:160
uint16_t url_counter
Number of URLs encoded after the end of the struct, in NBO.
Definition: hello-uri.c:155
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 (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Private ECC key encoded for transmission.
an ECC signature using EdDSA.
Context for building (or parsing) HELLO URIs.
Definition: hello-uri.c:205
struct GNUNET_PeerIdentity pid
Public key of the peer.
Definition: hello-uri.c:209
struct Address * a_tail
Tail of the addresses DLL.
Definition: hello-uri.c:219
struct Address * a_head
Head of the addresses DLL.
Definition: hello-uri.c:214
unsigned int a_length
Length of the a_head DLL.
Definition: hello-uri.c:224
Context for parsing HELLOs.
Definition: hello-uri.c:258
struct GNUNET_PeerIdentity pid
Public key of the peer.
Definition: hello-uri.c:262
struct GNUNET_TIME_Absolute et
Expiration time parsed.
Definition: hello-uri.c:287
struct GNUNET_CRYPTO_EddsaSignature sig
The signature (may have been provided)
Definition: hello-uri.c:282
struct Address * a_tail
Tail of the addresses DLL.
Definition: hello-uri.c:272
unsigned int a_length
Length of the a_head DLL.
Definition: hello-uri.c:277
struct Address * a_head
Head of the addresses DLL.
Definition: hello-uri.c:267
A 512-bit hashcode.
Header for all communications.
pid_t pid
PID of the process.
Definition: os_priority.c:49
The identity of the host (wraps the signing key of the peer).
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.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Message signed as part of a HELLO block/URL.
Definition: hello-uri.c:71
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition: hello-uri.c:75
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the signature expire?
Definition: hello-uri.c:80
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Definition: hello-uri.c:85
Message used when gossiping HELLOs between peers.
Definition: hello-uri.c:93
uint16_t reserved
Reserved.
Definition: hello-uri.c:102
uint16_t url_counter
Number of URLs encoded after the end of the struct, in NBO.
Definition: hello-uri.c:107
struct GNUNET_MessageHeader header
Type must be GNUNET_MESSAGE_TYPE_HELLO_URI.
Definition: hello-uri.c:97
struct MyAddress * next
Kept in a DLL.
Binary block we sign when we sign an address.
Definition: hello-uri.c:50
struct GNUNET_HashCode addr_hash
Hash of the address.
Definition: hello-uri.c:64
struct GNUNET_TIME_AbsoluteNBO mono_time
When was the address generated.
Definition: hello-uri.c:59
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS.
Definition: hello-uri.c:54