aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_reliability.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_api_reliability.c')
-rw-r--r--src/transport/test_transport_api_reliability.c416
1 files changed, 199 insertions, 217 deletions
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 37395ad0f..60191394d 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -51,17 +51,17 @@
51 51
52static int ok; 52static int ok;
53 53
54static GNUNET_SCHEDULER_TaskIdentifier die_task; 54static GNUNET_SCHEDULER_TaskIdentifier die_task;
55 55
56struct PeerContext * p1; 56struct PeerContext *p1;
57 57
58struct PeerContext * p2; 58struct PeerContext *p2;
59 59
60struct GNUNET_TRANSPORT_TransmitHandle * th; 60struct GNUNET_TRANSPORT_TransmitHandle *th;
61 61
62char * cfg_file_p1; 62char *cfg_file_p1;
63 63
64char * cfg_file_p2; 64char *cfg_file_p2;
65 65
66/* 66/*
67 * Testcase specific declarations 67 * Testcase specific declarations
@@ -108,27 +108,27 @@ static void
108end () 108end ()
109{ 109{
110 unsigned long long delta; 110 unsigned long long delta;
111
111 //char *value_name; 112 //char *value_name;
112 113
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
114 115
115 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 116 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
116 fprintf (stderr, 117 fprintf (stderr,
117 "\nThroughput was %llu kb/s\n", 118 "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta);
118 total_bytes * 1000 / 1024 / delta);
119 //GNUNET_asprintf(&value_name, "reliable_%s", test_name); 119 //GNUNET_asprintf(&value_name, "reliable_%s", test_name);
120 //GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s"); 120 //GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s");
121 //GNUNET_free(value_name); 121 //GNUNET_free(value_name);
122 122
123 if (die_task != GNUNET_SCHEDULER_NO_TASK) 123 if (die_task != GNUNET_SCHEDULER_NO_TASK)
124 GNUNET_SCHEDULER_cancel(die_task); 124 GNUNET_SCHEDULER_cancel (die_task);
125 125
126 if (th != NULL) 126 if (th != NULL)
127 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 127 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
128 th = NULL; 128 th = NULL;
129 129
130 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 130 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
131 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 131 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
132} 132}
133 133
134static void 134static void
@@ -138,13 +138,13 @@ end_badly ()
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); 138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
139 139
140 if (th != NULL) 140 if (th != NULL)
141 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 141 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
142 th = NULL; 142 th = NULL;
143 143
144 if (p1 != NULL) 144 if (p1 != NULL)
145 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 145 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
146 if (p2 != NULL) 146 if (p2 != NULL)
147 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 147 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
148 148
149 ok = GNUNET_SYSERR; 149 ok = GNUNET_SYSERR;
150} 150}
@@ -172,75 +172,66 @@ notify_receive (void *cls,
172 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; 172 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
173 const struct TestMessage *hdr; 173 const struct TestMessage *hdr;
174 174
175 hdr = (const struct TestMessage*) message; 175 hdr = (const struct TestMessage *) message;
176 s = get_size (n); 176 s = get_size (n);
177 if (MTYPE != ntohs (message->type)) 177 if (MTYPE != ntohs (message->type))
178 return; 178 return;
179 msg_recv_expected = n; 179 msg_recv_expected = n;
180 msg_recv = ntohl(hdr->num); 180 msg_recv = ntohl (hdr->num);
181 if (ntohs (message->size) != (s)) 181 if (ntohs (message->size) != (s))
182 { 182 {
183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
184 "Expected message %u of size %u, got %u bytes of message %u\n", 184 "Expected message %u of size %u, got %u bytes of message %u\n",
185 n, s, 185 n, s, ntohs (message->size), ntohl (hdr->num));
186 ntohs (message->size), 186 if (die_task != GNUNET_SCHEDULER_NO_TASK)
187 ntohl (hdr->num)); 187 GNUNET_SCHEDULER_cancel (die_task);
188 if (die_task != GNUNET_SCHEDULER_NO_TASK) 188 test_failed = GNUNET_YES;
189 GNUNET_SCHEDULER_cancel (die_task); 189 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
190 test_failed = GNUNET_YES; 190 return;
191 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 191 }
192 return;
193 }
194 if (ntohl (hdr->num) != n) 192 if (ntohl (hdr->num) != n)
195 { 193 {
196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 "Expected message %u of size %u, got %u bytes of message %u\n", 195 "Expected message %u of size %u, got %u bytes of message %u\n",
198 n, s, 196 n, s, ntohs (message->size), ntohl (hdr->num));
199 ntohs (message->size), 197 if (die_task != GNUNET_SCHEDULER_NO_TASK)
200 ntohl (hdr->num)); 198 GNUNET_SCHEDULER_cancel (die_task);
201 if (die_task != GNUNET_SCHEDULER_NO_TASK) 199 test_failed = GNUNET_YES;
202 GNUNET_SCHEDULER_cancel (die_task); 200 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
203 test_failed = GNUNET_YES; 201 return;
204 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 202 }
205 return;
206 }
207 memset (cbuf, n, s - sizeof (struct TestMessage)); 203 memset (cbuf, n, s - sizeof (struct TestMessage));
208 if (0 != memcmp (cbuf, 204 if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage)))
209 &hdr[1], 205 {
210 s - sizeof (struct TestMessage))) 206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
211 { 207 "Expected message %u with bits %u, but body did not match\n",
212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 208 n, (unsigned char) n);
213 "Expected message %u with bits %u, but body did not match\n", 209 if (die_task != GNUNET_SCHEDULER_NO_TASK)
214 n, (unsigned char) n); 210 GNUNET_SCHEDULER_cancel (die_task);
215 if (die_task != GNUNET_SCHEDULER_NO_TASK) 211 test_failed = GNUNET_YES;
216 GNUNET_SCHEDULER_cancel (die_task); 212 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
217 test_failed = GNUNET_YES; 213 return;
218 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 214 }
219 return;
220 }
221#if VERBOSE 215#if VERBOSE
222 if (ntohl(hdr->num) % 5000 == 0) 216 if (ntohl (hdr->num) % 5000 == 0)
223 { 217 {
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
225 "Got message %u of size %u\n", 219 "Got message %u of size %u\n",
226 ntohl (hdr->num), 220 ntohl (hdr->num), ntohs (message->size));
227 ntohs (message->size)); 221 }
228 }
229#endif 222#endif
230 n++; 223 n++;
231 if (0 == (n % (TOTAL_MSGS/100))) 224 if (0 == (n % (TOTAL_MSGS / 100)))
232 { 225 {
233 fprintf (stderr, "."); 226 fprintf (stderr, ".");
234 if (die_task != GNUNET_SCHEDULER_NO_TASK) 227 if (die_task != GNUNET_SCHEDULER_NO_TASK)
235 GNUNET_SCHEDULER_cancel (die_task); 228 GNUNET_SCHEDULER_cancel (die_task);
236 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 229 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
237 &end_badly, 230 }
238 NULL);
239 }
240 if (n == TOTAL_MSGS) 231 if (n == TOTAL_MSGS)
241 { 232 {
242 ok = 0; 233 ok = 0;
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"All messages received\n"); 234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages received\n");
244 end (); 235 end ();
245 } 236 }
246} 237}
@@ -256,11 +247,11 @@ notify_ready (void *cls, size_t size, void *buf)
256 unsigned int ret; 247 unsigned int ret;
257 248
258 if (buf == NULL) 249 if (buf == NULL)
259 { 250 {
260 GNUNET_break (0); 251 GNUNET_break (0);
261 ok = 42; 252 ok = 42;
262 return 0; 253 return 0;
263 } 254 }
264 th = NULL; 255 th = NULL;
265 ret = 0; 256 ret = 0;
266 s = get_size (n); 257 s = get_size (n);
@@ -268,50 +259,46 @@ notify_ready (void *cls, size_t size, void *buf)
268 GNUNET_assert (buf != NULL); 259 GNUNET_assert (buf != NULL);
269 cbuf = buf; 260 cbuf = buf;
270 do 261 do
271 { 262 {
272 hdr.header.size = htons (s); 263 hdr.header.size = htons (s);
273 hdr.header.type = htons (MTYPE); 264 hdr.header.type = htons (MTYPE);
274 hdr.num = htonl (n); 265 hdr.num = htonl (n);
275 msg_sent = n; 266 msg_sent = n;
276 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); 267 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
277 ret += sizeof (struct TestMessage); 268 ret += sizeof (struct TestMessage);
278 memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); 269 memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
279 ret += s - sizeof (struct TestMessage); 270 ret += s - sizeof (struct TestMessage);
280#if VERBOSE 271#if VERBOSE
281 if (n % 5000 == 0) 272 if (n % 5000 == 0)
282 { 273 {
283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
284 "Sending message %u of size %u\n", 275 "Sending message %u of size %u\n", n, s);
285 n,
286 s);
287 }
288#endif
289 n++;
290 s = get_size (n);
291 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
292 break; /* sometimes pack buffer full, sometimes not */
293 } 276 }
277#endif
278 n++;
279 s = get_size (n);
280 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
281 break; /* sometimes pack buffer full, sometimes not */
282 }
294 while (size - ret >= s); 283 while (size - ret >= s);
295 if (n < TOTAL_MSGS) 284 if (n < TOTAL_MSGS)
296 { 285 {
297 if (th == NULL) 286 if (th == NULL)
298 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, 287 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
299 &p1->id, 288 &p1->id,
300 s, 0, TIMEOUT, 289 s, 0, TIMEOUT,
301 &notify_ready, 290 &notify_ready, NULL);
302 NULL);
303 msg_scheduled = n; 291 msg_scheduled = n;
304 } 292 }
305 if (n % 5000 == 0) 293 if (n % 5000 == 0)
306 { 294 {
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
308 "Returning total message block of size %u\n", 296 "Returning total message block of size %u\n", ret);
309 ret); 297 }
310 }
311 total_bytes += ret; 298 total_bytes += ret;
312 if (n == TOTAL_MSGS) 299 if (n == TOTAL_MSGS)
313 { 300 {
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"All messages sent\n"); 301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages sent\n");
315 } 302 }
316 return ret; 303 return ret;
317} 304}
@@ -325,34 +312,34 @@ notify_connect (void *cls,
325{ 312{
326 313
327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
328 "Peer `%4s' connected to us (%p)!\n", 315 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
329 GNUNET_i2s (peer),
330 cls);
331 316
332 if (cls == p1) 317 if (cls == p1)
333 { 318 {
334 GNUNET_TRANSPORT_set_quota (p1->th, 319 GNUNET_TRANSPORT_set_quota (p1->th,
335 &p2->id, 320 &p2->id,
336 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), 321 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
337 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); 322 1024),
338 } 323 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
339 else if (cls == p2) 324 1024));
340 { 325 }
341 GNUNET_TRANSPORT_set_quota (p2->th, 326 else if (cls == p2)
342 &p1->id, 327 {
343 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), 328 GNUNET_TRANSPORT_set_quota (p2->th,
344 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); 329 &p1->id,
345 } 330 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
331 1024),
332 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
333 1024));
334 }
346} 335}
347 336
348 337
349static void 338static void
350notify_disconnect (void *cls, 339notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
351 const struct GNUNET_PeerIdentity *peer)
352{ 340{
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
354 "Peer `%4s' disconnected (%p)!\n", 342 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
355 GNUNET_i2s (peer), cls);
356} 343}
357 344
358static void 345static void
@@ -360,23 +347,22 @@ sendtask ()
360{ 347{
361 start_time = GNUNET_TIME_absolute_get (); 348 start_time = GNUNET_TIME_absolute_get ();
362 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, 349 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
363 &p1->id, 350 &p1->id,
364 get_size (0), 0, TIMEOUT, 351 get_size (0), 0, TIMEOUT,
365 &notify_ready, 352 &notify_ready, NULL);
366 NULL);
367} 353}
368 354
369static void 355static void
370testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void *cls) 356testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
371{ 357{
372 char * p1_c = strdup (GNUNET_i2s(&p1->id)); 358 char *p1_c = strdup (GNUNET_i2s (&p1->id));
359
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", 360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n",
374 p1_c, 361 p1_c, GNUNET_i2s (&p2->id));
375 GNUNET_i2s (&p2->id));
376 GNUNET_free (p1_c); 362 GNUNET_free (p1_c);
377 363
378 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! 364 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
379 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); 365 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
380} 366}
381 367
382static void 368static void
@@ -384,21 +370,18 @@ run (void *cls,
384 char *const *args, 370 char *const *args,
385 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 371 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
386{ 372{
387 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 373 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
388 &end_badly, NULL); 374
389 375 p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1,
390 p1 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p1, 376 &notify_receive,
391 &notify_receive, 377 &notify_connect,
392 &notify_connect, 378 &notify_disconnect, NULL);
393 &notify_disconnect, 379 p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2,
394 NULL); 380 &notify_receive,
395 p2 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p2, 381 &notify_connect,
396 &notify_receive, 382 &notify_disconnect, NULL);
397 &notify_connect, 383
398 &notify_disconnect, 384 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
399 NULL);
400
401 GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL);
402} 385}
403 386
404static int 387static int
@@ -417,12 +400,11 @@ check ()
417 }; 400 };
418 401
419#if WRITECONFIG 402#if WRITECONFIG
420 setTransportOptions("test_transport_api_data.conf"); 403 setTransportOptions ("test_transport_api_data.conf");
421#endif 404#endif
422 ok = 1; 405 ok = 1;
423 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 406 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
424 argv, "test-transport-api", "nohelp", 407 argv, "test-transport-api", "nohelp", options, &run, &ok);
425 options, &run, &ok);
426 408
427 return ok; 409 return ok;
428} 410}
@@ -444,32 +426,32 @@ get_path_from_PATH (char *binary)
444 426
445 p = getenv ("PATH"); 427 p = getenv ("PATH");
446 if (p == NULL) 428 if (p == NULL)
447 { 429 {
448 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 430 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
449 _("PATH environment variable is unset.\n")); 431 _("PATH environment variable is unset.\n"));
450 return NULL; 432 return NULL;
451 } 433 }
452 path = GNUNET_strdup (p); /* because we write on it */ 434 path = GNUNET_strdup (p); /* because we write on it */
453 buf = GNUNET_malloc (strlen (path) + 20); 435 buf = GNUNET_malloc (strlen (path) + 20);
454 pos = path; 436 pos = path;
455 437
456 while (NULL != (end = strchr (pos, PATH_SEPARATOR))) 438 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
457 { 439 {
458 *end = '\0'; 440 *end = '\0';
459 sprintf (buf, "%s/%s", pos, binary); 441 sprintf (buf, "%s/%s", pos, binary);
460 if (GNUNET_DISK_file_test (buf) == GNUNET_YES) 442 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
461 {
462 GNUNET_free (path);
463 return buf;
464 }
465 pos = end + 1;
466 }
467 sprintf (buf, "%s/%s", pos, binary);
468 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
469 { 443 {
470 GNUNET_free (path); 444 GNUNET_free (path);
471 return buf; 445 return buf;
472 } 446 }
447 pos = end + 1;
448 }
449 sprintf (buf, "%s/%s", pos, binary);
450 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
451 {
452 GNUNET_free (path);
453 return buf;
454 }
473 GNUNET_free (buf); 455 GNUNET_free (buf);
474 GNUNET_free (path); 456 GNUNET_free (path);
475 return NULL; 457 return NULL;
@@ -486,16 +468,18 @@ get_path_from_PATH (char *binary)
486 * can be run properly, GNUNET_NO otherwise 468 * can be run properly, GNUNET_NO otherwise
487 */ 469 */
488static int 470static int
489check_gnunet_nat_binary(char *binary) 471check_gnunet_nat_binary (char *binary)
490{ 472{
491 struct stat statbuf; 473 struct stat statbuf;
492 char *p; 474 char *p;
475
493#ifdef MINGW 476#ifdef MINGW
494 SOCKET rawsock; 477 SOCKET rawsock;
495#endif 478#endif
496 479
497#ifdef MINGW 480#ifdef MINGW
498 char *binaryexe; 481 char *binaryexe;
482
499 GNUNET_asprintf (&binaryexe, "%s.exe", binary); 483 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
500 p = get_path_from_PATH (binaryexe); 484 p = get_path_from_PATH (binaryexe);
501 free (binaryexe); 485 free (binaryexe);
@@ -503,36 +487,34 @@ check_gnunet_nat_binary(char *binary)
503 p = get_path_from_PATH (binary); 487 p = get_path_from_PATH (binary);
504#endif 488#endif
505 if (p == NULL) 489 if (p == NULL)
506 { 490 {
507 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 491 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
508 _("Could not find binary `%s' in PATH!\n"), 492 _("Could not find binary `%s' in PATH!\n"), binary);
509 binary); 493 return GNUNET_NO;
510 return GNUNET_NO; 494 }
511 }
512 if (0 != STAT (p, &statbuf)) 495 if (0 != STAT (p, &statbuf))
513 { 496 {
514 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 497 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
515 _("stat (%s) failed: %s\n"), 498 _("stat (%s) failed: %s\n"), p, STRERROR (errno));
516 p, 499 GNUNET_free (p);
517 STRERROR (errno)); 500 return GNUNET_SYSERR;
518 GNUNET_free (p); 501 }
519 return GNUNET_SYSERR;
520 }
521 GNUNET_free (p); 502 GNUNET_free (p);
522#ifndef MINGW 503#ifndef MINGW
523 if ( (0 != (statbuf.st_mode & S_ISUID)) && 504 if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
524 (statbuf.st_uid == 0) )
525 return GNUNET_YES; 505 return GNUNET_YES;
526 return GNUNET_NO; 506 return GNUNET_NO;
527#else 507#else
528 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); 508 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
529 if (INVALID_SOCKET == rawsock) 509 if (INVALID_SOCKET == rawsock)
530 { 510 {
531 DWORD err = GetLastError (); 511 DWORD err = GetLastError ();
532 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 512
533 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err); 513 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
534 return GNUNET_NO; /* not running as administrator */ 514 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n",
535 } 515 err);
516 return GNUNET_NO; /* not running as administrator */
517 }
536 closesocket (rawsock); 518 closesocket (rawsock);
537 return GNUNET_YES; 519 return GNUNET_YES;
538#endif 520#endif
@@ -551,13 +533,13 @@ main (int argc, char *argv[])
551#endif 533#endif
552 NULL); 534 NULL);
553 535
554 char * pch = strdup(argv[0]); 536 char *pch = strdup (argv[0]);
555 char * backup = pch; 537 char *backup = pch;
556 char * filename = NULL; 538 char *filename = NULL;
557 char *dotexe; 539 char *dotexe;
558 540
559 /* get executable filename */ 541 /* get executable filename */
560 pch = strtok (pch,"/"); 542 pch = strtok (pch, "/");
561 while (pch != NULL) 543 while (pch != NULL)
562 { 544 {
563 pch = strtok (NULL, "/"); 545 pch = strtok (NULL, "/");
@@ -565,35 +547,35 @@ main (int argc, char *argv[])
565 filename = pch; 547 filename = pch;
566 } 548 }
567 /* remove "lt-" */ 549 /* remove "lt-" */
568 filename = strstr(filename, "tes"); 550 filename = strstr (filename, "tes");
569 if (NULL != (dotexe = strstr (filename, ".exe"))) 551 if (NULL != (dotexe = strstr (filename, ".exe")))
570 dotexe[0] = '\0'; 552 dotexe[0] = '\0';
571 553
572 /* create cfg filename */ 554 /* create cfg filename */
573 GNUNET_asprintf(&cfg_file_p1, "%s_peer1.conf",filename); 555 GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
574 GNUNET_asprintf(&cfg_file_p2, "%s_peer2.conf", filename); 556 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
575 GNUNET_free (backup); 557 GNUNET_free (backup);
576 558
577 if (strstr(argv[0], "tcp_nat") != NULL) 559 if (strstr (argv[0], "tcp_nat") != NULL)
560 {
561 if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
578 { 562 {
579 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) 563 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
580 { 564 "`%s' not properly installed, cannot run NAT test!\n",
581 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 565 "gnunet-nat-server");
582 "`%s' not properly installed, cannot run NAT test!\n", 566 return 0;
583 "gnunet-nat-server");
584 return 0;
585 }
586 } 567 }
587 else if (strstr(argv[0], "udp_nat") != NULL) 568 }
569 else if (strstr (argv[0], "udp_nat") != NULL)
570 {
571 if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
588 { 572 {
589 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) 573 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
590 { 574 "`%s' not properly installed, cannot run NAT test!\n",
591 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 575 "gnunet-nat-server");
592 "`%s' not properly installed, cannot run NAT test!\n", 576 return 0;
593 "gnunet-nat-server");
594 return 0;
595 }
596 } 577 }
578 }
597 579
598 ret = check (); 580 ret = check ();
599 581