diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-06 15:42:11 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-06 15:42:11 +0000 |
commit | 1b130a115ce60a5d567f721e5e1b2d56f8336e29 (patch) | |
tree | 4a1b74577b44ac393a04a957a932f60f337a8125 /src/ats-tool | |
parent | 75455b169f473ab0be5f1049af3c1312b75d8d10 (diff) | |
download | gnunet-1b130a115ce60a5d567f721e5e1b2d56f8336e29.tar.gz gnunet-1b130a115ce60a5d567f721e5e1b2d56f8336e29.zip |
- change peer preferences via cmd line
Diffstat (limited to 'src/ats-tool')
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 78 |
1 files changed, 71 insertions, 7 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index fdb09df41..af6d8381e 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -38,6 +38,14 @@ static int results; | |||
38 | static int resolve_addresses_numeric; | 38 | static int resolve_addresses_numeric; |
39 | static int monitor; | 39 | static int monitor; |
40 | 40 | ||
41 | /** | ||
42 | * For which peer should we change preference values? | ||
43 | */ | ||
44 | static char *pid_str; | ||
45 | |||
46 | static char *type_str; | ||
47 | static unsigned int value; | ||
48 | |||
41 | static struct GNUNET_ATS_PerformanceHandle *ph; | 49 | static struct GNUNET_ATS_PerformanceHandle *ph; |
42 | 50 | ||
43 | static struct GNUNET_CONFIGURATION_Handle *cfg; | 51 | static struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -135,7 +143,10 @@ void end (void *cls, | |||
135 | void testservice_ats (void *cls, | 143 | void testservice_ats (void *cls, |
136 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 144 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
137 | { | 145 | { |
146 | struct GNUNET_PeerIdentity pid; | ||
138 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 147 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
148 | unsigned int c; | ||
149 | unsigned int type; | ||
139 | 150 | ||
140 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 151 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) |
141 | { | 152 | { |
@@ -144,14 +155,56 @@ void testservice_ats (void *cls, | |||
144 | } | 155 | } |
145 | 156 | ||
146 | results = 0; | 157 | results = 0; |
147 | ph = GNUNET_ATS_performance_init (cfg, ats_perf_cb, NULL); | 158 | if (NULL != pid_str) |
148 | if (NULL == ph) | 159 | { |
149 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); | 160 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (pid_str, &pid.hashPubKey)) |
150 | 161 | { | |
151 | if (GNUNET_NO == monitor) | 162 | FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), pid_str); |
152 | end_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end, NULL); | 163 | return; |
164 | } | ||
165 | if (NULL == type_str) | ||
166 | { | ||
167 | FPRINTF (stderr, _("Type required\n")); | ||
168 | return; | ||
169 | } | ||
170 | |||
171 | for (c = 0; c<strlen(type_str); c++) | ||
172 | if (isupper (type_str[c])) | ||
173 | type_str[c] = tolower (type_str[c]); | ||
174 | |||
175 | |||
176 | if (0 == strcasecmp("latency", type_str)) | ||
177 | type = GNUNET_ATS_PREFERENCE_LATENCY; | ||
178 | else if (0 == strcasecmp("bandwidth", type_str)) | ||
179 | type = GNUNET_ATS_PREFERENCE_BANDWIDTH; | ||
180 | else | ||
181 | { | ||
182 | FPRINTF (stderr, _("Type required\n")); | ||
183 | return; | ||
184 | } | ||
185 | |||
186 | /* set */ | ||
187 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); | ||
188 | if (NULL == ph) | ||
189 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); | ||
190 | |||
191 | GNUNET_ATS_change_preference (ph, &pid, type, (double) value, GNUNET_ATS_PREFERENCE_END); | ||
192 | |||
193 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); | ||
194 | } | ||
153 | else | 195 | else |
154 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); | 196 | { |
197 | ph = GNUNET_ATS_performance_init (cfg, ats_perf_cb, NULL); | ||
198 | if (NULL == ph) | ||
199 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); | ||
200 | |||
201 | if (GNUNET_NO == monitor) | ||
202 | end_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end, NULL); | ||
203 | else | ||
204 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); | ||
205 | } | ||
206 | |||
207 | |||
155 | ret = 1; | 208 | ret = 1; |
156 | } | 209 | } |
157 | 210 | ||
@@ -196,6 +249,15 @@ main (int argc, char *const *argv) | |||
196 | {'m', "monitor", NULL, | 249 | {'m', "monitor", NULL, |
197 | gettext_noop ("monitor mode"), | 250 | gettext_noop ("monitor mode"), |
198 | 0, &GNUNET_GETOPT_set_one, &monitor}, | 251 | 0, &GNUNET_GETOPT_set_one, &monitor}, |
252 | {'p', "preference", "PEER", | ||
253 | gettext_noop ("set preference for the given peer"), | ||
254 | 1, &GNUNET_GETOPT_set_string, &pid_str}, | ||
255 | {'t', "type", "TYPE", | ||
256 | gettext_noop ("preference type to set: latency | bandwidth"), | ||
257 | 1, &GNUNET_GETOPT_set_string, &type_str}, | ||
258 | {'k', "value", "VALUE", | ||
259 | gettext_noop ("preference value"), | ||
260 | 1, &GNUNET_GETOPT_set_uint, &value}, | ||
199 | GNUNET_GETOPT_OPTION_END | 261 | GNUNET_GETOPT_OPTION_END |
200 | }; | 262 | }; |
201 | 263 | ||
@@ -205,6 +267,8 @@ main (int argc, char *const *argv) | |||
205 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats", | 267 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats", |
206 | gettext_noop ("Print information about ATS state"), options, &run, | 268 | gettext_noop ("Print information about ATS state"), options, &run, |
207 | NULL); | 269 | NULL); |
270 | GNUNET_free_non_null (pid_str); | ||
271 | GNUNET_free_non_null (type_str); | ||
208 | GNUNET_free ((void *) argv); | 272 | GNUNET_free ((void *) argv); |
209 | 273 | ||
210 | if (GNUNET_OK == res) | 274 | if (GNUNET_OK == res) |