GNUnet  0.11.x
Data Structures | Macros | Typedefs | Enumerations | Functions
Hello library

Helper library for handling HELLOs. More...

Data Structures

struct  GNUNET_HELLO_Address
 An address for communicating with a peer. More...
 
struct  GNUNET_HELLO_Message
 A HELLO message is used to exchange information about transports with other peers. More...
 

Macros

#define GNUNET_HELLO_URI_PREFIX   "gnunet://hello/"
 Prefix that every HELLO URI must start with. More...
 
#define GNUNET_FRIEND_HELLO_URI_PREFIX   "gnunet://friend-hello/"
 Prefix that every FRIEND HELLO URI must start with. More...
 
#define GNUNET_HELLO_URI_SEP   '+'
 Separator used in HELLO URI. More...
 
#define GNUNET_HELLO_address_free(addr)   GNUNET_free (addr)
 Free an address. More...
 

Typedefs

typedef ssize_t(* GNUNET_HELLO_GenerateAddressListCallback) (void *cls, size_t max, void *buf)
 Callback function used to fill a buffer of max bytes with a list of addresses in the format used by HELLOs. More...
 
typedef int(* GNUNET_HELLO_AddressIterator) (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Iterator callback to go over all addresses. More...
 
typedef struct GNUNET_TRANSPORT_PluginFunctions *(* GNUNET_HELLO_TransportPluginsFind) (const char *name)
 Helper function to load/access transport plugins. More...
 

Enumerations

enum  GNUNET_HELLO_AddressInfo { GNUNET_HELLO_ADDRESS_INFO_NONE = 0, GNUNET_HELLO_ADDRESS_INFO_INBOUND = 1 }
 Additional local information about an address. More...
 

Functions

struct GNUNET_HELLO_AddressGNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
 Allocate an address struct. More...
 
struct GNUNET_HELLO_AddressGNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address)
 Copy an address struct. More...
 
int GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
 Compare two addresses. More...
 
size_t GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address)
 Get the size of an address struct. More...
 
int GNUNET_HELLO_address_check_option (const struct GNUNET_HELLO_Address *address, enum GNUNET_HELLO_AddressInfo option)
 Check if an address has a local option set. More...
 
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...
 
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...
 
uint16_t GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello)
 Return the size of the given HELLO message. 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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
char * GNUNET_HELLO_extract_address (const void *raw, size_t raw_size, const struct GNUNET_PeerIdentity *pid, enum GNUNET_NetworkType *nt, struct GNUNET_TIME_Absolute *mono_time)
 Check signature and extract address record. 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...
 

Detailed Description

Helper library for handling HELLOs.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_HELLO_URI_PREFIX

#define GNUNET_HELLO_URI_PREFIX   "gnunet://hello/"

Prefix that every HELLO URI must start with.

Definition at line 49 of file gnunet_hello_lib.h.

Referenced by GNUNET_HELLO_compose_uri(), and GNUNET_HELLO_parse_uri().

◆ GNUNET_FRIEND_HELLO_URI_PREFIX

#define GNUNET_FRIEND_HELLO_URI_PREFIX   "gnunet://friend-hello/"

Prefix that every FRIEND HELLO URI must start with.

Definition at line 54 of file gnunet_hello_lib.h.

Referenced by GNUNET_HELLO_compose_uri(), and GNUNET_HELLO_parse_uri().

◆ GNUNET_HELLO_URI_SEP

#define GNUNET_HELLO_URI_SEP   '+'

Separator used in HELLO URI.

Definition at line 59 of file gnunet_hello_lib.h.

Referenced by add_address_to_hello(), add_address_to_uri(), and GNUNET_HELLO_parse_uri().

◆ GNUNET_HELLO_address_free

#define GNUNET_HELLO_address_free (   addr)    GNUNET_free (addr)

Typedef Documentation

◆ GNUNET_HELLO_GenerateAddressListCallback

typedef ssize_t(* GNUNET_HELLO_GenerateAddressListCallback) (void *cls, size_t max, void *buf)

Callback function used to fill a buffer of max bytes with a list of addresses in the format used by HELLOs.

Should use GNUNET_HELLO_add_address() as a helper function.

Parameters
clsclosure
maxmaximum number of bytes that can be written to buf
bufwhere to write the address information
Returns
number of bytes written or 0, GNUNET_SYSERR to signal the end of the iteration.

Definition at line 271 of file gnunet_hello_lib.h.

◆ GNUNET_HELLO_AddressIterator

typedef int(* GNUNET_HELLO_AddressIterator) (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)

Iterator callback to go over all addresses.

Parameters
clsclosure
addressthe address
expirationexpiration time
Returns
GNUNET_OK to keep the address, GNUNET_NO to delete it from the HELLO GNUNET_SYSERR to stop iterating (but keep current address)

Definition at line 353 of file gnunet_hello_lib.h.

◆ GNUNET_HELLO_TransportPluginsFind

typedef struct GNUNET_TRANSPORT_PluginFunctions*( * GNUNET_HELLO_TransportPluginsFind) (const char *name)

Helper function to load/access transport plugins.

FIXME: pass closure!

Parameters
namename of the transport plugin to load
Returns
NULL if a plugin with name name is not known/loadable

Definition at line 442 of file gnunet_hello_lib.h.

Enumeration Type Documentation

◆ GNUNET_HELLO_AddressInfo

Additional local information about an address.

