GNUnet  0.10.x
plugin_ats2_common.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011-2015, 2018 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  */
30 #define DEFAULT_BANDWIDTH 65536
31 
32 
42 static void
44  const char *nts,
45  const char *direction,
46  unsigned long long *quota)
47 {
48  char *quota_str;
49  char *quota_s;
50  int res;
51 
52  GNUNET_asprintf (&quota_s,
53  "%s_QUOTA_%s",
54  nts,
55  direction);
56  if (GNUNET_OK !=
58  "ATS",
59  quota_s,
60  &quota_str))
61  {
63  "ATS",
64  quota_s);
65  GNUNET_free (quota_s);
66  return;
67  }
68  GNUNET_free (quota_s);
69  res = GNUNET_NO;
70  if (0 == strcmp (quota_str,
71  "unlimited"))
72  {
73  *quota = ULONG_MAX;
74  res = GNUNET_YES;
75  }
76  if ((GNUNET_NO == res) &&
77  (GNUNET_OK ==
79  quota)))
80  res = GNUNET_YES;
81  if ((GNUNET_NO == res) &&
82  (1 ==
83  sscanf (quota_str,
84  "%llu",
85  quota)))
86  res = GNUNET_YES;
87  if (GNUNET_NO == res)
88  {
90  _ (
91  "Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"),
92  direction,
93  nts,
94  quota_str,
95  (unsigned long long) DEFAULT_BANDWIDTH);
96  *quota = DEFAULT_BANDWIDTH;
97  }
98  GNUNET_free (quota_str);
99 }
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:319
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
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 struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static void get_quota(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *nts, const char *direction, unsigned long long *quota)
Parse cfg for quota as specified for direction of network type nts.
static unsigned long long quota
How much space are we allowed to use?
#define DEFAULT_BANDWIDTH
Default bandwidth assigned to a network: 64 KB/s.
configuration data
Definition: configuration.c:85
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_free(ptr)
Wrapper around free.