GNUnet  0.11.x
Data Structures | Functions
hello.c File Reference

helper library for handling HELLOs More...

#include "platform.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_util_lib.h"
#include "gnunet_transport_plugin.h"
Include dependency graph for hello.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_HELLO_ComposeUriContext
 Context used for building our own URI. More...
 
struct  GNUNET_HELLO_ParseUriContext
 Context for add_address_to_hello(). More...
 
struct  ExpireContext
 Closure for get_match_exp(). More...
 
struct  MergeContext
 Closure for merge_pr(). More...
 
struct  DeltaContext
 Context used in GNUNET_HELLO_iterate_new_addresses() to figure out which addresses are in fact 'new'. More...
 
struct  EqualsContext
 Context used for comparing HELLOs in GNUNET_HELLO_equals(). More...
 

Functions

int GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h)
 Return HELLO type. More...
 
size_t GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration, char *target, size_t max)
 Copy the given address information into the given buffer using the format of HELLOs. More...
 
static size_t get_hello_address_size (const char *buf, size_t max, uint16_t *ralen)
 Get the size of an address entry in a HELLO message. More...
 
struct GNUNET_HELLO_MessageGNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, GNUNET_HELLO_GenerateAddressListCallback addrgen, void *addrgen_cls, int friend_only)
 Construct a HELLO message given the public key, expiration time and an iterator that spews the transport addresses. More...
 
struct GNUNET_HELLO_MessageGNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
 Iterate over all of the addresses in the HELLO. More...
 
static int get_match_exp (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Store the expiration time of an address that matches the template. More...
 
static int copy_latest (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Append the address address to the buffer from the merge context IF it is more recent than equivalent addresses in other. More...
 
static ssize_t merge_addr (void *cls, size_t max, void *buf)
 Function called to build the HELLO during GNUNET_HELLO_merge() by merging addresses from two original HELLOs. More...
 
struct GNUNET_HELLO_MessageGNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1, const struct GNUNET_HELLO_Message *h2)
 Construct a HELLO message by merging the addresses in two existing HELLOs (which must be for the same peer). More...
 
static int delta_match (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Check if the given address is 'new', and if so, call the iterator. More...
 
void GNUNET_HELLO_iterate_new_addresses (const struct GNUNET_HELLO_Message *new_hello, const struct GNUNET_HELLO_Message *old_hello, struct GNUNET_TIME_Absolute expiration_limit, GNUNET_HELLO_AddressIterator it, void *it_cls)
 Iterate over addresses in new_hello that are NOT already present in old_hello. More...
 
uint16_t GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello)
 Return the size of the given HELLO message. More...
 
int GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
 Get the peer identity from a HELLO message. More...
 
struct GNUNET_MessageHeaderGNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello)
 Get the header from a HELLO message, used so other code can correctly send HELLO messages. More...
 
