diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-01-19 15:21:42 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-01-19 15:21:42 +0000 |
commit | 4afc7dedbafd7a9fa3ae96ddc68a3e9946c8fdb4 (patch) | |
tree | 6a5f042245a609d9df1c26c68c26e08cdc956103 | |
parent | 08db56809eff3599cd47792d3dd8c5f0c27a11a8 (diff) | |
download | gnunet-4afc7dedbafd7a9fa3ae96ddc68a3e9946c8fdb4.tar.gz gnunet-4afc7dedbafd7a9fa3ae96ddc68a3e9946c8fdb4.zip |
making udp maybe, possibly, do something
-rw-r--r-- | src/transport/gnunet-service-transport.c | 4 | ||||
-rw-r--r-- | src/transport/plugin_transport_http.c | 10 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 20 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 81 | ||||
-rw-r--r-- | src/transport/test_plugin_transport_udp.c | 14 | ||||
-rw-r--r-- | src/transport/transport_api_address_lookup.c | 4 |
6 files changed, 79 insertions, 54 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index acdac052c..306efeac1 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -1688,8 +1688,8 @@ check_hello_validated (void *cls, | |||
1688 | va = va->next; | 1688 | va = va->next; |
1689 | } | 1689 | } |
1690 | GNUNET_SCHEDULER_add_delayed (sched, | 1690 | GNUNET_SCHEDULER_add_delayed (sched, |
1691 | GNUNET_TIME_absolute_get_remaining (chvc->e-> | 1691 | GNUNET_TIME_absolute_get_remaining (chvc-> |
1692 | timeout), | 1692 | e->timeout), |
1693 | &cleanup_validation, NULL); | 1693 | &cleanup_validation, NULL); |
1694 | GNUNET_free (chvc); | 1694 | GNUNET_free (chvc); |
1695 | } | 1695 | } |
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index e5f1361ac..6d4413bba 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -1006,8 +1006,9 @@ receiveContentCallback (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
1006 | cpy = sizeof (GNUNET_MessageHeader) - httpSession->cs.client.rpos1; | 1006 | cpy = sizeof (GNUNET_MessageHeader) - httpSession->cs.client.rpos1; |
1007 | if (cpy > have) | 1007 | if (cpy > have) |
1008 | cpy = have; | 1008 | cpy = have; |
1009 | memcpy (&httpSession->cs.client. | 1009 | memcpy (&httpSession->cs. |
1010 | rbuff1[httpSession->cs.client.rpos1], &inbuf[poff], cpy); | 1010 | client.rbuff1[httpSession->cs.client.rpos1], &inbuf[poff], |
1011 | cpy); | ||
1011 | httpSession->cs.client.rpos1 += cpy; | 1012 | httpSession->cs.client.rpos1 += cpy; |
1012 | have -= cpy; | 1013 | have -= cpy; |
1013 | poff += cpy; | 1014 | poff += cpy; |
@@ -1027,8 +1028,9 @@ receiveContentCallback (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
1027 | httpSession->cs.client.rpos2; | 1028 | httpSession->cs.client.rpos2; |
1028 | if (cpy > have) | 1029 | if (cpy > have) |
1029 | cpy = have; | 1030 | cpy = have; |
1030 | memcpy (&httpSession->cs.client. | 1031 | memcpy (&httpSession->cs. |
1031 | rbuff2[httpSession->cs.client.rpos2], &inbuf[poff], cpy); | 1032 | client.rbuff2[httpSession->cs.client.rpos2], &inbuf[poff], |
1033 | cpy); | ||
1032 | have -= cpy; | 1034 | have -= cpy; |
1033 | poff += cpy; | 1035 | poff += cpy; |
1034 | httpSession->cs.client.rpos2 += cpy; | 1036 | httpSession->cs.client.rpos2 += cpy; |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index d877a7f5b..9221f7e49 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -624,14 +624,16 @@ process_pending_messages (struct Session *session) | |||
624 | return; | 624 | return; |
625 | session->transmit_handle | 625 | session->transmit_handle |
626 | = GNUNET_SERVER_notify_transmit_ready (session->client, | 626 | = GNUNET_SERVER_notify_transmit_ready (session->client, |
627 | ntohs (session->pending_messages-> | 627 | ntohs (session-> |
628 | msg->size) + | 628 | pending_messages->msg-> |
629 | (session->pending_messages-> | 629 | size) + |
630 | is_welcome ? 0 : sizeof (struct | 630 | (session-> |
631 | DataMessage)), | 631 | pending_messages->is_welcome ? 0 : |
632 | sizeof (struct DataMessage)), | ||
632 | GNUNET_TIME_absolute_get_remaining | 633 | GNUNET_TIME_absolute_get_remaining |
633 | (session->pending_messages[0]. | 634 | (session-> |
634 | timeout), &do_transmit, session); | 635 | pending_messages[0].timeout), |
636 | &do_transmit, session); | ||
635 | } | 637 | } |
636 | 638 | ||
637 | 639 | ||
@@ -803,8 +805,8 @@ disconnect_session (struct Session *session) | |||
803 | } | 805 | } |
804 | if (session->transmit_handle != NULL) | 806 | if (session->transmit_handle != NULL) |
805 | { | 807 | { |
806 | GNUNET_CONNECTION_notify_transmit_ready_cancel (session-> | 808 | GNUNET_CONNECTION_notify_transmit_ready_cancel |
807 | transmit_handle); | 809 | (session->transmit_handle); |
808 | session->transmit_handle = NULL; | 810 | session->transmit_handle = NULL; |
809 | } | 811 | } |
810 | while (NULL != (pm = session->pending_messages)) | 812 | while (NULL != (pm = session->pending_messages)) |
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 | */ |
54 | static struct GNUNET_RESOLVER_RequestHandle *hostname_dns; | 48 | static 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 | ||
282 | static struct Session * | 285 | static struct Session * |
283 | find_session (void *cls, struct Session *session_list, | 286 | find_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; |
diff --git a/src/transport/test_plugin_transport_udp.c b/src/transport/test_plugin_transport_udp.c index 1bfe0f269..c8122e2e2 100644 --- a/src/transport/test_plugin_transport_udp.c +++ b/src/transport/test_plugin_transport_udp.c | |||
@@ -147,7 +147,7 @@ validation_notification (void *cls, | |||
147 | const struct GNUNET_PeerIdentity *peer, | 147 | const struct GNUNET_PeerIdentity *peer, |
148 | uint32_t challenge, const char *sender_addr) | 148 | uint32_t challenge, const char *sender_addr) |
149 | { | 149 | { |
150 | struct sockaddr_storage *addr = (struct sockaddr_storage *)sender_addr; | 150 | struct sockaddr_storage *addr = (struct sockaddr_storage *) sender_addr; |
151 | 151 | ||
152 | if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK) | 152 | if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK) |
153 | { | 153 | { |
@@ -156,14 +156,18 @@ validation_notification (void *cls, | |||
156 | } | 156 | } |
157 | 157 | ||
158 | switch (addr->ss_family) | 158 | switch (addr->ss_family) |
159 | { | 159 | { |
160 | case AF_INET: | 160 | case AF_INET: |
161 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | 161 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
162 | ("got address %s\n"),GNUNET_a2s((struct sockaddr *)addr, INET_ADDRSTRLEN)); | 162 | ("got address %s\n"), |
163 | GNUNET_a2s ((struct sockaddr *) addr, | ||
164 | INET_ADDRSTRLEN)); | ||
163 | case AF_INET6: | 165 | case AF_INET6: |
164 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | 166 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
165 | ("got address %s\n"),GNUNET_a2s((struct sockaddr *)addr, INET6_ADDRSTRLEN)); | 167 | ("got address %s\n"), |
166 | } | 168 | GNUNET_a2s ((struct sockaddr *) addr, |
169 | INET6_ADDRSTRLEN)); | ||
170 | } | ||
167 | 171 | ||
168 | 172 | ||
169 | GNUNET_assert (challenge == 42); | 173 | GNUNET_assert (challenge == 42); |
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 961ee0713..d2bc51d47 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c | |||
@@ -57,8 +57,8 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) | |||
57 | /* expect more replies */ | 57 | /* expect more replies */ |
58 | GNUNET_CLIENT_receive (alucb->client, &address_response_processor, | 58 | GNUNET_CLIENT_receive (alucb->client, &address_response_processor, |
59 | alucb, | 59 | alucb, |
60 | GNUNET_TIME_absolute_get_remaining (alucb-> | 60 | GNUNET_TIME_absolute_get_remaining |
61 | timeout)); | 61 | (alucb->timeout)); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | alucb->cb (alucb->cls, address); | 64 | alucb->cb (alucb->cls, address); |