These information are only valid for the local peer and are not serialized when a GNUNET_HELLO_Message is created

Enumerator
GNUNET_HELLO_ADDRESS_INFO_NONE 

No additional information.

GNUNET_HELLO_ADDRESS_INFO_INBOUND 

This is an inbound address and cannot be used to initiate an outbound connection to another peer.

Definition at line 68 of file gnunet_hello_lib.h.

69 {
74 
80 };
This is an inbound address and cannot be used to initiate an outbound connection to another peer...
No additional information.

Function Documentation

◆ GNUNET_HELLO_address_allocate()

struct GNUNET_HELLO_Address* GNUNET_HELLO_address_allocate ( const struct GNUNET_PeerIdentity peer,
const char *  transport_name,
const void *  address,
size_t  address_length,
enum GNUNET_HELLO_AddressInfo  local_info 
)

Allocate an address struct.

Parameters
peerthe peer
transport_nameplugin name
addressbinary address
address_lengthnumber of bytes in address
local_infoadditional local information for the address
Returns
the address struct
Parameters
peerthe peer
transport_nameplugin name
addressbinary address
address_lengthnumber of bytes in 'address'
local_infoadditional local information for the address
Returns
the address struct

Definition at line 73 of file address.c.

References GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, end, GNUNET_malloc, GNUNET_memcpy, GNUNET_HELLO_Address::local_info, peer, GNUNET_HELLO_Address::peer, and GNUNET_HELLO_Address::transport_name.

Referenced by ack_proc(), address_notification(), broadcast_mst_cb(), create_session(), GNUNET_HELLO_address_copy(), handle_helper_message(), handle_response(), handle_tcp_nat_probe(), handle_tcp_welcome(), LIBGNUNET_PLUGIN_TRANSPORT_DONE(), libgnunet_plugin_transport_unix_done(), process_data(), process_udp_message(), read_process_ack(), server_add_address(), server_lookup_connection(), server_notify_external_hostname(), server_remove_address(), tcp_nat_port_map_callback(), udp_nat_port_map_callback(), and unix_demultiplexer().

78 {
79  struct GNUNET_HELLO_Address *addr;
80  size_t slen;
81  char *end;
82 
83  slen = strlen (transport_name) + 1;
84  addr = GNUNET_malloc (sizeof(struct GNUNET_HELLO_Address)
85  + address_length + slen);
86  addr->peer = *peer;
87  addr->address = &addr[1];
89  addr->local_info = local_info;
90  end = (char *) &addr[1];
91  addr->transport_name = &end[address_length];
92  GNUNET_memcpy (end,
93  address,
97  slen);
98  return addr;
99 }
size_t address_length
Number of bytes in address.
enum GNUNET_HELLO_AddressInfo local_info
Extended information about address.
const void * address
Binary representation of the address (plugin-specific).
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * transport_name
Name of the transport plugin enabling the communication using this address.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
An address for communicating with a peer.
static char * address
GNS address for this phone.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the caller graph for this function:

◆ GNUNET_HELLO_address_copy()

struct GNUNET_HELLO_Address* GNUNET_HELLO_address_copy ( const struct GNUNET_HELLO_Address address)

Copy an address struct.

Parameters
addressaddress to copy
Returns
a copy of the address struct

Definition at line 109 of file address.c.

References GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_Address::local_info, GNUNET_HELLO_Address::peer, and GNUNET_HELLO_Address::transport_name.

Referenced by ats_perf_cb(), ats_perf_mon_cb(), create_session(), find_validation_entry(), GNUNET_ATS_address_add(), GST_ats_add_address(), GST_ats_add_inbound_address(), GST_blacklist_test_allowed(), GST_hello_modify_addresses(), http_client_plugin_get_session(), process_peer_monitoring_cb(), resolve_peer_address(), set_alternative_address(), set_primary_address(), test_connection_ok(), udp_plugin_create_session(), and unix_plugin_get_session().

110 {
111  if (NULL == address)
112  return NULL;
113  return GNUNET_HELLO_address_allocate (&address->peer,
114  address->transport_name,
115  address->address,
116  address->address_length,
117  address->local_info);
118 }
size_t address_length
Number of bytes in address.
enum GNUNET_HELLO_AddressInfo local_info
Extended information about address.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
const void * address
Binary representation of the address (plugin-specific).
const char * transport_name
Name of the transport plugin enabling the communication using this address.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_address_cmp()

int GNUNET_HELLO_address_cmp ( const struct GNUNET_HELLO_Address a1,
const struct GNUNET_HELLO_Address a2 
)

Compare two addresses.

Does NOT compare the peer identity, that is assumed already to match!

Parameters
a1first address
a2second address
Returns
0 if the addresses are equal, -1 if a1< a2, 1 if a1> a2.

Does NOT compare the peer identity, that is assumed already to match!

Parameters
a1first address
a2second address
Returns
0 if the addresses are equal, -1 if a1<a2, 1 if a1>a2.

Definition at line 130 of file address.c.

References GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, GNUNET_HELLO_Address::local_info, ret, and GNUNET_HELLO_Address::transport_name.

Referenced by find_address_it(), find_ai_cb(), find_ai_no_session_cb(), find_other_matching(), find_session_id(), get_match_exp(), GST_blacklist_abort_matching(), GST_hello_modify_addresses(), GST_hello_test_address(), lookup_session_it(), process_peer_monitoring_cb(), session_cmp_it(), session_lookup_client_by_address(), session_lookup_it(), set_primary_address(), switch_address_bl_check_cont(), try_run_fast_ats_update(), and validation_entry_match().

