*/
/**
- * @file mesh/test_mesh_local.c
- * @brief test mesh local: test of mesh channels with just one peer
+ * @file mesh/test_mesh_single.c
+ * @brief test mesh single: test of mesh channels with just one client
* @author Bartlomiej Polot
*/
static struct GNUNET_MESH_Channel *ch2;
-static int result = GNUNET_OK;
+static int result;
static GNUNET_SCHEDULER_TaskIdentifier abort_task;
if (NULL != mesh)
{
GNUNET_MESH_disconnect (mesh);
+ mesh = NULL;
+ }
+ else
+ {
+ GNUNET_break (0);
}
}
}
+static void
+finish (void)
+{
+ if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
+ GNUNET_SCHEDULER_cancel (shutdown_task);
+ shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &do_shutdown, NULL);
+}
+
+
/**
* Function is called whenever a message is received.
*
my_channel = ch2;
GNUNET_MESH_notify_transmit_ready (my_channel, GNUNET_NO,
GNUNET_TIME_UNIT_FOREVER_REL,
- sizeof (struct GNUNET_MessageHeader) + DATA_SIZE,
+ sizeof (struct GNUNET_MessageHeader)
+ + DATA_SIZE,
&do_send, NULL);
GNUNET_MESH_receive_done (channel);
return GNUNET_OK;
}
- if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown,
- NULL);
- GNUNET_MESH_receive_done (channel);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All data OK. Destroying channel.\n");
+ GNUNET_MESH_channel_destroy (ch1);
+ ch1 = NULL;
return GNUNET_OK;
}
* @param channel new handle to the channel
* @param initiator peer that started the channel
* @param port port number
- * @return initial channel context for the channel (can be NULL -- that's not an error)
+ * @param options channel option flags
+ * @return initial channel context for the channel
+ * (can be NULL -- that's not an error)
*/
static void *
inbound_channel (void *cls, struct GNUNET_MESH_Channel *channel,
const struct GNUNET_PeerIdentity *initiator,
- uint32_t port)
+ uint32_t port, enum GNUNET_MESH_ChannelOption options)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"received incoming channel on port %u\n",
* with the channel is stored
*/
static void
-inbound_end (void *cls, const struct GNUNET_MESH_Channel *channel,
+channel_end (void *cls, const struct GNUNET_MESH_Channel *channel,
void *channel_ctx)
{
long id = (long) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"incoming channel closed at peer %ld\n",
id);
+ if (REPETITIONS == repetition && channel == ch2)
+ {
+ ch2 = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "everything fine! finishing!\n");
+ result = GNUNET_OK;
+ finish ();
+ }
}
do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_PeerIdentity id;
+ size_t size = sizeof (struct GNUNET_MessageHeader) + DATA_SIZE;
+
+ if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
+ return;
GNUNET_TESTING_peer_get_identity (me, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
- ch1 = GNUNET_MESH_channel_create (mesh, NULL, &id, 1, GNUNET_YES, GNUNET_NO);
+ ch1 = GNUNET_MESH_channel_create (mesh, NULL, &id, 1,
+ GNUNET_MESH_OPTION_DEFAULT);
GNUNET_MESH_notify_transmit_ready (ch1, GNUNET_NO,
GNUNET_TIME_UNIT_FOREVER_REL,
- sizeof (struct GNUNET_MessageHeader) + DATA_SIZE,
- &do_send, NULL);
+ size, &do_send, NULL);
}
mesh = GNUNET_MESH_connect (cfg, /* configuration */
(void *) 1L, /* cls */
&inbound_channel, /* inbound new hndlr */
- &inbound_end, /* inbound end hndlr */
+ &channel_end, /* inbound end hndlr */
handlers1, /* traffic handlers */
ports); /* ports offered */
int
main (int argc, char *argv[])
{
+ result = GNUNET_NO;
if (0 != GNUNET_TESTING_peer_run ("test-mesh-local",
"test_mesh.conf",
&run, NULL))
return (result == GNUNET_OK) ? 0 : 1;
}
-/* end of test_mesh_local_1.c */
+/* end of test_mesh_single.c */