diff options
author | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
commit | 6e599264ad13e8fc105493d74d7c11d46f8739ed (patch) | |
tree | 169bef1ecbade5a659831fb169f3ae6943af127f /src/dht/gnunet-dht-monitor.c | |
parent | 4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff) | |
download | gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip |
first step to remove plibc
Diffstat (limited to 'src/dht/gnunet-dht-monitor.c')
-rw-r--r-- | src/dht/gnunet-dht-monitor.c | 110 |
1 files changed, 56 insertions, 54 deletions
diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c index 52a57473b..3787b7cfa 100644 --- a/src/dht/gnunet-dht-monitor.c +++ b/src/dht/gnunet-dht-monitor.c | |||
@@ -39,7 +39,7 @@ static char *query_key; | |||
39 | /** | 39 | /** |
40 | * User supplied timeout value (in seconds) | 40 | * User supplied timeout value (in seconds) |
41 | */ | 41 | */ |
42 | static struct GNUNET_TIME_Relative timeout_request = { 60000 }; | 42 | static struct GNUNET_TIME_Relative timeout_request = {60000}; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Be verbose | 45 | * Be verbose |
@@ -86,7 +86,7 @@ static void | |||
86 | cleanup_task (void *cls) | 86 | cleanup_task (void *cls) |
87 | { | 87 | { |
88 | if (verbose) | 88 | if (verbose) |
89 | FPRINTF (stderr, "%s", "Cleaning up!\n"); | 89 | fprintf (stderr, "%s", "Cleaning up!\n"); |
90 | if (NULL != monitor_handle) | 90 | if (NULL != monitor_handle) |
91 | { | 91 | { |
92 | GNUNET_DHT_monitor_stop (monitor_handle); | 92 | GNUNET_DHT_monitor_stop (monitor_handle); |
@@ -118,7 +118,6 @@ timeout_task (void *cls) | |||
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | |||
122 | /** | 121 | /** |
123 | * Callback called on each GET request going through the DHT. | 122 | * Callback called on each GET request going through the DHT. |
124 | * | 123 | * |
@@ -139,13 +138,13 @@ get_callback (void *cls, | |||
139 | uint32_t desired_replication_level, | 138 | uint32_t desired_replication_level, |
140 | unsigned int path_length, | 139 | unsigned int path_length, |
141 | const struct GNUNET_PeerIdentity *path, | 140 | const struct GNUNET_PeerIdentity *path, |
142 | const struct GNUNET_HashCode * key) | 141 | const struct GNUNET_HashCode *key) |
143 | { | 142 | { |
144 | FPRINTF (stdout, | 143 | fprintf (stdout, |
145 | "GET #%u: type %d, key `%s'\n", | 144 | "GET #%u: type %d, key `%s'\n", |
146 | result_count, | 145 | result_count, |
147 | (int) type, | 146 | (int) type, |
148 | GNUNET_h2s_full(key)); | 147 | GNUNET_h2s_full (key)); |
149 | result_count++; | 148 | result_count++; |
150 | } | 149 | } |
151 | 150 | ||
@@ -172,14 +171,14 @@ get_resp_callback (void *cls, | |||
172 | const struct GNUNET_PeerIdentity *put_path, | 171 | const struct GNUNET_PeerIdentity *put_path, |
173 | unsigned int put_path_length, | 172 | unsigned int put_path_length, |
174 | struct GNUNET_TIME_Absolute exp, | 173 | struct GNUNET_TIME_Absolute exp, |
175 | const struct GNUNET_HashCode * key, | 174 | const struct GNUNET_HashCode *key, |
176 | const void *data, | 175 | const void *data, |
177 | size_t size) | 176 | size_t size) |
178 | { | 177 | { |
179 | FPRINTF (stdout, | 178 | fprintf (stdout, |
180 | (GNUNET_BLOCK_TYPE_TEST == type) | 179 | (GNUNET_BLOCK_TYPE_TEST == type) |
181 | ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n" | 180 | ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n" |
182 | : "RESPONSE #%u (%s): type %d, key `%s'\n", | 181 | : "RESPONSE #%u (%s): type %d, key `%s'\n", |
183 | result_count, | 182 | result_count, |
184 | GNUNET_STRINGS_absolute_time_to_string (exp), | 183 | GNUNET_STRINGS_absolute_time_to_string (exp), |
185 | (int) type, | 184 | (int) type, |
@@ -214,18 +213,18 @@ put_callback (void *cls, | |||
214 | unsigned int path_length, | 213 | unsigned int path_length, |
215 | const struct GNUNET_PeerIdentity *path, | 214 | const struct GNUNET_PeerIdentity *path, |
216 | struct GNUNET_TIME_Absolute exp, | 215 | struct GNUNET_TIME_Absolute exp, |
217 | const struct GNUNET_HashCode * key, | 216 | const struct GNUNET_HashCode *key, |
218 | const void *data, | 217 | const void *data, |
219 | size_t size) | 218 | size_t size) |
220 | { | 219 | { |
221 | FPRINTF (stdout, | 220 | fprintf (stdout, |
222 | (GNUNET_BLOCK_TYPE_TEST == type) | 221 | (GNUNET_BLOCK_TYPE_TEST == type) |
223 | ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n" | 222 | ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n" |
224 | : "PUT %u (%s): type %d, key `%s'\n", | 223 | : "PUT %u (%s): type %d, key `%s'\n", |
225 | result_count, | 224 | result_count, |
226 | GNUNET_STRINGS_absolute_time_to_string (exp), | 225 | GNUNET_STRINGS_absolute_time_to_string (exp), |
227 | (int) type, | 226 | (int) type, |
228 | GNUNET_h2s_full(key), | 227 | GNUNET_h2s_full (key), |
229 | (unsigned int) size, | 228 | (unsigned int) size, |
230 | (char *) data); | 229 | (char *) data); |
231 | result_count++; | 230 | result_count++; |
@@ -253,33 +252,29 @@ run (void *cls, | |||
253 | 252 | ||
254 | if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) | 253 | if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) |
255 | { | 254 | { |
256 | FPRINTF (stderr, "%s", | 255 | fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n")); |
257 | _("Failed to connect to DHT service!\n")); | ||
258 | ret = 1; | 256 | ret = 1; |
259 | return; | 257 | return; |
260 | } | 258 | } |
261 | if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */ | 259 | if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */ |
262 | block_type = GNUNET_BLOCK_TYPE_TEST; | 260 | block_type = GNUNET_BLOCK_TYPE_TEST; |
263 | if (NULL != query_key) | 261 | if (NULL != query_key) |
264 | { | 262 | { |
265 | key = &hc; | 263 | key = &hc; |
266 | if (GNUNET_OK != | 264 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (query_key, key)) |
267 | GNUNET_CRYPTO_hash_from_string (query_key, key)) | 265 | GNUNET_CRYPTO_hash (query_key, strlen (query_key), key); |
268 | GNUNET_CRYPTO_hash (query_key, strlen (query_key), key); | 266 | } |
269 | } | ||
270 | else | 267 | else |
271 | { | 268 | { |
272 | key = NULL; | 269 | key = NULL; |
273 | } | 270 | } |
274 | if (verbose) | 271 | if (verbose) |
275 | FPRINTF (stderr, | 272 | fprintf (stderr, |
276 | "Monitoring for %s\n", | 273 | "Monitoring for %s\n", |
277 | GNUNET_STRINGS_relative_time_to_string (timeout_request, GNUNET_NO)); | 274 | GNUNET_STRINGS_relative_time_to_string (timeout_request, |
278 | tt = GNUNET_SCHEDULER_add_delayed (timeout_request, | 275 | GNUNET_NO)); |
279 | &timeout_task, | 276 | tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL); |
280 | NULL); | 277 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); |
281 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, | ||
282 | NULL); | ||
283 | monitor_handle = GNUNET_DHT_monitor_start (dht_handle, | 278 | monitor_handle = GNUNET_DHT_monitor_start (dht_handle, |
284 | block_type, | 279 | block_type, |
285 | key, | 280 | key, |
@@ -308,34 +303,41 @@ main (int argc, char *const *argv) | |||
308 | &query_key), | 303 | &query_key), |
309 | 304 | ||
310 | GNUNET_GETOPT_option_uint ('t', | 305 | GNUNET_GETOPT_option_uint ('t', |
311 | "type", | 306 | "type", |
312 | "TYPE", | 307 | "TYPE", |
313 | gettext_noop ("the type of data to look for"), | 308 | gettext_noop ("the type of data to look for"), |
314 | &block_type), | 309 | &block_type), |
315 | 310 | ||
316 | GNUNET_GETOPT_option_relative_time ('T', | 311 | GNUNET_GETOPT_option_relative_time ( |
317 | "timeout", | 312 | 'T', |
318 | "TIMEOUT", | 313 | "timeout", |
319 | gettext_noop ("how long should the monitor command run"), | 314 | "TIMEOUT", |
320 | &timeout_request), | 315 | gettext_noop ("how long should the monitor command run"), |
316 | &timeout_request), | ||
321 | 317 | ||
322 | GNUNET_GETOPT_option_flag ('V', | 318 | GNUNET_GETOPT_option_flag ('V', |
323 | "verbose", | 319 | "verbose", |
324 | gettext_noop ("be verbose (print progress information)"), | 320 | gettext_noop ( |
325 | &verbose), | 321 | "be verbose (print progress information)"), |
322 | &verbose), | ||
326 | 323 | ||
327 | GNUNET_GETOPT_OPTION_END | 324 | GNUNET_GETOPT_OPTION_END}; |
328 | }; | ||
329 | 325 | ||
330 | 326 | ||
331 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 327 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
332 | return 2; | 328 | return 2; |
333 | 329 | ||
334 | return (GNUNET_OK == | 330 | return (GNUNET_OK == |
335 | GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-monitor", | 331 | GNUNET_PROGRAM_run (argc, |
336 | gettext_noop | 332 | argv, |
337 | ("Prints all packets that go through the DHT."), | 333 | "gnunet-dht-monitor", |
338 | options, &run, NULL)) ? ret : 1; | 334 | gettext_noop ( |
335 | "Prints all packets that go through the DHT."), | ||
336 | options, | ||
337 | &run, | ||
338 | NULL)) | ||
339 | ? ret | ||
340 | : 1; | ||
339 | } | 341 | } |
340 | 342 | ||
341 | /* end of gnunet-dht-monitor.c */ | 343 | /* end of gnunet-dht-monitor.c */ |