+/**
+ * Listen success callback; connects a peer to stream as client
+ */
+static void
+stream_connect (void);
+
+
+/**
+ * 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)
+{
+ struct GNUNET_STREAM_ListenSocket *lsocket;
+
+ if (&peer2 == cls)
+ {
+ lsocket = op_result;
+ GNUNET_STREAM_listen_close (lsocket);
+ if (NULL != peer1.op)
+ GNUNET_TESTBED_operation_done (peer1.op);
+ else
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (&peer1 == cls)
+ {
+ GNUNET_assert (op_result == peer1.socket);
+ GNUNET_STREAM_close (peer1.socket);
+ GNUNET_SCHEDULER_shutdown (); /* Exit point of the test */
+ return;
+ }
+ GNUNET_assert (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 GNUNET_STREAM_ListenSocket *lsocket;
+
+ switch (setup_state)
+ {
+ case PEER2_STREAM_CONNECT:
+ lsocket = GNUNET_STREAM_listen (cfg, 10, &stream_listen_cb, NULL,
+ GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS,
+ &stream_connect, GNUNET_STREAM_OPTION_END);
+ GNUNET_assert (NULL != lsocket);
+ return lsocket;
+ case PEER1_STREAM_CONNECT:
+ peer1.socket = GNUNET_STREAM_open (cfg, &peer2.our_id, 10, &stream_open_cb,
+ &peer1, GNUNET_STREAM_OPTION_END);
+ GNUNET_assert (NULL != peer1.socket);
+ return peer1.socket;
+ default:
+ GNUNET_assert (0);
+ }
+}
+
+