fix #4546
[oweals/gnunet.git] / src / dv / gnunet-service-dv.c
index ad00264d0d0481f4e0f694a9f34ebb76468b9683..df95fd67b36f5498ffdb72ab5bfbfba2325f231c 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2013 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.
 */
 
 /**
@@ -230,7 +230,7 @@ struct DirectNeighbor
    * ID of the task we use to (periodically) update our consensus
    * with this peer.  Used if we are the initiating peer.
    */
-  GNUNET_SCHEDULER_TaskIdentifier initiate_task;
+  struct GNUNET_SCHEDULER_Task * initiate_task;
 
   /**
    * At what offset are we, with respect to inserting our own routes
@@ -386,7 +386,7 @@ static struct GNUNET_ATS_PerformanceHandle *ats;
 /**
  * Task scheduled to refresh routes based on direct neighbours.
  */
-static GNUNET_SCHEDULER_TaskIdentifier rr_task;
+static struct GNUNET_SCHEDULER_Task * rr_task;
 
 /**
  * #GNUNET_YES if we are shutting down.
@@ -398,11 +398,9 @@ static int in_shutdown;
  *
  * @param cls the 'struct DirectNeighbor' of the peer we're building
  *        a routing consensus with
- * @param tc scheduler context
  */
 static void
-initiate_set_union (void *cls,
-                   const struct GNUNET_SCHEDULER_TaskContext *tc);
+initiate_set_union (void *cls);
 
 
 /**
@@ -633,7 +631,7 @@ core_transmit_notify (void *cls, size_t size, void *buf)
              off,
              GNUNET_i2s (&dn->peer));
   GNUNET_assert (NULL != core_api);
-  if (NULL != dn->pm_head)
+  if (NULL != pending)
     dn->cth =
       GNUNET_CORE_notify_transmit_ready (core_api,
                                         GNUNET_YES /* cork */,
@@ -852,7 +850,7 @@ build_set (void *cls)
   target = &route->target;
   GNUNET_assert (ntohl (target->distance) < DEFAULT_FISHEYE_DEPTH);
   element.size = sizeof (struct Target);
-  element.type = htons (0); /* do we need this? */
+  element.element_type = htons (0);
   element.data = target;
 
   /* Find next non-NULL entry */
