more refactoring
authorChristian Grothoff <christian@grothoff.org>
Thu, 13 Oct 2011 21:16:04 +0000 (21:16 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 13 Oct 2011 21:16:04 +0000 (21:16 +0000)
src/ats/ats.h
src/ats/gnunet-service-ats_addresses.c
src/ats/gnunet-service-ats_addresses.h
src/ats/gnunet-service-ats_scheduling.c

index 2bf16b1254838359d964a4a32572b9988a024e73..bef63553e173a814d5e2a8feb0ff64a23edec006 100644 (file)
@@ -41,7 +41,6 @@ enum StartFlag
 };
 
 
-
 struct ClientStartMessage
 {
   struct GNUNET_MessageHeader header;
@@ -53,7 +52,6 @@ struct ClientStartMessage
 };
 
 
-
 struct RequestAddressMessage
 {
   struct GNUNET_MessageHeader header;
@@ -63,6 +61,7 @@ struct RequestAddressMessage
   struct GNUNET_PeerIdentity peer;
 };
 
+
 struct AddressUpdateMessage
 {
   struct GNUNET_MessageHeader header;
@@ -85,6 +84,7 @@ struct AddressUpdateMessage
 
 };
 
+
 struct AddressDestroyedMessage
 {
   struct GNUNET_MessageHeader header;
@@ -134,7 +134,6 @@ struct AddressSuggestionMessage
 };
 
 
-
 struct PeerInformationMessage
 {
   struct GNUNET_MessageHeader header;
@@ -160,8 +159,6 @@ struct PeerInformationMessage
 };
 
 
