aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_twopeer_put_get.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/test_dht_twopeer_put_get.c')
-rw-r--r--src/dht/test_dht_twopeer_put_get.c419
1 files changed, 218 insertions, 201 deletions
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c
index 40a165236..9db0ca385 100644
--- a/src/dht/test_dht_twopeer_put_get.c
+++ b/src/dht/test_dht_twopeer_put_get.c
@@ -137,14 +137,14 @@ static struct GNUNET_DHT_Handle *peer2dht;
137/** 137/**
138 * Check whether peers successfully shut down. 138 * Check whether peers successfully shut down.
139 */ 139 */
140void shutdown_callback (void *cls, 140void
141 const char *emsg) 141shutdown_callback (void *cls, const char *emsg)
142{ 142{
143 if (emsg != NULL) 143 if (emsg != NULL)
144 { 144 {
145 if (ok == 0) 145 if (ok == 0)
146 ok = 2; 146 ok = 2;
147 } 147 }
148} 148}
149 149
150/** 150/**
@@ -152,13 +152,13 @@ void shutdown_callback (void *cls,
152 * testcase. Specifically, called when our get request completes. 152 * testcase. Specifically, called when our get request completes.
153 */ 153 */
154static void 154static void
155finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 155finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156{ 156{
157 GNUNET_assert (pg != NULL); 157 GNUNET_assert (pg != NULL);
158 GNUNET_assert (peer1dht != NULL); 158 GNUNET_assert (peer1dht != NULL);
159 GNUNET_assert (peer2dht != NULL); 159 GNUNET_assert (peer2dht != NULL);
160 GNUNET_DHT_disconnect(peer1dht); 160 GNUNET_DHT_disconnect (peer1dht);
161 GNUNET_DHT_disconnect(peer2dht); 161 GNUNET_DHT_disconnect (peer2dht);
162 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 162 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
163 ok = 0; 163 ok = 0;
164} 164}
@@ -168,13 +168,13 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
168 * down the peers without freeing memory associated with GET request. 168 * down the peers without freeing memory associated with GET request.
169 */ 169 */
170static void 170static void
171end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 171end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
172{ 172{
173 if (peer1dht != NULL) 173 if (peer1dht != NULL)
174 GNUNET_DHT_disconnect(peer1dht); 174 GNUNET_DHT_disconnect (peer1dht);
175 175
176 if (peer2dht != NULL) 176 if (peer2dht != NULL)
177 GNUNET_DHT_disconnect(peer2dht); 177 GNUNET_DHT_disconnect (peer2dht);
178 178
179 if (pg != NULL) 179 if (pg != NULL)
180 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 180 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
@@ -186,15 +186,16 @@ end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
186 * test. 186 * test.
187 */ 187 */
188static void 188static void
189end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 189end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
190{ 190{
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n", (char *)cls); 191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failing test with error: `%s'!\n",
192 (char *) cls);
192 if (global_get_handle != NULL) 193 if (global_get_handle != NULL)
193 { 194 {
194 GNUNET_DHT_get_stop(global_get_handle); 195 GNUNET_DHT_get_stop (global_get_handle);
195 global_get_handle = NULL; 196 global_get_handle = NULL;
196 } 197 }
197 GNUNET_SCHEDULER_add_now(&end_badly_cont, NULL); 198 GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
198 ok = 1; 199 ok = 1;
199} 200}
200 201
@@ -208,40 +209,47 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
208 * @param size number of bytes in data 209 * @param size number of bytes in data
209 * @param data pointer to the result data 210 * @param data pointer to the result data
210 */ 211 */
211void get_result_iterator (void *cls, 212void
212 struct GNUNET_TIME_Absolute exp, 213get_result_iterator (void *cls,
213 const GNUNET_HashCode * key, 214 struct GNUNET_TIME_Absolute exp,
214 const struct GNUNET_PeerIdentity * const *get_path, 215 const GNUNET_HashCode * key,
215 const struct GNUNET_PeerIdentity * const *put_path, 216 const struct GNUNET_PeerIdentity *const *get_path,
216 enum GNUNET_BLOCK_Type type, 217 const struct GNUNET_PeerIdentity *const *put_path,
217 size_t size, 218 enum GNUNET_BLOCK_Type type,
218 const void *result_data) 219 size_t size, const void *result_data)
219{ 220{
220 GNUNET_HashCode original_key; /* Key data was stored data under */ 221 GNUNET_HashCode original_key; /* Key data was stored data under */
221 char original_data[4]; /* Made up data that was stored */ 222 char original_data[4]; /* Made up data that was stored */
222 memset(&original_key, 42, sizeof(GNUNET_HashCode)); /* Set the key to what it was set to previously */ 223
223 memset(original_data, 43, sizeof(original_data)); 224 memset (&original_key, 42, sizeof (GNUNET_HashCode)); /* Set the key to what it was set to previously */
225 memset (original_data, 43, sizeof (original_data));
224 226
225#if DNS 227#if DNS
226 if ((0 != memcmp(&data.service_descriptor, key, sizeof (GNUNET_HashCode))) || (0 != memcmp((char *)&data, result_data, sizeof(original_data)))) 228 if ((0 != memcmp (&data.service_descriptor, key, sizeof (GNUNET_HashCode))) ||
227 { 229 (0 != memcmp ((char *) &data, result_data, sizeof (original_data))))
228 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Key or data is not the same as was inserted!\n"); 230 {
229 GNUNET_SCHEDULER_cancel(die_task); 231 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
230 GNUNET_SCHEDULER_add_now(&end_badly, "key or data mismatch in get response!\n"); 232 "Key or data is not the same as was inserted!\n");
231 return; 233 GNUNET_SCHEDULER_cancel (die_task);
232 } 234 GNUNET_SCHEDULER_add_now (&end_badly,
235 "key or data mismatch in get response!\n");
236 return;
237 }
233#else 238#else
234 if ((0 != memcmp(&original_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, result_data, sizeof(original_data)))) 239 if ((0 != memcmp (&original_key, key, sizeof (GNUNET_HashCode))) ||
240 (0 != memcmp (original_data, result_data, sizeof (original_data))))
235 { 241 {
236 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Key or data is not the same as was inserted!\n"); 242 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
237 GNUNET_SCHEDULER_cancel(die_task); 243 "Key or data is not the same as was inserted!\n");
238 GNUNET_SCHEDULER_add_now(&end_badly, "key or data mismatch in get response!\n"); 244 GNUNET_SCHEDULER_cancel (die_task);
245 GNUNET_SCHEDULER_add_now (&end_badly,
246 "key or data mismatch in get response!\n");
239 return; 247 return;
240 } 248 }
241#endif 249#endif
242 250
243 GNUNET_SCHEDULER_cancel(die_task); 251 GNUNET_SCHEDULER_cancel (die_task);
244 GNUNET_DHT_get_stop(global_get_handle); 252 GNUNET_DHT_get_stop (global_get_handle);
245 GNUNET_SCHEDULER_add_now (&finish_testing, NULL); 253 GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
246} 254}
247 255
@@ -249,26 +257,26 @@ void get_result_iterator (void *cls,
249 * Start the GET request for the same key/data that was inserted. 257 * Start the GET request for the same key/data that was inserted.
250 */ 258 */
251static void 259static void
252do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 260do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
253{ 261{
254 GNUNET_HashCode key; /* Key for data lookup */ 262 GNUNET_HashCode key; /* Key for data lookup */
263
255#if DNS 264#if DNS
256 memcpy(&key, &data.service_descriptor, sizeof(GNUNET_HashCode)); 265 memcpy (&key, &data.service_descriptor, sizeof (GNUNET_HashCode));
257#else 266#else
258 memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ 267 memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */
259#endif 268#endif
260 global_get_handle = GNUNET_DHT_get_start(peer2dht, GNUNET_TIME_relative_get_forever(), 269 global_get_handle =
270 GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (),
261#if DNS 271#if DNS
262 GNUNET_BLOCK_TYPE_DNS, 272 GNUNET_BLOCK_TYPE_DNS,
263#else 273#else
264 GNUNET_BLOCK_TYPE_TEST, 274 GNUNET_BLOCK_TYPE_TEST,
265#endif 275#endif
266 &key, 276 &key,
267 DEFAULT_GET_REPLICATION, 277 DEFAULT_GET_REPLICATION,
268 GNUNET_DHT_RO_NONE, 278 GNUNET_DHT_RO_NONE,
269 NULL, 0, 279 NULL, 0, NULL, 0, &get_result_iterator, NULL);
270 NULL, 0,
271 &get_result_iterator, NULL);
272} 280}
273 281
274/** 282/**
@@ -276,12 +284,14 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
276 * Schedule the GET request for some time in the future. 284 * Schedule the GET request for some time in the future.
277 */ 285 */
278static void 286static void
279put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 287put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
280{ 288{
281 GNUNET_SCHEDULER_cancel (die_task); 289 GNUNET_SCHEDULER_cancel (die_task);
282 die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, 290 die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
283 &end_badly, "waiting for get response (data not found)"); 291 &end_badly,
284 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL); 292 "waiting for get response (data not found)");
293 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
294 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL);
285} 295}
286 296
287 297
@@ -290,23 +300,23 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
290 * Set up some data, and call API PUT function 300 * Set up some data, and call API PUT function
291 */ 301 */
292static void 302static void
293do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 303do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
294{ 304{
295 GNUNET_HashCode key; /* Made up key to store data under */ 305 GNUNET_HashCode key; /* Made up key to store data under */
296 char data[4]; /* Made up data to store */ 306 char data[4]; /* Made up data to store */
297 memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to something simple so we can issue GET request */ 307
298 memset(data, 43, sizeof(data)); 308 memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to something simple so we can issue GET request */
309 memset (data, 43, sizeof (data));
299 310
300 /* Insert the data at the first peer */ 311 /* Insert the data at the first peer */
301 GNUNET_DHT_put(peer1dht, 312 GNUNET_DHT_put (peer1dht,
302 &key, 313 &key,
303 DEFAULT_PUT_REPLICATION, 314 DEFAULT_PUT_REPLICATION,
304 GNUNET_DHT_RO_NONE, 315 GNUNET_DHT_RO_NONE,
305 GNUNET_BLOCK_TYPE_TEST, 316 GNUNET_BLOCK_TYPE_TEST,
306 sizeof(data), data, 317 sizeof (data), data,
307 GNUNET_TIME_UNIT_FOREVER_ABS, 318 GNUNET_TIME_UNIT_FOREVER_ABS,
308 GNUNET_TIME_UNIT_FOREVER_REL, 319 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
309 &put_finished, NULL);
310} 320}
311#else 321#else
312 322
@@ -314,55 +324,56 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
314 * Set up some data, and call API PUT function 324 * Set up some data, and call API PUT function
315 */ 325 */
316static void 326static void
317do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 327do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
318{ 328{
319 char* name = "philipptoelke.gnunet."; 329 char *name = "philipptoelke.gnunet.";
320 size_t size = sizeof(struct GNUNET_DNS_Record); 330 size_t size = sizeof (struct GNUNET_DNS_Record);
321 memset(&data, 0, size); 331
332 memset (&data, 0, size);
322 333
323 data.purpose.size = htonl(size - sizeof(struct GNUNET_CRYPTO_RsaSignature)); 334 data.purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
324 data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD; 335 data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD;
325 336
326 GNUNET_CRYPTO_hash(name, strlen(name)+1, &data.service_descriptor); 337 GNUNET_CRYPTO_hash (name, strlen (name) + 1, &data.service_descriptor);
338
339 data.service_type = htonl (GNUNET_DNS_SERVICE_TYPE_UDP);
340 data.ports = htons (69);
327 341
328 data.service_type = htonl(GNUNET_DNS_SERVICE_TYPE_UDP); 342 char *keyfile;
329 data.ports = htons(69);
330 343
331 char* keyfile; 344 GNUNET_asprintf (&keyfile, "/tmp/test_dns_data_key");
332 GNUNET_asprintf(&keyfile, "/tmp/test_dns_data_key"); 345 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key =
333 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file(keyfile); 346 GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
334 GNUNET_free(keyfile); 347 GNUNET_free (keyfile);
335 GNUNET_assert(my_private_key != NULL); 348 GNUNET_assert (my_private_key != NULL);
336 349
337 GNUNET_CRYPTO_rsa_key_get_public(my_private_key, &data.peer); 350 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer);
338 351
339 data.expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS); 352 data.expiration_time =
353 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
340 354
341 /* Sign the block */ 355 /* Sign the block */
342 if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign(my_private_key, 356 if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key,
343 &data.purpose, 357 &data.purpose, &data.signature))
344 &data.signature)) 358 {
345 { 359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
346 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n"); 360 return;
347 return; 361 }
348 } 362 GNUNET_CRYPTO_rsa_key_free (my_private_key);
349 GNUNET_CRYPTO_rsa_key_free(my_private_key); 363
350 364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 365 "Putting with key %08x\n",
352 "Putting with key %08x\n", 366 *((unsigned int *) &data.service_descriptor));
353 *((unsigned int*)&data.service_descriptor)); 367
354 368 GNUNET_DHT_put (peer1dht,
355 GNUNET_DHT_put(peer1dht, 369 &data.service_descriptor,
356 &data.service_descriptor, 370 DEFAULT_PUT_REPLICATION,
357 DEFAULT_PUT_REPLICATION, 371 GNUNET_DHT_RO_NONE,
358 GNUNET_DHT_RO_NONE, 372 GNUNET_BLOCK_TYPE_DNS,
359 GNUNET_BLOCK_TYPE_DNS, 373 size,
360 size, 374 (char *) &data,
361 (char*)&data, 375 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
362 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS), 376 GNUNET_TIME_UNIT_MINUTES, &put_finished, NULL);
363 GNUNET_TIME_UNIT_MINUTES,
364 &put_finished,
365 NULL);
366} 377}
367#endif 378#endif
368 379
@@ -387,43 +398,45 @@ topology_callback (void *cls,
387 const char *emsg) 398 const char *emsg)
388{ 399{
389 if (emsg == NULL) 400 if (emsg == NULL)
390 { 401 {
391 total_connections++; 402 total_connections++;
392#if VERBOSE 403#if VERBOSE
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n", 404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 first_daemon->shortname, 405 "connected peer %s to peer %s, distance %u\n",
395 second_daemon->shortname, 406 first_daemon->shortname, second_daemon->shortname, distance);
396 distance);
397#endif 407#endif
398 } 408 }
399#if VERBOSE 409#if VERBOSE
400 else 410 else
401 { 411 {
402 failed_connections++; 412 failed_connections++;
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n", 413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 first_daemon->shortname, 414 "Failed to connect peer %s to peer %s with error :\n%s\n",
405 second_daemon->shortname, emsg); 415 first_daemon->shortname, second_daemon->shortname, emsg);
406 } 416 }
407#endif 417#endif
408 418
409 if (total_connections == expected_connections) 419 if (total_connections == expected_connections)
410 { 420 {
411#if VERBOSE 421#if VERBOSE
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
413 "Created %d total connections, which is our target number! Starting next phase of testing.\n", 423 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
414 total_connections); 424 total_connections);
415#endif 425#endif
416 GNUNET_SCHEDULER_cancel (die_task); 426 GNUNET_SCHEDULER_cancel (die_task);
417 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 427 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
418 &end_badly, "from test gets"); 428 &end_badly, "from test gets");
419 429
420 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL); 430 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
421 } 431 (GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL);
432 }
422 else if (total_connections + failed_connections == expected_connections) 433 else if (total_connections + failed_connections == expected_connections)
423 { 434 {
424 GNUNET_SCHEDULER_cancel (die_task); 435 GNUNET_SCHEDULER_cancel (die_task);
425 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)"); 436 die_task =
426 } 437 GNUNET_SCHEDULER_add_now (&end_badly,
438 "from topology_callback (too many failed connections)");
439 }
427} 440}
428 441
429 442
@@ -440,73 +453,74 @@ topology_callback (void *cls,
440 */ 453 */
441static void 454static void
442peers_started_callback (void *cls, 455peers_started_callback (void *cls,
443 const struct GNUNET_PeerIdentity *id, 456 const struct GNUNET_PeerIdentity *id,
444 const struct GNUNET_CONFIGURATION_Handle *cfg, 457 const struct GNUNET_CONFIGURATION_Handle *cfg,
445 struct GNUNET_TESTING_Daemon *d, const char *emsg) 458 struct GNUNET_TESTING_Daemon *d, const char *emsg)
446{ 459{
447 if (emsg != NULL) 460 if (emsg != NULL)
448 { 461 {
449 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to start daemon with error: `%s'\n", 462 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
450 emsg); 463 "Failed to start daemon with error: `%s'\n", emsg);
451 return; 464 return;
452 } 465 }
453 GNUNET_assert (id != NULL); 466 GNUNET_assert (id != NULL);
454 467
455 /* This is the first peer started */ 468 /* This is the first peer started */
456 if (peers_left == num_peers) 469 if (peers_left == num_peers)
457 { 470 {
458 memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity)); /* Save the peer id */ 471 memcpy (&peer1id, id, sizeof (struct GNUNET_PeerIdentity)); /* Save the peer id */
459 peer1dht = GNUNET_DHT_connect(cfg, 100); /* Connect to the first peers DHT service */ 472 peer1dht = GNUNET_DHT_connect (cfg, 100); /* Connect to the first peers DHT service */
460 if (peer1dht == NULL) /* If DHT connect failed */ 473 if (peer1dht == NULL) /* If DHT connect failed */
461 { 474 {
462 GNUNET_SCHEDULER_cancel (die_task); 475 GNUNET_SCHEDULER_cancel (die_task);
463 GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); 476 GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
464 } 477 }
465 } 478 }
466 else /* This is the second peer started */ 479 else /* This is the second peer started */
467 { 480 {
468 memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity)); /* Same as for first peer... */ 481 memcpy (&peer2id, id, sizeof (struct GNUNET_PeerIdentity)); /* Same as for first peer... */
469 peer2dht = GNUNET_DHT_connect(cfg, 100); 482 peer2dht = GNUNET_DHT_connect (cfg, 100);
470 if (peer2dht == NULL) 483 if (peer2dht == NULL)
471 { 484 {
472 GNUNET_SCHEDULER_cancel (die_task); 485 GNUNET_SCHEDULER_cancel (die_task);
473 GNUNET_SCHEDULER_add_now(&end_badly, "Failed to get dht handle!\n"); 486 GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
474 } 487 }
475 } 488 }
476 489
477 /* Decrement number of peers left to start */ 490 /* Decrement number of peers left to start */
478 peers_left--; 491 peers_left--;
479 492
480 if (peers_left == 0) /* Indicates all peers started */ 493 if (peers_left == 0) /* Indicates all peers started */
481 { 494 {
482#if VERBOSE 495#if VERBOSE
483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
484 "All %d daemons started, now connecting peers!\n", 497 "All %d daemons started, now connecting peers!\n", num_peers);
485 num_peers);
486#endif 498#endif
487 expected_connections = -1; 499 expected_connections = -1;
488 if ((pg != NULL)) /* Sanity check */ 500 if ((pg != NULL)) /* Sanity check */
489 { 501 {
490 /* Connect peers in a "straight line" topology, return the number of expected connections */ 502 /* Connect peers in a "straight line" topology, return the number of expected connections */
491 expected_connections = GNUNET_TESTING_connect_topology (pg, 503 expected_connections = GNUNET_TESTING_connect_topology (pg,
492 GNUNET_TESTING_TOPOLOGY_LINE, 504 GNUNET_TESTING_TOPOLOGY_LINE,
493 GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 505 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
494 0.0, 506 0.0,
495 TIMEOUT, 507 TIMEOUT,
496 12, 508 12, NULL, NULL);
497 NULL, NULL);
498 }
499
500 /* Cancel current timeout fail task */
501 GNUNET_SCHEDULER_cancel (die_task);
502 if (expected_connections == GNUNET_SYSERR) /* Some error happened */
503 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)");
504
505 /* Schedule timeout on failure task */
506 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
507 &end_badly, "from connect topology (timeout)");
508 ok = 0;
509 } 509 }
510
511 /* Cancel current timeout fail task */
512 GNUNET_SCHEDULER_cancel (die_task);
513 if (expected_connections == GNUNET_SYSERR) /* Some error happened */
514 die_task =
515 GNUNET_SCHEDULER_add_now (&end_badly,
516 "from connect topology (bad return)");
517
518 /* Schedule timeout on failure task */
519 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
520 &end_badly,
521 "from connect topology (timeout)");
522 ok = 0;
523 }
510} 524}
511 525
512static void 526static void
@@ -516,11 +530,13 @@ run (void *cls,
516{ 530{
517 531
518 /* Get path from configuration file */ 532 /* Get path from configuration file */
519 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) 533 if (GNUNET_YES !=
520 { 534 GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
521 ok = 404; 535 &test_directory))
522 return; 536 {
523 } 537 ok = 404;
538 return;
539 }
524 540
525 /* Get number of peers to start from configuration (should be two) */ 541 /* Get number of peers to start from configuration (should be two) */
526 if (GNUNET_SYSERR == 542 if (GNUNET_SYSERR ==
@@ -533,7 +549,8 @@ run (void *cls,
533 549
534 /* Set up a task to end testing if peer start fails */ 550 /* Set up a task to end testing if peer start fails */
535 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 551 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
536 &end_badly, "didn't start all daemons in reasonable amount of time!!!"); 552 &end_badly,
553 "didn't start all daemons in reasonable amount of time!!!");
537 554
538 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */ 555 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */
539 /* Read the API documentation for other parameters! */ 556 /* Read the API documentation for other parameters! */
@@ -545,10 +562,7 @@ run (void *cls,
545 NULL, 562 NULL,
546 NULL, 563 NULL,
547 &peers_started_callback, 564 &peers_started_callback,
548 NULL, 565 NULL, &topology_callback, NULL, NULL);
549 &topology_callback,
550 NULL,
551 NULL);
552 566
553} 567}
554 568
@@ -556,10 +570,11 @@ static int
556check () 570check ()
557{ 571{
558 int ret; 572 int ret;
573
559 /* Arguments for GNUNET_PROGRAM_run */ 574 /* Arguments for GNUNET_PROGRAM_run */
560 char *const argv[] = {"test-dht-twopeer-put-get", /* Name to give running binary */ 575 char *const argv[] = { "test-dht-twopeer-put-get", /* Name to give running binary */
561 "-c", 576 "-c",
562 "test_dht_twopeer_data.conf", /* Config file to use */ 577 "test_dht_twopeer_data.conf", /* Config file to use */
563#if VERBOSE 578#if VERBOSE
564 "-L", "DEBUG", 579 "-L", "DEBUG",
565#endif 580#endif
@@ -570,12 +585,13 @@ check ()
570 }; 585 };
571 /* Run the run function as a new program */ 586 /* Run the run function as a new program */
572 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 587 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
573 argv, "test-dht-twopeer-put-get", "nohelp", 588 argv, "test-dht-twopeer-put-get", "nohelp",
574 options, &run, &ok); 589 options, &run, &ok);
575 if (ret != GNUNET_OK) 590 if (ret != GNUNET_OK)
576 { 591 {
577 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-twopeer': Failed with error code %d\n", ret); 592 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
578 } 593 "`test-dht-twopeer': Failed with error code %d\n", ret);
594 }
579 return ok; 595 return ok;
580} 596}
581 597
@@ -597,9 +613,10 @@ main (int argc, char *argv[])
597 * of by the testing framework. 613 * of by the testing framework.
598 */ 614 */
599 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK) 615 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
600 { 616 {
601 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory); 617 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
602 } 618 "Failed to remove testing directory %s\n", test_directory);
619 }
603 return ret; 620 return ret;
604} 621}
605 622