GNUnet  0.10.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 268 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 350 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 439 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.

68  {
73 
79 };
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
Final status code.
Definition: gnunet-arm.c:89
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 87 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().

88 {
89  if (GNUNET_YES == ntohl(h->friend_only))
90  return GNUNET_YES;
91  return GNUNET_NO;
92 }
#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 107 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().

111 {
112  uint16_t alen;
113  size_t slen;
114  struct GNUNET_TIME_AbsoluteNBO exp;
115 
116  slen = strlen(address->transport_name) + 1;
117  if (slen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO) +
118  address->address_length > max)
119  return 0;
120  exp = GNUNET_TIME_absolute_hton(expiration);
121  alen = htons((uint16_t)address->address_length);
122  GNUNET_memcpy(target, address->transport_name, slen);
123  GNUNET_memcpy(&target[slen], &alen, sizeof(uint16_t));
124  slen += sizeof(uint16_t);
125  GNUNET_memcpy(&target[slen], &exp, sizeof(struct GNUNET_TIME_AbsoluteNBO));
126  slen += sizeof(struct GNUNET_TIME_AbsoluteNBO);
127  GNUNET_memcpy(&target[slen], address->address, address->address_length);
128  slen += address->address_length;
129  return slen;
130 }
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:655
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 202 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().

206 {
207  char buffer[GNUNET_MAX_MESSAGE_SIZE - 1 - 256 -
208  sizeof(struct GNUNET_HELLO_Message)];
209  size_t max;
210  size_t used;
211  size_t ret;
212  struct GNUNET_HELLO_Message *hello;
213 
214  GNUNET_assert(NULL != public_key);
216  (GNUNET_NO == friend_only));
217  max = sizeof(buffer);
218  used = 0;
219  if (NULL != addrgen)
220  {
221  while (GNUNET_SYSERR != (ret = addrgen(addrgen_cls,
222  max,
223  &buffer[used])))
224  {
225  max -= ret;
226  used += ret;
227  }
228  }
229  hello = GNUNET_malloc(sizeof(struct GNUNET_HELLO_Message) + used);
230  hello->header.type = htons(GNUNET_MESSAGE_TYPE_HELLO);
231  hello->header.size = htons(sizeof(struct GNUNET_HELLO_Message) + used);
232  hello->friend_only = htonl(friend_only);
233  hello->publicKey = *public_key;
234  GNUNET_memcpy(&hello[1],
235  buffer,
236  used);
237  return hello;
238 }
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.
#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...
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 643 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().

644 {
645  uint16_t ret = ntohs(hello->header.size);
646 
647  if ((ret < sizeof(struct GNUNET_HELLO_Message)) ||
648  (ntohs(hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
649  return 0;
650  return ret;
651 }
A HELLO message is used to exchange information about transports with other peers.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 519 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().

521 {
522  struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 };
523  int friend_only;
524 
525  if (h1->friend_only != h2->friend_only)
526  friend_only = GNUNET_YES; /* One of the HELLOs is friend only */
527  else
528  friend_only = ntohl(h1->friend_only); /* Both HELLO's have the same type */
529 
530  return GNUNET_HELLO_create(&h1->publicKey,
531  &merge_addr,
532  &mc,
533  friend_only);
534 }
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:202
const struct GNUNET_HELLO_Message * h1
First HELLO we are merging.
Definition: hello.c:388
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:478
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:393
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 824 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().

827 {
828  struct EqualsContext ec;
829 
830  if (h1->header.type != h2->header.type)
832  if (0 !=
834  &h2->publicKey))
836  ec.expiration_limit = now;
837  ec.result = GNUNET_TIME_UNIT_FOREVER_ABS;
838  ec.ref = h2;
840  GNUNET_NO,
841  &find_matching,
842  &ec);
843  if (ec.result.abs_value_us == GNUNET_TIME_UNIT_ZERO.rel_value_us)
844  return ec.result;
845  ec.ref = h1;
847  GNUNET_NO,
848  &find_matching,
849  &ec);
850  return ec.result;
851 }
#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:252
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:782
#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:699
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 882 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().

883 {
884  struct GNUNET_TIME_Absolute ret;
885 
888  GNUNET_NO,
890  &ret);
891  return ret;
892 }
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
#define GNUNET_NO
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:864
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:252
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 252 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().

256 {
258  uint16_t msize;
259  struct GNUNET_HELLO_Message *ret;
260  const char *inptr;
261  size_t insize;
262  size_t esize;
263  size_t wpos;
264  char *woff;
265  uint16_t alen;
267  int iret;
268 
269  msize = GNUNET_HELLO_size(msg);
270  if ((msize < sizeof(struct GNUNET_HELLO_Message)) ||
271  (ntohs(msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
272  {
273  GNUNET_break_op(0);
274  return NULL;
275  }
276  ret = NULL;
277  if (return_modified)
278  {
279  ret = GNUNET_malloc(msize);
280  GNUNET_memcpy(ret,
281  msg,
282  msize);
283  }
284  inptr = (const char *)&msg[1];
285  insize = msize - sizeof(struct GNUNET_HELLO_Message);
286  wpos = 0;
287  woff = (NULL != ret) ? (char *)&ret[1] : NULL;
288  address.peer.public_key = msg->publicKey;
290  "HELLO has %u bytes of address data\n",
291  (unsigned int)insize);
292 
293  while (insize > 0)
294  {
295  esize = get_hello_address_size(inptr,
296  insize,
297  &alen);
298  if (0 == esize)
299  {
300  GNUNET_break(0);
302  return NULL;
303  }
304  /* need GNUNET_memcpy() due to possibility of misalignment */
306  &inptr[esize - alen - sizeof(struct GNUNET_TIME_AbsoluteNBO)],
307  sizeof(struct GNUNET_TIME_AbsoluteNBO));
308  address.address = &inptr[esize - alen];
309  address.address_length = alen;
310  address.transport_name = inptr;
312  iret = it(it_cls,
313  &address,
315  if (GNUNET_SYSERR == iret)
316  break;
317  if ((GNUNET_OK == iret) &&
318  (NULL != ret))
319  {
320  /* copy address over */
321  GNUNET_memcpy(woff,
322  inptr,
323  esize);
324  woff += esize;
325  wpos += esize;
326  }
327  insize -= esize;
328  inptr += esize;
329  }
330  if (NULL != ret)
331  ret->header.size = ntohs(sizeof(struct GNUNET_HELLO_Message) + wpos);
332  return ret;
333 }
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:142
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:671
static void expire(void *cls)
Expire a PooledConnection object.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#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...
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:643
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 617 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.

622 {
623  struct DeltaContext dc;
624 
625  dc.expiration_limit = expiration_limit;
626  dc.it = it;
627  dc.it_cls = it_cls;
628  dc.old_hello = old_hello;
629  GNUNET_assert(NULL ==
631  GNUNET_NO,
632  &delta_match,
633  &dc));
634 }
#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:541
GNUNET_HELLO_AddressIterator it
Function to call on addresses that are indeed new.
Definition: hello.c:550
#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:561
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:252
void * it_cls
Closure for it.
Definition: hello.c:555
struct GNUNET_TIME_Absolute expiration_limit
We should ignore addresses that expire before this time.
Definition: hello.c:545
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:578
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 662 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().

664 {
665  uint16_t ret = ntohs(hello->header.size);
666 
667  if ((ret < sizeof(struct GNUNET_HELLO_Message)) ||
668  (ntohs(hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
669  return GNUNET_SYSERR;
670  peer->public_key = hello->publicKey;
671  return GNUNET_OK;
672 }
A HELLO message is used to exchange information about transports with other peers.
#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...
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 684 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().

685 {
686  uint16_t ret = ntohs(hello->header.size);
687 
688  if ((ret < sizeof(struct GNUNET_HELLO_Message)) ||
689  (ntohs(hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
690  return NULL;
691 
692  return &hello->header;
693 }
A HELLO message is used to exchange information about transports with other peers.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 1020 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().

1022 {
1024  char *pkey;
1025 
1026  ctx.plugins_find = plugins_find;
1028  GNUNET_asprintf(&ctx.uri,
1029  "%s%s",
1033  pkey);
1034  GNUNET_free(pkey);
1036  GNUNET_NO,
1038  &ctx);
1039  return ctx.uri;
1040 }
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:949
#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:45
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:252
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:367
#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:87
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 1205 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().

1209 {
1210  const char *pks;
1211  const char *exc;
1212  int friend_only;
1214 
1215  if (0 == strncmp(uri,
1217  strlen(GNUNET_HELLO_URI_PREFIX)))
1218  {
1219  pks = &uri[strlen(GNUNET_HELLO_URI_PREFIX)];
1220  friend_only = GNUNET_NO;
1221  }
1222  else if (0 == strncmp(uri,
1225  {
1226  pks = &uri[strlen(GNUNET_FRIEND_HELLO_URI_PREFIX)];
1227  friend_only = GNUNET_YES;
1228  }
1229  else
1230  return GNUNET_SYSERR;
1231  exc = strchr(pks, GNUNET_HELLO_URI_SEP);
1232 
1233  if (GNUNET_OK !=
1235  (NULL == exc) ? strlen(pks) : (exc - pks),
1236  (unsigned char *)pubkey,
1237  sizeof(*pubkey)))
1238  return GNUNET_SYSERR;
1239 
1240  ctx.pos = exc;
1241  ctx.ret = GNUNET_OK;
1242  ctx.counter_total = 0;
1243  ctx.counter_added = 0;
1244  ctx.plugins_find = plugins_find;
1245  *hello = GNUNET_HELLO_create(pubkey,
1247  &ctx,
1248  friend_only);
1249 
1251  "HELLO URI contained %u addresses, added %u addresses\n",
1252  ctx.counter_total,
1253  ctx.counter_added);
1254 
1255  return ctx.ret;
1256 }
#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:1056
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:202
#define GNUNET_HELLO_URI_SEP
Separator used in HELLO URI.
Context for add_address_to_hello().
Definition: hello.c:52
#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:76
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:953
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 65 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().

72 {
73  struct SignedAddress sa;
75  char *sig_str;
76 
77  sa.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS);
78  sa.purpose.size = htonl(sizeof(sa));
79  sa.mono_time = GNUNET_TIME_absolute_hton(mono_time);
80  GNUNET_CRYPTO_hash(address, strlen(address), &sa.h_addr);
82  GNUNET_CRYPTO_eddsa_sign(private_key, &sa.purpose, &sig));
83  sig_str = NULL;
84  (void)GNUNET_STRINGS_base64_encode(&sig, sizeof(sig), &sig_str);
85  *result_size =
86  1 + GNUNET_asprintf((char **)result,
87  "%s;%llu;%u;%s",
88  sig_str,
89  (unsigned long long)mono_time.abs_value_us,
90  (unsigned int)nt,
91  address);
92  GNUNET_free(sig_str);
93 }
#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:989
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:44
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:1856
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:655
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 107 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.

Referenced by watch_cb().

112 {
113  const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key;
114  const char *raws = raw;
115  unsigned long long raw_us;
116  unsigned int raw_nt;
117  const char *sc;
118  const char *sc2;
119  const char *sc3;
120  const char *raw_addr;
121  struct GNUNET_TIME_Absolute raw_mono_time;
122  struct SignedAddress sa;
123  struct GNUNET_CRYPTO_EddsaSignature *sig;
124 
125  if ('\0' != raws[raw_size])
126  {
127  GNUNET_break_op(0);
128  return NULL;
129  }
130  if (NULL == (sc = strchr(raws, ';')))
131  {
132  GNUNET_break_op(0);
133  return NULL;
134  }
135  if (NULL == (sc2 = strchr(sc + 1, ';')))
136  {
137  GNUNET_break_op(0);
138  return NULL;
139  }
140  if (NULL == (sc3 = strchr(sc2 + 1, ';')))
141  {
142  GNUNET_break_op(0);
143  return NULL;
144  }
145  if (1 != sscanf(sc + 1, "%llu;%u;", &raw_us, &raw_nt))
146  {
147  GNUNET_break_op(0);
148  return NULL;
149  }
150  raw_mono_time.abs_value_us = raw_us;
151  sig = NULL;
152  if (sizeof(struct GNUNET_CRYPTO_EddsaSignature) !=
153  GNUNET_STRINGS_base64_decode(raws, sc - raws, (void **)&sig))
154  {
155  GNUNET_break_op(0);
157  return NULL;
158  }
159  raw_addr = sc3 + 1;
160 
161  sa.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS);
162  sa.purpose.size = htonl(sizeof(sa));
163  sa.mono_time = GNUNET_TIME_absolute_hton(raw_mono_time);
164  GNUNET_CRYPTO_hash(raw_addr, strlen(raw_addr), &sa.h_addr);
165  if (GNUNET_YES !=
167  &sa.purpose,
168  sig,
169  public_key))
170  {
171  GNUNET_break_op(0);
172  GNUNET_free(sig);
173  return NULL;
174  }
175  GNUNET_free(sig);
176  *mono_time = raw_mono_time;
177  *nt = (enum GNUNET_NetworkType)raw_nt;
178  return GNUNET_strdup(raw_addr);
179 }
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:1116
#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:44
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:655
#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:
Here is the caller graph for this function:

◆ GNUNET_HELLO_address_to_prefix()

char* GNUNET_HELLO_address_to_prefix ( const char *  address)

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

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

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

References GNUNET_strndup.

Referenced by GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(), and suggest_to_connect().

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