-only trigger check config if we actually need it
[oweals/gnunet.git] / src / dht / gnunet-service-xdht_neighbours.c
index 3d14fbcd4a1717432c2be0241be1e825fc2c2857..3464de844658456cdc7e42ead414eaf78a833dc4 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009-2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009-2014 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.
 */
 
 /**
@@ -41,7 +41,6 @@
 #include "gnunet-service-xdht_datacache.h"
 #include "gnunet-service-xdht_neighbours.h"
 #include "gnunet-service-xdht_routing.h"
-#include <fenv.h>
 #include "dht.h"
 
 /**
@@ -285,7 +284,7 @@ struct PeerGetResultMessage
   /**
    * When does the content expire?
    */
-  struct GNUNET_TIME_Absolute expiration_time;
+  struct GNUNET_TIME_AbsoluteNBO expiration_time;
 
   /**
    * The key of the corresponding GET request.
@@ -939,12 +938,6 @@ static struct GNUNET_TIME_Relative notify_successor_retry_time;
  */
 unsigned int track_topology;
 
-/**
- * Should I be a malicious peer and drop the PUT/GET packets?
- * if 0 then NOT malicious.
- */
-unsigned int act_malicious;
-
 /**
  * Count of fingers found. Ideally we should have O(logn) fingers for a
  * stable network.
@@ -1069,19 +1062,6 @@ process_friend_queue (struct FriendInfo *peer)
 }
 
 
-#if ENABLE_MALICIOUS
-/**
- * Set the ENABLE_MALICIOUS value to malicious.
- * @param malicious
- */
-int
-GDS_NEIGHBOURS_act_malicious (unsigned int malicious)
-{
-  act_malicious = malicious;
-  return GNUNET_OK;
-}
-#endif
-
 /**
  * Construct a trail setup message and forward it to target_friend
  * @param source_peer Peer which wants to setup the trail
@@ -2182,11 +2162,11 @@ find_local_best_known_next_hop (uint64_t destination_finger_value,
 void
 GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
                          enum GNUNET_BLOCK_Type block_type,
-                                          enum GNUNET_DHT_RouteOption options,
-                                          uint32_t desired_replication_level,
-                                          struct GNUNET_PeerIdentity best_known_dest,
-                                          struct GNUNET_HashCode intermediate_trail_id,
-                                          struct GNUNET_PeerIdentity *target_peer,
+                         enum GNUNET_DHT_RouteOption options,
+                         uint32_t desired_replication_level,
+                         struct GNUNET_PeerIdentity best_known_dest,
+                         struct GNUNET_HashCode intermediate_trail_id,
+                         struct GNUNET_PeerIdentity *target_peer,
                          uint32_t hop_count,
                          uint32_t put_path_length,
                          struct GNUNET_PeerIdentity *put_path,
@@ -2292,38 +2272,6 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
   }
   /* In case we are sending the request to  a finger, then send across all of its
    trail.*/
-#if ENABLE_MALICIOUS
-  if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
-                                            &successor.next_hop))
-  {
-    struct FingerInfo *next_hop_finger;
-    unsigned int i;
-
-    next_hop_finger = &finger_table[successor.finger_table_index];
-    for (i = 0; i < next_hop_finger->trails_count; i++)
-    {
-      if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
-      {
-        if(0 == next_hop_finger->trail_list[i].trail_length)
-        {
-           GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
-                                    best_known_dest, intermediate_trail_id, &next_hop,
-                                    0, 1, &my_identity, expiration_time,
-                                    data, data_size);
-           return;
-        }
-        next_hop = next_hop_finger->trail_list[i].trail_head->peer;
-        GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
-                                 best_known_dest,
-                                 next_hop_finger->trail_list[i].trail_id,
-                                 &next_hop, 0, 1, &my_identity,
-                                 expiration_time,
-                                 data, data_size);
-       }
-    }
-    return;
-  }
-#endif
  GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
                           best_known_dest, intermediate_trail_id, &next_hop,
                           0, 1, &my_identity, expiration_time,
@@ -2437,38 +2385,6 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
     return;
   }
 
-#if ENABLE_MALICIOUS
-  struct GNUNET_PeerIdentity next_hop;
-  if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
-                                            &successor.next_hop))
-  {
-    struct FingerInfo *next_hop_finger;
-    unsigned int i;
-
-    next_hop_finger = &finger_table[successor.finger_table_index];
-    for (i = 0; i < next_hop_finger->trails_count; i++)
-    {
-      if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
-      {
-        if(0 == next_hop_finger->trail_list[i].trail_length)
-        {
-           GDS_NEIGHBOURS_send_get (key, block_type, options,
-                                    desired_replication_level,
-                                    best_known_dest,intermediate_trail_id,
-                                    &successor.next_hop,
-                                    0, 1, &my_identity);
-           return;
-        }
-        next_hop = next_hop_finger->trail_list[i].trail_head->peer;
-        GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level,
-                                 best_known_dest,
-                                 next_hop_finger->trail_list[i].trail_id,
-                                 &next_hop, 0, 1, &my_identity);
-       }
-    }
-    return;
-  }
-#endif
   GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level,
                            best_known_dest,intermediate_trail_id, &successor.next_hop,
                            0, 1, &my_identity);
