aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r--src/transport/plugin_transport_udp.c81
1 files changed, 49 insertions, 32 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 5dca2a748..d3c2bac85 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -43,12 +43,6 @@
43#define DEBUG_UDP GNUNET_NO 43#define DEBUG_UDP GNUNET_NO
44 44
45/** 45/**
46 * The default maximum size of each outbound UDP message,
47 * optimal value for Ethernet (10 or 100 MBit).
48 */
49#define MESSAGE_SIZE 1472
50
51/**
52 * Handle for request of hostname resolution, non-NULL if pending. 46 * Handle for request of hostname resolution, non-NULL if pending.
53 */ 47 */
54static struct GNUNET_RESOLVER_RequestHandle *hostname_dns; 48static struct GNUNET_RESOLVER_RequestHandle *hostname_dns;
@@ -115,6 +109,15 @@ struct Session
115 */ 109 */
116 unsigned int validated; 110 unsigned int validated;
117 111
112 /*
113 * What is the latency of this connection? (Time between ping and pong)
114 */
115 struct GNUNET_TIME_Relative latency;
116
117 /*
118 * At what GNUNET_TIME did we send a ping?
119 */
120 struct GNUNET_TIME_Absolute ping_sent;
118}; 121};
119 122
120/** 123/**
@@ -280,12 +283,11 @@ udp_transport_server_stop (void *cls)
280} 283}
281 284
282static struct Session * 285static struct Session *
283find_session (void *cls, struct Session *session_list, 286find_session (void *cls, const struct GNUNET_PeerIdentity *peer)
284 const struct GNUNET_PeerIdentity *peer)
285{ 287{
286 struct Plugin *plugin = cls; 288 struct Plugin *plugin = cls;
287 struct Session *pos; 289 struct Session *pos;
288 pos = session_list; 290 pos = plugin->sessions;
289 291
290 while (pos != NULL) 292 while (pos != NULL)
291 { 293 {
@@ -329,7 +331,7 @@ udp_plugin_send (void *cls,
329 int ssize; 331 int ssize;
330 size_t sent; 332 size_t sent;
331 333
332 session = find_session (plugin, plugin->sessions, target); 334 session = find_session (plugin, target);
333 335
334 if ((session == NULL) || (udp_sock == NULL)) 336 if ((session == NULL) || (udp_sock == NULL))
335 return; 337 return;
@@ -361,7 +363,7 @@ udp_plugin_send (void *cls,
361 else 363 else
362 cont (cont_cls, target, GNUNET_OK); 364 cont (cont_cls, target, GNUNET_OK);
363 } 365 }
364 GNUNET_free(message); 366 GNUNET_free (message);
365 return; 367 return;
366} 368}
367 369
@@ -380,7 +382,6 @@ handle_udp_ping (void *cls,
380 const struct GNUNET_MessageHeader *message) 382 const struct GNUNET_MessageHeader *message)
381{ 383{
382 struct Plugin *plugin = cls; 384 struct Plugin *plugin = cls;
383 struct Session *head = plugin->sessions;
384 const struct UDPPingMessage *ping = (const struct UDPPingMessage *) message; 385 const struct UDPPingMessage *ping = (const struct UDPPingMessage *) message;
385 struct UDPPongMessage *pong; 386 struct UDPPongMessage *pong;
386 struct Session *found; 387 struct Session *found;
@@ -390,7 +391,7 @@ handle_udp_ping (void *cls,
390 ("handling ping, challenge is %d\n"), 391 ("handling ping, challenge is %d\n"),
391 ntohs (ping->challenge)); 392 ntohs (ping->challenge));
392#endif 393#endif
393 found = find_session (plugin, head, sender); 394 found = find_session (plugin, sender);
394 if (found != NULL) 395 if (found != NULL)
395 { 396 {
396 pong = GNUNET_malloc (sizeof (struct UDPPongMessage) + addrlen); 397 pong = GNUNET_malloc (sizeof (struct UDPPongMessage) + addrlen);
@@ -404,7 +405,7 @@ handle_udp_ping (void *cls,
404 &pong->header, 405 &pong->header,
405 GNUNET_TIME_relative_multiply 406 GNUNET_TIME_relative_multiply
406 (GNUNET_TIME_UNIT_SECONDS, 30), NULL, NULL); 407 (GNUNET_TIME_UNIT_SECONDS, 30), NULL, NULL);
407 GNUNET_free(pong); 408 GNUNET_free (pong);
408 } 409 }
409 410
410 return; 411 return;
@@ -434,7 +435,7 @@ handle_udp_pong (void *cls,
434#if DEBUG_UDP 435#if DEBUG_UDP
435 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _("handling pong\n")); 436 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _("handling pong\n"));
436#endif 437#endif
437 found = find_session (plugin, plugin->sessions, sender); 438 found = find_session (plugin, sender);
438#if DEBUG_UDP 439#if DEBUG_UDP
439 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 440 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
440 ("found->challenge %d, pong->challenge %d\n"), 441 ("found->challenge %d, pong->challenge %d\n"),
@@ -443,6 +444,9 @@ handle_udp_pong (void *cls,
443 if ((found != NULL) && (found->challenge == ntohs (pong->challenge))) 444 if ((found != NULL) && (found->challenge == ntohs (pong->challenge)))
444 { 445 {
445 found->validated = GNUNET_YES; 446 found->validated = GNUNET_YES;
447 found->latency =
448 GNUNET_TIME_absolute_get_difference (found->ping_sent,
449 GNUNET_TIME_absolute_get ());
446 addr_len = ntohs (pong->addrlen); 450 addr_len = ntohs (pong->addrlen);
447#if DEBUG_UDP 451#if DEBUG_UDP
448 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 452 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
@@ -479,6 +483,7 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
479 socklen_t fromlen; 483 socklen_t fromlen;
480 struct sockaddr_storage addr; 484 struct sockaddr_storage addr;
481 ssize_t ret; 485 ssize_t ret;
486 struct Session *found;
482 487
483 do 488 do
484 { 489 {
@@ -528,13 +533,13 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
528 ("header reports message type of %d\n"), 533 ("header reports message type of %d\n"),
529 ntohs (msg->header.type)); 534 ntohs (msg->header.type));
530#endif 535#endif
531 /*if (ntohs(hdr->size) < sizeof(struct UDPMessage)) 536 if (ntohs (msg->header.size) < sizeof (struct UDPMessage))
532 { 537 {
533 GNUNET_free(buf); 538 GNUNET_free (buf);
534 GNUNET_NETWORK_fdset_zero(plugin->rs); 539 GNUNET_NETWORK_fdset_zero (plugin->rs);
535 GNUNET_NETWORK_fdset_set(plugin->rs, udp_sock); 540 GNUNET_NETWORK_fdset_set (plugin->rs, udp_sock);
536 break; 541 break;
537 } */ 542 }
538 hdr = (const struct GNUNET_MessageHeader *) &msg[1]; 543 hdr = (const struct GNUNET_MessageHeader *) &msg[1];
539 sender = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 544 sender = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
540 memcpy (sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); 545 memcpy (sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity));
@@ -553,12 +558,22 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
553 { 558 {
554 handle_udp_ping (plugin, sender, &addr, fromlen, hdr); 559 handle_udp_ping (plugin, sender, &addr, fromlen, hdr);
555 } 560 }
556 561 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PONG)
557 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PONG)
558 { 562 {
559 handle_udp_pong (plugin, sender, hdr); 563 handle_udp_pong (plugin, sender, hdr);
560 } 564 }
561 GNUNET_free(sender); 565 else
566 {
567 found = find_session (plugin, sender);
568 if (found != NULL)
569 plugin->env->receive (plugin->env->cls, found->latency, sender,
570 &msg->header);
571 else
572 plugin->env->receive (plugin->env->cls,
573 GNUNET_TIME_relative_get_forever (), sender,
574 &msg->header);
575 }
576 GNUNET_free (sender);
562 GNUNET_free (buf); 577 GNUNET_free (buf);
563 578
564 } 579 }
@@ -676,7 +691,7 @@ udp_plugin_validate (void *cls,
676{ 691{
677 struct Plugin *plugin = cls; 692 struct Plugin *plugin = cls;
678 struct Session *new_session; 693 struct Session *new_session;
679 struct UDPPongMessage *msg; 694 struct UDPPingMessage *msg;
680 695
681 if (addrlen <= 0) 696 if (addrlen <= 0)
682 return GNUNET_SYSERR; 697 return GNUNET_SYSERR;
@@ -697,11 +712,13 @@ udp_plugin_validate (void *cls,
697 memcpy (&new_session->target, target, sizeof (struct GNUNET_PeerIdentity)); 712 memcpy (&new_session->target, target, sizeof (struct GNUNET_PeerIdentity));
698 new_session->challenge = challenge; 713 new_session->challenge = challenge;
699 new_session->validated = GNUNET_NO; 714 new_session->validated = GNUNET_NO;
715 new_session->latency = GNUNET_TIME_relative_get_zero ();
716 new_session->ping_sent = GNUNET_TIME_absolute_get ();
700 new_session->next = plugin->sessions; 717 new_session->next = plugin->sessions;
701 plugin->sessions = new_session; 718 plugin->sessions = new_session;
702 719
703 msg = GNUNET_malloc (sizeof (struct UDPPongMessage)); 720 msg = GNUNET_malloc (sizeof (struct UDPPingMessage));
704 msg->header.size = htons (sizeof (struct UDPPongMessage)); 721 msg->header.size = htons (sizeof (struct UDPPingMessage));
705 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PING); 722 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PING);
706 msg->challenge = htons (challenge); 723 msg->challenge = htons (challenge);
707#if DEBUG_UDP 724#if DEBUG_UDP
@@ -713,7 +730,7 @@ udp_plugin_validate (void *cls,
713 udp_plugin_send (plugin, target, GNUNET_SCHEDULER_PRIORITY_DEFAULT, 730 udp_plugin_send (plugin, target, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
714 &msg->header, timeout, NULL, NULL); 731 &msg->header, timeout, NULL, NULL);
715 732
716 GNUNET_free(msg); 733 GNUNET_free (msg);
717 return GNUNET_OK; 734 return GNUNET_OK;
718} 735}
719 736
@@ -880,13 +897,13 @@ libgnunet_plugin_transport_udp_done (void *cls)
880 pos = plugin->sessions; 897 pos = plugin->sessions;
881 while (pos != NULL) 898 while (pos != NULL)
882 { 899 {
883 GNUNET_free(pos->connect_addr); 900 GNUNET_free (pos->connect_addr);
884 oldpos = pos; 901 oldpos = pos;
885 pos = pos->next; 902 pos = pos->next;
886 GNUNET_free(oldpos); 903 GNUNET_free (oldpos);
887 } 904 }
888 905
889 GNUNET_NETWORK_fdset_destroy(plugin->rs); 906 GNUNET_NETWORK_fdset_destroy (plugin->rs);
890 GNUNET_free (plugin); 907 GNUNET_free (plugin);
891 GNUNET_free (api); 908 GNUNET_free (api);
892 return NULL; 909 return NULL;