core connect change, forgotten dht driver change
authorNathan S. Evans <evans@in.tum.de>
Tue, 21 Dec 2010 13:52:30 +0000 (13:52 +0000)
committerNathan S. Evans <evans@in.tum.de>
Tue, 21 Dec 2010 13:52:30 +0000 (13:52 +0000)
src/dht/gnunet-dht-driver.c
src/dht/gnunet-service-dht.c

index a1eb36bcb404c6624817fd9f6dfe26334c06cd73..bfab4a38876ec49ac8ee4948863be97b2c1c2293 100644 (file)
@@ -500,6 +500,12 @@ static unsigned int replicate_same;
  */
 static unsigned int get_from_same;
 
+/**
+ * Should malicious peers be set after allowing for settle time?
+ * Default is to set them malicious after initial connection setup.
+ */
+static unsigned int malicious_after_settle;
+
 /**
  * Number of rounds for testing (PUTS + GETS)
  */
@@ -1933,6 +1939,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
 static void
 schedule_find_peer_requests (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
 
+static void
+setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
+
 /**
  * Given a number of total peers and a bucket size, estimate the number of
  * connections in a perfect kademlia topology.
@@ -1993,6 +2002,9 @@ count_peers_cb (void *cls,
           GNUNET_CONTAINER_heap_destroy(find_peer_context->peer_min_heap);
           GNUNET_free(find_peer_context);
           fprintf(stderr, "Not sending any more find peer requests.\n");
+
+          if (GNUNET_YES == malicious_after_settle)
+            GNUNET_SCHEDULER_add_now(&setup_malicious_peers, NULL);
         }
     }
 }
@@ -2324,8 +2336,11 @@ setup_malicious_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc
     }
   else /* Otherwise, continue testing */
     {
-      GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Scheduling continue_puts_and_gets now!\n");
-      GNUNET_SCHEDULER_add_now (&continue_puts_and_gets, NULL);
+      if (cls != NULL)
+        {
+          GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Scheduling continue_puts_and_gets now!\n");
+          GNUNET_SCHEDULER_add_now (&continue_puts_and_gets, NULL);
+        }
     }
 }
 
@@ -2390,21 +2405,22 @@ topology_callback (void *cls,
         }
 
       GNUNET_SCHEDULER_cancel (die_task);
-      /*die_task = GNUNET_SCHEDULER_add_delayed (DEFAULT_TIMEOUT,
-                                               &end_badly, "from setup puts/gets");*/
+
       if ((dhtlog_handle != NULL) && (settle_time > 0))
         {
           topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
-          topo_ctx->cont = &setup_malicious_peers;
+          if (GNUNET_YES == malicious_after_settle) /* Don't set malicious peers until after settle_time */
+            topo_ctx->cont = &continue_puts_and_gets;
+          else /* Set malicious peers now */
+            topo_ctx->cont = &setup_malicious_peers;
           topo_ctx->peers_seen = GNUNET_CONTAINER_multihashmap_create(num_peers);
-          //topo_ctx->cont = &continue_puts_and_gets;
+          topo_ctx->cls = NULL;
+          //
           GNUNET_SCHEDULER_add_now(&capture_current_topology, topo_ctx);
         }
       else
         {
-          GNUNET_SCHEDULER_add_now(&setup_malicious_peers, NULL);
-          /*GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time),
-                                        &continue_puts_and_gets, NULL);*/
+          GNUNET_SCHEDULER_add_now(&setup_malicious_peers, &continue_puts_and_gets);
         }
     }
   else if (total_connections + failed_connections == expected_connections)
@@ -2921,6 +2937,8 @@ run (void *cls,
                                                        &malicious_put_frequency))
     malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
 
+  if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "DHT_TESTING", "MALICIOUS_AFTER_SETTLE"))
+    malicious_after_settle = GNUNET_YES;
 
   /* The normal behavior of the DHT is to do find peer requests
    * on its own.  Only if this is explicitly turned off should
index a621e8e82d87214c468111638388d1017c2b865d..13fda66aee35fe770be6d78341cf9ba954d9dc29 100644 (file)
@@ -4929,6 +4929,10 @@ handle_core_connect (void *cls,
 {
   struct PeerInfo *ret;
 
+  /* Check for connect to self message */
+  if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+    return;
+
 #if DEBUG_DHT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "%s:%s Receives core connect message for peer %s distance %d!\n",
@@ -4978,6 +4982,10 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
   struct PeerInfo *to_remove;
   int current_bucket;
 
+  /* Check for disconnect from self message */
+  if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+    return;
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "%s:%s: Received peer disconnect message for peer `%s' from %s\n",
               my_short_id, "DHT", GNUNET_i2s (peer), "CORE");