diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-04-04 14:14:15 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-04-04 14:14:15 +0000 |
commit | 90c0d0137a71dc752066ae2922ae0dedf6f8b63e (patch) | |
tree | 7a92db44e539cd98ac239e70591c77507a6ec924 /src/dht/test_dht_api.c | |
parent | f5ee95ef07151a06778fa02a6d74689dcbb0bdf5 (diff) | |
download | gnunet-90c0d0137a71dc752066ae2922ae0dedf6f8b63e.tar.gz gnunet-90c0d0137a71dc752066ae2922ae0dedf6f8b63e.zip |
service does simple put and get into datacache, test case verifies it works
Diffstat (limited to 'src/dht/test_dht_api.c')
-rw-r--r-- | src/dht/test_dht_api.c | 128 |
1 files changed, 77 insertions, 51 deletions
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 9dc429148..f9d9e008c 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c | |||
@@ -75,8 +75,7 @@ GNUNET_SCHEDULER_TaskIdentifier die_task; | |||
75 | 75 | ||
76 | 76 | ||
77 | static void | 77 | static void |
78 | end (void *cls, | 78 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
79 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
80 | { | 79 | { |
81 | /* do work here */ | 80 | /* do work here */ |
82 | GNUNET_SCHEDULER_cancel (sched, die_task); | 81 | GNUNET_SCHEDULER_cancel (sched, die_task); |
@@ -86,15 +85,17 @@ end (void *cls, | |||
86 | die_task = GNUNET_SCHEDULER_NO_TASK; | 85 | die_task = GNUNET_SCHEDULER_NO_TASK; |
87 | 86 | ||
88 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 87 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) |
89 | { | 88 | { |
90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DHT disconnected, returning FAIL!\n"); | 89 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
91 | ok = 365; | 90 | "DHT disconnected, returning FAIL!\n"); |
92 | } | 91 | ok = 365; |
92 | } | ||
93 | else | 93 | else |
94 | { | 94 | { |
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DHT disconnected, returning success!\n"); | 95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
96 | ok = 0; | 96 | "DHT disconnected, returning success!\n"); |
97 | } | 97 | ok = 0; |
98 | } | ||
98 | } | 99 | } |
99 | 100 | ||
100 | static void | 101 | static void |
@@ -114,7 +115,7 @@ end_badly () | |||
114 | { | 115 | { |
115 | /* do work here */ | 116 | /* do work here */ |
116 | #if VERBOSE | 117 | #if VERBOSE |
117 | fprintf(stderr, "Ending on an unhappy note.\n"); | 118 | fprintf (stderr, "Ending on an unhappy note.\n"); |
118 | #endif | 119 | #endif |
119 | 120 | ||
120 | GNUNET_DHT_disconnect (p1.dht_handle); | 121 | GNUNET_DHT_disconnect (p1.dht_handle); |
@@ -129,18 +130,18 @@ end_badly () | |||
129 | * @param cls closure | 130 | * @param cls closure |
130 | * @param tc context information (why was this task triggered now) | 131 | * @param tc context information (why was this task triggered now) |
131 | */ | 132 | */ |
132 | void test_find_peer_stop (void *cls, | 133 | void |
133 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 134 | test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
134 | { | 135 | { |
135 | struct PeerContext *peer = cls; | 136 | struct PeerContext *peer = cls; |
136 | 137 | ||
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n"); | 138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n"); |
138 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 139 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) |
139 | GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL); | 140 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); |
140 | 141 | ||
141 | GNUNET_assert (peer->dht_handle != NULL); | 142 | GNUNET_assert (peer->dht_handle != NULL); |
142 | 143 | ||
143 | GNUNET_DHT_find_peer_stop(peer->find_peer_handle, &end, &p1); | 144 | GNUNET_DHT_find_peer_stop (peer->find_peer_handle, &end, &p1); |
144 | 145 | ||
145 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1); | 146 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1); |
146 | 147 | ||
@@ -152,20 +153,22 @@ void test_find_peer_stop (void *cls, | |||
152 | * @param cls closure | 153 | * @param cls closure |
153 | * @param tc context information (why was this task triggered now) | 154 | * @param tc context information (why was this task triggered now) |
154 | */ | 155 | */ |
155 | void test_find_peer (void *cls, | 156 | void |
156 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 157 | test_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
157 | { | 158 | { |
158 | struct PeerContext *peer = cls; | 159 | struct PeerContext *peer = cls; |
159 | GNUNET_HashCode hash; | 160 | GNUNET_HashCode hash; |
160 | memset(&hash, 42, sizeof(GNUNET_HashCode)); | 161 | memset (&hash, 42, sizeof (GNUNET_HashCode)); |
161 | 162 | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n"); | 163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n"); |
163 | GNUNET_assert (peer->dht_handle != NULL); | 164 | GNUNET_assert (peer->dht_handle != NULL); |
164 | 165 | ||
165 | peer->find_peer_handle = GNUNET_DHT_find_peer_start(peer->dht_handle, TIMEOUT, 0, NULL, &hash, NULL, NULL, &test_find_peer_stop, &p1); | 166 | peer->find_peer_handle = |
167 | GNUNET_DHT_find_peer_start (peer->dht_handle, TIMEOUT, 0, NULL, &hash, | ||
168 | NULL, NULL, &test_find_peer_stop, &p1); | ||
166 | 169 | ||
167 | if (peer->find_peer_handle == NULL) | 170 | if (peer->find_peer_handle == NULL) |
168 | GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1); | 171 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); |
169 | } | 172 | } |
170 | 173 | ||
171 | /** | 174 | /** |
@@ -174,21 +177,34 @@ void test_find_peer (void *cls, | |||
174 | * @param cls closure | 177 | * @param cls closure |
175 | * @param tc context information (why was this task triggered now) | 178 | * @param tc context information (why was this task triggered now) |
176 | */ | 179 | */ |
177 | void test_put (void *cls, | 180 | void |
178 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 181 | test_get_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
179 | { | 182 | { |
180 | struct PeerContext *peer = cls; | 183 | struct PeerContext *peer = cls; |
181 | GNUNET_HashCode hash; | 184 | |
182 | char *data; | 185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); |
183 | size_t data_size = 42; | 186 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) |
184 | memset(&hash, 42, sizeof(GNUNET_HashCode)); | 187 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); |
185 | data = GNUNET_malloc(data_size); | 188 | |
186 | memset(data, 43, data_size); | ||
187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_put!\n"); | ||
188 | GNUNET_assert (peer->dht_handle != NULL); | 189 | GNUNET_assert (peer->dht_handle != NULL); |
189 | 190 | ||
190 | GNUNET_DHT_put(peer->dht_handle, &hash, 0, data_size, data, GNUNET_TIME_relative_to_absolute(TIMEOUT), TIMEOUT, &test_find_peer, &p1); | 191 | GNUNET_DHT_get_stop (peer->get_handle, &test_find_peer, &p1); |
192 | |||
193 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); | ||
194 | |||
195 | } | ||
196 | |||
197 | void | ||
198 | test_get_iterator (void *cls, | ||
199 | struct GNUNET_TIME_Absolute exp, | ||
200 | const GNUNET_HashCode * key, | ||
201 | uint32_t type, uint32_t size, const void *data) | ||
202 | { | ||
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
204 | "test_get_iterator called (we got a result), stopping get request!\n"); | ||
191 | 205 | ||
206 | GNUNET_SCHEDULER_add_continuation (sched, &test_get_stop, &p1, | ||
207 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
192 | } | 208 | } |
193 | 209 | ||
194 | /** | 210 | /** |
@@ -197,21 +213,23 @@ void test_put (void *cls, | |||
197 | * @param cls closure | 213 | * @param cls closure |
198 | * @param tc context information (why was this task triggered now) | 214 | * @param tc context information (why was this task triggered now) |
199 | */ | 215 | */ |
200 | void test_get_stop (void *cls, | 216 | void |
201 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 217 | test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
202 | { | 218 | { |
203 | struct PeerContext *peer = cls; | 219 | struct PeerContext *peer = cls; |
220 | GNUNET_HashCode hash; | ||
221 | memset (&hash, 42, sizeof (GNUNET_HashCode)); | ||
204 | 222 | ||
205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); | 223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get!\n"); |
206 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | ||
207 | GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL); | ||
208 | 224 | ||
209 | GNUNET_assert (peer->dht_handle != NULL); | 225 | GNUNET_assert (peer->dht_handle != NULL); |
210 | 226 | ||
211 | GNUNET_DHT_get_stop(peer->get_handle, &test_put, &p1); | 227 | peer->get_handle = |
212 | 228 | GNUNET_DHT_get_start (peer->dht_handle, TIMEOUT, 42, &hash, | |
213 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); | 229 | &test_get_iterator, NULL, NULL, NULL); |
214 | 230 | ||
231 | if (peer->get_handle == NULL) | ||
232 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | ||
215 | } | 233 | } |
216 | 234 | ||
217 | /** | 235 | /** |
@@ -220,21 +238,25 @@ void test_get_stop (void *cls, | |||
220 | * @param cls closure | 238 | * @param cls closure |
221 | * @param tc context information (why was this task triggered now) | 239 | * @param tc context information (why was this task triggered now) |
222 | */ | 240 | */ |
223 | void test_get (void *cls, | 241 | void |
224 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 242 | test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
225 | { | 243 | { |
226 | struct PeerContext *peer = cls; | 244 | struct PeerContext *peer = cls; |
227 | GNUNET_HashCode hash; | 245 | GNUNET_HashCode hash; |
228 | memset(&hash, 42, sizeof(GNUNET_HashCode)); | 246 | char *data; |
229 | 247 | size_t data_size = 42; | |
230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get!\n"); | 248 | memset (&hash, 42, sizeof (GNUNET_HashCode)); |
249 | data = GNUNET_malloc (data_size); | ||
250 | memset (data, 43, data_size); | ||
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_put!\n"); | ||
231 | peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg, 100); | 252 | peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg, 100); |
253 | |||
232 | GNUNET_assert (peer->dht_handle != NULL); | 254 | GNUNET_assert (peer->dht_handle != NULL); |
233 | 255 | ||
234 | peer->get_handle = GNUNET_DHT_get_start(peer->dht_handle, TIMEOUT, 42, &hash, NULL, NULL, &test_get_stop, &p1); | 256 | GNUNET_DHT_put (peer->dht_handle, &hash, 0, data_size, data, |
257 | GNUNET_TIME_relative_to_absolute (TIMEOUT), TIMEOUT, | ||
258 | &test_get, &p1); | ||
235 | 259 | ||
236 | if (peer->get_handle == NULL) | ||
237 | GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1); | ||
238 | } | 260 | } |
239 | 261 | ||
240 | static void | 262 | static void |
@@ -264,11 +286,16 @@ run (void *cls, | |||
264 | sched = s; | 286 | sched = s; |
265 | 287 | ||
266 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | 288 | die_task = GNUNET_SCHEDULER_add_delayed (sched, |
267 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1), &end_badly, NULL); | 289 | GNUNET_TIME_relative_multiply |
290 | (GNUNET_TIME_UNIT_MINUTES, 1), | ||
291 | &end_badly, NULL); | ||
268 | 292 | ||
269 | setup_peer (&p1, "test_dht_api_peer1.conf"); | 293 | setup_peer (&p1, "test_dht_api_peer1.conf"); |
270 | 294 | ||
271 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get, &p1); | 295 | GNUNET_SCHEDULER_add_delayed (sched, |
296 | GNUNET_TIME_relative_multiply | ||
297 | (GNUNET_TIME_UNIT_SECONDS, 1), &test_put, | ||
298 | &p1); | ||
272 | } | 299 | } |
273 | 300 | ||
274 | static int | 301 | static int |
@@ -290,8 +317,7 @@ check () | |||
290 | 317 | ||
291 | ok = 1; | 318 | ok = 1; |
292 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 319 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
293 | argv, "test-dht-api", "nohelp", | 320 | argv, "test-dht-api", "nohelp", options, &run, &ok); |
294 | options, &run, &ok); | ||
295 | stop_arm (&p1); | 321 | stop_arm (&p1); |
296 | return ok; | 322 | return ok; |
297 | } | 323 | } |
@@ -314,7 +340,7 @@ main (int argc, char *argv[]) | |||
314 | NULL); | 340 | NULL); |
315 | ret = check (); | 341 | ret = check (); |
316 | 342 | ||
317 | //GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-dht-peer-1"); | 343 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-dht-peer-1"); |
318 | 344 | ||
319 | return ret; | 345 | return ret; |
320 | } | 346 | } |