132 {
133  int ret;
134 
135  if ((NULL == a1) &&
136  (NULL == a2))
137  return 0;
138  if (NULL == a1)
139  return 1;
140  if (NULL == a2)
141  return -1;
142  ret = strcmp (a1->transport_name, a2->transport_name);
143  if (0 != ret)
144  return ret;
145  if (a1->local_info != a2->local_info)
146  return (((int) a1->local_info) < ((int) a2->local_info)) ? -1 : 1;
147  if (a1->address_length < a2->address_length)
148  return -1;
149  if (a1->address_length > a2->address_length)
150  return 1;
151  return memcmp (a1->address,
152  a2->address,
153  a1->address_length);
154 }
size_t address_length
Number of bytes in address.
enum GNUNET_HELLO_AddressInfo local_info
Extended information about address.
const void * address
Binary representation of the address (plugin-specific).
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
const char * transport_name
Name of the transport plugin enabling the communication using this address.
Here is the caller graph for this function:

◆ GNUNET_HELLO_address_get_size()

size_t GNUNET_HELLO_address_get_size ( const struct GNUNET_HELLO_Address address)

Get the size of an address struct.

Parameters
addressaddress
Returns
the size

Definition at line 55 of file address.c.

56 {
57  return sizeof(struct GNUNET_HELLO_Address) + address->address_length
58  + strlen (address->transport_name) + 1;
59 }
size_t address_length
Number of bytes in address.
const char * transport_name
Name of the transport plugin enabling the communication using this address.
An address for communicating with a peer.

◆ GNUNET_HELLO_address_check_option()

int GNUNET_HELLO_address_check_option ( const struct GNUNET_HELLO_Address address,
enum GNUNET_HELLO_AddressInfo  option 
)

Check if an address has a local option set.

Parameters
addressthe address to check
optionthe respective option to check for
Returns
GNUNET_YES or GNUNET_NO

Definition at line 39 of file address.c.

References GNUNET_NO, GNUNET_YES, and GNUNET_HELLO_Address::local_info.

Referenced by GNUNET_ATS_address_del_session(), GST_ats_add_address(), GST_ats_add_inbound_address(), GST_ats_block_address(), GST_ats_del_session(), GST_neighbours_switch_to_address(), GST_validation_set_address_use(), handle_ats_address_suggestion(), handle_tcp_welcome(), notify_session_monitor(), plugin_env_session_start(), plugin_env_session_start_bl_check_cont(), switch_address_bl_check_cont(), and tcp_plugin_get_session().

41 {
42  if (option == (address->local_info & option))
43  return GNUNET_YES;
44  return GNUNET_NO;
45 }
enum GNUNET_HELLO_AddressInfo local_info
Extended information about address.
#define GNUNET_NO
Definition: gnunet_common.h:78
static char * option
Name of the option.
Definition: gnunet-config.c:38
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the caller graph for this function:

◆ GNUNET_HELLO_is_friend_only()

int GNUNET_HELLO_is_friend_only ( const struct GNUNET_HELLO_Message h)

Return HELLO type.

Parameters
hHELLO Message to test
Returns
GNUNET_YES for friend-only or GNUNET_NO otherwise

Definition at line 89 of file hello.c.

References GNUNET_HELLO_Message::friend_only, GNUNET_NO, and GNUNET_YES.

Referenced by dump_my_hello(), GNUNET_HELLO_compose_uri(), GST_validation_handle_hello(), main(), peerinfo_list_iteration(), print_peer_info(), read_host_file(), update_friend_hello(), and update_hello().

90 {
91  if (GNUNET_YES == ntohl (h->friend_only))
92  return GNUNET_YES;
93  return GNUNET_NO;
94 }
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_YES
Definition: gnunet_common.h:77
uint32_t friend_only
Use in F2F mode: Do not gossip this HELLO message.
Here is the caller graph for this function:

◆ GNUNET_HELLO_add_address()

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.

Parameters
addressaddress to add
expirationexpiration for the address
targetwhere to copy the address
maxmaximum number of bytes to copy to target
Returns
number of bytes copied, 0 if the target buffer was not big enough.
Parameters
addressthe address
expirationexpiration for the address
targetwhere to copy the address
maxmaximum number of bytes to copy to target
Returns
number of bytes copied, 0 if the target buffer was not big enough.

Definition at line 109 of file hello.c.

References GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, GNUNET_memcpy, GNUNET_TIME_absolute_hton(), and GNUNET_HELLO_Address::transport_name.

Referenced by add_address_to_hello(), add_to_buf(), add_valid_peer_address(), address_generator(), and copy_latest().

113 {
114  uint16_t alen;
115  size_t slen;
116  struct GNUNET_TIME_AbsoluteNBO exp;
117 
118  slen = strlen (address->transport_name) + 1;
119  if (slen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO)
120  + address->address_length > max)
121  return 0;
122  exp = GNUNET_TIME_absolute_hton (expiration);
123  alen = htons ((uint16_t) address->address_length);
124  GNUNET_memcpy (target, address->transport_name, slen);
125  GNUNET_memcpy (&target[slen], &alen, sizeof(uint16_t));
126  slen += sizeof(uint16_t);
127  GNUNET_memcpy (&target[slen], &exp, sizeof(struct GNUNET_TIME_AbsoluteNBO));
128  slen += sizeof(struct GNUNET_TIME_AbsoluteNBO);
129  GNUNET_memcpy (&target[slen], address->address, address->address_length);
130  slen += address->address_length;
131  return slen;
132 }
size_t address_length
Number of bytes in address.
const void * address
Binary representation of the address (plugin-specific).
#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. ...
const char * transport_name
Name of the transport plugin enabling the communication using this address.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_create()

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.

