+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 300), &do_abort,
+ NULL);
+}
+
+
+/**
+ * Adapter function called to establish a connection to
+ * a service.
+ *
+ * @param cls closure
+ * @param cfg configuration of the peer to connect to; will be available until
+ * GNUNET_TESTBED_operation_done() is called on the operation returned
+ * from GNUNET_TESTBED_service_connect()
+ * @return service handle to return in 'op_result', NULL on error
+ */
+static void *
+stream_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg);
+
+
+/**
+ * Adapter function called to destroy a connection to
+ * a service.
+ *
+ * @param cls closure
+ * @param op_result service handle returned from the connect adapter
+ */
+static void
+stream_da (void *cls, void *op_result)
+{
+ if (&peer_data[1] == cls)
+ {
+ GNUNET_STREAM_listen_close (op_result);
+ return;
+ }
+ else if (&peer_data[0] == cls)
+ {
+ GNUNET_STREAM_close (op_result);
+ return;
+ }
+ GNUNET_assert (0);
+}
+
+
+/**
+ * Listen success callback; connects a peer to stream as client. Called from
+ * testbed stream_ca
+ */
+static void
+stream_connect2 (void)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stream listen open successful\n");
+ peer_data[0].op =
+ GNUNET_TESTBED_service_connect (&peer_data[0], peer_data[0].peer,
+ "stream", NULL, NULL, stream_ca,
+ stream_da, &peer_data[0]);
+}
+
+
+/**
+ * Adapter function called to establish a connection to
+ * a service.
+ *
+ * @param cls closure
+ * @param cfg configuration of the peer to connect to; will be available until
+ * GNUNET_TESTBED_operation_done() is called on the operation returned
+ * from GNUNET_TESTBED_service_connect()
+ * @return service handle to return in 'op_result', NULL on error
+ */
+static void *
+stream_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct PeerData *pdata = cls;
+
+ if (&peer_data[1] == pdata)
+ {
+ peer2_listen_socket = NULL;
+ peer2_listen_socket =
+ GNUNET_STREAM_listen (cfg, 10, &stream_listen_cb, &peer_data[1],
+ GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS,
+ &stream_connect2,
+ GNUNET_STREAM_OPTION_MAX_PAYLOAD_SIZE,
+ payload_size[payload_size_index],
+ GNUNET_STREAM_OPTION_END);
+ GNUNET_assert (NULL != peer2_listen_socket);
+ return peer2_listen_socket;
+ }
+ if (&peer_data[0] == pdata)
+ {
+ pdata->socket =
+ GNUNET_STREAM_open (cfg, &peer_data[1].id, 10, &stream_open_cb,
+ &peer_data[0],
+ GNUNET_STREAM_OPTION_MAX_PAYLOAD_SIZE,
+ payload_size[payload_size_index],
+ GNUNET_STREAM_OPTION_END);
+ GNUNET_assert (NULL != pdata->socket);
+ return pdata->socket;
+ }
+ GNUNET_assert (0);
+ return NULL;
+}
+
+
+/**
+ * Callback to be called when the requested peer information is available
+ *
+ * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
+ * @param op the operation this callback corresponds to
+ * @param pinfo the result; will be NULL if the operation has failed
+ * @param emsg error message if the operation has failed; will be NULL if the
+ * operation is successfull
+ */
+static void
+peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
+ const struct GNUNET_TESTBED_PeerInformation *pinfo,
+ const char *emsg)
+{
+ struct PeerData *pdata = cb_cls;
+
+ GNUNET_assert (NULL == emsg);
+ GNUNET_assert (common_op == op);
+ GNUNET_assert (NULL != pdata);
+ memcpy (&pdata->id, pinfo->result.id, sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_TESTBED_operation_done (op);
+ if (pdata == &peer_data[0])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 id: %s\n",
+ GNUNET_i2s (&pdata->id));
+ common_op = GNUNET_TESTBED_peer_get_information (peer_data[1].peer,
+ GNUNET_TESTBED_PIT_IDENTITY,
+ &peerinfo_cb, &peer_data[1]);
+ }
+ else if (pdata == &peer_data[1])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 id: %s\n",
+ GNUNET_i2s (&pdata->id));
+ if (TEST_STEP_2_HOP == test_step)
+ peer_data[1].op =
+ GNUNET_TESTBED_service_connect (&peer_data[1], peer_data[1].peer,
+ "stream", NULL, NULL, stream_ca,
+ stream_da, &peer_data[1]);
+ else
+ GNUNET_break (0); /* FIXME: 3 hop test case here... */
+ }
+}
+
+
+/**
+ * Controller event callback
+ *
+ * @param cls NULL
+ * @param event the controller event
+ */
+static void
+controller_event_cb (void *cls,
+ const struct GNUNET_TESTBED_EventInformation *event)
+{
+ switch (event->type)
+ {
+ case GNUNET_TESTBED_ET_OPERATION_FINISHED:
+ if (NULL != event->details.operation_finished.emsg)
+ {
+ FPRINTF (stderr, "Error while expecting an operation to succeed:%s \n",
+ event->details.operation_finished.emsg);
+ GNUNET_assert (0);
+ }
+ break;
+ case GNUNET_TESTBED_ET_CONNECT:
+ GNUNET_TESTBED_operation_done (common_op);
+ /* Get the peer identity and configuration of peers */
+ common_op =
+ GNUNET_TESTBED_peer_get_information (peer_data[0].peer,
+ GNUNET_TESTBED_PIT_IDENTITY,
+ &peerinfo_cb, &peer_data[0]);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+}
+
+
+/**
+ * Signature of a main function for a testcase.
+ *
+ * @param cls closure
+ * @param num_peers number of peers in 'peers'
+ * @param peers handle to peers run in the testbed
+ */
+static void
+test_master (void *cls, unsigned int num_peers_,
+ struct GNUNET_TESTBED_Peer **peers)
+{
+ GNUNET_assert (NULL != peers);
+ GNUNET_assert (NULL != peers[0]);
+ GNUNET_assert (NULL != peers[1]);
+ GNUNET_assert (num_peers_ == num_peers);
+ peer_data[0].peer = peers[0];
+ peer_data[1].peer = peers[1];
+ if (2 == num_peers)
+ common_op = GNUNET_TESTBED_overlay_connect (NULL, NULL, NULL,
+ peer_data[0].peer,
+ peer_data[1].peer);
+ else
+ GNUNET_break (0);
+ abort_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 120), &do_abort,
+ NULL);