static int find_other_matching (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Check if the given address matches the address we are currently looking for. More...
 
static int find_matching (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Helper function for GNUNET_HELLO_equals(). More...
 
struct GNUNET_TIME_Absolute GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1, const struct GNUNET_HELLO_Message *h2, struct GNUNET_TIME_Absolute now)
 Test if two HELLO messages contain the same addresses. More...
 
static int find_max_expire (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Iterator to find the time when the last address will expire. More...
 
struct GNUNET_TIME_Absolute GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg)
 When does the last address in the given HELLO expire? More...
 
static int add_address_to_uri (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 GNUnet URIs are of the general form "gnunet://MODULE/IDENTIFIER". More...
 
char * GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello, GNUNET_HELLO_TransportPluginsFind plugins_find)
 Compose a hello URI string from a hello message. More...
 
static ssize_t add_address_to_hello (void *cls, size_t max, void *buffer)
 We're building a HELLO. More...
 
int GNUNET_HELLO_parse_uri (const char *uri, struct GNUNET_CRYPTO_EddsaPublicKey *pubkey, struct GNUNET_HELLO_Message **hello, GNUNET_HELLO_TransportPluginsFind plugins_find)
 Parse a hello URI string to a hello message. More...
 

Detailed Description

helper library for handling HELLOs

Author
Christian Grothoff
Matthias Wachs

Definition in file hello.c.

Function Documentation

◆ get_hello_address_size()

static size_t get_hello_address_size ( const char *  buf,
size_t  max,
uint16_t *  ralen 
)
static

Get the size of an address entry in a HELLO message.

Parameters
bufpointer to the start of the address entry
maxmaximum size of the entry (end of buf)
ralenset to the address length
Returns
size of the entry, or 0 if max is not large enough

Definition at line 144 of file hello.c.

References buf, GNUNET_break_op, and GNUNET_memcpy.

Referenced by GNUNET_HELLO_iterate_addresses().

147 {
148  const char *pos;
149  uint16_t alen;
150  size_t left;
151  size_t slen;
152 
153  left = max;
154  pos = buf;
155  slen = 1;
156  while ((left > 0) && ('\0' != *pos))
157  {
158  left--;
159  pos++;
160  slen++;
161  }
162  if (0 == left)
163  {
164  /* 0-termination not found */
165  GNUNET_break_op (0);
166  return 0;
167  }
168  pos++;
169  if (left < sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO))
170  {
171  /* not enough space for addrlen */
172  GNUNET_break_op (0);
173  return 0;
174  }
175  GNUNET_memcpy (&alen, pos, sizeof(uint16_t));
176  alen = ntohs (alen);
177  *ralen = alen;
178  slen += alen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO);
179  if (max < slen)
180  {
181  /* not enough space for addr */
182  GNUNET_break_op (0);
183  return 0;
184  }
185  return slen;
186 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static char buf[2048]
Here is the caller graph for this function:

◆ get_match_exp()

static int get_match_exp ( void *  cls,
const struct GNUNET_HELLO_Address address,
struct GNUNET_TIME_Absolute  expiration 
)
static

Store the expiration time of an address that matches the template.

Parameters
clsthe struct ExpireContext
addressaddress to match against the template
expirationexpiration time of address, to store in cls
Returns
GNUNET_SYSERR if we found a matching address, GNUNET_OK otherwise

Definition at line 370 of file hello.c.

References ExpireContext::address, expiration, ExpireContext::expiration, ExpireContext::found, GNUNET_HELLO_address_cmp(), GNUNET_OK, GNUNET_SYSERR, and GNUNET_YES.

Referenced by copy_latest(), and delta_match().

373 {
374  struct ExpireContext *ec = cls;
375 
376  if (0 != GNUNET_HELLO_address_cmp (address,
377  ec->address))
378  return GNUNET_OK;
379  ec->found = GNUNET_YES;
380  ec->expiration = expiration;
381  return GNUNET_SYSERR; /* done here */
382 }
int found
Set to GNUNET_YES if we found the address.
Definition: hello.c:352
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
const struct GNUNET_HELLO_Address * address
Address we are looking for.
Definition: hello.c:347
static char * expiration
Credential TTL.
Definition: gnunet-abd.c:96
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_TIME_Absolute expiration
Set to the expiration of the match if found is GNUNET_YES.
Definition: hello.c:357
Closure for get_match_exp().
Definition: hello.c:342
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_latest()

static int copy_latest ( void *  cls,
const struct GNUNET_HELLO_Address address,
struct GNUNET_TIME_Absolute  expiration 
)
static

Append the address address to the buffer from the merge context IF it is more recent than equivalent addresses in other.

Parameters
clsthe struct MergeContext
addressthe HELLO address we might copy
expirationexpiration time for address
Returns
always GNUNET_OK

Definition at line 442 of file hello.c.

References GNUNET_TIME_Absolute::abs_value_us, address, ExpireContext::address, MergeContext::buf, ExpireContext::expiration, ExpireContext::found, get_match_exp(), GNUNET_HELLO_add_address(), GNUNET_HELLO_iterate_addresses(), GNUNET_NO, GNUNET_OK, GNUNET_YES, MergeContext::max, mc, MergeContext::other, MergeContext::ret, and MergeContext::take_equal.

Referenced by merge_addr().