@@ -2558,7 +2474,7 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key,
   get_result->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_GET_RESULT);
   get_result->key = *key;
   get_result->querying_peer = *source_peer;
-  get_result->expiration_time = expiration;
+  get_result->expiration_time = GNUNET_TIME_absolute_hton (expiration);
   get_result->get_path_length = htonl (get_path_length);
   get_result->put_path_length = htonl (put_path_length);
   paths = (struct GNUNET_PeerIdentity *)&get_result[1];
@@ -2675,11 +2591,9 @@ compute_finger_identity_value (unsigned int finger_index)
  * finger identity through this random friend.
  *
  * @param cls closure for this task
- * @param tc the context under which the task is running
  */
 static void
-send_find_finger_trail_message (void *cls,
-                                const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_find_finger_trail_message (void *cls)
 {
   struct FriendInfo *target_friend;
   struct GNUNET_HashCode trail_id;
@@ -3220,12 +3134,11 @@ add_new_finger (struct GNUNET_PeerIdentity finger_identity,
  * Periodic task to verify current successor. There can be multiple trails to reach
  * to successor, choose the shortest one and send verify successor message
  * across that trail.
+ *
  * @param cls closure for this task
- * @param tc the context under which the task is running
  */
 static void
-send_verify_successor_message (void *cls,
-                               const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_verify_successor_message (void *cls)
 {
   struct FriendInfo *target_friend;
   struct GNUNET_HashCode trail_id;
@@ -3313,8 +3226,10 @@ send_verify_successor_message (void *cls,
   trail_id = trail->trail_id;
   if (NULL == GDS_ROUTING_get_next_hop(trail_id,GDS_ROUTING_SRC_TO_DEST))
   {
-    DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line",
-            GNUNET_i2s(&my_identity), GNUNET_h2s(&trail->trail_id), __LINE__);
+    DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line %u",
+          GNUNET_i2s (&my_identity),
+          GNUNET_h2s (&trail->trail_id),
+          __LINE__);
     GNUNET_break(0);
     return;
   }
@@ -3688,13 +3603,6 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
     GNUNET_break_op (0);
     return GNUNET_OK;
   }
-#if ENABLE_MALICIOUS
-  if(1 == act_malicious)
-  {
-    DEBUG("\n I AM MALICIOUS PUT_REQUEST_DROPPED for key = %ss",GNUNET_h2s(&put->key));
-    return GNUNET_OK;
-  }
-#endif
   GNUNET_STATISTICS_update (GDS_stats,
                             gettext_noop
                             ("# Bytes received from other peers"), (int64_t) msize,
@@ -3736,6 +3644,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
   {
     switch (GNUNET_BLOCK_evaluate (GDS_block_context,
                                    ntohl (put->block_type),
+                                   GNUNET_BLOCK_EO_NONE,
                                    NULL,    /* query */
                                    NULL, 0, /* bloom filer */
                                    NULL, 0, /* xquery */
@@ -3819,45 +3728,6 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
                               &(put->key),putlen, pp, ntohl (put->block_type),
                               payload_size, payload);
   }
-  else
-  {
-#if ENABLE_MALICIOUS
-  if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
-                                            &successor.next_hop))
-  {
-    struct FingerInfo *next_hop_finger;
-    unsigned int i;
-
-    next_hop_finger = &finger_table[successor.finger_table_index];
-    for (i = 0; i < next_hop_finger->trails_count; i++)
-    {
-      if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
-      {
-        if(0 == next_hop_finger->trail_list[i].trail_length)
-        {
-          GDS_NEIGHBOURS_send_put (&put->key,
-                                  ntohl (put->block_type),ntohl (put->options),
-                                  ntohl (put->desired_replication_level),
-                                  best_known_dest, intermediate_trail_id, &next_hop,
-                                  hop_count, putlen, pp,
-                                  GNUNET_TIME_absolute_ntoh (put->expiration_time),
-                                  payload, payload_size);
-          return GNUNET_OK;
-        }
-        next_hop = next_hop_finger->trail_list[i].trail_head->peer;
-        GDS_NEIGHBOURS_send_put (&put->key,
-                                 ntohl (put->block_type),ntohl (put->options),
-                                 ntohl (put->desired_replication_level),
-                                 best_known_dest,
-                                 next_hop_finger->trail_list[i].trail_id,
-                                 &next_hop, hop_count, putlen, pp,
-                                 GNUNET_TIME_absolute_ntoh (put->expiration_time),
-                                 payload, payload_size);
-       }
-    }
-    return GNUNET_OK;
-  }
-#endif
   GDS_NEIGHBOURS_send_put (&put->key,
                            ntohl (put->block_type),ntohl (put->options),
                            ntohl (put->desired_replication_level),
@@ -3865,7 +3735,6 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
                            hop_count, putlen, pp,
                            GNUNET_TIME_absolute_ntoh (put->expiration_time),
                            payload, payload_size);
-   }
   return GNUNET_OK;
 }
 
@@ -3918,13 +3787,6 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
     return GNUNET_YES;
   }
 
-#if ENABLE_MALICIOUS
-  if(1 == act_malicious)
-  {
-    DEBUG("I am malicious,GET_REQUEST_DROPPED for key = %s. \n",GNUNET_h2s(&get->key));
-    return GNUNET_OK;
-  }
-#endif
   current_best_known_dest = get->best_known_destination;
   received_intermediate_trail_id = get->intermediate_trail_id;
   get_path = (const struct GNUNET_PeerIdentity *)&get[1];
@@ -3998,37 +3860,6 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
   else
   {
 
-#if ENABLE_MALICIOUS
-  if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
-                                            &successor.next_hop))
-  {
-    struct FingerInfo *next_hop_finger;
-    unsigned int i;
-
-    next_hop_finger = &finger_table[successor.finger_table_index];
-    for (i = 0; i < next_hop_finger->trails_count; i++)
-    {
-      if(0 == next_hop_finger->trail_list[i].trail_length)
-      {
-        GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
-                                get->desired_replication_level, best_known_dest,
-                                intermediate_trail_id, &next_hop, hop_count,
-                                get_length, gp);
-        return GNUNET_OK;
-      }
-      if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
-      {
-        next_hop = next_hop_finger->trail_list[i].trail_head->peer;
-        GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
-                                 get->desired_replication_level, best_known_dest,
-                                 next_hop_finger->trail_list[i].trail_id,
-                                 &next_hop, hop_count,
-                                 get_length, gp);
-       }
-    }
-    return GNUNET_OK;
-  }
-#endif
     GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
                              get->desired_replication_level, best_known_dest,
                              intermediate_trail_id, &next_hop, hop_count,
