-improve UDP logging
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses.c
index e87bf487bdd520209e63f7db3daf3e3b59bf7f8e..c4d7f2da9737239cd898c2af3aada1c7db943347 100644 (file)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- (C) 2011-2015 Christian Grothoff (and other contributing authors)
Copyright (C) 2011-2015 Christian Grothoff (and other contributing authors)
 
  GNUnet is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  * @author Christian Grothoff
  */
 #include "platform.h"
-#include "gnunet_ats_service.h"
-#include "gnunet-service-ats.h"
 #include "gnunet-service-ats_addresses.h"
-#include "gnunet-service-ats_normalization.h"
 #include "gnunet-service-ats_performance.h"
+#include "gnunet-service-ats_normalization.h"
 #include "gnunet-service-ats_plugins.h"
-#include "gnunet-service-ats_scheduling.h"
-#include "gnunet-service-ats_reservations.h"
 
 
 /**
  */
 struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses;
 
-/**
- * Context for sending messages to performance clients without PIC.
- */
-static struct GNUNET_SERVER_NotificationContext *nc;
-
 
 /**
  * Update statistic on number of addresses.
@@ -421,6 +412,7 @@ create_address (const struct GNUNET_PeerIdentity *peer,
   for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
   {
     aa->atsin[c1].avg_queue_index = 0;
+    aa->atsin[c1].norm = DEFAULT_REL_QUALITY;
     for (c2 = 0; c2 < GAS_normalization_queue_length; c2++)
       aa->atsin[c1].atsi_abs[c2] = GNUNET_ATS_VALUE_UNDEFINED;
   }
@@ -501,10 +493,10 @@ find_exact_address (const struct GNUNET_PeerIdentity *peer,
  * @return the value in HBO or #GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist
  */
 static int
-get_performance_info (struct ATS_Address *address, uint32_t type)
+get_performance_info (struct ATS_Address *address,
+                      uint32_t type)
 {
-  int c1;
-  GNUNET_assert(NULL != address);
+  uint32_t c1;
 
   if ((NULL == address->atsi) || (0 == address->atsi_count))
     return GNUNET_ATS_VALUE_UNDEFINED;
@@ -550,11 +542,6 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
     GNUNET_break (0);
     return;
   }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received `%s' for peer `%s'\n",
-              "ADDRESS ADD",
-              GNUNET_i2s (peer));
   new_address = create_address (peer,
                                 plugin_name,
                                 plugin_addr,
@@ -581,18 +568,17 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
                                                   GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
   update_addresses_stat ();
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-             "Adding new address %p for peer `%s', length %u, session id %u, %s\n",
-             new_address,
+             "Adding new address for peer `%s' slot %u\n",
              GNUNET_i2s (peer),
-             plugin_addr_len,
-             session_id,
-             GNUNET_ATS_print_network_type (addr_net));
-
+             session_id);
   /* Tell solver about new address */
+  GAS_plugin_solver_lock ();
   GAS_plugin_new_address (new_address,
-                         addr_net,
-                         atsi,
-                         atsi_count);
+                         addr_net);
+  GAS_normalization_update_property (new_address,
+                                     atsi,
+                                     atsi_count);
+  GAS_plugin_solver_unlock ();
   /* Notify performance clients about new address */
   GAS_performance_notify_all_clients (&new_address->peer,
                                      new_address->plugin,
@@ -638,10 +624,9 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received `%s' for peer `%s' address \n",
-              "ADDRESS UPDATE",
+              "Received ADDRESS_UPDATE for peer `%s' slot %u\n",
               GNUNET_i2s (peer),
-              aa);
+              (unsigned int) session_id);
 
   /* Update address */
   aa->t_last_activity = GNUNET_TIME_absolute_get();
@@ -664,16 +649,16 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
                                        GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out),
                                        GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in));
 
-    GAS_plugin_update_address (aa,
-                              atsi,
-                              atsi_count);
+    GAS_normalization_update_property (aa,
+                                          atsi,
+                                          atsi_count);
   }
   GNUNET_free_non_null (atsi_delta);
 }
 
 
 /**
- * Remove an address or just a session for a peer.
+ * Remove an address for a peer.
  *
  * @param peer peer
  * @param session_id session id, can never be 0
@@ -693,9 +678,8 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received ADDRESS_DESTROYED for peer `%s' address %p session %u\n",
+              "Received ADDRESS_DESTROYED for peer `%s' session %u\n",
               GNUNET_i2s (peer),
-              ea,
               session_id);
   free_address (ea);
 }
@@ -714,7 +698,6 @@ GAS_addresses_init (struct GNUNET_SERVER_Handle *server)
 {
   GSA_addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
   update_addresses_stat ();
-  nc = GNUNET_SERVER_notification_context_create (server, 32);
 }
 
 
@@ -746,6 +729,9 @@ GAS_addresses_destroy_all ()
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Destroying all addresses\n");
+  if (0 ==
+      GNUNET_CONTAINER_multipeermap_size (GSA_addresses))
+    return;
   GAS_plugin_solver_lock ();
   GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
                                          &destroy_all_address_it,
@@ -765,8 +751,6 @@ GAS_addresses_done ()
   GAS_addresses_destroy_all ();
   GNUNET_CONTAINER_multipeermap_destroy (GSA_addresses);
   GSA_addresses = NULL;
-  GNUNET_SERVER_notification_context_destroy (nc);
-  nc = NULL;
 }
 
 
@@ -918,6 +902,7 @@ transmit_req_addr (struct AddressIteration *ai,
   char *addrp;
   size_t plugin_name_length;
   size_t msize;
+  struct GNUNET_SERVER_NotificationContext *nc;
 
   if (NULL != plugin_name)
     plugin_name_length = strlen (plugin_name) + 1;
@@ -953,6 +938,13 @@ transmit_req_addr (struct AddressIteration *ai,
     memcpy (addrp, plugin_addr, plugin_addr_len);
   if (NULL != plugin_name)
     strcpy (&addrp[plugin_addr_len], plugin_name);
+  nc = *GNUNET_SERVER_client_get_user_context (ai->client,
+                                               struct GNUNET_SERVER_NotificationContext *);
+  if (NULL == nc)
+  {
+    GNUNET_break (0);
+    return;
+  }
   GNUNET_SERVER_notification_context_unicast (nc,
                                               ai->client,
                                               &msg->header,
@@ -1037,8 +1029,6 @@ GAS_handle_request_address_list (void *cls,
   const struct AddressListRequestMessage *alrm;
   struct GNUNET_PeerIdentity allzeros;
 
-  GNUNET_SERVER_notification_context_add (nc,
-                                          client);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received ADDRESSLIST_REQUEST message\n");
   alrm = (const struct AddressListRequestMessage *) message;