GNUnet  0.20.0
gnunet-service-transport_ats.c File Reference

interfacing between transport and ATS service More...

Include dependency graph for gnunet-service-transport_ats.c:

Go to the source code of this file.

Data Structures

struct  AddressInfo
 Information we track for each address known to ATS. More...
 
struct  FindClosure
 Closure for find_ai_cb() and find_ai_no_session_cb(). More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "transport-ats", __VA_ARGS__)
 Log convenience function. More...
 

Functions

static void publish_p2a_stat_update ()
 Provide an update on the p2a map size to statistics. More...
 
static int find_ai_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Find matching address info. More...
 
static struct AddressInfofind_ai (const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
 Find the address information struct for the given address and session. More...
 
static int find_ai_no_session_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Find matching address info, ignoring sessions and expired addresses. More...
 
static struct AddressInfofind_ai_no_session (const struct GNUNET_HELLO_Address *address)
 Find the address information struct for the given address (ignoring sessions) More...
 
int GST_ats_is_known (const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
 Test if ATS knows about this address and session. More...
 
int GST_ats_is_known_no_session (const struct GNUNET_HELLO_Address *address)
 Test if ATS knows about this address. More...
 
static void unblock_address (void *cls)
 The blocking time for an address has expired, allow ATS to suggest it again. More...
 
void GST_ats_block_address (const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
 Temporarily block a valid address for use by ATS for address suggestions. More...
 
void GST_ats_block_reset (const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
 Reset address blocking time. More...
 
void GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, const struct GNUNET_ATS_Properties *prop)
 Notify ATS about a new inbound address. More...
 
void GST_ats_add_address (const struct GNUNET_HELLO_Address *address, const struct GNUNET_ATS_Properties *prop)
 Notify ATS about a new address including the network the address is located in. More...
 
void GST_ats_new_session (const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
 Notify ATS about a new session now existing for the given address. More...
 
static void destroy_ai (struct AddressInfo *ai)
 Release memory used by the given address data. More...
 
void GST_ats_del_session (const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
 Notify ATS that the session (but not the address) of a given address is no longer relevant. More...
 
void GST_ats_update_distance (const struct GNUNET_HELLO_Address *address, uint32_t distance)
 Notify ATS about DV distance change to an address. More...
 
void GST_ats_update_delay (const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Relative delay)
 Notify ATS about delay changes to properties of an address. More...
 
void GST_ats_update_utilization (const struct GNUNET_HELLO_Address *address, uint32_t bps_in, uint32_t bps_out)
 Notify ATS about utilization changes to an address. More...
 
void GST_ats_expire_address (const struct GNUNET_HELLO_Address *address)
 Notify ATS that the address has expired and thus cannot be used any longer. More...
 
void GST_ats_init ()
 Initialize ATS subsystem. More...
 
static int destroy_ai_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Release memory used by the given address data. More...
 
void GST_ats_done ()
 Shutdown ATS subsystem. More...
 

Variables

static struct GNUNET_CONTAINER_MultiPeerMapp2a
 Map from peer identities to one or more struct AddressInfo values for the peer. More...
 
static unsigned int num_blocked
 Number of blocked addresses. More...
 

Detailed Description

interfacing between transport and ATS service

Author
Christian Grothoff

Definition in file gnunet-service-transport_ats.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "transport-ats", __VA_ARGS__)

Log convenience function.

Definition at line 35 of file gnunet-service-transport_ats.c.

Function Documentation

◆ publish_p2a_stat_update()

static void publish_p2a_stat_update ( )
static

Provide an update on the p2a map size to statistics.

This function should be called whenever the p2a map is changed.

Definition at line 134 of file gnunet-service-transport_ats.c.

135 {
137  gettext_noop ("# Addresses given to ATS"),
139  GNUNET_NO);
141  "# blocked addresses",
142  num_blocked,
143  GNUNET_NO);
144 }
#define gettext_noop(String)
Definition: gettext.h:70
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
static struct GNUNET_CONTAINER_MultiPeerMap * p2a
Map from peer identities to one or more struct AddressInfo values for the peer.
static unsigned int num_blocked
Number of blocked addresses.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
@ GNUNET_NO
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.

References gettext_noop, GNUNET_CONTAINER_multipeermap_size(), GNUNET_NO, GNUNET_STATISTICS_set(), GST_stats, num_blocked, and p2a.

Referenced by destroy_ai(), GST_ats_add_address(), GST_ats_add_inbound_address(), GST_ats_block_address(), GST_ats_done(), and unblock_address().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_ai_cb()

static int find_ai_cb ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Find matching address info.

Both the address and the session must match; note that expired addresses are still found (as the session kind-of keeps those alive).

Parameters
clsthe struct FindClosure
keywhich peer is this about
valuethe struct AddressInfo
Returns
GNUNET_YES to continue to iterate, GNUNET_NO if we found the value

Definition at line 158 of file gnunet-service-transport_ats.c.

161 {
162  struct FindClosure *fc = cls;
163  struct AddressInfo *ai = value;
164 
165  if ((0 ==
167  ai->address)) &&
168  (fc->session == ai->session))
169  {
170  fc->ret = ai;
171  return GNUNET_NO;
172  }
173  return GNUNET_YES;
174 }
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static char * value
Value of the record to add/remove.
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:112
@ GNUNET_YES
Information we track for each address known to ATS.
Closure for find_ai_cb() and find_ai_no_session_cb().
struct GNUNET_ATS_Session * session
Session to look for (only used if the address is inbound).
struct AddressInfo * ret
Where to store the result.
const struct GNUNET_HELLO_Address * address
Address to look for.

References FindClosure::address, GNUNET_TRANSPORT_AddressIdentifier::address, ai, GNUNET_HELLO_address_cmp(), GNUNET_NO, GNUNET_YES, FindClosure::ret, FindClosure::session, and value.

Referenced by find_ai().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_ai()

static struct AddressInfo* find_ai ( const struct GNUNET_HELLO_Address address,
struct GNUNET_ATS_Session session 
)
static

Find the address information struct for the given address and session.

Parameters
addressaddress to look for
sessionsession to match for inbound connections
Returns
NULL if this combination is unknown

Definition at line 186 of file gnunet-service-transport_ats.c.

188 {
189  struct FindClosure fc;
190 
191  fc.address = address;
192  fc.session = session;
193  fc.ret = NULL;
195  &address->peer,
196  &find_ai_cb,
197  &fc);
198  return fc.ret;
199 }
static char * address
GNS address for this phone.
static int find_ai_cb(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Find matching address info.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.

References address, FindClosure::address, find_ai_cb(), GNUNET_CONTAINER_multipeermap_get_multiple(), p2a, FindClosure::ret, and FindClosure::session.

Referenced by GST_ats_add_inbound_address(), GST_ats_block_address(), GST_ats_block_reset(), GST_ats_del_session(), GST_ats_is_known(), and GST_ats_new_session().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_ai_no_session_cb()

static int find_ai_no_session_cb ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Find matching address info, ignoring sessions and expired addresses.

Parameters
clsthe struct FindClosure
keywhich peer is this about
valuethe struct AddressInfo
Returns
GNUNET_YES to continue to iterate, GNUNET_NO if we found the value

Definition at line 212 of file gnunet-service-transport_ats.c.

215 {
216  struct FindClosure *fc = cls;
217  struct AddressInfo *ai = value;
218 
219  if (ai->expired)
220  return GNUNET_YES; /* expired do not count here */
221  if (0 ==
223  ai->address))
224  {
225  fc->ret = ai;
226  return GNUNET_NO;
227  }
228  return GNUNET_YES;
229 }

References FindClosure::address, GNUNET_TRANSPORT_AddressIdentifier::address, ai, GNUNET_HELLO_address_cmp(), GNUNET_NO, GNUNET_YES, FindClosure::ret, and value.

Referenced by find_ai_no_session().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_ai_no_session()

static struct AddressInfo* find_ai_no_session ( const struct GNUNET_HELLO_Address address)
static

Find the address information struct for the given address (ignoring sessions)

Parameters
addressaddress to look for
Returns
NULL if this combination is unknown

Definition at line 240 of file gnunet-service-transport_ats.c.

241 {
242  struct FindClosure fc;
243 
244  fc.address = address;
245  fc.session = NULL;
246  fc.ret = NULL;
248  &address->peer,
250  &fc);
251  return fc.ret;
252 }
static int find_ai_no_session_cb(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Find matching address info, ignoring sessions and expired addresses.

References address, FindClosure::address, find_ai_no_session_cb(), GNUNET_CONTAINER_multipeermap_get_multiple(), p2a, FindClosure::ret, and FindClosure::session.

Referenced by GST_ats_add_address(), GST_ats_expire_address(), GST_ats_is_known_no_session(), GST_ats_update_delay(), GST_ats_update_distance(), and GST_ats_update_utilization().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_is_known()

int GST_ats_is_known ( const struct GNUNET_HELLO_Address address,
struct GNUNET_ATS_Session session 
)

Test if ATS knows about this address and session.

Note that even if the address is expired, we return GNUNET_YES if the respective session matches.

Parameters
addressthe address
sessionthe session
Returns
GNUNET_YES if address is known, GNUNET_NO if not.

Definition at line 265 of file gnunet-service-transport_ats.c.

267 {
268  return (NULL != find_ai (address, session)) ? GNUNET_YES : GNUNET_NO;
269 }
static struct AddressInfo * find_ai(const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
Find the address information struct for the given address and session.

References address, find_ai(), GNUNET_NO, GNUNET_YES, and FindClosure::session.

Referenced by GST_neighbours_session_terminated(), send_with_session(), set_primary_address(), and try_run_fast_ats_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_is_known_no_session()

int GST_ats_is_known_no_session ( const struct GNUNET_HELLO_Address address)

Test if ATS knows about this address.

Note that expired addresses do not count.

Parameters
addressthe address
Returns
GNUNET_YES if address is known, GNUNET_NO if not.

Definition at line 280 of file gnunet-service-transport_ats.c.

281 {
282  return (NULL != find_ai_no_session (address))
283  ? GNUNET_YES
284  : GNUNET_NO;
285 }
static struct AddressInfo * find_ai_no_session(const struct GNUNET_HELLO_Address *address)
Find the address information struct for the given address (ignoring sessions)

References address, find_ai_no_session(), GNUNET_NO, and GNUNET_YES.

Referenced by add_valid_address(), cleanup_validation_entry(), find_validation_entry(), and GST_validation_handle_pong().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unblock_address()

static void unblock_address ( void *  cls)
static

The blocking time for an address has expired, allow ATS to suggest it again.

Parameters
clsthe struct AddressInfo of the address to unblock

Definition at line 295 of file gnunet-service-transport_ats.c.

296 {
297  struct AddressInfo *ai = cls;
298 
299  ai->unblock_task = NULL;
301  "Unblocking address %s of peer %s\n",
303  GNUNET_i2s (&ai->address->peer));
305  ai->address,
306  ai->session,
307  &ai->properties);
308  GNUNET_break (NULL != ai->ar);
309  num_blocked--;
311 }
struct GNUNET_ATS_SchedulingHandle * GST_ats
ATS scheduling handle.
static void publish_p2a_stat_update()
Provide an update on the p2a map size to statistics.
#define LOG(kind,...)
Log convenience function.
const char * GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
Convert a given address to a human-readable format.
struct GNUNET_ATS_AddressRecord * GNUNET_ATS_address_add(struct GNUNET_ATS_SchedulingHandle *sh, const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, const struct GNUNET_ATS_Properties *prop)
We have a new address ATS should know.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG

References GNUNET_TRANSPORT_AddressIdentifier::address, ai, GNUNET_ATS_address_add(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GST_ats, GST_plugins_a2s(), LOG, num_blocked, and publish_p2a_stat_update().

Referenced by GST_ats_block_address().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_block_address()

void GST_ats_block_address ( const struct GNUNET_HELLO_Address address,
struct GNUNET_ATS_Session session 
)

Temporarily block a valid address for use by ATS for address suggestions.

This function should be called if an address was suggested by ATS but failed to perform (i.e. failure to establish a session or to exchange the PING/PONG).

Parameters
addressthe address to block
sessionthe session (can be NULL)

Definition at line 324 of file gnunet-service-transport_ats.c.

326 {
327  struct AddressInfo *ai;
328 
329  if (0 ==
330  memcmp (&GST_my_identity,
331  &address->peer,
332  sizeof(struct GNUNET_PeerIdentity)))
333  return; /* our own, ignore! */
334  ai = find_ai (address,
335  session);
336  if ((NULL == ai) || (NULL == ai->ar))
337  {
338  /* The address is already gone/blocked, this can happen during a blacklist
339  * callback. */
340  return;
341  }
342  ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off);
343  if (GNUNET_YES ==
347  "Removing address %s of peer %s from use (inbound died)\n",
349  GNUNET_i2s (&address->peer));
350  else
352  "Blocking address %s of peer %s from use for %s\n",
354  GNUNET_i2s (&address->peer),
356  GNUNET_YES));
357  /* destroy session and address */
358  if ((NULL == session) ||
359  (GNUNET_NO ==
361  session)))
362  {
364  }
365  /* "ar" has been freed, regardless how the branch
366  above played out: it was either freed in
367  #GNUNET_ATS_address_del_session() because it was
368  incoming, or explicitly in
369  #GNUNET_ATS_address_del_session(). */ai->ar = NULL;
370 
371  /* determine when the address should come back to life */
372  ai->blocked = GNUNET_TIME_relative_to_absolute (ai->back_off);
373  ai->unblock_task = GNUNET_SCHEDULER_add_delayed (ai->back_off,
375  ai);
376  num_blocked++;
378 }
static struct GNUNET_PeerIdentity GST_my_identity
Our public key.
static void unblock_address(void *cls)
The blocking time for an address has expired, allow ATS to suggest it again.
int GNUNET_ATS_address_del_session(struct GNUNET_ATS_AddressRecord *ar, struct GNUNET_ATS_Session *session)
A session was destroyed, disassociate it from the given address record.
void GNUNET_ATS_address_destroy(struct GNUNET_ATS_AddressRecord *ar)
An address got destroyed, stop using it as a valid address.
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.
Definition: address.c:39
@ GNUNET_HELLO_ADDRESS_INFO_INBOUND
This is an inbound address and cannot be used to initiate an outbound connection to another peer.
@ GNUNET_ERROR_TYPE_INFO
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
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
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:569
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
struct GNUNET_ATS_Session * session
Session (can be NULL)
The identity of the host (wraps the signing key of the peer).