@@ -1132,13 +1130,11 @@ refresh_routes (void *cls,
  * Task to run #refresh_routes() on all direct neighbours.
  *
  * @param cls NULL
- * @param tc unused
  */
 static void
-refresh_routes_task (void *cls,
-                     const struct GNUNET_SCHEDULER_TaskContext *tc)
+refresh_routes_task (void *cls)
 {
-  rr_task = GNUNET_SCHEDULER_NO_TASK;
+  rr_task = NULL;
   GNUNET_CONTAINER_multipeermap_iterate (direct_neighbors,
                                         &refresh_routes,
                                          NULL);
@@ -1152,52 +1148,12 @@ refresh_routes_task (void *cls,
 static void
 schedule_refresh_routes ()
 {
-  if (GNUNET_SCHEDULER_NO_TASK == rr_task)
+  if (NULL == rr_task)
     rr_task = GNUNET_SCHEDULER_add_now (&refresh_routes_task,
                                         NULL);
 }
 
 
-/**
- * Get distance information from 'atsi'.
- *
- * @param atsi performance data
- * @param atsi_count number of entries in atsi
- * @return connected transport distance
- */
-static uint32_t
-get_atsi_distance (const struct GNUNET_ATS_Information *atsi,
-                   uint32_t atsi_count)
-{
-  uint32_t i;
-
-  for (i = 0; i < atsi_count; i++)
-    if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DISTANCE)
-      return (0 == ntohl (atsi[i].value)) ? DIRECT_NEIGHBOR_COST : ntohl (atsi[i].value); // FIXME: 0 check should not be required once ATS is fixed!
-  /* If we do not have explicit distance data, assume direct neighbor. */
-  return DIRECT_NEIGHBOR_COST;
-}
-
-
-/**
- * Get network information from 'atsi'.
- *
- * @param atsi performance data
- * @param atsi_count number of entries in atsi
- * @return connected transport network
- */
-static enum GNUNET_ATS_Network_Type
-get_atsi_network (const struct GNUNET_ATS_Information *atsi,
-                   uint32_t atsi_count)
-{
-  uint32_t i;
-
-  for (i = 0; i < atsi_count; i++)
-    if (ntohl (atsi[i].type) == GNUNET_ATS_NETWORK_TYPE)
-      return (enum GNUNET_ATS_Network_Type) ntohl (atsi[i].value);
-  return GNUNET_ATS_NET_UNSPECIFIED;
-}
-
 /**
  * Multipeermap iterator for freeing routes that go via a particular
  * neighbor that disconnected and is thus no longer available.
@@ -1288,10 +1244,10 @@ handle_direct_disconnect (struct DirectNeighbor *neighbor)
     GNUNET_SET_listen_cancel (neighbor->listen_handle);
     neighbor->listen_handle = NULL;
   }
-  if (GNUNET_SCHEDULER_NO_TASK != neighbor->initiate_task)
+  if (NULL != neighbor->initiate_task)
   {
     GNUNET_SCHEDULER_cancel (neighbor->initiate_task);
-    neighbor->initiate_task = GNUNET_SCHEDULER_NO_TASK;
+    neighbor->initiate_task = NULL;
   }
 }
 
@@ -1308,8 +1264,7 @@ handle_direct_disconnect (struct DirectNeighbor *neighbor)
  *        #GNUNET_SYSERR if this address is no longer available for ATS
  * @param bandwidth_out assigned outbound bandwidth for the connection
  * @param bandwidth_in assigned inbound bandwidth for the connection
- * @param ats performance data for the address (as far as known)
- * @param ats_count number of performance records in @a ats
+ * @param prop performance data for the address (as far as known)
  */
 static void
 handle_ats_update (void *cls,
@@ -1317,12 +1272,11 @@ handle_ats_update (void *cls,
                   int active,
                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
-                  const struct GNUNET_ATS_Information *ats,
-                  uint32_t ats_count)
+                  const struct GNUNET_ATS_Properties *prop)
 {
   struct DirectNeighbor *neighbor;
   uint32_t distance;
-  enum GNUNET_ATS_Network_Type network = GNUNET_ATS_NET_UNSPECIFIED;
+  enum GNUNET_ATS_Network_Type network;
 
   if (NULL == address)
   {
@@ -1335,8 +1289,8 @@ handle_ats_update (void *cls,
     // FIXME: handle disconnect/inactive case too!
     return;
   }
-  distance = get_atsi_distance (ats, ats_count);
-  network = get_atsi_network (ats, ats_count);
+  distance = prop->distance;
+  network = prop->scope;
   GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network);
   /* check if entry exists */
   neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
@@ -1560,9 +1514,6 @@ handle_set_union_result (void *cls,
   case GNUNET_SET_STATUS_OK:
     status_str = "GNUNET_SET_STATUS_OK";
     break;
-  case GNUNET_SET_STATUS_TIMEOUT:
-    status_str = "GNUNET_SET_STATUS_TIMEOUT";
-    break;
   case GNUNET_SET_STATUS_FAILURE:
     status_str = "GNUNET_SET_STATUS_FAILURE";
     break;
@@ -1614,7 +1565,6 @@ handle_set_union_result (void *cls,
       GNUNET_free (target);
     }
     break;
-  case GNUNET_SET_STATUS_TIMEOUT:
   case GNUNET_SET_STATUS_FAILURE:
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Failed to establish DV union, will try again later\n");
@@ -1738,18 +1688,16 @@ listen_set_union (void *cls,
  *
  * @param cls the `struct DirectNeighbor *` of the peer we're building
  *        a routing consensus with
- * @param tc scheduler context
  */
 static void
-initiate_set_union (void *cls,
-                   const struct GNUNET_SCHEDULER_TaskContext *tc)
+initiate_set_union (void *cls)
 {
   struct DirectNeighbor *neighbor = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Initiating SET union with peer `%s'\n",
              GNUNET_i2s (&neighbor->peer));
-  neighbor->initiate_task = GNUNET_SCHEDULER_NO_TASK;
+  neighbor->initiate_task = NULL;
   neighbor->my_set = GNUNET_SET_create (cfg,
                                        GNUNET_SET_OPERATION_UNION);
   neighbor->set_op = GNUNET_SET_prepare (&neighbor->peer,
@@ -2128,11 +2076,9 @@ free_direct_neighbors (void *cls,
  * Task run during shutdown.
  *
  * @param cls unused
- * @param tc unused
  */
 static void
-shutdown_task (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
   unsigned int i;
 
@@ -2158,10 +2104,10 @@ shutdown_task (void *cls,
                       consensi[i].array_length,
                       0);
   }
-  if (GNUNET_SCHEDULER_NO_TASK != rr_task)
+  if (NULL != rr_task)
   {
     GNUNET_SCHEDULER_cancel (rr_task);
-    rr_task = GNUNET_SCHEDULER_NO_TASK;
+    rr_task = NULL;
   }
 }
 
@@ -2283,8 +2229,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
                                                  MAX_QUEUE_SIZE_PLUGIN);
   stats = GNUNET_STATISTICS_create ("dv", cfg);
   GNUNET_SERVER_add_handlers (server, plugin_handlers);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                               &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }