aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-11-02 14:10:52 +0000
committerChristian Grothoff <christian@grothoff.org>2012-11-02 14:10:52 +0000
commitb1cd707e422e03960947a6773a6bcb95c0098f2c (patch)
tree7def2c83956758622fec17bb206d479216aee427 /src
parentc6ef80f13164795b0b53bc7c4c7cae2452cf861e (diff)
downloadgnunet-b1cd707e422e03960947a6773a6bcb95c0098f2c.tar.gz
gnunet-b1cd707e422e03960947a6773a6bcb95c0098f2c.zip
-more DHT test modernization
Diffstat (limited to 'src')
-rw-r--r--src/dht/Makefile.am19
-rw-r--r--src/dht/test_dht_line.conf1
-rw-r--r--src/dht/test_dht_monitor.c423
-rw-r--r--src/dht/test_dht_monitor.conf57
-rw-r--r--src/dht/test_dht_multipeer.conf1
5 files changed, 246 insertions, 255 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index 0baf6b00e..2270d094b 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -125,21 +125,21 @@ check_PROGRAMS = \
125 test_dht_twopeer \ 125 test_dht_twopeer \
126 test_dht_multipeer \ 126 test_dht_multipeer \
127 test_dht_line \ 127 test_dht_line \
128 test_dht_2dtorus 128 test_dht_2dtorus \
129# test_dht_monitor 129 test_dht_monitor
130 130
131if HAVE_EXPERIMENTAL 131if HAVE_EXPERIMENTAL
132# These tests still do not work as testbed does 132# These tests still do not work as testbed does
133# not support the respective topology op 133# not support the respective topology op
134 NEW_TESTS = test_dht_2dtorus test_dht_multipeer 134 NEW_TESTS = test_dht_2dtorus test_dht_multipeer
135endif 135endif
136 136
137if ENABLE_TEST_RUN 137if ENABLE_TEST_RUN
138TESTS = test_dht_api $(check_SCRIPTS) \ 138TESTS = test_dht_api $(check_SCRIPTS) \
139 test_dht_twopeer \ 139 test_dht_twopeer \
140 test_dht_line \ 140 test_dht_line \
141 test_dht_monitor \
141 $(NEW_TESTS) 142 $(NEW_TESTS)
142# test_dht_monitor
143endif 143endif
144 144
145test_dht_api_SOURCES = \ 145test_dht_api_SOURCES = \
@@ -184,18 +184,20 @@ test_dht_line_DEPENDENCIES = \
184test_dht_multipeer_SOURCES = \ 184test_dht_multipeer_SOURCES = \
185 test_dht_topo.c 185 test_dht_topo.c
186test_dht_multipeer_LDADD = \ 186test_dht_multipeer_LDADD = \
187 $(top_builddir)/src/dht/libgnunetdhttest.a \
187 $(top_builddir)/src/util/libgnunetutil.la \ 188 $(top_builddir)/src/util/libgnunetutil.la \
188 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 189 $(top_builddir)/src/statistics/libgnunetstatistics.la \
189 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ 190 $(top_builddir)/src/testbed/libgnunettestbed.la \
190 $(top_builddir)/src/dht/libgnunetdht.la 191 $(top_builddir)/src/dht/libgnunetdht.la
191test_dht_multipeer_DEPENDENCIES = \ 192test_dht_multipeer_DEPENDENCIES = \
192 libgnunetdht.la 193 libgnunetdht.la
193 194
194# fixme, rewrite based on test_dht_topo.c! 195test_dht_monitor_SOURCES = \
195test_dht_monitor_SOURCES = test_dht_monitor.c 196 test_dht_monitor.c
196test_dht_monitor_LDADD = \ 197test_dht_monitor_LDADD = \
198 $(top_builddir)/src/dht/libgnunetdhttest.a \
197 $(top_builddir)/src/util/libgnunetutil.la \ 199 $(top_builddir)/src/util/libgnunetutil.la \
198 $(top_builddir)/src/testing_old/libgnunettesting_old.la \ 200 $(top_builddir)/src/testbed/libgnunettestbed.la \
199 $(top_builddir)/src/dht/libgnunetdht.la 201 $(top_builddir)/src/dht/libgnunetdht.la
200test_dht_monitor_DEPENDENCIES = \ 202test_dht_monitor_DEPENDENCIES = \
201 libgnunetdht.la 203 libgnunetdht.la
@@ -205,6 +207,7 @@ EXTRA_DIST = \
205 test_dht_api_data.conf \ 207 test_dht_api_data.conf \
206 test_dht_api_peer1.conf \ 208 test_dht_api_peer1.conf \
207 test_dht_twopeer_data.conf \ 209 test_dht_twopeer_data.conf \
210 test_dht_monitor.conf \
208 test_dht_multipeer.conf \ 211 test_dht_multipeer.conf \
209 test_dht_2dtorus.conf \ 212 test_dht_2dtorus.conf \
210 test_dht_line.conf \ 213 test_dht_line.conf \
diff --git a/src/dht/test_dht_line.conf b/src/dht/test_dht_line.conf
index e2bb54f1b..0c790aaa1 100644
--- a/src/dht/test_dht_line.conf
+++ b/src/dht/test_dht_line.conf
@@ -10,6 +10,7 @@ AUTOSTART = NO
10[nat] 10[nat]
11DISABLEV6 = YES 11DISABLEV6 = YES
12RETURN_LOCAL_ADDRESSES = YES 12RETURN_LOCAL_ADDRESSES = YES
13USE_LOCALADDR = YES
13ENABLE_UPNP = NO 14ENABLE_UPNP = NO
14BEHIND_NAT = NO 15BEHIND_NAT = NO
15ALLOW_NAT = NO 16ALLOW_NAT = NO
diff --git a/src/dht/test_dht_monitor.c b/src/dht/test_dht_monitor.c
index e8be7e49c..74024edf2 100644
--- a/src/dht/test_dht_monitor.c
+++ b/src/dht/test_dht_monitor.c
@@ -19,277 +19,212 @@
19*/ 19*/
20/** 20/**
21 * @file dht/test_dht_monitor.c 21 * @file dht/test_dht_monitor.c
22 * 22 * @brief Test for the dht monitoring API; checks that we receive "some" monitor events
23 * @brief Test for the dht service: store, retrieve and monitor in a line. 23 * @author Christian Grothoff
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 */ 24 */
30#include "platform.h" 25#include "platform.h"
31#include "gnunet_testing_lib.h" 26#include "gnunet_testbed_service.h"
32#include "gnunet_dht_service.h" 27#include "gnunet_dht_service.h"
33 28#include "dht_test_lib.h"
34#define REMOVE_DIR GNUNET_YES
35 29
36 30
37/** 31/**
38 * How long until we give up on connecting the peers? 32 * How long do we run the test at most?
39 */ 33 */
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500) 34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
41
42#define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
43 35
36/**
37 * How often do we run the PUTs?
38 */
44#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)
45 40
46static int ok;
47 41
48/** 42/**
49 * Be verbose 43 * Information we keep for each GET operation.
50 */ 44 */
51static int verbose; 45struct GetOperation
46{
47 /**
48 * DLL.
49 */
50 struct GetOperation *next;
52 51
53/** 52 /**
54 * Total number of peers in the test. 53 * DLL.
55 */ 54 */
56static unsigned long long num_peers; 55 struct GetOperation *prev;
57 56
58/** 57 /**
59 * Global configuration file 58 * Handle for the operation.
60 */ 59 */
61static struct GNUNET_CONFIGURATION_Handle *testing_cfg; 60 struct GNUNET_DHT_GetHandle *get;
61
62};
62 63
63/**
64 * Total number of currently running peers.
65 */
66static unsigned long long peers_running;
67 64
68/** 65/**
69 * Total number of connections in the whole network. 66 * Return value from 'main'.
70 */ 67 */
71static unsigned int total_connections; 68static int ok;
72 69
73/** 70/**
74 * The currently running peer group. 71 * Head of list of active GET operations.
75 */ 72 */
76static struct GNUNET_TESTING_PeerGroup *pg; 73static struct GetOperation *get_head;
77 74
78/** 75/**
79 * File to report results to. 76 * Tail of list of active GET operations.
80 */ 77 */
81static struct GNUNET_DISK_FileHandle *output_file; 78static struct GetOperation *get_tail;
82 79
83/** 80/**
84 * File to log connection info, statistics to. 81 * Array of the testbed's peers.
85 */ 82 */
86static struct GNUNET_DISK_FileHandle *data_file; 83static struct GNUNET_TESTBED_Peer **my_peers;
87 84
88/** 85/**
89 * Task called to disconnect peers. 86 * Number of peers to run.
90 */ 87 */
91static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; 88static unsigned int NUM_PEERS = 3;
92 89
93/** 90/**
94 * Task To perform tests 91 * Task called to disconnect peers.
95 */ 92 */
96static GNUNET_SCHEDULER_TaskIdentifier test_task; 93static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
97 94
98/** 95/**
99 * Task to do DHT_puts 96 * Task to do DHT_puts
100 */ 97 */
101static GNUNET_SCHEDULER_TaskIdentifier put_task; 98static GNUNET_SCHEDULER_TaskIdentifier put_task;
102 99
103/** 100static struct GNUNET_DHT_MonitorHandle **monitors;
104 * Task called to shutdown test.
105 */
106static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
107
108static char *topology_file;
109
110static struct GNUNET_DHT_Handle **hs;
111
112static struct GNUNET_DHT_MonitorHandle **mhs;
113
114static struct GNUNET_DHT_GetHandle *get_h_far;
115
116static const char *id_far = "2UVH";
117
118static struct GNUNET_TESTING_Daemon *d_far;
119
120static struct GNUNET_TESTING_Daemon *o;
121 101
122static unsigned int monitor_counter; 102static unsigned int monitor_counter;
123 103
124static unsigned int monitor_expect = UINT_MAX;
125
126static int in_test;
127
128 104
129/** 105/**
130 * Check whether peers successfully shut down. 106 * Task run on success or timeout to clean up.
131 */ 107 * Terminates active get operations and shuts down
132static void 108 * the testbed.
133shutdown_callback (void *cls, const char *emsg) 109 *
134{ 110 * @param cls the 'struct GNUNET_DHT_TestContext'
135 if (emsg != NULL) 111 * @param tc scheduler context
136 { 112 */
137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: Shutdown of peers failed: %s\n",
138 emsg);
139 ok++;
140 }
141 else
142 {
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
144 "test: All peers successfully shut down!\n");
145 }
146 GNUNET_CONFIGURATION_destroy (testing_cfg);
147}
148
149
150static void
151shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
152{
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Ending test.\n");
154 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
155 {
156 GNUNET_SCHEDULER_cancel (disconnect_task);
157 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
158 }
159 if (data_file != NULL)
160 GNUNET_DISK_file_close (data_file);
161 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
162}
163
164
165static void 113static void
166disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 114shutdown_task (void *cls,
115 const struct GNUNET_SCHEDULER_TaskContext *tc)
167{ 116{
117 struct GNUNET_DHT_TEST_Context *ctx = cls;
168 unsigned int i; 118 unsigned int i;
119 struct GetOperation *get_op;
169 120
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n"); 121 ok = (monitor_counter > NUM_PEERS) ? 0 : 2;
171 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 122 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
172 GNUNET_SCHEDULER_cancel (put_task); 123 "Received %u monitor events\n",
173 if (NULL != get_h_far) 124 monitor_counter);
174 GNUNET_DHT_get_stop (get_h_far); 125 while (NULL != (get_op = get_tail))
175 for (i = 0; i < num_peers; i++)
176 { 126 {
177 GNUNET_DHT_monitor_stop(mhs[i]); 127 GNUNET_DHT_get_stop (get_op->get);
178 GNUNET_DHT_disconnect (hs[i]); 128 GNUNET_CONTAINER_DLL_remove (get_head,
129 get_tail,
130 get_op);
131 GNUNET_free (get_op);
179 } 132 }
180 GNUNET_SCHEDULER_cancel (shutdown_handle); 133 for (i=0;i<NUM_PEERS;i++)
181 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 134 GNUNET_DHT_monitor_stop (monitors[i]);
135 GNUNET_free (monitors);
136 GNUNET_SCHEDULER_cancel (put_task);
137 GNUNET_DHT_TEST_cleanup (ctx);
182} 138}
183 139
184 140
141/**
142 * Iterator called on each result obtained for a DHT
143 * operation that expects a reply
144 *
145 * @param cls closure with our 'struct GetOperation'
146 * @param exp when will this value expire
147 * @param key key of the result
148 * @param get_path peers on reply path (or NULL if not recorded)
149 * @param get_path_length number of entries in get_path
150 * @param put_path peers on the PUT path (or NULL if not recorded)
151 * @param put_path_length number of entries in get_path
152 * @param type type of the result
153 * @param size number of bytes in data
154 * @param data pointer to the result data
155 */
185static void 156static void
186dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, 157dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp,
187 const struct GNUNET_HashCode * key, 158 const struct GNUNET_HashCode * key,
188 const struct GNUNET_PeerIdentity *get_path, 159 const struct GNUNET_PeerIdentity *get_path,
189 unsigned int get_path_length, 160 unsigned int get_path_length,
190 const struct GNUNET_PeerIdentity *put_path, 161 const struct GNUNET_PeerIdentity *put_path,
191 unsigned int put_path_length, enum GNUNET_BLOCK_Type type, 162 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
192 size_t size, const void *data) 163 size_t size, const void *data)
193{ 164{
194 int i; 165 struct GetOperation *get_op = cls;
166 struct GNUNET_HashCode want;
167 struct GNUNET_DHT_TestContext *ctx;
195 168
196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 169 if (sizeof (struct GNUNET_HashCode) != size)
197 "test: ************* FOUND!!! ***********\n");
198 if (sizeof (struct GNUNET_HashCode) == size)
199 { 170 {
200 const struct GNUNET_HashCode *h = data; 171 GNUNET_break (0);
201 172 return;
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Contents: %s\n",
203 GNUNET_h2s_full (h));
204
205 }
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: PATH: (get %u, put %u)\n",
207 get_path_length, put_path_length);
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: LOCAL\n");
209 for (i = get_path_length - 1; i >= 0; i--)
210 {
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n",
212 GNUNET_i2s (&get_path[i]));
213 }
214 for (i = put_path_length - 1; i >= 0; i--)
215 {
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n",
217 GNUNET_i2s (&put_path[i]));
218 }
219 monitor_expect = get_path_length + put_path_length;
220 if (monitor_counter >= monitor_expect)
221 {
222 ok = 0;
223 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "expected at least %u hops, got %u\n",
224 get_path_length + put_path_length, monitor_counter);
225 GNUNET_SCHEDULER_cancel (disconnect_task);
226 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL);
227 } 173 }
228} 174 GNUNET_CRYPTO_hash (key, sizeof (*key), &want);
229 175 if (0 != memcmp (&want, data, sizeof (want)))
230
231/**
232 * Start test: start GET request from the first node in the line looking for
233 * the ID of the last node in the line.
234 *
235 * @param cls Closure (not used).
236 * @param tc Task context.
237 */
238static void
239do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
240{
241 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
242 { 176 {
177 GNUNET_break (0);
243 return; 178 return;
244 } 179 }
245 180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
246 in_test = GNUNET_YES; 181 "Get successful\n");
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); 182 GNUNET_DHT_get_stop (get_op->get);
248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", 183 GNUNET_CONTAINER_DLL_remove (get_head,
249 GNUNET_h2s_full (&d_far->id.hashPubKey)); 184 get_tail,
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n", 185 get_op);
251 GNUNET_h2s_full (&o->id.hashPubKey)); 186 GNUNET_free (get_op);
252 get_h_far = GNUNET_DHT_get_start (hs[0], 187 if (NULL != get_head)
253 GNUNET_BLOCK_TYPE_TEST, /* type */ 188 return;
254 &d_far->id.hashPubKey, /*key to search */ 189 /* all DHT GET operations successful; terminate! */
255 4U, /* replication level */ 190 ok = 0;
256 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ 191 ctx = GNUNET_SCHEDULER_cancel (timeout_task);
257 0, /* xquery bits */ 192 timeout_task = GNUNET_SCHEDULER_add_now (&shutdown_task, ctx);
258 &dht_get_id_handler, NULL);
259 GNUNET_SCHEDULER_cancel (disconnect_task);
260 disconnect_task =
261 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL);
262} 193}
263 194
264 195
265/** 196/**
266 * Periodic function used to put the ID of the far peer in the DHT. 197 * Task to put the id of each peer into the DHT.
267 * 198 *
268 * @param cls Closure (not used). 199 * @param cls array with NUM_PEERS DHT handles
269 * @param tc Task context. 200 * @param tc Task context
270 */ 201 */
271static void 202static void
272put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 203do_puts (void *cls,
204 const struct GNUNET_SCHEDULER_TaskContext *tc)
273{ 205{
274 struct GNUNET_TESTING_Daemon *d; 206 struct GNUNET_DHT_Handle **hs = cls;
207 struct GNUNET_HashCode key;
208 struct GNUNET_HashCode value;
209 unsigned int i;
275 210
276 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
212 "Putting values into DHT\n");
213 for (i = 0; i < NUM_PEERS; i++)
277 { 214 {
278 put_task = GNUNET_SCHEDULER_NO_TASK; 215 GNUNET_CRYPTO_hash (&i, sizeof (i), &key);
279 return; 216 GNUNET_CRYPTO_hash (&key, sizeof (key), &value);
217 GNUNET_DHT_put (hs[i], &key, 10U,
218 GNUNET_DHT_RO_RECORD_ROUTE |
219 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
220 GNUNET_BLOCK_TYPE_TEST,
221 sizeof (value), &value,
222 GNUNET_TIME_UNIT_FOREVER_ABS,
223 GNUNET_TIME_UNIT_FOREVER_REL,
224 NULL, NULL);
280 } 225 }
281 226 put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY,
282 d = GNUNET_TESTING_daemon_get (pg, 4); 227 &do_puts, hs);
283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n",
284 GNUNET_h2s_full (&d->id.hashPubKey));
285 GNUNET_DHT_put (hs[4], &d->id.hashPubKey, 10U,
286 GNUNET_DHT_RO_RECORD_ROUTE |
287 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
288 GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity),
289 (const char *) &d->id, GNUNET_TIME_UNIT_FOREVER_ABS,
290 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
291
292 put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL);
293} 228}
294 229
295 230
@@ -316,27 +251,14 @@ monitor_get_cb (void *cls,
316 const struct GNUNET_PeerIdentity *path, 251 const struct GNUNET_PeerIdentity *path,
317 const struct GNUNET_HashCode * key) 252 const struct GNUNET_HashCode * key)
318{ 253{
319 const char *s_key;
320 unsigned int i; 254 unsigned int i;
321 255
322 i = (unsigned int) (long) cls; 256 i = (unsigned int) (long) cls;
323 s_key = GNUNET_h2s(key);
324 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 257 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
325 "%u got a GET message for key %s\n", 258 "%u got a GET message for key %s\n",
326 i, s_key); 259 i,
327 260 GNUNET_h2s (key));
328 if (strncmp (s_key, id_far, 4) == 0 && in_test == GNUNET_YES) 261 monitor_counter++;
329 {
330 monitor_counter++;
331 if (monitor_counter >= monitor_expect)
332 {
333 ok = 0;
334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "expected at least %u hops, got %u\n",
335 monitor_expect, monitor_counter);
336 GNUNET_SCHEDULER_cancel (disconnect_task);
337 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL);
338 }
339 }
340} 262}
341 263
342 264
@@ -369,18 +291,14 @@ monitor_put_cb (void *cls,
369 const void *data, 291 const void *data,
370 size_t size) 292 size_t size)
371{ 293{
372 const char *s_key;
373 unsigned int i; 294 unsigned int i;
374 295
375 i = (unsigned int) (long) cls; 296 i = (unsigned int) (long) cls;
376 s_key = GNUNET_h2s(key);
377
378 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 297 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
379 "%u got a PUT message for key %s with %u bytes\n", 298 "%u got a PUT message for key %s with %u bytes\n",
380 i, s_key, size); 299 i,
381 300 GNUNET_h2s (key), size);
382 if (strncmp (s_key, id_far, 4) == 0 && in_test == GNUNET_YES) 301 monitor_counter++;
383 monitor_counter++;
384} 302}
385 303
386 304
@@ -411,17 +329,14 @@ monitor_res_cb (void *cls,
411 const void *data, 329 const void *data,
412 size_t size) 330 size_t size)
413{ 331{
414 const char *s_key;
415 unsigned int i; 332 unsigned int i;
416 333
417 i = (unsigned int) (long) cls; 334 i = (unsigned int) (long) cls;
418 s_key = GNUNET_h2s(key);
419 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 335 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
420 "%u got a REPLY message for key %s with %u bytes\n", 336 "%u got a REPLY message for key %s with %u bytes\n",
421 i, s_key, size); 337 i,
422 338 GNUNET_h2s (key), size);
423 if (strncmp (s_key, id_far, 4) == 0 && in_test == GNUNET_YES) 339 monitor_counter++;
424 monitor_counter++;
425} 340}
426 341
427 342
@@ -442,31 +357,45 @@ run (void *cls,
442 struct GNUNET_DHT_Handle **dhts) 357 struct GNUNET_DHT_Handle **dhts)
443{ 358{
444 unsigned int i; 359 unsigned int i;
360 unsigned int j;
361 struct GNUNET_HashCode key;
362 struct GetOperation *get_op;
445 363
446 GNUNET_assert (NUM_PEERS == num_peers); 364 GNUNET_assert (NUM_PEERS == num_peers);
447 my_peers = peers; 365 my_peers = peers;
448 mhs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_MonitorHandle *)); 366 monitors = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_MonitorHandle *));
449 for (i = 0; i < num_peers; i++) 367 for (i = 0; i < num_peers; i++)
368 monitors[i] = GNUNET_DHT_monitor_start (dhts[i],
369 GNUNET_BLOCK_TYPE_ANY,
370 NULL,
371 &monitor_get_cb,
372 &monitor_res_cb,
373 &monitor_put_cb,
374 (void *)(long)i);
375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
376 "Peers setup, starting test\n");
377 put_task = GNUNET_SCHEDULER_add_now (&do_puts, dhts);
378 for (i=0;i<num_peers;i++)
450 { 379 {
451 d = GNUNET_TESTING_daemon_get (pg, i); 380 GNUNET_CRYPTO_hash (&i, sizeof (i), &key);
452 hs[i] = GNUNET_DHT_connect (d->cfg, 32); 381 for (j=0;j<num_peers;j++)
453 mhs[i] = GNUNET_DHT_monitor_start (hs[i], 382 {
454 GNUNET_BLOCK_TYPE_ANY, 383 get_op = GNUNET_malloc (sizeof (struct GetOperation));
455 NULL, 384 GNUNET_CONTAINER_DLL_insert (get_head,
456 &monitor_get_cb, 385 get_tail,
457 &monitor_res_cb, 386 get_op);
458 &monitor_put_cb, 387 get_op->get = GNUNET_DHT_get_start (dhts[j],
459 (void *)(long)i); 388 GNUNET_BLOCK_TYPE_TEST, /* type */
389 &key, /*key to search */
390 4U, /* replication level */
391 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
392 NULL, /* xquery */
393 0, /* xquery bits */
394 &dht_get_handler, get_op);
395 }
460 } 396 }
461 put_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 397 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
462 (GNUNET_TIME_UNIT_SECONDS, 3), 398 &shutdown_task, ctx);
463 &put_id, NULL);
464 test_task =
465 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
466 (GNUNET_TIME_UNIT_SECONDS, 6), &do_test,
467 NULL);
468 disconnect_task =
469 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL);
470} 399}
471 400
472 401
diff --git a/src/dht/test_dht_monitor.conf b/src/dht/test_dht_monitor.conf
new file mode 100644
index 000000000..ebefcca38
--- /dev/null
+++ b/src/dht/test_dht_monitor.conf
@@ -0,0 +1,57 @@
1[fs]
2AUTOSTART = NO
3
4[resolver]
5AUTOSTART = NO
6
7[block]
8plugins = test dht
9
10[dhtcache]
11QUOTA = 1 MB
12DATABASE = sqlite
13
14[transport]
15PLUGINS = tcp
16
17[ats]
18WAN_QUOTA_IN = 1 GB
19WAN_QUOTA_OUT = 1 GB
20
21[arm]
22DEFAULTSERVICES = dht core
23
24[TESTING]
25WEAKRANDOM = YES
26
27[testbed]
28OVERLAY_TOPOLOGY = LINE
29
30[gnunetd]
31HOSTKEY = $SERVICEHOME/.hostkey
32
33[PATHS]
34SERVICEHOME = /tmp/test-dht-multipeer/
35
36[nat]
37DISABLEV6 = YES
38ENABLE_UPNP = NO
39BEHIND_NAT = NO
40ALLOW_NAT = NO
41INTERNAL_ADDRESS = 127.0.0.1
42EXTERNAL_ADDRESS = 127.0.0.1
43USE_LOCALADDR = YES
44RETURN_LOCAL_ADDRESSES = YES
45
46[dns]
47AUTOSTART = NO
48
49[namestore]
50AUTOSTART = NO
51
52[nse]
53AUTOSTART = NO
54
55[vpn]
56AUTOSTART=NO
57
diff --git a/src/dht/test_dht_multipeer.conf b/src/dht/test_dht_multipeer.conf
index 497510ce5..1408f05b9 100644
--- a/src/dht/test_dht_multipeer.conf
+++ b/src/dht/test_dht_multipeer.conf
@@ -36,6 +36,7 @@ SERVICEHOME = /tmp/test-dht-multipeer/
36 36
37[nat] 37[nat]
38DISABLEV6 = YES 38DISABLEV6 = YES
39RETURN_LOCAL_ADDRESSES = YES
39ENABLE_UPNP = NO 40ENABLE_UPNP = NO
40BEHIND_NAT = NO 41BEHIND_NAT = NO
41ALLOW_NAT = NO 42ALLOW_NAT = NO