References address, ai, find_ai(), GNUNET_ATS_address_del_session(), GNUNET_ATS_address_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_HELLO_address_check_option(), GNUNET_HELLO_ADDRESS_INFO_INBOUND, GNUNET_i2s(), GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, GST_my_identity, GST_plugins_a2s(), LOG, num_blocked, publish_p2a_stat_update(), AddressInfo::session, and unblock_address().

Referenced by free_address(), GST_neighbours_switch_to_address(), set_primary_address(), and switch_address_bl_check_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_block_reset()

void GST_ats_block_reset ( const struct GNUNET_HELLO_Address address,
struct GNUNET_ATS_Session session 
)

Reset address blocking time.

Resets the exponential back-off timer for this address to zero. Called when an address was used to create a successful connection.

Parameters
addressthe address to reset the blocking timer
sessionthe session (can be NULL)

Definition at line 390 of file gnunet-service-transport_ats.c.

392 {
393  struct AddressInfo *ai;
394 
395  if (0 ==
396  memcmp (&GST_my_identity,
397  &address->peer,
398  sizeof(struct GNUNET_PeerIdentity)))
399  return; /* our own, ignore! */
400  ai = find_ai (address, session);
401  if (NULL == ai)
402  {
403  GNUNET_break (0);
404  return;
405  }
406  /* address is in successful use, so it should not be blocked right now */
407  GNUNET_break (NULL == ai->unblock_task);
408  ai->back_off = GNUNET_TIME_UNIT_ZERO;
409 }
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.

References address, ai, find_ai(), GNUNET_break, GNUNET_TIME_UNIT_ZERO, GST_my_identity, and AddressInfo::session.

Referenced by GST_neighbours_handle_session_ack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_add_inbound_address()

void GST_ats_add_inbound_address ( const struct GNUNET_HELLO_Address address,
struct GNUNET_ATS_Session session,
const struct GNUNET_ATS_Properties prop 
)

Notify ATS about a new inbound address.

The address in combination with the session must be new, but this function will perform a santiy check. If the address is indeed new, make it available to ATS.

Parameters
addressthe address
sessionthe session
propperformance information

Definition at line 423 of file gnunet-service-transport_ats.c.

426 {
427  struct GNUNET_ATS_AddressRecord *ar;
428  struct AddressInfo *ai;
429 
430  if (0 ==
431  memcmp (&GST_my_identity,
432  &address->peer,
433  sizeof(struct GNUNET_PeerIdentity)))
434  return; /* our own, ignore! */
435 
436  /* Sanity checks for a valid inbound address */
437  if (NULL == address->transport_name)
438  {
439  GNUNET_break (0);
440  return;
441  }
446  GNUNET_assert (NULL != session);
447  ai = find_ai (address, session);
448  if (NULL != ai)
449  {
450  /* This should only be called for new sessions, and thus
451  we should not already have the address */
452  GNUNET_break (0);
453  return;
454  }
455  /* Is indeed new, let's tell ATS */
457  "Notifying ATS about peer `%s''s new inbound address `%s' session %p in network %s\n",
458  GNUNET_i2s (&address->peer),
460  session,
461  GNUNET_NT_to_string (prop->scope));
463  address,
464  session,
465  prop);
466  GNUNET_assert (NULL != ar);
467  ai = GNUNET_new (struct AddressInfo);
469  ai->session = session;
470  ai->properties = *prop;
471  ai->ar = ar;
473  &ai->address->peer,
474  ai,
477 }
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:99
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:38
@ GNUNET_NT_UNSPECIFIED
Category of last resort.
Definition: gnunet_nt_lib.h:43
struct GNUNET_ATS_AddressRecord * ar
Record with ATS API for the address.
Information we track per address, incoming or outgoing.
enum GNUNET_NetworkType scope
Which network scope does the respective address belong to? This property does not change.

References address, GNUNET_TRANSPORT_AddressIdentifier::address, ai, AddressInfo::ar, find_ai(), GNUNET_assert, GNUNET_ATS_address_add(), GNUNET_break, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_address_check_option(), GNUNET_HELLO_address_copy(), GNUNET_HELLO_ADDRESS_INFO_INBOUND, GNUNET_i2s(), GNUNET_new, GNUNET_NT_to_string(), GNUNET_NT_UNSPECIFIED, GNUNET_YES, GST_ats, GST_my_identity, GST_plugins_a2s(), LOG, p2a, publish_p2a_stat_update(), GNUNET_ATS_Properties::scope, and AddressInfo::session.

Referenced by plugin_env_session_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_add_address()

void GST_ats_add_address ( const struct GNUNET_HELLO_Address address,
const struct GNUNET_ATS_Properties prop 
)

Notify ATS about a new address including the network the address is located in.

The address must NOT be inbound and must be new to ATS.

Parameters
addressthe address
propperformance information

Definition at line 481 of file gnunet-service-transport_ats.c.

483 {
484  struct GNUNET_ATS_AddressRecord *ar;
485  struct AddressInfo *ai;
486 
487  if (0 ==
488  memcmp (&GST_my_identity,
489  &address->peer,
490  sizeof(struct GNUNET_PeerIdentity)))
491  return; /* our own, ignore! */
492  /* validadte address */
493  if (NULL == address->transport_name)
494  {
495  GNUNET_break (0);
496  return;
497  }
502  GNUNET_assert (NULL == ai);
504 
505  /* address seems sane, let's tell ATS */
507  "Notifying ATS about peer %s's new address `%s'\n",
508  GNUNET_i2s (&address->peer),
511  address,
512  NULL,
513  prop);
514  GNUNET_assert (NULL != ar);
515  ai = GNUNET_new (struct AddressInfo);
517  ai->ar = ar;
518  ai->properties = *prop;
520  &ai->address->peer,
521  ai,
524 }

References address, GNUNET_TRANSPORT_AddressIdentifier::address, ai, AddressInfo::ar, find_ai_no_session(), GNUNET_assert, GNUNET_ATS_address_add(), GNUNET_break, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_INFO, GNUNET_HELLO_address_check_option(), GNUNET_HELLO_address_copy(), GNUNET_HELLO_ADDRESS_INFO_INBOUND, GNUNET_i2s(), GNUNET_new, GNUNET_NT_UNSPECIFIED, GNUNET_YES, GST_ats, GST_my_identity, GST_plugins_a2s(), LOG, p2a, publish_p2a_stat_update(), and GNUNET_ATS_Properties::scope.

Referenced by add_valid_address(), and GST_validation_handle_pong().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_new_session()

void GST_ats_new_session ( const struct GNUNET_HELLO_Address address,
struct GNUNET_ATS_Session session 
)

Notify ATS about a new session now existing for the given address.

Essentially, an outbound address was used to establish a session. It is safe to call this function repeatedly for the same address and session pair.

Parameters
addressthe address
sessionthe session

Definition at line 537 of file gnunet-service-transport_ats.c.

539 {
540  struct AddressInfo *ai;
541 
542  if (0 ==
543  memcmp (&GST_my_identity,
544  &address->peer,
545  sizeof(struct GNUNET_PeerIdentity)))
546  return; /* our own, ignore! */
547  ai = find_ai (address, NULL);
548  if (NULL == ai)
549  {
550  /* We may simply already be aware of the session, even if some
551  other part of the code could not tell if it just created a new
552  session or just got one recycled from the plugin; hence, we may
553  be called with "new" session even for an "old" session; in that
554  case, check that this is the case, but just ignore it. */GNUNET_assert (NULL != (find_ai (address, session)));
555  return;
556  }
557  GNUNET_assert (NULL == ai->session);
558  ai->session = session;
560  "Telling ATS about new session for peer %s\n",
561  GNUNET_i2s (&address->peer));
562  /* Note that the address might currently be blocked; we only
563  tell ATS about the session if the address is currently not
564  blocked; otherwise, ATS will be told about the session on
565  unblock. */
566  if (NULL != ai->ar)
568  session);
569  else
570  GNUNET_assert (NULL != ai->unblock_task);
571 }
void GNUNET_ATS_address_add_session(struct GNUNET_ATS_AddressRecord *ar, struct GNUNET_ATS_Session *session)
An address was used to initiate a session.

References address, ai, find_ai(), GNUNET_assert, GNUNET_ATS_address_add_session(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GST_my_identity, LOG, and AddressInfo::session.

Referenced by multicast_pong(), send_syn_ack_message(), send_with_session(), and switch_address_bl_check_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_ai()

static void destroy_ai ( struct AddressInfo ai)
static

Release memory used by the given address data.

Parameters
aithe struct AddressInfo

Definition at line 580 of file gnunet-service-transport_ats.c.

581 {
582  GNUNET_assert (NULL == ai->session);
583  if (NULL != ai->unblock_task)
584  {
585  GNUNET_SCHEDULER_cancel (ai->unblock_task);
586  ai->unblock_task = NULL;
587  num_blocked--;
588  }
591  &ai->address->peer,
592  ai));
594  "Telling ATS to destroy address from peer %s\n",
595  GNUNET_i2s (&ai->address->peer));
596  if (NULL != ai->ar)
597  {
599  ai->ar = NULL;
600  }
603  GNUNET_free (ai);
604 }
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_HELLO_address_free(addr)
Free an address.
#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:975

References GNUNET_TRANSPORT_AddressIdentifier::address, ai, GNUNET_assert, GNUNET_ATS_address_destroy(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_address_free, GNUNET_i2s(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, LOG, num_blocked, p2a, and publish_p2a_stat_update().

Referenced by destroy_ai_cb(), GST_ats_del_session(), and GST_ats_expire_address().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_del_session()

void GST_ats_del_session ( const struct GNUNET_HELLO_Address address,
struct GNUNET_ATS_Session session 
)

Notify ATS that the session (but not the address) of a given address is no longer relevant.

(The session went down.) This function may be called even if for the respective outbound address GST_ats_new_session() was never called and thus the pair is unknown to ATS. In this case, the call is simply ignored.

Parameters
addressthe address
sessionthe session

Definition at line 619 of file gnunet-service-transport_ats.c.

621 {
622  struct AddressInfo *ai;
623 
624  if (0 ==
625  memcmp (&GST_my_identity,
626  &address->peer,
627  sizeof(struct GNUNET_PeerIdentity)))
628  return; /* our own, ignore! */
629  if (NULL == session)
630  {
631  GNUNET_break (0);
632  return;
633  }
634  ai = find_ai (address,
635  session);
636  if (NULL == ai)
637  {
638  /* We sometimes create sessions just for sending a PING,
639  and if those are destroyed they were never known to
640  ATS which means we end up here (however, in this
641  case, the address must be an outbound address). */
645  return;
646  }
647  GNUNET_assert (session == ai->session);
648  ai->session = NULL;
650  "Telling ATS to destroy session %p from peer %s\n",
651  session,
652  GNUNET_i2s (&address->peer));
653  if (GNUNET_YES == ai->expired)
654  {
655  /* last reason to keep this 'ai' around is now gone, the
656  session is dead as well, clean up */
657  if (NULL != ai->ar)
658  {
659  /* Address expired but not blocked, and thus 'ar' was still
660  live because of the session; deleting just the session
661  will do for an inbound session, but for an outbound we
662  then also need to destroy the address with ATS. */
663  if (GNUNET_NO ==
665  session))
666  {
668  }
669  /* "ar" has been freed, regardless how the branch
670  above played out: it was either freed in
671  #GNUNET_ATS_address_del_session() because it was
672  incoming, or explicitly in
673  #GNUNET_ATS_address_del_session(). */ai->ar = NULL;
674  }
675  destroy_ai (ai);
676  return;
677  }
678 
679  if (NULL == ai->ar)
680  {
681  /* If ATS doesn't know about the address/session, this means
682  this address was blocked. */
683  if (GNUNET_YES ==
686  {
687  /* This was a blocked inbound session, which now lost the
688  session. But inbound addresses are by themselves useless,
689  so we must forget about the address as well. */
690  destroy_ai (ai);
691  return;
692  }
693  /* Otherwise, we are done as we have set `ai->session` to NULL
694  already and ATS will simply not be told about the session when
695  the connection is unblocked and the outbound address becomes
696  available again. . */
697  return;
698  }
699 
700  /* This is the "simple" case where ATS knows about the session and
701  the address is neither blocked nor expired. Delete the session,
702  and if it was inbound, free the address as well. */
703  if (GNUNET_YES ==
705  session))
706  {
707  /* This was an inbound address, the session is now gone, so we
708  need to also forget about the address itself. */
709  ai->ar = NULL;
710  destroy_ai (ai);
711  }
712 }
static void destroy_ai(struct AddressInfo *ai)
Release memory used by the given address data.

References address, ai, destroy_ai(), find_ai(), GNUNET_assert, GNUNET_ATS_address_del_session(), GNUNET_ATS_address_destroy(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_address_check_option(), GNUNET_HELLO_ADDRESS_INFO_INBOUND, GNUNET_i2s(), GNUNET_NO, GNUNET_YES, GST_my_identity, LOG, and AddressInfo::session.

Referenced by plugin_env_session_end().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_update_distance()

void GST_ats_update_distance ( const struct GNUNET_HELLO_Address address,
uint32_t  distance 
)

Notify ATS about DV distance change to an address.

Does nothing if the address is not known to us.

Parameters
addressthe address
distancenew distance value

Definition at line 723 of file gnunet-service-transport_ats.c.

725 {
726  struct AddressInfo *ai;
727 
729  if (NULL == ai)
730  {
731  /* We do not know about this address, do nothing. */
732  return;
733  }
735  "Updated distance for peer `%s' to %u\n",
736  GNUNET_i2s (&address->peer),
737  distance);
738  ai->properties.distance = distance;
739  /* Give manipulation its chance to change metrics */
741  ai->session,
742  &ai->properties);
743  /* Address may be blocked, only give ATS if address is
744  currently active. */
745  if (NULL != ai->ar)
747  &ai->properties);
748 }
void GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, struct GNUNET_ATS_Properties *prop)
Function that will be called to manipulate ATS information according to current manipulation settings...
void GNUNET_ATS_address_update(struct GNUNET_ATS_AddressRecord *ar, const struct GNUNET_ATS_Properties *prop)
We have updated performance statistics for a given address.

References address, ai, find_ai_no_session(), GNUNET_ATS_address_update(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GST_manipulation_manipulate_metrics(), and LOG.

Referenced by plugin_env_address_to_type().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_update_delay()

void GST_ats_update_delay ( const struct GNUNET_HELLO_Address address,
struct GNUNET_TIME_Relative  delay 
)

Notify ATS about delay changes to properties of an address.

Does nothing if the address is not known to us.

Parameters
addressthe address
delaynew delay value

Definition at line 752 of file gnunet-service-transport_ats.c.

754 {
755  struct AddressInfo *ai;
756 
758  if (NULL == ai)
759  {
760  /* We do not know about this address, do nothing. */
761  return;
762  }
764  "Updated latency for peer `%s' to %s\n",
765  GNUNET_i2s (&address->peer),
767  GNUNET_YES));
768  ai->properties.delay = delay;
769  /* Give manipulation its chance to change metrics */
771  ai->session,
772  &ai->properties);
773  /* Address may be blocked, only give ATS if address is
774  currently active. */
775  if (NULL != ai->ar)
777  &ai->properties);
778 }
static struct GNUNET_TIME_Relative delay
When should dkg communication start?

