aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/test_dht_api.c')
-rw-r--r--src/dht/test_dht_api.c194
1 files changed, 0 insertions, 194 deletions
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
deleted file mode 100644
index 044983b7e..000000000
--- a/src/dht/test_dht_api.c
+++ /dev/null
@@ -1,194 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009, 2015, 2017 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero 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.
9
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.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file dht/test_dht_api.c
22 * @brief base test case for dht api
23 * @author Christian Grothoff
24 *
25 * This test case tests DHT api to DUMMY DHT service communication.
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_hello_lib.h"
30#include "gnunet_testing_lib.h"
31#include "gnunet_dht_service.h"
32
33
34/**
35 * How long until we really give up on a particular testcase portion?
36 */
37#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
38 60)
39
40static struct GNUNET_DHT_Handle *dht_handle;
41
42static struct GNUNET_DHT_GetHandle *get_handle;
43
44static struct GNUNET_DHT_PutHandle *put_handle;
45
46static int ok = 1;
47
48static struct GNUNET_SCHEDULER_Task *die_task;
49
50
51static void
52do_shutdown (void *cls)
53{
54 if (NULL != die_task)
55 {
56 GNUNET_SCHEDULER_cancel (die_task);
57 die_task = NULL;
58 }
59 if (NULL != put_handle)
60 {
61 GNUNET_DHT_put_cancel (put_handle);
62 put_handle = NULL;
63 }
64 if (NULL != get_handle)
65 {
66 GNUNET_DHT_get_stop (get_handle);
67 get_handle = NULL;
68 }
69 GNUNET_DHT_disconnect (dht_handle);
70 dht_handle = NULL;
71}
72
73
74static void
75end_badly (void *cls)
76{
77 die_task = NULL;
78 fprintf (stderr,
79 "%s",
80 "Ending on an unhappy note.\n");
81 GNUNET_SCHEDULER_shutdown ();
82 ok = 1;
83}
84
85
86static void
87test_get_iterator (void *cls,
88 struct GNUNET_TIME_Absolute exp,
89 const struct GNUNET_HashCode *key,
90 const struct GNUNET_PeerIdentity *trunc_peer,
91 const struct GNUNET_DHT_PathElement *get_path,
92 unsigned int get_path_length,
93 const struct GNUNET_DHT_PathElement *put_path,
94 unsigned int put_path_length,
95 enum GNUNET_BLOCK_Type type,
96 size_t size,
97 const void *data)
98{
99 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
100 "test_get_iterator called (we got a result), stopping get request!\n");
101 GNUNET_SCHEDULER_shutdown ();
102 ok = 0;
103}
104
105
106/**
107 * Signature of the main function of a task.
108 *
109 * @param cls closure
110 */
111static void
112test_get (void *cls)
113{
114 struct GNUNET_HashCode hash;
115
116 put_handle = NULL;
117 memset (&hash,
118 42,
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,
125 &hash,
126 1,
127 GNUNET_DHT_RO_NONE,
128 NULL,
129 0,
130 &test_get_iterator,
131 NULL);
132
133 if (NULL == get_handle)
134 {
135 GNUNET_break (0);
136 ok = 1;
137 GNUNET_SCHEDULER_shutdown ();
138 return;
139 }
140}
141
142
143static void
144run (void *cls,
145 const struct GNUNET_CONFIGURATION_Handle *cfg,
146 struct GNUNET_TESTING_Peer *peer)
147{
148 struct GNUNET_HashCode hash;
149 char *data;
150 size_t data_size = 42;
151
152 GNUNET_assert (ok == 1);
153 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
154 NULL);
155 die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT,
156 &end_badly,
157 NULL);
158 memset (&hash,
159 42,
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,
166 100);
167 GNUNET_assert (NULL != dht_handle);
168 put_handle = GNUNET_DHT_put (dht_handle,
169 &hash,
170 1,
171 GNUNET_DHT_RO_NONE,
172 GNUNET_BLOCK_TYPE_TEST,
173 data_size,
174 data,
175 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT),
176 &test_get,
177 NULL);
178 GNUNET_free (data);
179}
180
181
182int
183main (int argc,
184 char *argv[])
185{
186 if (0 != GNUNET_TESTING_peer_run ("test-dht-api",
187 "test_dht_api_data.conf",
188 &run, NULL))
189 return 1;
190 return ok;
191}
192
193
194/* end of test_dht_api.c */