guix-env: some update.
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses.c
index 17f030a6cadfb1d832a5250047415309218c5035..ba34cbacb122451786fa03c7bd81c014171a3b26 100644 (file)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- Copyright (C) 2011-2015 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2011-2015 GNUnet e.V.
 
  GNUnet is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
  You should have received a copy of the GNU General Public License
  along with GNUnet; see the file COPYING.  If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -58,9 +58,10 @@ update_addresses_stat ()
 static void
 free_address (struct ATS_Address *addr)
 {
-  GNUNET_CONTAINER_multipeermap_remove (GSA_addresses,
-                                        &addr->peer,
-                                        addr);
+  GNUNET_assert (GNUNET_YES ==
+                 GNUNET_CONTAINER_multipeermap_remove (GSA_addresses,
+                                                       &addr->peer,
+                                                       addr));
   update_addresses_stat ();
   GAS_plugin_delete_address (addr);
   GAS_performance_notify_all_clients (&addr->peer,
@@ -69,6 +70,7 @@ free_address (struct ATS_Address *addr)
                                       addr->addr_len,
                                       GNUNET_NO,
                                       NULL,
+                                      addr->local_address_info,
                                       GNUNET_BANDWIDTH_ZERO,
                                       GNUNET_BANDWIDTH_ZERO);
   GNUNET_free (addr->plugin);
@@ -116,7 +118,7 @@ create_address (const struct GNUNET_PeerIdentity *peer,
   aa->peer = *peer;
   aa->addr_len = plugin_addr_len;
   aa->addr = &aa[1];
-  memcpy (&aa[1],
+  GNUNET_memcpy (&aa[1],
           plugin_addr,
           plugin_addr_len);
   aa->plugin = GNUNET_strdup (plugin_name);
@@ -223,6 +225,7 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
     GNUNET_break (0);
     return;
   }
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
   new_address = create_address (peer,
                                 plugin_name,
                                 plugin_addr,
@@ -255,6 +258,7 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
                                      new_address->addr_len,
                                      new_address->active,
                                      &new_address->properties,
+                                      new_address->local_address_info,
                                      GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_out),
                                      GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_in));
 }
@@ -291,7 +295,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
               "Received ADDRESS_UPDATE for peer `%s' slot %u\n",
               GNUNET_i2s (peer),
               (unsigned int) session_id);
-
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
   /* Update address */
   aa->t_last_activity = GNUNET_TIME_absolute_get();
   aa->properties = *prop;
@@ -302,6 +306,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
                                       aa->addr_len,
                                       aa->active,
                                       prop,
+                                      aa->local_address_info,
                                       GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out),
                                       GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in));
 
@@ -342,13 +347,13 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
  * known and current performance information. It has a solver component
  * responsible for the resource allocation. It tells the solver about changes
  * and receives updates when the solver changes the resource allocation.
- *
- * @param server handle to our server
  */
 void
-GAS_addresses_init (struct GNUNET_SERVER_Handle *server)
+GAS_addresses_init ()
 {
-  GSA_addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
+  GSA_addresses
+    = GNUNET_CONTAINER_multipeermap_create (128,
+                                           GNUNET_NO);
   update_addresses_stat ();
 }
 
@@ -400,7 +405,9 @@ GAS_addresses_done ()
 {
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
              "Shutting down addresses\n");
+  GAS_plugin_solver_lock ();
   GAS_addresses_destroy_all ();
+  GAS_plugin_solver_unlock ();
   GNUNET_CONTAINER_multipeermap_destroy (GSA_addresses);
   GSA_addresses = NULL;
 }
@@ -446,6 +453,7 @@ peerinfo_it (void *cls,
               addr->addr_len,
               addr->active,
               &addr->properties,
+              addr->local_address_info,
               GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out),
               GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in));
   return GNUNET_OK;
@@ -492,6 +500,7 @@ GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
          NULL, NULL, NULL, 0,
          GNUNET_NO,
          NULL,
+         GNUNET_HELLO_ADDRESS_INFO_NONE,
          GNUNET_BANDWIDTH_ZERO,
          GNUNET_BANDWIDTH_ZERO);
 }
@@ -506,7 +515,7 @@ struct AddressIteration
   /**
    * Actual handle to the client.
    */
-  struct GNUNET_SERVER_Client *client;
+  struct GNUNET_SERVICE_Client *client;
 
   /**
    * Are we sending all addresses, or only those that are active?
@@ -532,6 +541,7 @@ struct AddressIteration
  * @param plugin_addr_len length of @a plugin_addr
  * @param active #GNUNET_YES if this address is actively used
  * @param prop performance information
+ * @param local_address_info flags for the address
  * @param bandwidth_out current outbound bandwidth assigned to address
  * @param bandwidth_in current inbound bandwidth assigned to address
  */
@@ -543,56 +553,49 @@ transmit_req_addr (struct AddressIteration *ai,
                    size_t plugin_addr_len,
                    int active,
                    const struct GNUNET_ATS_Properties *prop,
+                   enum GNUNET_HELLO_AddressInfo local_address_info,
                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
                    struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 
 {
+  struct GNUNET_MQ_Envelope *env;
   struct PeerInformationMessage *msg;
   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;
   else
     plugin_name_length = 0;
-  msize = sizeof (struct PeerInformationMessage) +
-          plugin_addr_len + plugin_name_length;
-  char buf[msize] GNUNET_ALIGN;
-
-  GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
-  msg = (struct PeerInformationMessage *) buf;
-  msg->header.size = htons (msize);
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
+  msize = plugin_addr_len + plugin_name_length;
+
+  GNUNET_assert (sizeof (struct PeerInformationMessage) + msize
+                < GNUNET_MAX_MESSAGE_SIZE);
+  env = GNUNET_MQ_msg_extra (msg,
+                            msize,
+                            GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
   msg->id = htonl (ai->id);
   if (NULL != id)
     msg->peer = *id;
-  else
-    memset (&msg->peer, '\0', sizeof (struct GNUNET_PeerIdentity));
   msg->address_length = htons (plugin_addr_len);
   msg->address_active = ntohl (active);
   msg->plugin_name_length = htons (plugin_name_length);
   msg->bandwidth_out = bandwidth_out;
   msg->bandwidth_in = bandwidth_in;
-  GNUNET_ATS_properties_hton (&msg->properties,
-                              prop);
+  if (NULL != prop)
+    GNUNET_ATS_properties_hton (&msg->properties,
+                                prop);
+  msg->address_local_info = htonl ((uint32_t) local_address_info);
   addrp = (char *) &msg[1];
-  if (NULL != plugin_addr)
-    memcpy (addrp, plugin_addr, plugin_addr_len);
+  GNUNET_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,
-                                              GNUNET_NO);
+    strcpy (&addrp[plugin_addr_len],
+           plugin_name);
+  GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ai->client),
+                 env);
 }
 
 
@@ -607,6 +610,7 @@ transmit_req_addr (struct AddressIteration *ai,
  * @param plugin_addr_len length of @a plugin_addr
  * @param active is address actively used
  * @param prop performance information
+ * @param local_address_info additional local info for the address
  * @param bandwidth_out current outbound bandwidth assigned to address
  * @param bandwidth_in current inbound bandwidth assigned to address
  */
@@ -618,6 +622,7 @@ req_addr_peerinfo_it (void *cls,
                       size_t plugin_addr_len,
                       int active,
                       const struct GNUNET_ATS_Properties *prop,
+                      enum GNUNET_HELLO_AddressInfo local_address_info,
                       struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
                       struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {
@@ -649,6 +654,7 @@ req_addr_peerinfo_it (void *cls,
                      plugin_addr, plugin_addr_len,
                      active,
                      prop,
+                     local_address_info,
                      bandwidth_out,
                      bandwidth_in);
 }
@@ -657,22 +663,18 @@ req_addr_peerinfo_it (void *cls,
 /**
  * Handle 'address list request' messages from clients.
  *
- * @param cls unused, NULL
- * @param client client that sent the request
- * @param message the request message
+ * @param cls client that sent the request
+ * @param alrm the request message
  */
 void
-GAS_handle_request_address_list (void *cls,
-                                 struct GNUNET_SERVER_Client *client,
-                                 const struct GNUNET_MessageHeader *message)
+GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client,
+                                 const struct AddressListRequestMessage *alrm)
 {
   struct AddressIteration ai;
-  const struct AddressListRequestMessage *alrm;
   struct GNUNET_PeerIdentity allzeros;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received ADDRESSLIST_REQUEST message\n");
-  alrm = (const struct AddressListRequestMessage *) message;
   ai.all = ntohl (alrm->all);
   ai.id = ntohl (alrm->id);
   ai.client = client;
@@ -703,10 +705,9 @@ GAS_handle_request_address_list (void *cls,
                      NULL, NULL, NULL,
                      0, GNUNET_NO,
                      NULL,
+                     GNUNET_HELLO_ADDRESS_INFO_NONE,
                      GNUNET_BANDWIDTH_ZERO,
                      GNUNET_BANDWIDTH_ZERO);
-  GNUNET_SERVER_receive_done (client,
-                              GNUNET_OK);
 }