send session release messages back to ATS API
authorChristian Grothoff <christian@grothoff.org>
Tue, 18 Oct 2011 15:20:50 +0000 (15:20 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 18 Oct 2011 15:20:50 +0000 (15:20 +0000)
src/ats/ats.h
src/ats/ats_api_scheduling.c
src/ats/gnunet-service-ats_scheduling.c
src/include/gnunet_protocols.h

index fbc6ca7120a145ebda5bfffc7806f20f493116c6..a39b16942df48beb13d4c16f1d94f12ad9c9e2e0 100644 (file)
@@ -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;
index b61d320a7ab868e8518e061c861a72e282df9e1e..94c798b5357d23fafedd808bc69cdad2a13acfac 100644 (file)
@@ -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)) )
   {
index 6f3fa990e35a38218b40dbefb001b00cc7132298..242076568f3c3359701eaf76e28765c0bbecc628 100644 (file)
@@ -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);
 }
 
index ce14a9f205fce33613adb6f0873246bc404f8465..d611927107d965dd83af04e46f93e475f9e8e621 100644 (file)
@@ -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).