If friend only is set to GNUNET_YES we create a FRIEND_HELLO which will not be gossiped to other peers.

Parameters
public_keypublic key to include in the HELLO
addrgencallback to invoke to get addresses
addrgen_clsclosure for addrgen
friend_onlyshould the returned HELLO be only visible to friends?
Returns
the hello message

Definition at line 204 of file hello.c.

References GNUNET_HELLO_Message::friend_only, GNUNET_assert, GNUNET_malloc, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_HELLO, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_HELLO_Message::header, GNUNET_HELLO_Message::publicKey, ret, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by GNUNET_HELLO_merge(), GNUNET_HELLO_parse_uri(), GST_validation_handle_pong(), main(), refresh_hello_task(), and update_friend_hello().

208 {
209  char buffer[GNUNET_MAX_MESSAGE_SIZE - 1 - 256
210  - sizeof(struct GNUNET_HELLO_Message)];
211  size_t max;
212  size_t used;
213  size_t ret;
214  struct GNUNET_HELLO_Message *hello;
215 
216  GNUNET_assert (NULL != public_key);
218  (GNUNET_NO == friend_only));
219  max = sizeof(buffer);
220  used = 0;
221  if (NULL != addrgen)
222  {
223  while (GNUNET_SYSERR != (ret = addrgen (addrgen_cls,
224  max,
225  &buffer[used])))
226  {
227  max -= ret;
228  used += ret;
229  }
230  }
231  hello = GNUNET_malloc (sizeof(struct GNUNET_HELLO_Message) + used);
232  hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO);
233  hello->header.size = htons (sizeof(struct GNUNET_HELLO_Message) + used);
234  hello->friend_only = htonl (friend_only);
235  hello->publicKey = *public_key;
236  GNUNET_memcpy (&hello[1],
237  buffer,
238  used);
239  return hello;
240 }
A HELLO message is used to exchange information about transports with other peers.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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_NO
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_HELLO.
struct GNUNET_CRYPTO_EddsaPublicKey publicKey
The public key of the peer.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
uint32_t friend_only
Use in F2F mode: Do not gossip this HELLO message.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the caller graph for this function:

◆ GNUNET_HELLO_size()

uint16_t GNUNET_HELLO_size ( const struct GNUNET_HELLO_Message hello)

Return the size of the given HELLO message.

Parameters
helloto inspect
Returns
the size, 0 if HELLO is invalid

Definition at line 652 of file hello.c.

References GNUNET_MESSAGE_TYPE_HELLO, GNUNET_HELLO_Message::header, ret, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by add_to_tc(), announce_id(), callback_download(), check_info(), check_notification(), consider_for_advertising(), dht_get_id_handler(), discard_hosts_helper(), dump_my_hello(), find_advertisable_hello(), GCP_set_hello(), GNUNET_HELLO_iterate_addresses(), got_hello(), handle_find_peer(), host_processor(), main(), make_info_message(), make_peer(), offer_hello(), prepare_beacon(), process_hello(), read_host_file(), refresh_hello_task(), schedule_next_hello(), send_hello_beacon(), and update_hello().

653 {
654  uint16_t ret = ntohs (hello->header.size);
655 
656  if ((ret < sizeof(struct GNUNET_HELLO_Message)) ||
657  (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
658  return 0;
659  return ret;
660 }
A HELLO message is used to exchange information about transports with other peers.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_HELLO.
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
Here is the caller graph for this function:

◆ GNUNET_HELLO_merge()

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).

Parameters
h1first HELLO message
h2the second HELLO message
Returns
the combined hello message
Parameters
h1first HELLO message
h2the second HELLO message
Returns
the combined HELLO message

Definition at line 524 of file hello.c.

References GNUNET_HELLO_Message::friend_only, GNUNET_HELLO_create(), GNUNET_YES, MergeContext::h1, MergeContext::h2, merge_addr(), and GNUNET_HELLO_Message::publicKey.

Referenced by consider_for_advertising(), GCP_set_hello(), update_friend_hello(), and update_hello().

526 {
527  struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 };
528  int friend_only;
529 
530  if (h1->friend_only != h2->friend_only)
531  friend_only = GNUNET_YES; /* One of the HELLOs is friend only */
532  else
533  friend_only = ntohl (h1->friend_only); /* Both HELLO's have the same type */
534 
535  return GNUNET_HELLO_create (&h1->publicKey,
536  &merge_addr,
537  &mc,
538  friend_only);
539 }
Closure for merge_pr().
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 transp...
Definition: hello.c:204
const struct GNUNET_HELLO_Message * h1
First HELLO we are merging.
Definition: hello.c:393
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...
Definition: hello.c:483
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
const struct GNUNET_HELLO_Message * h2
Second HELLO we are merging.
Definition: hello.c:398
struct GNUNET_CRYPTO_EddsaPublicKey publicKey
The public key of the peer.
#define GNUNET_YES
Definition: gnunet_common.h:77
uint32_t friend_only
Use in F2F mode: Do not gossip this HELLO message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_equals()

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.

