2 This file is part of GNUnet.
3 Copyright (C) 2010, 2016 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 * @file core/test_core_api_send_to_self.c
23 * @brief test that sending a message to ourselves via CORE works
24 * @author Philipp Toelke
25 * @author Christian Grothoff
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testing_lib.h"
30 #include "gnunet_protocols.h"
31 #include "gnunet_core_service.h"
32 #include "gnunet_constants.h"
40 * Handle to the cleanup task.
42 static struct GNUNET_SCHEDULER_Task *die_task;
45 * Identity of this peer.
47 static struct GNUNET_PeerIdentity myself;
52 static struct GNUNET_CORE_Handle *core;
56 * Function scheduled as very last function, cleans up after us
63 GNUNET_SCHEDULER_cancel (die_task);
68 GNUNET_CORE_disconnecT (core);
71 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
77 * Function scheduled as very last function, cleans up after us
80 do_timeout (void *cls)
82 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
85 GNUNET_SCHEDULER_shutdown ();
90 handle_test (void *cls,
91 const struct GNUNET_MessageHeader *message)
93 GNUNET_SCHEDULER_shutdown ();
100 const struct GNUNET_PeerIdentity *my_identity)
102 if (NULL == my_identity)
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "Correctly connected to CORE; we are the peer %s.\n",
109 GNUNET_i2s (my_identity));
110 GNUNET_memcpy (&myself,
112 sizeof (struct GNUNET_PeerIdentity));
117 connect_cb (void *cls,
118 const struct GNUNET_PeerIdentity *peer,
119 struct GNUNET_MQ_Handle *mq)
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
122 "Connected to peer %s.\n",
124 if (0 == memcmp (peer,
126 sizeof (struct GNUNET_PeerIdentity)))
128 struct GNUNET_MQ_Envelope *env;
129 struct GNUNET_MessageHeader *msg;
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Connected to myself; sending message!\n");
133 env = GNUNET_MQ_msg (msg,
134 GNUNET_MESSAGE_TYPE_DUMMY);
143 * Main function that will be run by the scheduler.
146 * @param cfg configuration
150 const struct GNUNET_CONFIGURATION_Handle *cfg,
151 struct GNUNET_TESTING_Peer *peer)
153 struct GNUNET_MQ_MessageHandler handlers[] = {
154 GNUNET_MQ_hd_fixed_size (test,
155 GNUNET_MESSAGE_TYPE_DUMMY,
156 struct GNUNET_MessageHeader,
158 GNUNET_MQ_handler_end ()
162 GNUNET_CORE_connecT (cfg,
168 GNUNET_SCHEDULER_add_shutdown (&cleanup,
170 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
177 * The main function to test sending a message to the local peer via core
179 * @param argc number of arguments from the command line
180 * @param argv command line arguments
181 * @return 0 ok, 1 on error
184 main (int argc, char *argv[])
187 if (0 != GNUNET_TESTING_peer_run ("test-core-api-send-to-self",
188 "test_core_api_peer1.conf",
194 /* end of test_core_api_send_to_self.c */