gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r34961 - gnunet/src/ats


From: gnunet
Subject: [GNUnet-SVN] r34961 - gnunet/src/ats
Date: Thu, 22 Jan 2015 22:25:54 +0100

Author: grothoff
Date: 2015-01-22 22:25:54 +0100 (Thu, 22 Jan 2015)
New Revision: 34961

Modified:
   gnunet/src/ats/ats.h
   gnunet/src/ats/ats_api_scheduling.c
   gnunet/src/ats/gnunet-service-ats.c
   gnunet/src/ats/gnunet-service-ats_addresses.c
   gnunet/src/ats/gnunet-service-ats_addresses.h
   gnunet/src/ats/gnunet-service-ats_scheduling.c
Log:
simplifying IPC for address in use and address update

Modified: gnunet/src/ats/ats.h
===================================================================
--- gnunet/src/ats/ats.h        2015-01-22 21:08:43 UTC (rev 34960)
+++ gnunet/src/ats/ats.h        2015-01-22 21:25:54 UTC (rev 34961)
@@ -86,7 +86,7 @@
   struct GNUNET_MessageHeader header;
 
   /**
-   * Size of the `struct GNUNET_ATS_Information` array that follows this 
struct.
+   * Length of the `struct GNUNET_ATS_Information` array that follows this 
struct.
    */
   uint32_t ats_count GNUNET_PACKED;
 
@@ -126,51 +126,68 @@
 };
 
 
+/**
+ * Message used to notify ATS that the performance
+ * characteristics for an address have changed.
+ */
 struct AddressUpdateMessage
 {
+  /**
+   * Message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE.
+   */
   struct GNUNET_MessageHeader header;
 
+  /**
+   * Length of the `struct GNUNET_ATS_Information` array that follows.
+   */
   uint32_t ats_count GNUNET_PACKED;
 
+  /**
+   * Which peer is this about? (Technically redundant, as the
+   * @e session_id should be sufficient, but enables ATS service
+   * to find the session faster).
+   */
   struct GNUNET_PeerIdentity peer;
 
-
-  uint16_t address_length GNUNET_PACKED;
-
-  uint16_t plugin_name_length GNUNET_PACKED;
-
+  /**
+   * Internal number this client uses to refer to this address.
+   */
   uint32_t session_id GNUNET_PACKED;
 
-  uint32_t address_local_info GNUNET_PACKED;
-
   /* followed by:
    * - struct GNUNET_ATS_Information [ats_count];
-   * - char address[address_length]
-   * - char plugin_name[plugin_name_length] (including '\0'-termination).
    */
 
 };
 
+
+/**
+ * Message sent from ATS client to ATS service to notify
+ * it if we started (or stopped) using an address.
+ */
 struct AddressUseMessage
 {
+  /**
+   * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE.
+   */
   struct GNUNET_MessageHeader header;
 
-  struct GNUNET_PeerIdentity peer;
-
-  uint16_t in_use GNUNET_PACKED;
-
-  uint16_t address_length GNUNET_PACKED;
-
-  uint16_t plugin_name_length GNUNET_PACKED;
-
+  /**
+   * Internal number this client uses to refer to this address.
+   */
   uint32_t session_id GNUNET_PACKED;
 
-  uint32_t address_local_info GNUNET_PACKED;
+  /**
+   * Which peer is this about? (Technically redundant, as the
+   * @e session_id should be sufficient, but enables ATS service
+   * to find the session faster).
+   */
+  struct GNUNET_PeerIdentity peer;
 
-  /* followed by:
-   * - char address[address_length]
-   * - char plugin_name[plugin_name_length] (including '\0'-termination).
+  /**
+   * #GNUNET_YES or #GNUNET_NO.
    */
+  uint32_t in_use GNUNET_PACKED;
 
 };
 