@@ -4097,7 +3928,8 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer,
 
   if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_path[0]))))
   {
-    GDS_CLIENTS_handle_reply (get_result->expiration_time, &(get_result->key),
+    GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (get_result->expiration_time),
+                              &(get_result->key),
                               getlen, get_path, putlen,
                               put_path, get_result->type, payload_size, payload);
     return GNUNET_YES;
@@ -4120,7 +3952,8 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer,
     GDS_NEIGHBOURS_send_get_result (&(get_result->key), get_result->type,
                                     &get_path[current_path_index - 1],
                                     &(get_result->querying_peer), putlen, put_path,
-                                    getlen, get_path, get_result->expiration_time,
+                                    getlen, get_path,
+                                    GNUNET_TIME_absolute_ntoh (get_result->expiration_time),
                                     payload, payload_size);
     return GNUNET_YES;
   }
@@ -5075,10 +4908,10 @@ struct SendNotifyContext
   unsigned int num_retries_scheduled;
 };
 
+
 void
-send_notify_new_successor (void *cls,
-                           const struct GNUNET_SCHEDULER_TaskContext
-                           * tc);
+send_notify_new_successor (void *cls);
+
 
 /**
  * Check if the peer which sent us verify successor result message is still ours
@@ -5248,11 +5081,9 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
 
 
 void
-send_notify_new_successor (void *cls,
-                           const struct GNUNET_SCHEDULER_TaskContext
-                           * tc)
+send_notify_new_successor (void *cls)
 {
-  struct SendNotifyContext *ctx = (struct SendNotifyContext *) cls;
+  struct SendNotifyContext *ctx = cls;
 
   GDS_NEIGHBOURS_send_notify_new_successor (ctx->source_peer,
                                             ctx->successor,
@@ -5355,8 +5186,10 @@ handle_dht_p2p_verify_successor_result(void *cls,
   {
     /* Here it may happen that source peer has found a new successor, and removed
      the trail, Hence no entry found in the routing table. Fail silently.*/
-    DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line",
-            GNUNET_i2s(&my_identity), GNUNET_h2s(&trail_id), __LINE__);
+    DEBUG (" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line %u",
+           GNUNET_i2s (&my_identity),
+           GNUNET_h2s (&trail_id),
+           __LINE__);
     GNUNET_break_op(0);
     return GNUNET_OK;
   }
@@ -5776,8 +5609,10 @@ handle_dht_p2p_trail_teardown (void *cls, const struct GNUNET_PeerIdentity *peer
   next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction);
   if (NULL == next_hop)
   {
-    DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line",
-            GNUNET_i2s(&my_identity), GNUNET_h2s(&trail_id), __LINE__);
+    DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line %u",
+          GNUNET_i2s (&my_identity),
+          GNUNET_h2s(&trail_id),
+          __LINE__);
     GNUNET_break (0);
     return GNUNET_SYSERR;
   }
@@ -6165,10 +6000,6 @@ GDS_NEIGHBOURS_init (void)
     {NULL, 0, 0}
   };
 
-#if ENABLE_MALICIOUS
-  act_malicious = 0;
-#endif
-
   core_api =
     GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect,
                          &handle_core_disconnect, NULL, GNUNET_NO, NULL,