summaryrefslogtreecommitdiff
path: root/src/dht/test_dht_monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/test_dht_monitor.c')
-rw-r--r--src/dht/test_dht_monitor.c316
1 files changed, 159 insertions, 157 deletions
diff --git a/src/dht/test_dht_monitor.c b/src/dht/test_dht_monitor.c
index f5586e9bc..95fb37bcd 100644
--- a/src/dht/test_dht_monitor.c
+++ b/src/dht/test_dht_monitor.c
@@ -31,18 +31,20 @@
31/** 31/**
32 * How long do we run the test at most? 32 * How long do we run the test at most?
33 */ 33 */
34#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) 34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
35 35
36/** 36/**
37 * How often do we run the PUTs? 37 * How often do we run the PUTs?
38 */ 38 */
39#define PUT_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 39#define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
40 10)
40 41
41 42
42/** 43/**
43 * Information we keep for each GET operation. 44 * Information we keep for each GET operation.
44 */ 45 */
45struct GetOperation { 46struct GetOperation
47{
46 /** 48 /**
47 * DLL. 49 * DLL.
48 */ 50 */
@@ -93,7 +95,7 @@ static struct GNUNET_SCHEDULER_Task *timeout_task;
93/** 95/**
94 * Task to do DHT_puts 96 * Task to do DHT_puts
95 */ 97 */
96static struct GNUNET_SCHEDULER_Task * put_task; 98static struct GNUNET_SCHEDULER_Task *put_task;
97 99
98static struct GNUNET_DHT_MonitorHandle **monitors; 100static struct GNUNET_DHT_MonitorHandle **monitors;
99 101
@@ -108,34 +110,34 @@ static unsigned int monitor_counter;
108 * @param cls the `struct GNUNET_DHT_TEST_Context` 110 * @param cls the `struct GNUNET_DHT_TEST_Context`
109 */ 111 */
110static void 112static void
111shutdown_task(void *cls) 113shutdown_task (void *cls)
112{ 114{
113 struct GNUNET_DHT_TEST_Context *ctx = cls; 115 struct GNUNET_DHT_TEST_Context *ctx = cls;
114 unsigned int i; 116 unsigned int i;
115 struct GetOperation *get_op; 117 struct GetOperation *get_op;
116 118
117 ok = (monitor_counter > NUM_PEERS) ? 0 : 2; 119 ok = (monitor_counter > NUM_PEERS) ? 0 : 2;
118 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 120 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
119 "Received %u monitor events\n", 121 "Received %u monitor events\n",
120 monitor_counter); 122 monitor_counter);
121 while (NULL != (get_op = get_tail)) 123 while (NULL != (get_op = get_tail))
122 { 124 {
123 GNUNET_DHT_get_stop(get_op->get); 125 GNUNET_DHT_get_stop (get_op->get);
124 GNUNET_CONTAINER_DLL_remove(get_head, 126 GNUNET_CONTAINER_DLL_remove (get_head,
125 get_tail, 127 get_tail,
126 get_op); 128 get_op);
127 GNUNET_free(get_op); 129 GNUNET_free (get_op);
128 } 130 }
129 for (i = 0; i < NUM_PEERS; i++) 131 for (i = 0; i < NUM_PEERS; i++)
130 GNUNET_DHT_monitor_stop(monitors[i]); 132 GNUNET_DHT_monitor_stop (monitors[i]);
131 GNUNET_free(monitors); 133 GNUNET_free (monitors);
132 GNUNET_SCHEDULER_cancel(put_task); 134 GNUNET_SCHEDULER_cancel (put_task);
133 GNUNET_DHT_TEST_cleanup(ctx); 135 GNUNET_DHT_TEST_cleanup (ctx);
134 if (NULL != timeout_task) 136 if (NULL != timeout_task)
135 { 137 {
136 GNUNET_SCHEDULER_cancel(timeout_task); 138 GNUNET_SCHEDULER_cancel (timeout_task);
137 timeout_task = NULL; 139 timeout_task = NULL;
138 } 140 }
139} 141}
140 142
141 143
@@ -147,10 +149,10 @@ shutdown_task(void *cls)
147 * @param cls NULL 149 * @param cls NULL
148 */ 150 */
149static void 151static void
150timeout_task_cb(void *cls) 152timeout_task_cb (void *cls)
151{ 153{
152 timeout_task = NULL; 154 timeout_task = NULL;
153 GNUNET_SCHEDULER_shutdown(); 155 GNUNET_SCHEDULER_shutdown ();
154} 156}
155 157
156 158
@@ -170,41 +172,41 @@ timeout_task_cb(void *cls)
170 * @param data pointer to the result data 172 * @param data pointer to the result data
171 */ 173 */
172static void 174static void
173dht_get_handler(void *cls, struct GNUNET_TIME_Absolute exp, 175dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp,
174 const struct GNUNET_HashCode * key, 176 const struct GNUNET_HashCode *key,
175 const struct GNUNET_PeerIdentity *get_path, 177 const struct GNUNET_PeerIdentity *get_path,
176 unsigned int get_path_length, 178 unsigned int get_path_length,
177 const struct GNUNET_PeerIdentity *put_path, 179 const struct GNUNET_PeerIdentity *put_path,
178 unsigned int put_path_length, 180 unsigned int put_path_length,
179 enum GNUNET_BLOCK_Type type, 181 enum GNUNET_BLOCK_Type type,
180 size_t size, const void *data) 182 size_t size, const void *data)
181{ 183{
182 struct GetOperation *get_op = cls; 184 struct GetOperation *get_op = cls;
183 struct GNUNET_HashCode want; 185 struct GNUNET_HashCode want;
184 186
185 if (sizeof(struct GNUNET_HashCode) != size) 187 if (sizeof(struct GNUNET_HashCode) != size)
186 { 188 {
187 GNUNET_break(0); 189 GNUNET_break (0);
188 return; 190 return;
189 } 191 }
190 GNUNET_CRYPTO_hash(key, sizeof(*key), &want); 192 GNUNET_CRYPTO_hash (key, sizeof(*key), &want);
191 if (0 != memcmp(&want, data, sizeof(want))) 193 if (0 != memcmp (&want, data, sizeof(want)))
192 { 194 {
193 GNUNET_break(0); 195 GNUNET_break (0);
194 return; 196 return;
195 } 197 }
196 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
197 "Get successful\n"); 199 "Get successful\n");
198 GNUNET_DHT_get_stop(get_op->get); 200 GNUNET_DHT_get_stop (get_op->get);
199 GNUNET_CONTAINER_DLL_remove(get_head, 201 GNUNET_CONTAINER_DLL_remove (get_head,
200 get_tail, 202 get_tail,
201 get_op); 203 get_op);
202 GNUNET_free(get_op); 204 GNUNET_free (get_op);
203 if (NULL != get_head) 205 if (NULL != get_head)
204 return; 206 return;
205 /* all DHT GET operations successful; terminate! */ 207 /* all DHT GET operations successful; terminate! */
206 ok = 0; 208 ok = 0;
207 GNUNET_SCHEDULER_shutdown(); 209 GNUNET_SCHEDULER_shutdown ();
208} 210}
209 211
210 212
@@ -214,28 +216,28 @@ dht_get_handler(void *cls, struct GNUNET_TIME_Absolute exp,
214 * @param cls array with NUM_PEERS DHT handles 216 * @param cls array with NUM_PEERS DHT handles
215 */ 217 */
216static void 218static void
217do_puts(void *cls) 219do_puts (void *cls)
218{ 220{
219 struct GNUNET_DHT_Handle **hs = cls; 221 struct GNUNET_DHT_Handle **hs = cls;
220 struct GNUNET_HashCode key; 222 struct GNUNET_HashCode key;
221 struct GNUNET_HashCode value; 223 struct GNUNET_HashCode value;
222 224
223 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Putting values into DHT\n"); 226 "Putting values into DHT\n");
225 for (unsigned int i = 0; i < NUM_PEERS; i++) 227 for (unsigned int i = 0; i < NUM_PEERS; i++)
226 { 228 {
227 GNUNET_CRYPTO_hash(&i, sizeof(i), &key); 229 GNUNET_CRYPTO_hash (&i, sizeof(i), &key);
228 GNUNET_CRYPTO_hash(&key, sizeof(key), &value); 230 GNUNET_CRYPTO_hash (&key, sizeof(key), &value);
229 GNUNET_DHT_put(hs[i], &key, 10U, 231 GNUNET_DHT_put (hs[i], &key, 10U,
230 GNUNET_DHT_RO_RECORD_ROUTE | 232 GNUNET_DHT_RO_RECORD_ROUTE
231 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 233 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
232 GNUNET_BLOCK_TYPE_TEST, 234 GNUNET_BLOCK_TYPE_TEST,
233 sizeof(value), &value, 235 sizeof(value), &value,
234 GNUNET_TIME_UNIT_FOREVER_ABS, 236 GNUNET_TIME_UNIT_FOREVER_ABS,
235 NULL, NULL); 237 NULL, NULL);
236 } 238 }
237 put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY, 239 put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY,
238 &do_puts, hs); 240 &do_puts, hs);
239} 241}
240 242
241 243
@@ -253,22 +255,22 @@ do_puts(void *cls)
253 * @param key Key of the requested data. 255 * @param key Key of the requested data.
254 */ 256 */
255static void 257static void
256monitor_get_cb(void *cls, 258monitor_get_cb (void *cls,
257 enum GNUNET_DHT_RouteOption options, 259 enum GNUNET_DHT_RouteOption options,
258 enum GNUNET_BLOCK_Type type, 260 enum GNUNET_BLOCK_Type type,
259 uint32_t hop_count, 261 uint32_t hop_count,
260 uint32_t desired_replication_level, 262 uint32_t desired_replication_level,
261 unsigned int path_length, 263 unsigned int path_length,
262 const struct GNUNET_PeerIdentity *path, 264 const struct GNUNET_PeerIdentity *path,
263 const struct GNUNET_HashCode * key) 265 const struct GNUNET_HashCode *key)
264{ 266{
265 unsigned int i; 267 unsigned int i;
266 268
267 i = (unsigned int)(long)cls; 269 i = (unsigned int) (long) cls;
268 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 270 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
269 "%u got a GET message for key %s\n", 271 "%u got a GET message for key %s\n",
270 i, 272 i,
271 GNUNET_h2s(key)); 273 GNUNET_h2s (key));
272 monitor_counter++; 274 monitor_counter++;
273} 275}
274 276
@@ -290,26 +292,26 @@ monitor_get_cb(void *cls,
290 * @param size Number of bytes in data. 292 * @param size Number of bytes in data.
291 */ 293 */
292static void 294static void
293monitor_put_cb(void *cls, 295monitor_put_cb (void *cls,
294 enum GNUNET_DHT_RouteOption options, 296 enum GNUNET_DHT_RouteOption options,
295 enum GNUNET_BLOCK_Type type, 297 enum GNUNET_BLOCK_Type type,
296 uint32_t hop_count, 298 uint32_t hop_count,
297 uint32_t desired_replication_level, 299 uint32_t desired_replication_level,
298 unsigned int path_length, 300 unsigned int path_length,
299 const struct GNUNET_PeerIdentity *path, 301 const struct GNUNET_PeerIdentity *path,
300 struct GNUNET_TIME_Absolute exp, 302 struct GNUNET_TIME_Absolute exp,
301 const struct GNUNET_HashCode * key, 303 const struct GNUNET_HashCode *key,
302 const void *data, 304 const void *data,
303 size_t size) 305 size_t size)
304{ 306{
305 unsigned int i; 307 unsigned int i;
306 308
307 i = (unsigned int)(long)cls; 309 i = (unsigned int) (long) cls;
308 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 310 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
309 "%u got a PUT message for key %s with %u bytes\n", 311 "%u got a PUT message for key %s with %u bytes\n",
310 i, 312 i,
311 GNUNET_h2s(key), 313 GNUNET_h2s (key),
312 (unsigned int)size); 314 (unsigned int) size);
313 monitor_counter++; 315 monitor_counter++;
314} 316}
315 317
@@ -330,25 +332,25 @@ monitor_put_cb(void *cls,
330 * @param size Number of bytes in data. 332 * @param size Number of bytes in data.
331 */ 333 */
332static void 334static void
333monitor_res_cb(void *cls, 335monitor_res_cb (void *cls,
334 enum GNUNET_BLOCK_Type type, 336 enum GNUNET_BLOCK_Type type,
335 const struct GNUNET_PeerIdentity *get_path, 337 const struct GNUNET_PeerIdentity *get_path,
336 unsigned int get_path_length, 338 unsigned int get_path_length,
337 const struct GNUNET_PeerIdentity *put_path, 339 const struct GNUNET_PeerIdentity *put_path,
338 unsigned int put_path_length, 340 unsigned int put_path_length,
339 struct GNUNET_TIME_Absolute exp, 341 struct GNUNET_TIME_Absolute exp,
340 const struct GNUNET_HashCode * key, 342 const struct GNUNET_HashCode *key,
341 const void *data, 343 const void *data,
342 size_t size) 344 size_t size)
343{ 345{
344 unsigned int i; 346 unsigned int i;
345 347
346 i = (unsigned int)(long)cls; 348 i = (unsigned int) (long) cls;
347 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 349 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
348 "%u got a REPLY message for key %s with %u bytes\n", 350 "%u got a REPLY message for key %s with %u bytes\n",
349 i, 351 i,
350 GNUNET_h2s(key), 352 GNUNET_h2s (key),
351 (unsigned int)size); 353 (unsigned int) size);
352 monitor_counter++; 354 monitor_counter++;
353} 355}
354 356
@@ -363,56 +365,56 @@ monitor_res_cb(void *cls,
363 * @param dhts handle to each of the DHTs of the peers 365 * @param dhts handle to each of the DHTs of the peers
364 */ 366 */
365static void 367static void
366run(void *cls, 368run (void *cls,
367 struct GNUNET_DHT_TEST_Context *ctx, 369 struct GNUNET_DHT_TEST_Context *ctx,
368 unsigned int num_peers, 370 unsigned int num_peers,
369 struct GNUNET_TESTBED_Peer **peers, 371 struct GNUNET_TESTBED_Peer **peers,
370 struct GNUNET_DHT_Handle **dhts) 372 struct GNUNET_DHT_Handle **dhts)
371{ 373{
372 unsigned int i; 374 unsigned int i;
373 unsigned int j; 375 unsigned int j;
374 struct GNUNET_HashCode key; 376 struct GNUNET_HashCode key;
375 struct GetOperation *get_op; 377 struct GetOperation *get_op;
376 378
377 GNUNET_assert(NUM_PEERS == num_peers); 379 GNUNET_assert (NUM_PEERS == num_peers);
378 my_peers = peers; 380 my_peers = peers;
379 monitors = GNUNET_new_array(num_peers, 381 monitors = GNUNET_new_array (num_peers,
380 struct GNUNET_DHT_MonitorHandle *); 382 struct GNUNET_DHT_MonitorHandle *);
381 for (i = 0; i < num_peers; i++) 383 for (i = 0; i < num_peers; i++)
382 monitors[i] = GNUNET_DHT_monitor_start(dhts[i], 384 monitors[i] = GNUNET_DHT_monitor_start (dhts[i],
383 GNUNET_BLOCK_TYPE_ANY, 385 GNUNET_BLOCK_TYPE_ANY,
384 NULL, 386 NULL,
385 &monitor_get_cb, 387 &monitor_get_cb,
386 &monitor_res_cb, 388 &monitor_res_cb,
387 &monitor_put_cb, 389 &monitor_put_cb,
388 (void *)(long)i); 390 (void *) (long) i);
389 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
390 "Peers setup, starting test\n"); 392 "Peers setup, starting test\n");
391 put_task = GNUNET_SCHEDULER_add_now(&do_puts, dhts); 393 put_task = GNUNET_SCHEDULER_add_now (&do_puts, dhts);
392 for (i = 0; i < num_peers; i++) 394 for (i = 0; i < num_peers; i++)
395 {
396 GNUNET_CRYPTO_hash (&i, sizeof(i), &key);
397 for (j = 0; j < num_peers; j++)
393 { 398 {
394 GNUNET_CRYPTO_hash(&i, sizeof(i), &key); 399 get_op = GNUNET_new (struct GetOperation);
395 for (j = 0; j < num_peers; j++) 400 GNUNET_CONTAINER_DLL_insert (get_head,
396 { 401 get_tail,
397 get_op = GNUNET_new(struct GetOperation); 402 get_op);
398 GNUNET_CONTAINER_DLL_insert(get_head, 403 get_op->get = GNUNET_DHT_get_start (dhts[j],
399 get_tail, 404 GNUNET_BLOCK_TYPE_TEST, /* type */
400 get_op); 405 &key, /*key to search */
401 get_op->get = GNUNET_DHT_get_start(dhts[j], 406 4U, /* replication level */
402 GNUNET_BLOCK_TYPE_TEST, /* type */ 407 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
403 &key, /*key to search */ 408 NULL, /* xquery */
404 4U, /* replication level */ 409 0, /* xquery bits */
405 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 410 &dht_get_handler, get_op);
406 NULL, /* xquery */
407 0, /* xquery bits */
408 &dht_get_handler, get_op);
409 }
410 } 411 }
411 timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, 412 }
412 &timeout_task_cb, 413 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
413 NULL); 414 &timeout_task_cb,
414 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, 415 NULL);
415 ctx); 416 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
417 ctx);
416} 418}
417 419
418 420
@@ -420,12 +422,12 @@ run(void *cls,
420 * Main: start test 422 * Main: start test
421 */ 423 */
422int 424int
423main(int xargc, char *xargv[]) 425main (int xargc, char *xargv[])
424{ 426{
425 GNUNET_DHT_TEST_run("test-dht-monitor", 427 GNUNET_DHT_TEST_run ("test-dht-monitor",
426 "test_dht_monitor.conf", 428 "test_dht_monitor.conf",
427 NUM_PEERS, 429 NUM_PEERS,
428 &run, NULL); 430 &run, NULL);
429 return ok; 431 return ok;
430} 432}
431 433