summaryrefslogtreecommitdiff
path: root/src/dht/gnunet-dht-monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-dht-monitor.c')
-rw-r--r--src/dht/gnunet-dht-monitor.c260
1 files changed, 130 insertions, 130 deletions
diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c
index 26989467c..d0cd4cff1 100644
--- a/src/dht/gnunet-dht-monitor.c
+++ b/src/dht/gnunet-dht-monitor.c
@@ -83,25 +83,25 @@ static struct GNUNET_SCHEDULER_Task *tt;
83 * @param cls closure (unused) 83 * @param cls closure (unused)
84 */ 84 */
85static void 85static void
86cleanup_task(void *cls) 86cleanup_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);
93 monitor_handle = NULL; 93 monitor_handle = NULL;
94 } 94 }
95 if (NULL != dht_handle) 95 if (NULL != dht_handle)
96 { 96 {
97 GNUNET_DHT_disconnect(dht_handle); 97 GNUNET_DHT_disconnect (dht_handle);
98 dht_handle = NULL; 98 dht_handle = NULL;
99 } 99 }
100 if (NULL != tt) 100 if (NULL != tt)
101 { 101 {
102 GNUNET_SCHEDULER_cancel(tt); 102 GNUNET_SCHEDULER_cancel (tt);
103 tt = NULL; 103 tt = NULL;
104 } 104 }
105} 105}
106 106
107 107
@@ -111,10 +111,10 @@ cleanup_task(void *cls)
111 * @param cls closure (unused) 111 * @param cls closure (unused)
112 */ 112 */
113static void 113static void
114timeout_task(void *cls) 114timeout_task (void *cls)
115{ 115{
116 tt = NULL; 116 tt = NULL;
117 GNUNET_SCHEDULER_shutdown(); 117 GNUNET_SCHEDULER_shutdown ();
118} 118}
119 119
120 120
@@ -131,20 +131,20 @@ timeout_task(void *cls)
131 * @param key Key of the requested data. 131 * @param key Key of the requested data.
132 */ 132 */
133static void 133static void
134get_callback(void *cls, 134get_callback (void *cls,
135 enum GNUNET_DHT_RouteOption options, 135 enum GNUNET_DHT_RouteOption options,
136 enum GNUNET_BLOCK_Type type, 136 enum GNUNET_BLOCK_Type type,
137 uint32_t hop_count, 137 uint32_t hop_count,
138 uint32_t desired_replication_level, 138 uint32_t desired_replication_level,
139 unsigned int path_length, 139 unsigned int path_length,
140 const struct GNUNET_PeerIdentity *path, 140 const struct GNUNET_PeerIdentity *path,
141 const struct GNUNET_HashCode *key) 141 const struct GNUNET_HashCode *key)
142{ 142{
143 fprintf(stdout, 143 fprintf (stdout,
144 "GET #%u: type %d, key `%s'\n", 144 "GET #%u: type %d, key `%s'\n",
145 result_count, 145 result_count,
146 (int)type, 146 (int) type,
147 GNUNET_h2s_full(key)); 147 GNUNET_h2s_full (key));
148 result_count++; 148 result_count++;
149} 149}
150 150
@@ -164,27 +164,27 @@ get_callback(void *cls,
164 * @param size Number of bytes in data. 164 * @param size Number of bytes in data.
165 */ 165 */
166static void 166static void
167get_resp_callback(void *cls, 167get_resp_callback (void *cls,
168 enum GNUNET_BLOCK_Type type, 168 enum GNUNET_BLOCK_Type type,
169 const struct GNUNET_PeerIdentity *get_path, 169 const struct GNUNET_PeerIdentity *get_path,
170 unsigned int get_path_length, 170 unsigned int get_path_length,
171 const struct GNUNET_PeerIdentity *put_path, 171 const struct GNUNET_PeerIdentity *put_path,
172 unsigned int put_path_length, 172 unsigned int put_path_length,
173 struct GNUNET_TIME_Absolute exp, 173 struct GNUNET_TIME_Absolute exp,
174 const struct GNUNET_HashCode *key, 174 const struct GNUNET_HashCode *key,
175 const void *data, 175 const void *data,
176 size_t size) 176 size_t size)
177{ 177{
178 fprintf(stdout, 178 fprintf (stdout,
179 (GNUNET_BLOCK_TYPE_TEST == type) 179 (GNUNET_BLOCK_TYPE_TEST == type)
180 ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n" 180 ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n"
181 : "RESPONSE #%u (%s): type %d, key `%s'\n", 181 : "RESPONSE #%u (%s): type %d, key `%s'\n",
182 result_count, 182 result_count,
183 GNUNET_STRINGS_absolute_time_to_string(exp), 183 GNUNET_STRINGS_absolute_time_to_string (exp),
184 (int)type, 184 (int) type,
185 GNUNET_h2s_full(key), 185 GNUNET_h2s_full (key),
186 (unsigned int)size, 186 (unsigned int) size,
187 (char *)data); 187 (char *) data);
188 result_count++; 188 result_count++;
189} 189}
190 190
@@ -205,28 +205,28 @@ get_resp_callback(void *cls,
205 * @param size Number of bytes in data. 205 * @param size Number of bytes in data.
206 */ 206 */
207static void 207static void
208put_callback(void *cls, 208put_callback (void *cls,
209 enum GNUNET_DHT_RouteOption options, 209 enum GNUNET_DHT_RouteOption options,
210 enum GNUNET_BLOCK_Type type, 210 enum GNUNET_BLOCK_Type type,
211 uint32_t hop_count, 211 uint32_t hop_count,
212 uint32_t desired_replication_level, 212 uint32_t desired_replication_level,
213 unsigned int path_length, 213 unsigned int path_length,
214 const struct GNUNET_PeerIdentity *path, 214 const struct GNUNET_PeerIdentity *path,
215 struct GNUNET_TIME_Absolute exp, 215 struct GNUNET_TIME_Absolute exp,
216 const struct GNUNET_HashCode *key, 216 const struct GNUNET_HashCode *key,
217 const void *data, 217 const void *data,
218 size_t size) 218 size_t size)
219{ 219{
220 fprintf(stdout, 220 fprintf (stdout,
221 (GNUNET_BLOCK_TYPE_TEST == type) 221 (GNUNET_BLOCK_TYPE_TEST == type)
222 ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n" 222 ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n"
223 : "PUT %u (%s): type %d, key `%s'\n", 223 : "PUT %u (%s): type %d, key `%s'\n",
224 result_count, 224 result_count,
225 GNUNET_STRINGS_absolute_time_to_string(exp), 225 GNUNET_STRINGS_absolute_time_to_string (exp),
226 (int)type, 226 (int) type,
227 GNUNET_h2s_full(key), 227 GNUNET_h2s_full (key),
228 (unsigned int)size, 228 (unsigned int) size,
229 (char *)data); 229 (char *) data);
230 result_count++; 230 result_count++;
231} 231}
232 232
@@ -240,48 +240,48 @@ put_callback(void *cls,
240 * @param c configuration 240 * @param c configuration
241 */ 241 */
242static void 242static void
243run(void *cls, 243run (void *cls,
244 char *const *args, 244 char *const *args,
245 const char *cfgfile, 245 const char *cfgfile,
246 const struct GNUNET_CONFIGURATION_Handle *c) 246 const struct GNUNET_CONFIGURATION_Handle *c)
247{ 247{
248 struct GNUNET_HashCode *key; 248 struct GNUNET_HashCode *key;
249 struct GNUNET_HashCode hc; 249 struct GNUNET_HashCode hc;
250 250
251 cfg = c; 251 cfg = c;
252 252
253 if (NULL == (dht_handle = GNUNET_DHT_connect(cfg, 1))) 253 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
254 { 254 {
255 fprintf(stderr, "%s", _("Failed to connect to DHT service!\n")); 255 fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n"));
256 ret = 1; 256 ret = 1;
257 return; 257 return;
258 } 258 }
259 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 */
260 block_type = GNUNET_BLOCK_TYPE_TEST; 260 block_type = GNUNET_BLOCK_TYPE_TEST;
261 if (NULL != query_key) 261 if (NULL != query_key)
262 { 262 {
263 key = &hc; 263 key = &hc;
264 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(query_key, key)) 264 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (query_key, key))
265 GNUNET_CRYPTO_hash(query_key, strlen(query_key), key); 265 GNUNET_CRYPTO_hash (query_key, strlen (query_key), key);
266 } 266 }
267 else 267 else
268 { 268 {
269 key = NULL; 269 key = NULL;
270 } 270 }
271 if (verbose) 271 if (verbose)
272 fprintf(stderr, 272 fprintf (stderr,
273 "Monitoring for %s\n", 273 "Monitoring for %s\n",
274 GNUNET_STRINGS_relative_time_to_string(timeout_request, 274 GNUNET_STRINGS_relative_time_to_string (timeout_request,
275 GNUNET_NO)); 275 GNUNET_NO));
276 tt = GNUNET_SCHEDULER_add_delayed(timeout_request, &timeout_task, NULL); 276 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL);
277 GNUNET_SCHEDULER_add_shutdown(&cleanup_task, NULL); 277 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
278 monitor_handle = GNUNET_DHT_monitor_start(dht_handle, 278 monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
279 block_type, 279 block_type,
280 key, 280 key,
281 &get_callback, 281 &get_callback,
282 &get_resp_callback, 282 &get_resp_callback,
283 &put_callback, 283 &put_callback,
284 NULL); 284 NULL);
285} 285}
286 286
287/** 287/**
@@ -292,50 +292,50 @@ run(void *cls,
292 * @return 0 ok, 1 on error 292 * @return 0 ok, 1 on error
293 */ 293 */
294int 294int
295main(int argc, char *const *argv) 295main (int argc, char *const *argv)
296{ 296{
297 struct GNUNET_GETOPT_CommandLineOption options[] = { 297 struct GNUNET_GETOPT_CommandLineOption options[] = {
298 GNUNET_GETOPT_option_string('k', 298 GNUNET_GETOPT_option_string ('k',
299 "key", 299 "key",
300 "KEY", 300 "KEY",
301 gettext_noop("the query key"), 301 gettext_noop ("the query key"),
302 &query_key), 302 &query_key),
303 303
304 GNUNET_GETOPT_option_uint('t', 304 GNUNET_GETOPT_option_uint ('t',
305 "type", 305 "type",
306 "TYPE", 306 "TYPE",
307 gettext_noop("the type of data to look for"), 307 gettext_noop ("the type of data to look for"),
308 &block_type), 308 &block_type),
309 309
310 GNUNET_GETOPT_option_relative_time( 310 GNUNET_GETOPT_option_relative_time (
311 'T', 311 'T',
312 "timeout", 312 "timeout",
313 "TIMEOUT", 313 "TIMEOUT",
314 gettext_noop("how long should the monitor command run"), 314 gettext_noop ("how long should the monitor command run"),
315 &timeout_request), 315 &timeout_request),
316 316
317 GNUNET_GETOPT_option_flag('V', 317 GNUNET_GETOPT_option_flag ('V',
318 "verbose", 318 "verbose",
319 gettext_noop( 319 gettext_noop (
320 "be verbose (print progress information)"), 320 "be verbose (print progress information)"),
321 &verbose), 321 &verbose),
322 322
323 GNUNET_GETOPT_OPTION_END 323 GNUNET_GETOPT_OPTION_END
324 }; 324 };
325 325
326 326
327 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))
328 return 2; 328 return 2;
329 329
330 return (GNUNET_OK == 330 return (GNUNET_OK ==
331 GNUNET_PROGRAM_run(argc, 331 GNUNET_PROGRAM_run (argc,
332 argv, 332 argv,
333 "gnunet-dht-monitor", 333 "gnunet-dht-monitor",
334 gettext_noop( 334 gettext_noop (
335 "Prints all packets that go through the DHT."), 335 "Prints all packets that go through the DHT."),
336 options, 336 options,
337 &run, 337 &run,
338 NULL)) 338 NULL))
339 ? ret 339 ? ret
340 : 1; 340 : 1;
341} 341}