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