aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_api.c')
-rw-r--r--src/transport/test_transport_api.c228
1 files changed, 109 insertions, 119 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 0e3473441..f9ac6a8e5 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -57,17 +57,17 @@
57 57
58static int ok; 58static int ok;
59 59
60static GNUNET_SCHEDULER_TaskIdentifier die_task; 60static GNUNET_SCHEDULER_TaskIdentifier die_task;
61 61
62struct PeerContext * p1; 62struct PeerContext *p1;
63 63
64struct PeerContext * p2; 64struct PeerContext *p2;
65 65
66struct GNUNET_TRANSPORT_TransmitHandle * th; 66struct GNUNET_TRANSPORT_TransmitHandle *th;
67 67
68char * cfg_file_p1; 68char *cfg_file_p1;
69 69
70char * cfg_file_p2; 70char *cfg_file_p2;
71 71
72#if VERBOSE 72#if VERBOSE
73#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)
@@ -82,33 +82,33 @@ end ()
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
83 83
84 if (die_task != GNUNET_SCHEDULER_NO_TASK) 84 if (die_task != GNUNET_SCHEDULER_NO_TASK)
85 GNUNET_SCHEDULER_cancel(die_task); 85 GNUNET_SCHEDULER_cancel (die_task);
86 86
87 if (th != NULL) 87 if (th != NULL)
88 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 88 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
89 th = NULL; 89 th = NULL;
90 90
91 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 91 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
92 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 92 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
93} 93}
94 94
95static void 95static void
96end_badly () 96end_badly ()
97{ 97{
98 if (die_task != GNUNET_SCHEDULER_NO_TASK) 98 if (die_task != GNUNET_SCHEDULER_NO_TASK)
99 GNUNET_SCHEDULER_cancel(die_task); 99 GNUNET_SCHEDULER_cancel (die_task);
100 100
101 die_task = GNUNET_SCHEDULER_NO_TASK; 101 die_task = GNUNET_SCHEDULER_NO_TASK;
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); 102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
103 103
104 if (th != NULL) 104 if (th != NULL)
105 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 105 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
106 th = NULL; 106 th = NULL;
107 107
108 if (p1 != NULL) 108 if (p1 != NULL)
109 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 109 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
110 if (p2 != NULL) 110 if (p2 != NULL)
111 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 111 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
112 112
113 ok = GNUNET_SYSERR; 113 ok = GNUNET_SYSERR;
114} 114}
@@ -121,22 +121,21 @@ notify_receive (void *cls,
121 const struct GNUNET_TRANSPORT_ATS_Information *ats, 121 const struct GNUNET_TRANSPORT_ATS_Information *ats,
122 uint32_t ats_count) 122 uint32_t ats_count)
123{ 123{
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
125 "Received message of type %d from peer %s!\n", 125 "Received message of type %d from peer %s!\n",
126 ntohs(message->type), 126 ntohs (message->type), GNUNET_i2s (peer));
127 GNUNET_i2s (peer));
128 127
129 if ((MTYPE == ntohs (message->type)) && 128 if ((MTYPE == ntohs (message->type)) &&
130 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) 129 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
131 { 130 {
132 ok = 0; 131 ok = 0;
133 end(); 132 end ();
134 } 133 }
135 else 134 else
136 { 135 {
137 GNUNET_break (0); 136 GNUNET_break (0);
138 ok = 1; 137 ok = 1;
139 end(); 138 end ();
140 } 139 }
141} 140}
142 141
@@ -150,9 +149,8 @@ notify_ready (void *cls, size_t size, void *buf)
150 th = NULL; 149 th = NULL;
151 150
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Transmitting message with %u bytes to peer %s\n", 152 "Transmitting message with %u bytes to peer %s\n",
154 sizeof (struct GNUNET_MessageHeader), 153 sizeof (struct GNUNET_MessageHeader), GNUNET_i2s (&p->id));
155 GNUNET_i2s (&p->id));
156 GNUNET_assert (size >= 256); 154 GNUNET_assert (size >= 256);
157 155
158 if (buf != NULL) 156 if (buf != NULL)
@@ -172,41 +170,37 @@ notify_connect (void *cls,
172 uint32_t ats_count) 170 uint32_t ats_count)
173{ 171{
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Peer `%4s' connected to us (%p)!\n", 173 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
176 GNUNET_i2s (peer),
177 cls);
178} 174}
179 175
180 176
181static void 177static void
182notify_disconnect (void *cls, 178notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
183 const struct GNUNET_PeerIdentity *peer)
184{ 179{
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
186 "Peer `%4s' disconnected (%p)!\n", 181 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
187 GNUNET_i2s (peer), cls);
188} 182}
189 183
190static void 184static void
191sendtask () 185sendtask ()
192{ 186{
193 th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, 187 th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th,
194 &p2->id, 188 &p2->id,
195 256, 0, TIMEOUT, &notify_ready, 189 256, 0, TIMEOUT, &notify_ready,
196 &p1); 190 &p1);
197} 191}
198 192
199static void 193static void
200testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void *cls) 194testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
201{ 195{
202 char * p1_c = strdup (GNUNET_i2s(&p1->id)); 196 char *p1_c = strdup (GNUNET_i2s (&p1->id));
197
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", 198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n",
204 p1_c, 199 p1_c, GNUNET_i2s (&p2->id));
205 GNUNET_i2s (&p2->id));
206 GNUNET_free (p1_c); 200 GNUNET_free (p1_c);
207 201
208 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! 202 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
209 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); 203 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
210} 204}
211 205
212static void 206static void
@@ -214,21 +208,18 @@ run (void *cls,
214 char *const *args, 208 char *const *args,
215 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 209 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
216{ 210{
217 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 211 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
218 &end_badly, NULL); 212
219 213 p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1,
220 p1 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p1, 214 &notify_receive,
221 &notify_receive, 215 &notify_connect,
222 &notify_connect, 216 &notify_disconnect, NULL);
223 &notify_disconnect, 217 p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2,
224 NULL); 218 &notify_receive,
225 p2 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p2, 219 &notify_connect,
226 &notify_receive, 220 &notify_disconnect, NULL);
227 &notify_connect, 221
228 &notify_disconnect, 222 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
229 NULL);
230
231 GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL);
232} 223}
233 224
234static int 225static int
@@ -247,12 +238,11 @@ check ()
247 }; 238 };
248 239
249#if WRITECONFIG 240#if WRITECONFIG
250 setTransportOptions("test_transport_api_data.conf"); 241 setTransportOptions ("test_transport_api_data.conf");
251#endif 242#endif
252 ok = 1; 243 ok = 1;
253 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 244 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
254 argv, "test-transport-api", "nohelp", 245 argv, "test-transport-api", "nohelp", options, &run, &ok);
255 options, &run, &ok);
256 246
257 return ok; 247 return ok;
258} 248}
@@ -274,32 +264,32 @@ get_path_from_PATH (char *binary)
274 264
275 p = getenv ("PATH"); 265 p = getenv ("PATH");
276 if (p == NULL) 266 if (p == NULL)
277 { 267 {
278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
279 _("PATH environment variable is unset.\n")); 269 _("PATH environment variable is unset.\n"));
280 return NULL; 270 return NULL;
281 } 271 }
282 path = GNUNET_strdup (p); /* because we write on it */ 272 path = GNUNET_strdup (p); /* because we write on it */
283 buf = GNUNET_malloc (strlen (path) + 20); 273 buf = GNUNET_malloc (strlen (path) + 20);
284 pos = path; 274 pos = path;
285 275
286 while (NULL != (end = strchr (pos, PATH_SEPARATOR))) 276 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
287 { 277 {
288 *end = '\0'; 278 *end = '\0';
289 sprintf (buf, "%s/%s", pos, binary); 279 sprintf (buf, "%s/%s", pos, binary);
290 if (GNUNET_DISK_file_test (buf) == GNUNET_YES) 280 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
291 {
292 GNUNET_free (path);
293 return buf;
294 }
295 pos = end + 1;
296 }
297 sprintf (buf, "%s/%s", pos, binary);
298 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
299 { 281 {
300 GNUNET_free (path); 282 GNUNET_free (path);
301 return buf; 283 return buf;
302 } 284 }
285 pos = end + 1;
286 }
287 sprintf (buf, "%s/%s", pos, binary);
288 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
289 {
290 GNUNET_free (path);
291 return buf;
292 }
303 GNUNET_free (buf); 293 GNUNET_free (buf);
304 GNUNET_free (path); 294 GNUNET_free (path);
305 return NULL; 295 return NULL;
@@ -316,16 +306,18 @@ get_path_from_PATH (char *binary)
316 * can be run properly, GNUNET_NO otherwise 306 * can be run properly, GNUNET_NO otherwise
317 */ 307 */
318static int 308static int
319check_gnunet_nat_binary(char *binary) 309check_gnunet_nat_binary (char *binary)
320{ 310{
321 struct stat statbuf; 311 struct stat statbuf;
322 char *p; 312 char *p;
313
323#ifdef MINGW 314#ifdef MINGW
324 SOCKET rawsock; 315 SOCKET rawsock;
325#endif 316#endif
326 317
327#ifdef MINGW 318#ifdef MINGW
328 char *binaryexe; 319 char *binaryexe;
320
329 GNUNET_asprintf (&binaryexe, "%s.exe", binary); 321 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
330 p = get_path_from_PATH (binaryexe); 322 p = get_path_from_PATH (binaryexe);
331 free (binaryexe); 323 free (binaryexe);
@@ -333,36 +325,34 @@ check_gnunet_nat_binary(char *binary)
333 p = get_path_from_PATH (binary); 325 p = get_path_from_PATH (binary);
334#endif 326#endif
335 if (p == NULL) 327 if (p == NULL)
336 { 328 {
337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 329 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
338 _("Could not find binary `%s' in PATH!\n"), 330 _("Could not find binary `%s' in PATH!\n"), binary);
339 binary); 331 return GNUNET_NO;
340 return GNUNET_NO; 332 }
341 }
342 if (0 != STAT (p, &statbuf)) 333 if (0 != STAT (p, &statbuf))
343 { 334 {
344 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 335 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
345 _("stat (%s) failed: %s\n"), 336 _("stat (%s) failed: %s\n"), p, STRERROR (errno));
346 p, 337 GNUNET_free (p);
347 STRERROR (errno)); 338 return GNUNET_SYSERR;
348 GNUNET_free (p); 339 }
349 return GNUNET_SYSERR;
350 }
351 GNUNET_free (p); 340 GNUNET_free (p);
352#ifndef MINGW 341#ifndef MINGW
353 if ( (0 != (statbuf.st_mode & S_ISUID)) && 342 if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
354 (statbuf.st_uid == 0) )
355 return GNUNET_YES; 343 return GNUNET_YES;
356 return GNUNET_NO; 344 return GNUNET_NO;
357#else 345#else
358 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); 346 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
359 if (INVALID_SOCKET == rawsock) 347 if (INVALID_SOCKET == rawsock)
360 { 348 {
361 DWORD err = GetLastError (); 349 DWORD err = GetLastError ();
362 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 350
363 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err); 351 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
364 return GNUNET_NO; /* not running as administrator */ 352 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n",
365 } 353 err);
354 return GNUNET_NO; /* not running as administrator */
355 }
366 closesocket (rawsock); 356 closesocket (rawsock);
367 return GNUNET_YES; 357 return GNUNET_YES;
368#endif 358#endif
@@ -381,13 +371,13 @@ main (int argc, char *argv[])
381#endif 371#endif
382 NULL); 372 NULL);
383 373
384 char * pch = strdup(argv[0]); 374 char *pch = strdup (argv[0]);
385 char * backup = pch; 375 char *backup = pch;
386 char * filename = NULL; 376 char *filename = NULL;
387 char *dotexe; 377 char *dotexe;
388 378
389 /* get executable filename */ 379 /* get executable filename */
390 pch = strtok (pch,"/"); 380 pch = strtok (pch, "/");
391 while (pch != NULL) 381 while (pch != NULL)
392 { 382 {
393 pch = strtok (NULL, "/"); 383 pch = strtok (NULL, "/");
@@ -395,35 +385,35 @@ main (int argc, char *argv[])
395 filename = pch; 385 filename = pch;
396 } 386 }
397 /* remove "lt-" */ 387 /* remove "lt-" */
398 filename = strstr(filename, "tes"); 388 filename = strstr (filename, "tes");
399 if (NULL != (dotexe = strstr (filename, ".exe"))) 389 if (NULL != (dotexe = strstr (filename, ".exe")))
400 dotexe[0] = '\0'; 390 dotexe[0] = '\0';
401 391
402 /* create cfg filename */ 392 /* create cfg filename */
403 GNUNET_asprintf(&cfg_file_p1, "%s_peer1.conf",filename); 393 GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
404 GNUNET_asprintf(&cfg_file_p2, "%s_peer2.conf", filename); 394 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
405 GNUNET_free (backup); 395 GNUNET_free (backup);
406 396
407 if (strstr(argv[0], "tcp_nat") != NULL) 397 if (strstr (argv[0], "tcp_nat") != NULL)
398 {
399 if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
408 { 400 {
409 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) 401 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
410 { 402 "`%s' not properly installed, cannot run NAT test!\n",
411 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 403 "gnunet-nat-server");
412 "`%s' not properly installed, cannot run NAT test!\n", 404 return 0;
413 "gnunet-nat-server");
414 return 0;
415 }
416 } 405 }
417 else if (strstr(argv[0], "udp_nat") != NULL) 406 }
407 else if (strstr (argv[0], "udp_nat") != NULL)
408 {
409 if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
418 { 410 {
419 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) 411 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
420 { 412 "`%s' not properly installed, cannot run NAT test!\n",
421 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 413 "gnunet-nat-server");
422 "`%s' not properly installed, cannot run NAT test!\n", 414 return 0;
423 "gnunet-nat-server");
424 return 0;
425 }
426 } 415 }
416 }
427 417
428 ret = check (); 418 ret = check ();
429 419