GNUNET_SCHEDULER_cancel (ccc->timeout_task);
ccc->timeout_task = NULL;
}
+ if (NULL != ccc->connect_task)
+ {
+ GNUNET_SCHEDULER_cancel (ccc->connect_task);
+ ccc->connect_task = NULL;
+ }
while (NULL != (crl = ccc->crl_head))
{
GNUNET_CONTAINER_DLL_remove (ccc->crl_head,
}
for (unsigned int i=0;i<ccc->num_peers;i++)
{
- GNUNET_TRANSPORT_TESTING_stop_peer (ccc->p[i]);
- ccc->p[i] = NULL;
+ if (NULL != ccc->p[i])
+ {
+ GNUNET_TRANSPORT_TESTING_stop_peer (ccc->p[i]);
+ ccc->p[i] = NULL;
+ }
}
}
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
ccc->timeout_task = NULL;
- GNUNET_break (0); /* signal timeout */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Testcase timed out\n");
ccc->global_ret = GNUNET_SYSERR;
GNUNET_SCHEDULER_shutdown ();
}
/**
- * Function called when we connected two peers.
- * Once we have gotten to the clique, launch
- * test-specific logic.
+ * Information tracked per connected peer.
+ */
+struct ConnectPairInfo
+{
+ /**
+ * Peer this is about.
+ */
+ const struct GNUNET_PeerIdentity *sender;
+
+ /**
+ * Information about the receiving peer.
+ */
+ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi;
+};
+
+
+/**
+ * Function called when we connected two peers. Once we have gotten
+ * to the clique, launch test-specific logic.
*
* @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *`
*/
*
* @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
* @param peer peer we got connected to
+ * @param mq message queue for transmissions to @a peer
+ * @return closure for message handlers
*/
-static void
+static void *
my_nc (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
{
struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
+ struct ConnectPairInfo *cpi;
if (NULL != ccc->nc)
ccc->nc (ccc->cls,
ccc->p[ipi->off],
peer);
+ cpi = GNUNET_new (struct ConnectPairInfo);
+ cpi->ipi = ipi;
+ cpi->sender = peer; /* valid until disconnect */
+ return cpi;
}
-
/**
* Wrapper around peers disconnecting. Calls client's nd function.
*
* @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
* @param peer peer we got disconnected from
+ * @param custom_cls return value from @my_nc
*/
static void
my_nd (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer,
+ void *custom_cls)
{
struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
+ struct ConnectPairInfo *cpi = custom_cls;
if (NULL != ccc->nd)
ccc->nd (ccc->cls,
ccc->p[ipi->off],
peer);
+ GNUNET_free (cpi);
}
/**
* Wrapper around receiving data. Calls client's rec function.
*
- * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
- * @param peer peer we got a message from
+ * @param cls our `struct ConnectPairInfo *`
+ * @param message message we received
+ * @return #GNUNET_OK (all messages are fine)
+ */
+static int
+check_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Wrapper around receiving data. Calls client's rec function.
+ *
+ * @param cls our `struct ConnectPairInfo *`
* @param message message we received
*/
static void
-my_rec (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message)
+handle_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
{
- struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
+ struct ConnectPairInfo *cpi = cls;
+ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi;
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
if (NULL != ccc->rec)
ccc->rec (ccc->cls,
ccc->p[ipi->off],
- peer,
+ cpi->sender,
message);
}
/**
- * Function called once we have successfully launched a peer.
- * Once all peers have been launched, we connect all of them
- * in a clique.
+ * Wrapper around receiving data. Calls client's rec function.
*
- * @param p peer that was launched (redundant, kill ASAP)
- * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
+ * @param cls our `struct ConnectPairInfo *`
+ * @param message message we received
+ * @return #GNUNET_OK (all messages are fine)
+ */
+static int
+check_test2 (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Wrapper around receiving data. Calls client's rec function.
+ *
+ * @param cls our `struct ConnectPairInfo *`
+ * @param message message we received
*/
static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
- void *cls)
+handle_test2 (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
{
- struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
+ struct ConnectPairInfo *cpi = cls;
+ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi;
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
- ccc->started++;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Peer %u (`%s') started\n",
- p->no,
- GNUNET_i2s (&p->id));
- if (ccc->started != ccc->num_peers)
- return;
+ if (NULL != ccc->rec)
+ ccc->rec (ccc->cls,
+ ccc->p[ipi->off],
+ cpi->sender,
+ message);
+}
+
+/**
+ * Connect the peers as a clique.
+ *
+ * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
+ */
+static void
+do_connect (void *cls)
+{
+ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
+
+ ccc->connect_task = NULL;
for (unsigned int i=0;i<ccc->num_peers;i++)
- for (unsigned int j=i+1;j<ccc->num_peers;j++)
+ for (unsigned int j=(ccc->bi_directional ? 0 : i+1);j<ccc->num_peers;j++)
{
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl;
+ if (i == j)
+ continue;
crl = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequestList);
GNUNET_CONTAINER_DLL_insert (ccc->crl_head,
ccc->crl_tail,
}
+/**
+ * Function called once we have successfully launched a peer.
+ * Once all peers have been launched, we connect all of them
+ * in a clique.
+ *
+ * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
+ */
+static void
+start_cb (void *cls)
+{
+ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
+ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
+ struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off];
+
+ ccc->started++;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Peer %u (`%s') started\n",
+ p->no,
+ GNUNET_i2s (&p->id));
+ if (ccc->started != ccc->num_peers)
+ return;
+ if (NULL != ccc->pre_connect_task)
+ {
+ /* Run the custom per-connect job, then give it a second to
+ go into effect before we continue connecting peers. */
+ ccc->pre_connect_task (ccc->pre_connect_task_cls);
+ ccc->connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &do_connect,
+ ccc);
+ }
+ else
+ {
+ do_connect (ccc);
+ }
+}
+
+
/**
* Function run from #GNUNET_TRANSPORT_TESTING_connect_check
* once the scheduler is up. Should launch the peers and
ok = GNUNET_OK;
for (unsigned int i=0;i<ccc->num_peers;i++)
{
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_var_size (test,
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
+ struct GNUNET_TRANSPORT_TESTING_TestMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (test2,
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
+ struct GNUNET_TRANSPORT_TESTING_TestMessage,
+ NULL),
+ GNUNET_MQ_handler_end()
+ };
ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer (ccc->tth,
ccc->cfg_files[i],
i + 1,
- &my_rec,
+ handlers,
&my_nc,
&my_nd,
+ &ccc->ip[i],
&start_cb,
&ccc->ip[i]);
if (NULL == ccc->p[i])
ip[i].off = i;
ip[i].ccc = ccc;
}
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv,
- test_name_,
- "nohelp",
- options,
- &connect_check_run,
- ccc);
+ if (GNUNET_OK !=
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv,
+ test_name_,
+ "nohelp",
+ options,
+ &connect_check_run,
+ ccc))
+ return GNUNET_SYSERR;
return ccc->global_ret;
}
for (unsigned int i=0;i<num_peers;i++)
GNUNET_free (cfg_names[i]);
GNUNET_free (test_source);
- GNUNET_free (test_plugin);
+ GNUNET_free_non_null (test_plugin);
GNUNET_free (test_name);
return ret;
}