-
-
 struct ReservationRequestMessage
 {
   struct GNUNET_MessageHeader header;
index ff83f4fd802c744916fec1dc2b36e382b9e5afb4..4f9f877a575ea106f3f49c460c997f2fb4c00c16 100644 (file)
@@ -81,6 +81,52 @@ free_address_it (void *cls,
 }
 
 
+void
+GAS_address_update (struct GNUNET_SERVER_Client *client,
+                   const struct GNUNET_PeerIdentity *peer,
+                   const char *plugin_name,
+                   const void *plugin_addr, size_t plugin_addr_len,
+                   uint32_t session_id,
+                   const struct GNUNET_TRANSPORT_ATS_Information *atsi,
+                   uint32_t atsi_count)
+{
+  struct ATS_Address * aa;
+
+  aa = GNUNET_malloc (sizeof (struct ATS_Address) +
+                     atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
+                     plugin_addr_len);
+  aa->peer = *peer;
+  aa->addr_len = plugin_addr_len;
+  aa->ats_count = atsi_count;
+  aa->ats = (struct GNUNET_TRANSPORT_ATS_Information *) &aa[1];  
+  memcpy (&aa->ats, atsi, atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+  memcpy (aa->addr, plugin_addr, plugin_addr_len);
+  aa->plugin = GNUNET_strdup (plugin_name);
+  aa->session_id = session_id;
+
+  GNUNET_assert (GNUNET_OK == 
+                GNUNET_CONTAINER_multihashmap_put(addresses, 
+                                                  &peer->hashPubKey, 
+                                                  aa, 
+                                                  GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+}
+
+
+void
+GAS_address_destroyed (struct GNUNET_SERVER_Client *client,
+                      ...)
+{
+#if 0
+  // struct AddressDestroyedMessage * msg = (struct AddressDestroyedMessage *) message;
+/*
+  struct GNUNET_PeerIdentity *peer = &msg->peer;
+  struct ATS_Address * aa = find_address_by_addr (peer);
+  GNUNET_CONTAINER_multihashmap_remove(addresses, peer, aa);
+  GNUNET_free (aa);*/
+#endif
+}
+
+
 /**
  */
 void
index 1bc6b65c25c0a23a3a479edc43135b96dc7a5600..299619c6fdbbc5cfe939d4de00dbf8eaf25ff629 100644 (file)
@@ -27,7 +27,7 @@
 #define GNUNET_SERVICE_ATS_ADDRESSES_H
 
 #include "gnunet_util_lib.h"
-
+#include "gnunet_transport_service.h" // FIXME...
 
 /**
  */
@@ -41,4 +41,13 @@ void
 GAS_addresses_done (void);
 
 
+void
+GAS_address_update (struct GNUNET_SERVER_Client *client,
+                   const struct GNUNET_PeerIdentity *peer,
+                   const char *plugin_name,
+                   const void *plugin_addr, size_t plugin_addr_len,
+                   uint32_t session_id,
+                   const struct GNUNET_TRANSPORT_ATS_Information *atsi,
+                   uint32_t atsi_count);
+
 #endif
index bf2c6187ab5dbc3fd2640a03dee6e2dcd530047d..60305bac91509e1a9f3b2f4a9f47458595ae3b74 100644 (file)
@@ -24,6 +24,7 @@
  * @author Matthias Wachs
  */
 #include "platform.h"
+#include "gnunet-service-ats_addresses.h"
 #include "gnunet-service-ats_scheduling.h"
 #include "ats.h"
 
@@ -105,54 +106,52 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
                       const struct GNUNET_MessageHeader *message)
 
 {
-#if 0
-  struct AddressUpdateMessage * msg = (struct AddressUpdateMessage *) message;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_UPDATE");
-
-  struct GNUNET_TRANSPORT_ATS_Information *am;
-  char *pm;
-
-  size_t size = ntohs (msg->header.size);
-  if ((size <= sizeof (struct AddressUpdateMessage)) || (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
+  const struct AddressUpdateMessage * m;
+  const struct GNUNET_TRANSPORT_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;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+             "Received `%s' message\n",
+             "ADDRESS_UPDATE");
+  size = ntohs (message->size);
+  if (size <= sizeof (struct AddressUpdateMessage))
   {
     GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-
-  size_t ats_count = ntohs (msg->ats_count);
-  size_t addr_len = ntohs (msg->address_length);
-  size_t plugin_len = ntohs (msg->plugin_name_length) + 1 ;
-
-  if (
-       (plugin_len  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
-       (addr_len  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
-       (addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)) )
+  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_TRANSPORT_ATS_Information*) &m[1];
+  address = (const char*) &atsi[ats_count];
+  plugin_name = &address[address_length];
+  if ( (address_length +
+       plugin_name_length +
+       ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
+       sizeof (struct AddressSuggestionMessage) != ntohs (message->size))  ||
+       (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
+       (plugin_name[plugin_name_length - 1] != '\0') )
   {
     GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-
-  struct ATS_Address * aa = GNUNET_malloc (sizeof (struct ATS_Address) +
-                                           ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
-                                           addr_len +
-                                           plugin_len);
-
-
-
-  memcpy (&aa->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity));
-  aa->addr_len = addr_len;
-  aa->ats_count = ats_count;
-  aa->ats = (struct GNUNET_TRANSPORT_ATS_Information *) &aa[1];
-
-  am = (struct GNUNET_TRANSPORT_ATS_Information*) &msg[1];
-  memcpy (&aa->ats, am, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
-  pm = (char *) &am[ats_count];
-  memcpy (aa->addr, pm, addr_len);
-  memcpy (aa->plugin, &pm[plugin_len], plugin_len);
-  aa->session_id = ntohl(msg->session_id);
-
-  GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(addresses, &aa->peer.hashPubKey, aa, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
-#endif
+  GAS_address_update (client,
+                     &m->peer,
+                     plugin_name,
+                     address,
+                     address_length,
+                     ntohl (m->session_id),
+                     atsi,
+                     ats_count);
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
@@ -161,15 +160,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
                       const struct GNUNET_MessageHeader *message)
 
 {
-#if 0
-  // struct AddressDestroyedMessage * msg = (struct AddressDestroyedMessage *) message;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_DESTROYED");
-/*
-  struct GNUNET_PeerIdentity *peer = &msg->peer;
-  struct ATS_Address * aa = find_address_by_addr (peer);
-  GNUNET_CONTAINER_multihashmap_remove(addresses, peer, aa);
-  GNUNET_free (aa);*/
-#endif
 }
 
 /* end of gnunet-service-ats_scheduling.c */