GNUnet  0.11.x
Macros | Typedefs | Functions
Hello_Uri library

Helper library for handling HELLO URIs. More...

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 54 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 196 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 301 of file hello-uri.c.

302 {
304 
306  builder->pid = *pid;
307  return builder;
308 }
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 312 of file hello-uri.c.

313 {
314  struct Address *a;
315 
316  while (NULL != (a = builder->a_head))
317  {
319  builder->a_tail,
320  a);
321  builder->a_length--;
322  GNUNET_free (a);
323  }
324  GNUNET_assert (0 == builder->a_length);
326 }
#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 330 of file hello-uri.c.

331 {
332  const struct HelloUriMessage *h;
333  uint16_t size = ntohs (msg->size);
334 
335  if (GNUNET_MESSAGE_TYPE_HELLO_URI != ntohs (msg->type))
336  {
337  GNUNET_break (0);
338  return NULL;
339  }
340  if (sizeof (struct HelloUriMessage) > size)
341  {
342  GNUNET_break_op (0);
343  return NULL;
344  }
345  h = (const struct HelloUriMessage *) msg;
346  size -= sizeof (*h);
348  size);
349 }
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:353
#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 353 of file hello-uri.c.

355 {
356  const struct BlockHeader *bh = block;
357  struct GNUNET_HELLO_Builder *b;
358 
359  if (block_size < sizeof (*bh))
360  {
361  GNUNET_break_op (0);
362  return NULL;
363  }
364  b = GNUNET_HELLO_builder_new (&bh->pid);
365  block += sizeof (*bh);
366  block_size -= sizeof (*bh);
367  while (block_size > 0)
368  {
369  const void *end = memchr (block,
370  '\0',
371  block_size);
372 
373  if (NULL == end)
374  {
375  GNUNET_break_op (0);
377  return NULL;
378  }
379  if (GNUNET_OK !=
381  block))
382  {
383  GNUNET_break_op (0);
385  return NULL;
386  }
387  end++;
388  block_size -= (end - block);
389  block = end;
390  }
391  {
393 
394  ret = verify_hello (b,
395  GNUNET_TIME_absolute_ntoh (bh->expiration_time),
396  &bh->sig);
398  if (GNUNET_OK != ret)
399  {
401  return NULL;
402  }
403  }
404  return b;
405 }
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.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:312
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:741
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new(const struct GNUNET_PeerIdentity *pid)
Allocate builder.
Definition: hello-uri.c:301
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:273
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 409 of file hello-uri.c.

410 {
411  const char *q;
412  const char *s1;
413  const char *s2;
414  struct GNUNET_PeerIdentity pid;
415  struct GNUNET_CRYPTO_EddsaSignature sig;
416  struct GNUNET_TIME_Absolute et;
417  size_t len;
418  struct GNUNET_HELLO_Builder *b;
419 
420  if (0 != strncasecmp (url,
421  "gnunet://hello/",
422  strlen ("gnunet://hello/")))
423  return NULL;
424  url += strlen ("gnunet://hello/");
425  s1 = strchr (url, '/');
426  if (NULL == s1)
427  {
428  GNUNET_break_op (0);
429  return NULL;
430  }
431  s2 = strchr (s1 + 1, '/');
432  if (NULL == s1)
433  {
434  GNUNET_break_op (0);
435  return NULL;
436  }
437  q = strchr (url, '?');
438  if (NULL == q)
439  q = url + strlen (url);
440  if (GNUNET_OK !=
442  s1 - url,
443  &pid,
444  sizeof(pid)))
445  {
446  GNUNET_break_op (0);
447  return NULL;
448  }
449  if (GNUNET_OK !=
451  s2 - (s1 + 1),
452  &sig,
453  sizeof(sig)))
454  {
455  GNUNET_break_op (0);
456  return NULL;
457  }
458  {
459  unsigned long long sec;
460  char dummy = '?';
461 
462  if ( (0 == sscanf (s2 + 1,
463  "%llu%c",
464  &sec,
465  &dummy)) ||
466  ('?' != dummy) )
467  {
468  GNUNET_break_op (0);
469  return NULL;
470  }
471  et = GNUNET_TIME_absolute_from_s (sec);
472  }
473 
475  len = strlen (q);
476  while (len > 0)
477  {
478  const char *eq;
479  const char *amp;
480  char *addr = NULL;
481  char *uri;
482 
483  /* skip ?/& separator */
484  len--;
485  q++;
486  eq = strchr (q, '=');
487  if ( (eq == q) ||
488  (NULL == eq) )
489  {
490  GNUNET_break_op (0);
492  return NULL;
493  }
494  amp = strchr (eq, '&');
495  if (NULL == amp)
496  amp = &q[len];
497  GNUNET_STRINGS_urldecode (eq + 1,
498  amp - (eq + 1),
499  &addr);
500  if ( (NULL == addr) ||
501  (0 == strlen (addr)) )
502  {
503  GNUNET_free (addr);
504  GNUNET_break_op (0);
506  return NULL;
507  }
509  "%.*s://%s",
510  (int) (eq - q),
511  q,
512  addr);
513  GNUNET_free (addr);
514  if (GNUNET_OK !=
516  uri))
517  {
518  GNUNET_break_op (0);
519  GNUNET_free (uri);
521  return NULL;
522  }
523  GNUNET_free (uri);
524  /* move to next URL */
525  len -= (amp - q);
526  q = amp;
527  }
528 
529  {
531 
532  ret = verify_hello (b,
533  et,
534  &sig);
536  if (GNUNET_OK != ret)
537  {
539  return NULL;
540  }
541  }
542  return b;
543 }
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 547 of file hello-uri.c.

