diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/hostlist/test_gnunet_daemon_hostlist_learning.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist_learning.c')
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_learning.c | 485 |
1 files changed, 228 insertions, 257 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index f821a7320..7ecca8a85 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c | |||
@@ -43,7 +43,7 @@ | |||
43 | 43 | ||
44 | #define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 44 | #define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
45 | 45 | ||
46 | 46 | ||
47 | struct PeerContext | 47 | struct PeerContext |
48 | { | 48 | { |
49 | struct GNUNET_CONFIGURATION_Handle *cfg; | 49 | struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -66,7 +66,7 @@ static int learned_hostlist_saved; | |||
66 | 66 | ||
67 | static int learned_hostlist_downloaded; | 67 | static int learned_hostlist_downloaded; |
68 | 68 | ||
69 | static char * current_adv_uri; | 69 | static char *current_adv_uri; |
70 | 70 | ||
71 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 71 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
72 | 72 | ||
@@ -78,106 +78,99 @@ static struct PeerContext adv_peer; | |||
78 | 78 | ||
79 | static struct PeerContext learn_peer; | 79 | static struct PeerContext learn_peer; |
80 | 80 | ||
81 | static struct GNUNET_STATISTICS_GetHandle * download_stats; | 81 | static struct GNUNET_STATISTICS_GetHandle *download_stats; |
82 | 82 | ||
83 | static struct GNUNET_STATISTICS_GetHandle * urisrecv_stat; | 83 | static struct GNUNET_STATISTICS_GetHandle *urisrecv_stat; |
84 | 84 | ||
85 | static struct GNUNET_STATISTICS_GetHandle * advsent_stat; | 85 | static struct GNUNET_STATISTICS_GetHandle *advsent_stat; |
86 | 86 | ||
87 | 87 | ||
88 | static void | 88 | static void |
89 | shutdown_testcase() | 89 | shutdown_testcase () |
90 | { | 90 | { |
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown testcase....\n"); |
92 | "Shutdown testcase....\n"); | ||
93 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | 92 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) |
94 | { | 93 | { |
95 | GNUNET_SCHEDULER_cancel (timeout_task); | 94 | GNUNET_SCHEDULER_cancel (timeout_task); |
96 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 95 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
97 | } | 96 | } |
98 | if (NULL != download_stats) | 97 | if (NULL != download_stats) |
99 | { | 98 | { |
100 | GNUNET_STATISTICS_get_cancel (download_stats); | 99 | GNUNET_STATISTICS_get_cancel (download_stats); |
101 | download_stats = NULL; | 100 | download_stats = NULL; |
102 | } | 101 | } |
103 | if (NULL != urisrecv_stat) | 102 | if (NULL != urisrecv_stat) |
104 | { | 103 | { |
105 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); | 104 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); |
106 | urisrecv_stat = NULL; | 105 | urisrecv_stat = NULL; |
107 | } | 106 | } |
108 | if (NULL != advsent_stat) | 107 | if (NULL != advsent_stat) |
109 | { | 108 | { |
110 | GNUNET_STATISTICS_get_cancel (advsent_stat); | 109 | GNUNET_STATISTICS_get_cancel (advsent_stat); |
111 | advsent_stat = NULL; | 110 | advsent_stat = NULL; |
112 | } | 111 | } |
113 | if (check_task != GNUNET_SCHEDULER_NO_TASK) | 112 | if (check_task != GNUNET_SCHEDULER_NO_TASK) |
114 | { | 113 | { |
115 | GNUNET_SCHEDULER_cancel (check_task); | 114 | GNUNET_SCHEDULER_cancel (check_task); |
116 | check_task = GNUNET_SCHEDULER_NO_TASK; | 115 | check_task = GNUNET_SCHEDULER_NO_TASK; |
117 | } | 116 | } |
118 | if (NULL != current_adv_uri) | 117 | if (NULL != current_adv_uri) |
119 | { | 118 | { |
120 | GNUNET_free (current_adv_uri); | 119 | GNUNET_free (current_adv_uri); |
121 | current_adv_uri = NULL; | 120 | current_adv_uri = NULL; |
122 | } | 121 | } |
123 | if (adv_peer.th != NULL) | 122 | if (adv_peer.th != NULL) |
124 | { | 123 | { |
125 | GNUNET_TRANSPORT_disconnect (adv_peer.th); | 124 | GNUNET_TRANSPORT_disconnect (adv_peer.th); |
126 | adv_peer.th = NULL; | 125 | adv_peer.th = NULL; |
127 | } | 126 | } |
128 | if (learn_peer.th != NULL) | 127 | if (learn_peer.th != NULL) |
129 | { | 128 | { |
130 | GNUNET_TRANSPORT_disconnect (learn_peer.th); | 129 | GNUNET_TRANSPORT_disconnect (learn_peer.th); |
131 | learn_peer.th = NULL; | 130 | learn_peer.th = NULL; |
132 | } | 131 | } |
133 | if (adv_peer.core != NULL) | 132 | if (adv_peer.core != NULL) |
134 | { | 133 | { |
135 | GNUNET_CORE_disconnect (adv_peer.core); | 134 | GNUNET_CORE_disconnect (adv_peer.core); |
136 | adv_peer.core = NULL; | 135 | adv_peer.core = NULL; |
137 | } | 136 | } |
138 | if (learn_peer.core != NULL) | 137 | if (learn_peer.core != NULL) |
139 | { | 138 | { |
140 | GNUNET_CORE_disconnect (learn_peer.core); | 139 | GNUNET_CORE_disconnect (learn_peer.core); |
141 | learn_peer.core = NULL; | 140 | learn_peer.core = NULL; |
142 | } | 141 | } |
143 | #if START_ARM | 142 | #if START_ARM |
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
145 | "Killing hostlist server ARM process.\n"); | 144 | "Killing hostlist server ARM process.\n"); |
146 | if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, SIGTERM)) | 145 | if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, SIGTERM)) |
147 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 146 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
148 | "kill"); | 147 | if (GNUNET_OS_process_wait (adv_peer.arm_proc) != GNUNET_OK) |
149 | if (GNUNET_OS_process_wait(adv_peer.arm_proc) != GNUNET_OK) | 148 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
150 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
151 | "waitpid"); | ||
152 | GNUNET_OS_process_close (adv_peer.arm_proc); | 149 | GNUNET_OS_process_close (adv_peer.arm_proc); |
153 | adv_peer.arm_proc = NULL; | 150 | adv_peer.arm_proc = NULL; |
154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
155 | "Killing hostlist client ARM process.\n"); | 152 | "Killing hostlist client ARM process.\n"); |
156 | if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, SIGTERM)) | 153 | if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, SIGTERM)) |
157 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 154 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
158 | "kill"); | 155 | if (GNUNET_OS_process_wait (learn_peer.arm_proc) != GNUNET_OK) |
159 | if (GNUNET_OS_process_wait(learn_peer.arm_proc) != GNUNET_OK) | 156 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
160 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
161 | "waitpid"); | ||
162 | GNUNET_OS_process_close (learn_peer.arm_proc); | 157 | GNUNET_OS_process_close (learn_peer.arm_proc); |
163 | learn_peer.arm_proc = NULL; | 158 | learn_peer.arm_proc = NULL; |
164 | #endif | 159 | #endif |
165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown complete....\n"); |
166 | "Shutdown complete....\n"); | ||
167 | } | 161 | } |
168 | 162 | ||
169 | /** | 163 | /** |
170 | * Timeout, give up. | 164 | * Timeout, give up. |
171 | */ | 165 | */ |
172 | static void | 166 | static void |
173 | timeout_error (void *cls, | 167 | timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
174 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
175 | { | 168 | { |
176 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 169 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
177 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 170 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
178 | "Timeout while executing testcase, test failed.\n"); | 171 | "Timeout while executing testcase, test failed.\n"); |
179 | timeout = GNUNET_YES; | 172 | timeout = GNUNET_YES; |
180 | shutdown_testcase(); | 173 | shutdown_testcase (); |
181 | } | 174 | } |
182 | 175 | ||
183 | 176 | ||
@@ -190,21 +183,17 @@ process_downloads_done (void *cls, int success) | |||
190 | 183 | ||
191 | static int | 184 | static int |
192 | process_downloads (void *cls, | 185 | process_downloads (void *cls, |
193 | const char *subsystem, | 186 | const char *subsystem, |
194 | const char *name, | 187 | const char *name, uint64_t value, int is_persistent) |
195 | uint64_t value, | ||
196 | int is_persistent) | ||
197 | { | 188 | { |
198 | if ( (value >= 2) && | 189 | if ((value >= 2) && (learned_hostlist_downloaded == GNUNET_NO)) |
199 | (learned_hostlist_downloaded == GNUNET_NO) ) | 190 | { |
200 | { | 191 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
201 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 192 | "Peer has successfully downloaded advertised URI\n"); |
202 | "Peer has successfully downloaded advertised URI\n"); | 193 | learned_hostlist_downloaded = GNUNET_YES; |
203 | learned_hostlist_downloaded = GNUNET_YES; | 194 | if ((learned_hostlist_saved == GNUNET_YES) && (adv_sent == GNUNET_YES)) |
204 | if ( (learned_hostlist_saved == GNUNET_YES) && | 195 | shutdown_testcase (); |
205 | (adv_sent == GNUNET_YES) ) | 196 | } |
206 | shutdown_testcase(); | ||
207 | } | ||
208 | return GNUNET_OK; | 197 | return GNUNET_OK; |
209 | } | 198 | } |
210 | 199 | ||
@@ -218,22 +207,18 @@ process_uris_recv_done (void *cls, int success) | |||
218 | 207 | ||
219 | static int | 208 | static int |
220 | process_uris_recv (void *cls, | 209 | process_uris_recv (void *cls, |
221 | const char *subsystem, | 210 | const char *subsystem, |
222 | const char *name, | 211 | const char *name, uint64_t value, int is_persistent) |
223 | uint64_t value, | ||
224 | int is_persistent) | ||
225 | { | 212 | { |
226 | if ( ((struct PeerContext *) cls == &learn_peer) && | 213 | if (((struct PeerContext *) cls == &learn_peer) && |
227 | (value == 1) && | 214 | (value == 1) && (learned_hostlist_saved == GNUNET_NO)) |
228 | (learned_hostlist_saved == GNUNET_NO) ) | 215 | { |
229 | { | 216 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
230 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 217 | "Peer has successfully saved advertised URI\n"); |
231 | "Peer has successfully saved advertised URI\n"); | 218 | learned_hostlist_saved = GNUNET_YES; |
232 | learned_hostlist_saved = GNUNET_YES; | 219 | if ((learned_hostlist_downloaded == GNUNET_YES) && (adv_sent == GNUNET_YES)) |
233 | if ( (learned_hostlist_downloaded == GNUNET_YES) && | 220 | shutdown_testcase (); |
234 | (adv_sent == GNUNET_YES) ) | 221 | } |
235 | shutdown_testcase(); | ||
236 | } | ||
237 | return GNUNET_OK; | 222 | return GNUNET_OK; |
238 | } | 223 | } |
239 | 224 | ||
@@ -247,20 +232,18 @@ process_adv_sent_done (void *cls, int success) | |||
247 | 232 | ||
248 | static int | 233 | static int |
249 | process_adv_sent (void *cls, | 234 | process_adv_sent (void *cls, |
250 | const char *subsystem, | 235 | const char *subsystem, |
251 | const char *name, | 236 | const char *name, uint64_t value, int is_persistent) |
252 | uint64_t value, | ||
253 | int is_persistent) | ||
254 | { | 237 | { |
255 | if ( (value >= 1) && (adv_sent == GNUNET_NO)) | 238 | if ((value >= 1) && (adv_sent == GNUNET_NO)) |
256 | { | 239 | { |
257 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
258 | "Server has successfully sent advertisement\n"); | 241 | "Server has successfully sent advertisement\n"); |
259 | adv_sent = GNUNET_YES; | 242 | adv_sent = GNUNET_YES; |
260 | if ( (learned_hostlist_downloaded == GNUNET_YES) && | 243 | if ((learned_hostlist_downloaded == GNUNET_YES) && |
261 | (learned_hostlist_saved == GNUNET_YES) ) | 244 | (learned_hostlist_saved == GNUNET_YES)) |
262 | shutdown_testcase(); | 245 | shutdown_testcase (); |
263 | } | 246 | } |
264 | return GNUNET_OK; | 247 | return GNUNET_OK; |
265 | } | 248 | } |
266 | 249 | ||
@@ -269,8 +252,7 @@ process_adv_sent (void *cls, | |||
269 | * Check the server statistics regularly | 252 | * Check the server statistics regularly |
270 | */ | 253 | */ |
271 | static void | 254 | static void |
272 | check_statistics (void *cls, | 255 | check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
273 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
274 | { | 256 | { |
275 | char *stat; | 257 | char *stat; |
276 | 258 | ||
@@ -278,105 +260,102 @@ check_statistics (void *cls, | |||
278 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 260 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
279 | return; | 261 | return; |
280 | GNUNET_asprintf (&stat, | 262 | GNUNET_asprintf (&stat, |
281 | gettext_noop("# advertised URI `%s' downloaded"), | 263 | gettext_noop ("# advertised URI `%s' downloaded"), |
282 | current_adv_uri); | 264 | current_adv_uri); |
283 | if (NULL != learn_peer.stats) | 265 | if (NULL != learn_peer.stats) |
284 | { | 266 | { |
285 | if (NULL != download_stats) | 267 | if (NULL != download_stats) |
286 | GNUNET_STATISTICS_get_cancel (download_stats); | 268 | GNUNET_STATISTICS_get_cancel (download_stats); |
287 | download_stats = GNUNET_STATISTICS_get (learn_peer.stats, | 269 | download_stats = GNUNET_STATISTICS_get (learn_peer.stats, |
288 | "hostlist", | 270 | "hostlist", |
289 | stat, | 271 | stat, |
290 | GNUNET_TIME_UNIT_MINUTES, | 272 | GNUNET_TIME_UNIT_MINUTES, |
291 | &process_downloads_done, | 273 | &process_downloads_done, |
292 | &process_downloads, | 274 | &process_downloads, &learn_peer); |
293 | &learn_peer); | 275 | if (NULL != urisrecv_stat) |
294 | if (NULL != urisrecv_stat) | 276 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); |
295 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); | 277 | urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats, |
296 | urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats, | 278 | "hostlist", |
297 | "hostlist", | 279 | gettext_noop |
298 | gettext_noop("# advertised hostlist URIs"), | 280 | ("# advertised hostlist URIs"), |
299 | GNUNET_TIME_UNIT_MINUTES, | 281 | GNUNET_TIME_UNIT_MINUTES, |
300 | &process_uris_recv_done, | 282 | &process_uris_recv_done, |
301 | &process_uris_recv, | 283 | &process_uris_recv, &learn_peer); |
302 | &learn_peer); | 284 | } |
303 | } | ||
304 | GNUNET_free (stat); | 285 | GNUNET_free (stat); |
305 | if ( NULL != adv_peer.stats) | 286 | if (NULL != adv_peer.stats) |
306 | { | 287 | { |
307 | if (NULL != advsent_stat) | 288 | if (NULL != advsent_stat) |
308 | GNUNET_STATISTICS_get_cancel (advsent_stat); | 289 | GNUNET_STATISTICS_get_cancel (advsent_stat); |
309 | advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats, | 290 | advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats, |
310 | "hostlist", | 291 | "hostlist", |
311 | gettext_noop("# hostlist advertisements send"), | 292 | gettext_noop |
312 | GNUNET_TIME_UNIT_MINUTES, | 293 | ("# hostlist advertisements send"), |
313 | &process_adv_sent_done, | 294 | GNUNET_TIME_UNIT_MINUTES, |
314 | &process_adv_sent, | 295 | &process_adv_sent_done, |
315 | NULL); | 296 | &process_adv_sent, NULL); |
316 | } | 297 | } |
317 | check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, | 298 | check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, |
318 | &check_statistics, | 299 | &check_statistics, NULL); |
319 | NULL); | ||
320 | } | 300 | } |
321 | 301 | ||
322 | 302 | ||
323 | /** | 303 | /** |
324 | * Core handler for p2p hostlist advertisements | 304 | * Core handler for p2p hostlist advertisements |
325 | */ | 305 | */ |
326 | static int | 306 | static int |
327 | ad_arrive_handler (void *cls, | 307 | ad_arrive_handler (void *cls, |
328 | const struct GNUNET_PeerIdentity * peer, | 308 | const struct GNUNET_PeerIdentity *peer, |
329 | const struct GNUNET_MessageHeader * message, | 309 | const struct GNUNET_MessageHeader *message, |
330 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 310 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
331 | { | 311 | { |
332 | char *hostname; | 312 | char *hostname; |
333 | char *expected_uri; | 313 | char *expected_uri; |
334 | unsigned long long port; | 314 | unsigned long long port; |
335 | const struct GNUNET_MessageHeader * incoming; | 315 | const struct GNUNET_MessageHeader *incoming; |
336 | const char *end; | 316 | const char *end; |
337 | 317 | ||
338 | if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, | 318 | if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, |
339 | "HOSTLIST", | 319 | "HOSTLIST", |
340 | "HTTPPORT", | 320 | "HTTPPORT", &port)) |
341 | &port)) | 321 | { |
342 | { | 322 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 323 | "Could not read advertising server's configuration\n"); |
344 | "Could not read advertising server's configuration\n" ); | 324 | return GNUNET_SYSERR; |
345 | return GNUNET_SYSERR; | 325 | } |
346 | } | 326 | |
347 | 327 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, | |
348 | if ( GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, | 328 | "HOSTLIST", |
349 | "HOSTLIST", | 329 | "EXTERNAL_DNS_NAME", |
350 | "EXTERNAL_DNS_NAME", | 330 | &hostname)) |
351 | &hostname)) | ||
352 | hostname = GNUNET_RESOLVER_local_fqdn_get (); | 331 | hostname = GNUNET_RESOLVER_local_fqdn_get (); |
353 | GNUNET_asprintf (&expected_uri, | 332 | GNUNET_asprintf (&expected_uri, |
354 | "http://%s:%u/", | 333 | "http://%s:%u/", |
355 | hostname != NULL ? hostname : "localhost", | 334 | hostname != NULL ? hostname : "localhost", |
356 | (unsigned int) port); | 335 | (unsigned int) port); |
357 | incoming = (const struct GNUNET_MessageHeader *) message; | 336 | incoming = (const struct GNUNET_MessageHeader *) message; |
358 | end = (const char*) &incoming[1]; | 337 | end = (const char *) &incoming[1]; |
359 | if ('\0' != end[ntohs(message->size) - sizeof (struct GNUNET_MessageHeader) - 1]) | 338 | if ('\0' != |
360 | { | 339 | end[ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - 1]) |
361 | GNUNET_break (0); | 340 | { |
362 | GNUNET_free (expected_uri); | 341 | GNUNET_break (0); |
363 | GNUNET_free_non_null (hostname); | 342 | GNUNET_free (expected_uri); |
364 | return GNUNET_SYSERR; | 343 | GNUNET_free_non_null (hostname); |
365 | } | 344 | return GNUNET_SYSERR; |
345 | } | ||
366 | current_adv_uri = GNUNET_strdup (end); | 346 | current_adv_uri = GNUNET_strdup (end); |
367 | if ( 0 == strcmp( expected_uri, current_adv_uri ) ) | 347 | if (0 == strcmp (expected_uri, current_adv_uri)) |
368 | { | 348 | { |
369 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
370 | "Received hostlist advertisement with URI `%s' as expected\n", | 350 | "Received hostlist advertisement with URI `%s' as expected\n", |
371 | current_adv_uri); | 351 | current_adv_uri); |
372 | adv_arrived = GNUNET_YES; | 352 | adv_arrived = GNUNET_YES; |
373 | adv_sent = GNUNET_YES; | 353 | adv_sent = GNUNET_YES; |
374 | } | 354 | } |
375 | else | 355 | else |
376 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 356 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
377 | "Expected URI `%s' and recieved URI `%s' differ\n", | 357 | "Expected URI `%s' and recieved URI `%s' differ\n", |
378 | expected_uri, | 358 | expected_uri, current_adv_uri); |
379 | current_adv_uri); | ||
380 | GNUNET_free (expected_uri); | 359 | GNUNET_free (expected_uri); |
381 | GNUNET_free_non_null (hostname); | 360 | GNUNET_free_non_null (hostname); |
382 | return GNUNET_OK; | 361 | return GNUNET_OK; |
@@ -387,83 +366,79 @@ ad_arrive_handler (void *cls, | |||
387 | * List of handlers if we are learning. | 366 | * List of handlers if we are learning. |
388 | */ | 367 | */ |
389 | static struct GNUNET_CORE_MessageHandler learn_handlers[] = { | 368 | static struct GNUNET_CORE_MessageHandler learn_handlers[] = { |
390 | { &ad_arrive_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, | 369 | {&ad_arrive_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, |
391 | { NULL, 0, 0 } | 370 | {NULL, 0, 0} |
392 | }; | 371 | }; |
393 | 372 | ||
394 | 373 | ||
395 | static void | 374 | static void |
396 | setup_learn_peer (struct PeerContext *p, | 375 | setup_learn_peer (struct PeerContext *p, const char *cfgname) |
397 | const char *cfgname) | ||
398 | { | 376 | { |
399 | char * filename; | 377 | char *filename; |
400 | unsigned int result; | 378 | unsigned int result; |
401 | 379 | ||
402 | p->cfg = GNUNET_CONFIGURATION_create (); | 380 | p->cfg = GNUNET_CONFIGURATION_create (); |
403 | #if START_ARM | 381 | #if START_ARM |
404 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 382 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
405 | "gnunet-service-arm", | 383 | "gnunet-service-arm", |
406 | #if VERBOSE | 384 | #if VERBOSE |
407 | "-L", "DEBUG", | 385 | "-L", "DEBUG", |
408 | #endif | 386 | #endif |
409 | "-c", cfgname, NULL); | 387 | "-c", cfgname, NULL); |
410 | #endif | 388 | #endif |
411 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 389 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
412 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, | 390 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, |
413 | "HOSTLIST", | 391 | "HOSTLIST", |
414 | "HOSTLISTFILE", | 392 | "HOSTLISTFILE", |
415 | &filename)) | 393 | &filename)) |
394 | { | ||
395 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | ||
416 | { | 396 | { |
417 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 397 | result = UNLINK (filename); |
418 | { | 398 | if (result == 0) |
419 | result = UNLINK (filename); | 399 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
420 | if (result == 0) | 400 | _("Hostlist file `%s' was removed\n"), filename); |
421 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
422 | _("Hostlist file `%s' was removed\n"),filename); | ||
423 | } | ||
424 | GNUNET_free (filename); | ||
425 | } | 401 | } |
402 | GNUNET_free (filename); | ||
403 | } | ||
426 | p->core = GNUNET_CORE_connect (p->cfg, | 404 | p->core = GNUNET_CORE_connect (p->cfg, |
427 | 1, | 405 | 1, |
428 | NULL, | 406 | NULL, |
429 | NULL, | 407 | NULL, |
430 | NULL, NULL, NULL, | 408 | NULL, NULL, NULL, |
431 | NULL, GNUNET_NO, | 409 | NULL, GNUNET_NO, |
432 | NULL, GNUNET_NO, | 410 | NULL, GNUNET_NO, learn_handlers); |
433 | learn_handlers ); | 411 | GNUNET_assert (NULL != p->core); |
434 | GNUNET_assert ( NULL != p->core ); | ||
435 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); | 412 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); |
436 | GNUNET_assert ( NULL != p->stats ); | 413 | GNUNET_assert (NULL != p->stats); |
437 | } | 414 | } |
438 | 415 | ||
439 | 416 | ||
440 | static void | 417 | static void |
441 | setup_adv_peer (struct PeerContext *p, | 418 | setup_adv_peer (struct PeerContext *p, const char *cfgname) |
442 | const char *cfgname) | ||
443 | { | 419 | { |
444 | p->cfg = GNUNET_CONFIGURATION_create (); | 420 | p->cfg = GNUNET_CONFIGURATION_create (); |
445 | #if START_ARM | 421 | #if START_ARM |
446 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 422 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
447 | "gnunet-service-arm", | 423 | "gnunet-service-arm", |
448 | #if VERBOSE | 424 | #if VERBOSE |
449 | "-L", "DEBUG", | 425 | "-L", "DEBUG", |
450 | #endif | 426 | #endif |
451 | "-c", cfgname, NULL); | 427 | "-c", cfgname, NULL); |
452 | #endif | 428 | #endif |
453 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 429 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
454 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); | 430 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); |
455 | GNUNET_assert ( NULL != p->stats ); | 431 | GNUNET_assert (NULL != p->stats); |
456 | } | 432 | } |
457 | 433 | ||
458 | 434 | ||
459 | static void | 435 | static void |
460 | run (void *cls, | 436 | run (void *cls, |
461 | char *const *args, | 437 | char *const *args, |
462 | const char *cfgfile, | 438 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
463 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
464 | { | 439 | { |
465 | timeout = GNUNET_NO; | 440 | timeout = GNUNET_NO; |
466 | adv_sent =GNUNET_NO; | 441 | adv_sent = GNUNET_NO; |
467 | 442 | ||
468 | adv_arrived = 0; | 443 | adv_arrived = 0; |
469 | learned_hostlist_saved = GNUNET_NO; | 444 | learned_hostlist_saved = GNUNET_NO; |
@@ -473,13 +448,10 @@ run (void *cls, | |||
473 | 448 | ||
474 | setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf"); | 449 | setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf"); |
475 | setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf"); | 450 | setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf"); |
476 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 451 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
477 | &timeout_error, | ||
478 | NULL); | ||
479 | 452 | ||
480 | check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, | 453 | check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, |
481 | &check_statistics, | 454 | &check_statistics, NULL); |
482 | NULL); | ||
483 | } | 455 | } |
484 | 456 | ||
485 | 457 | ||
@@ -487,7 +459,8 @@ static int | |||
487 | check () | 459 | check () |
488 | { | 460 | { |
489 | unsigned int failed; | 461 | unsigned int failed; |
490 | char *const argv[] = { | 462 | |
463 | char *const argv[] = { | ||
491 | "test-gnunet-daemon-hostlist-learning", | 464 | "test-gnunet-daemon-hostlist-learning", |
492 | "-c", "learning_data.conf", | 465 | "-c", "learning_data.conf", |
493 | #if VERBOSE | 466 | #if VERBOSE |
@@ -501,39 +474,37 @@ check () | |||
501 | 474 | ||
502 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 475 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
503 | argv, "test-gnunet-daemon-hostlist-learning", | 476 | argv, "test-gnunet-daemon-hostlist-learning", |
504 | "nohelp", options, | 477 | "nohelp", options, &run, NULL); |
505 | &run, NULL); | ||
506 | failed = GNUNET_NO; | 478 | failed = GNUNET_NO; |
507 | if (timeout == GNUNET_YES) | 479 | if (timeout == GNUNET_YES) |
508 | { | 480 | { |
509 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 481 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase timeout\n"); |
510 | "Testcase timeout\n"); | 482 | failed = GNUNET_YES; |
511 | failed = GNUNET_YES; | 483 | } |
512 | } | ||
513 | if (adv_arrived != GNUNET_YES) | 484 | if (adv_arrived != GNUNET_YES) |
514 | { | 485 | { |
515 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 486 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
516 | "Learning peer did not receive advertisement from server\n"); | 487 | "Learning peer did not receive advertisement from server\n"); |
517 | failed = GNUNET_YES; | 488 | failed = GNUNET_YES; |
518 | } | 489 | } |
519 | if ( learned_hostlist_saved == GNUNET_NO ) | 490 | if (learned_hostlist_saved == GNUNET_NO) |
520 | { | 491 | { |
521 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 492 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
522 | "Advertised hostlist was not saved in datastore\n"); | 493 | "Advertised hostlist was not saved in datastore\n"); |
523 | failed = GNUNET_YES; | 494 | failed = GNUNET_YES; |
524 | } | 495 | } |
525 | if (learned_hostlist_downloaded == GNUNET_NO) | 496 | if (learned_hostlist_downloaded == GNUNET_NO) |
526 | { | 497 | { |
527 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 498 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
528 | "Advertised hostlist could not be downloaded from server\n"); | 499 | "Advertised hostlist could not be downloaded from server\n"); |
529 | failed = GNUNET_YES; | 500 | failed = GNUNET_YES; |
530 | } | 501 | } |
531 | if (adv_sent == GNUNET_NO) | 502 | if (adv_sent == GNUNET_NO) |
532 | { | 503 | { |
533 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 504 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
534 | "Advertised was not sent from server to client\n"); | 505 | "Advertised was not sent from server to client\n"); |
535 | failed = GNUNET_YES; | 506 | failed = GNUNET_YES; |
536 | } | 507 | } |
537 | if (GNUNET_YES == failed) | 508 | if (GNUNET_YES == failed) |
538 | return GNUNET_YES; | 509 | return GNUNET_YES; |
539 | return GNUNET_NO; | 510 | return GNUNET_NO; |
@@ -542,7 +513,7 @@ check () | |||
542 | 513 | ||
543 | int | 514 | int |
544 | main (int argc, char *argv[]) | 515 | main (int argc, char *argv[]) |
545 | { | 516 | { |
546 | int ret; | 517 | int ret; |
547 | 518 | ||
548 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); | 519 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); |
@@ -565,12 +536,12 @@ main (int argc, char *argv[]) | |||
565 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); | 536 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); |
566 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); | 537 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); |
567 | if (GNUNET_YES == GNUNET_DISK_file_test ("hostlists_learn_peer.file")) | 538 | if (GNUNET_YES == GNUNET_DISK_file_test ("hostlists_learn_peer.file")) |
568 | { | 539 | { |
569 | if (0 == UNLINK("hostlists_learn_peer.file")) | 540 | if (0 == UNLINK ("hostlists_learn_peer.file")) |
570 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 541 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
571 | "Hostlist file hostlists_learn_peer.file was removed\n"); | 542 | "Hostlist file hostlists_learn_peer.file was removed\n"); |
572 | } | 543 | } |
573 | return ret; | 544 | return ret; |
574 | } | 545 | } |
575 | 546 | ||
576 | /* end of test_gnunet_daemon_hostlist.c */ | 547 | /* end of test_gnunet_daemon_hostlist.c */ |