GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-ats.c File Reference

ATS command line tool. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_ats_service.h"
#include "gnunet_transport_service.h"
Include dependency graph for gnunet-ats.c:

Go to the source code of this file.

Data Structures

struct  PendingResolutions
 Structure used to remember all pending address resolutions. More...
 
struct  ATSAddress
 Information we keep for an address. More...
 
struct  AddressFindCtx
 Closure for find_address_it(). More...
 

Macros

#define UNLIMITED_STRING   "unlimited"
 String to respresent unlimited. More...
 

Functions

static int free_addr_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Free address corresponding to a given peer. More...
 
static void end (void *cls)
 Task run on shutdown. More...
 
static void transport_addr_to_str_cb (void *cls, const char *address, int res)
 Function to call with a textual representation of an address. More...
 
static int find_address_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Find address corresponding to a given peer. More...
 
static void ats_perf_mon_cb (void *cls, const struct GNUNET_HELLO_Address *address, int active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, const struct GNUNET_ATS_Properties *prop)
 Signature of a function that is called with QoS information about an address. More...
 
static void ats_perf_cb (void *cls, const struct GNUNET_HELLO_Address *address, int active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, const struct GNUNET_ATS_Properties *prop)
 Signature of a function that is called with QoS information about an address. More...
 
static unsigned int print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Print information about the quotas configured for the various network scopes. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *my_cfg)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 The main function. More...
 

Variables

static int opt_resolve_addresses_numeric
 CLI Opt: More...
 
static int opt_verbose
 CLI Opt: Print verbose ATS information. More...
 
static int opt_list_used
 CLI Option: List only addresses currently used (active) More...
 
static int opt_list_all
 CLI Option: List all addresses. More...
 
static int opt_set_pref
 CLI Option: set preference. More...
 
static int opt_print_quotas
 CLI Option: print quotas configured. More...
 
static int opt_monitor
 CLI Option: Monitor addresses used. More...
 
static char * opt_pid_str
 CLI Option: use specific peer. More...
 
static char * opt_type_str
 CLI Option: preference type to set. More...
 
static unsigned int opt_pref_value
 CLI Option: preference value to set. More...
 
static int ret
 Final status code. More...
 
static int stat_results
 Number of results returned from service. More...
 
static int stat_receive_done
 State: all pending receive operations done? More...
 
static int stat_pending
 State: number of pending operations. More...
 
static char * cpid_str
 Which peer should we connect to? More...
 
static struct GNUNET_ATS_PerformanceHandleph
 ATS performance handle used. More...
 
static struct GNUNET_ATS_ConnectivityHandleats_ch
 Our connectivity handle. More...
 
static struct GNUNET_ATS_ConnectivitySuggestHandleats_sh
 Handle for address suggestion request. More...
 
static struct GNUNET_ATS_AddressListHandlealh
 ATS address list handle used. More...
 
static struct GNUNET_CONFIGURATION_Handlecfg
 Configuration handle. More...
 
static struct GNUNET_SCHEDULER_Taskshutdown_task
 Shutdown task. More...
 
static struct GNUNET_CONTAINER_MultiPeerMapaddresses
 Hashmap to store addresses. More...
 
static struct PendingResolutionshead
 Head of list of pending resolution requests. More...
 
static struct PendingResolutionstail
 Tail of list of pending resolution requests. More...
 

Detailed Description

ATS command line tool.

Author
Matthias Wachs
Christian Grothoff

Definition in file gnunet-ats.c.

Macro Definition Documentation

◆ UNLIMITED_STRING

#define UNLIMITED_STRING   "unlimited"

String to respresent unlimited.

Definition at line 35 of file gnunet-ats.c.

Referenced by print_quotas().

Function Documentation

◆ free_addr_it()

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

Free address corresponding to a given peer.

Parameters
clsNULL
keypeer identity
valuethe struct ATSAddress * to be freed
Returns
GNUNET_YES (always)

Definition at line 248 of file gnunet-ats.c.

References ATSAddress::address, GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_HELLO_address_free, GNUNET_OK, and value.

Referenced by ats_perf_mon_cb(), and end().

251 {
252  struct ATSAddress *a = value;
253 
256  key,
257  value));
259  GNUNET_free (a);
260  return GNUNET_OK;
261 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int 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.
static struct GNUNET_CONTAINER_MultiPeerMap * addresses
Hashmap to store addresses.
Definition: gnunet-ats.c:146
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static char * value
Value of the record to add/remove.
struct GNUNET_HELLO_Address * address
Address information.
Definition: gnunet-ats.c:208
Information we keep for an address.
Definition: gnunet-ats.c:203
#define GNUNET_HELLO_address_free(addr)
Free an address.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

static void end ( void *  cls)
static

Task run on shutdown.

Parameters
clsNULL

Definition at line 270 of file gnunet-ats.c.

References _, PendingResolutions::address, FPRINTF, free_addr_it(), GNUNET_ATS_connectivity_done(), GNUNET_ATS_connectivity_suggest_cancel(), GNUNET_ATS_performance_done(), GNUNET_ATS_performance_list_addresses_cancel(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_free, GNUNET_TRANSPORT_address_to_string_cancel(), head, PendingResolutions::next, opt_list_all, opt_list_used, pending, ret, stat_results, and PendingResolutions::tats_ctx.

Referenced by ats_perf_cb(), run(), and transport_addr_to_str_cb().

271 {
272  struct PendingResolutions * pr;
273  struct PendingResolutions * next;
274  unsigned int pending;
275 
276  if (NULL != alh)
277  {
279  alh = NULL;
280  }
281 
282  if (NULL != ph)
283  {
285  ph = NULL;
286  }
287 
288  pending = 0;
289  next = head;
290  while (NULL != (pr = next))
291  {
292  next = pr->next;
295  GNUNET_free(pr->address);
296  GNUNET_free(pr);
297  pending++;
298  }
300  &free_addr_it,
301  NULL);
303  addresses = NULL;
304 
305  if (0 < pending)
306  FPRINTF (stdout,
307  _("%u address resolutions had a timeout\n"),
308  pending);
310  FPRINTF (stdout,
311  _("ATS returned stat_results for %u addresses\n"),
312  stat_results);
313 
314  if (NULL != ats_sh)
315  {
317  ats_sh = NULL;
318  }
319  if (NULL != ats_ch)
320  {
322  ats_ch = NULL;
323  }
324  ret = 0;
325 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static int opt_list_all
CLI Option: List all addresses.
Definition: gnunet-ats.c:56
#define FPRINTF
Definition: plibc.h:683
Structure used to remember all pending address resolutions.
Definition: gnunet-ats.c:154
struct GNUNET_HELLO_Address * address
Copy of the address we are resolving.
Definition: gnunet-ats.c:169
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
static int opt_list_used
CLI Option: List only addresses currently used (active)
Definition: gnunet-ats.c:51
void GNUNET_ATS_performance_done(struct GNUNET_ATS_PerformanceHandle *ph)
Client is done using the ATS performance subsystem, release resources.
static struct GNUNET_CONTAINER_MultiPeerMap * addresses
Hashmap to store addresses.
Definition: gnunet-ats.c:146
void GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh)
We no longer care about being connected to a peer.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_ATS_AddressListHandle * alh
ATS address list handle used.
Definition: gnunet-ats.c:131
struct PendingResolutions * next
Kept in a DLL.
Definition: gnunet-ats.c:159
struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx
Handle to the transport request to convert the address to a string.
Definition: gnunet-ats.c:175
void GNUNET_TRANSPORT_address_to_string_cancel(struct GNUNET_TRANSPORT_AddressToStringContext *alc)
Cancel request for address conversion.
static int stat_results
Number of results returned from service.
Definition: gnunet-ats.c:96
static int free_addr_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Free address corresponding to a given peer.
Definition: gnunet-ats.c:248
static struct GNUNET_ATS_ConnectivitySuggestHandle * ats_sh
Handle for address suggestion request.
Definition: gnunet-ats.c:126
static int ret
Final status code.
Definition: gnunet-ats.c:91
static unsigned int pending
The number of queries that are outstanding.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct PendingResolutions * head
Head of list of pending resolution requests.
Definition: gnunet-ats.c:231
void GNUNET_ATS_performance_list_addresses_cancel(struct GNUNET_ATS_AddressListHandle *alh)
Cancel a pending address listing operation.
static struct PendingResolutions * tail
Tail of list of pending resolution requests.
Definition: gnunet-ats.c:236
void GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
Client is done with ATS connectivity management, release resources.
static struct GNUNET_ATS_ConnectivityHandle * ats_ch
Our connectivity handle.
Definition: gnunet-ats.c:121
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transport_addr_to_str_cb()

static void transport_addr_to_str_cb ( void *  cls,
const char *  address,
int  res 
)
static

Function to call with a textual representation of an address.

This function will be called several times with different possible textual representations, and a last time with address being NULL to signal the end of the iteration. Note that address NULL always is the last call, regardless of the value in res.

Parameters
clsclosure, a struct PendingResolutions *
addressNULL on end of iteration, otherwise 0-terminated printable UTF-8 string, in particular an empty string if res is GNUNET_NO
resresult of the address to string conversion: if GNUNET_OK: conversion successful if GNUNET_NO: address was invalid (or not supported) if GNUNET_SYSERR: communication error (IPC error)

Definition at line 345 of file gnunet-ats.c.

References _, PendingResolutions::active, PendingResolutions::address, GNUNET_HELLO_Address::address_length, PendingResolutions::bandwidth_in, PendingResolutions::bandwidth_out, end(), FPRINTF, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_i2s(), GNUNET_NO, GNUNET_NT_to_string(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_YES, GNUNET_HELLO_Address::peer, PendingResolutions::properties, GNUNET_ATS_Properties::scope, stat_pending, stat_receive_done, GNUNET_HELLO_Address::transport_name, and GNUNET_BANDWIDTH_Value32NBO::value__.

Referenced by ats_perf_cb(), and ats_perf_mon_cb().

348 {
349  struct PendingResolutions *pr = cls;
350 
351  if (NULL == address)
352  {
353  /* We're done */
355  tail,
356  pr);
357  GNUNET_free (pr->address);
358  GNUNET_free (pr);
359  stat_pending--;
360 
361  if ((GNUNET_YES == stat_receive_done) && (0 == stat_pending))
362  {
363  /* All messages received and no resolutions pending*/
364  if (shutdown_task != NULL)
367  }
368  return;
369  }
370  switch (res)
371  {
372  case GNUNET_SYSERR:
373  FPRINTF (stderr,
374  "Failed to convert address for peer `%s' plugin `%s' length %u to string (communication error)\n",
375  GNUNET_i2s (&pr->address->peer),
376  pr->address->transport_name,
377  (unsigned int) pr->address->address_length);
378  return;
379  case GNUNET_NO:
380  FPRINTF (stderr,
381  "Failed to convert address for peer `%s' plugin `%s' length %u to string (address invalid or not supported)\n",
382  GNUNET_i2s (&pr->address->peer),
383  pr->address->transport_name,
384  (unsigned int) pr->address->address_length);
385  return;
386  case GNUNET_OK:
387  /* continues below */
388  break;
389  default:
390  GNUNET_break (0);
391  return;
392  }
393 
394  FPRINTF (stdout,
395  _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
396  GNUNET_i2s (&pr->address->peer),
397  pr->address->transport_name,
398  address,
400  ntohl (pr->bandwidth_out.value__),
401  ntohl (pr->bandwidth_in.value__),
402  pr->active ? _("active ") : _("inactive "));
403 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
size_t address_length
Number of bytes in address.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Amount of inbound bandwidth assigned by ATS.
Definition: gnunet-ats.c:190
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:43
static int stat_receive_done
State: all pending receive operations done?
Definition: gnunet-ats.c:101
#define FPRINTF
Definition: plibc.h:683
static void end(void *cls)
Task run on shutdown.
Definition: gnunet-ats.c:270
Structure used to remember all pending address resolutions.
Definition: gnunet-ats.c:154
struct GNUNET_HELLO_Address * address
Copy of the address we are resolving.
Definition: gnunet-ats.c:169
struct GNUNET_ATS_Properties properties
Performance data.
Definition: gnunet-ats.c:180
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint32_t value__
The actual value (bytes per second).
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_SCHEDULER_Task * shutdown_task
Shutdown task.
Definition: gnunet-ats.c:141
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:1273
const char * transport_name
Name of the transport plugin enabling the communication using this address.
static int res
static int stat_pending
State: number of pending operations.
Definition: gnunet-ats.c:106
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Amount of outbound bandwidth assigned by ATS.
Definition: gnunet-ats.c:185
struct GNUNET_PeerIdentity peer
For which peer is this an address?
int active
Is this an active address?
Definition: gnunet-ats.c:195
enum GNUNET_NetworkType scope
Which network scope does the respective address belong to? This property does not change...
static struct PendingResolutions * head
Head of list of pending resolution requests.
Definition: gnunet-ats.c:231
static struct PendingResolutions * tail
Tail of list of pending resolution requests.
Definition: gnunet-ats.c:236
#define GNUNET_YES
Definition: gnunet_common.h:80
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#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:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_address_it()

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

Find address corresponding to a given peer.

Parameters
clsthe struct AddressFindCtx *
keypeer identity
valuethe struct ATSAddress * for an existing address
Returns
GNUNET_NO if we found a match, GNUNET_YES if not

Definition at line 432 of file gnunet-ats.c.

References ATSAddress::address, GNUNET_HELLO_address_cmp(), GNUNET_NO, GNUNET_YES, AddressFindCtx::res, AddressFindCtx::src, and value.

Referenced by ats_perf_mon_cb().

435 {
436  struct AddressFindCtx *actx = cls;
437  struct ATSAddress *exist = value;
438 
439  if (0 == GNUNET_HELLO_address_cmp (actx->src, exist->address))
440  {
441  actx->res = exist;
442  return GNUNET_NO;
443  }
444  return GNUNET_YES;
445 }
#define GNUNET_NO
Definition: gnunet_common.h:81
const struct GNUNET_HELLO_Address * src
Address we are looking for.
Definition: gnunet-ats.c:414
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 char * value
Value of the record to add/remove.
struct ATSAddress * res
Where to write the struct ATSAddress if we found one that matches.
Definition: gnunet-ats.c:419
struct GNUNET_HELLO_Address * address
Address information.
Definition: gnunet-ats.c:208
Information we keep for an address.
Definition: gnunet-ats.c:203
Closure for find_address_it().
Definition: gnunet-ats.c:409
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ats_perf_mon_cb()

static void ats_perf_mon_cb ( void *  cls,
const struct GNUNET_HELLO_Address address,
int  active,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_out,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_in,
const struct GNUNET_ATS_Properties prop 
)
static

Signature of a function that is called with QoS information about an address.

Parameters
clsclosure (NULL)
addressthe address, NULL if ATS service was disconnected
activeGNUNET_YES if this address is actively used to maintain a connection to a peer; GNUNET_NO if the address is not actively used; GNUNET_SYSERR if this address is no longer available for ATS
bandwidth_outassigned outbound bandwidth for the connection
bandwidth_inassigned inbound bandwidth for the connection
propperformance data for the address (as far as known)

Definition at line 463 of file gnunet-ats.c.

References _, PendingResolutions::active, ATSAddress::active, PendingResolutions::address, ATSAddress::address, PendingResolutions::bandwidth_in, ATSAddress::bandwidth_in, PendingResolutions::bandwidth_out, ATSAddress::bandwidth_out, find_address_it(), FPRINTF, free_addr_it(), GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_HELLO_address_copy(), GNUNET_HELLO_address_free, GNUNET_i2s(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_SECONDS, GNUNET_TRANSPORT_address_to_string(), GNUNET_TRANSPORT_address_to_string_cancel(), head, PendingResolutions::next, opt_resolve_addresses_numeric, opt_verbose, GNUNET_HELLO_Address::peer, PendingResolutions::properties, AddressFindCtx::res, AddressFindCtx::src, stat_pending, stat_results, PendingResolutions::tats_ctx, transport_addr_to_str_cb(), GNUNET_HELLO_Address::transport_name, and GNUNET_BANDWIDTH_Value32NBO::value__.

Referenced by run().

469 {
470  struct PendingResolutions *pr;
471  struct PendingResolutions *cur;
472  struct PendingResolutions *next;
473 
474  if (NULL == address)
475  {
476  /* ATS service temporarily disconnected, remove current state */
477  next = head;
478  for (cur = next; NULL != cur; cur = next)
479  {
480  next = cur->next;
484  GNUNET_free (cur);
485  }
487  &free_addr_it,
488  NULL);
489  return;
490  }
491  if (GNUNET_SYSERR == active)
492  {
493  /* remove address */
494  struct AddressFindCtx actx;
495 
496  actx.src = address;
497  actx.res = NULL;
499  &address->peer,
501  &actx);
502  if (NULL == actx.res)
503  {
504  GNUNET_break (0);
505  return;
506  }
509  &address->peer,
510  actx.res));
511  FPRINTF (stdout,
512  _("Removed address of peer `%s' with plugin `%s'\n"),
513  GNUNET_i2s (&address->peer),
514  actx.res->address->transport_name);
515  GNUNET_HELLO_address_free (actx.res);
516  return;
517  }
518 
519  if (GNUNET_NO == opt_verbose)
520  {
521  struct AddressFindCtx actx;
522  struct ATSAddress *a;
523 
524  actx.src = address;
525  actx.res = NULL;
527  &address->peer,
529  &actx);
530  if ((NULL != actx.res))
531  {
532  if ((bandwidth_in.value__ == actx.res->bandwidth_in.value__) &&
533  (bandwidth_out.value__ == actx.res->bandwidth_out.value__) &&
534  (active == actx.res->active))
535  {
536  return; /* Nothing to do here */
537  }
538  else
539  {
540  actx.res->bandwidth_in = bandwidth_in;
541  actx.res->bandwidth_out = bandwidth_out;
542  }
543  }
544  else
545  {
546  a = GNUNET_new (struct ATSAddress);
547 
548  a->address = GNUNET_HELLO_address_copy(address);
551  a->active = active;
553  &address->peer,
554  a,
556  }
557  }
558 
559  pr = GNUNET_new (struct PendingResolutions);
560  pr->properties = *prop;
561  pr->address = GNUNET_HELLO_address_copy (address);
564  pr->active = active;
569  pr);
571  stat_results++;
572  stat_pending++;
573 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Current inbound bandwidth.
Definition: gnunet-ats.c:218
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Amount of inbound bandwidth assigned by ATS.
Definition: gnunet-ats.c:190
int active
Is this an active address?
Definition: gnunet-ats.c:223
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define FPRINTF
Definition: plibc.h:683
Structure used to remember all pending address resolutions.
Definition: gnunet-ats.c:154
struct GNUNET_HELLO_Address * address
Copy of the address we are resolving.
Definition: gnunet-ats.c:169
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_ATS_Properties properties
Performance data.
Definition: gnunet-ats.c:180
int 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_NO
Definition: gnunet_common.h:81
static struct GNUNET_CONTAINER_MultiPeerMap * addresses
Hashmap to store addresses.
Definition: gnunet-ats.c:146
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const struct GNUNET_HELLO_Address * src
Address we are looking for.
Definition: gnunet-ats.c:414
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint32_t value__
The actual value (bytes per second).
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct PendingResolutions * next
Kept in a DLL.
Definition: gnunet-ats.c:159
struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx
Handle to the transport request to convert the address to a string.
Definition: gnunet-ats.c:175
void GNUNET_TRANSPORT_address_to_string_cancel(struct GNUNET_TRANSPORT_AddressToStringContext *alc)
Cancel request for address conversion.
static int opt_resolve_addresses_numeric
CLI Opt:
Definition: gnunet-ats.c:41
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Current outbound bandwidth.
Definition: gnunet-ats.c:213
static struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle.
Definition: gnunet-ats.c:136
static int stat_results
Number of results returned from service.
Definition: gnunet-ats.c:96
static int free_addr_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Free address corresponding to a given peer.
Definition: gnunet-ats.c:248
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:439
static int stat_pending
State: number of pending operations.
Definition: gnunet-ats.c:106
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_TRANSPORT_AddressToStringContext * GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HELLO_Address *address, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressToStringCallback aluc, void *aluc_cls)
Convert a binary address into a human readable address.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Amount of outbound bandwidth assigned by ATS.
Definition: gnunet-ats.c:185
struct GNUNET_PeerIdentity peer
For which peer is this an address?
int active
Is this an active address?
Definition: gnunet-ats.c:195
static int find_address_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Find address corresponding to a given peer.
Definition: gnunet-ats.c:432
Allow multiple values with the same key.
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.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_HELLO_Address * address
Address information.
Definition: gnunet-ats.c:208
static struct PendingResolutions * head
Head of list of pending resolution requests.
Definition: gnunet-ats.c:231
Information we keep for an address.
Definition: gnunet-ats.c:203
static int opt_verbose
CLI Opt: Print verbose ATS information.
Definition: gnunet-ats.c:46
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
static void transport_addr_to_str_cb(void *cls, const char *address, int res)
Function to call with a textual representation of an address.
Definition: gnunet-ats.c:345
Closure for find_address_it().
Definition: gnunet-ats.c:409
static struct PendingResolutions * tail
Tail of list of pending resolution requests.
Definition: gnunet-ats.c:236
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_HELLO_address_free(addr)
Free an address.
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.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ats_perf_cb()

static void ats_perf_cb ( void *  cls,
const struct GNUNET_HELLO_Address address,
int  active,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_out,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_in,
const struct GNUNET_ATS_Properties prop 
)
static

Signature of a function that is called with QoS information about an address.

Parameters
clsclosure (NULL)
addressthe address, NULL if ATS service was disconnected
activeis this address actively used to maintain a connection to a peer
bandwidth_outassigned outbound bandwidth for the connection
bandwidth_inassigned inbound bandwidth for the connection
propperformance data for the address (as far as known)

Definition at line 588 of file gnunet-ats.c.

References PendingResolutions::active, PendingResolutions::address, PendingResolutions::bandwidth_in, PendingResolutions::bandwidth_out, end(), GNUNET_CONTAINER_DLL_insert, GNUNET_HELLO_address_copy(), GNUNET_new, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_SECONDS, GNUNET_TRANSPORT_address_to_string(), GNUNET_YES, opt_resolve_addresses_numeric, PendingResolutions::properties, stat_pending, stat_receive_done, stat_results, PendingResolutions::tats_ctx, and transport_addr_to_str_cb().

Referenced by run().

594 {
595  struct PendingResolutions *pr;
596 
597  if (NULL == address)
598  {
599  /* All messages received */
601  alh = NULL;
602  if (0 == stat_pending)
603  {
604  /* All messages received and no resolutions pending*/
605  if (shutdown_task != NULL)
608  }
609  return;
610  }
611 
612  pr = GNUNET_new (struct PendingResolutions);
613  pr->properties = *prop;
614  pr->address = GNUNET_HELLO_address_copy (address);
617  pr->active = active;
623  stat_results++;
624  stat_pending++;
625 }
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Amount of inbound bandwidth assigned by ATS.
Definition: gnunet-ats.c:190
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static int stat_receive_done
State: all pending receive operations done?
Definition: gnunet-ats.c:101
static void end(void *cls)
Task run on shutdown.
Definition: gnunet-ats.c:270
Structure used to remember all pending address resolutions.
Definition: gnunet-ats.c:154
struct GNUNET_HELLO_Address * address
Copy of the address we are resolving.
Definition: gnunet-ats.c:169
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_ATS_Properties properties
Performance data.
Definition: gnunet-ats.c:180
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_ATS_AddressListHandle * alh
ATS address list handle used.
Definition: gnunet-ats.c:131
static struct GNUNET_SCHEDULER_Task * shutdown_task
Shutdown task.
Definition: gnunet-ats.c:141
struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx
Handle to the transport request to convert the address to a string.
Definition: gnunet-ats.c:175
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:1273
static int opt_resolve_addresses_numeric
CLI Opt:
Definition: gnunet-ats.c:41
static struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle.
Definition: gnunet-ats.c:136
static int stat_results
Number of results returned from service.
Definition: gnunet-ats.c:96
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:439
static int stat_pending
State: number of pending operations.
Definition: gnunet-ats.c:106
struct GNUNET_TRANSPORT_AddressToStringContext * GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HELLO_Address *address, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressToStringCallback aluc, void *aluc_cls)
Convert a binary address into a human readable address.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Amount of outbound bandwidth assigned by ATS.
Definition: gnunet-ats.c:185
int active
Is this an active address?
Definition: gnunet-ats.c:195
static struct PendingResolutions * head
Head of list of pending resolution requests.
Definition: gnunet-ats.c:231
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
static void transport_addr_to_str_cb(void *cls, const char *address, int res)
Function to call with a textual representation of an address.
Definition: gnunet-ats.c:345
static struct PendingResolutions * tail
Tail of list of pending resolution requests.
Definition: gnunet-ats.c:236
#define GNUNET_YES
Definition: gnunet_common.h:80
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_quotas()

static unsigned int print_quotas ( const struct GNUNET_CONFIGURATION_Handle cfg)
static

Print information about the quotas configured for the various network scopes.

Parameters
cfgconfiguration to obtain quota information from
Returns
total number of ATS network types known

Definition at line 636 of file gnunet-ats.c.

References _, FPRINTF, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_free, GNUNET_NT_COUNT, GNUNET_NT_to_string(), GNUNET_OK, GNUNET_STRINGS_fancy_size_to_bytes(), GNUNET_SYSERR, and UNLIMITED_STRING.

Referenced by run().

637 {
638  char * entry_in = NULL;
639  char * entry_out = NULL;
640  char * quota_out_str;
641  char * quota_in_str;
642  unsigned long long int quota_out;
643  unsigned long long int quota_in;
644  int c;
645 
646  for (c = 0; (c < GNUNET_NT_COUNT); c++)
647  {
648 
649  GNUNET_asprintf (&entry_out,
650  "%s_QUOTA_OUT",
651  GNUNET_NT_to_string (c));
652  GNUNET_asprintf (&entry_in,
653  "%s_QUOTA_IN",
654  GNUNET_NT_to_string (c));
655 
656  /* quota out */
657  if (GNUNET_OK ==
659  "ats",
660  entry_out,
661  &quota_out_str))
662  {
663  if (0 == strcmp (quota_out_str, UNLIMITED_STRING)
664  || (GNUNET_SYSERR ==
665  GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str,
666  &quota_out)))
667  quota_out = UINT32_MAX;
668 
669  GNUNET_free(quota_out_str);
670  GNUNET_asprintf (&quota_out_str, "%llu", quota_out);
671  }
672  else
673  {
674  FPRINTF (stderr,
675  "Outbound quota for network `%11s' not configured!\n",
676  GNUNET_NT_to_string (c));
677  GNUNET_asprintf (&quota_out_str, "-");
678  }
679  GNUNET_free (entry_out);
680 
681  /* quota in */
682  if (GNUNET_OK ==
684  "ats",
685  entry_in,
686  &quota_in_str))
687  {
688  if (0 == strcmp (quota_in_str, UNLIMITED_STRING)
689  || (GNUNET_SYSERR ==
690  GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &quota_in)))
691  quota_in = UINT32_MAX;
692  GNUNET_free (quota_in_str);
693  GNUNET_asprintf (&quota_in_str, "%llu", quota_in);
694  }
695  else
696  {
697  FPRINTF (stderr,
698  "Inbound quota for network `%11s' not configured!\n",
699  GNUNET_NT_to_string (c));
700  GNUNET_asprintf (&quota_in_str, "-");
701  }
702  GNUNET_free(entry_in);
703 
704  FPRINTF (stdout,
705  _("Quota for network `%11s' (in/out): %10s / %10s\n"),
707  quota_in_str,
708  quota_out_str);
709  GNUNET_free(quota_out_str);
710  GNUNET_free(quota_in_str);
711  }
712  return GNUNET_NT_COUNT;
713 }
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:43
#define FPRINTF
Definition: plibc.h:683
int GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size, unsigned long long *size)
Convert a given fancy human-readable size to bytes.
Definition: strings.c:317
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define UNLIMITED_STRING
String to respresent unlimited.
Definition: gnunet-ats.c:35
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_NT_COUNT
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle my_cfg 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
my_cfgconfiguration

Definition at line 725 of file gnunet-ats.c.

References _, ats_perf_cb(), ats_perf_mon_cb(), cpid_str, end(), FPRINTF, GNUNET_ATS_connectivity_init(), GNUNET_ATS_connectivity_suggest(), GNUNET_ATS_performance_change_preference(), GNUNET_ATS_performance_init(), GNUNET_ATS_performance_list_addresses(), GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_PREFERENCE_LATENCY, GNUNET_CONTAINER_multipeermap_create(), GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_TIME_UNIT_SECONDS, GNUNET_YES, opt_list_all, opt_list_used, opt_monitor, opt_pid_str, opt_pref_value, opt_print_quotas, opt_set_pref, opt_type_str, print_quotas(), GNUNET_PeerIdentity::public_key, ret, stat_results, and type.

Referenced by main().

729 {
730  struct GNUNET_PeerIdentity pid;
731  struct GNUNET_PeerIdentity cpid;
732  unsigned int c;
733  unsigned int type;
734 
735  cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg;
737  stat_results = 0;
738 
739  c = 0;
740  if (NULL != opt_pid_str)
741  {
742  if (GNUNET_OK !=
744  strlen (opt_pid_str),
745  &pid.public_key))
746  {
747  FPRINTF (stderr,
748  _("Failed to parse peer identity `%s'\n"),
749  opt_pid_str);
750  return;
751  }
752  }
753  if (NULL != cpid_str)
754  {
755  if (GNUNET_OK !=
757  strlen (cpid_str),
758  &cpid.public_key))
759  {
760  FPRINTF (stderr,
761  _("Failed to parse peer identity `%s'\n"),
762  cpid_str);
763  return;
764  }
765  c++;
766  }
767 
769 
770  if (1 < c)
771  {
772  FPRINTF (stderr,
773  _("Please select one operation: %s or %s or %s or %s or %s\n"),
774  "--used",
775  "--all",
776  "--monitor",
777  "--preference",
778  "--quotas");
779  return;
780  }
781  if (0 == c)
782  opt_list_used = GNUNET_YES; /* set default */
783  if (opt_print_quotas)
784  {
785  ret = print_quotas (cfg);
786  return;
787  }
788  if (opt_list_all)
789  {
790  ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
791  if (NULL == ph)
792  {
793  FPRINTF (stderr,
794  "%s",
795  _("Cannot connect to ATS service, exiting...\n"));
796  return;
797  }
799  (NULL == opt_pid_str) ? NULL : &pid,
800  GNUNET_YES,
801  &ats_perf_cb, NULL);
802  if (NULL == alh)
803  {
804  FPRINTF (stderr,
805  "%s",
806  _("Cannot issue request to ATS service, exiting...\n"));
808  return;
809  }
811  NULL);
812  return;
813  }
814  if (opt_list_used)
815  {
816  ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
817  if (NULL == ph)
818  FPRINTF (stderr,
819  "%s",
820  _("Cannot connect to ATS service, exiting...\n"));
821 
823  (NULL == opt_pid_str)
824  ? NULL
825  : &pid,
826  GNUNET_NO,
827  &ats_perf_cb, NULL);
828  if (NULL == alh)
829  {
830  FPRINTF (stderr,
831  "%s",
832  _("Cannot issue request to ATS service, exiting...\n"));
834  return;
835  }
837  NULL);
838  return;
839  }
840  if (opt_monitor)
841  {
844  NULL);
846  NULL);
847  if (NULL == ph)
848  {
849  FPRINTF (stderr,
850  "%s",
851  _("Cannot connect to ATS service, exiting...\n"));
853  }
854  return;
855  }
856  if (opt_set_pref)
857  {
858  if (NULL == opt_type_str)
859  {
860  FPRINTF (stderr,
861  "%s",
862  _("No preference type given!\n"));
863  return;
864  }
865  if (NULL == opt_pid_str)
866  {
867  FPRINTF (stderr,
868  "%s",
869  _("No peer given!\n"));
870  return;
871  }
872 
873  for (c = 0; c < strlen (opt_type_str); c++)
874  {
875  if (isupper ((unsigned char) opt_type_str[c]))
876  opt_type_str[c] = tolower ((unsigned char) opt_type_str[c]);
877  }
878 
879  if (0 == strcasecmp ("latency", opt_type_str))
881  else if (0 == strcasecmp ("bandwidth", opt_type_str))
883  else
884  {
885  FPRINTF (stderr,
886  "%s",
887  _("Valid type required\n"));
888  return;
889  }
890 
891  /* set */
892  ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
893  if (NULL == ph)
894  FPRINTF (stderr,
895  "%s",
896  _("Cannot connect to ATS service, exiting...\n"));
897 
899  &pid,
900  type,
901  (double) opt_pref_value,
903 
905  &end,
906  NULL);
907  return;
908  }
909  if (NULL != cpid_str)
910  {
913  &cpid,
914  1000);
917  &end,
918  NULL);
919  return;
920  }
921  ret = 1;
922 }
static int opt_list_all
CLI Option: List all addresses.
Definition: gnunet-ats.c:56
static char * cpid
Which peer should we connect to?
static int opt_monitor
CLI Option: Monitor addresses used.
Definition: gnunet-ats.c:71
static char * opt_type_str
CLI Option: preference type to set.
Definition: gnunet-ats.c:81
static unsigned int print_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg)
Print information about the quotas configured for the various network scopes.
Definition: gnunet-ats.c:636
#define FPRINTF
Definition: plibc.h:683
static void end(void *cls)
Task run on shutdown.
Definition: gnunet-ats.c:270
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
#define GNUNET_TIME_UNIT_SECONDS
One second.
static int opt_list_used
CLI Option: List only addresses currently used (active)
Definition: gnunet-ats.c:51
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_CONTAINER_MultiPeerMap * addresses
Hashmap to store addresses.
Definition: gnunet-ats.c:146
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
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).
End of preference list.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_ATS_ConnectivitySuggestHandle * GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch, const struct GNUNET_PeerIdentity *peer, uint32_t strength)
We would like to receive address suggestions for a peer.
static struct GNUNET_ATS_AddressListHandle * alh
ATS address list handle used.
Definition: gnunet-ats.c:131
static void ats_perf_mon_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, const struct GNUNET_ATS_Properties *prop)
Signature of a function that is called with QoS information about an address.
Definition: gnunet-ats.c:463
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:1246
static struct GNUNET_SCHEDULER_Task * shutdown_task
Shutdown task.
Definition: gnunet-ats.c:141
static int opt_set_pref
CLI Option: set preference.
Definition: gnunet-ats.c:61
static unsigned int opt_pref_value
CLI Option: preference value to set.
Definition: gnunet-ats.c:86
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:1273
static struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle.
Definition: gnunet-ats.c:136
static int stat_results
Number of results returned from service.
Definition: gnunet-ats.c:96
static void ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, const struct GNUNET_ATS_Properties *prop)
Signature of a function that is called with QoS information about an address.
Definition: gnunet-ats.c:588
static struct GNUNET_ATS_ConnectivitySuggestHandle * ats_sh
Handle for address suggestion request.
Definition: gnunet-ats.c:126
static int ret
Final status code.
Definition: gnunet-ats.c:91
static char * cpid_str
Which peer should we connect to?
Definition: gnunet-ats.c:111
Change the peer&#39;s latency value to the given amount.
static char * opt_pid_str
CLI Option: use specific peer.
Definition: gnunet-ats.c:76
struct GNUNET_ATS_PerformanceHandle * GNUNET_ATS_performance_init(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ATS_AddressInformationCallback addr_info_cb, void *addr_info_cb_cls)
Get handle to access performance API of the ATS subsystem.
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
int GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:501
The identity of the host (wraps the signing key of the peer).
static int opt_print_quotas
CLI Option: print quotas configured.
Definition: gnunet-ats.c:66
configuration data
Definition: configuration.c:85
void GNUNET_ATS_performance_change_preference(struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer,...)
Change preferences for the given peer.
Change the peer&#39;s bandwidth value (value per byte of bandwidth in the goal function) to the given amo...
struct GNUNET_ATS_AddressListHandle * GNUNET_ATS_performance_list_addresses(struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer, int all, GNUNET_ATS_AddressInformationCallback infocb, void *infocb_cls)
Get information about addresses known to the ATS subsystem.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_ATS_ConnectivityHandle * ats_ch
Our connectivity handle.
Definition: gnunet-ats.c:121
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 933 of file gnunet-ats.c.

References cpid_str, gettext_noop, GNUNET_free, GNUNET_free_non_null, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_uint(), GNUNET_NO, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), opt_list_all, opt_list_used, opt_monitor, opt_pid_str, opt_pref_value, opt_print_quotas, opt_resolve_addresses_numeric, opt_set_pref, opt_type_str, opt_verbose, res, ret, run(), stat_pending, and stat_receive_done.

935 {
936  int res;
937 
943  stat_pending = 0;
945  opt_type_str = NULL;
946 
949  "used",
950  gettext_noop ("get list of active addresses currently used"),
951  &opt_list_used),
953  "all",
954  gettext_noop ("get list of all active addresses"),
955  &opt_list_all),
956 
958  "connect",
959  NULL,
960  gettext_noop ("connect to PEER"),
961  &cpid_str),
963  "numeric",
964  gettext_noop ("do not resolve IP addresses to hostnames"),
966 
968  "monitor",
969  gettext_noop ("monitor mode"),
970  &opt_monitor),
971 
973  "preference",
974  gettext_noop ("set preference for the given peer"),
975  &opt_set_pref),
976 
978  "quotas",
979  gettext_noop ("print all configured quotas"),
982  "id",
983  "TYPE",
984  gettext_noop ("peer id"),
985  &opt_pid_str),
986 
988  "type",
989  "TYPE",
990  gettext_noop ("preference type to set: latency | bandwidth"),
991  &opt_type_str),
992 
994  "value",
995  "VALUE",
996  gettext_noop ("preference value"),
997  &opt_pref_value),
998 
1000  "verbose",
1001  gettext_noop ("verbose output (include ATS address properties)"),
1002  &opt_verbose),
1004  };
1005 
1006  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1007  return 2;
1008 
1009  res = GNUNET_PROGRAM_run (argc, argv,
1010  "gnunet-ats",
1011  gettext_noop ("Print information about ATS state"),
1012  options,
1013  &run, NULL);
1016  GNUNET_free((void *) argv);
1017 
1018  if (GNUNET_OK == res)
1019  return ret;
1020  else
1021  return 1;
1022 }
static int opt_list_all
CLI Option: List all addresses.
Definition: gnunet-ats.c:56
static int opt_monitor
CLI Option: Monitor addresses used.
Definition: gnunet-ats.c:71
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static int stat_receive_done
State: all pending receive operations done?
Definition: gnunet-ats.c:101
static char * opt_type_str
CLI Option: preference type to set.
Definition: gnunet-ats.c:81
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
static int opt_list_used
CLI Option: List only addresses currently used (active)
Definition: gnunet-ats.c:51
#define GNUNET_NO
Definition: gnunet_common.h:81
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *my_cfg)
Main function that will be run by the scheduler.
Definition: gnunet-ats.c:725
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
static int opt_set_pref
CLI Option: set preference.
Definition: gnunet-ats.c:61
static unsigned int opt_pref_value
CLI Option: preference value to set.
Definition: gnunet-ats.c:86
static int opt_resolve_addresses_numeric
CLI Opt:
Definition: gnunet-ats.c:41
static int res
static int ret
Final status code.
Definition: gnunet-ats.c:91
static int stat_pending
State: number of pending operations.
Definition: gnunet-ats.c:106
static char * cpid_str
Which peer should we connect to?
Definition: gnunet-ats.c:111
static char * opt_pid_str
CLI Option: use specific peer.
Definition: gnunet-ats.c:76
static int opt_print_quotas
CLI Option: print quotas configured.
Definition: gnunet-ats.c:66
static int opt_verbose
CLI Opt: Print verbose ATS information.
Definition: gnunet-ats.c:46
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
int GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:361
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ opt_resolve_addresses_numeric

int opt_resolve_addresses_numeric
static

CLI Opt:

Definition at line 41 of file gnunet-ats.c.

Referenced by ats_perf_cb(), ats_perf_mon_cb(), and main().

◆ opt_verbose

int opt_verbose
static

CLI Opt: Print verbose ATS information.

Definition at line 46 of file gnunet-ats.c.

Referenced by ats_perf_mon_cb(), and main().

◆ opt_list_used

int opt_list_used
static

CLI Option: List only addresses currently used (active)

Definition at line 51 of file gnunet-ats.c.

Referenced by end(), main(), and run().

◆ opt_list_all

int opt_list_all
static

CLI Option: List all addresses.

Definition at line 56 of file gnunet-ats.c.

Referenced by end(), main(), and run().

◆ opt_set_pref

int opt_set_pref
static

CLI Option: set preference.

Definition at line 61 of file gnunet-ats.c.

Referenced by main(), and run().

◆ opt_print_quotas

int opt_print_quotas
static

CLI Option: print quotas configured.

Definition at line 66 of file gnunet-ats.c.

Referenced by main(), and run().

◆ opt_monitor

int opt_monitor
static

CLI Option: Monitor addresses used.

Definition at line 71 of file gnunet-ats.c.

Referenced by main(), and run().

◆ opt_pid_str

char* opt_pid_str
static

CLI Option: use specific peer.

Definition at line 76 of file gnunet-ats.c.

Referenced by main(), and run().

◆ opt_type_str

char* opt_type_str
static

CLI Option: preference type to set.

Definition at line 81 of file gnunet-ats.c.

Referenced by main(), and run().

◆ opt_pref_value

unsigned int opt_pref_value
static

CLI Option: preference value to set.

Definition at line 86 of file gnunet-ats.c.

Referenced by main(), and run().

◆ ret

int ret
static

Final status code.

Definition at line 91 of file gnunet-ats.c.

Referenced by end(), main(), and run().

◆ stat_results

int stat_results
static

Number of results returned from service.

Definition at line 96 of file gnunet-ats.c.

Referenced by ats_perf_cb(), ats_perf_mon_cb(), end(), and run().

◆ stat_receive_done

int stat_receive_done
static

State: all pending receive operations done?

Definition at line 101 of file gnunet-ats.c.

Referenced by ats_perf_cb(), main(), and transport_addr_to_str_cb().

◆ stat_pending

int stat_pending
static

State: number of pending operations.

Definition at line 106 of file gnunet-ats.c.

Referenced by ats_perf_cb(), ats_perf_mon_cb(), main(), and transport_addr_to_str_cb().

◆ cpid_str

char* cpid_str
static

Which peer should we connect to?

Definition at line 111 of file gnunet-ats.c.

Referenced by main(), and run().

◆ ph

struct GNUNET_ATS_PerformanceHandle* ph
static

◆ ats_ch

struct GNUNET_ATS_ConnectivityHandle* ats_ch
static

Our connectivity handle.

Definition at line 121 of file gnunet-ats.c.

Referenced by consider_peer_activate().

◆ ats_sh

struct GNUNET_ATS_ConnectivitySuggestHandle* ats_sh
static

Handle for address suggestion request.

Definition at line 126 of file gnunet-ats.c.

◆ alh

struct GNUNET_ATS_AddressListHandle* alh
static

ATS address list handle used.

Definition at line 131 of file gnunet-ats.c.

Referenced by do_reconnect(), GNUNET_ATS_performance_done(), GNUNET_ATS_performance_list_addresses(), and handle_address_list().

◆ cfg

struct GNUNET_CONFIGURATION_Handle* cfg
static

Configuration handle.

Definition at line 136 of file gnunet-ats.c.

◆ shutdown_task

struct GNUNET_SCHEDULER_Task* shutdown_task
static

Shutdown task.

Definition at line 141 of file gnunet-ats.c.

◆ addresses

struct GNUNET_CONTAINER_MultiPeerMap* addresses
static

Hashmap to store addresses.

Definition at line 146 of file gnunet-ats.c.

Referenced by mlp_create_problem_count_peers(), and plugin_env_address_change_notification().

◆ head

struct PendingResolutions* head
static

Head of list of pending resolution requests.

Definition at line 231 of file gnunet-ats.c.

Referenced by ats_perf_mon_cb(), end(), GPI_plugins_find(), meminfo(), multirecord_process(), and select_peer().

◆ tail

struct PendingResolutions* tail
static

Tail of list of pending resolution requests.

Definition at line 236 of file gnunet-ats.c.

Referenced by discard_all_from_rung_tail(), and meminfo().