aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-04-18 17:03:13 +0000
committerng0 <ng0@n0.is>2019-04-18 17:03:13 +0000
commitceebd916f46aae6dee0bcfb1bba80e47d0cac2d2 (patch)
treeda33dfe7f33b2d57611efa6a89cf5268ebc6158d
parent8f326fde8ba13b6220678f100e2db21c0d1877df (diff)
parentf308b735ee352dc4ceaf72a96c54883414a8e18d (diff)
downloadgnunet-ceebd916f46aae6dee0bcfb1bba80e47d0cac2d2.tar.gz
gnunet-ceebd916f46aae6dee0bcfb1bba80e47d0cac2d2.zip
Merge branch 'master' of gnunet.org:gnunet
-rw-r--r--.dir-locals.el3
-rw-r--r--.gitignore1
-rwxr-xr-xbootstrap3
-rw-r--r--src/include/gnunet_tun_lib.h174
-rw-r--r--src/transport/gnunet-service-tng.c2172
5 files changed, 1054 insertions, 1299 deletions
diff --git a/.dir-locals.el b/.dir-locals.el
index 687863811..29999b944 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -1,5 +1,8 @@
1;; Per-directory local variables for GNU Emacs 23 and later. 1;; Per-directory local variables for GNU Emacs 23 and later.
2 2
3((c-mode
4 (eval add-hook 'before-save-hook #'clang-format-buffer nil t)))
5
3((nil 6((nil
4 . ((fill-column . 78) 7 . ((fill-column . 78)
5 (tab-width . 4) 8 (tab-width . 4)
diff --git a/.gitignore b/.gitignore
index 31cfa5897..e898f41f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@
11*.swp 11*.swp
12*.trs 12*.trs
13*.kdev4 13*.kdev4
14.clang-format
14.deps/ 15.deps/
15.libs/ 16.libs/
16.svn/ 17.svn/
diff --git a/bootstrap b/bootstrap
index 9d9d97b1d..c87f375ea 100755
--- a/bootstrap
+++ b/bootstrap
@@ -3,6 +3,9 @@
3echo "Removing folder 'libltdl'..." 3echo "Removing folder 'libltdl'..."
4rm -rf libltdl 4rm -rf libltdl
5 5
6# Install clang format symlink (if possible)
7ln -s contrib/conf/editors/clang-format .clang-format &> /dev/null
8
6echo "checking for libtoolize / libtool... " 9echo "checking for libtoolize / libtool... "
7 10
8# This is more portable than `which' but comes with 11# This is more portable than `which' but comes with
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h
index 11c43e8b7..c01e641c1 100644
--- a/src/include/gnunet_tun_lib.h
+++ b/src/include/gnunet_tun_lib.h
@@ -11,7 +11,7 @@
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 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -23,10 +23,12 @@
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * 24 *
25 * @file 25 * @file
26 * Standard TCP/IP network structs and IP checksum calculations for TUN interaction 26 * Standard TCP/IP network structs and IP checksum calculations for TUN
27 * interaction
27 * 28 *
28 * @defgroup tun TUN library 29 * @defgroup tun TUN library
29 * Standard TCP/IP network structs and IP checksum calculations for TUN interaction 30 * Standard TCP/IP network structs and IP checksum calculations for TUN
31 * interaction
30 * @{ 32 * @{
31 */ 33 */
32#ifndef GNUNET_TUN_LIB_H 34#ifndef GNUNET_TUN_LIB_H
@@ -96,13 +98,13 @@ struct GNUNET_TUN_Layer2PacketHeader
96struct GNUNET_TUN_IPv4Header 98struct GNUNET_TUN_IPv4Header
97{ 99{
98#if __BYTE_ORDER == __LITTLE_ENDIAN 100#if __BYTE_ORDER == __LITTLE_ENDIAN
99 unsigned int header_length:4 GNUNET_PACKED; 101 unsigned int header_length : 4 GNUNET_PACKED;
100 unsigned int version:4 GNUNET_PACKED; 102 unsigned int version : 4 GNUNET_PACKED;
101#elif __BYTE_ORDER == __BIG_ENDIAN 103#elif __BYTE_ORDER == __BIG_ENDIAN
102 unsigned int version:4 GNUNET_PACKED; 104 unsigned int version : 4 GNUNET_PACKED;
103 unsigned int header_length:4 GNUNET_PACKED; 105 unsigned int header_length : 4 GNUNET_PACKED;
104#else 106#else
105 #error byteorder undefined 107#error byteorder undefined
106#endif 108#endif
107 uint8_t diff_serv; 109 uint8_t diff_serv;
108 110
@@ -116,9 +118,9 @@ struct GNUNET_TUN_IPv4Header
116 */ 118 */
117 uint16_t identification GNUNET_PACKED; 119 uint16_t identification GNUNET_PACKED;
118 120
119 unsigned int flags:3 GNUNET_PACKED; 121 unsigned int flags : 3 GNUNET_PACKED;
120 122
121 unsigned int fragmentation_offset:13 GNUNET_PACKED; 123 unsigned int fragmentation_offset : 13 GNUNET_PACKED;
122 124
123 /** 125 /**
124 * How many more hops can this packet be forwarded? 126 * How many more hops can this packet be forwarded?
@@ -138,12 +140,12 @@ struct GNUNET_TUN_IPv4Header
138 /** 140 /**
139 * Origin of the packet. 141 * Origin of the packet.
140 */ 142 */
141 struct in_addr source_address GNUNET_PACKED; 143 struct in_addr source_address;
142 144
143 /** 145 /**
144 * Destination of the packet. 146 * Destination of the packet.
145 */ 147 */
146 struct in_addr destination_address GNUNET_PACKED; 148 struct in_addr destination_address;
147} GNUNET_GCC_STRUCT_LAYOUT; 149} GNUNET_GCC_STRUCT_LAYOUT;
148 150
149 151
@@ -153,16 +155,16 @@ struct GNUNET_TUN_IPv4Header
153struct GNUNET_TUN_IPv6Header 155struct GNUNET_TUN_IPv6Header
154{ 156{
155#if __BYTE_ORDER == __LITTLE_ENDIAN 157#if __BYTE_ORDER == __LITTLE_ENDIAN
156 unsigned int traffic_class_h:4 GNUNET_PACKED; 158 unsigned int traffic_class_h : 4 GNUNET_PACKED;
157 unsigned int version:4 GNUNET_PACKED; 159 unsigned int version : 4 GNUNET_PACKED;
158 unsigned int traffic_class_l:4 GNUNET_PACKED; 160 unsigned int traffic_class_l : 4 GNUNET_PACKED;
159 unsigned int flow_label:20 GNUNET_PACKED; 161 unsigned int flow_label : 20 GNUNET_PACKED;
160#elif __BYTE_ORDER == __BIG_ENDIAN 162#elif __BYTE_ORDER == __BIG_ENDIAN
161 unsigned int version:4 GNUNET_PACKED; 163 unsigned int version : 4 GNUNET_PACKED;
162 unsigned int traffic_class:8 GNUNET_PACKED; 164 unsigned int traffic_class : 8 GNUNET_PACKED;
163 unsigned int flow_label:20 GNUNET_PACKED; 165 unsigned int flow_label : 20 GNUNET_PACKED;
164#else 166#else
165 #error byteorder undefined 167#error byteorder undefined
166#endif 168#endif
167 /** 169 /**
168 * Length of the payload, excluding this header. 170 * Length of the payload, excluding this header.
@@ -246,7 +248,7 @@ struct GNUNET_TUN_TcpHeader
246 */ 248 */
247 unsigned int reserved : 4 GNUNET_PACKED; 249 unsigned int reserved : 4 GNUNET_PACKED;
248#else 250#else
249 #error byteorder undefined 251#error byteorder undefined
250#endif 252#endif
251 253
252 /** 254 /**
@@ -298,7 +300,6 @@ struct GNUNET_TUN_UdpHeader
298}; 300};
299 301
300 302
301
302/** 303/**
303 * A few common DNS classes (ok, only one is common, but I list a 304 * A few common DNS classes (ok, only one is common, but I list a
304 * couple more to make it clear what we're talking about here). 305 * couple more to make it clear what we're talking about here).
@@ -341,12 +342,12 @@ struct GNUNET_TUN_DnsFlags
341 /** 342 /**
342 * Set to 1 if recursion is desired (client -> server) 343 * Set to 1 if recursion is desired (client -> server)
343 */ 344 */
344 unsigned int recursion_desired : 1 GNUNET_PACKED; 345 unsigned int recursion_desired : 1 GNUNET_PACKED;
345 346
346 /** 347 /**
347 * Set to 1 if message is truncated 348 * Set to 1 if message is truncated
348 */ 349 */
349 unsigned int message_truncated : 1 GNUNET_PACKED; 350 unsigned int message_truncated : 1 GNUNET_PACKED;
350 351
351 /** 352 /**
352 * Set to 1 if this is an authoritative answer 353 * Set to 1 if this is an authoritative answer
@@ -356,48 +357,48 @@ struct GNUNET_TUN_DnsFlags
356 /** 357 /**
357 * See GNUNET_TUN_DNS_OPCODE_ defines. 358 * See GNUNET_TUN_DNS_OPCODE_ defines.
358 */ 359 */
359 unsigned int opcode : 4 GNUNET_PACKED; 360 unsigned int opcode : 4 GNUNET_PACKED;
360 361
361 /** 362 /**
362 * query:0, response:1 363 * query:0, response:1
363 */ 364 */
364 unsigned int query_or_response : 1 GNUNET_PACKED; 365 unsigned int query_or_response : 1 GNUNET_PACKED;
365 366
366 /** 367 /**
367 * See GNUNET_TUN_DNS_RETURN_CODE_ defines. 368 * See GNUNET_TUN_DNS_RETURN_CODE_ defines.
368 */ 369 */
369 unsigned int return_code : 4 GNUNET_PACKED; 370 unsigned int return_code : 4 GNUNET_PACKED;
370 371
371 /** 372 /**
372 * See RFC 4035. 373 * See RFC 4035.
373 */ 374 */
374 unsigned int checking_disabled : 1 GNUNET_PACKED; 375 unsigned int checking_disabled : 1 GNUNET_PACKED;
375 376
376 /** 377 /**
377 * Response has been cryptographically verified, RFC 4035. 378 * Response has been cryptographically verified, RFC 4035.
378 */ 379 */
379 unsigned int authenticated_data : 1 GNUNET_PACKED; 380 unsigned int authenticated_data : 1 GNUNET_PACKED;
380 381
381 /** 382 /**
382 * Always zero. 383 * Always zero.
383 */ 384 */
384 unsigned int zero : 1 GNUNET_PACKED; 385 unsigned int zero : 1 GNUNET_PACKED;
385 386
386 /** 387 /**
387 * Set to 1 if recursion is available (server -> client) 388 * Set to 1 if recursion is available (server -> client)
388 */ 389 */
389 unsigned int recursion_available : 1 GNUNET_PACKED; 390 unsigned int recursion_available : 1 GNUNET_PACKED;
390#elif __BYTE_ORDER == __BIG_ENDIAN 391#elif __BYTE_ORDER == __BIG_ENDIAN
391 392
392 /** 393 /**
393 * query:0, response:1 394 * query:0, response:1
394 */ 395 */
395 unsigned int query_or_response : 1 GNUNET_PACKED; 396 unsigned int query_or_response : 1 GNUNET_PACKED;
396 397
397 /** 398 /**
398 * See GNUNET_TUN_DNS_OPCODE_ defines. 399 * See GNUNET_TUN_DNS_OPCODE_ defines.
399 */ 400 */
400 unsigned int opcode : 4 GNUNET_PACKED; 401 unsigned int opcode : 4 GNUNET_PACKED;
401 402
402 /** 403 /**
403 * Set to 1 if this is an authoritative answer 404 * Set to 1 if this is an authoritative answer
@@ -407,46 +408,45 @@ struct GNUNET_TUN_DnsFlags
407 /** 408 /**
408 * Set to 1 if message is truncated 409 * Set to 1 if message is truncated
409 */ 410 */
410 unsigned int message_truncated : 1 GNUNET_PACKED; 411 unsigned int message_truncated : 1 GNUNET_PACKED;
411 412
412 /** 413 /**
413 * Set to 1 if recursion is desired (client -> server) 414 * Set to 1 if recursion is desired (client -> server)
414 */ 415 */
415 unsigned int recursion_desired : 1 GNUNET_PACKED; 416 unsigned int recursion_desired : 1 GNUNET_PACKED;
416 417
417 418
418 /** 419 /**
419 * Set to 1 if recursion is available (server -> client) 420 * Set to 1 if recursion is available (server -> client)
420 */ 421 */
421 unsigned int recursion_available : 1 GNUNET_PACKED; 422 unsigned int recursion_available : 1 GNUNET_PACKED;
422 423
423 /** 424 /**
424 * Always zero. 425 * Always zero.
425 */ 426 */
426 unsigned int zero : 1 GNUNET_PACKED; 427 unsigned int zero : 1 GNUNET_PACKED;
427 428
428 /** 429 /**
429 * Response has been cryptographically verified, RFC 4035. 430 * Response has been cryptographically verified, RFC 4035.
430 */ 431 */
431 unsigned int authenticated_data : 1 GNUNET_PACKED; 432 unsigned int authenticated_data : 1 GNUNET_PACKED;
432 433
433 /** 434 /**
434 * See RFC 4035. 435 * See RFC 4035.
435 */ 436 */
436 unsigned int checking_disabled : 1 GNUNET_PACKED; 437 unsigned int checking_disabled : 1 GNUNET_PACKED;
437 438
438 /** 439 /**
439 * See GNUNET_TUN_DNS_RETURN_CODE_ defines. 440 * See GNUNET_TUN_DNS_RETURN_CODE_ defines.
440 */ 441 */
441 unsigned int return_code : 4 GNUNET_PACKED; 442 unsigned int return_code : 4 GNUNET_PACKED;
442#else 443#else
443 #error byteorder undefined 444#error byteorder undefined
444#endif 445#endif
445 446
446} GNUNET_GCC_STRUCT_LAYOUT; 447} GNUNET_GCC_STRUCT_LAYOUT;
447 448
448 449
449
450/** 450/**
451 * DNS header. 451 * DNS header.
452 */ 452 */
@@ -683,21 +683,21 @@ struct GNUNET_TUN_DnsRecordLine
683}; 683};
684 684
685 685
686#define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0 686#define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0
687#define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3 687#define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3
688#define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4 688#define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4
689#define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE 5 689#define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE 5
690#define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST 8 690#define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST 8
691#define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT 9 691#define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT 9
692#define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION 10 692#define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION 10
693#define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED 11 693#define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED 11
694 694
695#define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE 1 695#define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE 1
696#define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG 2 696#define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG 2
697#define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED 3 697#define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED 3
698#define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM 4 698#define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM 4
699#define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST 128 699#define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST 128
700#define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY 129 700#define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY 129
701 701
702 702
703/** 703/**
@@ -716,8 +716,8 @@ struct GNUNET_TUN_IcmpHeader
716 */ 716 */
717 struct 717 struct
718 { 718 {
719 uint16_t identifier GNUNET_PACKED; 719 uint16_t identifier GNUNET_PACKED;
720 uint16_t sequence_number GNUNET_PACKED; 720 uint16_t sequence_number GNUNET_PACKED;
721 } echo; 721 } echo;
722 722
723 /** 723 /**
@@ -727,13 +727,14 @@ struct GNUNET_TUN_IcmpHeader
727 { 727 {
728 uint16_t empty GNUNET_PACKED; 728 uint16_t empty GNUNET_PACKED;
729 uint16_t next_hop_mtu GNUNET_PACKED; 729 uint16_t next_hop_mtu GNUNET_PACKED;
730 /* followed by original IP header + first 8 bytes of original IP datagram */ 730 /* followed by original IP header + first 8 bytes of original IP datagram
731 */
731 } destination_unreachable; 732 } destination_unreachable;
732 733
733 /** 734 /**
734 * ICMP Redirect 735 * ICMP Redirect
735 */ 736 */
736 struct in_addr redirect_gateway_address GNUNET_PACKED; 737 struct in_addr redirect_gateway_address;
737 738
738 /** 739 /**
739 * MTU for packets that are too big (IPv6). 740 * MTU for packets that are too big (IPv6).
@@ -741,7 +742,6 @@ struct GNUNET_TUN_IcmpHeader
741 uint32_t packet_too_big_mtu GNUNET_PACKED; 742 uint32_t packet_too_big_mtu GNUNET_PACKED;
742 743
743 } quench; 744 } quench;
744
745}; 745};
746 746
747 747
@@ -753,16 +753,17 @@ GNUNET_NETWORK_STRUCT_END
753 * 753 *
754 * @param ip header to initialize 754 * @param ip header to initialize
755 * @param protocol protocol to use (i.e. IPPROTO_UDP) 755 * @param protocol protocol to use (i.e. IPPROTO_UDP)
756 * @param payload_length number of bytes of payload that follow (excluding IPv4 header) 756 * @param payload_length number of bytes of payload that follow (excluding IPv4
757 * header)
757 * @param src source IP address to use 758 * @param src source IP address to use
758 * @param dst destination IP address to use 759 * @param dst destination IP address to use
759 */ 760 */
760void 761void
761GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, 762GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
762 uint8_t protocol, 763 uint8_t protocol,
763 uint16_t payload_length, 764 uint16_t payload_length,
764 const struct in_addr *src, 765 const struct in_addr *src,
765 const struct in_addr *dst); 766 const struct in_addr *dst);
766 767
767 768
768/** 769/**
@@ -770,16 +771,17 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
770 * 771 *
771 * @param ip header to initialize 772 * @param ip header to initialize
772 * @param protocol protocol to use (i.e. IPPROTO_UDP) 773 * @param protocol protocol to use (i.e. IPPROTO_UDP)
773 * @param payload_length number of bytes of payload that follow (excluding IPv4 header) 774 * @param payload_length number of bytes of payload that follow (excluding IPv4
775 * header)
774 * @param src source IP address to use 776 * @param src source IP address to use
775 * @param dst destination IP address to use 777 * @param dst destination IP address to use
776 */ 778 */
777void 779void
778GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, 780GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
779 uint8_t protocol, 781 uint8_t protocol,
780 uint16_t payload_length, 782 uint16_t payload_length,
781 const struct in6_addr *src, 783 const struct in6_addr *src,
782 const struct in6_addr *dst); 784 const struct in6_addr *dst);
783 785
784/** 786/**
785 * Calculate IPv4 TCP checksum. 787 * Calculate IPv4 TCP checksum.
@@ -791,9 +793,9 @@ GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
791 */ 793 */
792void 794void
793GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, 795GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
794 struct GNUNET_TUN_TcpHeader *tcp, 796 struct GNUNET_TUN_TcpHeader *tcp,
795 const void *payload, 797 const void *payload,
796 uint16_t payload_length); 798 uint16_t payload_length);
797 799
798/** 800/**
799 * Calculate IPv6 TCP checksum. 801 * Calculate IPv6 TCP checksum.
@@ -805,9 +807,9 @@ GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
805 */ 807 */
806void 808void
807GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, 809GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
808 struct GNUNET_TUN_TcpHeader *tcp, 810 struct GNUNET_TUN_TcpHeader *tcp,
809 const void *payload, 811 const void *payload,
810 uint16_t payload_length); 812 uint16_t payload_length);
811 813
812/** 814/**
813 * Calculate IPv4 UDP checksum. 815 * Calculate IPv4 UDP checksum.
@@ -819,9 +821,9 @@ GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
819 */ 821 */
820void 822void
821GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, 823GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
822 struct GNUNET_TUN_UdpHeader *udp, 824 struct GNUNET_TUN_UdpHeader *udp,
823 const void *payload, 825 const void *payload,
824 uint16_t payload_length); 826 uint16_t payload_length);
825 827
826 828
827/** 829/**
@@ -834,9 +836,9 @@ GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
834 */ 836 */
835void 837void
836GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, 838GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
837 struct GNUNET_TUN_UdpHeader *udp, 839 struct GNUNET_TUN_UdpHeader *udp,
838 const void *payload, 840 const void *payload,
839 uint16_t payload_length); 841 uint16_t payload_length);
840 842
841 843
842/** 844/**
@@ -848,8 +850,8 @@ GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
848 */ 850 */
849void 851void
850GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, 852GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
851 const void *payload, 853 const void *payload,
852 uint16_t payload_length); 854 uint16_t payload_length);
853 855
854 856
855/** 857/**
@@ -949,4 +951,4 @@ GNUNET_TUN_compute_service_cadet_port (const struct GNUNET_HashCode *desc,
949 951
950#endif 952#endif
951 953
952/** @} */ /* end of group */ 954/** @} */ /* end of group */
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 27c97860e..bca03574d 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -156,47 +156,55 @@
156 * of seconds we log a warning. Note: this is for testing, 156 * of seconds we log a warning. Note: this is for testing,
157 * the value chosen here might be too aggressively low! 157 * the value chosen here might be too aggressively low!
158 */ 158 */
159#define DELAY_WARN_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 159#define DELAY_WARN_THRESHOLD \
160 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
160 161
161/** 162/**
162 * We only consider queues as "quality" connections when 163 * We only consider queues as "quality" connections when
163 * suppressing the generation of DV initiation messages if 164 * suppressing the generation of DV initiation messages if
164 * the latency of the queue is below this threshold. 165 * the latency of the queue is below this threshold.
165 */ 166 */
166#define DV_QUALITY_RTT_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 167#define DV_QUALITY_RTT_THRESHOLD \
168 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
167 169
168/** 170/**
169 * How long do we consider a DV path valid if we see no 171 * How long do we consider a DV path valid if we see no
170 * further updates on it? Note: the value chosen here might be too low! 172 * further updates on it? Note: the value chosen here might be too low!
171 */ 173 */
172#define DV_PATH_VALIDITY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 174#define DV_PATH_VALIDITY_TIMEOUT \
175 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
173 176
174/** 177/**
175 * How long before paths expire would we like to (re)discover DV paths? Should 178 * How long before paths expire would we like to (re)discover DV paths? Should
176 * be below #DV_PATH_VALIDITY_TIMEOUT. 179 * be below #DV_PATH_VALIDITY_TIMEOUT.
177 */ 180 */
178#define DV_PATH_DISCOVERY_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) 181#define DV_PATH_DISCOVERY_FREQUENCY \
182 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4)
179 183
180/** 184/**
181 * How long are ephemeral keys valid? 185 * How long are ephemeral keys valid?
182 */ 186 */
183#define EPHEMERAL_VALIDITY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) 187#define EPHEMERAL_VALIDITY \
188 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
184 189
185/** 190/**
186 * How long do we keep partially reassembled messages around before giving up? 191 * How long do we keep partially reassembled messages around before giving up?
187 */ 192 */
188#define REASSEMBLY_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) 193#define REASSEMBLY_EXPIRATION \
194 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4)
189 195
190/** 196/**
191 * What is the fastest rate at which we send challenges *if* we keep learning 197 * What is the fastest rate at which we send challenges *if* we keep learning
192 * an address (gossip, DHT, etc.)? 198 * an address (gossip, DHT, etc.)?
193 */ 199 */
194#define FAST_VALIDATION_CHALLENGE_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) 200#define FAST_VALIDATION_CHALLENGE_FREQ \
201 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
195 202
196/** 203/**
197 * What is the slowest rate at which we send challenges? 204 * What is the slowest rate at which we send challenges?
198 */ 205 */
199#define MAX_VALIDATION_CHALLENGE_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1) 206#define MAX_VALIDATION_CHALLENGE_FREQ \
207 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1)
200 208
201/** 209/**
202 * What is the non-randomized base frequency at which we 210 * What is the non-randomized base frequency at which we
@@ -213,11 +221,13 @@
213/** 221/**
214 * When do we forget an invalid address for sure? 222 * When do we forget an invalid address for sure?
215 */ 223 */
216#define MAX_ADDRESS_VALID_UNTIL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1) 224#define MAX_ADDRESS_VALID_UNTIL \
225 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1)
217/** 226/**
218 * How long do we consider an address valid if we just checked? 227 * How long do we consider an address valid if we just checked?
219 */ 228 */
220#define ADDRESS_VALIDATION_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) 229#define ADDRESS_VALIDATION_LIFETIME \
230 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
221 231
222/** 232/**
223 * What is the maximum frequency at which we do address validation? 233 * What is the maximum frequency at which we do address validation?
@@ -337,7 +347,6 @@ struct EphemeralConfirmation
337 * to encrypt the payload. 347 * to encrypt the payload.
338 */ 348 */
339 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; 349 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
340
341}; 350};
342 351
343 352
@@ -392,7 +401,6 @@ struct TransportBackchannelRequestPayload
392 401
393 /* Followed by a 0-termianted string specifying the name of 402 /* Followed by a 0-termianted string specifying the name of
394 the communicator which is to receive the message */ 403 the communicator which is to receive the message */
395
396}; 404};
397 405
398 406
@@ -491,7 +499,6 @@ struct TransportFragmentBox
491 * Total size of the message that is being fragmented. 499 * Total size of the message that is being fragmented.
492 */ 500 */
493 uint16_t msg_size GNUNET_PACKED; 501 uint16_t msg_size GNUNET_PACKED;
494
495}; 502};
496 503
497 504
@@ -585,7 +592,6 @@ struct DvInitPS
585 * Challenge value used by the initiator to re-identify the path. 592 * Challenge value used by the initiator to re-identify the path.
586 */ 593 */
587 struct GNUNET_ShortHashCode challenge; 594 struct GNUNET_ShortHashCode challenge;
588
589}; 595};
590 596
591 597
@@ -626,7 +632,6 @@ struct DvHopPS
626 * Challenge value used by the initiator to re-identify the path. 632 * Challenge value used by the initiator to re-identify the path.
627 */ 633 */
628 struct GNUNET_ShortHashCode challenge; 634 struct GNUNET_ShortHashCode challenge;
629
630}; 635};
631 636
632 637
@@ -646,7 +651,6 @@ struct DVPathEntryP
646 * #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP 651 * #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP
647 */ 652 */
648 struct GNUNET_CRYPTO_EddsaSignature hop_sig; 653 struct GNUNET_CRYPTO_EddsaSignature hop_sig;
649
650}; 654};
651 655
652 656
@@ -712,7 +716,6 @@ struct TransportDVLearn
712 /* Followed by @e num_hops `struct DVPathEntryP` values, 716 /* Followed by @e num_hops `struct DVPathEntryP` values,
713 excluding the initiator of the DV trace; the last entry is the 717 excluding the initiator of the DV trace; the last entry is the
714 current sender; the current peer must not be included. */ 718 current sender; the current peer must not be included. */
715
716}; 719};
717 720
718 721
@@ -817,7 +820,6 @@ struct TransportValidationPS
817 * Challenge signed by the receiving peer. 820 * Challenge signed by the receiving peer.
818 */ 821 */
819 struct GNUNET_ShortHashCode challenge; 822 struct GNUNET_ShortHashCode challenge;
820
821}; 823};
822 824
823 825
@@ -863,7 +865,6 @@ struct TransportValidationResponse
863}; 865};
864 866
865 867
866
867GNUNET_NETWORK_STRUCT_END 868GNUNET_NETWORK_STRUCT_END
868 869
869 870
@@ -925,7 +926,6 @@ struct LearnLaunchEntry
925 * determine freshness of paths learned via this operation. 926 * determine freshness of paths learned via this operation.
926 */ 927 */
927 struct GNUNET_TIME_Absolute launch_time; 928 struct GNUNET_TIME_Absolute launch_time;
928
929}; 929};
930 930
931 931
@@ -1050,8 +1050,9 @@ struct DistanceVectorHop
1050 struct GNUNET_TIME_Absolute freshness; 1050 struct GNUNET_TIME_Absolute freshness;
1051 1051
1052 /** 1052 /**
1053 * How many hops in total to the `target` (excluding @e next_hop and `target` itself), 1053 * How many hops in total to the `target` (excluding @e next_hop and `target`
1054 * thus 0 still means a distance of 2 hops (to @e next_hop and then to `target`)? 1054 * itself), thus 0 still means a distance of 2 hops (to @e next_hop and then
1055 * to `target`)?
1055 */ 1056 */
1056 unsigned int distance; 1057 unsigned int distance;
1057}; 1058};
@@ -1353,7 +1354,8 @@ struct ReassemblyContext
1353 */ 1354 */
1354 uint16_t msg_missing; 1355 uint16_t msg_missing;
1355 1356
1356 /* Followed by @e msg_size bytes of the (partially) defragmented original message */ 1357 /* Followed by @e msg_size bytes of the (partially) defragmented original
1358 * message */
1357 1359
1358 /* Followed by @e bitfield data */ 1360 /* Followed by @e bitfield data */
1359}; 1361};
@@ -1480,7 +1482,6 @@ struct PeerRequest
1480 * How much bandwidth would this @e tc like to see? 1482 * How much bandwidth would this @e tc like to see?
1481 */ 1483 */
1482 struct GNUNET_BANDWIDTH_Value32NBO bw; 1484 struct GNUNET_BANDWIDTH_Value32NBO bw;
1483
1484}; 1485};
1485 1486
1486 1487
@@ -1567,17 +1568,20 @@ struct PendingMessage
1567 struct PendingMessage *prev_client; 1568 struct PendingMessage *prev_client;
1568 1569
1569 /** 1570 /**
1570 * Kept in a MDLL of messages from this @a cpm (if @e pmt is #PMT_FRAGMENT_BOx) 1571 * Kept in a MDLL of messages from this @a cpm (if @e pmt is
1572 * #PMT_FRAGMENT_BOx)
1571 */ 1573 */
1572 struct PendingMessage *next_frag; 1574 struct PendingMessage *next_frag;
1573 1575
1574 /** 1576 /**
1575 * Kept in a MDLL of messages from this @a cpm (if @e pmt is #PMT_FRAGMENT_BOX) 1577 * Kept in a MDLL of messages from this @a cpm (if @e pmt is
1578 * #PMT_FRAGMENT_BOX)
1576 */ 1579 */
1577 struct PendingMessage *prev_frag; 1580 struct PendingMessage *prev_frag;
1578 1581
1579 /** 1582 /**
1580 * This message, reliability boxed. Only possibly available if @e pmt is #PMT_CORE. 1583 * This message, reliability boxed. Only possibly available if @e pmt is
1584 * #PMT_CORE.
1581 */ 1585 */
1582 struct PendingMessage *bpm; 1586 struct PendingMessage *bpm;
1583 1587
@@ -1702,7 +1706,6 @@ struct AddressListEntry
1702 * Network type offered by this address. 1706 * Network type offered by this address.
1703 */ 1707 */
1704 enum GNUNET_NetworkType nt; 1708 enum GNUNET_NetworkType nt;
1705
1706}; 1709};
1707 1710
1708 1711
@@ -1743,7 +1746,8 @@ struct TransportClient
1743 /** 1746 /**
1744 * Information for @e type #CT_CORE. 1747 * Information for @e type #CT_CORE.
1745 */ 1748 */
1746 struct { 1749 struct
1750 {
1747 1751
1748 /** 1752 /**
1749 * Head of list of messages pending for this client, sorted by 1753 * Head of list of messages pending for this client, sorted by
@@ -1761,7 +1765,8 @@ struct TransportClient
1761 /** 1765 /**
1762 * Information for @e type #CT_MONITOR. 1766 * Information for @e type #CT_MONITOR.
1763 */ 1767 */
1764 struct { 1768 struct
1769 {
1765 1770
1766 /** 1771 /**
1767 * Peer identity to monitor the addresses of. 1772 * Peer identity to monitor the addresses of.
@@ -1781,7 +1786,8 @@ struct TransportClient
1781 /** 1786 /**
1782 * Information for @e type #CT_COMMUNICATOR. 1787 * Information for @e type #CT_COMMUNICATOR.
1783 */ 1788 */
1784 struct { 1789 struct
1790 {
1785 /** 1791 /**
1786 * If @e type is #CT_COMMUNICATOR, this communicator 1792 * If @e type is #CT_COMMUNICATOR, this communicator
1787 * supports communicating using these addresses. 1793 * supports communicating using these addresses.
@@ -1799,12 +1805,14 @@ struct TransportClient
1799 struct Queue *queue_tail; 1805 struct Queue *queue_tail;
1800 1806
1801 /** 1807 /**
1802 * Head of list of the addresses of this peer offered by this communicator. 1808 * Head of list of the addresses of this peer offered by this
1809 * communicator.
1803 */ 1810 */
1804 struct AddressListEntry *addr_head; 1811 struct AddressListEntry *addr_head;
1805 1812
1806 /** 1813 /**
1807 * Tail of list of the addresses of this peer offered by this communicator. 1814 * Tail of list of the addresses of this peer offered by this
1815 * communicator.
1808 */ 1816 */
1809 struct AddressListEntry *addr_tail; 1817 struct AddressListEntry *addr_tail;
1810 1818
@@ -1825,7 +1833,8 @@ struct TransportClient
1825 /** 1833 /**
1826 * Information for @e type #CT_APPLICATION 1834 * Information for @e type #CT_APPLICATION
1827 */ 1835 */
1828 struct { 1836 struct
1837 {
1829 1838
1830 /** 1839 /**
1831 * Map of requests for peers the given client application would like to 1840 * Map of requests for peers the given client application would like to
@@ -1836,7 +1845,6 @@ struct TransportClient
1836 } application; 1845 } application;
1837 1846
1838 } details; 1847 } details;
1839
1840}; 1848};
1841 1849
1842 1850
@@ -1940,7 +1948,6 @@ struct ValidationState
1940 * the respective queue to become available for transmission. 1948 * the respective queue to become available for transmission.
1941 */ 1949 */
1942 int awaiting_queue; 1950 int awaiting_queue;
1943
1944}; 1951};
1945 1952
1946 1953
@@ -2058,9 +2065,7 @@ static struct GNUNET_SCHEDULER_Task *validation_task;
2058static void 2065static void
2059free_ephemeral (struct EphemeralCacheEntry *ece) 2066free_ephemeral (struct EphemeralCacheEntry *ece)
2060{ 2067{
2061 GNUNET_CONTAINER_multipeermap_remove (ephemeral_map, 2068 GNUNET_CONTAINER_multipeermap_remove (ephemeral_map, &ece->target, ece);
2062 &ece->target,
2063 ece);
2064 GNUNET_CONTAINER_heap_remove_node (ece->hn); 2069 GNUNET_CONTAINER_heap_remove_node (ece->hn);
2065 GNUNET_free (ece); 2070 GNUNET_free (ece);
2066} 2071}
@@ -2074,9 +2079,7 @@ free_ephemeral (struct EphemeralCacheEntry *ece)
2074static void 2079static void
2075free_validation_state (struct ValidationState *vs) 2080free_validation_state (struct ValidationState *vs)
2076{ 2081{
2077 GNUNET_CONTAINER_multipeermap_remove (validation_map, 2082 GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs);
2078 &vs->pid,
2079 vs);
2080 GNUNET_CONTAINER_heap_remove_node (vs->hn); 2083 GNUNET_CONTAINER_heap_remove_node (vs->hn);
2081 vs->hn = NULL; 2084 vs->hn = NULL;
2082 if (NULL != vs->sc) 2085 if (NULL != vs->sc)
@@ -2098,8 +2101,7 @@ free_validation_state (struct ValidationState *vs)
2098static struct Neighbour * 2101static struct Neighbour *
2099lookup_neighbour (const struct GNUNET_PeerIdentity *pid) 2102lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
2100{ 2103{
2101 return GNUNET_CONTAINER_multipeermap_get (neighbours, 2104 return GNUNET_CONTAINER_multipeermap_get (neighbours, pid);
2102 pid);
2103} 2105}
2104 2106
2105 2107
@@ -2134,8 +2136,6 @@ struct MonitorEvent
2134 * Bytes pending. 2136 * Bytes pending.
2135 */ 2137 */
2136 uint32_t num_bytes_pending; 2138 uint32_t num_bytes_pending;
2137
2138
2139}; 2139};
2140 2140
2141 2141
@@ -2153,14 +2153,8 @@ free_distance_vector_hop (struct DistanceVectorHop *dvh)
2153 struct Neighbour *n = dvh->next_hop; 2153 struct Neighbour *n = dvh->next_hop;
2154 struct DistanceVector *dv = dvh->dv; 2154 struct DistanceVector *dv = dvh->dv;
2155 2155
2156 GNUNET_CONTAINER_MDLL_remove (neighbour, 2156 GNUNET_CONTAINER_MDLL_remove (neighbour, n->dv_head, n->dv_tail, dvh);
2157 n->dv_head, 2157 GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, dvh);
2158 n->dv_tail,
2159 dvh);
2160 GNUNET_CONTAINER_MDLL_remove (dv,
2161 dv->dv_head,
2162 dv->dv_tail,
2163 dvh);
2164 GNUNET_free (dvh); 2158 GNUNET_free (dvh);
2165} 2159}
2166 2160
@@ -2180,10 +2174,9 @@ free_dv_route (struct DistanceVector *dv)
2180 free_distance_vector_hop (dvh); 2174 free_distance_vector_hop (dvh);
2181 if (NULL == dv->dv_head) 2175 if (NULL == dv->dv_head)
2182 { 2176 {
2183 GNUNET_assert (GNUNET_YES == 2177 GNUNET_assert (
2184 GNUNET_CONTAINER_multipeermap_remove (dv_routes, 2178 GNUNET_YES ==
2185 &dv->target, 2179 GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv));
2186 dv));
2187 if (NULL != dv->timeout_task) 2180 if (NULL != dv->timeout_task)
2188 GNUNET_SCHEDULER_cancel (dv->timeout_task); 2181 GNUNET_SCHEDULER_cancel (dv->timeout_task);
2189 GNUNET_free (dv); 2182 GNUNET_free (dv);
@@ -2227,11 +2220,8 @@ notify_monitor (struct TransportClient *tc,
2227 md->cs = htonl ((uint32_t) me->cs); 2220 md->cs = htonl ((uint32_t) me->cs);
2228 md->num_msg_pending = htonl (me->num_msg_pending); 2221 md->num_msg_pending = htonl (me->num_msg_pending);
2229 md->num_bytes_pending = htonl (me->num_bytes_pending); 2222 md->num_bytes_pending = htonl (me->num_bytes_pending);
2230 memcpy (&md[1], 2223 memcpy (&md[1], address, addr_len);
2231 address, 2224 GNUNET_MQ_send (tc->mq, env);
2232 addr_len);
2233 GNUNET_MQ_send (tc->mq,
2234 env);
2235} 2225}
2236 2226
2237 2227
@@ -2250,23 +2240,16 @@ notify_monitors (const struct GNUNET_PeerIdentity *peer,
2250 enum GNUNET_NetworkType nt, 2240 enum GNUNET_NetworkType nt,
2251 const struct MonitorEvent *me) 2241 const struct MonitorEvent *me)
2252{ 2242{
2253 for (struct TransportClient *tc = clients_head; 2243 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
2254 NULL != tc;
2255 tc = tc->next)
2256 { 2244 {
2257 if (CT_MONITOR != tc->type) 2245 if (CT_MONITOR != tc->type)
2258 continue; 2246 continue;
2259 if (tc->details.monitor.one_shot) 2247 if (tc->details.monitor.one_shot)
2260 continue; 2248 continue;
2261 if ( (0 != GNUNET_is_zero (&tc->details.monitor.peer)) && 2249 if ((0 != GNUNET_is_zero (&tc->details.monitor.peer)) &&
2262 (0 != GNUNET_memcmp (&tc->details.monitor.peer, 2250 (0 != GNUNET_memcmp (&tc->details.monitor.peer, peer)))
2263 peer)) )
2264 continue; 2251 continue;
2265 notify_monitor (tc, 2252 notify_monitor (tc, peer, address, nt, me);
2266 peer,
2267 address,
2268 nt,
2269 me);
2270 } 2253 }
2271} 2254}
2272 2255
@@ -2291,12 +2274,8 @@ client_connect_cb (void *cls,
2291 tc = GNUNET_new (struct TransportClient); 2274 tc = GNUNET_new (struct TransportClient);
2292 tc->client = client; 2275 tc->client = client;
2293 tc->mq = mq; 2276 tc->mq = mq;
2294 GNUNET_CONTAINER_DLL_insert (clients_head, 2277 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
2295 clients_tail, 2278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
2296 tc);
2297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2298 "Client %p connected\n",
2299 tc);
2300 return tc; 2279 return tc;
2301} 2280}
2302 2281
@@ -2311,8 +2290,7 @@ free_reassembly_context (struct ReassemblyContext *rc)
2311{ 2290{
2312 struct Neighbour *n = rc->neighbour; 2291 struct Neighbour *n = rc->neighbour;
2313 2292
2314 GNUNET_assert (rc == 2293 GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn));
2315 GNUNET_CONTAINER_heap_remove_node (rc->hn));
2316 GNUNET_assert (GNUNET_OK == 2294 GNUNET_assert (GNUNET_OK ==
2317 GNUNET_CONTAINER_multishortmap_remove (n->reassembly_map, 2295 GNUNET_CONTAINER_multishortmap_remove (n->reassembly_map,
2318 &rc->msg_uuid, 2296 &rc->msg_uuid,
@@ -2335,15 +2313,17 @@ reassembly_cleanup_task (void *cls)
2335 n->reassembly_timeout_task = NULL; 2313 n->reassembly_timeout_task = NULL;
2336 while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap))) 2314 while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap)))
2337 { 2315 {
2338 if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout).rel_value_us) 2316 if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)
2317 .rel_value_us)
2339 { 2318 {
2340 free_reassembly_context (rc); 2319 free_reassembly_context (rc);
2341 continue; 2320 continue;
2342 } 2321 }
2343 GNUNET_assert (NULL == n->reassembly_timeout_task); 2322 GNUNET_assert (NULL == n->reassembly_timeout_task);
2344 n->reassembly_timeout_task = GNUNET_SCHEDULER_add_at (rc->reassembly_timeout, 2323 n->reassembly_timeout_task =
2345 &reassembly_cleanup_task, 2324 GNUNET_SCHEDULER_add_at (rc->reassembly_timeout,
2346 n); 2325 &reassembly_cleanup_task,
2326 n);
2347 return; 2327 return;
2348 } 2328 }
2349} 2329}
@@ -2363,9 +2343,9 @@ free_reassembly_cb (void *cls,
2363 void *value) 2343 void *value)
2364{ 2344{
2365 struct ReassemblyContext *rc = value; 2345 struct ReassemblyContext *rc = value;
2346
2366 (void) cls; 2347 (void) cls;
2367 (void) key; 2348 (void) key;
2368
2369 free_reassembly_context (rc); 2349 free_reassembly_context (rc);
2370 return GNUNET_OK; 2350 return GNUNET_OK;
2371} 2351}
@@ -2428,12 +2408,10 @@ core_send_connect_info (struct TransportClient *tc,
2428 struct ConnectInfoMessage *cim; 2408 struct ConnectInfoMessage *cim;
2429 2409
2430 GNUNET_assert (CT_CORE == tc->type); 2410 GNUNET_assert (CT_CORE == tc->type);
2431 env = GNUNET_MQ_msg (cim, 2411 env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
2432 GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
2433 cim->quota_out = quota_out; 2412 cim->quota_out = quota_out;
2434 cim->id = *pid; 2413 cim->id = *pid;
2435 GNUNET_MQ_send (tc->mq, 2414 GNUNET_MQ_send (tc->mq, env);
2436 env);
2437} 2415}
2438 2416
2439 2417
@@ -2447,15 +2425,11 @@ static void
2447cores_send_connect_info (const struct GNUNET_PeerIdentity *pid, 2425cores_send_connect_info (const struct GNUNET_PeerIdentity *pid,
2448 struct GNUNET_BANDWIDTH_Value32NBO quota_out) 2426 struct GNUNET_BANDWIDTH_Value32NBO quota_out)
2449{ 2427{
2450 for (struct TransportClient *tc = clients_head; 2428 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
2451 NULL != tc;
2452 tc = tc->next)
2453 { 2429 {
2454 if (CT_CORE != tc->type) 2430 if (CT_CORE != tc->type)
2455 continue; 2431 continue;
2456 core_send_connect_info (tc, 2432 core_send_connect_info (tc, pid, quota_out);
2457 pid,
2458 quota_out);
2459 } 2433 }
2460} 2434}
2461 2435
@@ -2468,20 +2442,16 @@ cores_send_connect_info (const struct GNUNET_PeerIdentity *pid,
2468static void 2442static void
2469cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid) 2443cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid)
2470{ 2444{
2471 for (struct TransportClient *tc = clients_head; 2445 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
2472 NULL != tc;
2473 tc = tc->next)
2474 { 2446 {
2475 struct GNUNET_MQ_Envelope *env; 2447 struct GNUNET_MQ_Envelope *env;
2476 struct DisconnectInfoMessage *dim; 2448 struct DisconnectInfoMessage *dim;
2477 2449
2478 if (CT_CORE != tc->type) 2450 if (CT_CORE != tc->type)
2479 continue; 2451 continue;
2480 env = GNUNET_MQ_msg (dim, 2452 env = GNUNET_MQ_msg (dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
2481 GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
2482 dim->peer = *pid; 2453 dim->peer = *pid;
2483 GNUNET_MQ_send (tc->mq, 2454 GNUNET_MQ_send (tc->mq, env);
2484 env);
2485 } 2455 }
2486} 2456}
2487 2457
@@ -2519,10 +2489,11 @@ schedule_transmit_on_queue (struct Queue *queue)
2519 if (queue->tc->details.communicator.total_queue_length >= 2489 if (queue->tc->details.communicator.total_queue_length >=
2520 COMMUNICATOR_TOTAL_QUEUE_LIMIT) 2490 COMMUNICATOR_TOTAL_QUEUE_LIMIT)
2521 { 2491 {
2522 GNUNET_STATISTICS_update (GST_stats, 2492 GNUNET_STATISTICS_update (
2523 "# Transmission throttled due to communicator queue limit", 2493 GST_stats,
2524 1, 2494 "# Transmission throttled due to communicator queue limit",
2525 GNUNET_NO); 2495 1,
2496 GNUNET_NO);
2526 return; 2497 return;
2527 } 2498 }
2528 if (queue->queue_length >= QUEUE_LENGTH_LIMIT) 2499 if (queue->queue_length >= QUEUE_LENGTH_LIMIT)
@@ -2534,32 +2505,27 @@ schedule_transmit_on_queue (struct Queue *queue)
2534 return; 2505 return;
2535 } 2506 }
2536 2507
2537 wsize = (0 == queue->mtu) 2508 wsize = (0 == queue->mtu) ? pm->bytes_msg /* FIXME: add overheads? */
2538 ? pm->bytes_msg /* FIXME: add overheads? */ 2509 : queue->mtu;
2539 : queue->mtu; 2510 out_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_out, wsize);
2540 out_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_out, 2511 out_delay = GNUNET_TIME_relative_max (GNUNET_TIME_absolute_get_remaining (
2541 wsize); 2512 pm->next_attempt),
2542 out_delay = GNUNET_TIME_relative_max (GNUNET_TIME_absolute_get_remaining (pm->next_attempt),
2543 out_delay); 2513 out_delay);
2544 if (0 == out_delay.rel_value_us) 2514 if (0 == out_delay.rel_value_us)
2545 return; /* we should run immediately! */ 2515 return; /* we should run immediately! */
2546 /* queue has changed since we were scheduled, reschedule again */ 2516 /* queue has changed since we were scheduled, reschedule again */
2547 queue->transmit_task 2517 queue->transmit_task =
2548 = GNUNET_SCHEDULER_add_delayed (out_delay, 2518 GNUNET_SCHEDULER_add_delayed (out_delay, &transmit_on_queue, queue);
2549 &transmit_on_queue,
2550 queue);
2551 if (out_delay.rel_value_us > DELAY_WARN_THRESHOLD.rel_value_us) 2519 if (out_delay.rel_value_us > DELAY_WARN_THRESHOLD.rel_value_us)
2552 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2520 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2553 "Next transmission on queue `%s' in %s (high delay)\n", 2521 "Next transmission on queue `%s' in %s (high delay)\n",
2554 queue->address, 2522 queue->address,
2555 GNUNET_STRINGS_relative_time_to_string (out_delay, 2523 GNUNET_STRINGS_relative_time_to_string (out_delay, GNUNET_YES));
2556 GNUNET_YES));
2557 else 2524 else
2558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2559 "Next transmission on queue `%s' in %s\n", 2526 "Next transmission on queue `%s' in %s\n",
2560 queue->address, 2527 queue->address,
2561 GNUNET_STRINGS_relative_time_to_string (out_delay, 2528 GNUNET_STRINGS_relative_time_to_string (out_delay, GNUNET_YES));
2562 GNUNET_YES));
2563} 2529}
2564 2530
2565 2531
@@ -2583,10 +2549,8 @@ free_queue (struct Queue *queue)
2583{ 2549{
2584 struct Neighbour *neighbour = queue->neighbour; 2550 struct Neighbour *neighbour = queue->neighbour;
2585 struct TransportClient *tc = queue->tc; 2551 struct TransportClient *tc = queue->tc;
2586 struct MonitorEvent me = { 2552 struct MonitorEvent me = {.cs = GNUNET_TRANSPORT_CS_DOWN,
2587 .cs = GNUNET_TRANSPORT_CS_DOWN, 2553 .rtt = GNUNET_TIME_UNIT_FOREVER_REL};
2588 .rtt = GNUNET_TIME_UNIT_FOREVER_REL
2589 };
2590 struct QueueEntry *qe; 2554 struct QueueEntry *qe;
2591 int maxxed; 2555 int maxxed;
2592 2556
@@ -2608,40 +2572,36 @@ free_queue (struct Queue *queue)
2608 tc->details.communicator.queue_head, 2572 tc->details.communicator.queue_head,
2609 tc->details.communicator.queue_tail, 2573 tc->details.communicator.queue_tail,
2610 queue); 2574 queue);
2611 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >= tc->details.communicator.total_queue_length); 2575 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >=
2576 tc->details.communicator.total_queue_length);
2612 while (NULL != (qe = queue->queue_head)) 2577 while (NULL != (qe = queue->queue_head))
2613 { 2578 {
2614 GNUNET_CONTAINER_DLL_remove (queue->queue_head, 2579 GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe);
2615 queue->queue_tail,
2616 qe);
2617 queue->queue_length--; 2580 queue->queue_length--;
2618 tc->details.communicator.total_queue_length--; 2581 tc->details.communicator.total_queue_length--;
2619 GNUNET_free (qe); 2582 GNUNET_free (qe);
2620 } 2583 }
2621 GNUNET_assert (0 == queue->queue_length); 2584 GNUNET_assert (0 == queue->queue_length);
2622 if ( (maxxed) && 2585 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT <
2623 (COMMUNICATOR_TOTAL_QUEUE_LIMIT < tc->details.communicator.total_queue_length) ) 2586 tc->details.communicator.total_queue_length))
2624 { 2587 {
2625 /* Communicator dropped below threshold, resume all queues */ 2588 /* Communicator dropped below threshold, resume all queues */
2626 GNUNET_STATISTICS_update (GST_stats, 2589 GNUNET_STATISTICS_update (
2627 "# Transmission throttled due to communicator queue limit", 2590 GST_stats,
2628 -1, 2591 "# Transmission throttled due to communicator queue limit",
2629 GNUNET_NO); 2592 -1,
2630 for (struct Queue *s = tc->details.communicator.queue_head; 2593 GNUNET_NO);
2631 NULL != s; 2594 for (struct Queue *s = tc->details.communicator.queue_head; NULL != s;
2632 s = s->next_client) 2595 s = s->next_client)
2633 schedule_transmit_on_queue (s); 2596 schedule_transmit_on_queue (s);
2634 } 2597 }
2635 notify_monitors (&neighbour->pid, 2598 notify_monitors (&neighbour->pid, queue->address, queue->nt, &me);
2636 queue->address,
2637 queue->nt,
2638 &me);
2639 GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_in); 2599 GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_in);
2640 GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_out); 2600 GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_out);
2641 GNUNET_free (queue); 2601 GNUNET_free (queue);
2642 2602
2643 update_neighbour_core_visibility (neighbour); 2603 update_neighbour_core_visibility (neighbour);
2644 cores_send_disconnect_info (&neighbour->pid); 2604 cores_send_disconnect_info (&neighbour->pid);
2645 2605
2646 if (NULL == neighbour->queue_head) 2606 if (NULL == neighbour->queue_head)
2647 { 2607 {
@@ -2694,10 +2654,11 @@ stop_peer_request (void *cls,
2694 struct PeerRequest *pr = value; 2654 struct PeerRequest *pr = value;
2695 2655
2696 GNUNET_PEERSTORE_watch_cancel (pr->wc); 2656 GNUNET_PEERSTORE_watch_cancel (pr->wc);
2697 GNUNET_assert (GNUNET_YES == 2657 GNUNET_assert (
2698 GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, 2658 GNUNET_YES ==
2699 pid, 2659 GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests,
2700 pr)); 2660 pid,
2661 pr));
2701 GNUNET_free (pr); 2662 GNUNET_free (pr);
2702 2663
2703 return GNUNET_OK; 2664 return GNUNET_OK;
@@ -2723,41 +2684,37 @@ client_disconnect_cb (void *cls,
2723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2724 "Client %p disconnected, cleaning up.\n", 2685 "Client %p disconnected, cleaning up.\n",
2725 tc); 2686 tc);
2726 GNUNET_CONTAINER_DLL_remove (clients_head, 2687 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
2727 clients_tail,
2728 tc);
2729 switch (tc->type) 2688 switch (tc->type)
2730 { 2689 {
2731 case CT_NONE: 2690 case CT_NONE:
2732 break; 2691 break;
2733 case CT_CORE: 2692 case CT_CORE: {
2734 { 2693 struct PendingMessage *pm;
2735 struct PendingMessage *pm;
2736 2694
2737 while (NULL != (pm = tc->details.core.pending_msg_head)) 2695 while (NULL != (pm = tc->details.core.pending_msg_head))
2738 {
2739 GNUNET_CONTAINER_MDLL_remove (client,
2740 tc->details.core.pending_msg_head,
2741 tc->details.core.pending_msg_tail,
2742 pm);
2743 pm->client = NULL;
2744 }
2745 }
2746 break;
2747 case CT_MONITOR:
2748 break;
2749 case CT_COMMUNICATOR:
2750 { 2696 {
2751 struct Queue *q; 2697 GNUNET_CONTAINER_MDLL_remove (client,
2752 struct AddressListEntry *ale; 2698 tc->details.core.pending_msg_head,
2753 2699 tc->details.core.pending_msg_tail,
2754 while (NULL != (q = tc->details.communicator.queue_head)) 2700 pm);
2755 free_queue (q); 2701 pm->client = NULL;
2756 while (NULL != (ale = tc->details.communicator.addr_head))
2757 free_address_list_entry (ale);
2758 GNUNET_free (tc->details.communicator.address_prefix);
2759 } 2702 }
2703 }
2704 break;
2705 case CT_MONITOR:
2760 break; 2706 break;
2707 case CT_COMMUNICATOR: {
2708 struct Queue *q;
2709 struct AddressListEntry *ale;
2710
2711 while (NULL != (q = tc->details.communicator.queue_head))
2712 free_queue (q);
2713 while (NULL != (ale = tc->details.communicator.addr_head))
2714 free_address_list_entry (ale);
2715 GNUNET_free (tc->details.communicator.address_prefix);
2716 }
2717 break;
2761 case CT_APPLICATION: 2718 case CT_APPLICATION:
2762 GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests, 2719 GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests,
2763 &stop_peer_request, 2720 &stop_peer_request,
@@ -2786,9 +2743,7 @@ notify_client_connect_info (void *cls,
2786 struct TransportClient *tc = cls; 2743 struct TransportClient *tc = cls;
2787 struct Neighbour *neighbour = value; 2744 struct Neighbour *neighbour = value;
2788 2745
2789 core_send_connect_info (tc, 2746 core_send_connect_info (tc, pid, neighbour->quota_out);
2790 pid,
2791 neighbour->quota_out);
2792 return GNUNET_OK; 2747 return GNUNET_OK;
2793} 2748}
2794 2749
@@ -2802,17 +2757,14 @@ notify_client_connect_info (void *cls,
2802 * @param start the start message that was sent 2757 * @param start the start message that was sent
2803 */ 2758 */
2804static void 2759static void
2805handle_client_start (void *cls, 2760handle_client_start (void *cls, const struct StartMessage *start)
2806 const struct StartMessage *start)
2807{ 2761{
2808 struct TransportClient *tc = cls; 2762 struct TransportClient *tc = cls;
2809 uint32_t options; 2763 uint32_t options;
2810 2764
2811 options = ntohl (start->options); 2765 options = ntohl (start->options);
2812 if ( (0 != (1 & options)) && 2766 if ((0 != (1 & options)) &&
2813 (0 != 2767 (0 != GNUNET_memcmp (&start->self, &GST_my_identity)))
2814 GNUNET_memcmp (&start->self,
2815 &GST_my_identity)) )
2816 { 2768 {
2817 /* client thinks this is a different peer, reject */ 2769 /* client thinks this is a different peer, reject */
2818 GNUNET_break (0); 2770 GNUNET_break (0);
@@ -2840,8 +2792,7 @@ handle_client_start (void *cls,
2840 * @param obm the send message that was sent 2792 * @param obm the send message that was sent
2841 */ 2793 */
2842static int 2794static int
2843check_client_send (void *cls, 2795check_client_send (void *cls, const struct OutboundMessage *obm)
2844 const struct OutboundMessage *obm)
2845{ 2796{
2846 struct TransportClient *tc = cls; 2797 struct TransportClient *tc = cls;
2847 uint16_t size; 2798 uint16_t size;
@@ -2881,10 +2832,7 @@ free_fragment_tree (struct PendingMessage *root)
2881 while (NULL != (frag = root->head_frag)) 2832 while (NULL != (frag = root->head_frag))
2882 { 2833 {
2883 free_fragment_tree (frag); 2834 free_fragment_tree (frag);
2884 GNUNET_CONTAINER_MDLL_remove (frag, 2835 GNUNET_CONTAINER_MDLL_remove (frag, root->head_frag, root->tail_frag, frag);
2885 root->head_frag,
2886 root->tail_frag,
2887 frag);
2888 GNUNET_free (frag); 2836 GNUNET_free (frag);
2889 } 2837 }
2890} 2838}
@@ -2944,14 +2892,12 @@ client_send_response (struct PendingMessage *pm,
2944 2892
2945 if (NULL != tc) 2893 if (NULL != tc)
2946 { 2894 {
2947 env = GNUNET_MQ_msg (som, 2895 env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
2948 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
2949 som->success = htonl ((uint32_t) success); 2896 som->success = htonl ((uint32_t) success);
2950 som->bytes_msg = htons (pm->bytes_msg); 2897 som->bytes_msg = htons (pm->bytes_msg);
2951 som->bytes_physical = htonl (bytes_physical); 2898 som->bytes_physical = htonl (bytes_physical);
2952 som->peer = target->pid; 2899 som->peer = target->pid;
2953 GNUNET_MQ_send (tc->mq, 2900 GNUNET_MQ_send (tc->mq, env);
2954 env);
2955 } 2901 }
2956 free_pending_message (pm); 2902 free_pending_message (pm);
2957} 2903}
@@ -2974,9 +2920,7 @@ check_queue_timeouts (void *cls)
2974 n->timeout_task = NULL; 2920 n->timeout_task = NULL;
2975 earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 2921 earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
2976 now = GNUNET_TIME_absolute_get (); 2922 now = GNUNET_TIME_absolute_get ();
2977 for (struct PendingMessage *pos = n->pending_msg_head; 2923 for (struct PendingMessage *pos = n->pending_msg_head; NULL != pos; pos = pm)
2978 NULL != pos;
2979 pos = pm)
2980 { 2924 {
2981 pm = pos->next_neighbour; 2925 pm = pos->next_neighbour;
2982 if (pos->timeout.abs_value_us <= now.abs_value_us) 2926 if (pos->timeout.abs_value_us <= now.abs_value_us)
@@ -2985,19 +2929,16 @@ check_queue_timeouts (void *cls)
2985 "# messages dropped (timeout before confirmation)", 2929 "# messages dropped (timeout before confirmation)",
2986 1, 2930 1,
2987 GNUNET_NO); 2931 GNUNET_NO);
2988 client_send_response (pm, 2932 client_send_response (pm, GNUNET_NO, 0);
2989 GNUNET_NO,
2990 0);
2991 continue; 2933 continue;
2992 } 2934 }
2993 earliest_timeout = GNUNET_TIME_absolute_min (earliest_timeout, 2935 earliest_timeout =
2994 pos->timeout); 2936 GNUNET_TIME_absolute_min (earliest_timeout, pos->timeout);
2995 } 2937 }
2996 n->earliest_timeout = earliest_timeout; 2938 n->earliest_timeout = earliest_timeout;
2997 if (NULL != n->pending_msg_head) 2939 if (NULL != n->pending_msg_head)
2998 n->timeout_task = GNUNET_SCHEDULER_add_at (earliest_timeout, 2940 n->timeout_task =
2999 &check_queue_timeouts, 2941 GNUNET_SCHEDULER_add_at (earliest_timeout, &check_queue_timeouts, n);
3000 n);
3001} 2942}
3002 2943
3003 2944
@@ -3008,8 +2949,7 @@ check_queue_timeouts (void *cls)
3008 * @param obm the send message that was sent 2949 * @param obm the send message that was sent
3009 */ 2950 */
3010static void 2951static void
3011handle_client_send (void *cls, 2952handle_client_send (void *cls, const struct OutboundMessage *obm)
3012 const struct OutboundMessage *obm)
3013{ 2953{
3014 struct TransportClient *tc = cls; 2954 struct TransportClient *tc = cls;
3015 struct PendingMessage *pm; 2955 struct PendingMessage *pm;
@@ -3031,14 +2971,12 @@ handle_client_send (void *cls,
3031 struct GNUNET_MQ_Envelope *env; 2971 struct GNUNET_MQ_Envelope *env;
3032 struct SendOkMessage *som; 2972 struct SendOkMessage *som;
3033 2973
3034 env = GNUNET_MQ_msg (som, 2974 env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
3035 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
3036 som->success = htonl (GNUNET_SYSERR); 2975 som->success = htonl (GNUNET_SYSERR);
3037 som->bytes_msg = htonl (bytes_msg); 2976 som->bytes_msg = htonl (bytes_msg);
3038 som->bytes_physical = htonl (0); 2977 som->bytes_physical = htonl (0);
3039 som->peer = obm->peer; 2978 som->peer = obm->peer;
3040 GNUNET_MQ_send (tc->mq, 2979 GNUNET_MQ_send (tc->mq, env);
3041 env);
3042 GNUNET_SERVICE_client_continue (tc->client); 2980 GNUNET_SERVICE_client_continue (tc->client);
3043 GNUNET_STATISTICS_update (GST_stats, 2981 GNUNET_STATISTICS_update (GST_stats,
3044 "# messages dropped (neighbour unknown)", 2982 "# messages dropped (neighbour unknown)",
@@ -3051,10 +2989,9 @@ handle_client_send (void *cls,
3051 pm->client = tc; 2989 pm->client = tc;
3052 pm->target = target; 2990 pm->target = target;
3053 pm->bytes_msg = bytes_msg; 2991 pm->bytes_msg = bytes_msg;
3054 pm->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (obm->timeout)); 2992 pm->timeout =
3055 memcpy (&pm[1], 2993 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (obm->timeout));
3056 &obm[1], 2994 memcpy (&pm[1], &obm[1], bytes_msg);
3057 bytes_msg);
3058 GNUNET_CONTAINER_MDLL_insert (neighbour, 2995 GNUNET_CONTAINER_MDLL_insert (neighbour,
3059 target->pending_msg_head, 2996 target->pending_msg_head,
3060 target->pending_msg_tail, 2997 target->pending_msg_tail,
@@ -3068,21 +3005,19 @@ handle_client_send (void *cls,
3068 target->earliest_timeout.abs_value_us = pm->timeout.abs_value_us; 3005 target->earliest_timeout.abs_value_us = pm->timeout.abs_value_us;
3069 if (NULL != target->timeout_task) 3006 if (NULL != target->timeout_task)
3070 GNUNET_SCHEDULER_cancel (target->timeout_task); 3007 GNUNET_SCHEDULER_cancel (target->timeout_task);
3071 target->timeout_task 3008 target->timeout_task = GNUNET_SCHEDULER_add_at (target->earliest_timeout,
3072 = GNUNET_SCHEDULER_add_at (target->earliest_timeout, 3009 &check_queue_timeouts,
3073 &check_queue_timeouts, 3010 target);
3074 target);
3075 } 3011 }
3076 if (! was_empty) 3012 if (! was_empty)
3077 return; /* all queues must already be busy */ 3013 return; /* all queues must already be busy */
3078 for (struct Queue *queue = target->queue_head; 3014 for (struct Queue *queue = target->queue_head; NULL != queue;
3079 NULL != queue;
3080 queue = queue->next_neighbour) 3015 queue = queue->next_neighbour)
3081 { 3016 {
3082 /* try transmission on any queue that is idle */ 3017 /* try transmission on any queue that is idle */
3083 if (NULL == queue->transmit_task) 3018 if (NULL == queue->transmit_task)
3084 queue->transmit_task = GNUNET_SCHEDULER_add_now (&transmit_on_queue, 3019 queue->transmit_task =
3085 queue); 3020 GNUNET_SCHEDULER_add_now (&transmit_on_queue, queue);
3086 } 3021 }
3087} 3022}
3088 3023
@@ -3094,8 +3029,9 @@ handle_client_send (void *cls,
3094 * @param cam the send message that was sent 3029 * @param cam the send message that was sent
3095 */ 3030 */
3096static int 3031static int
3097check_communicator_available (void *cls, 3032check_communicator_available (
3098 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) 3033 void *cls,
3034 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
3099{ 3035{
3100 struct TransportClient *tc = cls; 3036 struct TransportClient *tc = cls;
3101 uint16_t size; 3037 uint16_t size;
@@ -3121,8 +3057,9 @@ check_communicator_available (void *cls,
3121 * @param cam the send message that was sent 3057 * @param cam the send message that was sent
3122 */ 3058 */
3123static void 3059static void
3124handle_communicator_available (void *cls, 3060handle_communicator_available (
3125 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) 3061 void *cls,
3062 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
3126{ 3063{
3127 struct TransportClient *tc = cls; 3064 struct TransportClient *tc = cls;
3128 uint16_t size; 3065 uint16_t size;
@@ -3130,10 +3067,10 @@ handle_communicator_available (void *cls,
3130 size = ntohs (cam->header.size) - sizeof (*cam); 3067 size = ntohs (cam->header.size) - sizeof (*cam);
3131 if (0 == size) 3068 if (0 == size)
3132 return; /* receive-only communicator */ 3069 return; /* receive-only communicator */
3133 tc->details.communicator.address_prefix 3070 tc->details.communicator.address_prefix =
3134 = GNUNET_strdup ((const char *) &cam[1]); 3071 GNUNET_strdup ((const char *) &cam[1]);
3135 tc->details.communicator.cc 3072 tc->details.communicator.cc =
3136 = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc); 3073 (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc);
3137 GNUNET_SERVICE_client_continue (tc->client); 3074 GNUNET_SERVICE_client_continue (tc->client);
3138} 3075}
3139 3076
@@ -3146,8 +3083,9 @@ handle_communicator_available (void *cls,
3146 * @return #GNUNET_OK if message is well-formed 3083 * @return #GNUNET_OK if message is well-formed
3147 */ 3084 */
3148static int 3085static int
3149check_communicator_backchannel (void *cls, 3086check_communicator_backchannel (
3150 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 3087 void *cls,
3088 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
3151{ 3089{
3152 const struct GNUNET_MessageHeader *inbox; 3090 const struct GNUNET_MessageHeader *inbox;
3153 const char *is; 3091 const char *is;
@@ -3158,7 +3096,7 @@ check_communicator_backchannel (void *cls,
3158 msize = ntohs (cb->header.size) - sizeof (*cb); 3096 msize = ntohs (cb->header.size) - sizeof (*cb);
3159 if (UINT16_MAX - msize > 3097 if (UINT16_MAX - msize >
3160 sizeof (struct TransportBackchannelEncapsulationMessage) + 3098 sizeof (struct TransportBackchannelEncapsulationMessage) +
3161 sizeof (struct TransportBackchannelRequestPayload) ) 3099 sizeof (struct TransportBackchannelRequestPayload))
3162 { 3100 {
3163 GNUNET_break (0); 3101 GNUNET_break (0);
3164 return GNUNET_SYSERR; 3102 return GNUNET_SYSERR;
@@ -3174,7 +3112,7 @@ check_communicator_backchannel (void *cls,
3174 is += isize; 3112 is += isize;
3175 msize -= isize; 3113 msize -= isize;
3176 GNUNET_assert (msize > 0); 3114 GNUNET_assert (msize > 0);
3177 if ('\0' != is[msize-1]) 3115 if ('\0' != is[msize - 1])
3178 { 3116 {
3179 GNUNET_break (0); 3117 GNUNET_break (0);
3180 return GNUNET_SYSERR; 3118 return GNUNET_SYSERR;
@@ -3197,7 +3135,8 @@ expire_ephemerals (void *cls)
3197 ephemeral_task = NULL; 3135 ephemeral_task = NULL;
3198 while (NULL != (ece = GNUNET_CONTAINER_heap_peek (ephemeral_heap))) 3136 while (NULL != (ece = GNUNET_CONTAINER_heap_peek (ephemeral_heap)))
3199 { 3137 {
3200 if (0 == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity).rel_value_us) 3138 if (0 == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity)
3139 .rel_value_us)
3201 { 3140 {
3202 free_ephemeral (ece); 3141 free_ephemeral (ece);
3203 continue; 3142 continue;
@@ -3230,10 +3169,10 @@ lookup_ephemeral (const struct GNUNET_PeerIdentity *pid,
3230 struct EphemeralCacheEntry *ece; 3169 struct EphemeralCacheEntry *ece;
3231 struct EphemeralConfirmation ec; 3170 struct EphemeralConfirmation ec;
3232 3171
3233 ece = GNUNET_CONTAINER_multipeermap_get (ephemeral_map, 3172 ece = GNUNET_CONTAINER_multipeermap_get (ephemeral_map, pid);
3234 pid); 3173 if ((NULL != ece) &&
3235 if ( (NULL != ece) && 3174 (0 == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity)
3236 (0 == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity).rel_value_us) ) 3175 .rel_value_us))
3237 { 3176 {
3238 free_ephemeral (ece); 3177 free_ephemeral (ece);
3239 ece = NULL; 3178 ece = NULL;
@@ -3242,28 +3181,29 @@ lookup_ephemeral (const struct GNUNET_PeerIdentity *pid,
3242 { 3181 {
3243 ece = GNUNET_new (struct EphemeralCacheEntry); 3182 ece = GNUNET_new (struct EphemeralCacheEntry);
3244 ece->target = *pid; 3183 ece->target = *pid;
3245 ece->ephemeral_validity = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get_monotonic (GST_cfg), 3184 ece->ephemeral_validity =
3246 EPHEMERAL_VALIDITY); 3185 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get_monotonic (GST_cfg),
3186 EPHEMERAL_VALIDITY);
3247 GNUNET_assert (GNUNET_OK == 3187 GNUNET_assert (GNUNET_OK ==
3248 GNUNET_CRYPTO_ecdhe_key_create2 (&ece->private_key)); 3188 GNUNET_CRYPTO_ecdhe_key_create2 (&ece->private_key));
3249 GNUNET_CRYPTO_ecdhe_key_get_public (&ece->private_key, 3189 GNUNET_CRYPTO_ecdhe_key_get_public (&ece->private_key, &ece->ephemeral_key);
3250 &ece->ephemeral_key);
3251 ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); 3190 ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
3252 ec.purpose.size = htonl (sizeof (ec)); 3191 ec.purpose.size = htonl (sizeof (ec));
3253 ec.target = *pid; 3192 ec.target = *pid;
3254 ec.ephemeral_key = ece->ephemeral_key; 3193 ec.ephemeral_key = ece->ephemeral_key;
3194 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
3195 &ec.purpose,
3196 &ece->sender_sig));
3197 ece->hn =
3198 GNUNET_CONTAINER_heap_insert (ephemeral_heap,
3199 ece,
3200 ece->ephemeral_validity.abs_value_us);
3255 GNUNET_assert (GNUNET_OK == 3201 GNUNET_assert (GNUNET_OK ==
3256 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 3202 GNUNET_CONTAINER_multipeermap_put (
3257 &ec.purpose, 3203 ephemeral_map,
3258 &ece->sender_sig)); 3204 &ece->target,
3259 ece->hn = GNUNET_CONTAINER_heap_insert (ephemeral_heap, 3205 ece,
3260 ece, 3206 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
3261 ece->ephemeral_validity.abs_value_us);
3262 GNUNET_assert (GNUNET_OK ==
3263 GNUNET_CONTAINER_multipeermap_put (ephemeral_map,
3264 &ece->target,
3265 ece,
3266 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
3267 if (NULL == ephemeral_task) 3207 if (NULL == ephemeral_task)
3268 ephemeral_task = GNUNET_SCHEDULER_add_at (ece->ephemeral_validity, 3208 ephemeral_task = GNUNET_SCHEDULER_add_at (ece->ephemeral_validity,
3269 &expire_ephemerals, 3209 &expire_ephemerals,
@@ -3301,9 +3241,7 @@ queue_send_msg (struct Queue *queue,
3301 smt->qid = queue->qid; 3241 smt->qid = queue->qid;
3302 smt->mid = queue->mid_gen; 3242 smt->mid = queue->mid_gen;
3303 smt->receiver = n->pid; 3243 smt->receiver = n->pid;
3304 memcpy (&smt[1], 3244 memcpy (&smt[1], payload, payload_size);
3305 payload,
3306 payload_size);
3307 { 3245 {
3308 /* Pass the env to the communicator of queue for transmission. */ 3246 /* Pass the env to the communicator of queue for transmission. */
3309 struct QueueEntry *qe; 3247 struct QueueEntry *qe;
@@ -3313,14 +3251,11 @@ queue_send_msg (struct Queue *queue,
3313 qe->queue = queue; 3251 qe->queue = queue;
3314 // qe->pm = pm; // FIXME: not so easy, reference management on 'free(s)'! 3252 // qe->pm = pm; // FIXME: not so easy, reference management on 'free(s)'!
3315 // (also, note that pm may be NULL!) 3253 // (also, note that pm may be NULL!)
3316 GNUNET_CONTAINER_DLL_insert (queue->queue_head, 3254 GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe);
3317 queue->queue_tail,
3318 qe);
3319 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); 3255 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type);
3320 queue->queue_length++; 3256 queue->queue_length++;
3321 queue->tc->details.communicator.total_queue_length++; 3257 queue->tc->details.communicator.total_queue_length++;
3322 GNUNET_MQ_send (queue->tc->mq, 3258 GNUNET_MQ_send (queue->tc->mq, env);
3323 env);
3324 } 3259 }
3325} 3260}
3326 3261
@@ -3329,7 +3264,8 @@ queue_send_msg (struct Queue *queue,
3329 * Which transmission options are allowable for transmission? 3264 * Which transmission options are allowable for transmission?
3330 * Interpreted bit-wise! 3265 * Interpreted bit-wise!
3331 */ 3266 */
3332enum RouteMessageOptions { 3267enum RouteMessageOptions
3268{
3333 /** 3269 /**
3334 * Only confirmed, non-DV direct neighbours. 3270 * Only confirmed, non-DV direct neighbours.
3335 */ 3271 */
@@ -3373,8 +3309,58 @@ route_via_neighbour (const struct Neighbour *n,
3373 const struct GNUNET_MessageHeader *hdr, 3309 const struct GNUNET_MessageHeader *hdr,
3374 enum RouteMessageOptions options) 3310 enum RouteMessageOptions options)
3375{ 3311{
3376 // FIXME: pick on or two 'random' queue (under constraints of options) 3312 struct GNUNET_TIME_Absolute now;
3377 // Then add wrapper and enqueue message! 3313 unsigned int candidates;
3314 unsigned int sel1;
3315 unsigned int sel2;
3316
3317 /* Pick one or two 'random' queues from n (under constraints of options) */
3318 now = GNUNET_TIME_absolute_get ();
3319 /* FIXME-OPTIMIZE: give queues 'weights' and pick proportional to
3320 weight in the future; weight could be assigned by observed
3321 bandwidth (note: not sure if we should do this for this type
3322 of control traffic though). */
3323 candidates = 0;
3324 for (struct Queue *pos = n->queue_head; NULL != pos;
3325 pos = pos->next_neighbour)
3326 {
3327 /* Count the queue with the visibility task in all cases, as
3328 otherwise we may end up with no queues just because the
3329 time for the visibility task just expired but the scheduler
3330 just ran this task first */
3331 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
3332 (pos->validated_until.abs_value_us > now.abs_value_us) ||
3333 (NULL != pos->visibility_task))
3334 candidates++;
3335 }
3336 if (0 == candidates)
3337 {
3338 /* Given that we above check for pos->visibility task,
3339 this should be strictly impossible. */
3340 GNUNET_break (0);
3341 return;
3342 }
3343 sel1 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates);
3344 if (0 == (options & RMO_REDUNDANT))
3345 sel2 = candidates; /* picks none! */
3346 else
3347 sel2 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates);
3348 candidates = 0;
3349 for (struct Queue *pos = n->queue_head; NULL != pos;
3350 pos = pos->next_neighbour)
3351 {
3352 /* Count the queue with the visibility task in all cases, as
3353 otherwise we may end up with no queues just because the
3354 time for the visibility task just expired but the scheduler
3355 just ran this task first */
3356 if ((pos->validated_until.abs_value_us > now.abs_value_us) ||
3357 (NULL != pos->visibility_task))
3358 {
3359 if ((sel1 == candidates) || (sel2 == candidates))
3360 queue_send_msg (pos, NULL, hdr, ntohs (hdr->size));
3361 candidates++;
3362 }
3363 }
3378} 3364}
3379 3365
3380 3366
@@ -3414,25 +3400,20 @@ route_message (const struct GNUNET_PeerIdentity *target,
3414 struct Neighbour *n; 3400 struct Neighbour *n;
3415 struct DistanceVector *dv; 3401 struct DistanceVector *dv;
3416 3402
3417 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 3403 n = GNUNET_CONTAINER_multipeermap_get (neighbours, target);
3418 target);
3419 dv = (0 != (options & RMO_DV_ALLOWED)) 3404 dv = (0 != (options & RMO_DV_ALLOWED))
3420 ? GNUNET_CONTAINER_multipeermap_get (dv_routes, 3405 ? GNUNET_CONTAINER_multipeermap_get (dv_routes, target)
3421 target) 3406 : NULL;
3422 : NULL;
3423 if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) 3407 if (0 == (options & RMO_UNCONFIRMED_ALLOWED))
3424 { 3408 {
3425 /* if confirmed is required, and we do not have anything 3409 /* if confirmed is required, and we do not have anything
3426 confirmed, drop respective options */ 3410 confirmed, drop respective options */
3427 if ( (NULL != n) && 3411 if ((NULL != n) && (GNUNET_NO == n->core_visible))
3428 (GNUNET_NO == n->core_visible) )
3429 n = NULL; 3412 n = NULL;
3430 if ( (NULL != dv) && 3413 if ((NULL != dv) && (GNUNET_NO == dv->core_visible))
3431 (GNUNET_NO == dv->core_visible) )
3432 dv = NULL; 3414 dv = NULL;
3433 } 3415 }
3434 if ( (NULL == n) && 3416 if ((NULL == n) && (NULL == dv))
3435 (NULL == dv) )
3436 { 3417 {
3437 GNUNET_STATISTICS_update (GST_stats, 3418 GNUNET_STATISTICS_update (GST_stats,
3438 "# Messages dropped in routing: no acceptable method", 3419 "# Messages dropped in routing: no acceptable method",
@@ -3443,30 +3424,23 @@ route_message (const struct GNUNET_PeerIdentity *target,
3443 } 3424 }
3444 /* If both dv and n are possible and we must choose: 3425 /* If both dv and n are possible and we must choose:
3445 flip a coin for the choice between the two; for now 50/50 */ 3426 flip a coin for the choice between the two; for now 50/50 */
3446 if ( (NULL != n) && 3427 if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT)))
3447 (NULL != dv) &&
3448 (0 == (options & RMO_REDUNDANT)) )
3449 { 3428 {
3450 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2)) 3429 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2))
3451 n = NULL; 3430 n = NULL;
3452 else 3431 else
3453 dv = NULL; 3432 dv = NULL;
3454 } 3433 }
3455 if ( (NULL != n) && 3434 if ((NULL != n) && (NULL != dv))
3456 (NULL != dv) )
3457 options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's 3435 options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's
3458 enough for redunancy, so clear the flag. */ 3436 enough for redunancy, so clear the flag. */
3459 if (NULL != n) 3437 if (NULL != n)
3460 { 3438 {
3461 route_via_neighbour (n, 3439 route_via_neighbour (n, hdr, options);
3462 hdr,
3463 options);
3464 } 3440 }
3465 if (NULL != dv) 3441 if (NULL != dv)
3466 { 3442 {
3467 route_via_dv (dv, 3443 route_via_dv (dv, hdr, options);
3468 hdr,
3469 options);
3470 } 3444 }
3471 GNUNET_free (hdr); 3445 GNUNET_free (hdr);
3472} 3446}
@@ -3485,7 +3459,8 @@ struct BackchannelKeyState
3485 /** 3459 /**
3486 * Actual key material. 3460 * Actual key material.
3487 */ 3461 */
3488 struct { 3462 struct
3463 {
3489 3464
3490 /** 3465 /**
3491 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()). 3466 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()).
@@ -3495,12 +3470,12 @@ struct BackchannelKeyState
3495 /** 3470 /**
3496 * Symmetric key to use for encryption. 3471 * Symmetric key to use for encryption.
3497 */ 3472 */
3498 char aes_key[256/8]; 3473 char aes_key[256 / 8];
3499 3474
3500 /** 3475 /**
3501 * Counter value to use during setup. 3476 * Counter value to use during setup.
3502 */ 3477 */
3503 char aes_ctr[128/8]; 3478 char aes_ctr[128 / 8];
3504 3479
3505 } material; 3480 } material;
3506}; 3481};
@@ -3544,20 +3519,18 @@ bc_setup_key_state_from_km (const struct GNUNET_HashCode *km,
3544 * @param key[out] set to the key material 3519 * @param key[out] set to the key material
3545 */ 3520 */
3546static void 3521static void
3547dh_key_derive_eph_pid (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, 3522dh_key_derive_eph_pid (
3548 const struct GNUNET_PeerIdentity *target, 3523 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral,
3549 const struct GNUNET_ShortHashCode *iv, 3524 const struct GNUNET_PeerIdentity *target,
3550 struct BackchannelKeyState *key) 3525 const struct GNUNET_ShortHashCode *iv,
3526 struct BackchannelKeyState *key)
3551{ 3527{
3552 struct GNUNET_HashCode km; 3528 struct GNUNET_HashCode km;
3553 3529
3554 GNUNET_assert (GNUNET_YES == 3530 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral,
3555 GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral, 3531 &target->public_key,
3556 &target->public_key, 3532 &km));
3557 &km)); 3533 bc_setup_key_state_from_km (&km, iv, key);
3558 bc_setup_key_state_from_km (&km,
3559 iv,
3560 key);
3561} 3534}
3562 3535
3563 3536
@@ -3577,13 +3550,10 @@ dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
3577{ 3550{
3578 struct GNUNET_HashCode km; 3551 struct GNUNET_HashCode km;
3579 3552
3580 GNUNET_assert (GNUNET_YES == 3553 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key,
3581 GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key, 3554 pub_ephemeral,
3582 pub_ephemeral, 3555 &km));
3583 &km)); 3556 bc_setup_key_state_from_km (&km, iv, key);
3584 bc_setup_key_state_from_km (&km,
3585 iv,
3586 key);
3587} 3557}
3588 3558
3589 3559
@@ -3602,10 +3572,7 @@ bc_hmac (const struct BackchannelKeyState *key,
3602 const void *data, 3572 const void *data,
3603 size_t data_size) 3573 size_t data_size)
3604{ 3574{
3605 GNUNET_CRYPTO_hmac (&key->material.hmac_key, 3575 GNUNET_CRYPTO_hmac (&key->material.hmac_key, data, data_size, hmac);
3606 data,
3607 data_size,
3608 hmac);
3609} 3576}
3610 3577
3611 3578
@@ -3625,11 +3592,7 @@ bc_encrypt (struct BackchannelKeyState *key,
3625 size_t in_size) 3592 size_t in_size)
3626{ 3593{
3627 GNUNET_assert (0 == 3594 GNUNET_assert (0 ==
3628 gcry_cipher_encrypt (key->cipher, 3595 gcry_cipher_encrypt (key->cipher, dst, in_size, in, in_size));
3629 dst,
3630 in_size,
3631 in,
3632 in_size));
3633} 3596}
3634 3597
3635 3598
@@ -3648,12 +3611,8 @@ bc_decrypt (struct BackchannelKeyState *key,
3648 const void *ciph, 3611 const void *ciph,
3649 size_t out_size) 3612 size_t out_size)
3650{ 3613{
3651 GNUNET_assert (0 == 3614 GNUNET_assert (
3652 gcry_cipher_decrypt (key->cipher, 3615 0 == gcry_cipher_decrypt (key->cipher, out, out_size, ciph, out_size));
3653 out,
3654 out_size,
3655 ciph,
3656 out_size));
3657} 3616}
3658 3617
3659 3618
@@ -3666,8 +3625,7 @@ static void
3666bc_key_clean (struct BackchannelKeyState *key) 3625bc_key_clean (struct BackchannelKeyState *key)
3667{ 3626{
3668 gcry_cipher_close (key->cipher); 3627 gcry_cipher_close (key->cipher);
3669 GNUNET_CRYPTO_zero_keys (&key->material, 3628 GNUNET_CRYPTO_zero_keys (&key->material, sizeof (key->material));
3670 sizeof (key->material));
3671} 3629}
3672 3630
3673 3631
@@ -3678,8 +3636,9 @@ bc_key_clean (struct BackchannelKeyState *key)
3678 * @param cb the send message that was sent 3636 * @param cb the send message that was sent
3679 */ 3637 */
3680static void 3638static void
3681handle_communicator_backchannel (void *cls, 3639handle_communicator_backchannel (
3682 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 3640 void *cls,
3641 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
3683{ 3642{
3684 struct TransportClient *tc = cls; 3643 struct TransportClient *tc = cls;
3685 struct GNUNET_CRYPTO_EcdhePrivateKey private_key; 3644 struct GNUNET_CRYPTO_EcdhePrivateKey private_key;
@@ -3691,9 +3650,11 @@ handle_communicator_backchannel (void *cls,
3691 uint16_t msize; 3650 uint16_t msize;
3692 3651
3693 /* encapsulate and encrypt message */ 3652 /* encapsulate and encrypt message */
3694 msize = ntohs (cb->header.size) - sizeof (*cb) + sizeof (struct TransportBackchannelRequestPayload); 3653 msize = ntohs (cb->header.size) - sizeof (*cb) +
3654 sizeof (struct TransportBackchannelRequestPayload);
3695 enc = GNUNET_malloc (sizeof (*enc) + msize); 3655 enc = GNUNET_malloc (sizeof (*enc) + msize);
3696 enc->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); 3656 enc->header.type =
3657 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION);
3697 enc->header.size = htons (sizeof (*enc) + msize); 3658 enc->header.size = htons (sizeof (*enc) + msize);
3698 enc->target = cb->pid; 3659 enc->target = cb->pid;
3699 lookup_ephemeral (&cb->pid, 3660 lookup_ephemeral (&cb->pid,
@@ -3704,17 +3665,12 @@ handle_communicator_backchannel (void *cls,
3704 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 3665 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
3705 &enc->iv, 3666 &enc->iv,
3706 sizeof (enc->iv)); 3667 sizeof (enc->iv));
3707 dh_key_derive_eph_pid (&private_key, 3668 dh_key_derive_eph_pid (&private_key, &cb->pid, &enc->iv, &key);
3708 &cb->pid,
3709 &enc->iv,
3710 &key);
3711 ppay.ephemeral_validity = GNUNET_TIME_absolute_hton (ephemeral_validity); 3669 ppay.ephemeral_validity = GNUNET_TIME_absolute_hton (ephemeral_validity);
3712 ppay.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg)); 3670 ppay.monotonic_time =
3671 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg));
3713 mpos = (char *) &enc[1]; 3672 mpos = (char *) &enc[1];
3714 bc_encrypt (&key, 3673 bc_encrypt (&key, &ppay, mpos, sizeof (ppay));
3715 &ppay,
3716 mpos,
3717 sizeof (ppay));
3718 bc_encrypt (&key, 3674 bc_encrypt (&key,
3719 &cb[1], 3675 &cb[1],
3720 &mpos[sizeof (ppay)], 3676 &mpos[sizeof (ppay)],
@@ -3724,9 +3680,7 @@ handle_communicator_backchannel (void *cls,
3724 mpos, 3680 mpos,
3725 sizeof (ppay) + ntohs (cb->header.size) - sizeof (*cb)); 3681 sizeof (ppay) + ntohs (cb->header.size) - sizeof (*cb));
3726 bc_key_clean (&key); 3682 bc_key_clean (&key);
3727 route_message (&cb->pid, 3683 route_message (&cb->pid, &enc->header, RMO_DV_ALLOWED);
3728 &enc->header,
3729 RMO_DV_ALLOWED);
3730 GNUNET_SERVICE_client_continue (tc->client); 3684 GNUNET_SERVICE_client_continue (tc->client);
3731} 3685}
3732 3686
@@ -3770,8 +3724,7 @@ store_pi (void *cls);
3770 * @param success #GNUNET_YES if peerstore was successful 3724 * @param success #GNUNET_YES if peerstore was successful
3771 */ 3725 */
3772static void 3726static void
3773peerstore_store_own_cb (void *cls, 3727peerstore_store_own_cb (void *cls, int success)
3774 int success)
3775{ 3728{
3776 struct AddressListEntry *ale = cls; 3729 struct AddressListEntry *ale = cls;
3777 3730
@@ -3782,10 +3735,11 @@ peerstore_store_own_cb (void *cls,
3782 ale->address); 3735 ale->address);
3783 /* refresh period is 1/4 of expiration time, that should be plenty 3736 /* refresh period is 1/4 of expiration time, that should be plenty
3784 without being excessive. */ 3737 without being excessive. */
3785 ale->st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration, 3738 ale->st =
3786 4ULL), 3739 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration,
3787 &store_pi, 3740 4ULL),
3788 ale); 3741 &store_pi,
3742 ale);
3789} 3743}
3790 3744
3791 3745
@@ -3826,9 +3780,8 @@ store_pi (void *cls)
3826 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3780 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3827 "Failed to store our address `%s' with peerstore\n", 3781 "Failed to store our address `%s' with peerstore\n",
3828 ale->address); 3782 ale->address);
3829 ale->st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 3783 ale->st =
3830 &store_pi, 3784 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &store_pi, ale);
3831 ale);
3832 } 3785 }
3833} 3786}
3834 3787
@@ -3854,14 +3807,11 @@ handle_add_address (void *cls,
3854 ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration); 3807 ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration);
3855 ale->aid = aam->aid; 3808 ale->aid = aam->aid;
3856 ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt); 3809 ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt);
3857 memcpy (&ale[1], 3810 memcpy (&ale[1], &aam[1], slen);
3858 &aam[1],
3859 slen);
3860 GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head, 3811 GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head,
3861 tc->details.communicator.addr_tail, 3812 tc->details.communicator.addr_tail,
3862 ale); 3813 ale);
3863 ale->st = GNUNET_SCHEDULER_add_now (&store_pi, 3814 ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale);
3864 ale);
3865 GNUNET_SERVICE_client_continue (tc->client); 3815 GNUNET_SERVICE_client_continue (tc->client);
3866} 3816}
3867 3817
@@ -3949,13 +3899,11 @@ finish_cmc_handling (struct CommunicatorMessageContext *cmc)
3949 struct GNUNET_MQ_Envelope *env; 3899 struct GNUNET_MQ_Envelope *env;
3950 struct GNUNET_TRANSPORT_IncomingMessageAck *ack; 3900 struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
3951 3901
3952 env = GNUNET_MQ_msg (ack, 3902 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
3953 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
3954 ack->reserved = htonl (0); 3903 ack->reserved = htonl (0);
3955 ack->fc_id = cmc->im.fc_id; 3904 ack->fc_id = cmc->im.fc_id;
3956 ack->sender = cmc->im.sender; 3905 ack->sender = cmc->im.sender;
3957 GNUNET_MQ_send (cmc->tc->mq, 3906 GNUNET_MQ_send (cmc->tc->mq, env);
3958 env);
3959 } 3907 }
3960 GNUNET_SERVICE_client_continue (cmc->tc->client); 3908 GNUNET_SERVICE_client_continue (cmc->tc->client);
3961 GNUNET_free (cmc); 3909 GNUNET_free (cmc);
@@ -3966,18 +3914,18 @@ finish_cmc_handling (struct CommunicatorMessageContext *cmc)
3966 * Communicator gave us an unencapsulated message to pass as-is to 3914 * Communicator gave us an unencapsulated message to pass as-is to
3967 * CORE. Process the request. 3915 * CORE. Process the request.
3968 * 3916 *
3969 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 3917 * @param cls a `struct CommunicatorMessageContext` (must call
3918 * #finish_cmc_handling() when done)
3970 * @param mh the message that was received 3919 * @param mh the message that was received
3971 */ 3920 */
3972static void 3921static void
3973handle_raw_message (void *cls, 3922handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
3974 const struct GNUNET_MessageHeader *mh)
3975{ 3923{
3976 struct CommunicatorMessageContext *cmc = cls; 3924 struct CommunicatorMessageContext *cmc = cls;
3977 uint16_t size = ntohs (mh->size); 3925 uint16_t size = ntohs (mh->size);
3978 3926
3979 if ( (size > UINT16_MAX - sizeof (struct InboundMessage)) || 3927 if ((size > UINT16_MAX - sizeof (struct InboundMessage)) ||
3980 (size < sizeof (struct GNUNET_MessageHeader)) ) 3928 (size < sizeof (struct GNUNET_MessageHeader)))
3981 { 3929 {
3982 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 3930 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
3983 3931
@@ -3987,24 +3935,17 @@ handle_raw_message (void *cls,
3987 return; 3935 return;
3988 } 3936 }
3989 /* Forward to all CORE clients */ 3937 /* Forward to all CORE clients */
3990 for (struct TransportClient *tc = clients_head; 3938 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3991 NULL != tc;
3992 tc = tc->next)
3993 { 3939 {
3994 struct GNUNET_MQ_Envelope *env; 3940 struct GNUNET_MQ_Envelope *env;
3995 struct InboundMessage *im; 3941 struct InboundMessage *im;
3996 3942
3997 if (CT_CORE != tc->type) 3943 if (CT_CORE != tc->type)
3998 continue; 3944 continue;
3999 env = GNUNET_MQ_msg_extra (im, 3945 env = GNUNET_MQ_msg_extra (im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
4000 size,
4001 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
4002 im->peer = cmc->im.sender; 3946 im->peer = cmc->im.sender;
4003 memcpy (&im[1], 3947 memcpy (&im[1], mh, size);
4004 mh, 3948 GNUNET_MQ_send (tc->mq, env);
4005 size);
4006 GNUNET_MQ_send (tc->mq,
4007 env);
4008 } 3949 }
4009 /* FIXME: consider doing this _only_ once the message 3950 /* FIXME: consider doing this _only_ once the message
4010 was drained from the CORE MQs to extend flow control to CORE! 3951 was drained from the CORE MQs to extend flow control to CORE!
@@ -4021,8 +3962,7 @@ handle_raw_message (void *cls,
4021 * @return #GNUNET_YES if message is well-formed 3962 * @return #GNUNET_YES if message is well-formed
4022 */ 3963 */
4023static int 3964static int
4024check_fragment_box (void *cls, 3965check_fragment_box (void *cls, const struct TransportFragmentBox *fb)
4025 const struct TransportFragmentBox *fb)
4026{ 3966{
4027 uint16_t size = ntohs (fb->header.size); 3967 uint16_t size = ntohs (fb->header.size);
4028 uint16_t bsize = size - sizeof (*fb); 3968 uint16_t bsize = size - sizeof (*fb);
@@ -4064,14 +4004,12 @@ send_fragment_ack (struct ReassemblyContext *rc)
4064 ack->msg_uuid = rc->msg_uuid; 4004 ack->msg_uuid = rc->msg_uuid;
4065 ack->avg_ack_delay = GNUNET_TIME_relative_hton (rc->avg_ack_delay); 4005 ack->avg_ack_delay = GNUNET_TIME_relative_hton (rc->avg_ack_delay);
4066 if (0 == rc->msg_missing) 4006 if (0 == rc->msg_missing)
4067 ack->reassembly_timeout 4007 ack->reassembly_timeout = GNUNET_TIME_relative_hton (
4068 = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL); /* signal completion */ 4008 GNUNET_TIME_UNIT_FOREVER_REL); /* signal completion */
4069 else 4009 else
4070 ack->reassembly_timeout 4010 ack->reassembly_timeout = GNUNET_TIME_relative_hton (
4071 = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)); 4011 GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout));
4072 route_message (&rc->neighbour->pid, 4012 route_message (&rc->neighbour->pid, &ack->header, RMO_DV_ALLOWED);
4073 &ack->header,
4074 RMO_DV_ALLOWED);
4075 rc->avg_ack_delay = GNUNET_TIME_UNIT_ZERO; 4013 rc->avg_ack_delay = GNUNET_TIME_UNIT_ZERO;
4076 rc->num_acks = 0; 4014 rc->num_acks = 0;
4077 rc->extra_acks = 0LLU; 4015 rc->extra_acks = 0LLU;
@@ -4081,12 +4019,12 @@ send_fragment_ack (struct ReassemblyContext *rc)
4081/** 4019/**
4082 * Communicator gave us a fragment. Process the request. 4020 * Communicator gave us a fragment. Process the request.
4083 * 4021 *
4084 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4022 * @param cls a `struct CommunicatorMessageContext` (must call
4023 * #finish_cmc_handling() when done)
4085 * @param fb the message that was received 4024 * @param fb the message that was received
4086 */ 4025 */
4087static void 4026static void
4088handle_fragment_box (void *cls, 4027handle_fragment_box (void *cls, const struct TransportFragmentBox *fb)
4089 const struct TransportFragmentBox *fb)
4090{ 4028{
4091 struct CommunicatorMessageContext *cmc = cls; 4029 struct CommunicatorMessageContext *cmc = cls;
4092 struct Neighbour *n; 4030 struct Neighbour *n;
@@ -4100,8 +4038,7 @@ handle_fragment_box (void *cls,
4100 struct GNUNET_TIME_Relative cdelay; 4038 struct GNUNET_TIME_Relative cdelay;
4101 int ack_now; 4039 int ack_now;
4102 4040
4103 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 4041 n = GNUNET_CONTAINER_multipeermap_get (neighbours, &cmc->im.sender);
4104 &cmc->im.sender);
4105 if (NULL == n) 4042 if (NULL == n)
4106 { 4043 {
4107 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 4044 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
@@ -4113,34 +4050,35 @@ handle_fragment_box (void *cls,
4113 } 4050 }
4114 if (NULL == n->reassembly_map) 4051 if (NULL == n->reassembly_map)
4115 { 4052 {
4116 n->reassembly_map = GNUNET_CONTAINER_multishortmap_create (8, 4053 n->reassembly_map = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_YES);
4117 GNUNET_YES); 4054 n->reassembly_heap =
4118 n->reassembly_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 4055 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
4119 n->reassembly_timeout_task = GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION, 4056 n->reassembly_timeout_task =
4120 &reassembly_cleanup_task, 4057 GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION,
4121 n); 4058 &reassembly_cleanup_task,
4059 n);
4122 } 4060 }
4123 msize = ntohs (fb->msg_size); 4061 msize = ntohs (fb->msg_size);
4124 rc = GNUNET_CONTAINER_multishortmap_get (n->reassembly_map, 4062 rc = GNUNET_CONTAINER_multishortmap_get (n->reassembly_map, &fb->msg_uuid);
4125 &fb->msg_uuid);
4126 if (NULL == rc) 4063 if (NULL == rc)
4127 { 4064 {
4128 rc = GNUNET_malloc (sizeof (*rc) + 4065 rc = GNUNET_malloc (sizeof (*rc) + msize + /* reassembly payload buffer */
4129 msize + /* reassembly payload buffer */ 4066 (msize + 7) / 8 * sizeof (uint8_t) /* bitfield */);
4130 (msize + 7) / 8 * sizeof (uint8_t) /* bitfield */);
4131 rc->msg_uuid = fb->msg_uuid; 4067 rc->msg_uuid = fb->msg_uuid;
4132 rc->neighbour = n; 4068 rc->neighbour = n;
4133 rc->msg_size = msize; 4069 rc->msg_size = msize;
4134 rc->reassembly_timeout = GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION); 4070 rc->reassembly_timeout =
4071 GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION);
4135 rc->last_frag = GNUNET_TIME_absolute_get (); 4072 rc->last_frag = GNUNET_TIME_absolute_get ();
4136 rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap, 4073 rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap,
4137 rc, 4074 rc,
4138 rc->reassembly_timeout.abs_value_us); 4075 rc->reassembly_timeout.abs_value_us);
4139 GNUNET_assert (GNUNET_OK == 4076 GNUNET_assert (GNUNET_OK ==
4140 GNUNET_CONTAINER_multishortmap_put (n->reassembly_map, 4077 GNUNET_CONTAINER_multishortmap_put (
4141 &rc->msg_uuid, 4078 n->reassembly_map,
4142 rc, 4079 &rc->msg_uuid,
4143 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 4080 rc,
4081 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
4144 target = (char *) &rc[1]; 4082 target = (char *) &rc[1];
4145 rc->bitfield = (uint8_t *) (target + rc->msg_size); 4083 rc->bitfield = (uint8_t *) (target + rc->msg_size);
4146 rc->msg_missing = rc->msg_size; 4084 rc->msg_missing = rc->msg_size;
@@ -4159,11 +4097,9 @@ handle_fragment_box (void *cls,
4159 /* reassemble */ 4097 /* reassemble */
4160 fsize = ntohs (fb->header.size) - sizeof (*fb); 4098 fsize = ntohs (fb->header.size) - sizeof (*fb);
4161 frag_off = ntohs (fb->frag_off); 4099 frag_off = ntohs (fb->frag_off);
4162 memcpy (&target[frag_off], 4100 memcpy (&target[frag_off], &fb[1], fsize);
4163 &fb[1],
4164 fsize);
4165 /* update bitfield and msg_missing */ 4101 /* update bitfield and msg_missing */
4166 for (unsigned int i=frag_off;i<frag_off+fsize;i++) 4102 for (unsigned int i = frag_off; i < frag_off + fsize; i++)
4167 { 4103 {
4168 if (0 == (rc->bitfield[i / 8] & (1 << (i % 8)))) 4104 if (0 == (rc->bitfield[i / 8] & (1 << (i % 8))))
4169 { 4105 {
@@ -4175,11 +4111,9 @@ handle_fragment_box (void *cls,
4175 /* Compute cummulative ACK */ 4111 /* Compute cummulative ACK */
4176 frag_uuid = ntohl (fb->frag_uuid); 4112 frag_uuid = ntohl (fb->frag_uuid);
4177 cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag); 4113 cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag);
4178 cdelay = GNUNET_TIME_relative_multiply (cdelay, 4114 cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->num_acks);
4179 rc->num_acks);
4180 rc->last_frag = GNUNET_TIME_absolute_get (); 4115 rc->last_frag = GNUNET_TIME_absolute_get ();
4181 rc->avg_ack_delay = GNUNET_TIME_relative_add (rc->avg_ack_delay, 4116 rc->avg_ack_delay = GNUNET_TIME_relative_add (rc->avg_ack_delay, cdelay);
4182 cdelay);
4183 ack_now = GNUNET_NO; 4117 ack_now = GNUNET_NO;
4184 if (0 == rc->num_acks) 4118 if (0 == rc->num_acks)
4185 { 4119 {
@@ -4188,12 +4122,11 @@ handle_fragment_box (void *cls,
4188 rc->extra_acks = 0LLU; 4122 rc->extra_acks = 0LLU;
4189 rc->num_acks = 1; 4123 rc->num_acks = 1;
4190 } 4124 }
4191 else if ( (frag_uuid >= rc->frag_uuid) && 4125 else if ((frag_uuid >= rc->frag_uuid) && (frag_uuid <= rc->frag_uuid + 64))
4192 (frag_uuid <= rc->frag_uuid + 64) )
4193 { 4126 {
4194 /* case two: ack fits after existing min UUID */ 4127 /* case two: ack fits after existing min UUID */
4195 if ( (frag_uuid == rc->frag_uuid) || 4128 if ((frag_uuid == rc->frag_uuid) ||
4196 (0 != (rc->extra_acks & (1LLU << (frag_uuid - rc->frag_uuid - 1)))) ) 4129 (0 != (rc->extra_acks & (1LLU << (frag_uuid - rc->frag_uuid - 1)))))
4197 { 4130 {
4198 /* duplicate fragment, ack now! */ 4131 /* duplicate fragment, ack now! */
4199 ack_now = GNUNET_YES; 4132 ack_now = GNUNET_YES;
@@ -4204,11 +4137,12 @@ handle_fragment_box (void *cls,
4204 rc->num_acks++; 4137 rc->num_acks++;
4205 } 4138 }
4206 } 4139 }
4207 else if ( (rc->frag_uuid > frag_uuid) && 4140 else if ((rc->frag_uuid > frag_uuid) &&
4208 ( ( (rc->frag_uuid == frag_uuid + 64) && 4141 (((rc->frag_uuid == frag_uuid + 64) && (0 == rc->extra_acks)) ||
4209 (0 == rc->extra_acks) ) || 4142 ((rc->frag_uuid < frag_uuid + 64) &&
4210 ( (rc->frag_uuid < frag_uuid + 64) && 4143 (rc->extra_acks ==
4211 (rc->extra_acks == (rc->extra_acks & ~ ((1LLU << (64 - (rc->frag_uuid - frag_uuid))) - 1LLU))) ) ) ) 4144 (rc->extra_acks &
4145 ~((1LLU << (64 - (rc->frag_uuid - frag_uuid))) - 1LLU))))))
4212 { 4146 {
4213 /* can fit ack by shifting extra acks and starting at 4147 /* can fit ack by shifting extra acks and starting at
4214 frag_uid, test above esured that the bits we will 4148 frag_uid, test above esured that the bits we will
@@ -4218,7 +4152,8 @@ handle_fragment_box (void *cls,
4218 rc->frag_uuid = frag_uuid; 4152 rc->frag_uuid = frag_uuid;
4219 rc->num_acks++; 4153 rc->num_acks++;
4220 } 4154 }
4221 if (65 == rc->num_acks) /* FIXME: maybe use smaller threshold? This is very aggressive. */ 4155 if (65 == rc->num_acks) /* FIXME: maybe use smaller threshold? This is very
4156 aggressive. */
4222 ack_now = GNUNET_YES; /* maximum acks received */ 4157 ack_now = GNUNET_YES; /* maximum acks received */
4223 // FIXME: possibly also ACK based on RTT (but for that we'd need to 4158 // FIXME: possibly also ACK based on RTT (but for that we'd need to
4224 // determine the queue used for the ACK first!) 4159 // determine the queue used for the ACK first!)
@@ -4242,8 +4177,7 @@ handle_fragment_box (void *cls,
4242 } 4177 }
4243 /* successful reassembly */ 4178 /* successful reassembly */
4244 send_fragment_ack (rc); 4179 send_fragment_ack (rc);
4245 demultiplex_with_cmc (cmc, 4180 demultiplex_with_cmc (cmc, msg);
4246 msg);
4247 /* FIXME: really free here? Might be bad if fragments are still 4181 /* FIXME: really free here? Might be bad if fragments are still
4248 en-route and we forget that we finished this reassembly immediately! 4182 en-route and we forget that we finished this reassembly immediately!
4249 -> keep around until timeout? 4183 -> keep around until timeout?
@@ -4271,21 +4205,17 @@ check_ack_against_pm (struct PendingMessage *pm,
4271 uint64_t xtra = GNUNET_ntohll (fa->extra_acks); 4205 uint64_t xtra = GNUNET_ntohll (fa->extra_acks);
4272 4206
4273 match = GNUNET_NO; 4207 match = GNUNET_NO;
4274 for (struct PendingMessage *frag = pm->head_frag; 4208 for (struct PendingMessage *frag = pm->head_frag; NULL != frag; frag = nxt)
4275 NULL != frag;
4276 frag = nxt)
4277 { 4209 {
4278 const struct TransportFragmentBox *tfb 4210 const struct TransportFragmentBox *tfb =
4279 = (const struct TransportFragmentBox *) &pm[1]; 4211 (const struct TransportFragmentBox *) &pm[1];
4280 uint32_t fu = ntohl (tfb->frag_uuid); 4212 uint32_t fu = ntohl (tfb->frag_uuid);
4281 4213
4282 GNUNET_assert (PMT_FRAGMENT_BOX == frag->pmt); 4214 GNUNET_assert (PMT_FRAGMENT_BOX == frag->pmt);
4283 nxt = frag->next_frag; 4215 nxt = frag->next_frag;
4284 /* Check for exact match or match in the 'xtra' bitmask */ 4216 /* Check for exact match or match in the 'xtra' bitmask */
4285 if ( (fu == fs) || 4217 if ((fu == fs) ||
4286 ( (fu > fs) && 4218 ((fu > fs) && (fu <= fs + 64) && (0 != (1LLU << (fu - fs - 1) & xtra))))
4287 (fu <= fs + 64) &&
4288 (0 != (1LLU << (fu - fs - 1) & xtra)) ) )
4289 { 4219 {
4290 match = GNUNET_YES; 4220 match = GNUNET_YES;
4291 free_fragment_tree (frag); 4221 free_fragment_tree (frag);
@@ -4298,19 +4228,18 @@ check_ack_against_pm (struct PendingMessage *pm,
4298/** 4228/**
4299 * Communicator gave us a fragment acknowledgement. Process the request. 4229 * Communicator gave us a fragment acknowledgement. Process the request.
4300 * 4230 *
4301 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4231 * @param cls a `struct CommunicatorMessageContext` (must call
4232 * #finish_cmc_handling() when done)
4302 * @param fa the message that was received 4233 * @param fa the message that was received
4303 */ 4234 */
4304static void 4235static void
4305handle_fragment_ack (void *cls, 4236handle_fragment_ack (void *cls, const struct TransportFragmentAckMessage *fa)
4306 const struct TransportFragmentAckMessage *fa)
4307{ 4237{
4308 struct CommunicatorMessageContext *cmc = cls; 4238 struct CommunicatorMessageContext *cmc = cls;
4309 struct Neighbour *n; 4239 struct Neighbour *n;
4310 int matched; 4240 int matched;
4311 4241
4312 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 4242 n = GNUNET_CONTAINER_multipeermap_get (neighbours, &cmc->im.sender);
4313 &cmc->im.sender);
4314 if (NULL == n) 4243 if (NULL == n)
4315 { 4244 {
4316 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 4245 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
@@ -4322,21 +4251,16 @@ handle_fragment_ack (void *cls,
4322 } 4251 }
4323 /* FIXME-OPTIMIZE: maybe use another hash map here? */ 4252 /* FIXME-OPTIMIZE: maybe use another hash map here? */
4324 matched = GNUNET_NO; 4253 matched = GNUNET_NO;
4325 for (struct PendingMessage *pm = n->pending_msg_head; 4254 for (struct PendingMessage *pm = n->pending_msg_head; NULL != pm;
4326 NULL != pm;
4327 pm = pm->prev_neighbour) 4255 pm = pm->prev_neighbour)
4328 { 4256 {
4329 if (0 != 4257 if (0 != GNUNET_memcmp (&fa->msg_uuid, &pm->msg_uuid))
4330 GNUNET_memcmp (&fa->msg_uuid,
4331 &pm->msg_uuid))
4332 continue; 4258 continue;
4333 matched = GNUNET_YES; 4259 matched = GNUNET_YES;
4334 if (GNUNET_YES == 4260 if (GNUNET_YES == check_ack_against_pm (pm, fa))
4335 check_ack_against_pm (pm,
4336 fa))
4337 { 4261 {
4338 struct GNUNET_TIME_Relative avg_ack_delay 4262 struct GNUNET_TIME_Relative avg_ack_delay =
4339 = GNUNET_TIME_relative_ntoh (fa->avg_ack_delay); 4263 GNUNET_TIME_relative_ntoh (fa->avg_ack_delay);
4340 // FIXME: update RTT and other reliability data! 4264 // FIXME: update RTT and other reliability data!
4341 // ISSUE: we don't know which of n's queues the message(s) 4265 // ISSUE: we don't know which of n's queues the message(s)
4342 // took (and in fact the different messages might have gone 4266 // took (and in fact the different messages might have gone
@@ -4365,9 +4289,10 @@ handle_fragment_ack (void *cls,
4365 } 4289 }
4366 else 4290 else
4367 { 4291 {
4368 struct GNUNET_TIME_Relative reassembly_timeout 4292 struct GNUNET_TIME_Relative reassembly_timeout =
4369 = GNUNET_TIME_relative_ntoh (fa->reassembly_timeout); 4293 GNUNET_TIME_relative_ntoh (fa->reassembly_timeout);
4370 // OPTIMIZE-FIXME: adjust retransmission strategy based on reassembly_timeout! 4294 // OPTIMIZE-FIXME: adjust retransmission strategy based on
4295 // reassembly_timeout!
4371 (void) reassembly_timeout; 4296 (void) reassembly_timeout;
4372 } 4297 }
4373 break; 4298 break;
@@ -4391,8 +4316,7 @@ handle_fragment_ack (void *cls,
4391 * @return #GNUNET_YES if message is well-formed 4316 * @return #GNUNET_YES if message is well-formed
4392 */ 4317 */
4393static int 4318static int
4394check_reliability_box (void *cls, 4319check_reliability_box (void *cls, const struct TransportReliabilityBox *rb)
4395 const struct TransportReliabilityBox *rb)
4396{ 4320{
4397 GNUNET_MQ_check_boxed_message (rb); 4321 GNUNET_MQ_check_boxed_message (rb);
4398 return GNUNET_YES; 4322 return GNUNET_YES;
@@ -4402,15 +4326,16 @@ check_reliability_box (void *cls,
4402/** 4326/**
4403 * Communicator gave us a reliability box. Process the request. 4327 * Communicator gave us a reliability box. Process the request.
4404 * 4328 *
4405 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4329 * @param cls a `struct CommunicatorMessageContext` (must call
4330 * #finish_cmc_handling() when done)
4406 * @param rb the message that was received 4331 * @param rb the message that was received
4407 */ 4332 */
4408static void 4333static void
4409handle_reliability_box (void *cls, 4334handle_reliability_box (void *cls, const struct TransportReliabilityBox *rb)
4410 const struct TransportReliabilityBox *rb)
4411{ 4335{
4412 struct CommunicatorMessageContext *cmc = cls; 4336 struct CommunicatorMessageContext *cmc = cls;
4413 const struct GNUNET_MessageHeader *inbox = (const struct GNUNET_MessageHeader *) &rb[1]; 4337 const struct GNUNET_MessageHeader *inbox =
4338 (const struct GNUNET_MessageHeader *) &rb[1];
4414 4339
4415 if (0 == ntohl (rb->ack_countdown)) 4340 if (0 == ntohl (rb->ack_countdown))
4416 { 4341 {
@@ -4418,28 +4343,23 @@ handle_reliability_box (void *cls,
4418 4343
4419 /* FIXME: implement cummulative ACKs and ack_countdown, 4344 /* FIXME: implement cummulative ACKs and ack_countdown,
4420 then setting the avg_ack_delay field below: */ 4345 then setting the avg_ack_delay field below: */
4421 ack = GNUNET_malloc (sizeof (*ack) + 4346 ack = GNUNET_malloc (sizeof (*ack) + sizeof (struct GNUNET_ShortHashCode));
4422 sizeof (struct GNUNET_ShortHashCode));
4423 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); 4347 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK);
4424 ack->header.size = htons (sizeof (*ack) + 4348 ack->header.size =
4425 sizeof (struct GNUNET_ShortHashCode)); 4349 htons (sizeof (*ack) + sizeof (struct GNUNET_ShortHashCode));
4426 memcpy (&ack[1], 4350 memcpy (&ack[1], &rb->msg_uuid, sizeof (struct GNUNET_ShortHashCode));
4427 &rb->msg_uuid, 4351 route_message (&cmc->im.sender, &ack->header, RMO_DV_ALLOWED);
4428 sizeof (struct GNUNET_ShortHashCode));
4429 route_message (&cmc->im.sender,
4430 &ack->header,
4431 RMO_DV_ALLOWED);
4432 } 4352 }
4433 /* continue with inner message */ 4353 /* continue with inner message */
4434 demultiplex_with_cmc (cmc, 4354 demultiplex_with_cmc (cmc, inbox);
4435 inbox);
4436} 4355}
4437 4356
4438 4357
4439/** 4358/**
4440 * Communicator gave us a reliability ack. Process the request. 4359 * Communicator gave us a reliability ack. Process the request.
4441 * 4360 *
4442 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4361 * @param cls a `struct CommunicatorMessageContext` (must call
4362 * #finish_cmc_handling() when done)
4443 * @param ra the message that was received 4363 * @param ra the message that was received
4444 */ 4364 */
4445static void 4365static void
@@ -4453,8 +4373,7 @@ handle_reliability_ack (void *cls,
4453 struct PendingMessage *nxt; 4373 struct PendingMessage *nxt;
4454 int matched; 4374 int matched;
4455 4375
4456 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 4376 n = GNUNET_CONTAINER_multipeermap_get (neighbours, &cmc->im.sender);
4457 &cmc->im.sender);
4458 if (NULL == n) 4377 if (NULL == n)
4459 { 4378 {
4460 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 4379 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
@@ -4464,25 +4383,21 @@ handle_reliability_ack (void *cls,
4464 GNUNET_SERVICE_client_drop (client); 4383 GNUNET_SERVICE_client_drop (client);
4465 return; 4384 return;
4466 } 4385 }
4467 n_acks = (ntohs (ra->header.size) - sizeof (*ra)) 4386 n_acks = (ntohs (ra->header.size) - sizeof (*ra)) /
4468 / sizeof (struct GNUNET_ShortHashCode); 4387 sizeof (struct GNUNET_ShortHashCode);
4469 msg_uuids = (const struct GNUNET_ShortHashCode *) &ra[1]; 4388 msg_uuids = (const struct GNUNET_ShortHashCode *) &ra[1];
4470 4389
4471 /* FIXME-OPTIMIZE: maybe use another hash map here? */ 4390 /* FIXME-OPTIMIZE: maybe use another hash map here? */
4472 matched = GNUNET_NO; 4391 matched = GNUNET_NO;
4473 for (struct PendingMessage *pm = n->pending_msg_head; 4392 for (struct PendingMessage *pm = n->pending_msg_head; NULL != pm; pm = nxt)
4474 NULL != pm;
4475 pm = nxt)
4476 { 4393 {
4477 int in_list; 4394 int in_list;
4478 4395
4479 nxt = pm->next_neighbour; 4396 nxt = pm->next_neighbour;
4480 in_list = GNUNET_NO; 4397 in_list = GNUNET_NO;
4481 for (unsigned int i=0;i<n_acks;i++) 4398 for (unsigned int i = 0; i < n_acks; i++)
4482 { 4399 {
4483 if (0 != 4400 if (0 != GNUNET_memcmp (&msg_uuids[i], &pm->msg_uuid))
4484 GNUNET_memcmp (&msg_uuids[i],
4485 &pm->msg_uuid))
4486 continue; 4401 continue;
4487 in_list = GNUNET_YES; 4402 in_list = GNUNET_YES;
4488 break; 4403 break;
@@ -4495,8 +4410,8 @@ handle_reliability_ack (void *cls,
4495 free_pending_message (pm); 4410 free_pending_message (pm);
4496 4411
4497 { 4412 {
4498 struct GNUNET_TIME_Relative avg_ack_delay 4413 struct GNUNET_TIME_Relative avg_ack_delay =
4499 = GNUNET_TIME_relative_ntoh (ra->avg_ack_delay); 4414 GNUNET_TIME_relative_ntoh (ra->avg_ack_delay);
4500 // FIXME: update RTT and other reliability data! 4415 // FIXME: update RTT and other reliability data!
4501 // ISSUE: we don't know which of n's queues the message(s) 4416 // ISSUE: we don't know which of n's queues the message(s)
4502 // took (and in fact the different messages might have gone 4417 // took (and in fact the different messages might have gone
@@ -4528,15 +4443,16 @@ handle_reliability_ack (void *cls,
4528 * @return #GNUNET_YES if message is well-formed 4443 * @return #GNUNET_YES if message is well-formed
4529 */ 4444 */
4530static int 4445static int
4531check_backchannel_encapsulation (void *cls, 4446check_backchannel_encapsulation (
4532 const struct TransportBackchannelEncapsulationMessage *be) 4447 void *cls,
4448 const struct TransportBackchannelEncapsulationMessage *be)
4533{ 4449{
4534 uint16_t size = ntohs (be->header.size); 4450 uint16_t size = ntohs (be->header.size);
4535 4451
4536 (void) cls; 4452 (void) cls;
4537 if (size - sizeof (*be) < 4453 if ((size - sizeof (*be)) <
4538 sizeof (struct TransportBackchannelRequestPayload) + 4454 (sizeof (struct TransportBackchannelRequestPayload) +
4539 sizeof (struct GNUNET_MessageHeader) ) 4455 sizeof (struct GNUNET_MessageHeader)))
4540 { 4456 {
4541 GNUNET_break_op (0); 4457 GNUNET_break_op (0);
4542 return GNUNET_SYSERR; 4458 return GNUNET_SYSERR;
@@ -4550,12 +4466,14 @@ check_backchannel_encapsulation (void *cls,
4550 * (We are not the origin of the backchannel here, the communicator simply 4466 * (We are not the origin of the backchannel here, the communicator simply
4551 * received a backchannel message and we are expected to forward it.) 4467 * received a backchannel message and we are expected to forward it.)
4552 * 4468 *
4553 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4469 * @param cls a `struct CommunicatorMessageContext` (must call
4470 * #finish_cmc_handling() when done)
4554 * @param be the message that was received 4471 * @param be the message that was received
4555 */ 4472 */
4556static void 4473static void
4557handle_backchannel_encapsulation (void *cls, 4474handle_backchannel_encapsulation (
4558 const struct TransportBackchannelEncapsulationMessage *be) 4475 void *cls,
4476 const struct TransportBackchannelEncapsulationMessage *be)
4559{ 4477{
4560 struct CommunicatorMessageContext *cmc = cls; 4478 struct CommunicatorMessageContext *cmc = cls;
4561 struct BackchannelKeyState key; 4479 struct BackchannelKeyState key;
@@ -4563,8 +4481,7 @@ handle_backchannel_encapsulation (void *cls,
4563 const char *hdr; 4481 const char *hdr;
4564 size_t hdr_len; 4482 size_t hdr_len;
4565 4483
4566 if (0 != GNUNET_memcmp (&be->target, 4484 if (0 != GNUNET_memcmp (&be->target, &GST_my_identity))
4567 &GST_my_identity))
4568 { 4485 {
4569 /* not for me, try to route to target */ 4486 /* not for me, try to route to target */
4570 /* FIXME: someone needs to update be->distance! */ 4487 /* FIXME: someone needs to update be->distance! */
@@ -4576,18 +4493,11 @@ handle_backchannel_encapsulation (void *cls,
4576 finish_cmc_handling (cmc); 4493 finish_cmc_handling (cmc);
4577 return; 4494 return;
4578 } 4495 }
4579 dh_key_derive_eph_pub (&be->ephemeral_key, 4496 dh_key_derive_eph_pub (&be->ephemeral_key, &be->iv, &key);
4580 &be->iv,
4581 &key);
4582 hdr = (const char *) &be[1]; 4497 hdr = (const char *) &be[1];
4583 hdr_len = ntohs (be->header.size) - sizeof (*be); 4498 hdr_len = ntohs (be->header.size) - sizeof (*be);
4584 bc_hmac (&key, 4499 bc_hmac (&key, &hmac, hdr, hdr_len);
4585 &hmac, 4500 if (0 != GNUNET_memcmp (&hmac, &be->hmac))
4586 hdr,
4587 hdr_len);
4588 if (0 !=
4589 GNUNET_memcmp (&hmac,
4590 &be->hmac))
4591 { 4501 {
4592 /* HMAC missmatch, disard! */ 4502 /* HMAC missmatch, disard! */
4593 GNUNET_break_op (0); 4503 GNUNET_break_op (0);
@@ -4599,15 +4509,10 @@ handle_backchannel_encapsulation (void *cls,
4599 struct TransportBackchannelRequestPayload ppay; 4509 struct TransportBackchannelRequestPayload ppay;
4600 char body[hdr_len - sizeof (ppay)]; 4510 char body[hdr_len - sizeof (ppay)];
4601 4511
4602 GNUNET_assert (hdr_len >= sizeof (ppay) + sizeof (struct GNUNET_MessageHeader)); 4512 GNUNET_assert (hdr_len >=
4603 bc_decrypt (&key, 4513 sizeof (ppay) + sizeof (struct GNUNET_MessageHeader));
4604 &ppay, 4514 bc_decrypt (&key, &ppay, hdr, sizeof (ppay));
4605 hdr, 4515 bc_decrypt (&key, &body, &hdr[sizeof (ppay)], hdr_len - sizeof (ppay));
4606 sizeof (ppay));
4607 bc_decrypt (&key,
4608 &body,
4609 &hdr[sizeof (ppay)],
4610 hdr_len - sizeof (ppay));
4611 bc_key_clean (&key); 4516 bc_key_clean (&key);
4612 // FIXME: verify signatures in ppay! 4517 // FIXME: verify signatures in ppay!
4613 // => check if ephemeral key is known & valid, if not 4518 // => check if ephemeral key is known & valid, if not
@@ -4649,9 +4554,8 @@ path_cleanup_cb (void *cls)
4649 free_dv_route (dv); 4554 free_dv_route (dv);
4650 return; 4555 return;
4651 } 4556 }
4652 dv->timeout_task = GNUNET_SCHEDULER_add_at (pos->timeout, 4557 dv->timeout_task =
4653 &path_cleanup_cb, 4558 GNUNET_SCHEDULER_add_at (pos->timeout, &path_cleanup_cb, dv);
4654 dv);
4655} 4559}
4656 4560
4657 4561
@@ -4670,8 +4574,8 @@ path_cleanup_cb (void *cls)
4670 * and then path contains a valid path from us to `path[path_len-1]` 4574 * and then path contains a valid path from us to `path[path_len-1]`
4671 * path[1] should be a direct neighbour (we should check!) 4575 * path[1] should be a direct neighbour (we should check!)
4672 * @param path_len number of entries on the @a path, at least three! 4576 * @param path_len number of entries on the @a path, at least three!
4673 * @param network_latency how long does the message take from us to `path[path_len-1]`? 4577 * @param network_latency how long does the message take from us to
4674 * set to "forever" if unknown 4578 * `path[path_len-1]`? set to "forever" if unknown
4675 * @return #GNUNET_YES on success, 4579 * @return #GNUNET_YES on success,
4676 * #GNUNET_NO if we have better path(s) to the target 4580 * #GNUNET_NO if we have better path(s) to the target
4677 * #GNUNET_SYSERR if the path is useless and/or invalid 4581 * #GNUNET_SYSERR if the path is useless and/or invalid
@@ -4694,29 +4598,23 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4694 GNUNET_break (0); 4598 GNUNET_break (0);
4695 return GNUNET_SYSERR; 4599 return GNUNET_SYSERR;
4696 } 4600 }
4697 GNUNET_assert (0 == 4601 GNUNET_assert (0 == GNUNET_memcmp (&GST_my_identity, &path[0]));
4698 GNUNET_memcmp (&GST_my_identity, 4602 next_hop = GNUNET_CONTAINER_multipeermap_get (neighbours, &path[1]);
4699 &path[0]));
4700 next_hop = GNUNET_CONTAINER_multipeermap_get (neighbours,
4701 &path[1]);
4702 if (NULL == next_hop) 4603 if (NULL == next_hop)
4703 { 4604 {
4704 /* next hop must be a neighbour, otherwise this whole thing is useless! */ 4605 /* next hop must be a neighbour, otherwise this whole thing is useless! */
4705 GNUNET_break (0); 4606 GNUNET_break (0);
4706 return GNUNET_SYSERR; 4607 return GNUNET_SYSERR;
4707 } 4608 }
4708 for (unsigned int i=2;i<path_len;i++) 4609 for (unsigned int i = 2; i < path_len; i++)
4709 if (NULL != 4610 if (NULL != GNUNET_CONTAINER_multipeermap_get (neighbours, &path[i]))
4710 GNUNET_CONTAINER_multipeermap_get (neighbours,
4711 &path[i]))
4712 { 4611 {
4713 /* Useless path, we have a direct connection to some hop 4612 /* Useless path, we have a direct connection to some hop
4714 in the middle of the path, so this one doesn't even 4613 in the middle of the path, so this one doesn't even
4715 seem terribly useful for redundancy */ 4614 seem terribly useful for redundancy */
4716 return GNUNET_SYSERR; 4615 return GNUNET_SYSERR;
4717 } 4616 }
4718 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, 4617 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &path[path_len - 1]);
4719 &path[path_len - 1]);
4720 if (NULL == dv) 4618 if (NULL == dv)
4721 { 4619 {
4722 dv = GNUNET_new (struct DistanceVector); 4620 dv = GNUNET_new (struct DistanceVector);
@@ -4725,15 +4623,15 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4725 &path_cleanup_cb, 4623 &path_cleanup_cb,
4726 dv); 4624 dv);
4727 GNUNET_assert (GNUNET_OK == 4625 GNUNET_assert (GNUNET_OK ==
4728 GNUNET_CONTAINER_multipeermap_put (dv_routes, 4626 GNUNET_CONTAINER_multipeermap_put (
4729 &dv->target, 4627 dv_routes,
4730 dv, 4628 &dv->target,
4731 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 4629 dv,
4630 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
4732 } 4631 }
4733 /* Check if we have this path already! */ 4632 /* Check if we have this path already! */
4734 shorter_distance = 0; 4633 shorter_distance = 0;
4735 for (struct DistanceVectorHop *pos = dv->dv_head; 4634 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
4736 NULL != pos;
4737 pos = pos->next_dv) 4635 pos = pos->next_dv)
4738 { 4636 {
4739 if (pos->distance < path_len - 2) 4637 if (pos->distance < path_len - 2)
@@ -4741,16 +4639,13 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4741 /* Note that the distances in 'pos' excludes us (path[0]) and 4639 /* Note that the distances in 'pos' excludes us (path[0]) and
4742 the next_hop (path[1]), so we need to subtract two 4640 the next_hop (path[1]), so we need to subtract two
4743 and check next_hop explicitly */ 4641 and check next_hop explicitly */
4744 if ( (pos->distance == path_len - 2) && 4642 if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop))
4745 (pos->next_hop == next_hop) )
4746 { 4643 {
4747 int match = GNUNET_YES; 4644 int match = GNUNET_YES;
4748 4645
4749 for (unsigned int i=0;i<pos->distance;i++) 4646 for (unsigned int i = 0; i < pos->distance; i++)
4750 { 4647 {
4751 if (0 != 4648 if (0 != GNUNET_memcmp (&pos->path[i], &path[i + 2]))
4752 GNUNET_memcmp (&pos->path[i],
4753 &path[i+2]))
4754 { 4649 {
4755 match = GNUNET_NO; 4650 match = GNUNET_NO;
4756 break; 4651 break;
@@ -4766,19 +4661,14 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4766 1, 4661 1,
4767 GNUNET_NO); 4662 GNUNET_NO);
4768 last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout); 4663 last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout);
4769 pos->timeout 4664 pos->timeout =
4770 = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); 4665 GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT);
4771 GNUNET_CONTAINER_MDLL_remove (dv, 4666 GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, pos);
4772 dv->dv_head, 4667 GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, pos);
4773 dv->dv_tail,
4774 pos);
4775 GNUNET_CONTAINER_MDLL_insert (dv,
4776 dv->dv_head,
4777 dv->dv_tail,
4778 pos);
4779 if (last_timeout.rel_value_us < 4668 if (last_timeout.rel_value_us <
4780 GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT, 4669 GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT,
4781 DV_PATH_DISCOVERY_FREQUENCY).rel_value_us) 4670 DV_PATH_DISCOVERY_FREQUENCY)
4671 .rel_value_us)
4782 { 4672 {
4783 /* Some peer send DV learn messages too often, we are learning 4673 /* Some peer send DV learn messages too often, we are learning
4784 the same path faster than it would be useful; do not forward! */ 4674 the same path faster than it would be useful; do not forward! */
@@ -4806,10 +4696,7 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4806 sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); 4696 sizeof (struct GNUNET_PeerIdentity) * (path_len - 2));
4807 hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); 4697 hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT);
4808 hop->distance = path_len - 2; 4698 hop->distance = path_len - 2;
4809 GNUNET_CONTAINER_MDLL_insert (dv, 4699 GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, hop);
4810 dv->dv_head,
4811 dv->dv_tail,
4812 hop);
4813 GNUNET_CONTAINER_MDLL_insert (neighbour, 4700 GNUNET_CONTAINER_MDLL_insert (neighbour,
4814 next_hop->dv_head, 4701 next_hop->dv_head,
4815 next_hop->dv_tail, 4702 next_hop->dv_tail,
@@ -4826,8 +4713,7 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4826 * @return #GNUNET_YES if message is well-formed 4713 * @return #GNUNET_YES if message is well-formed
4827 */ 4714 */
4828static int 4715static int
4829check_dv_learn (void *cls, 4716check_dv_learn (void *cls, const struct TransportDVLearn *dvl)
4830 const struct TransportDVLearn *dvl)
4831{ 4717{
4832 uint16_t size = ntohs (dvl->header.size); 4718 uint16_t size = ntohs (dvl->header.size);
4833 uint16_t num_hops = ntohs (dvl->num_hops); 4719 uint16_t num_hops = ntohs (dvl->num_hops);
@@ -4844,16 +4730,14 @@ check_dv_learn (void *cls,
4844 GNUNET_break_op (0); 4730 GNUNET_break_op (0);
4845 return GNUNET_SYSERR; 4731 return GNUNET_SYSERR;
4846 } 4732 }
4847 for (unsigned int i=0;i<num_hops;i++) 4733 for (unsigned int i = 0; i < num_hops; i++)
4848 { 4734 {
4849 if (0 == GNUNET_memcmp (&dvl->initiator, 4735 if (0 == GNUNET_memcmp (&dvl->initiator, &hops[i].hop))
4850 &hops[i].hop))
4851 { 4736 {
4852 GNUNET_break_op (0); 4737 GNUNET_break_op (0);
4853 return GNUNET_SYSERR; 4738 return GNUNET_SYSERR;
4854 } 4739 }
4855 if (0 == GNUNET_memcmp (&GST_my_identity, 4740 if (0 == GNUNET_memcmp (&GST_my_identity, &hops[i].hop))
4856 &hops[i].hop))
4857 { 4741 {
4858 GNUNET_break_op (0); 4742 GNUNET_break_op (0);
4859 return GNUNET_SYSERR; 4743 return GNUNET_SYSERR;
@@ -4871,7 +4755,8 @@ check_dv_learn (void *cls,
4871 * @param bi_history bitmask specifying hops on path that were bidirectional 4755 * @param bi_history bitmask specifying hops on path that were bidirectional
4872 * @param nhops length of the @a hops array 4756 * @param nhops length of the @a hops array
4873 * @param hops path the message traversed so far 4757 * @param hops path the message traversed so far
4874 * @param in_time when did we receive the message, used to calculate network delay 4758 * @param in_time when did we receive the message, used to calculate network
4759 * delay
4875 */ 4760 */
4876static void 4761static void
4877forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, 4762forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
@@ -4895,33 +4780,29 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
4895 fwd->num_hops = htons (nhops + 1); 4780 fwd->num_hops = htons (nhops + 1);
4896 fwd->bidirectional = htons (bi_history); 4781 fwd->bidirectional = htons (bi_history);
4897 nnd = GNUNET_TIME_relative_add (GNUNET_TIME_absolute_get_duration (in_time), 4782 nnd = GNUNET_TIME_relative_add (GNUNET_TIME_absolute_get_duration (in_time),
4898 GNUNET_TIME_relative_ntoh (msg->non_network_delay)); 4783 GNUNET_TIME_relative_ntoh (
4784 msg->non_network_delay));
4899 fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd); 4785 fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd);
4900 fwd->init_sig = msg->init_sig; 4786 fwd->init_sig = msg->init_sig;
4901 fwd->initiator = msg->initiator; 4787 fwd->initiator = msg->initiator;
4902 fwd->challenge = msg->challenge; 4788 fwd->challenge = msg->challenge;
4903 dhops = (struct DVPathEntryP *) &fwd[1]; 4789 dhops = (struct DVPathEntryP *) &fwd[1];
4904 GNUNET_memcpy (dhops, 4790 GNUNET_memcpy (dhops, hops, sizeof (struct DVPathEntryP) * nhops);
4905 hops,
4906 sizeof (struct DVPathEntryP) * nhops);
4907 dhops[nhops].hop = GST_my_identity; 4791 dhops[nhops].hop = GST_my_identity;
4908 { 4792 {
4909 struct DvHopPS dhp = { 4793 struct DvHopPS dhp = {.purpose.purpose =
4910 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), 4794 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP),
4911 .purpose.size = htonl (sizeof (dhp)), 4795 .purpose.size = htonl (sizeof (dhp)),
4912 .pred = dhops[nhops-1].hop, 4796 .pred = dhops[nhops - 1].hop,
4913 .succ = *next_hop, 4797 .succ = *next_hop,
4914 .challenge = msg->challenge 4798 .challenge = msg->challenge};
4915 };
4916 4799
4917 GNUNET_assert (GNUNET_OK == 4800 GNUNET_assert (GNUNET_OK ==
4918 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 4801 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
4919 &dhp.purpose, 4802 &dhp.purpose,
4920 &dhops[nhops].hop_sig)); 4803 &dhops[nhops].hop_sig));
4921 } 4804 }
4922 route_message (next_hop, 4805 route_message (next_hop, &fwd->header, RMO_UNCONFIRMED_ALLOWED);
4923 &fwd->header,
4924 RMO_UNCONFIRMED_ALLOWED);
4925} 4806}
4926 4807
4927 4808
@@ -4934,21 +4815,22 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
4934 * @return #GNUNET_OK if the signature is valid 4815 * @return #GNUNET_OK if the signature is valid
4935 */ 4816 */
4936static int 4817static int
4937validate_dv_initiator_signature (const struct GNUNET_PeerIdentity *init, 4818validate_dv_initiator_signature (
4938 const struct GNUNET_ShortHashCode *challenge, 4819 const struct GNUNET_PeerIdentity *init,
4939 const struct GNUNET_CRYPTO_EddsaSignature *init_sig) 4820 const struct GNUNET_ShortHashCode *challenge,
4940{ 4821 const struct GNUNET_CRYPTO_EddsaSignature *init_sig)
4941 struct DvInitPS ip = { 4822{
4942 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), 4823 struct DvInitPS ip = {.purpose.purpose = htonl (
4943 .purpose.size = htonl (sizeof (ip)), 4824 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR),
4944 .challenge = *challenge 4825 .purpose.size = htonl (sizeof (ip)),
4945 }; 4826 .challenge = *challenge};
4946 4827
4947 if (GNUNET_OK != 4828 if (
4948 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, 4829 GNUNET_OK !=
4949 &ip.purpose, 4830 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR,
4950 init_sig, 4831 &ip.purpose,
4951 &init->public_key)) 4832 init_sig,
4833 &init->public_key))
4952 { 4834 {
4953 GNUNET_break_op (0); 4835 GNUNET_break_op (0);
4954 return GNUNET_SYSERR; 4836 return GNUNET_SYSERR;
@@ -4960,12 +4842,12 @@ validate_dv_initiator_signature (const struct GNUNET_PeerIdentity *init,
4960/** 4842/**
4961 * Communicator gave us a DV learn message. Process the request. 4843 * Communicator gave us a DV learn message. Process the request.
4962 * 4844 *
4963 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4845 * @param cls a `struct CommunicatorMessageContext` (must call
4846 * #finish_cmc_handling() when done)
4964 * @param dvl the message that was received 4847 * @param dvl the message that was received
4965 */ 4848 */
4966static void 4849static void
4967handle_dv_learn (void *cls, 4850handle_dv_learn (void *cls, const struct TransportDVLearn *dvl)
4968 const struct TransportDVLearn *dvl)
4969{ 4851{
4970 struct CommunicatorMessageContext *cmc = cls; 4852 struct CommunicatorMessageContext *cmc = cls;
4971 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; 4853 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
@@ -4983,8 +4865,7 @@ handle_dv_learn (void *cls,
4983 if (0 == nhops) 4865 if (0 == nhops)
4984 { 4866 {
4985 /* sanity check */ 4867 /* sanity check */
4986 if (0 != GNUNET_memcmp (&dvl->initiator, 4868 if (0 != GNUNET_memcmp (&dvl->initiator, &cmc->im.sender))
4987 &cmc->im.sender))
4988 { 4869 {
4989 GNUNET_break (0); 4870 GNUNET_break (0);
4990 finish_cmc_handling (cmc); 4871 finish_cmc_handling (cmc);
@@ -4994,8 +4875,7 @@ handle_dv_learn (void *cls,
4994 else 4875 else
4995 { 4876 {
4996 /* sanity check */ 4877 /* sanity check */
4997 if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, 4878 if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, &cmc->im.sender))
4998 &cmc->im.sender))
4999 { 4879 {
5000 GNUNET_break (0); 4880 GNUNET_break (0);
5001 finish_cmc_handling (cmc); 4881 finish_cmc_handling (cmc);
@@ -5005,7 +4885,8 @@ handle_dv_learn (void *cls,
5005 4885
5006 GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type); 4886 GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type);
5007 cc = cmc->tc->details.communicator.cc; 4887 cc = cmc->tc->details.communicator.cc;
5008 bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE == cc); // FIXME: add bi-directional flag to cc? 4888 bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE ==
4889 cc); // FIXME: add bi-directional flag to cc?
5009 in_time = GNUNET_TIME_absolute_get (); 4890 in_time = GNUNET_TIME_absolute_get ();
5010 4891
5011 /* continue communicator here, everything else can happen asynchronous! */ 4892 /* continue communicator here, everything else can happen asynchronous! */
@@ -5013,20 +4894,19 @@ handle_dv_learn (void *cls,
5013 4894
5014 /* OPTIMIZE-FIXME: Technically, we only need to bother checking 4895 /* OPTIMIZE-FIXME: Technically, we only need to bother checking
5015 the initiator signature if we send the message back to the initiator... */ 4896 the initiator signature if we send the message back to the initiator... */
5016 if (GNUNET_OK != 4897 if (GNUNET_OK != validate_dv_initiator_signature (&dvl->initiator,
5017 validate_dv_initiator_signature (&dvl->initiator, 4898 &dvl->challenge,
5018 &dvl->challenge, 4899 &dvl->init_sig))
5019 &dvl->init_sig))
5020 { 4900 {
5021 GNUNET_break_op (0); 4901 GNUNET_break_op (0);
5022 return; 4902 return;
5023 } 4903 }
5024 // FIXME: asynchronously (!) verify hop-by-hop signatures! 4904 // FIXME: asynchronously (!) verify hop-by-hop signatures!
5025 // => if signature verification load too high, implement random drop strategy!? 4905 // => if signature verification load too high, implement random drop
4906 // strategy!?
5026 4907
5027 do_fwd = GNUNET_YES; 4908 do_fwd = GNUNET_YES;
5028 if (0 == GNUNET_memcmp (&GST_my_identity, 4909 if (0 == GNUNET_memcmp (&GST_my_identity, &dvl->initiator))
5029 &dvl->initiator))
5030 { 4910 {
5031 struct GNUNET_PeerIdentity path[nhops + 1]; 4911 struct GNUNET_PeerIdentity path[nhops + 1];
5032 struct GNUNET_TIME_Relative host_latency_sum; 4912 struct GNUNET_TIME_Relative host_latency_sum;
@@ -5043,27 +4923,22 @@ handle_dv_learn (void *cls,
5043 latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly 4923 latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly
5044 // (based on dvl->challenge, we can identify time of origin!) 4924 // (based on dvl->challenge, we can identify time of origin!)
5045 4925
5046 network_latency = GNUNET_TIME_relative_subtract (latency, 4926 network_latency = GNUNET_TIME_relative_subtract (latency, host_latency_sum);
5047 host_latency_sum);
5048 /* assumption: latency on all links is the same */ 4927 /* assumption: latency on all links is the same */
5049 network_latency = GNUNET_TIME_relative_divide (network_latency, 4928 network_latency = GNUNET_TIME_relative_divide (network_latency, nhops);
5050 nhops);
5051 4929
5052 for (unsigned int i=2;i<=nhops;i++) 4930 for (unsigned int i = 2; i <= nhops; i++)
5053 { 4931 {
5054 struct GNUNET_TIME_Relative ilat; 4932 struct GNUNET_TIME_Relative ilat;
5055 4933
5056 /* assumption: linear latency increase per hop */ 4934 /* assumption: linear latency increase per hop */
5057 ilat = GNUNET_TIME_relative_multiply (network_latency, 4935 ilat = GNUNET_TIME_relative_multiply (network_latency, i);
5058 i); 4936 path[i] = hops[i - 1].hop;
5059 path[i] = hops[i-1].hop;
5060 // FIXME: mark ALL of these as *confirmed* (with what timeout?) 4937 // FIXME: mark ALL of these as *confirmed* (with what timeout?)
5061 // -- and schedule a job for the confirmation to time out! -- 4938 // -- and schedule a job for the confirmation to time out! --
5062 // and possibly do #cores_send_connect_info() if 4939 // and possibly do #cores_send_connect_info() if
5063 // the respective neighbour is NOT confirmed yet! 4940 // the respective neighbour is NOT confirmed yet!
5064 learn_dv_path (path, 4941 learn_dv_path (path, i, ilat);
5065 i,
5066 ilat);
5067 } 4942 }
5068 /* as we initiated, do not forward again (would be circular!) */ 4943 /* as we initiated, do not forward again (would be circular!) */
5069 do_fwd = GNUNET_NO; 4944 do_fwd = GNUNET_NO;
@@ -5076,7 +4951,7 @@ handle_dv_learn (void *cls,
5076 4951
5077 path[0] = GST_my_identity; 4952 path[0] = GST_my_identity;
5078 path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */ 4953 path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */
5079 for (unsigned int i=0;i<nhops;i++) 4954 for (unsigned int i = 0; i < nhops; i++)
5080 { 4955 {
5081 int iret; 4956 int iret;
5082 4957
@@ -5091,9 +4966,7 @@ handle_dv_learn (void *cls,
5091 path[i + 2] = hops[nhops - i - 2].hop; 4966 path[i + 2] = hops[nhops - i - 2].hop;
5092 } 4967 }
5093 4968
5094 iret = learn_dv_path (path, 4969 iret = learn_dv_path (path, i + 2, GNUNET_TIME_UNIT_FOREVER_REL);
5095 i + 2,
5096 GNUNET_TIME_UNIT_FOREVER_REL);
5097 if (GNUNET_SYSERR == iret) 4970 if (GNUNET_SYSERR == iret)
5098 { 4971 {
5099 /* path invalid or too long to be interesting for US, thus should also 4972 /* path invalid or too long to be interesting for US, thus should also
@@ -5107,8 +4980,7 @@ handle_dv_learn (void *cls,
5107 do_fwd = GNUNET_NO; 4980 do_fwd = GNUNET_NO;
5108 break; 4981 break;
5109 } 4982 }
5110 if ( (GNUNET_NO == iret) && 4983 if ((GNUNET_NO == iret) && (nhops == i + 1))
5111 (nhops == i + 1) )
5112 { 4984 {
5113 /* we have better paths, and this is the longest target, 4985 /* we have better paths, and this is the longest target,
5114 so there cannot be anything interesting later */ 4986 so there cannot be anything interesting later */
@@ -5132,27 +5004,20 @@ handle_dv_learn (void *cls,
5132 /* Forward to initiator, if path non-trivial and possible */ 5004 /* Forward to initiator, if path non-trivial and possible */
5133 bi_history = (bi_history << 1) | (bi_hop ? 1 : 0); 5005 bi_history = (bi_history << 1) | (bi_hop ? 1 : 0);
5134 did_initiator = GNUNET_NO; 5006 did_initiator = GNUNET_NO;
5135 if ( (1 < nhops) && 5007 if ((1 < nhops) &&
5136 (GNUNET_YES == 5008 (GNUNET_YES ==
5137 GNUNET_CONTAINER_multipeermap_contains (neighbours, 5009 GNUNET_CONTAINER_multipeermap_contains (neighbours, &dvl->initiator)))
5138 &dvl->initiator)) )
5139 { 5010 {
5140 /* send back to origin! */ 5011 /* send back to origin! */
5141 forward_dv_learn (&dvl->initiator, 5012 forward_dv_learn (&dvl->initiator, dvl, bi_history, nhops, hops, in_time);
5142 dvl,
5143 bi_history,
5144 nhops,
5145 hops,
5146 in_time);
5147 did_initiator = GNUNET_YES; 5013 did_initiator = GNUNET_YES;
5148 } 5014 }
5149 /* We forward under two conditions: either we still learned something 5015 /* We forward under two conditions: either we still learned something
5150 ourselves (do_fwd), or the path was darn short and thus the initiator is 5016 ourselves (do_fwd), or the path was darn short and thus the initiator is
5151 likely to still be very interested in this (and we did NOT already 5017 likely to still be very interested in this (and we did NOT already
5152 send it back to the initiator) */ 5018 send it back to the initiator) */
5153 if ( (do_fwd) || 5019 if ((do_fwd) || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) &&
5154 ( (nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) && 5020 (GNUNET_NO == did_initiator)))
5155 (GNUNET_NO == did_initiator) ) )
5156 { 5021 {
5157 /* FIXME: loop over all neighbours, pick those with low 5022 /* FIXME: loop over all neighbours, pick those with low
5158 queues AND that are not yet on the path; possibly 5023 queues AND that are not yet on the path; possibly
@@ -5177,38 +5042,39 @@ handle_dv_learn (void *cls,
5177 * @return #GNUNET_YES if message is well-formed 5042 * @return #GNUNET_YES if message is well-formed
5178 */ 5043 */
5179static int 5044static int
5180check_dv_box (void *cls, 5045check_dv_box (void *cls, const struct TransportDVBox *dvb)
5181 const struct TransportDVBox *dvb)
5182{ 5046{
5183 uint16_t size = ntohs (dvb->header.size); 5047 uint16_t size = ntohs (dvb->header.size);
5184 uint16_t num_hops = ntohs (dvb->num_hops); 5048 uint16_t num_hops = ntohs (dvb->num_hops);
5185 const struct GNUNET_PeerIdentity *hops = (const struct GNUNET_PeerIdentity *) &dvb[1]; 5049 const struct GNUNET_PeerIdentity *hops =
5186 const struct GNUNET_MessageHeader *inbox = (const struct GNUNET_MessageHeader *) &hops[num_hops]; 5050 (const struct GNUNET_PeerIdentity *) &dvb[1];
5051 const struct GNUNET_MessageHeader *inbox =
5052 (const struct GNUNET_MessageHeader *) &hops[num_hops];
5187 uint16_t isize; 5053 uint16_t isize;
5188 uint16_t itype; 5054 uint16_t itype;
5189 5055
5190 (void) cls; 5056 (void) cls;
5191 if (size < sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + sizeof (struct GNUNET_MessageHeader)) 5057 if (size < sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) +
5058 sizeof (struct GNUNET_MessageHeader))
5192 { 5059 {
5193 GNUNET_break_op (0); 5060 GNUNET_break_op (0);
5194 return GNUNET_SYSERR; 5061 return GNUNET_SYSERR;
5195 } 5062 }
5196 isize = ntohs (inbox->size); 5063 isize = ntohs (inbox->size);
5197 if (size != sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + isize) 5064 if (size !=
5065 sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + isize)
5198 { 5066 {
5199 GNUNET_break_op (0); 5067 GNUNET_break_op (0);
5200 return GNUNET_SYSERR; 5068 return GNUNET_SYSERR;
5201 } 5069 }
5202 itype = ntohs (inbox->type); 5070 itype = ntohs (inbox->type);
5203 if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX == itype) || 5071 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX == itype) ||
5204 (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN == itype) ) 5072 (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN == itype))
5205 { 5073 {
5206 GNUNET_break_op (0); 5074 GNUNET_break_op (0);
5207 return GNUNET_SYSERR; 5075 return GNUNET_SYSERR;
5208 } 5076 }
5209 if (0 == 5077 if (0 == GNUNET_memcmp (&dvb->origin, &GST_my_identity))
5210 GNUNET_memcmp (&dvb->origin,
5211 &GST_my_identity))
5212 { 5078 {
5213 GNUNET_break_op (0); 5079 GNUNET_break_op (0);
5214 return GNUNET_SYSERR; 5080 return GNUNET_SYSERR;
@@ -5241,74 +5107,66 @@ forward_dv_box (struct Neighbour *next_hop,
5241 struct TransportDVBox *dvb; 5107 struct TransportDVBox *dvb;
5242 struct GNUNET_PeerIdentity *dhops; 5108 struct GNUNET_PeerIdentity *dhops;
5243 5109
5244 GNUNET_assert (UINT16_MAX < 5110 GNUNET_assert (UINT16_MAX < sizeof (struct TransportDVBox) +
5245 sizeof (struct TransportDVBox) + 5111 sizeof (struct GNUNET_PeerIdentity) * num_hops +
5246 sizeof (struct GNUNET_PeerIdentity) * num_hops + 5112 payload_size);
5247 payload_size);
5248 dvb = GNUNET_malloc (sizeof (struct TransportDVBox) + 5113 dvb = GNUNET_malloc (sizeof (struct TransportDVBox) +
5249 sizeof (struct GNUNET_PeerIdentity) * num_hops + 5114 sizeof (struct GNUNET_PeerIdentity) * num_hops +
5250 payload_size); 5115 payload_size);
5251 dvb->header.size = htons (sizeof (struct TransportDVBox) + 5116 dvb->header.size =
5252 sizeof (struct GNUNET_PeerIdentity) * num_hops + 5117 htons (sizeof (struct TransportDVBox) +
5253 payload_size); 5118 sizeof (struct GNUNET_PeerIdentity) * num_hops + payload_size);
5254 dvb->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX); 5119 dvb->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX);
5255 dvb->total_hops = htons (total_hops); 5120 dvb->total_hops = htons (total_hops);
5256 dvb->num_hops = htons (num_hops); 5121 dvb->num_hops = htons (num_hops);
5257 dvb->origin = *origin; 5122 dvb->origin = *origin;
5258 dhops = (struct GNUNET_PeerIdentity *) &dvb[1]; 5123 dhops = (struct GNUNET_PeerIdentity *) &dvb[1];
5259 memcpy (dhops, 5124 memcpy (dhops, hops, num_hops * sizeof (struct GNUNET_PeerIdentity));
5260 hops, 5125 memcpy (&dhops[num_hops], payload, payload_size);
5261 num_hops * sizeof (struct GNUNET_PeerIdentity)); 5126 route_message (&next_hop->pid, &dvb->header, RMO_NONE);
5262 memcpy (&dhops[num_hops],
5263 payload,
5264 payload_size);
5265 route_message (&next_hop->pid,
5266 &dvb->header,
5267 RMO_NONE);
5268} 5127}
5269 5128
5270 5129
5271/** 5130/**
5272 * Communicator gave us a DV box. Process the request. 5131 * Communicator gave us a DV box. Process the request.
5273 * 5132 *
5274 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 5133 * @param cls a `struct CommunicatorMessageContext` (must call
5134 * #finish_cmc_handling() when done)
5275 * @param dvb the message that was received 5135 * @param dvb the message that was received
5276 */ 5136 */
5277static void 5137static void
5278handle_dv_box (void *cls, 5138handle_dv_box (void *cls, const struct TransportDVBox *dvb)
5279 const struct TransportDVBox *dvb)
5280{ 5139{
5281 struct CommunicatorMessageContext *cmc = cls; 5140 struct CommunicatorMessageContext *cmc = cls;
5282 uint16_t size = ntohs (dvb->header.size) - sizeof (*dvb); 5141 uint16_t size = ntohs (dvb->header.size) - sizeof (*dvb);
5283 uint16_t num_hops = ntohs (dvb->num_hops); 5142 uint16_t num_hops = ntohs (dvb->num_hops);
5284 const struct GNUNET_PeerIdentity *hops = (const struct GNUNET_PeerIdentity *) &dvb[1]; 5143 const struct GNUNET_PeerIdentity *hops =
5285 const struct GNUNET_MessageHeader *inbox = (const struct GNUNET_MessageHeader *) &hops[num_hops]; 5144 (const struct GNUNET_PeerIdentity *) &dvb[1];
5145 const struct GNUNET_MessageHeader *inbox =
5146 (const struct GNUNET_MessageHeader *) &hops[num_hops];
5286 5147
5287 if (num_hops > 0) 5148 if (num_hops > 0)
5288 { 5149 {
5289 /* We're trying from the end of the hops array, as we may be 5150 /* We're trying from the end of the hops array, as we may be
5290 able to find a shortcut unknown to the origin that way */ 5151 able to find a shortcut unknown to the origin that way */
5291 for (int i=num_hops-1;i>=0;i--) 5152 for (int i = num_hops - 1; i >= 0; i--)
5292 { 5153 {
5293 struct Neighbour *n; 5154 struct Neighbour *n;
5294 5155
5295 if (0 == 5156 if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity))
5296 GNUNET_memcmp (&hops[i],
5297 &GST_my_identity))
5298 { 5157 {
5299 GNUNET_break_op (0); 5158 GNUNET_break_op (0);
5300 finish_cmc_handling (cmc); 5159 finish_cmc_handling (cmc);
5301 return; 5160 return;
5302 } 5161 }
5303 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 5162 n = GNUNET_CONTAINER_multipeermap_get (neighbours, &hops[i]);
5304 &hops[i]);
5305 if (NULL == n) 5163 if (NULL == n)
5306 continue; 5164 continue;
5307 forward_dv_box (n, 5165 forward_dv_box (n,
5308 ntohs (dvb->total_hops) + 1, 5166 ntohs (dvb->total_hops) + 1,
5309 num_hops - i - 1, /* number of hops left */ 5167 num_hops - i - 1, /* number of hops left */
5310 &dvb->origin, 5168 &dvb->origin,
5311 &hops[i+1], /* remaining hops */ 5169 &hops[i + 1], /* remaining hops */
5312 (const void *) &dvb[1], 5170 (const void *) &dvb[1],
5313 size); 5171 size);
5314 finish_cmc_handling (cmc); 5172 finish_cmc_handling (cmc);
@@ -5325,8 +5183,7 @@ handle_dv_box (void *cls,
5325 /* We are the target. Unbox and handle message. */ 5183 /* We are the target. Unbox and handle message. */
5326 cmc->im.sender = dvb->origin; 5184 cmc->im.sender = dvb->origin;
5327 cmc->total_hops = ntohs (dvb->total_hops); 5185 cmc->total_hops = ntohs (dvb->total_hops);
5328 demultiplex_with_cmc (cmc, 5186 demultiplex_with_cmc (cmc, inbox);
5329 inbox);
5330} 5187}
5331 5188
5332 5189
@@ -5354,9 +5211,11 @@ check_incoming_msg (void *cls,
5354 5211
5355 5212
5356/** 5213/**
5357 * Communicator gave us a transport address validation challenge. Process the request. 5214 * Communicator gave us a transport address validation challenge. Process the
5215 * request.
5358 * 5216 *
5359 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 5217 * @param cls a `struct CommunicatorMessageContext` (must call
5218 * #finish_cmc_handling() when done)
5360 * @param tvc the message that was received 5219 * @param tvc the message that was received
5361 */ 5220 */
5362static void 5221static void
@@ -5374,24 +5233,23 @@ handle_validation_challenge (void *cls,
5374 return; 5233 return;
5375 } 5234 }
5376 tvr = GNUNET_new (struct TransportValidationResponse); 5235 tvr = GNUNET_new (struct TransportValidationResponse);
5377 tvr->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); 5236 tvr->header.type =
5237 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE);
5378 tvr->header.size = htons (sizeof (*tvr)); 5238 tvr->header.size = htons (sizeof (*tvr));
5379 tvr->challenge = tvc->challenge; 5239 tvr->challenge = tvc->challenge;
5380 tvr->origin_time = tvc->sender_time; 5240 tvr->origin_time = tvc->sender_time;
5381 tvr->validity_duration = cmc->im.expected_address_validity; 5241 tvr->validity_duration = cmc->im.expected_address_validity;
5382 { 5242 {
5383 /* create signature */ 5243 /* create signature */
5384 struct TransportValidationPS tvp = { 5244 struct TransportValidationPS tvp =
5385 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), 5245 {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
5386 .purpose.size = htonl (sizeof (tvp)), 5246 .purpose.size = htonl (sizeof (tvp)),
5387 .validity_duration = tvr->validity_duration, 5247 .validity_duration = tvr->validity_duration,
5388 .challenge = tvc->challenge 5248 .challenge = tvc->challenge};
5389 };
5390 5249
5391 GNUNET_assert (GNUNET_OK == 5250 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
5392 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 5251 &tvp.purpose,
5393 &tvp.purpose, 5252 &tvr->signature));
5394 &tvr->signature));
5395 } 5253 }
5396 route_message (&cmc->im.sender, 5254 route_message (&cmc->im.sender,
5397 &tvr->header, 5255 &tvr->header,
@@ -5435,8 +5293,7 @@ check_known_challenge (void *cls,
5435 struct ValidationState *vs = value; 5293 struct ValidationState *vs = value;
5436 5294
5437 (void) pid; 5295 (void) pid;
5438 if (0 != GNUNET_memcmp (&vs->challenge, 5296 if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge))
5439 ckac->challenge))
5440 return GNUNET_OK; 5297 return GNUNET_OK;
5441 ckac->vs = vs; 5298 ckac->vs = vs;
5442 return GNUNET_NO; 5299 return GNUNET_NO;
@@ -5451,8 +5308,7 @@ check_known_challenge (void *cls,
5451 * @param success #GNUNET_YES on success 5308 * @param success #GNUNET_YES on success
5452 */ 5309 */
5453static void 5310static void
5454peerstore_store_validation_cb (void *cls, 5311peerstore_store_validation_cb (void *cls, int success)
5455 int success)
5456{ 5312{
5457 struct ValidationState *vs = cls; 5313 struct ValidationState *vs = cls;
5458 5314
@@ -5492,25 +5348,22 @@ update_next_challenge_time (struct ValidationState *vs,
5492 return; /* be lazy */ 5348 return; /* be lazy */
5493 vs->next_challenge = new_time; 5349 vs->next_challenge = new_time;
5494 if (NULL == vs->hn) 5350 if (NULL == vs->hn)
5495 vs->hn = GNUNET_CONTAINER_heap_insert (validation_heap, 5351 vs->hn =
5496 vs, 5352 GNUNET_CONTAINER_heap_insert (validation_heap, vs, new_time.abs_value_us);
5497 new_time.abs_value_us);
5498 else 5353 else
5499 GNUNET_CONTAINER_heap_update_cost (vs->hn, 5354 GNUNET_CONTAINER_heap_update_cost (vs->hn, new_time.abs_value_us);
5500 new_time.abs_value_us); 5355 if ((vs != GNUNET_CONTAINER_heap_peek (validation_heap)) &&
5501 if ( (vs != GNUNET_CONTAINER_heap_peek (validation_heap)) && 5356 (NULL != validation_task))
5502 (NULL != validation_task) )
5503 return; 5357 return;
5504 if (NULL != validation_task) 5358 if (NULL != validation_task)
5505 GNUNET_SCHEDULER_cancel (validation_task); 5359 GNUNET_SCHEDULER_cancel (validation_task);
5506 /* randomize a bit */ 5360 /* randomize a bit */
5507 delta.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 5361 delta.rel_value_us =
5508 MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); 5362 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
5509 new_time = GNUNET_TIME_absolute_add (new_time, 5363 MIN_DELAY_ADDRESS_VALIDATION.rel_value_us);
5510 delta); 5364 new_time = GNUNET_TIME_absolute_add (new_time, delta);
5511 validation_task = GNUNET_SCHEDULER_add_at (new_time, 5365 validation_task =
5512 &validation_start_cb, 5366 GNUNET_SCHEDULER_add_at (new_time, &validation_start_cb, NULL);
5513 NULL);
5514} 5367}
5515 5368
5516 5369
@@ -5522,21 +5375,17 @@ update_next_challenge_time (struct ValidationState *vs,
5522 * @return NULL if no such queue exists 5375 * @return NULL if no such queue exists
5523 */ 5376 */
5524static struct Queue * 5377static struct Queue *
5525find_queue (const struct GNUNET_PeerIdentity *pid, 5378find_queue (const struct GNUNET_PeerIdentity *pid, const char *address)
5526 const char *address)
5527{ 5379{
5528 struct Neighbour *n; 5380 struct Neighbour *n;
5529 5381
5530 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 5382 n = GNUNET_CONTAINER_multipeermap_get (neighbours, pid);
5531 pid);
5532 if (NULL == n) 5383 if (NULL == n)
5533 return NULL; 5384 return NULL;
5534 for (struct Queue *pos = n->queue_head; 5385 for (struct Queue *pos = n->queue_head; NULL != pos;
5535 NULL != pos;
5536 pos = pos->next_neighbour) 5386 pos = pos->next_neighbour)
5537 { 5387 {
5538 if (0 == strcmp (pos->address, 5388 if (0 == strcmp (pos->address, address))
5539 address))
5540 return pos; 5389 return pos;
5541 } 5390 }
5542 return NULL; 5391 return NULL;
@@ -5559,10 +5408,9 @@ core_queue_visibility_check (void *cls)
5559 q->visibility_task = NULL; 5408 q->visibility_task = NULL;
5560 if (0 != GNUNET_TIME_absolute_get_remaining (q->validated_until).rel_value_us) 5409 if (0 != GNUNET_TIME_absolute_get_remaining (q->validated_until).rel_value_us)
5561 { 5410 {
5562 q->visibility_task 5411 q->visibility_task = GNUNET_SCHEDULER_add_at (q->validated_until,
5563 = GNUNET_SCHEDULER_add_at (q->validated_until, 5412 &core_queue_visibility_check,
5564 &core_queue_visibility_check, 5413 q);
5565 q);
5566 return; 5414 return;
5567 } 5415 }
5568 update_neighbour_core_visibility (q->neighbour); 5416 update_neighbour_core_visibility (q->neighbour);
@@ -5586,17 +5434,16 @@ update_neighbour_core_visibility (struct Neighbour *n)
5586 GNUNET_assert (GNUNET_YES == n->core_visible); 5434 GNUNET_assert (GNUNET_YES == n->core_visible);
5587 /* Check if _any_ queue of this neighbour is still valid, if so, schedule 5435 /* Check if _any_ queue of this neighbour is still valid, if so, schedule
5588 the #core_queue_visibility_check() task for that queue */ 5436 the #core_queue_visibility_check() task for that queue */
5589 for (struct Queue *q = n->queue_head; 5437 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
5590 NULL != q;
5591 q = q->next_neighbour)
5592 { 5438 {
5593 if (0 != GNUNET_TIME_absolute_get_remaining (q->validated_until).rel_value_us) 5439 if (0 !=
5440 GNUNET_TIME_absolute_get_remaining (q->validated_until).rel_value_us)
5594 { 5441 {
5595 /* found a valid queue, use this one */ 5442 /* found a valid queue, use this one */
5596 q->visibility_task 5443 q->visibility_task =
5597 = GNUNET_SCHEDULER_add_at (q->validated_until, 5444 GNUNET_SCHEDULER_add_at (q->validated_until,
5598 &core_queue_visibility_check, 5445 &core_queue_visibility_check,
5599 q); 5446 q);
5600 return; 5447 return;
5601 } 5448 }
5602 } 5449 }
@@ -5605,8 +5452,7 @@ update_neighbour_core_visibility (struct Neighbour *n)
5605 /* Check if _any_ DV route to this neighbour is currently 5452 /* Check if _any_ DV route to this neighbour is currently
5606 valid, if so, do NOT tell core about the loss of direct 5453 valid, if so, do NOT tell core about the loss of direct
5607 connectivity (DV still counts!) */ 5454 connectivity (DV still counts!) */
5608 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, 5455 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &n->pid);
5609 &n->pid);
5610 if (GNUNET_YES == dv->core_visible) 5456 if (GNUNET_YES == dv->core_visible)
5611 return; 5457 return;
5612 /* Nothing works anymore, need to tell CORE about the loss of 5458 /* Nothing works anymore, need to tell CORE about the loss of
@@ -5616,9 +5462,11 @@ update_neighbour_core_visibility (struct Neighbour *n)
5616 5462
5617 5463
5618/** 5464/**
5619 * Communicator gave us a transport address validation response. Process the request. 5465 * Communicator gave us a transport address validation response. Process the
5466 * request.
5620 * 5467 *
5621 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 5468 * @param cls a `struct CommunicatorMessageContext` (must call
5469 * #finish_cmc_handling() when done)
5622 * @param tvr the message that was received 5470 * @param tvr the message that was received
5623 */ 5471 */
5624static void 5472static void
@@ -5627,10 +5475,8 @@ handle_validation_response (void *cls,
5627{ 5475{
5628 struct CommunicatorMessageContext *cmc = cls; 5476 struct CommunicatorMessageContext *cmc = cls;
5629 struct ValidationState *vs; 5477 struct ValidationState *vs;
5630 struct CheckKnownChallengeContext ckac = { 5478 struct CheckKnownChallengeContext ckac = {.challenge = &tvr->challenge,
5631 .challenge = &tvr->challenge, 5479 .vs = NULL};
5632 .vs = NULL
5633 };
5634 struct GNUNET_TIME_Absolute origin_time; 5480 struct GNUNET_TIME_Absolute origin_time;
5635 struct Queue *q; 5481 struct Queue *q;
5636 struct DistanceVector *dv; 5482 struct DistanceVector *dv;
@@ -5654,8 +5500,8 @@ handle_validation_response (void *cls,
5654 5500
5655 /* sanity check on origin time */ 5501 /* sanity check on origin time */
5656 origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time); 5502 origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time);
5657 if ( (origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) || 5503 if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) ||
5658 (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us) ) 5504 (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us))
5659 { 5505 {
5660 GNUNET_break_op (0); 5506 GNUNET_break_op (0);
5661 finish_cmc_handling (cmc); 5507 finish_cmc_handling (cmc);
@@ -5664,18 +5510,18 @@ handle_validation_response (void *cls,
5664 5510
5665 { 5511 {
5666 /* check signature */ 5512 /* check signature */
5667 struct TransportValidationPS tvp = { 5513 struct TransportValidationPS tvp =
5668 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), 5514 {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
5669 .purpose.size = htonl (sizeof (tvp)), 5515 .purpose.size = htonl (sizeof (tvp)),
5670 .validity_duration = tvr->validity_duration, 5516 .validity_duration = tvr->validity_duration,
5671 .challenge = tvr->challenge 5517 .challenge = tvr->challenge};
5672 }; 5518
5673 5519 if (
5674 if (GNUNET_OK != 5520 GNUNET_OK !=
5675 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, 5521 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE,
5676 &tvp.purpose, 5522 &tvp.purpose,
5677 &tvr->signature, 5523 &tvr->signature,
5678 &cmc->im.sender.public_key)) 5524 &cmc->im.sender.public_key))
5679 { 5525 {
5680 GNUNET_break_op (0); 5526 GNUNET_break_op (0);
5681 finish_cmc_handling (cmc); 5527 finish_cmc_handling (cmc);
@@ -5685,23 +5531,26 @@ handle_validation_response (void *cls,
5685 5531
5686 /* validity is capped by our willingness to keep track of the 5532 /* validity is capped by our willingness to keep track of the
5687 validation entry and the maximum the other peer allows */ 5533 validation entry and the maximum the other peer allows */
5688 vs->valid_until 5534 vs->valid_until = GNUNET_TIME_relative_to_absolute (
5689 = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_min (GNUNET_TIME_relative_ntoh (tvr->validity_duration), 5535 GNUNET_TIME_relative_min (GNUNET_TIME_relative_ntoh (
5690 MAX_ADDRESS_VALID_UNTIL)); 5536 tvr->validity_duration),
5691 vs->validated_until 5537 MAX_ADDRESS_VALID_UNTIL));
5692 = GNUNET_TIME_absolute_min (vs->valid_until, 5538 vs->validated_until =
5693 GNUNET_TIME_relative_to_absolute (ADDRESS_VALIDATION_LIFETIME)); 5539 GNUNET_TIME_absolute_min (vs->valid_until,
5540 GNUNET_TIME_relative_to_absolute (
5541 ADDRESS_VALIDATION_LIFETIME));
5694 vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time); 5542 vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time);
5695 vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO; 5543 vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO;
5696 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 5544 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
5697 &vs->challenge, 5545 &vs->challenge,
5698 sizeof (vs->challenge)); 5546 sizeof (vs->challenge));
5699 vs->first_challenge_use = GNUNET_TIME_absolute_subtract (vs->validated_until, 5547 vs->first_challenge_use = GNUNET_TIME_absolute_subtract (
5700 GNUNET_TIME_relative_multiply (vs->validation_rtt, 5548 vs->validated_until,
5701 VALIDATION_RTT_BUFFER_FACTOR)); 5549 GNUNET_TIME_relative_multiply (vs->validation_rtt,
5702 vs->last_challenge_use = GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */ 5550 VALIDATION_RTT_BUFFER_FACTOR));
5703 update_next_challenge_time (vs, 5551 vs->last_challenge_use =
5704 vs->first_challenge_use); 5552 GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */
5553 update_next_challenge_time (vs, vs->first_challenge_use);
5705 vs->sc = GNUNET_PEERSTORE_store (peerstore, 5554 vs->sc = GNUNET_PEERSTORE_store (peerstore,
5706 "transport", 5555 "transport",
5707 &cmc->im.sender, 5556 &cmc->im.sender,
@@ -5716,8 +5565,7 @@ handle_validation_response (void *cls,
5716 5565
5717 /* Finally, we now possibly have a confirmed (!) working queue, 5566 /* Finally, we now possibly have a confirmed (!) working queue,
5718 update queue status (if queue still is around) */ 5567 update queue status (if queue still is around) */
5719 q = find_queue (&vs->pid, 5568 q = find_queue (&vs->pid, vs->address);
5720 vs->address);
5721 if (NULL == q) 5569 if (NULL == q)
5722 { 5570 {
5723 GNUNET_STATISTICS_update (GST_stats, 5571 GNUNET_STATISTICS_update (GST_stats,
@@ -5731,20 +5579,17 @@ handle_validation_response (void *cls,
5731 if (GNUNET_NO != q->neighbour->core_visible) 5579 if (GNUNET_NO != q->neighbour->core_visible)
5732 return; /* nothing changed, we are done here */ 5580 return; /* nothing changed, we are done here */
5733 q->neighbour->core_visible = GNUNET_YES; 5581 q->neighbour->core_visible = GNUNET_YES;
5734 q->visibility_task 5582 q->visibility_task = GNUNET_SCHEDULER_add_at (q->validated_until,
5735 = GNUNET_SCHEDULER_add_at (q->validated_until, 5583 &core_queue_visibility_check,
5736 &core_queue_visibility_check, 5584 q);
5737 q);
5738 /* Check if _any_ DV route to this neighbour is 5585 /* Check if _any_ DV route to this neighbour is
5739 currently valid, if so, do NOT tell core anything! */ 5586 currently valid, if so, do NOT tell core anything! */
5740 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, 5587 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &q->neighbour->pid);
5741 &q->neighbour->pid);
5742 if (GNUNET_YES == dv->core_visible) 5588 if (GNUNET_YES == dv->core_visible)
5743 return; /* nothing changed, done */ 5589 return; /* nothing changed, done */
5744 /* We lacked a confirmed connection to the neighbour 5590 /* We lacked a confirmed connection to the neighbour
5745 before, so tell CORE about it (finally!) */ 5591 before, so tell CORE about it (finally!) */
5746 cores_send_connect_info (&q->neighbour->pid, 5592 cores_send_connect_info (&q->neighbour->pid, GNUNET_BANDWIDTH_ZERO);
5747 GNUNET_BANDWIDTH_ZERO);
5748} 5593}
5749 5594
5750 5595
@@ -5758,12 +5603,12 @@ handle_incoming_msg (void *cls,
5758 const struct GNUNET_TRANSPORT_IncomingMessage *im) 5603 const struct GNUNET_TRANSPORT_IncomingMessage *im)
5759{ 5604{
5760 struct TransportClient *tc = cls; 5605 struct TransportClient *tc = cls;
5761 struct CommunicatorMessageContext *cmc = GNUNET_new (struct CommunicatorMessageContext); 5606 struct CommunicatorMessageContext *cmc =
5607 GNUNET_new (struct CommunicatorMessageContext);
5762 5608
5763 cmc->tc = tc; 5609 cmc->tc = tc;
5764 cmc->im = *im; 5610 cmc->im = *im;
5765 demultiplex_with_cmc (cmc, 5611 demultiplex_with_cmc (cmc, (const struct GNUNET_MessageHeader *) &im[1]);
5766 (const struct GNUNET_MessageHeader *) &im[1]);
5767} 5612}
5768 5613
5769 5614
@@ -5778,49 +5623,49 @@ static void
5778demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, 5623demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
5779 const struct GNUNET_MessageHeader *msg) 5624 const struct GNUNET_MessageHeader *msg)
5780{ 5625{
5781 struct GNUNET_MQ_MessageHandler handlers[] = { 5626 struct GNUNET_MQ_MessageHandler handlers[] =
5782 GNUNET_MQ_hd_var_size (fragment_box, 5627 {GNUNET_MQ_hd_var_size (fragment_box,
5783 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, 5628 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT,
5784 struct TransportFragmentBox, 5629 struct TransportFragmentBox,
5785 &cmc), 5630 &cmc),
5786 GNUNET_MQ_hd_fixed_size (fragment_ack, 5631 GNUNET_MQ_hd_fixed_size (fragment_ack,
5787 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT_ACK, 5632 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT_ACK,
5788 struct TransportFragmentAckMessage, 5633 struct TransportFragmentAckMessage,
5789 &cmc), 5634 &cmc),
5790 GNUNET_MQ_hd_var_size (reliability_box, 5635 GNUNET_MQ_hd_var_size (reliability_box,
5791 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, 5636 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX,
5792 struct TransportReliabilityBox, 5637 struct TransportReliabilityBox,
5793 &cmc), 5638 &cmc),
5794 GNUNET_MQ_hd_fixed_size (reliability_ack, 5639 GNUNET_MQ_hd_fixed_size (reliability_ack,
5795 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, 5640 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK,
5796 struct TransportReliabilityAckMessage, 5641 struct TransportReliabilityAckMessage,
5797 &cmc), 5642 &cmc),
5798 GNUNET_MQ_hd_var_size (backchannel_encapsulation, 5643 GNUNET_MQ_hd_var_size (backchannel_encapsulation,
5799 GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, 5644 GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION,
5800 struct TransportBackchannelEncapsulationMessage, 5645 struct TransportBackchannelEncapsulationMessage,
5801 &cmc), 5646 &cmc),
5802 GNUNET_MQ_hd_var_size (dv_learn, 5647 GNUNET_MQ_hd_var_size (dv_learn,
5803 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, 5648 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN,
5804 struct TransportDVLearn, 5649 struct TransportDVLearn,
5805 &cmc), 5650 &cmc),
5806 GNUNET_MQ_hd_var_size (dv_box, 5651 GNUNET_MQ_hd_var_size (dv_box,
5807 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, 5652 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX,
5808 struct TransportDVBox, 5653 struct TransportDVBox,
5809 &cmc), 5654 &cmc),
5810 GNUNET_MQ_hd_fixed_size (validation_challenge, 5655 GNUNET_MQ_hd_fixed_size (
5811 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE, 5656 validation_challenge,
5812 struct TransportValidationChallenge, 5657 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE,
5813 &cmc), 5658 struct TransportValidationChallenge,
5814 GNUNET_MQ_hd_fixed_size (validation_response, 5659 &cmc),
5815 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE, 5660 GNUNET_MQ_hd_fixed_size (
5816 struct TransportValidationResponse, 5661 validation_response,
5817 &cmc), 5662 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE,
5818 GNUNET_MQ_handler_end() 5663 struct TransportValidationResponse,
5819 }; 5664 &cmc),
5665 GNUNET_MQ_handler_end ()};
5820 int ret; 5666 int ret;
5821 5667
5822 ret = GNUNET_MQ_handle_message (handlers, 5668 ret = GNUNET_MQ_handle_message (handlers, msg);
5823 msg);
5824 if (GNUNET_SYSERR == ret) 5669 if (GNUNET_SYSERR == ret)
5825 { 5670 {
5826 GNUNET_break (0); 5671 GNUNET_break (0);
@@ -5831,8 +5676,7 @@ demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
5831 if (GNUNET_NO == ret) 5676 if (GNUNET_NO == ret)
5832 { 5677 {
5833 /* unencapsulated 'raw' message */ 5678 /* unencapsulated 'raw' message */
5834 handle_raw_message (&cmc, 5679 handle_raw_message (&cmc, msg);
5835 msg);
5836 } 5680 }
5837} 5681}
5838 5682
@@ -5873,8 +5717,7 @@ tracker_update_in_cb (void *cls)
5873 unsigned int rsize; 5717 unsigned int rsize;
5874 5718
5875 rsize = (0 == queue->mtu) ? IN_PACKET_SIZE_WITHOUT_MTU : queue->mtu; 5719 rsize = (0 == queue->mtu) ? IN_PACKET_SIZE_WITHOUT_MTU : queue->mtu;
5876 in_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_in, 5720 in_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_in, rsize);
5877 rsize);
5878 // FIXME: how exactly do we do inbound flow control? 5721 // FIXME: how exactly do we do inbound flow control?
5879} 5722}
5880 5723
@@ -5907,8 +5750,7 @@ set_pending_message_uuid (struct PendingMessage *pm)
5907 * @return new message to transmit 5750 * @return new message to transmit
5908 */ 5751 */
5909static struct PendingMessage * 5752static struct PendingMessage *
5910fragment_message (struct PendingMessage *pm, 5753fragment_message (struct PendingMessage *pm, uint16_t mtu)
5911 uint16_t mtu)
5912{ 5754{
5913 struct PendingMessage *ff; 5755 struct PendingMessage *ff;
5914 5756
@@ -5918,19 +5760,16 @@ fragment_message (struct PendingMessage *pm,
5918 GNUNET_assert (mtu > sizeof (struct TransportFragmentBox)); 5760 GNUNET_assert (mtu > sizeof (struct TransportFragmentBox));
5919 5761
5920 /* select fragment for transmission, descending the tree if it has 5762 /* select fragment for transmission, descending the tree if it has
5921 been expanded until we are at a leaf or at a fragment that is small enough */ 5763 been expanded until we are at a leaf or at a fragment that is small enough
5764 */
5922 ff = pm; 5765 ff = pm;
5923 while ( ( (ff->bytes_msg > mtu) || 5766 while (((ff->bytes_msg > mtu) || (pm == ff)) &&
5924 (pm == ff) ) && 5767 (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag))
5925 (ff->frag_off == ff->bytes_msg) &&
5926 (NULL != ff->head_frag) )
5927 { 5768 {
5928 ff = ff->head_frag; /* descent into fragmented fragments */ 5769 ff = ff->head_frag; /* descent into fragmented fragments */
5929 } 5770 }
5930 5771
5931 if ( ( (ff->bytes_msg > mtu) || 5772 if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg))
5932 (pm == ff) ) &&
5933 (pm->frag_off < pm->bytes_msg) )
5934 { 5773 {
5935 /* Did not yet calculate all fragments, calculate next fragment */ 5774 /* Did not yet calculate all fragments, calculate next fragment */
5936 struct PendingMessage *frag; 5775 struct PendingMessage *frag;
@@ -5954,11 +5793,9 @@ fragment_message (struct PendingMessage *pm,
5954 xoff = ntohs (tfbo->frag_off); 5793 xoff = ntohs (tfbo->frag_off);
5955 } 5794 }
5956 fragmax = mtu - sizeof (struct TransportFragmentBox); 5795 fragmax = mtu - sizeof (struct TransportFragmentBox);
5957 fragsize = GNUNET_MIN (msize - ff->frag_off, 5796 fragsize = GNUNET_MIN (msize - ff->frag_off, fragmax);
5958 fragmax);
5959 frag = GNUNET_malloc (sizeof (struct PendingMessage) + 5797 frag = GNUNET_malloc (sizeof (struct PendingMessage) +
5960 sizeof (struct TransportFragmentBox) + 5798 sizeof (struct TransportFragmentBox) + fragsize);
5961 fragsize);
5962 frag->target = pm->target; 5799 frag->target = pm->target;
5963 frag->frag_parent = ff; 5800 frag->frag_parent = ff;
5964 frag->timeout = pm->timeout; 5801 frag->timeout = pm->timeout;
@@ -5966,35 +5803,27 @@ fragment_message (struct PendingMessage *pm,
5966 frag->pmt = PMT_FRAGMENT_BOX; 5803 frag->pmt = PMT_FRAGMENT_BOX;
5967 msg = (char *) &frag[1]; 5804 msg = (char *) &frag[1];
5968 tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); 5805 tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT);
5969 tfb.header.size = htons (sizeof (struct TransportFragmentBox) + 5806 tfb.header.size = htons (sizeof (struct TransportFragmentBox) + fragsize);
5970 fragsize);
5971 tfb.frag_uuid = htonl (pm->frag_uuidgen++); 5807 tfb.frag_uuid = htonl (pm->frag_uuidgen++);
5972 tfb.msg_uuid = pm->msg_uuid; 5808 tfb.msg_uuid = pm->msg_uuid;
5973 tfb.frag_off = htons (ff->frag_off + xoff); 5809 tfb.frag_off = htons (ff->frag_off + xoff);
5974 tfb.msg_size = htons (pm->bytes_msg); 5810 tfb.msg_size = htons (pm->bytes_msg);
5975 memcpy (msg, 5811 memcpy (msg, &tfb, sizeof (tfb));
5976 &tfb, 5812 memcpy (&msg[sizeof (tfb)], &orig[ff->frag_off], fragsize);
5977 sizeof (tfb)); 5813 GNUNET_CONTAINER_MDLL_insert (frag, ff->head_frag, ff->tail_frag, frag);
5978 memcpy (&msg[sizeof (tfb)],
5979 &orig[ff->frag_off],
5980 fragsize);
5981 GNUNET_CONTAINER_MDLL_insert (frag,
5982 ff->head_frag,
5983 ff->tail_frag,
5984 frag);
5985 ff->frag_off += fragsize; 5814 ff->frag_off += fragsize;
5986 ff = frag; 5815 ff = frag;
5987 } 5816 }
5988 5817
5989 /* Move head to the tail and return it */ 5818 /* Move head to the tail and return it */
5990 GNUNET_CONTAINER_MDLL_remove (frag, 5819 GNUNET_CONTAINER_MDLL_remove (frag,
5991 ff->frag_parent->head_frag, 5820 ff->frag_parent->head_frag,
5992 ff->frag_parent->tail_frag, 5821 ff->frag_parent->tail_frag,
5993 ff); 5822 ff);
5994 GNUNET_CONTAINER_MDLL_insert_tail (frag, 5823 GNUNET_CONTAINER_MDLL_insert_tail (frag,
5995 ff->frag_parent->head_frag, 5824 ff->frag_parent->head_frag,
5996 ff->frag_parent->tail_frag, 5825 ff->frag_parent->tail_frag,
5997 ff); 5826 ff);
5998 return ff; 5827 return ff;
5999} 5828}
6000 5829
@@ -6017,7 +5846,8 @@ reliability_box_message (struct PendingMessage *pm)
6017 char *msg; 5846 char *msg;
6018 5847
6019 if (PMT_CORE != pm->pmt) 5848 if (PMT_CORE != pm->pmt)
6020 return pm; /* already fragmented or reliability boxed, or control message: do nothing */ 5849 return pm; /* already fragmented or reliability boxed, or control message:
5850 do nothing */
6021 if (NULL != pm->bpm) 5851 if (NULL != pm->bpm)
6022 return pm->bpm; /* already computed earlier: do nothing */ 5852 return pm->bpm; /* already computed earlier: do nothing */
6023 GNUNET_assert (NULL == pm->head_frag); 5853 GNUNET_assert (NULL == pm->head_frag);
@@ -6025,20 +5855,14 @@ reliability_box_message (struct PendingMessage *pm)
6025 { 5855 {
6026 /* failed hard */ 5856 /* failed hard */
6027 GNUNET_break (0); 5857 GNUNET_break (0);
6028 client_send_response (pm, 5858 client_send_response (pm, GNUNET_NO, 0);
6029 GNUNET_NO,
6030 0);
6031 return NULL; 5859 return NULL;
6032 } 5860 }
6033 bpm = GNUNET_malloc (sizeof (struct PendingMessage) + 5861 bpm = GNUNET_malloc (sizeof (struct PendingMessage) + sizeof (rbox) +
6034 sizeof (rbox) +
6035 pm->bytes_msg); 5862 pm->bytes_msg);
6036 bpm->target = pm->target; 5863 bpm->target = pm->target;
6037 bpm->frag_parent = pm; 5864 bpm->frag_parent = pm;
6038 GNUNET_CONTAINER_MDLL_insert (frag, 5865 GNUNET_CONTAINER_MDLL_insert (frag, pm->head_frag, pm->tail_frag, bpm);
6039 pm->head_frag,
6040 pm->tail_frag,
6041 bpm);
6042 bpm->timeout = pm->timeout; 5866 bpm->timeout = pm->timeout;
6043 bpm->pmt = PMT_RELIABILITY_BOX; 5867 bpm->pmt = PMT_RELIABILITY_BOX;
6044 bpm->bytes_msg = pm->bytes_msg + sizeof (rbox); 5868 bpm->bytes_msg = pm->bytes_msg + sizeof (rbox);
@@ -6048,12 +5872,8 @@ reliability_box_message (struct PendingMessage *pm)
6048 rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support 5872 rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support
6049 rbox.msg_uuid = pm->msg_uuid; 5873 rbox.msg_uuid = pm->msg_uuid;
6050 msg = (char *) &bpm[1]; 5874 msg = (char *) &bpm[1];
6051 memcpy (msg, 5875 memcpy (msg, &rbox, sizeof (rbox));
6052 &rbox, 5876 memcpy (&msg[sizeof (rbox)], &pm[1], pm->bytes_msg);
6053 sizeof (rbox));
6054 memcpy (&msg[sizeof (rbox)],
6055 &pm[1],
6056 pm->bytes_msg);
6057 pm->bpm = bpm; 5877 pm->bpm = bpm;
6058 return bpm; 5878 return bpm;
6059} 5879}
@@ -6097,8 +5917,9 @@ transmit_on_queue (void *cls)
6097 this queue */) ) 5917 this queue */) )
6098 s = fragment_message (s, 5918 s = fragment_message (s,
6099 (0 == queue->mtu) 5919 (0 == queue->mtu)
6100 ? UINT16_MAX - sizeof (struct GNUNET_TRANSPORT_SendMessageTo) 5920 ? UINT16_MAX -
6101 : queue->mtu); 5921 sizeof (struct GNUNET_TRANSPORT_SendMessageTo)
5922 : queue->mtu);
6102 if (NULL == s) 5923 if (NULL == s)
6103 { 5924 {
6104 /* Fragmentation failed, try next message... */ 5925 /* Fragmentation failed, try next message... */
@@ -6115,56 +5936,45 @@ transmit_on_queue (void *cls)
6115 } 5936 }
6116 5937
6117 /* Pass 's' for transission to the communicator */ 5938 /* Pass 's' for transission to the communicator */
6118 queue_send_msg (queue, 5939 queue_send_msg (queue, s, &s[1], s->bytes_msg);
6119 s,
6120 &s[1],
6121 s->bytes_msg);
6122 // FIXME: do something similar to the logic below 5940 // FIXME: do something similar to the logic below
6123 // in defragmentation / reliability ACK handling! 5941 // in defragmentation / reliability ACK handling!
6124 5942
6125 /* Check if this transmission somehow conclusively finished handing 'pm' 5943 /* Check if this transmission somehow conclusively finished handing 'pm'
6126 even without any explicit ACKs */ 5944 even without any explicit ACKs */
6127 if ( (PMT_CORE == s->pmt) && 5945 if ((PMT_CORE == s->pmt) &&
6128 (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) ) 5946 (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc))
6129 { 5947 {
6130 /* Full message sent, and over reliabile channel */ 5948 /* Full message sent, and over reliabile channel */
6131 client_send_response (pm, 5949 client_send_response (pm, GNUNET_YES, pm->bytes_msg);
6132 GNUNET_YES,
6133 pm->bytes_msg);
6134 } 5950 }
6135 else if ( (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) && 5951 else if ((GNUNET_TRANSPORT_CC_RELIABLE ==
6136 (PMT_FRAGMENT_BOX == s->pmt) ) 5952 queue->tc->details.communicator.cc) &&
5953 (PMT_FRAGMENT_BOX == s->pmt))
6137 { 5954 {
6138 struct PendingMessage *pos; 5955 struct PendingMessage *pos;
6139 5956
6140 /* Fragment sent over reliabile channel */ 5957 /* Fragment sent over reliabile channel */
6141 free_fragment_tree (s); 5958 free_fragment_tree (s);
6142 pos = s->frag_parent; 5959 pos = s->frag_parent;
6143 GNUNET_CONTAINER_MDLL_remove (frag, 5960 GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, s);
6144 pos->head_frag,
6145 pos->tail_frag,
6146 s);
6147 GNUNET_free (s); 5961 GNUNET_free (s);
6148 /* check if subtree is done */ 5962 /* check if subtree is done */
6149 while ( (NULL == pos->head_frag) && 5963 while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) &&
6150 (pos->frag_off == pos->bytes_msg) && 5964 (pos != pm))
6151 (pos != pm) )
6152 { 5965 {
6153 s = pos; 5966 s = pos;
6154 pos = s->frag_parent; 5967 pos = s->frag_parent;
6155 GNUNET_CONTAINER_MDLL_remove (frag, 5968 GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, s);
6156 pos->head_frag,
6157 pos->tail_frag,
6158 s);
6159 GNUNET_free (s); 5969 GNUNET_free (s);
6160 } 5970 }
6161 5971
6162 /* Was this the last applicable fragmment? */ 5972 /* Was this the last applicable fragmment? */
6163 if ( (NULL == pm->head_frag) && 5973 if ((NULL == pm->head_frag) && (pm->frag_off == pm->bytes_msg))
6164 (pm->frag_off == pm->bytes_msg) ) 5974 client_send_response (
6165 client_send_response (pm, 5975 pm,
6166 GNUNET_YES, 5976 GNUNET_YES,
6167 pm->bytes_msg /* FIXME: calculate and add overheads! */); 5977 pm->bytes_msg /* FIXME: calculate and add overheads! */);
6168 } 5978 }
6169 else if (PMT_CORE != pm->pmt) 5979 else if (PMT_CORE != pm->pmt)
6170 { 5980 {
@@ -6182,9 +5992,8 @@ transmit_on_queue (void *cls)
6182 retransmitting. Note that in the future this heuristic should 5992 retransmitting. Note that in the future this heuristic should
6183 likely be improved further (measure RTT stability, consider 5993 likely be improved further (measure RTT stability, consider
6184 message urgency and size when delaying ACKs, etc.) */ 5994 message urgency and size when delaying ACKs, etc.) */
6185 s->next_attempt = GNUNET_TIME_relative_to_absolute 5995 s->next_attempt = GNUNET_TIME_relative_to_absolute (
6186 (GNUNET_TIME_relative_multiply (queue->rtt, 5996 GNUNET_TIME_relative_multiply (queue->rtt, 4));
6187 4));
6188 if (s == pm) 5997 if (s == pm)
6189 { 5998 {
6190 struct PendingMessage *pos; 5999 struct PendingMessage *pos;
@@ -6195,8 +6004,8 @@ transmit_on_queue (void *cls)
6195 neighbour->pending_msg_tail, 6004 neighbour->pending_msg_tail,
6196 pm); 6005 pm);
6197 pos = neighbour->pending_msg_tail; 6006 pos = neighbour->pending_msg_tail;
6198 while ( (NULL != pos) && 6007 while ((NULL != pos) &&
6199 (pm->next_attempt.abs_value_us > pos->next_attempt.abs_value_us) ) 6008 (pm->next_attempt.abs_value_us > pos->next_attempt.abs_value_us))
6200 pos = pos->prev_neighbour; 6009 pos = pos->prev_neighbour;
6201 GNUNET_CONTAINER_MDLL_insert_after (neighbour, 6010 GNUNET_CONTAINER_MDLL_insert_after (neighbour,
6202 neighbour->pending_msg_head, 6011 neighbour->pending_msg_head,
@@ -6210,13 +6019,10 @@ transmit_on_queue (void *cls)
6210 struct PendingMessage *fp = s->frag_parent; 6019 struct PendingMessage *fp = s->frag_parent;
6211 struct PendingMessage *pos; 6020 struct PendingMessage *pos;
6212 6021
6213 GNUNET_CONTAINER_MDLL_remove (frag, 6022 GNUNET_CONTAINER_MDLL_remove (frag, fp->head_frag, fp->tail_frag, s);
6214 fp->head_frag,
6215 fp->tail_frag,
6216 s);
6217 pos = fp->tail_frag; 6023 pos = fp->tail_frag;
6218 while ( (NULL != pos) && 6024 while ((NULL != pos) &&
6219 (s->next_attempt.abs_value_us > pos->next_attempt.abs_value_us) ) 6025 (s->next_attempt.abs_value_us > pos->next_attempt.abs_value_us))
6220 pos = pos->prev_frag; 6026 pos = pos->prev_frag;
6221 GNUNET_CONTAINER_MDLL_insert_after (frag, 6027 GNUNET_CONTAINER_MDLL_insert_after (frag,
6222 fp->head_frag, 6028 fp->head_frag,
@@ -6246,8 +6052,8 @@ tracker_update_out_cb (void *cls)
6246 if (NULL == n->pending_msg_head) 6052 if (NULL == n->pending_msg_head)
6247 { 6053 {
6248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6249 "Bandwidth allocation updated for empty transmission queue `%s'\n", 6055 "Bandwidth allocation updated for empty transmission queue `%s'\n",
6250 queue->address); 6056 queue->address);
6251 return; /* no message pending, nothing to do here! */ 6057 return; /* no message pending, nothing to do here! */
6252 } 6058 }
6253 GNUNET_SCHEDULER_cancel (queue->transmit_task); 6059 GNUNET_SCHEDULER_cancel (queue->transmit_task);
@@ -6279,7 +6085,6 @@ tracker_excess_out_cb (void *cls)
6279} 6085}
6280 6086
6281 6087
6282
6283/** 6088/**
6284 * Bandwidth tracker informs us that excessive inbound bandwidth was allocated 6089 * Bandwidth tracker informs us that excessive inbound bandwidth was allocated
6285 * which is not being used. 6090 * which is not being used.
@@ -6317,15 +6122,13 @@ handle_del_queue_message (void *cls,
6317 GNUNET_SERVICE_client_drop (tc->client); 6122 GNUNET_SERVICE_client_drop (tc->client);
6318 return; 6123 return;
6319 } 6124 }
6320 for (struct Queue *queue = tc->details.communicator.queue_head; 6125 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue;
6321 NULL != queue;
6322 queue = queue->next_client) 6126 queue = queue->next_client)
6323 { 6127 {
6324 struct Neighbour *neighbour = queue->neighbour; 6128 struct Neighbour *neighbour = queue->neighbour;
6325 6129
6326 if ( (dqm->qid != queue->qid) || 6130 if ((dqm->qid != queue->qid) ||
6327 (0 != GNUNET_memcmp (&dqm->receiver, 6131 (0 != GNUNET_memcmp (&dqm->receiver, &neighbour->pid)))
6328 &neighbour->pid)) )
6329 continue; 6132 continue;
6330 free_queue (queue); 6133 free_queue (queue);
6331 GNUNET_SERVICE_client_continue (tc->client); 6134 GNUNET_SERVICE_client_continue (tc->client);
@@ -6358,15 +6161,12 @@ handle_send_message_ack (void *cls,
6358 6161
6359 /* find our queue entry matching the ACK */ 6162 /* find our queue entry matching the ACK */
6360 qe = NULL; 6163 qe = NULL;
6361 for (struct Queue *queue = tc->details.communicator.queue_head; 6164 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue;
6362 NULL != queue;
6363 queue = queue->next_client) 6165 queue = queue->next_client)
6364 { 6166 {
6365 if (0 != GNUNET_memcmp (&queue->neighbour->pid, 6167 if (0 != GNUNET_memcmp (&queue->neighbour->pid, &sma->receiver))
6366 &sma->receiver))
6367 continue; 6168 continue;
6368 for (struct QueueEntry *qep = queue->queue_head; 6169 for (struct QueueEntry *qep = queue->queue_head; NULL != qep;
6369 NULL != qep;
6370 qep = qep->next) 6170 qep = qep->next)
6371 { 6171 {
6372 if (qep->mid != sma->mid) 6172 if (qep->mid != sma->mid)
@@ -6391,13 +6191,15 @@ handle_send_message_ack (void *cls,
6391 GNUNET_SERVICE_client_continue (tc->client); 6191 GNUNET_SERVICE_client_continue (tc->client);
6392 6192
6393 /* if applicable, resume transmissions that waited on ACK */ 6193 /* if applicable, resume transmissions that waited on ACK */
6394 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 == tc->details.communicator.total_queue_length) 6194 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 ==
6195 tc->details.communicator.total_queue_length)
6395 { 6196 {
6396 /* Communicator dropped below threshold, resume all queues */ 6197 /* Communicator dropped below threshold, resume all queues */
6397 GNUNET_STATISTICS_update (GST_stats, 6198 GNUNET_STATISTICS_update (
6398 "# Transmission throttled due to communicator queue limit", 6199 GST_stats,
6399 -1, 6200 "# Transmission throttled due to communicator queue limit",
6400 GNUNET_NO); 6201 -1,
6202 GNUNET_NO);
6401 for (struct Queue *queue = tc->details.communicator.queue_head; 6203 for (struct Queue *queue = tc->details.communicator.queue_head;
6402 NULL != queue; 6204 NULL != queue;
6403 queue = queue->next_client) 6205 queue = queue->next_client)
@@ -6440,22 +6242,15 @@ notify_client_queues (void *cls,
6440 struct Neighbour *neighbour = value; 6242 struct Neighbour *neighbour = value;
6441 6243
6442 GNUNET_assert (CT_MONITOR == tc->type); 6244 GNUNET_assert (CT_MONITOR == tc->type);
6443 for (struct Queue *q = neighbour->queue_head; 6245 for (struct Queue *q = neighbour->queue_head; NULL != q;
6444 NULL != q;
6445 q = q->next_neighbour) 6246 q = q->next_neighbour)
6446 { 6247 {
6447 struct MonitorEvent me = { 6248 struct MonitorEvent me = {.rtt = q->rtt,
6448 .rtt = q->rtt, 6249 .cs = q->cs,
6449 .cs = q->cs, 6250 .num_msg_pending = q->num_msg_pending,
6450 .num_msg_pending = q->num_msg_pending, 6251 .num_bytes_pending = q->num_bytes_pending};
6451 .num_bytes_pending = q->num_bytes_pending
6452 };
6453 6252
6454 notify_monitor (tc, 6253 notify_monitor (tc, pid, q->address, q->nt, &me);
6455 pid,
6456 q->address,
6457 q->nt,
6458 &me);
6459 } 6254 }
6460 return GNUNET_OK; 6255 return GNUNET_OK;
6461} 6256}
@@ -6482,9 +6277,7 @@ handle_monitor_start (void *cls,
6482 tc->type = CT_MONITOR; 6277 tc->type = CT_MONITOR;
6483 tc->details.monitor.peer = start->peer; 6278 tc->details.monitor.peer = start->peer;
6484 tc->details.monitor.one_shot = ntohl (start->one_shot); 6279 tc->details.monitor.one_shot = ntohl (start->one_shot);
6485 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 6280 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &notify_client_queues, tc);
6486 &notify_client_queues,
6487 tc);
6488 GNUNET_SERVICE_client_mark_monitor (tc->client); 6281 GNUNET_SERVICE_client_mark_monitor (tc->client);
6489 GNUNET_SERVICE_client_continue (tc->client); 6282 GNUNET_SERVICE_client_continue (tc->client);
6490} 6283}
@@ -6500,19 +6293,17 @@ handle_monitor_start (void *cls,
6500static struct TransportClient * 6293static struct TransportClient *
6501lookup_communicator (const char *prefix) 6294lookup_communicator (const char *prefix)
6502{ 6295{
6503 for (struct TransportClient *tc = clients_head; 6296 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
6504 NULL != tc;
6505 tc = tc->next)
6506 { 6297 {
6507 if (CT_COMMUNICATOR != tc->type) 6298 if (CT_COMMUNICATOR != tc->type)
6508 continue; 6299 continue;
6509 if (0 == strcmp (prefix, 6300 if (0 == strcmp (prefix, tc->details.communicator.address_prefix))
6510 tc->details.communicator.address_prefix))
6511 return tc; 6301 return tc;
6512 } 6302 }
6513 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 6303 GNUNET_log (
6514 "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n", 6304 GNUNET_ERROR_TYPE_WARNING,
6515 prefix); 6305 "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n",
6306 prefix);
6516 return NULL; 6307 return NULL;
6517} 6308}
6518 6309
@@ -6525,8 +6316,7 @@ lookup_communicator (const char *prefix)
6525 * @param address the address to try 6316 * @param address the address to try
6526 */ 6317 */
6527static void 6318static void
6528suggest_to_connect (const struct GNUNET_PeerIdentity *pid, 6319suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address)
6529 const char *address)
6530{ 6320{
6531 static uint32_t idgen; 6321 static uint32_t idgen;
6532 struct TransportClient *tc; 6322 struct TransportClient *tc;
@@ -6557,16 +6347,12 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid,
6557 prefix, 6347 prefix,
6558 address); 6348 address);
6559 alen = strlen (address) + 1; 6349 alen = strlen (address) + 1;
6560 env = GNUNET_MQ_msg_extra (cqm, 6350 env =
6561 alen, 6351 GNUNET_MQ_msg_extra (cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
6562 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
6563 cqm->request_id = htonl (idgen++); 6352 cqm->request_id = htonl (idgen++);
6564 cqm->receiver = *pid; 6353 cqm->receiver = *pid;
6565 memcpy (&cqm[1], 6354 memcpy (&cqm[1], address, alen);
6566 address, 6355 GNUNET_MQ_send (tc->mq, env);
6567 alen);
6568 GNUNET_MQ_send (tc->mq,
6569 env);
6570} 6356}
6571 6357
6572 6358
@@ -6578,21 +6364,18 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid,
6578 * @param vs state to derive validation challenge from 6364 * @param vs state to derive validation challenge from
6579 */ 6365 */
6580static void 6366static void
6581validation_transmit_on_queue (struct Queue *q, 6367validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs)
6582 struct ValidationState *vs)
6583{ 6368{
6584 struct TransportValidationChallenge tvc; 6369 struct TransportValidationChallenge tvc;
6585 6370
6586 vs->last_challenge_use = GNUNET_TIME_absolute_get (); 6371 vs->last_challenge_use = GNUNET_TIME_absolute_get ();
6587 tvc.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); 6372 tvc.header.type =
6373 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE);
6588 tvc.header.size = htons (sizeof (tvc)); 6374 tvc.header.size = htons (sizeof (tvc));
6589 tvc.reserved = htonl (0); 6375 tvc.reserved = htonl (0);
6590 tvc.challenge = vs->challenge; 6376 tvc.challenge = vs->challenge;
6591 tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); 6377 tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use);
6592 queue_send_msg (q, 6378 queue_send_msg (q, NULL, &tvc, sizeof (tvc));
6593 NULL,
6594 &tvc,
6595 sizeof (tvc));
6596} 6379}
6597 6380
6598 6381
@@ -6611,8 +6394,9 @@ validation_start_cb (void *cls)
6611 validation_task = NULL; 6394 validation_task = NULL;
6612 vs = GNUNET_CONTAINER_heap_peek (validation_heap); 6395 vs = GNUNET_CONTAINER_heap_peek (validation_heap);
6613 /* drop validations past their expiration */ 6396 /* drop validations past their expiration */
6614 while ( (NULL != vs) && 6397 while (
6615 (0 == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us) ) 6398 (NULL != vs) &&
6399 (0 == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us))
6616 { 6400 {
6617 free_validation_state (vs); 6401 free_validation_state (vs);
6618 vs = GNUNET_CONTAINER_heap_peek (validation_heap); 6402 vs = GNUNET_CONTAINER_heap_peek (validation_heap);
@@ -6620,22 +6404,21 @@ validation_start_cb (void *cls)
6620 if (NULL == vs) 6404 if (NULL == vs)
6621 return; /* woopsie, no more addresses known, should only 6405 return; /* woopsie, no more addresses known, should only
6622 happen if we're really a lonely peer */ 6406 happen if we're really a lonely peer */
6623 q = find_queue (&vs->pid, 6407 q = find_queue (&vs->pid, vs->address);
6624 vs->address);
6625 if (NULL == q) 6408 if (NULL == q)
6626 { 6409 {
6627 vs->awaiting_queue = GNUNET_YES; 6410 vs->awaiting_queue = GNUNET_YES;
6628 suggest_to_connect (&vs->pid, 6411 suggest_to_connect (&vs->pid, vs->address);
6629 vs->address);
6630 } 6412 }
6631 else 6413 else
6632 validation_transmit_on_queue (q, 6414 validation_transmit_on_queue (q, vs);
6633 vs);
6634 /* Finally, reschedule next attempt */ 6415 /* Finally, reschedule next attempt */
6635 vs->challenge_backoff = GNUNET_TIME_randomized_backoff (vs->challenge_backoff, 6416 vs->challenge_backoff =
6636 MAX_VALIDATION_CHALLENGE_FREQ); 6417 GNUNET_TIME_randomized_backoff (vs->challenge_backoff,
6418 MAX_VALIDATION_CHALLENGE_FREQ);
6637 update_next_challenge_time (vs, 6419 update_next_challenge_time (vs,
6638 GNUNET_TIME_relative_to_absolute (vs->challenge_backoff)); 6420 GNUNET_TIME_relative_to_absolute (
6421 vs->challenge_backoff));
6639} 6422}
6640 6423
6641 6424
@@ -6664,7 +6447,6 @@ struct QueueQualityContext
6664 * k-th queue in @e q. 6447 * k-th queue in @e q.
6665 */ 6448 */
6666 unsigned int k; 6449 unsigned int k;
6667
6668}; 6450};
6669 6451
6670 6452
@@ -6690,9 +6472,7 @@ check_connection_quality (void *cls,
6690 6472
6691 (void) pid; 6473 (void) pid;
6692 do_inc = GNUNET_NO; 6474 do_inc = GNUNET_NO;
6693 for (struct Queue *q = n->queue_head; 6475 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
6694 NULL != q;
6695 q = q->next_neighbour)
6696 { 6476 {
6697 if (0 != q->distance) 6477 if (0 != q->distance)
6698 continue; /* DV does not count */ 6478 continue; /* DV does not count */
@@ -6730,8 +6510,7 @@ start_dv_learn (void *cls)
6730 6510
6731 (void) cls; 6511 (void) cls;
6732 dvlearn_task = NULL; 6512 dvlearn_task = NULL;
6733 if (0 == 6513 if (0 == GNUNET_CONTAINER_multipeermap_size (neighbours))
6734 GNUNET_CONTAINER_multipeermap_size (neighbours))
6735 return; /* lost all connectivity, cannot do learning */ 6514 return; /* lost all connectivity, cannot do learning */
6736 qqc.quality_count = 0; 6515 qqc.quality_count = 0;
6737 qqc.num_queues = 0; 6516 qqc.num_queues = 0;
@@ -6745,11 +6524,8 @@ start_dv_learn (void *cls)
6745 6524
6746 /* scale our retries by how far we are above the threshold */ 6525 /* scale our retries by how far we are above the threshold */
6747 factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; 6526 factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD;
6748 delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, 6527 delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, factor);
6749 factor); 6528 dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay, &start_dv_learn, NULL);
6750 dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay,
6751 &start_dv_learn,
6752 NULL);
6753 return; 6529 return;
6754 } 6530 }
6755 /* remove old entries in #dvlearn_map if it has grown too big */ 6531 /* remove old entries in #dvlearn_map if it has grown too big */
@@ -6761,9 +6537,7 @@ start_dv_learn (void *cls)
6761 GNUNET_CONTAINER_multishortmap_remove (dvlearn_map, 6537 GNUNET_CONTAINER_multishortmap_remove (dvlearn_map,
6762 &lle->challenge, 6538 &lle->challenge,
6763 lle)); 6539 lle));
6764 GNUNET_CONTAINER_DLL_remove (lle_head, 6540 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle);
6765 lle_tail,
6766 lle);
6767 GNUNET_free (lle); 6541 GNUNET_free (lle);
6768 } 6542 }
6769 /* setup data structure for learning */ 6543 /* setup data structure for learning */
@@ -6771,37 +6545,33 @@ start_dv_learn (void *cls)
6771 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 6545 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
6772 &lle->challenge, 6546 &lle->challenge,
6773 sizeof (lle->challenge)); 6547 sizeof (lle->challenge));
6774 GNUNET_CONTAINER_DLL_insert (lle_head, 6548 GNUNET_CONTAINER_DLL_insert (lle_head, lle_tail, lle);
6775 lle_tail,
6776 lle);
6777 GNUNET_break (GNUNET_YES == 6549 GNUNET_break (GNUNET_YES ==
6778 GNUNET_CONTAINER_multishortmap_put (dvlearn_map, 6550 GNUNET_CONTAINER_multishortmap_put (
6779 &lle->challenge, 6551 dvlearn_map,
6780 lle, 6552 &lle->challenge,
6781 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6553 lle,
6554 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
6782 dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); 6555 dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN);
6783 dvl.header.size = htons (sizeof (dvl)); 6556 dvl.header.size = htons (sizeof (dvl));
6784 dvl.num_hops = htons (0); 6557 dvl.num_hops = htons (0);
6785 dvl.bidirectional = htons (0); 6558 dvl.bidirectional = htons (0);
6786 dvl.non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); 6559 dvl.non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO);
6787 { 6560 {
6788 struct DvInitPS dvip = { 6561 struct DvInitPS dvip = {.purpose.purpose = htonl (
6789 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), 6562 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR),
6790 .purpose.size = htonl (sizeof (dvip)), 6563 .purpose.size = htonl (sizeof (dvip)),
6791 .challenge = lle->challenge 6564 .challenge = lle->challenge};
6792 };
6793 6565
6794 GNUNET_assert (GNUNET_OK == 6566 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
6795 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 6567 &dvip.purpose,
6796 &dvip.purpose, 6568 &dvl.init_sig));
6797 &dvl.init_sig));
6798 } 6569 }
6799 dvl.initiator = GST_my_identity; 6570 dvl.initiator = GST_my_identity;
6800 dvl.challenge = lle->challenge; 6571 dvl.challenge = lle->challenge;
6801 6572
6802 qqc.quality_count = 0; 6573 qqc.quality_count = 0;
6803 qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 6574 qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues);
6804 qqc.num_queues);
6805 qqc.num_queues = 0; 6575 qqc.num_queues = 0;
6806 qqc.q = NULL; 6576 qqc.q = NULL;
6807 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 6577 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
@@ -6812,16 +6582,13 @@ start_dv_learn (void *cls)
6812 /* Do this as close to transmission time as possible! */ 6582 /* Do this as close to transmission time as possible! */
6813 lle->launch_time = GNUNET_TIME_absolute_get (); 6583 lle->launch_time = GNUNET_TIME_absolute_get ();
6814 6584
6815 queue_send_msg (qqc.q, 6585 queue_send_msg (qqc.q, NULL, &dvl, sizeof (dvl));
6816 NULL,
6817 &dvl,
6818 sizeof (dvl));
6819 /* reschedule this job, randomizing the time it runs (but no 6586 /* reschedule this job, randomizing the time it runs (but no
6820 actual backoff!) */ 6587 actual backoff!) */
6821 dvlearn_task 6588 dvlearn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_randomize (
6822 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_randomize (DV_LEARN_BASE_FREQUENCY), 6589 DV_LEARN_BASE_FREQUENCY),
6823 &start_dv_learn, 6590 &start_dv_learn,
6824 NULL); 6591 NULL);
6825} 6592}
6826 6593
6827 6594
@@ -6843,13 +6610,11 @@ check_validation_request_pending (void *cls,
6843 struct ValidationState *vs = value; 6610 struct ValidationState *vs = value;
6844 6611
6845 (void) pid; 6612 (void) pid;
6846 if ( (GNUNET_YES == vs->awaiting_queue) && 6613 if ((GNUNET_YES == vs->awaiting_queue) &&
6847 (0 == strcmp (vs->address, 6614 (0 == strcmp (vs->address, q->address)))
6848 q->address)) )
6849 { 6615 {
6850 vs->awaiting_queue = GNUNET_NO; 6616 vs->awaiting_queue = GNUNET_NO;
6851 validation_transmit_on_queue (q, 6617 validation_transmit_on_queue (q, vs);
6852 vs);
6853 return GNUNET_NO; 6618 return GNUNET_NO;
6854 } 6619 }
6855 return GNUNET_OK; 6620 return GNUNET_OK;
@@ -6887,10 +6652,11 @@ handle_add_queue_message (void *cls,
6887 neighbour->earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 6652 neighbour->earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
6888 neighbour->pid = aqm->receiver; 6653 neighbour->pid = aqm->receiver;
6889 GNUNET_assert (GNUNET_OK == 6654 GNUNET_assert (GNUNET_OK ==
6890 GNUNET_CONTAINER_multipeermap_put (neighbours, 6655 GNUNET_CONTAINER_multipeermap_put (
6891 &neighbour->pid, 6656 neighbours,
6892 neighbour, 6657 &neighbour->pid,
6893 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6658 neighbour,
6659 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
6894 } 6660 }
6895 addr_len = ntohs (aqm->header.size) - sizeof (*aqm); 6661 addr_len = ntohs (aqm->header.size) - sizeof (*aqm);
6896 addr = (const char *) &aqm[1]; 6662 addr = (const char *) &aqm[1];
@@ -6918,20 +6684,12 @@ handle_add_queue_message (void *cls,
6918 GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S, 6684 GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S,
6919 &tracker_excess_out_cb, 6685 &tracker_excess_out_cb,
6920 queue); 6686 queue);
6921 memcpy (&queue[1], 6687 memcpy (&queue[1], addr, addr_len);
6922 addr,
6923 addr_len);
6924 /* notify monitors about new queue */ 6688 /* notify monitors about new queue */
6925 { 6689 {
6926 struct MonitorEvent me = { 6690 struct MonitorEvent me = {.rtt = queue->rtt, .cs = queue->cs};
6927 .rtt = queue->rtt,
6928 .cs = queue->cs
6929 };
6930 6691
6931 notify_monitors (&neighbour->pid, 6692 notify_monitors (&neighbour->pid, queue->address, queue->nt, &me);
6932 queue->address,
6933 queue->nt,
6934 &me);
6935 } 6693 }
6936 GNUNET_CONTAINER_MDLL_insert (neighbour, 6694 GNUNET_CONTAINER_MDLL_insert (neighbour,
6937 neighbour->queue_head, 6695 neighbour->queue_head,
@@ -6942,14 +6700,14 @@ handle_add_queue_message (void *cls,
6942 tc->details.communicator.queue_tail, 6700 tc->details.communicator.queue_tail,
6943 queue); 6701 queue);
6944 /* check if valdiations are waiting for the queue */ 6702 /* check if valdiations are waiting for the queue */
6945 (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, 6703 (void)
6946 &aqm->receiver, 6704 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
6947 &check_validation_request_pending, 6705 &aqm->receiver,
6948 queue); 6706 &check_validation_request_pending,
6707 queue);
6949 /* might be our first queue, try launching DV learning */ 6708 /* might be our first queue, try launching DV learning */
6950 if (NULL == dvlearn_task) 6709 if (NULL == dvlearn_task)
6951 dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, 6710 dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, NULL);
6952 NULL);
6953 GNUNET_SERVICE_client_continue (tc->client); 6711 GNUNET_SERVICE_client_continue (tc->client);
6954} 6712}
6955 6713
@@ -6986,15 +6744,16 @@ handle_queue_create_ok (void *cls,
6986 6744
6987/** 6745/**
6988 * Communicator tells us that our request to create a queue failed. This usually 6746 * Communicator tells us that our request to create a queue failed. This usually
6989 * indicates that the provided address is simply invalid or that the communicator's 6747 * indicates that the provided address is simply invalid or that the
6990 * resources are exhausted. 6748 * communicator's resources are exhausted.
6991 * 6749 *
6992 * @param cls the `struct TransportClient` 6750 * @param cls the `struct TransportClient`
6993 * @param cqr failure message 6751 * @param cqr failure message
6994 */ 6752 */
6995static void 6753static void
6996handle_queue_create_fail (void *cls, 6754handle_queue_create_fail (
6997 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) 6755 void *cls,
6756 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr)
6998{ 6757{
6999 struct TransportClient *tc = cls; 6758 struct TransportClient *tc = cls;
7000 6759
@@ -7016,14 +6775,14 @@ handle_queue_create_fail (void *cls,
7016 6775
7017 6776
7018/** 6777/**
7019 * We have received a `struct ExpressPreferenceMessage` from an application client. 6778 * We have received a `struct ExpressPreferenceMessage` from an application
6779 * client.
7020 * 6780 *
7021 * @param cls handle to the client 6781 * @param cls handle to the client
7022 * @param msg the start message 6782 * @param msg the start message
7023 */ 6783 */
7024static void 6784static void
7025handle_suggest_cancel (void *cls, 6785handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg)
7026 const struct ExpressPreferenceMessage *msg)
7027{ 6786{
7028 struct TransportClient *tc = cls; 6787 struct TransportClient *tc = cls;
7029 struct PeerRequest *pr; 6788 struct PeerRequest *pr;
@@ -7042,9 +6801,7 @@ handle_suggest_cancel (void *cls,
7042 GNUNET_SERVICE_client_drop (tc->client); 6801 GNUNET_SERVICE_client_drop (tc->client);
7043 return; 6802 return;
7044 } 6803 }
7045 (void) stop_peer_request (tc, 6804 (void) stop_peer_request (tc, &pr->pid, pr);
7046 &pr->pid,
7047 pr);
7048 GNUNET_SERVICE_client_continue (tc->client); 6805 GNUNET_SERVICE_client_continue (tc->client);
7049} 6806}
7050 6807
@@ -7058,8 +6815,9 @@ handle_suggest_cancel (void *cls,
7058 * @return #GNUNET_OK 6815 * @return #GNUNET_OK
7059 */ 6816 */
7060static int 6817static int
7061check_address_consider_verify (void *cls, 6818check_address_consider_verify (
7062 const struct GNUNET_TRANSPORT_AddressToVerify *hdr) 6819 void *cls,
6820 const struct GNUNET_TRANSPORT_AddressToVerify *hdr)
7063{ 6821{
7064 (void) cls; 6822 (void) cls;
7065 (void) hdr; 6823 (void) hdr;
@@ -7102,8 +6860,7 @@ check_known_address (void *cls,
7102 struct ValidationState *vs = value; 6860 struct ValidationState *vs = value;
7103 6861
7104 (void) pid; 6862 (void) pid;
7105 if (0 != strcmp (vs->address, 6863 if (0 != strcmp (vs->address, ckac->address))
7106 ckac->address))
7107 return GNUNET_OK; 6864 return GNUNET_OK;
7108 ckac->vs = vs; 6865 ckac->vs = vs;
7109 return GNUNET_NO; 6866 return GNUNET_NO;
@@ -7124,10 +6881,7 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
7124{ 6881{
7125 struct GNUNET_TIME_Absolute now; 6882 struct GNUNET_TIME_Absolute now;
7126 struct ValidationState *vs; 6883 struct ValidationState *vs;
7127 struct CheckKnownAddressContext ckac = { 6884 struct CheckKnownAddressContext ckac = {.address = address, .vs = NULL};
7128 .address = address,
7129 .vs = NULL
7130 };
7131 6885
7132 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) 6886 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
7133 return; /* expired */ 6887 return; /* expired */
@@ -7137,19 +6891,22 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
7137 &ckac); 6891 &ckac);
7138 if (NULL != (vs = ckac.vs)) 6892 if (NULL != (vs = ckac.vs))
7139 { 6893 {
7140 /* if 'vs' is not currently valid, we need to speed up retrying the validation */ 6894 /* if 'vs' is not currently valid, we need to speed up retrying the
6895 * validation */
7141 if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) 6896 if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us)
7142 { 6897 {
7143 /* reduce backoff as we got a fresh advertisement */ 6898 /* reduce backoff as we got a fresh advertisement */
7144 vs->challenge_backoff = GNUNET_TIME_relative_min (FAST_VALIDATION_CHALLENGE_FREQ, 6899 vs->challenge_backoff =
7145 GNUNET_TIME_relative_divide (vs->challenge_backoff, 6900 GNUNET_TIME_relative_min (FAST_VALIDATION_CHALLENGE_FREQ,
7146 2)); 6901 GNUNET_TIME_relative_divide (vs->challenge_backoff,
6902 2));
7147 update_next_challenge_time (vs, 6903 update_next_challenge_time (vs,
7148 GNUNET_TIME_relative_to_absolute (vs->challenge_backoff)); 6904 GNUNET_TIME_relative_to_absolute (
6905 vs->challenge_backoff));
7149 } 6906 }
7150 return; 6907 return;
7151 } 6908 }
7152 now = GNUNET_TIME_absolute_get(); 6909 now = GNUNET_TIME_absolute_get ();
7153 vs = GNUNET_new (struct ValidationState); 6910 vs = GNUNET_new (struct ValidationState);
7154 vs->pid = *pid; 6911 vs->pid = *pid;
7155 vs->valid_until = expiration; 6912 vs->valid_until = expiration;
@@ -7160,12 +6917,12 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
7160 sizeof (vs->challenge)); 6917 sizeof (vs->challenge));
7161 vs->address = GNUNET_strdup (address); 6918 vs->address = GNUNET_strdup (address);
7162 GNUNET_assert (GNUNET_YES == 6919 GNUNET_assert (GNUNET_YES ==
7163 GNUNET_CONTAINER_multipeermap_put (validation_map, 6920 GNUNET_CONTAINER_multipeermap_put (
7164 &vs->pid, 6921 validation_map,
7165 vs, 6922 &vs->pid,
7166 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6923 vs,
7167 update_next_challenge_time (vs, 6924 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
7168 now); 6925 update_next_challenge_time (vs, now);
7169} 6926}
7170 6927
7171 6928
@@ -7192,8 +6949,7 @@ handle_hello (void *cls,
7192 return; 6949 return;
7193 } 6950 }
7194 val = record->value; 6951 val = record->value;
7195 if ( (0 == record->value_size) || 6952 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1]))
7196 ('\0' != val[record->value_size - 1]) )
7197 { 6953 {
7198 GNUNET_break (0); 6954 GNUNET_break (0);
7199 return; 6955 return;
@@ -7205,14 +6961,14 @@ handle_hello (void *cls,
7205 6961
7206 6962
7207/** 6963/**
7208 * We have received a `struct ExpressPreferenceMessage` from an application client. 6964 * We have received a `struct ExpressPreferenceMessage` from an application
6965 * client.
7209 * 6966 *
7210 * @param cls handle to the client 6967 * @param cls handle to the client
7211 * @param msg the start message 6968 * @param msg the start message
7212 */ 6969 */
7213static void 6970static void
7214handle_suggest (void *cls, 6971handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg)
7215 const struct ExpressPreferenceMessage *msg)
7216{ 6972{
7217 struct TransportClient *tc = cls; 6973 struct TransportClient *tc = cls;
7218 struct PeerRequest *pr; 6974 struct PeerRequest *pr;
@@ -7220,9 +6976,8 @@ handle_suggest (void *cls,
7220 if (CT_NONE == tc->type) 6976 if (CT_NONE == tc->type)
7221 { 6977 {
7222 tc->type = CT_APPLICATION; 6978 tc->type = CT_APPLICATION;
7223 tc->details.application.requests 6979 tc->details.application.requests =
7224 = GNUNET_CONTAINER_multipeermap_create (16, 6980 GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
7225 GNUNET_YES);
7226 } 6981 }
7227 if (CT_APPLICATION != tc->type) 6982 if (CT_APPLICATION != tc->type)
7228 { 6983 {
@@ -7240,11 +6995,11 @@ handle_suggest (void *cls,
7240 pr->pid = msg->peer; 6995 pr->pid = msg->peer;
7241 pr->bw = msg->bw; 6996 pr->bw = msg->bw;
7242 pr->pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk); 6997 pr->pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk);
7243 if (GNUNET_YES != 6998 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put (
7244 GNUNET_CONTAINER_multipeermap_put (tc->details.application.requests, 6999 tc->details.application.requests,
7245 &pr->pid, 7000 &pr->pid,
7246 pr, 7001 pr,
7247 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 7002 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
7248 { 7003 {
7249 GNUNET_break (0); 7004 GNUNET_break (0);
7250 GNUNET_free (pr); 7005 GNUNET_free (pr);
@@ -7270,8 +7025,9 @@ handle_suggest (void *cls,
7270 * signature in the body, see #GNUNET_HELLO_extract_address() 7025 * signature in the body, see #GNUNET_HELLO_extract_address()
7271 */ 7026 */
7272static void 7027static void
7273handle_address_consider_verify (void *cls, 7028handle_address_consider_verify (
7274 const struct GNUNET_TRANSPORT_AddressToVerify *hdr) 7029 void *cls,
7030 const struct GNUNET_TRANSPORT_AddressToVerify *hdr)
7275{ 7031{
7276 struct TransportClient *tc = cls; 7032 struct TransportClient *tc = cls;
7277 char *address; 7033 char *address;
@@ -7282,19 +7038,18 @@ handle_address_consider_verify (void *cls,
7282 // OPTIMIZE-FIXME: checking that we know this address already should 7038 // OPTIMIZE-FIXME: checking that we know this address already should
7283 // be done BEFORE checking the signature => HELLO API change! 7039 // be done BEFORE checking the signature => HELLO API change!
7284 // OPTIMIZE-FIXME: pre-check: rate-limit signature verification / validation?! 7040 // OPTIMIZE-FIXME: pre-check: rate-limit signature verification / validation?!
7285 address = GNUNET_HELLO_extract_address (&hdr[1], 7041 address =
7286 ntohs (hdr->header.size) - sizeof (*hdr), 7042 GNUNET_HELLO_extract_address (&hdr[1],
7287 &hdr->peer, 7043 ntohs (hdr->header.size) - sizeof (*hdr),
7288 &nt, 7044 &hdr->peer,
7289 &expiration); 7045 &nt,
7046 &expiration);
7290 if (NULL == address) 7047 if (NULL == address)
7291 { 7048 {
7292 GNUNET_break_op (0); 7049 GNUNET_break_op (0);
7293 return; 7050 return;
7294 } 7051 }
7295 start_address_validation (&hdr->peer, 7052 start_address_validation (&hdr->peer, address, expiration);
7296 address,
7297 expiration);
7298 GNUNET_free (address); 7053 GNUNET_free (address);
7299 GNUNET_SERVICE_client_continue (tc->client); 7054 GNUNET_SERVICE_client_continue (tc->client);
7300} 7055}
@@ -7446,19 +7201,15 @@ do_shutdown (void *cls)
7446 GNUNET_SCHEDULER_cancel (ephemeral_task); 7201 GNUNET_SCHEDULER_cancel (ephemeral_task);
7447 ephemeral_task = NULL; 7202 ephemeral_task = NULL;
7448 } 7203 }
7449 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 7204 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &free_neighbour_cb, NULL);
7450 &free_neighbour_cb,
7451 NULL);
7452 if (NULL != peerstore) 7205 if (NULL != peerstore)
7453 { 7206 {
7454 GNUNET_PEERSTORE_disconnect (peerstore, 7207 GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO);
7455 GNUNET_NO);
7456 peerstore = NULL; 7208 peerstore = NULL;
7457 } 7209 }
7458 if (NULL != GST_stats) 7210 if (NULL != GST_stats)
7459 { 7211 {
7460 GNUNET_STATISTICS_destroy (GST_stats, 7212 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
7461 GNUNET_NO);
7462 GST_stats = NULL; 7213 GST_stats = NULL;
7463 } 7214 }
7464 if (NULL != GST_my_private_key) 7215 if (NULL != GST_my_private_key)
@@ -7475,18 +7226,14 @@ do_shutdown (void *cls)
7475 validation_map = NULL; 7226 validation_map = NULL;
7476 while (NULL != (lle = lle_head)) 7227 while (NULL != (lle = lle_head))
7477 { 7228 {
7478 GNUNET_CONTAINER_DLL_remove (lle_head, 7229 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle);
7479 lle_tail,
7480 lle);
7481 GNUNET_free (lle); 7230 GNUNET_free (lle);
7482 } 7231 }
7483 GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map); 7232 GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map);
7484 dvlearn_map = NULL; 7233 dvlearn_map = NULL;
7485 GNUNET_CONTAINER_heap_destroy (validation_heap); 7234 GNUNET_CONTAINER_heap_destroy (validation_heap);
7486 validation_heap = NULL; 7235 validation_heap = NULL;
7487 GNUNET_CONTAINER_multipeermap_iterate (dv_routes, 7236 GNUNET_CONTAINER_multipeermap_iterate (dv_routes, &free_dv_routes_cb, NULL);
7488 &free_dv_routes_cb,
7489 NULL);
7490 GNUNET_CONTAINER_multipeermap_destroy (dv_routes); 7237 GNUNET_CONTAINER_multipeermap_destroy (dv_routes);
7491 dv_routes = NULL; 7238 dv_routes = NULL;
7492 GNUNET_CONTAINER_multipeermap_iterate (ephemeral_map, 7239 GNUNET_CONTAINER_multipeermap_iterate (ephemeral_map,
@@ -7515,35 +7262,34 @@ run (void *cls,
7515 (void) service; 7262 (void) service;
7516 /* setup globals */ 7263 /* setup globals */
7517 GST_cfg = c; 7264 GST_cfg = c;
7518 neighbours = GNUNET_CONTAINER_multipeermap_create (1024, 7265 neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
7519 GNUNET_YES); 7266 dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
7520 dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, 7267 ephemeral_map = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES);
7521 GNUNET_YES); 7268 ephemeral_heap =
7522 ephemeral_map = GNUNET_CONTAINER_multipeermap_create (32, 7269 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
7523 GNUNET_YES);
7524 ephemeral_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
7525 dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING, 7270 dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING,
7526 GNUNET_YES); 7271 GNUNET_YES);
7527 validation_map = GNUNET_CONTAINER_multipeermap_create (1024, 7272 validation_map = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
7528 GNUNET_YES); 7273 validation_heap =
7529 validation_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 7274 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
7530 GST_my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); 7275 GST_my_private_key =
7276 GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg);
7531 if (NULL == GST_my_private_key) 7277 if (NULL == GST_my_private_key)
7532 { 7278 {
7533 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 7279 GNUNET_log (
7534 _("Transport service is lacking key configuration settings. Exiting.\n")); 7280 GNUNET_ERROR_TYPE_ERROR,
7281 _ (
7282 "Transport service is lacking key configuration settings. Exiting.\n"));
7535 GNUNET_SCHEDULER_shutdown (); 7283 GNUNET_SCHEDULER_shutdown ();
7536 return; 7284 return;
7537 } 7285 }
7538 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, 7286 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
7539 &GST_my_identity.public_key); 7287 &GST_my_identity.public_key);
7540 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 7288 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
7541 "My identity is `%s'\n", 7289 "My identity is `%s'\n",
7542 GNUNET_i2s_full (&GST_my_identity)); 7290 GNUNET_i2s_full (&GST_my_identity));
7543 GST_stats = GNUNET_STATISTICS_create ("transport", 7291 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
7544 GST_cfg); 7292 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
7545 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
7546 NULL);
7547 peerstore = GNUNET_PEERSTORE_connect (GST_cfg); 7293 peerstore = GNUNET_PEERSTORE_connect (GST_cfg);
7548 if (NULL == peerstore) 7294 if (NULL == peerstore)
7549 { 7295 {
@@ -7557,86 +7303,86 @@ run (void *cls,
7557/** 7303/**
7558 * Define "main" method using service macro. 7304 * Define "main" method using service macro.
7559 */ 7305 */
7560GNUNET_SERVICE_MAIN 7306GNUNET_SERVICE_MAIN (
7561("transport", 7307 "transport",
7562 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, 7308 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
7563 &run, 7309 &run,
7564 &client_connect_cb, 7310 &client_connect_cb,
7565 &client_disconnect_cb, 7311 &client_disconnect_cb,
7566 NULL, 7312 NULL,
7567 /* communication with applications */ 7313 /* communication with applications */
7568 GNUNET_MQ_hd_fixed_size (suggest, 7314 GNUNET_MQ_hd_fixed_size (suggest,
7569 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, 7315 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST,
7570 struct ExpressPreferenceMessage, 7316 struct ExpressPreferenceMessage,
7571 NULL), 7317 NULL),
7572 GNUNET_MQ_hd_fixed_size (suggest_cancel, 7318 GNUNET_MQ_hd_fixed_size (suggest_cancel,
7573 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, 7319 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL,
7574 struct ExpressPreferenceMessage, 7320 struct ExpressPreferenceMessage,
7575 NULL), 7321 NULL),
7576 GNUNET_MQ_hd_var_size (request_hello_validation, 7322 GNUNET_MQ_hd_var_size (request_hello_validation,
7577 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, 7323 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION,
7578 struct RequestHelloValidationMessage, 7324 struct RequestHelloValidationMessage,
7579 NULL), 7325 NULL),
7580 /* communication with core */ 7326 /* communication with core */
7581 GNUNET_MQ_hd_fixed_size (client_start, 7327 GNUNET_MQ_hd_fixed_size (client_start,
7582 GNUNET_MESSAGE_TYPE_TRANSPORT_START, 7328 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
7583 struct StartMessage, 7329 struct StartMessage,
7584 NULL), 7330 NULL),
7585 GNUNET_MQ_hd_var_size (client_send, 7331 GNUNET_MQ_hd_var_size (client_send,
7586 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 7332 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
7587 struct OutboundMessage, 7333 struct OutboundMessage,
7588 NULL), 7334 NULL),
7589 /* communication with communicators */ 7335 /* communication with communicators */
7590 GNUNET_MQ_hd_var_size (communicator_available, 7336 GNUNET_MQ_hd_var_size (communicator_available,
7591 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, 7337 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR,
7592 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, 7338 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
7593 NULL), 7339 NULL),
7594 GNUNET_MQ_hd_var_size (communicator_backchannel, 7340 GNUNET_MQ_hd_var_size (communicator_backchannel,
7595 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, 7341 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
7596 struct GNUNET_TRANSPORT_CommunicatorBackchannel, 7342 struct GNUNET_TRANSPORT_CommunicatorBackchannel,
7597 NULL), 7343 NULL),
7598 GNUNET_MQ_hd_var_size (add_address, 7344 GNUNET_MQ_hd_var_size (add_address,
7599 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, 7345 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
7600 struct GNUNET_TRANSPORT_AddAddressMessage, 7346 struct GNUNET_TRANSPORT_AddAddressMessage,
7601 NULL), 7347 NULL),
7602 GNUNET_MQ_hd_fixed_size (del_address, 7348 GNUNET_MQ_hd_fixed_size (del_address,
7603 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, 7349 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
7604 struct GNUNET_TRANSPORT_DelAddressMessage, 7350 struct GNUNET_TRANSPORT_DelAddressMessage,
7605 NULL), 7351 NULL),
7606 GNUNET_MQ_hd_var_size (incoming_msg, 7352 GNUNET_MQ_hd_var_size (incoming_msg,
7607 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, 7353 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
7608 struct GNUNET_TRANSPORT_IncomingMessage, 7354 struct GNUNET_TRANSPORT_IncomingMessage,
7609 NULL), 7355 NULL),
7610 GNUNET_MQ_hd_fixed_size (queue_create_ok, 7356 GNUNET_MQ_hd_fixed_size (queue_create_ok,
7611 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, 7357 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
7612 struct GNUNET_TRANSPORT_CreateQueueResponse, 7358 struct GNUNET_TRANSPORT_CreateQueueResponse,
7613 NULL), 7359 NULL),
7614 GNUNET_MQ_hd_fixed_size (queue_create_fail, 7360 GNUNET_MQ_hd_fixed_size (queue_create_fail,
7615 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, 7361 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
7616 struct GNUNET_TRANSPORT_CreateQueueResponse, 7362 struct GNUNET_TRANSPORT_CreateQueueResponse,
7617 NULL), 7363 NULL),
7618 GNUNET_MQ_hd_var_size (add_queue_message, 7364 GNUNET_MQ_hd_var_size (add_queue_message,
7619 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, 7365 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
7620 struct GNUNET_TRANSPORT_AddQueueMessage, 7366 struct GNUNET_TRANSPORT_AddQueueMessage,
7621 NULL), 7367 NULL),
7622 GNUNET_MQ_hd_var_size (address_consider_verify, 7368 GNUNET_MQ_hd_var_size (address_consider_verify,
7623 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY, 7369 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY,
7624 struct GNUNET_TRANSPORT_AddressToVerify, 7370 struct GNUNET_TRANSPORT_AddressToVerify,
7625 NULL), 7371 NULL),
7626 GNUNET_MQ_hd_fixed_size (del_queue_message, 7372 GNUNET_MQ_hd_fixed_size (del_queue_message,
7627 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, 7373 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
7628 struct GNUNET_TRANSPORT_DelQueueMessage, 7374 struct GNUNET_TRANSPORT_DelQueueMessage,
7629 NULL), 7375 NULL),
7630 GNUNET_MQ_hd_fixed_size (send_message_ack, 7376 GNUNET_MQ_hd_fixed_size (send_message_ack,
7631 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, 7377 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK,
7632 struct GNUNET_TRANSPORT_SendMessageToAck, 7378 struct GNUNET_TRANSPORT_SendMessageToAck,
7633 NULL), 7379 NULL),
7634 /* communication with monitors */ 7380 /* communication with monitors */
7635 GNUNET_MQ_hd_fixed_size (monitor_start, 7381 GNUNET_MQ_hd_fixed_size (monitor_start,
7636 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, 7382 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START,
7637 struct GNUNET_TRANSPORT_MonitorStart, 7383 struct GNUNET_TRANSPORT_MonitorStart,
7638 NULL), 7384 NULL),
7639 GNUNET_MQ_handler_end ()); 7385 GNUNET_MQ_handler_end ());
7640 7386
7641 7387
7642/* end of file gnunet-service-transport.c */ 7388/* end of file gnunet-service-transport.c */