From b35fa325e2e5dad6c83af8252e06561d60ef7147 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 18 Oct 2011 15:20:50 +0000 Subject: [PATCH] send session release messages back to ATS API --- src/ats/ats.h | 14 +++++++ src/ats/ats_api_scheduling.c | 53 +++++++++++++++++++++++++ src/ats/gnunet-service-ats_scheduling.c | 12 ++++++ src/include/gnunet_protocols.h | 6 +++ 4 files changed, 85 insertions(+) diff --git a/src/ats/ats.h b/src/ats/ats.h index fbc6ca712..a39b16942 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h @@ -169,6 +169,20 @@ struct ReservationRequestMessage }; +/** + * Message sent by ATS service to client to confirm that it is done + * using the given session ID. + */ +struct SessionReleaseMessage +{ + struct GNUNET_MessageHeader header; + + uint32_t session_id GNUNET_PACKED; + + struct GNUNET_PeerIdentity peer; +}; + + struct ReservationResultMessage { struct GNUNET_MessageHeader header; diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index b61d320a7..94c798b53 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c @@ -71,6 +71,11 @@ struct SessionRecord * Session handle. */ struct Session *session; + + /** + * Set to GNUNET_YES if the slot is used. + */ + int slot_used; }; @@ -321,6 +326,7 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, GNUNET_assert (f > 0); sh->session_array[f].session = session; sh->session_array[f].peer = *peer; + sh->session_array[f].slot_used = GNUNET_YES; return f; } @@ -343,6 +349,43 @@ remove_session (struct GNUNET_ATS_SchedulingHandle *sh, &sh->session_array[session_id].peer, sizeof (struct GNUNET_PeerIdentity))); sh->session_array[session_id].session = NULL; + memset (&sh->session_array[session_id].peer, + 0, + sizeof (struct GNUNET_PeerIdentity)); +} + + +/** + * Release the session slot from the session table (ATS service is + * also done using it). + * + * @param sh our handle + * @param session_id identifies session that is no longer valid + * @param peer peer the session belongs to + */ +static void +release_session (struct GNUNET_ATS_SchedulingHandle *sh, + uint32_t session_id, + const struct GNUNET_PeerIdentity *peer) +{ + GNUNET_assert (session_id < sh->session_array_size); + GNUNET_assert (0 == memcmp (peer, + &sh->session_array[session_id].peer, + sizeof (struct GNUNET_PeerIdentity))); + sh->session_array[session_id].slot_used = GNUNET_NO; + memset (&sh->session_array[session_id].peer, + 0, + sizeof (struct GNUNET_PeerIdentity)); +} + + +static void +process_release_message (struct GNUNET_ATS_SchedulingHandle *sh, + const struct SessionReleaseMessage *srm) +{ + release_session (sh, + ntohl (srm->session_id), + &srm->peer); } @@ -374,6 +417,16 @@ process_ats_message (void *cls, &reconnect_task, sh); return; } + if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) && + (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)) ) + { + process_release_message (sh, + (const struct SessionReleaseMessage*) msg); + GNUNET_CLIENT_receive (sh->client, + &process_ats_message, sh, + GNUNET_TIME_UNIT_FOREVER_REL); + return; + } if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) || (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) ) { diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index 6f3fa990e..242076568 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c @@ -234,6 +234,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, { const struct AddressDestroyedMessage * m; + struct SessionReleaseMessage srm; const char *address; const char *plugin_name; uint16_t address_length; @@ -280,6 +281,17 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, address, address_length, ntohl (m->session_id)); + if (0 != ntohl (m->session_id)) + { + srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); + srm.header.size = ntohs (sizeof (struct SessionReleaseMessage)); + srm.session_id = m->session_id; + srm.peer = m->peer; + GNUNET_SERVER_notification_context_unicast (nc, + client, + &srm.header, + GNUNET_NO); + } GNUNET_SERVER_receive_done (client, GNUNET_OK); } diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index ce14a9f20..d61192710 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -1044,6 +1044,12 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE 348 +/** + * Type of the 'struct SessionReleaseMessage' sent by ATS to client + * to confirm that a session ID was destroyed. + */ +#define GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE 349 + /******************************************************************************* * TODO: we need a way to register message types centrally (via some webpage). -- 2.25.1