Modified: gnunet/src/ats/ats_api_scheduling.c
===================================================================
--- gnunet/src/ats/ats_api_scheduling.c 2015-01-22 21:08:43 UTC (rev 34960)
+++ gnunet/src/ats/ats_api_scheduling.c 2015-01-22 21:25:54 UTC (rev 34961)
@@ -1319,8 +1319,6 @@
   struct GNUNET_MQ_Envelope *ev;
   struct AddressUpdateMessage *m;
   struct GNUNET_ATS_Information *am;
-  char *pm;
-  size_t namelen;
   size_t msize;
 
   GNUNET_array_grow (ar->ats,
@@ -1333,18 +1331,11 @@
 
   if (NULL == sh->mq)
     return; /* disconnected, skip for now */
-  namelen = (NULL == ar->address->transport_name)
-    ? 0
-    : strlen (ar->address->transport_name) + 1;
-  msize = ar->address->address_length +
-    ar->ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
+  msize = ar->ats_count * sizeof (struct GNUNET_ATS_Information);
 
   ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
   m->ats_count = htonl (ar->ats_count);
   m->peer = ar->address->peer;
-  m->address_length = htons (ar->address->address_length);
-  m->address_local_info = htonl ((uint32_t) ar->address->local_info);
-  m->plugin_name_length = htons (namelen);
   m->session_id = htonl (ar->slot);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1357,14 +1348,6 @@
   memcpy (am,
           ar->ats,
           ar->ats_count * sizeof (struct GNUNET_ATS_Information));
-  pm = (char *) &am[ar->ats_count];
-  memcpy (pm,
-          ar->address->address,
-          ar->address->address_length);
-  if (NULL != ar->address->transport_name)
-    memcpy (&pm[ar->address->address_length],
-            ar->address->transport_name,
-            namelen);
   GNUNET_MQ_send (sh->mq, ev);
 }
 
@@ -1383,36 +1366,18 @@
   struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
   struct GNUNET_MQ_Envelope *ev;
   struct AddressUseMessage *m;
-  char *pm;
-  size_t namelen;
-  size_t msize;
 
   ar->in_use = in_use;
-  namelen = (NULL == ar->address->transport_name)
-    ? 0
-    : strlen (ar->address->transport_name) + 1;
-  msize = ar->address->address_length + namelen;
-
-  ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE);
+  ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE);
   m->peer = ar->address->peer;
-  m->in_use = htons (in_use);
-  m->address_length = htons (ar->address->address_length);
-  m->address_local_info = htonl ((uint32_t) ar->address->local_info);
-  m->plugin_name_length = htons (namelen);
-
+  m->in_use = htonl ((uint32_t) in_use);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Setting address used to %s for peer `%s', plugin `%s', session 
%p\n",
               (GNUNET_YES == in_use) ? "YES" : "NO",
               GNUNET_i2s (&ar->address->peer),
               ar->address->transport_name,
               ar->session);
-
   m->session_id = htonl (ar->slot);
-  pm = (char *) &m[1];
-  /* FIXME: no need to send the address data */
-  memcpy (pm, ar->address->address, ar->address->address_length);
-  memcpy (&pm[ar->address->address_length],
-          ar->address->transport_name, namelen);
   GNUNET_MQ_send (sh->mq, ev);
 }
 

Modified: gnunet/src/ats/gnunet-service-ats.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats.c 2015-01-22 21:08:43 UTC (rev 34960)
+++ gnunet/src/ats/gnunet-service-ats.c 2015-01-22 21:25:54 UTC (rev 34961)
@@ -165,7 +165,8 @@
     {&GAS_handle_address_update, NULL,
      GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0},
     {&GAS_handle_address_in_use, NULL,
-     GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0},
+     GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE,
+     sizeof (struct AddressUseMessage) },
     {&GAS_handle_address_destroyed, NULL,
      GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0},
     {&GAS_handle_reservation_request, NULL,

Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2015-01-22 21:08:43 UTC 
(rev 34960)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2015-01-22 21:25:54 UTC 
(rev 34961)
@@ -468,9 +468,9 @@
 static void
 free_address (struct ATS_Address *addr)
 {
-  GNUNET_free(addr->plugin);
-  GNUNET_free_non_null(addr->atsi);
-  GNUNET_free(addr);
+  GNUNET_free (addr->plugin);
+  GNUNET_free_non_null (addr->atsi);
+  GNUNET_free (addr);
 }
 
 
@@ -642,44 +642,69 @@
 
 
 /**
+ * Closure for #find_address_cb()
+ */
+struct FindAddressContext
+{
+  /**
+   * Session Id to look for.
+   */
+  uint32_t session_id;
+
+  /**
+   * Where to store matching address result.
+   */
+  struct ATS_Address *exact_address;
+
+};
+
+
+/**
+ * Find session matching given session ID.
+ *
+ * @param cls a `struct FindAddressContext`
+ * @param key peer id
+ * @param value the address to compare with
+ * @return #GNUNET_YES to continue, #GNUNET_NO if address is found
+ */
+static int
+find_address_cb (void *cls,
+                 const struct GNUNET_PeerIdentity *key,
+                 void *value)
+{
+  struct FindAddressContext *fac = cls;
+  struct ATS_Address *aa = value;
+
+  if (aa->session_id == fac->session_id)
+  {
+    fac->exact_address = aa;
+    return GNUNET_NO;
+  }
+  return GNUNET_YES;
+}
+
+
+/**
  * Find the exact address
  *
  * @param handle the address handle to use
  * @param peer peer
- * @param plugin_name transport plugin name
- * @param plugin_addr plugin address
- * @param plugin_addr_len length of the plugin address
- * @param local_address_info the local address for the address
  * @param session_id session id, can never be 0
  * @return an ATS_address or NULL
  */
 static struct ATS_Address *
 find_exact_address (struct GAS_Addresses_Handle *handle,
                     const struct GNUNET_PeerIdentity *peer,
-                    const char *plugin_name,
-                    const void *plugin_addr,
-                    size_t plugin_addr_len,
-                    uint32_t local_address_info,
                     uint32_t session_id)
 {
-  struct ATS_Address *aa;
-  struct ATS_Address *ea;
+  struct FindAddressContext fac;
 
-  aa = create_address (peer,
-                       plugin_name,
-                       plugin_addr,
-                       plugin_addr_len,
-                       local_address_info,
-                       session_id);
-
-  /* Get existing address or address with session == 0 */
-  ea = find_equivalent_address (handle, peer, aa);
-  free_address (aa);
-  if (ea == NULL)
-    return NULL;
-  else if (ea->session_id != session_id)
-    return NULL;
-  return ea;
+  fac.exact_address = NULL;
+  fac.session_id = session_id;
+  GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses,
+                                             peer,
+                                             &find_address_cb, &fac);
+  return fac.exact_address;
 }
 
 
@@ -918,28 +943,17 @@
 
 
 /**
- * Update an address with a session or performance information for a peer.
+ * Update an address with new performance information for a peer.
  *
- * If an address was added without a session it will be updated with the
- * session
- *
  * @param handle the address handle to use
  * @param peer peer
- * @param plugin_name transport plugin name
- * @param plugin_addr plugin address
- * @param plugin_addr_len length of the plugin address
- * @param local_address_info the local address for the address
- * @param session_id session id, can be 0
+ * @param session_id session id, never 0
  * @param atsi performance information for this address
  * @param atsi_count number of performance information contained in @a atsi
  */
 void
 GAS_addresses_update (struct GAS_Addresses_Handle *handle,
                       const struct GNUNET_PeerIdentity *peer,
-                      const char *plugin_name,
-                      const void *plugin_addr,
-                      size_t plugin_addr_len,
-                      uint32_t local_address_info,
                       uint32_t session_id,
                       const struct GNUNET_ATS_Information *atsi,
                       uint32_t atsi_count)
