HOME = $SERVICEHOME
CONFIG = $DEFAULTCONFIG
BINARY = gnunet-service-transport
+#PREFIX = valgrind
NEIGHBOUR_LIMIT = 50
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;
#include "dht.h"
#include "gauger.h"
-/* Specific DEBUG hack, do not use normally (may leak memory, segfault, or eat children.) */
-#define ONLY_TESTING GNUNET_NO
-
/* DEFINES */
#define VERBOSE GNUNET_NO
*/
struct GNUNET_CONTAINER_MultiHashMap *peer_hash;
+ /**
+ * Handle to an active attempt to connect this peer.
+ */
+ struct GNUNET_TESTING_ConnectContext *cc;
+
/**
* Min heap which orders values in the peer_hash for
* easy lookup.
*/
static unsigned int insert_gauger_data;
-#if ONLY_TESTING
-/**
- * Are we currently trying to connect two peers repeatedly?
- */
-static unsigned int repeat_connect_mode;
-
-/**
- * Task for repeating connects.
- */
-GNUNET_SCHEDULER_TaskIdentifier repeat_connect_task;
-
-struct GNUNET_TESTING_Daemon *repeat_connect_peer1;
-struct GNUNET_TESTING_Daemon *repeat_connect_peer2;
-#endif
-
/**
* Boolean value, should replication be done by the dht
* service (GNUNET_YES) or by the driver (GNUNET_NO)
*/
static unsigned long long gets_failed;
+#ifndef HAVE_MALICIOUS
/**
* How many malicious control messages do
* we currently have in flight?
* How many set malicious peers are done?
*/
static unsigned int malicious_completed;
+#endif
/**
* For gauger logging, what specific identifier (svn revision)
}
}
+static void
+did_connect (void *cls,
+ const struct
+ GNUNET_PeerIdentity * first,
+ const struct
+ GNUNET_PeerIdentity * second,
+ uint32_t distance,
+ const struct
+ GNUNET_CONFIGURATION_Handle *
+ first_cfg,
+ const struct
+ GNUNET_CONFIGURATION_Handle *
+ second_cfg,
+ struct GNUNET_TESTING_Daemon *
+ first_daemon,
+ struct GNUNET_TESTING_Daemon *
+ second_daemon,
+ const char *emsg)
+{
+ struct FindPeerContext *find_peer_context = cls;
+
+ find_peer_context->cc = NULL;
+}
+
/**
* Iterate over min heap of connections per peer. For any
* peer that has 0 connections, attempt to connect them to
d1 = GNUNET_TESTING_daemon_get_by_id (pg, &peer_count->peer_id);
GNUNET_assert (d1 != NULL);
d2 = d1;
- while ((d2 == d1) || (GNUNET_YES != GNUNET_TESTING_daemon_running (d2)))
+ while ((d2 == d1) || (GNUNET_YES != GNUNET_TESTING_test_daemon_running (d2)))
{
d2 = GNUNET_TESTING_daemon_get (pg,
GNUNET_CRYPTO_random_u32
{
timeout = GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime);
}
- GNUNET_TESTING_daemons_connect (d1, d2, timeout, DEFAULT_RECONNECT_ATTEMPTS,
- GNUNET_YES, NULL, NULL);
+ if (NULL != find_peer_context->cc)
+ GNUNET_TESTING_daemons_connect_cancel (find_peer_context->cc);
+ find_peer_context->cc = GNUNET_TESTING_daemons_connect (d1, d2, timeout, DEFAULT_RECONNECT_ATTEMPTS,
+ GNUNET_YES,
+ &did_connect,
+ find_peer_context);
}
if (GNUNET_TIME_absolute_get_remaining (find_peer_context->endtime).rel_value
> 0)
return GNUNET_YES;
- else
- return GNUNET_NO;
+ return GNUNET_NO;
}
/**
find_peer_context);
GNUNET_CONTAINER_multihashmap_destroy (find_peer_context->peer_hash);
GNUNET_CONTAINER_heap_destroy (find_peer_context->peer_min_heap);
+ if (NULL != find_peer_context->cc)
+ GNUNET_TESTING_daemons_connect_cancel (find_peer_context->cc);
GNUNET_free (find_peer_context);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Churn round %u of %llu finished, scheduling next GET round.\n",
for (i = 0; i < num_peers; i++)
{
temp_daemon = GNUNET_TESTING_daemon_get (pg, i);
- if (GNUNET_YES == GNUNET_TESTING_daemon_running (temp_daemon))
+ if (GNUNET_YES == GNUNET_TESTING_test_daemon_running (temp_daemon))
{
peer_count = GNUNET_malloc (sizeof (struct PeerCount));
memcpy (&peer_count->peer_id, &temp_daemon->id,
/* Set this here in case we are re-running gets */
test_get->succeeded = GNUNET_NO;
- if (GNUNET_YES != GNUNET_TESTING_daemon_running (test_get->daemon)) /* If the peer has been churned off, don't try issuing request from it! */
+ if (GNUNET_YES != GNUNET_TESTING_test_daemon_running (test_get->daemon)) /* If the peer has been churned off, don't try issuing request from it! */
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer we should issue get request from is down, skipping.\n");
if (test_put == NULL)
return; /* End of list */
- if (GNUNET_YES != GNUNET_TESTING_daemon_running (test_put->daemon)) /* If the peer has been churned off, don't try issuing request from it! */
+ if (GNUNET_YES != GNUNET_TESTING_test_daemon_running (test_put->daemon)) /* If the peer has been churned off, don't try issuing request from it! */
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer we should issue put request at is down, skipping.\n");
find_peer_context);
GNUNET_CONTAINER_multihashmap_destroy (find_peer_context->peer_hash);
GNUNET_CONTAINER_heap_destroy (find_peer_context->peer_min_heap);
+ if (NULL != find_peer_context->cc)
+ GNUNET_TESTING_daemons_connect_cancel (find_peer_context->cc);
GNUNET_free (find_peer_context);
fprintf (stderr, "Not sending any more find peer requests.\n");
}
}
+#if HAVE_MALICIOUS
/**
* Task to release DHT handles
*/
}
}
-#if HAVE_MALICIOUS
/**
* Task to release DHT handles
*/
temp_daemon = GNUNET_TESTING_daemon_get (pg, i);
hash_from_uid (i, &uid_hash);
/* Check if this peer matches the bloomfilter */
- if ((GNUNET_NO == GNUNET_TESTING_daemon_running (temp_daemon)) ||
+ if ((GNUNET_NO == GNUNET_TESTING_test_daemon_running (temp_daemon)) ||
(GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bloom, &uid_hash)))
continue;
}
#endif
-#if ONLY_TESTING
-/* Forward declaration */
-static void
-topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second, uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg);
-
-/**
- * Retry connecting two specific peers until they connect,
- * at a specific interval. These two peers previously failed
- * to connect, and we hope they continue to so that we can
- * debug the reason they are having issues.
- */
-static void
-repeat_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Repeating connect attempt between %s and %s.\n",
- repeat_connect_peer1->shortname, repeat_connect_peer2->shortname);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peer 1 configuration `%s'\n",
- repeat_connect_peer1->cfgfile);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peer 2 configuration `%s'\n",
- repeat_connect_peer2->cfgfile);
-
- repeat_connect_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_TESTING_daemons_connect (repeat_connect_peer1, repeat_connect_peer2,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 60), 2,
- &topology_callback, NULL);
-}
-#endif
-
/**
* This function is called whenever a connection attempt is finished between two of
* the started peers (started with GNUNET_TESTING_daemons_start). The total
char *temp_conn_failed_string;
char *revision_str;
-#if ONLY_TESTING
- if (repeat_connect_mode == GNUNET_YES)
- {
- if ((first_daemon == repeat_connect_peer1) &&
- (second_daemon == repeat_connect_peer2))
- {
- if (emsg != NULL) /* Peers failed to connect again! */
- {
- GNUNET_assert (repeat_connect_task == GNUNET_SCHEDULER_NO_TASK);
- repeat_connect_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 60),
- &repeat_connect, NULL);
- return;
- }
- else /* Repeat peers actually connected! */
- {
- if (repeat_connect_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (repeat_connect_task);
- repeat_connect_peer1 = NULL;
- repeat_connect_peer2 = NULL;
- repeat_connect_mode = GNUNET_NO;
- GNUNET_TESTING_resume_connections (pg);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Resuming normal connection mode, debug connection was successful!\n");
- }
- }
- }
-#endif
-
if (GNUNET_TIME_absolute_get_difference
(connect_last_time,
GNUNET_TIME_absolute_get ()).rel_value >
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"have %llu total_connections, %llu failed\n", total_connections,
failed_connections);
-#if ONLY_TESTING
- /* These conditions likely mean we've entered the death spiral of doom */
- if ((total_connections > 20000) && (conns_per_sec_recent < 5.0) &&
- (conns_per_sec_total > 10.0) && (emsg != NULL) &&
- (repeat_connect_mode == GNUNET_NO))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Entering repeat connection attempt mode!\n");
- repeat_connect_peer1 = first_daemon;
- repeat_connect_peer2 = second_daemon;
- repeat_connect_mode = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Stopping NEW connections from being scheduled!\n");
- GNUNET_TESTING_stop_connections (pg);
- repeat_connect_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 60),
- &repeat_connect, NULL);
- }
-#endif
}
if (emsg == NULL)
#endif
}
-#if ONLY_TESTING
- if ((repeat_connect_mode == GNUNET_YES))
- return;
-#endif
-
GNUNET_assert (peer_connect_meter != NULL);
if (GNUNET_YES == update_meter (peer_connect_meter))
{
}
-struct ConnectContext
+struct GNUNET_FS_TEST_ConnectContext
{
GNUNET_SCHEDULER_Task cont;
void *cont_cls;
+ struct GNUNET_TESTING_ConnectContext *cc;
};
struct GNUNET_TESTING_Daemon *second_daemon,
const char *emsg)
{
- struct ConnectContext *cc = cls;
+ struct GNUNET_FS_TEST_ConnectContext *cc = cls;
+ cc->cc = NULL;
if (emsg != NULL)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to connect peers: %s\n",
emsg);
* @param cont function to call when done
* @param cont_cls closure for cont
*/
-void
+struct GNUNET_FS_TEST_ConnectContext *
GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
struct GNUNET_FS_TestDaemon *daemon2,
struct GNUNET_TIME_Relative timeout,
GNUNET_SCHEDULER_Task cont, void *cont_cls)
{
- struct ConnectContext *ncc;
+ struct GNUNET_FS_TEST_ConnectContext *ncc;
- ncc = GNUNET_malloc (sizeof (struct ConnectContext));
+ ncc = GNUNET_malloc (sizeof (struct GNUNET_FS_TEST_ConnectContext));
ncc->cont = cont;
ncc->cont_cls = cont_cls;
- GNUNET_TESTING_daemons_connect (daemon1->daemon, daemon2->daemon, timeout,
- CONNECT_ATTEMPTS, GNUNET_YES,
- ¬ify_connection, ncc);
+ ncc->cc = GNUNET_TESTING_daemons_connect (daemon1->daemon, daemon2->daemon, timeout,
+ CONNECT_ATTEMPTS, GNUNET_YES,
+ ¬ify_connection, ncc);
+ return ncc;
+}
+
+
+/**
+ * Cancel connect operation.
+ *
+ * @param cc operation to cancel
+ */
+void
+GNUNET_FS_TEST_daemons_connect_cancel (struct GNUNET_FS_TEST_ConnectContext *cc)
+{
+ GNUNET_TESTING_daemons_connect_cancel (cc->cc);
+ GNUNET_free (cc);
}
GNUNET_SCHEDULER_Task cont, void *cont_cls);
+struct GNUNET_FS_TEST_ConnectContext;
+
+
/**
* Connect two daemons for testing.
*
* @param cont function to call when done
* @param cont_cls closure for cont
*/
-void
+struct GNUNET_FS_TEST_ConnectContext *
GNUNET_FS_TEST_daemons_connect (struct GNUNET_FS_TestDaemon *daemon1,
struct GNUNET_FS_TestDaemon *daemon2,
struct GNUNET_TIME_Relative timeout,
GNUNET_SCHEDULER_Task cont, void *cont_cls);
+/**
+ * Cancel connect operation.
+ *
+ * @param cc operation to cancel
+ */
+void
+GNUNET_FS_TEST_daemons_connect_cancel (struct GNUNET_FS_TEST_ConnectContext *cc);
+
+
/**
* Obtain peer group used for testing.
*
static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
+static struct GNUNET_FS_TEST_ConnectContext *cc;
+
static int ret;
static void
do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ if (NULL != cc)
+ {
+ GNUNET_FS_TEST_daemons_connect_cancel (cc);
+ cc = NULL;
+ }
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
{
GNUNET_break (0);
static void
do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ cc = NULL;
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
{
GNUNET_break (0);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Daemons started, will now try to connect them\n");
- GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, &do_publish,
- NULL);
+ cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, &do_publish,
+ NULL);
}
static struct GNUNET_TIME_Absolute start_time;
+static struct GNUNET_FS_TEST_ConnectContext *cc;
+
static void
do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TIME_Relative del;
char *fancy;
-
+
+ if (NULL != cc)
+ {
+ GNUNET_FS_TEST_daemons_connect_cancel (cc);
+ cc = NULL;
+ }
GNUNET_FS_TEST_daemons_stop (2, daemons);
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
{
static void
do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ cc = NULL;
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
{
GNUNET_FS_TEST_daemons_stop (2, daemons);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Daemons started, will now try to connect them\n");
- GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, &do_publish,
- NULL);
+ cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, &do_publish,
+ NULL);
}
static struct GNUNET_TIME_Absolute start_time;
+static struct GNUNET_FS_TEST_ConnectContext *cc;
+
static void
do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_TIME_Relative del;
char *fancy;
+ if (NULL != cc)
+ {
+ GNUNET_FS_TEST_daemons_connect_cancel (cc);
+ cc = NULL;
+ }
GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
{
static void
do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ cc = NULL;
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
{
GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Daemons started, will now try to connect them\n");
- GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, &do_publish,
- NULL);
+ cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, &do_publish,
+ NULL);
}
second_daemon,
const char *emsg);
+
/**
* Prototype of a callback function indicating that two peers
* are currently connected.
* Check whether the given daemon is running.
*
* @param daemon the daemon to check
- *
* @return GNUNET_YES if the daemon is up, GNUNET_NO if the
* daemon is down, GNUNET_SYSERR on error.
*/
int
-GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon);
+GNUNET_TESTING_test_daemon_running (struct GNUNET_TESTING_Daemon *daemon);
/**
*/
void
GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d,
- char *service,
+ const char *service,
struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_NotifyDaemonRunning cb,
void *cb_cls);
*/
void
GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d,
- char *service,
+ const char *service,
struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_NotifyCompletion cb,
void *cb_cls);
/**
- * Establish a connection between two GNUnet daemons.
+ * Handle for an active request to connect two peers.
+ */
+struct GNUNET_TESTING_ConnectContext;
+
+
+/**
+ * Establish a connection between two GNUnet daemons. The daemons
+ * must both be running and not be stopped until either the
+ * 'cb' callback is called OR the connection request has been
+ * explicitly cancelled.
*
* @param d1 handle for the first daemon
* @param d2 handle for the second daemon
* the HELLO has already been exchanged
* @param cb function to call at the end
* @param cb_cls closure for cb
+ * @return handle to cancel the request, NULL on error
*/
-void /* struct GNUNET_TESTING_ConnectContext * */
+struct GNUNET_TESTING_ConnectContext *
GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
struct GNUNET_TESTING_Daemon *d2,
struct GNUNET_TIME_Relative timeout,
void *cb_cls);
-#if 0
+
/**
* Cancel an attempt to connect two daemons.
*
void
GNUNET_TESTING_daemons_connect_cancel (struct GNUNET_TESTING_ConnectContext
*cc);
-#endif
+
/**
current_peer = GNUNET_malloc (sizeof (struct NSEPeer));
current_peer->daemon = GNUNET_TESTING_daemon_get (pg, i);
if (GNUNET_YES ==
- GNUNET_TESTING_daemon_running (GNUNET_TESTING_daemon_get (pg, i)))
+ GNUNET_TESTING_test_daemon_running (GNUNET_TESTING_daemon_get (pg, i)))
{
current_peer->nse_handle =
GNUNET_NSE_connect (current_peer->daemon->cfg, &handle_estimate,
static struct GNUNET_CONFIGURATION_Handle *c2;
+static struct GNUNET_TESTING_ConnectContext *cc;
+
static void
end2_cb (void *cls, const char *emsg)
{
struct GNUNET_TESTING_Daemon *second_daemon,
const char *emsg)
{
+ cc = NULL;
GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon `%s' started.\n",
GNUNET_i2s (id));
#endif
- GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, CONNECT_ATTEMPTS, GNUNET_YES,
- &my_connect_complete, NULL);
+ cc = GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, CONNECT_ATTEMPTS, GNUNET_YES,
+ &my_connect_complete, NULL);
}
static struct GNUNET_CONFIGURATION_Handle *c2;
+static struct GNUNET_TESTING_ConnectContext *cc;
+
/**
* How many start-connect-stop iterations should we do?
*/
* stopping them again.
*/
static void
-run_phase ();
+run_phase (void);
static void
end2_cb (void *cls, const char *emsg)
struct GNUNET_TESTING_Daemon *second_daemon,
const char *emsg)
{
+ cc = NULL;
#if VERBOSE
fprintf (stderr, "Peer %s ", GNUNET_i2s (first));
fprintf (stderr, "connected to %s\n", GNUNET_i2s (second));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon `%s' started.\n",
GNUNET_i2s (id));
#endif
- GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, CONNECT_ATTEMPTS, GNUNET_YES,
- &my_connect_complete, NULL);
+ cc = GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, CONNECT_ATTEMPTS, GNUNET_YES,
+ &my_connect_complete, NULL);
}
#define DEBUG_TESTING_RECONNECT GNUNET_NO
-#define WAIT_FOR_HELLO GNUNET_NO
-
/**
* Hack to deal with initial HELLO's being often devoid of addresses.
* This hack causes 'process_hello' to ignore HELLOs without addresses.
{
struct GNUNET_TESTING_Daemon *daemon = cls;
int msize;
-
-#if WAIT_FOR_HELLO
- GNUNET_TESTING_NotifyDaemonRunning cb;
-#endif
#if EMPTY_HACK
int empty;
return;
}
#endif
- if (daemon == NULL)
- return;
-
GNUNET_assert (daemon->phase == SP_GET_HELLO ||
daemon->phase == SP_START_DONE);
-#if WAIT_FOR_HELLO
- cb = daemon->cb;
-#endif
daemon->cb = NULL;
if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */
GNUNET_SCHEDULER_cancel (daemon->task);
daemon->th = NULL;
}
daemon->phase = SP_START_DONE;
-
-#if WAIT_FOR_HELLO
- if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */
- cb (daemon->cb_cls, &daemon->id, daemon->cfg, daemon, NULL);
-#endif
}
static void
start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-#if WAIT_FOR_HELLO
-/**
- * Function called after GNUNET_CORE_connect has succeeded
- * (or failed for good). Note that the private key of the
- * peer is intentionally not exposed here; if you need it,
- * your process should try to read the private key file
- * directly (which should work if you are authorized...).
- *
- * @param cls closure
- * @param server handle to the server, NULL if we failed
- * @param my_identity ID of this peer, NULL if we failed
- * @param publicKey public key of this peer, NULL if we failed
- */
-static void
-testing_init (void *cls, struct GNUNET_CORE_Handle *server,
- const struct GNUNET_PeerIdentity *my_identity,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
-{
- struct GNUNET_TESTING_Daemon *d = cls;
-
- GNUNET_assert (d->phase == SP_START_CORE);
- d->phase = SP_GET_HELLO;
-
- if (server == NULL)
- {
- d->server = NULL;
- if (GNUNET_YES == d->dead)
- GNUNET_TESTING_daemon_stop (d,
- GNUNET_TIME_absolute_get_remaining
- (d->max_timeout), d->dead_cb, d->dead_cb_cls,
- GNUNET_YES, GNUNET_NO);
- else if (NULL != d->cb)
- d->cb (d->cb_cls, NULL, d->cfg, d,
- _("Failed to connect to core service\n"));
- return;
- }
-#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully started peer `%4s'.\n",
- GNUNET_i2s (my_identity));
-#endif
- d->id = *my_identity; /* FIXME: shouldn't we already have this from reading the hostkey file? */
- if (d->shortname == NULL)
- d->shortname = strdup (GNUNET_i2s (my_identity));
- d->server = server;
- d->running = GNUNET_YES;
-
- if (GNUNET_NO == d->running)
- {
-#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer is dead (d->running == GNUNET_NO)\n");
-#endif
- return;
- }
-#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully started peer `%4s', connecting to transport service.\n",
- GNUNET_i2s (my_identity));
-#endif
-
- d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL);
- if (d->th == NULL)
- {
- if (GNUNET_YES == d->dead)
- GNUNET_TESTING_daemon_stop (d,
- GNUNET_TIME_absolute_get_remaining
- (d->max_timeout), d->dead_cb, d->dead_cb_cls,
- GNUNET_YES, GNUNET_NO);
- else if (NULL != d->cb)
- d->cb (d->cb_cls, &d->id, d->cfg, d,
- _("Failed to connect to transport service!\n"));
- return;
- }
-#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected to transport service `%s', getting HELLO\n",
- GNUNET_i2s (my_identity));
-#endif
-
- d->ghh = GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
- /* wait some more */
- if (d->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (d->task);
- d->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d);
-}
-#endif
-
-#if !WAIT_FOR_HELLO
/**
* Notify of a peer being up and running. Scheduled as a task
* so that variables which may need to be set are set before
if (NULL != cb)
cb (d->cb_cls, &d->id, d->cfg, d, NULL);
}
-#endif
+
/**
* Finite-state machine for starting GNUnet.
if (d->server != NULL)
GNUNET_CORE_disconnect (d->server);
-#if WAIT_FOR_HELLO
- if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls, NULL, d->cfg, d,
- _("Unable to connect to CORE service for peer!\n"));
- GNUNET_CONFIGURATION_destroy (d->cfg);
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free (d);
- return;
- }
- d->server =
- GNUNET_CORE_connect (d->cfg, 1, d, &testing_init, NULL, NULL, NULL,
- NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers);
- d->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_CONSTANTS_SERVICE_RETRY, 2),
- &start_fsm, d);
-#else
d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL);
if (d->th == NULL)
{
#endif
d->ghh = GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
+ /* FIXME: store task ID somewhere! */
GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d);
/*cb = d->cb;
* d->cb = NULL;
* cb (d->cb_cls, &d->id, d->cfg, d, NULL); */
d->running = GNUNET_YES;
d->phase = SP_GET_HELLO;
-#endif
break;
case SP_GET_HELLO:
if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
* daemon is down, GNUNET_SYSERR on error.
*/
int
-GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon)
+GNUNET_TESTING_test_daemon_running (struct GNUNET_TESTING_Daemon *daemon)
{
if (daemon == NULL)
return GNUNET_SYSERR;
*/
void
GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d,
- char *service,
+ const char *service,
struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_NotifyDaemonRunning cb,
void *cb_cls)
daemon->cb_cls = cb_cls;
daemon->phase = SP_TOPOLOGY_SETUP;
daemon->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
-
+ /* FIXME: why add_continuation? */
GNUNET_SCHEDULER_add_continuation (&start_fsm, daemon,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
"No need to copy configuration file since we are running locally.\n");
#endif
ret->phase = SP_COPIED;
+ /* FIXME: why add_cont? */
GNUNET_SCHEDULER_add_continuation (&start_fsm, ret,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
*/
void
GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d,
- char *service,
+ const char *service,
struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_NotifyCompletion cb,
void *cb_cls)
* Data kept for each pair of peers that we try
* to connect.
*/
-struct ConnectContext
+struct GNUNET_TESTING_ConnectContext
{
/**
* Testing handle to the first daemon.
* Notify callback about success or failure of the attempt
* to connect the two peers
*
- * @param cls our "struct ConnectContext" (freed)
+ * @param cls our "struct GNUNET_TESTING_ConnectContext" (freed)
* @param tc reason tells us if we succeeded or failed
*/
static void
notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct ConnectContext *ctx = cls;
+ struct GNUNET_TESTING_ConnectContext *ctx = cls;
ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
ctx->d1th = NULL;
if (ctx->d1core != NULL)
GNUNET_CORE_disconnect (ctx->d1core);
-#if CONNECT_CORE2
- if (ctx->d2core != NULL)
- GNUNET_CORE_disconnect (ctx->d2core);
- ctx->d2core = NULL;
-#endif
ctx->d1core = NULL;
GNUNET_free (ctx);
return;
else if (ctx->connect_attempts > 0)
{
ctx->d1core_ready = GNUNET_NO;
-#if CONNECT_CORE2
- if (ctx->d2core != NULL)
- {
- GNUNET_CORE_disconnect (ctx->d2core);
- ctx->d2core = NULL;
- }
-#endif
- GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx);
+ ctx->timeout_task = GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx);
return;
}
else
ctx->d2->cfg, ctx->d1, ctx->d2, _("Peers failed to connect"));
}
}
-
GNUNET_free (ctx);
}
/**
* Success, connection is up. Signal client our success.
*
- * @param cls our "struct ConnectContext"
+ * @param cls our "struct GNUNET_TESTING_ConnectContext"
* @param peer identity of the peer that has connected
* @param atsi performance information
*
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
- struct ConnectContext *ctx = cls;
+ struct GNUNET_TESTING_ConnectContext *ctx = cls;
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Connected peer %s to peer %s\n",
ctx->d1->shortname, GNUNET_i2s (peer));
#endif
- if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))
- {
-
- ctx->connected = GNUNET_YES;
- ctx->distance = 0; /* FIXME: distance */
- if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
+ if (0 != memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))
+ return;
+ ctx->connected = GNUNET_YES;
+ ctx->distance = 0; /* FIXME: distance */
+ if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (ctx->hello_send_task);
ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
}
- GNUNET_SCHEDULER_cancel (ctx->timeout_task);
- ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx);
- }
-}
-
-#if CONNECT_CORE2
-/**
- * Success, connection is up. Signal client our success.
- *
- * @param cls our "struct ConnectContext"
- * @param peer identity of the peer that has connected
- * @param atsi performance information
- *
- */
-static void
-connect_notify_core2 (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
-{
- struct ConnectContext *ctx = cls;
-
- if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0)
- {
- ctx->connected = GNUNET_YES;
- ctx->distance = 0; /* FIXME: distance */
- GNUNET_SCHEDULER_cancel (ctx->timeout_task);
- ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx);
- }
-
+ GNUNET_SCHEDULER_cancel (ctx->timeout_task);
+ ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx);
}
-#endif
/**
* Task called once a core connect request has been transmitted.
*
- * @param cls struct ConnectContext
+ * @param cls struct GNUNET_TESTING_ConnectContext
* @param success was the request successful?
*/
void
core_connect_request_cont (void *cls, int success)
{
- struct ConnectContext *ctx = cls;
+ struct GNUNET_TESTING_ConnectContext *ctx = cls;
ctx->connect_request_handle = NULL;
}
static void
send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct ConnectContext *ctx = cls;
+ struct GNUNET_TESTING_ConnectContext *ctx = cls;
struct GNUNET_MessageHeader *hello;
ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
*publicKey)
{
- struct ConnectContext *connect_ctx = cls;
+ struct GNUNET_TESTING_ConnectContext *connect_ctx = cls;
connect_ctx->d1core_ready = GNUNET_YES;
reattempt_daemons_connect (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct ConnectContext *ctx = cls;
+ struct GNUNET_TESTING_ConnectContext *ctx = cls;
+ ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- GNUNET_free (ctx);
return;
- }
#if DEBUG_TESTING_RECONNECT
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"re-attempting connect of peer %s to peer %s\n",
_("Failed to connect to transport service!\n"));
return;
}
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ctx->hello_send_task);
ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
}
else
* that we don't try to send duplicate connect
* requests to core.
*
- * @param cls our "struct ConnectContext"
+ * @param cls our "struct GNUNET_TESTING_ConnectContext"
* @param peer identity of the peer that has connected,
* NULL when iteration has finished
* @param atsi performance information
core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
- struct ConnectContext *ctx = cls;
+ struct GNUNET_TESTING_ConnectContext *ctx = cls;
if ((peer != NULL) &&
(0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))))
ctx->distance = 0; /* FIXME: distance */
return;
}
- else if (peer == NULL) /* End of iteration over peers */
- {
+ if (peer != NULL)
+ return; /* ignore other peers */
+ /* peer == NULL: End of iteration over peers */
+
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ctx->timeout_task);
if (ctx->connected == GNUNET_YES)
{
ctx->timeout_task =
if (ctx->d1core == NULL)
{
- GNUNET_free (ctx);
- if (NULL != ctx->cb)
- ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
- ctx->d2->cfg, ctx->d1, ctx->d2,
- _("Failed to connect to core service of first peer!\n"));
+ ctx->timeout_task =
+ GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx);
return;
}
if (ctx->d2->th == NULL)
{
GNUNET_CORE_disconnect (ctx->d1core);
- GNUNET_free (ctx);
- if (NULL != ctx->cb)
- ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
- ctx->d2->cfg, ctx->d1, ctx->d2,
- _("Failed to connect to transport service!\n"));
+ ctx->d1core = NULL;
+ ctx->timeout_task =
+ GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx);
return;
}
ctx->d2->ghh =
if (ctx->d1th == NULL)
{
GNUNET_CORE_disconnect (ctx->d1core);
- GNUNET_free (ctx);
- if (NULL != ctx->cb)
- ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
- ctx->d2->cfg, ctx->d1, ctx->d2,
- _("Failed to connect to transport service!\n"));
+ ctx->d1core = NULL;
+ ctx->timeout_task =
+ GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx);
return;
}
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ctx->hello_send_task);
ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
}
ctx->timeout_task =
GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
¬ify_connect_result, ctx);
- }
+
}
/**
- * Establish a connection between two GNUnet daemons.
+ * Establish a connection between two GNUnet daemons. The daemons
+ * must both be running and not be stopped until either the
+ * 'cb' callback is called OR the connection request has been
+ * explicitly cancelled.
*
* @param d1 handle for the first daemon
* @param d2 handle for the second daemon
* the HELLO has already been exchanged
* @param cb function to call at the end
* @param cb_cls closure for cb
+ * @return handle to cancel the request
*/
-void
+struct GNUNET_TESTING_ConnectContext *
GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
struct GNUNET_TESTING_Daemon *d2,
struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_NotifyConnection cb,
void *cb_cls)
{
- struct ConnectContext *ctx;
+ struct GNUNET_TESTING_ConnectContext *ctx;
if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO))
{
cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2,
_("Peers are not fully running yet, can not connect!\n"));
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n");
- return;
+ return NULL;
}
- ctx = GNUNET_malloc (sizeof (struct ConnectContext));
+ ctx = GNUNET_malloc (sizeof (struct GNUNET_TESTING_ConnectContext));
ctx->d1 = d1;
ctx->d2 = d2;
ctx->timeout_hello =
GNUNET_assert (GNUNET_OK ==
GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id,
&core_initial_iteration, ctx));
- /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg, &core_initial_iteration, ctx)); */
+ return ctx;
}
+
+/**
+ * Cancel an attempt to connect two daemons.
+ *
+ * @param cc connect context
+ */
+void
+GNUNET_TESTING_daemons_connect_cancel (struct GNUNET_TESTING_ConnectContext
+ *cc)
+{
+ if (GNUNET_SCHEDULER_NO_TASK != cc->timeout_task)
+ {
+ GNUNET_SCHEDULER_cancel (cc->timeout_task);
+ cc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (GNUNET_SCHEDULER_NO_TASK != cc->hello_send_task)
+ {
+ GNUNET_SCHEDULER_cancel (cc->hello_send_task);
+ cc->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (NULL != cc->d1core)
+ {
+ GNUNET_CORE_disconnect (cc->d1core);
+ cc->d1core = NULL;
+ }
+ if (NULL != cc->d1th)
+ {
+ GNUNET_TRANSPORT_disconnect (cc->d1th);
+ cc->d1th = NULL;
+ }
+ GNUNET_free (cc);
+}
+
+
/* end of testing.c */
* @brief convenience API for writing testcases for GNUnet
* @author Nathan Evans
* @author Christian Grothoff
- *
*/
#include "platform.h"
#include "gnunet_constants.h"
void *notify_cls;
};
+struct ConnectContext;
+
/**
* Handle to a group of GNUnet peers.
*/
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct ConnectContext *cc_head;
+
+ struct ConnectContext *cc_tail;
+
/**
* Function to call on each started daemon.
*/
struct ConnectContext
{
+
+ struct ConnectContext *next;
+
+ struct ConnectContext *prev;
+
/**
* Index of peer to connect second to.
*/
*/
uint32_t second_index;
+ /**
+ * Task associated with the attempt to connect.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier task;
+
+ /**
+ * Context in 'testing.c', to cancel connection attempt.
+ */
+ struct GNUNET_TESTING_ConnectContext *cc;
+
/**
* Higher level topology connection context.
*/
* Choose a random peer's next connection to create, and
* call schedule_connect to set up the connect task.
*
- * @param ct_ctx the overall connection context
+ * @param pg the peer group to connect
*/
static void
preschedule_connect (struct GNUNET_TESTING_PeerGroup *pg)
connect_context->first_index = random_peer;
connect_context->second_index = connection_iter->index;
connect_context->ct_ctx = ct_ctx;
- GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
+ connect_context->task = GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
+ GNUNET_CONTAINER_DLL_insert (pg->cc_head,
+ pg->cc_tail,
+ connect_context);
GNUNET_CONTAINER_DLL_remove (pg->peers[random_peer].connect_peers_head,
pg->peers[random_peer].connect_peers_tail,
connection_iter);
GNUNET_assert (send_hello_context->peer->daemon->th != NULL);
GNUNET_TRANSPORT_disconnect (send_hello_context->peer->daemon->th);
send_hello_context->peer->daemon->th = NULL;
-
- /*if (send_hello_context->pg->remaining_hellos == 0)
- * {
- * for (pg_iter = 0; pg_iter < send_hello_context->pg->max_outstanding_connections; pg_iter++)
- * {
- * preschedule_connect(&send_hello_context->pg->ct_ctx);
- * }
- * }
- */
GNUNET_assert (send_hello_context->peer->daemon->server == NULL);
send_hello_context->peer->daemon->server =
GNUNET_CORE_connect (send_hello_context->peer->cfg, 1,
struct GNUNET_TESTING_PeerGroup *pg = ct_ctx->pg;
struct PeerConnection *connection;
+ GNUNET_assert (NULL != connect_ctx->cc);
+ connect_ctx->cc = NULL;
GNUNET_assert (0 < pg->outstanding_connects);
pg->outstanding_connects--;
-
+ GNUNET_CONTAINER_DLL_remove (pg->cc_head,
+ pg->cc_tail,
+ connect_ctx);
/*
* Check whether the inverse connection has been scheduled yet,
* if not, we can remove it from the other peers list and avoid
(0 !=
memcmp (first, &pg->peers[connection->index].daemon->id,
sizeof (struct GNUNET_PeerIdentity))))
- {
connection = connection->next;
- }
if (connection != NULL) /* Can safely remove! */
{
pg->notify_connection (pg->notify_connection_cls, first, second, distance,
first_cfg, second_cfg, first_daemon, second_daemon,
emsg);
-
GNUNET_free (connect_ctx);
}
struct ConnectContext *connect_context = cls;
struct GNUNET_TESTING_PeerGroup *pg = connect_context->ct_ctx->pg;
+ connect_context->task = GNUNET_SCHEDULER_NO_TASK;
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
_
("Delaying connect, we have too many outstanding connections!\n"));
#endif
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 100),
- &schedule_connect, connect_context);
+ connect_context->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &schedule_connect, connect_context);
+ return;
}
- else
- {
#if VERBOSE_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_
#endif
pg->outstanding_connects++;
pg->total_connects_scheduled++;
- GNUNET_TESTING_daemons_connect (pg->
+ GNUNET_assert (NULL == connect_context->cc);
+ connect_context->cc
+ = GNUNET_TESTING_daemons_connect (pg->
peers[connect_context->first_index].daemon,
pg->peers[connect_context->
second_index].daemon,
#else
GNUNET_YES,
#endif
- &internal_connect_notify, connect_context); /* FIXME: free connect context! */
- }
+ &internal_connect_notify, connect_context);
+
}
#if !OLD
connect_context->first = first->daemon;
connect_context->second = second;
connect_context->ct_ctx = ct_ctx;
- GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
-
+ connect_context->task = GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
+ GNUNET_CONTAINER_DLL_insert (ct_ctx->pg->cc_head,
+ ct_ctx->pg->cc_tail,
+ connect_context);
return GNUNET_YES;
}
#endif
struct PeerConnection *conn_iter;
struct PeerConnection *temp_conn;
#endif
+ struct ConnectContext *cc;
GNUNET_assert (pg->total > 0);
+ while (NULL != (cc = pg->cc_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (pg->cc_head,
+ pg->cc_tail,
+ cc);
+ if (GNUNET_SCHEDULER_NO_TASK != cc->task)
+ GNUNET_SCHEDULER_cancel (cc->task);
+ if (NULL != cc->cc)
+ GNUNET_TESTING_daemons_connect_cancel (cc->cc);
+ GNUNET_free (cc);
+ }
shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
shutdown_ctx->delete_files =
shutdown_ctx->total_peers = pg->total;
shutdown_ctx->timeout = timeout;
shutdown_ctx->pg = pg;
- /* shtudown_ctx->outstanding = 0; */
for (off = 0; off < pg->total; off++)
{
static struct GNUNET_TESTING_Daemon *last;
+/**
+ * Active connection attempt.
+ */
+struct GNUNET_TESTING_ConnectContext *cc[NUM_PEERS];
+
/**
* Check whether peers successfully shut down.
*/
static void
clean_up_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ unsigned int i;
+
+ for (i=0;i<NUM_PEERS;i++)
+ {
+ if (NULL != cc[i])
+ {
+ GNUNET_TESTING_daemons_connect_cancel (cc[i]);
+ cc[i] = NULL;
+ }
+ }
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
ok = 0;
}
struct GNUNET_TESTING_Daemon *second_daemon,
const char *emsg)
{
+ struct GNUNET_TESTING_ConnectContext **cc;
+ unsigned int i;
+
+ *cc = NULL;
if (NULL != emsg)
{
fprintf (stderr, "Failed to connect two peers: %s\n", emsg);
+ for (i=0;i<NUM_PEERS;i++)
+ if (NULL != cc[i])
+ {
+ GNUNET_TESTING_daemons_connect_cancel (cc[i]);
+ cc[i] = NULL;
+ }
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
GNUNET_assert (0);
return;
last = d;
return;
}
- GNUNET_TESTING_daemons_connect (last, d, TIMEOUT, CONNECT_ATTEMPTS,
- GNUNET_YES, ¬ify_connect_complete, NULL);
+ cc[peers_left] = GNUNET_TESTING_daemons_connect (last, d, TIMEOUT, CONNECT_ATTEMPTS,
+ GNUNET_YES, ¬ify_connect_complete, &cc[peers_left]);
if (peers_left == 0)
{
/* close circle */
- GNUNET_TESTING_daemons_connect (d, first, TIMEOUT, CONNECT_ATTEMPTS,
- GNUNET_YES, ¬ify_connect_complete, NULL);
+ cc[NUM_PEERS-1] = GNUNET_TESTING_daemons_connect (d, first, TIMEOUT, CONNECT_ATTEMPTS,
+ GNUNET_YES, ¬ify_connect_complete, &cc[peers_left]);
}
}