GNUnet 0.21.1
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_signatures.h"
40#include "gnunet_protocols.h"
41#include "gnunet_util_lib.h"
42
43
45
49struct SignedAddress
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
254
261static void
263 struct GNUNET_HashCode *hash)
264{
265 struct GNUNET_HashContext *hc;
266
268 for (struct Address *a = builder->a_head;
269 NULL != a;
270 a = a->next)
271 {
273 "Hashing over %.*s\n",
274 (int) a->uri_len,
275 a->uri);
277 a->uri,
278 a->uri_len);
279 }
281 hash);
282
283}
284
285
294static void
296 struct GNUNET_TIME_Timestamp et,
297 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
299{
300 struct HelloSignaturePurpose hsp = {
301 .purpose.size = htonl (sizeof (hsp)),
302 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
303 .expiration_time = GNUNET_TIME_absolute_hton (et.abs_time)
304 };
305
307 &hsp.h_addrs);
309 "Address hash is %s\n",
310 GNUNET_h2s_full (&hsp.h_addrs));
312 &hsp,
313 sig);
314}
315
316
328 struct GNUNET_TIME_Absolute et,
329 const struct GNUNET_CRYPTO_EddsaSignature *sig)
330{
331 struct HelloSignaturePurpose hsp = {
332 .purpose.size = htonl (sizeof (hsp)),
333 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
334 .expiration_time = GNUNET_TIME_absolute_hton (et)
335 };
336
338 &hsp.h_addrs);
339 if (GNUNET_OK !=
341 &hsp,
342 sig,
343 &builder->pid.public_key))
344 {
345 GNUNET_break_op (0);
346 return GNUNET_SYSERR;
347 }
349 return GNUNET_NO;
350 return GNUNET_OK;
351}
352
353
356{
358
360 builder->pid = *pid;
361 return builder;
362}
363
364
365const struct GNUNET_PeerIdentity *
367{
368 return &builder->pid;
369}
370
371
372void
374{
375 struct Address *a;
376
377 while (NULL != (a = builder->a_head))
378 {
380 builder->a_tail,
381 a);
382 builder->a_length--;
383 GNUNET_free (a);
384 }
385 GNUNET_assert (0 == builder->a_length);
387}
388
389
392{
393 const struct HelloUriMessage *h;
394 uint16_t size = ntohs (msg->size);
395
396 if (GNUNET_MESSAGE_TYPE_HELLO_URI != ntohs (msg->type))
397 {
398 GNUNET_break (0);
399 return NULL;
400 }
401 if (sizeof (struct HelloUriMessage) > size)
402 {
403 GNUNET_break_op (0);
404 return NULL;
405 }
406 h = (const struct HelloUriMessage *) msg;
407 size -= sizeof (*h);
409 size);
410}
411
412
415 size_t block_size)
416{
417 const struct BlockHeader *bh = block;
418 struct GNUNET_HELLO_Builder *b;
419
420 if (block_size < sizeof (*bh))
421 {
422 GNUNET_break_op (0);
423 return NULL;
424 }
425 b = GNUNET_HELLO_builder_new (&bh->pid);
426 block += sizeof (*bh);
427 block_size -= sizeof (*bh);
428 while (block_size > 0)
429 {
430 const void *end = memchr (block,
431 '\0',
432 block_size);
433
434 if (NULL == end)
435 {
436 GNUNET_break_op (0);
438 return NULL;
439 }
440 if (GNUNET_OK !=
442 block))
443 {
444 GNUNET_break_op (0);
446 return NULL;
447 }
448 end++;
449 block_size -= (end - block);
450 block = end;
451 }
452 {
454
455 ret = verify_hello (b,
457 &bh->sig);
459 if (GNUNET_OK != ret)
460 {
462 return NULL;
463 }
464 }
465 return b;
466}
467
468
472{
473 if (GNUNET_MESSAGE_TYPE_HELLO_URI == ntohs (msg->type))
474 {
475 const struct HelloUriMessage *h = (struct HelloUriMessage *) msg;
476 const struct BlockHeader *bh = (const struct BlockHeader *) &h[1];
477
479 }
480 else if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO == ntohs (msg->type))
481 {
482 const struct DhtHelloMessage *dht_hello = (struct DhtHelloMessage *) msg;
483
484 return GNUNET_TIME_absolute_ntoh (dht_hello->expiration_time);
485 }
486 else
487 GNUNET_break (0);
489}
490
491
494{
495 const char *q;
496 const char *s1;
497 const char *s2;
500 struct GNUNET_TIME_Absolute et;
501 size_t len;
502 struct GNUNET_HELLO_Builder *b;
503
504 if (0 != strncasecmp (url,
505 "gnunet://hello/",
506 strlen ("gnunet://hello/")))
507 return NULL;
508 url += strlen ("gnunet://hello/");
509 s1 = strchr (url, '/');
510 if (NULL == s1)
511 {
512 GNUNET_break_op (0);
513 return NULL;
514 }
515 s2 = strchr (s1 + 1, '/');
516 if (NULL == s1)
517 {
518 GNUNET_break_op (0);
519 return NULL;
520 }
521 q = strchr (url, '?');
522 if (NULL == q)
523 q = url + strlen (url);
524 if (GNUNET_OK !=
526 s1 - url,
527 &pid,
528 sizeof(pid)))
529 {
530 GNUNET_break_op (0);
531 return NULL;
532 }
533 if (GNUNET_OK !=
535 s2 - (s1 + 1),
536 &sig,
537 sizeof(sig)))
538 {
539 GNUNET_break_op (0);
540 return NULL;
541 }
542 {
543 unsigned long long sec;
544 char dummy = '?';
545
546 if ( (0 == sscanf (s2 + 1,
547 "%llu%c",
548 &sec,
549 &dummy)) ||
550 ('?' != dummy) )
551 {
552 GNUNET_break_op (0);
553 return NULL;
554 }
556 }
557
559 len = strlen (q);
560 while (len > 0)
561 {
562 const char *eq;
563 const char *amp;
564 char *addr = NULL;
565 char *uri;
566
567 /* skip ?/& separator */
568 len--;
569 q++;
570 eq = strchr (q, '=');
571 if ( (eq == q) ||
572 (NULL == eq) )
573 {
574 GNUNET_break_op (0);
576 return NULL;
577 }
578 amp = strchr (eq, '&');
579 if (NULL == amp)
580 amp = &q[len];
582 amp - (eq + 1),
583 &addr);
584 if ( (NULL == addr) ||
585 (0 == strlen (addr)) )
586 {
587 GNUNET_free (addr);
588 GNUNET_break_op (0);
590 return NULL;
591 }
593 "%.*s://%s",
594 (int) (eq - q),
595 q,
596 addr);
597 GNUNET_free (addr);
598 if (GNUNET_OK !=
600 uri))
601 {
602 GNUNET_break_op (0);
605 return NULL;
606 }
608 /* move to next URL */
609 len -= (amp - q);
610 q = amp;
611 }
612
613 {
615
616 ret = verify_hello (b,
617 et,
618 &sig);
620 if (GNUNET_OK != ret)
621 {
623 return NULL;
624 }
625 }
626 return b;
627}
628
629
630struct GNUNET_MQ_Envelope *
632 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
633 struct GNUNET_TIME_Relative expiration_time)
634{
635 struct GNUNET_MQ_Envelope *env;
636 struct HelloUriMessage *msg;
637 size_t blen;
638
639 if (builder->a_length > UINT16_MAX)
640 {
641 GNUNET_break (0);
642 return NULL;
643 }
644 blen = 0;
647 priv,
648 NULL,
649 &blen,
650 expiration_time));
652 blen,
654 msg->url_counter = htons ((uint16_t) builder->a_length);
657 priv,
658 &msg[1],
659 &blen,
660 expiration_time));
661 return env;
662}
663
664
667 const struct GNUNET_HELLO_Builder *builder,
668 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
669 struct GNUNET_TIME_Relative expiration_time)
670{
671 struct DhtHelloMessage *msg;
672 size_t blen;
673
674 if (builder->a_length > UINT16_MAX)
675 {
676 GNUNET_break (0);
677 return NULL;
678 }
679 blen = 0;
682 priv,
683 NULL,
684 &blen,
686 GNUNET_assert (blen < UINT16_MAX);
687 GNUNET_assert (blen >= sizeof (struct BlockHeader));
688 {
689 char buf[blen] GNUNET_ALIGN;
690 const struct BlockHeader *block = (const struct BlockHeader *) buf;
691
694 priv,
695 buf,
696 &blen,
698 msg = GNUNET_malloc (sizeof (*msg)
699 + blen
700 - sizeof (*block));
702 msg->header.size = htons (sizeof (*msg)
703 + blen
704 - sizeof (*block));
705 memcpy (&msg[1],
706 &block[1],
707 blen - sizeof (*block));
708 msg->sig = block->sig;
709 msg->expiration_time = block->expiration_time;
710 }
711 msg->url_counter = htons ((uint16_t) builder->a_length);
712 return &msg->header;
713}
714
715
716char *
718 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
719{
721 struct GNUNET_TIME_Timestamp et;
722 char *result;
723 char *pids;
724 char *sigs;
725 const char *sep = "?";
726
729 et,
730 priv,
731 &sig);
733 sizeof (builder->pid));
735 sizeof (sig));
737 "gnunet://hello/%s/%s/%llu",
738 pids,
739 sigs,
740 (unsigned long long) GNUNET_TIME_timestamp_to_s (et));
741 GNUNET_free (sigs);
742 GNUNET_free (pids);
743 for (struct Address *a = builder->a_head;
744 NULL != a;
745 a = a->next)
746 {
747 char *ue;
748 char *tmp;
749 int pfx_len;
750 const char *eou;
751
752 eou = strstr (a->uri,
753 "://");
754 if (NULL == eou)
755 {
756 GNUNET_break (0);
758 return NULL;
759 }
760 pfx_len = eou - a->uri;
761 eou += 3;
762 GNUNET_STRINGS_urlencode (a->uri_len - 4 - pfx_len,
763 eou,
764 &ue);
765 GNUNET_asprintf (&tmp,
766 "%s%s%.*s=%s",
767 result,
768 sep,
769 pfx_len,
770 a->uri,
771 ue);
772 GNUNET_free (ue);
774 result = tmp;
775 sep = "&";
776 }
777 return result;
778}
779
780
783 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
784 void *block,
785 size_t *block_size,
786 struct GNUNET_TIME_Relative expiration_time)
787{
788 struct BlockHeader bh;
789 size_t needed = sizeof (bh);
790 char *pos;
791 struct GNUNET_TIME_Timestamp et;
792
793 for (struct Address *a = builder->a_head;
794 NULL != a;
795 a = a->next)
796 {
797 GNUNET_assert (needed + a->uri_len > needed);
798 needed += a->uri_len;
799 }
800 if ( (NULL == block) ||
801 (needed < *block_size) )
802 {
803 *block_size = needed;
804 return GNUNET_NO;
805 }
806 bh.pid = builder->pid;
807 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == expiration_time.rel_value_us)
809 else
810 et = GNUNET_TIME_relative_to_timestamp (expiration_time);
813 et,
814 priv,
815 &bh.sig);
816 memcpy (block,
817 &bh,
818 sizeof (bh));
819 pos = block + sizeof (bh);
820 for (struct Address *a = builder->a_head;
821 NULL != a;
822 a = a->next)
823 {
824 memcpy (pos,
825 a->uri,
826 a->uri_len);
827 pos += a->uri_len;
828 }
829 *block_size = needed;
830 return GNUNET_OK;
831}
832
833
836 const char *address)
837{
838 size_t alen = strlen (address) + 1;
839 struct Address *a;
840 const char *e;
841
842 if (NULL == (e = strstr (address,
843 "://")))
844 {
845 GNUNET_break_op (0);
847 "Invalid address `%s'\n",
848 address);
849 return GNUNET_SYSERR;
850 }
851 if (e == address)
852 {
853 GNUNET_break_op (0);
854 return GNUNET_SYSERR;
855 }
856 for (const char *p = address; p != e; p++)
857 if ( (! isalpha ((unsigned char) *p)) &&
858 ('+' != *p) )
859 {
860 GNUNET_break_op (0);
861 return GNUNET_SYSERR;
862 }
863 /* check for duplicates */
864 for (a = builder->a_head;
865 NULL != a;
866 a = a->next)
867 if (0 == strcmp (address,
868 a->uri))
869 return GNUNET_NO;
870 a = GNUNET_malloc (sizeof (struct Address) + alen);
871 a->uri_len = alen;
872 memcpy (&a[1],
873 address,
874 alen);
875 a->uri = (const char *) &a[1];
877 builder->a_tail,
878 a);
879 builder->a_length++;
880 return GNUNET_OK;
881}
882
883
886 const char *address)
887{
888 struct Address *a;
889
890 /* check for duplicates */
891 for (a = builder->a_head;
892 NULL != a;
893 a = a->next)
894 if (0 == strcmp (address,
895 a->uri))
896 break;
897 if (NULL == a)
898 return GNUNET_NO;
900 builder->a_tail,
901 a);
902 builder->a_length--;
903 GNUNET_free (a);
904 return GNUNET_OK;
905}
906
907
908const struct GNUNET_PeerIdentity*
911 void *uc_cls)
912{
913 struct Address *nxt;
914
915 if (NULL == uc)
916 return &builder->pid;
917 for (struct Address *a = builder->a_head;
918 NULL != a;
919 a = nxt)
920 {
921 nxt = a->next;
922 uc (uc_cls,
923 &builder->pid,
924 a->uri);
925 }
926 return &builder->pid;
927}
928
929
932 const struct GNUNET_PeerIdentity *pid,
933 void **block,
934 size_t *block_size,
935 struct GNUNET_TIME_Absolute *block_expiration)
936{
937 const struct DhtHelloMessage *msg
938 = (const struct DhtHelloMessage *) hello;
939 uint16_t len = ntohs (hello->size);
940 struct BlockHeader *bh;
941 struct GNUNET_HELLO_Builder *b;
943
944 if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO != ntohs (hello->type))
945 {
946 GNUNET_break (0);
947 return GNUNET_SYSERR;
948 }
949 if (len < sizeof (*msg))
950 {
951 GNUNET_break_op (0);
952 return GNUNET_SYSERR;
953 }
954 len -= sizeof (*msg);
955 *block_size = len + sizeof (*bh);
956 *block = GNUNET_malloc (*block_size);
957 bh = *block;
958 bh->pid = *pid;
959 bh->sig = msg->sig;
960 bh->expiration_time = msg->expiration_time;
961 *block_expiration = GNUNET_TIME_absolute_ntoh (msg->expiration_time);
962 memcpy (&bh[1],
963 &msg[1],
964 len);
966 *block_size);
967 if (NULL == b)
968 {
969 GNUNET_break_op (0);
970 GNUNET_free (*block);
971 *block_size = 0;
972 return GNUNET_SYSERR;
973 }
974 ret = verify_hello (b,
975 *block_expiration,
976 &msg->sig);
978 if (GNUNET_SYSERR == ret)
979 {
980 GNUNET_free (*block);
981 *block_size = 0;
982 return GNUNET_SYSERR;
983 }
984 return ret;
985}
986
987
995char *
997{
998 const char *dash;
999
1000 dash = strchr (address, '-');
1001 if (NULL == dash)
1002 return NULL;
1003 return GNUNET_strndup (address, dash - address);
1004}
1005
1006
1017void
1019 const char *address,
1021 struct GNUNET_TIME_Absolute mono_time,
1022 const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key,
1023 void **result,
1024 size_t *result_size)
1025{
1026 struct SignedAddress sa;
1028 char *sig_str;
1029
1031 sa.purpose.size = htonl (sizeof(sa));
1032 sa.mono_time = GNUNET_TIME_absolute_hton (mono_time);
1034 GNUNET_CRYPTO_eddsa_sign (private_key, &sa, &sig);
1035 sig_str = NULL;
1036 (void) GNUNET_STRINGS_base64_encode (&sig, sizeof(sig), &sig_str);
1037 *result_size =
1038 1 + GNUNET_asprintf ((char **) result,
1039 "%s;%llu;%u;%s",
1040 sig_str,
1041 (unsigned long long) mono_time.abs_value_us,
1042 (unsigned int) nt,
1043 address);
1044 GNUNET_free (sig_str);
1045}
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:99
static int ret
Final status code.
Definition: gnunet-arm.c:94
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
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 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
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:1018
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:373
const struct GNUNET_PeerIdentity * GNUNET_HELLO_builder_iterate(const struct GNUNET_HELLO_Builder *builder, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a builder.
Definition: hello-uri.c:909
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:931
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new(const struct GNUNET_PeerIdentity *pid)
Allocate builder.
Definition: hello-uri.c:355
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_block(const void *block, size_t block_size)
Parse block into builder.
Definition: hello-uri.c:414
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg into builder.
Definition: hello-uri.c:391
const struct GNUNET_PeerIdentity * GNUNET_HELLO_builder_get_id(const struct GNUNET_HELLO_Builder *builder)
Get the PeerIdentity for this builder.
Definition: hello-uri.c:366
struct GNUNET_TIME_Absolute GNUNET_HELLO_builder_get_expiration_time(const struct GNUNET_MessageHeader *msg)
Get the expiration time for this HELLO.
Definition: hello-uri.c:470
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:885
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:782
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_Builder * GNUNET_HELLO_builder_from_url(const char *url)
Parse GNUnet HELLO url into builder.
Definition: hello-uri.c:493
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:835
char * GNUNET_HELLO_builder_to_url(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Generate GNUnet HELLO URI from a builder.
Definition: hello-uri.c:717
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:996
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:666
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:631
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#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:366
#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:390
#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.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:350
#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:63
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:1877
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:764
size_t GNUNET_STRINGS_urldecode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1831
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:789
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1622
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_from_s(uint64_t s_after_epoch)
Convert seconds after the UNIX epoch to absolute time.
Definition: time.c:703
struct GNUNET_TIME_Timestamp GNUNET_TIME_relative_to_timestamp(struct GNUNET_TIME_Relative rel)
Convert relative time to a timestamp in the future.
Definition: time.c:335
uint64_t GNUNET_TIME_timestamp_to_s(struct GNUNET_TIME_Timestamp ts)
Convert timestamp to number of seconds after the UNIX epoch.
Definition: time.c:730
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
#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:638
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition: time.c:669
static void sign_hello(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_TIME_Timestamp et, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaSignature *sig)
Create HELLO signature.
Definition: hello-uri.c:295
static enum GNUNET_GenericReturnValue verify_hello(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_TIME_Absolute et, const struct GNUNET_CRYPTO_EddsaSignature *sig)
Verify HELLO signature.
Definition: hello-uri.c:327
static void hash_addresses(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
Compute hash over addresses in builder.
Definition: hello-uri.c:262
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 allready 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
A 512-bit hashcode.
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).
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.
Rounded time for timestamps used by GNUnet, in seconds.
struct GNUNET_TIME_Absolute abs_time
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
Binary block we sign when we sign an address.
Definition: hello-ng.c:37
struct GNUNET_HashCode addr_hash
Hash of the address.
Definition: hello-ng.c:51
struct GNUNET_TIME_AbsoluteNBO mono_time
When was the address generated.
Definition: hello-ng.c:46
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS.
Definition: hello-ng.c:41