If they only differ in expiration time, the lowest expiration time larger than 'now' where they differ is returned.

Parameters
h1first HELLO message
h2the second HELLO message
nowtime to use for deciding which addresses have expired and should not be considered at all
Returns
absolute time forever if the two HELLOs are totally identical; smallest timestamp >= now if they only differ in timestamps; zero if the some addresses with expirations >= now do not match at all

If they only differ in expiration time, the lowest expiration time larger than now where they differ is returned.

Parameters
h1first HELLO message
h2the second HELLO message
nowtime to use for deciding which addresses have expired and should not be considered at all
Returns
absolute time forever if the two HELLOs are totally identical; smallest timestamp >= now if they only differ in timestamps; zero if the some addresses with expirations >= now do not match at all

Definition at line 834 of file hello.c.

References GNUNET_TIME_Absolute::abs_value_us, EqualsContext::expiration_limit, find_matching(), GNUNET_HELLO_iterate_addresses(), GNUNET_memcmp, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_HELLO_Message::header, GNUNET_HELLO_Message::publicKey, EqualsContext::ref, EqualsContext::result, and GNUNET_MessageHeader::type.

Referenced by consider_for_advertising(), and update_hello().

837 {
838  struct EqualsContext ec;
839 
840  if (h1->header.type != h2->header.type)
842  if (0 !=
843  GNUNET_memcmp (&h1->publicKey,
844  &h2->publicKey))
846  ec.expiration_limit = now;
847  ec.result = GNUNET_TIME_UNIT_FOREVER_ABS;
848  ec.ref = h2;
850  GNUNET_NO,
851  &find_matching,
852  &ec);
853  if (ec.result.abs_value_us == GNUNET_TIME_UNIT_ZERO.rel_value_us)
854  return ec.result;
855  ec.ref = h1;
857  GNUNET_NO,
858  &find_matching,
859  &ec);
860  return ec.result;
861 }
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
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 int find_matching(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Helper function for GNUNET_HELLO_equals().
Definition: hello.c:792
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_HELLO.
struct GNUNET_CRYPTO_EddsaPublicKey publicKey
The public key of the peer.
Context used for comparing HELLOs in GNUNET_HELLO_equals().
Definition: hello.c:708
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_get_last_expiration()

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?

Parameters
msgHELLO to inspect
Returns
time the last address expires, 0 if there are no addresses in the HELLO

Definition at line 892 of file hello.c.

References find_max_expire(), GNUNET_HELLO_iterate_addresses(), GNUNET_NO, GNUNET_TIME_UNIT_ZERO_ABS, msg, and ret.

Referenced by announce_id(), consider_peer_destroy(), got_hello(), and process_hello().

893 {
894  struct GNUNET_TIME_Absolute ret;
895 
898  GNUNET_NO,
900  &ret);
901  return ret;
902 }
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
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.
Definition: hello.c:874
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
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:

◆ GNUNET_HELLO_iterate_addresses()

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.

Parameters
msgHELLO to iterate over; client does not need to have verified that msg is well-formed (beyond starting with a GNUNET_MessageHeader of the right type).
return_modifiedif a modified copy should be returned, otherwise NULL will be returned
ititerator to call on each address
it_clsclosure for it
Returns
the modified HELLO or NULL
Parameters
msgHELLO to iterate over
return_modifiedif a modified copy should be returned, otherwise NULL will be returned
ititerator to call on each address
it_clsclosure for it
Returns
modified HELLO message

Definition at line 254 of file hello.c.

References GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, get_hello_address_size(), GNUNET_break, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free_non_null, GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_HELLO_size(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_HELLO, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_ntoh(), GNUNET_HELLO_Message::header, GNUNET_HELLO_Address::local_info, GNUNET_HELLO_Address::peer, GNUNET_PeerIdentity::public_key, GNUNET_HELLO_Message::publicKey, ret, GNUNET_MessageHeader::size, GNUNET_HELLO_Address::transport_name, and GNUNET_MessageHeader::type.

Referenced by add_from_hello(), consider_for_advertising(), copy_latest(), delta_match(), discard_hosts_helper(), dump_my_hello(), find_matching(), GNUNET_HELLO_compose_uri(), GNUNET_HELLO_equals(), GNUNET_HELLO_get_last_expiration(), GNUNET_HELLO_iterate_new_addresses(), GST_validation_handle_hello(), hello_update_cb(), host_processor(), merge_addr(), peerinfo_list_iteration(), print_peer_info(), process_peerinfo_hello(), read_host_file(), and update_hello().

258 {
260  uint16_t msize;
261  struct GNUNET_HELLO_Message *ret;
262  const char *inptr;
263  size_t insize;
264  size_t esize;
265  size_t wpos;
266  char *woff;
267  uint16_t alen;
269  int iret;
270 
271  msize = GNUNET_HELLO_size (msg);
272  if ((msize < sizeof(struct GNUNET_HELLO_Message)) ||
273  (ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
274  {
275  GNUNET_break_op (0);
276  return NULL;
277  }
278  ret = NULL;
279  if (return_modified)
280  {
281  ret = GNUNET_malloc (msize);
282  GNUNET_memcpy (ret,
283  msg,
284  msize);
285  }
286  inptr = (const char *) &msg[1];
287  insize = msize - sizeof(struct GNUNET_HELLO_Message);
288  wpos = 0;
289  woff = (NULL != ret) ? (char *) &ret[1] : NULL;
290  address.peer.public_key = msg->publicKey;
292  "HELLO has %u bytes of address data\n",
293  (unsigned int) insize);
294 
295  while (insize > 0)
296  {
297  esize = get_hello_address_size (inptr,
298  insize,
299  &alen);
300  if (0 == esize)
301  {
302  GNUNET_break (0);
303  GNUNET_free_non_null (ret);
304  return NULL;
305  }
306  /* need GNUNET_memcpy() due to possibility of misalignment */
308  &inptr[esize - alen - sizeof(struct
310  sizeof(struct GNUNET_TIME_AbsoluteNBO));
311  address.address = &inptr[esize - alen];
312  address.address_length = alen;
313  address.transport_name = inptr;
315  iret = it (it_cls,
316  &address,
318  if (GNUNET_SYSERR == iret)
319  break;
320  if ((GNUNET_OK == iret) &&
321  (NULL != ret))
322  {
323  /* copy address over */
324  GNUNET_memcpy (woff,
325  inptr,
326  esize);
327  woff += esize;
328  wpos += esize;
329  }
330  insize -= esize;
331  inptr += esize;
332  }
333  if (NULL != ret)
334  ret->header.size = ntohs (sizeof(struct GNUNET_HELLO_Message) + wpos);
335  return ret;
336 }
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.
Definition: hello.c:144
A HELLO message is used to exchange information about transports with other peers.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
static void expire(void *cls)
Expire a PooledConnection object.
#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
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
No additional information.
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_HELLO.
An address for communicating with a peer.
#define GNUNET_log(kind,...)
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:652
struct GNUNET_CRYPTO_EddsaPublicKey publicKey
The public key of the peer.
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
static char * address
GNS address for this phone.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_iterate_new_addresses()

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.

Note that if the address is present in old_hello but the expiration time in new_hello is more recent, the iterator is also called.

Parameters
new_helloa HELLO message
old_helloa HELLO message
expiration_limitignore addresses in old_hello that expired before the given time stamp
ititerator to call on each address
it_clsclosure for it

Note that if the address is present in old_hello but the expiration time in new_hello is more recent, the iterator is also called.

Parameters
new_helloa HELLO message
old_helloa HELLO message
expiration_limitignore addresses in old_hello that expired before the given time stamp
ititerator to call on each address
it_clsclosure for it

Definition at line 623 of file hello.c.

References delta_match(), DeltaContext::expiration_limit, GNUNET_assert, GNUNET_HELLO_iterate_addresses(), GNUNET_NO, DeltaContext::it, DeltaContext::it_cls, and DeltaContext::old_hello.

631 {
632  struct DeltaContext dc;
633 
634  dc.expiration_limit = expiration_limit;
635  dc.it = it;
636  dc.it_cls = it_cls;
637  dc.old_hello = old_hello;
638  GNUNET_assert (NULL ==
640  GNUNET_NO,
641  &delta_match,
642  &dc));
643 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Context used in GNUNET_HELLO_iterate_new_addresses() to figure out which addresses are in fact &#39;new&#39;...
Definition: hello.c:546
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
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
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
static int delta_match(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Check if the given address is &#39;new&#39;, and if so, call the iterator.
Definition: hello.c:584
static struct GNUNET_FS_DownloadContext * dc
Here is the call graph for this function:

◆ GNUNET_HELLO_get_id()

int GNUNET_HELLO_get_id ( const struct GNUNET_HELLO_Message hello,
struct GNUNET_PeerIdentity peer 
)

Get the peer identity from a HELLO message.

Parameters
hellothe hello message
peerwhere to store the peer's identity
Returns
GNUNET_SYSERR if the HELLO was malformed

Definition at line 671 of file hello.c.

References GNUNET_MESSAGE_TYPE_HELLO, GNUNET_OK, GNUNET_SYSERR, GNUNET_HELLO_Message::header, GNUNET_PeerIdentity::public_key, GNUNET_HELLO_Message::publicKey, ret, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by add_valid_address(), block_plugin_dht_evaluate(), block_plugin_dht_get_key(), check_hello(), check_info(), consider_for_advertising(), get_hello(), GNUNET_PEERINFO_add_peer(), GNUNET_TRANSPORT_offer_hello(), GST_validation_handle_hello(), handle_dht_p2p_result(), handle_hello(), hello_callback(), hosts_directory_scan_callback(), main(), process_data(), and update_friend_hello().

673 {
674  uint16_t ret = ntohs (hello->header.size);
675 
676  if ((ret < sizeof(struct GNUNET_HELLO_Message)) ||
677  (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
678  return GNUNET_SYSERR;
679  peer->public_key = hello->publicKey;
680  return GNUNET_OK;
681 }
A HELLO message is used to exchange information about transports with other peers.
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
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_HELLO.
struct GNUNET_CRYPTO_EddsaPublicKey publicKey
The public key of the peer.
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the caller graph for this function:

◆ GNUNET_HELLO_get_header()

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.

Parameters
hellothe hello message
Returns
header or NULL if the HELLO was malformed

Definition at line 693 of file hello.c.

References GNUNET_MESSAGE_TYPE_HELLO, GNUNET_HELLO_Message::header, ret, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by GCP_set_hello().

694 {
695  uint16_t ret = ntohs (hello->header.size);
696 
697  if ((ret < sizeof(struct GNUNET_HELLO_Message)) ||
698  (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
699  return NULL;
700 
701  return &hello->header;
702 }
A HELLO message is used to exchange information about transports with other peers.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_HELLO.
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
Here is the caller graph for this function:

◆ GNUNET_HELLO_compose_uri()

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.

Parameters
helloHello message
plugins_findFunction to find transport plugins by name
Returns
Hello URI string

Definition at line 1029 of file hello.c.

References add_address_to_uri(), GNUNET_asprintf(), GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_free, GNUNET_FRIEND_HELLO_URI_PREFIX, GNUNET_HELLO_is_friend_only(), GNUNET_HELLO_iterate_addresses(), GNUNET_HELLO_URI_PREFIX, GNUNET_NO, GNUNET_YES, pkey, GNUNET_HELLO_ComposeUriContext::plugins_find, GNUNET_HELLO_Message::publicKey, and GNUNET_HELLO_ComposeUriContext::uri.

Referenced by print_my_uri().

1031 {
1033  char *pkey;
1034 
1035  ctx.plugins_find = plugins_find;
1037  GNUNET_asprintf (&ctx.uri,
1038  "%s%s",
1042  pkey);
1043  GNUNET_free (pkey);
1045  GNUNET_NO,
1047  &ctx);
1048  return ctx.uri;
1049 }
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".
Definition: hello.c:958
#define GNUNET_FRIEND_HELLO_URI_PREFIX
Prefix that every FRIEND HELLO URI must start with.
static char * pkey
Public key of the zone to look in, in ASCII.
#define GNUNET_NO
Definition: gnunet_common.h:78
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
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
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:365
#define GNUNET_HELLO_URI_PREFIX
Prefix that every HELLO URI must start with.
int GNUNET_HELLO_is_friend_only(const struct GNUNET_HELLO_Message *h)
Return HELLO type.
Definition: hello.c:89
Context used for building our own URI.
Definition: hello.c:36
struct GNUNET_CRYPTO_EddsaPublicKey publicKey
The public key of the peer.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_parse_uri()

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.

Parameters
uriURI string to parse
pubkeyPointer to struct where public key is parsed
helloPointer to struct where hello message is parsed
plugins_findFunction to find transport plugins by name
Returns
GNUNET_OK on success, GNUNET_SYSERR if the URI was invalid, GNUNET_NO on other errors

Definition at line 1217 of file hello.c.

References add_address_to_hello(), GNUNET_HELLO_ParseUriContext::counter_added, GNUNET_HELLO_ParseUriContext::counter_total, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FRIEND_HELLO_URI_PREFIX, GNUNET_HELLO_create(), GNUNET_HELLO_URI_PREFIX, GNUNET_HELLO_URI_SEP, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_YES, GNUNET_HELLO_ComposeUriContext::plugins_find, GNUNET_HELLO_ParseUriContext::plugins_find, GNUNET_HELLO_ParseUriContext::pos, and GNUNET_HELLO_ParseUriContext::ret.

Referenced by parse_hello_uri().

1221 {
1222  const char *pks;
1223  const char *exc;
1224  int friend_only;
1226 
1227  if (0 == strncmp (uri,
1229  strlen (GNUNET_HELLO_URI_PREFIX)))
1230  {
1231  pks = &uri[strlen (GNUNET_HELLO_URI_PREFIX)];
1232  friend_only = GNUNET_NO;
1233  }
1234  else if (0 == strncmp (uri,
1237  {
1238  pks = &uri[strlen (GNUNET_FRIEND_HELLO_URI_PREFIX)];
1239  friend_only = GNUNET_YES;
1240  }
1241  else
1242  return GNUNET_SYSERR;
1243  exc = strchr (pks, GNUNET_HELLO_URI_SEP);
1244 
1245  if (GNUNET_OK !=
1247  (NULL == exc) ? strlen (pks) : (exc - pks),
1248  (unsigned char *) pubkey,
1249  sizeof(*pubkey)))
1250  return GNUNET_SYSERR;
1251 
1252  ctx.pos = exc;
1253  ctx.ret = GNUNET_OK;
1254  ctx.counter_total = 0;
1255  ctx.counter_added = 0;
1256  ctx.plugins_find = plugins_find;
1257  *hello = GNUNET_HELLO_create (pubkey,
1259  &ctx,
1260  friend_only);
1261 
1263  "HELLO URI contained %u addresses, added %u addresses\n",
1264  ctx.counter_total,
1265  ctx.counter_added);
1266 
1267  return ctx.ret;
1268 }
#define GNUNET_FRIEND_HELLO_URI_PREFIX
Prefix that every FRIEND HELLO URI must start with.
static ssize_t add_address_to_hello(void *cls, size_t max, void *buffer)
We&#39;re building a HELLO.
Definition: hello.c:1065
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 transp...
Definition: hello.c:204
#define GNUNET_HELLO_URI_SEP
Separator used in HELLO URI.
Context for add_address_to_hello().
Definition: hello.c:53
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
#define GNUNET_HELLO_URI_PREFIX
Prefix that every HELLO URI must start with.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
GNUNET_HELLO_TransportPluginsFind plugins_find
Function for finding transport plugins by name.
Definition: hello.c:78
int 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:952
Here is the call graph for this function:
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
result[out]where to write address record (allocated)
result_size[out]set 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
result[out]where to write address record (allocated)
result_size[out]set to size of result

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

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_asprintf(), GNUNET_assert, GNUNET_CRYPTO_eddsa_sign(), GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, GNUNET_STRINGS_base64_encode(), GNUNET_TIME_absolute_hton(), GNUNET_YES, SignedAddress::h_addr, SignedAddress::mono_time, GNUNET_CRYPTO_EccSignaturePurpose::purpose, SignedAddress::purpose, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by store_pi().

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.h_addr);
83  GNUNET_CRYPTO_eddsa_sign (private_key, &sa.purpose, &sig));
84  sig_str = NULL;
85  (void) GNUNET_STRINGS_base64_encode (&sig, sizeof(sig), &sig_str);
86  *result_size =
87  1 + GNUNET_asprintf ((char **) result,
88  "%s;%llu;%u;%s",
89  sig_str,
90  (unsigned long long) mono_time.abs_value_us,
91  (unsigned int) nt,
92  address);
93  GNUNET_free (sig_str);
94 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CRYPTO_eddsa_sign(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:987
uint64_t abs_value_us
The actual value.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
static int result
Global testing status.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1855
Binary block we sign when we sign an address.
Definition: hello-ng.c:36
#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS
Signature by a peer affirming that this is one of its addresses (for the given time period)...
an ECC signature using EdDSA.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
static char * address
GNS address for this phone.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELLO_extract_address()

char* GNUNET_HELLO_extract_address ( const void *  raw,
size_t  raw_size,
const struct GNUNET_PeerIdentity pid,
enum GNUNET_NetworkType nt,
struct GNUNET_TIME_Absolute mono_time 
)

Check signature and extract address record.

Parameters
rawraw signed address
raw_sizesize of raw
pidpublic key to use for signature verification
nt[out]set to network type
mono_time[out]when was the address generated
Returns
NULL on error, otherwise the address

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

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break_op, GNUNET_CRYPTO_eddsa_verify(), GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_free_non_null, GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, GNUNET_strdup, GNUNET_STRINGS_base64_decode(), GNUNET_TIME_absolute_hton(), GNUNET_YES, SignedAddress::h_addr, SignedAddress::mono_time, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, SignedAddress::purpose, raw, sc, and GNUNET_CRYPTO_EccSignaturePurpose::size.

113 {
114  const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key;
115  const char *raws = raw;
116  unsigned long long raw_us;
117  unsigned int raw_nt;
118  const char *sc;
119  const char *sc2;
120  const char *sc3;
121  const char *raw_addr;
122  struct GNUNET_TIME_Absolute raw_mono_time;
123  struct SignedAddress sa;
124  struct GNUNET_CRYPTO_EddsaSignature *sig;
125 
126  if ('\0' != raws[raw_size])
127  {
128  GNUNET_break_op (0);
129  return NULL;
130  }
131  if (NULL == (sc = strchr (raws, ';')))
132  {
133  GNUNET_break_op (0);
134  return NULL;
135  }
136  if (NULL == (sc2 = strchr (sc + 1, ';')))
137  {
138  GNUNET_break_op (0);
139  return NULL;
140  }
141  if (NULL == (sc3 = strchr (sc2 + 1, ';')))
142  {
143  GNUNET_break_op (0);
144  return NULL;
145  }
146  if (1 != sscanf (sc + 1, "%llu;%u;", &raw_us, &raw_nt))
147  {
148  GNUNET_break_op (0);
149  return NULL;
150  }
151  raw_mono_time.abs_value_us = raw_us;
152  sig = NULL;
153  if (sizeof(struct GNUNET_CRYPTO_EddsaSignature) !=
154  GNUNET_STRINGS_base64_decode (raws, sc - raws, (void **) &sig))
155  {
156  GNUNET_break_op (0);
157  GNUNET_free_non_null (sig);
158  return NULL;
159  }
160  raw_addr = sc3 + 1;
161 
162  sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS);
163  sa.purpose.size = htonl (sizeof(sa));
164  sa.mono_time = GNUNET_TIME_absolute_hton (raw_mono_time);
165  GNUNET_CRYPTO_hash (raw_addr, strlen (raw_addr), &sa.h_addr);
166  if (GNUNET_YES !=
168  &sa.purpose,
169  sig,
170  public_key))
171  {
172  GNUNET_break_op (0);
173  GNUNET_free (sig);
174  return NULL;
175  }
176  GNUNET_free (sig);
177  *mono_time = raw_mono_time;
178  *nt = (enum GNUNET_NetworkType) raw_nt;
179  return GNUNET_strdup (raw_addr);
180 }
static int raw
raw output
Definition: gnunet-gns.c:55
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
int GNUNET_CRYPTO_eddsa_verify(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:1114
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1920
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
Binary block we sign when we sign an address.
Definition: hello-ng.c:36
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS
Signature by a peer affirming that this is one of its addresses (for the given time period)...
an ECC signature using EdDSA.
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
Here is the call 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 191 of file hello-ng.c.

References GNUNET_strndup.

Referenced by GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(), and suggest_to_connect().

192 {
193  const char *dash;
194 
195  dash = strchr (address, '-');
196  if (NULL == dash)
197  return NULL;
198  return GNUNET_strndup (address, dash - address);
199 }
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
static char * address
GNS address for this phone.
Here is the caller graph for this function: