fix for 0002392
[oweals/gnunet.git] / src / ats / gnunet-service-ats_scheduling.c
index 4659a2363222a356dad5d0198e9175ab660204ac..0b66ac5668345d78351407b9b5a50299fe67439d 100644 (file)
@@ -59,7 +59,6 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
   }
   my_client = client;
   GNUNET_SERVER_notification_context_add (nc, client);
-  GNUNET_SERVER_client_keep (client);
   return GNUNET_OK;
 }
 
@@ -76,7 +75,6 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client)
   if (my_client != client)
     return;
   GAS_addresses_destroy_all ();
-  GNUNET_SERVER_client_drop (client);
   my_client = NULL;
 }
 
@@ -114,7 +112,7 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity
       sizeof (struct AddressSuggestionMessage) +
       atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
       plugin_name_length;
-  char buf[msize];
+  char buf[msize] GNUNET_ALIGN;
   struct GNUNET_ATS_Information *atsp;
   char *addrp;
 
@@ -142,8 +140,10 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity
   memcpy (addrp, plugin_addr, plugin_addr_len);
   strcpy (&addrp[plugin_addr_len], plugin_name);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS sends quota for peer `%s': (in/out) %u/%u\n",
-      GNUNET_i2s (peer), ntohl (bandwidth_in.value__), ntohl(bandwidth_out.value__));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "ATS sends quota for peer `%s': (in/out) %u/%u\n",
+              GNUNET_i2s (peer), ntohl (bandwidth_in.value__),
+              ntohl (bandwidth_out.value__));
 
   GNUNET_SERVER_notification_context_unicast (nc, my_client, &msg->header,
                                               GNUNET_YES);
@@ -182,8 +182,9 @@ GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
  * @param message the request message
  */
 void
-GAS_handle_request_address_cancel (void *cls, struct GNUNET_SERVER_Client *client,
-                            const struct GNUNET_MessageHeader *message)
+GAS_handle_request_address_cancel (void *cls,
+                                   struct GNUNET_SERVER_Client *client,
+                                   const struct GNUNET_MessageHeader *message)
 {
   const struct RequestAddressMessage *msg =
       (const struct RequestAddressMessage *) message;
@@ -197,6 +198,30 @@ GAS_handle_request_address_cancel (void *cls, struct GNUNET_SERVER_Client *clien
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
+/**
+ * Handle 'reset backoff' messages from clients.
+ *
+ * @param cls unused, NULL
+ * @param client client that sent the request
+ * @param message the request message
+ */
+void
+GAS_handle_reset_backoff (void *cls,
+                          struct GNUNET_SERVER_Client *client,
+                          const struct GNUNET_MessageHeader *message)
+{
+  const struct ResetBackoffMessage *msg =
+      (const struct ResetBackoffMessage *) message;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
+              "RESET_BACKOFF");
+  GNUNET_STATISTICS_update (GSA_stats, "# backoff reset requests received", 1,
+                            GNUNET_NO);
+  GNUNET_break (0 == ntohl (msg->reserved));
+  GAS_addresses_handle_backoff_reset (&msg->peer);
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
 
 /**
  * Handle 'address update' messages from clients.
@@ -237,12 +262,13 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
     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[plugin_name_length - 1] != '\0'))
+       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);
@@ -270,6 +296,7 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
   const struct AddressUseMessage *m;
   const char *address;
   const char *plugin_name;
+  int res;
   uint16_t address_length;
   uint16_t plugin_name_length;
 
@@ -296,7 +323,8 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
 
   if ((address_length + plugin_name_length +
        sizeof (struct AddressUseMessage) != ntohs (message->size)) ||
-      (plugin_name[plugin_name_length - 1] != '\0'))
+      ((plugin_name_length > 0) &&
+      (plugin_name[plugin_name_length - 1] != '\0')))
   {
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -304,14 +332,21 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
   }
 
   in_use = ntohs (m->in_use);
-  GAS_addresses_in_use (&m->peer,
-                        plugin_name,
-                        address,
-                        address_length,
-                        ntohl (m->session_id),
-                        in_use);
+  res = GAS_addresses_in_use (&m->peer,
+                             plugin_name,
+                             address,
+                             address_length,
+                             ntohl (m->session_id),
+                             in_use);
+
+  if (res == GNUNET_OK)
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+  else
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+  }
 
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 /**
@@ -359,8 +394,8 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-  if ( (plugin_name_length == 0) ||
-       (plugin_name[plugin_name_length - 1] != '\0'))
+  if ((plugin_name_length == 0) ||
+      (plugin_name[plugin_name_length - 1] != '\0'))
   {
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -400,8 +435,13 @@ GAS_scheduling_init (struct GNUNET_SERVER_Handle *server)
 void
 GAS_scheduling_done ()
 {
+  if (NULL != my_client)
+  {
+    my_client = NULL;
+  }
   GNUNET_SERVER_notification_context_destroy (nc);
   nc = NULL;
+
 }