2 This file is part of GNUnet.
3 Copyright (C) 2009, 2015, 2017 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.
21 * @file dht/test_dht_api.c
22 * @brief base test case for dht api
23 * @author Christian Grothoff
25 * This test case tests DHT api to DUMMY DHT service communication.
28 #include "gnunet_util_lib.h"
29 #include "gnunet_hello_lib.h"
30 #include "gnunet_testing_lib.h"
31 #include "gnunet_dht_service.h"
35 * How long until we really give up on a particular testcase portion?
37 #define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
39 static struct GNUNET_DHT_Handle *dht_handle;
41 static struct GNUNET_DHT_GetHandle *get_handle;
43 static struct GNUNET_DHT_PutHandle *put_handle;
47 static struct GNUNET_SCHEDULER_Task *die_task;
51 do_shutdown (void *cls)
55 GNUNET_SCHEDULER_cancel (die_task);
58 if (NULL != put_handle)
60 GNUNET_DHT_put_cancel (put_handle);
63 if (NULL != get_handle)
65 GNUNET_DHT_get_stop (get_handle);
68 GNUNET_DHT_disconnect (dht_handle);
79 "Ending on an unhappy note.\n");
80 GNUNET_SCHEDULER_shutdown ();
86 test_get_iterator (void *cls,
87 struct GNUNET_TIME_Absolute exp,
88 const struct GNUNET_HashCode *key,
89 const struct GNUNET_PeerIdentity *get_path,
90 unsigned int get_path_length,
91 const struct GNUNET_PeerIdentity *put_path,
92 unsigned int put_path_length,
93 enum GNUNET_BLOCK_Type type,
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
98 "test_get_iterator called (we got a result), stopping get request!\n");
99 GNUNET_SCHEDULER_shutdown ();
105 * Signature of the main function of a task.
108 * @param success result of PUT
114 struct GNUNET_HashCode hash;
119 sizeof (struct GNUNET_HashCode));
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 "Called test_get!\n");
122 GNUNET_assert (dht_handle != NULL);
123 get_handle = GNUNET_DHT_get_start (dht_handle,
124 GNUNET_BLOCK_TYPE_TEST,
133 if (NULL == get_handle)
137 GNUNET_SCHEDULER_shutdown ();
145 const struct GNUNET_CONFIGURATION_Handle *cfg,
146 struct GNUNET_TESTING_Peer *peer)
148 struct GNUNET_HashCode hash;
150 size_t data_size = 42;
152 GNUNET_assert (ok == 1);
153 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
155 die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT,
160 sizeof (struct GNUNET_HashCode));
161 data = GNUNET_malloc (data_size);
162 memset (data, 43, data_size);
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Called test_put!\n");
165 dht_handle = GNUNET_DHT_connect (cfg,
167 GNUNET_assert (NULL != dht_handle);
168 put_handle = GNUNET_DHT_put (dht_handle,
172 GNUNET_BLOCK_TYPE_TEST,
175 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT),
186 if (0 != GNUNET_TESTING_peer_run ("test-dht-api",
187 "test_dht_api_data.conf",
193 /* end of test_dht_api.c */