- cleanup
[oweals/gnunet.git] / src / ats / gnunet-service-ats_scheduling.c
index 0b66ac5668345d78351407b9b5a50299fe67439d..a4c04275f09bd55461614173863cf273de19a6c0 100644 (file)
@@ -222,6 +222,64 @@ GAS_handle_reset_backoff (void *cls,
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
+/**
+ * Handle 'address add' messages from clients.
+ *
+ * @param cls unused, NULL
+ * @param client client that sent the request
+ * @param message the request message
+ */
+void
+GAS_handle_address_add (void *cls, struct GNUNET_SERVER_Client *client,
+                        const struct GNUNET_MessageHeader *message)
+{
+  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;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
+              "ADDRESS_ADD");
+  size = ntohs (message->size);
+  if (size < sizeof (struct AddressUpdateMessage))
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+  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) +
+       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_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+  GNUNET_STATISTICS_update (GSA_stats, "# address updates received", 1,
+                            GNUNET_NO);
+  GAS_addresses_add (&m->peer, plugin_name, address, address_length,
+                        ntohl (m->session_id), atsi, ats_count);
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
 
 /**
  * Handle 'address update' messages from clients.