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"
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_Message * | GNUNET_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_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. 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_Message * | GNUNET_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_MessageHeader * | GNUNET_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... | |
helper library for handling HELLOs
Definition in file hello.c.
|
static |
Get the size of an address entry in a HELLO message.
buf | pointer to the start of the address entry |
max | maximum size of the entry (end of buf) |
ralen | set to the address length |
Definition at line 144 of file hello.c.
References buf, GNUNET_break_op, GNUNET_memcpy, and max.
Referenced by GNUNET_HELLO_iterate_addresses().
|
static |
Store the expiration time of an address that matches the template.
cls | the struct ExpireContext |
address | address to match against the template |
expiration | expiration time of address, to store in cls |
Definition at line 370 of file hello.c.
References address, 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().
|
static |
Append the address address to the buffer from the merge context IF it is more recent than equivalent addresses in other
.
cls | the struct MergeContext |
address | the HELLO address we might copy |
expiration | expiration time for address |
Definition at line 442 of file hello.c.
References GNUNET_TIME_Absolute::abs_value_us, address, ExpireContext::address, expiration, ExpireContext::expiration, ExpireContext::found, get_match_exp(), GNUNET_HELLO_add_address(), GNUNET_HELLO_iterate_addresses(), GNUNET_NO, GNUNET_OK, GNUNET_YES, and mc.
Referenced by merge_addr().
|
static |
Function called to build the HELLO during GNUNET_HELLO_merge() by merging addresses from two original HELLOs.
cls | the struct MergeContext |
max | number of bytes we can write at most in buf |
buf | where to copy the addresses |
Definition at line 483 of file hello.c.
References buf, copy_latest(), GNUNET_HELLO_iterate_addresses(), GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, max, and mc.
Referenced by GNUNET_HELLO_merge().
|
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).
cls | the struct DeltaContext |
address | an address to check whether it is new |
expiration | expiration time for address |
Definition at line 575 of file hello.c.
References GNUNET_TIME_Absolute::abs_value_us, address, ExpireContext::address, dc, expiration, ExpireContext::expiration, ExpireContext::found, get_match_exp(), GNUNET_HELLO_iterate_addresses(), GNUNET_NO, GNUNET_YES, and ret.
Referenced by GNUNET_HELLO_iterate_new_addresses().
|
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
cls | the struct EqualsContext |
address | address from the reference HELLO |
expiration | expiration time for address |
Definition at line 737 of file hello.c.
References GNUNET_TIME_Absolute::abs_value_us, address, EqualsContext::address, expiration, 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().
|
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.
cls | the struct EqualsContext |
address | address to locate |
expiration | expiration time of the current address |
Definition at line 770 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.
|
static |
Iterator to find the time when the last address will expire.
Updates the maximum value stored in cls.
cls | where to store the max, a struct GNUNET_TIME_Absolute |
address | an address (ignored) |
expiration | expiration time for address |
Definition at line 852 of file hello.c.
References expiration, GNUNET_OK, GNUNET_TIME_absolute_max(), and max.
|
static |
GNUnet URIs are of the general form "gnunet://MODULE/IDENTIFIER".
The specific structure of "IDENTIFIER" depends on the module and maybe differentiated 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.
cls | the struct GNUNET_HELLO_ComposeUriContext |
address | address to add |
expiration | expiration time for the address |
Definition at line 936 of file hello.c.
References address, GNUNET_TRANSPORT_PluginFunctions::address_to_string, GNUNET_TRANSPORT_PluginFunctions::cls, ctx, expiration, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_URI_SEP, GNUNET_log, GNUNET_memcpy, GNUNET_OK, GNUNET_strdup, ret, and t.
Referenced by GNUNET_HELLO_compose_uri().
|
static |
We're building a HELLO.
Parse the next address from the parsing context and append it.
cls | the struct GNUNET_HELLO_ParseUriContext |
max | number of bytes available for HELLO construction |
buffer | where to copy the next address (in binary format) |
Definition at line 1043 of file hello.c.
References _, address, GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, GNUNET_TRANSPORT_PluginFunctions::cls, ctx, end, expire, 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, max, plugin_name, ret, GNUNET_TRANSPORT_PluginFunctions::string_to_address, and GNUNET_HELLO_Address::transport_name.
Referenced by GNUNET_HELLO_parse_uri().