GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
gnunet-service-transport_hello.c File Reference

hello management implementation More...

#include "platform.h"
#include "gnunet_constants.h"
#include "gnunet_hello_lib.h"
#include "gnunet_peerinfo_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet-service-transport_hello.h"
#include "gnunet-service-transport.h"
#include "gnunet-service-transport_plugins.h"
Include dependency graph for gnunet-service-transport_hello.c:

Go to the source code of this file.

Data Structures

struct  OwnAddressList
 Entry in linked list of network addresses for ourselves. More...
 
struct  GeneratorContext
 Closure for address_generator(). More...
 

Macros

#define HELLO_REFRESH_PERIOD
 How often do we refresh our HELLO (due to expiration concerns)? More...
 

Functions

static ssize_t address_generator (void *cls, size_t max, void *buf)
 Add an address from the struct OwnAddressList to the buffer. More...
 
static void refresh_hello_task (void *cls)
 Construct our HELLO message from all of the addresses of all of the transports. More...
 
static void refresh_hello ()
 Schedule task to refresh hello (but only if such a task exists already, as otherwise the module might have been shutdown). More...
 
void GST_hello_start (int friend_only, GST_HelloCallback cb, void *cb_cls)
 Initialize the HELLO module. More...
 
void GST_hello_stop ()
 Shutdown the HELLO module. More...
 
const struct GNUNET_MessageHeaderGST_hello_get ()
 Obtain this peers HELLO message. More...
 
void GST_hello_modify_addresses (int addremove, const struct GNUNET_HELLO_Address *address)
 Add or remove an address from this peer's HELLO message. More...
 
int GST_hello_test_address (const struct GNUNET_HELLO_Address *address, struct GNUNET_CRYPTO_EddsaSignature **sig, struct GNUNET_TIME_Absolute **sig_expiration)
 Test if a particular address is one of ours. More...
 

Variables

struct GNUNET_TIME_Relative hello_expiration
 Hello address expiration. More...
 
static struct GNUNET_HELLO_Messageour_hello
 Our HELLO message. More...
 
static GST_HelloCallback hello_cb
 Function to call on HELLO changes. More...
 
static void * hello_cb_cls
 Closure for hello_cb. More...
 
static struct OwnAddressListoal_head
 Head of my addresses. More...
 
static struct OwnAddressListoal_tail
 Tail of my addresses. More...
 
static int friend_option
 Should we use a friend-only HELLO? More...
 
static struct GNUNET_SCHEDULER_Taskhello_task
 Identifier of refresh_hello_task(). More...
 

Detailed Description

hello management implementation

Author
Christian Grothoff

Definition in file gnunet-service-transport_hello.c.

Macro Definition Documentation

◆ HELLO_REFRESH_PERIOD

#define HELLO_REFRESH_PERIOD
Value:
#define GNUNET_TIME_UNIT_HOURS
One hour.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:442

How often do we refresh our HELLO (due to expiration concerns)?

Definition at line 39 of file gnunet-service-transport_hello.c.

Referenced by refresh_hello_task().

Function Documentation

◆ address_generator()

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

Add an address from the struct OwnAddressList to the buffer.

Parameters
clsthe struct GeneratorContext
maxmaximum number of bytes left
bufwhere to write the address
Returns
bytes written or GNUNET_SYSERR to signal the end of the iteration.

Definition at line 152 of file gnunet-service-transport_hello.c.

References GeneratorContext::addr_pos, OwnAddressList::address, GeneratorContext::expiration, GNUNET_HELLO_add_address(), GNUNET_SYSERR, OwnAddressList::next, and ret.

Referenced by refresh_hello_task().

155 {
156  struct GeneratorContext *gc = cls;
157  ssize_t ret;
158 
159  if (NULL == gc->addr_pos)
160  return GNUNET_SYSERR; /* Done */
162  gc->expiration,
163  buf,
164  max);
165  gc->addr_pos = gc->addr_pos->next;
166  return ret;
167 }
struct OwnAddressList * next
This is a doubly-linked list.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char buf[2048]
struct OwnAddressList * addr_pos
Where are we in the DLL?
struct GNUNET_TIME_Absolute expiration
When do addresses expire?
Closure for address_generator().
size_t GNUNET_HELLO_add_address(const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration, char *target, size_t max)
Copy the given address information into the given buffer using the format of HELLOs.
Definition: hello.c:109
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_HELLO_Address * address
The address.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ refresh_hello_task()

