aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-01-28 12:01:04 +0000
committerNathan S. Evans <evans@in.tum.de>2010-01-28 12:01:04 +0000
commit1c051694d229c10ee0c5ed4a60b4f7b46e972b3e (patch)
tree070e09634187d54d6fbaf78dc74487ee9120d1ed /src/transport/plugin_transport_udp.c
parentf206220e03ccf5cfdb8e8d51d253fed17db4d4ee (diff)
downloadgnunet-1c051694d229c10ee0c5ed4a60b4f7b46e972b3e.tar.gz
gnunet-1c051694d229c10ee0c5ed4a60b4f7b46e972b3e.zip
udp test_transport_api test now working, tcp not... but a good omen
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r--src/transport/plugin_transport_udp.c129
1 files changed, 64 insertions, 65 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 3df492a91..5a3e92e1e 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -345,8 +345,6 @@ static void
345udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 345udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
346{ 346{
347 struct Plugin *plugin = cls; 347 struct Plugin *plugin = cls;
348 struct GNUNET_TIME_Relative timeout =
349 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500);
350 char *buf; 348 char *buf;
351 struct UDPMessage *msg; 349 struct UDPMessage *msg;
352 const struct GNUNET_MessageHeader *hdr; 350 const struct GNUNET_MessageHeader *hdr;
@@ -361,8 +359,11 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
361 char *msgbuf; 359 char *msgbuf;
362 const struct GNUNET_MessageHeader *currhdr; 360 const struct GNUNET_MessageHeader *currhdr;
363 361
364 do 362#if DEBUG_UDP
365 { 363 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
364 ("entered select...\n"));
365#endif
366
366 buflen = GNUNET_NETWORK_socket_recvfrom_amount (udp_sock); 367 buflen = GNUNET_NETWORK_socket_recvfrom_amount (udp_sock);
367 368
368#if DEBUG_UDP 369#if DEBUG_UDP
@@ -370,82 +371,80 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
370 ("we expect to read %u bytes\n"), buflen); 371 ("we expect to read %u bytes\n"), buflen);
371#endif 372#endif
372 373
373 if (buflen == GNUNET_NO) 374 if (buflen == GNUNET_NO)
374 return; 375 return;
375 376
376 buf = GNUNET_malloc (buflen); 377 buf = GNUNET_malloc (buflen);
377 fromlen = sizeof (addr); 378 fromlen = sizeof (addr);
378 379
379 memset (&addr, 0, fromlen); 380 memset (&addr, 0, fromlen);
380 ret = 381 ret =
381 GNUNET_NETWORK_socket_recvfrom (udp_sock, buf, buflen, 382 GNUNET_NETWORK_socket_recvfrom (udp_sock, buf, buflen,
382 (struct sockaddr *) &addr, &fromlen); 383 (struct sockaddr *) &addr, &fromlen);
383 384
384#if DEBUG_UDP 385#if DEBUG_UDP
385 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 386 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
386 ("socket_recv returned %u, src_addr_len is %u\n"), ret, 387 ("socket_recv returned %u, src_addr_len is %u\n"), ret,
387 fromlen); 388 fromlen);
388#endif 389#endif
389 390
390 if (ret <= 0) 391 if (ret <= 0)
391 { 392 {
392 GNUNET_free (buf); 393 GNUNET_free (buf);
393 return; 394 return;
394 } 395 }
395 msg = (struct UDPMessage *) buf; 396 msg = (struct UDPMessage *) buf;
396 397
397#if DEBUG_UDP 398#if DEBUG_UDP
398 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 399 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
399 ("header reports message size of %d\n"), 400 ("header reports message size of %d\n"),
400 ntohs (msg->header.size)); 401 ntohs (msg->header.size));
401 402
402 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 403 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
403 ("header reports message type of %d\n"), 404 ("header reports message type of %d\n"),
404 ntohs (msg->header.type)); 405 ntohs (msg->header.type));
405#endif 406#endif
406 if (ntohs (msg->header.size) < sizeof (struct UDPMessage)) 407 if (ntohs (msg->header.size) < sizeof (struct UDPMessage))
407 { 408 {
408 GNUNET_free (buf); 409 GNUNET_free (buf);
409 GNUNET_NETWORK_fdset_zero (plugin->rs); 410 GNUNET_NETWORK_fdset_zero (plugin->rs);
410 GNUNET_NETWORK_fdset_set (plugin->rs, udp_sock); 411 GNUNET_NETWORK_fdset_set (plugin->rs, udp_sock);
411 break; 412 return;
412 } 413 }
413 hdr = (const struct GNUNET_MessageHeader *) &msg[1]; 414 hdr = (const struct GNUNET_MessageHeader *) &msg[1];
414 msgbuf = (char *)&msg[1]; 415 msgbuf = (char *)&msg[1];
415 sender = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 416 sender = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
416 memcpy (sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); 417 memcpy (sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity));
417 418
418 offset = 0; 419 offset = 0;
419 count = 0; 420 count = 0;
420 tsize = ntohs (msg->header.size) - sizeof(struct UDPMessage); 421 tsize = ntohs (msg->header.size) - sizeof(struct UDPMessage);
421 while (offset < tsize)
422 {
423 currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset];
424#if DEBUG_UDP 422#if DEBUG_UDP
425 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 423 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "UDP", _
426 ("processing msg %d: type %d, size %d at offset %d\n"), 424 ("offset is %d, tsize is %d (UDPMessage size is %d)\n"),
427 count, ntohs(currhdr->type), ntohs(currhdr->size), offset); 425 offset, tsize, sizeof(struct UDPMessage));
428#endif 426#endif
429 plugin->env->receive (plugin->env->cls, 427 while (offset < tsize)
430 sender, currhdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen); 428 {
431 offset += ntohs(currhdr->size); 429 currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset];
432#if DEBUG_UDP 430#if DEBUG_UDP
433 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 431 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
434 ("offset now %d, tsize %d\n"), 432 ("processing msg %d: type %d, size %d at offset %d\n"),
435 offset, tsize); 433 count, ntohs(currhdr->type), ntohs(currhdr->size), offset);
436#endif 434#endif
437 count++; 435 plugin->env->receive (plugin->env->cls,
438 } 436 sender, currhdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen);
439 437 offset += ntohs(currhdr->size);
440 GNUNET_free (sender); 438#if DEBUG_UDP
441 GNUNET_free (buf); 439 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
440 ("offset now %d, tsize %d\n"),
441 offset, tsize);
442#endif
443 count++;
444 }
442 445
443 } 446 GNUNET_free (sender);
444 while (GNUNET_NETWORK_socket_select (plugin->rs, 447 GNUNET_free (buf);
445 NULL,
446 NULL,
447 timeout) > 0
448 && GNUNET_NETWORK_fdset_isset (plugin->rs, udp_sock));
449 448
450 plugin->select_task = 449 plugin->select_task =
451 GNUNET_SCHEDULER_add_select (plugin->env->sched, 450 GNUNET_SCHEDULER_add_select (plugin->env->sched,