549 {
550  struct GNUNET_MQ_Envelope *env;
551  struct HelloUriMessage *msg;
552  size_t blen;
553 
554  if (builder->a_length > UINT16_MAX)
555  {
556  GNUNET_break (0);
557  return NULL;
558  }
559  blen = 0;
562  priv,
563  NULL,
564  &blen));
566  blen,
568  msg->url_counter = htonl ((uint16_t) builder->a_length);
571  priv,
572  &msg[1],
573  &blen));
574  return env;
575 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
@ GNUNET_NO
Definition: gnunet_common.h:94
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:692
#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:52

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 579 of file hello-uri.c.

582 {
583  struct DhtHelloMessage *msg;
584  size_t blen;
585 
586  if (builder->a_length > UINT16_MAX)
587  {
588  GNUNET_break (0);
589  return NULL;
590  }
591  blen = 0;
594  priv,
595  NULL,
596  &blen));
597  GNUNET_assert (blen < UINT16_MAX);
598  GNUNET_assert (blen >= sizeof (struct BlockHeader));
599  {
600  char buf[blen] GNUNET_ALIGN;
601  const struct BlockHeader *block = (const struct BlockHeader *) buf;
602 
605  priv,
606  buf,
607  &blen));
608  msg = GNUNET_malloc (sizeof (*msg)
609  + blen
610  - sizeof (*block));
611  msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO);
612  msg->header.size = htons (sizeof (*msg)
613  + blen
614  - sizeof (*block));
615  memcpy (&msg[1],
616  &block[1],
617  blen - sizeof (*block));
618  msg->sig = block->sig;
619  msg->expiration_time = block->expiration_time;
620  }
621  msg->url_counter = htonl ((uint16_t) builder->a_length);
622  return &msg->header;
623 }
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 627 of file hello-uri.c.

629 {
630  struct GNUNET_CRYPTO_EddsaSignature sig;
631  struct GNUNET_TIME_Timestamp et;
632  char *result;
633  char *pids;
634  char *sigs;
635  const char *sep = "?";
636 
639  et,
640  priv,
641  &sig);
643  sizeof (builder->pid));
645  sizeof (sig));
647  "gnunet://hello/%s/%s/%llu",
648  pids,
649  sigs,
650  (unsigned long long) GNUNET_TIME_timestamp_to_s (et));
651  GNUNET_free (sigs);
652  GNUNET_free (pids);
653  for (struct Address *a = builder->a_head;
654  NULL != a;
655  a = a->next)
656  {
657  char *ue;
658  char *tmp;
659  int pfx_len;
660  const char *eou;
661 
662  eou = strstr (a->uri,
663  "://");
664  if (NULL == eou)
665  {
666  GNUNET_break (0);
668  return NULL;
669  }
670  pfx_len = eou - a->uri;
671  eou += 3;
673  a->uri_len - 4 - pfx_len,
674  &ue);
675  GNUNET_asprintf (&tmp,
676  "%s%s%.*s=%s",
677  result,
678  sep,
679  pfx_len,
680  a->uri,
681  ue);
682  GNUNET_free (ue);
684  result = tmp;
685  sep = "&";
686  }
687  return result;
688 }
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:244
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 627 of file hello-uri.c.

