aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-10-20 17:35:19 +0000
committerBart Polot <bart@net.in.tum.de>2011-10-20 17:35:19 +0000
commit3df90c73c968bc0efd3027aa0e1811ef7902fe2a (patch)
tree4b6a2f4dd59dd82018a5bb5b1c4bbd00b8da4fef /src/dht
parent13dc02087efbf8a33a6669e12d294e8fd6aa702f (diff)
downloadgnunet-3df90c73c968bc0efd3027aa0e1811ef7902fe2a.tar.gz
gnunet-3df90c73c968bc0efd3027aa0e1811ef7902fe2a.zip
Added testcase for opposite peers in a small 2d grid
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/Makefile.am15
-rw-r--r--src/dht/test_dht_2dtorus.c57
2 files changed, 53 insertions, 19 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index 2a62979e1..6a8ce280a 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -78,7 +78,8 @@ check_PROGRAMS = \
78 test_dht_twopeer_get_put \ 78 test_dht_twopeer_get_put \
79 test_dht_twopeer_path_tracking \ 79 test_dht_twopeer_path_tracking \
80 test_dht_multipeer \ 80 test_dht_multipeer \
81 test_dht_2dtorus 81 test_dht_2dtorus \
82 test_dht_2dtorus_far
82 83
83if ENABLE_TEST_RUN 84if ENABLE_TEST_RUN
84TESTS = test_dht_api $(check_SCRIPTS) \ 85TESTS = test_dht_api $(check_SCRIPTS) \
@@ -87,7 +88,8 @@ TESTS = test_dht_api $(check_SCRIPTS) \
87 test_dht_twopeer_get_put \ 88 test_dht_twopeer_get_put \
88 test_dht_twopeer_path_tracking \ 89 test_dht_twopeer_path_tracking \
89 test_dht_multipeer \ 90 test_dht_multipeer \
90 test_dht_2dtorus 91 test_dht_2dtorus \
92 test_dht_2dtorus_far
91endif 93endif
92 94
93test_dht_api_SOURCES = \ 95test_dht_api_SOURCES = \
@@ -148,6 +150,15 @@ test_dht_2dtorus_LDADD = \
148test_dht_2dtorus_DEPENDENCIES = \ 150test_dht_2dtorus_DEPENDENCIES = \
149 libgnunetdht.la 151 libgnunetdht.la
150 152
153test_dht_2dtorus_far_SOURCES = \
154 test_dht_2dtorus.c
155test_dht_2dtorus_far_LDADD = \
156 $(top_builddir)/src/util/libgnunetutil.la \
157 $(top_builddir)/src/testing/libgnunettesting.la \
158 $(top_builddir)/src/dht/libgnunetdht.la
159test_dht_2dtorus_far_DEPENDENCIES = \
160 libgnunetdht.la
161
151 162
152EXTRA_DIST = \ 163EXTRA_DIST = \
153 $(check_SCRIPTS) \ 164 $(check_SCRIPTS) \
diff --git a/src/dht/test_dht_2dtorus.c b/src/dht/test_dht_2dtorus.c
index d5acbbcb3..7c6c61a81 100644
--- a/src/dht/test_dht_2dtorus.c
+++ b/src/dht/test_dht_2dtorus.c
@@ -41,6 +41,8 @@
41 41
42static int ok; 42static int ok;
43 43
44static int far;
45
44/** 46/**
45 * Be verbose 47 * Be verbose
46 */ 48 */
@@ -204,15 +206,38 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
204{ 206{
205 struct GNUNET_TESTING_Daemon *d; 207 struct GNUNET_TESTING_Daemon *d;
206 struct GNUNET_TESTING_Daemon *o; 208 struct GNUNET_TESTING_Daemon *o;
209 struct GNUNET_TESTING_Daemon *aux;
210 const char *id_aux;
211 const char *id_origin = "FC74";
212 const char *id_near = "9P6V";
213 const char *id_far = "KPST";
214 unsigned int i;
207 215
208 d = GNUNET_TESTING_daemon_get (pg, 2); 216 d = o = NULL;
209 o = GNUNET_TESTING_daemon_get (pg, 0); 217 for (i = 0; i < num_peers; i++)
218 {
219 aux = GNUNET_TESTING_daemon_get (pg, i);
220 id_aux = GNUNET_i2s (&aux->id);
221 if (strcmp (id_aux, id_origin) == 0)
222 o = aux;
223 if (far == GNUNET_YES && strcmp (id_aux, id_far) == 0)
224 d = aux;
225 if (far == GNUNET_NO && strcmp (id_aux, id_near) == 0)
226 d = aux;
227 }
228 if (NULL == o || NULL == d)
229 {
230 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
231 "test: Peers not found (hostkey file changed?)\n");
232 GNUNET_SCHEDULER_cancel (disconnect_task);
233 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL);
234 }
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); 235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
212 "test: looking for [2] %s\n", 237 "test: looking for %s\n",
213 GNUNET_h2s_full (&d->id.hashPubKey)); 238 GNUNET_h2s_full (&d->id.hashPubKey));
214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
215 "test: from [0] %s\n", 240 "test: from %s\n",
216 GNUNET_h2s_full (&o->id.hashPubKey)); 241 GNUNET_h2s_full (&o->id.hashPubKey));
217 get_h = GNUNET_DHT_get_start (hs[0], 242 get_h = GNUNET_DHT_get_start (hs[0],
218 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 243 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
@@ -353,23 +378,12 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
353 struct GNUNET_TESTING_Daemon *first_daemon, 378 struct GNUNET_TESTING_Daemon *first_daemon,
354 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) 379 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
355{ 380{
356// GNUNET_PEER_Id f;
357// GNUNET_PEER_Id s;
358 381
359 if (emsg == NULL) 382 if (emsg == NULL)
360 { 383 {
361 total_connections++; 384 total_connections++;
362 /*f = */GNUNET_PEER_intern(first); 385 GNUNET_PEER_intern(first);
363 /*s = */GNUNET_PEER_intern(second); 386 GNUNET_PEER_intern(second);
364// GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: New connection!\n");
365// GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
366// "test: %s (%u)\n",
367// GNUNET_h2s(&first->hashPubKey),
368// f);
369// GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
370// "test: %s (%u)\n",
371// GNUNET_h2s(&second->hashPubKey),
372// s);
373 } 387 }
374 else 388 else
375 { 389 {
@@ -508,6 +522,15 @@ main (int xargc, char *xargv[])
508#endif 522#endif
509 NULL 523 NULL
510 }; 524 };
525
526 if (strstr (xargv[0], "2dtorus_far") != NULL)
527 {
528 far = GNUNET_YES;
529 }
530 else
531 {
532 far = GNUNET_NO;
533 }
511 534
512 GNUNET_PROGRAM_run (sizeof(argv)/sizeof(char*) - 1, argv, "test_dht_2dtorus", 535 GNUNET_PROGRAM_run (sizeof(argv)/sizeof(char*) - 1, argv, "test_dht_2dtorus",
513 gettext_noop ("Test dht in a small 2D torus."), options, 536 gettext_noop ("Test dht in a small 2D torus."), options,