GNUnet 0.21.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 struct GNUNET_PeerIdentity *pid, 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...
 
const struct GNUNET_PeerIdentityGNUNET_HELLO_builder_get_id (const struct GNUNET_HELLO_Builder *builder)
 Get the PeerIdentity for this 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_TIME_Absolute GNUNET_HELLO_builder_get_expiration_time (const struct GNUNET_MessageHeader *msg)
 Get the expiration time for this HELLO. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_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. More...
 
struct GNUNET_MessageHeaderGNUNET_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. 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, struct GNUNET_TIME_Relative expiration_time)
 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...
 
const struct GNUNET_PeerIdentityGNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder, 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...
 
char * GNUNET_HELLO_address_to_prefix (const char *address)
 Given an address as a string, extract the prefix that identifies the communicator offering transmissions to that address. More...
 
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. 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:484

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 struct GNUNET_PeerIdentity *pid, const char *uri)

Callback function used to extract URIs from a builder.

Parameters
clsclosure
urione of the URIs

Definition at line 221 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 355 of file hello-uri.c.

356{
358
360 builder->pid = *pid;
361 return builder;
362}
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:205

References builder, GNUNET_new, and pid.

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

Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_get_id()

const struct GNUNET_PeerIdentity * GNUNET_HELLO_builder_get_id ( const struct GNUNET_HELLO_Builder builder)

Get the PeerIdentity for this builder.

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

367{
368 return &builder->pid;
369}

References builder.

Referenced by check_hello(), GNUNET_PEERSTORE_hello_add(), and hosts_directory_scan_callback().

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

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}
#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:178

References builder, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, and GNUNET_free.

Referenced by block_plugin_dht_check_block(), block_plugin_dht_check_reply(), block_plugin_dht_get_key(), check_for_global_natted(), consider_for_advertising(), dht_get_id_handler(), do_shutdown(), GCH_get_mine(), GNUNET_HELLO_builder_from_block(), GNUNET_HELLO_builder_from_url(), GNUNET_HELLO_dht_msg_to_block(), GNUNET_PEERSTORE_hello_add(), got_hello(), handle_dht_local_hello_offer(), handle_hello(), handle_hello_for_client(), handle_hello_for_incoming(), hello_check(), hosts_directory_scan_callback(), peerinfo_cb(), run(), 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 391 of file hello-uri.c.

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}
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:414
#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:68
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:93

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.

Referenced by check_for_global_natted(), check_hello(), consider_for_advertising(), dht_get_id_handler(), GNUNET_PEERSTORE_hello_add(), got_hello(), handle_hello(), handle_hello_for_client(), handle_hello_for_incoming(), hosts_directory_scan_callback(), and peerinfo_cb().

Here is the call graph for this function:
Here is the caller 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 414 of file hello-uri.c.

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}
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
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:373
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new(const struct GNUNET_PeerIdentity *pid)
Allocate builder.
Definition: hello-uri.c:355
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
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_SYSERR
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
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
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

References end, BlockHeader::expiration_time, 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(), BlockHeader::pid, ret, BlockHeader::sig, and verify_hello().

Referenced by block_plugin_dht_check_block(), block_plugin_dht_check_reply(), block_plugin_dht_get_key(), GNUNET_HELLO_builder_from_msg(), GNUNET_HELLO_dht_msg_to_block(), and hello_check().

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

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}
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
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: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
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
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(), 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_get_expiration_time()

struct GNUNET_TIME_Absolute GNUNET_HELLO_builder_get_expiration_time ( const struct GNUNET_MessageHeader msg)

Get the expiration time for this HELLO.

Parameters
msgThe hello msg.
Returns
The expiration time.

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

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}
#define GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO
HELLO advertising a neighbours addresses.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
Message used when a DHT provides its HELLO to direct neighbours.
Definition: hello-uri.c:141
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the HELLO expire?
Definition: hello-uri.c:165

References BlockHeader::expiration_time, DhtHelloMessage::expiration_time, GNUNET_break, GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO, GNUNET_MESSAGE_TYPE_HELLO_URI, GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_ZERO_ABS, h, msg, and GNUNET_MessageHeader::type.

Referenced by announce_id(), consider_for_advertising(), consider_peer_destroy(), GCP_set_hello(), GNUNET_PEERSTORE_hello_add(), got_hello(), and hello_add_iter().

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,
struct GNUNET_TIME_Relative  expiration_time 
)

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

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}
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, struct GNUNET_TIME_Relative expiration_time)
Generate DHT block from a builder.
Definition: hello-uri.c:782
@ GNUNET_NO
#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

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.

Referenced by run(), and store_pi().

Here is the call graph for this function:
Here is the caller 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,
struct GNUNET_TIME_Relative  expiration_time 
)

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

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}
#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.

References builder, BlockHeader::expiration_time, DhtHelloMessage::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(), GCH_get_mine(), and got_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 717 of file hello-uri.c.

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}
static int result
Global testing status.
#define GNUNET_HELLO_ADDRESS_EXPIRATION
For how long are HELLO signatures valid?
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
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
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
Rounded time for timestamps used by GNUnet, in seconds.

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 handle_dht_local_hello_get(), and run().