static void refresh_hello_task ( void *  cls)
static

Construct our HELLO message from all of the addresses of all of the transports.

Parameters
clsunused

Definition at line 177 of file gnunet-service-transport_hello.c.

References GeneratorContext::addr_pos, address_generator(), GeneratorContext::expiration, friend_option, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free_non_null, GNUNET_HELLO_create(), GNUNET_HELLO_size(), GNUNET_log, GNUNET_NO, GNUNET_PEERINFO_add_peer(), GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, GST_hello_get(), GST_my_identity, GST_peerinfo, GST_stats, hello_cb, hello_cb_cls, hello_expiration, HELLO_REFRESH_PERIOD, oal_head, and GNUNET_PeerIdentity::public_key.

Referenced by GST_hello_start(), and refresh_hello().

178 {
179  struct GeneratorContext gc;
180 
181  hello_task = NULL;
182  gc.addr_pos = oal_head;
184 
188  &gc,
189  friend_option);
191  "Refreshed my %s HELLO, new size is %d\n",
192  (GNUNET_YES == friend_option) ? "friend-only" : "public",
195  gettext_noop ("# refreshed my HELLO"),
196  1,
197  GNUNET_NO);
198  if (NULL != hello_cb)
200  GST_hello_get ());
202  our_hello,
203  NULL,
204  NULL);
205  hello_task =
208  NULL);
209 }
static struct GNUNET_PeerIdentity GST_my_identity
Our public key.
static int friend_option
Should we use a friend-only HELLO?
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
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
static void refresh_hello_task(void *cls)
Construct our HELLO message from all of the addresses of all of the transports.
static struct GNUNET_HELLO_Message * our_hello
Our HELLO message.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static GST_HelloCallback hello_cb
Function to call on HELLO changes.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
static void * hello_cb_cls
Closure for hello_cb.
static ssize_t address_generator(void *cls, size_t max, void *buf)
Add an address from the struct OwnAddressList to the buffer.
Closure for address_generator().
struct GNUNET_MQ_Envelope * GNUNET_PEERINFO_add_peer(struct GNUNET_PEERINFO_Handle *h, const struct GNUNET_HELLO_Message *hello, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Add a host to the persistent list.
Definition: peerinfo_api.c:553
#define HELLO_REFRESH_PERIOD
How often do we refresh our HELLO (due to expiration concerns)?
static struct OwnAddressList * oal_head
Head of my addresses.
const struct GNUNET_MessageHeader * GST_hello_get()
Obtain this peers HELLO message.
struct GNUNET_PEERINFO_Handle * GST_peerinfo
Handle to peerinfo service.
static struct GNUNET_SCHEDULER_Task * hello_task
Identifier of refresh_hello_task().
#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
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_Relative hello_expiration
Hello address expiration.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ refresh_hello()

static void refresh_hello ( )
static

Schedule task to refresh hello (but only if such a task exists already, as otherwise the module might have been shutdown).

Definition at line 218 of file gnunet-service-transport_hello.c.

References GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), and refresh_hello_task().

Referenced by GST_hello_modify_addresses().

219 {
220  if (NULL != hello_task)
221  {
224  NULL);
225  }
226 }
static void refresh_hello_task(void *cls)
Construct our HELLO message from all of the addresses of all of the transports.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
static struct GNUNET_SCHEDULER_Task * hello_task
Identifier of refresh_hello_task().
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_hello_start()

void GST_hello_start ( int  friend_only,
GST_HelloCallback  cb,
void *  cb_cls 
)

Initialize the HELLO module.

Parameters
friend_onlyuse a friend only hello
cbfunction to call whenever our HELLO changes
cb_clsclosure for cb

Definition at line 237 of file gnunet-service-transport_hello.c.

References friend_option, hello_cb, hello_cb_cls, and refresh_hello_task().

Referenced by run().

240 {
241  hello_cb = cb;
242  hello_cb_cls = cb_cls;
243  friend_option = friend_only;
244  refresh_hello_task (NULL);
245 }
static int friend_option
Should we use a friend-only HELLO?
static void refresh_hello_task(void *cls)
Construct our HELLO message from all of the addresses of all of the transports.
static GST_HelloCallback hello_cb
Function to call on HELLO changes.
static void * hello_cb_cls
Closure for hello_cb.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_hello_stop()

void GST_hello_stop ( void  )

Shutdown the HELLO module.

Definition at line 252 of file gnunet-service-transport_hello.c.

References GNUNET_free, GNUNET_SCHEDULER_cancel(), hello_cb, and hello_cb_cls.

Referenced by shutdown_task().

253 {
254  hello_cb = NULL;
255  hello_cb_cls = NULL;
256  if (NULL != hello_task)
257  {
259  hello_task = NULL;
260  }
261  if (NULL != our_hello)
262  {
264  our_hello = NULL;
265  }
266 }
static struct GNUNET_HELLO_Message * our_hello
Our HELLO message.
static GST_HelloCallback hello_cb
Function to call on HELLO changes.
static void * hello_cb_cls
Closure for hello_cb.
static struct GNUNET_SCHEDULER_Task * hello_task
Identifier of refresh_hello_task().
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_hello_get()

const struct GNUNET_MessageHeader* GST_hello_get ( void  )

Obtain this peers HELLO message.

Returns
our HELLO message

Definition at line 275 of file gnunet-service-transport_hello.c.

References our_hello.

Referenced by GST_plugins_load(), handle_client_start(), refresh_hello_task(), and transmit_ping_if_allowed().

276 {
277  return (const struct GNUNET_MessageHeader *) our_hello;
278 }
static struct GNUNET_HELLO_Message * our_hello
Our HELLO message.
Header for all communications.
Here is the caller graph for this function:

◆ GST_hello_modify_addresses()

void GST_hello_modify_addresses ( int  addremove,
const struct GNUNET_HELLO_Address address 
)

Add or remove an address from this peer's HELLO message.

Parameters
addremoveGNUNET_YES to add, GNUNET_NO to remove
addressaddress to add or remove

Definition at line 288 of file gnunet-service-transport_hello.c.

References OwnAddressList::address, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_address_cmp(), GNUNET_HELLO_address_copy(), GNUNET_HELLO_address_free, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_YES, GST_plugins_a2s(), OwnAddressList::next, OwnAddressList::rc, and refresh_hello().

Referenced by plugin_env_address_change_notification().

