char **emsg);
+/**
+ * Obtain the peer identity from a peer handle.
+ *
+ * @param peer peer handle for which we want the peer's identity
+ * @param id identifier for the daemon, will be set
+ */
+void
+GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
+ struct GNUNET_PeerIdentity *id);
+
+
/**
* Start the peer.
*
*
* @param cls closure
* @param cfg configuration of the peer that was started
+ * @param peer identity of the peer that was created
*/
typedef void (*GNUNET_TESTING_RestartableTestMain)(void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_TESTING_Peer *peer);
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const struct GNUNET_TESTING_Peer *peer);
/**
* The only difference is that we handle the GNUNET_TESTING_Peer to
* the RestartableTestMain, so that the peer can be destroyed and re-created
* to simulate failure in tests.
+ *
+ * FIXME: change 'GNUNET_TESTING_TestMain' to have the 'restartable' signature
+ * and remove this extra function (in some sense, make this the primary one,
+ * but keep the old name).
*/
int
GNUNET_TESTING_service_run_restartable (const char *testdir,
return size;
}
+
/**
* Writes data using the given socket. The amount of data written is limited by
* the receiver_window_size
static void
write_data (struct GNUNET_STREAM_Socket *socket);
+
/**
* Task for retransmitting data messages if they aren't ACK before their ack
* deadline
socket->write_offset = 0;
socket->read_offset = 0;
socket->state = STATE_ESTABLISHED;
- /* FIXME: What if listen_cb is NULL */
if (NULL != socket->lsocket)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
&socket->other_peer))
{
socket->state = STATE_CLOSED;
- /* FIXME: We should close in a decent way */
+ /* FIXME: We should close in a decent way (send RST) */
GNUNET_MESH_tunnel_destroy (socket->tunnel); /* Destroy the tunnel */
GNUNET_free (socket);
}
}
- else if (socket->open_cb)
+ else if (NULL != socket->open_cb)
socket->open_cb (socket->open_cls, socket);
}
socket->state = STATE_CLOSED;
}
+
/**
* Returns a new HelloAckMessage. Also sets the write sequence number for the
* socket
if (GNUNET_SCHEDULER_NO_TASK != handle->close_msg_retransmission_task_id)
GNUNET_SCHEDULER_cancel (handle->close_msg_retransmission_task_id);
GNUNET_free (handle);
- return;
}
enum GNUNET_STREAM_Option option;
va_list vargs;
+ GNUNET_assert (NULL != listen_cb);
lsocket = GNUNET_malloc (sizeof (struct GNUNET_STREAM_ListenSocket));
lsocket->cfg = GNUNET_CONFIGURATION_dup (cfg);
lsocket->lockmanager = GNUNET_LOCKMANAGER_connect (lsocket->cfg);
}
-
/**
* Tries to read data from the stream.
*
GNUNET_free (socket->write_handle);
socket->write_handle = NULL;
- return;
}
void
GNUNET_STREAM_io_read_cancel (struct GNUNET_STREAM_IOReadHandle *ioh)
{
- return;
+ // FIXME: do stuff
}
+
+/* end of stream_api.c */
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_stream_lib.h"
-#include "gnunet_testing_lib.h"
+#include "gnunet_testing_lib-new.h"
#define LOG(kind, ...) \
GNUNET_log (kind, __VA_ARGS__);
*/
struct GNUNET_STREAM_Socket *socket;
+ struct GNUNET_PeerIdentity self;
+
/**
* Peer's io write handle
*/
unsigned int bytes_read;
};
-static struct GNUNET_OS_Process *arm_pid;
static struct PeerData peer1;
static struct PeerData peer2;
static struct GNUNET_STREAM_ListenSocket *peer2_listen_socket;
-static struct GNUNET_CONFIGURATION_Handle *config;
+static const struct GNUNET_CONFIGURATION_Handle *config;
static GNUNET_SCHEDULER_TaskIdentifier abort_task;
static GNUNET_SCHEDULER_TaskIdentifier test_task;
{
GNUNET_SCHEDULER_cancel (abort_task);
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: arm\n");
- if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
- /* Free the duplicated configuration */
- GNUNET_CONFIGURATION_destroy (config);
- GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
- GNUNET_OS_process_destroy (arm_pid);
}
stream_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerData *peer = cls;
- struct GNUNET_PeerIdentity self;
- GNUNET_assert (&peer1 == peer);
- GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config,
- &self));
/* Connect to stream */
peer->socket = GNUNET_STREAM_open (config,
- &self, /* Null for local peer? */
+ &peer2.self, /* Null for local peer? */
10, /* App port */
&stream_open_cb,
&peer1,
/**
- * Testing function
+ * Initialize framework and start test
*
- * @param cls NULL
- * @param tc the task context
+ * @param cls closure
+ * @param cfg configuration of the peer that was started
+ * @param peer identity of the peer that was created
*/
static void
-test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_PeerIdentity self;
-
- test_task = GNUNET_SCHEDULER_NO_TASK;
- /* Get our identity */
- GNUNET_assert (GNUNET_OK == GNUNET_TESTING_get_peer_identity (config,
- &self));
-
+
+ GNUNET_TESTING_peer_get_identity (peer, &self);
+ config = cfg;
+ abort_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort,
+ NULL);
peer2_listen_socket = GNUNET_STREAM_listen (config,
10, /* App port */
&stream_listen_cb,
NULL,
GNUNET_STREAM_OPTION_END);
GNUNET_assert (NULL != peer2_listen_socket);
+ peer1.self = self;
+ peer2.self = self;
GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(2), &stream_connect, &peer1);
}
-
-/**
- * Initialize framework and start test
- */
-static void
-run (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- /* Duplicate the configuration */
- config = GNUNET_CONFIGURATION_dup (cfg);
- arm_pid =
- GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
-#if VERBOSE_ARM
- "-L", "DEBUG",
-#endif
- "-c", "test_stream_local.conf", NULL);
-
- abort_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort,
- NULL);
- test_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(3), &test, NULL);
-}
-
/**
* Main function
*/
int main (int argc, char **argv)
{
- int ret;
-
- char *const argv2[] = { "test-stream-big",
- "-c", "test_stream_local.conf",
- "-L", "DEBUG",
- NULL
- };
-
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
-
- ret =
- GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
- "test-stream-big", "nohelp", options, &run, NULL);
-
- if (GNUNET_OK != ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
- ret);
+ if (0 != GNUNET_TESTING_service_run_restartable ("test-stream-big",
+ "arm",
+ "test_stream_local.conf",
+ &run, NULL))
return 1;
- }
- if (GNUNET_SYSERR == result)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
- return 1;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n");
- return 0;
+ return (GNUNET_SYSERR == result) ? 1 : 0;
}