445 {
446  struct MergeContext *mc = cls;
447  struct ExpireContext ec;
448 
449  ec.address = address;
450  ec.found = GNUNET_NO;
451  /* check if address exists in other */
453  GNUNET_NO,
454  &get_match_exp,
455  &ec);
456  if ((GNUNET_NO == ec.found) ||
457  (ec.expiration.abs_value_us < expiration.abs_value_us) ||
458  ((ec.expiration.abs_value_us == expiration.abs_value_us) &&
459  (GNUNET_YES == mc->take_equal)))
460  {
461  /* copy address to buffer */
462  mc->ret +=
463  GNUNET_HELLO_add_address (address,
464  expiration,
465  &mc->buf[mc->ret],
466  mc->max - mc->ret);
467  }
468  return GNUNET_OK;
469 }
Closure for merge_pr().
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint64_t abs_value_us
The actual value.
char * buf
Buffer where we copy to.
Definition: hello.c:410
struct GNUNET_HELLO_Message * GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
Iterate over all of the addresses in the HELLO.
Definition: hello.c:254
const struct GNUNET_HELLO_Address * address
Address we are looking for.
Definition: hello.c:347
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
int take_equal
Should we copy addresses with an identical value and expiration time in other, or do we only copy add...
Definition: hello.c:427
size_t GNUNET_HELLO_add_address(const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration, char *target, size_t max)
Copy the given address information into the given buffer using the format of HELLOs.
Definition: hello.c:109
size_t ret
Current (write) offset in buf.
Definition: hello.c:420
size_t max
Number of bytes allocated in buf.
Definition: hello.c:415
Closure for get_match_exp().
Definition: hello.c:342
const struct GNUNET_HELLO_Message * other
Either h1 or h2, used when copying to compare against (so we only copy the most recent entry)...
Definition: hello.c:405
static int get_match_exp(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Store the expiration time of an address that matches the template.
Definition: hello.c:370
#define GNUNET_YES
Definition: gnunet_common.h:77
static char * address
GNS address for this phone.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ merge_addr()

static ssize_t merge_addr ( void *  cls,
size_t  max,
void *  buf 
)
static

Function called to build the HELLO during GNUNET_HELLO_merge() by merging addresses from two original HELLOs.

Parameters
clsthe struct MergeContext
maxnumber of bytes we can write at most in buf
bufwhere to copy the addresses
Returns
GNUNET_SYSERR to end iteration, otherwise number of bytes written to buf

Definition at line 483 of file hello.c.

References buf, MergeContext::buf, copy_latest(), GNUNET_HELLO_iterate_addresses(), GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, MergeContext::h1, MergeContext::h2, MergeContext::max, mc, MergeContext::other, MergeContext::ret, and MergeContext::take_equal.

Referenced by GNUNET_HELLO_merge().

486 {
487  struct MergeContext *mc = cls;
488 
489  if (NULL == mc->h1)
490  return GNUNET_SYSERR; /* Stop iteration */
491  mc->ret = 0;
492  mc->max = max;
493  mc->buf = buf;
494  mc->take_equal = GNUNET_NO;
495  mc->other = mc->h2;
496  /* copy addresses from h1, if strictly larger expiration than h2 */
498  GNUNET_NO,
499  &copy_latest,
500  mc);
501  mc->take_equal = GNUNET_YES;
502  mc->other = mc->h1;
503  /* copy addresses from h2, if larger or equal expiration than h1 */
505  GNUNET_NO,
506  &copy_latest,
507  mc);
508  /* set marker to stop iteration */
509  mc->h1 = NULL;
510  return mc->ret;
511 }
Closure for merge_pr().
const struct GNUNET_HELLO_Message * h1
First HELLO we are merging.
Definition: hello.c:393
#define GNUNET_NO
Definition: gnunet_common.h:78
char * buf
Buffer where we copy to.
Definition: hello.c:410
struct GNUNET_HELLO_Message * GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
Iterate over all of the addresses in the HELLO.
Definition: hello.c:254
static char buf[2048]
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
int take_equal
Should we copy addresses with an identical value and expiration time in other, or do we only copy add...
Definition: hello.c:427
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static int copy_latest(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Append the address address to the buffer from the merge context IF it is more recent than equivalent ...
Definition: hello.c:442
const struct GNUNET_HELLO_Message * h2
Second HELLO we are merging.
Definition: hello.c:398
size_t ret
Current (write) offset in buf.
Definition: hello.c:420
size_t max
Number of bytes allocated in buf.
Definition: hello.c:415
const struct GNUNET_HELLO_Message * other
Either h1 or h2, used when copying to compare against (so we only copy the most recent entry)...
Definition: hello.c:405
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ delta_match()

static int delta_match ( void *  cls,
const struct GNUNET_HELLO_Address address,
struct GNUNET_TIME_Absolute  expiration 
)
static

Check if the given address is 'new', and if so, call the iterator.

Compares the existing address against addresses in the context's old_hello and calls the iterator on those that are new (and not expired).

Parameters
clsthe struct DeltaContext
addressan address to check whether it is new
expirationexpiration time for address
Returns
GNUNET_YES if the address is ignored, otherwise whatever the iterator returned.

Definition at line 584 of file hello.c.

References GNUNET_TIME_Absolute::abs_value_us, address, ExpireContext::address, dc, ExpireContext::expiration, DeltaContext::expiration_limit, ExpireContext::found, get_match_exp(), GNUNET_HELLO_iterate_addresses(), GNUNET_NO, GNUNET_YES, DeltaContext::it, DeltaContext::it_cls, DeltaContext::old_hello, and ret.

Referenced by GNUNET_HELLO_iterate_new_addresses().

587 {
588  struct DeltaContext *dc = cls;
589  int ret;
590  struct ExpireContext ec;
591 
592  ec.address = address;
593  ec.found = GNUNET_NO;
595  GNUNET_NO,
596  &get_match_exp,
597  &ec);
598  if ((GNUNET_YES == ec.found) &&
599  ((ec.expiration.abs_value_us > expiration.abs_value_us) ||
600  (ec.expiration.abs_value_us >= dc->expiration_limit.abs_value_us)))
601  return GNUNET_YES; /* skip: found and boring */
602  ret = dc->it (dc->it_cls,
603  address,
604  expiration);
605  return ret;
606 }
Context used in GNUNET_HELLO_iterate_new_addresses() to figure out which addresses are in fact &#39;new&#39;...
Definition: hello.c:546
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
GNUNET_HELLO_AddressIterator it
Function to call on addresses that are indeed new.
Definition: hello.c:556
#define GNUNET_NO
Definition: gnunet_common.h:78
uint64_t abs_value_us
The actual value.
const struct GNUNET_HELLO_Message * old_hello
HELLO with known addresses, addresses in this HELLO we must always ignore.
Definition: hello.c:567
struct GNUNET_HELLO_Message * GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
Iterate over all of the addresses in the HELLO.
Definition: hello.c:254
const struct GNUNET_HELLO_Address * address
Address we are looking for.
Definition: hello.c:347
void * it_cls
Closure for it.
Definition: hello.c:561
struct GNUNET_TIME_Absolute expiration_limit
We should ignore addresses that expire before this time.
Definition: hello.c:551
Closure for get_match_exp().
Definition: hello.c:342
static int get_match_exp(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Store the expiration time of an address that matches the template.
Definition: hello.c:370
#define GNUNET_YES
Definition: gnunet_common.h:77
static char * address
GNS address for this phone.
static struct GNUNET_FS_DownloadContext * dc
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_other_matching()

static int find_other_matching ( void *  cls,
const struct GNUNET_HELLO_Address address,
struct GNUNET_TIME_Absolute  expiration 
)
static

Check if the given address matches the address we are currently looking for.

If so, sets found to GNUNET_YES and, if the expiration times for the two addresses differ, updates result to the minimum of our expiration and the existing value

Parameters
clsthe struct EqualsContext
addressaddress from the reference HELLO
expirationexpiration time for address
Returns
GNUNET_YES if the address is expired or does not match GNUNET_SYSERR if the address does match.

Definition at line 759 of file hello.c.

References GNUNET_TIME_Absolute::abs_value_us, EqualsContext::address, EqualsContext::expiration, EqualsContext::expiration_limit, EqualsContext::found, GNUNET_HELLO_address_cmp(), GNUNET_SYSERR, GNUNET_TIME_absolute_min(), GNUNET_YES, and EqualsContext::result.

Referenced by find_matching().

762 {
763  struct EqualsContext *ec = cls;
764 
765  if (expiration.abs_value_us < ec->expiration_limit.abs_value_us)
766  return GNUNET_YES;
767  if (0 == GNUNET_HELLO_address_cmp (address, ec->address))
768  {
769  ec->found = GNUNET_YES;
770  if (expiration.abs_value_us < ec->expiration.abs_value_us)
771  ec->result = GNUNET_TIME_absolute_min (expiration,
772  ec->result);
773  return GNUNET_SYSERR;
774  }
775  return GNUNET_YES;
776 }
struct GNUNET_TIME_Absolute expiration
Expiration time of address.
Definition: hello.c:737
struct GNUNET_TIME_Absolute expiration_limit
Addresses that expired before this date are ignored for the comparisson.
Definition: hello.c:714
uint64_t abs_value_us
The actual value.
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
int found
Did we find the address we were looking for?
Definition: hello.c:742
struct GNUNET_TIME_Absolute result
Earliest expiration time for which we found a match with a difference in expiration times...
Definition: hello.c:721
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the minimum of two absolute time values.
Definition: time.c:302
#define GNUNET_YES
Definition: gnunet_common.h:77
Context used for comparing HELLOs in GNUNET_HELLO_equals().
Definition: hello.c:708
const struct GNUNET_HELLO_Address * address
Address we are currently looking for.
Definition: hello.c:732
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_matching()

static int find_matching ( void *  cls,
const struct GNUNET_HELLO_Address address,
struct GNUNET_TIME_Absolute  expiration 
)
static

Helper function for GNUNET_HELLO_equals().

Checks if the given address exists also in the other HELLO; if not, the result time is set to zero and the iteration is aborted.

Parameters
clsthe struct EqualsContext
addressaddress to locate
expirationexpiration time of the current address
Returns
GNUNET_OK if the address exists or is expired, GNUNET_SYSERR if it was not found

Definition at line 792 of file hello.c.

References GNUNET_TIME_Absolute::abs_value_us, address, EqualsContext::address, expiration, EqualsContext::expiration, EqualsContext::expiration_limit, find_other_matching(), EqualsContext::found, GNUNET_HELLO_iterate_addresses(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_ZERO_ABS, EqualsContext::ref, and EqualsContext::result.

Referenced by GNUNET_HELLO_equals().

795 {
796  struct EqualsContext *ec = cls;
797 
798  if (expiration.abs_value_us < ec->expiration_limit.abs_value_us)
799  return GNUNET_OK; /* expired, we don't care */
800  ec->address = address;
801  ec->expiration = expiration;
802  ec->found = GNUNET_NO;
804  GNUNET_NO,
806  ec);
807  if (GNUNET_NO == ec->found)
808  {
809  /* not found, we differ *now* */
811  return GNUNET_SYSERR;
812  }
813  return GNUNET_OK;
814 }
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
struct GNUNET_TIME_Absolute expiration
Expiration time of address.
Definition: hello.c:737
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_TIME_Absolute expiration_limit
Addresses that expired before this date are ignored for the comparisson.
Definition: hello.c:714
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint64_t abs_value_us
The actual value.
static int find_other_matching(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Check if the given address matches the address we are currently looking for.
Definition: hello.c:759
const struct GNUNET_HELLO_Message * ref
HELLO message to compare against.
Definition: hello.c:727
int found
Did we find the address we were looking for?
Definition: hello.c:742
struct GNUNET_HELLO_Message * GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
Iterate over all of the addresses in the HELLO.
Definition: hello.c:254
struct GNUNET_TIME_Absolute result
Earliest expiration time for which we found a match with a difference in expiration times...
Definition: hello.c:721
static char * expiration
Credential TTL.
Definition: gnunet-abd.c:96
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Context used for comparing HELLOs in GNUNET_HELLO_equals().
Definition: hello.c:708
static char * address
GNS address for this phone.
const struct GNUNET_HELLO_Address * address
Address we are currently looking for.
Definition: hello.c:732
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_max_expire()

static int find_max_expire ( void *  cls,
const struct GNUNET_HELLO_Address address,
struct GNUNET_TIME_Absolute  expiration 
)
static

Iterator to find the time when the last address will expire.

Updates the maximum value stored in cls.

Parameters
clswhere to store the max, a struct GNUNET_TIME_Absolute
addressan address (ignored)
expirationexpiration time for address
Returns
GNUNET_OK (always)

Definition at line 874 of file hello.c.

References GNUNET_OK, and GNUNET_TIME_absolute_max().

Referenced by GNUNET_HELLO_get_last_expiration().

877 {
878  struct GNUNET_TIME_Absolute *max = cls;
879 
880  *max = GNUNET_TIME_absolute_max (*max, expiration);
881  return GNUNET_OK;
882 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the maximum of two absolute time values.
Definition: time.c:317
Time for absolute times used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_address_to_uri()

static int add_address_to_uri ( void *  cls,
const struct GNUNET_HELLO_Address address,
struct GNUNET_TIME_Absolute  expiration 
)
static

GNUnet URIs are of the general form "gnunet://MODULE/IDENTIFIER".

The specific structure of "IDENTIFIER" depends on the module and maybe differenciated into additional subcategories if applicable. This module only deals with hello identifiers (MODULE = "hello").

The concrete URI format is:

"gnunet://hello/PEER[+YYYYMMDDHHMMSS+<TYPE>+<ADDRESS>]...". These URIs can be used to add a peer record to peerinfo service. PEER is the string representation of peer's public key. YYYYMMDDHHMMSS is the expiration date. TYPE is a transport type. ADDRESS is the address, its format depends upon the transport type. The concrete transport types and corresponding address formats are:

  • <TCP|UDP>!IPADDRESS IPVDDRESS is either IPV4 .-delimited address in form of XXX.XXX.XXX.XXX:PPPPP or IPV6 :-delimited address with '[' and ']' (according to RFC2732):

    PPPPP is the port number. May be 0.

  • [add SMTP, HTTP and other addresses here]

The encoding for hexadecimal values is defined in the crypto_hash.c module in the gnunetutil library and discussed there.

Examples:

gnunet://hello/V8XXK9GAN5ZJFRFQP8MQX3D83BZTSBQVHKWWD0JPE63Z821906EG+20120302010059+TCP+192.168.0.1:2086+TCP+64.23.8.174:0 gnunet://hello/V8XXK9GAN5ZJFRFQP8MQX3D83BZTSBQVHKWWD0JPE63Z821906EG+20120302010059+TCP+[2001:db8:85a3:8d3:1319:8a2e:370:7348]:2086

Function that is called on each address of this peer. Expands the corresponding URI string.

Parameters
clsthe struct GNUNET_HELLO_ComposeUriContext
addressaddress to add
expirationexpiration time for the address
Returns
GNUNET_OK (continue iteration).

Definition at line 958 of file hello.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, GNUNET_TRANSPORT_PluginFunctions::address_to_string, GNUNET_TRANSPORT_PluginFunctions::cls, ctx, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_URI_SEP, GNUNET_log, GNUNET_memcpy, GNUNET_OK, GNUNET_strdup, GNUNET_HELLO_ComposeUriContext::plugins_find, ret, t, GNUNET_HELLO_Address::transport_name, and GNUNET_HELLO_ComposeUriContext::uri.

Referenced by GNUNET_HELLO_compose_uri().

961 {
962  struct GNUNET_HELLO_ComposeUriContext *ctx = cls;
964  const char *addr;
965  char *ret;
966  char *addr_dup;
967  char *pos;
968  char tbuf[16] = "";
969  char *client_str = "_client";
970  struct tm *t;
971  time_t seconds;
972 
973  papi = ctx->plugins_find (address->transport_name);
974  if (NULL == papi)
975  {
976  /* Not an error - we might just not have the right plugin. */
977  return GNUNET_OK;
978  }
979  if (NULL == papi->address_to_string)
980  {
982  "URI conversion not implemented for plugin `%s'\n",
983  address->transport_name);
984  return GNUNET_OK;
985  }
986  addr = papi->address_to_string (papi->cls,
987  address->address,
988  address->address_length);
989  if ((NULL == addr) ||
990  (0 == strlen (addr)))
991  return GNUNET_OK;
992 
993  addr_dup = GNUNET_strdup (addr);
994  if (NULL != (pos = strstr (addr_dup, "_server")))
995  GNUNET_memcpy (pos,
996  client_str,
997  strlen (client_str)); /* Replace all server addresses with client addresses */
998 
999  seconds = expiration.abs_value_us / 1000LL / 1000LL;
1000  t = gmtime (&seconds);
1001 
1002  GNUNET_asprintf (&ret,
1003  "%s%c%s%c%s%c%s",
1004  ctx->uri,
1006  strftime (tbuf,
1007  sizeof(tbuf),
1008  "%Y%m%d%H%M%S",
1009  t) ? tbuf : "0",
1011  address->transport_name,
1013  addr_dup);
1014  GNUNET_free (addr_dup);
1015  GNUNET_free (ctx->uri);
1016  ctx->uri = ret;
1017  return GNUNET_OK;
1018 }
size_t address_length
Number of bytes in address.
GNUNET_TRANSPORT_AddressToString address_to_string
Function that will be called to convert a binary address to a string (numeric conversion only)...
const void * address
Binary representation of the address (plugin-specific).
#define GNUNET_HELLO_URI_SEP
Separator used in HELLO URI.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint64_t abs_value_us
The actual value.
char * uri
Final URI.
Definition: hello.c:41
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
GNUNET_HELLO_TransportPluginsFind plugins_find
Function for finding transport plugins by name.
Definition: hello.c:46
void * cls
Closure for all of the callbacks.
const char * transport_name
Name of the transport plugin enabling the communication using this address.
#define GNUNET_log(kind,...)
Context used for building our own URI.
Definition: hello.c:36
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_address_to_hello()

static ssize_t add_address_to_hello ( void *  cls,
size_t  max,
void *  buffer 
)
static

We're building a HELLO.

Parse the next address from the parsing context and append it.

Parameters
clsthe struct GNUNET_HELLO_ParseUriContext
maxnumber of bytes available for HELLO construction
bufferwhere to copy the next address (in binary format)
Returns
number of bytes added to buffer, GNUNET_SYSERR on error

Definition at line 1065 of file hello.c.

References _, GNUNET_TIME_Absolute::abs_value_us, GNUNET_HELLO_Address::address, address, GNUNET_HELLO_Address::address_length, GNUNET_TRANSPORT_PluginFunctions::cls, GNUNET_HELLO_ParseUriContext::counter_added, GNUNET_HELLO_ParseUriContext::counter_total, ctx, end, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_HELLO_add_address(), GNUNET_HELLO_URI_SEP, GNUNET_log, GNUNET_OK, GNUNET_strndup, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_ABS, plugin_name, GNUNET_HELLO_ParseUriContext::plugins_find, GNUNET_HELLO_ParseUriContext::pos, GNUNET_HELLO_ParseUriContext::ret, ret, GNUNET_TRANSPORT_PluginFunctions::string_to_address, and GNUNET_HELLO_Address::transport_name.

Referenced by GNUNET_HELLO_parse_uri().

1068 {
1069  struct GNUNET_HELLO_ParseUriContext *ctx = cls;
1070  const char *tname;
1071  const char *address;
1072  char *uri_address;
1073  const char *end;
1074  char *plugin_name;
1075  struct tm expiration_time;
1076  time_t expiration_seconds;
1078  struct GNUNET_TRANSPORT_PluginFunctions *papi;
1079  void *addr;
1080  size_t addr_len;
1081  struct GNUNET_HELLO_Address haddr;
1082  ssize_t ret;
1083 
1084  if (NULL == ctx->pos)
1085  return GNUNET_SYSERR;
1086  if (GNUNET_HELLO_URI_SEP != ctx->pos[0])
1087  {
1088  ctx->ret = GNUNET_SYSERR;
1089  GNUNET_break (0);
1090  return GNUNET_SYSERR;
1091  }
1092  ctx->pos++;
1093 
1094  if (('0' == ctx->pos[0]) &&
1095  (GNUNET_HELLO_URI_SEP == ctx->pos[1]))
1096  {
1098  tname = ctx->pos + 1;
1099  }
1100  else
1101  {
1102  memset (&expiration_time, 0, sizeof(expiration_time));
1103  tname = strptime (ctx->pos,
1104  "%Y%m%d%H%M%S",
1105  &expiration_time);
1106  if (NULL == tname)
1107  {
1108  ctx->ret = GNUNET_SYSERR;
1110  _ (
1111  "Failed to parse HELLO message: missing expiration time\n"));
1112  GNUNET_break (0);
1113  return GNUNET_SYSERR;
1114  }
1115 
1116  expiration_seconds = mktime (&expiration_time);
1117  if (expiration_seconds == (time_t) -1)
1118  {
1120  _ (
1121  "Failed to parse HELLO message: invalid expiration time\n"));
1122  ctx->ret = GNUNET_SYSERR;
1123  GNUNET_break (0);
1124  return GNUNET_SYSERR;
1125  }
1126  expire.abs_value_us = expiration_seconds * 1000LL * 1000LL;
1127  }
1128  if (GNUNET_HELLO_URI_SEP != tname[0])
1129  {
1131  _ ("Failed to parse HELLO message: malformed\n"));
1132  ctx->ret = GNUNET_SYSERR;
1133  GNUNET_break (0);
1134  return GNUNET_SYSERR;
1135  }
1136  tname++;
1137  address = strchr (tname,
1138  (int) GNUNET_HELLO_URI_SEP);
1139  if (NULL == address)
1140  {
1142  _ (
1143  "Failed to parse HELLO message: missing transport plugin\n"));
1144  ctx->ret = GNUNET_SYSERR;
1145  GNUNET_break (0);
1146  return GNUNET_SYSERR;
1147  }
1148  address++;
1149  end = strchr (address, (int) GNUNET_HELLO_URI_SEP);
1150  ctx->pos = end;
1151  ctx->counter_total++;
1152  plugin_name = GNUNET_strndup (tname, address - (tname + 1));
1153  papi = ctx->plugins_find (plugin_name);
1154  if (NULL == papi)
1155  {
1156  /* Not an error - we might just not have the right plugin.
1157  * Skip this part, advance to the next one and recurse.
1158  * But only if this is not the end of string.
1159  */
1161  _ ("Plugin `%s' not found, skipping address\n"),
1162  plugin_name);
1163  GNUNET_free (plugin_name);
1164  return 0;
1165  }
1166  if (NULL == papi->string_to_address)
1167  {
1169  _ ("Plugin `%s' does not support URIs yet\n"),
1170  plugin_name);
1171  GNUNET_free (plugin_name);
1172  GNUNET_break (0);
1173  return 0;
1174  }
1175  uri_address = GNUNET_strndup (address, end - address);
1176  if (GNUNET_OK !=
1177  papi->string_to_address (papi->cls,
1178  uri_address,
1179  strlen (uri_address) + 1,
1180  &addr,
1181  &addr_len))
1182  {
1184  _ ("Failed to parse `%s' as an address for plugin `%s'\n"),
1185  uri_address,
1186  plugin_name);
1187  GNUNET_free (plugin_name);
1188  GNUNET_free (uri_address);
1189  return 0;
1190  }
1191  GNUNET_free (uri_address);
1192  /* address.peer is unset - not used by add_address() */
1193  haddr.address_length = addr_len;
1194  haddr.address = addr;
1195  haddr.transport_name = plugin_name;
1196  ret = GNUNET_HELLO_add_address (&haddr,
1197  expire,
1198  buffer,
1199  max);
1200  ctx->counter_added++;
1201  GNUNET_free (addr);
1202  GNUNET_free (plugin_name);
1203  return ret;
1204 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define GNUNET_HELLO_URI_SEP
Separator used in HELLO URI.
static void expire(void *cls)
Expire a PooledConnection object.
const char * pos
Position in the URI with the next address to parse.
Definition: hello.c:58
int ret
Set to GNUNET_SYSERR to indicate parse errors.
Definition: hello.c:63
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
Context for add_address_to_hello().
Definition: hello.c:53
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
void * cls
Closure for all of the callbacks.
GNUNET_TRANSPORT_StringToAddress string_to_address
Function that will be called to convert a string address to binary (numeric conversion only)...
unsigned int counter_added
Counter skipped addresses.
Definition: hello.c:73
size_t GNUNET_HELLO_add_address(const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration, char *target, size_t max)
Copy the given address information into the given buffer using the format of HELLOs.
Definition: hello.c:109
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
An address for communicating with a peer.
#define GNUNET_log(kind,...)
Time for absolute times used by GNUnet, in microseconds.
GNUNET_HELLO_TransportPluginsFind plugins_find
Function for finding transport plugins by name.
Definition: hello.c:78
unsigned int counter_total
Counter.
Definition: hello.c:68
static char * address
GNS address for this phone.
static char * plugin_name
Name of our plugin.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: