diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-16 11:51:02 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-16 11:51:02 +0000 |
commit | 985c18baa426b7383faaba20651d793553f9a0cb (patch) | |
tree | 2a73f0ce7ed0a72f2da5759f20dd7c4a5438b002 /src/testbed | |
parent | f736b24935d66733e9a53798fbc87dbc8aff9fca (diff) | |
download | gnunet-985c18baa426b7383faaba20651d793553f9a0cb.tar.gz gnunet-985c18baa426b7383faaba20651d793553f9a0cb.zip |
extended rocc
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 167 |
1 files changed, 156 insertions, 11 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index bd163f1dd..0b4fd12f3 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -61,6 +61,12 @@ | |||
61 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) | 61 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * Timeout of Transport try_connect requests | ||
65 | */ | ||
66 | #define TRANSPORT_TRY_CONNECT_TIMEOUT \ | ||
67 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100) | ||
68 | |||
69 | /** | ||
64 | * The main context information associated with the client which started us | 70 | * The main context information associated with the client which started us |
65 | */ | 71 | */ |
66 | struct Context | 72 | struct Context |
@@ -413,6 +419,42 @@ struct OverlayConnectContext | |||
413 | 419 | ||
414 | 420 | ||
415 | /** | 421 | /** |
422 | * Context information for RequestOverlayConnect | ||
423 | * operations. RequestOverlayConnect is used when peers A, B reside on different | ||
424 | * hosts and the host controller for peer B is asked by the host controller of | ||
425 | * peer A to make peer B connect to peer A | ||
426 | */ | ||
427 | struct RequestOverlayConnectContext | ||
428 | { | ||
429 | /** | ||
430 | * The transport handle of peer B | ||
431 | */ | ||
432 | struct GNUNET_TRANSPORT_Handle *th; | ||
433 | |||
434 | /** | ||
435 | * Peer A's HELLO | ||
436 | */ | ||
437 | struct GNUNET_MessageHeader *hello; | ||
438 | |||
439 | /** | ||
440 | * The peer identity of peer A | ||
441 | */ | ||
442 | struct GNUNET_PeerIdentity a_id; | ||
443 | |||
444 | /** | ||
445 | * Task for offering HELLO of A to B and doing try_connect | ||
446 | */ | ||
447 | GNUNET_SCHEDULER_TaskIdentifier attempt_connect_task_id; | ||
448 | |||
449 | /** | ||
450 | * Task to timeout RequestOverlayConnect | ||
451 | */ | ||
452 | GNUNET_SCHEDULER_TaskIdentifier timeout_rocc_task_id; | ||
453 | |||
454 | }; | ||
455 | |||
456 | |||
457 | /** | ||
416 | * Context information for operations forwarded to subcontrollers | 458 | * Context information for operations forwarded to subcontrollers |
417 | */ | 459 | */ |
418 | struct ForwardedOperationContext | 460 | struct ForwardedOperationContext |
@@ -2109,7 +2151,8 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2109 | } | 2151 | } |
2110 | GNUNET_free (other_peer_str); | 2152 | GNUNET_free (other_peer_str); |
2111 | occ->send_hello_task = | 2153 | occ->send_hello_task = |
2112 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &send_hello, occ); | 2154 | GNUNET_SCHEDULER_add_delayed (TRANSPORT_TRY_CONNECT_TIMEOUT, |
2155 | &send_hello, occ); | ||
2113 | } | 2156 | } |
2114 | 2157 | ||
2115 | /** | 2158 | /** |
@@ -2351,6 +2394,89 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
2351 | 2394 | ||
2352 | 2395 | ||
2353 | /** | 2396 | /** |
2397 | * Function to cleanup RequestOverlayConnectContext and any associated tasks | ||
2398 | * with it | ||
2399 | * | ||
2400 | * @param | ||
2401 | * @return | ||
2402 | */ | ||
2403 | static void | ||
2404 | cleanup_rocc (struct RequestOverlayConnectContext *rocc) | ||
2405 | { | ||
2406 | if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id) | ||
2407 | GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id); | ||
2408 | if (GNUNET_SCHEDULER_NO_TASK != rocc->timeout_rocc_task_id) | ||
2409 | GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id); | ||
2410 | GNUNET_TRANSPORT_disconnect (rocc->th); | ||
2411 | GNUNET_free_non_null (rocc->hello); | ||
2412 | GNUNET_free (rocc); | ||
2413 | } | ||
2414 | |||
2415 | |||
2416 | /** | ||
2417 | * Task to timeout rocc and cleanit up | ||
2418 | * | ||
2419 | * @param cls the RequestOverlayConnectContext | ||
2420 | * @param tc the TaskContext from scheduler | ||
2421 | */ | ||
2422 | static void | ||
2423 | timeout_rocc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2424 | { | ||
2425 | struct RequestOverlayConnectContext *rocc = cls; | ||
2426 | |||
2427 | rocc->timeout_rocc_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
2428 | cleanup_rocc (rocc); | ||
2429 | } | ||
2430 | |||
2431 | |||
2432 | /** | ||
2433 | * Function called to notify transport users that another | ||
2434 | * peer connected to us. | ||
2435 | * | ||
2436 | * @param cls closure | ||
2437 | * @param peer the peer that connected | ||
2438 | * @param ats performance data | ||
2439 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
2440 | */ | ||
2441 | static void | ||
2442 | transport_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer, | ||
2443 | const struct GNUNET_ATS_Information * ats, | ||
2444 | uint32_t ats_count) | ||
2445 | { | ||
2446 | struct RequestOverlayConnectContext *rocc = cls; | ||
2447 | |||
2448 | LOG_DEBUG ("Request Overlay connect notify\n"); | ||
2449 | if (0 != memcmp (new_peer, &rocc->a_id, sizeof (struct GNUNET_PeerIdentity))) | ||
2450 | { | ||
2451 | return; | ||
2452 | } | ||
2453 | LOG_DEBUG ("Peer %4s connected\n", GNUNET_i2s (&rocc->a_id)); | ||
2454 | cleanup_rocc (rocc); | ||
2455 | } | ||
2456 | |||
2457 | |||
2458 | /** | ||
2459 | * Task to offer the HELLO message to the peer and ask it to connect to the peer | ||
2460 | * whose identity is in RequestOverlayConnectContext | ||
2461 | * | ||
2462 | * @param cls the RequestOverlayConnectContext | ||
2463 | * @param tc the TaskContext from scheduler | ||
2464 | */ | ||
2465 | static void | ||
2466 | attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2467 | { | ||
2468 | struct RequestOverlayConnectContext *rocc = cls; | ||
2469 | |||
2470 | rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
2471 | GNUNET_TRANSPORT_offer_hello (rocc->th, rocc->hello, NULL, NULL); | ||
2472 | GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id); | ||
2473 | rocc->attempt_connect_task_id = | ||
2474 | GNUNET_SCHEDULER_add_delayed (TRANSPORT_TRY_CONNECT_TIMEOUT, | ||
2475 | &attempt_connect_task, rocc); | ||
2476 | } | ||
2477 | |||
2478 | |||
2479 | /** | ||
2354 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages | 2480 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages |
2355 | * | 2481 | * |
2356 | * @param cls NULL | 2482 | * @param cls NULL |
@@ -2362,17 +2488,19 @@ handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
2362 | const struct GNUNET_MessageHeader *message) | 2488 | const struct GNUNET_MessageHeader *message) |
2363 | { | 2489 | { |
2364 | const struct GNUNET_TESTBED_RequestConnectMessage *msg; | 2490 | const struct GNUNET_TESTBED_RequestConnectMessage *msg; |
2365 | struct GNUNET_TRANSPORT_Handle *th; | 2491 | struct RequestOverlayConnectContext *rocc; |
2366 | struct Peer *peer; | 2492 | struct Peer *peer; |
2367 | uint32_t peer_id; | 2493 | uint32_t peer_id; |
2494 | uint16_t msize; | ||
2495 | uint16_t hsize; | ||
2368 | 2496 | ||
2369 | if (sizeof (struct GNUNET_TESTBED_RequestConnectMessage) >= ntohs | 2497 | msize = ntohs (message->size); |
2370 | (message->size)) | 2498 | if (sizeof (struct GNUNET_TESTBED_RequestConnectMessage) >= msize) |
2371 | { | 2499 | { |
2372 | GNUNET_break (0); | 2500 | GNUNET_break (0); |
2373 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2501 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2374 | return; | 2502 | return; |
2375 | } | 2503 | } |
2376 | msg = (const struct GNUNET_TESTBED_RequestConnectMessage *) message; | 2504 | msg = (const struct GNUNET_TESTBED_RequestConnectMessage *) message; |
2377 | if ((NULL == msg->hello) || | 2505 | if ((NULL == msg->hello) || |
2378 | (GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type))) | 2506 | (GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type))) |
@@ -2381,10 +2509,17 @@ handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
2381 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2509 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2382 | return; | 2510 | return; |
2383 | } | 2511 | } |
2512 | hsize = ntohs (msg->hello->size); | ||
2513 | if ((sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hsize) != msize) | ||
2514 | { | ||
2515 | GNUNET_break (0); | ||
2516 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
2517 | return; | ||
2518 | } | ||
2384 | peer_id = ntohl (msg->peer); | 2519 | peer_id = ntohl (msg->peer); |
2385 | if ((peer_id >= peer_list_size) || (NULL == (peer = peer_list[peer_id]))) | 2520 | if ((peer_id >= peer_list_size) || (NULL == (peer = peer_list[peer_id]))) |
2386 | { | 2521 | { |
2387 | GNUNET_break (0); | 2522 | GNUNET_break_op (0); |
2388 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2523 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2389 | return; | 2524 | return; |
2390 | } | 2525 | } |
@@ -2394,16 +2529,26 @@ handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
2394 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2529 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2395 | return; | 2530 | return; |
2396 | } | 2531 | } |
2397 | th = GNUNET_TRANSPORT_connect (peer->details.local.cfg, NULL, NULL, NULL, | 2532 | rocc = GNUNET_malloc (sizeof (struct RequestOverlayConnectContext)); |
2398 | NULL, NULL); | 2533 | rocc->th = GNUNET_TRANSPORT_connect (peer->details.local.cfg, NULL, rocc, |
2399 | if (NULL == th) | 2534 | NULL, &transport_connect_notify, NULL); |
2535 | if (NULL == rocc->th) | ||
2400 | { | 2536 | { |
2401 | GNUNET_break (0); | 2537 | GNUNET_break (0); |
2538 | GNUNET_free (rocc); | ||
2402 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2539 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2403 | return; | 2540 | return; |
2404 | } | 2541 | } |
2405 | GNUNET_TRANSPORT_offer_hello (th, msg->hello, NULL, NULL); | 2542 | memcpy (&rocc->a_id, &msg->peer_identity, |
2406 | GNUNET_TRANSPORT_try_connect (th, &msg->peer_identity); | 2543 | sizeof (struct GNUNET_PeerIdentity)); |
2544 | rocc->hello = GNUNET_malloc (hsize); | ||
2545 | memcpy (rocc->hello, msg->hello, hsize); | ||
2546 | /* GNUNET_TRANSPORT_offer_hello (th, msg->hello, NULL, NULL); */ | ||
2547 | /* GNUNET_TRANSPORT_try_connect (th, &msg->peer_identity); */ | ||
2548 | rocc->attempt_connect_task_id = | ||
2549 | GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc); | ||
2550 | rocc->timeout_rocc_task_id = | ||
2551 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc); | ||
2407 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2552 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2408 | } | 2553 | } |
2409 | 2554 | ||