GNUnet 0.28.1-dev.4-47-g3e168ca2d
 
Loading...
Searching...
No Matches
hello-uri.c File Reference

helper library for handling URI-based HELLOs More...

#include "gnunet_time_lib.h"
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_signatures.h"
#include "gnunet_hello_uri_lib.h"
#include "gnunet_protocols.h"
Include dependency graph for hello-uri.c:

Go to the source code of this file.

Data Structures

struct  PilsHelloSignaturePurpose
 Message signed as part of a HELLO block/URL. More...
 
struct  HelloUriMessage
 Message used when gossiping HELLOs between peers. More...
 
struct  BlockHeader
 Start of a 'block'. More...
 
struct  DhtHelloMessage
 Message used when a DHT provides its HELLO to direct neighbours. More...
 
struct  Address
 Address of a peer. More...
 
struct  GNUNET_HELLO_Builder
 Context for building (or parsing) HELLO URIs. More...
 
struct  AddressUriMergeResult
 Struct to wrap data to do the merge of to hello uris. More...
 
struct  GNUNET_HELLO_Parser
 Context for parsing HELLOs. More...
 

Functions

static void hash_addresses (const struct Address *addr_start, struct GNUNET_HashCode *hash)
 
static enum GNUNET_GenericReturnValue verify_hello (const struct GNUNET_HELLO_Parser *parser, struct GNUNET_TIME_Absolute et, const struct GNUNET_CRYPTO_EddsaSignature *sig)
 Verify HELLO signature.
 
static struct GNUNET_HELLO_Parserparser_new (const struct GNUNET_PeerIdentity *pid)
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_new ()
 Allocate builder.
 
const struct GNUNET_PeerIdentityGNUNET_HELLO_parser_get_id (const struct GNUNET_HELLO_Parser *parser)
 Get the PeerIdentity for this builder.
 
struct GNUNET_HELLO_BuilderGNUNET_HELLO_builder_from_parser (const struct GNUNET_HELLO_Parser *p, struct GNUNET_PeerIdentity *pid)
 Allocate builder from parser.
 
void GNUNET_HELLO_parser_free (struct GNUNET_HELLO_Parser *parser)
 Release resources of a builder.
 
void GNUNET_HELLO_builder_free (struct GNUNET_HELLO_Builder *builder)
 Release resources of a builder.
 
struct GNUNET_HELLO_ParserGNUNET_HELLO_parser_from_msg (const struct GNUNET_MessageHeader *msg, const struct GNUNET_PeerIdentity *pid)
 Parse msg.
 
struct GNUNET_HELLO_ParserGNUNET_HELLO_parser_from_msg_ (const struct GNUNET_MessageHeader *msg, const struct GNUNET_PeerIdentity *pid, int noverify)
 Parse msg.
 
static enum GNUNET_GenericReturnValue check_address (const char *address)
 
static int cmp_address (void *cls, struct Address *a, struct Address *b)
 Alphanumeric sorting for addresses.
 
static enum GNUNET_GenericReturnValue parser_add_address (struct GNUNET_HELLO_Parser *parser, const char *address)
 
struct GNUNET_HELLO_ParserGNUNET_HELLO_parser_from_block (const void *block, size_t block_size)
 Parse block.
 
struct GNUNET_HELLO_ParserGNUNET_HELLO_parser_from_block_ (const void *block, size_t block_size, int noverify)
 Parse block.
 
struct GNUNET_TIME_Absolute GNUNET_HELLO_get_expiration_time_from_msg (const struct GNUNET_MessageHeader *msg)
 Get the expiration time for this HELLO.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_add_address (struct GNUNET_HELLO_Builder *builder, const char *address)
 Add individual address to the builder.
 
struct GNUNET_HELLO_ParserGNUNET_HELLO_parser_from_url (const char *url)
 Parse GNUnet HELLO url.
 
char * GNUNET_HELLO_parser_to_url (const struct GNUNET_HELLO_Parser *parser)
 Generate GNUnet HELLO URI from a parser.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_parser_to_block (const struct GNUNET_HELLO_Parser *parser, void *block, size_t *block_size)
 Generate DHT block from a parser.
 
struct GNUNET_MQ_EnvelopeGNUNET_HELLO_parser_to_env (const struct GNUNET_HELLO_Parser *parser)
 Generate envelope with GNUnet HELLO message (including peer ID) from a parser.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_del_address (struct GNUNET_HELLO_Builder *builder, const char *address)
 Remove individual address from the builder.
 
void GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder, GNUNET_HELLO_UriCallback uc, void *uc_cls)
 Iterate over URIs in a builder.
 
