aboutsummaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats2_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/plugin_ats2_common.c')
-rw-r--r--src/ats/plugin_ats2_common.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/ats/plugin_ats2_common.c b/src/ats/plugin_ats2_common.c
new file mode 100644
index 000000000..6911ba44d
--- /dev/null
+++ b/src/ats/plugin_ats2_common.c
@@ -0,0 +1,96 @@
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/**
19 * @file ats/plugin_ats2_common.c
20 * @brief ATS solver helper functions to be inlined
21 * @author Matthias Wachs
22 * @author Christian Grothoff
23 */
24
25/**
26 * Default bandwidth assigned to a network: 64 KB/s
27 */
28#define DEFAULT_BANDWIDTH 65536
29
30
31/**
32 * Parse @a cfg for @a quota as specified for @a direction of
33 * network type @a nts.
34 *
35 * @param cfg configuration to parse
36 * @param nts network type string to get quota for
37 * @param direction direction to get quota for ("IN" or "OUT")
38 * @param quota[out] set to quota, #DEFAULT_BANDWIDTH if @a cfg does not say anything useful
39 */
40static void
41get_quota (const struct GNUNET_CONFIGURATION_Handle *cfg,
42 const char *nts,
43 const char *direction,
44 unsigned long long *quota)
45{
46 char *quota_str;
47 char *quota_s;
48 int res;
49
50 GNUNET_asprintf (&quota_s,
51 "%s_QUOTA_%s",
52 nts,
53 direction);
54 if (GNUNET_OK !=
55 GNUNET_CONFIGURATION_get_value_string (cfg,
56 "ATS",
57 quota_s,
58 &quota_str))
59 {
60 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
61 "ATS",
62 quota_s);
63 GNUNET_free (quota_s);
64 return;
65 }
66 GNUNET_free (quota_s);
67 res = GNUNET_NO;
68 if (0 == strcmp (quota_str,
69 "unlimited"))
70 {
71 *quota = ULONG_MAX;
72 res = GNUNET_YES;
73 }
74 if ( (GNUNET_NO == res) &&
75 (GNUNET_OK ==
76 GNUNET_STRINGS_fancy_size_to_bytes (quota_str,
77 quota)) )
78 res = GNUNET_YES;
79 if ( (GNUNET_NO == res) &&
80 (1 ==
81 sscanf (quota_str,
82 "%llu",
83 quota)) )
84 res = GNUNET_YES;
85 if (GNUNET_NO == res)
86 {
87 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
88 _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"),
89 direction,
90 nts,
91 quota_str,
92 (unsigned long long) DEFAULT_BANDWIDTH);
93 *quota = DEFAULT_BANDWIDTH;
94 }
95 GNUNET_free (quota_str);
96}