diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-01-13 16:59:57 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-01-13 16:59:57 +0000 |
commit | 1257490cb630ade315a196a724d0233e662afb2c (patch) | |
tree | 0d9c01593a1aa73d8f6490127b640d67da69b54c /src/transport/plugin_transport_udp.c | |
parent | 35d79cb1941c9f9607195b8760d8a14d836e6397 (diff) | |
download | gnunet-1257490cb630ade315a196a724d0233e662afb2c.tar.gz gnunet-1257490cb630ade315a196a724d0233e662afb2c.zip |
implementing 0003268 to inbound information in HELLO addresses
All transport plugin functions are modified to use HELLO addresses instead of peer,address,address_length
All plugins are modified to use HELLO addresses internally
This commit can break transport functionality: core tests on my system still pass,
but transport tests may still fail, errors messages may occurs or crashs
Will be fixed asap
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 2141 |
1 files changed, 934 insertions, 1207 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index d3a8d1017..836cf2ad5 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file transport/plugin_transport_udp.c | 22 | * @file transport/plugin_transport_udp.c |
@@ -44,8 +44,6 @@ | |||
44 | 44 | ||
45 | #define UDP_SESSION_TIME_OUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 45 | #define UDP_SESSION_TIME_OUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
46 | 46 | ||
47 | #define PLUGIN_NAME "udp" | ||
48 | |||
49 | /** | 47 | /** |
50 | * Number of messages we can defragment in parallel. We only really | 48 | * Number of messages we can defragment in parallel. We only really |
51 | * defragment 1 message at a time, but if messages get re-ordered, we | 49 | * defragment 1 message at a time, but if messages get re-ordered, we |
@@ -127,7 +125,6 @@ struct PrettyPrinterContext | |||
127 | uint32_t options; | 125 | uint32_t options; |
128 | }; | 126 | }; |
129 | 127 | ||
130 | |||
131 | enum UDP_MessageType | 128 | enum UDP_MessageType |
132 | { | 129 | { |
133 | UNDEFINED = 0, | 130 | UNDEFINED = 0, |
@@ -138,7 +135,6 @@ enum UDP_MessageType | |||
138 | MSG_BEACON = 5 | 135 | MSG_BEACON = 5 |
139 | }; | 136 | }; |
140 | 137 | ||
141 | |||
142 | struct Session | 138 | struct Session |
143 | { | 139 | { |
144 | /** | 140 | /** |
@@ -157,11 +153,6 @@ struct Session | |||
157 | struct UDP_FragmentationContext *frag_ctx; | 153 | struct UDP_FragmentationContext *frag_ctx; |
158 | 154 | ||
159 | /** | 155 | /** |
160 | * Address of the other peer | ||
161 | */ | ||
162 | const struct sockaddr *sock_addr; | ||
163 | |||
164 | /** | ||
165 | * Desired delay for next sending we send to other peer | 156 | * Desired delay for next sending we send to other peer |
166 | */ | 157 | */ |
167 | struct GNUNET_TIME_Relative flow_delay_for_other_peer; | 158 | struct GNUNET_TIME_Relative flow_delay_for_other_peer; |
@@ -188,10 +179,7 @@ struct Session | |||
188 | 179 | ||
189 | struct GNUNET_ATS_Information ats; | 180 | struct GNUNET_ATS_Information ats; |
190 | 181 | ||
191 | /** | 182 | struct GNUNET_HELLO_Address *address; |
192 | * Number of bytes in @e sock_addr. | ||
193 | */ | ||
194 | size_t addrlen; | ||
195 | 183 | ||
196 | /** | 184 | /** |
197 | * Reference counter to indicate that this session is | 185 | * Reference counter to indicate that this session is |
@@ -208,22 +196,17 @@ struct Session | |||
208 | * @e rc is non-zero). | 196 | * @e rc is non-zero). |
209 | */ | 197 | */ |
210 | int in_destroy; | 198 | int in_destroy; |
211 | |||
212 | int inbound; | ||
213 | }; | 199 | }; |
214 | 200 | ||
215 | |||
216 | /** | 201 | /** |
217 | * Closure for #session_cmp_it(). | 202 | * Closure for #session_cmp_it(). |
218 | */ | 203 | */ |
219 | struct SessionCompareContext | 204 | struct SessionCompareContext |
220 | { | 205 | { |
221 | struct Session *res; | 206 | struct Session *res; |
222 | const struct GNUNET_HELLO_Address *addr; | 207 | const struct GNUNET_HELLO_Address *address; |
223 | int inbound; | ||
224 | }; | 208 | }; |
225 | 209 | ||
226 | |||
227 | /** | 210 | /** |
228 | * Closure for #process_inbound_tokenized_messages(). | 211 | * Closure for #process_inbound_tokenized_messages(). |
229 | */ | 212 | */ |
@@ -251,7 +234,6 @@ struct SourceInformation | |||
251 | 234 | ||
252 | }; | 235 | }; |
253 | 236 | ||
254 | |||
255 | /** | 237 | /** |
256 | * Closure for #find_receive_context(). | 238 | * Closure for #find_receive_context(). |
257 | */ | 239 | */ |
@@ -276,8 +258,6 @@ struct FindReceiveContext | |||
276 | 258 | ||
277 | }; | 259 | }; |
278 | 260 | ||
279 | |||
280 | |||
281 | /** | 261 | /** |
282 | * Data structure to track defragmentation contexts based | 262 | * Data structure to track defragmentation contexts based |
283 | * on the source of the UDP traffic. | 263 | * on the source of the UDP traffic. |
@@ -312,8 +292,6 @@ struct DefragContext | |||
312 | size_t addr_len; | 292 | size_t addr_len; |
313 | }; | 293 | }; |
314 | 294 | ||
315 | |||
316 | |||
317 | /** | 295 | /** |
318 | * Context to send fragmented messages | 296 | * Context to send fragmented messages |
319 | */ | 297 | */ |
@@ -373,7 +351,6 @@ struct UDP_FragmentationContext | |||
373 | 351 | ||
374 | }; | 352 | }; |
375 | 353 | ||
376 | |||
377 | struct UDP_MessageWrapper | 354 | struct UDP_MessageWrapper |
378 | { | 355 | { |
379 | /** | 356 | /** |
@@ -437,7 +414,6 @@ struct UDP_MessageWrapper | |||
437 | struct UDP_FragmentationContext *frag_ctx; | 414 | struct UDP_FragmentationContext *frag_ctx; |
438 | }; | 415 | }; |
439 | 416 | ||
440 | |||
441 | /** | 417 | /** |
442 | * UDP ACK Message-Packet header (after defragmentation). | 418 | * UDP ACK Message-Packet header (after defragmentation). |
443 | */ | 419 | */ |
@@ -465,13 +441,11 @@ struct UDP_ACK_Message | |||
465 | */ | 441 | */ |
466 | static uint32_t myoptions; | 442 | static uint32_t myoptions; |
467 | 443 | ||
468 | |||
469 | /** | 444 | /** |
470 | * Encapsulation of all of the state of the plugin. | 445 | * Encapsulation of all of the state of the plugin. |
471 | */ | 446 | */ |
472 | struct Plugin * plugin; | 447 | struct Plugin * plugin; |
473 | 448 | ||
474 | |||
475 | /** | 449 | /** |
476 | * We have been notified that our readset has something to read. We don't | 450 | * We have been notified that our readset has something to read. We don't |
477 | * know which socket needs to be read, so we have to check each one | 451 | * know which socket needs to be read, so we have to check each one |
@@ -483,7 +457,6 @@ struct Plugin * plugin; | |||
483 | static void | 457 | static void |
484 | udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 458 | udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
485 | 459 | ||
486 | |||
487 | /** | 460 | /** |
488 | * We have been notified that our readset has something to read. We don't | 461 | * We have been notified that our readset has something to read. We don't |
489 | * know which socket needs to be read, so we have to check each one | 462 | * know which socket needs to be read, so we have to check each one |
@@ -495,7 +468,6 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
495 | static void | 468 | static void |
496 | udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 469 | udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
497 | 470 | ||
498 | |||
499 | /** | 471 | /** |
500 | * (re)schedule select tasks for this plugin. | 472 | * (re)schedule select tasks for this plugin. |
501 | * | 473 | * |
@@ -514,40 +486,41 @@ schedule_select (struct Plugin *plugin) | |||
514 | min_delay = GNUNET_TIME_UNIT_FOREVER_REL; | 486 | min_delay = GNUNET_TIME_UNIT_FOREVER_REL; |
515 | for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next) | 487 | for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next) |
516 | min_delay = GNUNET_TIME_relative_min (min_delay, | 488 | min_delay = GNUNET_TIME_relative_min (min_delay, |
517 | GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer)); | 489 | GNUNET_TIME_absolute_get_remaining ( |
490 | udpw->session->flow_delay_from_other_peer)); | ||
518 | 491 | ||
519 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) | 492 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK ) |
520 | GNUNET_SCHEDULER_cancel(plugin->select_task); | 493 | GNUNET_SCHEDULER_cancel (plugin->select_task); |
521 | 494 | ||
522 | /* Schedule with: | 495 | /* Schedule with: |
523 | * - write active set if message is ready | 496 | * - write active set if message is ready |
524 | * - timeout minimum delay */ | 497 | * - timeout minimum delay */ |
525 | plugin->select_task = | 498 | plugin->select_task = GNUNET_SCHEDULER_add_select ( |
526 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 499 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
527 | (0 == min_delay.rel_value_us) ? GNUNET_TIME_UNIT_FOREVER_REL : min_delay, | 500 | (0 == min_delay.rel_value_us) ? |
528 | plugin->rs_v4, | 501 | GNUNET_TIME_UNIT_FOREVER_REL : min_delay, plugin->rs_v4, |
529 | (0 == min_delay.rel_value_us) ? plugin->ws_v4 : NULL, | 502 | (0 == min_delay.rel_value_us) ? plugin->ws_v4 : NULL, |
530 | &udp_plugin_select, plugin); | 503 | &udp_plugin_select, plugin); |
531 | } | 504 | } |
532 | if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6)) | 505 | if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6)) |
533 | { | 506 | { |
534 | min_delay = GNUNET_TIME_UNIT_FOREVER_REL; | 507 | min_delay = GNUNET_TIME_UNIT_FOREVER_REL; |
535 | for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next) | 508 | for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next) |
536 | min_delay = GNUNET_TIME_relative_min (min_delay, | 509 | min_delay = GNUNET_TIME_relative_min (min_delay, |
537 | GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer)); | 510 | GNUNET_TIME_absolute_get_remaining ( |
511 | udpw->session->flow_delay_from_other_peer)); | ||
538 | 512 | ||
539 | if (GNUNET_SCHEDULER_NO_TASK != plugin->select_task_v6) | 513 | if (GNUNET_SCHEDULER_NO_TASK != plugin->select_task_v6) |
540 | GNUNET_SCHEDULER_cancel(plugin->select_task_v6); | 514 | GNUNET_SCHEDULER_cancel (plugin->select_task_v6); |
541 | plugin->select_task_v6 = | 515 | plugin->select_task_v6 = GNUNET_SCHEDULER_add_select ( |
542 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 516 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
543 | (0 == min_delay.rel_value_us) ? GNUNET_TIME_UNIT_FOREVER_REL : min_delay, | 517 | (0 == min_delay.rel_value_us) ? |
544 | plugin->rs_v6, | 518 | GNUNET_TIME_UNIT_FOREVER_REL : min_delay, plugin->rs_v6, |
545 | (0 == min_delay.rel_value_us) ? plugin->ws_v6 : NULL, | 519 | (0 == min_delay.rel_value_us) ? plugin->ws_v6 : NULL, |
546 | &udp_plugin_select_v6, plugin); | 520 | &udp_plugin_select_v6, plugin); |
547 | } | 521 | } |
548 | } | 522 | } |
549 | 523 | ||
550 | |||
551 | /** | 524 | /** |
552 | * Function called for a quick conversion of the binary address to | 525 | * Function called for a quick conversion of the binary address to |
553 | * a numeric address. Note that the caller must not free the | 526 | * a numeric address. Note that the caller must not free the |
@@ -573,37 +546,36 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
573 | uint16_t port; | 546 | uint16_t port; |
574 | uint32_t options; | 547 | uint32_t options; |
575 | 548 | ||
576 | if ((NULL != addr) && (addrlen == sizeof (struct IPv6UdpAddress))) | 549 | if ((NULL != addr) && (addrlen == sizeof(struct IPv6UdpAddress))) |
577 | { | 550 | { |
578 | t6 = addr; | 551 | t6 = addr; |
579 | af = AF_INET6; | 552 | af = AF_INET6; |
580 | options = ntohl (t6->options); | 553 | options = ntohl (t6->options); |
581 | port = ntohs (t6->u6_port); | 554 | port = ntohs (t6->u6_port); |
582 | memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); | 555 | memcpy (&a6, &t6->ipv6_addr, sizeof(a6)); |
583 | sb = &a6; | 556 | sb = &a6; |
584 | } | 557 | } |
585 | else if ((NULL != addr) && (addrlen == sizeof (struct IPv4UdpAddress))) | 558 | else if ((NULL != addr) && (addrlen == sizeof(struct IPv4UdpAddress))) |
586 | { | 559 | { |
587 | t4 = addr; | 560 | t4 = addr; |
588 | af = AF_INET; | 561 | af = AF_INET; |
589 | options = ntohl (t4->options); | 562 | options = ntohl (t4->options); |
590 | port = ntohs (t4->u4_port); | 563 | port = ntohs (t4->u4_port); |
591 | memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); | 564 | memcpy (&a4, &t4->ipv4_addr, sizeof(a4)); |
592 | sb = &a4; | 565 | sb = &a4; |
593 | } | 566 | } |
594 | else | 567 | else |
595 | { | 568 | { |
596 | return NULL; | 569 | return NULL ; |
597 | } | 570 | } |
598 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); | 571 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); |
599 | 572 | ||
600 | GNUNET_snprintf (rbuf, sizeof (rbuf), | 573 | GNUNET_snprintf (rbuf, sizeof(rbuf), |
601 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", | 574 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", PLUGIN_NAME, options, |
602 | PLUGIN_NAME, options, buf, port); | 575 | buf, port); |
603 | return rbuf; | 576 | return rbuf; |
604 | } | 577 | } |
605 | 578 | ||
606 | |||
607 | /** | 579 | /** |
608 | * Function called to convert a string address to | 580 | * Function called to convert a string address to |
609 | * a binary address. | 581 | * a binary address. |
@@ -633,87 +605,85 @@ udp_string_to_address (void *cls, const char *addr, uint16_t addrlen, | |||
633 | 605 | ||
634 | if ((NULL == addr) || (addrlen == 0)) | 606 | if ((NULL == addr) || (addrlen == 0)) |
635 | { | 607 | { |
636 | GNUNET_break (0); | 608 | GNUNET_break(0); |
637 | return GNUNET_SYSERR; | 609 | return GNUNET_SYSERR; |
638 | } | 610 | } |
639 | if ('\0' != addr[addrlen - 1]) | 611 | if ('\0' != addr[addrlen - 1]) |
640 | { | 612 | { |
641 | GNUNET_break (0); | 613 | GNUNET_break(0); |
642 | return GNUNET_SYSERR; | 614 | return GNUNET_SYSERR; |
643 | } | 615 | } |
644 | if (strlen (addr) != addrlen - 1) | 616 | if (strlen (addr) != addrlen - 1) |
645 | { | 617 | { |
646 | GNUNET_break (0); | 618 | GNUNET_break(0); |
647 | return GNUNET_SYSERR; | 619 | return GNUNET_SYSERR; |
648 | } | 620 | } |
649 | plugin = GNUNET_strdup (addr); | 621 | plugin = GNUNET_strdup (addr); |
650 | optionstr = strchr (plugin, '.'); | 622 | optionstr = strchr (plugin, '.'); |
651 | if (NULL == optionstr) | 623 | if (NULL == optionstr) |
652 | { | 624 | { |
653 | GNUNET_break (0); | 625 | GNUNET_break(0); |
654 | GNUNET_free (plugin); | 626 | GNUNET_free(plugin); |
655 | return GNUNET_SYSERR; | 627 | return GNUNET_SYSERR; |
656 | } | 628 | } |
657 | optionstr[0] = '\0'; | 629 | optionstr[0] = '\0'; |
658 | optionstr ++; | 630 | optionstr++; |
659 | options = atol (optionstr); | 631 | options = atol (optionstr); |
660 | address = strchr (optionstr, '.'); | 632 | address = strchr (optionstr, '.'); |
661 | if (NULL == address) | 633 | if (NULL == address) |
662 | { | 634 | { |
663 | GNUNET_break (0); | 635 | GNUNET_break(0); |
664 | GNUNET_free (plugin); | 636 | GNUNET_free(plugin); |
665 | return GNUNET_SYSERR; | 637 | return GNUNET_SYSERR; |
666 | } | 638 | } |
667 | address[0] = '\0'; | 639 | address[0] = '\0'; |
668 | address ++; | 640 | address++; |
669 | 641 | ||
670 | if (GNUNET_OK != | 642 | if (GNUNET_OK |
671 | GNUNET_STRINGS_to_address_ip (address, strlen (address), | 643 | != GNUNET_STRINGS_to_address_ip (address, strlen (address), |
672 | &socket_address)) | 644 | &socket_address)) |
673 | { | 645 | { |
674 | GNUNET_break (0); | 646 | GNUNET_break(0); |
675 | GNUNET_free (plugin); | 647 | GNUNET_free(plugin); |
676 | return GNUNET_SYSERR; | 648 | return GNUNET_SYSERR; |
677 | } | 649 | } |
678 | 650 | ||
679 | GNUNET_free (plugin); | 651 | GNUNET_free(plugin); |
680 | 652 | ||
681 | switch (socket_address.ss_family) | 653 | switch (socket_address.ss_family) |
682 | { | 654 | { |
683 | case AF_INET: | 655 | case AF_INET: |
684 | { | 656 | { |
685 | struct IPv4UdpAddress *u4; | 657 | struct IPv4UdpAddress *u4; |
686 | struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; | 658 | struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; |
687 | u4 = GNUNET_new (struct IPv4UdpAddress); | 659 | u4 = GNUNET_new (struct IPv4UdpAddress); |
688 | u4->options = htonl (options); | 660 | u4->options = htonl (options); |
689 | u4->ipv4_addr = in4->sin_addr.s_addr; | 661 | u4->ipv4_addr = in4->sin_addr.s_addr; |
690 | u4->u4_port = in4->sin_port; | 662 | u4->u4_port = in4->sin_port; |
691 | *buf = u4; | 663 | *buf = u4; |
692 | *added = sizeof (struct IPv4UdpAddress); | 664 | *added = sizeof(struct IPv4UdpAddress); |
693 | return GNUNET_OK; | 665 | return GNUNET_OK; |
694 | } | 666 | } |
695 | case AF_INET6: | 667 | case AF_INET6: |
696 | { | 668 | { |
697 | struct IPv6UdpAddress *u6; | 669 | struct IPv6UdpAddress *u6; |
698 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; | 670 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; |
699 | u6 = GNUNET_new (struct IPv6UdpAddress); | 671 | u6 = GNUNET_new (struct IPv6UdpAddress); |
700 | u6->options = htonl (options); | 672 | u6->options = htonl (options); |
701 | u6->ipv6_addr = in6->sin6_addr; | 673 | u6->ipv6_addr = in6->sin6_addr; |
702 | u6->u6_port = in6->sin6_port; | 674 | u6->u6_port = in6->sin6_port; |
703 | *buf = u6; | 675 | *buf = u6; |
704 | *added = sizeof (struct IPv6UdpAddress); | 676 | *added = sizeof(struct IPv6UdpAddress); |
705 | return GNUNET_OK; | 677 | return GNUNET_OK; |
706 | } | 678 | } |
707 | default: | 679 | default: |
708 | GNUNET_break (0); | 680 | GNUNET_break(0); |
709 | return GNUNET_SYSERR; | 681 | return GNUNET_SYSERR; |
710 | } | 682 | } |
711 | } | 683 | } |
712 | 684 | ||
713 | |||
714 | static void | 685 | static void |
715 | ppc_cancel_task (void *cls, | 686 | ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
716 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
717 | { | 687 | { |
718 | struct PrettyPrinterContext *ppc = cls; | 688 | struct PrettyPrinterContext *ppc = cls; |
719 | 689 | ||
@@ -723,11 +693,10 @@ ppc_cancel_task (void *cls, | |||
723 | GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); | 693 | GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); |
724 | ppc->resolver_handle = NULL; | 694 | ppc->resolver_handle = NULL; |
725 | } | 695 | } |
726 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); | 696 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); |
727 | GNUNET_free (ppc); | 697 | GNUNET_free(ppc); |
728 | } | 698 | } |
729 | 699 | ||
730 | |||
731 | /** | 700 | /** |
732 | * Append our port and forward the result. | 701 | * Append our port and forward the result. |
733 | * | 702 | * |
@@ -741,14 +710,14 @@ append_port (void *cls, const char *hostname) | |||
741 | struct PrettyPrinterContext *cur; | 710 | struct PrettyPrinterContext *cur; |
742 | char *ret; | 711 | char *ret; |
743 | 712 | ||
744 | if (hostname == NULL) | 713 | if (hostname == NULL ) |
745 | { | 714 | { |
746 | ppc->asc (ppc->asc_cls, NULL); | 715 | ppc->asc (ppc->asc_cls, NULL ); |
747 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); | 716 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); |
748 | GNUNET_SCHEDULER_cancel (ppc->timeout_task); | 717 | GNUNET_SCHEDULER_cancel (ppc->timeout_task); |
749 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 718 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
750 | ppc->resolver_handle = NULL; | 719 | ppc->resolver_handle = NULL; |
751 | GNUNET_free (ppc); | 720 | GNUNET_free(ppc); |
752 | return; | 721 | return; |
753 | } | 722 | } |
754 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) | 723 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) |
@@ -758,30 +727,20 @@ append_port (void *cls, const char *hostname) | |||
758 | } | 727 | } |
759 | if (NULL == cur) | 728 | if (NULL == cur) |
760 | { | 729 | { |
761 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 730 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Invalid callback for PPC %p \n", ppc); |
762 | "Invalid callback for PPC %p \n", ppc); | ||
763 | return; | 731 | return; |
764 | } | 732 | } |
765 | 733 | ||
766 | if (GNUNET_YES == ppc->ipv6) | 734 | if (GNUNET_YES == ppc->ipv6) |
767 | GNUNET_asprintf (&ret, | 735 | GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, |
768 | "%s.%u.[%s]:%d", | 736 | ppc->port); |
769 | PLUGIN_NAME, | ||
770 | ppc->options, | ||
771 | hostname, | ||
772 | ppc->port); | ||
773 | else | 737 | else |
774 | GNUNET_asprintf (&ret, | 738 | GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, |
775 | "%s.%u.%s:%d", | 739 | ppc->port); |
776 | PLUGIN_NAME, | ||
777 | ppc->options, | ||
778 | hostname, | ||
779 | ppc->port); | ||
780 | ppc->asc (ppc->asc_cls, ret); | 740 | ppc->asc (ppc->asc_cls, ret); |
781 | GNUNET_free (ret); | 741 | GNUNET_free(ret); |
782 | } | 742 | } |
783 | 743 | ||
784 | |||
785 | /** | 744 | /** |
786 | * Convert the transports address to a nice, human-readable | 745 | * Convert the transports address to a nice, human-readable |
787 | * format. | 746 | * format. |
@@ -798,11 +757,9 @@ append_port (void *cls, const char *hostname) | |||
798 | */ | 757 | */ |
799 | static void | 758 | static void |
800 | udp_plugin_address_pretty_printer (void *cls, const char *type, | 759 | udp_plugin_address_pretty_printer (void *cls, const char *type, |
801 | const void *addr, size_t addrlen, | 760 | const void *addr, size_t addrlen, int numeric, |
802 | int numeric, | 761 | struct GNUNET_TIME_Relative timeout, |
803 | struct GNUNET_TIME_Relative timeout, | 762 | GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) |
804 | GNUNET_TRANSPORT_AddressStringCallback asc, | ||
805 | void *asc_cls) | ||
806 | { | 763 | { |
807 | struct PrettyPrinterContext *ppc; | 764 | struct PrettyPrinterContext *ppc; |
808 | const void *sb; | 765 | const void *sb; |
@@ -814,25 +771,25 @@ udp_plugin_address_pretty_printer (void *cls, const char *type, | |||
814 | uint16_t port; | 771 | uint16_t port; |
815 | uint32_t options; | 772 | uint32_t options; |
816 | 773 | ||
817 | if (addrlen == sizeof (struct IPv6UdpAddress)) | 774 | if (addrlen == sizeof(struct IPv6UdpAddress)) |
818 | { | 775 | { |
819 | u6 = addr; | 776 | u6 = addr; |
820 | memset (&a6, 0, sizeof (a6)); | 777 | memset (&a6, 0, sizeof(a6)); |
821 | a6.sin6_family = AF_INET6; | 778 | a6.sin6_family = AF_INET6; |
822 | #if HAVE_SOCKADDR_IN_SIN_LEN | 779 | #if HAVE_SOCKADDR_IN_SIN_LEN |
823 | a6.sin6_len = sizeof (a6); | 780 | a6.sin6_len = sizeof (a6); |
824 | #endif | 781 | #endif |
825 | a6.sin6_port = u6->u6_port; | 782 | a6.sin6_port = u6->u6_port; |
826 | memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr)); | 783 | memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); |
827 | port = ntohs (u6->u6_port); | 784 | port = ntohs (u6->u6_port); |
828 | options = ntohl (u6->options); | 785 | options = ntohl (u6->options); |
829 | sb = &a6; | 786 | sb = &a6; |
830 | sbs = sizeof (a6); | 787 | sbs = sizeof(a6); |
831 | } | 788 | } |
832 | else if (addrlen == sizeof (struct IPv4UdpAddress)) | 789 | else if (addrlen == sizeof(struct IPv4UdpAddress)) |
833 | { | 790 | { |
834 | u4 = addr; | 791 | u4 = addr; |
835 | memset (&a4, 0, sizeof (a4)); | 792 | memset (&a4, 0, sizeof(a4)); |
836 | a4.sin_family = AF_INET; | 793 | a4.sin_family = AF_INET; |
837 | #if HAVE_SOCKADDR_IN_SIN_LEN | 794 | #if HAVE_SOCKADDR_IN_SIN_LEN |
838 | a4.sin_len = sizeof (a4); | 795 | a4.sin_len = sizeof (a4); |
@@ -842,13 +799,13 @@ udp_plugin_address_pretty_printer (void *cls, const char *type, | |||
842 | port = ntohs (u4->u4_port); | 799 | port = ntohs (u4->u4_port); |
843 | options = ntohl (u4->options); | 800 | options = ntohl (u4->options); |
844 | sb = &a4; | 801 | sb = &a4; |
845 | sbs = sizeof (a4); | 802 | sbs = sizeof(a4); |
846 | } | 803 | } |
847 | else | 804 | else |
848 | { | 805 | { |
849 | /* invalid address */ | 806 | /* invalid address */ |
850 | GNUNET_break_op (0); | 807 | GNUNET_break_op(0); |
851 | asc (asc_cls, NULL); | 808 | asc (asc_cls, NULL ); |
852 | return; | 809 | return; |
853 | } | 810 | } |
854 | ppc = GNUNET_new (struct PrettyPrinterContext); | 811 | ppc = GNUNET_new (struct PrettyPrinterContext); |
@@ -856,26 +813,23 @@ udp_plugin_address_pretty_printer (void *cls, const char *type, | |||
856 | ppc->asc_cls = asc_cls; | 813 | ppc->asc_cls = asc_cls; |
857 | ppc->port = port; | 814 | ppc->port = port; |
858 | ppc->options = options; | 815 | ppc->options = options; |
859 | if (addrlen == sizeof (struct IPv6UdpAddress)) | 816 | if (addrlen == sizeof(struct IPv6UdpAddress)) |
860 | ppc->ipv6 = GNUNET_YES; | 817 | ppc->ipv6 = GNUNET_YES; |
861 | else | 818 | else |
862 | ppc->ipv6 = GNUNET_NO; | 819 | ppc->ipv6 = GNUNET_NO; |
863 | ppc->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(timeout, 2), | 820 | ppc->timeout_task = GNUNET_SCHEDULER_add_delayed ( |
864 | &ppc_cancel_task, ppc); | 821 | GNUNET_TIME_relative_multiply (timeout, 2), &ppc_cancel_task, ppc); |
865 | GNUNET_CONTAINER_DLL_insert (ppc_dll_head, ppc_dll_tail, ppc); | 822 | GNUNET_CONTAINER_DLL_insert(ppc_dll_head, ppc_dll_tail, ppc); |
866 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, | 823 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, |
867 | !numeric, | 824 | timeout, &append_port, ppc); |
868 | timeout, | ||
869 | &append_port, ppc); | ||
870 | } | 825 | } |
871 | 826 | ||
872 | |||
873 | static void | 827 | static void |
874 | call_continuation (struct UDP_MessageWrapper *udpw, int result) | 828 | call_continuation (struct UDP_MessageWrapper *udpw, int result) |
875 | { | 829 | { |
876 | size_t overhead; | 830 | size_t overhead; |
877 | 831 | ||
878 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 832 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
879 | "Calling continuation for %u byte message to `%s' with result %s\n", | 833 | "Calling continuation for %u byte message to `%s' with result %s\n", |
880 | udpw->payload_size, GNUNET_i2s (&udpw->session->target), | 834 | udpw->payload_size, GNUNET_i2s (&udpw->session->target), |
881 | (GNUNET_OK == result) ? "OK" : "SYSERR"); | 835 | (GNUNET_OK == result) ? "OK" : "SYSERR"); |
@@ -885,160 +839,148 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
885 | else | 839 | else |
886 | overhead = udpw->msg_size; | 840 | overhead = udpw->msg_size; |
887 | 841 | ||
888 | switch (result) { | 842 | switch (result) |
889 | case GNUNET_OK: | 843 | { |
890 | switch (udpw->msg_type) { | 844 | case GNUNET_OK: |
891 | case MSG_UNFRAGMENTED: | 845 | switch (udpw->msg_type) |
892 | if (NULL != udpw->cont) | 846 | { |
893 | { | 847 | case MSG_UNFRAGMENTED: |
894 | /* Transport continuation */ | 848 | if (NULL != udpw->cont) |
895 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, | 849 | { |
896 | udpw->payload_size, udpw->msg_size); | 850 | /* Transport continuation */ |
897 | } | 851 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, |
898 | GNUNET_STATISTICS_update (plugin->env->stats, | 852 | udpw->payload_size, udpw->msg_size); |
899 | "# UDP, unfragmented msgs, messages, sent, success", | ||
900 | 1, GNUNET_NO); | ||
901 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
902 | "# UDP, unfragmented msgs, bytes payload, sent, success", | ||
903 | udpw->payload_size, GNUNET_NO); | ||
904 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
905 | "# UDP, unfragmented msgs, bytes overhead, sent, success", | ||
906 | overhead, GNUNET_NO); | ||
907 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
908 | "# UDP, total, bytes overhead, sent", | ||
909 | overhead, GNUNET_NO); | ||
910 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
911 | "# UDP, total, bytes payload, sent", | ||
912 | udpw->payload_size, GNUNET_NO); | ||
913 | break; | ||
914 | case MSG_FRAGMENTED_COMPLETE: | ||
915 | GNUNET_assert (NULL != udpw->frag_ctx); | ||
916 | if (udpw->frag_ctx->cont != NULL) | ||
917 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, GNUNET_OK, | ||
918 | udpw->frag_ctx->payload_size, udpw->frag_ctx->on_wire_size); | ||
919 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
920 | "# UDP, fragmented msgs, messages, sent, success", | ||
921 | 1, GNUNET_NO); | ||
922 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
923 | "# UDP, fragmented msgs, bytes payload, sent, success", | ||
924 | udpw->payload_size, GNUNET_NO); | ||
925 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
926 | "# UDP, fragmented msgs, bytes overhead, sent, success", | ||
927 | overhead, GNUNET_NO); | ||
928 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
929 | "# UDP, total, bytes overhead, sent", | ||
930 | overhead, GNUNET_NO); | ||
931 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
932 | "# UDP, total, bytes payload, sent", | ||
933 | udpw->payload_size, GNUNET_NO); | ||
934 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
935 | "# UDP, fragmented msgs, messages, pending", | ||
936 | -1, GNUNET_NO); | ||
937 | break; | ||
938 | case MSG_FRAGMENTED: | ||
939 | /* Fragmented message: enqueue next fragment */ | ||
940 | if (NULL != udpw->cont) | ||
941 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, | ||
942 | udpw->payload_size, udpw->msg_size); | ||
943 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
944 | "# UDP, fragmented msgs, fragments, sent, success", | ||
945 | 1, GNUNET_NO); | ||
946 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
947 | "# UDP, fragmented msgs, fragments bytes, sent, success", | ||
948 | udpw->msg_size, GNUNET_NO); | ||
949 | break; | ||
950 | case MSG_ACK: | ||
951 | /* No continuation */ | ||
952 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
953 | "# UDP, ACK msgs, messages, sent, success", | ||
954 | 1, GNUNET_NO); | ||
955 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
956 | "# UDP, ACK msgs, bytes overhead, sent, success", | ||
957 | overhead, GNUNET_NO); | ||
958 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
959 | "# UDP, total, bytes overhead, sent", | ||
960 | overhead, GNUNET_NO); | ||
961 | break; | ||
962 | case MSG_BEACON: | ||
963 | GNUNET_break (0); | ||
964 | break; | ||
965 | default: | ||
966 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
967 | "ERROR: %u\n", udpw->msg_type); | ||
968 | GNUNET_break (0); | ||
969 | break; | ||
970 | } | 853 | } |
854 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
855 | "# UDP, unfragmented msgs, messages, sent, success", 1, GNUNET_NO); | ||
856 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
857 | "# UDP, unfragmented msgs, bytes payload, sent, success", | ||
858 | udpw->payload_size, GNUNET_NO); | ||
859 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
860 | "# UDP, unfragmented msgs, bytes overhead, sent, success", overhead, | ||
861 | GNUNET_NO); | ||
862 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
863 | "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); | ||
864 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
865 | "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO); | ||
971 | break; | 866 | break; |
972 | case GNUNET_SYSERR: | 867 | case MSG_FRAGMENTED_COMPLETE: |
973 | switch (udpw->msg_type) { | 868 | GNUNET_assert(NULL != udpw->frag_ctx); |
974 | case MSG_UNFRAGMENTED: | 869 | if (udpw->frag_ctx->cont != NULL ) |
975 | /* Unfragmented message: failed to send */ | 870 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, |
976 | if (NULL != udpw->cont) | 871 | GNUNET_OK, udpw->frag_ctx->payload_size, |
977 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, | 872 | udpw->frag_ctx->on_wire_size); |
978 | udpw->payload_size, overhead); | 873 | GNUNET_STATISTICS_update (plugin->env->stats, |
979 | GNUNET_STATISTICS_update (plugin->env->stats, | 874 | "# UDP, fragmented msgs, messages, sent, success", 1, GNUNET_NO); |
980 | "# UDP, unfragmented msgs, messages, sent, failure", | 875 | GNUNET_STATISTICS_update (plugin->env->stats, |
981 | 1, GNUNET_NO); | 876 | "# UDP, fragmented msgs, bytes payload, sent, success", |
982 | GNUNET_STATISTICS_update (plugin->env->stats, | 877 | udpw->payload_size, GNUNET_NO); |
983 | "# UDP, unfragmented msgs, bytes payload, sent, failure", | 878 | GNUNET_STATISTICS_update (plugin->env->stats, |
984 | udpw->payload_size, GNUNET_NO); | 879 | "# UDP, fragmented msgs, bytes overhead, sent, success", overhead, |
985 | GNUNET_STATISTICS_update (plugin->env->stats, | 880 | GNUNET_NO); |
986 | "# UDP, unfragmented msgs, bytes overhead, sent, failure", | 881 | GNUNET_STATISTICS_update (plugin->env->stats, |
987 | overhead, GNUNET_NO); | 882 | "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); |
988 | break; | 883 | GNUNET_STATISTICS_update (plugin->env->stats, |
989 | case MSG_FRAGMENTED_COMPLETE: | 884 | "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO); |
990 | GNUNET_assert (NULL != udpw->frag_ctx); | 885 | GNUNET_STATISTICS_update (plugin->env->stats, |
991 | if (udpw->frag_ctx->cont != NULL) | 886 | "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); |
992 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, GNUNET_SYSERR, | 887 | break; |
993 | udpw->frag_ctx->payload_size, udpw->frag_ctx->on_wire_size); | 888 | case MSG_FRAGMENTED: |
994 | GNUNET_STATISTICS_update (plugin->env->stats, | 889 | /* Fragmented message: enqueue next fragment */ |
995 | "# UDP, fragmented msgs, messages, sent, failure", | 890 | if (NULL != udpw->cont) |
996 | 1, GNUNET_NO); | 891 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, |
997 | GNUNET_STATISTICS_update (plugin->env->stats, | 892 | udpw->payload_size, udpw->msg_size); |
998 | "# UDP, fragmented msgs, bytes payload, sent, failure", | 893 | GNUNET_STATISTICS_update (plugin->env->stats, |
999 | udpw->payload_size, GNUNET_NO); | 894 | "# UDP, fragmented msgs, fragments, sent, success", 1, GNUNET_NO); |
1000 | GNUNET_STATISTICS_update (plugin->env->stats, | 895 | GNUNET_STATISTICS_update (plugin->env->stats, |
1001 | "# UDP, fragmented msgs, bytes payload, sent, failure", | 896 | "# UDP, fragmented msgs, fragments bytes, sent, success", |
1002 | overhead, GNUNET_NO); | 897 | udpw->msg_size, GNUNET_NO); |
1003 | GNUNET_STATISTICS_update (plugin->env->stats, | 898 | break; |
1004 | "# UDP, fragmented msgs, bytes payload, sent, failure", | 899 | case MSG_ACK: |
1005 | overhead, GNUNET_NO); | 900 | /* No continuation */ |
1006 | GNUNET_STATISTICS_update (plugin->env->stats, | 901 | GNUNET_STATISTICS_update (plugin->env->stats, |
1007 | "# UDP, fragmented msgs, messages, pending", | 902 | "# UDP, ACK msgs, messages, sent, success", 1, GNUNET_NO); |
1008 | -1, GNUNET_NO); | 903 | GNUNET_STATISTICS_update (plugin->env->stats, |
1009 | break; | 904 | "# UDP, ACK msgs, bytes overhead, sent, success", overhead, |
1010 | case MSG_FRAGMENTED: | 905 | GNUNET_NO); |
1011 | GNUNET_assert (NULL != udpw->frag_ctx); | 906 | GNUNET_STATISTICS_update (plugin->env->stats, |
1012 | /* Fragmented message: failed to send */ | 907 | "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); |
1013 | GNUNET_STATISTICS_update (plugin->env->stats, | 908 | break; |
1014 | "# UDP, fragmented msgs, fragments, sent, failure", | 909 | case MSG_BEACON: |
1015 | 1, GNUNET_NO); | 910 | GNUNET_break(0); |
1016 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
1017 | "# UDP, fragmented msgs, fragments bytes, sent, failure", | ||
1018 | udpw->msg_size, GNUNET_NO); | ||
1019 | break; | ||
1020 | case MSG_ACK: | ||
1021 | /* ACK message: failed to send */ | ||
1022 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
1023 | "# UDP, ACK msgs, messages, sent, failure", | ||
1024 | 1, GNUNET_NO); | ||
1025 | break; | ||
1026 | case MSG_BEACON: | ||
1027 | /* Beacon message: failed to send */ | ||
1028 | GNUNET_break (0); | ||
1029 | break; | ||
1030 | default: | ||
1031 | GNUNET_break (0); | ||
1032 | break; | ||
1033 | } | ||
1034 | break; | 911 | break; |
1035 | default: | 912 | default: |
1036 | GNUNET_break (0); | 913 | LOG(GNUNET_ERROR_TYPE_ERROR, "ERROR: %u\n", udpw->msg_type); |
914 | GNUNET_break(0); | ||
1037 | break; | 915 | break; |
916 | } | ||
917 | break; | ||
918 | case GNUNET_SYSERR: | ||
919 | switch (udpw->msg_type) | ||
920 | { | ||
921 | case MSG_UNFRAGMENTED: | ||
922 | /* Unfragmented message: failed to send */ | ||
923 | if (NULL != udpw->cont) | ||
924 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, | ||
925 | udpw->payload_size, overhead); | ||
926 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
927 | "# UDP, unfragmented msgs, messages, sent, failure", 1, GNUNET_NO); | ||
928 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
929 | "# UDP, unfragmented msgs, bytes payload, sent, failure", | ||
930 | udpw->payload_size, GNUNET_NO); | ||
931 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
932 | "# UDP, unfragmented msgs, bytes overhead, sent, failure", overhead, | ||
933 | GNUNET_NO); | ||
934 | break; | ||
935 | case MSG_FRAGMENTED_COMPLETE: | ||
936 | GNUNET_assert(NULL != udpw->frag_ctx); | ||
937 | if (udpw->frag_ctx->cont != NULL ) | ||
938 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, | ||
939 | GNUNET_SYSERR, udpw->frag_ctx->payload_size, | ||
940 | udpw->frag_ctx->on_wire_size); | ||
941 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
942 | "# UDP, fragmented msgs, messages, sent, failure", 1, GNUNET_NO); | ||
943 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
944 | "# UDP, fragmented msgs, bytes payload, sent, failure", | ||
945 | udpw->payload_size, GNUNET_NO); | ||
946 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
947 | "# UDP, fragmented msgs, bytes payload, sent, failure", overhead, | ||
948 | GNUNET_NO); | ||
949 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
950 | "# UDP, fragmented msgs, bytes payload, sent, failure", overhead, | ||
951 | GNUNET_NO); | ||
952 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
953 | "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); | ||
954 | break; | ||
955 | case MSG_FRAGMENTED: | ||
956 | GNUNET_assert(NULL != udpw->frag_ctx); | ||
957 | /* Fragmented message: failed to send */ | ||
958 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
959 | "# UDP, fragmented msgs, fragments, sent, failure", 1, GNUNET_NO); | ||
960 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
961 | "# UDP, fragmented msgs, fragments bytes, sent, failure", | ||
962 | udpw->msg_size, GNUNET_NO); | ||
963 | break; | ||
964 | case MSG_ACK: | ||
965 | /* ACK message: failed to send */ | ||
966 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
967 | "# UDP, ACK msgs, messages, sent, failure", 1, GNUNET_NO); | ||
968 | break; | ||
969 | case MSG_BEACON: | ||
970 | /* Beacon message: failed to send */ | ||
971 | GNUNET_break(0); | ||
972 | break; | ||
973 | default: | ||
974 | GNUNET_break(0); | ||
975 | break; | ||
976 | } | ||
977 | break; | ||
978 | default: | ||
979 | GNUNET_break(0); | ||
980 | break; | ||
1038 | } | 981 | } |
1039 | } | 982 | } |
1040 | 983 | ||
1041 | |||
1042 | /** | 984 | /** |
1043 | * Check if the given port is plausible (must be either our listen | 985 | * Check if the given port is plausible (must be either our listen |
1044 | * port or our advertised port). If it is neither, we return | 986 | * port or our advertised port). If it is neither, we return |
@@ -1056,7 +998,6 @@ check_port (struct Plugin *plugin, uint16_t in_port) | |||
1056 | return GNUNET_SYSERR; | 998 | return GNUNET_SYSERR; |
1057 | } | 999 | } |
1058 | 1000 | ||
1059 | |||
1060 | /** | 1001 | /** |
1061 | * Function that will be called to check if a binary address for this | 1002 | * Function that will be called to check if a binary address for this |
1062 | * plugin is well-formed and corresponds to an address for THIS peer | 1003 | * plugin is well-formed and corresponds to an address for THIS peer |
@@ -1074,28 +1015,26 @@ check_port (struct Plugin *plugin, uint16_t in_port) | |||
1074 | * | 1015 | * |
1075 | */ | 1016 | */ |
1076 | static int | 1017 | static int |
1077 | udp_plugin_check_address (void *cls, | 1018 | udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) |
1078 | const void *addr, | ||
1079 | size_t addrlen) | ||
1080 | { | 1019 | { |
1081 | struct Plugin *plugin = cls; | 1020 | struct Plugin *plugin = cls; |
1082 | struct IPv4UdpAddress *v4; | 1021 | struct IPv4UdpAddress *v4; |
1083 | struct IPv6UdpAddress *v6; | 1022 | struct IPv6UdpAddress *v6; |
1084 | 1023 | ||
1085 | if ((addrlen != sizeof (struct IPv4UdpAddress)) && | 1024 | if ((addrlen != sizeof(struct IPv4UdpAddress)) |
1086 | (addrlen != sizeof (struct IPv6UdpAddress))) | 1025 | && (addrlen != sizeof(struct IPv6UdpAddress))) |
1087 | { | 1026 | { |
1088 | GNUNET_break_op (0); | 1027 | GNUNET_break_op(0); |
1089 | return GNUNET_SYSERR; | 1028 | return GNUNET_SYSERR; |
1090 | } | 1029 | } |
1091 | if (addrlen == sizeof (struct IPv4UdpAddress)) | 1030 | if (addrlen == sizeof(struct IPv4UdpAddress)) |
1092 | { | 1031 | { |
1093 | v4 = (struct IPv4UdpAddress *) addr; | 1032 | v4 = (struct IPv4UdpAddress *) addr; |
1094 | if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) | 1033 | if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) |
1095 | return GNUNET_SYSERR; | 1034 | return GNUNET_SYSERR; |
1096 | if (GNUNET_OK != | 1035 | if (GNUNET_OK |
1097 | GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, | 1036 | != GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, |
1098 | sizeof (struct in_addr))) | 1037 | sizeof(struct in_addr))) |
1099 | return GNUNET_SYSERR; | 1038 | return GNUNET_SYSERR; |
1100 | } | 1039 | } |
1101 | else | 1040 | else |
@@ -1103,20 +1042,19 @@ udp_plugin_check_address (void *cls, | |||
1103 | v6 = (struct IPv6UdpAddress *) addr; | 1042 | v6 = (struct IPv6UdpAddress *) addr; |
1104 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) | 1043 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) |
1105 | { | 1044 | { |
1106 | GNUNET_break_op (0); | 1045 | GNUNET_break_op(0); |
1107 | return GNUNET_SYSERR; | 1046 | return GNUNET_SYSERR; |
1108 | } | 1047 | } |
1109 | if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port))) | 1048 | if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port))) |
1110 | return GNUNET_SYSERR; | 1049 | return GNUNET_SYSERR; |
1111 | if (GNUNET_OK != | 1050 | if (GNUNET_OK |
1112 | GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, | 1051 | != GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, |
1113 | sizeof (struct in6_addr))) | 1052 | sizeof(struct in6_addr))) |
1114 | return GNUNET_SYSERR; | 1053 | return GNUNET_SYSERR; |
1115 | } | 1054 | } |
1116 | return GNUNET_OK; | 1055 | return GNUNET_OK; |
1117 | } | 1056 | } |
1118 | 1057 | ||
1119 | |||
1120 | /** | 1058 | /** |
1121 | * Function to free last resources associated with a session. | 1059 | * Function to free last resources associated with a session. |
1122 | * | 1060 | * |
@@ -1127,39 +1065,35 @@ free_session (struct Session *s) | |||
1127 | { | 1065 | { |
1128 | if (NULL != s->frag_ctx) | 1066 | if (NULL != s->frag_ctx) |
1129 | { | 1067 | { |
1130 | GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL); | 1068 | GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL ); |
1131 | GNUNET_free (s->frag_ctx); | 1069 | GNUNET_free(s->frag_ctx); |
1132 | s->frag_ctx = NULL; | 1070 | s->frag_ctx = NULL; |
1133 | } | 1071 | } |
1134 | GNUNET_free (s); | 1072 | GNUNET_free(s); |
1135 | } | 1073 | } |
1136 | 1074 | ||
1137 | |||
1138 | static void | 1075 | static void |
1139 | dequeue (struct Plugin *plugin, | 1076 | dequeue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) |
1140 | struct UDP_MessageWrapper * udpw) | ||
1141 | { | 1077 | { |
1142 | if (plugin->bytes_in_buffer < udpw->msg_size) | 1078 | if (plugin->bytes_in_buffer < udpw->msg_size) |
1143 | GNUNET_break (0); | 1079 | GNUNET_break(0); |
1144 | else | 1080 | else |
1145 | { | 1081 | { |
1146 | GNUNET_STATISTICS_update (plugin->env->stats, | 1082 | GNUNET_STATISTICS_update (plugin->env->stats, |
1147 | "# UDP, total, bytes in buffers", | 1083 | "# UDP, total, bytes in buffers", -(long long) udpw->msg_size, |
1148 | - (long long) udpw->msg_size, GNUNET_NO); | 1084 | GNUNET_NO); |
1149 | plugin->bytes_in_buffer -= udpw->msg_size; | 1085 | plugin->bytes_in_buffer -= udpw->msg_size; |
1150 | } | 1086 | } |
1151 | GNUNET_STATISTICS_update (plugin->env->stats, | 1087 | GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, msgs in buffers", |
1152 | "# UDP, total, msgs in buffers", | 1088 | -1, GNUNET_NO); |
1153 | -1, GNUNET_NO); | 1089 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in)) |
1154 | if (udpw->session->addrlen == sizeof (struct sockaddr_in)) | 1090 | GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, |
1155 | GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head, | 1091 | plugin->ipv4_queue_tail, udpw); |
1156 | plugin->ipv4_queue_tail, udpw); | 1092 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in6)) |
1157 | if (udpw->session->addrlen == sizeof (struct sockaddr_in6)) | 1093 | GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, |
1158 | GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head, | 1094 | plugin->ipv6_queue_tail, udpw); |
1159 | plugin->ipv6_queue_tail, udpw); | ||
1160 | } | 1095 | } |
1161 | 1096 | ||
1162 | |||
1163 | static void | 1097 | static void |
1164 | fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | 1098 | fragmented_message_done (struct UDP_FragmentationContext *fc, int result) |
1165 | { | 1099 | { |
@@ -1168,13 +1102,12 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | |||
1168 | struct UDP_MessageWrapper dummy; | 1102 | struct UDP_MessageWrapper dummy; |
1169 | struct Session *s = fc->session; | 1103 | struct Session *s = fc->session; |
1170 | 1104 | ||
1171 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1105 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1172 | "%p : Fragmented message removed with result %s\n", | 1106 | "%p : Fragmented message removed with result %s\n", fc, |
1173 | fc, | 1107 | (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); |
1174 | (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); | ||
1175 | 1108 | ||
1176 | /* Call continuation for fragmented message */ | 1109 | /* Call continuation for fragmented message */ |
1177 | memset (&dummy, 0, sizeof (dummy)); | 1110 | memset (&dummy, 0, sizeof(dummy)); |
1178 | dummy.msg_type = MSG_FRAGMENTED_COMPLETE; | 1111 | dummy.msg_type = MSG_FRAGMENTED_COMPLETE; |
1179 | dummy.msg_size = s->frag_ctx->on_wire_size; | 1112 | dummy.msg_size = s->frag_ctx->on_wire_size; |
1180 | dummy.payload_size = s->frag_ctx->payload_size; | 1113 | dummy.payload_size = s->frag_ctx->payload_size; |
@@ -1186,46 +1119,43 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | |||
1186 | call_continuation (&dummy, result); | 1119 | call_continuation (&dummy, result); |
1187 | 1120 | ||
1188 | /* Remove leftover fragments from queue */ | 1121 | /* Remove leftover fragments from queue */ |
1189 | if (s->addrlen == sizeof (struct sockaddr_in6)) | 1122 | if (s->address->address_length == sizeof(struct sockaddr_in6)) |
1190 | { | 1123 | { |
1191 | udpw = plugin->ipv6_queue_head; | 1124 | udpw = plugin->ipv6_queue_head; |
1192 | while (NULL != udpw) | 1125 | while (NULL != udpw) |
1193 | { | 1126 | { |
1194 | tmp = udpw->next; | 1127 | tmp = udpw->next; |
1195 | if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx)) | 1128 | if ((udpw->frag_ctx != NULL )&& (udpw->frag_ctx == s->frag_ctx)){ |
1196 | { | 1129 | dequeue (plugin, udpw); |
1197 | dequeue (plugin, udpw); | 1130 | call_continuation (udpw, GNUNET_SYSERR); |
1198 | call_continuation (udpw, GNUNET_SYSERR); | 1131 | GNUNET_free (udpw); |
1199 | GNUNET_free (udpw); | 1132 | } |
1200 | } | ||
1201 | udpw = tmp; | 1133 | udpw = tmp; |
1202 | } | 1134 | } |
1203 | } | 1135 | } |
1204 | if (s->addrlen == sizeof (struct sockaddr_in)) | 1136 | if (s->address->address_length == sizeof(struct sockaddr_in)) |
1205 | { | 1137 | { |
1206 | udpw = plugin->ipv4_queue_head; | 1138 | udpw = plugin->ipv4_queue_head; |
1207 | while (udpw!= NULL) | 1139 | while (udpw != NULL ) |
1208 | { | 1140 | { |
1209 | tmp = udpw->next; | 1141 | tmp = udpw->next; |
1210 | if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == s->frag_ctx)) | 1142 | if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == s->frag_ctx)) |
1211 | { | 1143 | { |
1212 | dequeue (plugin, udpw); | 1144 | dequeue (plugin, udpw); |
1213 | call_continuation (udpw, GNUNET_SYSERR); | 1145 | call_continuation (udpw, GNUNET_SYSERR); |
1214 | GNUNET_free (udpw); | 1146 | GNUNET_free(udpw); |
1215 | } | 1147 | } |
1216 | udpw = tmp; | 1148 | udpw = tmp; |
1217 | } | 1149 | } |
1218 | } | 1150 | } |
1219 | 1151 | ||
1220 | /* Destroy fragmentation context */ | 1152 | /* Destroy fragmentation context */ |
1221 | GNUNET_FRAGMENT_context_destroy (fc->frag, | 1153 | GNUNET_FRAGMENT_context_destroy (fc->frag, &s->last_expected_msg_delay, |
1222 | &s->last_expected_msg_delay, | 1154 | &s->last_expected_ack_delay); |
1223 | &s->last_expected_ack_delay); | ||
1224 | s->frag_ctx = NULL; | 1155 | s->frag_ctx = NULL; |
1225 | GNUNET_free (fc); | 1156 | GNUNET_free(fc); |
1226 | } | 1157 | } |
1227 | 1158 | ||
1228 | |||
1229 | /** | 1159 | /** |
1230 | * Functions with this signature are called whenever we need | 1160 | * Functions with this signature are called whenever we need |
1231 | * to close a session due to a disconnect or failure to | 1161 | * to close a session due to a disconnect or failure to |
@@ -1236,19 +1166,16 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | |||
1236 | * @return #GNUNET_OK on success | 1166 | * @return #GNUNET_OK on success |
1237 | */ | 1167 | */ |
1238 | static int | 1168 | static int |
1239 | udp_disconnect_session (void *cls, | 1169 | udp_disconnect_session (void *cls, struct Session *s) |
1240 | struct Session *s) | ||
1241 | { | 1170 | { |
1242 | struct Plugin *plugin = cls; | 1171 | struct Plugin *plugin = cls; |
1243 | struct UDP_MessageWrapper *udpw; | 1172 | struct UDP_MessageWrapper *udpw; |
1244 | struct UDP_MessageWrapper *next; | 1173 | struct UDP_MessageWrapper *next; |
1245 | 1174 | ||
1246 | GNUNET_assert (GNUNET_YES != s->in_destroy); | 1175 | GNUNET_assert(GNUNET_YES != s->in_destroy); |
1247 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1176 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Session %p to peer `%s' address ended\n", s, |
1248 | "Session %p to peer `%s' address ended\n", | 1177 | GNUNET_i2s (&s->target), |
1249 | s, | 1178 | GNUNET_a2s (s->address->address, s->address->address_length)); |
1250 | GNUNET_i2s (&s->target), | ||
1251 | GNUNET_a2s (s->sock_addr, s->addrlen)); | ||
1252 | /* stop timeout task */ | 1179 | /* stop timeout task */ |
1253 | if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task) | 1180 | if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task) |
1254 | { | 1181 | { |
@@ -1269,7 +1196,7 @@ udp_disconnect_session (void *cls, | |||
1269 | { | 1196 | { |
1270 | dequeue (plugin, udpw); | 1197 | dequeue (plugin, udpw); |
1271 | call_continuation (udpw, GNUNET_SYSERR); | 1198 | call_continuation (udpw, GNUNET_SYSERR); |
1272 | GNUNET_free (udpw); | 1199 | GNUNET_free(udpw); |
1273 | } | 1200 | } |
1274 | } | 1201 | } |
1275 | next = plugin->ipv6_queue_head; | 1202 | next = plugin->ipv6_queue_head; |
@@ -1280,7 +1207,7 @@ udp_disconnect_session (void *cls, | |||
1280 | { | 1207 | { |
1281 | dequeue (plugin, udpw); | 1208 | dequeue (plugin, udpw); |
1282 | call_continuation (udpw, GNUNET_SYSERR); | 1209 | call_continuation (udpw, GNUNET_SYSERR); |
1283 | GNUNET_free (udpw); | 1210 | GNUNET_free(udpw); |
1284 | } | 1211 | } |
1285 | } | 1212 | } |
1286 | plugin->env->session_end (plugin->env->cls, &s->target, s); | 1213 | plugin->env->session_end (plugin->env->cls, &s->target, s); |
@@ -1290,29 +1217,27 @@ udp_disconnect_session (void *cls, | |||
1290 | if (NULL != s->frag_ctx->cont) | 1217 | if (NULL != s->frag_ctx->cont) |
1291 | { | 1218 | { |
1292 | s->frag_ctx->cont (s->frag_ctx->cont_cls, &s->target, GNUNET_SYSERR, | 1219 | s->frag_ctx->cont (s->frag_ctx->cont_cls, &s->target, GNUNET_SYSERR, |
1293 | s->frag_ctx->payload_size, s->frag_ctx->on_wire_size); | 1220 | s->frag_ctx->payload_size, s->frag_ctx->on_wire_size); |
1294 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1221 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1295 | "Calling continuation for fragemented message to `%s' with result SYSERR\n", | 1222 | "Calling continuation for fragemented message to `%s' with result SYSERR\n", |
1296 | GNUNET_i2s (&s->target)); | 1223 | GNUNET_i2s (&s->target)); |
1297 | } | 1224 | } |
1298 | } | 1225 | } |
1299 | 1226 | ||
1300 | GNUNET_assert (GNUNET_YES == | 1227 | GNUNET_assert( |
1301 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, | 1228 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s)); |
1302 | &s->target, | 1229 | GNUNET_STATISTICS_set (plugin->env->stats, "# UDP, sessions active", |
1303 | s)); | 1230 | GNUNET_CONTAINER_multipeermap_size (plugin->sessions), GNUNET_NO); |
1304 | GNUNET_STATISTICS_set (plugin->env->stats, | ||
1305 | "# UDP, sessions active", | ||
1306 | GNUNET_CONTAINER_multipeermap_size(plugin->sessions), | ||
1307 | GNUNET_NO); | ||
1308 | if (s->rc > 0) | 1231 | if (s->rc > 0) |
1309 | s->in_destroy = GNUNET_YES; | 1232 | s->in_destroy = GNUNET_YES; |
1310 | else | 1233 | else |
1234 | { | ||
1235 | GNUNET_HELLO_address_free (s->address); | ||
1311 | free_session (s); | 1236 | free_session (s); |
1237 | } | ||
1312 | return GNUNET_OK; | 1238 | return GNUNET_OK; |
1313 | } | 1239 | } |
1314 | 1240 | ||
1315 | |||
1316 | /** | 1241 | /** |
1317 | * Function that is called to get the keepalive factor. | 1242 | * Function that is called to get the keepalive factor. |
1318 | * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to | 1243 | * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to |
@@ -1327,7 +1252,6 @@ udp_query_keepalive_factor (void *cls) | |||
1327 | return 15; | 1252 | return 15; |
1328 | } | 1253 | } |
1329 | 1254 | ||
1330 | |||
1331 | /** | 1255 | /** |
1332 | * Destroy a session, plugin is being unloaded. | 1256 | * Destroy a session, plugin is being unloaded. |
1333 | * | 1257 | * |
@@ -1337,9 +1261,8 @@ udp_query_keepalive_factor (void *cls) | |||
1337 | * @return #GNUNET_OK (continue to iterate) | 1261 | * @return #GNUNET_OK (continue to iterate) |
1338 | */ | 1262 | */ |
1339 | static int | 1263 | static int |
1340 | disconnect_and_free_it (void *cls, | 1264 | disconnect_and_free_it (void *cls, const struct GNUNET_PeerIdentity *key, |
1341 | const struct GNUNET_PeerIdentity *key, | 1265 | void *value) |
1342 | void *value) | ||
1343 | { | 1266 | { |
1344 | struct Plugin *plugin = cls; | 1267 | struct Plugin *plugin = cls; |
1345 | 1268 | ||
@@ -1347,7 +1270,6 @@ disconnect_and_free_it (void *cls, | |||
1347 | return GNUNET_OK; | 1270 | return GNUNET_OK; |
1348 | } | 1271 | } |
1349 | 1272 | ||
1350 | |||
1351 | /** | 1273 | /** |
1352 | * Disconnect from a remote node. Clean up session if we have one for | 1274 | * Disconnect from a remote node. Clean up session if we have one for |
1353 | * this peer. | 1275 | * this peer. |
@@ -1357,20 +1279,17 @@ disconnect_and_free_it (void *cls, | |||
1357 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed | 1279 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed |
1358 | */ | 1280 | */ |
1359 | static void | 1281 | static void |
1360 | udp_disconnect (void *cls, | 1282 | udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) |
1361 | const struct GNUNET_PeerIdentity *target) | ||
1362 | { | 1283 | { |
1363 | struct Plugin *plugin = cls; | 1284 | struct Plugin *plugin = cls; |
1364 | 1285 | ||
1365 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1286 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer `%s'\n", |
1366 | "Disconnecting from peer `%s'\n", | 1287 | GNUNET_i2s (target)); |
1367 | GNUNET_i2s (target)); | ||
1368 | /* Clean up sessions */ | 1288 | /* Clean up sessions */ |
1369 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, | 1289 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, |
1370 | &disconnect_and_free_it, plugin); | 1290 | &disconnect_and_free_it, plugin); |
1371 | } | 1291 | } |
1372 | 1292 | ||
1373 | |||
1374 | /** | 1293 | /** |
1375 | * Session was idle, so disconnect it | 1294 | * Session was idle, so disconnect it |
1376 | * | 1295 | * |
@@ -1378,23 +1297,18 @@ udp_disconnect (void *cls, | |||
1378 | * @param tc scheduler context | 1297 | * @param tc scheduler context |
1379 | */ | 1298 | */ |
1380 | static void | 1299 | static void |
1381 | session_timeout (void *cls, | 1300 | session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1382 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1383 | { | 1301 | { |
1384 | struct Session *s = cls; | 1302 | struct Session *s = cls; |
1385 | 1303 | ||
1386 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1304 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1305 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1388 | "Session %p was idle for %s, disconnecting\n", | 1306 | "Session %p was idle for %s, disconnecting\n", s, |
1389 | s, | 1307 | GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, GNUNET_YES)); |
1390 | GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, | ||
1391 | GNUNET_YES)); | ||
1392 | /* call session destroy function */ | 1308 | /* call session destroy function */ |
1393 | udp_disconnect_session (s->plugin, | 1309 | udp_disconnect_session (s->plugin, s); |
1394 | s); | ||
1395 | } | 1310 | } |
1396 | 1311 | ||
1397 | |||
1398 | /** | 1312 | /** |
1399 | * Increment session timeout due to activity | 1313 | * Increment session timeout due to activity |
1400 | * | 1314 | * |
@@ -1405,155 +1319,51 @@ reschedule_session_timeout (struct Session *s) | |||
1405 | { | 1319 | { |
1406 | if (GNUNET_YES == s->in_destroy) | 1320 | if (GNUNET_YES == s->in_destroy) |
1407 | return; | 1321 | return; |
1408 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); | 1322 | GNUNET_assert(GNUNET_SCHEDULER_NO_TASK != s->timeout_task); |
1409 | GNUNET_SCHEDULER_cancel (s->timeout_task); | 1323 | GNUNET_SCHEDULER_cancel (s->timeout_task); |
1410 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, | 1324 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, |
1411 | &session_timeout, | 1325 | &session_timeout, s); |
1412 | s); | 1326 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Timeout restarted for session %p\n", s); |
1413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1414 | "Timeout restarted for session %p\n", | ||
1415 | s); | ||
1416 | } | 1327 | } |
1417 | 1328 | ||
1418 | |||
1419 | static struct Session * | 1329 | static struct Session * |
1420 | create_session (struct Plugin *plugin, | 1330 | create_session (struct Plugin *plugin, |
1421 | const struct GNUNET_PeerIdentity *target, | 1331 | const struct GNUNET_HELLO_Address *address) |
1422 | const void *addr, size_t addrlen, | ||
1423 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | ||
1424 | { | 1332 | { |
1425 | struct Session *s; | 1333 | struct Session *s; |
1426 | const struct IPv4UdpAddress *t4; | ||
1427 | const struct IPv6UdpAddress *t6; | ||
1428 | struct sockaddr_in *v4; | ||
1429 | struct sockaddr_in6 *v6; | ||
1430 | size_t len; | ||
1431 | |||
1432 | if (NULL == addr) | ||
1433 | { | ||
1434 | GNUNET_break (0); | ||
1435 | return NULL; | ||
1436 | } | ||
1437 | 1334 | ||
1438 | switch (addrlen) | 1335 | s = GNUNET_new (struct Session); |
1439 | { | 1336 | s->address = GNUNET_HELLO_address_copy (address); |
1440 | case sizeof (struct IPv4UdpAddress): | 1337 | s->target = address->peer; |
1441 | if (NULL == plugin->sockv4) | 1338 | s->last_expected_ack_delay = GNUNET_TIME_relative_multiply ( |
1442 | { | 1339 | GNUNET_TIME_UNIT_MILLISECONDS, 250); |
1443 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1444 | "Could not create session for peer `%s' address `%s': IPv4 is not enabled\n", | ||
1445 | GNUNET_i2s(target), | ||
1446 | udp_address_to_string (NULL, addr, addrlen)); | ||
1447 | return NULL; | ||
1448 | } | ||
1449 | t4 = addr; | ||
1450 | s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in)); | ||
1451 | s->plugin = plugin; | ||
1452 | len = sizeof (struct sockaddr_in); | ||
1453 | v4 = (struct sockaddr_in *) &s[1]; | ||
1454 | v4->sin_family = AF_INET; | ||
1455 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1456 | v4->sin_len = sizeof (struct sockaddr_in); | ||
1457 | #endif | ||
1458 | v4->sin_port = t4->u4_port; | ||
1459 | v4->sin_addr.s_addr = t4->ipv4_addr; | ||
1460 | s->ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) v4, sizeof (struct sockaddr_in)); | ||
1461 | break; | ||
1462 | case sizeof (struct IPv6UdpAddress): | ||
1463 | if (NULL == plugin->sockv6) | ||
1464 | { | ||
1465 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1466 | "Could not create session for peer `%s' address `%s': IPv6 is not enabled\n", | ||
1467 | GNUNET_i2s(target), | ||
1468 | udp_address_to_string(NULL, addr, addrlen)); | ||
1469 | return NULL; | ||
1470 | } | ||
1471 | t6 = addr; | ||
1472 | s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6)); | ||
1473 | s->plugin = plugin; | ||
1474 | len = sizeof (struct sockaddr_in6); | ||
1475 | v6 = (struct sockaddr_in6 *) &s[1]; | ||
1476 | v6->sin6_family = AF_INET6; | ||
1477 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1478 | v6->sin6_len = sizeof (struct sockaddr_in6); | ||
1479 | #endif | ||
1480 | v6->sin6_port = t6->u6_port; | ||
1481 | v6->sin6_addr = t6->ipv6_addr; | ||
1482 | s->ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) v6, sizeof (struct sockaddr_in6)); | ||
1483 | break; | ||
1484 | default: | ||
1485 | /* Must have a valid address to send to */ | ||
1486 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
1487 | gettext_noop | ||
1488 | ("# requests to create session with invalid address"), | ||
1489 | 1, GNUNET_NO); | ||
1490 | return NULL; | ||
1491 | } | ||
1492 | s->addrlen = len; | ||
1493 | s->target = *target; | ||
1494 | s->sock_addr = (const struct sockaddr *) &s[1]; | ||
1495 | s->last_expected_ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250); | ||
1496 | s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; | 1340 | s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; |
1497 | s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS; | 1341 | s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS; |
1498 | s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; | 1342 | s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; |
1499 | s->inbound = GNUNET_NO; | 1343 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, |
1500 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, | 1344 | &session_timeout, s); |
1501 | &session_timeout, | ||
1502 | s); | ||
1503 | return s; | 1345 | return s; |
1504 | } | 1346 | } |
1505 | 1347 | ||
1506 | |||
1507 | static int | 1348 | static int |
1508 | session_cmp_it (void *cls, | 1349 | session_cmp_it (void *cls, const struct GNUNET_PeerIdentity * key, void *value) |
1509 | const struct GNUNET_PeerIdentity * key, | ||
1510 | void *value) | ||
1511 | { | 1350 | { |
1512 | struct SessionCompareContext * cctx = cls; | 1351 | struct SessionCompareContext * cctx = cls; |
1513 | const struct GNUNET_HELLO_Address *address = cctx->addr; | 1352 | const struct GNUNET_HELLO_Address *address = cctx->address; |
1514 | struct Session *s = value; | 1353 | struct Session *s = value; |
1515 | socklen_t s_addrlen = s->addrlen; | ||
1516 | |||
1517 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1518 | "Comparing address %s <-> %s\n", | ||
1519 | udp_address_to_string (NULL, (void *) address->address, | ||
1520 | address->address_length), | ||
1521 | GNUNET_a2s (s->sock_addr, s->addrlen)); | ||
1522 | if (s->inbound != cctx->inbound) | ||
1523 | return GNUNET_YES; | ||
1524 | if ((address->address_length == sizeof (struct IPv4UdpAddress)) && | ||
1525 | (s_addrlen == sizeof (struct sockaddr_in))) | ||
1526 | { | ||
1527 | struct IPv4UdpAddress * u4 = NULL; | ||
1528 | u4 = (struct IPv4UdpAddress *) address->address; | ||
1529 | GNUNET_assert (NULL != u4); | ||
1530 | const struct sockaddr_in *s4 = (const struct sockaddr_in *) s->sock_addr; | ||
1531 | if ((0 == memcmp ((const void *) &u4->ipv4_addr,(const void *) &s4->sin_addr, sizeof (struct in_addr))) && | ||
1532 | (u4->u4_port == s4->sin_port)) | ||
1533 | { | ||
1534 | cctx->res = s; | ||
1535 | return GNUNET_NO; | ||
1536 | } | ||
1537 | 1354 | ||
1538 | } | 1355 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Comparing address %s <-> %s\n", |
1539 | if ((address->address_length == sizeof (struct IPv6UdpAddress)) && | 1356 | udp_address_to_string (NULL, (void *) address->address, address->address_length), |
1540 | (s_addrlen == sizeof (struct sockaddr_in6))) | 1357 | udp_address_to_string (NULL, s->address->address, s->address->address_length)); |
1358 | |||
1359 | if (0 == GNUNET_HELLO_address_cmp(s->address, cctx->address)) | ||
1541 | { | 1360 | { |
1542 | struct IPv6UdpAddress * u6 = NULL; | 1361 | cctx->res = s; |
1543 | u6 = (struct IPv6UdpAddress *) address->address; | 1362 | return GNUNET_NO; |
1544 | GNUNET_assert (NULL != u6); | ||
1545 | const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) s->sock_addr; | ||
1546 | if ((0 == memcmp (&u6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr))) && | ||
1547 | (u6->u6_port == s6->sin6_port)) | ||
1548 | { | ||
1549 | cctx->res = s; | ||
1550 | return GNUNET_NO; | ||
1551 | } | ||
1552 | } | 1363 | } |
1553 | return GNUNET_YES; | 1364 | return GNUNET_YES; |
1554 | } | 1365 | } |
1555 | 1366 | ||
1556 | |||
1557 | /** | 1367 | /** |
1558 | * Function obtain the network type for a session | 1368 | * Function obtain the network type for a session |
1559 | * | 1369 | * |
@@ -1562,13 +1372,11 @@ session_cmp_it (void *cls, | |||
1562 | * @return the network type | 1372 | * @return the network type |
1563 | */ | 1373 | */ |
1564 | static enum GNUNET_ATS_Network_Type | 1374 | static enum GNUNET_ATS_Network_Type |
1565 | udp_get_network (void *cls, | 1375 | udp_get_network (void *cls, struct Session *session) |
1566 | struct Session *session) | ||
1567 | { | 1376 | { |
1568 | return ntohl (session->ats.value); | 1377 | return ntohl (session->ats.value); |
1569 | } | 1378 | } |
1570 | 1379 | ||
1571 | |||
1572 | /** | 1380 | /** |
1573 | * Creates a new outbound session the transport service will use to | 1381 | * Creates a new outbound session the transport service will use to |
1574 | * send data to the peer | 1382 | * send data to the peer |
@@ -1580,107 +1388,130 @@ udp_get_network (void *cls, | |||
1580 | */ | 1388 | */ |
1581 | static struct Session * | 1389 | static struct Session * |
1582 | udp_plugin_lookup_session (void *cls, | 1390 | udp_plugin_lookup_session (void *cls, |
1583 | const struct GNUNET_HELLO_Address *address, | 1391 | const struct GNUNET_HELLO_Address *address) |
1584 | int inbound) | ||
1585 | { | 1392 | { |
1586 | struct Plugin * plugin = cls; | 1393 | struct Plugin * plugin = cls; |
1587 | struct IPv6UdpAddress * udp_a6; | 1394 | struct IPv6UdpAddress * udp_a6; |
1588 | struct IPv4UdpAddress * udp_a4; | 1395 | struct IPv4UdpAddress * udp_a4; |
1589 | 1396 | ||
1590 | GNUNET_assert (plugin != NULL); | 1397 | GNUNET_assert(plugin != NULL); |
1591 | GNUNET_assert (address != NULL); | 1398 | GNUNET_assert(address != NULL); |
1592 | 1399 | ||
1593 | 1400 | if ((address->address == NULL )|| | |
1594 | if ((address->address == NULL) || | 1401 | ((address->address_length != sizeof (struct IPv4UdpAddress)) && |
1595 | ((address->address_length != sizeof (struct IPv4UdpAddress)) && | 1402 | (address->address_length != sizeof (struct IPv6UdpAddress)))){ |
1596 | (address->address_length != sizeof (struct IPv6UdpAddress)))) | 1403 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1597 | { | 1404 | _("Trying to create session for address of unexpected length %u (should be %u or %u)\n"), |
1598 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1405 | address->address_length, |
1599 | _("Trying to create session for address of unexpected length %u (should be %u or %u)\n"), | 1406 | sizeof (struct IPv4UdpAddress), |
1600 | address->address_length, | 1407 | sizeof (struct IPv6UdpAddress)); |
1601 | sizeof (struct IPv4UdpAddress), | 1408 | return NULL; |
1602 | sizeof (struct IPv6UdpAddress)); | 1409 | } |
1603 | return NULL; | ||
1604 | } | ||
1605 | 1410 | ||
1606 | if (address->address_length == sizeof (struct IPv4UdpAddress)) | 1411 | if (address->address_length == sizeof(struct IPv4UdpAddress)) |
1607 | { | 1412 | { |
1608 | if (plugin->sockv4 == NULL) | 1413 | if (plugin->sockv4 == NULL ) |
1609 | return NULL; | 1414 | return NULL ; |
1610 | udp_a4 = (struct IPv4UdpAddress *) address->address; | 1415 | udp_a4 = (struct IPv4UdpAddress *) address->address; |
1611 | if (udp_a4->u4_port == 0) | 1416 | if (udp_a4->u4_port == 0) |
1612 | return NULL; | 1417 | return NULL ; |
1613 | } | 1418 | } |
1614 | 1419 | ||
1615 | if (address->address_length == sizeof (struct IPv6UdpAddress)) | 1420 | if (address->address_length == sizeof(struct IPv6UdpAddress)) |
1616 | { | 1421 | { |
1617 | if (plugin->sockv6 == NULL) | 1422 | if (plugin->sockv6 == NULL ) |
1618 | return NULL; | 1423 | return NULL ; |
1619 | udp_a6 = (struct IPv6UdpAddress *) address->address; | 1424 | udp_a6 = (struct IPv6UdpAddress *) address->address; |
1620 | if (udp_a6->u6_port == 0) | 1425 | if (udp_a6->u6_port == 0) |
1621 | return NULL; | 1426 | return NULL ; |
1622 | } | 1427 | } |
1623 | 1428 | ||
1624 | /* check if session already exists */ | 1429 | /* check if session already exists */ |
1625 | struct SessionCompareContext cctx; | 1430 | struct SessionCompareContext cctx; |
1626 | cctx.addr = address; | 1431 | cctx.address = address; |
1627 | cctx.res = NULL; | 1432 | cctx.res = NULL; |
1628 | cctx.inbound = inbound; | 1433 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1629 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1434 | "Looking for existing session for peer `%s' `%s' \n", |
1630 | "Looking for existing session for peer `%s' `%s' \n", | 1435 | GNUNET_i2s (&address->peer), |
1631 | GNUNET_i2s (&address->peer), | 1436 | udp_address_to_string(NULL, address->address, address->address_length)); |
1632 | udp_address_to_string(NULL, address->address, address->address_length)); | 1437 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, &address->peer, |
1633 | GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, &address->peer, session_cmp_it, &cctx); | 1438 | session_cmp_it, &cctx); |
1634 | if (cctx.res != NULL) | 1439 | if (cctx.res != NULL ) |
1635 | { | 1440 | { |
1636 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); | 1441 | LOG(GNUNET_ERROR_TYPE_ERROR, "Found existing session %p\n", cctx.res); |
1637 | return cctx.res; | 1442 | return cctx.res; |
1638 | } | 1443 | } |
1639 | return NULL; | 1444 | return NULL ; |
1640 | } | 1445 | } |
1641 | 1446 | ||
1447 | static int | ||
1448 | udp_address_is_inbound (const struct GNUNET_HELLO_Address *address) | ||
1449 | { | ||
1450 | if (GNUNET_HELLO_ADDRESS_INFO_INBOUND == (address->local_info & GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | ||
1451 | return GNUNET_YES; | ||
1452 | else | ||
1453 | return GNUNET_NO; | ||
1454 | } | ||
1642 | 1455 | ||
1643 | static struct Session * | 1456 | static struct Session * |
1644 | udp_plugin_create_session (void *cls, | 1457 | udp_plugin_create_session (void *cls, |
1645 | const struct GNUNET_HELLO_Address *address, | 1458 | const struct GNUNET_HELLO_Address *address) |
1646 | int inbound) | ||
1647 | { | 1459 | { |
1648 | struct Session *s; | 1460 | struct Session *s; |
1461 | struct IPv4UdpAddress *udp_v4; | ||
1462 | struct IPv6UdpAddress *udp_v6; | ||
1463 | |||
1464 | s = create_session (plugin, address); | ||
1465 | if (sizeof (struct IPv4UdpAddress) == address->address_length) | ||
1466 | { | ||
1467 | struct sockaddr_in v4; | ||
1468 | udp_v4 = (struct IPv4UdpAddress *) address->address; | ||
1469 | memset (&v4, '\0', sizeof (v4)); | ||
1470 | v4.sin_family = AF_INET; | ||
1471 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1472 | v4->sin_len = sizeof (struct sockaddr_in); | ||
1473 | #endif | ||
1474 | v4.sin_port = udp_v4->u4_port; | ||
1475 | v4.sin_addr.s_addr = udp_v4->ipv4_addr; | ||
1476 | s->ats = plugin->env->get_address_type (plugin->env->cls, | ||
1477 | (const struct sockaddr *) &v4, sizeof (v4)); | ||
1478 | } | ||
1479 | else if (sizeof (struct IPv6UdpAddress) == address->address_length) | ||
1480 | { | ||
1481 | struct sockaddr_in6 v6; | ||
1482 | udp_v6 = (struct IPv6UdpAddress *) address->address; | ||
1483 | memset (&v6, '\0', sizeof (v6)); | ||
1484 | v6.sin6_family = AF_INET6; | ||
1485 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1486 | v6->sin_len = sizeof (struct sockaddr_in6); | ||
1487 | #endif | ||
1488 | v6.sin6_port = udp_v6->u6_port; | ||
1489 | v6.sin6_addr = udp_v6->ipv6_addr; | ||
1490 | s->ats = plugin->env->get_address_type (plugin->env->cls, | ||
1491 | (const struct sockaddr *) &v6, sizeof (v6)); | ||
1492 | } | ||
1649 | 1493 | ||
1650 | s = create_session (plugin, | ||
1651 | &address->peer, | ||
1652 | address->address, | ||
1653 | address->address_length, | ||
1654 | NULL, NULL); | ||
1655 | if (NULL == s) | 1494 | if (NULL == s) |
1656 | return NULL; /* protocol not supported or address invalid */ | 1495 | return NULL ; /* protocol not supported or address invalid */ |
1657 | s->inbound = inbound; | 1496 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1658 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1497 | "Creating new %s session %p for peer `%s' address `%s'\n", |
1659 | "Creating new %s session %p for peer `%s' address `%s'\n", | 1498 | (GNUNET_YES == udp_address_is_inbound(address)) ? "inbound" : "outbound", |
1660 | (GNUNET_YES == s->inbound) ? "inbound" : "outbound", | 1499 | s, GNUNET_i2s (&address->peer), |
1661 | s, | 1500 | udp_address_to_string(NULL,address->address,address->address_length)); |
1662 | GNUNET_i2s(&address->peer), | 1501 | GNUNET_assert( |
1663 | udp_address_to_string(NULL,address->address,address->address_length)); | 1502 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->sessions, &s->target, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
1664 | GNUNET_assert (GNUNET_OK == | 1503 | GNUNET_STATISTICS_set (plugin->env->stats, "# UDP, sessions active", |
1665 | GNUNET_CONTAINER_multipeermap_put (plugin->sessions, | 1504 | GNUNET_CONTAINER_multipeermap_size (plugin->sessions), GNUNET_NO); |
1666 | &s->target, | ||
1667 | s, | ||
1668 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
1669 | GNUNET_STATISTICS_set(plugin->env->stats, | ||
1670 | "# UDP, sessions active", | ||
1671 | GNUNET_CONTAINER_multipeermap_size(plugin->sessions), | ||
1672 | GNUNET_NO); | ||
1673 | return s; | 1505 | return s; |
1674 | } | 1506 | } |
1675 | 1507 | ||
1676 | static void | 1508 | static void |
1677 | udp_plugin_update_session_timeout (void *cls, | 1509 | udp_plugin_update_session_timeout (void *cls, |
1678 | const struct GNUNET_PeerIdentity *peer, | 1510 | const struct GNUNET_PeerIdentity *peer, struct Session *session) |
1679 | struct Session *session) | ||
1680 | { | 1511 | { |
1681 | if (GNUNET_YES | 1512 | if (GNUNET_YES |
1682 | != GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, | 1513 | != GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, peer, |
1683 | peer, session)) | 1514 | session)) |
1684 | { | 1515 | { |
1685 | GNUNET_break(0); | 1516 | GNUNET_break(0); |
1686 | return; | 1517 | return; |
@@ -1699,52 +1530,46 @@ udp_plugin_update_session_timeout (void *cls, | |||
1699 | * @return the session or NULL of max connections exceeded | 1530 | * @return the session or NULL of max connections exceeded |
1700 | */ | 1531 | */ |
1701 | static struct Session * | 1532 | static struct Session * |
1702 | udp_plugin_get_session (void *cls, | 1533 | udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) |
1703 | const struct GNUNET_HELLO_Address *address) | ||
1704 | { | 1534 | { |
1705 | struct Session *s; | 1535 | struct Session *s; |
1706 | 1536 | ||
1707 | if (NULL == address) | 1537 | if (NULL == address) |
1708 | { | 1538 | { |
1709 | GNUNET_break (0); | 1539 | GNUNET_break(0); |
1710 | return NULL; | 1540 | return NULL ; |
1711 | } | 1541 | } |
1712 | if ((address->address_length != sizeof (struct IPv4UdpAddress)) && | 1542 | if ((address->address_length != sizeof(struct IPv4UdpAddress)) |
1713 | (address->address_length != sizeof (struct IPv6UdpAddress))) | 1543 | && (address->address_length != sizeof(struct IPv6UdpAddress))) |
1714 | return NULL; | 1544 | return NULL ; |
1715 | 1545 | ||
1716 | /* otherwise create new */ | 1546 | /* otherwise create new */ |
1717 | if (NULL != (s = udp_plugin_lookup_session (cls, address, GNUNET_NO))) | 1547 | if (NULL != (s = udp_plugin_lookup_session (cls, address))) |
1718 | return s; | 1548 | return s; |
1719 | return udp_plugin_create_session (cls, address, GNUNET_NO); | 1549 | return udp_plugin_create_session (cls, address); |
1720 | } | 1550 | } |
1721 | 1551 | ||
1722 | |||
1723 | static void | 1552 | static void |
1724 | enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | 1553 | enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) |
1725 | { | 1554 | { |
1726 | if (plugin->bytes_in_buffer + udpw->msg_size > INT64_MAX) | 1555 | if (plugin->bytes_in_buffer + udpw->msg_size > INT64_MAX) |
1727 | GNUNET_break (0); | 1556 | GNUNET_break(0); |
1728 | else | 1557 | else |
1729 | { | 1558 | { |
1730 | GNUNET_STATISTICS_update (plugin->env->stats, | 1559 | GNUNET_STATISTICS_update (plugin->env->stats, |
1731 | "# UDP, total, bytes in buffers", | 1560 | "# UDP, total, bytes in buffers", udpw->msg_size, GNUNET_NO); |
1732 | udpw->msg_size, GNUNET_NO); | ||
1733 | plugin->bytes_in_buffer += udpw->msg_size; | 1561 | plugin->bytes_in_buffer += udpw->msg_size; |
1734 | } | 1562 | } |
1735 | GNUNET_STATISTICS_update (plugin->env->stats, | 1563 | GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, msgs in buffers", |
1736 | "# UDP, total, msgs in buffers", | 1564 | 1, GNUNET_NO); |
1737 | 1, GNUNET_NO); | 1565 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in)) |
1738 | if (udpw->session->addrlen == sizeof (struct sockaddr_in)) | 1566 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, |
1739 | GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head, | 1567 | plugin->ipv4_queue_tail, udpw); |
1740 | plugin->ipv4_queue_tail, udpw); | 1568 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in6)) |
1741 | if (udpw->session->addrlen == sizeof (struct sockaddr_in6)) | 1569 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head, |
1742 | GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head, | 1570 | plugin->ipv6_queue_tail, udpw); |
1743 | plugin->ipv6_queue_tail, udpw); | ||
1744 | } | 1571 | } |
1745 | 1572 | ||
1746 | |||
1747 | |||
1748 | /** | 1573 | /** |
1749 | * Fragment message was transmitted via UDP, let fragmentation know | 1574 | * Fragment message was transmitted via UDP, let fragmentation know |
1750 | * to send the next fragment now. | 1575 | * to send the next fragment now. |
@@ -1756,16 +1581,14 @@ enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | |||
1756 | * @param physical bytes physical sent | 1581 | * @param physical bytes physical sent |
1757 | */ | 1582 | */ |
1758 | static void | 1583 | static void |
1759 | send_next_fragment (void *cls, | 1584 | send_next_fragment (void *cls, const struct GNUNET_PeerIdentity *target, |
1760 | const struct GNUNET_PeerIdentity *target, | 1585 | int result, size_t payload, size_t physical) |
1761 | int result, size_t payload, size_t physical) | ||
1762 | { | 1586 | { |
1763 | struct UDP_MessageWrapper *udpw = cls; | 1587 | struct UDP_MessageWrapper *udpw = cls; |
1764 | 1588 | ||
1765 | GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); | 1589 | GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); |
1766 | } | 1590 | } |
1767 | 1591 | ||
1768 | |||
1769 | /** | 1592 | /** |
1770 | * Function that is called with messages created by the fragmentation | 1593 | * Function that is called with messages created by the fragmentation |
1771 | * module. In the case of the 'proc' callback of the | 1594 | * module. In the case of the 'proc' callback of the |
@@ -1783,9 +1606,8 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1783 | struct UDP_MessageWrapper * udpw; | 1606 | struct UDP_MessageWrapper * udpw; |
1784 | size_t msg_len = ntohs (msg->size); | 1607 | size_t msg_len = ntohs (msg->size); |
1785 | 1608 | ||
1786 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1609 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len); |
1787 | "Enqueuing fragment with %u bytes\n", msg_len); | 1610 | frag_ctx->fragments_used++; |
1788 | frag_ctx->fragments_used ++; | ||
1789 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len); | 1611 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len); |
1790 | udpw->session = frag_ctx->session; | 1612 | udpw->session = frag_ctx->session; |
1791 | udpw->msg_buf = (char *) &udpw[1]; | 1613 | udpw->msg_buf = (char *) &udpw[1]; |
@@ -1801,7 +1623,6 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1801 | schedule_select (plugin); | 1623 | schedule_select (plugin); |
1802 | } | 1624 | } |
1803 | 1625 | ||
1804 | |||
1805 | /** | 1626 | /** |
1806 | * Function that can be used by the transport service to transmit | 1627 | * Function that can be used by the transport service to transmit |
1807 | * a message using the plugin. Note that in the case of a | 1628 | * a message using the plugin. Note that in the case of a |
@@ -1830,42 +1651,38 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1830 | * and does NOT mean that the message was not transmitted (DV) | 1651 | * and does NOT mean that the message was not transmitted (DV) |
1831 | */ | 1652 | */ |
1832 | static ssize_t | 1653 | static ssize_t |
1833 | udp_plugin_send (void *cls, | 1654 | udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, |
1834 | struct Session *s, | 1655 | size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, |
1835 | const char *msgbuf, size_t msgbuf_size, | 1656 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
1836 | unsigned int priority, | ||
1837 | struct GNUNET_TIME_Relative to, | ||
1838 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | ||
1839 | { | 1657 | { |
1840 | struct Plugin *plugin = cls; | 1658 | struct Plugin *plugin = cls; |
1841 | size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage); | 1659 | size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage); |
1842 | struct UDP_FragmentationContext * frag_ctx; | 1660 | struct UDP_FragmentationContext * frag_ctx; |
1843 | struct UDP_MessageWrapper * udpw; | 1661 | struct UDP_MessageWrapper * udpw; |
1844 | struct UDPMessage *udp; | 1662 | struct UDPMessage *udp; |
1845 | char mbuf[udpmlen]; | 1663 | char mbuf[udpmlen]; |
1846 | GNUNET_assert (plugin != NULL); | 1664 | GNUNET_assert(plugin != NULL); |
1847 | GNUNET_assert (s != NULL); | 1665 | GNUNET_assert(s != NULL); |
1848 | 1666 | ||
1849 | if ((s->addrlen == sizeof (struct sockaddr_in6)) && (plugin->sockv6 == NULL)) | 1667 | if ((s->address->address_length == sizeof(struct sockaddr_in6)) && (plugin->sockv6 == NULL )) |
1850 | return GNUNET_SYSERR; | 1668 | return GNUNET_SYSERR; |
1851 | if ((s->addrlen == sizeof (struct sockaddr_in)) && (plugin->sockv4 == NULL)) | 1669 | if ((s->address->address_length == sizeof(struct sockaddr_in)) && (plugin->sockv4 == NULL )) |
1852 | return GNUNET_SYSERR; | 1670 | return GNUNET_SYSERR; |
1853 | if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1671 | if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1854 | { | 1672 | { |
1855 | GNUNET_break (0); | 1673 | GNUNET_break(0); |
1856 | return GNUNET_SYSERR; | 1674 | return GNUNET_SYSERR; |
1857 | } | 1675 | } |
1858 | if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions, &s->target, s)) | 1676 | if (GNUNET_YES |
1677 | != GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, | ||
1678 | &s->target, s)) | ||
1859 | { | 1679 | { |
1860 | GNUNET_break (0); | 1680 | GNUNET_break(0); |
1861 | return GNUNET_SYSERR; | 1681 | return GNUNET_SYSERR; |
1862 | } | 1682 | } |
1863 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1683 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1864 | "UDP transmits %u-byte message to `%s' using address `%s'\n", | 1684 | "UDP transmits %u-byte message to `%s' using address `%s'\n", udpmlen, |
1865 | udpmlen, | 1685 | GNUNET_i2s (&s->target), udp_address_to_string (NULL, s->address->address, s->address->address_length)); |
1866 | GNUNET_i2s (&s->target), | ||
1867 | GNUNET_a2s(s->sock_addr, s->addrlen)); | ||
1868 | |||
1869 | 1686 | ||
1870 | /* Message */ | 1687 | /* Message */ |
1871 | udp = (struct UDPMessage *) mbuf; | 1688 | udp = (struct UDPMessage *) mbuf; |
@@ -1889,26 +1706,25 @@ udp_plugin_send (void *cls, | |||
1889 | udpw->msg_buf = (char *) &udpw[1]; | 1706 | udpw->msg_buf = (char *) &udpw[1]; |
1890 | udpw->msg_size = udpmlen; /* message size with UDP overhead */ | 1707 | udpw->msg_size = udpmlen; /* message size with UDP overhead */ |
1891 | udpw->payload_size = msgbuf_size; /* message size without UDP overhead */ | 1708 | udpw->payload_size = msgbuf_size; /* message size without UDP overhead */ |
1892 | udpw->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); | 1709 | udpw->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to); |
1893 | udpw->cont = cont; | 1710 | udpw->cont = cont; |
1894 | udpw->cont_cls = cont_cls; | 1711 | udpw->cont_cls = cont_cls; |
1895 | udpw->frag_ctx = NULL; | 1712 | udpw->frag_ctx = NULL; |
1896 | udpw->msg_type = MSG_UNFRAGMENTED; | 1713 | udpw->msg_type = MSG_UNFRAGMENTED; |
1897 | memcpy (udpw->msg_buf, udp, sizeof (struct UDPMessage)); | 1714 | memcpy (udpw->msg_buf, udp, sizeof(struct UDPMessage)); |
1898 | memcpy (&udpw->msg_buf[sizeof (struct UDPMessage)], msgbuf, msgbuf_size); | 1715 | memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)], msgbuf, msgbuf_size); |
1899 | enqueue (plugin, udpw); | 1716 | enqueue (plugin, udpw); |
1900 | 1717 | ||
1901 | GNUNET_STATISTICS_update (plugin->env->stats, | 1718 | GNUNET_STATISTICS_update (plugin->env->stats, |
1902 | "# UDP, unfragmented msgs, messages, attempt", | 1719 | "# UDP, unfragmented msgs, messages, attempt", 1, GNUNET_NO); |
1903 | 1, GNUNET_NO); | ||
1904 | GNUNET_STATISTICS_update (plugin->env->stats, | 1720 | GNUNET_STATISTICS_update (plugin->env->stats, |
1905 | "# UDP, unfragmented msgs, bytes payload, attempt", | 1721 | "# UDP, unfragmented msgs, bytes payload, attempt", udpw->payload_size, |
1906 | udpw->payload_size, GNUNET_NO); | 1722 | GNUNET_NO); |
1907 | } | 1723 | } |
1908 | else | 1724 | else |
1909 | { | 1725 | { |
1910 | /* fragmented message */ | 1726 | /* fragmented message */ |
1911 | if (s->frag_ctx != NULL) | 1727 | if (s->frag_ctx != NULL ) |
1912 | return GNUNET_SYSERR; | 1728 | return GNUNET_SYSERR; |
1913 | memcpy (&udp[1], msgbuf, msgbuf_size); | 1729 | memcpy (&udp[1], msgbuf, msgbuf_size); |
1914 | frag_ctx = GNUNET_new (struct UDP_FragmentationContext); | 1730 | frag_ctx = GNUNET_new (struct UDP_FragmentationContext); |
@@ -1916,93 +1732,87 @@ udp_plugin_send (void *cls, | |||
1916 | frag_ctx->session = s; | 1732 | frag_ctx->session = s; |
1917 | frag_ctx->cont = cont; | 1733 | frag_ctx->cont = cont; |
1918 | frag_ctx->cont_cls = cont_cls; | 1734 | frag_ctx->cont_cls = cont_cls; |
1919 | frag_ctx->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); | 1735 | frag_ctx->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), |
1736 | to); | ||
1920 | frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */ | 1737 | frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */ |
1921 | frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ | 1738 | frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ |
1922 | frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, | 1739 | frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, |
1923 | UDP_MTU, | 1740 | UDP_MTU, &plugin->tracker, s->last_expected_msg_delay, |
1924 | &plugin->tracker, | 1741 | s->last_expected_ack_delay, &udp->header, &enqueue_fragment, frag_ctx); |
1925 | s->last_expected_msg_delay, | ||
1926 | s->last_expected_ack_delay, | ||
1927 | &udp->header, | ||
1928 | &enqueue_fragment, | ||
1929 | frag_ctx); | ||
1930 | s->frag_ctx = frag_ctx; | 1742 | s->frag_ctx = frag_ctx; |
1931 | GNUNET_STATISTICS_update (plugin->env->stats, | 1743 | GNUNET_STATISTICS_update (plugin->env->stats, |
1932 | "# UDP, fragmented msgs, messages, pending", | 1744 | "# UDP, fragmented msgs, messages, pending", 1, GNUNET_NO); |
1933 | 1, GNUNET_NO); | ||
1934 | GNUNET_STATISTICS_update (plugin->env->stats, | 1745 | GNUNET_STATISTICS_update (plugin->env->stats, |
1935 | "# UDP, fragmented msgs, messages, attempt", | 1746 | "# UDP, fragmented msgs, messages, attempt", 1, GNUNET_NO); |
1936 | 1, GNUNET_NO); | ||
1937 | GNUNET_STATISTICS_update (plugin->env->stats, | 1747 | GNUNET_STATISTICS_update (plugin->env->stats, |
1938 | "# UDP, fragmented msgs, bytes payload, attempt", | 1748 | "# UDP, fragmented msgs, bytes payload, attempt", |
1939 | frag_ctx->payload_size, GNUNET_NO); | 1749 | frag_ctx->payload_size, GNUNET_NO); |
1940 | } | 1750 | } |
1941 | schedule_select (plugin); | 1751 | schedule_select (plugin); |
1942 | return udpmlen; | 1752 | return udpmlen; |
1943 | } | 1753 | } |
1944 | 1754 | ||
1945 | |||
1946 | /** | 1755 | /** |
1947 | * Our external IP address/port mapping has changed. | 1756 | * Our external IP address/port mapping has changed. |
1948 | * | 1757 | * |
1949 | * @param cls closure, the 'struct LocalAddrList' | 1758 | * @param cls closure, the 'struct LocalAddrList' |
1950 | * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean | 1759 | * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean |
1951 | * the previous (now invalid) one | 1760 | * the previous (now invalid) one |
1952 | * @param addr either the previous or the new public IP address | 1761 | * @param address either the previous or the new public IP address |
1953 | * @param addrlen actual lenght of the address | 1762 | * @param addrlen actual lenght of the address |
1954 | */ | 1763 | */ |
1955 | static void | 1764 | static void |
1956 | udp_nat_port_map_callback (void *cls, int add_remove, | 1765 | udp_nat_port_map_callback (void *cls, int add_remove, |
1957 | const struct sockaddr *addr, socklen_t addrlen) | 1766 | const struct sockaddr *addr, socklen_t addrlen) |
1958 | { | 1767 | { |
1959 | struct Plugin *plugin = cls; | 1768 | struct Plugin *plugin = cls; |
1769 | struct GNUNET_HELLO_Address *address; | ||
1960 | struct IPv4UdpAddress u4; | 1770 | struct IPv4UdpAddress u4; |
1961 | struct IPv6UdpAddress u6; | 1771 | struct IPv6UdpAddress u6; |
1962 | void *arg; | 1772 | void *arg; |
1963 | size_t args; | 1773 | size_t args; |
1964 | 1774 | ||
1965 | LOG (GNUNET_ERROR_TYPE_INFO, | 1775 | LOG(GNUNET_ERROR_TYPE_INFO, "NAT notification to %s address `%s'\n", |
1966 | "NAT notification to %s address `%s'\n", | 1776 | (GNUNET_YES == add_remove) ? "add" : "remove", |
1967 | (GNUNET_YES == add_remove) ? "add" : "remove", | 1777 | GNUNET_a2s (addr, addrlen)); |
1968 | GNUNET_a2s (addr, addrlen)); | ||
1969 | 1778 | ||
1970 | /* convert 'addr' to our internal format */ | 1779 | /* convert 'address' to our internal format */ |
1971 | switch (addr->sa_family) | 1780 | switch (addr->sa_family) |
1972 | { | 1781 | { |
1973 | case AF_INET: | 1782 | case AF_INET: |
1974 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); | 1783 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); |
1975 | memset (&u4, 0, sizeof (u4)); | 1784 | memset (&u4, 0, sizeof(u4)); |
1976 | u4.options = htonl(myoptions); | 1785 | u4.options = htonl (myoptions); |
1977 | u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; | 1786 | u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; |
1978 | u4.u4_port = ((struct sockaddr_in *) addr)->sin_port; | 1787 | u4.u4_port = ((struct sockaddr_in *) addr)->sin_port; |
1979 | if (0 == ((struct sockaddr_in *) addr)->sin_port) | 1788 | if (0 == ((struct sockaddr_in *) addr)->sin_port) |
1980 | return; | 1789 | return; |
1981 | arg = &u4; | 1790 | arg = &u4; |
1982 | args = sizeof (struct IPv4UdpAddress); | 1791 | args = sizeof(struct IPv4UdpAddress); |
1983 | break; | 1792 | break; |
1984 | case AF_INET6: | 1793 | case AF_INET6: |
1985 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); | 1794 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); |
1986 | memset (&u4, 0, sizeof (u4)); | 1795 | memset (&u4, 0, sizeof(u4)); |
1987 | u6.options = htonl(myoptions); | 1796 | u6.options = htonl (myoptions); |
1988 | if (0 == ((struct sockaddr_in6 *) addr)->sin6_port) | 1797 | if (0 == ((struct sockaddr_in6 *) addr)->sin6_port) |
1989 | return; | 1798 | return; |
1990 | memcpy (&u6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, | 1799 | memcpy (&u6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, |
1991 | sizeof (struct in6_addr)); | 1800 | sizeof(struct in6_addr)); |
1992 | u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; | 1801 | u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; |
1993 | arg = &u6; | 1802 | arg = &u6; |
1994 | args = sizeof (struct IPv6UdpAddress); | 1803 | args = sizeof(struct IPv6UdpAddress); |
1995 | break; | 1804 | break; |
1996 | default: | 1805 | default: |
1997 | GNUNET_break (0); | 1806 | GNUNET_break(0); |
1998 | return; | 1807 | return; |
1999 | } | 1808 | } |
2000 | /* modify our published address list */ | 1809 | /* modify our published address list */ |
2001 | plugin->env->notify_address (plugin->env->cls, add_remove, arg, args, "udp"); | 1810 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1811 | PLUGIN_NAME, arg, args, GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
1812 | plugin->env->notify_address (plugin->env->cls, add_remove, address); | ||
1813 | GNUNET_HELLO_address_free (address); | ||
2002 | } | 1814 | } |
2003 | 1815 | ||
2004 | |||
2005 | |||
2006 | /** | 1816 | /** |
2007 | * Message tokenizer has broken up an incomming message. Pass it on | 1817 | * Message tokenizer has broken up an incomming message. Pass it on |
2008 | * to the service. | 1818 | * to the service. |
@@ -2014,37 +1824,26 @@ udp_nat_port_map_callback (void *cls, int add_remove, | |||
2014 | */ | 1824 | */ |
2015 | static int | 1825 | static int |
2016 | process_inbound_tokenized_messages (void *cls, void *client, | 1826 | process_inbound_tokenized_messages (void *cls, void *client, |
2017 | const struct GNUNET_MessageHeader *hdr) | 1827 | const struct GNUNET_MessageHeader *hdr) |
2018 | { | 1828 | { |
2019 | struct Plugin *plugin = cls; | 1829 | struct Plugin *plugin = cls; |
2020 | struct SourceInformation *si = client; | 1830 | struct SourceInformation *si = client; |
2021 | struct GNUNET_TIME_Relative delay; | 1831 | struct GNUNET_TIME_Relative delay; |
2022 | 1832 | ||
2023 | GNUNET_assert (si->session != NULL); | 1833 | GNUNET_assert(si->session != NULL); |
2024 | if (GNUNET_YES == si->session->in_destroy) | 1834 | if (GNUNET_YES == si->session->in_destroy) |
2025 | return GNUNET_OK; | 1835 | return GNUNET_OK; |
2026 | /* setup ATS */ | 1836 | /* setup ATS */ |
2027 | GNUNET_break (ntohl(si->session->ats.value) != GNUNET_ATS_NET_UNSPECIFIED); | 1837 | GNUNET_break(ntohl (si->session->ats.value) != GNUNET_ATS_NET_UNSPECIFIED); |
2028 | reschedule_session_timeout (si->session); | 1838 | reschedule_session_timeout (si->session); |
2029 | delay = plugin->env->receive (plugin->env->cls, | 1839 | delay = plugin->env->receive (plugin->env->cls, si->session->address, si->session, hdr); |
2030 | &si->sender, | ||
2031 | hdr, | ||
2032 | si->session, | ||
2033 | (GNUNET_YES == si->session->inbound) | ||
2034 | ? NULL : si->arg, | ||
2035 | (GNUNET_YES == si->session->inbound) | ||
2036 | ? 0 : si->args); | ||
2037 | plugin->env->update_address_metrics (plugin->env->cls, | 1840 | plugin->env->update_address_metrics (plugin->env->cls, |
2038 | &si->sender, | 1841 | si->session->address, si->session, |
2039 | (GNUNET_YES == si->session->inbound) ? NULL : si->arg, | 1842 | &si->session->ats, 1); |
2040 | (GNUNET_YES == si->session->inbound) ? 0 : si->args, | ||
2041 | si->session, | ||
2042 | &si->session->ats, 1); | ||
2043 | si->session->flow_delay_for_other_peer = delay; | 1843 | si->session->flow_delay_for_other_peer = delay; |
2044 | return GNUNET_OK; | 1844 | return GNUNET_OK; |
2045 | } | 1845 | } |
2046 | 1846 | ||
2047 | |||
2048 | /** | 1847 | /** |
2049 | * We've received a UDP Message. Process it (pass contents to main service). | 1848 | * We've received a UDP Message. Process it (pass contents to main service). |
2050 | * | 1849 | * |
@@ -2055,11 +1854,11 @@ process_inbound_tokenized_messages (void *cls, void *client, | |||
2055 | */ | 1854 | */ |
2056 | static void | 1855 | static void |
2057 | process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | 1856 | process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, |
2058 | const struct sockaddr *sender_addr, | 1857 | const struct sockaddr *sender_addr, socklen_t sender_addr_len) |
2059 | socklen_t sender_addr_len) | ||
2060 | { | 1858 | { |
2061 | struct SourceInformation si; | 1859 | struct SourceInformation si; |
2062 | struct Session * s; | 1860 | struct Session * s; |
1861 | struct GNUNET_HELLO_Address *address; | ||
2063 | struct IPv4UdpAddress u4; | 1862 | struct IPv4UdpAddress u4; |
2064 | struct IPv6UdpAddress u6; | 1863 | struct IPv6UdpAddress u6; |
2065 | const void *arg; | 1864 | const void *arg; |
@@ -2067,13 +1866,13 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | |||
2067 | 1866 | ||
2068 | if (0 != ntohl (msg->reserved)) | 1867 | if (0 != ntohl (msg->reserved)) |
2069 | { | 1868 | { |
2070 | GNUNET_break_op (0); | 1869 | GNUNET_break_op(0); |
2071 | return; | 1870 | return; |
2072 | } | 1871 | } |
2073 | if (ntohs (msg->header.size) < | 1872 | if (ntohs (msg->header.size) |
2074 | sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage)) | 1873 | < sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage)) |
2075 | { | 1874 | { |
2076 | GNUNET_break_op (0); | 1875 | GNUNET_break_op(0); |
2077 | return; | 1876 | return; |
2078 | } | 1877 | } |
2079 | 1878 | ||
@@ -2081,40 +1880,40 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | |||
2081 | switch (sender_addr->sa_family) | 1880 | switch (sender_addr->sa_family) |
2082 | { | 1881 | { |
2083 | case AF_INET: | 1882 | case AF_INET: |
2084 | GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in)); | 1883 | GNUNET_assert(sender_addr_len == sizeof(struct sockaddr_in)); |
2085 | memset (&u4, 0, sizeof (u4)); | 1884 | memset (&u4, 0, sizeof(u4)); |
2086 | u6.options = htonl (0); | 1885 | u6.options = htonl (0); |
2087 | u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr; | 1886 | u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr; |
2088 | u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port; | 1887 | u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port; |
2089 | arg = &u4; | 1888 | arg = &u4; |
2090 | args = sizeof (u4); | 1889 | args = sizeof(u4); |
2091 | break; | 1890 | break; |
2092 | case AF_INET6: | 1891 | case AF_INET6: |
2093 | GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in6)); | 1892 | GNUNET_assert(sender_addr_len == sizeof(struct sockaddr_in6)); |
2094 | memset (&u6, 0, sizeof (u6)); | 1893 | memset (&u6, 0, sizeof(u6)); |
2095 | u6.options = htonl (0); | 1894 | u6.options = htonl (0); |
2096 | u6.ipv6_addr = ((struct sockaddr_in6 *) sender_addr)->sin6_addr; | 1895 | u6.ipv6_addr = ((struct sockaddr_in6 *) sender_addr)->sin6_addr; |
2097 | u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port; | 1896 | u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port; |
2098 | arg = &u6; | 1897 | arg = &u6; |
2099 | args = sizeof (u6); | 1898 | args = sizeof(u6); |
2100 | break; | 1899 | break; |
2101 | default: | 1900 | default: |
2102 | GNUNET_break (0); | 1901 | GNUNET_break(0); |
2103 | return; | 1902 | return; |
2104 | } | 1903 | } |
2105 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1904 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2106 | "Received message with %u bytes from peer `%s' at `%s'\n", | 1905 | "Received message with %u bytes from peer `%s' at `%s'\n", |
2107 | (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender), | 1906 | (unsigned int ) ntohs (msg->header.size), GNUNET_i2s (&msg->sender), |
2108 | GNUNET_a2s (sender_addr, sender_addr_len)); | 1907 | GNUNET_a2s (sender_addr, sender_addr_len)); |
2109 | 1908 | ||
2110 | struct GNUNET_HELLO_Address * address = GNUNET_HELLO_address_allocate(&msg->sender, "udp", arg, args); | 1909 | address = GNUNET_HELLO_address_allocate ( &msg->sender, PLUGIN_NAME, |
2111 | if (NULL == (s = udp_plugin_lookup_session (plugin, address, GNUNET_YES))) | 1910 | arg, args, GNUNET_HELLO_ADDRESS_INFO_INBOUND); |
1911 | if (NULL == (s = udp_plugin_lookup_session (plugin, address))) | ||
2112 | { | 1912 | { |
2113 | s = udp_plugin_create_session (plugin, address, GNUNET_YES); | 1913 | s = udp_plugin_create_session (plugin, address); |
2114 | plugin->env->session_start (NULL, &address->peer, PLUGIN_NAME, | 1914 | plugin->env->session_start (NULL, address, s, NULL, 0); |
2115 | address->address, address->address_length, s, NULL, 0); | ||
2116 | } | 1915 | } |
2117 | GNUNET_free (address); | 1916 | GNUNET_free(address); |
2118 | 1917 | ||
2119 | /* iterate over all embedded messages */ | 1918 | /* iterate over all embedded messages */ |
2120 | si.session = s; | 1919 | si.session = s; |
@@ -2122,18 +1921,14 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | |||
2122 | si.arg = arg; | 1921 | si.arg = arg; |
2123 | si.args = args; | 1922 | si.args = args; |
2124 | s->rc++; | 1923 | s->rc++; |
2125 | GNUNET_SERVER_mst_receive (plugin->mst, | 1924 | GNUNET_SERVER_mst_receive (plugin->mst, &si, (const char *) &msg[1], |
2126 | &si, | 1925 | ntohs (msg->header.size) - sizeof(struct UDPMessage), GNUNET_YES, |
2127 | (const char *) &msg[1], | 1926 | GNUNET_NO); |
2128 | ntohs (msg->header.size) - sizeof (struct UDPMessage), | ||
2129 | GNUNET_YES, | ||
2130 | GNUNET_NO); | ||
2131 | s->rc--; | 1927 | s->rc--; |
2132 | if ( (0 == s->rc) && (GNUNET_YES == s->in_destroy)) | 1928 | if ((0 == s->rc) && (GNUNET_YES == s->in_destroy)) |
2133 | free_session (s); | 1929 | free_session (s); |
2134 | } | 1930 | } |
2135 | 1931 | ||
2136 | |||
2137 | /** | 1932 | /** |
2138 | * Scan the heap for a receive context with the given address. | 1933 | * Scan the heap for a receive context with the given address. |
2139 | * | 1934 | * |
@@ -2146,13 +1941,13 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | |||
2146 | */ | 1941 | */ |
2147 | static int | 1942 | static int |
2148 | find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, | 1943 | find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, |
2149 | void *element, GNUNET_CONTAINER_HeapCostType cost) | 1944 | void *element, GNUNET_CONTAINER_HeapCostType cost) |
2150 | { | 1945 | { |
2151 | struct FindReceiveContext *frc = cls; | 1946 | struct FindReceiveContext *frc = cls; |
2152 | struct DefragContext *e = element; | 1947 | struct DefragContext *e = element; |
2153 | 1948 | ||
2154 | if ((frc->addr_len == e->addr_len) && | 1949 | if ((frc->addr_len == e->addr_len) |
2155 | (0 == memcmp (frc->addr, e->src_addr, frc->addr_len))) | 1950 | && (0 == memcmp (frc->addr, e->src_addr, frc->addr_len))) |
2156 | { | 1951 | { |
2157 | frc->rc = e; | 1952 | frc->rc = e; |
2158 | return GNUNET_NO; | 1953 | return GNUNET_NO; |
@@ -2160,7 +1955,6 @@ find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, | |||
2160 | return GNUNET_YES; | 1955 | return GNUNET_YES; |
2161 | } | 1956 | } |
2162 | 1957 | ||
2163 | |||
2164 | /** | 1958 | /** |
2165 | * Process a defragmented message. | 1959 | * Process a defragmented message. |
2166 | * | 1960 | * |
@@ -2174,35 +1968,30 @@ fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg) | |||
2174 | 1968 | ||
2175 | if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) | 1969 | if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) |
2176 | { | 1970 | { |
2177 | GNUNET_break (0); | 1971 | GNUNET_break(0); |
2178 | return; | 1972 | return; |
2179 | } | 1973 | } |
2180 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) | 1974 | if (ntohs (msg->size) < sizeof(struct UDPMessage)) |
2181 | { | 1975 | { |
2182 | GNUNET_break (0); | 1976 | GNUNET_break(0); |
2183 | return; | 1977 | return; |
2184 | } | 1978 | } |
2185 | process_udp_message (rc->plugin, (const struct UDPMessage *) msg, | 1979 | process_udp_message (rc->plugin, (const struct UDPMessage *) msg, |
2186 | rc->src_addr, rc->addr_len); | 1980 | rc->src_addr, rc->addr_len); |
2187 | } | 1981 | } |
2188 | 1982 | ||
2189 | |||
2190 | struct LookupContext | 1983 | struct LookupContext |
2191 | { | 1984 | { |
2192 | struct Session *res; | 1985 | struct Session *res; |
2193 | 1986 | ||
2194 | const struct sockaddr * addr; | 1987 | const struct GNUNET_HELLO_Address *address; |
2195 | |||
2196 | size_t addrlen; | ||
2197 | 1988 | ||
2198 | int must_have_frag_ctx; | 1989 | int must_have_frag_ctx; |
2199 | }; | 1990 | }; |
2200 | 1991 | ||
2201 | |||
2202 | static int | 1992 | static int |
2203 | lookup_session_by_addr_it (void *cls, | 1993 | lookup_session_by_addr_it (void *cls, const struct GNUNET_PeerIdentity *key, |
2204 | const struct GNUNET_PeerIdentity *key, | 1994 | void *value) |
2205 | void *value) | ||
2206 | { | 1995 | { |
2207 | struct LookupContext *l_ctx = cls; | 1996 | struct LookupContext *l_ctx = cls; |
2208 | struct Session * s = value; | 1997 | struct Session * s = value; |
@@ -2210,15 +1999,7 @@ lookup_session_by_addr_it (void *cls, | |||
2210 | if ((GNUNET_YES == l_ctx->must_have_frag_ctx) && (NULL == s->frag_ctx)) | 1999 | if ((GNUNET_YES == l_ctx->must_have_frag_ctx) && (NULL == s->frag_ctx)) |
2211 | return GNUNET_YES; | 2000 | return GNUNET_YES; |
2212 | 2001 | ||
2213 | /* | 2002 | if (0 == GNUNET_HELLO_address_cmp (s->address, l_ctx->address)) |
2214 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Comparing session: have %s %s %p<-> want %s\n", | ||
2215 | GNUNET_a2s(s->sock_addr, s->addrlen), | ||
2216 | (GNUNET_YES == s->inbound) ? "inbound" : "outbound", | ||
2217 | s->frag_ctx, | ||
2218 | GNUNET_a2s(l_ctx->addr, l_ctx->addrlen)); | ||
2219 | */ | ||
2220 | if ((s->addrlen == l_ctx->addrlen) && | ||
2221 | (0 == memcmp (s->sock_addr, l_ctx->addr, s->addrlen))) | ||
2222 | { | 2003 | { |
2223 | l_ctx->res = s; | 2004 | l_ctx->res = s; |
2224 | return GNUNET_YES; | 2005 | return GNUNET_YES; |
@@ -2226,7 +2007,6 @@ lookup_session_by_addr_it (void *cls, | |||
2226 | return GNUNET_YES; | 2007 | return GNUNET_YES; |
2227 | } | 2008 | } |
2228 | 2009 | ||
2229 | |||
2230 | /** | 2010 | /** |
2231 | * Transmit an acknowledgement. | 2011 | * Transmit an acknowledgement. |
2232 | * | 2012 | * |
@@ -2238,20 +2018,19 @@ static void | |||
2238 | ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) | 2018 | ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) |
2239 | { | 2019 | { |
2240 | struct DefragContext *rc = cls; | 2020 | struct DefragContext *rc = cls; |
2241 | size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size); | 2021 | size_t msize = sizeof(struct UDP_ACK_Message) + ntohs (msg->size); |
2242 | struct UDP_ACK_Message *udp_ack; | 2022 | struct UDP_ACK_Message *udp_ack; |
2243 | uint32_t delay = 0; | 2023 | uint32_t delay = 0; |
2244 | struct UDP_MessageWrapper *udpw; | 2024 | struct UDP_MessageWrapper *udpw; |
2245 | struct Session *s; | 2025 | struct Session *s; |
2246 | struct LookupContext l_ctx; | 2026 | struct LookupContext l_ctx; |
2247 | 2027 | ||
2248 | l_ctx.addr = rc->src_addr; | 2028 | l_ctx.address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, rc->src_addr, |
2249 | l_ctx.addrlen = rc->addr_len; | 2029 | rc->addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE); |
2250 | l_ctx.res = NULL; | 2030 | l_ctx.res = NULL; |
2251 | l_ctx.must_have_frag_ctx = GNUNET_NO; | 2031 | l_ctx.must_have_frag_ctx = GNUNET_NO; |
2252 | GNUNET_CONTAINER_multipeermap_iterate (rc->plugin->sessions, | 2032 | GNUNET_CONTAINER_multipeermap_iterate (rc->plugin->sessions, |
2253 | &lookup_session_by_addr_it, | 2033 | &lookup_session_by_addr_it, &l_ctx); |
2254 | &l_ctx); | ||
2255 | s = l_ctx.res; | 2034 | s = l_ctx.res; |
2256 | 2035 | ||
2257 | if (NULL == s) | 2036 | if (NULL == s) |
@@ -2260,20 +2039,15 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) | |||
2260 | if (s->flow_delay_for_other_peer.rel_value_us <= UINT32_MAX) | 2039 | if (s->flow_delay_for_other_peer.rel_value_us <= UINT32_MAX) |
2261 | delay = s->flow_delay_for_other_peer.rel_value_us; | 2040 | delay = s->flow_delay_for_other_peer.rel_value_us; |
2262 | 2041 | ||
2263 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2042 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending ACK to `%s' including delay of %s\n", |
2264 | "Sending ACK to `%s' including delay of %s\n", | 2043 | GNUNET_a2s (rc->src_addr, (rc->src_addr->sa_family == AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct sockaddr_in6)), |
2265 | GNUNET_a2s (rc->src_addr, | 2044 | GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, GNUNET_YES)); |
2266 | (rc->src_addr->sa_family == | ||
2267 | AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct | ||
2268 | sockaddr_in6)), | ||
2269 | GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, | ||
2270 | GNUNET_YES)); | ||
2271 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize); | 2045 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize); |
2272 | udpw->msg_size = msize; | 2046 | udpw->msg_size = msize; |
2273 | udpw->payload_size = 0; | 2047 | udpw->payload_size = 0; |
2274 | udpw->session = s; | 2048 | udpw->session = s; |
2275 | udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 2049 | udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
2276 | udpw->msg_buf = (char *)&udpw[1]; | 2050 | udpw->msg_buf = (char *) &udpw[1]; |
2277 | udpw->msg_type = MSG_ACK; | 2051 | udpw->msg_type = MSG_ACK; |
2278 | udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf; | 2052 | udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf; |
2279 | udp_ack->header.size = htons ((uint16_t) msize); | 2053 | udp_ack->header.size = htons ((uint16_t) msize); |
@@ -2284,28 +2058,21 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) | |||
2284 | enqueue (rc->plugin, udpw); | 2058 | enqueue (rc->plugin, udpw); |
2285 | } | 2059 | } |
2286 | 2060 | ||
2287 | |||
2288 | static void | 2061 | static void |
2289 | read_process_msg (struct Plugin *plugin, | 2062 | read_process_msg (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, |
2290 | const struct GNUNET_MessageHeader *msg, | 2063 | const struct sockaddr *addr, socklen_t fromlen) |
2291 | const struct sockaddr *addr, | ||
2292 | socklen_t fromlen) | ||
2293 | { | 2064 | { |
2294 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) | 2065 | if (ntohs (msg->size) < sizeof(struct UDPMessage)) |
2295 | { | 2066 | { |
2296 | GNUNET_break_op (0); | 2067 | GNUNET_break_op(0); |
2297 | return; | 2068 | return; |
2298 | } | 2069 | } |
2299 | process_udp_message (plugin, (const struct UDPMessage *) msg, | 2070 | process_udp_message (plugin, (const struct UDPMessage *) msg, addr, fromlen); |
2300 | addr, fromlen); | ||
2301 | } | 2071 | } |
2302 | 2072 | ||
2303 | |||
2304 | static void | 2073 | static void |
2305 | read_process_ack (struct Plugin *plugin, | 2074 | read_process_ack (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, |
2306 | const struct GNUNET_MessageHeader *msg, | 2075 | const struct sockaddr *addr, socklen_t fromlen) |
2307 | const struct sockaddr *addr, | ||
2308 | socklen_t fromlen) | ||
2309 | { | 2076 | { |
2310 | const struct GNUNET_MessageHeader *ack; | 2077 | const struct GNUNET_MessageHeader *ack; |
2311 | const struct UDP_ACK_Message *udp_ack; | 2078 | const struct UDP_ACK_Message *udp_ack; |
@@ -2313,70 +2080,64 @@ read_process_ack (struct Plugin *plugin, | |||
2313 | struct Session *s; | 2080 | struct Session *s; |
2314 | struct GNUNET_TIME_Relative flow_delay; | 2081 | struct GNUNET_TIME_Relative flow_delay; |
2315 | 2082 | ||
2316 | if (ntohs (msg->size) < | 2083 | if (ntohs (msg->size) |
2317 | sizeof (struct UDP_ACK_Message) + sizeof (struct GNUNET_MessageHeader)) | 2084 | < sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader)) |
2318 | { | 2085 | { |
2319 | GNUNET_break_op (0); | 2086 | GNUNET_break_op(0); |
2320 | return; | 2087 | return; |
2321 | } | 2088 | } |
2322 | udp_ack = (const struct UDP_ACK_Message *) msg; | 2089 | udp_ack = (const struct UDP_ACK_Message *) msg; |
2323 | l_ctx.addr = (const struct sockaddr *) addr; | 2090 | |
2324 | l_ctx.addrlen = fromlen; | 2091 | l_ctx.address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, |
2092 | (const struct sockaddr *) addr, fromlen, GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
2325 | l_ctx.res = NULL; | 2093 | l_ctx.res = NULL; |
2326 | l_ctx.must_have_frag_ctx = GNUNET_YES; | 2094 | l_ctx.must_have_frag_ctx = GNUNET_YES; |
2327 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, | 2095 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, |
2328 | &lookup_session_by_addr_it, | 2096 | &lookup_session_by_addr_it, &l_ctx); |
2329 | &l_ctx); | ||
2330 | s = l_ctx.res; | 2097 | s = l_ctx.res; |
2331 | if ((NULL == s) || (NULL == s->frag_ctx)) | 2098 | if ((NULL == s) || (NULL == s->frag_ctx)) |
2332 | { | 2099 | { |
2333 | return; | 2100 | return; |
2334 | } | 2101 | } |
2335 | 2102 | ||
2336 | |||
2337 | flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); | 2103 | flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); |
2338 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2104 | LOG(GNUNET_ERROR_TYPE_DEBUG, "We received a sending delay of %s\n", |
2339 | "We received a sending delay of %s\n", | 2105 | GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES)); |
2340 | GNUNET_STRINGS_relative_time_to_string (flow_delay, | 2106 | s->flow_delay_from_other_peer = GNUNET_TIME_relative_to_absolute (flow_delay); |
2341 | GNUNET_YES)); | ||
2342 | s->flow_delay_from_other_peer = | ||
2343 | GNUNET_TIME_relative_to_absolute (flow_delay); | ||
2344 | 2107 | ||
2345 | ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; | 2108 | ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; |
2346 | if (ntohs (ack->size) != | 2109 | if (ntohs (ack->size) != ntohs (msg->size) - sizeof(struct UDP_ACK_Message)) |
2347 | ntohs (msg->size) - sizeof (struct UDP_ACK_Message)) | ||
2348 | { | 2110 | { |
2349 | GNUNET_break_op (0); | 2111 | GNUNET_break_op(0); |
2350 | return; | 2112 | return; |
2351 | } | 2113 | } |
2352 | 2114 | ||
2353 | if (0 != memcmp (&l_ctx.res->target, &udp_ack->sender, sizeof (struct GNUNET_PeerIdentity))) | 2115 | if (0 |
2354 | GNUNET_break (0); | 2116 | != memcmp (&l_ctx.res->target, &udp_ack->sender, |
2117 | sizeof(struct GNUNET_PeerIdentity))) | ||
2118 | GNUNET_break(0); | ||
2355 | if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack)) | 2119 | if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack)) |
2356 | { | 2120 | { |
2357 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2121 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2358 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", | 2122 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", |
2359 | (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), | 2123 | (unsigned int ) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), |
2360 | GNUNET_a2s (addr, fromlen)); | 2124 | GNUNET_a2s (addr, fromlen)); |
2361 | /* Expect more ACKs to arrive */ | 2125 | /* Expect more ACKs to arrive */ |
2362 | return; | 2126 | return; |
2363 | } | 2127 | } |
2364 | 2128 | ||
2365 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2129 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Message full ACK'ed\n", |
2366 | "Message full ACK'ed\n", | 2130 | (unsigned int ) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), |
2367 | (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), | 2131 | GNUNET_a2s (addr, fromlen)); |
2368 | GNUNET_a2s (addr, fromlen)); | ||
2369 | 2132 | ||
2370 | /* Remove fragmented message after successful sending */ | 2133 | /* Remove fragmented message after successful sending */ |
2371 | fragmented_message_done (s->frag_ctx, GNUNET_OK); | 2134 | fragmented_message_done (s->frag_ctx, GNUNET_OK); |
2372 | } | 2135 | } |
2373 | 2136 | ||
2374 | |||
2375 | static void | 2137 | static void |
2376 | read_process_fragment (struct Plugin *plugin, | 2138 | read_process_fragment (struct Plugin *plugin, |
2377 | const struct GNUNET_MessageHeader *msg, | 2139 | const struct GNUNET_MessageHeader *msg, const struct sockaddr *addr, |
2378 | const struct sockaddr *addr, | 2140 | socklen_t fromlen) |
2379 | socklen_t fromlen) | ||
2380 | { | 2141 | { |
2381 | struct DefragContext *d_ctx; | 2142 | struct DefragContext *d_ctx; |
2382 | struct GNUNET_TIME_Absolute now; | 2143 | struct GNUNET_TIME_Absolute now; |
@@ -2386,17 +2147,15 @@ read_process_fragment (struct Plugin *plugin, | |||
2386 | frc.addr = addr; | 2147 | frc.addr = addr; |
2387 | frc.addr_len = fromlen; | 2148 | frc.addr_len = fromlen; |
2388 | 2149 | ||
2389 | LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n", | 2150 | LOG(GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n", |
2390 | (unsigned int) ntohs (msg->size), | 2151 | (unsigned int ) ntohs (msg->size), GNUNET_a2s (addr, fromlen)); |
2391 | GNUNET_a2s (addr, fromlen)); | ||
2392 | /* Lookup existing receive context for this address */ | 2152 | /* Lookup existing receive context for this address */ |
2393 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, | 2153 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, &find_receive_context, |
2394 | &find_receive_context, | 2154 | &frc); |
2395 | &frc); | ||
2396 | now = GNUNET_TIME_absolute_get (); | 2155 | now = GNUNET_TIME_absolute_get (); |
2397 | d_ctx = frc.rc; | 2156 | d_ctx = frc.rc; |
2398 | 2157 | ||
2399 | if (d_ctx == NULL) | 2158 | if (d_ctx == NULL ) |
2400 | { | 2159 | { |
2401 | /* Create a new defragmentation context */ | 2160 | /* Create a new defragmentation context */ |
2402 | d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + fromlen); | 2161 | d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + fromlen); |
@@ -2404,46 +2163,39 @@ read_process_fragment (struct Plugin *plugin, | |||
2404 | d_ctx->src_addr = (const struct sockaddr *) &d_ctx[1]; | 2163 | d_ctx->src_addr = (const struct sockaddr *) &d_ctx[1]; |
2405 | d_ctx->addr_len = fromlen; | 2164 | d_ctx->addr_len = fromlen; |
2406 | d_ctx->plugin = plugin; | 2165 | d_ctx->plugin = plugin; |
2407 | d_ctx->defrag = | 2166 | d_ctx->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, |
2408 | GNUNET_DEFRAGMENT_context_create (plugin->env->stats, UDP_MTU, | 2167 | UDP_MTU, UDP_MAX_MESSAGES_IN_DEFRAG, d_ctx, &fragment_msg_proc, |
2409 | UDP_MAX_MESSAGES_IN_DEFRAG, d_ctx, | 2168 | &ack_proc); |
2410 | &fragment_msg_proc, &ack_proc); | 2169 | d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, d_ctx, |
2411 | d_ctx->hnode = | 2170 | (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); |
2412 | GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, d_ctx, | 2171 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2413 | (GNUNET_CONTAINER_HeapCostType) | 2172 | "Created new defragmentation context for %u-byte fragment from `%s'\n", |
2414 | now.abs_value_us); | 2173 | (unsigned int ) ntohs (msg->size), GNUNET_a2s (addr, fromlen)); |
2415 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2416 | "Created new defragmentation context for %u-byte fragment from `%s'\n", | ||
2417 | (unsigned int) ntohs (msg->size), | ||
2418 | GNUNET_a2s (addr, fromlen)); | ||
2419 | } | 2174 | } |
2420 | else | 2175 | else |
2421 | { | 2176 | { |
2422 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2177 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2423 | "Found existing defragmentation context for %u-byte fragment from `%s'\n", | 2178 | "Found existing defragmentation context for %u-byte fragment from `%s'\n", |
2424 | (unsigned int) ntohs (msg->size), | 2179 | (unsigned int ) ntohs (msg->size), GNUNET_a2s (addr, fromlen)); |
2425 | GNUNET_a2s (addr, fromlen)); | ||
2426 | } | 2180 | } |
2427 | 2181 | ||
2428 | if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg)) | 2182 | if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg)) |
2429 | { | 2183 | { |
2430 | /* keep this 'rc' from expiring */ | 2184 | /* keep this 'rc' from expiring */ |
2431 | GNUNET_CONTAINER_heap_update_cost (plugin->defrag_ctxs, d_ctx->hnode, | 2185 | GNUNET_CONTAINER_heap_update_cost (plugin->defrag_ctxs, d_ctx->hnode, |
2432 | (GNUNET_CONTAINER_HeapCostType) | 2186 | (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); |
2433 | now.abs_value_us); | ||
2434 | } | 2187 | } |
2435 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > | 2188 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > |
2436 | UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) | 2189 | UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) |
2437 | { | 2190 | { |
2438 | /* remove 'rc' that was inactive the longest */ | 2191 | /* remove 'rc' that was inactive the longest */ |
2439 | d_ctx = GNUNET_CONTAINER_heap_remove_root (plugin->defrag_ctxs); | 2192 | d_ctx = GNUNET_CONTAINER_heap_remove_root (plugin->defrag_ctxs); |
2440 | GNUNET_assert (NULL != d_ctx); | 2193 | GNUNET_assert(NULL != d_ctx); |
2441 | GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); | 2194 | GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); |
2442 | GNUNET_free (d_ctx); | 2195 | GNUNET_free(d_ctx); |
2443 | } | 2196 | } |
2444 | } | 2197 | } |
2445 | 2198 | ||
2446 | |||
2447 | /** | 2199 | /** |
2448 | * Read and process a message from the given socket. | 2200 | * Read and process a message from the given socket. |
2449 | * | 2201 | * |
@@ -2459,10 +2211,10 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
2459 | ssize_t size; | 2211 | ssize_t size; |
2460 | const struct GNUNET_MessageHeader *msg; | 2212 | const struct GNUNET_MessageHeader *msg; |
2461 | 2213 | ||
2462 | fromlen = sizeof (addr); | 2214 | fromlen = sizeof(addr); |
2463 | memset (&addr, 0, sizeof (addr)); | 2215 | memset (&addr, 0, sizeof(addr)); |
2464 | size = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), | 2216 | size = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof(buf), |
2465 | (struct sockaddr *) &addr, &fromlen); | 2217 | (struct sockaddr *) &addr, &fromlen); |
2466 | #if MINGW | 2218 | #if MINGW |
2467 | /* On SOCK_DGRAM UDP sockets recvfrom might fail with a | 2219 | /* On SOCK_DGRAM UDP sockets recvfrom might fail with a |
2468 | * WSAECONNRESET error to indicate that previous sendto() (yes, sendto!) | 2220 | * WSAECONNRESET error to indicate that previous sendto() (yes, sendto!) |
@@ -2475,146 +2227,134 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
2475 | * Unreachable message. | 2227 | * Unreachable message. |
2476 | */ | 2228 | */ |
2477 | if ( (-1 == size) && (ECONNRESET == errno) ) | 2229 | if ( (-1 == size) && (ECONNRESET == errno) ) |
2478 | return; | 2230 | return; |
2479 | #endif | 2231 | #endif |
2480 | if (-1 == size) | 2232 | if (-1 == size) |
2481 | { | 2233 | { |
2482 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2234 | LOG(GNUNET_ERROR_TYPE_DEBUG, "UDP failed to receive data: %s\n", |
2483 | "UDP failed to receive data: %s\n", STRERROR (errno)); | 2235 | STRERROR (errno)); |
2484 | /* Connection failure or something. Not a protocol violation. */ | 2236 | /* Connection failure or something. Not a protocol violation. */ |
2485 | return; | 2237 | return; |
2486 | } | 2238 | } |
2487 | if (size < sizeof (struct GNUNET_MessageHeader)) | 2239 | if (size < sizeof(struct GNUNET_MessageHeader)) |
2488 | { | 2240 | { |
2489 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2241 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2490 | "UDP got %u bytes, which is not enough for a GNUnet message header\n", | 2242 | "UDP got %u bytes, which is not enough for a GNUnet message header\n", |
2491 | (unsigned int) size); | 2243 | (unsigned int ) size); |
2492 | /* _MAY_ be a connection failure (got partial message) */ | 2244 | /* _MAY_ be a connection failure (got partial message) */ |
2493 | /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ | 2245 | /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ |
2494 | GNUNET_break_op (0); | 2246 | GNUNET_break_op(0); |
2495 | return; | 2247 | return; |
2496 | } | 2248 | } |
2497 | msg = (const struct GNUNET_MessageHeader *) buf; | 2249 | msg = (const struct GNUNET_MessageHeader *) buf; |
2498 | 2250 | ||
2499 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2251 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2500 | "UDP received %u-byte message from `%s' type %u\n", | 2252 | "UDP received %u-byte message from `%s' type %u\n", (unsigned int ) size, |
2501 | (unsigned int) size, | 2253 | GNUNET_a2s ((const struct sockaddr * ) &addr, fromlen), |
2502 | GNUNET_a2s ((const struct sockaddr *) &addr, fromlen), | 2254 | ntohs (msg->type)); |
2503 | ntohs (msg->type)); | ||
2504 | 2255 | ||
2505 | if (size != ntohs (msg->size)) | 2256 | if (size != ntohs (msg->size)) |
2506 | { | 2257 | { |
2507 | GNUNET_break_op (0); | 2258 | GNUNET_break_op(0); |
2508 | return; | 2259 | return; |
2509 | } | 2260 | } |
2510 | 2261 | ||
2511 | GNUNET_STATISTICS_update (plugin->env->stats, | 2262 | GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, bytes, received", |
2512 | "# UDP, total, bytes, received", | 2263 | size, GNUNET_NO); |
2513 | size, GNUNET_NO); | ||
2514 | 2264 | ||
2515 | switch (ntohs (msg->type)) | 2265 | switch (ntohs (msg->type)) |
2516 | { | 2266 | { |
2517 | case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON: | 2267 | case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON: |
2518 | if (GNUNET_YES == plugin->enable_broadcasting_receiving) | 2268 | if (GNUNET_YES == plugin->enable_broadcasting_receiving) |
2519 | udp_broadcast_receive (plugin, buf, size, | 2269 | udp_broadcast_receive (plugin, buf, size, (const struct sockaddr *) &addr, |
2520 | (const struct sockaddr *) &addr, fromlen); | 2270 | fromlen); |
2521 | return; | 2271 | return; |
2522 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: | 2272 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: |
2523 | read_process_msg (plugin, msg, | 2273 | read_process_msg (plugin, msg, (const struct sockaddr *) &addr, fromlen); |
2524 | (const struct sockaddr *) &addr, fromlen); | ||
2525 | return; | 2274 | return; |
2526 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: | 2275 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: |
2527 | read_process_ack (plugin, msg, | 2276 | read_process_ack (plugin, msg, (const struct sockaddr *) &addr, fromlen); |
2528 | (const struct sockaddr *) &addr, fromlen); | ||
2529 | return; | 2277 | return; |
2530 | case GNUNET_MESSAGE_TYPE_FRAGMENT: | 2278 | case GNUNET_MESSAGE_TYPE_FRAGMENT: |
2531 | read_process_fragment (plugin, msg, | 2279 | read_process_fragment (plugin, msg, (const struct sockaddr *) &addr, |
2532 | (const struct sockaddr *) &addr, fromlen); | 2280 | fromlen); |
2533 | return; | 2281 | return; |
2534 | default: | 2282 | default: |
2535 | GNUNET_break_op (0); | 2283 | GNUNET_break_op(0); |
2536 | return; | 2284 | return; |
2537 | } | 2285 | } |
2538 | } | 2286 | } |
2539 | 2287 | ||
2540 | |||
2541 | static struct UDP_MessageWrapper * | 2288 | static struct UDP_MessageWrapper * |
2542 | remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | 2289 | remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, |
2543 | struct GNUNET_NETWORK_Handle *sock) | 2290 | struct GNUNET_NETWORK_Handle *sock) |
2544 | { | 2291 | { |
2545 | struct UDP_MessageWrapper *udpw = NULL; | 2292 | struct UDP_MessageWrapper *udpw = NULL; |
2546 | struct GNUNET_TIME_Relative remaining; | 2293 | struct GNUNET_TIME_Relative remaining; |
2547 | 2294 | ||
2548 | udpw = head; | 2295 | udpw = head; |
2549 | while (udpw != NULL) | 2296 | while (udpw != NULL ) |
2550 | { | 2297 | { |
2551 | /* Find messages with timeout */ | 2298 | /* Find messages with timeout */ |
2552 | remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout); | 2299 | remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout); |
2553 | if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) | 2300 | if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) |
2554 | { | 2301 | { |
2555 | /* Message timed out */ | 2302 | /* Message timed out */ |
2556 | switch (udpw->msg_type) { | 2303 | switch (udpw->msg_type) |
2557 | case MSG_UNFRAGMENTED: | 2304 | { |
2558 | GNUNET_STATISTICS_update (plugin->env->stats, | 2305 | case MSG_UNFRAGMENTED: |
2559 | "# UDP, total, bytes, sent, timeout", | 2306 | GNUNET_STATISTICS_update (plugin->env->stats, |
2560 | udpw->msg_size, GNUNET_NO); | 2307 | "# UDP, total, bytes, sent, timeout", udpw->msg_size, GNUNET_NO); |
2561 | GNUNET_STATISTICS_update (plugin->env->stats, | 2308 | GNUNET_STATISTICS_update (plugin->env->stats, |
2562 | "# UDP, total, messages, sent, timeout", | 2309 | "# UDP, total, messages, sent, timeout", 1, GNUNET_NO); |
2563 | 1, GNUNET_NO); | 2310 | GNUNET_STATISTICS_update (plugin->env->stats, |
2564 | GNUNET_STATISTICS_update (plugin->env->stats, | 2311 | "# UDP, unfragmented msgs, messages, sent, timeout", 1, GNUNET_NO); |
2565 | "# UDP, unfragmented msgs, messages, sent, timeout", | 2312 | GNUNET_STATISTICS_update (plugin->env->stats, |
2566 | 1, GNUNET_NO); | 2313 | "# UDP, unfragmented msgs, bytes, sent, timeout", |
2567 | GNUNET_STATISTICS_update (plugin->env->stats, | 2314 | udpw->payload_size, GNUNET_NO); |
2568 | "# UDP, unfragmented msgs, bytes, sent, timeout", | 2315 | /* Not fragmented message */ |
2569 | udpw->payload_size, GNUNET_NO); | 2316 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2570 | /* Not fragmented message */ | 2317 | "Message for peer `%s' with size %u timed out\n", |
2571 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2318 | GNUNET_i2s (&udpw->session->target), udpw->payload_size); |
2572 | "Message for peer `%s' with size %u timed out\n", | 2319 | call_continuation (udpw, GNUNET_SYSERR); |
2573 | GNUNET_i2s(&udpw->session->target), udpw->payload_size); | 2320 | /* Remove message */ |
2574 | call_continuation (udpw, GNUNET_SYSERR); | 2321 | dequeue (plugin, udpw); |
2575 | /* Remove message */ | 2322 | GNUNET_free(udpw); |
2576 | dequeue (plugin, udpw); | 2323 | break; |
2577 | GNUNET_free (udpw); | 2324 | case MSG_FRAGMENTED: |
2578 | break; | 2325 | /* Fragmented message */ |
2579 | case MSG_FRAGMENTED: | 2326 | GNUNET_STATISTICS_update (plugin->env->stats, |
2580 | /* Fragmented message */ | 2327 | "# UDP, total, bytes, sent, timeout", udpw->frag_ctx->on_wire_size, |
2581 | GNUNET_STATISTICS_update (plugin->env->stats, | 2328 | GNUNET_NO); |
2582 | "# UDP, total, bytes, sent, timeout", | 2329 | GNUNET_STATISTICS_update (plugin->env->stats, |
2583 | udpw->frag_ctx->on_wire_size, GNUNET_NO); | 2330 | "# UDP, total, messages, sent, timeout", 1, GNUNET_NO); |
2584 | GNUNET_STATISTICS_update (plugin->env->stats, | 2331 | call_continuation (udpw, GNUNET_SYSERR); |
2585 | "# UDP, total, messages, sent, timeout", | 2332 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2586 | 1, GNUNET_NO); | 2333 | "Fragment for message for peer `%s' with size %u timed out\n", |
2587 | call_continuation (udpw, GNUNET_SYSERR); | 2334 | GNUNET_i2s (&udpw->session->target), udpw->frag_ctx->payload_size); |
2588 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2335 | |
2589 | "Fragment for message for peer `%s' with size %u timed out\n", | 2336 | GNUNET_STATISTICS_update (plugin->env->stats, |
2590 | GNUNET_i2s(&udpw->session->target), udpw->frag_ctx->payload_size); | 2337 | "# UDP, fragmented msgs, messages, sent, timeout", 1, GNUNET_NO); |
2591 | 2338 | GNUNET_STATISTICS_update (plugin->env->stats, | |
2592 | 2339 | "# UDP, fragmented msgs, bytes, sent, timeout", | |
2593 | GNUNET_STATISTICS_update (plugin->env->stats, | 2340 | udpw->frag_ctx->payload_size, GNUNET_NO); |
2594 | "# UDP, fragmented msgs, messages, sent, timeout", | 2341 | /* Remove fragmented message due to timeout */ |
2595 | 1, GNUNET_NO); | 2342 | fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); |
2596 | GNUNET_STATISTICS_update (plugin->env->stats, | 2343 | break; |
2597 | "# UDP, fragmented msgs, bytes, sent, timeout", | 2344 | case MSG_ACK: |
2598 | udpw->frag_ctx->payload_size, GNUNET_NO); | 2345 | GNUNET_STATISTICS_update (plugin->env->stats, |
2599 | /* Remove fragmented message due to timeout */ | 2346 | "# UDP, total, bytes, sent, timeout", udpw->msg_size, GNUNET_NO); |
2600 | fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); | 2347 | GNUNET_STATISTICS_update (plugin->env->stats, |
2601 | break; | 2348 | "# UDP, total, messages, sent, timeout", 1, GNUNET_NO); |
2602 | case MSG_ACK: | 2349 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2603 | GNUNET_STATISTICS_update (plugin->env->stats, | 2350 | "ACK Message for peer `%s' with size %u timed out\n", |
2604 | "# UDP, total, bytes, sent, timeout", | 2351 | GNUNET_i2s (&udpw->session->target), udpw->payload_size); |
2605 | udpw->msg_size, GNUNET_NO); | 2352 | call_continuation (udpw, GNUNET_SYSERR); |
2606 | GNUNET_STATISTICS_update (plugin->env->stats, | 2353 | dequeue (plugin, udpw); |
2607 | "# UDP, total, messages, sent, timeout", | 2354 | GNUNET_free(udpw); |
2608 | 1, GNUNET_NO); | 2355 | break; |
2609 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2356 | default: |
2610 | "ACK Message for peer `%s' with size %u timed out\n", | 2357 | break; |
2611 | GNUNET_i2s(&udpw->session->target), udpw->payload_size); | ||
2612 | call_continuation (udpw, GNUNET_SYSERR); | ||
2613 | dequeue (plugin, udpw); | ||
2614 | GNUNET_free (udpw); | ||
2615 | break; | ||
2616 | default: | ||
2617 | break; | ||
2618 | } | 2358 | } |
2619 | if (sock == plugin->sockv4) | 2359 | if (sock == plugin->sockv4) |
2620 | udpw = plugin->ipv4_queue_head; | 2360 | udpw = plugin->ipv4_queue_head; |
@@ -2622,33 +2362,32 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | |||
2622 | udpw = plugin->ipv6_queue_head; | 2362 | udpw = plugin->ipv6_queue_head; |
2623 | else | 2363 | else |
2624 | { | 2364 | { |
2625 | GNUNET_break (0); /* should never happen */ | 2365 | GNUNET_break(0); /* should never happen */ |
2626 | udpw = NULL; | 2366 | udpw = NULL; |
2627 | } | 2367 | } |
2628 | GNUNET_STATISTICS_update (plugin->env->stats, | 2368 | GNUNET_STATISTICS_update (plugin->env->stats, |
2629 | "# messages dismissed due to timeout", | 2369 | "# messages dismissed due to timeout", 1, GNUNET_NO); |
2630 | 1, GNUNET_NO); | ||
2631 | } | 2370 | } |
2632 | else | 2371 | else |
2633 | { | 2372 | { |
2634 | /* Message did not time out, check flow delay */ | 2373 | /* Message did not time out, check flow delay */ |
2635 | remaining = GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer); | 2374 | remaining = GNUNET_TIME_absolute_get_remaining ( |
2375 | udpw->session->flow_delay_from_other_peer); | ||
2636 | if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) | 2376 | if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) |
2637 | { | 2377 | { |
2638 | /* this message is not delayed */ | 2378 | /* this message is not delayed */ |
2639 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2379 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2640 | "Message for peer `%s' (%u bytes) is not delayed \n", | 2380 | "Message for peer `%s' (%u bytes) is not delayed \n", |
2641 | GNUNET_i2s(&udpw->session->target), udpw->payload_size); | 2381 | GNUNET_i2s (&udpw->session->target), udpw->payload_size); |
2642 | break; /* Found message to send, break */ | 2382 | break; /* Found message to send, break */ |
2643 | } | 2383 | } |
2644 | else | 2384 | else |
2645 | { | 2385 | { |
2646 | /* Message is delayed, try next */ | 2386 | /* Message is delayed, try next */ |
2647 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2387 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2648 | "Message for peer `%s' (%u bytes) is delayed for %s\n", | 2388 | "Message for peer `%s' (%u bytes) is delayed for %s\n", |
2649 | GNUNET_i2s(&udpw->session->target), udpw->payload_size, | 2389 | GNUNET_i2s (&udpw->session->target), udpw->payload_size, |
2650 | GNUNET_STRINGS_relative_time_to_string (remaining, | 2390 | GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES)); |
2651 | GNUNET_YES)); | ||
2652 | udpw = udpw->next; | 2391 | udpw = udpw->next; |
2653 | } | 2392 | } |
2654 | } | 2393 | } |
@@ -2656,54 +2395,51 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | |||
2656 | return udpw; | 2395 | return udpw; |
2657 | } | 2396 | } |
2658 | 2397 | ||
2659 | |||
2660 | static void | 2398 | static void |
2661 | analyze_send_error (struct Plugin *plugin, | 2399 | analyze_send_error (struct Plugin *plugin, const struct sockaddr * sa, |
2662 | const struct sockaddr * sa, | 2400 | socklen_t slen, int error) |
2663 | socklen_t slen, | ||
2664 | int error) | ||
2665 | { | 2401 | { |
2666 | static int network_down_error; | 2402 | static int network_down_error; |
2667 | struct GNUNET_ATS_Information type; | 2403 | struct GNUNET_ATS_Information type; |
2668 | 2404 | ||
2669 | type = plugin->env->get_address_type (plugin->env->cls,sa, slen); | 2405 | type = plugin->env->get_address_type (plugin->env->cls, sa, slen); |
2670 | if (((GNUNET_ATS_NET_LAN == ntohl(type.value)) || (GNUNET_ATS_NET_WAN == ntohl(type.value))) && | 2406 | if (((GNUNET_ATS_NET_LAN == ntohl (type.value)) |
2671 | ((ENETUNREACH == errno) || (ENETDOWN == errno))) | 2407 | || (GNUNET_ATS_NET_WAN == ntohl (type.value))) |
2672 | { | 2408 | && ((ENETUNREACH == errno)|| (ENETDOWN == errno))) |
2673 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in))) | 2409 | { |
2674 | { | 2410 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in))) |
2675 | /* IPv4: "Network unreachable" or "Network down" | 2411 | { |
2676 | * | 2412 | /* IPv4: "Network unreachable" or "Network down" |
2677 | * This indicates we do not have connectivity | 2413 | * |
2678 | */ | 2414 | * This indicates we do not have connectivity |
2679 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 2415 | */ |
2680 | _("UDP could not transmit message to `%s': " | 2416 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
2681 | "Network seems down, please check your network configuration\n"), | 2417 | _("UDP could not transmit message to `%s': " |
2682 | GNUNET_a2s (sa, slen)); | 2418 | "Network seems down, please check your network configuration\n"), |
2683 | } | 2419 | GNUNET_a2s (sa, slen)); |
2684 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in6))) | 2420 | } |
2685 | { | 2421 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in6))) |
2686 | /* IPv6: "Network unreachable" or "Network down" | 2422 | { |
2687 | * | 2423 | /* IPv6: "Network unreachable" or "Network down" |
2688 | * This indicates that this system is IPv6 enabled, but does not | 2424 | * |
2689 | * have a valid global IPv6 address assigned or we do not have | 2425 | * This indicates that this system is IPv6 enabled, but does not |
2690 | * connectivity | 2426 | * have a valid global IPv6 address assigned or we do not have |
2691 | */ | 2427 | * connectivity |
2692 | 2428 | */ | |
2693 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 2429 | |
2694 | _("UDP could not transmit IPv6 message! " | 2430 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
2695 | "Please check your network configuration and disable IPv6 if your " | 2431 | _("UDP could not transmit IPv6 message! " |
2696 | "connection does not have a global IPv6 address\n")); | 2432 | "Please check your network configuration and disable IPv6 if your " |
2697 | } | 2433 | "connection does not have a global IPv6 address\n")); |
2698 | } | 2434 | } |
2699 | else | 2435 | } |
2700 | { | 2436 | else |
2701 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2437 | { |
2702 | "UDP could not transmit message to `%s': `%s'\n", | 2438 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2703 | GNUNET_a2s (sa, slen), STRERROR (error)); | 2439 | "UDP could not transmit message to `%s': `%s'\n", |
2704 | } | 2440 | GNUNET_a2s (sa, slen), STRERROR (error)); |
2705 | } | 2441 | } |
2706 | 2442 | } | |
2707 | 2443 | ||
2708 | static size_t | 2444 | static size_t |
2709 | udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | 2445 | udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) |
@@ -2715,53 +2451,51 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | |||
2715 | struct UDP_MessageWrapper *udpw = NULL; | 2451 | struct UDP_MessageWrapper *udpw = NULL; |
2716 | 2452 | ||
2717 | /* Find message to send */ | 2453 | /* Find message to send */ |
2718 | udpw = remove_timeout_messages_and_select ((sock == plugin->sockv4) ? plugin->ipv4_queue_head : plugin->ipv6_queue_head, | 2454 | udpw = remove_timeout_messages_and_select ( |
2719 | sock); | 2455 | (sock == plugin->sockv4) ? |
2456 | plugin->ipv4_queue_head : plugin->ipv6_queue_head, sock); | ||
2720 | if (NULL == udpw) | 2457 | if (NULL == udpw) |
2721 | return 0; /* No message to send */ | 2458 | return 0; /* No message to send */ |
2722 | 2459 | ||
2723 | sa = udpw->session->sock_addr; | 2460 | sa = udpw->session->address->address; |
2724 | slen = udpw->session->addrlen; | 2461 | slen = udpw->session->address->address_length; |
2725 | 2462 | ||
2726 | sent = GNUNET_NETWORK_socket_sendto (sock, udpw->msg_buf, udpw->msg_size, sa, slen); | 2463 | sent = GNUNET_NETWORK_socket_sendto (sock, udpw->msg_buf, udpw->msg_size, sa, |
2464 | slen); | ||
2727 | 2465 | ||
2728 | if (GNUNET_SYSERR == sent) | 2466 | if (GNUNET_SYSERR == sent) |
2729 | { | 2467 | { |
2730 | /* Failure */ | 2468 | /* Failure */ |
2731 | analyze_send_error (plugin, sa, slen, errno); | 2469 | analyze_send_error (plugin, sa, slen, errno); |
2732 | call_continuation(udpw, GNUNET_SYSERR); | 2470 | call_continuation (udpw, GNUNET_SYSERR); |
2733 | GNUNET_STATISTICS_update (plugin->env->stats, | 2471 | GNUNET_STATISTICS_update (plugin->env->stats, |
2734 | "# UDP, total, bytes, sent, failure", | 2472 | "# UDP, total, bytes, sent, failure", sent, GNUNET_NO); |
2735 | sent, GNUNET_NO); | ||
2736 | GNUNET_STATISTICS_update (plugin->env->stats, | 2473 | GNUNET_STATISTICS_update (plugin->env->stats, |
2737 | "# UDP, total, messages, sent, failure", | 2474 | "# UDP, total, messages, sent, failure", 1, GNUNET_NO); |
2738 | 1, GNUNET_NO); | ||
2739 | } | 2475 | } |
2740 | else | 2476 | else |
2741 | { | 2477 | { |
2742 | /* Success */ | 2478 | /* Success */ |
2743 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2479 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2744 | "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", | 2480 | "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", |
2745 | (unsigned int) (udpw->msg_size), GNUNET_i2s(&udpw->session->target) ,GNUNET_a2s (sa, slen), (int) sent, | 2481 | (unsigned int ) (udpw->msg_size), GNUNET_i2s (&udpw->session->target), |
2746 | (sent < 0) ? STRERROR (errno) : "ok"); | 2482 | GNUNET_a2s (sa, slen), (int ) sent, |
2483 | (sent < 0) ? STRERROR (errno) : "ok"); | ||
2747 | GNUNET_STATISTICS_update (plugin->env->stats, | 2484 | GNUNET_STATISTICS_update (plugin->env->stats, |
2748 | "# UDP, total, bytes, sent, success", | 2485 | "# UDP, total, bytes, sent, success", sent, GNUNET_NO); |
2749 | sent, GNUNET_NO); | ||
2750 | GNUNET_STATISTICS_update (plugin->env->stats, | 2486 | GNUNET_STATISTICS_update (plugin->env->stats, |
2751 | "# UDP, total, messages, sent, success", | 2487 | "# UDP, total, messages, sent, success", 1, GNUNET_NO); |
2752 | 1, GNUNET_NO); | ||
2753 | if (NULL != udpw->frag_ctx) | 2488 | if (NULL != udpw->frag_ctx) |
2754 | udpw->frag_ctx->on_wire_size += udpw->msg_size; | 2489 | udpw->frag_ctx->on_wire_size += udpw->msg_size; |
2755 | call_continuation (udpw, GNUNET_OK); | 2490 | call_continuation (udpw, GNUNET_OK); |
2756 | } | 2491 | } |
2757 | dequeue (plugin, udpw); | 2492 | dequeue (plugin, udpw); |
2758 | GNUNET_free (udpw); | 2493 | GNUNET_free(udpw); |
2759 | udpw = NULL; | 2494 | udpw = NULL; |
2760 | 2495 | ||
2761 | return sent; | 2496 | return sent; |
2762 | } | 2497 | } |
2763 | 2498 | ||
2764 | |||
2765 | /** | 2499 | /** |
2766 | * We have been notified that our readset has something to read. We don't | 2500 | * We have been notified that our readset has something to read. We don't |
2767 | * know which socket needs to be read, so we have to check each one | 2501 | * know which socket needs to be read, so we have to check each one |
@@ -2778,19 +2512,17 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2778 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; | 2512 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; |
2779 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 2513 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
2780 | return; | 2514 | return; |
2781 | if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && | 2515 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) |
2782 | (NULL != plugin->sockv4) && | 2516 | && (NULL != plugin->sockv4) |
2783 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)) ) | 2517 | && (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4))) |
2784 | udp_select_read (plugin, plugin->sockv4); | 2518 | udp_select_read (plugin, plugin->sockv4); |
2785 | if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && | 2519 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) |
2786 | (NULL != plugin->sockv4) && | 2520 | && (NULL != plugin->sockv4) && (NULL != plugin->ipv4_queue_head) |
2787 | (NULL != plugin->ipv4_queue_head) && | 2521 | && (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv4))) |
2788 | (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv4)) ) | ||
2789 | udp_select_send (plugin, plugin->sockv4); | 2522 | udp_select_send (plugin, plugin->sockv4); |
2790 | schedule_select (plugin); | 2523 | schedule_select (plugin); |
2791 | } | 2524 | } |
2792 | 2525 | ||
2793 | |||
2794 | /** | 2526 | /** |
2795 | * We have been notified that our readset has something to read. We don't | 2527 | * We have been notified that our readset has something to read. We don't |
2796 | * know which socket needs to be read, so we have to check each one | 2528 | * know which socket needs to be read, so we have to check each one |
@@ -2807,26 +2539,23 @@ udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2807 | plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 2539 | plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
2808 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 2540 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
2809 | return; | 2541 | return; |
2810 | if ( ((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0) && | 2542 | if (((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0) |
2811 | (NULL != plugin->sockv6) && | 2543 | && (NULL != plugin->sockv6) |
2812 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)) ) | 2544 | && (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6))) |
2813 | udp_select_read (plugin, plugin->sockv6); | 2545 | udp_select_read (plugin, plugin->sockv6); |
2814 | if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && | 2546 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) |
2815 | (NULL != plugin->sockv6) && (plugin->ipv6_queue_head != NULL) && | 2547 | && (NULL != plugin->sockv6) && (plugin->ipv6_queue_head != NULL )&& |
2816 | (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv6)) ) | 2548 | (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv6)) )udp_select_send (plugin, plugin->sockv6); |
2817 | udp_select_send (plugin, plugin->sockv6); | ||
2818 | schedule_select (plugin); | 2549 | schedule_select (plugin); |
2819 | } | 2550 | } |
2820 | 2551 | ||
2821 | |||
2822 | /** | 2552 | /** |
2823 | * | 2553 | * |
2824 | * @return number of sockets that were successfully bound | 2554 | * @return number of sockets that were successfully bound |
2825 | */ | 2555 | */ |
2826 | static int | 2556 | static int |
2827 | setup_sockets (struct Plugin *plugin, | 2557 | setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, |
2828 | const struct sockaddr_in6 *bind_v6, | 2558 | const struct sockaddr_in *bind_v4) |
2829 | const struct sockaddr_in *bind_v4) | ||
2830 | { | 2559 | { |
2831 | int tries; | 2560 | int tries; |
2832 | int sockets_created = 0; | 2561 | int sockets_created = 0; |
@@ -2845,46 +2574,52 @@ setup_sockets (struct Plugin *plugin, | |||
2845 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); | 2574 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); |
2846 | if (NULL == plugin->sockv6) | 2575 | if (NULL == plugin->sockv6) |
2847 | { | 2576 | { |
2848 | LOG (GNUNET_ERROR_TYPE_WARNING, "Disabling IPv6 since it is not supported on this system!\n"); | 2577 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2578 | "Disabling IPv6 since it is not supported on this system!\n"); | ||
2849 | plugin->enable_ipv6 = GNUNET_NO; | 2579 | plugin->enable_ipv6 = GNUNET_NO; |
2850 | } | 2580 | } |
2851 | else | 2581 | else |
2852 | { | 2582 | { |
2853 | memset (&server_addrv6, '\0', sizeof (struct sockaddr_in6)); | 2583 | memset (&server_addrv6, '\0', sizeof(struct sockaddr_in6)); |
2854 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2584 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2855 | server_addrv6.sin6_len = sizeof (struct sockaddr_in6); | 2585 | server_addrv6.sin6_len = sizeof (struct sockaddr_in6); |
2856 | #endif | 2586 | #endif |
2857 | server_addrv6.sin6_family = AF_INET6; | 2587 | server_addrv6.sin6_family = AF_INET6; |
2858 | if (NULL != bind_v6) | 2588 | if (NULL != bind_v6) |
2859 | server_addrv6.sin6_addr = bind_v6->sin6_addr; | 2589 | server_addrv6.sin6_addr = bind_v6->sin6_addr; |
2860 | else | 2590 | else |
2861 | server_addrv6.sin6_addr = in6addr_any; | 2591 | server_addrv6.sin6_addr = in6addr_any; |
2862 | 2592 | ||
2863 | if (0 == plugin->port) /* autodetect */ | 2593 | if (0 == plugin->port) /* autodetect */ |
2864 | server_addrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); | 2594 | server_addrv6.sin6_port = htons ( |
2595 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) | ||
2596 | + 32000); | ||
2865 | else | 2597 | else |
2866 | server_addrv6.sin6_port = htons (plugin->port); | 2598 | server_addrv6.sin6_port = htons (plugin->port); |
2867 | addrlen = sizeof (struct sockaddr_in6); | 2599 | addrlen = sizeof(struct sockaddr_in6); |
2868 | server_addr = (struct sockaddr *) &server_addrv6; | 2600 | server_addr = (struct sockaddr *) &server_addrv6; |
2869 | 2601 | ||
2870 | tries = 0; | 2602 | tries = 0; |
2871 | while (tries < 10) | 2603 | while (tries < 10) |
2872 | { | 2604 | { |
2873 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 `%s'\n", | 2605 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 `%s'\n", |
2874 | GNUNET_a2s (server_addr, addrlen)); | 2606 | GNUNET_a2s (server_addr, addrlen)); |
2875 | /* binding */ | 2607 | /* binding */ |
2876 | if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv6, | 2608 | if (GNUNET_OK |
2877 | server_addr, addrlen)) | 2609 | == GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, |
2878 | break; | 2610 | addrlen)) |
2879 | eno = errno; | 2611 | break; |
2880 | if (0 != plugin->port) | 2612 | eno = errno; |
2881 | { | 2613 | if (0 != plugin->port) |
2882 | tries = 10; /* fail */ | 2614 | { |
2883 | break; /* bind failed on specific port */ | 2615 | tries = 10; /* fail */ |
2884 | } | 2616 | break; /* bind failed on specific port */ |
2885 | /* autodetect */ | 2617 | } |
2886 | server_addrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); | 2618 | /* autodetect */ |
2887 | tries ++; | 2619 | server_addrv6.sin6_port = htons ( |
2620 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) | ||
2621 | + 32000); | ||
2622 | tries++; | ||
2888 | } | 2623 | } |
2889 | if (tries >= 10) | 2624 | if (tries >= 10) |
2890 | { | 2625 | { |
@@ -2893,21 +2628,18 @@ setup_sockets (struct Plugin *plugin, | |||
2893 | plugin->sockv6 = NULL; | 2628 | plugin->sockv6 = NULL; |
2894 | } | 2629 | } |
2895 | 2630 | ||
2896 | if (plugin->sockv6 != NULL) | 2631 | if (plugin->sockv6 != NULL ) |
2897 | { | 2632 | { |
2898 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2633 | LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv6 socket created on port %s\n", |
2899 | "IPv6 socket created on port %s\n", | 2634 | GNUNET_a2s (server_addr, addrlen)); |
2900 | GNUNET_a2s (server_addr, addrlen)); | ||
2901 | addrs[sockets_created] = (struct sockaddr *) &server_addrv6; | 2635 | addrs[sockets_created] = (struct sockaddr *) &server_addrv6; |
2902 | addrlens[sockets_created] = sizeof (struct sockaddr_in6); | 2636 | addrlens[sockets_created] = sizeof(struct sockaddr_in6); |
2903 | sockets_created++; | 2637 | sockets_created++; |
2904 | } | 2638 | } |
2905 | else | 2639 | else |
2906 | { | 2640 | { |
2907 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2641 | LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to bind UDP socket to %s: %s\n", |
2908 | "Failed to bind UDP socket to %s: %s\n", | 2642 | GNUNET_a2s (server_addr, addrlen), STRERROR (eno)); |
2909 | GNUNET_a2s (server_addr, addrlen), | ||
2910 | STRERROR (eno)); | ||
2911 | } | 2643 | } |
2912 | } | 2644 | } |
2913 | } | 2645 | } |
@@ -2917,13 +2649,14 @@ setup_sockets (struct Plugin *plugin, | |||
2917 | plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); | 2649 | plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); |
2918 | if (NULL == plugin->sockv4) | 2650 | if (NULL == plugin->sockv4) |
2919 | { | 2651 | { |
2920 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); | 2652 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "socket"); |
2921 | LOG (GNUNET_ERROR_TYPE_WARNING, "Disabling IPv4 since it is not supported on this system!\n"); | 2653 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2654 | "Disabling IPv4 since it is not supported on this system!\n"); | ||
2922 | plugin->enable_ipv4 = GNUNET_NO; | 2655 | plugin->enable_ipv4 = GNUNET_NO; |
2923 | } | 2656 | } |
2924 | else | 2657 | else |
2925 | { | 2658 | { |
2926 | memset (&server_addrv4, '\0', sizeof (struct sockaddr_in)); | 2659 | memset (&server_addrv4, '\0', sizeof(struct sockaddr_in)); |
2927 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2660 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2928 | server_addrv4.sin_len = sizeof (struct sockaddr_in); | 2661 | server_addrv4.sin_len = sizeof (struct sockaddr_in); |
2929 | #endif | 2662 | #endif |
@@ -2935,34 +2668,37 @@ setup_sockets (struct Plugin *plugin, | |||
2935 | 2668 | ||
2936 | if (0 == plugin->port) | 2669 | if (0 == plugin->port) |
2937 | /* autodetect */ | 2670 | /* autodetect */ |
2938 | server_addrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); | 2671 | server_addrv4.sin_port = htons ( |
2672 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) | ||
2673 | + 32000); | ||
2939 | else | 2674 | else |
2940 | server_addrv4.sin_port = htons (plugin->port); | 2675 | server_addrv4.sin_port = htons (plugin->port); |
2941 | 2676 | ||
2942 | 2677 | addrlen = sizeof(struct sockaddr_in); | |
2943 | addrlen = sizeof (struct sockaddr_in); | ||
2944 | server_addr = (struct sockaddr *) &server_addrv4; | 2678 | server_addr = (struct sockaddr *) &server_addrv4; |
2945 | 2679 | ||
2946 | tries = 0; | 2680 | tries = 0; |
2947 | while (tries < 10) | 2681 | while (tries < 10) |
2948 | { | 2682 | { |
2949 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 `%s'\n", | 2683 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 `%s'\n", |
2950 | GNUNET_a2s (server_addr, addrlen)); | 2684 | GNUNET_a2s (server_addr, addrlen)); |
2951 | 2685 | ||
2952 | /* binding */ | 2686 | /* binding */ |
2953 | if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv4, | 2687 | if (GNUNET_OK |
2954 | server_addr, addrlen)) | 2688 | == GNUNET_NETWORK_socket_bind (plugin->sockv4, server_addr, addrlen)) |
2955 | break; | 2689 | break; |
2956 | eno = errno; | 2690 | eno = errno; |
2957 | if (0 != plugin->port) | 2691 | if (0 != plugin->port) |
2958 | { | 2692 | { |
2959 | tries = 10; /* fail */ | 2693 | tries = 10; /* fail */ |
2960 | break; /* bind failed on specific port */ | 2694 | break; /* bind failed on specific port */ |
2961 | } | 2695 | } |
2962 | 2696 | ||
2963 | /* autodetect */ | 2697 | /* autodetect */ |
2964 | server_addrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); | 2698 | server_addrv4.sin_port = htons ( |
2965 | tries ++; | 2699 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) |
2700 | + 32000); | ||
2701 | tries++; | ||
2966 | } | 2702 | } |
2967 | 2703 | ||
2968 | if (tries >= 10) | 2704 | if (tries >= 10) |
@@ -2972,40 +2708,39 @@ setup_sockets (struct Plugin *plugin, | |||
2972 | plugin->sockv4 = NULL; | 2708 | plugin->sockv4 = NULL; |
2973 | } | 2709 | } |
2974 | 2710 | ||
2975 | if (plugin->sockv4 != NULL) | 2711 | if (plugin->sockv4 != NULL ) |
2976 | { | 2712 | { |
2977 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2713 | LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv4 socket created on port %s\n", |
2978 | "IPv4 socket created on port %s\n", GNUNET_a2s (server_addr, addrlen)); | 2714 | GNUNET_a2s (server_addr, addrlen)); |
2979 | addrs[sockets_created] = (struct sockaddr *) &server_addrv4; | 2715 | addrs[sockets_created] = (struct sockaddr *) &server_addrv4; |
2980 | addrlens[sockets_created] = sizeof (struct sockaddr_in); | 2716 | addrlens[sockets_created] = sizeof(struct sockaddr_in); |
2981 | sockets_created++; | 2717 | sockets_created++; |
2982 | } | 2718 | } |
2983 | else | 2719 | else |
2984 | { | 2720 | { |
2985 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2721 | LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to bind UDP socket to %s: %s\n", |
2986 | "Failed to bind UDP socket to %s: %s\n", | 2722 | GNUNET_a2s (server_addr, addrlen), STRERROR (eno)); |
2987 | GNUNET_a2s (server_addr, addrlen), STRERROR (eno)); | ||
2988 | } | 2723 | } |
2989 | } | 2724 | } |
2990 | 2725 | ||
2991 | if (0 == sockets_created) | 2726 | if (0 == sockets_created) |
2992 | { | 2727 | { |
2993 | LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); | 2728 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); |
2994 | return 0; /* No sockets created, return */ | 2729 | return 0; /* No sockets created, return */ |
2995 | } | 2730 | } |
2996 | 2731 | ||
2997 | /* Create file descriptors */ | 2732 | /* Create file descriptors */ |
2998 | if (plugin->enable_ipv4 == GNUNET_YES) | 2733 | if (plugin->enable_ipv4 == GNUNET_YES) |
2999 | { | 2734 | { |
3000 | plugin->rs_v4 = GNUNET_NETWORK_fdset_create (); | 2735 | plugin->rs_v4 = GNUNET_NETWORK_fdset_create (); |
3001 | plugin->ws_v4 = GNUNET_NETWORK_fdset_create (); | 2736 | plugin->ws_v4 = GNUNET_NETWORK_fdset_create (); |
3002 | GNUNET_NETWORK_fdset_zero (plugin->rs_v4); | 2737 | GNUNET_NETWORK_fdset_zero (plugin->rs_v4); |
3003 | GNUNET_NETWORK_fdset_zero (plugin->ws_v4); | 2738 | GNUNET_NETWORK_fdset_zero (plugin->ws_v4); |
3004 | if (NULL != plugin->sockv4) | 2739 | if (NULL != plugin->sockv4) |
3005 | { | 2740 | { |
3006 | GNUNET_NETWORK_fdset_set (plugin->rs_v4, plugin->sockv4); | 2741 | GNUNET_NETWORK_fdset_set (plugin->rs_v4, plugin->sockv4); |
3007 | GNUNET_NETWORK_fdset_set (plugin->ws_v4, plugin->sockv4); | 2742 | GNUNET_NETWORK_fdset_set (plugin->ws_v4, plugin->sockv4); |
3008 | } | 2743 | } |
3009 | } | 2744 | } |
3010 | 2745 | ||
3011 | if (plugin->enable_ipv6 == GNUNET_YES) | 2746 | if (plugin->enable_ipv6 == GNUNET_YES) |
@@ -3022,16 +2757,13 @@ setup_sockets (struct Plugin *plugin, | |||
3022 | } | 2757 | } |
3023 | 2758 | ||
3024 | schedule_select (plugin); | 2759 | schedule_select (plugin); |
3025 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, | 2760 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, GNUNET_NO, plugin->port, |
3026 | GNUNET_NO, plugin->port, | 2761 | sockets_created, (const struct sockaddr **) addrs, addrlens, |
3027 | sockets_created, | 2762 | &udp_nat_port_map_callback, NULL, plugin); |
3028 | (const struct sockaddr **) addrs, addrlens, | ||
3029 | &udp_nat_port_map_callback, NULL, plugin); | ||
3030 | 2763 | ||
3031 | return sockets_created; | 2764 | return sockets_created; |
3032 | } | 2765 | } |
3033 | 2766 | ||
3034 | |||
3035 | /** | 2767 | /** |
3036 | * The exported method. Makes the core api available via a global and | 2768 | * The exported method. Makes the core api available via a global and |
3037 | * returns the udp transport API. | 2769 | * returns the udp transport API. |
@@ -3064,7 +2796,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3064 | if (NULL == env->receive) | 2796 | if (NULL == env->receive) |
3065 | { | 2797 | { |
3066 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 2798 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
3067 | initialze the plugin or the API */ | 2799 | initialze the plugin or the API */ |
3068 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 2800 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
3069 | api->cls = NULL; | 2801 | api->cls = NULL; |
3070 | api->address_pretty_printer = &udp_plugin_address_pretty_printer; | 2802 | api->address_pretty_printer = &udp_plugin_address_pretty_printer; |
@@ -3073,106 +2805,105 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3073 | return api; | 2805 | return api; |
3074 | } | 2806 | } |
3075 | 2807 | ||
3076 | GNUNET_assert (NULL != env->stats); | 2808 | GNUNET_assert(NULL != env->stats); |
3077 | 2809 | ||
3078 | /* Get port number: port == 0 : autodetect a port, | 2810 | /* Get port number: port == 0 : autodetect a port, |
3079 | * > 0 : use this port, not given : 2086 default */ | 2811 | * > 0 : use this port, not given : 2086 default */ |
3080 | if (GNUNET_OK != | 2812 | if (GNUNET_OK |
3081 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT", | 2813 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
3082 | &port)) | 2814 | "PORT", &port)) |
3083 | port = 2086; | 2815 | port = 2086; |
3084 | if (GNUNET_OK != | 2816 | if (GNUNET_OK |
3085 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", | 2817 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
3086 | "ADVERTISED_PORT", &aport)) | 2818 | "ADVERTISED_PORT", &aport)) |
3087 | aport = port; | 2819 | aport = port; |
3088 | if (port > 65535) | 2820 | if (port > 65535) |
3089 | { | 2821 | { |
3090 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2822 | LOG(GNUNET_ERROR_TYPE_WARNING, |
3091 | _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port, | 2823 | _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port, |
3092 | 65535); | 2824 | 65535); |
3093 | return NULL; | 2825 | return NULL ; |
3094 | } | 2826 | } |
3095 | 2827 | ||
3096 | /* Protocols */ | 2828 | /* Protocols */ |
3097 | if ((GNUNET_YES == | 2829 | if ((GNUNET_YES |
3098 | GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", | 2830 | == GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6"))) |
3099 | "DISABLEV6"))) | ||
3100 | enable_v6 = GNUNET_NO; | 2831 | enable_v6 = GNUNET_NO; |
3101 | else | 2832 | else |
3102 | enable_v6 = GNUNET_YES; | 2833 | enable_v6 = GNUNET_YES; |
3103 | 2834 | ||
3104 | /* Addresses */ | 2835 | /* Addresses */ |
3105 | have_bind4 = GNUNET_NO; | 2836 | have_bind4 = GNUNET_NO; |
3106 | memset (&server_addrv4, 0, sizeof (server_addrv4)); | 2837 | memset (&server_addrv4, 0, sizeof(server_addrv4)); |
3107 | if (GNUNET_YES == | 2838 | if (GNUNET_YES |
3108 | GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", | 2839 | == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", |
3109 | "BINDTO", &bind4_address)) | 2840 | "BINDTO", &bind4_address)) |
3110 | { | 2841 | { |
3111 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2842 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3112 | "Binding udp plugin to specific address: `%s'\n", | 2843 | "Binding udp plugin to specific address: `%s'\n", bind4_address); |
3113 | bind4_address); | ||
3114 | if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) | 2844 | if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) |
3115 | { | 2845 | { |
3116 | GNUNET_free (bind4_address); | 2846 | GNUNET_free(bind4_address); |
3117 | return NULL; | 2847 | return NULL ; |
3118 | } | 2848 | } |
3119 | have_bind4 = GNUNET_YES; | 2849 | have_bind4 = GNUNET_YES; |
3120 | } | 2850 | } |
3121 | GNUNET_free_non_null (bind4_address); | 2851 | GNUNET_free_non_null(bind4_address); |
3122 | have_bind6 = GNUNET_NO; | 2852 | have_bind6 = GNUNET_NO; |
3123 | memset (&server_addrv6, 0, sizeof (server_addrv6)); | 2853 | memset (&server_addrv6, 0, sizeof(server_addrv6)); |
3124 | if (GNUNET_YES == | 2854 | if (GNUNET_YES |
3125 | GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", | 2855 | == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", |
3126 | "BINDTO6", &bind6_address)) | 2856 | "BINDTO6", &bind6_address)) |
3127 | { | 2857 | { |
3128 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2858 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3129 | "Binding udp plugin to specific address: `%s'\n", | 2859 | "Binding udp plugin to specific address: `%s'\n", bind6_address); |
3130 | bind6_address); | 2860 | if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) |
3131 | if (1 != | ||
3132 | inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) | ||
3133 | { | 2861 | { |
3134 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), | 2862 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), |
3135 | bind6_address); | 2863 | bind6_address); |
3136 | GNUNET_free (bind6_address); | 2864 | GNUNET_free(bind6_address); |
3137 | return NULL; | 2865 | return NULL ; |
3138 | } | 2866 | } |
3139 | have_bind6 = GNUNET_YES; | 2867 | have_bind6 = GNUNET_YES; |
3140 | } | 2868 | } |
3141 | GNUNET_free_non_null (bind6_address); | 2869 | GNUNET_free_non_null(bind6_address); |
3142 | 2870 | ||
3143 | /* Initialize my flags */ | 2871 | /* Initialize my flags */ |
3144 | myoptions = 0; | 2872 | myoptions = 0; |
3145 | 2873 | ||
3146 | /* Enable neighbour discovery */ | 2874 | /* Enable neighbour discovery */ |
3147 | enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp", | 2875 | enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, |
3148 | "BROADCAST"); | 2876 | "transport-udp", "BROADCAST"); |
3149 | if (enable_broadcasting == GNUNET_SYSERR) | 2877 | if (enable_broadcasting == GNUNET_SYSERR) |
3150 | enable_broadcasting = GNUNET_NO; | 2878 | enable_broadcasting = GNUNET_NO; |
3151 | 2879 | ||
3152 | enable_broadcasting_recv = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp", | 2880 | enable_broadcasting_recv = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, |
3153 | "BROADCAST_RECEIVE"); | 2881 | "transport-udp", "BROADCAST_RECEIVE"); |
3154 | if (enable_broadcasting_recv == GNUNET_SYSERR) | 2882 | if (enable_broadcasting_recv == GNUNET_SYSERR) |
3155 | enable_broadcasting_recv = GNUNET_YES; | 2883 | enable_broadcasting_recv = GNUNET_YES; |
3156 | 2884 | ||
3157 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", | 2885 | if (GNUNET_SYSERR |
3158 | "BROADCAST_INTERVAL", &fancy_interval)) | 2886 | == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", |
2887 | "BROADCAST_INTERVAL", &fancy_interval)) | ||
3159 | { | 2888 | { |
3160 | interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2889 | interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); |
3161 | } | 2890 | } |
3162 | else | 2891 | else |
3163 | { | 2892 | { |
3164 | if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_time_to_relative(fancy_interval, &interval)) | 2893 | if (GNUNET_SYSERR |
3165 | { | 2894 | == GNUNET_STRINGS_fancy_time_to_relative (fancy_interval, &interval)) |
3166 | interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | 2895 | { |
3167 | } | 2896 | interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); |
3168 | GNUNET_free (fancy_interval); | 2897 | } |
2898 | GNUNET_free(fancy_interval); | ||
3169 | } | 2899 | } |
3170 | 2900 | ||
3171 | /* Maximum datarate */ | 2901 | /* Maximum datarate */ |
3172 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", | 2902 | if (GNUNET_OK |
3173 | "MAX_BPS", &udp_max_bps)) | 2903 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
2904 | "MAX_BPS", &udp_max_bps)) | ||
3174 | { | 2905 | { |
3175 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ | 2906 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ |
3176 | } | 2907 | } |
3177 | 2908 | ||
3178 | p = GNUNET_new (struct Plugin); | 2909 | p = GNUNET_new (struct Plugin); |
@@ -3185,7 +2916,8 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3185 | p->enable_broadcasting_receiving = enable_broadcasting_recv; | 2916 | p->enable_broadcasting_receiving = enable_broadcasting_recv; |
3186 | p->env = env; | 2917 | p->env = env; |
3187 | p->sessions = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 2918 | p->sessions = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
3188 | p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2919 | p->defrag_ctxs = GNUNET_CONTAINER_heap_create ( |
2920 | GNUNET_CONTAINER_HEAP_ORDER_MIN); | ||
3189 | p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, p); | 2921 | p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, p); |
3190 | GNUNET_BANDWIDTH_tracker_init (&p->tracker, | 2922 | GNUNET_BANDWIDTH_tracker_init (&p->tracker, |
3191 | GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 30); | 2923 | GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 30); |
@@ -3197,7 +2929,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3197 | if ((res == 0) || ((p->sockv4 == NULL )&& (p->sockv6 == NULL))) | 2929 | if ((res == 0) || ((p->sockv4 == NULL )&& (p->sockv6 == NULL))) |
3198 | { | 2930 | { |
3199 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2931 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3200 | _("Failed to create network sockets, plugin failed\n")); | 2932 | _("Failed to create network sockets, plugin failed\n")); |
3201 | GNUNET_CONTAINER_multipeermap_destroy (p->sessions); | 2933 | GNUNET_CONTAINER_multipeermap_destroy (p->sessions); |
3202 | GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); | 2934 | GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); |
3203 | GNUNET_SERVER_mst_destroy (p->mst); | 2935 | GNUNET_SERVER_mst_destroy (p->mst); |
@@ -3225,23 +2957,19 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3225 | return api; | 2957 | return api; |
3226 | } | 2958 | } |
3227 | 2959 | ||
3228 | |||
3229 | static int | 2960 | static int |
3230 | heap_cleanup_iterator (void *cls, | 2961 | heap_cleanup_iterator (void *cls, struct GNUNET_CONTAINER_HeapNode *node, |
3231 | struct GNUNET_CONTAINER_HeapNode *node, | 2962 | void *element, GNUNET_CONTAINER_HeapCostType cost) |
3232 | void *element, | ||
3233 | GNUNET_CONTAINER_HeapCostType cost) | ||
3234 | { | 2963 | { |
3235 | struct DefragContext * d_ctx = element; | 2964 | struct DefragContext * d_ctx = element; |
3236 | 2965 | ||
3237 | GNUNET_CONTAINER_heap_remove_node (node); | 2966 | GNUNET_CONTAINER_heap_remove_node (node); |
3238 | GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag); | 2967 | GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); |
3239 | GNUNET_free (d_ctx); | 2968 | GNUNET_free(d_ctx); |
3240 | 2969 | ||
3241 | return GNUNET_YES; | 2970 | return GNUNET_YES; |
3242 | } | 2971 | } |
3243 | 2972 | ||
3244 | |||
3245 | /** | 2973 | /** |
3246 | * The exported method. Makes the core api available via a global and | 2974 | * The exported method. Makes the core api available via a global and |
3247 | * returns the udp transport API. | 2975 | * returns the udp transport API. |
@@ -3259,17 +2987,17 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3259 | 2987 | ||
3260 | if (NULL == plugin) | 2988 | if (NULL == plugin) |
3261 | { | 2989 | { |
3262 | GNUNET_free (api); | 2990 | GNUNET_free(api); |
3263 | return NULL; | 2991 | return NULL ; |
3264 | } | 2992 | } |
3265 | 2993 | ||
3266 | stop_broadcast (plugin); | 2994 | stop_broadcast (plugin); |
3267 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) | 2995 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK ) |
3268 | { | 2996 | { |
3269 | GNUNET_SCHEDULER_cancel (plugin->select_task); | 2997 | GNUNET_SCHEDULER_cancel (plugin->select_task); |
3270 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; | 2998 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; |
3271 | } | 2999 | } |
3272 | if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK) | 3000 | if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK ) |
3273 | { | 3001 | { |
3274 | GNUNET_SCHEDULER_cancel (plugin->select_task_v6); | 3002 | GNUNET_SCHEDULER_cancel (plugin->select_task_v6); |
3275 | plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 3003 | plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
@@ -3280,7 +3008,7 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3280 | { | 3008 | { |
3281 | if (NULL != plugin->sockv4) | 3009 | if (NULL != plugin->sockv4) |
3282 | { | 3010 | { |
3283 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); | 3011 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); |
3284 | plugin->sockv4 = NULL; | 3012 | plugin->sockv4 = NULL; |
3285 | } | 3013 | } |
3286 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); | 3014 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); |
@@ -3290,7 +3018,7 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3290 | { | 3018 | { |
3291 | if (NULL != plugin->sockv6) | 3019 | if (NULL != plugin->sockv6) |
3292 | { | 3020 | { |
3293 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); | 3021 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); |
3294 | plugin->sockv6 = NULL; | 3022 | plugin->sockv6 = NULL; |
3295 | 3023 | ||
3296 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); | 3024 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); |
@@ -3304,60 +3032,60 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3304 | } | 3032 | } |
3305 | if (NULL != plugin->defrag_ctxs) | 3033 | if (NULL != plugin->defrag_ctxs) |
3306 | { | 3034 | { |
3307 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, | 3035 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, heap_cleanup_iterator, |
3308 | heap_cleanup_iterator, NULL); | 3036 | NULL ); |
3309 | GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); | 3037 | GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); |
3310 | plugin->defrag_ctxs = NULL; | 3038 | plugin->defrag_ctxs = NULL; |
3311 | } | 3039 | } |
3312 | if (plugin->mst != NULL) | 3040 | if (plugin->mst != NULL ) |
3313 | { | 3041 | { |
3314 | GNUNET_SERVER_mst_destroy(plugin->mst); | 3042 | GNUNET_SERVER_mst_destroy (plugin->mst); |
3315 | plugin->mst = NULL; | 3043 | plugin->mst = NULL; |
3316 | } | 3044 | } |
3317 | 3045 | ||
3318 | /* Clean up leftover messages */ | 3046 | /* Clean up leftover messages */ |
3319 | struct UDP_MessageWrapper * udpw; | 3047 | struct UDP_MessageWrapper * udpw; |
3320 | udpw = plugin->ipv4_queue_head; | 3048 | udpw = plugin->ipv4_queue_head; |
3321 | while (udpw != NULL) | 3049 | while (udpw != NULL ) |
3322 | { | 3050 | { |
3323 | struct UDP_MessageWrapper *tmp = udpw->next; | 3051 | struct UDP_MessageWrapper *tmp = udpw->next; |
3324 | dequeue (plugin, udpw); | 3052 | dequeue (plugin, udpw); |
3325 | call_continuation(udpw, GNUNET_SYSERR); | 3053 | call_continuation (udpw, GNUNET_SYSERR); |
3326 | GNUNET_free (udpw); | 3054 | GNUNET_free(udpw); |
3327 | 3055 | ||
3328 | udpw = tmp; | 3056 | udpw = tmp; |
3329 | } | 3057 | } |
3330 | udpw = plugin->ipv6_queue_head; | 3058 | udpw = plugin->ipv6_queue_head; |
3331 | while (udpw != NULL) | 3059 | while (udpw != NULL ) |
3332 | { | 3060 | { |
3333 | struct UDP_MessageWrapper *tmp = udpw->next; | 3061 | struct UDP_MessageWrapper *tmp = udpw->next; |
3334 | dequeue (plugin, udpw); | 3062 | dequeue (plugin, udpw); |
3335 | call_continuation(udpw, GNUNET_SYSERR); | 3063 | call_continuation (udpw, GNUNET_SYSERR); |
3336 | GNUNET_free (udpw); | 3064 | GNUNET_free(udpw); |
3337 | 3065 | ||
3338 | udpw = tmp; | 3066 | udpw = tmp; |
3339 | } | 3067 | } |
3340 | 3068 | ||
3341 | /* Clean up sessions */ | 3069 | /* Clean up sessions */ |
3342 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3070 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up sessions\n"); |
3343 | "Cleaning up sessions\n"); | 3071 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, |
3344 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, &disconnect_and_free_it, plugin); | 3072 | &disconnect_and_free_it, plugin); |
3345 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); | 3073 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); |
3346 | 3074 | ||
3347 | next = ppc_dll_head; | 3075 | next = ppc_dll_head; |
3348 | for (cur = next; NULL != cur; cur = next) | 3076 | for (cur = next; NULL != cur; cur = next) |
3349 | { | 3077 | { |
3350 | next = cur->next; | 3078 | next = cur->next; |
3351 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, cur); | 3079 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, cur); |
3352 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); | 3080 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); |
3353 | GNUNET_SCHEDULER_cancel (cur->timeout_task); | 3081 | GNUNET_SCHEDULER_cancel (cur->timeout_task); |
3354 | GNUNET_free (cur); | 3082 | GNUNET_free(cur); |
3355 | GNUNET_break (0); | 3083 | GNUNET_break(0); |
3356 | } | 3084 | } |
3357 | 3085 | ||
3358 | plugin->nat = NULL; | 3086 | plugin->nat = NULL; |
3359 | GNUNET_free (plugin); | 3087 | GNUNET_free(plugin); |
3360 | GNUNET_free (api); | 3088 | GNUNET_free(api); |
3361 | #if DEBUG_MALLOC | 3089 | #if DEBUG_MALLOC |
3362 | struct Allocation *allocation; | 3090 | struct Allocation *allocation; |
3363 | while (NULL != ahead) | 3091 | while (NULL != ahead) |
@@ -3374,8 +3102,7 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3374 | GNUNET_free (allocator); | 3102 | GNUNET_free (allocator); |
3375 | } | 3103 | } |
3376 | #endif | 3104 | #endif |
3377 | return NULL; | 3105 | return NULL ; |
3378 | } | 3106 | } |
3379 | 3107 | ||
3380 | |||
3381 | /* end of plugin_transport_udp.c */ | 3108 | /* end of plugin_transport_udp.c */ |