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 it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
17 * @file core/test_core_api_send_to_self.c
18 * @brief test that sending a message to ourselves via CORE works
19 * @author Philipp Toelke
20 * @author Christian Grothoff
23 #include "gnunet_util_lib.h"
24 #include "gnunet_testing_lib.h"
25 #include "gnunet_protocols.h"
26 #include "gnunet_core_service.h"
27 #include "gnunet_constants.h"
35 * Handle to the cleanup task.
37 static struct GNUNET_SCHEDULER_Task *die_task;
40 * Identity of this peer.
42 static struct GNUNET_PeerIdentity myself;
47 static struct GNUNET_CORE_Handle *core;
51 * Function scheduled as very last function, cleans up after us
58 GNUNET_SCHEDULER_cancel (die_task);
63 GNUNET_CORE_disconnect (core);
66 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
72 * Function scheduled as very last function, cleans up after us
75 do_timeout (void *cls)
77 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
80 GNUNET_SCHEDULER_shutdown ();
85 handle_test (void *cls,
86 const struct GNUNET_MessageHeader *message)
88 GNUNET_SCHEDULER_shutdown ();
95 const struct GNUNET_PeerIdentity *my_identity)
97 if (NULL == my_identity)
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
103 "Correctly connected to CORE; we are the peer %s.\n",
104 GNUNET_i2s (my_identity));
105 GNUNET_memcpy (&myself,
107 sizeof (struct GNUNET_PeerIdentity));
112 connect_cb (void *cls,
113 const struct GNUNET_PeerIdentity *peer,
114 struct GNUNET_MQ_Handle *mq)
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
117 "Connected to peer %s.\n",
119 if (0 == memcmp (peer,
121 sizeof (struct GNUNET_PeerIdentity)))
123 struct GNUNET_MQ_Envelope *env;
124 struct GNUNET_MessageHeader *msg;
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "Connected to myself; sending message!\n");
128 env = GNUNET_MQ_msg (msg,
129 GNUNET_MESSAGE_TYPE_DUMMY);
138 * Main function that will be run by the scheduler.
141 * @param cfg configuration
145 const struct GNUNET_CONFIGURATION_Handle *cfg,
146 struct GNUNET_TESTING_Peer *peer)
148 struct GNUNET_MQ_MessageHandler handlers[] = {
149 GNUNET_MQ_hd_fixed_size (test,
150 GNUNET_MESSAGE_TYPE_DUMMY,
151 struct GNUNET_MessageHeader,
153 GNUNET_MQ_handler_end ()
157 GNUNET_CORE_connect (cfg,
163 GNUNET_SCHEDULER_add_shutdown (&cleanup,
165 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
172 * The main function to test sending a message to the local peer via core
174 * @param argc number of arguments from the command line
175 * @param argv command line arguments
176 * @return 0 ok, 1 on error
179 main (int argc, char *argv[])
182 if (0 != GNUNET_TESTING_peer_run ("test-core-api-send-to-self",
183 "test_core_api_peer1.conf",
189 /* end of test_core_api_send_to_self.c */