@@ -955,11 +969,10 @@
   GNUNET_assert (NULL != handle->addresses);
 
   /* Get existing address */
-  aa = find_exact_address (handle, peer, plugin_name, plugin_addr,
-                           plugin_addr_len,
-                           local_address_info,
+  aa = find_exact_address (handle,
+                           peer,
                            session_id);
-  if (aa == NULL)
+  if (NULL == aa)
   {
     GNUNET_break (0);
     return;
@@ -1129,10 +1142,6 @@
   /* Get existing address */
   ea = find_exact_address (handle,
                            peer,
-                           plugin_name,
-                           plugin_addr,
-                           plugin_addr_len,
-                           local_address_info,
                            session_id);
   if (NULL == ea)
   {
@@ -1182,10 +1191,6 @@
  *
  * @param handle the address handle to use
  * @param peer peer
- * @param plugin_name transport plugin name
- * @param plugin_addr plugin address
- * @param plugin_addr_len length of the plugin address
- * @param local_address_info the local address for the address
  * @param session_id session id, can be 0
  * @param in_use #GNUNET_YES if #GNUNET_NO FIXME
  * @return #GNUNET_SYSERR on failure (address unknown ...)
@@ -1193,10 +1198,6 @@
 int
 GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
                       const struct GNUNET_PeerIdentity *peer,
-                      const char *plugin_name,
-                      const void *plugin_addr,
-                      size_t plugin_addr_len,
-                      uint32_t local_address_info,
                       uint32_t session_id,
                       int in_use)
 {
@@ -1209,17 +1210,13 @@
   if (GNUNET_NO == handle->running)
     return GNUNET_SYSERR;
   ea = find_exact_address (handle,
-                           peer, plugin_name,
-                           plugin_addr,
-                           plugin_addr_len,
-                           local_address_info,
+                           peer,
                            session_id);
   if (NULL == ea)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Trying to set unknown address `%s' `%s' `%u' to %s \n",
+                "Trying to set unknown address `%s' `%u' to %s \n",
                 GNUNET_i2s (peer),
-                plugin_name,
                 session_id,
                 (GNUNET_NO == in_use) ? "NO" : "YES");
     GNUNET_break (0);

Modified: gnunet/src/ats/gnunet-service-ats_addresses.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.h       2015-01-22 21:08:43 UTC 
(rev 34960)
+++ gnunet/src/ats/gnunet-service-ats_addresses.h       2015-01-22 21:25:54 UTC 
(rev 34961)
@@ -473,10 +473,6 @@
  *
  * @param handle the address handle to use
  * @param peer peer
- * @param plugin_name transport plugin name
- * @param plugin_addr plugin address
- * @param plugin_addr_len length of the plugin address in @a plugin_addr
- * @param local_address_info the local address for the address
  * @param session_id session id, can never be 0
  * @param in_use #GNUNET_YES if #GNUNET_NO FIXME
  * @return #GNUNET_SYSERR on failure (address unknown ...)
@@ -484,26 +480,15 @@
 int
 GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
                       const struct GNUNET_PeerIdentity *peer,
-                      const char *plugin_name,
-                      const void *plugin_addr,
-                      size_t plugin_addr_len,
-                      uint32_t local_address_info,
                       uint32_t session_id,
                       int in_use);
 
 
 /**
- * Update an address with a session or performance information for a peer.
+ * Update an address with new performance information for a peer.
  *
- * If an address was added without a session it will be updated with the
- * session
- *
  * @param handle the address handle to use
  * @param peer peer
- * @param plugin_name transport plugin name
- * @param plugin_addr plugin address
- * @param plugin_addr_len length of the plugin address
- * @param local_address_info the local address for the address
  * @param session_id session id, can never be 0
  * @param atsi performance information for this address
  * @param atsi_count number of performance information contained in @a atsi
@@ -511,10 +496,6 @@
 void
 GAS_addresses_update (struct GAS_Addresses_Handle *handle,
                       const struct GNUNET_PeerIdentity *peer,
-                      const char *plugin_name,
-                      const void *plugin_addr,
-                      size_t plugin_addr_len,
-                      uint32_t local_address_info,
                       uint32_t session_id,
                       const struct GNUNET_ATS_Information *atsi,
                       uint32_t atsi_count);

Modified: gnunet/src/ats/gnunet-service-ats_scheduling.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_scheduling.c      2015-01-22 21:08:43 UTC 
(rev 34960)
+++ gnunet/src/ats/gnunet-service-ats_scheduling.c      2015-01-22 21:25:54 UTC 
(rev 34961)
@@ -311,10 +311,6 @@
 {
   const struct AddressUpdateMessage *m;
   const struct GNUNET_ATS_Information *atsi;
-  const char *address;
-  const char *plugin_name;
-  uint16_t address_length;
-  uint16_t plugin_name_length;
   uint32_t ats_count;
   uint16_t size;
 
@@ -330,21 +326,12 @@
   }
   m = (const struct AddressUpdateMessage *) message;
   ats_count = ntohl (m->ats_count);
-  address_length = ntohs (m->address_length);
-  plugin_name_length = ntohs (m->plugin_name_length);
   atsi = (const struct GNUNET_ATS_Information *) &m[1];
-  address = (const char *) &atsi[ats_count];
-  if (plugin_name_length != 0)
-    plugin_name = &address[address_length];
-  else
-    plugin_name = "";
 
-  if ((address_length + plugin_name_length +
-       ats_count * sizeof (struct GNUNET_ATS_Information) +
+  if ((ats_count * sizeof (struct GNUNET_ATS_Information) +
        sizeof (struct AddressUpdateMessage) != ntohs (message->size)) ||
       (ats_count >
-       GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct 
GNUNET_ATS_Information)) ||
-       ((plugin_name_length > 0) && (plugin_name[plugin_name_length - 1] != 
'\0')))
+       GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct 
GNUNET_ATS_Information)))
   {
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -356,11 +343,8 @@
                             GNUNET_NO);
   GAS_addresses_update (address_handle,
                         &m->peer,
-                        plugin_name,
-                        address,
-                        address_length,
-                        ntohl (m->address_local_info),
-                        ntohl (m->session_id), atsi, ats_count);
+                        ntohl (m->session_id),
+                        atsi, ats_count);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
@@ -378,52 +362,13 @@
                            const struct GNUNET_MessageHeader *message)
 {
   const struct AddressUseMessage *m;
-  const char *address;
-  const char *plugin_name;
   int res;
-  uint16_t address_length;
-  uint16_t plugin_name_length;
-  uint16_t size;
-  uint16_t in_use;
 
-  size = ntohs (message->size);
-  if (size < sizeof (struct AddressUseMessage))
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
   m = (const struct AddressUseMessage *) message;
-
-  address_length = ntohs (m->address_length);
-  plugin_name_length = ntohs (m->plugin_name_length);
-
-  address = (const char *) &m[1];
-  if (plugin_name_length != 0)
-    plugin_name = &address[address_length];
-  else
-    plugin_name = "";
-
-  if ((address_length + plugin_name_length +
-       sizeof (struct AddressUseMessage) != ntohs (message->size)) ||
-      ((plugin_name_length > 0) &&
-      (plugin_name[plugin_name_length - 1] != '\0')))
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-
-  in_use = ntohs (m->in_use);
   res = GAS_addresses_in_use (address_handle,
                               &m->peer,
-                              plugin_name,
-                              address,
-                              address_length,
-                              ntohl (m->address_local_info),
                               ntohl (m->session_id),
-                              in_use);
-
+                              ntohl (m->in_use));
   if (GNUNET_OK != res)
   {
     GNUNET_break (0);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]