aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-01-10 14:22:35 +0100
committerChristian Grothoff <christian@grothoff.org>2022-01-10 14:22:35 +0100
commit8ee3c5121e87d8f25193ae6044d5818f4629fa1e (patch)
treeeb0dd0250f11fb5f9bc788cef8ba55da90160698 /src/dht
parentd4641d36b885ba764945d6353ed71b7bc485c6ac (diff)
downloadgnunet-8ee3c5121e87d8f25193ae6044d5818f4629fa1e.tar.gz
gnunet-8ee3c5121e87d8f25193ae6044d5818f4629fa1e.zip
-DHT: add path signature verification logic; tests pass, but logic remains dead
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/Makefile.am1
-rw-r--r--src/dht/dht_api.c42
-rw-r--r--src/dht/dht_test_lib.c15
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c74
-rw-r--r--src/dht/test_dht_topo.c190
5 files changed, 241 insertions, 81 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index 69e34000c..be48fab02 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -63,6 +63,7 @@ gnunet_service_dht_SOURCES = \
63 gnunet-service-dht_neighbours.c gnunet-service-dht_neighbours.h \ 63 gnunet-service-dht_neighbours.c gnunet-service-dht_neighbours.h \
64 gnunet-service-dht_routing.c gnunet-service-dht_routing.h 64 gnunet-service-dht_routing.c gnunet-service-dht_routing.h
65gnunet_service_dht_LDADD = \ 65gnunet_service_dht_LDADD = \
66 libgnunetdht.la \
66 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 67 $(top_builddir)/src/statistics/libgnunetstatistics.la \
67 $(top_builddir)/src/core/libgnunetcore.la \ 68 $(top_builddir)/src/core/libgnunetcore.la \
68 $(top_builddir)/src/nse/libgnunetnse.la \ 69 $(top_builddir)/src/nse/libgnunetnse.la \
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index af3c7d685..8389bbb95 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -1198,31 +1198,51 @@ GNUNET_DHT_verify_path (const struct GNUNET_HashCode *key,
1198 const void *data, 1198 const void *data,
1199 size_t data_size, 1199 size_t data_size,
1200 struct GNUNET_TIME_Absolute exp_time, 1200 struct GNUNET_TIME_Absolute exp_time,
1201 const struct GNUNET_DHT_PathElement *path, 1201 const struct GNUNET_DHT_PathElement *put_path,
1202 unsigned int path_len, 1202 unsigned int put_path_len,
1203 const struct GNUNET_DHT_PathElement *get_path,
1204 unsigned int get_path_len,
1203 const struct GNUNET_PeerIdentity *me) 1205 const struct GNUNET_PeerIdentity *me)
1204{ 1206{
1205
1206 struct GNUNET_DHT_HopSignature hs = { 1207 struct GNUNET_DHT_HopSignature hs = {
1207 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DHT_HOP), 1208 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DHT_HOP),
1208 .purpose.size = htonl (sizeof (hs)), 1209 .purpose.size = htonl (sizeof (hs)),
1209 .expiration_time = GNUNET_TIME_absolute_hton (exp_time), 1210 .expiration_time = GNUNET_TIME_absolute_hton (exp_time),
1210 .key = *key, 1211 .key = *key,
1211 }; 1212 };
1212 unsigned int i = path_len - 1; 1213 unsigned int i;
1213 1214
1215 if (0 == get_path_len + put_path_len)
1216 return 0;
1217 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1218 "Verifying signatures with GPL: %u PPL: %u!\n",
1219 get_path_len,
1220 put_path_len);
1221 i = put_path_len + get_path_len - 1;
1214 GNUNET_CRYPTO_hash (data, 1222 GNUNET_CRYPTO_hash (data,
1215 data_size, 1223 data_size,
1216 &hs.h_data); 1224 &hs.h_data);
1217 while (i > 0) 1225 while (i > 0)
1218 { 1226 {
1219 hs.pred = path[i - 1].pred; 1227 hs.pred = (i - 1 >= put_path_len)
1220 hs.succ = (path_len == i + 1) ? *me : path[i + 1].pred; 1228 ? get_path[i - put_path_len - 1].pred
1229 : put_path[i - 1].pred;
1230 if (i + 1 == get_path_len + put_path_len)
1231 hs.succ = *me;
1232 else
1233 hs.succ = (i + 1 >= put_path_len)
1234 ? get_path[i + 1 - put_path_len].pred
1235 : put_path[i + 1].pred;
1221 if (GNUNET_OK != 1236 if (GNUNET_OK !=
1222 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_DHT_HOP, 1237 GNUNET_CRYPTO_eddsa_verify (
1223 &hs, 1238 GNUNET_SIGNATURE_PURPOSE_DHT_HOP,
1224 &path[i - 1].sig, 1239 &hs,
1225 &path[i].pred.public_key)) 1240 (i - 1 >= put_path_len)
1241 ? &get_path[i - put_path_len - 1].sig
1242 : &put_path[i - 1].sig,
1243 (i >= put_path_len)
1244 ? &get_path[i - put_path_len].pred.public_key
1245 : &put_path[i].pred.public_key))
1226 return i; 1246 return i;
1227 i--; 1247 i--;
1228 } 1248 }
diff --git a/src/dht/dht_test_lib.c b/src/dht/dht_test_lib.c
index 0d382cd74..29c5088d1 100644
--- a/src/dht/dht_test_lib.c
+++ b/src/dht/dht_test_lib.c
@@ -138,11 +138,6 @@ dht_connect_cb (void *cls,
138} 138}
139 139
140 140
141/**
142 * Clean up the testbed.
143 *
144 * @param ctx handle for the testbed
145 */
146void 141void
147GNUNET_DHT_TEST_cleanup (struct GNUNET_DHT_TEST_Context *ctx) 142GNUNET_DHT_TEST_cleanup (struct GNUNET_DHT_TEST_Context *ctx)
148{ 143{
@@ -179,16 +174,6 @@ dht_test_run (void *cls,
179} 174}
180 175
181 176
182/**
183 * Run a test using the given name, configuration file and number of
184 * peers.
185 *
186 * @param testname name of the test (for logging)
187 * @param cfgname name of the configuration file
188 * @param num_peers number of peers to start
189 * @param tmain main function to run once the testbed is ready
190 * @param tmain_cls closure for 'tmain'
191 */
192void 177void
193GNUNET_DHT_TEST_run (const char *testname, 178GNUNET_DHT_TEST_run (const char *testname,
194 const char *cfgname, 179 const char *cfgname,
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 95d8bb032..cf150ea0c 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -1308,6 +1308,21 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd,
1308 unsigned int put_path_length = bd->put_path_length; 1308 unsigned int put_path_length = bd->put_path_length;
1309 1309
1310 GNUNET_assert (NULL != bf); 1310 GNUNET_assert (NULL != bf);
1311#if SANITY_CHECKS
1312 if (0 !=
1313 GNUNET_DHT_verify_path (&bd->key,
1314 bd->data,
1315 bd->data_size,
1316 bd->expiration_time,
1317 bd->put_path,
1318 bd->put_path_length,
1319 NULL, 0, /* get_path */
1320 &my_identity))
1321 {
1322 GNUNET_break_op (0);
1323 put_path_length = 0;
1324 }
1325#endif
1311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1312 "Adding myself (%s) to PUT bloomfilter for %s\n", 1327 "Adding myself (%s) to PUT bloomfilter for %s\n",
1313 GNUNET_i2s (&my_identity), 1328 GNUNET_i2s (&my_identity),
@@ -1564,13 +1579,43 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi,
1564 struct PeerResultMessage *prm; 1579 struct PeerResultMessage *prm;
1565 struct GNUNET_DHT_PathElement *paths; 1580 struct GNUNET_DHT_PathElement *paths;
1566 size_t msize; 1581 size_t msize;
1582 unsigned int ppl = bd->put_path_length;
1567 1583
1568 msize = bd->data_size + (get_path_length + bd->put_path_length) 1584#if SANITY_CHECKS
1585 if (0 !=
1586 GNUNET_DHT_verify_path (&bd->key,
1587 bd->data,
1588 bd->data_size,
1589 bd->expiration_time,
1590 bd->put_path,
1591 bd->put_path_length,
1592 get_path,
1593 get_path_length,
1594 &my_identity))
1595 {
1596 GNUNET_break_op (0);
1597 get_path_length = 0;
1598 ppl = 0;
1599 }
1600#endif
1601 msize = bd->data_size + (get_path_length + ppl)
1569 * sizeof(struct GNUNET_DHT_PathElement); 1602 * sizeof(struct GNUNET_DHT_PathElement);
1570 if ( (msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) || 1603 if ( (msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
1571 (get_path_length > 1604 (get_path_length >
1572 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || 1605 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) ||
1573 (bd->put_path_length > 1606 (ppl >
1607 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) ||
1608 (bd->data_size > GNUNET_MAX_MESSAGE_SIZE))
1609 {
1610 ppl = 0;
1611 get_path_length = 0;
1612 msize = bd->data_size + (get_path_length + ppl)
1613 * sizeof(struct GNUNET_DHT_PathElement);
1614 }
1615 if ( (msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
1616 (get_path_length >
1617 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) ||
1618 (ppl >
1574 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || 1619 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) ||
1575 (bd->data_size > GNUNET_MAX_MESSAGE_SIZE)) 1620 (bd->data_size > GNUNET_MAX_MESSAGE_SIZE))
1576 { 1621 {
@@ -1602,15 +1647,15 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi,
1602 msize, 1647 msize,
1603 GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); 1648 GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT);
1604 prm->type = htonl (bd->type); 1649 prm->type = htonl (bd->type);
1605 prm->put_path_length = htonl (bd->put_path_length); 1650 prm->put_path_length = htonl (ppl);
1606 prm->get_path_length = htonl (get_path_length); 1651 prm->get_path_length = htonl (get_path_length);
1607 prm->expiration_time = GNUNET_TIME_absolute_hton (bd->expiration_time); 1652 prm->expiration_time = GNUNET_TIME_absolute_hton (bd->expiration_time);
1608 prm->key = *query_hash; 1653 prm->key = *query_hash;
1609 paths = (struct GNUNET_DHT_PathElement *) &prm[1]; 1654 paths = (struct GNUNET_DHT_PathElement *) &prm[1];
1610 GNUNET_memcpy (paths, 1655 GNUNET_memcpy (paths,
1611 bd->put_path, 1656 bd->put_path,
1612 bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement)); 1657 ppl * sizeof(struct GNUNET_DHT_PathElement));
1613 GNUNET_memcpy (&paths[bd->put_path_length], 1658 GNUNET_memcpy (&paths[ppl],
1614 get_path, 1659 get_path,
1615 get_path_length * sizeof(struct GNUNET_DHT_PathElement)); 1660 get_path_length * sizeof(struct GNUNET_DHT_PathElement));
1616 /* 0 == get_path_length means path is not being tracked */ 1661 /* 0 == get_path_length means path is not being tracked */
@@ -1622,11 +1667,11 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi,
1622 bd->data, 1667 bd->data,
1623 bd->data_size, 1668 bd->data_size,
1624 bd->expiration_time, 1669 bd->expiration_time,
1625 &paths[bd->put_path_length + get_path_length - 1].pred, 1670 &paths[ppl + get_path_length - 1].pred,
1626 pi->id, 1671 pi->id,
1627 &paths[bd->put_path_length + get_path_length - 1].sig); 1672 &paths[ppl + get_path_length - 1].sig);
1628 } 1673 }
1629 GNUNET_memcpy (&paths[bd->put_path_length + get_path_length], 1674 GNUNET_memcpy (&paths[ppl + get_path_length],
1630 bd->data, 1675 bd->data,
1631 bd->data_size); 1676 bd->data_size);
1632 GNUNET_MQ_send (pi->mq, 1677 GNUNET_MQ_send (pi->mq,
@@ -1798,6 +1843,19 @@ handle_dht_p2p_put (void *cls,
1798 GNUNET_memcmp (&pp[i].pred, 1843 GNUNET_memcmp (&pp[i].pred,
1799 peer->id)); 1844 peer->id));
1800 } 1845 }
1846 if (0 !=
1847 GNUNET_DHT_verify_path (&bd.key,
1848 bd.data,
1849 bd.data_size,
1850 bd.expiration_time,
1851 bd.put_path,
1852 putlen,
1853 NULL, 0, /* get_path */
1854 &my_identity))
1855 {
1856 GNUNET_break_op (0);
1857 putlen = 0;
1858 }
1801#endif 1859#endif
1802 GNUNET_memcpy (pp, 1860 GNUNET_memcpy (pp,
1803 put_path, 1861 put_path,
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c
index dfe969bb9..9f4b1b034 100644
--- a/src/dht/test_dht_topo.c
+++ b/src/dht/test_dht_topo.c
@@ -58,16 +58,36 @@ struct GetOperation
58 struct GetOperation *prev; 58 struct GetOperation *prev;
59 59
60 /** 60 /**
61 * Operation to fetch @a me.
62 */
63 struct GNUNET_TESTBED_Operation *to;
64
65 /**
61 * Handle for the operation. 66 * Handle for the operation.
62 */ 67 */
63 struct GNUNET_DHT_GetHandle *get; 68 struct GNUNET_DHT_GetHandle *get;
69
70 /**
71 * DHT used by this operation.
72 */
73 struct GNUNET_DHT_Handle *dht;
74
75 /**
76 * Key we are looking up.
77 */
78 struct GNUNET_HashCode key;
79
80 /**
81 * At which peer is this operation being performed?
82 */
83 struct GNUNET_PeerIdentity me;
64}; 84};
65 85
66 86
67/** 87/**
68 * Result of the test. 88 * Result of the test.
69 */ 89 */
70static int ok = 1; 90static int ok;
71 91
72/** 92/**
73 * Task to do DHT_puts 93 * Task to do DHT_puts
@@ -154,7 +174,7 @@ static struct
154 174
155 175
156static struct GNUNET_DHT_TEST_Context * 176static struct GNUNET_DHT_TEST_Context *
157stop_ops () 177stop_ops (void)
158{ 178{
159 struct GetOperation *get_op; 179 struct GetOperation *get_op;
160 struct GNUNET_DHT_TEST_Context *ctx = NULL; 180 struct GNUNET_DHT_TEST_Context *ctx = NULL;
@@ -176,7 +196,16 @@ stop_ops ()
176 } 196 }
177 while (NULL != (get_op = get_tail)) 197 while (NULL != (get_op = get_tail))
178 { 198 {
179 GNUNET_DHT_get_stop (get_op->get); 199 if (NULL != get_op->to)
200 {
201 GNUNET_TESTBED_operation_done (get_op->to);
202 get_op->to = NULL;
203 }
204 if (NULL != get_op->get)
205 {
206 GNUNET_DHT_get_stop (get_op->get);
207 get_op->get = NULL;
208 }
180 GNUNET_CONTAINER_DLL_remove (get_head, 209 GNUNET_CONTAINER_DLL_remove (get_head,
181 get_tail, 210 get_tail,
182 get_op); 211 get_op);
@@ -199,7 +228,6 @@ stats_finished (void *cls,
199 const char *emsg) 228 const char *emsg)
200{ 229{
201 struct GNUNET_DHT_TEST_Context *ctx = cls; 230 struct GNUNET_DHT_TEST_Context *ctx = cls;
202 unsigned int i;
203 231
204 if (NULL != op) 232 if (NULL != op)
205 GNUNET_TESTBED_operation_done (op); 233 GNUNET_TESTBED_operation_done (op);
@@ -212,7 +240,7 @@ stats_finished (void *cls,
212 GNUNET_DHT_TEST_cleanup (ctx); 240 GNUNET_DHT_TEST_cleanup (ctx);
213 return; 241 return;
214 } 242 }
215 for (i = 0; NULL != stats[i].name; i++) 243 for (unsigned int i = 0; NULL != stats[i].name; i++)
216 fprintf (stderr, 244 fprintf (stderr,
217 "%6s/%60s = %12llu\n", 245 "%6s/%60s = %12llu\n",
218 stats[i].subsystem, 246 stats[i].subsystem,
@@ -234,7 +262,7 @@ stats_finished (void *cls,
234 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not 262 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
235 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 263 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
236 */ 264 */
237static int 265static enum GNUNET_GenericReturnValue
238handle_stats (void *cls, 266handle_stats (void *cls,
239 const struct GNUNET_TESTBED_Peer *peer, 267 const struct GNUNET_TESTBED_Peer *peer,
240 const char *subsystem, 268 const char *subsystem,
@@ -242,9 +270,7 @@ handle_stats (void *cls,
242 uint64_t value, 270 uint64_t value,
243 int is_persistent) 271 int is_persistent)
244{ 272{
245 unsigned int i; 273 for (unsigned int i = 0; NULL != stats[i].name; i++)
246
247 for (i = 0; NULL != stats[i].name; i++)
248 if ((0 == strcasecmp (subsystem, 274 if ((0 == strcasecmp (subsystem,
249 stats[i].subsystem)) && 275 stats[i].subsystem)) &&
250 (0 == strcasecmp (name, 276 (0 == strcasecmp (name,
@@ -263,7 +289,14 @@ handle_stats (void *cls,
263static void 289static void
264shutdown_task (void *cls) 290shutdown_task (void *cls)
265{ 291{
266 (void) stop_ops (); 292 struct GNUNET_DHT_TEST_Context *ctx;
293
294 (void) cls;
295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
296 "Performing shutdown\n");
297 ctx = stop_ops ();
298 if (NULL != ctx)
299 GNUNET_DHT_TEST_cleanup (ctx);
267} 300}
268 301
269 302
@@ -276,7 +309,11 @@ shutdown_task (void *cls)
276static void 309static void
277timeout_cb (void *cls) 310timeout_cb (void *cls)
278{ 311{
279 timeout_task = NULL; 312 struct GNUNET_DHT_TEST_Context *ctx = cls;
313
314 timeout_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
315 &timeout_cb,
316 ctx);
280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
281 "Timeout\n"); 318 "Timeout\n");
282 GNUNET_SCHEDULER_shutdown (); 319 GNUNET_SCHEDULER_shutdown ();
@@ -314,6 +351,13 @@ dht_get_handler (void *cls,
314 struct GNUNET_HashCode want; 351 struct GNUNET_HashCode want;
315 struct GNUNET_DHT_TEST_Context *ctx; 352 struct GNUNET_DHT_TEST_Context *ctx;
316 353
354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
355 "Handling reply with GPL: %u PPL: %u!\n",
356 get_path_len,
357 put_path_len);
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
359 "GET HANDLER called on PID %s\n",
360 GNUNET_i2s (&get_op->me));
317 if (sizeof(struct GNUNET_HashCode) != size) 361 if (sizeof(struct GNUNET_HashCode) != size)
318 { 362 {
319 GNUNET_break (0); 363 GNUNET_break (0);
@@ -329,26 +373,26 @@ dht_get_handler (void *cls,
329 GNUNET_break (0); 373 GNUNET_break (0);
330 return; 374 return;
331 } 375 }
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 376 if (0 !=
333 "Get successful\n"); 377 GNUNET_DHT_verify_path (key,
334#if 0 378 data,
379 size,
380 exp,
381 get_path,
382 get_path_length,
383 put_path,
384 put_path_length,
385 &get_op->me))
386 {
387 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
388 "Path signature verification failed!\n");
389 }
390 else
335 { 391 {
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
337 "PATH: (get %u, put %u)\n", 393 "Get successful\n");
338 get_path_length, 394 ok--;
339 put_path_length);
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 " LOCAL\n");
342 for (int i = get_path_length - 1; i >= 0; i--)
343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
344 " %s\n",
345 GNUNET_i2s (&get_path[i]));
346 for (int i = put_path_length - 1; i >= 0; i--)
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
348 " %s\n",
349 GNUNET_i2s (&put_path[i]));
350 } 395 }
351#endif
352 GNUNET_DHT_get_stop (get_op->get); 396 GNUNET_DHT_get_stop (get_op->get);
353 GNUNET_CONTAINER_DLL_remove (get_head, 397 GNUNET_CONTAINER_DLL_remove (get_head,
354 get_tail, 398 get_tail,
@@ -359,7 +403,6 @@ dht_get_handler (void *cls,
359 /* all DHT GET operations successful; get stats! */ 403 /* all DHT GET operations successful; get stats! */
360 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 404 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
361 "All DHT operations successful. Obtaining stats!\n"); 405 "All DHT operations successful. Obtaining stats!\n");
362 ok = 0;
363 ctx = stop_ops (); 406 ctx = stop_ops ();
364 GNUNET_assert (NULL != ctx); 407 GNUNET_assert (NULL != ctx);
365 (void) GNUNET_TESTBED_get_statistics (NUM_PEERS, 408 (void) GNUNET_TESTBED_get_statistics (NUM_PEERS,
@@ -386,7 +429,8 @@ do_puts (void *cls)
386 429
387 put_task = NULL; 430 put_task = NULL;
388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
389 "Putting values into DHT\n"); 432 "Putting %u values into DHT\n",
433 NUM_PEERS);
390 for (unsigned int i = 0; i < NUM_PEERS; i++) 434 for (unsigned int i = 0; i < NUM_PEERS; i++)
391 { 435 {
392 GNUNET_CRYPTO_hash (&i, 436 GNUNET_CRYPTO_hash (&i,
@@ -414,37 +458,86 @@ do_puts (void *cls)
414 458
415 459
416/** 460/**
461 * Callback to be called when the requested peer information is available
462 * The peer information in the callback is valid until the operation 'op' is canceled.
463 *
464 * @param cls a `struct GetOperation *`
465 * @param op the operation this callback corresponds to
466 * @param pinfo the result; will be NULL if the operation has failed
467 * @param emsg error message if the operation has failed; will be NULL if the
468 * operation is successful
469 */
470static void
471pid_cb (void *cls,
472 struct GNUNET_TESTBED_Operation *op,
473 const struct GNUNET_TESTBED_PeerInformation *pinfo,
474 const char *emsg)
475{
476 struct GetOperation *get_op = cls;
477
478 if (NULL != emsg)
479 {
480 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
481 "Testbed failure: %s\n",
482 emsg);
483 GNUNET_TESTBED_operation_done (get_op->to);
484 get_op->to = NULL;
485 GNUNET_SCHEDULER_shutdown ();
486 return;
487 }
488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
489 "Testbed provided PID %s\n",
490 GNUNET_i2s (pinfo->result.id));
491 get_op->me = *pinfo->result.id;
492 GNUNET_TESTBED_operation_done (get_op->to);
493 get_op->to = NULL;
494 get_op->get = GNUNET_DHT_get_start (get_op->dht,
495 GNUNET_BLOCK_TYPE_TEST,
496 &get_op->key,
497 4U, /* replication level */
498 GNUNET_DHT_RO_RECORD_ROUTE
499 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
500 NULL, /* xquery */
501 0, /* xquery bits */
502 &dht_get_handler,
503 get_op);
504}
505
506
507/**
417 * Start GET operations. 508 * Start GET operations.
418 */ 509 */
419static void 510static void
420start_get (void *cls) 511start_get (void *cls)
421{ 512{
422 struct GNUNET_DHT_Handle **dhts = cls; 513 struct GNUNET_DHT_Handle **dhts = cls;
423 unsigned int i;
424 unsigned int j;
425 struct GNUNET_HashCode key;
426 struct GetOperation *get_op;
427 514
428 get_task = NULL; 515 get_task = NULL;
429 for (i = 0; i < NUM_PEERS; i++) 516 for (unsigned int i = 0; i < NUM_PEERS; i++)
430 { 517 {
431 GNUNET_CRYPTO_hash (&i, sizeof(i), &key); 518 struct GNUNET_HashCode key;
432 for (j = 0; j < NUM_PEERS; j++) 519
520 GNUNET_CRYPTO_hash (&i,
521 sizeof(i),
522 &key);
523 for (unsigned int j = 0; j < NUM_PEERS; j++)
433 { 524 {
525 struct GetOperation *get_op;
526
434 get_op = GNUNET_new (struct GetOperation); 527 get_op = GNUNET_new (struct GetOperation);
528 ok++;
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
530 "Starting GET %p\n",
531 get_op);
532 get_op->key = key;
533 get_op->dht = dhts[j];
534 get_op->to = GNUNET_TESTBED_peer_get_information (my_peers[j],
535 GNUNET_TESTBED_PIT_IDENTITY,
536 &pid_cb,
537 get_op);
435 GNUNET_CONTAINER_DLL_insert (get_head, 538 GNUNET_CONTAINER_DLL_insert (get_head,
436 get_tail, 539 get_tail,
437 get_op); 540 get_op);
438 get_op->get = GNUNET_DHT_get_start (dhts[j],
439 GNUNET_BLOCK_TYPE_TEST, /* type */
440 &key, /*key to search */
441 4U, /* replication level */
442 GNUNET_DHT_RO_RECORD_ROUTE
443 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
444 NULL, /* xquery */
445 0, /* xquery bits */
446 &dht_get_handler,
447 get_op);
448 } 541 }
449 } 542 }
450} 543}
@@ -492,6 +585,9 @@ main (int xargc, char *xargv[])
492 const char *cfg_filename; 585 const char *cfg_filename;
493 const char *test_name; 586 const char *test_name;
494 587
588 unsetenv ("XDG_DATA_HOME");
589 unsetenv ("XDG_CONFIG_HOME");
590 unsetenv ("XDG_CACHE_HOME");
495 if (NULL != strstr (xargv[0], "test_dht_2dtorus")) 591 if (NULL != strstr (xargv[0], "test_dht_2dtorus"))
496 { 592 {
497 cfg_filename = "test_dht_2dtorus.conf"; 593 cfg_filename = "test_dht_2dtorus.conf";