gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r17470 - gnunet/src/ats
Date: Thu, 13 Oct 2011 23:16:04 +0200

Author: grothoff
Date: 2011-10-13 23:16:04 +0200 (Thu, 13 Oct 2011)
New Revision: 17470

Modified:
   gnunet/src/ats/ats.h
   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:
more refactoring

Modified: gnunet/src/ats/ats.h
===================================================================
--- gnunet/src/ats/ats.h        2011-10-13 21:01:22 UTC (rev 17469)
+++ gnunet/src/ats/ats.h        2011-10-13 21:16:04 UTC (rev 17470)
@@ -41,7 +41,6 @@
 };
 
 
-
 struct ClientStartMessage
 {
   struct GNUNET_MessageHeader header;
@@ -53,7 +52,6 @@
 };
 
 
-
 struct RequestAddressMessage
 {
   struct GNUNET_MessageHeader header;
@@ -63,6 +61,7 @@
   struct GNUNET_PeerIdentity peer;
 };
 
+
 struct AddressUpdateMessage
 {
   struct GNUNET_MessageHeader header;
@@ -85,6 +84,7 @@
 
 };
 
+
 struct AddressDestroyedMessage
 {
   struct GNUNET_MessageHeader header;
@@ -134,7 +134,6 @@
 };
 
 
-
 struct PeerInformationMessage
 {
   struct GNUNET_MessageHeader header;
@@ -160,8 +159,6 @@
 };
 
 
-
-
 struct ReservationRequestMessage
 {
   struct GNUNET_MessageHeader header;

Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2011-10-13 21:01:22 UTC 
(rev 17469)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2011-10-13 21:16:04 UTC 
(rev 17470)
@@ -81,6 +81,52 @@
 }
 
 
+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

Modified: gnunet/src/ats/gnunet-service-ats_addresses.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.h       2011-10-13 21:01:22 UTC 
(rev 17469)
+++ gnunet/src/ats/gnunet-service-ats_addresses.h       2011-10-13 21:16:04 UTC 
(rev 17470)
@@ -27,8 +27,8 @@
 #define GNUNET_SERVICE_ATS_ADDRESSES_H
 
 #include "gnunet_util_lib.h"
+#include "gnunet_transport_service.h" // FIXME...
 
-
 /**
  */
 void
@@ -41,4 +41,13 @@
 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

Modified: gnunet/src/ats/gnunet-service-ats_scheduling.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_scheduling.c      2011-10-13 21:01:22 UTC 
(rev 17469)
+++ gnunet/src/ats/gnunet-service-ats_scheduling.c      2011-10-13 21:16:04 UTC 
(rev 17470)
@@ -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 @@
                       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");
+  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;
 
-  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))
+  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 @@
                       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 */




reply via email to

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