GNUnet  0.20.0
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"
39 #include "gnunet_hello_uri_lib.h"
40 #include "gnunet_protocols.h"
41 #include "gnunet_util_lib.h"
42 
43 
45 
50 {
55 
60 
64  struct GNUNET_HashCode h_addrs;
65 
66 };
67 
72 {
77 
82 
87 
88  /* followed by a 'block' */
89 };
90 
91 
96 {
100  struct GNUNET_PeerIdentity pid;
101 
106 
111 
112 };
113 
114 
120 {
125 
130 
135 
140 
145 
146  /* followed by the serialized addresses of the 'block' */
147 };
148 
149 
151 
152 
156 struct Address
157 {
161  struct Address *next;
162 
166  struct Address *prev;
167 
171  const char *uri;
172 
176  size_t uri_len;
177 };
178 
179 
184 {
188  struct GNUNET_PeerIdentity pid;
189 
193  struct Address *a_head;
194 
198  struct Address *a_tail;
199 
203  unsigned int a_length;
204 
205 };
206 
207 
214 static void
216  struct GNUNET_HashCode *hash)
217 {
218  struct GNUNET_HashContext *hc;
219 
221  for (struct Address *a = builder->a_head;
222  NULL != a;
223  a = a->next)
224  {
226  "Hashing over %.*s\n",
227  (int) a->uri_len,
228  a->uri);
230  a->uri,
231  a->uri_len);
232  }
234  hash);
235 
236 }
237 
238 
247 static void
249  struct GNUNET_TIME_Timestamp et,
250  const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
251  struct GNUNET_CRYPTO_EddsaSignature *sig)
252 {
253  struct HelloSignaturePurpose hsp = {
254  .purpose.size = htonl (sizeof (hsp)),
255  .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
256  .expiration_time = GNUNET_TIME_absolute_hton (et.abs_time)
257  };
258 
260  &hsp.h_addrs);
262  "Address hash is %s\n",
263  GNUNET_h2s_full (&hsp.h_addrs));
265  &hsp,
266  sig);
267 }
268 
269 
279 static enum GNUNET_GenericReturnValue
281  struct GNUNET_TIME_Absolute et,
282  const struct GNUNET_CRYPTO_EddsaSignature *sig)
283 {
284  struct HelloSignaturePurpose hsp = {
285  .purpose.size = htonl (sizeof (hsp)),
286  .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
287  .expiration_time = GNUNET_TIME_absolute_hton (et)
288  };
289 
291  &hsp.h_addrs);
292  if (GNUNET_OK !=
294  &hsp,
295  sig,
296  &builder->pid.public_key))
297  {
298  GNUNET_break_op (0);
299  return GNUNET_SYSERR;
300  }
302  return GNUNET_NO;
303  return GNUNET_OK;
304 }
305 
306 
307 struct GNUNET_HELLO_Builder *
309 {
311 
313  builder->pid = *pid;
314  return builder;
315 }
316 
317 
318 void
320 {
321  struct Address *a;
322 
323  while (NULL != (a = builder->a_head))
324  {
326  builder->a_tail,
327  a);
328  builder->a_length--;
329  GNUNET_free (a);
330  }
331  GNUNET_assert (0 == builder->a_length);
333 }
334 
335 
336 struct GNUNET_HELLO_Builder *
338 {
339  const struct HelloUriMessage *h;
340  uint16_t size = ntohs (msg->size);
341 
342  if (GNUNET_MESSAGE_TYPE_HELLO_URI != ntohs (msg->type))
343  {
344  GNUNET_break (0);
345  return NULL;
346  }
347  if (sizeof (struct HelloUriMessage) > size)
348  {
349  GNUNET_break_op (0);
350  return NULL;
351  }
352  h = (const struct HelloUriMessage *) msg;
353  size -= sizeof (*h);
355  size);
356 }
357 
358 
359 struct GNUNET_HELLO_Builder *
361  size_t block_size)
362 {
363  const struct BlockHeader *bh = block;
364  struct GNUNET_HELLO_Builder *b;
365 
366  if (block_size < sizeof (*bh))
367  {
368  GNUNET_break_op (0);
369  return NULL;
370  }
371  b = GNUNET_HELLO_builder_new (&bh->pid);
372  block += sizeof (*bh);
373  block_size -= sizeof (*bh);
374  while (block_size > 0)
375  {
376  const void *end = memchr (block,
377  '\0',
378  block_size);
379 
380  if (NULL == end)
381  {
382  GNUNET_break_op (0);
384  return NULL;
385  }
386  if (GNUNET_OK !=
388  block))
389  {
390  GNUNET_break_op (0);
392  return NULL;
393  }
394  end++;
395  block_size -= (end - block);
396  block = end;
397  }
398  {
400 
401  ret = verify_hello (b,
402  GNUNET_TIME_absolute_ntoh (bh->expiration_time),
403  &bh->sig);
405  if (GNUNET_OK != ret)
406  {
408  return NULL;
409  }
410  }
411  return b;
412 }
413 
414 
415 struct GNUNET_HELLO_Builder *
417 {
418  const char *q;
419  const char *s1;
420  const char *s2;
421  struct GNUNET_PeerIdentity pid;
422  struct GNUNET_CRYPTO_EddsaSignature sig;
423  struct GNUNET_TIME_Absolute et;
424  size_t len;
425  struct GNUNET_HELLO_Builder *b;
426 
427  if (0 != strncasecmp (url,
428  "gnunet://hello/",
429  strlen ("gnunet://hello/")))
430  return NULL;
431  url += strlen ("gnunet://hello/");
432  s1 = strchr (url, '/');
433  if (NULL == s1)
434  {
435  GNUNET_break_op (0);
436  return NULL;
437  }
438  s2 = strchr (s1 + 1, '/');
439  if (NULL == s1)
440  {
441  GNUNET_break_op (0);
442  return NULL;
443  }
444  q = strchr (url, '?');
445  if (NULL == q)
446  q = url + strlen (url);
447  if (GNUNET_OK !=
449  s1 - url,
450  &pid,
451  sizeof(pid)))
452  {
453  GNUNET_break_op (0);
454  return NULL;
455  }
456  if (GNUNET_OK !=
458  s2 - (s1 + 1),
459  &sig,
460  sizeof(sig)))
461  {
462  GNUNET_break_op (0);
463  return NULL;
464  }
465  {
466  unsigned long long sec;
467  char dummy = '?';
468 
469  if ( (0 == sscanf (s2 + 1,
470  "%llu%c",
471  &sec,
472  &dummy)) ||
473  ('?' != dummy) )
474  {
475  GNUNET_break_op (0);
476  return NULL;
477  }
478  et = GNUNET_TIME_absolute_from_s (sec);
479  }
480 
482  len = strlen (q);
483  while (len > 0)
484  {
485  const char *eq;
486  const char *amp;
487  char *addr = NULL;
488  char *uri;
489 
490  /* skip ?/& separator */
491  len--;
492  q++;
493  eq = strchr (q, '=');
494  if ( (eq == q) ||
495  (NULL == eq) )
496  {
497  GNUNET_break_op (0);
499  return NULL;
500  }
501  amp = strchr (eq, '&');
502  if (NULL == amp)
503  amp = &q[len];
504  GNUNET_STRINGS_urldecode (eq + 1,
505  amp - (eq + 1),
506  &addr);
507  if ( (NULL == addr) ||
508  (0 == strlen (addr)) )
509  {
510  GNUNET_free (addr);
511  GNUNET_break_op (0);
513  return NULL;
514  }
516  "%.*s://%s",
517  (int) (eq - q),
518  q,
519  addr);
520  GNUNET_free (addr);
521  if (GNUNET_OK !=
523  uri))
524  {
525  GNUNET_break_op (0);
526  GNUNET_free (uri);
528  return NULL;
529  }
530  GNUNET_free (uri);
531  /* move to next URL */
532  len -= (amp - q);
533  q = amp;
534  }
535 
536  {
538 
539  ret = verify_hello (b,
540  et,
541  &sig);
543  if (GNUNET_OK != ret)
544  {
546  return NULL;
547  }
548  }
549  return b;
550 }
551 
552 
553 struct GNUNET_MQ_Envelope *
555  const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
556 {
557  struct GNUNET_MQ_Envelope *env;
558  struct HelloUriMessage *msg;
559  size_t blen;
560 
561  if (builder->a_length > UINT16_MAX)
562  {
563  GNUNET_break (0);
564  return NULL;
565  }
566  blen = 0;
569  priv,
570  NULL,
571  &blen));
573  blen,
575  msg->url_counter = htons ((uint16_t) builder->a_length);
578  priv,
579  &msg[1],
580  &blen));
581  return env;
582 }
583 
584 
585 struct GNUNET_MessageHeader *
587  const struct GNUNET_HELLO_Builder *builder,
588  const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
589 {
590  struct DhtHelloMessage *msg;
591  size_t blen;
592 
593  if (builder->a_length > UINT16_MAX)
594  {
595  GNUNET_break (0);
596  return NULL;
597  }
598  blen = 0;
601  priv,
602  NULL,
603  &blen));
604  GNUNET_assert (blen < UINT16_MAX);
605  GNUNET_assert (blen >= sizeof (struct BlockHeader));
606  {
607  char buf[blen] GNUNET_ALIGN;
608  const struct BlockHeader *block = (const struct BlockHeader *) buf;
609 
612  priv,
613  buf,
614  &blen));
615  msg = GNUNET_malloc (sizeof (*msg)
616  + blen
617  - sizeof (*block));
618  msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO);
619  msg->header.size = htons (sizeof (*msg)
620  + blen
621  - sizeof (*block));
622  memcpy (&msg[1],
623  &block[1],
624  blen - sizeof (*block));
625  msg->sig = block->sig;
626  msg->expiration_time = block->expiration_time;
627  }
628  msg->url_counter = htons ((uint16_t) builder->a_length);
629  return &msg->header;
630 }
631 
632 
633 char *
635  const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
636 {
637  struct GNUNET_CRYPTO_EddsaSignature sig;
638  struct GNUNET_TIME_Timestamp et;
639  char *result;
640  char *pids;
641  char *sigs;
642  const char *sep = "?";
643 
646  et,
647  priv,
648  &sig);
650  sizeof (builder->pid));
652  sizeof (sig));
654  "gnunet://hello/%s/%s/%llu",
655  pids,
656  sigs,
657  (unsigned long long) GNUNET_TIME_timestamp_to_s (et));
658  GNUNET_free (sigs);
659  GNUNET_free (pids);
660  for (struct Address *a = builder->a_head;
661  NULL != a;
662  a = a->next)
663  {
664  char *ue;
665  char *tmp;
666  int pfx_len;
667  const char *eou;
668 
669  eou = strstr (a->uri,
670  "://");
671  if (NULL == eou)
672  {
673  GNUNET_break (0);
675  return NULL;
676  }
677  pfx_len = eou - a->uri;
678  eou += 3;
680  a->uri_len - 4 - pfx_len,
681  &ue);
682  GNUNET_asprintf (&tmp,
683  "%s%s%.*s=%s",
684  result,
685  sep,
686  pfx_len,
687  a->uri,
688  ue);
689  GNUNET_free (ue);
691  result = tmp;
692  sep = "&";
693  }
694  return result;
695 }
696 
697 
700  const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
701  void *block,
702  size_t *block_size)
703 {
704  struct BlockHeader bh;
705  size_t needed = sizeof (bh);
706  char *pos;
707  struct GNUNET_TIME_Timestamp et;
708 
709  for (struct Address *a = builder->a_head;
710  NULL != a;
711  a = a->next)
712  {
713  GNUNET_assert (needed + a->uri_len > needed);
714  needed += a->uri_len;
715  }
716  if ( (NULL == block) ||
717  (needed < *block_size) )
718  {
719  *block_size = needed;
720  return GNUNET_NO;
721  }
722  bh.pid = builder->pid;
724  bh.expiration_time = GNUNET_TIME_absolute_hton (et.abs_time);
726  et,
727  priv,
728  &bh.sig);
729  memcpy (block,
730  &bh,
731  sizeof (bh));
732  pos = block + sizeof (bh);
733  for (struct Address *a = builder->a_head;
734  NULL != a;
735  a = a->next)
736  {
737  memcpy (pos,
738  a->uri,
739  a->uri_len);
740  pos += a->uri_len;
741  }
742  *block_size = needed;
743  return GNUNET_OK;
744 }
745 
746 
749  const char *address)
750 {
751  size_t alen = strlen (address) + 1;
752  struct Address *a;
753  const char *e;
754 
755  if (NULL == (e = strstr (address,
756  "://")))
757  {
758  GNUNET_break_op (0);
760  "Invalid address `%s'\n",
761  address);
762  return GNUNET_SYSERR;
763  }
764  if (e == address)
765  {
766  GNUNET_break_op (0);
767  return GNUNET_SYSERR;
768  }
769  for (const char *p = address; p != e; p++)
770  if ( (! isalpha ((unsigned char) *p)) &&
771  ('+' != *p) )
772  {
773  GNUNET_break_op (0);
774  return GNUNET_SYSERR;
775  }
776  /* check for duplicates */
777  for (a = builder->a_head;
778  NULL != a;
779  a = a->next)
780  if (0 == strcmp (address,
781  a->uri))
782  return GNUNET_NO;
783  a = GNUNET_malloc (sizeof (struct Address) + alen);
784  a->uri_len = alen;
785  memcpy (&a[1],
786  address,
787  alen);
788  a->uri = (const char *) &a[1];
790  builder->a_tail,
791  a);
792  builder->a_length++;
793  return GNUNET_OK;
794 }
795 
796 
799  const char *address)
800 {
801  struct Address *a;
802 
803  /* check for duplicates */
804  for (a = builder->a_head;
805  NULL != a;
806  a = a->next)
807  if (0 == strcmp (address,
808  a->uri))
809  break;
810  if (NULL == a)
811  return GNUNET_NO;
813  builder->a_tail,
814  a);
815  builder->a_length--;
816  GNUNET_free (a);
817  return GNUNET_OK;
818 }
819 
820 
821 void
823  struct GNUNET_PeerIdentity *pid,
825  void *uc_cls)
826 {
827  struct Address *nxt;
828 
829  *pid = builder->pid;
830  if (NULL == uc)
831  return;
832  for (struct Address *a = builder->a_head;
833  NULL != a;
834  a = nxt)
835  {
836  nxt = a->next;
837  uc (uc_cls,
838  a->uri);
839  }
840 }
841 
842 
845  const struct GNUNET_PeerIdentity *pid,
846  void **block,
847  size_t *block_size,
848  struct GNUNET_TIME_Absolute *block_expiration)
849 {
850  const struct DhtHelloMessage *msg
851  = (const struct DhtHelloMessage *) hello;
852  uint16_t len = ntohs (hello->size);
853  struct BlockHeader *bh;
854  struct GNUNET_HELLO_Builder *b;
856 
857  if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO != ntohs (hello->type))
858  {
859  GNUNET_break (0);
860  return GNUNET_SYSERR;
861  }
862  if (len < sizeof (*msg))
863  {
864  GNUNET_break_op (0);
865  return GNUNET_SYSERR;
866  }
867  len -= sizeof (*msg);
868  *block_size = len + sizeof (*bh);
869  *block = GNUNET_malloc (*block_size);
870  bh = *block;
871  bh->pid = *pid;
872  bh->sig = msg->sig;
873  bh->expiration_time = msg->expiration_time;
874  *block_expiration = GNUNET_TIME_absolute_ntoh (msg->expiration_time);
875  memcpy (&bh[1],
876  &msg[1],
877  len);
879  *block_size);
880  if (NULL == b)
881  {
882  GNUNET_break_op (0);
883  GNUNET_free (*block);
884  *block_size = 0;
885  return GNUNET_SYSERR;
886  }
887  ret = verify_hello (b,
888  *block_expiration,
889  &msg->sig);
891  if (GNUNET_SYSERR == ret)
892  {
893  GNUNET_free (*block);
894  *block_size = 0;
895  return GNUNET_SYSERR;
896  }
897  return ret;
898 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static struct Experiment * e
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_TRANSPORT_Blacklist * bh
The blacklist handle we obtain from transport when we register ourselves for access control.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 char buf[2048]
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.
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_block(const void *block, size_t block_size)
Parse block into builder.
Definition: hello-uri.c:360
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:319
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:844
struct GNUNET_MessageHeader * GNUNET_HELLO_builder_to_dht_hello_msg(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Generate DHT HELLO message (without peer ID) from a builder.
Definition: hello-uri.c:586
void GNUNET_HELLO_builder_iterate(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_PeerIdentity *pid, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a builder.
Definition: hello-uri.c:822
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:798
#define GNUNET_HELLO_ADDRESS_EXPIRATION
For how long are HELLO signatures valid?
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg into builder.
Definition: hello-uri.c:337
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:748
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)
Generate DHT block from a builder.
Definition: hello-uri.c:699
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new(const struct GNUNET_PeerIdentity *pid)
Allocate builder.
Definition: hello-uri.c:308
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_url(const char *url)
Parse GNUnet HELLO url into builder.
Definition: hello-uri.c:416
void(* GNUNET_HELLO_UriCallback)(void *cls, const char *uri)
Callback function used to extract URIs from a builder.
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:634
struct GNUNET_MQ_Envelope * GNUNET_HELLO_builder_to_env(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Generate envelope with GNUnet HELLO message (including peer ID) from a builder.
Definition: hello-uri.c:554
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#define GNUNET_log(kind,...)
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
Definition: crypto_hash.c:350
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.
#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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#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_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
#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_urldecode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1806
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:763
size_t GNUNET_STRINGS_urlencode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1850
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:788
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
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:248
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:280
static void hash_addresses(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
Compute hash over addresses in builder.
Definition: hello-uri.c:215
static unsigned int size
Size of the "table".
Definition: peer.c:68
Address of a peer.
Definition: hello-uri.c:157
struct Address * next
Kept in a DLL.
Definition: hello-uri.c:161
size_t uri_len
Length of uri including 0-terminator.
Definition: hello-uri.c:176
struct Address * prev
Kept in a DLL.
Definition: hello-uri.c:166
const char * uri
Actual URI, allocated at the end of this struct.
Definition: hello-uri.c:171
Start of a 'block'.
Definition: hello-uri.c:96
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the HELLO expire?
Definition: hello-uri.c:110
struct GNUNET_CRYPTO_EddsaSignature sig
Signature over the block, of purpose GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition: hello-uri.c:105
struct GNUNET_PeerIdentity pid
Public key of the peer.
Definition: hello-uri.c:100
Message used when a DHT provides its HELLO to direct neighbours.
Definition: hello-uri.c:120
uint16_t reserved
Reserved.
Definition: hello-uri.c:129
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the HELLO expire?
Definition: hello-uri.c:144
struct GNUNET_MessageHeader header
Type must be GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO.
Definition: hello-uri.c:124
struct GNUNET_CRYPTO_EddsaSignature sig
Signature over the block, of purpose GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition: hello-uri.c:139
uint16_t url_counter
Number of URLs encoded after the end of the struct, in NBO.
Definition: hello-uri.c:134
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 (!...
Private ECC key encoded for transmission.
an ECC signature using EdDSA.
Context for building (or parsing) HELLO URIs.
Definition: hello-uri.c:184
struct GNUNET_PeerIdentity pid
Public key of the peer.
Definition: hello-uri.c:188
struct Address * a_tail
Tail of the addresses DLL.
Definition: hello-uri.c:198
struct Address * a_head
Head of the addresses DLL.
Definition: hello-uri.c:193
unsigned int a_length
Length of the a_head DLL.
Definition: hello-uri.c:203
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.
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:50
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition: hello-uri.c:54
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the signature expire?
Definition: hello-uri.c:59
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Definition: hello-uri.c:64
Message used when gossiping HELLOs between peers.
Definition: hello-uri.c:72
uint16_t reserved
Reserved.
Definition: hello-uri.c:81
uint16_t url_counter
Number of URLs encoded after the end of the struct, in NBO.
Definition: hello-uri.c:86
struct GNUNET_MessageHeader header
Type must be GNUNET_MESSAGE_TYPE_HELLO_URI.
Definition: hello-uri.c:76