GNUnet  0.18.1
Hello_Uri library

Helper library for handling HELLO URIs. More...

Collaboration diagram for Hello_Uri library:

Macros

#define GNUNET_HELLO_ADDRESS_EXPIRATION
 For how long are HELLO signatures valid? More...
 

Typedefs

typedef void(* GNUNET_HELLO_UriCallback) (void *cls, const char *uri)
 Callback function used to extract URIs from a builder. More...
 

Functions

struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_new (const struct GNUNET_PeerIdentity *pid)
 Allocate builder. More...
 
void GNUNET_HELLO_builder_free (struct GNUNET_HELLO_Builder *builder)
 Release resources of a builder. More...
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_from_msg (const struct GNUNET_MessageHeader *msg)
 Parse msg into builder. More...
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_from_block (const void *block, size_t block_size)
 Parse block into builder. More...
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_from_url (const char *url)
 Parse GNUnet HELLO url into builder. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_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. More...
 
struct GNUNET_MessageHeaderGNUNET_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. More...
 
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. More...
 
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. More...
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_add_address (struct GNUNET_HELLO_Builder *builder, const char *address)
 Add individual address to the builder. More...
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_del_address (struct GNUNET_HELLO_Builder *builder, const char *address)
 Remove individual address from the builder. More...
 
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. More...
 
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. More...
 

Detailed Description

Helper library for handling HELLO URIs.

Macro Definition Documentation

◆ GNUNET_HELLO_ADDRESS_EXPIRATION

#define GNUNET_HELLO_ADDRESS_EXPIRATION
Value:
#define GNUNET_TIME_UNIT_DAYS
One day.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:483

For how long are HELLO signatures valid?

Definition at line 58 of file gnunet_hello_uri_lib.h.

Typedef Documentation

◆ GNUNET_HELLO_UriCallback

typedef void(* GNUNET_HELLO_UriCallback) (void *cls, const char *uri)

Callback function used to extract URIs from a builder.

Parameters
clsclosure
urione of the URIs

Definition at line 200 of file gnunet_hello_uri_lib.h.

Function Documentation

◆ GNUNET_HELLO_builder_new()

struct GNUNET_HELLO_Builder* GNUNET_HELLO_builder_new ( const struct GNUNET_PeerIdentity pid)

Allocate builder.

Parameters
pidpeer the builder is for
Returns
new builder

Definition at line 308 of file hello-uri.c.

309 {
311 
313  builder->pid = *pid;
314  return builder;
315 }
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Context for building (or parsing) HELLO URIs.
Definition: hello-uri.c:184

References builder, GNUNET_new, and pid.

Referenced by GNUNET_HELLO_builder_from_block(), GNUNET_HELLO_builder_from_url(), and run().

Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_free()

void GNUNET_HELLO_builder_free ( struct GNUNET_HELLO_Builder builder)

Release resources of a builder.

Parameters
[in]builderto free

Definition at line 319 of file hello-uri.c.

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 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.
Address of a peer.
Definition: hello-uri.c:157

References builder, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, and GNUNET_free.

Referenced by GDS_NEIGHBOURS_handle_get(), GNUNET_HELLO_builder_from_block(), GNUNET_HELLO_builder_from_url(), handle_dht_local_hello_offer(), and shutdown_task().

Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_from_msg()

struct GNUNET_HELLO_Builder* GNUNET_HELLO_builder_from_msg ( const struct GNUNET_MessageHeader msg)

Parse msg into builder.

Parameters
msgmessage to parse
Returns
builder, NULL on failure

Definition at line 337 of file hello-uri.c.

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 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
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
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_MESSAGE_TYPE_HELLO_URI
Latest HELLO messages used for communicating peer addresses.
static unsigned int size
Size of the "table".
Definition: peer.c:67
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.
Message used when gossiping HELLOs between peers.
Definition: hello-uri.c:72

References GNUNET_break, GNUNET_break_op, GNUNET_HELLO_builder_from_block(), GNUNET_MESSAGE_TYPE_HELLO_URI, h, msg, GNUNET_MessageHeader::size, size, and GNUNET_MessageHeader::type.

Here is the call graph for this function:

◆ GNUNET_HELLO_builder_from_block()

struct GNUNET_HELLO_Builder* GNUNET_HELLO_builder_from_block ( const void *  block,
size_t  block_size 
)

Parse block into builder.

Parameters
blockDHT block to parse
block_sizenumber of bytes in block
Returns
builder, NULL on failure

Definition at line 360 of file hello-uri.c.

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 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static struct GNUNET_TRANSPORT_Blacklist * bh
The blacklist handle we obtain from transport when we register ourselves for access control.
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_builder_add_address(struct GNUNET_HELLO_Builder *builder, const char *address)
Add individual address to the builder.
Definition: hello-uri.c:748
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new(const struct GNUNET_PeerIdentity *pid)
Allocate builder.
Definition: hello-uri.c:308
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:97
@ GNUNET_OK
@ GNUNET_SYSERR
Definition: gnunet_common.h:98
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:736
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
Start of a 'block'.
Definition: hello-uri.c:96

References bh, end, GNUNET_break, GNUNET_break_op, GNUNET_HELLO_builder_add_address(), GNUNET_HELLO_builder_free(), GNUNET_HELLO_builder_new(), GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_ntoh(), ret, and verify_hello().

Referenced by GDS_NEIGHBOURS_handle_get(), and GNUNET_HELLO_builder_from_msg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_from_url()

struct GNUNET_HELLO_Builder* GNUNET_HELLO_builder_from_url ( const char *  url)

Parse GNUnet HELLO url into builder.

Parameters
urlURL to parse
Returns
builder, NULL on failure

Definition at line 416 of file hello-uri.c.

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 }
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 struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
size_t GNUNET_STRINGS_urldecode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1807
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
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:702
an ECC signature using EdDSA.
The identity of the host (wraps the signing key of the peer).
Time for absolute times used by GNUnet, in microseconds.

References dummy, GNUNET_asprintf(), GNUNET_break, GNUNET_break_op, GNUNET_free, GNUNET_HELLO_builder_add_address(), GNUNET_HELLO_builder_free(), GNUNET_HELLO_builder_new(), GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_STRINGS_urldecode(), GNUNET_SYSERR, GNUNET_TIME_absolute_from_s(), len, pid, q, ret, uri, and verify_hello().

Referenced by handle_dht_local_hello_offer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_to_env()

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.

Parameters
builderbuilder to serialize
privprivate key to use to sign the result
Returns
HELLO message matching builder

Definition at line 554 of file hello-uri.c.

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 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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
@ GNUNET_NO
Definition: gnunet_common.h:99
#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:57

References builder, env, GNUNET_assert, GNUNET_break, GNUNET_HELLO_builder_to_block(), GNUNET_MESSAGE_TYPE_HELLO_URI, GNUNET_MQ_msg_extra, GNUNET_NO, GNUNET_OK, and msg.

Here is the call graph for this function:

◆ GNUNET_HELLO_builder_to_dht_hello_msg()

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.

Parameters
builderbuilder to serialize
privprivate key to use to sign the result
Returns
HELLO message matching builder

Definition at line 586 of file hello-uri.c.

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 }
static char buf[2048]
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO
HELLO advertising a neighbours addresses.
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
Message used when a DHT provides its HELLO to direct neighbours.
Definition: hello-uri.c:120

References buf, builder, BlockHeader::expiration_time, GNUNET_ALIGN, GNUNET_assert, GNUNET_break, GNUNET_HELLO_builder_to_block(), GNUNET_malloc, GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO, GNUNET_NO, GNUNET_OK, msg, BlockHeader::sig, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by broadcast_hello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_to_url()

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.

Parameters
builderbuilder to serialize
privprivate key to use to sign the result
Returns
hello URI

Definition at line 634 of file hello-uri.c.

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 }
static int result
Global testing status.
#define GNUNET_HELLO_ADDRESS_EXPIRATION
For how long are HELLO signatures valid?
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_urlencode(const char *data, size_t len, char **out)
url/percent encode (RFC3986).
Definition: strings.c:1851
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:334
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:729
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
Rounded time for timestamps used by GNUnet, in seconds.

Referenced by check_dht_local_hello_offer().

Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_to_block()

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.

Parameters
builderthe builder to serialize
privprivate key to use to sign the result
[out]blockwhere to write the block, NULL to only calculate block_size
[in,out]block_sizeinput is number of bytes available in block, output is number of bytes needed in block
Returns
GNUNET_OK on success, GNUNET_NO if block_size was too small or if block was NULL

Definition at line 634 of file hello-uri.c.

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 }
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:637

Referenced by GNUNET_HELLO_builder_to_dht_hello_msg(), GNUNET_HELLO_builder_to_env(), and handle_find_my_hello().

Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_add_address()

enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_add_address ( struct GNUNET_HELLO_Builder builder,
const char *  address 
)

Add individual address to the builder.

Parameters
[in,out]builderto update
addressaddress URI to add
Returns
GNUNET_OK on success, GNUNET_NO if address was already in builder

Definition at line 634 of file hello-uri.c.

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 }
static struct Experiment * e
static char * address
GNS address for this phone.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:37
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR
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
const char * uri
Actual URI, allocated at the end of this struct.
Definition: hello-uri.c:171

References builder, GNUNET_asprintf(), GNUNET_break, GNUNET_free, GNUNET_HELLO_ADDRESS_EXPIRATION, GNUNET_STRINGS_data_to_string_alloc(), GNUNET_STRINGS_urlencode(), GNUNET_TIME_relative_to_timestamp(), GNUNET_TIME_timestamp_to_s(), result, and sign_hello().

Referenced by GNUNET_HELLO_builder_from_block(), GNUNET_HELLO_builder_from_url(), and u_address_add().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_del_address()

enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_del_address ( struct GNUNET_HELLO_Builder builder,
const char *  address 
)

Remove individual address from the builder.

Parameters
[in,out]builderto update
addressaddress URI to remove
Returns
GNUNET_OK on success, GNUNET_NO if address was not in builder

Definition at line 634 of file hello-uri.c.

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 }

Referenced by u_address_del().

Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_iterate()

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.

Parameters
builderbuilder to iterate over
[out]pidset to the peer the builder is for
uccallback invoked for each URI, can be NULL
uc_clsclosure for addrgen

Definition at line 822 of file hello-uri.c.

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 }
static struct GNUNET_FS_UnindexContext * uc

Referenced by GDS_NEIGHBOURS_handle_get(), and handle_dht_local_hello_offer().

Here is the caller graph for this function:

◆ GNUNET_HELLO_dht_msg_to_block()

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.

Parameters
hellothe HELLO message
pidpeer that created the hello
[out]blockset to the HELLO block
[out]block_sizeset to number of bytes in block
[out]block_expirationset to expiration time of block
Returns
GNUNET_OK on success, GNUNET_NO if the hello is expired (block is set!) GNUNET_SYSERR if hello is invalid (block will be set to NULL)

Definition at line 822 of file hello-uri.c.

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 }

Referenced by handle_dht_p2p_hello().

Here is the caller graph for this function: