diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-22 22:22:07 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-22 22:22:07 +0000 |
commit | 9eb79c486b5e793d4a93e822c695b88b67981466 (patch) | |
tree | e439150ce46e5f9277e06d54a7b80a34a319b6bb /src/ats/ats_api_scheduling.c | |
parent | bfc6d94bd600d3048c155dc2a48c2e1faee484d0 (diff) | |
download | gnunet-9eb79c486b5e793d4a93e822c695b88b67981466.tar.gz gnunet-9eb79c486b5e793d4a93e822c695b88b67981466.zip |
finish ATS reconnect logic to retransmit state on reconnect
Diffstat (limited to 'src/ats/ats_api_scheduling.c')
-rw-r--r-- | src/ats/ats_api_scheduling.c | 86 |
1 files changed, 67 insertions, 19 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index 13b5ef46d..9e65c3fb0 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c | |||
@@ -579,6 +579,54 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, | |||
579 | 579 | ||
580 | 580 | ||
581 | /** | 581 | /** |
582 | * Transmit request for an address suggestion. | ||
583 | * | ||
584 | * @param cls the `struct GNUNET_ATS_SchedulingHandle` | ||
585 | * @param peer peer to ask for an address suggestion for | ||
586 | * @param value the `struct GNUNET_ATS_SuggestHandle` | ||
587 | * @return #GNUNET_OK (continue to iterate) | ||
588 | */ | ||
589 | static int | ||
590 | transmit_suggestion (void *cls, | ||
591 | const struct GNUNET_PeerIdentity *peer, | ||
592 | void *value) | ||
593 | { | ||
594 | struct GNUNET_ATS_SchedulingHandle *sh = cls; | ||
595 | struct GNUNET_MQ_Envelope *ev; | ||
596 | struct RequestAddressMessage *m; | ||
597 | |||
598 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); | ||
599 | m->reserved = htonl (0); | ||
600 | m->peer = *peer; | ||
601 | GNUNET_MQ_send (sh->mq, ev); | ||
602 | return GNUNET_OK; | ||
603 | } | ||
604 | |||
605 | |||
606 | /** | ||
607 | * Generate and transmit the `struct AddressUseMessage` for the given | ||
608 | * address record. | ||
609 | * | ||
610 | * @param ar the address to inform the ATS service about | ||
611 | * @param in_use say if it is in use or not | ||
612 | */ | ||
613 | static void | ||
614 | send_in_use_message (struct GNUNET_ATS_AddressRecord *ar, | ||
615 | int in_use) | ||
616 | { | ||
617 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; | ||
618 | struct GNUNET_MQ_Envelope *ev; | ||
619 | struct AddressUseMessage *m; | ||
620 | |||
621 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); | ||
622 | m->peer = ar->address->peer; | ||
623 | m->in_use = htonl ((uint32_t) in_use); | ||
624 | m->session_id = htonl (ar->slot); | ||
625 | GNUNET_MQ_send (sh->mq, ev); | ||
626 | } | ||
627 | |||
628 | |||
629 | /** | ||
582 | * Re-establish the connection to the ATS service. | 630 | * Re-establish the connection to the ATS service. |
583 | * | 631 | * |
584 | * @param sh handle to use to re-connect. | 632 | * @param sh handle to use to re-connect. |
@@ -596,6 +644,8 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | |||
596 | { NULL, 0, 0 } }; | 644 | { NULL, 0, 0 } }; |
597 | struct GNUNET_MQ_Envelope *ev; | 645 | struct GNUNET_MQ_Envelope *ev; |
598 | struct ClientStartMessage *init; | 646 | struct ClientStartMessage *init; |
647 | unsigned int i; | ||
648 | struct GNUNET_ATS_AddressRecord *ar; | ||
599 | 649 | ||
600 | GNUNET_assert (NULL == sh->client); | 650 | GNUNET_assert (NULL == sh->client); |
601 | sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg); | 651 | sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg); |
@@ -612,8 +662,18 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | |||
612 | GNUNET_MESSAGE_TYPE_ATS_START); | 662 | GNUNET_MESSAGE_TYPE_ATS_START); |
613 | init->start_flag = htonl (START_FLAG_SCHEDULING); | 663 | init->start_flag = htonl (START_FLAG_SCHEDULING); |
614 | GNUNET_MQ_send (sh->mq, ev); | 664 | GNUNET_MQ_send (sh->mq, ev); |
615 | // FIXME: iterate over addresses... | 665 | for (i=0;i<sh->session_array_size;i++) |
616 | // FIXME: iterate over peermap for address suggestion requests! | 666 | { |
667 | ar = sh->session_array[i]; | ||
668 | if (NULL == ar) | ||
669 | continue; | ||
670 | send_add_address_message (sh, ar); | ||
671 | if (ar->in_use) | ||
672 | send_in_use_message (ar, GNUNET_YES); | ||
673 | } | ||
674 | GNUNET_CONTAINER_multipeermap_iterate (sh->sug_requests, | ||
675 | &transmit_suggestion, | ||
676 | sh); | ||
617 | } | 677 | } |
618 | 678 | ||
619 | 679 | ||
@@ -991,7 +1051,6 @@ free_sug_handle (void *cls, | |||
991 | } | 1051 | } |
992 | 1052 | ||
993 | 1053 | ||
994 | |||
995 | /** | 1054 | /** |
996 | * Client is done with ATS scheduling, release resources. | 1055 | * Client is done with ATS scheduling, release resources. |
997 | * | 1056 | * |
@@ -1067,8 +1126,6 @@ struct GNUNET_ATS_SuggestHandle * | |||
1067 | GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, | 1126 | GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, |
1068 | const struct GNUNET_PeerIdentity *peer) | 1127 | const struct GNUNET_PeerIdentity *peer) |
1069 | { | 1128 | { |
1070 | struct GNUNET_MQ_Envelope *ev; | ||
1071 | struct RequestAddressMessage *m; | ||
1072 | struct GNUNET_ATS_SuggestHandle *s; | 1129 | struct GNUNET_ATS_SuggestHandle *s; |
1073 | 1130 | ||
1074 | s = GNUNET_new (struct GNUNET_ATS_SuggestHandle); | 1131 | s = GNUNET_new (struct GNUNET_ATS_SuggestHandle); |
@@ -1084,10 +1141,9 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1084 | } | 1141 | } |
1085 | if (NULL == sh->mq) | 1142 | if (NULL == sh->mq) |
1086 | return s; | 1143 | return s; |
1087 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); | 1144 | (void) transmit_suggestion (sh, |
1088 | m->reserved = htonl (0); | 1145 | &s->id, |
1089 | m->peer = *peer; | 1146 | s); |
1090 | GNUNET_MQ_send (sh->mq, ev); | ||
1091 | return s; | 1147 | return s; |
1092 | } | 1148 | } |
1093 | 1149 | ||
@@ -1330,22 +1386,14 @@ void | |||
1330 | GNUNET_ATS_address_set_in_use (struct GNUNET_ATS_AddressRecord *ar, | 1386 | GNUNET_ATS_address_set_in_use (struct GNUNET_ATS_AddressRecord *ar, |
1331 | int in_use) | 1387 | int in_use) |
1332 | { | 1388 | { |
1333 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; | ||
1334 | struct GNUNET_MQ_Envelope *ev; | ||
1335 | struct AddressUseMessage *m; | ||
1336 | |||
1337 | ar->in_use = in_use; | ||
1338 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); | ||
1339 | m->peer = ar->address->peer; | ||
1340 | m->in_use = htonl ((uint32_t) in_use); | ||
1341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1389 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1342 | "Setting address used to %s for peer `%s', plugin `%s', session %p\n", | 1390 | "Setting address used to %s for peer `%s', plugin `%s', session %p\n", |
1343 | (GNUNET_YES == in_use) ? "YES" : "NO", | 1391 | (GNUNET_YES == in_use) ? "YES" : "NO", |
1344 | GNUNET_i2s (&ar->address->peer), | 1392 | GNUNET_i2s (&ar->address->peer), |
1345 | ar->address->transport_name, | 1393 | ar->address->transport_name, |
1346 | ar->session); | 1394 | ar->session); |
1347 | m->session_id = htonl (ar->slot); | 1395 | ar->in_use = in_use; |
1348 | GNUNET_MQ_send (sh->mq, ev); | 1396 | send_in_use_message (ar, in_use); |
1349 | } | 1397 | } |
1350 | 1398 | ||
1351 | 1399 | ||