const struct GNUNET_PeerIdentityGNUNET_HELLO_parser_iterate (const struct GNUNET_HELLO_Parser *parser, GNUNET_HELLO_UriCallback uc, void *uc_cls)
 Iterate over URIs in a parser.
 
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.
 
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.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_build_url (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, struct GNUNET_TIME_Absolute expiration, char **result)
 
void GNUNET_HELLO_builder_hash_addresses (const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
 Compute hash over addresses in builder.
 
struct GNUNET_MQ_EnvelopeGNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *hello_sig, struct GNUNET_TIME_Absolute expiration_time)
 Generate envelope with GNUnet HELLO message (including peer ID) from a builder.
 
struct GNUNET_MessageHeaderGNUNET_HELLO_parser_to_dht_hello_msg (const struct GNUNET_HELLO_Parser *parser)
 Generate DHT HELLO message from a parser.
 
struct GNUNET_MessageHeaderGNUNET_HELLO_builder_to_dht_hello_msg (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *hello_sig, struct GNUNET_TIME_Absolute expiration_time)
 Generate DHT HELLO message (without peer ID) from a builder.
 
void GNUNET_HELLO_builder_to_block (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, struct GNUNET_TIME_Absolute expiration_time, char *block)
 Generate DHT block from a builder.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_to_url2 (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, struct GNUNET_TIME_Absolute validity, char **result)
 Generate GNUnet HELLO URI from a builder.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_to_url (const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, char **result)
 Generate GNUnet HELLO URI from a builder.
 
size_t GNUNET_HELLO_get_builder_to_block_size (const struct GNUNET_HELLO_Builder *builder)
 Get projected block size for builder.
 
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_address_list_cmp (const struct GNUNET_HELLO_Builder *abuilder, const struct GNUNET_HELLO_Builder *bbuilder)
 Compare address lists of two builders.
 

Detailed Description

helper library for handling URI-based HELLOs

Author
Christian Grothoff

Note:

  • Current API does not support deserializing HELLO of another peer and then serializing it into another format (we always require the private key). Not sure if we need this, but if we do, we need to extend the builder and the API.
  • Current API does not allow overriding the default HELLO expiration time. We may want to add a function that does this to create bootstrap HELLOs shipped with the TGZ.

Definition in file hello-uri.c.

Function Documentation

◆ hash_addresses()

static void hash_addresses ( const struct Address addr_start,
struct GNUNET_HashCode hash 
)
static

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

269{
270 struct GNUNET_HashContext *hc;
271
273
274#if HELLO_DETERMINISTIC_PID_DERIVATION
275 for (const struct Address *a = addr_start;
276 NULL != a;
277 a = a->next)
278 {
280 "Hashing over %.*s\n",
281 (int) a->uri_len,
282 a->uri);
284 a->uri,
285 a->uri_len);
286 }
287#endif
289 hash);
290
291}
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, const void *buf, size_t size)
Add data to be hashed.
void GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, struct GNUNET_HashCode *r_hash)
Finish the hash computation.
struct GNUNET_HashContext * GNUNET_CRYPTO_hash_context_start(void)
Start incremental hashing operation.
@ GNUNET_ERROR_TYPE_DEBUG
Address of a peer.
Definition hello-uri.c:158
struct Address * next
Kept in a DLL.
Definition hello-uri.c:162

References GNUNET_CRYPTO_hash_context_finish(), GNUNET_CRYPTO_hash_context_read(), GNUNET_CRYPTO_hash_context_start(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and Address::next.

Referenced by GNUNET_HELLO_builder_hash_addresses(), and verify_hello().

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

◆ verify_hello()

static enum GNUNET_GenericReturnValue verify_hello ( const struct GNUNET_HELLO_Parser parser,
struct GNUNET_TIME_Absolute  et,
const struct GNUNET_CRYPTO_EddsaSignature sig 
)
static

Verify HELLO signature.

Parameters
builderthe builder to use
etexpiration time to verify
sigsignature to verify
Returns
GNUNET_OK if everything is ok, GNUNET_NO if the HELLO expired, GNUNET_SYSERR if the signature is wrong

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

307{
308 struct PilsHelloSignaturePurpose hsp = {
309 .purpose.size = htonl (sizeof (hsp)),
310 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
311 .expiration_time = GNUNET_TIME_absolute_hton (et)
312 };
313
314 hash_addresses (parser->a_head,
315 &hsp.h_addrs);
316 if (GNUNET_OK !=
318 &hsp,
319 sig,
320 &parser->pid.public_key))
321 {
323 "HELLO signature invalid, rejecting.\n");
324 return GNUNET_SYSERR;
325 }
327 return GNUNET_NO;
328 return GNUNET_OK;
329}
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition time.c:667
static void hash_addresses(const struct Address *addr_start, struct GNUNET_HashCode *hash)
Definition hello-uri.c:267
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
Message signed as part of a HELLO block/URL.
Definition hello-uri.c:51
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Definition hello-uri.c:65
struct GNUNET_CRYPTO_SignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition hello-uri.c:55