References address, ai, delay, find_ai_no_session(), GNUNET_ATS_address_update(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, GST_manipulation_manipulate_metrics(), and LOG.

Referenced by GST_neighbours_calculate_receive_delay(), and GST_validation_handle_pong().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_update_utilization()

void GST_ats_update_utilization ( const struct GNUNET_HELLO_Address address,
uint32_t  bps_in,
uint32_t  bps_out 
)

Notify ATS about utilization changes to an address.

Does nothing if the address is not known to us.

Parameters
addressour information about the address
bps_innew utilization inbound
bps_outnew utilization outbound

Definition at line 790 of file gnunet-service-transport_ats.c.

793 {
794  struct AddressInfo *ai;
795 
797  if (NULL == ai)
798  {
799  /* We do not know about this address, do nothing. */
800  return;
801  }
803  "Updating utilization for peer `%s' address %s: %u/%u\n",
804  GNUNET_i2s (&address->peer),
806  (unsigned int) bps_in,
807  (unsigned int) bps_out);
808  ai->properties.utilization_in = bps_in;
809  ai->properties.utilization_out = bps_out;
810  /* Give manipulation its chance to change metrics */
812  ai->session,
813  &ai->properties);
814  /* Address may be blocked, only give ATS if address is
815  currently active. */
816  if (NULL != ai->ar)
818  &ai->properties);
819 }

References address, ai, find_ai_no_session(), GNUNET_ATS_address_update(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GST_manipulation_manipulate_metrics(), GST_plugins_a2s(), and LOG.

Referenced by send_utilization_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_expire_address()

void GST_ats_expire_address ( const struct GNUNET_HELLO_Address address)

Notify ATS that the address has expired and thus cannot be used any longer.

This function must only be called if the corresponding session is already gone.

Parameters
addressthe address

Definition at line 830 of file gnunet-service-transport_ats.c.

831 {
832  struct AddressInfo *ai;
833 
834  if (0 ==
835  memcmp (&GST_my_identity,
836  &address->peer,
837  sizeof(struct GNUNET_PeerIdentity)))
838  return; /* our own, ignore! */
840  "Address %s of peer %s expired\n",
842  GNUNET_i2s (&address->peer));
844  if (NULL == ai)
845  {
846  GNUNET_assert (0);
847  return;
848  }
849  if (NULL != ai->session)
850  {
851  /* Got an active session, just remember the expiration
852  and act upon it when the session goes down. */
853  ai->expired = GNUNET_YES;
854  return;
855  }
856  /* Address expired, no session, free resources */
857  destroy_ai (ai);
858 }

References address, ai, destroy_ai(), find_ai_no_session(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_YES, GST_my_identity, GST_plugins_a2s(), and LOG.

Referenced by cleanup_validation_entry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_init()

void GST_ats_init ( void  )

Initialize ATS subsystem.

Definition at line 865 of file gnunet-service-transport_ats.c.

866 {
868 }
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).

References GNUNET_CONTAINER_multipeermap_create(), GNUNET_YES, and p2a.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_ai_cb()

static int destroy_ai_cb ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Release memory used by the given address data.

Parameters
clsNULL
keywhich peer is this about
valuethe struct AddressInfo
Returns
GNUNET_OK (continue to iterate)

Definition at line 880 of file gnunet-service-transport_ats.c.

883 {
884  struct AddressInfo *ai = value;
885 
886  destroy_ai (ai);
887  return GNUNET_OK;
888 }
@ GNUNET_OK

References ai, destroy_ai(), GNUNET_OK, and value.

Referenced by GST_ats_done().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_ats_done()

void GST_ats_done ( void  )

Shutdown ATS subsystem.

Definition at line 895 of file gnunet-service-transport_ats.c.

896 {
898  &destroy_ai_cb,
899  NULL);
902  p2a = NULL;
903 }
static int destroy_ai_cb(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Release memory used by the given address data.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.

References destroy_ai_cb(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), p2a, and publish_p2a_stat_update().

Referenced by shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ p2a

struct GNUNET_CONTAINER_MultiPeerMap* p2a
static

Map from peer identities to one or more struct AddressInfo values for the peer.

Definition at line 98 of file gnunet-service-transport_ats.c.

Referenced by destroy_ai(), find_ai(), find_ai_no_session(), GST_ats_add_address(), GST_ats_add_inbound_address(), GST_ats_done(), GST_ats_init(), and publish_p2a_stat_update().

◆ num_blocked

unsigned int num_blocked
static

Number of blocked addresses.

Definition at line 103 of file gnunet-service-transport_ats.c.

Referenced by destroy_ai(), GST_ats_block_address(), publish_p2a_stat_update(), and unblock_address().