diff options
author | Bart Polot <bart@net.in.tum.de> | 2012-01-05 20:58:18 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2012-01-05 20:58:18 +0000 |
commit | 11be45725d298530489f9425f4feb58a2ac15e64 (patch) | |
tree | 07ada603be120fff1a5d1358a8f8fdbd77bfa5da /src/dht | |
parent | 459242b68317b9dfc8965a73667fca02c931d51a (diff) | |
download | gnunet-11be45725d298530489f9425f4feb58a2ac15e64.tar.gz gnunet-11be45725d298530489f9425f4feb58a2ac15e64.zip |
Added testcase for DHT monitoring.
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/Makefile.am | 14 | ||||
-rw-r--r-- | src/dht/dht_api.c | 1 | ||||
-rw-r--r-- | src/dht/test_dht_monitor.c | 583 |
3 files changed, 595 insertions, 3 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index b2bbf5897..e5d3c88ed 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am | |||
@@ -99,7 +99,8 @@ check_PROGRAMS = \ | |||
99 | test_dht_twopeer_get_put \ | 99 | test_dht_twopeer_get_put \ |
100 | test_dht_twopeer_path_tracking \ | 100 | test_dht_twopeer_path_tracking \ |
101 | test_dht_multipeer \ | 101 | test_dht_multipeer \ |
102 | test_dht_2dtorus | 102 | test_dht_2dtorus \ |
103 | test_dht_monitor | ||
103 | 104 | ||
104 | if ENABLE_TEST_RUN | 105 | if ENABLE_TEST_RUN |
105 | TESTS = test_dht_api $(check_SCRIPTS) \ | 106 | TESTS = test_dht_api $(check_SCRIPTS) \ |
@@ -108,7 +109,8 @@ TESTS = test_dht_api $(check_SCRIPTS) \ | |||
108 | test_dht_twopeer_get_put \ | 109 | test_dht_twopeer_get_put \ |
109 | test_dht_twopeer_path_tracking \ | 110 | test_dht_twopeer_path_tracking \ |
110 | test_dht_multipeer \ | 111 | test_dht_multipeer \ |
111 | test_dht_2dtorus | 112 | test_dht_2dtorus \ |
113 | test_dht_monitor | ||
112 | endif | 114 | endif |
113 | 115 | ||
114 | test_dht_api_SOURCES = \ | 116 | test_dht_api_SOURCES = \ |
@@ -169,6 +171,14 @@ test_dht_2dtorus_LDADD = \ | |||
169 | test_dht_2dtorus_DEPENDENCIES = \ | 171 | test_dht_2dtorus_DEPENDENCIES = \ |
170 | libgnunetdht.la | 172 | libgnunetdht.la |
171 | 173 | ||
174 | test_dht_monitor_SOURCES = test_dht_monitor.c | ||
175 | test_dht_monitor_LDADD = \ | ||
176 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
177 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
178 | $(top_builddir)/src/dht/libgnunetdht.la | ||
179 | test_dht_monitor_DEPENDENCIES = \ | ||
180 | libgnunetdht.la | ||
181 | |||
172 | EXTRA_DIST = \ | 182 | EXTRA_DIST = \ |
173 | $(check_SCRIPTS) \ | 183 | $(check_SCRIPTS) \ |
174 | test_dht_api_data.conf \ | 184 | test_dht_api_data.conf \ |
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 353620960..31648a405 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -969,7 +969,6 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, | |||
969 | struct GNUNET_DHT_MonitorMessage *m; | 969 | struct GNUNET_DHT_MonitorMessage *m; |
970 | struct PendingMessage *pending; | 970 | struct PendingMessage *pending; |
971 | 971 | ||
972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "monitor start\n"); | ||
973 | h = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorHandle)); | 972 | h = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorHandle)); |
974 | GNUNET_CONTAINER_DLL_insert(handle->monitor_head, handle->monitor_tail, h); | 973 | GNUNET_CONTAINER_DLL_insert(handle->monitor_head, handle->monitor_tail, h); |
975 | 974 | ||
diff --git a/src/dht/test_dht_monitor.c b/src/dht/test_dht_monitor.c new file mode 100644 index 000000000..ae1cf3ecf --- /dev/null +++ b/src/dht/test_dht_monitor.c | |||
@@ -0,0 +1,583 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file dht/test_dht_monitor.c | ||
22 | * | ||
23 | * @brief Test for the dht service: store, retrieve and monitor in a 2d_torus. | ||
24 | * TODO: update this description | ||
25 | * Each peer stores it own ID in the DHT and then a different peer tries to | ||
26 | * retrieve that key from it. The GET starts after a first round of PUTS has | ||
27 | * been made. Periodically, each peer stores its ID into the DHT. If after | ||
28 | * a timeout no result has been returned, the test fails. | ||
29 | */ | ||
30 | #include "platform.h" | ||
31 | #include "gnunet_testing_lib.h" | ||
32 | #include "gnunet_dht_service.h" | ||
33 | |||
34 | #define VERBOSE 1 | ||
35 | |||
36 | #define REMOVE_DIR GNUNET_YES | ||
37 | |||
38 | |||
39 | /** | ||
40 | * How long until we give up on connecting the peers? | ||
41 | */ | ||
42 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500) | ||
43 | |||
44 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | ||
45 | |||
46 | #define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
47 | |||
48 | static int ok; | ||
49 | |||
50 | /** | ||
51 | * Be verbose | ||
52 | */ | ||
53 | static int verbose; | ||
54 | |||
55 | /** | ||
56 | * Total number of peers in the test. | ||
57 | */ | ||
58 | static unsigned long long num_peers; | ||
59 | |||
60 | /** | ||
61 | * Global configuration file | ||
62 | */ | ||
63 | static struct GNUNET_CONFIGURATION_Handle *testing_cfg; | ||
64 | |||
65 | /** | ||
66 | * Total number of currently running peers. | ||
67 | */ | ||
68 | static unsigned long long peers_running; | ||
69 | |||
70 | /** | ||
71 | * Total number of connections in the whole network. | ||
72 | */ | ||
73 | static unsigned int total_connections; | ||
74 | |||
75 | /** | ||
76 | * The currently running peer group. | ||
77 | */ | ||
78 | static struct GNUNET_TESTING_PeerGroup *pg; | ||
79 | |||
80 | /** | ||
81 | * File to report results to. | ||
82 | */ | ||
83 | static struct GNUNET_DISK_FileHandle *output_file; | ||
84 | |||
85 | /** | ||
86 | * File to log connection info, statistics to. | ||
87 | */ | ||
88 | static struct GNUNET_DISK_FileHandle *data_file; | ||
89 | |||
90 | /** | ||
91 | * Task called to disconnect peers. | ||
92 | */ | ||
93 | static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | ||
94 | |||
95 | /** | ||
96 | * Task To perform tests | ||
97 | */ | ||
98 | static GNUNET_SCHEDULER_TaskIdentifier test_task; | ||
99 | |||
100 | /** | ||
101 | * Task to do DHT_puts | ||
102 | */ | ||
103 | static GNUNET_SCHEDULER_TaskIdentifier put_task; | ||
104 | |||
105 | /** | ||
106 | * Task called to shutdown test. | ||
107 | */ | ||
108 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; | ||
109 | |||
110 | static char *topology_file; | ||
111 | |||
112 | struct GNUNET_TESTING_Daemon *d1; | ||
113 | |||
114 | struct GNUNET_TESTING_Daemon *d2; | ||
115 | |||
116 | struct GNUNET_DHT_Handle **hs; | ||
117 | |||
118 | struct GNUNET_DHT_MonitorHandle **mhs; | ||
119 | |||
120 | struct GNUNET_DHT_GetHandle *get_h_far; | ||
121 | |||
122 | const char *id_origin = "FC74"; | ||
123 | const char *id_far = "KPST"; | ||
124 | |||
125 | unsigned int i_origin; | ||
126 | unsigned int i_far; | ||
127 | |||
128 | struct GNUNET_TESTING_Daemon *d_far; | ||
129 | struct GNUNET_TESTING_Daemon *o; | ||
130 | |||
131 | unsigned int monitor_counter; | ||
132 | |||
133 | /** | ||
134 | * Check whether peers successfully shut down. | ||
135 | */ | ||
136 | static void | ||
137 | shutdown_callback (void *cls, const char *emsg) | ||
138 | { | ||
139 | if (emsg != NULL) | ||
140 | { | ||
141 | #if VERBOSE | ||
142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Shutdown of peers failed!\n"); | ||
143 | #endif | ||
144 | ok++; | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | #if VERBOSE | ||
149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
150 | "test: All peers successfully shut down!\n"); | ||
151 | #endif | ||
152 | } | ||
153 | } | ||
154 | |||
155 | |||
156 | static void | ||
157 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
158 | { | ||
159 | #if VERBOSE | ||
160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Ending test.\n"); | ||
161 | #endif | ||
162 | |||
163 | if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
164 | { | ||
165 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
166 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
167 | } | ||
168 | |||
169 | if (data_file != NULL) | ||
170 | GNUNET_DISK_file_close (data_file); | ||
171 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
172 | GNUNET_CONFIGURATION_destroy (testing_cfg); | ||
173 | } | ||
174 | |||
175 | |||
176 | static void | ||
177 | disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
178 | { | ||
179 | unsigned int i; | ||
180 | |||
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n"); | ||
182 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
183 | GNUNET_SCHEDULER_cancel (put_task); | ||
184 | if (NULL != get_h_far) | ||
185 | GNUNET_DHT_get_stop (get_h_far); | ||
186 | for (i = 0; i < num_peers; i++) | ||
187 | { | ||
188 | GNUNET_DHT_disconnect (hs[i]); | ||
189 | } | ||
190 | GNUNET_SCHEDULER_cancel (shutdown_handle); | ||
191 | shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
192 | } | ||
193 | |||
194 | static void | ||
195 | dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | ||
196 | const GNUNET_HashCode * key, | ||
197 | const struct GNUNET_PeerIdentity *get_path, | ||
198 | unsigned int get_path_length, | ||
199 | const struct GNUNET_PeerIdentity *put_path, | ||
200 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, | ||
201 | size_t size, const void *data) | ||
202 | { | ||
203 | int i; | ||
204 | |||
205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
206 | "test: ************* FOUND!!! ***********\n"); | ||
207 | if (sizeof (GNUNET_HashCode) == size) | ||
208 | { | ||
209 | const GNUNET_HashCode *h = data; | ||
210 | |||
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Contents: %s\n", | ||
212 | GNUNET_h2s_full (h)); | ||
213 | |||
214 | } | ||
215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: PATH: (get %u, put %u)\n", | ||
216 | get_path_length, put_path_length); | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: LOCAL\n"); | ||
218 | for (i = get_path_length - 1; i >= 0; i--) | ||
219 | { | ||
220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", | ||
221 | GNUNET_i2s (&get_path[i])); | ||
222 | } | ||
223 | for (i = put_path_length - 1; i >= 0; i--) | ||
224 | { | ||
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", | ||
226 | GNUNET_i2s (&put_path[i])); | ||
227 | } | ||
228 | if (monitor_counter >= get_path_length + put_path_length) | ||
229 | { | ||
230 | ok = 0; | ||
231 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "expected at least %u hops, got %u\n", | ||
232 | get_path_length + put_path_length, monitor_counter); | ||
233 | } | ||
234 | else | ||
235 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "expected at least %u hops, got %u\n", | ||
236 | get_path_length + put_path_length, monitor_counter); | ||
237 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
238 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); | ||
239 | } | ||
240 | |||
241 | static void | ||
242 | do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
243 | { | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); | ||
245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", | ||
246 | GNUNET_h2s_full (&d_far->id.hashPubKey)); | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n", | ||
248 | GNUNET_h2s_full (&o->id.hashPubKey)); | ||
249 | get_h_far = GNUNET_DHT_get_start (hs[i_origin], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | ||
250 | GNUNET_BLOCK_TYPE_TEST, /* type */ | ||
251 | &d_far->id.hashPubKey, /*key to search */ | ||
252 | 4U, /* replication level */ | ||
253 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ | ||
254 | 0, /* xquery bits */ | ||
255 | &dht_get_id_handler, NULL); | ||
256 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
257 | disconnect_task = | ||
258 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); | ||
259 | } | ||
260 | |||
261 | |||
262 | static void | ||
263 | put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
264 | { | ||
265 | struct GNUNET_TESTING_Daemon *d; | ||
266 | |||
267 | d = GNUNET_TESTING_daemon_get (pg, i_far); | ||
268 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n", | ||
269 | GNUNET_h2s_full (&d->id.hashPubKey)); | ||
270 | GNUNET_DHT_put (hs[i_far], &d->id.hashPubKey, 10U, | ||
271 | GNUNET_DHT_RO_RECORD_ROUTE | | ||
272 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
273 | GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity), | ||
274 | (const char *) &d->id, GNUNET_TIME_UNIT_FOREVER_ABS, | ||
275 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); | ||
276 | |||
277 | put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL); | ||
278 | } | ||
279 | |||
280 | /** | ||
281 | * Callback called on each request going through the DHT. | ||
282 | * | ||
283 | * @param cls Closure. | ||
284 | * @param mtype Type of the DHT message monitored. | ||
285 | * @param exp When will this value expire. | ||
286 | * @param key Key of the result/request. | ||
287 | * @param get_path Peers on reply path (or NULL if not recorded). | ||
288 | * @param get_path_length number of entries in get_path. | ||
289 | * @param put_path peers on the PUT path (or NULL if not recorded). | ||
290 | * @param put_path_length number of entries in get_path. | ||
291 | * @param desired_replication_level Desired replication level. | ||
292 | * @param type Type of the result/request. | ||
293 | * @param data Pointer to the result data. | ||
294 | * @param size Number of bytes in data. | ||
295 | */ | ||
296 | void | ||
297 | monitor_dht_cb (void *cls, | ||
298 | uint16_t mtype, | ||
299 | struct GNUNET_TIME_Absolute exp, | ||
300 | const GNUNET_HashCode * key, | ||
301 | const struct GNUNET_PeerIdentity * get_path, | ||
302 | unsigned int get_path_length, | ||
303 | const struct GNUNET_PeerIdentity * put_path, | ||
304 | unsigned int put_path_length, | ||
305 | uint32_t desired_replication_level, | ||
306 | enum GNUNET_DHT_RouteOption options, | ||
307 | enum GNUNET_BLOCK_Type type, | ||
308 | const void *data, | ||
309 | size_t size) | ||
310 | { | ||
311 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
312 | "%u got a message of type %u for key %s\n", | ||
313 | cls, mtype, GNUNET_h2s (key)); | ||
314 | if (mtype == GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET || | ||
315 | mtype == GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT) | ||
316 | monitor_counter++; | ||
317 | } | ||
318 | |||
319 | |||
320 | /** | ||
321 | * peergroup_ready: start test when all peers are connected | ||
322 | * @param cls closure | ||
323 | * @param emsg error message | ||
324 | */ | ||
325 | static void | ||
326 | peergroup_ready (void *cls, const char *emsg) | ||
327 | { | ||
328 | struct GNUNET_TESTING_Daemon *d; | ||
329 | char *buf; | ||
330 | const char *id_aux; | ||
331 | int buf_len; | ||
332 | unsigned int i; | ||
333 | |||
334 | if (emsg != NULL) | ||
335 | { | ||
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
337 | "test: Peergroup callback called with error, aborting test!\n"); | ||
338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n", | ||
339 | emsg); | ||
340 | ok++; | ||
341 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
342 | return; | ||
343 | } | ||
344 | #if VERBOSE | ||
345 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
346 | "************************************************************\n"); | ||
347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
348 | "test: Peer Group started successfully!\n"); | ||
349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n", | ||
350 | total_connections); | ||
351 | #endif | ||
352 | |||
353 | if (data_file != NULL) | ||
354 | { | ||
355 | buf = NULL; | ||
356 | buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections); | ||
357 | if (buf_len > 0) | ||
358 | GNUNET_DISK_file_write (data_file, buf, buf_len); | ||
359 | GNUNET_free (buf); | ||
360 | } | ||
361 | peers_running = GNUNET_TESTING_daemons_running (pg); | ||
362 | |||
363 | GNUNET_assert (peers_running == num_peers); | ||
364 | hs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_Handle *)); | ||
365 | mhs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_MonitorHandle *)); | ||
366 | d_far = o = NULL; | ||
367 | for (i = 0; i < num_peers; i++) | ||
368 | { | ||
369 | d = GNUNET_TESTING_daemon_get (pg, i); | ||
370 | hs[i] = GNUNET_DHT_connect (d->cfg, 32); | ||
371 | mhs[i] = GNUNET_DHT_monitor_start(hs[i], GNUNET_BLOCK_TYPE_ANY, NULL, | ||
372 | &monitor_dht_cb, (void *)(long long)i); | ||
373 | id_aux = GNUNET_i2s (&d->id); | ||
374 | if (strcmp (id_aux, id_origin) == 0) | ||
375 | { | ||
376 | o = d; | ||
377 | i_origin = i; | ||
378 | } | ||
379 | if (strcmp (id_aux, id_far) == 0) | ||
380 | { | ||
381 | i_far = i; | ||
382 | d_far = d; | ||
383 | } | ||
384 | } | ||
385 | |||
386 | if ((NULL == o) || (NULL == d_far)) | ||
387 | { | ||
388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
389 | "test: Peers not found (hostkey file changed?)\n"); | ||
390 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
391 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); | ||
392 | return; | ||
393 | } | ||
394 | monitor_counter = 0; | ||
395 | put_task = GNUNET_SCHEDULER_add_now (&put_id, NULL); | ||
396 | test_task = | ||
397 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
398 | (GNUNET_TIME_UNIT_SECONDS, 2), &do_test, | ||
399 | NULL); | ||
400 | disconnect_task = | ||
401 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); | ||
402 | |||
403 | } | ||
404 | |||
405 | |||
406 | /** | ||
407 | * Function that will be called whenever two daemons are connected by | ||
408 | * the testing library. | ||
409 | * | ||
410 | * @param cls closure | ||
411 | * @param first peer id for first daemon | ||
412 | * @param second peer id for the second daemon | ||
413 | * @param distance distance between the connected peers | ||
414 | * @param first_cfg config for the first daemon | ||
415 | * @param second_cfg config for the second daemon | ||
416 | * @param first_daemon handle for the first daemon | ||
417 | * @param second_daemon handle for the second daemon | ||
418 | * @param emsg error message (NULL on success) | ||
419 | */ | ||
420 | static void | ||
421 | connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, | ||
422 | const struct GNUNET_PeerIdentity *second, uint32_t distance, | ||
423 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, | ||
424 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, | ||
425 | struct GNUNET_TESTING_Daemon *first_daemon, | ||
426 | struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) | ||
427 | { | ||
428 | |||
429 | if (emsg == NULL) | ||
430 | { | ||
431 | total_connections++; | ||
432 | GNUNET_PEER_intern (first); | ||
433 | GNUNET_PEER_intern (second); | ||
434 | } | ||
435 | else | ||
436 | { | ||
437 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
438 | "test: Problem with new connection (%s)\n", emsg); | ||
439 | } | ||
440 | |||
441 | } | ||
442 | |||
443 | |||
444 | /** | ||
445 | * run: load configuration options and schedule test to run (start peergroup) | ||
446 | * @param cls closure | ||
447 | * @param args argv | ||
448 | * @param cfgfile configuration file name (can be NULL) | ||
449 | * @param cfg configuration handle | ||
450 | */ | ||
451 | static void | ||
452 | run (void *cls, char *const *args, const char *cfgfile, | ||
453 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
454 | { | ||
455 | char *temp_str; | ||
456 | struct GNUNET_TESTING_Host *hosts; | ||
457 | char *data_filename; | ||
458 | |||
459 | ok = 1; | ||
460 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
461 | |||
462 | GNUNET_log_setup ("test_dht_monitor", | ||
463 | #if VERBOSE | ||
464 | "DEBUG", | ||
465 | #else | ||
466 | "WARNING", | ||
467 | #endif | ||
468 | NULL); | ||
469 | |||
470 | #if VERBOSE | ||
471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Starting daemons.\n"); | ||
472 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", | ||
473 | "use_progressbars", "YES"); | ||
474 | #endif | ||
475 | |||
476 | if (GNUNET_OK != | ||
477 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", | ||
478 | "num_peers", &num_peers)) | ||
479 | { | ||
480 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
481 | "Option TESTING:NUM_PEERS is required!\n"); | ||
482 | return; | ||
483 | } | ||
484 | |||
485 | if (GNUNET_OK != | ||
486 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing", | ||
487 | "topology_output_file", | ||
488 | &topology_file)) | ||
489 | { | ||
490 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
491 | "Option test_dht_2d:topology_output_file is required!\n"); | ||
492 | return; | ||
493 | } | ||
494 | |||
495 | if (GNUNET_OK == | ||
496 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_dht_2dtorus", | ||
497 | "data_output_file", | ||
498 | &data_filename)) | ||
499 | { | ||
500 | data_file = | ||
501 | GNUNET_DISK_file_open (data_filename, | ||
502 | GNUNET_DISK_OPEN_READWRITE | | ||
503 | GNUNET_DISK_OPEN_CREATE, | ||
504 | GNUNET_DISK_PERM_USER_READ | | ||
505 | GNUNET_DISK_PERM_USER_WRITE); | ||
506 | if (data_file == NULL) | ||
507 | { | ||
508 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | ||
509 | data_filename); | ||
510 | GNUNET_free (data_filename); | ||
511 | } | ||
512 | } | ||
513 | |||
514 | if (GNUNET_YES == | ||
515 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_dht_2dtorus", | ||
516 | "output_file", &temp_str)) | ||
517 | { | ||
518 | output_file = | ||
519 | GNUNET_DISK_file_open (temp_str, | ||
520 | GNUNET_DISK_OPEN_READWRITE | | ||
521 | GNUNET_DISK_OPEN_CREATE, | ||
522 | GNUNET_DISK_PERM_USER_READ | | ||
523 | GNUNET_DISK_PERM_USER_WRITE); | ||
524 | if (output_file == NULL) | ||
525 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | ||
526 | temp_str); | ||
527 | } | ||
528 | GNUNET_free_non_null (temp_str); | ||
529 | |||
530 | hosts = GNUNET_TESTING_hosts_load (testing_cfg); | ||
531 | |||
532 | pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT, | ||
533 | &connect_cb, &peergroup_ready, NULL, | ||
534 | hosts); | ||
535 | GNUNET_assert (pg != NULL); | ||
536 | shutdown_handle = | ||
537 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
538 | &shutdown_task, NULL); | ||
539 | } | ||
540 | |||
541 | |||
542 | |||
543 | /** | ||
544 | * test_dht_monitor command line options | ||
545 | */ | ||
546 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
547 | {'V', "verbose", NULL, | ||
548 | gettext_noop ("be verbose (print progress information)"), | ||
549 | 0, &GNUNET_GETOPT_set_one, &verbose}, | ||
550 | GNUNET_GETOPT_OPTION_END | ||
551 | }; | ||
552 | |||
553 | |||
554 | /** | ||
555 | * Main: start test | ||
556 | */ | ||
557 | int | ||
558 | main (int xargc, char *xargv[]) | ||
559 | { | ||
560 | char *const argv[] = { "test-dht-monitor", | ||
561 | "-c", | ||
562 | "test_dht_2dtorus.conf", // reuse 2dtorus conf file | ||
563 | #if VERBOSE | ||
564 | "-L", "DEBUG", | ||
565 | #endif | ||
566 | NULL | ||
567 | }; | ||
568 | |||
569 | GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv, | ||
570 | "test_dht_monitor", | ||
571 | gettext_noop ("Test dht monitoring in a small 2D torus."), | ||
572 | options, &run, NULL); | ||
573 | #if REMOVE_DIR | ||
574 | GNUNET_DISK_directory_remove ("/tmp/test_dht_monitor"); | ||
575 | #endif | ||
576 | if (0 != ok) | ||
577 | { | ||
578 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: FAILED!\n"); | ||
579 | } | ||
580 | return ok; | ||
581 | } | ||
582 | |||
583 | /* end of test_dht_monitor.c */ | ||