static char *cfg_file_p2;
static struct GNUNET_TRANSPORT_PeerMonitoringContext *pmc_p1;
+
static struct GNUNET_TRANSPORT_PeerMonitoringContext *pmc_p2;
+static int p1_c = GNUNET_NO;
+
+static int p2_c = GNUNET_NO;
+
+static int p1_c_notify = GNUNET_NO;
+
+static int p2_c_notify = GNUNET_NO;
static void
end ()
GNUNET_SCHEDULER_cancel (send_task);
if (die_task != GNUNET_SCHEDULER_NO_TASK)
+ {
GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (th != NULL)
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
+ if (NULL != p1)
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+ p1 = NULL;
+ if (NULL != p2)
+ GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+ p2 = NULL;
+
if (NULL != pmc_p1)
{
GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p1);
pmc_p2 = NULL;
}
- GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
- p1 = NULL;
- GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
- p2 = NULL;
+
+
+ ok = 0;
}
static void
th = NULL;
+ if (NULL != pmc_p1)
+ {
+ GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p1);
+ pmc_p1 = NULL;
+ }
+ if (NULL != pmc_p2)
+ {
+ GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p2);
+ pmc_p2 = NULL;
+ }
+
if (p1 != NULL)
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
else
p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
GNUNET_free (receiver_s);
s_sending = GNUNET_YES;
- th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE, 0,
+ th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE,
TIMEOUT_TRANSMIT, ¬ify_ready,
p1);
}
+static void
+done ()
+{
+ if ((GNUNET_YES == p1_c) && (GNUNET_YES == p2_c) && p1_c_notify && p2_c_notify)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Both peers state to be connected\n");
+ ok = 0;
+ end();
+ }
+}
+
+
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *t = NULL;
if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ p1_c_notify = GNUNET_YES;
t = p1;
+ }
if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ p2_c_notify = GNUNET_YES;
t = p2;
+ }
GNUNET_assert (t != NULL);
char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps,
t->no, GNUNET_i2s (peer));
+ if (p1_c_notify && p2_c_notify)
+ GNUNET_SCHEDULER_add_now(&done, NULL);
GNUNET_free (ps);
}
NULL);
}
-static int p1_c = GNUNET_NO;
-static int p2_c = GNUNET_NO;
-static void done ()
-{
- if ((GNUNET_YES == p1_c) && (GNUNET_YES == p2_c))
- end();
-}
static void monitor1_cb (void *cls,
const struct GNUNET_PeerIdentity *peer,
if ((NULL == peer) || (NULL == p1))
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Monitor 1: %s %s %s\n",
- GNUNET_i2s (peer), GNUNET_TRANSPORT_p2s(state), GNUNET_STRINGS_absolute_time_to_string(state_timeout));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Monitor 1: %s %s %s\n",
+ GNUNET_i2s (peer), GNUNET_TRANSPORT_ps2s(state), GNUNET_STRINGS_absolute_time_to_string(state_timeout));
if ((0 == memcmp (peer, &p2->id, sizeof (p2->id)) &&
(GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) &&
GNUNET_NO == p1_c) )
if ((NULL == peer) || (NULL == p2))
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Monitor 2: %s %s %s\n",
- GNUNET_i2s (peer), GNUNET_TRANSPORT_p2s (state), GNUNET_STRINGS_absolute_time_to_string(state_timeout));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Monitor 2: %s %s %s\n",
+ GNUNET_i2s (peer), GNUNET_TRANSPORT_ps2s (state), GNUNET_STRINGS_absolute_time_to_string(state_timeout));
if ((0 == memcmp (peer, &p1->id, sizeof (p1->id)) &&
(GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) &&
GNUNET_NO == p2_c) )
¬ify_disconnect, &start_cb,
NULL);
pmc_p1 = GNUNET_TRANSPORT_monitor_peers (p1->cfg, NULL, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_REL, &monitor1_cb, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 started\n");
p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
¬ify_receive, ¬ify_connect,
¬ify_disconnect, &start_cb,
NULL);
pmc_p2 = GNUNET_TRANSPORT_monitor_peers (p2->cfg, NULL, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_REL, &monitor2_cb, NULL);
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 started\n");
if ((p1 == NULL) || (p2 == NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
{
int ret;
+ ok = 1;
+
GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
GNUNET_TRANSPORT_TESTING_done (tth);
- return ret;
+ if (0 != ret)
+ return ret;
+ else
+ return ok;
}
/* end of test_transport_api.c */