GNUnet  0.19.4
gnunet-service-transport_hello.c File Reference

hello management implementation More...

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:484

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

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

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.

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 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char buf[2048]
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
@ GNUNET_SYSERR
#define max(x, y)
Closure for address_generator().
struct GNUNET_TIME_Absolute expiration
When do addresses expire?
struct OwnAddressList * addr_pos
Where are we in the DLL?
struct GNUNET_HELLO_Address * address
The address.
struct OwnAddressList * next
This is a doubly-linked list.

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

Referenced by refresh_hello_task().

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.

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 }
#define gettext_noop(String)
Definition: gettext.h:70
static struct GNUNET_PeerIdentity GST_my_identity
Our public key.
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
struct GNUNET_PEERINFO_Handle * GST_peerinfo
Handle to peerinfo service.
static int friend_option
Should we use a friend-only HELLO?
static ssize_t address_generator(void *cls, size_t max, void *buf)
Add an address from the struct OwnAddressList to the buffer.
struct GNUNET_TIME_Relative hello_expiration
Hello address expiration.
static GST_HelloCallback hello_cb
Function to call on HELLO changes.
static struct GNUNET_SCHEDULER_Task * hello_task
Identifier of refresh_hello_task().
static struct GNUNET_HELLO_Message * our_hello
Our HELLO message.
#define HELLO_REFRESH_PERIOD
How often do we refresh our HELLO (due to expiration concerns)?
static void refresh_hello_task(void *cls)
Construct our HELLO message from all of the addresses of all of the transports.
static void * hello_cb_cls
Closure for hello_cb.
static struct OwnAddressList * oal_head
Head of my addresses.
const struct GNUNET_MessageHeader * GST_hello_get()
Obtain this peers HELLO message.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:630
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_log(kind,...)
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
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:530
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:1272
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
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:316
struct GNUNET_CRYPTO_EddsaPublicKey public_key

References GeneratorContext::addr_pos, address_generator(), GeneratorContext::expiration, friend_option, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, 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, hello_task, oal_head, our_hello, and GNUNET_PeerIdentity::public_key.

Referenced by GST_hello_start(), and refresh_hello().

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.

219 {
220  if (NULL != hello_task)
221  {
224  NULL);
225  }
226 }
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:1299
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975

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

Referenced by GST_hello_modify_addresses().

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.

240 {
241  hello_cb = cb;
242  hello_cb_cls = cb_cls;
243  friend_option = friend_only;
244  refresh_hello_task (NULL);
245 }

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

Referenced by run().

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.

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 }

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

Referenced by shutdown_task().

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.

276 {
277  return (const struct GNUNET_MessageHeader *) our_hello;
278 }
Header for all communications.

References our_hello.

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

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.

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",
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);
333  refresh_hello ();
334 }
static char * address
GNS address for this phone.
static struct OwnAddressList * oal_tail
Tail of my addresses.
static void refresh_hello()
Schedule task to refresh hello (but only if such a task exists already, as otherwise the module might...
const char * GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
Convert a given address to a human-readable format.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_HELLO_address_free(addr)
Free an address.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:99
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:112
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Entry in linked list of network addresses for ourselves.
unsigned int rc
How often has this address been added/removed? Used as some plugins may learn the same external addre...

References address, 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, oal_head, oal_tail, OwnAddressList::rc, and refresh_hello().

Referenced by plugin_env_address_change_notification().

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
addressthe address 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 338 of file gnunet-service-transport_hello.c.

341 {
342  struct OwnAddressList *al;
343 
344  for (al = oal_head; al != NULL; al = al->next)
346  al->address))
347  {
348  *sig = &al->pong_signature;
349  *sig_expiration = &al->pong_sig_expires;
350  return GNUNET_YES;
351  }
352  *sig = NULL;
353  *sig_expiration = NULL;
354  return GNUNET_NO;
355 }
struct GNUNET_CRYPTO_EddsaSignature pong_signature
Signature for a 'struct TransportPongMessage' for this address.
struct GNUNET_TIME_Absolute pong_sig_expires
How long until the current signature expires? (ZERO if the signature was never created).

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

Referenced by GST_validation_handle_ping().

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
extern

Hello address expiration.

Definition at line 397 of file gnunet-service-transport.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(), GST_hello_stop(), and refresh_hello_task().

◆ 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 GST_hello_modify_addresses(), GST_hello_test_address(), and 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.

Referenced by GST_hello_modify_addresses().

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

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