diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-08-12 07:03:34 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-08-12 07:03:34 +0000 |
commit | b19fa751b866bb6855ed92beb2bee30917f868c8 (patch) | |
tree | 76f0433e011d834a672d10d285369b9b7f1fb17e /src/transport/test_transport_api.c | |
parent | 5434646c91cc203f4113018503b06ada292060d4 (diff) | |
download | gnunet-b19fa751b866bb6855ed92beb2bee30917f868c8.tar.gz gnunet-b19fa751b866bb6855ed92beb2bee30917f868c8.zip |
test_transport_api ported to use new testing lib
Diffstat (limited to 'src/transport/test_transport_api.c')
-rw-r--r-- | src/transport/test_transport_api.c | 462 |
1 files changed, 71 insertions, 391 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 84cb2421d..449cd38d0 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -55,42 +55,20 @@ | |||
55 | 55 | ||
56 | #define MTYPE 12345 | 56 | #define MTYPE 12345 |
57 | 57 | ||
58 | static struct PeerContext p1; | ||
59 | |||
60 | static struct PeerContext p2; | ||
61 | |||
62 | static int ok; | 58 | static int ok; |
63 | 59 | ||
64 | static int is_tcp; | ||
65 | |||
66 | static int is_tcp_nat; | ||
67 | |||
68 | static int is_udp; | ||
69 | |||
70 | static int is_unix; | ||
71 | |||
72 | static int is_udp_nat; | ||
73 | |||
74 | static int is_http; | ||
75 | |||
76 | static int is_https; | ||
77 | |||
78 | static int is_multi_protocol; | ||
79 | |||
80 | static int is_wlan; | ||
81 | |||
82 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 60 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
83 | 61 | ||
84 | static GNUNET_SCHEDULER_TaskIdentifier tct; | 62 | struct PeerContext * p1; |
85 | |||
86 | static char * key_file_p1; | ||
87 | static char * cert_file_p1; | ||
88 | 63 | ||
89 | static char * key_file_p2; | 64 | struct PeerContext * p2; |
90 | static char * cert_file_p2; | ||
91 | 65 | ||
92 | struct GNUNET_TRANSPORT_TransmitHandle * th; | 66 | struct GNUNET_TRANSPORT_TransmitHandle * th; |
93 | 67 | ||
68 | char * cfg_file_p1; | ||
69 | |||
70 | char * cfg_file_p2; | ||
71 | |||
94 | #if VERBOSE | 72 | #if VERBOSE |
95 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 73 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) |
96 | #else | 74 | #else |
@@ -101,103 +79,29 @@ struct GNUNET_TRANSPORT_TransmitHandle * th; | |||
101 | static void | 79 | static void |
102 | end () | 80 | end () |
103 | { | 81 | { |
104 | GNUNET_assert (ok == 6); | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); |
105 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
106 | GNUNET_SCHEDULER_cancel (die_task); | ||
107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
108 | "Disconnecting from transports!\n"); | ||
109 | if (th != NULL) | ||
110 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); | ||
111 | th = NULL; | ||
112 | |||
113 | GNUNET_TRANSPORT_disconnect (p1.th); | ||
114 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
115 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
117 | "Transports disconnected, returning success!\n"); | ||
118 | ok = 0; | ||
119 | } | ||
120 | |||
121 | static void | ||
122 | stop_arm (struct PeerContext *p) | ||
123 | { | ||
124 | #if START_ARM | ||
125 | if (NULL != p->arm_proc) | ||
126 | { | ||
127 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
128 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
129 | GNUNET_OS_process_wait (p->arm_proc); | ||
130 | GNUNET_OS_process_close (p->arm_proc); | ||
131 | p->arm_proc = NULL; | ||
132 | } | ||
133 | #endif | ||
134 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
135 | } | ||
136 | |||
137 | 83 | ||
84 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
85 | GNUNET_SCHEDULER_cancel(die_task); | ||
138 | 86 | ||
87 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); | ||
88 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); | ||
139 | 89 | ||
140 | static void | 90 | ok = 0; |
141 | exchange_hello_last (void *cls, | ||
142 | const struct GNUNET_MessageHeader *message) | ||
143 | { | ||
144 | struct PeerContext *me = cls; | ||
145 | |||
146 | GNUNET_assert (message != NULL); | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
148 | "Exchanging HELLO of size %d with peer (%s)!\n", | ||
149 | (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), | ||
150 | GNUNET_i2s (&me->id)); | ||
151 | GNUNET_assert (GNUNET_OK == | ||
152 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | ||
153 | message, &me->id)); | ||
154 | GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); | ||
155 | } | ||
156 | |||
157 | |||
158 | static void | ||
159 | exchange_hello (void *cls, | ||
160 | const struct GNUNET_MessageHeader *message) | ||
161 | { | ||
162 | struct PeerContext *me = cls; | ||
163 | |||
164 | GNUNET_assert (message != NULL); | ||
165 | GNUNET_assert (GNUNET_OK == | ||
166 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | ||
167 | message, &me->id)); | ||
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
169 | "Exchanging HELLO of size %d from peer %s!\n", | ||
170 | (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), | ||
171 | GNUNET_i2s (&me->id)); | ||
172 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); | ||
173 | } | 91 | } |
174 | 92 | ||
175 | |||
176 | static void | 93 | static void |
177 | end_badly () | 94 | end_badly () |
178 | { | 95 | { |
179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | 96 | die_task = GNUNET_SCHEDULER_NO_TASK; |
180 | GNUNET_break (0); | 97 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
181 | 98 | ||
182 | if (th != NULL) | 99 | if (p1 != NULL) |
183 | { | 100 | GNUNET_TRANSPORT_TESTING_stop_peer(p1); |
184 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); | 101 | if (p2 != NULL) |
185 | th = NULL; | 102 | GNUNET_TRANSPORT_TESTING_stop_peer(p2); |
186 | } | ||
187 | else | ||
188 | { | ||
189 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); | ||
190 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); | ||
191 | } | ||
192 | 103 | ||
193 | GNUNET_TRANSPORT_disconnect (p1.th); | 104 | ok = GNUNET_SYSERR; |
194 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
195 | if (GNUNET_SCHEDULER_NO_TASK != tct) | ||
196 | { | ||
197 | GNUNET_SCHEDULER_cancel (tct); | ||
198 | tct = GNUNET_SCHEDULER_NO_TASK; | ||
199 | } | ||
200 | ok = 1; | ||
201 | } | 105 | } |
202 | 106 | ||
203 | 107 | ||
@@ -212,8 +116,7 @@ notify_receive (void *cls, | |||
212 | "Received message of type %d from peer %s!\n", | 116 | "Received message of type %d from peer %s!\n", |
213 | ntohs(message->type), | 117 | ntohs(message->type), |
214 | GNUNET_i2s (peer)); | 118 | GNUNET_i2s (peer)); |
215 | GNUNET_assert (ok == 5); | 119 | |
216 | OKPP; | ||
217 | GNUNET_assert (MTYPE == ntohs (message->type)); | 120 | GNUNET_assert (MTYPE == ntohs (message->type)); |
218 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == | 121 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == |
219 | ntohs (message->size)); | 122 | ntohs (message->size)); |
@@ -234,8 +137,7 @@ notify_ready (void *cls, size_t size, void *buf) | |||
234 | sizeof (struct GNUNET_MessageHeader), | 137 | sizeof (struct GNUNET_MessageHeader), |
235 | GNUNET_i2s (&p->id)); | 138 | GNUNET_i2s (&p->id)); |
236 | GNUNET_assert (size >= 256); | 139 | GNUNET_assert (size >= 256); |
237 | GNUNET_assert (ok == 4); | 140 | |
238 | OKPP; | ||
239 | if (buf != NULL) | 141 | if (buf != NULL) |
240 | { | 142 | { |
241 | hdr = buf; | 143 | hdr = buf; |
@@ -256,25 +158,6 @@ notify_connect (void *cls, | |||
256 | "Peer `%4s' connected to us (%p)!\n", | 158 | "Peer `%4s' connected to us (%p)!\n", |
257 | GNUNET_i2s (peer), | 159 | GNUNET_i2s (peer), |
258 | cls); | 160 | cls); |
259 | if (cls == &p1) | ||
260 | { | ||
261 | GNUNET_assert (ok >= 2); | ||
262 | OKPP; | ||
263 | OKPP; | ||
264 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
265 | GNUNET_SCHEDULER_cancel (die_task); | ||
266 | if (GNUNET_SCHEDULER_NO_TASK != tct) | ||
267 | GNUNET_SCHEDULER_cancel (tct); | ||
268 | tct = GNUNET_SCHEDULER_NO_TASK; | ||
269 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); | ||
270 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); | ||
271 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, | ||
272 | &end_badly, NULL); | ||
273 | th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th, | ||
274 | &p2.id, | ||
275 | 256, 0, TIMEOUT, ¬ify_ready, | ||
276 | &p1); | ||
277 | } | ||
278 | } | 161 | } |
279 | 162 | ||
280 | 163 | ||
@@ -287,185 +170,47 @@ notify_disconnect (void *cls, | |||
287 | GNUNET_i2s (peer), cls); | 170 | GNUNET_i2s (peer), cls); |
288 | } | 171 | } |
289 | 172 | ||
290 | |||
291 | static void | 173 | static void |
292 | setup_peer (struct PeerContext *p, | 174 | sendtask () |
293 | const char *cfgname) | ||
294 | { | 175 | { |
295 | p->cfg = GNUNET_CONFIGURATION_create (); | 176 | th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, |
296 | 177 | &p2->id, | |
297 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 178 | 256, 0, TIMEOUT, ¬ify_ready, |
298 | if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) | 179 | &p1); |
299 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome); | ||
300 | if (NULL != p->servicehome) | ||
301 | GNUNET_DISK_directory_remove (p->servicehome); | ||
302 | |||
303 | #if START_ARM | ||
304 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | ||
305 | "gnunet-service-arm", | ||
306 | #if VERBOSE_ARM | ||
307 | "-L", "DEBUG", | ||
308 | #endif | ||
309 | "-c", cfgname, NULL); | ||
310 | #endif | ||
311 | |||
312 | |||
313 | |||
314 | if (is_https) | ||
315 | { | ||
316 | struct stat sbuf; | ||
317 | if (p==&p1) | ||
318 | { | ||
319 | if (GNUNET_CONFIGURATION_have_value (p->cfg, | ||
320 | "transport-https", "KEY_FILE")) | ||
321 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p1); | ||
322 | if (key_file_p1==NULL) | ||
323 | GNUNET_asprintf(&key_file_p1,"https.key"); | ||
324 | if (0 == stat (key_file_p1, &sbuf )) | ||
325 | { | ||
326 | if (0 == remove(key_file_p1)) | ||
327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
328 | "Successfully removed existing private key file `%s'\n",key_file_p1); | ||
329 | else | ||
330 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
331 | "Failed to remove private key file `%s'\n",key_file_p1); | ||
332 | } | ||
333 | if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE")) | ||
334 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p1); | ||
335 | if (cert_file_p1==NULL) | ||
336 | GNUNET_asprintf(&cert_file_p1,"https.cert"); | ||
337 | if (0 == stat (cert_file_p1, &sbuf )) | ||
338 | { | ||
339 | if (0 == remove(cert_file_p1)) | ||
340 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
341 | "Successfully removed existing certificate file `%s'\n", | ||
342 | cert_file_p1); | ||
343 | else | ||
344 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
345 | "Failed to remove existing certificate file `%s'\n", | ||
346 | cert_file_p1); | ||
347 | } | ||
348 | } | ||
349 | else if (p==&p2) | ||
350 | { | ||
351 | if (GNUNET_CONFIGURATION_have_value (p->cfg, | ||
352 | "transport-https", "KEY_FILE")) | ||
353 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p2); | ||
354 | if (key_file_p2==NULL) | ||
355 | GNUNET_asprintf(&key_file_p2,"https.key"); | ||
356 | if (0 == stat (key_file_p2, &sbuf )) | ||
357 | { | ||
358 | if (0 == remove(key_file_p2)) | ||
359 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
360 | "Successfully removed existing private key file `%s'\n", | ||
361 | key_file_p2); | ||
362 | else | ||
363 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
364 | "Failed to remove private key file `%s'\n", | ||
365 | key_file_p2); | ||
366 | } | ||
367 | if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE")) | ||
368 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p2); | ||
369 | if (cert_file_p2==NULL) | ||
370 | GNUNET_asprintf(&cert_file_p2,"https.cert"); | ||
371 | if (0 == stat (cert_file_p2, &sbuf )) | ||
372 | { | ||
373 | if (0 == remove(cert_file_p2)) | ||
374 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
375 | "Successfully removed existing certificate file `%s'\n",cert_file_p2); | ||
376 | else | ||
377 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
378 | "Failed to remove existing certificate file `%s'\n",cert_file_p2); | ||
379 | } | ||
380 | } | ||
381 | } | ||
382 | |||
383 | p->th = GNUNET_TRANSPORT_connect (p->cfg, | ||
384 | NULL, p, | ||
385 | ¬ify_receive, | ||
386 | ¬ify_connect, ¬ify_disconnect); | ||
387 | GNUNET_assert (p->th != NULL); | ||
388 | } | 180 | } |
389 | 181 | ||
390 | |||
391 | static void | 182 | static void |
392 | try_connect (void *cls, | 183 | testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void *cls) |
393 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
394 | { | 184 | { |
395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 185 | char * p1_c = strdup (GNUNET_i2s(&p1->id)); |
396 | "Asking peers to connect...\n"); | 186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", |
397 | /* FIXME: 'pX.id' may still be all-zeros here... */ | 187 | p1_c, |
398 | GNUNET_TRANSPORT_try_connect (p2.th, | 188 | GNUNET_i2s (&p2->id)); |
399 | &p1.id); | ||
400 | GNUNET_TRANSPORT_try_connect (p1.th, | ||
401 | &p2.id); | ||
402 | tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
403 | &try_connect, | ||
404 | NULL); | ||
405 | } | ||
406 | 189 | ||
190 | // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! | ||
191 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); | ||
192 | } | ||
407 | 193 | ||
408 | static void | 194 | static void |
409 | run (void *cls, | 195 | run (void *cls, |
410 | char *const *args, | 196 | char *const *args, |
411 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 197 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
412 | { | 198 | { |
413 | GNUNET_assert (ok == 1); | ||
414 | OKPP; | ||
415 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 199 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
416 | &end_badly, NULL); | 200 | &end_badly, NULL); |
417 | 201 | ||
418 | if (is_udp) | 202 | p1 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p1, |
419 | { | 203 | ¬ify_receive, |
420 | setup_peer (&p1, "test_transport_api_udp_peer1.conf"); | 204 | ¬ify_connect, |
421 | setup_peer (&p2, "test_transport_api_udp_peer2.conf"); | 205 | ¬ify_disconnect, |
422 | } | 206 | NULL); |
423 | if (is_unix) | 207 | p2 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p2, |
424 | { | 208 | ¬ify_receive, |
425 | setup_peer (&p1, "test_transport_api_unix_peer1.conf"); | 209 | ¬ify_connect, |
426 | setup_peer (&p2, "test_transport_api_unix_peer2.conf"); | 210 | ¬ify_disconnect, |
427 | } | 211 | NULL); |
428 | if (is_multi_protocol) | 212 | |
429 | { | 213 | GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL); |
430 | setup_peer (&p1, "test_transport_api_multi_peer1.conf"); | ||
431 | setup_peer (&p2, "test_transport_api_multi_peer2.conf"); | ||
432 | } | ||
433 | else if (is_tcp) | ||
434 | { | ||
435 | setup_peer (&p1, "test_transport_api_tcp_peer1.conf"); | ||
436 | setup_peer (&p2, "test_transport_api_tcp_peer2.conf"); | ||
437 | } | ||
438 | else if (is_tcp_nat) | ||
439 | { | ||
440 | setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf"); | ||
441 | setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf"); | ||
442 | } | ||
443 | else if (is_udp_nat) | ||
444 | { | ||
445 | setup_peer (&p1, "test_transport_api_udp_nat_peer1.conf"); | ||
446 | setup_peer (&p2, "test_transport_api_udp_nat_peer2.conf"); | ||
447 | } | ||
448 | else if (is_http) | ||
449 | { | ||
450 | setup_peer (&p1, "test_transport_api_http_peer1.conf"); | ||
451 | setup_peer (&p2, "test_transport_api_http_peer2.conf"); | ||
452 | } | ||
453 | else if (is_https) | ||
454 | { | ||
455 | setup_peer (&p1, "test_transport_api_https_peer1.conf"); | ||
456 | setup_peer (&p2, "test_transport_api_https_peer2.conf"); | ||
457 | } | ||
458 | else if (is_wlan) | ||
459 | { | ||
460 | setup_peer (&p1, "test_transport_api_wlan_peer1.conf"); | ||
461 | setup_peer (&p2, "test_transport_api_wlan_peer2.conf"); | ||
462 | } | ||
463 | GNUNET_assert(p1.th != NULL); | ||
464 | GNUNET_assert(p2.th != NULL); | ||
465 | |||
466 | GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); | ||
467 | GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); | ||
468 | tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL); | ||
469 | } | 214 | } |
470 | 215 | ||
471 | static int | 216 | static int |
@@ -490,67 +235,7 @@ check () | |||
490 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 235 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
491 | argv, "test-transport-api", "nohelp", | 236 | argv, "test-transport-api", "nohelp", |
492 | options, &run, &ok); | 237 | options, &run, &ok); |
493 | stop_arm (&p1); | ||
494 | stop_arm (&p2); | ||
495 | 238 | ||
496 | if (is_https) | ||
497 | { | ||
498 | struct stat sbuf; | ||
499 | if (0 == stat (cert_file_p1, &sbuf )) | ||
500 | { | ||
501 | if (0 == remove(cert_file_p1)) | ||
502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
503 | "Successfully removed existing certificate file `%s'\n",cert_file_p1); | ||
504 | else | ||
505 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
506 | "Failed to remove certfile `%s'\n",cert_file_p1); | ||
507 | } | ||
508 | |||
509 | if (0 == stat (key_file_p1, &sbuf )) | ||
510 | { | ||
511 | if (0 == remove(key_file_p1)) | ||
512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
513 | "Successfully removed private key file `%s'\n",key_file_p1); | ||
514 | else | ||
515 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
516 | "Failed to private key file `%s'\n",key_file_p1); | ||
517 | } | ||
518 | |||
519 | if (0 == stat (cert_file_p2, &sbuf )) | ||
520 | { | ||
521 | if (0 == remove(cert_file_p2)) | ||
522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
523 | "Successfully removed existing certificate file `%s'\n",cert_file_p2); | ||
524 | else | ||
525 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
526 | "Failed to remove certfile `%s'\n",cert_file_p2); | ||
527 | } | ||
528 | |||
529 | if (0 == stat (key_file_p2, &sbuf )) | ||
530 | { | ||
531 | if (0 == remove(key_file_p2)) | ||
532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
533 | "Successfully removed private key file `%s'\n",key_file_p2); | ||
534 | else | ||
535 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
536 | "Failed to private key file `%s'\n",key_file_p2); | ||
537 | } | ||
538 | GNUNET_free(key_file_p1); | ||
539 | GNUNET_free(key_file_p2); | ||
540 | GNUNET_free(cert_file_p1); | ||
541 | GNUNET_free(cert_file_p2); | ||
542 | } | ||
543 | |||
544 | if (p1.servicehome != NULL) | ||
545 | { | ||
546 | GNUNET_DISK_directory_remove (p1.servicehome); | ||
547 | GNUNET_free(p1.servicehome); | ||
548 | } | ||
549 | if (p2.servicehome != NULL) | ||
550 | { | ||
551 | GNUNET_DISK_directory_remove (p2.servicehome); | ||
552 | GNUNET_free(p2.servicehome); | ||
553 | } | ||
554 | return ok; | 239 | return ok; |
555 | } | 240 | } |
556 | 241 | ||
@@ -678,9 +363,30 @@ main (int argc, char *argv[]) | |||
678 | #endif | 363 | #endif |
679 | NULL); | 364 | NULL); |
680 | 365 | ||
366 | char * pch = strdup(argv[0]); | ||
367 | char * filename = NULL; | ||
368 | |||
369 | /* get executable filename */ | ||
370 | pch = strtok (pch,"/"); | ||
371 | while (pch != NULL) | ||
372 | { | ||
373 | pch = strtok (NULL, "/"); | ||
374 | if (pch != NULL) | ||
375 | filename = pch; | ||
376 | } | ||
377 | |||
378 | /* remove "lt-" */ | ||
379 | |||
380 | filename = strstr(filename, "tes"); | ||
381 | //filename = &filename[1]; | ||
382 | //GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
383 | // "`%s'\n",filename); | ||
384 | /* create cfg filename */ | ||
385 | GNUNET_asprintf(&cfg_file_p1, "%s_peer1.conf",filename); | ||
386 | GNUNET_asprintf(&cfg_file_p2, "%s_peer2.conf", filename); | ||
387 | |||
681 | if (strstr(argv[0], "tcp_nat") != NULL) | 388 | if (strstr(argv[0], "tcp_nat") != NULL) |
682 | { | 389 | { |
683 | is_tcp_nat = GNUNET_YES; | ||
684 | if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) | 390 | if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) |
685 | { | 391 | { |
686 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 392 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -689,13 +395,8 @@ main (int argc, char *argv[]) | |||
689 | return 0; | 395 | return 0; |
690 | } | 396 | } |
691 | } | 397 | } |
692 | else if (strstr(argv[0], "tcp") != NULL) | ||
693 | { | ||
694 | is_tcp = GNUNET_YES; | ||
695 | } | ||
696 | else if (strstr(argv[0], "udp_nat") != NULL) | 398 | else if (strstr(argv[0], "udp_nat") != NULL) |
697 | { | 399 | { |
698 | is_udp_nat = GNUNET_YES; | ||
699 | if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) | 400 | if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) |
700 | { | 401 | { |
701 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 402 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -704,33 +405,12 @@ main (int argc, char *argv[]) | |||
704 | return 0; | 405 | return 0; |
705 | } | 406 | } |
706 | } | 407 | } |
707 | else if (strstr(argv[0], "udp") != NULL) | ||
708 | { | ||
709 | is_udp = GNUNET_YES; | ||
710 | } | ||
711 | else if (strstr(argv[0], "unix") != NULL) | ||
712 | { | ||
713 | is_unix = GNUNET_YES; | ||
714 | } | ||
715 | else if (strstr(argv[0], "https") != NULL) | ||
716 | { | ||
717 | is_https = GNUNET_YES; | ||
718 | } | ||
719 | else if (strstr(argv[0], "http") != NULL) | ||
720 | { | ||
721 | is_http = GNUNET_YES; | ||
722 | } | ||
723 | else if (strstr(argv[0], "wlan") != NULL) | ||
724 | { | ||
725 | is_wlan = GNUNET_YES; | ||
726 | } | ||
727 | else if (strstr(argv[0], "multi") != NULL) | ||
728 | { | ||
729 | is_multi_protocol = GNUNET_YES; | ||
730 | } | ||
731 | 408 | ||
732 | ret = check (); | 409 | ret = check (); |
733 | 410 | ||
411 | GNUNET_free (cfg_file_p1); | ||
412 | GNUNET_free (cfg_file_p2); | ||
413 | |||
734 | return ret; | 414 | return ret; |
735 | } | 415 | } |
736 | 416 | ||