2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 #include "gnunet_util_lib.h"
23 #include "gnunet_testing_lib.h"
24 #include "gnunet_core_service.h"
30 * Has the test been successful?
34 static unsigned int num_received;
36 static struct GNUNET_CORE_Handle *core;
38 static struct GNUNET_MQ_Handle *mq;
40 static struct GNUNET_PeerIdentity myself;
45 const struct GNUNET_PeerIdentity *my_identity)
47 if (NULL == my_identity)
52 myself = *my_identity;
53 mq = GNUNET_CORE_mq_create (core, my_identity);
58 connect_cb (void *cls,
59 const struct GNUNET_PeerIdentity *peer)
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
62 "Connected to peer %s.\n",
64 if (0 == memcmp (peer, &myself, sizeof (struct GNUNET_PeerIdentity)))
67 struct GNUNET_MQ_Envelope *ev;
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
70 "Queueing messages.\n");
71 for (i = 0; i < NUM_MSG; i++)
73 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_TEST);
74 GNUNET_MQ_send (mq, ev);
81 handle_test (void *cls,
82 const struct GNUNET_PeerIdentity *other,
83 const struct GNUNET_MessageHeader *message)
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "Got test message %d\n",
89 if (NUM_MSG == num_received)
92 GNUNET_SCHEDULER_shutdown ();
95 if (num_received > NUM_MSG)
105 shutdown_task (void *cls)
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
109 GNUNET_MQ_destroy (mq);
110 GNUNET_CORE_disconnect (core);
115 * Initialize framework and start test
117 * @param cls Closure (unused).
118 * @param cfg Configuration handle.
119 * @param peer Testing peer handle.
123 const struct GNUNET_CONFIGURATION_Handle *cfg,
124 struct GNUNET_TESTING_Peer *peer)
126 static const struct GNUNET_CORE_MessageHandler handlers[] = {
127 {&handle_test, GNUNET_MESSAGE_TYPE_TEST, 0},
130 core = GNUNET_CORE_connect (cfg,
131 NULL, &init_cb, &connect_cb, NULL,
132 NULL, GNUNET_NO, NULL,
133 GNUNET_NO, handlers);
139 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
144 main (int argc, char *argv1[])
146 if (0 != GNUNET_TESTING_peer_run ("test-core-api-mq",
147 "test_core_api_peer1.conf",
150 return (result == GNUNET_OK) ? 0 : 1;