290 {
291  struct OwnAddressList *al;
292 
294  (GNUNET_YES == addremove)
295  ? "Adding `%s' to the set of our addresses\n"
296  : "Removing `%s' from the set of our addresses\n",
297  GST_plugins_a2s (address));
298  GNUNET_assert (NULL != address);
299  for (al = oal_head; al != NULL; al = al->next)
300  if (0 == GNUNET_HELLO_address_cmp (address, al->address))
301  break;
302  if (GNUNET_NO == addremove)
303  {
304  if (NULL == al)
305  {
306  /* address to be removed not found!? */
307  GNUNET_break (0);
308  return;
309  }
310  al->rc--;
311  if (0 != al->rc)
312  return; /* RC not yet zero */
314  oal_tail,
315  al);
317  GNUNET_free (al);
318  refresh_hello ();
319  return;
320  }
321  if (NULL != al)
322  {
323  /* address added twice or more */
324  al->rc++;
325  return;
326  }
327  al = GNUNET_new (struct OwnAddressList);
328  al->rc = 1;
330  oal_tail,
331  al);
332  al->address = GNUNET_HELLO_address_copy (address);
333  refresh_hello ();
334 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct OwnAddressList * next
This is a doubly-linked list.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void refresh_hello()
Schedule task to refresh hello (but only if such a task exists already, as otherwise the module might...
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
static struct OwnAddressList * oal_tail
Tail of my addresses.
const char * GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
Convert a given address to a human-readable format.
static struct OwnAddressList * oal_head
Head of my addresses.
struct GNUNET_HELLO_Address * address
The address.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
#define GNUNET_log(kind,...)
Entry in linked list of network addresses for ourselves.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_HELLO_address_free(addr)
Free an address.
unsigned int rc
How often has this address been added/removed? Used as some plugins may learn the same external addre...
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_hello_test_address()

int GST_hello_test_address ( const struct GNUNET_HELLO_Address address,
struct GNUNET_CRYPTO_EddsaSignature **  sig,
struct GNUNET_TIME_Absolute **  sig_expiration 
)

Test if a particular address is one of ours.

Parameters
addressaddress to test
siglocation where to cache PONG signatures for this address [set]
sig_expirationhow long until the current 'sig' expires? (ZERO if sig was never created) [set]
Returns
GNUNET_YES if this is one of our addresses, GNUNET_NO if not

Definition at line 348 of file gnunet-service-transport_hello.c.

References OwnAddressList::address, GNUNET_HELLO_address_cmp(), GNUNET_NO, GNUNET_YES, OwnAddressList::next, OwnAddressList::pong_sig_expires, and OwnAddressList::pong_signature.

Referenced by GST_validation_handle_ping().

351 {
352  struct OwnAddressList *al;
353 
354  for (al = oal_head; al != NULL; al = al->next)
355  if (0 == GNUNET_HELLO_address_cmp (address,
356  al->address))
357  {
358  *sig = &al->pong_signature;
359  *sig_expiration = &al->pong_sig_expires;
360  return GNUNET_YES;
361  }
362  *sig = NULL;
363  *sig_expiration = NULL;
364  return GNUNET_NO;
365 }
struct OwnAddressList * next
This is a doubly-linked list.
#define GNUNET_NO
Definition: gnunet_common.h:78
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
struct GNUNET_TIME_Absolute pong_sig_expires
How long until the current signature expires? (ZERO if the signature was never created).
static struct OwnAddressList * oal_head
Head of my addresses.
struct GNUNET_CRYPTO_EddsaSignature pong_signature
Signature for a 'struct TransportPongMessage' for this address.
struct GNUNET_HELLO_Address * address
The address.
Entry in linked list of network addresses for ourselves.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ hello_expiration

struct GNUNET_TIME_Relative hello_expiration

Hello address expiration.

Definition at line 55 of file gnunet-service-dht.c.

Referenced by refresh_hello_task(), run(), and transmit_our_hello().

◆ our_hello

struct GNUNET_HELLO_Message* our_hello
static

Our HELLO message.

Definition at line 92 of file gnunet-service-transport_hello.c.

Referenced by GST_hello_get().

◆ hello_cb

GST_HelloCallback hello_cb
static

Function to call on HELLO changes.

Definition at line 97 of file gnunet-service-transport_hello.c.

Referenced by GST_hello_start(), GST_hello_stop(), and refresh_hello_task().

◆ hello_cb_cls

void* hello_cb_cls
static

Closure for hello_cb.

Definition at line 102 of file gnunet-service-transport_hello.c.

Referenced by GST_hello_start(), GST_hello_stop(), and refresh_hello_task().

◆ oal_head

struct OwnAddressList* oal_head
static

Head of my addresses.

Definition at line 107 of file gnunet-service-transport_hello.c.

Referenced by refresh_hello_task().

◆ oal_tail

struct OwnAddressList* oal_tail
static

Tail of my addresses.

Definition at line 112 of file gnunet-service-transport_hello.c.

◆ friend_option

int friend_option
static

Should we use a friend-only HELLO?

Definition at line 117 of file gnunet-service-transport_hello.c.

Referenced by GST_hello_start(), and refresh_hello_task().

◆ hello_task

struct GNUNET_SCHEDULER_Task* hello_task
static

Identifier of refresh_hello_task().

Definition at line 122 of file gnunet-service-transport_hello.c.