696 {
697  struct BlockHeader bh;
698  size_t needed = sizeof (bh);
699  char *pos;
700  struct GNUNET_TIME_Timestamp et;
701 
702  for (struct Address *a = builder->a_head;
703  NULL != a;
704  a = a->next)
705  {
706  GNUNET_assert (needed + a->uri_len > needed);
707  needed += a->uri_len;
708  }
709  if ( (NULL == block) ||
710  (needed < *block_size) )
711  {
712  *block_size = needed;
713  return GNUNET_NO;
714  }
715  bh.pid = builder->pid;
717  bh.expiration_time = GNUNET_TIME_absolute_hton (et.abs_time);
719  et,
720  priv,
721  &bh.sig);
722  memcpy (block,
723  &bh,
724  sizeof (bh));
725  pos = block + sizeof (bh);
726  for (struct Address *a = builder->a_head;
727  NULL != a;
728  a = a->next)
729  {
730  memcpy (pos,
731  a->uri,
732  a->uri_len);
733  pos += a->uri_len;
734  }
735  *block_size = needed;
736  return GNUNET_OK;
737 }
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 627 of file hello-uri.c.

743 {
744  size_t alen = strlen (address) + 1;
745  struct Address *a;
746  const char *e;
747 
748  if (NULL == (e = strstr (address,
749  "://")))
750  {
751  GNUNET_break_op (0);
753  "Invalid address `%s'\n",
754  address);
755  return GNUNET_SYSERR;
756  }
757  if (e == address)
758  {
759  GNUNET_break_op (0);
760  return GNUNET_SYSERR;
761  }
762  for (const char *p = address; p != e; p++)
763  if ( (! isalpha ((unsigned char) *p)) &&
764  ('+' != *p) )
765  {
766  GNUNET_break_op (0);
767  return GNUNET_SYSERR;
768  }
769  /* check for duplicates */
770  for (a = builder->a_head;
771  NULL != a;
772  a = a->next)
773  if (0 == strcmp (address,
774  a->uri))
775  return GNUNET_NO;
776  a = GNUNET_malloc (sizeof (struct Address) + alen);
777  a->uri_len = alen;
778  memcpy (&a[1],
779  address,
780  alen);
781  a->uri = (const char *) &a[1];
783  builder->a_tail,
784  a);
785  builder->a_length++;
786  return GNUNET_OK;
787 }
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_log(kind,...)
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
@ 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 627 of file hello-uri.c.

793 {
794  struct Address *a;
795 
796  /* check for duplicates */
797  for (a = builder->a_head;
798  NULL != a;
799  a = a->next)
800  if (0 == strcmp (address,
801  a->uri))
802  break;
803  if (NULL == a)
804  return GNUNET_NO;
806  builder->a_tail,
807  a);
808  builder->a_length--;
809  GNUNET_free (a);
810  return GNUNET_OK;
811 }

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 815 of file hello-uri.c.

819 {
820  struct Address *nxt;
821 
822  *pid = builder->pid;
823  if (NULL == uc)
824  return;
825  for (struct Address *a = builder->a_head;
826  NULL != a;
827  a = nxt)
828  {
829  nxt = a->next;
830  uc (uc_cls,
831  a->uri);
832  }
833 }
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 815 of file hello-uri.c.

842 {
843  const struct DhtHelloMessage *msg
844  = (const struct DhtHelloMessage *) hello;
845  uint16_t len = ntohs (hello->size);
846  struct BlockHeader *bh;
847  struct GNUNET_HELLO_Builder *b;
849 
850  if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO != ntohs (hello->type))
851  {
852  GNUNET_break (0);
853  return GNUNET_SYSERR;
854  }
855  if (len < sizeof (*msg))
856  {
857  GNUNET_break_op (0);
858  return GNUNET_SYSERR;
859  }
860  len -= sizeof (*msg);
861  *block_size = len + sizeof (*bh);
862  *block = GNUNET_malloc (*block_size);
863  bh = *block;
864  bh->pid = *pid;
865  bh->sig = msg->sig;
866  bh->expiration_time = msg->expiration_time;
867  *block_expiration = GNUNET_TIME_absolute_ntoh (msg->expiration_time);
868  memcpy (&bh[1],
869  &msg[1],
870  len);
872  *block_size);
873  if (NULL == b)
874  {
875  GNUNET_break_op (0);
876  GNUNET_free (*block);
877  *block_size = 0;
878  return GNUNET_SYSERR;
879  }
880  ret = verify_hello (b,
881  *block_expiration,
882  &msg->sig);
884  if (GNUNET_SYSERR == ret)
885  {
886  GNUNET_free (*block);
887  *block_size = 0;
888  return GNUNET_SYSERR;
889  }
890  return ret;
891 }

Referenced by handle_dht_p2p_hello().

Here is the caller graph for this function: