GNUnet  0.10.x
gnunet-ats.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009--2015 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_ats_service.h"
31 
35 #define UNLIMITED_STRING "unlimited"
36 
37 
42 
46 static int opt_verbose;
47 
51 static int opt_list_used;
52 
56 static int opt_list_all;
57 
61 static int opt_set_pref;
62 
66 static int opt_print_quotas;
67 
71 static int opt_monitor;
72 
76 static char *opt_pid_str;
77 
81 static char *opt_type_str;
82 
86 static unsigned int opt_pref_value;
87 
91 static int ret;
92 
96 static int stat_results;
97 
101 static int stat_receive_done;
102 
106 static int stat_pending;
107 
111 static char *cpid_str;
112 
117 
122 
127 
132 
137 
142 
147 
148 
159 
164 
169 
175 
180 
185 
190 
194  int active;
195 };
196 
197 
202 struct ATSAddress {
207 
212 
217 
221  int active;
222 };
223 
224 
228 static struct PendingResolutions *head;
229 
233 static struct PendingResolutions *tail;
234 
235 
244 static int
245 free_addr_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
246 {
247  struct ATSAddress *a = value;
248 
250  GNUNET_CONTAINER_multipeermap_remove(addresses, key, value));
252  GNUNET_free(a);
253  return GNUNET_OK;
254 }
255 
256 
262 static void
263 end(void *cls)
264 {
265  struct PendingResolutions *pr;
266  struct PendingResolutions *next;
267  unsigned int pending;
268 
269  if (NULL != alh)
270  {
272  alh = NULL;
273  }
274 
275  if (NULL != ph)
276  {
278  ph = NULL;
279  }
280 
281  pending = 0;
282  next = head;
283  while (NULL != (pr = next))
284  {
285  next = pr->next;
286  GNUNET_CONTAINER_DLL_remove(head, tail, pr);
288  GNUNET_free(pr->address);
289  GNUNET_free(pr);
290  pending++;
291  }
294  addresses = NULL;
295 
296  if (0 < pending)
297  fprintf(stdout, _("%u address resolutions had a timeout\n"), pending);
299  fprintf(stdout,
300  _("ATS returned stat_results for %u addresses\n"),
301  stat_results);
302 
303  if (NULL != ats_sh)
304  {
306  ats_sh = NULL;
307  }
308  if (NULL != ats_ch)
309  {
311  ats_ch = NULL;
312  }
313  ret = 0;
314 }
315 
316 
333 static void
334 transport_addr_to_str_cb(void *cls, const char *address, int res)
335 {
336  struct PendingResolutions *pr = cls;
337 
338  if (NULL == address)
339  {
340  /* We're done */
341  GNUNET_CONTAINER_DLL_remove(head, tail, pr);
342  GNUNET_free(pr->address);
343  GNUNET_free(pr);
344  stat_pending--;
345 
346  if ((GNUNET_YES == stat_receive_done) && (0 == stat_pending))
347  {
348  /* All messages received and no resolutions pending*/
349  if (shutdown_task != NULL)
350  GNUNET_SCHEDULER_cancel(shutdown_task);
351  shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
352  }
353  return;
354  }
355  switch (res)
356  {
357  case GNUNET_SYSERR:
358  fprintf(
359  stderr,
360  "Failed to convert address for peer `%s' plugin `%s' length %u to string (communication error)\n",
361  GNUNET_i2s(&pr->address->peer),
362  pr->address->transport_name,
363  (unsigned int)pr->address->address_length);
364  return;
365 
366  case GNUNET_NO:
367  fprintf(
368  stderr,
369  "Failed to convert address for peer `%s' plugin `%s' length %u to string (address invalid or not supported)\n",
370  GNUNET_i2s(&pr->address->peer),
371  pr->address->transport_name,
372  (unsigned int)pr->address->address_length);
373  return;
374 
375  case GNUNET_OK:
376  /* continues below */
377  break;
378 
379  default:
380  GNUNET_break(0);
381  return;
382  }
383 
384  fprintf(
385  stdout,
386  _(
387  "Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
388  GNUNET_i2s(&pr->address->peer),
389  pr->address->transport_name,
390  address,
392  ntohl(pr->bandwidth_out.value__),
393  ntohl(pr->bandwidth_in.value__),
394  pr->active ? _("active ") : _("inactive "));
395 }
396 
397 
405  const struct GNUNET_HELLO_Address *src;
406 
410  struct ATSAddress *res;
411 };
412 
413 
422 static int
423 find_address_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
424 {
425  struct AddressFindCtx *actx = cls;
426  struct ATSAddress *exist = value;
427 
428  if (0 == GNUNET_HELLO_address_cmp(actx->src, exist->address))
429  {
430  actx->res = exist;
431  return GNUNET_NO;
432  }
433  return GNUNET_YES;
434 }
435 
436 
450 static void
451 ats_perf_mon_cb(void *cls,
452  const struct GNUNET_HELLO_Address *address,
453  int active,
456  const struct GNUNET_ATS_Properties *prop)
457 {
458  struct PendingResolutions *pr;
459  struct PendingResolutions *cur;
460  struct PendingResolutions *next;
461 
462  if (NULL == address)
463  {
464  /* ATS service temporarily disconnected, remove current state */
465  next = head;
466  for (cur = next; NULL != cur; cur = next)
467  {
468  next = cur->next;
469  GNUNET_CONTAINER_DLL_remove(head, tail, cur);
472  GNUNET_free(cur);
473  }
475  return;
476  }
477  if (GNUNET_SYSERR == active)
478  {
479  /* remove address */
480  struct AddressFindCtx actx;
481 
482  actx.src = address;
483  actx.res = NULL;
485  &address->peer,
487  &actx);
488  if (NULL == actx.res)
489  {
490  GNUNET_break(0);
491  return;
492  }
495  &address->peer,
496  actx.res));
497  fprintf(stdout,
498  _("Removed address of peer `%s' with plugin `%s'\n"),
499  GNUNET_i2s(&address->peer),
500  actx.res->address->transport_name);
502  return;
503  }
504 
505  if (GNUNET_NO == opt_verbose)
506  {
507  struct AddressFindCtx actx;
508  struct ATSAddress *a;
509 
510  actx.src = address;
511  actx.res = NULL;
513  &address->peer,
515  &actx);
516  if ((NULL != actx.res))
517  {
518  if ((bandwidth_in.value__ == actx.res->bandwidth_in.value__) &&
519  (bandwidth_out.value__ == actx.res->bandwidth_out.value__) &&
520  (active == actx.res->active))
521  {
522  return; /* Nothing to do here */
523  }
524  else
525  {
526  actx.res->bandwidth_in = bandwidth_in;
528  }
529  }
530  else
531  {
532  a = GNUNET_new(struct ATSAddress);
533 
534  a->address = GNUNET_HELLO_address_copy(address);
537  a->active = active;
539  addresses,
540  &address->peer,
541  a,
543  }
544  }
545 
546  pr = GNUNET_new(struct PendingResolutions);
547  pr->properties = *prop;
548  pr->address = GNUNET_HELLO_address_copy(address);
551  pr->active = active;
553  cfg,
554  address,
558  pr);
559  GNUNET_CONTAINER_DLL_insert(head, tail, pr);
560  stat_results++;
561  stat_pending++;
562 }
563 
564 
576 static void
577 ats_perf_cb(void *cls,
578  const struct GNUNET_HELLO_Address *address,
579  int active,
582  const struct GNUNET_ATS_Properties *prop)
583 {
584  struct PendingResolutions *pr;
585 
586  if (NULL == address)
587  {
588  /* All messages received */
590  alh = NULL;
591  if (0 == stat_pending)
592  {
593  /* All messages received and no resolutions pending*/
594  if (shutdown_task != NULL)
595  GNUNET_SCHEDULER_cancel(shutdown_task);
596  shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
597  }
598  return;
599  }
600 
601  pr = GNUNET_new(struct PendingResolutions);
602  pr->properties = *prop;
603  pr->address = GNUNET_HELLO_address_copy(address);
606  pr->active = active;
608  cfg,
609  address,
613  pr);
614  GNUNET_CONTAINER_DLL_insert(head, tail, pr);
615  stat_results++;
616  stat_pending++;
617 }
618 
619 
627 static unsigned int
629 {
630  char *entry_in = NULL;
631  char *entry_out = NULL;
632  char *quota_out_str;
633  char *quota_in_str;
634  unsigned long long int quota_out;
635  unsigned long long int quota_in;
636  int c;
637 
638  for (c = 0; (c < GNUNET_NT_COUNT); c++)
639  {
640  GNUNET_asprintf(&entry_out, "%s_QUOTA_OUT", GNUNET_NT_to_string(c));
641  GNUNET_asprintf(&entry_in, "%s_QUOTA_IN", GNUNET_NT_to_string(c));
642 
643  /* quota out */
645  "ats",
646  entry_out,
647  &quota_out_str))
648  {
649  if (0 == strcmp(quota_out_str, UNLIMITED_STRING) ||
650  (GNUNET_SYSERR ==
651  GNUNET_STRINGS_fancy_size_to_bytes(quota_out_str, &quota_out)))
652  quota_out = UINT32_MAX;
653 
654  GNUNET_free(quota_out_str);
655  GNUNET_asprintf(&quota_out_str, "%llu", quota_out);
656  }
657  else
658  {
659  fprintf(stderr,
660  "Outbound quota for network `%11s' not configured!\n",
662  GNUNET_asprintf(&quota_out_str, "-");
663  }
664  GNUNET_free(entry_out);
665 
666  /* quota in */
668  "ats",
669  entry_in,
670  &quota_in_str))
671  {
672  if (0 == strcmp(quota_in_str, UNLIMITED_STRING) ||
673  (GNUNET_SYSERR ==
674  GNUNET_STRINGS_fancy_size_to_bytes(quota_in_str, &quota_in)))
675  quota_in = UINT32_MAX;
676  GNUNET_free(quota_in_str);
677  GNUNET_asprintf(&quota_in_str, "%llu", quota_in);
678  }
679  else
680  {
681  fprintf(stderr,
682  "Inbound quota for network `%11s' not configured!\n",
684  GNUNET_asprintf(&quota_in_str, "-");
685  }
686  GNUNET_free(entry_in);
687 
688  fprintf(stdout,
689  _("Quota for network `%11s' (in/out): %10s / %10s\n"),
691  quota_in_str,
692  quota_out_str);
693  GNUNET_free(quota_out_str);
694  GNUNET_free(quota_in_str);
695  }
696  return GNUNET_NT_COUNT;
697 }
698 
699 
708 static void
709 run(void *cls,
710  char *const *args,
711  const char *cfgfile,
712  const struct GNUNET_CONFIGURATION_Handle *my_cfg)
713 {
714  struct GNUNET_PeerIdentity pid;
715  struct GNUNET_PeerIdentity cpid;
716  unsigned int c;
717  unsigned int type;
718 
719  cfg = (struct GNUNET_CONFIGURATION_Handle *)my_cfg;
721  stat_results = 0;
722 
723  c = 0;
724  if (NULL != opt_pid_str)
725  {
726  if (GNUNET_OK !=
728  strlen(opt_pid_str),
729  &pid.public_key))
730  {
731  fprintf(stderr, _("Failed to parse peer identity `%s'\n"), opt_pid_str);
732  return;
733  }
734  }
735  if (NULL != cpid_str)
736  {
737  if (GNUNET_OK !=
739  strlen(cpid_str),
740  &cpid.public_key))
741  {
742  fprintf(stderr, _("Failed to parse peer identity `%s'\n"), cpid_str);
743  return;
744  }
745  c++;
746  }
747 
749 
750  if (1 < c)
751  {
752  fprintf(stderr,
753  _("Please select one operation: %s or %s or %s or %s or %s\n"),
754  "--used",
755  "--all",
756  "--monitor",
757  "--preference",
758  "--quotas");
759  return;
760  }
761  if (0 == c)
762  opt_list_used = GNUNET_YES; /* set default */
763  if (opt_print_quotas)
764  {
765  ret = print_quotas(cfg);
766  return;
767  }
768  if (opt_list_all)
769  {
770  ph = GNUNET_ATS_performance_init(cfg, NULL, NULL);
771  if (NULL == ph)
772  {
773  fprintf(stderr, "%s", _("Cannot connect to ATS service, exiting...\n"));
774  return;
775  }
777  (NULL == opt_pid_str) ? NULL
778  : &pid,
779  GNUNET_YES,
780  &ats_perf_cb,
781  NULL);
782  if (NULL == alh)
783  {
784  fprintf(stderr,
785  "%s",
786  _("Cannot issue request to ATS service, exiting...\n"));
787  shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
788  return;
789  }
790  shutdown_task = GNUNET_SCHEDULER_add_shutdown(&end, NULL);
791  return;
792  }
793  if (opt_list_used)
794  {
795  ph = GNUNET_ATS_performance_init(cfg, NULL, NULL);
796  if (NULL == ph)
797  fprintf(stderr, "%s", _("Cannot connect to ATS service, exiting...\n"));
798 
800  (NULL == opt_pid_str) ? NULL
801  : &pid,
802  GNUNET_NO,
803  &ats_perf_cb,
804  NULL);
805  if (NULL == alh)
806  {
807  fprintf(stderr,
808  "%s",
809  _("Cannot issue request to ATS service, exiting...\n"));
810  shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
811  return;
812  }
813  shutdown_task = GNUNET_SCHEDULER_add_shutdown(&end, NULL);
814  return;
815  }
816  if (opt_monitor)
817  {
819  shutdown_task = GNUNET_SCHEDULER_add_shutdown(&end, NULL);
820  if (NULL == ph)
821  {
822  fprintf(stderr, "%s", _("Cannot connect to ATS service, exiting...\n"));
824  }
825  return;
826  }
827  if (opt_set_pref)
828  {
829  if (NULL == opt_type_str)
830  {
831  fprintf(stderr, "%s", _("No preference type given!\n"));
832  return;
833  }
834  if (NULL == opt_pid_str)
835  {
836  fprintf(stderr, "%s", _("No peer given!\n"));
837  return;
838  }
839 
840  for (c = 0; c < strlen(opt_type_str); c++)
841  {
842  if (isupper((unsigned char)opt_type_str[c]))
843  opt_type_str[c] = tolower((unsigned char)opt_type_str[c]);
844  }
845 
846  if (0 == strcasecmp("latency", opt_type_str))
848  else if (0 == strcasecmp("bandwidth", opt_type_str))
850  else
851  {
852  fprintf(stderr, "%s", _("Valid type required\n"));
853  return;
854  }
855 
856  /* set */
857  ph = GNUNET_ATS_performance_init(cfg, NULL, NULL);
858  if (NULL == ph)
859  fprintf(stderr, "%s", _("Cannot connect to ATS service, exiting...\n"));
860 
862  &pid,
863  type,
864  (double)opt_pref_value,
866 
867  shutdown_task =
869  return;
870  }
871  if (NULL != cpid_str)
872  {
873  ats_ch = GNUNET_ATS_connectivity_init(cfg);
874  ats_sh = GNUNET_ATS_connectivity_suggest(ats_ch, &cpid, 1000);
875  shutdown_task =
877  return;
878  }
879  ret = 1;
880 }
881 
882 
890 int
891 main(int argc, char *const *argv)
892 {
893  int res;
894 
900  stat_pending = 0;
902  opt_type_str = NULL;
903 
904  struct GNUNET_GETOPT_CommandLineOption options[] =
906  "used",
907  gettext_noop(
908  "get list of active addresses currently used"),
909  &opt_list_used),
911  "all",
912  gettext_noop(
913  "get list of all active addresses"),
914  &opt_list_all),
915 
917  "connect",
918  NULL,
919  gettext_noop("connect to PEER"),
920  &cpid_str),
922  "numeric",
923  gettext_noop(
924  "do not resolve IP addresses to hostnames"),
926 
928  "monitor",
929  gettext_noop("monitor mode"),
930  &opt_monitor),
931 
933  "preference",
934  gettext_noop(
935  "set preference for the given peer"),
936  &opt_set_pref),
937 
939  "quotas",
940  gettext_noop("print all configured quotas"),
943  "id",
944  "TYPE",
945  gettext_noop("peer id"),
946  &opt_pid_str),
947 
949  "type",
950  "TYPE",
951  gettext_noop(
952  "preference type to set: latency | bandwidth"),
953  &opt_type_str),
954 
956  "value",
957  "VALUE",
958  gettext_noop("preference value"),
959  &opt_pref_value),
960 
962  'V',
963  "verbose",
964  gettext_noop("verbose output (include ATS address properties)"),
965  &opt_verbose),
967 
968  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
969  return 2;
970 
971  res = GNUNET_PROGRAM_run(argc,
972  argv,
973  "gnunet-ats",
974  gettext_noop("Print information about ATS state"),
975  options,
976  &run,
977  NULL);
980  GNUNET_free((void *)argv);
981 
982  if (GNUNET_OK == res)
983  return ret;
984  else
985  return 1;
986 }
987 
988 /* end of gnunet-ats.c */
#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:216
static int opt_list_all
CLI Option: List all addresses.
Definition: gnunet-ats.c:56
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:189
static int opt_monitor
CLI Option: Monitor addresses used.
Definition: gnunet-ats.c:71
int main(int argc, char *const *argv)
The main function.
Definition: gnunet-ats.c:891
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:43
int active
Is this an active address?
Definition: gnunet-ats.c:221
#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 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:628
static void end(void *cls)
Task run on shutdown.
Definition: gnunet-ats.c:263
Structure used to remember all pending address resolutions.
Definition: gnunet-ats.c:154
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:1284
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_HELLO_Address * address
Copy of the address we are resolving.
Definition: gnunet-ats.c:168
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
struct GNUNET_ATS_Properties properties
Performance data.
Definition: gnunet-ats.c:179
void GNUNET_ATS_performance_done(struct GNUNET_ATS_PerformanceHandle *ph)
Client is done using the ATS performance subsystem, release resources.
struct PendingResolutions * prev
Kept in a DLL.
Definition: gnunet-ats.c:163
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:318
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:78
static struct GNUNET_CONTAINER_MultiPeerMap * addresses
Hashmap to store addresses.
Definition: gnunet-ats.c:146
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:709
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Definition of a command line option.
void GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh)
We no longer care about being connected to a peer.
static const struct GNUNET_CONFIGURATION_Handle * my_cfg
Our configuration.
Definition: gnunet-cadet.c:97
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
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).
const struct GNUNET_HELLO_Address * src
Address we are looking for.
Definition: gnunet-ats.c:405
ATS performance characteristics for an address.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Linked list of pending reservations.
End of preference list.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
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.
uint32_t value__
The actual value (bytes per second).
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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:451
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
struct GNUNET_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:1237
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
struct PendingResolutions * next
Kept in a DLL.
Definition: gnunet-ats.c:158
static char * value
Value of the record to add/remove.
static unsigned int opt_pref_value
CLI Option: preference value to set.
Definition: gnunet-ats.c:86
struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx
Handle to the transport request to convert the address to a string.
Definition: gnunet-ats.c:174
void GNUNET_TRANSPORT_address_to_string_cancel(struct GNUNET_TRANSPORT_AddressToStringContext *alc)
Cancel request for address conversion.
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:1264
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:211
static struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle.
Definition: gnunet-ats.c:136
Handle for ATS address suggestion requests.
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:245
const char * transport_name
Name of the transport plugin enabling the communication using this address.
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:440
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:577
static struct GNUNET_ATS_ConnectivitySuggestHandle * ats_sh
Handle for address suggestion request.
Definition: gnunet-ats.c:126
Internal representation of the hash map.
static int res
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.
static int ret
Final status code.
Definition: gnunet-ats.c:91
#define UNLIMITED_STRING
String to respresent unlimited.
Definition: gnunet-ats.c:35
struct GNUNET_HashCode key
The key used in the DHT.
static int stat_pending
State: number of pending operations.
Definition: gnunet-ats.c:106
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static char * cpid_str
Which peer should we connect to?
Definition: gnunet-ats.c:111
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.
Change the peer&#39;s latency value to the given amount.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Amount of outbound bandwidth assigned by ATS.
Definition: gnunet-ats.c:184
static unsigned int pending
The number of queries that are outstanding.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
static char * opt_pid_str
CLI Option: use specific peer.
Definition: gnunet-ats.c:76
int active
Is this an active address?
Definition: gnunet-ats.c:194
ATS Handle to obtain and/or modify performance information.
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:423
struct ATSAddress * res
Where to write the struct ATSAddress if we found one that matches.
Definition: gnunet-ats.c:410
enum GNUNET_NetworkType scope
Which network scope does the respective address belong to? This property does not change...
Allow multiple values with the same key.
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.
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.
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
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
struct GNUNET_HELLO_Address * address
Address information.
Definition: gnunet-ats.c:206
configuration data
Definition: configuration.c:83
static struct PendingResolutions * head
Head of list of pending resolution requests.
Definition: gnunet-ats.c:228
Information we keep for an address.
Definition: gnunet-ats.c:202
void GNUNET_ATS_performance_change_preference(struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer,...)
Change preferences for the given peer.
An address for communicating with a peer.
static int opt_verbose
CLI Opt: Print verbose ATS information.
Definition: gnunet-ats.c:46
void GNUNET_ATS_performance_list_addresses_cancel(struct GNUNET_ATS_AddressListHandle *alh)
Cancel a pending address listing operation.
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.
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:334
Closure for find_address_it().
Definition: gnunet-ats.c:401
Automatic transport selection and outbound bandwidth determination.
Entry in list of pending tasks.
Definition: scheduler.c:131
Change the peer&#39;s bandwidth value (value per byte of bandwidth in the goal function) to the given amo...
static struct PendingResolutions * tail
Tail of list of pending resolution requests.
Definition: gnunet-ats.c:233
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:367
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:77
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.
Handle to the ATS subsystem for connectivity management.
void GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
Client is done with ATS connectivity management, release resources.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_NT_COUNT
#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.
static struct GNUNET_ATS_ConnectivityHandle * ats_ch
Our connectivity handle.
Definition: gnunet-ats.c:121
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
#define gettext_noop(String)
Definition: gettext.h:69
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956