+ if (0 == memcmp(&d->id, peer, sizeof(struct GNUNET_PeerIdentity)))
+ return;
+
+ distance = get_atsi_distance(atsi);
+
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
+ d->shortname,
+ second_shortname,
+ distance);
+#endif
+
+ second_daemon = GNUNET_CONTAINER_multihashmap_get(peer_daemon_hash, &peer->hashPubKey);
+
+ if (second_daemon == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Couldn't find second peer!\n");
+ GNUNET_free(second_shortname);
+ return;
+ }
+#if !TEST_ALL
+ if (distance > 1)
+ {
+ temp_total_other_messages++;
+ temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
+ temp_context->peer1 = d;
+ temp_context->peer2 = second_daemon;
+ temp_context->next = other_test_messages;
+ temp_context->uid = total_connections + temp_total_other_messages;
+ temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ other_test_messages = temp_context;
+ }
+#endif
+
+ if (dotOutFile != NULL)
+ {
+ if (distance == 1)
+ fprintf(dotOutFile, "\tn%s -- n%s;\n", d->shortname, second_shortname);
+ else if (distance == 2)
+ fprintf(dotOutFile, "\tn%s -- n%s [color=blue];\n", d->shortname, second_shortname);
+ else if (distance == 3)
+ fprintf(dotOutFile, "\tn%s -- n%s [color=red];\n", d->shortname, second_shortname);
+ else if (distance == 4)
+ fprintf(dotOutFile, "\tn%s -- n%s [color=green];\n", d->shortname, second_shortname);
+ else
+ fprintf(dotOutFile, "\tn%s -- n%s [color=brown];\n", d->shortname, second_shortname);
+ }
+ GNUNET_free(second_shortname);
+
+ if (temp_total_other_messages == num_additional_messages)
+ {
+ GNUNET_SCHEDULER_add_now (&send_other_messages, NULL);
+ }
+}
+
+static void
+peers_started_callback (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
+{
+ struct PeerContext *new_peer;
+ if (emsg != NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
+ emsg);
+ return;
+ }
+ GNUNET_assert (id != NULL);
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
+ (num_peers - peers_left) + 1, num_peers);
+#endif
+ GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put(peer_daemon_hash, &id->hashPubKey, d, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+
+ new_peer = GNUNET_malloc(sizeof(struct PeerContext));
+ new_peer->peer_handle = GNUNET_CORE_connect(cfg,
+ 1,
+ d, NULL,
+ &all_connect_handler,
+ NULL, NULL, NULL,
+ GNUNET_NO, NULL, GNUNET_NO,
+ no_handlers);
+ new_peer->daemon = d;
+ new_peer->next = all_peers;
+ all_peers = new_peer;
+ peers_left--;
+
+ if (peers_left == 0)
+ {
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All %d daemons started, now creating topology!\n",
+ num_peers);
+#endif
+ GNUNET_SCHEDULER_cancel (die_task);
+ /* Set up task in case topology creation doesn't finish
+ * within a reasonable amount of time */
+ die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 5),
+ &end_badly, "from peers_started_callback");
+
+ connect_topology ();
+ ok = 0;
+ }
+}
+
+/**
+ * Callback indicating that the hostkey was created for a peer.
+ *
+ * @param cls NULL
+ * @param id the peer identity
+ * @param d the daemon handle (pretty useless at this point, remove?)
+ * @param emsg non-null on failure
+ */
+void hostkey_callback (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ struct GNUNET_TESTING_Daemon *d,
+ const char *emsg)
+{
+ if (emsg != NULL)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
+ }