diff options
author | Bart Polot <bart@net.in.tum.de> | 2016-11-04 09:47:25 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2016-11-04 09:47:25 +0000 |
commit | 3341cc2ec22d6c67c6f6a2e07f08875230fb4724 (patch) | |
tree | f28fdb53a203ad05f8edd9fdb3dbfb5c5926c637 /src | |
parent | ed37f9ea1b7c49822ab5b806e0de7d62a820df94 (diff) | |
download | gnunet-3341cc2ec22d6c67c6f6a2e07f08875230fb4724.tar.gz gnunet-3341cc2ec22d6c67c6f6a2e07f08875230fb4724.zip |
- refactor connection upkeep code, remove unneeded functions
Diffstat (limited to 'src')
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 98 |
1 files changed, 25 insertions, 73 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 9d7b8dd1d..dc4239eab 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -517,25 +517,13 @@ mark_destroyed (struct CadetConnection *c) | |||
517 | 517 | ||
518 | 518 | ||
519 | /** | 519 | /** |
520 | * Callback called when a queued ACK message is sent. | 520 | * Function called if a connection has been stalled for a while, |
521 | * possibly due to a missed ACK. Poll the neighbor about its ACK status. | ||
521 | * | 522 | * |
522 | * @param cls Closure (FC). | 523 | * @param cls Closure (poll ctx). |
523 | * @param c Connection this message was on. | ||
524 | * @param q Queue handler this call invalidates. | ||
525 | * @param type Type of message sent. | ||
526 | * @param fwd Was this a FWD going message? | ||
527 | * @param size Size of the message. | ||
528 | */ | 524 | */ |
529 | static void | 525 | static void |
530 | ack_sent (void *cls, | 526 | send_poll (void *cls); |
531 | struct CadetConnection *c, | ||
532 | struct CadetConnectionQueue *q, | ||
533 | uint16_t type, int fwd, size_t size) | ||
534 | { | ||
535 | struct CadetFlowControl *fc = cls; | ||
536 | |||
537 | fc->ack_msg = NULL; | ||
538 | } | ||
539 | 527 | ||
540 | 528 | ||
541 | /** | 529 | /** |
@@ -621,7 +609,7 @@ send_ack (struct CadetConnection *c, unsigned int buffer, int fwd, int force) | |||
621 | 609 | ||
622 | prev_fc->ack_msg = GCC_send_prebuilt_message (&msg.header, UINT16_MAX, ack, | 610 | prev_fc->ack_msg = GCC_send_prebuilt_message (&msg.header, UINT16_MAX, ack, |
623 | c, !fwd, GNUNET_YES, | 611 | c, !fwd, GNUNET_YES, |
624 | &ack_sent, prev_fc); | 612 | NULL, NULL); |
625 | GNUNET_assert (NULL != prev_fc->ack_msg); | 613 | GNUNET_assert (NULL != prev_fc->ack_msg); |
626 | GCC_check_connections (); | 614 | GCC_check_connections (); |
627 | } | 615 | } |
@@ -797,6 +785,23 @@ conn_message_sent (void *cls, | |||
797 | 785 | ||
798 | case GNUNET_MESSAGE_TYPE_CADET_POLL: | 786 | case GNUNET_MESSAGE_TYPE_CADET_POLL: |
799 | fc->poll_msg = NULL; | 787 | fc->poll_msg = NULL; |
788 | if (2 == c->destroy) | ||
789 | { | ||
790 | LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL canceled on shutdown\n"); | ||
791 | return; | ||
792 | } | ||
793 | if (0 == fc->queue_max) | ||
794 | { | ||
795 | LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL cancelled: neighbor disconnected\n"); | ||
796 | return; | ||
797 | } | ||
798 | LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL sent for %s, scheduling new one!\n", | ||
799 | GCC_2s (c)); | ||
800 | GNUNET_assert (NULL == fc->poll_task); | ||
801 | fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time); | ||
802 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, | ||
803 | &send_poll, fc); | ||
804 | LOG (GNUNET_ERROR_TYPE_DEBUG, " task %u\n", fc->poll_task); | ||
800 | break; | 805 | break; |
801 | 806 | ||
802 | case GNUNET_MESSAGE_TYPE_CADET_ACK: | 807 | case GNUNET_MESSAGE_TYPE_CADET_ACK: |
@@ -1406,58 +1411,7 @@ connection_cancel_queues (struct CadetConnection *c, | |||
1406 | * @param cls Closure (poll ctx). | 1411 | * @param cls Closure (poll ctx). |
1407 | */ | 1412 | */ |
1408 | static void | 1413 | static void |
1409 | send_connection_poll (void *cls); | 1414 | send_poll (void *cls) |
1410 | |||
1411 | |||
1412 | /** | ||
1413 | * Callback called when a queued POLL message is sent. | ||
1414 | * | ||
1415 | * @param cls Closure (flow control context). | ||
1416 | * @param c Connection this message was on. | ||
1417 | * @param q Queue handler this call invalidates. | ||
1418 | * @param type Type of message sent. | ||
1419 | * @param fwd Was this a FWD going message? | ||
1420 | * @param size Size of the message. | ||
1421 | */ | ||
1422 | static void | ||
1423 | poll_sent (void *cls, | ||
1424 | struct CadetConnection *c, | ||
1425 | struct CadetConnectionQueue *q, | ||
1426 | uint16_t type, int fwd, size_t size) | ||
1427 | { | ||
1428 | struct CadetFlowControl *fc = cls; | ||
1429 | |||
1430 | GNUNET_assert (fc->poll_msg == q); | ||
1431 | fc->poll_msg = NULL; | ||
1432 | if (2 == c->destroy) | ||
1433 | { | ||
1434 | LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL canceled on shutdown\n"); | ||
1435 | return; | ||
1436 | } | ||
1437 | if (0 == fc->queue_max) | ||
1438 | { | ||
1439 | LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL cancelled: neighbor disconnected\n"); | ||
1440 | return; | ||
1441 | } | ||
1442 | LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL sent for %s, scheduling new one!\n", | ||
1443 | GCC_2s (c)); | ||
1444 | GNUNET_assert (NULL == fc->poll_task); | ||
1445 | fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time); | ||
1446 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, | ||
1447 | &send_connection_poll, | ||
1448 | fc); | ||
1449 | LOG (GNUNET_ERROR_TYPE_DEBUG, " task %u\n", fc->poll_task); | ||
1450 | } | ||
1451 | |||
1452 | |||
1453 | /** | ||
1454 | * Function called if a connection has been stalled for a while, | ||
1455 | * possibly due to a missed ACK. Poll the neighbor about its ACK status. | ||
1456 | * | ||
1457 | * @param cls Closure (poll ctx). | ||
1458 | */ | ||
1459 | static void | ||
1460 | send_connection_poll (void *cls) | ||
1461 | { | 1415 | { |
1462 | struct CadetFlowControl *fc = cls; | 1416 | struct CadetFlowControl *fc = cls; |
1463 | struct GNUNET_CADET_Poll msg; | 1417 | struct GNUNET_CADET_Poll msg; |
@@ -1478,7 +1432,7 @@ send_connection_poll (void *cls) | |||
1478 | LOG (GNUNET_ERROR_TYPE_DEBUG, " last pid sent: %u\n", fc->last_pid_sent); | 1432 | LOG (GNUNET_ERROR_TYPE_DEBUG, " last pid sent: %u\n", fc->last_pid_sent); |
1479 | fc->poll_msg = | 1433 | fc->poll_msg = |
1480 | GCC_send_prebuilt_message (&msg.header, UINT16_MAX, fc->last_pid_sent, c, | 1434 | GCC_send_prebuilt_message (&msg.header, UINT16_MAX, fc->last_pid_sent, c, |
1481 | fc == &c->fwd_fc, GNUNET_YES, &poll_sent, fc); | 1435 | fc == &c->fwd_fc, GNUNET_YES, NULL, NULL); |
1482 | GNUNET_assert (NULL != fc->poll_msg); | 1436 | GNUNET_assert (NULL != fc->poll_msg); |
1483 | GCC_check_connections (); | 1437 | GCC_check_connections (); |
1484 | } | 1438 | } |
@@ -3540,9 +3494,7 @@ GCC_start_poll (struct CadetConnection *c, int fwd) | |||
3540 | return; | 3494 | return; |
3541 | } | 3495 | } |
3542 | LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL started on request\n"); | 3496 | LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL started on request\n"); |
3543 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, | 3497 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, &send_poll, fc); |
3544 | &send_connection_poll, | ||
3545 | fc); | ||
3546 | } | 3498 | } |
3547 | 3499 | ||
3548 | 3500 | ||