References GNUNET_CRYPTO_eddsa_verify, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_HELLO, GNUNET_SYSERR, GNUNET_TIME_absolute_hton(), GNUNET_TIME_absolute_is_past(), PilsHelloSignaturePurpose::h_addrs, hash_addresses(), PilsHelloSignaturePurpose::purpose, and GNUNET_CRYPTO_SignaturePurpose::size.

Referenced by GNUNET_HELLO_dht_msg_to_block(), GNUNET_HELLO_parser_from_block_(), and GNUNET_HELLO_parser_from_url().

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

◆ parser_new()

static struct GNUNET_HELLO_Parser * parser_new ( const struct GNUNET_PeerIdentity pid)
static

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

334{
335 struct GNUNET_HELLO_Parser *p;
336
338 p->pid = *pid;
339 return p;
340}
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Context for parsing HELLOs.
Definition hello-uri.c:233
struct GNUNET_PeerIdentity pid
Public key of the peer.
Definition hello-uri.c:237
pid_t pid
PID of the process.
Definition os_process.c:94

References GNUNET_new, p, GNUNET_HELLO_Parser::pid, and GNUNET_Process::pid.

Referenced by GNUNET_HELLO_parser_from_block_(), and GNUNET_HELLO_parser_from_url().

Here is the caller graph for this function:

◆ check_address()

static enum GNUNET_GenericReturnValue check_address ( const char *  address)
static

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

498{
499 const char *e;
500
501 if (NULL == (e = strstr (address,
502 "://")))
503 {
504 GNUNET_break_op (0);
506 "Invalid address `%s'\n",
507 address);
508 return GNUNET_SYSERR;
509 }
510 if (e == address)
511 {
512 GNUNET_break_op (0);
513 return GNUNET_SYSERR;
514 }
515 for (const char *p = address; p != e; p++)
516 if ( (! isalpha ((unsigned char) *p)) &&
517 ('+' != *p) )
518 {
519 GNUNET_break_op (0);
520 return GNUNET_SYSERR;
521 }
522 return GNUNET_OK;
523}
static char * address
GNS address for this phone.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_ERROR

References address, GNUNET_break_op, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, and p.

Referenced by GNUNET_HELLO_builder_add_address(), and parser_add_address().

Here is the caller graph for this function:

◆ cmp_address()

static int cmp_address ( void *  cls,
struct Address a,
struct Address b 
)
static

Alphanumeric sorting for addresses.

Parameters
clsNULL
afirst address
baddress to compare first address with
Returns
result of strcmp on the URI of the addresses

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

537{
538 return strcmp (a->uri, b->uri);
539}
const char * uri
Actual URI, allocated at the end of this struct.
Definition hello-uri.c:172

References Address::uri.

Referenced by GNUNET_HELLO_builder_add_address(), and parser_add_address().

Here is the caller graph for this function:

◆ parser_add_address()

static enum GNUNET_GenericReturnValue parser_add_address ( struct GNUNET_HELLO_Parser parser,
const char *  address 
)
static

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

545{
546 struct Address *a;
548 size_t alen = strlen (address) + 1;
549
551 if (GNUNET_OK != ret)
552 {
554 "Failed to add address to builder\n");
555 return ret;
556 }
557 /* check for duplicates */
558 for (a = parser->a_head;
559 NULL != a;
560 a = a->next)
561 if (0 == strcmp (address,
562 a->uri))
563 return GNUNET_NO;
564 a = GNUNET_malloc (sizeof (struct Address) + alen);
565 a->uri_len = alen;
566 memcpy (&a[1],
567 address,
568 alen);
569 a->uri = (const char *) &a[1];
572 NULL,
573 parser->a_head,
574 parser->a_tail,
575 a);
576 parser->a_length++;
577 return GNUNET_OK;
578}
static int ret
Final status code.
Definition gnunet-arm.c:93
#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE, comparator, comparator_cls, head, tail, element)
Insertion sort of element into DLL from head to tail sorted by comparator.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_malloc(size)
Wrapper around malloc.
static int cmp_address(void *cls, struct Address *a, struct Address *b)
Alphanumeric sorting for addresses.
Definition hello-uri.c:536
static enum GNUNET_GenericReturnValue check_address(const char *address)
Definition hello-uri.c:497
size_t uri_len
Length of uri including 0-terminator.
Definition hello-uri.c:177

References address, check_address(), cmp_address(), GNUNET_CONTAINER_DLL_insert_sorted, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc, GNUNET_NO, GNUNET_OK, Address::next, ret, Address::uri, and Address::uri_len.

Referenced by GNUNET_HELLO_parser_from_block_(), and GNUNET_HELLO_parser_from_url().

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