Here is the call graph for this function:
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,
struct GNUNET_TIME_Relative  expiration_time 
)

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

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);
811 bh.expiration_time = GNUNET_TIME_absolute_hton (et.abs_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}
#define GNUNET_TIME_UNIT_ZERO
Relative 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
uint64_t rel_value_us
The actual value.

References GNUNET_TIME_Timestamp::abs_time, builder, BlockHeader::expiration_time, GNUNET_assert, GNUNET_HELLO_ADDRESS_EXPIRATION, GNUNET_NO, GNUNET_OK, GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_to_timestamp(), GNUNET_TIME_UNIT_ZERO, BlockHeader::pid, GNUNET_TIME_Relative::rel_value_us, BlockHeader::sig, and sign_hello().

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

Here is the call graph for this function:
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 835 of file hello-uri.c.

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}
static char * address
GNS address for this phone.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
#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:182
size_t uri_len
Length of uri including 0-terminator.
Definition: hello-uri.c:197
const char * uri
Actual URI, allocated at the end of this struct.
Definition: hello-uri.c:192

References address, builder, GNUNET_break_op, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, Address::next, p, Address::uri, and Address::uri_len.

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

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

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}

References address, builder, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NO, GNUNET_OK, Address::next, and Address::uri.

Referenced by u_address_del().

Here is the caller graph for this function:

◆ GNUNET_HELLO_builder_iterate()

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.

Parameters
builderbuilder to iterate over
uccallback invoked for each URI, can be NULL
uc_clsclosure for addrgen
Returns
pid of the peer the builder is for, can be NULL

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

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

References builder, Address::next, and uc.

Referenced by block_plugin_dht_check_block(), block_plugin_dht_check_reply(), block_plugin_dht_get_key(), check_for_global_natted(), consider_for_advertising(), handle_dht_local_hello_offer(), handle_hello_for_client(), handle_hello_for_incoming(), hello_check(), and peerinfo_cb().

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

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}

References BlockHeader::expiration_time, GNUNET_break, GNUNET_break_op, GNUNET_free, GNUNET_HELLO_builder_free(), GNUNET_HELLO_builder_from_block(), GNUNET_malloc, GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO, GNUNET_SYSERR, GNUNET_TIME_absolute_ntoh(), msg, BlockHeader::pid, pid, ret, BlockHeader::sig, GNUNET_MessageHeader::size, GNUNET_MessageHeader::type, and verify_hello().

Referenced by announce_id(), check_dht_p2p_hello(), and handle_dht_p2p_hello().

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

◆ GNUNET_HELLO_address_to_prefix()

char * GNUNET_HELLO_address_to_prefix ( const char *  address)

Given an address as a string, extract the prefix that identifies the communicator offering transmissions to that address.

Parameters
addressa peer's address
Returns
NULL if the address is mal-formed, otherwise the prefix

Definition at line 190 of file hello-ng.c.

191{
192 const char *dash;
193
194 dash = strchr (address, '-');
195 if (NULL == dash)
196 return NULL;
197 return GNUNET_strndup (address, dash - address);
198}
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.

References address, and GNUNET_strndup.

Referenced by GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(), store_pi(), and suggest_to_connect().

Here is the caller graph for this function:

◆ GNUNET_HELLO_sign_address()

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.

Parameters
addresstext address to sign
ntnetwork type of address
mono_timewhen was address valid
private_keysigning key to use
[out]resultwhere to write address record (allocated)
[out]result_sizeset to size of result
addresstext address at communicator to sign
ntnetwork type of address
mono_timemonotonic time at which address was valid
private_keysigning key to use
[out]resultwhere to write address record (allocated)
[out]result_sizeset to size of result

Definition at line 66 of file hello-ng.c.

73{
74 struct SignedAddress sa;
76 char *sig_str;
77
78 sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS);
79 sa.purpose.size = htonl (sizeof(sa));
80 sa.mono_time = GNUNET_TIME_absolute_hton (mono_time);
81 GNUNET_CRYPTO_hash (address, strlen (address), &sa.addr_hash);
82 GNUNET_CRYPTO_eddsa_sign (private_key, &sa, &sig);
83 sig_str = NULL;
84 (void) GNUNET_STRINGS_base64_encode (&sig, sizeof(sig), &sig_str);
85 *result_size =
86 1 + GNUNET_asprintf ((char **) result,
87 "%s;%llu;%u;%s",
88 sig_str,
89 (unsigned long long) mono_time.abs_value_us,
90 (unsigned int) nt,
91 address);
92 GNUNET_free (sig_str);
93}
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
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
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1622
#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS
Signature by a peer affirming that this is one of its addresses for the given time period.
uint64_t abs_value_us
The actual value.
Binary block we sign when we sign an address.
Definition: hello-ng.c:37

References GNUNET_TIME_Absolute::abs_value_us, SignedAddress::addr_hash, address, GNUNET_asprintf(), GNUNET_CRYPTO_eddsa_sign, GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, GNUNET_STRINGS_base64_encode(), GNUNET_TIME_absolute_hton(), SignedAddress::mono_time, nt, GNUNET_CRYPTO_EccSignaturePurpose::purpose, SignedAddress::purpose, result, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by store_pi().

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