aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-tng.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-tng.c')
-rw-r--r--src/transport/gnunet-service-tng.c7781
1 files changed, 3852 insertions, 3929 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index bae187e7c..09e15655f 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010-2016, 2018, 2019 GNUnet e.V. 3 Copyright (C) 2010-2016, 2018, 2019 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -176,14 +176,14 @@
176 * the value chosen here might be too aggressively low! 176 * the value chosen here might be too aggressively low!
177 */ 177 */
178#define DELAY_WARN_THRESHOLD \ 178#define DELAY_WARN_THRESHOLD \
179 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 179 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
180 180
181/** 181/**
182 * If a DVBox could not be forwarded after this number of 182 * If a DVBox could not be forwarded after this number of
183 * seconds we drop it. 183 * seconds we drop it.
184 */ 184 */
185#define DV_FORWARD_TIMEOUT \ 185#define DV_FORWARD_TIMEOUT \
186 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 186 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60)
187 187
188/** 188/**
189 * We only consider queues as "quality" connections when 189 * We only consider queues as "quality" connections when
@@ -191,53 +191,53 @@
191 * the latency of the queue is below this threshold. 191 * the latency of the queue is below this threshold.
192 */ 192 */
193#define DV_QUALITY_RTT_THRESHOLD \ 193#define DV_QUALITY_RTT_THRESHOLD \
194 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 194 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
195 195
196/** 196/**
197 * How long do we consider a DV path valid if we see no 197 * How long do we consider a DV path valid if we see no
198 * further updates on it? Note: the value chosen here might be too low! 198 * further updates on it? Note: the value chosen here might be too low!
199 */ 199 */
200#define DV_PATH_VALIDITY_TIMEOUT \ 200#define DV_PATH_VALIDITY_TIMEOUT \
201 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 201 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
202 202
203/** 203/**
204 * How long do we cache backchannel (struct Backtalker) information 204 * How long do we cache backchannel (struct Backtalker) information
205 * after a backchannel goes inactive? 205 * after a backchannel goes inactive?
206 */ 206 */
207#define BACKCHANNEL_INACTIVITY_TIMEOUT \ 207#define BACKCHANNEL_INACTIVITY_TIMEOUT \
208 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 208 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
209 209
210/** 210/**
211 * How long before paths expire would we like to (re)discover DV paths? Should 211 * How long before paths expire would we like to (re)discover DV paths? Should
212 * be below #DV_PATH_VALIDITY_TIMEOUT. 212 * be below #DV_PATH_VALIDITY_TIMEOUT.
213 */ 213 */
214#define DV_PATH_DISCOVERY_FREQUENCY \ 214#define DV_PATH_DISCOVERY_FREQUENCY \
215 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) 215 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 4)
216 216
217/** 217/**
218 * How long are ephemeral keys valid? 218 * How long are ephemeral keys valid?
219 */ 219 */
220#define EPHEMERAL_VALIDITY \ 220#define EPHEMERAL_VALIDITY \
221 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) 221 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4)
222 222
223/** 223/**
224 * How long do we keep partially reassembled messages around before giving up? 224 * How long do we keep partially reassembled messages around before giving up?
225 */ 225 */
226#define REASSEMBLY_EXPIRATION \ 226#define REASSEMBLY_EXPIRATION \
227 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) 227 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 4)
228 228
229/** 229/**
230 * What is the fastest rate at which we send challenges *if* we keep learning 230 * What is the fastest rate at which we send challenges *if* we keep learning
231 * an address (gossip, DHT, etc.)? 231 * an address (gossip, DHT, etc.)?
232 */ 232 */
233#define FAST_VALIDATION_CHALLENGE_FREQ \ 233#define FAST_VALIDATION_CHALLENGE_FREQ \
234 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) 234 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1)
235 235
236/** 236/**
237 * What is the slowest rate at which we send challenges? 237 * What is the slowest rate at which we send challenges?
238 */ 238 */
239#define MAX_VALIDATION_CHALLENGE_FREQ \ 239#define MAX_VALIDATION_CHALLENGE_FREQ \
240 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1) 240 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 1)
241 241
242/** 242/**
243 * How long until we forget about historic accumulators and thus 243 * How long until we forget about historic accumulators and thus
@@ -245,7 +245,7 @@
245 * active connection experiences without an ACK. 245 * active connection experiences without an ACK.
246 */ 246 */
247#define ACK_CUMMULATOR_TIMEOUT \ 247#define ACK_CUMMULATOR_TIMEOUT \
248 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) 248 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4)
249 249
250/** 250/**
251 * What is the non-randomized base frequency at which we 251 * What is the non-randomized base frequency at which we
@@ -263,13 +263,13 @@
263 * When do we forget an invalid address for sure? 263 * When do we forget an invalid address for sure?
264 */ 264 */
265#define MAX_ADDRESS_VALID_UNTIL \ 265#define MAX_ADDRESS_VALID_UNTIL \
266 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1) 266 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MONTHS, 1)
267 267
268/** 268/**
269 * How long do we consider an address valid if we just checked? 269 * How long do we consider an address valid if we just checked?
270 */ 270 */
271#define ADDRESS_VALIDATION_LIFETIME \ 271#define ADDRESS_VALIDATION_LIFETIME \
272 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) 272 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4)
273 273
274/** 274/**
275 * What is the maximum frequency at which we do address validation? 275 * What is the maximum frequency at which we do address validation?
@@ -308,8 +308,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
308/** 308/**
309 * Unique identifier we attach to a message. 309 * Unique identifier we attach to a message.
310 */ 310 */
311struct MessageUUIDP 311struct MessageUUIDP {
312{
313 /** 312 /**
314 * Unique value, generated by incrementing the 313 * Unique value, generated by incrementing the
315 * `message_uuid_ctr` of `struct Neighbour`. 314 * `message_uuid_ctr` of `struct Neighbour`.
@@ -321,8 +320,7 @@ struct MessageUUIDP
321/** 320/**
322 * Unique identifier to map an acknowledgement to a transmission. 321 * Unique identifier to map an acknowledgement to a transmission.
323 */ 322 */
324struct AcknowledgementUUIDP 323struct AcknowledgementUUIDP {
325{
326 /** 324 /**
327 * The UUID value. 325 * The UUID value.
328 */ 326 */
@@ -333,8 +331,7 @@ struct AcknowledgementUUIDP
333/** 331/**
334 * Type of a nonce used for challenges. 332 * Type of a nonce used for challenges.
335 */ 333 */
336struct ChallengeNonceP 334struct ChallengeNonceP {
337{
338 /** 335 /**
339 * The value of the nonce. Note that this is NOT a hash. 336 * The value of the nonce. Note that this is NOT a hash.
340 */ 337 */
@@ -345,8 +342,7 @@ struct ChallengeNonceP
345/** 342/**
346 * Outer layer of an encapsulated backchannel message. 343 * Outer layer of an encapsulated backchannel message.
347 */ 344 */
348struct TransportBackchannelEncapsulationMessage 345struct TransportBackchannelEncapsulationMessage {
349{
350 /** 346 /**
351 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION. 347 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION.
352 */ 348 */
@@ -362,9 +358,7 @@ struct TransportBackchannelEncapsulationMessage
362/** 358/**
363 * Body by which a peer confirms that it is using an ephemeral key. 359 * Body by which a peer confirms that it is using an ephemeral key.
364 */ 360 */
365struct EphemeralConfirmationPS 361struct EphemeralConfirmationPS {
366{
367
368 /** 362 /**
369 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL 363 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL
370 */ 364 */
@@ -403,9 +397,7 @@ struct EphemeralConfirmationPS
403 * Plaintext of the variable-size payload that is encrypted 397 * Plaintext of the variable-size payload that is encrypted
404 * within a `struct TransportBackchannelEncapsulationMessage` 398 * within a `struct TransportBackchannelEncapsulationMessage`
405 */ 399 */
406struct TransportDVBoxPayloadP 400struct TransportDVBoxPayloadP {
407{
408
409 /** 401 /**
410 * Sender's peer identity. 402 * Sender's peer identity.
411 */ 403 */
@@ -438,8 +430,7 @@ struct TransportDVBoxPayloadP
438 * Outer layer of an encapsulated unfragmented application message sent 430 * Outer layer of an encapsulated unfragmented application message sent
439 * over an unreliable channel. 431 * over an unreliable channel.
440 */ 432 */
441struct TransportReliabilityBoxMessage 433struct TransportReliabilityBoxMessage {
442{
443 /** 434 /**
444 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX 435 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX
445 */ 436 */
@@ -465,8 +456,7 @@ struct TransportReliabilityBoxMessage
465/** 456/**
466 * Acknowledgement payload. 457 * Acknowledgement payload.
467 */ 458 */
468struct TransportCummulativeAckPayloadP 459struct TransportCummulativeAckPayloadP {
469{
470 /** 460 /**
471 * How long was the ACK delayed for generating cummulative ACKs? 461 * How long was the ACK delayed for generating cummulative ACKs?
472 * Used to calculate the correct network RTT by taking the receipt 462 * Used to calculate the correct network RTT by taking the receipt
@@ -489,8 +479,7 @@ struct TransportCummulativeAckPayloadP
489 * so ACKs are identified by a combination of PID of sender and 479 * so ACKs are identified by a combination of PID of sender and
490 * message UUID, without the queue playing any role! 480 * message UUID, without the queue playing any role!
491 */ 481 */
492struct TransportReliabilityAckMessage 482struct TransportReliabilityAckMessage {
493{
494 /** 483 /**
495 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK 484 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK
496 */ 485 */
@@ -510,8 +499,7 @@ struct TransportReliabilityAckMessage
510/** 499/**
511 * Outer layer of an encapsulated fragmented application message. 500 * Outer layer of an encapsulated fragmented application message.
512 */ 501 */
513struct TransportFragmentBoxMessage 502struct TransportFragmentBoxMessage {
514{
515 /** 503 /**
516 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT 504 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT
517 */ 505 */
@@ -561,8 +549,7 @@ struct TransportFragmentBoxMessage
561 * potential amplificator will check the @e monotonic_time and only respond 549 * potential amplificator will check the @e monotonic_time and only respond
562 * (at most) once per message. 550 * (at most) once per message.
563 */ 551 */
564struct DvInitPS 552struct DvInitPS {
565{
566 /** 553 /**
567 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 554 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR
568 */ 555 */
@@ -605,8 +592,7 @@ struct DvInitPS
605 * replay old messages. Thus, passively learned paths should always be 592 * replay old messages. Thus, passively learned paths should always be
606 * immediately marked as "potentially stale". 593 * immediately marked as "potentially stale".
607 */ 594 */
608struct DvHopPS 595struct DvHopPS {
609{
610 /** 596 /**
611 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP 597 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP
612 */ 598 */
@@ -633,8 +619,7 @@ struct DvHopPS
633 * An entry describing a peer on a path in a 619 * An entry describing a peer on a path in a
634 * `struct TransportDVLearnMessage` message. 620 * `struct TransportDVLearnMessage` message.
635 */ 621 */
636struct DVPathEntryP 622struct DVPathEntryP {
637{
638 /** 623 /**
639 * Identity of a peer on the path. 624 * Identity of a peer on the path.
640 */ 625 */
@@ -661,8 +646,7 @@ struct DVPathEntryP
661 * zero, peers that can forward to the initator should always try to 646 * zero, peers that can forward to the initator should always try to
662 * forward to the initiator. 647 * forward to the initiator.
663 */ 648 */
664struct TransportDVLearnMessage 649struct TransportDVLearnMessage {
665{
666 /** 650 /**
667 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN 651 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN
668 */ 652 */
@@ -749,8 +733,7 @@ struct TransportDVLearnMessage
749 * the predecessor must be the origin (so this is not really useful 733 * the predecessor must be the origin (so this is not really useful
750 * for anonymization). 734 * for anonymization).
751 */ 735 */
752struct TransportDVBoxMessage 736struct TransportDVBoxMessage {
753{
754 /** 737 /**
755 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX 738 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX
756 */ 739 */
@@ -808,9 +791,7 @@ struct TransportDVBoxMessage
808 * Message send to another peer to validate that it can indeed 791 * Message send to another peer to validate that it can indeed
809 * receive messages at a particular address. 792 * receive messages at a particular address.
810 */ 793 */
811struct TransportValidationChallengeMessage 794struct TransportValidationChallengeMessage {
812{
813
814 /** 795 /**
815 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE 796 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE
816 */ 797 */
@@ -838,9 +819,7 @@ struct TransportValidationChallengeMessage
838 * Message signed by a peer to confirm that it can indeed 819 * Message signed by a peer to confirm that it can indeed
839 * receive messages at a particular address. 820 * receive messages at a particular address.
840 */ 821 */
841struct TransportValidationPS 822struct TransportValidationPS {
842{
843
844 /** 823 /**
845 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE 824 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE
846 */ 825 */
@@ -863,9 +842,7 @@ struct TransportValidationPS
863 * Message send to a peer to respond to a 842 * Message send to a peer to respond to a
864 * #GNUNET_MESSAGE_TYPE_ADDRESS_VALIDATION_CHALLENGE 843 * #GNUNET_MESSAGE_TYPE_ADDRESS_VALIDATION_CHALLENGE
865 */ 844 */
866struct TransportValidationResponseMessage 845struct TransportValidationResponseMessage {
867{
868
869 /** 846 /**
870 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE 847 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE
871 */ 848 */
@@ -909,8 +886,7 @@ struct TransportValidationResponseMessage
909 * send to us, and how much data we already received from the other 886 * send to us, and how much data we already received from the other
910 * peer. 887 * peer.
911 */ 888 */
912struct TransportFlowControlMessage 889struct TransportFlowControlMessage {
913{
914 /** 890 /**
915 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL 891 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL
916 */ 892 */
@@ -966,8 +942,7 @@ GNUNET_NETWORK_STRUCT_END
966/** 942/**
967 * What type of client is the `struct TransportClient` about? 943 * What type of client is the `struct TransportClient` about?
968 */ 944 */
969enum ClientType 945enum ClientType {
970{
971 /** 946 /**
972 * We do not know yet (client is fresh). 947 * We do not know yet (client is fresh).
973 */ 948 */
@@ -999,8 +974,7 @@ enum ClientType
999 * Which transmission options are allowable for transmission? 974 * Which transmission options are allowable for transmission?
1000 * Interpreted bit-wise! 975 * Interpreted bit-wise!
1001 */ 976 */
1002enum RouteMessageOptions 977enum RouteMessageOptions {
1003{
1004 /** 978 /**
1005 * Only confirmed, non-DV direct neighbours. 979 * Only confirmed, non-DV direct neighbours.
1006 */ 980 */
@@ -1033,9 +1007,7 @@ enum RouteMessageOptions
1033/** 1007/**
1034 * When did we launch this DV learning activity? 1008 * When did we launch this DV learning activity?
1035 */ 1009 */
1036struct LearnLaunchEntry 1010struct LearnLaunchEntry {
1037{
1038
1039 /** 1011 /**
1040 * Kept (also) in a DLL sorted by launch time. 1012 * Kept (also) in a DLL sorted by launch time.
1041 */ 1013 */
@@ -1063,8 +1035,7 @@ struct LearnLaunchEntry
1063 * Information we keep per #GOODPUT_AGING_SLOTS about historic 1035 * Information we keep per #GOODPUT_AGING_SLOTS about historic
1064 * (or current) transmission performance. 1036 * (or current) transmission performance.
1065 */ 1037 */
1066struct TransmissionHistoryEntry 1038struct TransmissionHistoryEntry {
1067{
1068 /** 1039 /**
1069 * Number of bytes actually sent in the interval. 1040 * Number of bytes actually sent in the interval.
1070 */ 1041 */
@@ -1081,8 +1052,7 @@ struct TransmissionHistoryEntry
1081/** 1052/**
1082 * Performance data for a transmission possibility. 1053 * Performance data for a transmission possibility.
1083 */ 1054 */
1084struct PerformanceData 1055struct PerformanceData {
1085{
1086 /** 1056 /**
1087 * Weighted average for the RTT. 1057 * Weighted average for the RTT.
1088 */ 1058 */
@@ -1149,9 +1119,7 @@ struct VirtualLink;
1149 * Context from #handle_incoming_msg(). Closure for many 1119 * Context from #handle_incoming_msg(). Closure for many
1150 * message handlers below. 1120 * message handlers below.
1151 */ 1121 */
1152struct CommunicatorMessageContext 1122struct CommunicatorMessageContext {
1153{
1154
1155 /** 1123 /**
1156 * Kept in a DLL of `struct VirtualLink` if waiting for CORE 1124 * Kept in a DLL of `struct VirtualLink` if waiting for CORE
1157 * flow control to unchoke. 1125 * flow control to unchoke.
@@ -1185,9 +1153,7 @@ struct CommunicatorMessageContext
1185/** 1153/**
1186 * Closure for #core_env_sent_cb. 1154 * Closure for #core_env_sent_cb.
1187 */ 1155 */
1188struct CoreSentContext 1156struct CoreSentContext {
1189{
1190
1191 /** 1157 /**
1192 * Kept in a DLL to clear @e vl in case @e vl is lost. 1158 * Kept in a DLL to clear @e vl in case @e vl is lost.
1193 */ 1159 */
@@ -1226,8 +1192,7 @@ struct CoreSentContext
1226 * data that is per neighbour that is not specific to how the 1192 * data that is per neighbour that is not specific to how the
1227 * connectivity is established. 1193 * connectivity is established.
1228 */ 1194 */
1229struct VirtualLink 1195struct VirtualLink {
1230{
1231 /** 1196 /**
1232 * Identity of the peer at the other end of the link. 1197 * Identity of the peer at the other end of the link.
1233 */ 1198 */
@@ -1425,9 +1390,7 @@ struct VirtualLink
1425/** 1390/**
1426 * Data structure kept when we are waiting for an acknowledgement. 1391 * Data structure kept when we are waiting for an acknowledgement.
1427 */ 1392 */
1428struct PendingAcknowledgement 1393struct PendingAcknowledgement {
1429{
1430
1431 /** 1394 /**
1432 * If @e pm is non-NULL, this is the DLL in which this acknowledgement 1395 * If @e pm is non-NULL, this is the DLL in which this acknowledgement
1433 * is kept in relation to its pending message. 1396 * is kept in relation to its pending message.
@@ -1520,9 +1483,7 @@ struct PendingAcknowledgement
1520/** 1483/**
1521 * One possible hop towards a DV target. 1484 * One possible hop towards a DV target.
1522 */ 1485 */
1523struct DistanceVectorHop 1486struct DistanceVectorHop {
1524{
1525
1526 /** 1487 /**
1527 * Kept in a MDLL, sorted by @e timeout. 1488 * Kept in a MDLL, sorted by @e timeout.
1528 */ 1489 */
@@ -1603,9 +1564,7 @@ struct DistanceVectorHop
1603 * Entry in our #dv_routes table, representing a (set of) distance 1564 * Entry in our #dv_routes table, representing a (set of) distance
1604 * vector routes to a particular peer. 1565 * vector routes to a particular peer.
1605 */ 1566 */
1606struct DistanceVector 1567struct DistanceVector {
1607{
1608
1609 /** 1568 /**
1610 * To which peer is this a route? 1569 * To which peer is this a route?
1611 */ 1570 */
@@ -1669,9 +1628,7 @@ struct DistanceVector
1669 * what the communicator can actually provide towards a particular 1628 * what the communicator can actually provide towards a particular
1670 * peer/target). 1629 * peer/target).
1671 */ 1630 */
1672struct QueueEntry 1631struct QueueEntry {
1673{
1674
1675 /** 1632 /**
1676 * Kept as a DLL. 1633 * Kept as a DLL.
1677 */ 1634 */
@@ -1703,8 +1660,7 @@ struct QueueEntry
1703 * A queue is a message queue provided by a communicator 1660 * A queue is a message queue provided by a communicator
1704 * via which we can reach a particular neighbour. 1661 * via which we can reach a particular neighbour.
1705 */ 1662 */
1706struct Queue 1663struct Queue {
1707{
1708 /** 1664 /**
1709 * Kept in a MDLL. 1665 * Kept in a MDLL.
1710 */ 1666 */
@@ -1832,9 +1788,7 @@ struct Queue
1832/** 1788/**
1833 * Information we keep for a message that we are reassembling. 1789 * Information we keep for a message that we are reassembling.
1834 */ 1790 */
1835struct ReassemblyContext 1791struct ReassemblyContext {
1836{
1837
1838 /** 1792 /**
1839 * Original message ID for of the message that all the fragments 1793 * Original message ID for of the message that all the fragments
1840 * belong to. 1794 * belong to.
@@ -1892,9 +1846,7 @@ struct ReassemblyContext
1892/** 1846/**
1893 * A neighbour that at least one communicator is connected to. 1847 * A neighbour that at least one communicator is connected to.
1894 */ 1848 */
1895struct Neighbour 1849struct Neighbour {
1896{
1897
1898 /** 1850 /**
1899 * Which peer is this about? 1851 * Which peer is this about?
1900 */ 1852 */
@@ -1977,9 +1929,7 @@ struct Neighbour
1977 * Another peer attempted to talk to us, we should try to establish 1929 * Another peer attempted to talk to us, we should try to establish
1978 * a connection in the other direction. 1930 * a connection in the other direction.
1979 */ 1931 */
1980struct IncomingRequest 1932struct IncomingRequest {
1981{
1982
1983 /** 1933 /**
1984 * Kept in a DLL. 1934 * Kept in a DLL.
1985 */ 1935 */
@@ -2005,9 +1955,7 @@ struct IncomingRequest
2005/** 1955/**
2006 * A peer that an application (client) would like us to talk to directly. 1956 * A peer that an application (client) would like us to talk to directly.
2007 */ 1957 */
2008struct PeerRequest 1958struct PeerRequest {
2009{
2010
2011 /** 1959 /**
2012 * Which peer is this about? 1960 * Which peer is this about?
2013 */ 1961 */
@@ -2040,9 +1988,7 @@ struct PeerRequest
2040/** 1988/**
2041 * Types of different pending messages. 1989 * Types of different pending messages.
2042 */ 1990 */
2043enum PendingMessageType 1991enum PendingMessageType {
2044{
2045
2046 /** 1992 /**
2047 * Ordinary message received from the CORE service. 1993 * Ordinary message received from the CORE service.
2048 */ 1994 */
@@ -2062,7 +2008,6 @@ enum PendingMessageType
2062 * Pending message created during #forward_dv_box(). 2008 * Pending message created during #forward_dv_box().
2063 */ 2009 */
2064 PMT_DV_BOX = 3 2010 PMT_DV_BOX = 3
2065
2066}; 2011};
2067 2012
2068 2013
@@ -2092,8 +2037,7 @@ enum PendingMessageType
2092 * is never again transmitted (even if it fits below the MTU), and 2037 * is never again transmitted (even if it fits below the MTU), and
2093 * only (remaining) fragments are sent. 2038 * only (remaining) fragments are sent.
2094 */ 2039 */
2095struct PendingMessage 2040struct PendingMessage {
2096{
2097 /** 2041 /**
2098 * Kept in a MDLL of messages for this @a vl. 2042 * Kept in a MDLL of messages for this @a vl.
2099 */ 2043 */
@@ -2232,8 +2176,7 @@ struct PendingMessage
2232/** 2176/**
2233 * Acknowledgement payload. 2177 * Acknowledgement payload.
2234 */ 2178 */
2235struct TransportCummulativeAckPayload 2179struct TransportCummulativeAckPayload {
2236{
2237 /** 2180 /**
2238 * When did we receive the message we are ACKing? Used to calculate 2181 * When did we receive the message we are ACKing? Used to calculate
2239 * the delay we introduced by cummulating ACKs. 2182 * the delay we introduced by cummulating ACKs.
@@ -2251,8 +2194,7 @@ struct TransportCummulativeAckPayload
2251 * Data structure in which we track acknowledgements still to 2194 * Data structure in which we track acknowledgements still to
2252 * be sent to the 2195 * be sent to the
2253 */ 2196 */
2254struct AcknowledgementCummulator 2197struct AcknowledgementCummulator {
2255{
2256 /** 2198 /**
2257 * Target peer for which we are accumulating ACKs here. 2199 * Target peer for which we are accumulating ACKs here.
2258 */ 2200 */
@@ -2292,9 +2234,7 @@ struct AcknowledgementCummulator
2292/** 2234/**
2293 * One of the addresses of this peer. 2235 * One of the addresses of this peer.
2294 */ 2236 */
2295struct AddressListEntry 2237struct AddressListEntry {
2296{
2297
2298 /** 2238 /**
2299 * Kept in a DLL. 2239 * Kept in a DLL.
2300 */ 2240 */
@@ -2346,9 +2286,7 @@ struct AddressListEntry
2346/** 2286/**
2347 * Client connected to the transport service. 2287 * Client connected to the transport service.
2348 */ 2288 */
2349struct TransportClient 2289struct TransportClient {
2350{
2351
2352 /** 2290 /**
2353 * Kept in a DLL. 2291 * Kept in a DLL.
2354 */ 2292 */
@@ -2374,15 +2312,11 @@ struct TransportClient
2374 */ 2312 */
2375 enum ClientType type; 2313 enum ClientType type;
2376 2314
2377 union 2315 union {
2378 {
2379
2380 /** 2316 /**
2381 * Information for @e type #CT_CORE. 2317 * Information for @e type #CT_CORE.
2382 */ 2318 */
2383 struct 2319 struct {
2384 {
2385
2386 /** 2320 /**
2387 * Head of list of messages pending for this client, sorted by 2321 * Head of list of messages pending for this client, sorted by
2388 * transmission time ("next_attempt" + possibly internal prioritization). 2322 * transmission time ("next_attempt" + possibly internal prioritization).
@@ -2393,15 +2327,12 @@ struct TransportClient
2393 * Tail of list of messages pending for this client. 2327 * Tail of list of messages pending for this client.
2394 */ 2328 */
2395 struct PendingMessage *pending_msg_tail; 2329 struct PendingMessage *pending_msg_tail;
2396
2397 } core; 2330 } core;
2398 2331
2399 /** 2332 /**
2400 * Information for @e type #CT_MONITOR. 2333 * Information for @e type #CT_MONITOR.
2401 */ 2334 */
2402 struct 2335 struct {
2403 {
2404
2405 /** 2336 /**
2406 * Peer identity to monitor the addresses of. 2337 * Peer identity to monitor the addresses of.
2407 * Zero to monitor all neighbours. Valid if 2338 * Zero to monitor all neighbours. Valid if
@@ -2413,15 +2344,13 @@ struct TransportClient
2413 * Is this a one-shot monitor? 2344 * Is this a one-shot monitor?
2414 */ 2345 */
2415 int one_shot; 2346 int one_shot;
2416
2417 } monitor; 2347 } monitor;
2418 2348
2419 2349
2420 /** 2350 /**
2421 * Information for @e type #CT_COMMUNICATOR. 2351 * Information for @e type #CT_COMMUNICATOR.
2422 */ 2352 */
2423 struct 2353 struct {
2424 {
2425 /** 2354 /**
2426 * If @e type is #CT_COMMUNICATOR, this communicator 2355 * If @e type is #CT_COMMUNICATOR, this communicator
2427 * supports communicating using these addresses. 2356 * supports communicating using these addresses.
@@ -2461,23 +2390,18 @@ struct TransportClient
2461 * Characteristics of this communicator. 2390 * Characteristics of this communicator.
2462 */ 2391 */
2463 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; 2392 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
2464
2465 } communicator; 2393 } communicator;
2466 2394
2467 /** 2395 /**
2468 * Information for @e type #CT_APPLICATION 2396 * Information for @e type #CT_APPLICATION
2469 */ 2397 */
2470 struct 2398 struct {
2471 {
2472
2473 /** 2399 /**
2474 * Map of requests for peers the given client application would like to 2400 * Map of requests for peers the given client application would like to
2475 * see connections for. Maps from PIDs to `struct PeerRequest`. 2401 * see connections for. Maps from PIDs to `struct PeerRequest`.
2476 */ 2402 */
2477 struct GNUNET_CONTAINER_MultiPeerMap *requests; 2403 struct GNUNET_CONTAINER_MultiPeerMap *requests;
2478
2479 } application; 2404 } application;
2480
2481 } details; 2405 } details;
2482}; 2406};
2483 2407
@@ -2486,9 +2410,7 @@ struct TransportClient
2486 * State we keep for validation activities. Each of these 2410 * State we keep for validation activities. Each of these
2487 * is both in the #validation_heap and the #validation_map. 2411 * is both in the #validation_heap and the #validation_map.
2488 */ 2412 */
2489struct ValidationState 2413struct ValidationState {
2490{
2491
2492 /** 2414 /**
2493 * For which peer is @a address to be validated (or possibly valid)? 2415 * For which peer is @a address to be validated (or possibly valid)?
2494 * Serves as key in the #validation_map. 2416 * Serves as key in the #validation_map.
@@ -2598,8 +2520,7 @@ struct ValidationState
2598 * material (to avoid repeatedly checking signatures), and to synchronize 2520 * material (to avoid repeatedly checking signatures), and to synchronize
2599 * monotonic time with the PEERSTORE. 2521 * monotonic time with the PEERSTORE.
2600 */ 2522 */
2601struct Backtalker 2523struct Backtalker {
2602{
2603 /** 2524 /**
2604 * Peer this is about. 2525 * Peer this is about.
2605 */ 2526 */
@@ -2822,11 +2743,11 @@ static struct GNUNET_TIME_Absolute hello_mono_time;
2822 * @return current age of the world 2743 * @return current age of the world
2823 */ 2744 */
2824static unsigned int 2745static unsigned int
2825get_age () 2746get_age()
2826{ 2747{
2827 struct GNUNET_TIME_Absolute now; 2748 struct GNUNET_TIME_Absolute now;
2828 2749
2829 now = GNUNET_TIME_absolute_get (); 2750 now = GNUNET_TIME_absolute_get();
2830 return now.abs_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us / 15; 2751 return now.abs_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us / 15;
2831} 2752}
2832 2753
@@ -2837,13 +2758,13 @@ get_age ()
2837 * @param ir data structure to release 2758 * @param ir data structure to release
2838 */ 2759 */
2839static void 2760static void
2840free_incoming_request (struct IncomingRequest *ir) 2761free_incoming_request(struct IncomingRequest *ir)
2841{ 2762{
2842 GNUNET_CONTAINER_DLL_remove (ir_head, ir_tail, ir); 2763 GNUNET_CONTAINER_DLL_remove(ir_head, ir_tail, ir);
2843 GNUNET_assert (ir_total > 0); 2764 GNUNET_assert(ir_total > 0);
2844 ir_total--; 2765 ir_total--;
2845 GNUNET_PEERSTORE_watch_cancel (ir->wc); 2766 GNUNET_PEERSTORE_watch_cancel(ir->wc);
2846 GNUNET_free (ir); 2767 GNUNET_free(ir);
2847} 2768}
2848 2769
2849 2770
@@ -2853,34 +2774,34 @@ free_incoming_request (struct IncomingRequest *ir)
2853 * @param pa data structure to release 2774 * @param pa data structure to release
2854 */ 2775 */
2855static void 2776static void
2856free_pending_acknowledgement (struct PendingAcknowledgement *pa) 2777free_pending_acknowledgement(struct PendingAcknowledgement *pa)
2857{ 2778{
2858 struct Queue *q = pa->queue; 2779 struct Queue *q = pa->queue;
2859 struct PendingMessage *pm = pa->pm; 2780 struct PendingMessage *pm = pa->pm;
2860 struct DistanceVectorHop *dvh = pa->dvh; 2781 struct DistanceVectorHop *dvh = pa->dvh;
2861 2782
2862 GNUNET_CONTAINER_MDLL_remove (pa, pa_head, pa_tail, pa); 2783 GNUNET_CONTAINER_MDLL_remove(pa, pa_head, pa_tail, pa);
2863 pa_count--; 2784 pa_count--;
2864 if (NULL != q) 2785 if (NULL != q)
2865 { 2786 {
2866 GNUNET_CONTAINER_MDLL_remove (queue, q->pa_head, q->pa_tail, pa); 2787 GNUNET_CONTAINER_MDLL_remove(queue, q->pa_head, q->pa_tail, pa);
2867 pa->queue = NULL; 2788 pa->queue = NULL;
2868 } 2789 }
2869 if (NULL != pm) 2790 if (NULL != pm)
2870 { 2791 {
2871 GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa); 2792 GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa);
2872 pa->pm = NULL; 2793 pa->pm = NULL;
2873 } 2794 }
2874 if (NULL != dvh) 2795 if (NULL != dvh)
2875 { 2796 {
2876 GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa); 2797 GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa);
2877 pa->queue = NULL; 2798 pa->queue = NULL;
2878 } 2799 }
2879 GNUNET_assert (GNUNET_YES == 2800 GNUNET_assert(GNUNET_YES ==
2880 GNUNET_CONTAINER_multiuuidmap_remove (pending_acks, 2801 GNUNET_CONTAINER_multiuuidmap_remove(pending_acks,
2881 &pa->ack_uuid.value, 2802 &pa->ack_uuid.value,
2882 pa)); 2803 pa));
2883 GNUNET_free (pa); 2804 GNUNET_free(pa);
2884} 2805}
2885 2806
2886 2807
@@ -2893,23 +2814,23 @@ free_pending_acknowledgement (struct PendingAcknowledgement *pa)
2893 * @param root root of the tree to free 2814 * @param root root of the tree to free
2894 */ 2815 */
2895static void 2816static void
2896free_fragment_tree (struct PendingMessage *root) 2817free_fragment_tree(struct PendingMessage *root)
2897{ 2818{
2898 struct PendingMessage *frag; 2819 struct PendingMessage *frag;
2899 2820
2900 while (NULL != (frag = root->head_frag)) 2821 while (NULL != (frag = root->head_frag))
2901 {
2902 struct PendingAcknowledgement *pa;
2903
2904 free_fragment_tree (frag);
2905 while (NULL != (pa = frag->pa_head))
2906 { 2822 {
2907 GNUNET_CONTAINER_MDLL_remove (pm, frag->pa_head, frag->pa_tail, pa); 2823 struct PendingAcknowledgement *pa;
2908 pa->pm = NULL; 2824
2825 free_fragment_tree(frag);
2826 while (NULL != (pa = frag->pa_head))
2827 {
2828 GNUNET_CONTAINER_MDLL_remove(pm, frag->pa_head, frag->pa_tail, pa);
2829 pa->pm = NULL;
2830 }
2831 GNUNET_CONTAINER_MDLL_remove(frag, root->head_frag, root->tail_frag, frag);
2832 GNUNET_free(frag);
2909 } 2833 }
2910 GNUNET_CONTAINER_MDLL_remove (frag, root->head_frag, root->tail_frag, frag);
2911 GNUNET_free (frag);
2912 }
2913} 2834}
2914 2835
2915 2836
@@ -2921,44 +2842,44 @@ free_fragment_tree (struct PendingMessage *root)
2921 * @param pm the pending message to free 2842 * @param pm the pending message to free
2922 */ 2843 */
2923static void 2844static void
2924free_pending_message (struct PendingMessage *pm) 2845free_pending_message(struct PendingMessage *pm)
2925{ 2846{
2926 struct TransportClient *tc = pm->client; 2847 struct TransportClient *tc = pm->client;
2927 struct VirtualLink *vl = pm->vl; 2848 struct VirtualLink *vl = pm->vl;
2928 struct PendingAcknowledgement *pa; 2849 struct PendingAcknowledgement *pa;
2929 2850
2930 if (NULL != tc) 2851 if (NULL != tc)
2931 { 2852 {
2932 GNUNET_CONTAINER_MDLL_remove (client, 2853 GNUNET_CONTAINER_MDLL_remove(client,
2933 tc->details.core.pending_msg_head, 2854 tc->details.core.pending_msg_head,
2934 tc->details.core.pending_msg_tail, 2855 tc->details.core.pending_msg_tail,
2935 pm); 2856 pm);
2936 } 2857 }
2937 if (NULL != vl) 2858 if (NULL != vl)
2938 { 2859 {
2939 GNUNET_CONTAINER_MDLL_remove (vl, 2860 GNUNET_CONTAINER_MDLL_remove(vl,
2940 vl->pending_msg_head, 2861 vl->pending_msg_head,
2941 vl->pending_msg_tail, 2862 vl->pending_msg_tail,
2942 pm); 2863 pm);
2943 } 2864 }
2944 while (NULL != (pa = pm->pa_head)) 2865 while (NULL != (pa = pm->pa_head))
2945 { 2866 {
2946 GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa); 2867 GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa);
2947 pa->pm = NULL; 2868 pa->pm = NULL;
2948 } 2869 }
2949 2870
2950 free_fragment_tree (pm); 2871 free_fragment_tree(pm);
2951 if (NULL != pm->qe) 2872 if (NULL != pm->qe)
2952 { 2873 {
2953 GNUNET_assert (pm == pm->qe->pm); 2874 GNUNET_assert(pm == pm->qe->pm);
2954 pm->qe->pm = NULL; 2875 pm->qe->pm = NULL;
2955 } 2876 }
2956 if (NULL != pm->bpm) 2877 if (NULL != pm->bpm)
2957 { 2878 {
2958 free_fragment_tree (pm->bpm); 2879 free_fragment_tree(pm->bpm);
2959 GNUNET_free (pm->bpm); 2880 GNUNET_free(pm->bpm);
2960 } 2881 }
2961 GNUNET_free (pm); 2882 GNUNET_free(pm);
2962} 2883}
2963 2884
2964 2885
@@ -2968,34 +2889,34 @@ free_pending_message (struct PendingMessage *pm)
2968 * @param vl link data to free 2889 * @param vl link data to free
2969 */ 2890 */
2970static void 2891static void
2971free_virtual_link (struct VirtualLink *vl) 2892free_virtual_link(struct VirtualLink *vl)
2972{ 2893{
2973 struct PendingMessage *pm; 2894 struct PendingMessage *pm;
2974 struct CoreSentContext *csc; 2895 struct CoreSentContext *csc;
2975 2896
2976 while (NULL != (pm = vl->pending_msg_head)) 2897 while (NULL != (pm = vl->pending_msg_head))
2977 free_pending_message (pm); 2898 free_pending_message(pm);
2978 GNUNET_assert (GNUNET_YES == 2899 GNUNET_assert(GNUNET_YES ==
2979 GNUNET_CONTAINER_multipeermap_remove (links, &vl->target, vl)); 2900 GNUNET_CONTAINER_multipeermap_remove(links, &vl->target, vl));
2980 if (NULL != vl->visibility_task) 2901 if (NULL != vl->visibility_task)
2981 { 2902 {
2982 GNUNET_SCHEDULER_cancel (vl->visibility_task); 2903 GNUNET_SCHEDULER_cancel(vl->visibility_task);
2983 vl->visibility_task = NULL; 2904 vl->visibility_task = NULL;
2984 } 2905 }
2985 if (NULL != vl->fc_retransmit_task) 2906 if (NULL != vl->fc_retransmit_task)
2986 { 2907 {
2987 GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); 2908 GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task);
2988 vl->fc_retransmit_task = NULL; 2909 vl->fc_retransmit_task = NULL;
2989 } 2910 }
2990 while (NULL != (csc = vl->csc_head)) 2911 while (NULL != (csc = vl->csc_head))
2991 { 2912 {
2992 GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, csc); 2913 GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, csc);
2993 GNUNET_assert (vl == csc->vl); 2914 GNUNET_assert(vl == csc->vl);
2994 csc->vl = NULL; 2915 csc->vl = NULL;
2995 } 2916 }
2996 GNUNET_break (NULL == vl->n); 2917 GNUNET_break(NULL == vl->n);
2997 GNUNET_break (NULL == vl->dv); 2918 GNUNET_break(NULL == vl->dv);
2998 GNUNET_free (vl); 2919 GNUNET_free(vl);
2999} 2920}
3000 2921
3001 2922
@@ -3005,20 +2926,20 @@ free_virtual_link (struct VirtualLink *vl)
3005 * @param vs validation state to free 2926 * @param vs validation state to free
3006 */ 2927 */
3007static void 2928static void
3008free_validation_state (struct ValidationState *vs) 2929free_validation_state(struct ValidationState *vs)
3009{ 2930{
3010 GNUNET_assert ( 2931 GNUNET_assert(
3011 GNUNET_YES == 2932 GNUNET_YES ==
3012 GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs)); 2933 GNUNET_CONTAINER_multipeermap_remove(validation_map, &vs->pid, vs));
3013 GNUNET_CONTAINER_heap_remove_node (vs->hn); 2934 GNUNET_CONTAINER_heap_remove_node(vs->hn);
3014 vs->hn = NULL; 2935 vs->hn = NULL;
3015 if (NULL != vs->sc) 2936 if (NULL != vs->sc)
3016 { 2937 {
3017 GNUNET_PEERSTORE_store_cancel (vs->sc); 2938 GNUNET_PEERSTORE_store_cancel(vs->sc);
3018 vs->sc = NULL; 2939 vs->sc = NULL;
3019 } 2940 }
3020 GNUNET_free (vs->address); 2941 GNUNET_free(vs->address);
3021 GNUNET_free (vs); 2942 GNUNET_free(vs);
3022} 2943}
3023 2944
3024 2945
@@ -3029,9 +2950,9 @@ free_validation_state (struct ValidationState *vs)
3029 * @return NULL if we do not have this peer as a neighbour 2950 * @return NULL if we do not have this peer as a neighbour
3030 */ 2951 */
3031static struct Neighbour * 2952static struct Neighbour *
3032lookup_neighbour (const struct GNUNET_PeerIdentity *pid) 2953lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
3033{ 2954{
3034 return GNUNET_CONTAINER_multipeermap_get (neighbours, pid); 2955 return GNUNET_CONTAINER_multipeermap_get(neighbours, pid);
3035} 2956}
3036 2957
3037 2958
@@ -3042,17 +2963,16 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
3042 * @return NULL if we do not have this peer as a virtual link 2963 * @return NULL if we do not have this peer as a virtual link
3043 */ 2964 */
3044static struct VirtualLink * 2965static struct VirtualLink *
3045lookup_virtual_link (const struct GNUNET_PeerIdentity *pid) 2966lookup_virtual_link(const struct GNUNET_PeerIdentity *pid)
3046{ 2967{
3047 return GNUNET_CONTAINER_multipeermap_get (links, pid); 2968 return GNUNET_CONTAINER_multipeermap_get(links, pid);
3048} 2969}
3049 2970
3050 2971
3051/** 2972/**
3052 * Details about what to notify monitors about. 2973 * Details about what to notify monitors about.
3053 */ 2974 */
3054struct MonitorEvent 2975struct MonitorEvent {
3055{
3056 /** 2976 /**
3057 * @deprecated To be discussed if we keep these... 2977 * @deprecated To be discussed if we keep these...
3058 */ 2978 */
@@ -3091,20 +3011,20 @@ struct MonitorEvent
3091 * @param dvh hop to free 3011 * @param dvh hop to free
3092 */ 3012 */
3093static void 3013static void
3094free_distance_vector_hop (struct DistanceVectorHop *dvh) 3014free_distance_vector_hop(struct DistanceVectorHop *dvh)
3095{ 3015{
3096 struct Neighbour *n = dvh->next_hop; 3016 struct Neighbour *n = dvh->next_hop;
3097 struct DistanceVector *dv = dvh->dv; 3017 struct DistanceVector *dv = dvh->dv;
3098 struct PendingAcknowledgement *pa; 3018 struct PendingAcknowledgement *pa;
3099 3019
3100 while (NULL != (pa = dvh->pa_head)) 3020 while (NULL != (pa = dvh->pa_head))
3101 { 3021 {
3102 GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa); 3022 GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa);
3103 pa->dvh = NULL; 3023 pa->dvh = NULL;
3104 } 3024 }
3105 GNUNET_CONTAINER_MDLL_remove (neighbour, n->dv_head, n->dv_tail, dvh); 3025 GNUNET_CONTAINER_MDLL_remove(neighbour, n->dv_head, n->dv_tail, dvh);
3106 GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, dvh); 3026 GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, dvh);
3107 GNUNET_free (dvh); 3027 GNUNET_free(dvh);
3108} 3028}
3109 3029
3110 3030
@@ -3115,7 +3035,7 @@ free_distance_vector_hop (struct DistanceVectorHop *dvh)
3115 * @param cls a `struct VirtualLink` 3035 * @param cls a `struct VirtualLink`
3116 */ 3036 */
3117static void 3037static void
3118check_link_down (void *cls); 3038check_link_down(void *cls);
3119 3039
3120 3040
3121/** 3041/**
@@ -3124,22 +3044,22 @@ check_link_down (void *cls);
3124 * @param pid peer the connection was for 3044 * @param pid peer the connection was for
3125 */ 3045 */
3126static void 3046static void
3127cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid) 3047cores_send_disconnect_info(const struct GNUNET_PeerIdentity *pid)
3128{ 3048{
3129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3049 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3130 "Informing CORE clients about disconnect from %s\n", 3050 "Informing CORE clients about disconnect from %s\n",
3131 GNUNET_i2s (pid)); 3051 GNUNET_i2s(pid));
3132 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 3052 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3133 { 3053 {
3134 struct GNUNET_MQ_Envelope *env; 3054 struct GNUNET_MQ_Envelope *env;
3135 struct DisconnectInfoMessage *dim; 3055 struct DisconnectInfoMessage *dim;
3136 3056
3137 if (CT_CORE != tc->type) 3057 if (CT_CORE != tc->type)
3138 continue; 3058 continue;
3139 env = GNUNET_MQ_msg (dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 3059 env = GNUNET_MQ_msg(dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
3140 dim->peer = *pid; 3060 dim->peer = *pid;
3141 GNUNET_MQ_send (tc->mq, env); 3061 GNUNET_MQ_send(tc->mq, env);
3142 } 3062 }
3143} 3063}
3144 3064
3145 3065
@@ -3150,43 +3070,43 @@ cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid)
3150 * @param dv route to free 3070 * @param dv route to free
3151 */ 3071 */
3152static void 3072static void
3153free_dv_route (struct DistanceVector *dv) 3073free_dv_route(struct DistanceVector *dv)
3154{ 3074{
3155 struct DistanceVectorHop *dvh; 3075 struct DistanceVectorHop *dvh;
3156 3076
3157 while (NULL != (dvh = dv->dv_head)) 3077 while (NULL != (dvh = dv->dv_head))
3158 free_distance_vector_hop (dvh); 3078 free_distance_vector_hop(dvh);
3159 if (NULL == dv->dv_head) 3079 if (NULL == dv->dv_head)
3160 {
3161 struct VirtualLink *vl;
3162
3163 GNUNET_assert (
3164 GNUNET_YES ==
3165 GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv));
3166 if (NULL != (vl = dv->vl))
3167 { 3080 {
3168 GNUNET_assert (dv == vl->dv); 3081 struct VirtualLink *vl;
3169 vl->dv = NULL;
3170 if (NULL == vl->n)
3171 {
3172 cores_send_disconnect_info (&dv->target);
3173 free_virtual_link (vl);
3174 }
3175 else
3176 {
3177 GNUNET_SCHEDULER_cancel (vl->visibility_task);
3178 vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl);
3179 }
3180 dv->vl = NULL;
3181 }
3182 3082
3183 if (NULL != dv->timeout_task) 3083 GNUNET_assert(
3184 { 3084 GNUNET_YES ==
3185 GNUNET_SCHEDULER_cancel (dv->timeout_task); 3085 GNUNET_CONTAINER_multipeermap_remove(dv_routes, &dv->target, dv));
3186 dv->timeout_task = NULL; 3086 if (NULL != (vl = dv->vl))
3087 {
3088 GNUNET_assert(dv == vl->dv);
3089 vl->dv = NULL;
3090 if (NULL == vl->n)
3091 {
3092 cores_send_disconnect_info(&dv->target);
3093 free_virtual_link(vl);
3094 }
3095 else
3096 {
3097 GNUNET_SCHEDULER_cancel(vl->visibility_task);
3098 vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl);
3099 }
3100 dv->vl = NULL;
3101 }
3102
3103 if (NULL != dv->timeout_task)
3104 {
3105 GNUNET_SCHEDULER_cancel(dv->timeout_task);
3106 dv->timeout_task = NULL;
3107 }
3108 GNUNET_free(dv);
3187 } 3109 }
3188 GNUNET_free (dv);
3189 }
3190} 3110}
3191 3111
3192 3112
@@ -3204,30 +3124,30 @@ free_dv_route (struct DistanceVector *dv)
3204 * @param me detailed information to transmit 3124 * @param me detailed information to transmit
3205 */ 3125 */
3206static void 3126static void
3207notify_monitor (struct TransportClient *tc, 3127notify_monitor(struct TransportClient *tc,
3208 const struct GNUNET_PeerIdentity *peer, 3128 const struct GNUNET_PeerIdentity *peer,
3209 const char *address, 3129 const char *address,
3210 enum GNUNET_NetworkType nt, 3130 enum GNUNET_NetworkType nt,
3211 const struct MonitorEvent *me) 3131 const struct MonitorEvent *me)
3212{ 3132{
3213 struct GNUNET_MQ_Envelope *env; 3133 struct GNUNET_MQ_Envelope *env;
3214 struct GNUNET_TRANSPORT_MonitorData *md; 3134 struct GNUNET_TRANSPORT_MonitorData *md;
3215 size_t addr_len = strlen (address) + 1; 3135 size_t addr_len = strlen(address) + 1;
3216 3136
3217 env = GNUNET_MQ_msg_extra (md, 3137 env = GNUNET_MQ_msg_extra(md,
3218 addr_len, 3138 addr_len,
3219 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA); 3139 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA);
3220 md->nt = htonl ((uint32_t) nt); 3140 md->nt = htonl((uint32_t)nt);
3221 md->peer = *peer; 3141 md->peer = *peer;
3222 md->last_validation = GNUNET_TIME_absolute_hton (me->last_validation); 3142 md->last_validation = GNUNET_TIME_absolute_hton(me->last_validation);
3223 md->valid_until = GNUNET_TIME_absolute_hton (me->valid_until); 3143 md->valid_until = GNUNET_TIME_absolute_hton(me->valid_until);
3224 md->next_validation = GNUNET_TIME_absolute_hton (me->next_validation); 3144 md->next_validation = GNUNET_TIME_absolute_hton(me->next_validation);
3225 md->rtt = GNUNET_TIME_relative_hton (me->rtt); 3145 md->rtt = GNUNET_TIME_relative_hton(me->rtt);
3226 md->cs = htonl ((uint32_t) me->cs); 3146 md->cs = htonl((uint32_t)me->cs);
3227 md->num_msg_pending = htonl (me->num_msg_pending); 3147 md->num_msg_pending = htonl(me->num_msg_pending);
3228 md->num_bytes_pending = htonl (me->num_bytes_pending); 3148 md->num_bytes_pending = htonl(me->num_bytes_pending);
3229 memcpy (&md[1], address, addr_len); 3149 memcpy(&md[1], address, addr_len);
3230 GNUNET_MQ_send (tc->mq, env); 3150 GNUNET_MQ_send(tc->mq, env);
3231} 3151}
3232 3152
3233 3153
@@ -3241,22 +3161,22 @@ notify_monitor (struct TransportClient *tc,
3241 * @param me detailed information to transmit 3161 * @param me detailed information to transmit
3242 */ 3162 */
3243static void 3163static void
3244notify_monitors (const struct GNUNET_PeerIdentity *peer, 3164notify_monitors(const struct GNUNET_PeerIdentity *peer,
3245 const char *address, 3165 const char *address,
3246 enum GNUNET_NetworkType nt, 3166 enum GNUNET_NetworkType nt,
3247 const struct MonitorEvent *me) 3167 const struct MonitorEvent *me)
3248{ 3168{
3249 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 3169 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3250 { 3170 {
3251 if (CT_MONITOR != tc->type) 3171 if (CT_MONITOR != tc->type)
3252 continue; 3172 continue;
3253 if (tc->details.monitor.one_shot) 3173 if (tc->details.monitor.one_shot)
3254 continue; 3174 continue;
3255 if ((0 != GNUNET_is_zero (&tc->details.monitor.peer)) && 3175 if ((0 != GNUNET_is_zero(&tc->details.monitor.peer)) &&
3256 (0 != GNUNET_memcmp (&tc->details.monitor.peer, peer))) 3176 (0 != GNUNET_memcmp(&tc->details.monitor.peer, peer)))
3257 continue; 3177 continue;
3258 notify_monitor (tc, peer, address, nt, me); 3178 notify_monitor(tc, peer, address, nt, me);
3259 } 3179 }
3260} 3180}
3261 3181
3262 3182
@@ -3270,18 +3190,18 @@ notify_monitors (const struct GNUNET_PeerIdentity *peer,
3270 * @return our `struct TransportClient` 3190 * @return our `struct TransportClient`
3271 */ 3191 */
3272static void * 3192static void *
3273client_connect_cb (void *cls, 3193client_connect_cb(void *cls,
3274 struct GNUNET_SERVICE_Client *client, 3194 struct GNUNET_SERVICE_Client *client,
3275 struct GNUNET_MQ_Handle *mq) 3195 struct GNUNET_MQ_Handle *mq)
3276{ 3196{
3277 struct TransportClient *tc; 3197 struct TransportClient *tc;
3278 3198
3279 (void) cls; 3199 (void)cls;
3280 tc = GNUNET_new (struct TransportClient); 3200 tc = GNUNET_new(struct TransportClient);
3281 tc->client = client; 3201 tc->client = client;
3282 tc->mq = mq; 3202 tc->mq = mq;
3283 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc); 3203 GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc);
3284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); 3204 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
3285 return tc; 3205 return tc;
3286} 3206}
3287 3207
@@ -3292,16 +3212,16 @@ client_connect_cb (void *cls,
3292 * @param rc data structure to free 3212 * @param rc data structure to free
3293 */ 3213 */
3294static void 3214static void
3295free_reassembly_context (struct ReassemblyContext *rc) 3215free_reassembly_context(struct ReassemblyContext *rc)
3296{ 3216{
3297 struct Neighbour *n = rc->neighbour; 3217 struct Neighbour *n = rc->neighbour;
3298 3218
3299 GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn)); 3219 GNUNET_assert(rc == GNUNET_CONTAINER_heap_remove_node(rc->hn));
3300 GNUNET_assert (GNUNET_OK == 3220 GNUNET_assert(GNUNET_OK ==
3301 GNUNET_CONTAINER_multihashmap32_remove (n->reassembly_map, 3221 GNUNET_CONTAINER_multihashmap32_remove(n->reassembly_map,
3302 rc->msg_uuid.uuid, 3222 rc->msg_uuid.uuid,
3303 rc)); 3223 rc));
3304 GNUNET_free (rc); 3224 GNUNET_free(rc);
3305} 3225}
3306 3226
3307 3227
@@ -3311,27 +3231,27 @@ free_reassembly_context (struct ReassemblyContext *rc)
3311 * @param cls a `struct Neighbour` 3231 * @param cls a `struct Neighbour`
3312 */ 3232 */
3313static void 3233static void
3314reassembly_cleanup_task (void *cls) 3234reassembly_cleanup_task(void *cls)
3315{ 3235{
3316 struct Neighbour *n = cls; 3236 struct Neighbour *n = cls;
3317 struct ReassemblyContext *rc; 3237 struct ReassemblyContext *rc;
3318 3238
3319 n->reassembly_timeout_task = NULL; 3239 n->reassembly_timeout_task = NULL;
3320 while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap))) 3240 while (NULL != (rc = GNUNET_CONTAINER_heap_peek(n->reassembly_heap)))
3321 {
3322 if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)
3323 .rel_value_us)
3324 { 3241 {
3325 free_reassembly_context (rc); 3242 if (0 == GNUNET_TIME_absolute_get_remaining(rc->reassembly_timeout)
3326 continue; 3243 .rel_value_us)
3244 {
3245 free_reassembly_context(rc);
3246 continue;
3247 }
3248 GNUNET_assert(NULL == n->reassembly_timeout_task);
3249 n->reassembly_timeout_task =
3250 GNUNET_SCHEDULER_add_at(rc->reassembly_timeout,
3251 &reassembly_cleanup_task,
3252 n);
3253 return;
3327 } 3254 }
3328 GNUNET_assert (NULL == n->reassembly_timeout_task);
3329 n->reassembly_timeout_task =
3330 GNUNET_SCHEDULER_add_at (rc->reassembly_timeout,
3331 &reassembly_cleanup_task,
3332 n);
3333 return;
3334 }
3335} 3255}
3336 3256
3337 3257
@@ -3344,13 +3264,13 @@ reassembly_cleanup_task (void *cls)
3344 * @return #GNUNET_OK (continue iteration) 3264 * @return #GNUNET_OK (continue iteration)
3345 */ 3265 */
3346static int 3266static int
3347free_reassembly_cb (void *cls, uint32_t key, void *value) 3267free_reassembly_cb(void *cls, uint32_t key, void *value)
3348{ 3268{
3349 struct ReassemblyContext *rc = value; 3269 struct ReassemblyContext *rc = value;
3350 3270
3351 (void) cls; 3271 (void)cls;
3352 (void) key; 3272 (void)key;
3353 free_reassembly_context (rc); 3273 free_reassembly_context(rc);
3354 return GNUNET_OK; 3274 return GNUNET_OK;
3355} 3275}
3356 3276
@@ -3361,66 +3281,66 @@ free_reassembly_cb (void *cls, uint32_t key, void *value)
3361 * @param neighbour neighbour entry to free 3281 * @param neighbour neighbour entry to free
3362 */ 3282 */
3363static void 3283static void
3364free_neighbour (struct Neighbour *neighbour) 3284free_neighbour(struct Neighbour *neighbour)
3365{ 3285{
3366 struct DistanceVectorHop *dvh; 3286 struct DistanceVectorHop *dvh;
3367 struct VirtualLink *vl; 3287 struct VirtualLink *vl;
3368 3288
3369 GNUNET_assert (NULL == neighbour->queue_head); 3289 GNUNET_assert(NULL == neighbour->queue_head);
3370 GNUNET_assert (GNUNET_YES == 3290 GNUNET_assert(GNUNET_YES ==
3371 GNUNET_CONTAINER_multipeermap_remove (neighbours, 3291 GNUNET_CONTAINER_multipeermap_remove(neighbours,
3372 &neighbour->pid, 3292 &neighbour->pid,
3373 neighbour)); 3293 neighbour));
3374 if (NULL != neighbour->reassembly_map) 3294 if (NULL != neighbour->reassembly_map)
3375 { 3295 {
3376 GNUNET_CONTAINER_multihashmap32_iterate (neighbour->reassembly_map, 3296 GNUNET_CONTAINER_multihashmap32_iterate(neighbour->reassembly_map,
3377 &free_reassembly_cb, 3297 &free_reassembly_cb,
3378 NULL); 3298 NULL);
3379 GNUNET_CONTAINER_multihashmap32_destroy (neighbour->reassembly_map); 3299 GNUNET_CONTAINER_multihashmap32_destroy(neighbour->reassembly_map);
3380 neighbour->reassembly_map = NULL; 3300 neighbour->reassembly_map = NULL;
3381 GNUNET_CONTAINER_heap_destroy (neighbour->reassembly_heap); 3301 GNUNET_CONTAINER_heap_destroy(neighbour->reassembly_heap);
3382 neighbour->reassembly_heap = NULL; 3302 neighbour->reassembly_heap = NULL;
3383 } 3303 }
3384 while (NULL != (dvh = neighbour->dv_head)) 3304 while (NULL != (dvh = neighbour->dv_head))
3385 { 3305 {
3386 struct DistanceVector *dv = dvh->dv; 3306 struct DistanceVector *dv = dvh->dv;
3387 3307
3388 free_distance_vector_hop (dvh); 3308 free_distance_vector_hop(dvh);
3389 if (NULL == dv->dv_head) 3309 if (NULL == dv->dv_head)
3390 free_dv_route (dv); 3310 free_dv_route(dv);
3391 } 3311 }
3392 if (NULL != neighbour->reassembly_timeout_task) 3312 if (NULL != neighbour->reassembly_timeout_task)
3393 { 3313 {
3394 GNUNET_SCHEDULER_cancel (neighbour->reassembly_timeout_task); 3314 GNUNET_SCHEDULER_cancel(neighbour->reassembly_timeout_task);
3395 neighbour->reassembly_timeout_task = NULL; 3315 neighbour->reassembly_timeout_task = NULL;
3396 } 3316 }
3397 if (NULL != neighbour->get) 3317 if (NULL != neighbour->get)
3398 { 3318 {
3399 GNUNET_PEERSTORE_iterate_cancel (neighbour->get); 3319 GNUNET_PEERSTORE_iterate_cancel(neighbour->get);
3400 neighbour->get = NULL; 3320 neighbour->get = NULL;
3401 } 3321 }
3402 if (NULL != neighbour->sc) 3322 if (NULL != neighbour->sc)
3403 {
3404 GNUNET_PEERSTORE_store_cancel (neighbour->sc);
3405 neighbour->sc = NULL;
3406 }
3407 if (NULL != (vl = neighbour->vl))
3408 {
3409 GNUNET_assert (neighbour == vl->n);
3410 vl->n = NULL;
3411 if (NULL == vl->dv)
3412 { 3323 {
3413 cores_send_disconnect_info (&vl->target); 3324 GNUNET_PEERSTORE_store_cancel(neighbour->sc);
3414 free_virtual_link (vl); 3325 neighbour->sc = NULL;
3415 } 3326 }
3416 else 3327 if (NULL != (vl = neighbour->vl))
3417 { 3328 {
3418 GNUNET_SCHEDULER_cancel (vl->visibility_task); 3329 GNUNET_assert(neighbour == vl->n);
3419 vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl); 3330 vl->n = NULL;
3331 if (NULL == vl->dv)
3332 {
3333 cores_send_disconnect_info(&vl->target);
3334 free_virtual_link(vl);
3335 }
3336 else
3337 {
3338 GNUNET_SCHEDULER_cancel(vl->visibility_task);
3339 vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl);
3340 }
3341 neighbour->vl = NULL;
3420 } 3342 }
3421 neighbour->vl = NULL; 3343 GNUNET_free(neighbour);
3422 }
3423 GNUNET_free (neighbour);
3424} 3344}
3425 3345
3426 3346
@@ -3431,16 +3351,16 @@ free_neighbour (struct Neighbour *neighbour)
3431 * @param pid peer the connection is for 3351 * @param pid peer the connection is for
3432 */ 3352 */
3433static void 3353static void
3434core_send_connect_info (struct TransportClient *tc, 3354core_send_connect_info(struct TransportClient *tc,
3435 const struct GNUNET_PeerIdentity *pid) 3355 const struct GNUNET_PeerIdentity *pid)
3436{ 3356{
3437 struct GNUNET_MQ_Envelope *env; 3357 struct GNUNET_MQ_Envelope *env;
3438 struct ConnectInfoMessage *cim; 3358 struct ConnectInfoMessage *cim;
3439 3359
3440 GNUNET_assert (CT_CORE == tc->type); 3360 GNUNET_assert(CT_CORE == tc->type);
3441 env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 3361 env = GNUNET_MQ_msg(cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
3442 cim->id = *pid; 3362 cim->id = *pid;
3443 GNUNET_MQ_send (tc->mq, env); 3363 GNUNET_MQ_send(tc->mq, env);
3444} 3364}
3445 3365
3446 3366
@@ -3450,17 +3370,17 @@ core_send_connect_info (struct TransportClient *tc,
3450 * @param pid peer the queue was for 3370 * @param pid peer the queue was for
3451 */ 3371 */
3452static void 3372static void
3453cores_send_connect_info (const struct GNUNET_PeerIdentity *pid) 3373cores_send_connect_info(const struct GNUNET_PeerIdentity *pid)
3454{ 3374{
3455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3375 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3456 "Informing CORE clients about connection to %s\n", 3376 "Informing CORE clients about connection to %s\n",
3457 GNUNET_i2s (pid)); 3377 GNUNET_i2s(pid));
3458 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 3378 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3459 { 3379 {
3460 if (CT_CORE != tc->type) 3380 if (CT_CORE != tc->type)
3461 continue; 3381 continue;
3462 core_send_connect_info (tc, pid); 3382 core_send_connect_info(tc, pid);
3463 } 3383 }
3464} 3384}
3465 3385
3466 3386
@@ -3472,7 +3392,7 @@ cores_send_connect_info (const struct GNUNET_PeerIdentity *pid)
3472 * @param cls the `struct Queue` to process transmissions for 3392 * @param cls the `struct Queue` to process transmissions for
3473 */ 3393 */
3474static void 3394static void
3475transmit_on_queue (void *cls); 3395transmit_on_queue(void *cls);
3476 3396
3477 3397
3478/** 3398/**
@@ -3483,38 +3403,38 @@ transmit_on_queue (void *cls);
3483 * @param p task priority to use, if @a queue is scheduled 3403 * @param p task priority to use, if @a queue is scheduled
3484 */ 3404 */
3485static void 3405static void
3486schedule_transmit_on_queue (struct Queue *queue, 3406schedule_transmit_on_queue(struct Queue *queue,
3487 enum GNUNET_SCHEDULER_Priority p) 3407 enum GNUNET_SCHEDULER_Priority p)
3488{ 3408{
3489 if (queue->tc->details.communicator.total_queue_length >= 3409 if (queue->tc->details.communicator.total_queue_length >=
3490 COMMUNICATOR_TOTAL_QUEUE_LIMIT) 3410 COMMUNICATOR_TOTAL_QUEUE_LIMIT)
3491 { 3411 {
3492 GNUNET_STATISTICS_update ( 3412 GNUNET_STATISTICS_update(
3493 GST_stats, 3413 GST_stats,
3494 "# Transmission throttled due to communicator queue limit", 3414 "# Transmission throttled due to communicator queue limit",
3495 1, 3415 1,
3496 GNUNET_NO); 3416 GNUNET_NO);
3497 queue->idle = GNUNET_NO; 3417 queue->idle = GNUNET_NO;
3498 return; 3418 return;
3499 } 3419 }
3500 if (queue->queue_length >= QUEUE_LENGTH_LIMIT) 3420 if (queue->queue_length >= QUEUE_LENGTH_LIMIT)
3501 { 3421 {
3502 GNUNET_STATISTICS_update (GST_stats, 3422 GNUNET_STATISTICS_update(GST_stats,
3503 "# Transmission throttled due to queue queue limit", 3423 "# Transmission throttled due to queue queue limit",
3504 1, 3424 1,
3505 GNUNET_NO); 3425 GNUNET_NO);
3506 queue->idle = GNUNET_NO; 3426 queue->idle = GNUNET_NO;
3507 return; 3427 return;
3508 } 3428 }
3509 /* queue might indeed be ready, schedule it */ 3429 /* queue might indeed be ready, schedule it */
3510 if (NULL != queue->transmit_task) 3430 if (NULL != queue->transmit_task)
3511 GNUNET_SCHEDULER_cancel (queue->transmit_task); 3431 GNUNET_SCHEDULER_cancel(queue->transmit_task);
3512 queue->transmit_task = 3432 queue->transmit_task =
3513 GNUNET_SCHEDULER_add_with_priority (p, &transmit_on_queue, queue); 3433 GNUNET_SCHEDULER_add_with_priority(p, &transmit_on_queue, queue);
3514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3434 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3515 "Considering transmission on queue `%s' to %s\n", 3435 "Considering transmission on queue `%s' to %s\n",
3516 queue->address, 3436 queue->address,
3517 GNUNET_i2s (&queue->neighbour->pid)); 3437 GNUNET_i2s(&queue->neighbour->pid));
3518} 3438}
3519 3439
3520 3440
@@ -3525,7 +3445,7 @@ schedule_transmit_on_queue (struct Queue *queue,
3525 * @param cls a `struct VirtualLink` 3445 * @param cls a `struct VirtualLink`
3526 */ 3446 */
3527static void 3447static void
3528check_link_down (void *cls) 3448check_link_down(void *cls)
3529{ 3449{
3530 struct VirtualLink *vl = cls; 3450 struct VirtualLink *vl = cls;
3531 struct DistanceVector *dv = vl->dv; 3451 struct DistanceVector *dv = vl->dv;
@@ -3537,30 +3457,30 @@ check_link_down (void *cls)
3537 dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS; 3457 dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS;
3538 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3458 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3539 pos = pos->next_dv) 3459 pos = pos->next_dv)
3540 dvh_timeout = GNUNET_TIME_absolute_max (dvh_timeout, pos->path_valid_until); 3460 dvh_timeout = GNUNET_TIME_absolute_max(dvh_timeout, pos->path_valid_until);
3541 if (0 == GNUNET_TIME_absolute_get_remaining (dvh_timeout).rel_value_us) 3461 if (0 == GNUNET_TIME_absolute_get_remaining(dvh_timeout).rel_value_us)
3542 { 3462 {
3543 vl->dv->vl = NULL; 3463 vl->dv->vl = NULL;
3544 vl->dv = NULL; 3464 vl->dv = NULL;
3545 } 3465 }
3546 q_timeout = GNUNET_TIME_UNIT_ZERO_ABS; 3466 q_timeout = GNUNET_TIME_UNIT_ZERO_ABS;
3547 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) 3467 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
3548 q_timeout = GNUNET_TIME_absolute_max (q_timeout, q->validated_until); 3468 q_timeout = GNUNET_TIME_absolute_max(q_timeout, q->validated_until);
3549 if (0 == GNUNET_TIME_absolute_get_remaining (q_timeout).rel_value_us) 3469 if (0 == GNUNET_TIME_absolute_get_remaining(q_timeout).rel_value_us)
3550 { 3470 {
3551 vl->n->vl = NULL; 3471 vl->n->vl = NULL;
3552 vl->n = NULL; 3472 vl->n = NULL;
3553 } 3473 }
3554 if ((NULL == vl->n) && (NULL == vl->dv)) 3474 if ((NULL == vl->n) && (NULL == vl->dv))
3555 { 3475 {
3556 cores_send_disconnect_info (&vl->target); 3476 cores_send_disconnect_info(&vl->target);
3557 free_virtual_link (vl); 3477 free_virtual_link(vl);
3558 return; 3478 return;
3559 } 3479 }
3560 vl->visibility_task = 3480 vl->visibility_task =
3561 GNUNET_SCHEDULER_add_at (GNUNET_TIME_absolute_max (q_timeout, dvh_timeout), 3481 GNUNET_SCHEDULER_add_at(GNUNET_TIME_absolute_max(q_timeout, dvh_timeout),
3562 &check_link_down, 3482 &check_link_down,
3563 vl); 3483 vl);
3564} 3484}
3565 3485
3566 3486
@@ -3570,77 +3490,77 @@ check_link_down (void *cls)
3570 * @param queue the queue to free 3490 * @param queue the queue to free
3571 */ 3491 */
3572static void 3492static void
3573free_queue (struct Queue *queue) 3493free_queue(struct Queue *queue)
3574{ 3494{
3575 struct Neighbour *neighbour = queue->neighbour; 3495 struct Neighbour *neighbour = queue->neighbour;
3576 struct TransportClient *tc = queue->tc; 3496 struct TransportClient *tc = queue->tc;
3577 struct MonitorEvent me = {.cs = GNUNET_TRANSPORT_CS_DOWN, 3497 struct MonitorEvent me = { .cs = GNUNET_TRANSPORT_CS_DOWN,
3578 .rtt = GNUNET_TIME_UNIT_FOREVER_REL}; 3498 .rtt = GNUNET_TIME_UNIT_FOREVER_REL };
3579 struct QueueEntry *qe; 3499 struct QueueEntry *qe;
3580 int maxxed; 3500 int maxxed;
3581 struct PendingAcknowledgement *pa; 3501 struct PendingAcknowledgement *pa;
3582 struct VirtualLink *vl; 3502 struct VirtualLink *vl;
3583 3503
3584 if (NULL != queue->transmit_task) 3504 if (NULL != queue->transmit_task)
3585 { 3505 {
3586 GNUNET_SCHEDULER_cancel (queue->transmit_task); 3506 GNUNET_SCHEDULER_cancel(queue->transmit_task);
3587 queue->transmit_task = NULL; 3507 queue->transmit_task = NULL;
3588 } 3508 }
3589 while (NULL != (pa = queue->pa_head)) 3509 while (NULL != (pa = queue->pa_head))
3590 { 3510 {
3591 GNUNET_CONTAINER_MDLL_remove (queue, queue->pa_head, queue->pa_tail, pa); 3511 GNUNET_CONTAINER_MDLL_remove(queue, queue->pa_head, queue->pa_tail, pa);
3592 pa->queue = NULL; 3512 pa->queue = NULL;
3593 } 3513 }
3594 3514
3595 GNUNET_CONTAINER_MDLL_remove (neighbour, 3515 GNUNET_CONTAINER_MDLL_remove(neighbour,
3596 neighbour->queue_head, 3516 neighbour->queue_head,
3597 neighbour->queue_tail, 3517 neighbour->queue_tail,
3598 queue); 3518 queue);
3599 GNUNET_CONTAINER_MDLL_remove (client, 3519 GNUNET_CONTAINER_MDLL_remove(client,
3600 tc->details.communicator.queue_head, 3520 tc->details.communicator.queue_head,
3601 tc->details.communicator.queue_tail, 3521 tc->details.communicator.queue_tail,
3602 queue); 3522 queue);
3603 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >= 3523 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >=
3604 tc->details.communicator.total_queue_length); 3524 tc->details.communicator.total_queue_length);
3605 while (NULL != (qe = queue->queue_head)) 3525 while (NULL != (qe = queue->queue_head))
3606 {
3607 GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe);
3608 queue->queue_length--;
3609 tc->details.communicator.total_queue_length--;
3610 if (NULL != qe->pm)
3611 { 3526 {
3612 GNUNET_assert (qe == qe->pm->qe); 3527 GNUNET_CONTAINER_DLL_remove(queue->queue_head, queue->queue_tail, qe);
3613 qe->pm->qe = NULL; 3528 queue->queue_length--;
3529 tc->details.communicator.total_queue_length--;
3530 if (NULL != qe->pm)
3531 {
3532 GNUNET_assert(qe == qe->pm->qe);
3533 qe->pm->qe = NULL;
3534 }
3535 GNUNET_free(qe);
3614 } 3536 }
3615 GNUNET_free (qe); 3537 GNUNET_assert(0 == queue->queue_length);
3616 }
3617 GNUNET_assert (0 == queue->queue_length);
3618 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT < 3538 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT <
3619 tc->details.communicator.total_queue_length)) 3539 tc->details.communicator.total_queue_length))
3620 { 3540 {
3621 /* Communicator dropped below threshold, resume all _other_ queues */ 3541 /* Communicator dropped below threshold, resume all _other_ queues */
3622 GNUNET_STATISTICS_update ( 3542 GNUNET_STATISTICS_update(
3623 GST_stats, 3543 GST_stats,
3624 "# Transmission throttled due to communicator queue limit", 3544 "# Transmission throttled due to communicator queue limit",
3625 -1, 3545 -1,
3626 GNUNET_NO); 3546 GNUNET_NO);
3627 for (struct Queue *s = tc->details.communicator.queue_head; NULL != s; 3547 for (struct Queue *s = tc->details.communicator.queue_head; NULL != s;
3628 s = s->next_client) 3548 s = s->next_client)
3629 schedule_transmit_on_queue (s, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 3549 schedule_transmit_on_queue(s, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
3630 } 3550 }
3631 notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); 3551 notify_monitors(&neighbour->pid, queue->address, queue->nt, &me);
3632 GNUNET_free (queue); 3552 GNUNET_free(queue);
3633 3553
3634 vl = lookup_virtual_link (&neighbour->pid); 3554 vl = lookup_virtual_link(&neighbour->pid);
3635 if ((NULL != vl) && (neighbour == vl->n)) 3555 if ((NULL != vl) && (neighbour == vl->n))
3636 { 3556 {
3637 GNUNET_SCHEDULER_cancel (vl->visibility_task); 3557 GNUNET_SCHEDULER_cancel(vl->visibility_task);
3638 check_link_down (vl); 3558 check_link_down(vl);
3639 } 3559 }
3640 if (NULL == neighbour->queue_head) 3560 if (NULL == neighbour->queue_head)
3641 { 3561 {
3642 free_neighbour (neighbour); 3562 free_neighbour(neighbour);
3643 } 3563 }
3644} 3564}
3645 3565
3646 3566
@@ -3650,24 +3570,24 @@ free_queue (struct Queue *queue)
3650 * @param ale address list entry to free 3570 * @param ale address list entry to free
3651 */ 3571 */
3652static void 3572static void
3653free_address_list_entry (struct AddressListEntry *ale) 3573free_address_list_entry(struct AddressListEntry *ale)
3654{ 3574{
3655 struct TransportClient *tc = ale->tc; 3575 struct TransportClient *tc = ale->tc;
3656 3576
3657 GNUNET_CONTAINER_DLL_remove (tc->details.communicator.addr_head, 3577 GNUNET_CONTAINER_DLL_remove(tc->details.communicator.addr_head,
3658 tc->details.communicator.addr_tail, 3578 tc->details.communicator.addr_tail,
3659 ale); 3579 ale);
3660 if (NULL != ale->sc) 3580 if (NULL != ale->sc)
3661 { 3581 {
3662 GNUNET_PEERSTORE_store_cancel (ale->sc); 3582 GNUNET_PEERSTORE_store_cancel(ale->sc);
3663 ale->sc = NULL; 3583 ale->sc = NULL;
3664 } 3584 }
3665 if (NULL != ale->st) 3585 if (NULL != ale->st)
3666 { 3586 {
3667 GNUNET_SCHEDULER_cancel (ale->st); 3587 GNUNET_SCHEDULER_cancel(ale->st);
3668 ale->st = NULL; 3588 ale->st = NULL;
3669 } 3589 }
3670 GNUNET_free (ale); 3590 GNUNET_free(ale);
3671} 3591}
3672 3592
3673 3593
@@ -3680,20 +3600,20 @@ free_address_list_entry (struct AddressListEntry *ale)
3680 * @return #GNUNET_YES (always) 3600 * @return #GNUNET_YES (always)
3681 */ 3601 */
3682static int 3602static int
3683stop_peer_request (void *cls, 3603stop_peer_request(void *cls,
3684 const struct GNUNET_PeerIdentity *pid, 3604 const struct GNUNET_PeerIdentity *pid,
3685 void *value) 3605 void *value)
3686{ 3606{
3687 struct TransportClient *tc = cls; 3607 struct TransportClient *tc = cls;
3688 struct PeerRequest *pr = value; 3608 struct PeerRequest *pr = value;
3689 3609
3690 GNUNET_PEERSTORE_watch_cancel (pr->wc); 3610 GNUNET_PEERSTORE_watch_cancel(pr->wc);
3691 GNUNET_assert ( 3611 GNUNET_assert(
3692 GNUNET_YES == 3612 GNUNET_YES ==
3693 GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, 3613 GNUNET_CONTAINER_multipeermap_remove(tc->details.application.requests,
3694 pid, 3614 pid,
3695 pr)); 3615 pr));
3696 GNUNET_free (pr); 3616 GNUNET_free(pr);
3697 3617
3698 return GNUNET_OK; 3618 return GNUNET_OK;
3699} 3619}
@@ -3708,56 +3628,60 @@ stop_peer_request (void *cls,
3708 * @param app_ctx our `struct TransportClient` 3628 * @param app_ctx our `struct TransportClient`
3709 */ 3629 */
3710static void 3630static void
3711client_disconnect_cb (void *cls, 3631client_disconnect_cb(void *cls,
3712 struct GNUNET_SERVICE_Client *client, 3632 struct GNUNET_SERVICE_Client *client,
3713 void *app_ctx) 3633 void *app_ctx)
3714{ 3634{
3715 struct TransportClient *tc = app_ctx; 3635 struct TransportClient *tc = app_ctx;
3716 3636
3717 (void) cls; 3637 (void)cls;
3718 (void) client; 3638 (void)client;
3719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3639 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3720 "Client %p disconnected, cleaning up.\n", 3640 "Client %p disconnected, cleaning up.\n",
3721 tc); 3641 tc);
3722 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); 3642 GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc);
3723 switch (tc->type) 3643 switch (tc->type)
3724 {
3725 case CT_NONE:
3726 break;
3727 case CT_CORE: {
3728 struct PendingMessage *pm;
3729
3730 while (NULL != (pm = tc->details.core.pending_msg_head))
3731 { 3644 {
3732 GNUNET_CONTAINER_MDLL_remove (client, 3645 case CT_NONE:
3733 tc->details.core.pending_msg_head, 3646 break;
3734 tc->details.core.pending_msg_tail, 3647
3735 pm); 3648 case CT_CORE: {
3736 pm->client = NULL; 3649 struct PendingMessage *pm;
3650
3651 while (NULL != (pm = tc->details.core.pending_msg_head))
3652 {
3653 GNUNET_CONTAINER_MDLL_remove(client,
3654 tc->details.core.pending_msg_head,
3655 tc->details.core.pending_msg_tail,
3656 pm);
3657 pm->client = NULL;
3658 }
3737 } 3659 }
3738 }
3739 break;
3740 case CT_MONITOR:
3741 break; 3660 break;
3742 case CT_COMMUNICATOR: { 3661
3743 struct Queue *q; 3662 case CT_MONITOR:
3744 struct AddressListEntry *ale; 3663 break;
3745 3664
3746 while (NULL != (q = tc->details.communicator.queue_head)) 3665 case CT_COMMUNICATOR: {
3747 free_queue (q); 3666 struct Queue *q;
3748 while (NULL != (ale = tc->details.communicator.addr_head)) 3667 struct AddressListEntry *ale;
3749 free_address_list_entry (ale); 3668
3750 GNUNET_free (tc->details.communicator.address_prefix); 3669 while (NULL != (q = tc->details.communicator.queue_head))
3751 } 3670 free_queue(q);
3752 break; 3671 while (NULL != (ale = tc->details.communicator.addr_head))
3753 case CT_APPLICATION: 3672 free_address_list_entry(ale);
3754 GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests, 3673 GNUNET_free(tc->details.communicator.address_prefix);
3755 &stop_peer_request, 3674 }
3756 tc);
3757 GNUNET_CONTAINER_multipeermap_destroy (tc->details.application.requests);
3758 break; 3675 break;
3759 } 3676
3760 GNUNET_free (tc); 3677 case CT_APPLICATION:
3678 GNUNET_CONTAINER_multipeermap_iterate(tc->details.application.requests,
3679 &stop_peer_request,
3680 tc);
3681 GNUNET_CONTAINER_multipeermap_destroy(tc->details.application.requests);
3682 break;
3683 }
3684 GNUNET_free(tc);
3761} 3685}
3762 3686
3763 3687
@@ -3771,17 +3695,17 @@ client_disconnect_cb (void *cls,
3771 * @return #GNUNET_OK (continue to iterate) 3695 * @return #GNUNET_OK (continue to iterate)
3772 */ 3696 */
3773static int 3697static int
3774notify_client_connect_info (void *cls, 3698notify_client_connect_info(void *cls,
3775 const struct GNUNET_PeerIdentity *pid, 3699 const struct GNUNET_PeerIdentity *pid,
3776 void *value) 3700 void *value)
3777{ 3701{
3778 struct TransportClient *tc = cls; 3702 struct TransportClient *tc = cls;
3779 3703
3780 (void) value; 3704 (void)value;
3781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3705 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3782 "Telling new CORE client about existing connection to %s\n", 3706 "Telling new CORE client about existing connection to %s\n",
3783 GNUNET_i2s (pid)); 3707 GNUNET_i2s(pid));
3784 core_send_connect_info (tc, pid); 3708 core_send_connect_info(tc, pid);
3785 return GNUNET_OK; 3709 return GNUNET_OK;
3786} 3710}
3787 3711
@@ -3795,34 +3719,34 @@ notify_client_connect_info (void *cls,
3795 * @param start the start message that was sent 3719 * @param start the start message that was sent
3796 */ 3720 */
3797static void 3721static void
3798handle_client_start (void *cls, const struct StartMessage *start) 3722handle_client_start(void *cls, const struct StartMessage *start)
3799{ 3723{
3800 struct TransportClient *tc = cls; 3724 struct TransportClient *tc = cls;
3801 uint32_t options; 3725 uint32_t options;
3802 3726
3803 options = ntohl (start->options); 3727 options = ntohl(start->options);
3804 if ((0 != (1 & options)) && 3728 if ((0 != (1 & options)) &&
3805 (0 != GNUNET_memcmp (&start->self, &GST_my_identity))) 3729 (0 != GNUNET_memcmp(&start->self, &GST_my_identity)))
3806 { 3730 {
3807 /* client thinks this is a different peer, reject */ 3731 /* client thinks this is a different peer, reject */
3808 GNUNET_break (0); 3732 GNUNET_break(0);
3809 GNUNET_SERVICE_client_drop (tc->client); 3733 GNUNET_SERVICE_client_drop(tc->client);
3810 return; 3734 return;
3811 } 3735 }
3812 if (CT_NONE != tc->type) 3736 if (CT_NONE != tc->type)
3813 { 3737 {
3814 GNUNET_break (0); 3738 GNUNET_break(0);
3815 GNUNET_SERVICE_client_drop (tc->client); 3739 GNUNET_SERVICE_client_drop(tc->client);
3816 return; 3740 return;
3817 } 3741 }
3818 tc->type = CT_CORE; 3742 tc->type = CT_CORE;
3819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3743 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3820 "New CORE client with PID %s registered\n", 3744 "New CORE client with PID %s registered\n",
3821 GNUNET_i2s (&start->self)); 3745 GNUNET_i2s(&start->self));
3822 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 3746 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
3823 &notify_client_connect_info, 3747 &notify_client_connect_info,
3824 tc); 3748 tc);
3825 GNUNET_SERVICE_client_continue (tc->client); 3749 GNUNET_SERVICE_client_continue(tc->client);
3826} 3750}
3827 3751
3828 3752
@@ -3833,29 +3757,29 @@ handle_client_start (void *cls, const struct StartMessage *start)
3833 * @param obm the send message that was sent 3757 * @param obm the send message that was sent
3834 */ 3758 */
3835static int 3759static int
3836check_client_send (void *cls, const struct OutboundMessage *obm) 3760check_client_send(void *cls, const struct OutboundMessage *obm)
3837{ 3761{
3838 struct TransportClient *tc = cls; 3762 struct TransportClient *tc = cls;
3839 uint16_t size; 3763 uint16_t size;
3840 const struct GNUNET_MessageHeader *obmm; 3764 const struct GNUNET_MessageHeader *obmm;
3841 3765
3842 if (CT_CORE != tc->type) 3766 if (CT_CORE != tc->type)
3843 { 3767 {
3844 GNUNET_break (0); 3768 GNUNET_break(0);
3845 return GNUNET_SYSERR; 3769 return GNUNET_SYSERR;
3846 } 3770 }
3847 size = ntohs (obm->header.size) - sizeof (struct OutboundMessage); 3771 size = ntohs(obm->header.size) - sizeof(struct OutboundMessage);
3848 if (size < sizeof (struct GNUNET_MessageHeader)) 3772 if (size < sizeof(struct GNUNET_MessageHeader))
3849 { 3773 {
3850 GNUNET_break (0); 3774 GNUNET_break(0);
3851 return GNUNET_SYSERR; 3775 return GNUNET_SYSERR;
3852 } 3776 }
3853 obmm = (const struct GNUNET_MessageHeader *) &obm[1]; 3777 obmm = (const struct GNUNET_MessageHeader *)&obm[1];
3854 if (size != ntohs (obmm->size)) 3778 if (size != ntohs(obmm->size))
3855 { 3779 {
3856 GNUNET_break (0); 3780 GNUNET_break(0);
3857 return GNUNET_SYSERR; 3781 return GNUNET_SYSERR;
3858 } 3782 }
3859 return GNUNET_OK; 3783 return GNUNET_OK;
3860} 3784}
3861 3785
@@ -3868,25 +3792,25 @@ check_client_send (void *cls, const struct OutboundMessage *obm)
3868 * @param pm handle to the original pending message 3792 * @param pm handle to the original pending message
3869 */ 3793 */
3870static void 3794static void
3871client_send_response (struct PendingMessage *pm) 3795client_send_response(struct PendingMessage *pm)
3872{ 3796{
3873 struct TransportClient *tc = pm->client; 3797 struct TransportClient *tc = pm->client;
3874 struct VirtualLink *vl = pm->vl; 3798 struct VirtualLink *vl = pm->vl;
3875 3799
3876 if (NULL != tc) 3800 if (NULL != tc)
3877 { 3801 {
3878 struct GNUNET_MQ_Envelope *env; 3802 struct GNUNET_MQ_Envelope *env;
3879 struct SendOkMessage *som; 3803 struct SendOkMessage *som;
3880 3804
3881 env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); 3805 env = GNUNET_MQ_msg(som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
3882 som->peer = vl->target; 3806 som->peer = vl->target;
3883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3807 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3884 "Confirming transmission of <%llu> to %s\n", 3808 "Confirming transmission of <%llu> to %s\n",
3885 pm->logging_uuid, 3809 pm->logging_uuid,
3886 GNUNET_i2s (&vl->target)); 3810 GNUNET_i2s(&vl->target));
3887 GNUNET_MQ_send (tc->mq, env); 3811 GNUNET_MQ_send(tc->mq, env);
3888 } 3812 }
3889 free_pending_message (pm); 3813 free_pending_message(pm);
3890} 3814}
3891 3815
3892 3816
@@ -3900,10 +3824,10 @@ client_send_response (struct PendingMessage *pm)
3900 * @return number of entries set in @a hops_array 3824 * @return number of entries set in @a hops_array
3901 */ 3825 */
3902static unsigned int 3826static unsigned int
3903pick_random_dv_hops (const struct DistanceVector *dv, 3827pick_random_dv_hops(const struct DistanceVector *dv,
3904 enum RouteMessageOptions options, 3828 enum RouteMessageOptions options,
3905 struct DistanceVectorHop **hops_array, 3829 struct DistanceVectorHop **hops_array,
3906 unsigned int hops_array_length) 3830 unsigned int hops_array_length)
3907{ 3831{
3908 uint64_t choices[hops_array_length]; 3832 uint64_t choices[hops_array_length];
3909 uint64_t num_dv; 3833 uint64_t num_dv;
@@ -3915,56 +3839,56 @@ pick_random_dv_hops (const struct DistanceVector *dv,
3915 dv_count = 0; 3839 dv_count = 0;
3916 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3840 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3917 pos = pos->next_dv) 3841 pos = pos->next_dv)
3918 { 3842 {
3919 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && 3843 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
3920 (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until) 3844 (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until)
3921 .rel_value_us == 0)) 3845 .rel_value_us == 0))
3922 continue; /* pos unconfirmed and confirmed required */ 3846 continue; /* pos unconfirmed and confirmed required */
3923 num_dv += MAX_DV_HOPS_ALLOWED - pos->distance; 3847 num_dv += MAX_DV_HOPS_ALLOWED - pos->distance;
3924 dv_count++; 3848 dv_count++;
3925 } 3849 }
3926 if (0 == dv_count) 3850 if (0 == dv_count)
3927 return 0; 3851 return 0;
3928 if (dv_count <= hops_array_length) 3852 if (dv_count <= hops_array_length)
3929 { 3853 {
3930 dv_count = 0; 3854 dv_count = 0;
3931 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3855 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3932 pos = pos->next_dv) 3856 pos = pos->next_dv)
3933 hops_array[dv_count++] = pos; 3857 hops_array[dv_count++] = pos;
3934 return dv_count; 3858 return dv_count;
3935 } 3859 }
3936 for (unsigned int i = 0; i < hops_array_length; i++) 3860 for (unsigned int i = 0; i < hops_array_length; i++)
3937 { 3861 {
3938 int ok = GNUNET_NO; 3862 int ok = GNUNET_NO;
3939 while (GNUNET_NO == ok) 3863 while (GNUNET_NO == ok)
3940 {
3941 choices[i] =
3942 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, num_dv);
3943 ok = GNUNET_YES;
3944 for (unsigned int j = 0; j < i; j++)
3945 if (choices[i] == choices[j])
3946 { 3864 {
3947 ok = GNUNET_NO; 3865 choices[i] =
3948 break; 3866 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, num_dv);
3867 ok = GNUNET_YES;
3868 for (unsigned int j = 0; j < i; j++)
3869 if (choices[i] == choices[j])
3870 {
3871 ok = GNUNET_NO;
3872 break;
3873 }
3949 } 3874 }
3950 } 3875 }
3951 }
3952 dv_count = 0; 3876 dv_count = 0;
3953 num_dv = 0; 3877 num_dv = 0;
3954 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3878 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3955 pos = pos->next_dv) 3879 pos = pos->next_dv)
3956 { 3880 {
3957 uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance; 3881 uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance;
3958 3882
3959 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && 3883 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
3960 (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until) 3884 (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until)
3961 .rel_value_us == 0)) 3885 .rel_value_us == 0))
3962 continue; /* pos unconfirmed and confirmed required */ 3886 continue; /* pos unconfirmed and confirmed required */
3963 for (unsigned int i = 0; i < hops_array_length; i++) 3887 for (unsigned int i = 0; i < hops_array_length; i++)
3964 if ((num_dv <= choices[i]) && (num_dv + delta > choices[i])) 3888 if ((num_dv <= choices[i]) && (num_dv + delta > choices[i]))
3965 hops_array[dv_count++] = pos; 3889 hops_array[dv_count++] = pos;
3966 num_dv += delta; 3890 num_dv += delta;
3967 } 3891 }
3968 return dv_count; 3892 return dv_count;
3969} 3893}
3970 3894
@@ -3976,7 +3900,7 @@ pick_random_dv_hops (const struct DistanceVector *dv,
3976 * @param cam the send message that was sent 3900 * @param cam the send message that was sent
3977 */ 3901 */
3978static int 3902static int
3979check_communicator_available ( 3903check_communicator_available(
3980 void *cls, 3904 void *cls,
3981 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) 3905 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
3982{ 3906{
@@ -3984,15 +3908,15 @@ check_communicator_available (
3984 uint16_t size; 3908 uint16_t size;
3985 3909
3986 if (CT_NONE != tc->type) 3910 if (CT_NONE != tc->type)
3987 { 3911 {
3988 GNUNET_break (0); 3912 GNUNET_break(0);
3989 return GNUNET_SYSERR; 3913 return GNUNET_SYSERR;
3990 } 3914 }
3991 tc->type = CT_COMMUNICATOR; 3915 tc->type = CT_COMMUNICATOR;
3992 size = ntohs (cam->header.size) - sizeof (*cam); 3916 size = ntohs(cam->header.size) - sizeof(*cam);
3993 if (0 == size) 3917 if (0 == size)
3994 return GNUNET_OK; /* receive-only communicator */ 3918 return GNUNET_OK; /* receive-only communicator */
3995 GNUNET_MQ_check_zero_termination (cam); 3919 GNUNET_MQ_check_zero_termination(cam);
3996 return GNUNET_OK; 3920 return GNUNET_OK;
3997} 3921}
3998 3922
@@ -4003,22 +3927,22 @@ check_communicator_available (
4003 * @param cmc context for which we are done handling the message 3927 * @param cmc context for which we are done handling the message
4004 */ 3928 */
4005static void 3929static void
4006finish_cmc_handling (struct CommunicatorMessageContext *cmc) 3930finish_cmc_handling(struct CommunicatorMessageContext *cmc)
4007{ 3931{
4008 if (0 != ntohl (cmc->im.fc_on)) 3932 if (0 != ntohl(cmc->im.fc_on))
4009 { 3933 {
4010 /* send ACK when done to communicator for flow control! */ 3934 /* send ACK when done to communicator for flow control! */
4011 struct GNUNET_MQ_Envelope *env; 3935 struct GNUNET_MQ_Envelope *env;
4012 struct GNUNET_TRANSPORT_IncomingMessageAck *ack; 3936 struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
4013 3937
4014 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); 3938 env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
4015 ack->reserved = htonl (0); 3939 ack->reserved = htonl(0);
4016 ack->fc_id = cmc->im.fc_id; 3940 ack->fc_id = cmc->im.fc_id;
4017 ack->sender = cmc->im.sender; 3941 ack->sender = cmc->im.sender;
4018 GNUNET_MQ_send (cmc->tc->mq, env); 3942 GNUNET_MQ_send(cmc->tc->mq, env);
4019 } 3943 }
4020 GNUNET_SERVICE_client_continue (cmc->tc->client); 3944 GNUNET_SERVICE_client_continue(cmc->tc->client);
4021 GNUNET_free (cmc); 3945 GNUNET_free(cmc);
4022} 3946}
4023 3947
4024 3948
@@ -4032,7 +3956,7 @@ finish_cmc_handling (struct CommunicatorMessageContext *cmc)
4032 * @param rom the message that was sent 3956 * @param rom the message that was sent
4033 */ 3957 */
4034static void 3958static void
4035handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom) 3959handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom)
4036{ 3960{
4037 struct TransportClient *tc = cls; 3961 struct TransportClient *tc = cls;
4038 struct VirtualLink *vl; 3962 struct VirtualLink *vl;
@@ -4040,31 +3964,31 @@ handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom)
4040 struct CommunicatorMessageContext *cmc; 3964 struct CommunicatorMessageContext *cmc;
4041 3965
4042 if (CT_CORE != tc->type) 3966 if (CT_CORE != tc->type)
4043 { 3967 {
4044 GNUNET_break (0); 3968 GNUNET_break(0);
4045 GNUNET_SERVICE_client_drop (tc->client); 3969 GNUNET_SERVICE_client_drop(tc->client);
4046 return; 3970 return;
4047 } 3971 }
4048 vl = lookup_virtual_link (&rom->peer); 3972 vl = lookup_virtual_link(&rom->peer);
4049 if (NULL == vl) 3973 if (NULL == vl)
4050 { 3974 {
4051 GNUNET_STATISTICS_update (GST_stats, 3975 GNUNET_STATISTICS_update(GST_stats,
4052 "# RECV_OK dropped: virtual link unknown", 3976 "# RECV_OK dropped: virtual link unknown",
4053 1, 3977 1,
4054 GNUNET_NO); 3978 GNUNET_NO);
4055 GNUNET_SERVICE_client_continue (tc->client); 3979 GNUNET_SERVICE_client_continue(tc->client);
4056 return; 3980 return;
4057 } 3981 }
4058 delta = ntohl (rom->increase_window_delta); 3982 delta = ntohl(rom->increase_window_delta);
4059 vl->core_recv_window += delta; 3983 vl->core_recv_window += delta;
4060 if (vl->core_recv_window <= 0) 3984 if (vl->core_recv_window <= 0)
4061 return; 3985 return;
4062 /* resume communicators */ 3986 /* resume communicators */
4063 while (NULL != (cmc = vl->cmc_tail)) 3987 while (NULL != (cmc = vl->cmc_tail))
4064 { 3988 {
4065 GNUNET_CONTAINER_DLL_remove (vl->cmc_head, vl->cmc_tail, cmc); 3989 GNUNET_CONTAINER_DLL_remove(vl->cmc_head, vl->cmc_tail, cmc);
4066 finish_cmc_handling (cmc); 3990 finish_cmc_handling(cmc);
4067 } 3991 }
4068} 3992}
4069 3993
4070 3994
@@ -4075,28 +3999,28 @@ handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom)
4075 * @param cam the send message that was sent 3999 * @param cam the send message that was sent
4076 */ 4000 */
4077static void 4001static void
4078handle_communicator_available ( 4002handle_communicator_available(
4079 void *cls, 4003 void *cls,
4080 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) 4004 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
4081{ 4005{
4082 struct TransportClient *tc = cls; 4006 struct TransportClient *tc = cls;
4083 uint16_t size; 4007 uint16_t size;
4084 4008
4085 size = ntohs (cam->header.size) - sizeof (*cam); 4009 size = ntohs(cam->header.size) - sizeof(*cam);
4086 if (0 == size) 4010 if (0 == size)
4087 { 4011 {
4088 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4012 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4089 "Receive-only communicator connected\n"); 4013 "Receive-only communicator connected\n");
4090 return; /* receive-only communicator */ 4014 return; /* receive-only communicator */
4091 } 4015 }
4092 tc->details.communicator.address_prefix = 4016 tc->details.communicator.address_prefix =
4093 GNUNET_strdup ((const char *) &cam[1]); 4017 GNUNET_strdup((const char *)&cam[1]);
4094 tc->details.communicator.cc = 4018 tc->details.communicator.cc =
4095 (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc); 4019 (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(cam->cc);
4096 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4020 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4097 "Communicator with prefix `%s' connected\n", 4021 "Communicator with prefix `%s' connected\n",
4098 tc->details.communicator.address_prefix); 4022 tc->details.communicator.address_prefix);
4099 GNUNET_SERVICE_client_continue (tc->client); 4023 GNUNET_SERVICE_client_continue(tc->client);
4100} 4024}
4101 4025
4102 4026
@@ -4108,7 +4032,7 @@ handle_communicator_available (
4108 * @return #GNUNET_OK if message is well-formed 4032 * @return #GNUNET_OK if message is well-formed
4109 */ 4033 */
4110static int 4034static int
4111check_communicator_backchannel ( 4035check_communicator_backchannel(
4112 void *cls, 4036 void *cls,
4113 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 4037 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
4114{ 4038{
@@ -4117,24 +4041,24 @@ check_communicator_backchannel (
4117 uint16_t msize; 4041 uint16_t msize;
4118 uint16_t isize; 4042 uint16_t isize;
4119 4043
4120 (void) cls; 4044 (void)cls;
4121 msize = ntohs (cb->header.size) - sizeof (*cb); 4045 msize = ntohs(cb->header.size) - sizeof(*cb);
4122 inbox = (const struct GNUNET_MessageHeader *) &cb[1]; 4046 inbox = (const struct GNUNET_MessageHeader *)&cb[1];
4123 isize = ntohs (inbox->size); 4047 isize = ntohs(inbox->size);
4124 if (isize >= msize) 4048 if (isize >= msize)
4125 { 4049 {
4126 GNUNET_break (0); 4050 GNUNET_break(0);
4127 return GNUNET_SYSERR; 4051 return GNUNET_SYSERR;
4128 } 4052 }
4129 is = (const char *) inbox; 4053 is = (const char *)inbox;
4130 is += isize; 4054 is += isize;
4131 msize -= isize; 4055 msize -= isize;
4132 GNUNET_assert (0 < msize); 4056 GNUNET_assert(0 < msize);
4133 if ('\0' != is[msize - 1]) 4057 if ('\0' != is[msize - 1])
4134 { 4058 {
4135 GNUNET_break (0); 4059 GNUNET_break(0);
4136 return GNUNET_SYSERR; 4060 return GNUNET_SYSERR;
4137 } 4061 }
4138 return GNUNET_OK; 4062 return GNUNET_OK;
4139} 4063}
4140 4064
@@ -4146,26 +4070,26 @@ check_communicator_backchannel (
4146 * @param dv[in,out] virtual link to update ephemeral for 4070 * @param dv[in,out] virtual link to update ephemeral for
4147 */ 4071 */
4148static void 4072static void
4149update_ephemeral (struct DistanceVector *dv) 4073update_ephemeral(struct DistanceVector *dv)
4150{ 4074{
4151 struct EphemeralConfirmationPS ec; 4075 struct EphemeralConfirmationPS ec;
4152 4076
4153 if (0 != 4077 if (0 !=
4154 GNUNET_TIME_absolute_get_remaining (dv->ephemeral_validity).rel_value_us) 4078 GNUNET_TIME_absolute_get_remaining(dv->ephemeral_validity).rel_value_us)
4155 return; 4079 return;
4156 dv->monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); 4080 dv->monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg);
4157 dv->ephemeral_validity = 4081 dv->ephemeral_validity =
4158 GNUNET_TIME_absolute_add (dv->monotime, EPHEMERAL_VALIDITY); 4082 GNUNET_TIME_absolute_add(dv->monotime, EPHEMERAL_VALIDITY);
4159 GNUNET_assert (GNUNET_OK == 4083 GNUNET_assert(GNUNET_OK ==
4160 GNUNET_CRYPTO_ecdhe_key_create2 (&dv->private_key)); 4084 GNUNET_CRYPTO_ecdhe_key_create2(&dv->private_key));
4161 GNUNET_CRYPTO_ecdhe_key_get_public (&dv->private_key, &dv->ephemeral_key); 4085 GNUNET_CRYPTO_ecdhe_key_get_public(&dv->private_key, &dv->ephemeral_key);
4162 ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); 4086 ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
4163 ec.purpose.size = htonl (sizeof (ec)); 4087 ec.purpose.size = htonl(sizeof(ec));
4164 ec.target = dv->target; 4088 ec.target = dv->target;
4165 ec.ephemeral_key = dv->ephemeral_key; 4089 ec.ephemeral_key = dv->ephemeral_key;
4166 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 4090 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key,
4167 &ec.purpose, 4091 &ec.purpose,
4168 &dv->sender_sig)); 4092 &dv->sender_sig));
4169} 4093}
4170 4094
4171 4095
@@ -4179,45 +4103,45 @@ update_ephemeral (struct DistanceVector *dv)
4179 * @param payload_size number of bytes in @a payload 4103 * @param payload_size number of bytes in @a payload
4180 */ 4104 */
4181static void 4105static void
4182queue_send_msg (struct Queue *queue, 4106queue_send_msg(struct Queue *queue,
4183 struct PendingMessage *pm, 4107 struct PendingMessage *pm,
4184 const void *payload, 4108 const void *payload,
4185 size_t payload_size) 4109 size_t payload_size)
4186{ 4110{
4187 struct Neighbour *n = queue->neighbour; 4111 struct Neighbour *n = queue->neighbour;
4188 struct GNUNET_TRANSPORT_SendMessageTo *smt; 4112 struct GNUNET_TRANSPORT_SendMessageTo *smt;
4189 struct GNUNET_MQ_Envelope *env; 4113 struct GNUNET_MQ_Envelope *env;
4190 4114
4191 queue->idle = GNUNET_NO; 4115 queue->idle = GNUNET_NO;
4192 GNUNET_log ( 4116 GNUNET_log(
4193 GNUNET_ERROR_TYPE_DEBUG, 4117 GNUNET_ERROR_TYPE_DEBUG,
4194 "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n", 4118 "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n",
4195 (unsigned int) payload_size, 4119 (unsigned int)payload_size,
4196 (NULL == pm) ? 0 : pm->logging_uuid, 4120 (NULL == pm) ? 0 : pm->logging_uuid,
4197 (unsigned long long) queue->qid, 4121 (unsigned long long)queue->qid,
4198 GNUNET_i2s (&queue->neighbour->pid)); 4122 GNUNET_i2s(&queue->neighbour->pid));
4199 env = GNUNET_MQ_msg_extra (smt, 4123 env = GNUNET_MQ_msg_extra(smt,
4200 payload_size, 4124 payload_size,
4201 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); 4125 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG);
4202 smt->qid = queue->qid; 4126 smt->qid = queue->qid;
4203 smt->mid = queue->mid_gen; 4127 smt->mid = queue->mid_gen;
4204 smt->receiver = n->pid; 4128 smt->receiver = n->pid;
4205 memcpy (&smt[1], payload, payload_size); 4129 memcpy(&smt[1], payload, payload_size);
4206 { 4130 {
4207 /* Pass the env to the communicator of queue for transmission. */ 4131 /* Pass the env to the communicator of queue for transmission. */
4208 struct QueueEntry *qe; 4132 struct QueueEntry *qe;
4209 4133
4210 qe = GNUNET_new (struct QueueEntry); 4134 qe = GNUNET_new(struct QueueEntry);
4211 qe->mid = queue->mid_gen++; 4135 qe->mid = queue->mid_gen++;
4212 qe->queue = queue; 4136 qe->queue = queue;
4213 if (NULL != pm) 4137 if (NULL != pm)
4214 { 4138 {
4215 qe->pm = pm; 4139 qe->pm = pm;
4216 GNUNET_assert (NULL == pm->qe); 4140 GNUNET_assert(NULL == pm->qe);
4217 pm->qe = qe; 4141 pm->qe = qe;
4218 } 4142 }
4219 GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe); 4143 GNUNET_CONTAINER_DLL_insert(queue->queue_head, queue->queue_tail, qe);
4220 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); 4144 GNUNET_assert(CT_COMMUNICATOR == queue->tc->type);
4221 queue->queue_length++; 4145 queue->queue_length++;
4222 queue->tc->details.communicator.total_queue_length++; 4146 queue->tc->details.communicator.total_queue_length++;
4223 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT == 4147 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT ==
@@ -4225,7 +4149,7 @@ queue_send_msg (struct Queue *queue,
4225 queue->idle = GNUNET_NO; 4149 queue->idle = GNUNET_NO;
4226 if (QUEUE_LENGTH_LIMIT == queue->queue_length) 4150 if (QUEUE_LENGTH_LIMIT == queue->queue_length)
4227 queue->idle = GNUNET_NO; 4151 queue->idle = GNUNET_NO;
4228 GNUNET_MQ_send (queue->tc->mq, env); 4152 GNUNET_MQ_send(queue->tc->mq, env);
4229 } 4153 }
4230} 4154}
4231 4155
@@ -4241,9 +4165,9 @@ queue_send_msg (struct Queue *queue,
4241 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed 4165 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
4242 */ 4166 */
4243static struct GNUNET_TIME_Relative 4167static struct GNUNET_TIME_Relative
4244route_via_neighbour (const struct Neighbour *n, 4168route_via_neighbour(const struct Neighbour *n,
4245 const struct GNUNET_MessageHeader *hdr, 4169 const struct GNUNET_MessageHeader *hdr,
4246 enum RouteMessageOptions options) 4170 enum RouteMessageOptions options)
4247{ 4171{
4248 struct GNUNET_TIME_Absolute now; 4172 struct GNUNET_TIME_Absolute now;
4249 unsigned int candidates; 4173 unsigned int candidates;
@@ -4252,7 +4176,7 @@ route_via_neighbour (const struct Neighbour *n,
4252 struct GNUNET_TIME_Relative rtt; 4176 struct GNUNET_TIME_Relative rtt;
4253 4177
4254 /* Pick one or two 'random' queues from n (under constraints of options) */ 4178 /* Pick one or two 'random' queues from n (under constraints of options) */
4255 now = GNUNET_TIME_absolute_get (); 4179 now = GNUNET_TIME_absolute_get();
4256 /* FIXME-OPTIMIZE: give queues 'weights' and pick proportional to 4180 /* FIXME-OPTIMIZE: give queues 'weights' and pick proportional to
4257 weight in the future; weight could be assigned by observed 4181 weight in the future; weight could be assigned by observed
4258 bandwidth (note: not sure if we should do this for this type 4182 bandwidth (note: not sure if we should do this for this type
@@ -4260,53 +4184,53 @@ route_via_neighbour (const struct Neighbour *n,
4260 candidates = 0; 4184 candidates = 0;
4261 for (struct Queue *pos = n->queue_head; NULL != pos; 4185 for (struct Queue *pos = n->queue_head; NULL != pos;
4262 pos = pos->next_neighbour) 4186 pos = pos->next_neighbour)
4263 { 4187 {
4264 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || 4188 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
4265 (pos->validated_until.abs_value_us > now.abs_value_us)) 4189 (pos->validated_until.abs_value_us > now.abs_value_us))
4266 candidates++; 4190 candidates++;
4267 } 4191 }
4268 if (0 == candidates) 4192 if (0 == candidates)
4269 { 4193 {
4270 /* This can happen rarely if the last confirmed queue timed 4194 /* This can happen rarely if the last confirmed queue timed
4271 out just as we were beginning to process this message. */ 4195 out just as we were beginning to process this message. */
4272 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4196 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
4273 "Could not route message of type %u to %s: no valid queue\n", 4197 "Could not route message of type %u to %s: no valid queue\n",
4274 ntohs (hdr->type), 4198 ntohs(hdr->type),
4275 GNUNET_i2s (&n->pid)); 4199 GNUNET_i2s(&n->pid));
4276 GNUNET_STATISTICS_update (GST_stats, 4200 GNUNET_STATISTICS_update(GST_stats,
4277 "# route selection failed (all no valid queue)", 4201 "# route selection failed (all no valid queue)",
4278 1, 4202 1,
4279 GNUNET_NO); 4203 GNUNET_NO);
4280 return GNUNET_TIME_UNIT_FOREVER_REL; 4204 return GNUNET_TIME_UNIT_FOREVER_REL;
4281 } 4205 }
4282 4206
4283 rtt = GNUNET_TIME_UNIT_FOREVER_REL; 4207 rtt = GNUNET_TIME_UNIT_FOREVER_REL;
4284 sel1 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates); 4208 sel1 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates);
4285 if (0 == (options & RMO_REDUNDANT)) 4209 if (0 == (options & RMO_REDUNDANT))
4286 sel2 = candidates; /* picks none! */ 4210 sel2 = candidates; /* picks none! */
4287 else 4211 else
4288 sel2 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates); 4212 sel2 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates);
4289 candidates = 0; 4213 candidates = 0;
4290 for (struct Queue *pos = n->queue_head; NULL != pos; 4214 for (struct Queue *pos = n->queue_head; NULL != pos;
4291 pos = pos->next_neighbour) 4215 pos = pos->next_neighbour)
4292 {
4293 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
4294 (pos->validated_until.abs_value_us > now.abs_value_us))
4295 { 4216 {
4296 if ((sel1 == candidates) || (sel2 == candidates)) 4217 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
4297 { 4218 (pos->validated_until.abs_value_us > now.abs_value_us))
4298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4219 {
4299 "Routing message of type %u to %s using %s (#%u)\n", 4220 if ((sel1 == candidates) || (sel2 == candidates))
4300 ntohs (hdr->type), 4221 {
4301 GNUNET_i2s (&n->pid), 4222 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4302 pos->address, 4223 "Routing message of type %u to %s using %s (#%u)\n",
4303 (sel1 == candidates) ? 1 : 2); 4224 ntohs(hdr->type),
4304 rtt = GNUNET_TIME_relative_min (rtt, pos->pd.aged_rtt); 4225 GNUNET_i2s(&n->pid),
4305 queue_send_msg (pos, NULL, hdr, ntohs (hdr->size)); 4226 pos->address,
4306 } 4227 (sel1 == candidates) ? 1 : 2);
4307 candidates++; 4228 rtt = GNUNET_TIME_relative_min(rtt, pos->pd.aged_rtt);
4229 queue_send_msg(pos, NULL, hdr, ntohs(hdr->size));
4230 }
4231 candidates++;
4232 }
4308 } 4233 }
4309 }
4310 return rtt; 4234 return rtt;
4311} 4235}
4312 4236
@@ -4314,8 +4238,7 @@ route_via_neighbour (const struct Neighbour *n,
4314/** 4238/**
4315 * Structure of the key material used to encrypt backchannel messages. 4239 * Structure of the key material used to encrypt backchannel messages.
4316 */ 4240 */
4317struct DVKeyState 4241struct DVKeyState {
4318{
4319 /** 4242 /**
4320 * State of our block cipher. 4243 * State of our block cipher.
4321 */ 4244 */
@@ -4324,9 +4247,7 @@ struct DVKeyState
4324 /** 4247 /**
4325 * Actual key material. 4248 * Actual key material.
4326 */ 4249 */
4327 struct 4250 struct {
4328 {
4329
4330 /** 4251 /**
4331 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()). 4252 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()).
4332 */ 4253 */
@@ -4341,7 +4262,6 @@ struct DVKeyState
4341 * Counter value to use during setup. 4262 * Counter value to use during setup.
4342 */ 4263 */
4343 char aes_ctr[128 / 8]; 4264 char aes_ctr[128 / 8];
4344
4345 } material; 4265 } material;
4346}; 4266};
4347 4267
@@ -4355,34 +4275,34 @@ struct DVKeyState
4355 * @param key[out] symmetric cipher and HMAC state to generate 4275 * @param key[out] symmetric cipher and HMAC state to generate
4356 */ 4276 */
4357static void 4277static void
4358dv_setup_key_state_from_km (const struct GNUNET_HashCode *km, 4278dv_setup_key_state_from_km(const struct GNUNET_HashCode *km,
4359 const struct GNUNET_ShortHashCode *iv, 4279 const struct GNUNET_ShortHashCode *iv,
4360 struct DVKeyState *key) 4280 struct DVKeyState *key)
4361{ 4281{
4362 /* must match #dh_key_derive_eph_pub */ 4282 /* must match #dh_key_derive_eph_pub */
4363 GNUNET_assert (GNUNET_YES == 4283 GNUNET_assert(GNUNET_YES ==
4364 GNUNET_CRYPTO_kdf (&key->material, 4284 GNUNET_CRYPTO_kdf(&key->material,
4365 sizeof (key->material), 4285 sizeof(key->material),
4366 "transport-backchannel-key", 4286 "transport-backchannel-key",
4367 strlen ("transport-backchannel-key"), 4287 strlen("transport-backchannel-key"),
4368 &km, 4288 &km,
4369 sizeof (km), 4289 sizeof(km),
4370 iv, 4290 iv,
4371 sizeof (*iv))); 4291 sizeof(*iv)));
4372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4292 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4373 "Deriving backchannel key based on KM %s and IV %s\n", 4293 "Deriving backchannel key based on KM %s and IV %s\n",
4374 GNUNET_h2s (km), 4294 GNUNET_h2s(km),
4375 GNUNET_sh2s (iv)); 4295 GNUNET_sh2s(iv));
4376 gcry_cipher_open (&key->cipher, 4296 gcry_cipher_open(&key->cipher,
4377 GCRY_CIPHER_AES256 /* low level: go for speed */, 4297 GCRY_CIPHER_AES256 /* low level: go for speed */,
4378 GCRY_CIPHER_MODE_CTR, 4298 GCRY_CIPHER_MODE_CTR,
4379 0 /* flags */); 4299 0 /* flags */);
4380 gcry_cipher_setkey (key->cipher, 4300 gcry_cipher_setkey(key->cipher,
4381 &key->material.aes_key, 4301 &key->material.aes_key,
4382 sizeof (key->material.aes_key)); 4302 sizeof(key->material.aes_key));
4383 gcry_cipher_setctr (key->cipher, 4303 gcry_cipher_setctr(key->cipher,
4384 &key->material.aes_ctr, 4304 &key->material.aes_ctr,
4385 sizeof (key->material.aes_ctr)); 4305 sizeof(key->material.aes_ctr));
4386} 4306}
4387 4307
4388 4308
@@ -4396,7 +4316,7 @@ dv_setup_key_state_from_km (const struct GNUNET_HashCode *km,
4396 * @param key[out] set to the key material 4316 * @param key[out] set to the key material
4397 */ 4317 */
4398static void 4318static void
4399dh_key_derive_eph_pid ( 4319dh_key_derive_eph_pid(
4400 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, 4320 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral,
4401 const struct GNUNET_PeerIdentity *target, 4321 const struct GNUNET_PeerIdentity *target,
4402 const struct GNUNET_ShortHashCode *iv, 4322 const struct GNUNET_ShortHashCode *iv,
@@ -4404,10 +4324,10 @@ dh_key_derive_eph_pid (
4404{ 4324{
4405 struct GNUNET_HashCode km; 4325 struct GNUNET_HashCode km;
4406 4326
4407 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral, 4327 GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa(priv_ephemeral,
4408 &target->public_key, 4328 &target->public_key,
4409 &km)); 4329 &km));
4410 dv_setup_key_state_from_km (&km, iv, key); 4330 dv_setup_key_state_from_km(&km, iv, key);
4411} 4331}
4412 4332
4413 4333
@@ -4421,16 +4341,16 @@ dh_key_derive_eph_pid (
4421 * @param key[out] set to the key material 4341 * @param key[out] set to the key material
4422 */ 4342 */
4423static void 4343static void
4424dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, 4344dh_key_derive_eph_pub(const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
4425 const struct GNUNET_ShortHashCode *iv, 4345 const struct GNUNET_ShortHashCode *iv,
4426 struct DVKeyState *key) 4346 struct DVKeyState *key)
4427{ 4347{
4428 struct GNUNET_HashCode km; 4348 struct GNUNET_HashCode km;
4429 4349
4430 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key, 4350 GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh(GST_my_private_key,
4431 pub_ephemeral, 4351 pub_ephemeral,
4432 &km)); 4352 &km));
4433 dv_setup_key_state_from_km (&km, iv, key); 4353 dv_setup_key_state_from_km(&km, iv, key);
4434} 4354}
4435 4355
4436 4356
@@ -4444,12 +4364,12 @@ dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
4444 * @param data_size number of bytes in @a data 4364 * @param data_size number of bytes in @a data
4445 */ 4365 */
4446static void 4366static void
4447dv_hmac (const struct DVKeyState *key, 4367dv_hmac(const struct DVKeyState *key,
4448 struct GNUNET_HashCode *hmac, 4368 struct GNUNET_HashCode *hmac,
4449 const void *data, 4369 const void *data,
4450 size_t data_size) 4370 size_t data_size)
4451{ 4371{
4452 GNUNET_CRYPTO_hmac (&key->material.hmac_key, data, data_size, hmac); 4372 GNUNET_CRYPTO_hmac(&key->material.hmac_key, data, data_size, hmac);
4453} 4373}
4454 4374
4455 4375
@@ -4463,10 +4383,10 @@ dv_hmac (const struct DVKeyState *key,
4463 * @param in_size number of bytes of input in @a in and available at @a dst 4383 * @param in_size number of bytes of input in @a in and available at @a dst
4464 */ 4384 */
4465static void 4385static void
4466dv_encrypt (struct DVKeyState *key, const void *in, void *dst, size_t in_size) 4386dv_encrypt(struct DVKeyState *key, const void *in, void *dst, size_t in_size)
4467{ 4387{
4468 GNUNET_assert (0 == 4388 GNUNET_assert(0 ==
4469 gcry_cipher_encrypt (key->cipher, dst, in_size, in, in_size)); 4389 gcry_cipher_encrypt(key->cipher, dst, in_size, in, in_size));
4470} 4390}
4471 4391
4472 4392
@@ -4480,13 +4400,13 @@ dv_encrypt (struct DVKeyState *key, const void *in, void *dst, size_t in_size)
4480 * @param out_size number of bytes of input in @a ciph and available in @a out 4400 * @param out_size number of bytes of input in @a ciph and available in @a out
4481 */ 4401 */
4482static void 4402static void
4483dv_decrypt (struct DVKeyState *key, 4403dv_decrypt(struct DVKeyState *key,
4484 void *out, 4404 void *out,
4485 const void *ciph, 4405 const void *ciph,
4486 size_t out_size) 4406 size_t out_size)
4487{ 4407{
4488 GNUNET_assert ( 4408 GNUNET_assert(
4489 0 == gcry_cipher_decrypt (key->cipher, out, out_size, ciph, out_size)); 4409 0 == gcry_cipher_decrypt(key->cipher, out, out_size, ciph, out_size));
4490} 4410}
4491 4411
4492 4412
@@ -4496,10 +4416,10 @@ dv_decrypt (struct DVKeyState *key,
4496 * @param key key material to clean up (memory must not be free'd!) 4416 * @param key key material to clean up (memory must not be free'd!)
4497 */ 4417 */
4498static void 4418static void
4499dv_key_clean (struct DVKeyState *key) 4419dv_key_clean(struct DVKeyState *key)
4500{ 4420{
4501 gcry_cipher_close (key->cipher); 4421 gcry_cipher_close(key->cipher);
4502 GNUNET_CRYPTO_zero_keys (&key->material, sizeof (key->material)); 4422 GNUNET_CRYPTO_zero_keys(&key->material, sizeof(key->material));
4503} 4423}
4504 4424
4505 4425
@@ -4532,92 +4452,92 @@ typedef void (*DVMessageHandler) (void *cls,
4532 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed 4452 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
4533 */ 4453 */
4534static struct GNUNET_TIME_Relative 4454static struct GNUNET_TIME_Relative
4535encapsulate_for_dv (struct DistanceVector *dv, 4455encapsulate_for_dv(struct DistanceVector *dv,
4536 unsigned int num_dvhs, 4456 unsigned int num_dvhs,
4537 struct DistanceVectorHop **dvhs, 4457 struct DistanceVectorHop **dvhs,
4538 const struct GNUNET_MessageHeader *hdr, 4458 const struct GNUNET_MessageHeader *hdr,
4539 DVMessageHandler use, 4459 DVMessageHandler use,
4540 void *use_cls, 4460 void *use_cls,
4541 enum RouteMessageOptions options) 4461 enum RouteMessageOptions options)
4542{ 4462{
4543 struct TransportDVBoxMessage box_hdr; 4463 struct TransportDVBoxMessage box_hdr;
4544 struct TransportDVBoxPayloadP payload_hdr; 4464 struct TransportDVBoxPayloadP payload_hdr;
4545 uint16_t enc_body_size = ntohs (hdr->size); 4465 uint16_t enc_body_size = ntohs(hdr->size);
4546 char enc[sizeof (struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN; 4466 char enc[sizeof(struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN;
4547 struct TransportDVBoxPayloadP *enc_payload_hdr = 4467 struct TransportDVBoxPayloadP *enc_payload_hdr =
4548 (struct TransportDVBoxPayloadP *) enc; 4468 (struct TransportDVBoxPayloadP *)enc;
4549 struct DVKeyState key; 4469 struct DVKeyState key;
4550 struct GNUNET_TIME_Relative rtt; 4470 struct GNUNET_TIME_Relative rtt;
4551 4471
4552 /* Encrypt payload */ 4472 /* Encrypt payload */
4553 box_hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX); 4473 box_hdr.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX);
4554 box_hdr.total_hops = htons (0); 4474 box_hdr.total_hops = htons(0);
4555 update_ephemeral (dv); 4475 update_ephemeral(dv);
4556 box_hdr.ephemeral_key = dv->ephemeral_key; 4476 box_hdr.ephemeral_key = dv->ephemeral_key;
4557 payload_hdr.sender_sig = dv->sender_sig; 4477 payload_hdr.sender_sig = dv->sender_sig;
4558 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 4478 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
4559 &box_hdr.iv, 4479 &box_hdr.iv,
4560 sizeof (box_hdr.iv)); 4480 sizeof(box_hdr.iv));
4561 dh_key_derive_eph_pid (&dv->private_key, &dv->target, &box_hdr.iv, &key); 4481 dh_key_derive_eph_pid(&dv->private_key, &dv->target, &box_hdr.iv, &key);
4562 payload_hdr.sender = GST_my_identity; 4482 payload_hdr.sender = GST_my_identity;
4563 payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton (dv->monotime); 4483 payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton(dv->monotime);
4564 dv_encrypt (&key, &payload_hdr, enc_payload_hdr, sizeof (payload_hdr)); 4484 dv_encrypt(&key, &payload_hdr, enc_payload_hdr, sizeof(payload_hdr));
4565 dv_encrypt (&key, 4485 dv_encrypt(&key,
4566 hdr, 4486 hdr,
4567 &enc[sizeof (struct TransportDVBoxPayloadP)], 4487 &enc[sizeof(struct TransportDVBoxPayloadP)],
4568 enc_body_size); 4488 enc_body_size);
4569 dv_hmac (&key, &box_hdr.hmac, enc, sizeof (enc)); 4489 dv_hmac(&key, &box_hdr.hmac, enc, sizeof(enc));
4570 dv_key_clean (&key); 4490 dv_key_clean(&key);
4571 rtt = GNUNET_TIME_UNIT_FOREVER_REL; 4491 rtt = GNUNET_TIME_UNIT_FOREVER_REL;
4572 /* For each selected path, take the pre-computed header and body 4492 /* For each selected path, take the pre-computed header and body
4573 and add the path in the middle of the message; then send it. */ 4493 and add the path in the middle of the message; then send it. */
4574 for (unsigned int i = 0; i < num_dvhs; i++) 4494 for (unsigned int i = 0; i < num_dvhs; i++)
4575 {
4576 struct DistanceVectorHop *dvh = dvhs[i];
4577 unsigned int num_hops = dvh->distance + 1;
4578 char buf[sizeof (struct TransportDVBoxMessage) +
4579 sizeof (struct GNUNET_PeerIdentity) * num_hops +
4580 sizeof (struct TransportDVBoxPayloadP) +
4581 enc_body_size] GNUNET_ALIGN;
4582 struct GNUNET_PeerIdentity *dhops;
4583
4584 box_hdr.header.size = htons (sizeof (buf));
4585 box_hdr.num_hops = htons (num_hops);
4586 memcpy (buf, &box_hdr, sizeof (box_hdr));
4587 dhops = (struct GNUNET_PeerIdentity *) &buf[sizeof (box_hdr)];
4588 memcpy (dhops,
4589 dvh->path,
4590 dvh->distance * sizeof (struct GNUNET_PeerIdentity));
4591 dhops[dvh->distance] = dv->target;
4592 if (GNUNET_EXTRA_LOGGING > 0)
4593 { 4495 {
4594 char *path; 4496 struct DistanceVectorHop *dvh = dvhs[i];
4595 4497 unsigned int num_hops = dvh->distance + 1;
4596 path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity)); 4498 char buf[sizeof(struct TransportDVBoxMessage) +
4597 for (unsigned int j = 0; j <= num_hops; j++) 4499 sizeof(struct GNUNET_PeerIdentity) * num_hops +
4598 { 4500 sizeof(struct TransportDVBoxPayloadP) +
4599 char *tmp; 4501 enc_body_size] GNUNET_ALIGN;
4600 4502 struct GNUNET_PeerIdentity *dhops;
4601 GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[j])); 4503
4602 GNUNET_free (path); 4504 box_hdr.header.size = htons(sizeof(buf));
4603 path = tmp; 4505 box_hdr.num_hops = htons(num_hops);
4604 } 4506 memcpy(buf, &box_hdr, sizeof(box_hdr));
4605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4507 dhops = (struct GNUNET_PeerIdentity *)&buf[sizeof(box_hdr)];
4606 "Routing message of type %u to %s using DV (#%u/%u) via %s\n", 4508 memcpy(dhops,
4607 ntohs (hdr->type), 4509 dvh->path,
4608 GNUNET_i2s (&dv->target), 4510 dvh->distance * sizeof(struct GNUNET_PeerIdentity));
4609 i + 1, 4511 dhops[dvh->distance] = dv->target;
4610 num_dvhs + 1, 4512 if (GNUNET_EXTRA_LOGGING > 0)
4611 path); 4513 {
4612 GNUNET_free (path); 4514 char *path;
4613 } 4515
4614 rtt = GNUNET_TIME_relative_min (rtt, dvh->pd.aged_rtt); 4516 path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity));
4615 memcpy (&dhops[num_hops], enc, sizeof (enc)); 4517 for (unsigned int j = 0; j <= num_hops; j++)
4616 use (use_cls, 4518 {
4617 dvh->next_hop, 4519 char *tmp;
4618 (const struct GNUNET_MessageHeader *) buf, 4520
4619 options); 4521 GNUNET_asprintf(&tmp, "%s-%s", path, GNUNET_i2s(&dhops[j]));
4620 } 4522 GNUNET_free(path);
4523 path = tmp;
4524 }
4525 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4526 "Routing message of type %u to %s using DV (#%u/%u) via %s\n",
4527 ntohs(hdr->type),
4528 GNUNET_i2s(&dv->target),
4529 i + 1,
4530 num_dvhs + 1,
4531 path);
4532 GNUNET_free(path);
4533 }
4534 rtt = GNUNET_TIME_relative_min(rtt, dvh->pd.aged_rtt);
4535 memcpy(&dhops[num_hops], enc, sizeof(enc));
4536 use(use_cls,
4537 dvh->next_hop,
4538 (const struct GNUNET_MessageHeader *)buf,
4539 options);
4540 }
4621 return rtt; 4541 return rtt;
4622} 4542}
4623 4543
@@ -4632,13 +4552,13 @@ encapsulate_for_dv (struct DistanceVector *dv,
4632 * @param options message options for queue selection 4552 * @param options message options for queue selection
4633 */ 4553 */
4634static void 4554static void
4635send_dv_to_neighbour (void *cls, 4555send_dv_to_neighbour(void *cls,
4636 struct Neighbour *next_hop, 4556 struct Neighbour *next_hop,
4637 const struct GNUNET_MessageHeader *hdr, 4557 const struct GNUNET_MessageHeader *hdr,
4638 enum RouteMessageOptions options) 4558 enum RouteMessageOptions options)
4639{ 4559{
4640 (void) cls; 4560 (void)cls;
4641 (void) route_via_neighbour (next_hop, hdr, options); 4561 (void)route_via_neighbour(next_hop, hdr, options);
4642} 4562}
4643 4563
4644 4564
@@ -4654,9 +4574,9 @@ send_dv_to_neighbour (void *cls,
4654 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed 4574 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
4655 */ 4575 */
4656static struct GNUNET_TIME_Relative 4576static struct GNUNET_TIME_Relative
4657route_control_message_without_fc (const struct GNUNET_PeerIdentity *target, 4577route_control_message_without_fc(const struct GNUNET_PeerIdentity *target,
4658 const struct GNUNET_MessageHeader *hdr, 4578 const struct GNUNET_MessageHeader *hdr,
4659 enum RouteMessageOptions options) 4579 enum RouteMessageOptions options)
4660{ 4580{
4661 struct VirtualLink *vl; 4581 struct VirtualLink *vl;
4662 struct Neighbour *n; 4582 struct Neighbour *n;
@@ -4664,78 +4584,78 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4664 struct GNUNET_TIME_Relative rtt1; 4584 struct GNUNET_TIME_Relative rtt1;
4665 struct GNUNET_TIME_Relative rtt2; 4585 struct GNUNET_TIME_Relative rtt2;
4666 4586
4667 vl = lookup_virtual_link (target); 4587 vl = lookup_virtual_link(target);
4668 GNUNET_assert (NULL != vl); 4588 GNUNET_assert(NULL != vl);
4669 n = vl->n; 4589 n = vl->n;
4670 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL; 4590 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL;
4671 if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) 4591 if (0 == (options & RMO_UNCONFIRMED_ALLOWED))
4672 { 4592 {
4673 /* if confirmed is required, and we do not have anything 4593 /* if confirmed is required, and we do not have anything
4674 confirmed, drop respective options */ 4594 confirmed, drop respective options */
4675 if (NULL == n) 4595 if (NULL == n)
4676 n = lookup_neighbour (target); 4596 n = lookup_neighbour(target);
4677 if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED))) 4597 if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED)))
4678 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, target); 4598 dv = GNUNET_CONTAINER_multipeermap_get(dv_routes, target);
4679 } 4599 }
4680 if ((NULL == n) && (NULL == dv)) 4600 if ((NULL == n) && (NULL == dv))
4681 { 4601 {
4682 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4602 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
4683 "Cannot route message of type %u to %s: no route\n", 4603 "Cannot route message of type %u to %s: no route\n",
4684 ntohs (hdr->type), 4604 ntohs(hdr->type),
4685 GNUNET_i2s (target)); 4605 GNUNET_i2s(target));
4686 GNUNET_STATISTICS_update (GST_stats, 4606 GNUNET_STATISTICS_update(GST_stats,
4687 "# Messages dropped in routing: no acceptable method", 4607 "# Messages dropped in routing: no acceptable method",
4688 1, 4608 1,
4689 GNUNET_NO); 4609 GNUNET_NO);
4690 return GNUNET_TIME_UNIT_FOREVER_REL; 4610 return GNUNET_TIME_UNIT_FOREVER_REL;
4691 } 4611 }
4692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4612 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4693 "Routing message of type %u to %s with options %X\n", 4613 "Routing message of type %u to %s with options %X\n",
4694 ntohs (hdr->type), 4614 ntohs(hdr->type),
4695 GNUNET_i2s (target), 4615 GNUNET_i2s(target),
4696 (unsigned int) options); 4616 (unsigned int)options);
4697 /* If both dv and n are possible and we must choose: 4617 /* If both dv and n are possible and we must choose:
4698 flip a coin for the choice between the two; for now 50/50 */ 4618 flip a coin for the choice between the two; for now 50/50 */
4699 if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT))) 4619 if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT)))
4700 { 4620 {
4701 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2)) 4621 if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2))
4702 n = NULL; 4622 n = NULL;
4703 else 4623 else
4704 dv = NULL; 4624 dv = NULL;
4705 } 4625 }
4706 if ((NULL != n) && (NULL != dv)) 4626 if ((NULL != n) && (NULL != dv))
4707 options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's 4627 options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's
4708 enough for redunancy, so clear the flag. */ 4628 enough for redunancy, so clear the flag. */
4709 rtt1 = GNUNET_TIME_UNIT_FOREVER_REL; 4629 rtt1 = GNUNET_TIME_UNIT_FOREVER_REL;
4710 rtt2 = GNUNET_TIME_UNIT_FOREVER_REL; 4630 rtt2 = GNUNET_TIME_UNIT_FOREVER_REL;
4711 if (NULL != n) 4631 if (NULL != n)
4712 { 4632 {
4713 rtt1 = route_via_neighbour (n, hdr, options); 4633 rtt1 = route_via_neighbour(n, hdr, options);
4714 } 4634 }
4715 if (NULL != dv) 4635 if (NULL != dv)
4716 { 4636 {
4717 struct DistanceVectorHop *hops[2]; 4637 struct DistanceVectorHop *hops[2];
4718 unsigned int res; 4638 unsigned int res;
4719 4639
4720 res = pick_random_dv_hops (dv, 4640 res = pick_random_dv_hops(dv,
4721 options, 4641 options,
4722 hops, 4642 hops,
4723 (0 == (options & RMO_REDUNDANT)) ? 1 : 2); 4643 (0 == (options & RMO_REDUNDANT)) ? 1 : 2);
4724 if (0 == res) 4644 if (0 == res)
4725 { 4645 {
4726 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4646 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
4727 "Failed to route message, could not determine DV path\n"); 4647 "Failed to route message, could not determine DV path\n");
4728 return rtt1; 4648 return rtt1;
4729 } 4649 }
4730 rtt2 = encapsulate_for_dv (dv, 4650 rtt2 = encapsulate_for_dv(dv,
4731 res, 4651 res,
4732 hops, 4652 hops,
4733 hdr, 4653 hdr,
4734 &send_dv_to_neighbour, 4654 &send_dv_to_neighbour,
4735 NULL, 4655 NULL,
4736 options & (~RMO_REDUNDANT)); 4656 options & (~RMO_REDUNDANT));
4737 } 4657 }
4738 return GNUNET_TIME_relative_min (rtt1, rtt2); 4658 return GNUNET_TIME_relative_min(rtt1, rtt2);
4739} 4659}
4740 4660
4741 4661
@@ -4746,7 +4666,7 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4746 * @param cls a `struct VirtualLink` to work with 4666 * @param cls a `struct VirtualLink` to work with
4747 */ 4667 */
4748static void 4668static void
4749consider_sending_fc (void *cls) 4669consider_sending_fc(void *cls)
4750{ 4670{
4751 struct VirtualLink *vl = cls; 4671 struct VirtualLink *vl = cls;
4752 struct GNUNET_TIME_Absolute monotime; 4672 struct GNUNET_TIME_Absolute monotime;
@@ -4754,7 +4674,7 @@ consider_sending_fc (void *cls)
4754 struct GNUNET_TIME_Relative duration; 4674 struct GNUNET_TIME_Relative duration;
4755 struct GNUNET_TIME_Relative rtt; 4675 struct GNUNET_TIME_Relative rtt;
4756 4676
4757 duration = GNUNET_TIME_absolute_get_duration (vl->last_fc_transmission); 4677 duration = GNUNET_TIME_absolute_get_duration(vl->last_fc_transmission);
4758 /* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing 4678 /* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing
4759 it always! */ 4679 it always! */
4760 /* For example, we should probably ONLY do this if a bit more than 4680 /* For example, we should probably ONLY do this if a bit more than
@@ -4763,41 +4683,41 @@ consider_sending_fc (void *cls)
4763 need an estimate for the bandwidth-delay-product for the entire 4683 need an estimate for the bandwidth-delay-product for the entire
4764 VL, as that determines "significantly". We have the delay, but 4684 VL, as that determines "significantly". We have the delay, but
4765 the bandwidth statistics need to be added for the VL!*/ 4685 the bandwidth statistics need to be added for the VL!*/
4766 (void) duration; 4686 (void)duration;
4767 4687
4768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4688 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4769 "Sending FC seq %u to %s with new window %llu\n", 4689 "Sending FC seq %u to %s with new window %llu\n",
4770 (unsigned int) vl->fc_seq_gen, 4690 (unsigned int)vl->fc_seq_gen,
4771 GNUNET_i2s (&vl->target), 4691 GNUNET_i2s(&vl->target),
4772 (unsigned long long) vl->incoming_fc_window_size); 4692 (unsigned long long)vl->incoming_fc_window_size);
4773 monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); 4693 monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg);
4774 vl->last_fc_transmission = monotime; 4694 vl->last_fc_transmission = monotime;
4775 fc.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL); 4695 fc.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL);
4776 fc.header.size = htons (sizeof (fc)); 4696 fc.header.size = htons(sizeof(fc));
4777 fc.seq = htonl (vl->fc_seq_gen++); 4697 fc.seq = htonl(vl->fc_seq_gen++);
4778 fc.inbound_window_size = GNUNET_htonll (vl->incoming_fc_window_size); 4698 fc.inbound_window_size = GNUNET_htonll(vl->incoming_fc_window_size);
4779 fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used); 4699 fc.outbound_sent = GNUNET_htonll(vl->outbound_fc_window_size_used);
4780 fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size); 4700 fc.outbound_window_size = GNUNET_htonll(vl->outbound_fc_window_size);
4781 fc.sender_time = GNUNET_TIME_absolute_hton (monotime); 4701 fc.sender_time = GNUNET_TIME_absolute_hton(monotime);
4782 rtt = route_control_message_without_fc (&vl->target, &fc.header, RMO_NONE); 4702 rtt = route_control_message_without_fc(&vl->target, &fc.header, RMO_NONE);
4783 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us) 4703 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us)
4784 { 4704 {
4785 rtt = GNUNET_TIME_UNIT_SECONDS; 4705 rtt = GNUNET_TIME_UNIT_SECONDS;
4786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4706 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4787 "FC retransmission to %s failed, will retry in %s\n", 4707 "FC retransmission to %s failed, will retry in %s\n",
4788 GNUNET_i2s (&vl->target), 4708 GNUNET_i2s(&vl->target),
4789 GNUNET_STRINGS_relative_time_to_string (rtt, GNUNET_YES)); 4709 GNUNET_STRINGS_relative_time_to_string(rtt, GNUNET_YES));
4790 vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO; 4710 vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO;
4791 } 4711 }
4792 else 4712 else
4793 { 4713 {
4794 /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */ 4714 /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */
4795 vl->last_fc_rtt = rtt; 4715 vl->last_fc_rtt = rtt;
4796 } 4716 }
4797 if (NULL != vl->fc_retransmit_task) 4717 if (NULL != vl->fc_retransmit_task)
4798 GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); 4718 GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task);
4799 vl->fc_retransmit_task = 4719 vl->fc_retransmit_task =
4800 GNUNET_SCHEDULER_add_delayed (rtt, &consider_sending_fc, vl); 4720 GNUNET_SCHEDULER_add_delayed(rtt, &consider_sending_fc, vl);
4801} 4721}
4802 4722
4803 4723
@@ -4818,7 +4738,7 @@ consider_sending_fc (void *cls)
4818 * @param vl virtual link where we should check for transmission 4738 * @param vl virtual link where we should check for transmission
4819 */ 4739 */
4820static void 4740static void
4821check_vl_transmission (struct VirtualLink *vl) 4741check_vl_transmission(struct VirtualLink *vl)
4822{ 4742{
4823 struct Neighbour *n = vl->n; 4743 struct Neighbour *n = vl->n;
4824 struct DistanceVector *dv = vl->dv; 4744 struct DistanceVector *dv = vl->dv;
@@ -4830,57 +4750,57 @@ check_vl_transmission (struct VirtualLink *vl)
4830 elig = GNUNET_NO; 4750 elig = GNUNET_NO;
4831 for (struct PendingMessage *pm = vl->pending_msg_head; NULL != pm; 4751 for (struct PendingMessage *pm = vl->pending_msg_head; NULL != pm;
4832 pm = pm->next_vl) 4752 pm = pm->next_vl)
4833 { 4753 {
4834 if (NULL != pm->qe) 4754 if (NULL != pm->qe)
4835 continue; /* not eligible, is in a queue! */ 4755 continue; /* not eligible, is in a queue! */
4836 if (pm->bytes_msg + vl->outbound_fc_window_size_used > 4756 if (pm->bytes_msg + vl->outbound_fc_window_size_used >
4837 vl->outbound_fc_window_size) 4757 vl->outbound_fc_window_size)
4838 { 4758 {
4839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4840 "Stalled transmision on VL %s due to flow control: %llu < %llu\n", 4760 "Stalled transmision on VL %s due to flow control: %llu < %llu\n",
4841 GNUNET_i2s (&vl->target), 4761 GNUNET_i2s(&vl->target),
4842 (unsigned long long) vl->outbound_fc_window_size, 4762 (unsigned long long)vl->outbound_fc_window_size,
4843 (unsigned long long) (pm->bytes_msg + 4763 (unsigned long long)(pm->bytes_msg +
4844 vl->outbound_fc_window_size_used)); 4764 vl->outbound_fc_window_size_used));
4845 consider_sending_fc (vl); 4765 consider_sending_fc(vl);
4846 return; /* We have a message, but flow control says "nope" */ 4766 return; /* We have a message, but flow control says "nope" */
4847 } 4767 }
4848 elig = GNUNET_YES; 4768 elig = GNUNET_YES;
4849 break; 4769 break;
4850 } 4770 }
4851 if (GNUNET_NO == elig) 4771 if (GNUNET_NO == elig)
4852 return; 4772 return;
4853 4773
4854 /* Notify queues at direct neighbours that we are interested */ 4774 /* Notify queues at direct neighbours that we are interested */
4855 now = GNUNET_TIME_absolute_get (); 4775 now = GNUNET_TIME_absolute_get();
4856 if (NULL != n) 4776 if (NULL != n)
4857 {
4858 for (struct Queue *queue = n->queue_head; NULL != queue;
4859 queue = queue->next_neighbour)
4860 if ((GNUNET_YES == queue->idle) &&
4861 (queue->validated_until.abs_value_us > now.abs_value_us))
4862 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
4863 }
4864 /* Notify queues via DV that we are interested */
4865 if (NULL != dv)
4866 {
4867 /* Do DV with lower scheduler priority, which effectively means that
4868 IF a neighbour exists and is available, we prefer it. */
4869 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
4870 pos = pos->next_dv)
4871 { 4777 {
4872 struct Neighbour *nh = pos->next_hop; 4778 for (struct Queue *queue = n->queue_head; NULL != queue;
4873
4874 if (pos->path_valid_until.abs_value_us <= now.abs_value_us)
4875 continue; /* skip this one: path not validated */
4876 for (struct Queue *queue = nh->queue_head; NULL != queue;
4877 queue = queue->next_neighbour) 4779 queue = queue->next_neighbour)
4878 if ((GNUNET_YES == queue->idle) && 4780 if ((GNUNET_YES == queue->idle) &&
4879 (queue->validated_until.abs_value_us > now.abs_value_us)) 4781 (queue->validated_until.abs_value_us > now.abs_value_us))
4880 schedule_transmit_on_queue (queue, 4782 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
4881 GNUNET_SCHEDULER_PRIORITY_BACKGROUND); 4783 }
4784 /* Notify queues via DV that we are interested */
4785 if (NULL != dv)
4786 {
4787 /* Do DV with lower scheduler priority, which effectively means that
4788 IF a neighbour exists and is available, we prefer it. */
4789 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
4790 pos = pos->next_dv)
4791 {
4792 struct Neighbour *nh = pos->next_hop;
4793
4794 if (pos->path_valid_until.abs_value_us <= now.abs_value_us)
4795 continue; /* skip this one: path not validated */
4796 for (struct Queue *queue = nh->queue_head; NULL != queue;
4797 queue = queue->next_neighbour)
4798 if ((GNUNET_YES == queue->idle) &&
4799 (queue->validated_until.abs_value_us > now.abs_value_us))
4800 schedule_transmit_on_queue(queue,
4801 GNUNET_SCHEDULER_PRIORITY_BACKGROUND);
4802 }
4882 } 4803 }
4883 }
4884} 4804}
4885 4805
4886 4806
@@ -4891,7 +4811,7 @@ check_vl_transmission (struct VirtualLink *vl)
4891 * @param obm the send message that was sent 4811 * @param obm the send message that was sent
4892 */ 4812 */
4893static void 4813static void
4894handle_client_send (void *cls, const struct OutboundMessage *obm) 4814handle_client_send(void *cls, const struct OutboundMessage *obm)
4895{ 4815{
4896 struct TransportClient *tc = cls; 4816 struct TransportClient *tc = cls;
4897 struct PendingMessage *pm; 4817 struct PendingMessage *pm;
@@ -4900,46 +4820,46 @@ handle_client_send (void *cls, const struct OutboundMessage *obm)
4900 struct VirtualLink *vl; 4820 struct VirtualLink *vl;
4901 enum GNUNET_MQ_PriorityPreferences pp; 4821 enum GNUNET_MQ_PriorityPreferences pp;
4902 4822
4903 GNUNET_assert (CT_CORE == tc->type); 4823 GNUNET_assert(CT_CORE == tc->type);
4904 obmm = (const struct GNUNET_MessageHeader *) &obm[1]; 4824 obmm = (const struct GNUNET_MessageHeader *)&obm[1];
4905 bytes_msg = ntohs (obmm->size); 4825 bytes_msg = ntohs(obmm->size);
4906 pp = (enum GNUNET_MQ_PriorityPreferences) ntohl (obm->priority); 4826 pp = (enum GNUNET_MQ_PriorityPreferences)ntohl(obm->priority);
4907 vl = lookup_virtual_link (&obm->peer); 4827 vl = lookup_virtual_link(&obm->peer);
4908 if (NULL == vl) 4828 if (NULL == vl)
4909 { 4829 {
4910 /* Failure: don't have this peer as a neighbour (anymore). 4830 /* Failure: don't have this peer as a neighbour (anymore).
4911 Might have gone down asynchronously, so this is NOT 4831 Might have gone down asynchronously, so this is NOT
4912 a protocol violation by CORE. Still count the event, 4832 a protocol violation by CORE. Still count the event,
4913 as this should be rare. */ 4833 as this should be rare. */
4914 GNUNET_SERVICE_client_continue (tc->client); 4834 GNUNET_SERVICE_client_continue(tc->client);
4915 GNUNET_STATISTICS_update (GST_stats, 4835 GNUNET_STATISTICS_update(GST_stats,
4916 "# messages dropped (neighbour unknown)", 4836 "# messages dropped (neighbour unknown)",
4917 1, 4837 1,
4918 GNUNET_NO); 4838 GNUNET_NO);
4919 return; 4839 return;
4920 } 4840 }
4921 4841
4922 pm = GNUNET_malloc (sizeof (struct PendingMessage) + bytes_msg); 4842 pm = GNUNET_malloc(sizeof(struct PendingMessage) + bytes_msg);
4923 pm->logging_uuid = logging_uuid_gen++; 4843 pm->logging_uuid = logging_uuid_gen++;
4924 pm->prefs = pp; 4844 pm->prefs = pp;
4925 pm->client = tc; 4845 pm->client = tc;
4926 pm->vl = vl; 4846 pm->vl = vl;
4927 pm->bytes_msg = bytes_msg; 4847 pm->bytes_msg = bytes_msg;
4928 memcpy (&pm[1], obmm, bytes_msg); 4848 memcpy(&pm[1], obmm, bytes_msg);
4929 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4849 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4930 "Sending %u bytes as <%llu> to %s\n", 4850 "Sending %u bytes as <%llu> to %s\n",
4931 bytes_msg, 4851 bytes_msg,
4932 pm->logging_uuid, 4852 pm->logging_uuid,
4933 GNUNET_i2s (&obm->peer)); 4853 GNUNET_i2s(&obm->peer));
4934 GNUNET_CONTAINER_MDLL_insert (client, 4854 GNUNET_CONTAINER_MDLL_insert(client,
4935 tc->details.core.pending_msg_head, 4855 tc->details.core.pending_msg_head,
4936 tc->details.core.pending_msg_tail, 4856 tc->details.core.pending_msg_tail,
4937 pm); 4857 pm);
4938 GNUNET_CONTAINER_MDLL_insert (vl, 4858 GNUNET_CONTAINER_MDLL_insert(vl,
4939 vl->pending_msg_head, 4859 vl->pending_msg_head,
4940 vl->pending_msg_tail, 4860 vl->pending_msg_tail,
4941 pm); 4861 pm);
4942 check_vl_transmission (vl); 4862 check_vl_transmission(vl);
4943} 4863}
4944 4864
4945 4865
@@ -4953,39 +4873,39 @@ handle_client_send (void *cls, const struct OutboundMessage *obm)
4953 * @param cb the send message that was sent 4873 * @param cb the send message that was sent
4954 */ 4874 */
4955static void 4875static void
4956handle_communicator_backchannel ( 4876handle_communicator_backchannel(
4957 void *cls, 4877 void *cls,
4958 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 4878 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
4959{ 4879{
4960 struct TransportClient *tc = cls; 4880 struct TransportClient *tc = cls;
4961 const struct GNUNET_MessageHeader *inbox = 4881 const struct GNUNET_MessageHeader *inbox =
4962 (const struct GNUNET_MessageHeader *) &cb[1]; 4882 (const struct GNUNET_MessageHeader *)&cb[1];
4963 uint16_t isize = ntohs (inbox->size); 4883 uint16_t isize = ntohs(inbox->size);
4964 const char *is = ((const char *) &cb[1]) + isize; 4884 const char *is = ((const char *)&cb[1]) + isize;
4965 char 4885 char
4966 mbuf[isize + 4886 mbuf[isize +
4967 sizeof (struct TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN; 4887 sizeof(struct TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN;
4968 struct TransportBackchannelEncapsulationMessage *be = 4888 struct TransportBackchannelEncapsulationMessage *be =
4969 (struct TransportBackchannelEncapsulationMessage *) mbuf; 4889 (struct TransportBackchannelEncapsulationMessage *)mbuf;
4970 4890
4971 /* 0-termination of 'is' was checked already in 4891 /* 0-termination of 'is' was checked already in
4972 #check_communicator_backchannel() */ 4892 #check_communicator_backchannel() */
4973 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4893 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4974 "Preparing backchannel transmission to %s:%s of type %u\n", 4894 "Preparing backchannel transmission to %s:%s of type %u\n",
4975 GNUNET_i2s (&cb->pid), 4895 GNUNET_i2s(&cb->pid),
4976 is, 4896 is,
4977 ntohs (inbox->size)); 4897 ntohs(inbox->size));
4978 /* encapsulate and encrypt message */ 4898 /* encapsulate and encrypt message */
4979 be->header.type = 4899 be->header.type =
4980 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); 4900 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION);
4981 be->header.size = htons (sizeof (mbuf)); 4901 be->header.size = htons(sizeof(mbuf));
4982 memcpy (&be[1], inbox, isize); 4902 memcpy(&be[1], inbox, isize);
4983 memcpy (&mbuf[sizeof (struct TransportBackchannelEncapsulationMessage) + 4903 memcpy(&mbuf[sizeof(struct TransportBackchannelEncapsulationMessage) +
4984 isize], 4904 isize],
4985 is, 4905 is,
4986 strlen (is) + 1); 4906 strlen(is) + 1);
4987 route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED); 4907 route_control_message_without_fc(&cb->pid, &be->header, RMO_DV_ALLOWED);
4988 GNUNET_SERVICE_client_continue (tc->client); 4908 GNUNET_SERVICE_client_continue(tc->client);
4989} 4909}
4990 4910
4991 4911
@@ -4997,17 +4917,17 @@ handle_communicator_backchannel (
4997 * @return #GNUNET_OK if message is well-formed 4917 * @return #GNUNET_OK if message is well-formed
4998 */ 4918 */
4999static int 4919static int
5000check_add_address (void *cls, 4920check_add_address(void *cls,
5001 const struct GNUNET_TRANSPORT_AddAddressMessage *aam) 4921 const struct GNUNET_TRANSPORT_AddAddressMessage *aam)
5002{ 4922{
5003 struct TransportClient *tc = cls; 4923 struct TransportClient *tc = cls;
5004 4924
5005 if (CT_COMMUNICATOR != tc->type) 4925 if (CT_COMMUNICATOR != tc->type)
5006 { 4926 {
5007 GNUNET_break (0); 4927 GNUNET_break(0);
5008 return GNUNET_SYSERR; 4928 return GNUNET_SYSERR;
5009 } 4929 }
5010 GNUNET_MQ_check_zero_termination (aam); 4930 GNUNET_MQ_check_zero_termination(aam);
5011 return GNUNET_OK; 4931 return GNUNET_OK;
5012} 4932}
5013 4933
@@ -5018,7 +4938,7 @@ check_add_address (void *cls,
5018 * @param cls an `struct AddressListEntry *` 4938 * @param cls an `struct AddressListEntry *`
5019 */ 4939 */
5020static void 4940static void
5021store_pi (void *cls); 4941store_pi(void *cls);
5022 4942
5023 4943
5024/** 4944/**
@@ -5028,26 +4948,26 @@ store_pi (void *cls);
5028 * @param success #GNUNET_YES if peerstore was successful 4948 * @param success #GNUNET_YES if peerstore was successful
5029 */ 4949 */
5030static void 4950static void
5031peerstore_store_own_cb (void *cls, int success) 4951peerstore_store_own_cb(void *cls, int success)
5032{ 4952{
5033 struct AddressListEntry *ale = cls; 4953 struct AddressListEntry *ale = cls;
5034 4954
5035 ale->sc = NULL; 4955 ale->sc = NULL;
5036 if (GNUNET_YES != success) 4956 if (GNUNET_YES != success)
5037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 4957 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
5038 "Failed to store our own address `%s' in peerstore!\n", 4958 "Failed to store our own address `%s' in peerstore!\n",
5039 ale->address); 4959 ale->address);
5040 else 4960 else
5041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4961 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5042 "Successfully stored our own address `%s' in peerstore!\n", 4962 "Successfully stored our own address `%s' in peerstore!\n",
5043 ale->address); 4963 ale->address);
5044 /* refresh period is 1/4 of expiration time, that should be plenty 4964 /* refresh period is 1/4 of expiration time, that should be plenty
5045 without being excessive. */ 4965 without being excessive. */
5046 ale->st = 4966 ale->st =
5047 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration, 4967 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(ale->expiration,
5048 4ULL), 4968 4ULL),
5049 &store_pi, 4969 &store_pi,
5050 ale); 4970 ale);
5051} 4971}
5052 4972
5053 4973
@@ -5057,7 +4977,7 @@ peerstore_store_own_cb (void *cls, int success)
5057 * @param cls an `struct AddressListEntry *` 4977 * @param cls an `struct AddressListEntry *`
5058 */ 4978 */
5059static void 4979static void
5060store_pi (void *cls) 4980store_pi(void *cls)
5061{ 4981{
5062 struct AddressListEntry *ale = cls; 4982 struct AddressListEntry *ale = cls;
5063 void *addr; 4983 void *addr;
@@ -5065,36 +4985,36 @@ store_pi (void *cls)
5065 struct GNUNET_TIME_Absolute expiration; 4985 struct GNUNET_TIME_Absolute expiration;
5066 4986
5067 ale->st = NULL; 4987 ale->st = NULL;
5068 expiration = GNUNET_TIME_relative_to_absolute (ale->expiration); 4988 expiration = GNUNET_TIME_relative_to_absolute(ale->expiration);
5069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4989 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5070 "Storing our address `%s' in peerstore until %s!\n", 4990 "Storing our address `%s' in peerstore until %s!\n",
5071 ale->address, 4991 ale->address,
5072 GNUNET_STRINGS_absolute_time_to_string (expiration)); 4992 GNUNET_STRINGS_absolute_time_to_string(expiration));
5073 GNUNET_HELLO_sign_address (ale->address, 4993 GNUNET_HELLO_sign_address(ale->address,
5074 ale->nt, 4994 ale->nt,
5075 hello_mono_time, 4995 hello_mono_time,
5076 GST_my_private_key, 4996 GST_my_private_key,
5077 &addr, 4997 &addr,
5078 &addr_len); 4998 &addr_len);
5079 ale->sc = GNUNET_PEERSTORE_store (peerstore, 4999 ale->sc = GNUNET_PEERSTORE_store(peerstore,
5080 "transport", 5000 "transport",
5081 &GST_my_identity, 5001 &GST_my_identity,
5082 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, 5002 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
5083 addr, 5003 addr,
5084 addr_len, 5004 addr_len,
5085 expiration, 5005 expiration,
5086 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, 5006 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
5087 &peerstore_store_own_cb, 5007 &peerstore_store_own_cb,
5088 ale); 5008 ale);
5089 GNUNET_free (addr); 5009 GNUNET_free(addr);
5090 if (NULL == ale->sc) 5010 if (NULL == ale->sc)
5091 { 5011 {
5092 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 5012 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
5093 "Failed to store our address `%s' with peerstore\n", 5013 "Failed to store our address `%s' with peerstore\n",
5094 ale->address); 5014 ale->address);
5095 ale->st = 5015 ale->st =
5096 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &store_pi, ale); 5016 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &store_pi, ale);
5097 } 5017 }
5098} 5018}
5099 5019
5100 5020
@@ -5105,30 +5025,30 @@ store_pi (void *cls)
5105 * @param aam the send message that was sent 5025 * @param aam the send message that was sent
5106 */ 5026 */
5107static void 5027static void
5108handle_add_address (void *cls, 5028handle_add_address(void *cls,
5109 const struct GNUNET_TRANSPORT_AddAddressMessage *aam) 5029 const struct GNUNET_TRANSPORT_AddAddressMessage *aam)
5110{ 5030{
5111 struct TransportClient *tc = cls; 5031 struct TransportClient *tc = cls;
5112 struct AddressListEntry *ale; 5032 struct AddressListEntry *ale;
5113 size_t slen; 5033 size_t slen;
5114 5034
5115 /* 0-termination of &aam[1] was checked in #check_add_address */ 5035 /* 0-termination of &aam[1] was checked in #check_add_address */
5116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5036 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5117 "Communicator added address `%s'!\n", 5037 "Communicator added address `%s'!\n",
5118 (const char *) &aam[1]); 5038 (const char *)&aam[1]);
5119 slen = ntohs (aam->header.size) - sizeof (*aam); 5039 slen = ntohs(aam->header.size) - sizeof(*aam);
5120 ale = GNUNET_malloc (sizeof (struct AddressListEntry) + slen); 5040 ale = GNUNET_malloc(sizeof(struct AddressListEntry) + slen);
5121 ale->tc = tc; 5041 ale->tc = tc;
5122 ale->address = (const char *) &ale[1]; 5042 ale->address = (const char *)&ale[1];
5123 ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration); 5043 ale->expiration = GNUNET_TIME_relative_ntoh(aam->expiration);
5124 ale->aid = aam->aid; 5044 ale->aid = aam->aid;
5125 ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt); 5045 ale->nt = (enum GNUNET_NetworkType)ntohl(aam->nt);
5126 memcpy (&ale[1], &aam[1], slen); 5046 memcpy(&ale[1], &aam[1], slen);
5127 GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head, 5047 GNUNET_CONTAINER_DLL_insert(tc->details.communicator.addr_head,
5128 tc->details.communicator.addr_tail, 5048 tc->details.communicator.addr_tail,
5129 ale); 5049 ale);
5130 ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale); 5050 ale->st = GNUNET_SCHEDULER_add_now(&store_pi, ale);
5131 GNUNET_SERVICE_client_continue (tc->client); 5051 GNUNET_SERVICE_client_continue(tc->client);
5132} 5052}
5133 5053
5134 5054
@@ -5139,34 +5059,34 @@ handle_add_address (void *cls,
5139 * @param dam the send message that was sent 5059 * @param dam the send message that was sent
5140 */ 5060 */
5141static void 5061static void
5142handle_del_address (void *cls, 5062handle_del_address(void *cls,
5143 const struct GNUNET_TRANSPORT_DelAddressMessage *dam) 5063 const struct GNUNET_TRANSPORT_DelAddressMessage *dam)
5144{ 5064{
5145 struct TransportClient *tc = cls; 5065 struct TransportClient *tc = cls;
5146 struct AddressListEntry *alen; 5066 struct AddressListEntry *alen;
5147 5067
5148 if (CT_COMMUNICATOR != tc->type) 5068 if (CT_COMMUNICATOR != tc->type)
5149 { 5069 {
5150 GNUNET_break (0); 5070 GNUNET_break(0);
5151 GNUNET_SERVICE_client_drop (tc->client); 5071 GNUNET_SERVICE_client_drop(tc->client);
5152 return; 5072 return;
5153 } 5073 }
5154 for (struct AddressListEntry *ale = tc->details.communicator.addr_head; 5074 for (struct AddressListEntry *ale = tc->details.communicator.addr_head;
5155 NULL != ale; 5075 NULL != ale;
5156 ale = alen) 5076 ale = alen)
5157 { 5077 {
5158 alen = ale->next; 5078 alen = ale->next;
5159 if (dam->aid != ale->aid) 5079 if (dam->aid != ale->aid)
5160 continue; 5080 continue;
5161 GNUNET_assert (ale->tc == tc); 5081 GNUNET_assert(ale->tc == tc);
5162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5082 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5163 "Communicator deleted address `%s'!\n", 5083 "Communicator deleted address `%s'!\n",
5164 ale->address); 5084 ale->address);
5165 free_address_list_entry (ale); 5085 free_address_list_entry(ale);
5166 GNUNET_SERVICE_client_continue (tc->client); 5086 GNUNET_SERVICE_client_continue(tc->client);
5167 } 5087 }
5168 GNUNET_break (0); 5088 GNUNET_break(0);
5169 GNUNET_SERVICE_client_drop (tc->client); 5089 GNUNET_SERVICE_client_drop(tc->client);
5170} 5090}
5171 5091
5172 5092
@@ -5178,8 +5098,8 @@ handle_del_address (void *cls,
5178 * @param msg message to demultiplex 5098 * @param msg message to demultiplex
5179 */ 5099 */
5180static void 5100static void
5181demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, 5101demultiplex_with_cmc(struct CommunicatorMessageContext *cmc,
5182 const struct GNUNET_MessageHeader *msg); 5102 const struct GNUNET_MessageHeader *msg);
5183 5103
5184 5104
5185/** 5105/**
@@ -5190,23 +5110,23 @@ demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
5190 * @param cls a `struct CoreSentContext` 5110 * @param cls a `struct CoreSentContext`
5191 */ 5111 */
5192static void 5112static void
5193core_env_sent_cb (void *cls) 5113core_env_sent_cb(void *cls)
5194{ 5114{
5195 struct CoreSentContext *ctx = cls; 5115 struct CoreSentContext *ctx = cls;
5196 struct VirtualLink *vl = ctx->vl; 5116 struct VirtualLink *vl = ctx->vl;
5197 5117
5198 if (NULL == vl) 5118 if (NULL == vl)
5199 { 5119 {
5200 /* lost the link in the meantime, ignore */ 5120 /* lost the link in the meantime, ignore */
5201 GNUNET_free (ctx); 5121 GNUNET_free(ctx);
5202 return; 5122 return;
5203 } 5123 }
5204 GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, ctx); 5124 GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, ctx);
5205 GNUNET_assert (vl->incoming_fc_window_size_ram >= ctx->size); 5125 GNUNET_assert(vl->incoming_fc_window_size_ram >= ctx->size);
5206 vl->incoming_fc_window_size_ram -= ctx->size; 5126 vl->incoming_fc_window_size_ram -= ctx->size;
5207 vl->incoming_fc_window_size_used += ctx->isize; 5127 vl->incoming_fc_window_size_used += ctx->isize;
5208 consider_sending_fc (vl); 5128 consider_sending_fc(vl);
5209 GNUNET_free (ctx); 5129 GNUNET_free(ctx);
5210} 5130}
5211 5131
5212 5132
@@ -5219,109 +5139,109 @@ core_env_sent_cb (void *cls)
5219 * @param mh the message that was received 5139 * @param mh the message that was received
5220 */ 5140 */
5221static void 5141static void
5222handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh) 5142handle_raw_message(void *cls, const struct GNUNET_MessageHeader *mh)
5223{ 5143{
5224 struct CommunicatorMessageContext *cmc = cls; 5144 struct CommunicatorMessageContext *cmc = cls;
5225 struct VirtualLink *vl; 5145 struct VirtualLink *vl;
5226 uint16_t size = ntohs (mh->size); 5146 uint16_t size = ntohs(mh->size);
5227 int have_core; 5147 int have_core;
5228 5148
5229 if ((size > UINT16_MAX - sizeof (struct InboundMessage)) || 5149 if ((size > UINT16_MAX - sizeof(struct InboundMessage)) ||
5230 (size < sizeof (struct GNUNET_MessageHeader))) 5150 (size < sizeof(struct GNUNET_MessageHeader)))
5231 { 5151 {
5232 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 5152 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
5233 5153
5234 GNUNET_break (0); 5154 GNUNET_break(0);
5235 finish_cmc_handling (cmc); 5155 finish_cmc_handling(cmc);
5236 GNUNET_SERVICE_client_drop (client); 5156 GNUNET_SERVICE_client_drop(client);
5237 return; 5157 return;
5238 } 5158 }
5239 vl = lookup_virtual_link (&cmc->im.sender); 5159 vl = lookup_virtual_link(&cmc->im.sender);
5240 if (NULL == vl) 5160 if (NULL == vl)
5241 { 5161 {
5242 /* FIXME: sender is giving us messages for CORE but we don't have 5162 /* FIXME: sender is giving us messages for CORE but we don't have
5243 the link up yet! I *suspect* this can happen right now (i.e. 5163 the link up yet! I *suspect* this can happen right now (i.e.
5244 sender has verified us, but we didn't verify sender), but if 5164 sender has verified us, but we didn't verify sender), but if
5245 we pass this on, CORE would be confused (link down, messages 5165 we pass this on, CORE would be confused (link down, messages
5246 arrive). We should investigate more if this happens often, 5166 arrive). We should investigate more if this happens often,
5247 or in a persistent manner, and possibly do "something" about 5167 or in a persistent manner, and possibly do "something" about
5248 it. Thus logging as error for now. */ 5168 it. Thus logging as error for now. */
5249 GNUNET_break_op (0); 5169 GNUNET_break_op(0);
5250 GNUNET_STATISTICS_update (GST_stats, 5170 GNUNET_STATISTICS_update(GST_stats,
5251 "# CORE messages droped (virtual link still down)", 5171 "# CORE messages droped (virtual link still down)",
5252 1, 5172 1,
5253 GNUNET_NO); 5173 GNUNET_NO);
5254 5174
5255 finish_cmc_handling (cmc); 5175 finish_cmc_handling(cmc);
5256 return; 5176 return;
5257 } 5177 }
5258 if (vl->incoming_fc_window_size_ram > UINT_MAX - size) 5178 if (vl->incoming_fc_window_size_ram > UINT_MAX - size)
5259 { 5179 {
5260 GNUNET_STATISTICS_update (GST_stats, 5180 GNUNET_STATISTICS_update(GST_stats,
5261 "# CORE messages droped (FC arithmetic overflow)", 5181 "# CORE messages droped (FC arithmetic overflow)",
5262 1, 5182 1,
5263 GNUNET_NO); 5183 GNUNET_NO);
5264 5184
5265 finish_cmc_handling (cmc); 5185 finish_cmc_handling(cmc);
5266 return; 5186 return;
5267 } 5187 }
5268 if (vl->incoming_fc_window_size_ram + size > vl->available_fc_window_size) 5188 if (vl->incoming_fc_window_size_ram + size > vl->available_fc_window_size)
5269 { 5189 {
5270 GNUNET_STATISTICS_update (GST_stats, 5190 GNUNET_STATISTICS_update(GST_stats,
5271 "# CORE messages droped (FC window overflow)", 5191 "# CORE messages droped (FC window overflow)",
5272 1, 5192 1,
5273 GNUNET_NO); 5193 GNUNET_NO);
5274 finish_cmc_handling (cmc); 5194 finish_cmc_handling(cmc);
5275 return; 5195 return;
5276 } 5196 }
5277 5197
5278 /* Forward to all CORE clients */ 5198 /* Forward to all CORE clients */
5279 have_core = GNUNET_NO; 5199 have_core = GNUNET_NO;
5280 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 5200 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
5281 { 5201 {
5282 struct GNUNET_MQ_Envelope *env; 5202 struct GNUNET_MQ_Envelope *env;
5283 struct InboundMessage *im; 5203 struct InboundMessage *im;
5284 struct CoreSentContext *ctx; 5204 struct CoreSentContext *ctx;
5285 5205
5286 if (CT_CORE != tc->type) 5206 if (CT_CORE != tc->type)
5287 continue; 5207 continue;
5288 vl->incoming_fc_window_size_ram += size; 5208 vl->incoming_fc_window_size_ram += size;
5289 env = GNUNET_MQ_msg_extra (im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 5209 env = GNUNET_MQ_msg_extra(im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
5290 ctx = GNUNET_new (struct CoreSentContext); 5210 ctx = GNUNET_new(struct CoreSentContext);
5291 ctx->vl = vl; 5211 ctx->vl = vl;
5292 ctx->size = size; 5212 ctx->size = size;
5293 ctx->isize = (GNUNET_NO == have_core) ? size : 0; 5213 ctx->isize = (GNUNET_NO == have_core) ? size : 0;
5294 have_core = GNUNET_YES; 5214 have_core = GNUNET_YES;
5295 GNUNET_CONTAINER_DLL_insert (vl->csc_head, vl->csc_tail, ctx); 5215 GNUNET_CONTAINER_DLL_insert(vl->csc_head, vl->csc_tail, ctx);
5296 GNUNET_MQ_notify_sent (env, &core_env_sent_cb, ctx); 5216 GNUNET_MQ_notify_sent(env, &core_env_sent_cb, ctx);
5297 im->peer = cmc->im.sender; 5217 im->peer = cmc->im.sender;
5298 memcpy (&im[1], mh, size); 5218 memcpy(&im[1], mh, size);
5299 GNUNET_MQ_send (tc->mq, env); 5219 GNUNET_MQ_send(tc->mq, env);
5300 vl->core_recv_window--; 5220 vl->core_recv_window--;
5301 } 5221 }
5302 if (GNUNET_NO == have_core) 5222 if (GNUNET_NO == have_core)
5303 { 5223 {
5304 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 5224 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
5305 "Dropped message to CORE: no CORE client connected!\n"); 5225 "Dropped message to CORE: no CORE client connected!\n");
5306 /* Nevertheless, count window as used, as it is from the 5226 /* Nevertheless, count window as used, as it is from the
5307 perspective of the other peer! */ 5227 perspective of the other peer! */
5308 vl->incoming_fc_window_size_used += size; 5228 vl->incoming_fc_window_size_used += size;
5309 /* TODO-M1 */ 5229 /* TODO-M1 */
5310 finish_cmc_handling (cmc); 5230 finish_cmc_handling(cmc);
5311 return; 5231 return;
5312 } 5232 }
5313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5233 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5314 "Delivered message from %s of type %u to CORE\n", 5234 "Delivered message from %s of type %u to CORE\n",
5315 GNUNET_i2s (&cmc->im.sender), 5235 GNUNET_i2s(&cmc->im.sender),
5316 ntohs (mh->type)); 5236 ntohs(mh->type));
5317 if (vl->core_recv_window > 0) 5237 if (vl->core_recv_window > 0)
5318 { 5238 {
5319 finish_cmc_handling (cmc); 5239 finish_cmc_handling(cmc);
5320 return; 5240 return;
5321 } 5241 }
5322 /* Wait with calling #finish_cmc_handling(cmc) until the message 5242 /* Wait with calling #finish_cmc_handling(cmc) until the message
5323 was processed by CORE MQs (for CORE flow control)! */ 5243 was processed by CORE MQs (for CORE flow control)! */
5324 GNUNET_CONTAINER_DLL_insert (vl->cmc_head, vl->cmc_tail, cmc); 5244 GNUNET_CONTAINER_DLL_insert(vl->cmc_head, vl->cmc_tail, cmc);
5325} 5245}
5326 5246
5327 5247
@@ -5333,27 +5253,27 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5333 * @return #GNUNET_YES if message is well-formed 5253 * @return #GNUNET_YES if message is well-formed
5334 */ 5254 */
5335static int 5255static int
5336check_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) 5256check_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
5337{ 5257{
5338 uint16_t size = ntohs (fb->header.size); 5258 uint16_t size = ntohs(fb->header.size);
5339 uint16_t bsize = size - sizeof (*fb); 5259 uint16_t bsize = size - sizeof(*fb);
5340 5260
5341 (void) cls; 5261 (void)cls;
5342 if (0 == bsize) 5262 if (0 == bsize)
5343 { 5263 {
5344 GNUNET_break_op (0); 5264 GNUNET_break_op(0);
5345 return GNUNET_SYSERR; 5265 return GNUNET_SYSERR;
5346 } 5266 }
5347 if (bsize + ntohs (fb->frag_off) > ntohs (fb->msg_size)) 5267 if (bsize + ntohs(fb->frag_off) > ntohs(fb->msg_size))
5348 { 5268 {
5349 GNUNET_break_op (0); 5269 GNUNET_break_op(0);
5350 return GNUNET_SYSERR; 5270 return GNUNET_SYSERR;
5351 } 5271 }
5352 if (ntohs (fb->frag_off) >= ntohs (fb->msg_size)) 5272 if (ntohs(fb->frag_off) >= ntohs(fb->msg_size))
5353 { 5273 {
5354 GNUNET_break_op (0); 5274 GNUNET_break_op(0);
5355 return GNUNET_SYSERR; 5275 return GNUNET_SYSERR;
5356 } 5276 }
5357 return GNUNET_YES; 5277 return GNUNET_YES;
5358} 5278}
5359 5279
@@ -5364,16 +5284,16 @@ check_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
5364 * @param cls a `struct AcknowledgementCummulator *` 5284 * @param cls a `struct AcknowledgementCummulator *`
5365 */ 5285 */
5366static void 5286static void
5367destroy_ack_cummulator (void *cls) 5287destroy_ack_cummulator(void *cls)
5368{ 5288{
5369 struct AcknowledgementCummulator *ac = cls; 5289 struct AcknowledgementCummulator *ac = cls;
5370 5290
5371 ac->task = NULL; 5291 ac->task = NULL;
5372 GNUNET_assert (0 == ac->num_acks); 5292 GNUNET_assert(0 == ac->num_acks);
5373 GNUNET_assert ( 5293 GNUNET_assert(
5374 GNUNET_YES == 5294 GNUNET_YES ==
5375 GNUNET_CONTAINER_multipeermap_remove (ack_cummulators, &ac->target, ac)); 5295 GNUNET_CONTAINER_multipeermap_remove(ack_cummulators, &ac->target, ac));
5376 GNUNET_free (ac); 5296 GNUNET_free(ac);
5377} 5297}
5378 5298
5379 5299
@@ -5383,39 +5303,39 @@ destroy_ack_cummulator (void *cls)
5383 * @param cls a `struct AcknowledgementCummulator *` 5303 * @param cls a `struct AcknowledgementCummulator *`
5384 */ 5304 */
5385static void 5305static void
5386transmit_cummulative_ack_cb (void *cls) 5306transmit_cummulative_ack_cb(void *cls)
5387{ 5307{
5388 struct AcknowledgementCummulator *ac = cls; 5308 struct AcknowledgementCummulator *ac = cls;
5389 char buf[sizeof (struct TransportReliabilityAckMessage) + 5309 char buf[sizeof(struct TransportReliabilityAckMessage) +
5390 ac->ack_counter * 5310 ac->ack_counter *
5391 sizeof (struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN; 5311 sizeof(struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN;
5392 struct TransportReliabilityAckMessage *ack = 5312 struct TransportReliabilityAckMessage *ack =
5393 (struct TransportReliabilityAckMessage *) buf; 5313 (struct TransportReliabilityAckMessage *)buf;
5394 struct TransportCummulativeAckPayloadP *ap; 5314 struct TransportCummulativeAckPayloadP *ap;
5395 5315
5396 ac->task = NULL; 5316 ac->task = NULL;
5397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5317 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5398 "Sending ACK with %u components to %s\n", 5318 "Sending ACK with %u components to %s\n",
5399 ac->ack_counter, 5319 ac->ack_counter,
5400 GNUNET_i2s (&ac->target)); 5320 GNUNET_i2s(&ac->target));
5401 GNUNET_assert (0 < ac->ack_counter); 5321 GNUNET_assert(0 < ac->ack_counter);
5402 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); 5322 ack->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK);
5403 ack->header.size = 5323 ack->header.size =
5404 htons (sizeof (*ack) + 5324 htons(sizeof(*ack) +
5405 ac->ack_counter * sizeof (struct TransportCummulativeAckPayloadP)); 5325 ac->ack_counter * sizeof(struct TransportCummulativeAckPayloadP));
5406 ack->ack_counter = htonl (ac->ack_counter++); 5326 ack->ack_counter = htonl(ac->ack_counter++);
5407 ap = (struct TransportCummulativeAckPayloadP *) &ack[1]; 5327 ap = (struct TransportCummulativeAckPayloadP *)&ack[1];
5408 for (unsigned int i = 0; i < ac->ack_counter; i++) 5328 for (unsigned int i = 0; i < ac->ack_counter; i++)
5409 { 5329 {
5410 ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid; 5330 ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid;
5411 ap[i].ack_delay = GNUNET_TIME_relative_hton ( 5331 ap[i].ack_delay = GNUNET_TIME_relative_hton(
5412 GNUNET_TIME_absolute_get_duration (ac->ack_uuids[i].receive_time)); 5332 GNUNET_TIME_absolute_get_duration(ac->ack_uuids[i].receive_time));
5413 } 5333 }
5414 route_control_message_without_fc (&ac->target, &ack->header, RMO_DV_ALLOWED); 5334 route_control_message_without_fc(&ac->target, &ack->header, RMO_DV_ALLOWED);
5415 ac->num_acks = 0; 5335 ac->num_acks = 0;
5416 ac->task = GNUNET_SCHEDULER_add_delayed (ACK_CUMMULATOR_TIMEOUT, 5336 ac->task = GNUNET_SCHEDULER_add_delayed(ACK_CUMMULATOR_TIMEOUT,
5417 &destroy_ack_cummulator, 5337 &destroy_ack_cummulator,
5418 ac); 5338 ac);
5419} 5339}
5420 5340
5421 5341
@@ -5428,56 +5348,55 @@ transmit_cummulative_ack_cb (void *cls)
5428 * @param max_delay how long can the ACK wait 5348 * @param max_delay how long can the ACK wait
5429 */ 5349 */
5430static void 5350static void
5431cummulative_ack (const struct GNUNET_PeerIdentity *pid, 5351cummulative_ack(const struct GNUNET_PeerIdentity *pid,
5432 const struct AcknowledgementUUIDP *ack_uuid, 5352 const struct AcknowledgementUUIDP *ack_uuid,
5433 struct GNUNET_TIME_Absolute max_delay) 5353 struct GNUNET_TIME_Absolute max_delay)
5434{ 5354{
5435 struct AcknowledgementCummulator *ac; 5355 struct AcknowledgementCummulator *ac;
5436 5356
5437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5357 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5438 "Scheduling ACK %s for transmission to %s\n", 5358 "Scheduling ACK %s for transmission to %s\n",
5439 GNUNET_uuid2s (&ack_uuid->value), 5359 GNUNET_uuid2s(&ack_uuid->value),
5440 GNUNET_i2s (pid)); 5360 GNUNET_i2s(pid));
5441 ac = GNUNET_CONTAINER_multipeermap_get (ack_cummulators, pid); 5361 ac = GNUNET_CONTAINER_multipeermap_get(ack_cummulators, pid);
5442 if (NULL == ac) 5362 if (NULL == ac)
5443 { 5363 {
5444 ac = GNUNET_new (struct AcknowledgementCummulator); 5364 ac = GNUNET_new(struct AcknowledgementCummulator);
5445 ac->target = *pid; 5365 ac->target = *pid;
5446 ac->min_transmission_time = max_delay; 5366 ac->min_transmission_time = max_delay;
5447 GNUNET_assert (GNUNET_YES == 5367 GNUNET_assert(GNUNET_YES ==
5448 GNUNET_CONTAINER_multipeermap_put ( 5368 GNUNET_CONTAINER_multipeermap_put(
5449 ack_cummulators, 5369 ack_cummulators,
5450 &ac->target, 5370 &ac->target,
5451 ac, 5371 ac,
5452 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 5372 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
5453 } 5373 }
5454 else 5374 else
5455 {
5456 if (MAX_CUMMULATIVE_ACKS == ac->num_acks)
5457 { 5375 {
5458 /* must run immediately, ack buffer full! */ 5376 if (MAX_CUMMULATIVE_ACKS == ac->num_acks)
5459 GNUNET_SCHEDULER_cancel (ac->task); 5377 {
5460 transmit_cummulative_ack_cb (ac); 5378 /* must run immediately, ack buffer full! */
5379 GNUNET_SCHEDULER_cancel(ac->task);
5380 transmit_cummulative_ack_cb(ac);
5381 }
5382 GNUNET_SCHEDULER_cancel(ac->task);
5383 ac->min_transmission_time =
5384 GNUNET_TIME_absolute_min(ac->min_transmission_time, max_delay);
5461 } 5385 }
5462 GNUNET_SCHEDULER_cancel (ac->task); 5386 GNUNET_assert(ac->num_acks < MAX_CUMMULATIVE_ACKS);
5463 ac->min_transmission_time = 5387 ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get();
5464 GNUNET_TIME_absolute_min (ac->min_transmission_time, max_delay);
5465 }
5466 GNUNET_assert (ac->num_acks < MAX_CUMMULATIVE_ACKS);
5467 ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get ();
5468 ac->ack_uuids[ac->num_acks].ack_uuid = *ack_uuid; 5388 ac->ack_uuids[ac->num_acks].ack_uuid = *ack_uuid;
5469 ac->num_acks++; 5389 ac->num_acks++;
5470 ac->task = GNUNET_SCHEDULER_add_at (ac->min_transmission_time, 5390 ac->task = GNUNET_SCHEDULER_add_at(ac->min_transmission_time,
5471 &transmit_cummulative_ack_cb, 5391 &transmit_cummulative_ack_cb,
5472 ac); 5392 ac);
5473} 5393}
5474 5394
5475 5395
5476/** 5396/**
5477 * Closure for #find_by_message_uuid. 5397 * Closure for #find_by_message_uuid.
5478 */ 5398 */
5479struct FindByMessageUuidContext 5399struct FindByMessageUuidContext {
5480{
5481 /** 5400 /**
5482 * UUID to look for. 5401 * UUID to look for.
5483 */ 5402 */
@@ -5500,17 +5419,17 @@ struct FindByMessageUuidContext
5500 * @return #GNUNET_YES if not found, #GNUNET_NO if found 5419 * @return #GNUNET_YES if not found, #GNUNET_NO if found
5501 */ 5420 */
5502static int 5421static int
5503find_by_message_uuid (void *cls, uint32_t key, void *value) 5422find_by_message_uuid(void *cls, uint32_t key, void *value)
5504{ 5423{
5505 struct FindByMessageUuidContext *fc = cls; 5424 struct FindByMessageUuidContext *fc = cls;
5506 struct ReassemblyContext *rc = value; 5425 struct ReassemblyContext *rc = value;
5507 5426
5508 (void) key; 5427 (void)key;
5509 if (0 == GNUNET_memcmp (&fc->message_uuid, &rc->msg_uuid)) 5428 if (0 == GNUNET_memcmp(&fc->message_uuid, &rc->msg_uuid))
5510 { 5429 {
5511 fc->rc = rc; 5430 fc->rc = rc;
5512 return GNUNET_NO; 5431 return GNUNET_NO;
5513 } 5432 }
5514 return GNUNET_YES; 5433 return GNUNET_YES;
5515} 5434}
5516 5435
@@ -5523,7 +5442,7 @@ find_by_message_uuid (void *cls, uint32_t key, void *value)
5523 * @param fb the message that was received 5442 * @param fb the message that was received
5524 */ 5443 */
5525static void 5444static void
5526handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) 5445handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
5527{ 5446{
5528 struct CommunicatorMessageContext *cmc = cls; 5447 struct CommunicatorMessageContext *cmc = cls;
5529 struct Neighbour *n; 5448 struct Neighbour *n;
@@ -5536,142 +5455,142 @@ handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
5536 struct GNUNET_TIME_Relative cdelay; 5455 struct GNUNET_TIME_Relative cdelay;
5537 struct FindByMessageUuidContext fc; 5456 struct FindByMessageUuidContext fc;
5538 5457
5539 n = lookup_neighbour (&cmc->im.sender); 5458 n = lookup_neighbour(&cmc->im.sender);
5540 if (NULL == n) 5459 if (NULL == n)
5541 { 5460 {
5542 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 5461 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
5543 5462
5544 GNUNET_break (0); 5463 GNUNET_break(0);
5545 finish_cmc_handling (cmc); 5464 finish_cmc_handling(cmc);
5546 GNUNET_SERVICE_client_drop (client); 5465 GNUNET_SERVICE_client_drop(client);
5547 return; 5466 return;
5548 } 5467 }
5549 if (NULL == n->reassembly_map) 5468 if (NULL == n->reassembly_map)
5550 { 5469 {
5551 n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create (8); 5470 n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create(8);
5552 n->reassembly_heap = 5471 n->reassembly_heap =
5553 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 5472 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
5554 n->reassembly_timeout_task = 5473 n->reassembly_timeout_task =
5555 GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION, 5474 GNUNET_SCHEDULER_add_delayed(REASSEMBLY_EXPIRATION,
5556 &reassembly_cleanup_task, 5475 &reassembly_cleanup_task,
5557 n); 5476 n);
5558 } 5477 }
5559 msize = ntohs (fb->msg_size); 5478 msize = ntohs(fb->msg_size);
5560 fc.message_uuid = fb->msg_uuid; 5479 fc.message_uuid = fb->msg_uuid;
5561 fc.rc = NULL; 5480 fc.rc = NULL;
5562 (void) GNUNET_CONTAINER_multihashmap32_get_multiple (n->reassembly_map, 5481 (void)GNUNET_CONTAINER_multihashmap32_get_multiple(n->reassembly_map,
5563 fb->msg_uuid.uuid, 5482 fb->msg_uuid.uuid,
5564 &find_by_message_uuid, 5483 &find_by_message_uuid,
5565 &fc); 5484 &fc);
5566 if (NULL == (rc = fc.rc)) 5485 if (NULL == (rc = fc.rc))
5567 { 5486 {
5568 rc = GNUNET_malloc (sizeof (*rc) + msize + /* reassembly payload buffer */ 5487 rc = GNUNET_malloc(sizeof(*rc) + msize + /* reassembly payload buffer */
5569 (msize + 7) / 8 * sizeof (uint8_t) /* bitfield */); 5488 (msize + 7) / 8 * sizeof(uint8_t) /* bitfield */);
5570 rc->msg_uuid = fb->msg_uuid; 5489 rc->msg_uuid = fb->msg_uuid;
5571 rc->neighbour = n; 5490 rc->neighbour = n;
5572 rc->msg_size = msize; 5491 rc->msg_size = msize;
5573 rc->reassembly_timeout = 5492 rc->reassembly_timeout =
5574 GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION); 5493 GNUNET_TIME_relative_to_absolute(REASSEMBLY_EXPIRATION);
5575 rc->last_frag = GNUNET_TIME_absolute_get (); 5494 rc->last_frag = GNUNET_TIME_absolute_get();
5576 rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap, 5495 rc->hn = GNUNET_CONTAINER_heap_insert(n->reassembly_heap,
5577 rc, 5496 rc,
5578 rc->reassembly_timeout.abs_value_us); 5497 rc->reassembly_timeout.abs_value_us);
5579 GNUNET_assert (GNUNET_OK == 5498 GNUNET_assert(GNUNET_OK ==
5580 GNUNET_CONTAINER_multihashmap32_put ( 5499 GNUNET_CONTAINER_multihashmap32_put(
5581 n->reassembly_map, 5500 n->reassembly_map,
5582 rc->msg_uuid.uuid, 5501 rc->msg_uuid.uuid,
5583 rc, 5502 rc,
5584 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 5503 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
5585 target = (char *) &rc[1]; 5504 target = (char *)&rc[1];
5586 rc->bitfield = (uint8_t *) (target + rc->msg_size); 5505 rc->bitfield = (uint8_t *)(target + rc->msg_size);
5587 rc->msg_missing = rc->msg_size; 5506 rc->msg_missing = rc->msg_size;
5588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5507 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5589 "Received fragment at offset %u/%u from %s for NEW message %u\n", 5508 "Received fragment at offset %u/%u from %s for NEW message %u\n",
5590 ntohs (fb->frag_off), 5509 ntohs(fb->frag_off),
5591 msize, 5510 msize,
5592 GNUNET_i2s (&cmc->im.sender), 5511 GNUNET_i2s(&cmc->im.sender),
5593 (unsigned int) fb->msg_uuid.uuid); 5512 (unsigned int)fb->msg_uuid.uuid);
5594 } 5513 }
5595 else 5514 else
5596 { 5515 {
5597 target = (char *) &rc[1]; 5516 target = (char *)&rc[1];
5598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5517 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5599 "Received fragment at offset %u/%u from %s for message %u\n", 5518 "Received fragment at offset %u/%u from %s for message %u\n",
5600 ntohs (fb->frag_off), 5519 ntohs(fb->frag_off),
5601 msize, 5520 msize,
5602 GNUNET_i2s (&cmc->im.sender), 5521 GNUNET_i2s(&cmc->im.sender),
5603 (unsigned int) fb->msg_uuid.uuid); 5522 (unsigned int)fb->msg_uuid.uuid);
5604 } 5523 }
5605 if (msize != rc->msg_size) 5524 if (msize != rc->msg_size)
5606 { 5525 {
5607 GNUNET_break (0); 5526 GNUNET_break(0);
5608 finish_cmc_handling (cmc); 5527 finish_cmc_handling(cmc);
5609 return; 5528 return;
5610 } 5529 }
5611 5530
5612 /* reassemble */ 5531 /* reassemble */
5613 fsize = ntohs (fb->header.size) - sizeof (*fb); 5532 fsize = ntohs(fb->header.size) - sizeof(*fb);
5614 if (0 == fsize) 5533 if (0 == fsize)
5615 { 5534 {
5616 GNUNET_break (0); 5535 GNUNET_break(0);
5617 finish_cmc_handling (cmc); 5536 finish_cmc_handling(cmc);
5618 return; 5537 return;
5619 } 5538 }
5620 frag_off = ntohs (fb->frag_off); 5539 frag_off = ntohs(fb->frag_off);
5621 if (frag_off + fsize > msize) 5540 if (frag_off + fsize > msize)
5622 { 5541 {
5623 /* Fragment (plus fragment size) exceeds message size! */ 5542 /* Fragment (plus fragment size) exceeds message size! */
5624 GNUNET_break_op (0); 5543 GNUNET_break_op(0);
5625 finish_cmc_handling (cmc); 5544 finish_cmc_handling(cmc);
5626 return; 5545 return;
5627 } 5546 }
5628 memcpy (&target[frag_off], &fb[1], fsize); 5547 memcpy(&target[frag_off], &fb[1], fsize);
5629 /* update bitfield and msg_missing */ 5548 /* update bitfield and msg_missing */
5630 for (unsigned int i = frag_off; i < frag_off + fsize; i++) 5549 for (unsigned int i = frag_off; i < frag_off + fsize; i++)
5631 {
5632 if (0 == (rc->bitfield[i / 8] & (1 << (i % 8))))
5633 { 5550 {
5634 rc->bitfield[i / 8] |= (1 << (i % 8)); 5551 if (0 == (rc->bitfield[i / 8] & (1 << (i % 8))))
5635 rc->msg_missing--; 5552 {
5553 rc->bitfield[i / 8] |= (1 << (i % 8));
5554 rc->msg_missing--;
5555 }
5636 } 5556 }
5637 }
5638 5557
5639 /* Compute cummulative ACK */ 5558 /* Compute cummulative ACK */
5640 cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag); 5559 cdelay = GNUNET_TIME_absolute_get_duration(rc->last_frag);
5641 cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->msg_missing / fsize); 5560 cdelay = GNUNET_TIME_relative_multiply(cdelay, rc->msg_missing / fsize);
5642 if (0 == rc->msg_missing) 5561 if (0 == rc->msg_missing)
5643 cdelay = GNUNET_TIME_UNIT_ZERO; 5562 cdelay = GNUNET_TIME_UNIT_ZERO;
5644 cummulative_ack (&cmc->im.sender, 5563 cummulative_ack(&cmc->im.sender,
5645 &fb->ack_uuid, 5564 &fb->ack_uuid,
5646 GNUNET_TIME_relative_to_absolute (cdelay)); 5565 GNUNET_TIME_relative_to_absolute(cdelay));
5647 rc->last_frag = GNUNET_TIME_absolute_get (); 5566 rc->last_frag = GNUNET_TIME_absolute_get();
5648 /* is reassembly complete? */ 5567 /* is reassembly complete? */
5649 if (0 != rc->msg_missing) 5568 if (0 != rc->msg_missing)
5650 { 5569 {
5651 finish_cmc_handling (cmc); 5570 finish_cmc_handling(cmc);
5652 return; 5571 return;
5653 } 5572 }
5654 /* reassembly is complete, verify result */ 5573 /* reassembly is complete, verify result */
5655 msg = (const struct GNUNET_MessageHeader *) &rc[1]; 5574 msg = (const struct GNUNET_MessageHeader *)&rc[1];
5656 if (ntohs (msg->size) != rc->msg_size) 5575 if (ntohs(msg->size) != rc->msg_size)
5657 { 5576 {
5658 GNUNET_break (0); 5577 GNUNET_break(0);
5659 free_reassembly_context (rc); 5578 free_reassembly_context(rc);
5660 finish_cmc_handling (cmc); 5579 finish_cmc_handling(cmc);
5661 return; 5580 return;
5662 } 5581 }
5663 /* successful reassembly */ 5582 /* successful reassembly */
5664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5583 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5665 "Fragment reassembly complete for message %u\n", 5584 "Fragment reassembly complete for message %u\n",
5666 (unsigned int) fb->msg_uuid.uuid); 5585 (unsigned int)fb->msg_uuid.uuid);
5667 /* FIXME: check that the resulting msg is NOT a 5586 /* FIXME: check that the resulting msg is NOT a
5668 DV Box or Reliability Box, as that is NOT allowed! */ 5587 DV Box or Reliability Box, as that is NOT allowed! */
5669 demultiplex_with_cmc (cmc, msg); 5588 demultiplex_with_cmc(cmc, msg);
5670 /* FIXME-OPTIMIZE: really free here? Might be bad if fragments are still 5589 /* FIXME-OPTIMIZE: really free here? Might be bad if fragments are still
5671 en-route and we forget that we finished this reassembly immediately! 5590 en-route and we forget that we finished this reassembly immediately!
5672 -> keep around until timeout? 5591 -> keep around until timeout?
5673 -> shorten timeout based on ACK? */ 5592 -> shorten timeout based on ACK? */
5674 free_reassembly_context (rc); 5593 free_reassembly_context(rc);
5675} 5594}
5676 5595
5677 5596
@@ -5683,11 +5602,11 @@ handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
5683 * @return #GNUNET_YES if message is well-formed 5602 * @return #GNUNET_YES if message is well-formed
5684 */ 5603 */
5685static int 5604static int
5686check_reliability_box (void *cls, 5605check_reliability_box(void *cls,
5687 const struct TransportReliabilityBoxMessage *rb) 5606 const struct TransportReliabilityBoxMessage *rb)
5688{ 5607{
5689 (void) cls; 5608 (void)cls;
5690 GNUNET_MQ_check_boxed_message (rb); 5609 GNUNET_MQ_check_boxed_message(rb);
5691 return GNUNET_YES; 5610 return GNUNET_YES;
5692} 5611}
5693 5612
@@ -5700,34 +5619,34 @@ check_reliability_box (void *cls,
5700 * @param rb the message that was received 5619 * @param rb the message that was received
5701 */ 5620 */
5702static void 5621static void
5703handle_reliability_box (void *cls, 5622handle_reliability_box(void *cls,
5704 const struct TransportReliabilityBoxMessage *rb) 5623 const struct TransportReliabilityBoxMessage *rb)
5705{ 5624{
5706 struct CommunicatorMessageContext *cmc = cls; 5625 struct CommunicatorMessageContext *cmc = cls;
5707 const struct GNUNET_MessageHeader *inbox = 5626 const struct GNUNET_MessageHeader *inbox =
5708 (const struct GNUNET_MessageHeader *) &rb[1]; 5627 (const struct GNUNET_MessageHeader *)&rb[1];
5709 struct GNUNET_TIME_Relative rtt; 5628 struct GNUNET_TIME_Relative rtt;
5710 5629
5711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5630 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5712 "Received reliability box from %s with UUID %s of type %u\n", 5631 "Received reliability box from %s with UUID %s of type %u\n",
5713 GNUNET_i2s (&cmc->im.sender), 5632 GNUNET_i2s(&cmc->im.sender),
5714 GNUNET_uuid2s (&rb->ack_uuid.value), 5633 GNUNET_uuid2s(&rb->ack_uuid.value),
5715 (unsigned int) ntohs (inbox->type)); 5634 (unsigned int)ntohs(inbox->type));
5716 rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we 5635 rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we
5717 do not really have an RTT for the 5636 do not really have an RTT for the
5718 *incoming* queue (should we have 5637 * incoming* queue (should we have
5719 the sender add it to the rb message?) */ 5638 the sender add it to the rb message?) */
5720 cummulative_ack ( 5639 cummulative_ack(
5721 &cmc->im.sender, 5640 &cmc->im.sender,
5722 &rb->ack_uuid, 5641 &rb->ack_uuid,
5723 (0 == ntohl (rb->ack_countdown)) 5642 (0 == ntohl(rb->ack_countdown))
5724 ? GNUNET_TIME_UNIT_ZERO_ABS 5643 ? GNUNET_TIME_UNIT_ZERO_ABS
5725 : GNUNET_TIME_relative_to_absolute ( 5644 : GNUNET_TIME_relative_to_absolute(
5726 GNUNET_TIME_relative_divide (rtt, 8 /* FIXME: magic constant */))); 5645 GNUNET_TIME_relative_divide(rtt, 8 /* FIXME: magic constant */)));
5727 /* continue with inner message */ 5646 /* continue with inner message */
5728 /* FIXME: check that inbox is NOT a DV Box, fragment or another 5647 /* FIXME: check that inbox is NOT a DV Box, fragment or another
5729 reliability box (not allowed!) */ 5648 reliability box (not allowed!) */
5730 demultiplex_with_cmc (cmc, inbox); 5649 demultiplex_with_cmc(cmc, inbox);
5731} 5650}
5732 5651
5733 5652
@@ -5740,20 +5659,20 @@ handle_reliability_box (void *cls,
5740 * @param age current age 5659 * @param age current age
5741 */ 5660 */
5742static void 5661static void
5743update_pd_age (struct PerformanceData *pd, unsigned int age) 5662update_pd_age(struct PerformanceData *pd, unsigned int age)
5744{ 5663{
5745 unsigned int sage; 5664 unsigned int sage;
5746 5665
5747 if (age == pd->last_age) 5666 if (age == pd->last_age)
5748 return; /* nothing to do */ 5667 return; /* nothing to do */
5749 sage = GNUNET_MAX (pd->last_age, age - 2 * GOODPUT_AGING_SLOTS); 5668 sage = GNUNET_MAX(pd->last_age, age - 2 * GOODPUT_AGING_SLOTS);
5750 for (unsigned int i = sage; i <= age - GOODPUT_AGING_SLOTS; i++) 5669 for (unsigned int i = sage; i <= age - GOODPUT_AGING_SLOTS; i++)
5751 { 5670 {
5752 struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS]; 5671 struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS];
5753 5672
5754 the->bytes_sent = 0; 5673 the->bytes_sent = 0;
5755 the->bytes_received = 0; 5674 the->bytes_received = 0;
5756 } 5675 }
5757 pd->last_age = age; 5676 pd->last_age = age;
5758} 5677}
5759 5678
@@ -5767,20 +5686,20 @@ update_pd_age (struct PerformanceData *pd, unsigned int age)
5767 * @param bytes_transmitted_ok number of bytes receiver confirmed as received 5686 * @param bytes_transmitted_ok number of bytes receiver confirmed as received
5768 */ 5687 */
5769static void 5688static void
5770update_performance_data (struct PerformanceData *pd, 5689update_performance_data(struct PerformanceData *pd,
5771 struct GNUNET_TIME_Relative rtt, 5690 struct GNUNET_TIME_Relative rtt,
5772 uint16_t bytes_transmitted_ok) 5691 uint16_t bytes_transmitted_ok)
5773{ 5692{
5774 uint64_t nval = rtt.rel_value_us; 5693 uint64_t nval = rtt.rel_value_us;
5775 uint64_t oval = pd->aged_rtt.rel_value_us; 5694 uint64_t oval = pd->aged_rtt.rel_value_us;
5776 unsigned int age = get_age (); 5695 unsigned int age = get_age();
5777 struct TransmissionHistoryEntry *the = &pd->the[age % GOODPUT_AGING_SLOTS]; 5696 struct TransmissionHistoryEntry *the = &pd->the[age % GOODPUT_AGING_SLOTS];
5778 5697
5779 if (oval == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) 5698 if (oval == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
5780 pd->aged_rtt = rtt; 5699 pd->aged_rtt = rtt;
5781 else 5700 else
5782 pd->aged_rtt.rel_value_us = (nval + 7 * oval) / 8; 5701 pd->aged_rtt.rel_value_us = (nval + 7 * oval) / 8;
5783 update_pd_age (pd, age); 5702 update_pd_age(pd, age);
5784 the->bytes_received += bytes_transmitted_ok; 5703 the->bytes_received += bytes_transmitted_ok;
5785} 5704}
5786 5705
@@ -5793,11 +5712,11 @@ update_performance_data (struct PerformanceData *pd,
5793 * @param bytes_transmitted_ok number of bytes successfully transmitted 5712 * @param bytes_transmitted_ok number of bytes successfully transmitted
5794 */ 5713 */
5795static void 5714static void
5796update_queue_performance (struct Queue *q, 5715update_queue_performance(struct Queue *q,
5797 struct GNUNET_TIME_Relative rtt, 5716 struct GNUNET_TIME_Relative rtt,
5798 uint16_t bytes_transmitted_ok) 5717 uint16_t bytes_transmitted_ok)
5799{ 5718{
5800 update_performance_data (&q->pd, rtt, bytes_transmitted_ok); 5719 update_performance_data(&q->pd, rtt, bytes_transmitted_ok);
5801} 5720}
5802 5721
5803 5722
@@ -5809,11 +5728,11 @@ update_queue_performance (struct Queue *q,
5809 * @param bytes_transmitted_ok number of bytes successfully transmitted 5728 * @param bytes_transmitted_ok number of bytes successfully transmitted
5810 */ 5729 */
5811static void 5730static void
5812update_dvh_performance (struct DistanceVectorHop *dvh, 5731update_dvh_performance(struct DistanceVectorHop *dvh,
5813 struct GNUNET_TIME_Relative rtt, 5732 struct GNUNET_TIME_Relative rtt,
5814 uint16_t bytes_transmitted_ok) 5733 uint16_t bytes_transmitted_ok)
5815{ 5734{
5816 update_performance_data (&dvh->pd, rtt, bytes_transmitted_ok); 5735 update_performance_data(&dvh->pd, rtt, bytes_transmitted_ok);
5817} 5736}
5818 5737
5819 5738
@@ -5825,45 +5744,47 @@ update_dvh_performance (struct DistanceVectorHop *dvh,
5825 * @param pm pending message that was transmitted 5744 * @param pm pending message that was transmitted
5826 */ 5745 */
5827static void 5746static void
5828completed_pending_message (struct PendingMessage *pm) 5747completed_pending_message(struct PendingMessage *pm)
5829{ 5748{
5830 struct PendingMessage *pos; 5749 struct PendingMessage *pos;
5831 5750
5832 switch (pm->pmt) 5751 switch (pm->pmt)
5833 { 5752 {
5834 case PMT_CORE: 5753 case PMT_CORE:
5835 case PMT_RELIABILITY_BOX: 5754 case PMT_RELIABILITY_BOX:
5836 /* Full message sent, we are done */ 5755 /* Full message sent, we are done */
5837 client_send_response (pm); 5756 client_send_response(pm);
5838 return; 5757 return;
5839 case PMT_FRAGMENT_BOX: 5758
5840 /* Fragment sent over reliabile channel */ 5759 case PMT_FRAGMENT_BOX:
5841 free_fragment_tree (pm); 5760 /* Fragment sent over reliabile channel */
5842 pos = pm->frag_parent; 5761 free_fragment_tree(pm);
5843 GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm);
5844 GNUNET_free (pm);
5845 /* check if subtree is done */
5846 while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) &&
5847 (pos != pm))
5848 {
5849 pm = pos;
5850 pos = pm->frag_parent; 5762 pos = pm->frag_parent;
5851 GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm); 5763 GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm);
5852 GNUNET_free (pm); 5764 GNUNET_free(pm);
5853 } 5765 /* check if subtree is done */
5766 while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) &&
5767 (pos != pm))
5768 {
5769 pm = pos;
5770 pos = pm->frag_parent;
5771 GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm);
5772 GNUNET_free(pm);
5773 }
5854 5774
5855 /* Was this the last applicable fragmment? */ 5775 /* Was this the last applicable fragmment? */
5856 if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) && 5776 if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) &&
5857 (pos->frag_off == pos->bytes_msg)) 5777 (pos->frag_off == pos->bytes_msg))
5858 client_send_response (pos); 5778 client_send_response(pos);
5859 return; 5779 return;
5860 case PMT_DV_BOX: 5780
5861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5781 case PMT_DV_BOX:
5862 "Completed transmission of message %llu (DV Box)\n", 5782 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5863 pm->logging_uuid); 5783 "Completed transmission of message %llu (DV Box)\n",
5864 free_pending_message (pm); 5784 pm->logging_uuid);
5865 return; 5785 free_pending_message(pm);
5866 } 5786 return;
5787 }
5867} 5788}
5868 5789
5869 5790
@@ -5875,23 +5796,23 @@ completed_pending_message (struct PendingMessage *pm)
5875 * other peer 5796 * other peer
5876 */ 5797 */
5877static void 5798static void
5878handle_acknowledged (struct PendingAcknowledgement *pa, 5799handle_acknowledged(struct PendingAcknowledgement *pa,
5879 struct GNUNET_TIME_Relative ack_delay) 5800 struct GNUNET_TIME_Relative ack_delay)
5880{ 5801{
5881 struct GNUNET_TIME_Relative delay; 5802 struct GNUNET_TIME_Relative delay;
5882 5803
5883 delay = GNUNET_TIME_absolute_get_duration (pa->transmission_time); 5804 delay = GNUNET_TIME_absolute_get_duration(pa->transmission_time);
5884 if (delay.rel_value_us > ack_delay.rel_value_us) 5805 if (delay.rel_value_us > ack_delay.rel_value_us)
5885 delay = GNUNET_TIME_UNIT_ZERO; 5806 delay = GNUNET_TIME_UNIT_ZERO;
5886 else 5807 else
5887 delay = GNUNET_TIME_relative_subtract (delay, ack_delay); 5808 delay = GNUNET_TIME_relative_subtract(delay, ack_delay);
5888 if (NULL != pa->queue) 5809 if (NULL != pa->queue)
5889 update_queue_performance (pa->queue, delay, pa->message_size); 5810 update_queue_performance(pa->queue, delay, pa->message_size);
5890 if (NULL != pa->dvh) 5811 if (NULL != pa->dvh)
5891 update_dvh_performance (pa->dvh, delay, pa->message_size); 5812 update_dvh_performance(pa->dvh, delay, pa->message_size);
5892 if (NULL != pa->pm) 5813 if (NULL != pa->pm)
5893 completed_pending_message (pa->pm); 5814 completed_pending_message(pa->pm);
5894 free_pending_acknowledgement (pa); 5815 free_pending_acknowledgement(pa);
5895} 5816}
5896 5817
5897 5818
@@ -5903,25 +5824,25 @@ handle_acknowledged (struct PendingAcknowledgement *pa,
5903 * @return #GNUNET_Ok if @a ra is well-formed 5824 * @return #GNUNET_Ok if @a ra is well-formed
5904 */ 5825 */
5905static int 5826static int
5906check_reliability_ack (void *cls, 5827check_reliability_ack(void *cls,
5907 const struct TransportReliabilityAckMessage *ra) 5828 const struct TransportReliabilityAckMessage *ra)
5908{ 5829{
5909 unsigned int n_acks; 5830 unsigned int n_acks;
5910 5831
5911 (void) cls; 5832 (void)cls;
5912 n_acks = (ntohs (ra->header.size) - sizeof (*ra)) / 5833 n_acks = (ntohs(ra->header.size) - sizeof(*ra)) /
5913 sizeof (struct TransportCummulativeAckPayloadP); 5834 sizeof(struct TransportCummulativeAckPayloadP);
5914 if (0 == n_acks) 5835 if (0 == n_acks)
5915 { 5836 {
5916 GNUNET_break_op (0); 5837 GNUNET_break_op(0);
5917 return GNUNET_SYSERR; 5838 return GNUNET_SYSERR;
5918 } 5839 }
5919 if ((ntohs (ra->header.size) - sizeof (*ra)) != 5840 if ((ntohs(ra->header.size) - sizeof(*ra)) !=
5920 n_acks * sizeof (struct TransportCummulativeAckPayloadP)) 5841 n_acks * sizeof(struct TransportCummulativeAckPayloadP))
5921 { 5842 {
5922 GNUNET_break_op (0); 5843 GNUNET_break_op(0);
5923 return GNUNET_SYSERR; 5844 return GNUNET_SYSERR;
5924 } 5845 }
5925 return GNUNET_OK; 5846 return GNUNET_OK;
5926} 5847}
5927 5848
@@ -5934,46 +5855,46 @@ check_reliability_ack (void *cls,
5934 * @param ra the message that was received 5855 * @param ra the message that was received
5935 */ 5856 */
5936static void 5857static void
5937handle_reliability_ack (void *cls, 5858handle_reliability_ack(void *cls,
5938 const struct TransportReliabilityAckMessage *ra) 5859 const struct TransportReliabilityAckMessage *ra)
5939{ 5860{
5940 struct CommunicatorMessageContext *cmc = cls; 5861 struct CommunicatorMessageContext *cmc = cls;
5941 const struct TransportCummulativeAckPayloadP *ack; 5862 const struct TransportCummulativeAckPayloadP *ack;
5942 unsigned int n_acks; 5863 unsigned int n_acks;
5943 uint32_t ack_counter; 5864 uint32_t ack_counter;
5944 5865
5945 n_acks = (ntohs (ra->header.size) - sizeof (*ra)) / 5866 n_acks = (ntohs(ra->header.size) - sizeof(*ra)) /
5946 sizeof (struct TransportCummulativeAckPayloadP); 5867 sizeof(struct TransportCummulativeAckPayloadP);
5947 ack = (const struct TransportCummulativeAckPayloadP *) &ra[1]; 5868 ack = (const struct TransportCummulativeAckPayloadP *)&ra[1];
5948 for (unsigned int i = 0; i < n_acks; i++) 5869 for (unsigned int i = 0; i < n_acks; i++)
5949 { 5870 {
5950 struct PendingAcknowledgement *pa = 5871 struct PendingAcknowledgement *pa =
5951 GNUNET_CONTAINER_multiuuidmap_get (pending_acks, &ack[i].ack_uuid.value); 5872 GNUNET_CONTAINER_multiuuidmap_get(pending_acks, &ack[i].ack_uuid.value);
5952 if (NULL == pa) 5873 if (NULL == pa)
5953 { 5874 {
5954 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 5875 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
5955 "Received ACK from %s with UUID %s which is unknown to us!\n", 5876 "Received ACK from %s with UUID %s which is unknown to us!\n",
5956 GNUNET_i2s (&cmc->im.sender), 5877 GNUNET_i2s(&cmc->im.sender),
5957 GNUNET_uuid2s (&ack[i].ack_uuid.value)); 5878 GNUNET_uuid2s(&ack[i].ack_uuid.value));
5958 GNUNET_STATISTICS_update ( 5879 GNUNET_STATISTICS_update(
5959 GST_stats, 5880 GST_stats,
5960 "# FRAGMENT_ACKS dropped, no matching pending message", 5881 "# FRAGMENT_ACKS dropped, no matching pending message",
5961 1, 5882 1,
5962 GNUNET_NO); 5883 GNUNET_NO);
5963 continue; 5884 continue;
5885 }
5886 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5887 "Received ACK from %s with UUID %s\n",
5888 GNUNET_i2s(&cmc->im.sender),
5889 GNUNET_uuid2s(&ack[i].ack_uuid.value));
5890 handle_acknowledged(pa, GNUNET_TIME_relative_ntoh(ack[i].ack_delay));
5964 } 5891 }
5965 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5966 "Received ACK from %s with UUID %s\n",
5967 GNUNET_i2s (&cmc->im.sender),
5968 GNUNET_uuid2s (&ack[i].ack_uuid.value));
5969 handle_acknowledged (pa, GNUNET_TIME_relative_ntoh (ack[i].ack_delay));
5970 }
5971 5892
5972 ack_counter = htonl (ra->ack_counter); 5893 ack_counter = htonl(ra->ack_counter);
5973 (void) ack_counter; /* silence compiler warning for now */ 5894 (void)ack_counter; /* silence compiler warning for now */
5974 // FIXME-OPTIMIZE: track ACK losses based on ack_counter somewhere! 5895 // FIXME-OPTIMIZE: track ACK losses based on ack_counter somewhere!
5975 // (DV and/or Neighbour?) 5896 // (DV and/or Neighbour?)
5976 finish_cmc_handling (cmc); 5897 finish_cmc_handling(cmc);
5977} 5898}
5978 5899
5979 5900
@@ -5985,30 +5906,30 @@ handle_reliability_ack (void *cls,
5985 * @return #GNUNET_YES if message is well-formed 5906 * @return #GNUNET_YES if message is well-formed
5986 */ 5907 */
5987static int 5908static int
5988check_backchannel_encapsulation ( 5909check_backchannel_encapsulation(
5989 void *cls, 5910 void *cls,
5990 const struct TransportBackchannelEncapsulationMessage *be) 5911 const struct TransportBackchannelEncapsulationMessage *be)
5991{ 5912{
5992 uint16_t size = ntohs (be->header.size) - sizeof (*be); 5913 uint16_t size = ntohs(be->header.size) - sizeof(*be);
5993 const struct GNUNET_MessageHeader *inbox = 5914 const struct GNUNET_MessageHeader *inbox =
5994 (const struct GNUNET_MessageHeader *) &be[1]; 5915 (const struct GNUNET_MessageHeader *)&be[1];
5995 const char *is; 5916 const char *is;
5996 uint16_t isize; 5917 uint16_t isize;
5997 5918
5998 (void) cls; 5919 (void)cls;
5999 if (ntohs (inbox->size) >= size) 5920 if (ntohs(inbox->size) >= size)
6000 { 5921 {
6001 GNUNET_break_op (0); 5922 GNUNET_break_op(0);
6002 return GNUNET_SYSERR; 5923 return GNUNET_SYSERR;
6003 } 5924 }
6004 isize = ntohs (inbox->size); 5925 isize = ntohs(inbox->size);
6005 is = ((const char *) inbox) + isize; 5926 is = ((const char *)inbox) + isize;
6006 size -= isize; 5927 size -= isize;
6007 if ('\0' != is[size - 1]) 5928 if ('\0' != is[size - 1])
6008 { 5929 {
6009 GNUNET_break_op (0); 5930 GNUNET_break_op(0);
6010 return GNUNET_SYSERR; 5931 return GNUNET_SYSERR;
6011 } 5932 }
6012 return GNUNET_YES; 5933 return GNUNET_YES;
6013} 5934}
6014 5935
@@ -6022,7 +5943,7 @@ check_backchannel_encapsulation (
6022 * @param be the message that was received 5943 * @param be the message that was received
6023 */ 5944 */
6024static void 5945static void
6025handle_backchannel_encapsulation ( 5946handle_backchannel_encapsulation(
6026 void *cls, 5947 void *cls,
6027 const struct TransportBackchannelEncapsulationMessage *be) 5948 const struct TransportBackchannelEncapsulationMessage *be)
6028{ 5949{
@@ -6031,41 +5952,41 @@ handle_backchannel_encapsulation (
6031 struct GNUNET_MQ_Envelope *env; 5952 struct GNUNET_MQ_Envelope *env;
6032 struct TransportClient *tc; 5953 struct TransportClient *tc;
6033 const struct GNUNET_MessageHeader *inbox = 5954 const struct GNUNET_MessageHeader *inbox =
6034 (const struct GNUNET_MessageHeader *) &be[1]; 5955 (const struct GNUNET_MessageHeader *)&be[1];
6035 uint16_t isize = ntohs (inbox->size); 5956 uint16_t isize = ntohs(inbox->size);
6036 const char *target_communicator = ((const char *) inbox) + isize; 5957 const char *target_communicator = ((const char *)inbox) + isize;
6037 5958
6038 /* Find client providing this communicator */ 5959 /* Find client providing this communicator */
6039 for (tc = clients_head; NULL != tc; tc = tc->next) 5960 for (tc = clients_head; NULL != tc; tc = tc->next)
6040 if ((CT_COMMUNICATOR == tc->type) && 5961 if ((CT_COMMUNICATOR == tc->type) &&
6041 (0 == 5962 (0 ==
6042 strcmp (tc->details.communicator.address_prefix, target_communicator))) 5963 strcmp(tc->details.communicator.address_prefix, target_communicator)))
6043 break; 5964 break;
6044 if (NULL == tc) 5965 if (NULL == tc)
6045 { 5966 {
6046 char *stastr; 5967 char *stastr;
6047 5968
6048 GNUNET_asprintf ( 5969 GNUNET_asprintf(
6049 &stastr, 5970 &stastr,
6050 "# Backchannel message dropped: target communicator `%s' unknown", 5971 "# Backchannel message dropped: target communicator `%s' unknown",
6051 target_communicator); 5972 target_communicator);
6052 GNUNET_STATISTICS_update (GST_stats, stastr, 1, GNUNET_NO); 5973 GNUNET_STATISTICS_update(GST_stats, stastr, 1, GNUNET_NO);
6053 GNUNET_free (stastr); 5974 GNUNET_free(stastr);
6054 return; 5975 return;
6055 } 5976 }
6056 /* Finally, deliver backchannel message to communicator */ 5977 /* Finally, deliver backchannel message to communicator */
6057 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5978 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6058 "Delivering backchannel message from %s of type %u to %s\n", 5979 "Delivering backchannel message from %s of type %u to %s\n",
6059 GNUNET_i2s (&cmc->im.sender), 5980 GNUNET_i2s(&cmc->im.sender),
6060 ntohs (inbox->type), 5981 ntohs(inbox->type),
6061 target_communicator); 5982 target_communicator);
6062 env = GNUNET_MQ_msg_extra ( 5983 env = GNUNET_MQ_msg_extra(
6063 cbi, 5984 cbi,
6064 isize, 5985 isize,
6065 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING); 5986 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING);
6066 cbi->pid = cmc->im.sender; 5987 cbi->pid = cmc->im.sender;
6067 memcpy (&cbi[1], inbox, isize); 5988 memcpy(&cbi[1], inbox, isize);
6068 GNUNET_MQ_send (tc->mq, env); 5989 GNUNET_MQ_send(tc->mq, env);
6069} 5990}
6070 5991
6071 5992
@@ -6079,26 +6000,26 @@ handle_backchannel_encapsulation (
6079 * @param cls a `struct DistanceVector` 6000 * @param cls a `struct DistanceVector`
6080 */ 6001 */
6081static void 6002static void
6082path_cleanup_cb (void *cls) 6003path_cleanup_cb(void *cls)
6083{ 6004{
6084 struct DistanceVector *dv = cls; 6005 struct DistanceVector *dv = cls;
6085 struct DistanceVectorHop *pos; 6006 struct DistanceVectorHop *pos;
6086 6007
6087 dv->timeout_task = NULL; 6008 dv->timeout_task = NULL;
6088 while (NULL != (pos = dv->dv_head)) 6009 while (NULL != (pos = dv->dv_head))
6089 { 6010 {
6090 GNUNET_assert (dv == pos->dv); 6011 GNUNET_assert(dv == pos->dv);
6091 if (GNUNET_TIME_absolute_get_remaining (pos->timeout).rel_value_us > 0) 6012 if (GNUNET_TIME_absolute_get_remaining(pos->timeout).rel_value_us > 0)
6092 break; 6013 break;
6093 free_distance_vector_hop (pos); 6014 free_distance_vector_hop(pos);
6094 } 6015 }
6095 if (NULL == pos) 6016 if (NULL == pos)
6096 { 6017 {
6097 free_dv_route (dv); 6018 free_dv_route(dv);
6098 return; 6019 return;
6099 } 6020 }
6100 dv->timeout_task = 6021 dv->timeout_task =
6101 GNUNET_SCHEDULER_add_at (pos->timeout, &path_cleanup_cb, dv); 6022 GNUNET_SCHEDULER_add_at(pos->timeout, &path_cleanup_cb, dv);
6102} 6023}
6103 6024
6104 6025
@@ -6110,44 +6031,44 @@ path_cleanup_cb (void *cls)
6110 * @param hop a path to some peer that is the reason for activation 6031 * @param hop a path to some peer that is the reason for activation
6111 */ 6032 */
6112static void 6033static void
6113activate_core_visible_dv_path (struct DistanceVectorHop *hop) 6034activate_core_visible_dv_path(struct DistanceVectorHop *hop)
6114{ 6035{
6115 struct DistanceVector *dv = hop->dv; 6036 struct DistanceVector *dv = hop->dv;
6116 struct VirtualLink *vl; 6037 struct VirtualLink *vl;
6117 6038
6118 vl = lookup_virtual_link (&dv->target); 6039 vl = lookup_virtual_link(&dv->target);
6119 if (NULL != vl) 6040 if (NULL != vl)
6120 { 6041 {
6121 /* Link was already up, remember dv is also now available and we are done */ 6042 /* Link was already up, remember dv is also now available and we are done */
6122 vl->dv = dv; 6043 vl->dv = dv;
6123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6044 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6124 "Virtual link to %s could now also use DV!\n", 6045 "Virtual link to %s could now also use DV!\n",
6125 GNUNET_i2s (&dv->target)); 6046 GNUNET_i2s(&dv->target));
6126 return; 6047 return;
6127 } 6048 }
6128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6049 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6129 "Creating new virtual link to %s using DV!\n", 6050 "Creating new virtual link to %s using DV!\n",
6130 GNUNET_i2s (&dv->target)); 6051 GNUNET_i2s(&dv->target));
6131 vl = GNUNET_new (struct VirtualLink); 6052 vl = GNUNET_new(struct VirtualLink);
6132 vl->message_uuid_ctr = 6053 vl->message_uuid_ctr =
6133 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 6054 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
6134 vl->target = dv->target; 6055 vl->target = dv->target;
6135 vl->dv = dv; 6056 vl->dv = dv;
6136 dv->vl = vl; 6057 dv->vl = vl;
6137 vl->core_recv_window = RECV_WINDOW_SIZE; 6058 vl->core_recv_window = RECV_WINDOW_SIZE;
6138 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; 6059 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE;
6139 vl->visibility_task = 6060 vl->visibility_task =
6140 GNUNET_SCHEDULER_add_at (hop->path_valid_until, &check_link_down, vl); 6061 GNUNET_SCHEDULER_add_at(hop->path_valid_until, &check_link_down, vl);
6141 GNUNET_break (GNUNET_YES == 6062 GNUNET_break(GNUNET_YES ==
6142 GNUNET_CONTAINER_multipeermap_put ( 6063 GNUNET_CONTAINER_multipeermap_put(
6143 links, 6064 links,
6144 &vl->target, 6065 &vl->target,
6145 vl, 6066 vl,
6146 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6067 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
6147 consider_sending_fc (vl); 6068 consider_sending_fc(vl);
6148 /* We lacked a confirmed connection to the target 6069 /* We lacked a confirmed connection to the target
6149 before, so tell CORE about it (finally!) */ 6070 before, so tell CORE about it (finally!) */
6150 cores_send_connect_info (&dv->target); 6071 cores_send_connect_info(&dv->target);
6151} 6072}
6152 6073
6153 6074
@@ -6177,10 +6098,10 @@ activate_core_visible_dv_path (struct DistanceVectorHop *hop)
6177 * or path[i+1] is a direct neighbour for i>0) 6098 * or path[i+1] is a direct neighbour for i>0)
6178 */ 6099 */
6179static int 6100static int
6180learn_dv_path (const struct GNUNET_PeerIdentity *path, 6101learn_dv_path(const struct GNUNET_PeerIdentity *path,
6181 unsigned int path_len, 6102 unsigned int path_len,
6182 struct GNUNET_TIME_Relative network_latency, 6103 struct GNUNET_TIME_Relative network_latency,
6183 struct GNUNET_TIME_Absolute path_valid_until) 6104 struct GNUNET_TIME_Absolute path_valid_until)
6184{ 6105{
6185 struct DistanceVectorHop *hop; 6106 struct DistanceVectorHop *hop;
6186 struct DistanceVector *dv; 6107 struct DistanceVector *dv;
@@ -6188,143 +6109,143 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
6188 unsigned int shorter_distance; 6109 unsigned int shorter_distance;
6189 6110
6190 if (path_len < 3) 6111 if (path_len < 3)
6191 { 6112 {
6192 /* what a boring path! not allowed! */ 6113 /* what a boring path! not allowed! */
6193 GNUNET_break (0); 6114 GNUNET_break(0);
6194 return GNUNET_SYSERR; 6115 return GNUNET_SYSERR;
6195 } 6116 }
6196 GNUNET_assert (0 == GNUNET_memcmp (&GST_my_identity, &path[0])); 6117 GNUNET_assert(0 == GNUNET_memcmp(&GST_my_identity, &path[0]));
6197 next_hop = lookup_neighbour (&path[1]); 6118 next_hop = lookup_neighbour(&path[1]);
6198 if (NULL == next_hop) 6119 if (NULL == next_hop)
6199 { 6120 {
6200 /* next hop must be a neighbour, otherwise this whole thing is useless! */ 6121 /* next hop must be a neighbour, otherwise this whole thing is useless! */
6201 GNUNET_break (0); 6122 GNUNET_break(0);
6202 return GNUNET_SYSERR;
6203 }
6204 for (unsigned int i = 2; i < path_len; i++)
6205 if (NULL != lookup_neighbour (&path[i]))
6206 {
6207 /* Useless path: we have a direct connection to some hop
6208 in the middle of the path, so this one is not even
6209 terribly useful for redundancy */
6210 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
6211 "Path of %u hops useless: directly link to hop %u (%s)\n",
6212 path_len,
6213 i,
6214 GNUNET_i2s (&path[i]));
6215 GNUNET_STATISTICS_update (GST_stats,
6216 "# Useless DV path ignored: hop is neighbour",
6217 1,
6218 GNUNET_NO);
6219 return GNUNET_SYSERR; 6123 return GNUNET_SYSERR;
6220 } 6124 }
6221 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &path[path_len - 1]); 6125 for (unsigned int i = 2; i < path_len; i++)
6126 if (NULL != lookup_neighbour(&path[i]))
6127 {
6128 /* Useless path: we have a direct connection to some hop
6129 in the middle of the path, so this one is not even
6130 terribly useful for redundancy */
6131 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
6132 "Path of %u hops useless: directly link to hop %u (%s)\n",
6133 path_len,
6134 i,
6135 GNUNET_i2s(&path[i]));
6136 GNUNET_STATISTICS_update(GST_stats,
6137 "# Useless DV path ignored: hop is neighbour",
6138 1,
6139 GNUNET_NO);
6140 return GNUNET_SYSERR;
6141 }
6142 dv = GNUNET_CONTAINER_multipeermap_get(dv_routes, &path[path_len - 1]);
6222 if (NULL == dv) 6143 if (NULL == dv)
6223 { 6144 {
6224 dv = GNUNET_new (struct DistanceVector); 6145 dv = GNUNET_new(struct DistanceVector);
6225 dv->target = path[path_len - 1]; 6146 dv->target = path[path_len - 1];
6226 dv->timeout_task = GNUNET_SCHEDULER_add_delayed (DV_PATH_VALIDITY_TIMEOUT, 6147 dv->timeout_task = GNUNET_SCHEDULER_add_delayed(DV_PATH_VALIDITY_TIMEOUT,
6227 &path_cleanup_cb, 6148 &path_cleanup_cb,
6228 dv); 6149 dv);
6229 GNUNET_assert (GNUNET_OK == 6150 GNUNET_assert(GNUNET_OK ==
6230 GNUNET_CONTAINER_multipeermap_put ( 6151 GNUNET_CONTAINER_multipeermap_put(
6231 dv_routes, 6152 dv_routes,
6232 &dv->target, 6153 &dv->target,
6233 dv, 6154 dv,
6234 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6155 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
6235 } 6156 }
6236 /* Check if we have this path already! */ 6157 /* Check if we have this path already! */
6237 shorter_distance = 0; 6158 shorter_distance = 0;
6238 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 6159 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
6239 pos = pos->next_dv) 6160 pos = pos->next_dv)
6240 {
6241 if (pos->distance < path_len - 2)
6242 shorter_distance++;
6243 /* Note that the distances in 'pos' excludes us (path[0]) and
6244 the next_hop (path[1]), so we need to subtract two
6245 and check next_hop explicitly */
6246 if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop))
6247 { 6161 {
6248 int match = GNUNET_YES; 6162 if (pos->distance < path_len - 2)
6249 6163 shorter_distance++;
6250 for (unsigned int i = 0; i < pos->distance; i++) 6164 /* Note that the distances in 'pos' excludes us (path[0]) and
6251 { 6165 the next_hop (path[1]), so we need to subtract two
6252 if (0 != GNUNET_memcmp (&pos->path[i], &path[i + 2])) 6166 and check next_hop explicitly */
6167 if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop))
6253 { 6168 {
6254 match = GNUNET_NO; 6169 int match = GNUNET_YES;
6255 break; 6170
6256 } 6171 for (unsigned int i = 0; i < pos->distance; i++)
6257 } 6172 {
6258 if (GNUNET_YES == match) 6173 if (0 != GNUNET_memcmp(&pos->path[i], &path[i + 2]))
6259 { 6174 {
6260 struct GNUNET_TIME_Relative last_timeout; 6175 match = GNUNET_NO;
6261 6176 break;
6262 /* Re-discovered known path, update timeout */ 6177 }
6263 GNUNET_STATISTICS_update (GST_stats, 6178 }
6264 "# Known DV path refreshed", 6179 if (GNUNET_YES == match)
6265 1, 6180 {
6266 GNUNET_NO); 6181 struct GNUNET_TIME_Relative last_timeout;
6267 last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout); 6182
6268 pos->timeout = 6183 /* Re-discovered known path, update timeout */
6269 GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); 6184 GNUNET_STATISTICS_update(GST_stats,
6270 pos->path_valid_until = 6185 "# Known DV path refreshed",
6271 GNUNET_TIME_absolute_max (pos->path_valid_until, path_valid_until); 6186 1,
6272 GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, pos); 6187 GNUNET_NO);
6273 GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, pos); 6188 last_timeout = GNUNET_TIME_absolute_get_remaining(pos->timeout);
6274 if (0 < 6189 pos->timeout =
6275 GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us) 6190 GNUNET_TIME_relative_to_absolute(DV_PATH_VALIDITY_TIMEOUT);
6276 activate_core_visible_dv_path (pos); 6191 pos->path_valid_until =
6277 if (last_timeout.rel_value_us < 6192 GNUNET_TIME_absolute_max(pos->path_valid_until, path_valid_until);
6278 GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT, 6193 GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, pos);
6279 DV_PATH_DISCOVERY_FREQUENCY) 6194 GNUNET_CONTAINER_MDLL_insert(dv, dv->dv_head, dv->dv_tail, pos);
6280 .rel_value_us) 6195 if (0 <
6281 { 6196 GNUNET_TIME_absolute_get_remaining(path_valid_until).rel_value_us)
6282 /* Some peer send DV learn messages too often, we are learning 6197 activate_core_visible_dv_path(pos);
6283 the same path faster than it would be useful; do not forward! */ 6198 if (last_timeout.rel_value_us <
6284 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 6199 GNUNET_TIME_relative_subtract(DV_PATH_VALIDITY_TIMEOUT,
6285 "Rediscovered path too quickly, not forwarding further\n"); 6200 DV_PATH_DISCOVERY_FREQUENCY)
6286 return GNUNET_NO; 6201 .rel_value_us)
6202 {
6203 /* Some peer send DV learn messages too often, we are learning
6204 the same path faster than it would be useful; do not forward! */
6205 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
6206 "Rediscovered path too quickly, not forwarding further\n");
6207 return GNUNET_NO;
6208 }
6209 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6210 "Refreshed known path to %s, forwarding further\n",
6211 GNUNET_i2s(&dv->target));
6212 return GNUNET_YES;
6213 }
6287 } 6214 }
6288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6289 "Refreshed known path to %s, forwarding further\n",
6290 GNUNET_i2s (&dv->target));
6291 return GNUNET_YES;
6292 }
6293 } 6215 }
6294 }
6295 /* Count how many shorter paths we have (incl. direct 6216 /* Count how many shorter paths we have (incl. direct
6296 neighbours) before simply giving up on this one! */ 6217 neighbours) before simply giving up on this one! */
6297 if (shorter_distance >= MAX_DV_PATHS_TO_TARGET) 6218 if (shorter_distance >= MAX_DV_PATHS_TO_TARGET)
6298 { 6219 {
6299 /* We have a shorter path already! */ 6220 /* We have a shorter path already! */
6300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6301 "Have many shorter DV paths %s, not forwarding further\n", 6222 "Have many shorter DV paths %s, not forwarding further\n",
6302 GNUNET_i2s (&dv->target)); 6223 GNUNET_i2s(&dv->target));
6303 return GNUNET_NO; 6224 return GNUNET_NO;
6304 } 6225 }
6305 /* create new DV path entry */ 6226 /* create new DV path entry */
6306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6227 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6307 "Discovered new DV path to %s\n", 6228 "Discovered new DV path to %s\n",
6308 GNUNET_i2s (&dv->target)); 6229 GNUNET_i2s(&dv->target));
6309 hop = GNUNET_malloc (sizeof (struct DistanceVectorHop) + 6230 hop = GNUNET_malloc(sizeof(struct DistanceVectorHop) +
6310 sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); 6231 sizeof(struct GNUNET_PeerIdentity) * (path_len - 2));
6311 hop->next_hop = next_hop; 6232 hop->next_hop = next_hop;
6312 hop->dv = dv; 6233 hop->dv = dv;
6313 hop->path = (const struct GNUNET_PeerIdentity *) &hop[1]; 6234 hop->path = (const struct GNUNET_PeerIdentity *)&hop[1];
6314 memcpy (&hop[1], 6235 memcpy(&hop[1],
6315 &path[2], 6236 &path[2],
6316 sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); 6237 sizeof(struct GNUNET_PeerIdentity) * (path_len - 2));
6317 hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); 6238 hop->timeout = GNUNET_TIME_relative_to_absolute(DV_PATH_VALIDITY_TIMEOUT);
6318 hop->path_valid_until = path_valid_until; 6239 hop->path_valid_until = path_valid_until;
6319 hop->distance = path_len - 2; 6240 hop->distance = path_len - 2;
6320 hop->pd.aged_rtt = network_latency; 6241 hop->pd.aged_rtt = network_latency;
6321 GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, hop); 6242 GNUNET_CONTAINER_MDLL_insert(dv, dv->dv_head, dv->dv_tail, hop);
6322 GNUNET_CONTAINER_MDLL_insert (neighbour, 6243 GNUNET_CONTAINER_MDLL_insert(neighbour,
6323 next_hop->dv_head, 6244 next_hop->dv_head,
6324 next_hop->dv_tail, 6245 next_hop->dv_tail,
6325 hop); 6246 hop);
6326 if (0 < GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us) 6247 if (0 < GNUNET_TIME_absolute_get_remaining(path_valid_until).rel_value_us)
6327 activate_core_visible_dv_path (hop); 6248 activate_core_visible_dv_path(hop);
6328 return GNUNET_YES; 6249 return GNUNET_YES;
6329} 6250}
6330 6251
@@ -6337,36 +6258,36 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
6337 * @return #GNUNET_YES if message is well-formed 6258 * @return #GNUNET_YES if message is well-formed
6338 */ 6259 */
6339static int 6260static int
6340check_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) 6261check_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl)
6341{ 6262{
6342 uint16_t size = ntohs (dvl->header.size); 6263 uint16_t size = ntohs(dvl->header.size);
6343 uint16_t num_hops = ntohs (dvl->num_hops); 6264 uint16_t num_hops = ntohs(dvl->num_hops);
6344 const struct DVPathEntryP *hops = (const struct DVPathEntryP *) &dvl[1]; 6265 const struct DVPathEntryP *hops = (const struct DVPathEntryP *)&dvl[1];
6345 6266
6346 (void) cls; 6267 (void)cls;
6347 if (size != sizeof (*dvl) + num_hops * sizeof (struct DVPathEntryP)) 6268 if (size != sizeof(*dvl) + num_hops * sizeof(struct DVPathEntryP))
6348 {
6349 GNUNET_break_op (0);
6350 return GNUNET_SYSERR;
6351 }
6352 if (num_hops > MAX_DV_HOPS_ALLOWED)
6353 {
6354 GNUNET_break_op (0);
6355 return GNUNET_SYSERR;
6356 }
6357 for (unsigned int i = 0; i < num_hops; i++)
6358 {
6359 if (0 == GNUNET_memcmp (&dvl->initiator, &hops[i].hop))
6360 { 6269 {
6361 GNUNET_break_op (0); 6270 GNUNET_break_op(0);
6362 return GNUNET_SYSERR; 6271 return GNUNET_SYSERR;
6363 } 6272 }
6364 if (0 == GNUNET_memcmp (&GST_my_identity, &hops[i].hop)) 6273 if (num_hops > MAX_DV_HOPS_ALLOWED)
6365 { 6274 {
6366 GNUNET_break_op (0); 6275 GNUNET_break_op(0);
6367 return GNUNET_SYSERR; 6276 return GNUNET_SYSERR;
6368 } 6277 }
6369 } 6278 for (unsigned int i = 0; i < num_hops; i++)
6279 {
6280 if (0 == GNUNET_memcmp(&dvl->initiator, &hops[i].hop))
6281 {
6282 GNUNET_break_op(0);
6283 return GNUNET_SYSERR;
6284 }
6285 if (0 == GNUNET_memcmp(&GST_my_identity, &hops[i].hop))
6286 {
6287 GNUNET_break_op(0);
6288 return GNUNET_SYSERR;
6289 }
6290 }
6370 return GNUNET_YES; 6291 return GNUNET_YES;
6371} 6292}
6372 6293
@@ -6383,56 +6304,56 @@ check_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
6383 * delay 6304 * delay
6384 */ 6305 */
6385static void 6306static void
6386forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, 6307forward_dv_learn(const struct GNUNET_PeerIdentity *next_hop,
6387 const struct TransportDVLearnMessage *msg, 6308 const struct TransportDVLearnMessage *msg,
6388 uint16_t bi_history, 6309 uint16_t bi_history,
6389 uint16_t nhops, 6310 uint16_t nhops,
6390 const struct DVPathEntryP *hops, 6311 const struct DVPathEntryP *hops,
6391 struct GNUNET_TIME_Absolute in_time) 6312 struct GNUNET_TIME_Absolute in_time)
6392{ 6313{
6393 struct DVPathEntryP *dhops; 6314 struct DVPathEntryP *dhops;
6394 char buf[sizeof (struct TransportDVLearnMessage) + 6315 char buf[sizeof(struct TransportDVLearnMessage) +
6395 (nhops + 1) * sizeof (struct DVPathEntryP)] GNUNET_ALIGN; 6316 (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN;
6396 struct TransportDVLearnMessage *fwd = (struct TransportDVLearnMessage *) buf; 6317 struct TransportDVLearnMessage *fwd = (struct TransportDVLearnMessage *)buf;
6397 struct GNUNET_TIME_Relative nnd; 6318 struct GNUNET_TIME_Relative nnd;
6398 6319
6399 /* compute message for forwarding */ 6320 /* compute message for forwarding */
6400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6321 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6401 "Forwarding DV learn message originating from %s to %s\n", 6322 "Forwarding DV learn message originating from %s to %s\n",
6402 GNUNET_i2s (&msg->initiator), 6323 GNUNET_i2s(&msg->initiator),
6403 GNUNET_i2s2 (next_hop)); 6324 GNUNET_i2s2(next_hop));
6404 GNUNET_assert (nhops < MAX_DV_HOPS_ALLOWED); 6325 GNUNET_assert(nhops < MAX_DV_HOPS_ALLOWED);
6405 fwd->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); 6326 fwd->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN);
6406 fwd->header.size = htons (sizeof (struct TransportDVLearnMessage) + 6327 fwd->header.size = htons(sizeof(struct TransportDVLearnMessage) +
6407 (nhops + 1) * sizeof (struct DVPathEntryP)); 6328 (nhops + 1) * sizeof(struct DVPathEntryP));
6408 fwd->num_hops = htons (nhops + 1); 6329 fwd->num_hops = htons(nhops + 1);
6409 fwd->bidirectional = htons (bi_history); 6330 fwd->bidirectional = htons(bi_history);
6410 nnd = GNUNET_TIME_relative_add (GNUNET_TIME_absolute_get_duration (in_time), 6331 nnd = GNUNET_TIME_relative_add(GNUNET_TIME_absolute_get_duration(in_time),
6411 GNUNET_TIME_relative_ntoh ( 6332 GNUNET_TIME_relative_ntoh(
6412 msg->non_network_delay)); 6333 msg->non_network_delay));
6413 fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd); 6334 fwd->non_network_delay = GNUNET_TIME_relative_hton(nnd);
6414 fwd->init_sig = msg->init_sig; 6335 fwd->init_sig = msg->init_sig;
6415 fwd->initiator = msg->initiator; 6336 fwd->initiator = msg->initiator;
6416 fwd->challenge = msg->challenge; 6337 fwd->challenge = msg->challenge;
6417 dhops = (struct DVPathEntryP *) &fwd[1]; 6338 dhops = (struct DVPathEntryP *)&fwd[1];
6418 GNUNET_memcpy (dhops, hops, sizeof (struct DVPathEntryP) * nhops); 6339 GNUNET_memcpy(dhops, hops, sizeof(struct DVPathEntryP) * nhops);
6419 dhops[nhops].hop = GST_my_identity; 6340 dhops[nhops].hop = GST_my_identity;
6420 { 6341 {
6421 struct DvHopPS dhp = {.purpose.purpose = 6342 struct DvHopPS dhp = { .purpose.purpose =
6422 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), 6343 htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP),
6423 .purpose.size = htonl (sizeof (dhp)), 6344 .purpose.size = htonl(sizeof(dhp)),
6424 .pred = dhops[nhops - 1].hop, 6345 .pred = dhops[nhops - 1].hop,
6425 .succ = *next_hop, 6346 .succ = *next_hop,
6426 .challenge = msg->challenge}; 6347 .challenge = msg->challenge };
6427 6348
6428 GNUNET_assert (GNUNET_OK == 6349 GNUNET_assert(GNUNET_OK ==
6429 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 6350 GNUNET_CRYPTO_eddsa_sign(GST_my_private_key,
6430 &dhp.purpose, 6351 &dhp.purpose,
6431 &dhops[nhops].hop_sig)); 6352 &dhops[nhops].hop_sig));
6432 } 6353 }
6433 route_control_message_without_fc (next_hop, 6354 route_control_message_without_fc(next_hop,
6434 &fwd->header, 6355 &fwd->header,
6435 RMO_UNCONFIRMED_ALLOWED); 6356 RMO_UNCONFIRMED_ALLOWED);
6436} 6357}
6437 6358
6438 6359
@@ -6446,28 +6367,28 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
6446 * @return #GNUNET_OK if the signature is valid 6367 * @return #GNUNET_OK if the signature is valid
6447 */ 6368 */
6448static int 6369static int
6449validate_dv_initiator_signature ( 6370validate_dv_initiator_signature(
6450 struct GNUNET_TIME_AbsoluteNBO sender_monotonic_time, 6371 struct GNUNET_TIME_AbsoluteNBO sender_monotonic_time,
6451 const struct GNUNET_PeerIdentity *init, 6372 const struct GNUNET_PeerIdentity *init,
6452 const struct ChallengeNonceP *challenge, 6373 const struct ChallengeNonceP *challenge,
6453 const struct GNUNET_CRYPTO_EddsaSignature *init_sig) 6374 const struct GNUNET_CRYPTO_EddsaSignature *init_sig)
6454{ 6375{
6455 struct DvInitPS ip = {.purpose.purpose = htonl ( 6376 struct DvInitPS ip = { .purpose.purpose = htonl(
6456 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), 6377 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR),
6457 .purpose.size = htonl (sizeof (ip)), 6378 .purpose.size = htonl(sizeof(ip)),
6458 .monotonic_time = sender_monotonic_time, 6379 .monotonic_time = sender_monotonic_time,
6459 .challenge = *challenge}; 6380 .challenge = *challenge };
6460 6381
6461 if ( 6382 if (
6462 GNUNET_OK != 6383 GNUNET_OK !=
6463 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, 6384 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR,
6464 &ip.purpose, 6385 &ip.purpose,
6465 init_sig, 6386 init_sig,
6466 &init->public_key)) 6387 &init->public_key))
6467 { 6388 {
6468 GNUNET_break_op (0); 6389 GNUNET_break_op(0);
6469 return GNUNET_SYSERR; 6390 return GNUNET_SYSERR;
6470 } 6391 }
6471 return GNUNET_OK; 6392 return GNUNET_OK;
6472} 6393}
6473 6394
@@ -6475,8 +6396,7 @@ validate_dv_initiator_signature (
6475/** 6396/**
6476 * Closure for #dv_neighbour_selection and #dv_neighbour_transmission. 6397 * Closure for #dv_neighbour_selection and #dv_neighbour_transmission.
6477 */ 6398 */
6478struct NeighbourSelectionContext 6399struct NeighbourSelectionContext {
6479{
6480 /** 6400 /**
6481 * Original message we received. 6401 * Original message we received.
6482 */ 6402 */
@@ -6528,18 +6448,19 @@ struct NeighbourSelectionContext
6528 * @return #GNUNET_YES (always) 6448 * @return #GNUNET_YES (always)
6529 */ 6449 */
6530static int 6450static int
6531dv_neighbour_selection (void *cls, 6451dv_neighbour_selection(void *cls,
6532 const struct GNUNET_PeerIdentity *pid, 6452 const struct GNUNET_PeerIdentity *pid,
6533 void *value) 6453 void *value)
6534{ 6454{
6535 struct NeighbourSelectionContext *nsc = cls; 6455 struct NeighbourSelectionContext *nsc = cls;
6536 6456
6537 (void) value; 6457 (void)value;
6538 if (0 == GNUNET_memcmp (pid, &nsc->dvl->initiator)) 6458 if (0 == GNUNET_memcmp(pid, &nsc->dvl->initiator))
6539 return GNUNET_YES; /* skip initiator */ 6459 return GNUNET_YES; /* skip initiator */
6540 for (unsigned int i = 0; i < nsc->nhops; i++) 6460 for (unsigned int i = 0; i < nsc->nhops; i++)
6541 if (0 == GNUNET_memcmp (pid, &nsc->hops[i].hop)) 6461 if (0 == GNUNET_memcmp(pid, &nsc->hops[i].hop))
6542 return GNUNET_YES; /* skip peers on path */ 6462 return GNUNET_YES;
6463 /* skip peers on path */
6543 nsc->num_eligible++; 6464 nsc->num_eligible++;
6544 return GNUNET_YES; 6465 return GNUNET_YES;
6545} 6466}
@@ -6556,31 +6477,32 @@ dv_neighbour_selection (void *cls,
6556 * @return #GNUNET_YES (always) 6477 * @return #GNUNET_YES (always)
6557 */ 6478 */
6558static int 6479static int
6559dv_neighbour_transmission (void *cls, 6480dv_neighbour_transmission(void *cls,
6560 const struct GNUNET_PeerIdentity *pid, 6481 const struct GNUNET_PeerIdentity *pid,
6561 void *value) 6482 void *value)
6562{ 6483{
6563 struct NeighbourSelectionContext *nsc = cls; 6484 struct NeighbourSelectionContext *nsc = cls;
6564 6485
6565 (void) value; 6486 (void)value;
6566 if (0 == GNUNET_memcmp (pid, &nsc->dvl->initiator)) 6487 if (0 == GNUNET_memcmp(pid, &nsc->dvl->initiator))
6567 return GNUNET_YES; /* skip initiator */ 6488 return GNUNET_YES; /* skip initiator */
6568 for (unsigned int i = 0; i < nsc->nhops; i++) 6489 for (unsigned int i = 0; i < nsc->nhops; i++)
6569 if (0 == GNUNET_memcmp (pid, &nsc->hops[i].hop)) 6490 if (0 == GNUNET_memcmp(pid, &nsc->hops[i].hop))
6570 return GNUNET_YES; /* skip peers on path */ 6491 return GNUNET_YES;
6492 /* skip peers on path */
6571 for (unsigned int i = 0; i < nsc->num_selections; i++) 6493 for (unsigned int i = 0; i < nsc->num_selections; i++)
6572 { 6494 {
6573 if (nsc->selections[i] == nsc->num_eligible) 6495 if (nsc->selections[i] == nsc->num_eligible)
6574 { 6496 {
6575 forward_dv_learn (pid, 6497 forward_dv_learn(pid,
6576 nsc->dvl, 6498 nsc->dvl,
6577 nsc->bi_history, 6499 nsc->bi_history,
6578 nsc->nhops, 6500 nsc->nhops,
6579 nsc->hops, 6501 nsc->hops,
6580 nsc->in_time); 6502 nsc->in_time);
6581 break; 6503 break;
6504 }
6582 } 6505 }
6583 }
6584 nsc->num_eligible++; 6506 nsc->num_eligible++;
6585 return GNUNET_YES; 6507 return GNUNET_YES;
6586} 6508}
@@ -6630,42 +6552,42 @@ dv_neighbour_transmission (void *cls,
6630 * theory forward to 6552 * theory forward to
6631 */ 6553 */
6632static unsigned int 6554static unsigned int
6633calculate_fork_degree (unsigned int hops_taken, 6555calculate_fork_degree(unsigned int hops_taken,
6634 unsigned int neighbour_count, 6556 unsigned int neighbour_count,
6635 unsigned int eligible_count) 6557 unsigned int eligible_count)
6636{ 6558{
6637 double target_total = 50.0; /* FIXME: use LOG(NSE)? */ 6559 double target_total = 50.0; /* FIXME: use LOG(NSE)? */
6638 double eligible_ratio = 6560 double eligible_ratio =
6639 ((double) eligible_count) / ((double) neighbour_count); 6561 ((double)eligible_count) / ((double)neighbour_count);
6640 double boost_factor = eligible_ratio * eligible_ratio; 6562 double boost_factor = eligible_ratio * eligible_ratio;
6641 unsigned int rnd; 6563 unsigned int rnd;
6642 double left; 6564 double left;
6643 6565
6644 if (hops_taken >= 64) 6566 if (hops_taken >= 64)
6645 { 6567 {
6646 GNUNET_break (0); 6568 GNUNET_break(0);
6647 return 0; /* precaution given bitshift below */ 6569 return 0; /* precaution given bitshift below */
6648 } 6570 }
6649 for (unsigned int i = 1; i < hops_taken; i++) 6571 for (unsigned int i = 1; i < hops_taken; i++)
6650 { 6572 {
6651 /* For each hop, subtract the expected number of targets 6573 /* For each hop, subtract the expected number of targets
6652 reached at distance d (so what remains divided by 2^d) */ 6574 reached at distance d (so what remains divided by 2^d) */
6653 target_total -= (target_total * boost_factor / (1LLU << i)); 6575 target_total -= (target_total * boost_factor / (1LLU << i));
6654 } 6576 }
6655 rnd = 6577 rnd =
6656 (unsigned int) floor (target_total * boost_factor / (1LLU << hops_taken)); 6578 (unsigned int)floor(target_total * boost_factor / (1LLU << hops_taken));
6657 /* round up or down probabilistically depending on how close we were 6579 /* round up or down probabilistically depending on how close we were
6658 when floor()ing to rnd */ 6580 when floor()ing to rnd */
6659 left = target_total - (double) rnd; 6581 left = target_total - (double)rnd;
6660 if (UINT32_MAX * left > 6582 if (UINT32_MAX * left >
6661 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)) 6583 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX))
6662 rnd++; /* round up */ 6584 rnd++; /* round up */
6663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6585 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6664 "Forwarding DV learn message of %u hops %u(/%u/%u) times\n", 6586 "Forwarding DV learn message of %u hops %u(/%u/%u) times\n",
6665 hops_taken, 6587 hops_taken,
6666 rnd, 6588 rnd,
6667 eligible_count, 6589 eligible_count,
6668 neighbour_count); 6590 neighbour_count);
6669 return rnd; 6591 return rnd;
6670} 6592}
6671 6593
@@ -6677,14 +6599,14 @@ calculate_fork_degree (unsigned int hops_taken,
6677 * @param success #GNUNET_YES if peerstore was successful 6599 * @param success #GNUNET_YES if peerstore was successful
6678 */ 6600 */
6679static void 6601static void
6680neighbour_store_dvmono_cb (void *cls, int success) 6602neighbour_store_dvmono_cb(void *cls, int success)
6681{ 6603{
6682 struct Neighbour *n = cls; 6604 struct Neighbour *n = cls;
6683 6605
6684 n->sc = NULL; 6606 n->sc = NULL;
6685 if (GNUNET_YES != success) 6607 if (GNUNET_YES != success)
6686 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6608 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
6687 "Failed to store other peer's monotonic time in peerstore!\n"); 6609 "Failed to store other peer's monotonic time in peerstore!\n");
6688} 6610}
6689 6611
6690 6612
@@ -6696,7 +6618,7 @@ neighbour_store_dvmono_cb (void *cls, int success)
6696 * @param dvl the message that was received 6618 * @param dvl the message that was received
6697 */ 6619 */
6698static void 6620static void
6699handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) 6621handle_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl)
6700{ 6622{
6701 struct CommunicatorMessageContext *cmc = cls; 6623 struct CommunicatorMessageContext *cmc = cls;
6702 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; 6624 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
@@ -6709,287 +6631,287 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
6709 struct GNUNET_TIME_Absolute in_time; 6631 struct GNUNET_TIME_Absolute in_time;
6710 struct Neighbour *n; 6632 struct Neighbour *n;
6711 6633
6712 nhops = ntohs (dvl->bidirectional); /* 0 = sender is initiator */ 6634 nhops = ntohs(dvl->bidirectional); /* 0 = sender is initiator */
6713 bi_history = ntohs (dvl->bidirectional); 6635 bi_history = ntohs(dvl->bidirectional);
6714 hops = (const struct DVPathEntryP *) &dvl[1]; 6636 hops = (const struct DVPathEntryP *)&dvl[1];
6715 if (0 == nhops) 6637 if (0 == nhops)
6716 {
6717 /* sanity check */
6718 if (0 != GNUNET_memcmp (&dvl->initiator, &cmc->im.sender))
6719 { 6638 {
6720 GNUNET_break (0); 6639 /* sanity check */
6721 finish_cmc_handling (cmc); 6640 if (0 != GNUNET_memcmp(&dvl->initiator, &cmc->im.sender))
6722 return; 6641 {
6642 GNUNET_break(0);
6643 finish_cmc_handling(cmc);
6644 return;
6645 }
6723 } 6646 }
6724 }
6725 else 6647 else
6726 {
6727 /* sanity check */
6728 if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, &cmc->im.sender))
6729 { 6648 {
6730 GNUNET_break (0); 6649 /* sanity check */
6731 finish_cmc_handling (cmc); 6650 if (0 != GNUNET_memcmp(&hops[nhops - 1].hop, &cmc->im.sender))
6732 return; 6651 {
6652 GNUNET_break(0);
6653 finish_cmc_handling(cmc);
6654 return;
6655 }
6733 } 6656 }
6734 }
6735 6657
6736 GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type); 6658 GNUNET_assert(CT_COMMUNICATOR == cmc->tc->type);
6737 cc = cmc->tc->details.communicator.cc; 6659 cc = cmc->tc->details.communicator.cc;
6738 bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE == 6660 bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE ==
6739 cc); // FIXME: add bi-directional flag to cc? 6661 cc); // FIXME: add bi-directional flag to cc?
6740 in_time = GNUNET_TIME_absolute_get (); 6662 in_time = GNUNET_TIME_absolute_get();
6741 6663
6742 /* continue communicator here, everything else can happen asynchronous! */ 6664 /* continue communicator here, everything else can happen asynchronous! */
6743 finish_cmc_handling (cmc); 6665 finish_cmc_handling(cmc);
6744 6666
6745 n = lookup_neighbour (&dvl->initiator); 6667 n = lookup_neighbour(&dvl->initiator);
6746 if (NULL != n) 6668 if (NULL != n)
6747 {
6748 if ((n->dv_monotime_available == GNUNET_YES) &&
6749 (GNUNET_TIME_absolute_ntoh (dvl->monotonic_time).abs_value_us <
6750 n->last_dv_learn_monotime.abs_value_us))
6751 {
6752 GNUNET_STATISTICS_update (GST_stats,
6753 "# DV learn discarded due to time travel",
6754 1,
6755 GNUNET_NO);
6756 return;
6757 }
6758 if (GNUNET_OK != validate_dv_initiator_signature (dvl->monotonic_time,
6759 &dvl->initiator,
6760 &dvl->challenge,
6761 &dvl->init_sig))
6762 { 6669 {
6763 GNUNET_break_op (0); 6670 if ((n->dv_monotime_available == GNUNET_YES) &&
6764 return; 6671 (GNUNET_TIME_absolute_ntoh(dvl->monotonic_time).abs_value_us <
6765 } 6672 n->last_dv_learn_monotime.abs_value_us))
6766 n->last_dv_learn_monotime = GNUNET_TIME_absolute_ntoh (dvl->monotonic_time); 6673 {
6767 if (GNUNET_YES == n->dv_monotime_available) 6674 GNUNET_STATISTICS_update(GST_stats,
6768 { 6675 "# DV learn discarded due to time travel",
6769 if (NULL != n->sc) 6676 1,
6770 GNUNET_PEERSTORE_store_cancel (n->sc); 6677 GNUNET_NO);
6771 n->sc = 6678 return;
6772 GNUNET_PEERSTORE_store (peerstore, 6679 }
6773 "transport", 6680 if (GNUNET_OK != validate_dv_initiator_signature(dvl->monotonic_time,
6774 &dvl->initiator, 6681 &dvl->initiator,
6775 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, 6682 &dvl->challenge,
6776 &dvl->monotonic_time, 6683 &dvl->init_sig))
6777 sizeof (dvl->monotonic_time), 6684 {
6778 GNUNET_TIME_UNIT_FOREVER_ABS, 6685 GNUNET_break_op(0);
6779 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 6686 return;
6780 &neighbour_store_dvmono_cb, 6687 }
6781 n); 6688 n->last_dv_learn_monotime = GNUNET_TIME_absolute_ntoh(dvl->monotonic_time);
6689 if (GNUNET_YES == n->dv_monotime_available)
6690 {
6691 if (NULL != n->sc)
6692 GNUNET_PEERSTORE_store_cancel(n->sc);
6693 n->sc =
6694 GNUNET_PEERSTORE_store(peerstore,
6695 "transport",
6696 &dvl->initiator,
6697 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME,
6698 &dvl->monotonic_time,
6699 sizeof(dvl->monotonic_time),
6700 GNUNET_TIME_UNIT_FOREVER_ABS,
6701 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
6702 &neighbour_store_dvmono_cb,
6703 n);
6704 }
6782 } 6705 }
6783 }
6784 /* OPTIMIZE-FIXME: asynchronously (!) verify signatures!, 6706 /* OPTIMIZE-FIXME: asynchronously (!) verify signatures!,
6785 If signature verification load too high, implement random drop strategy */ 6707 If signature verification load too high, implement random drop strategy */
6786 for (unsigned int i = 0; i < nhops; i++) 6708 for (unsigned int i = 0; i < nhops; i++)
6787 { 6709 {
6788 struct DvHopPS dhp = {.purpose.purpose = 6710 struct DvHopPS dhp = { .purpose.purpose =
6789 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), 6711 htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP),
6790 .purpose.size = htonl (sizeof (dhp)), 6712 .purpose.size = htonl(sizeof(dhp)),
6791 .pred = (0 == i) ? dvl->initiator : hops[i - 1].hop, 6713 .pred = (0 == i) ? dvl->initiator : hops[i - 1].hop,
6792 .succ = (nhops == i + 1) ? GST_my_identity 6714 .succ = (nhops == i + 1) ? GST_my_identity
6793 : hops[i + 1].hop, 6715 : hops[i + 1].hop,
6794 .challenge = dvl->challenge}; 6716 .challenge = dvl->challenge };
6795 6717
6796 if (GNUNET_OK != 6718 if (GNUNET_OK !=
6797 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP, 6719 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP,
6798 &dhp.purpose, 6720 &dhp.purpose,
6799 &hops[i].hop_sig, 6721 &hops[i].hop_sig,
6800 &hops[i].hop.public_key)) 6722 &hops[i].hop.public_key))
6801 { 6723 {
6802 GNUNET_break_op (0); 6724 GNUNET_break_op(0);
6803 return; 6725 return;
6726 }
6804 } 6727 }
6805 }
6806 6728
6807 if (GNUNET_EXTRA_LOGGING > 0) 6729 if (GNUNET_EXTRA_LOGGING > 0)
6808 { 6730 {
6809 char *path; 6731 char *path;
6810 6732
6811 path = GNUNET_strdup (GNUNET_i2s (&dvl->initiator)); 6733 path = GNUNET_strdup(GNUNET_i2s(&dvl->initiator));
6812 for (unsigned int i = 0; i < nhops; i++) 6734 for (unsigned int i = 0; i < nhops; i++)
6813 { 6735 {
6814 char *tmp; 6736 char *tmp;
6815 6737
6816 GNUNET_asprintf (&tmp, 6738 GNUNET_asprintf(&tmp,
6817 "%s%s%s", 6739 "%s%s%s",
6818 path, 6740 path,
6819 (bi_history & (1 << (nhops - i))) ? "<->" : "-->", 6741 (bi_history & (1 << (nhops - i))) ? "<->" : "-->",
6820 GNUNET_i2s (&hops[i].hop)); 6742 GNUNET_i2s(&hops[i].hop));
6821 GNUNET_free (path); 6743 GNUNET_free(path);
6822 path = tmp; 6744 path = tmp;
6823 } 6745 }
6824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6746 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6825 "Received DVInit via %s%s%s\n", 6747 "Received DVInit via %s%s%s\n",
6826 path, 6748 path,
6827 bi_hop ? "<->" : "-->", 6749 bi_hop ? "<->" : "-->",
6828 GNUNET_i2s (&GST_my_identity)); 6750 GNUNET_i2s(&GST_my_identity));
6829 GNUNET_free (path); 6751 GNUNET_free(path);
6830 } 6752 }
6831 6753
6832 do_fwd = GNUNET_YES; 6754 do_fwd = GNUNET_YES;
6833 if (0 == GNUNET_memcmp (&GST_my_identity, &dvl->initiator)) 6755 if (0 == GNUNET_memcmp(&GST_my_identity, &dvl->initiator))
6834 { 6756 {
6835 struct GNUNET_PeerIdentity path[nhops + 1]; 6757 struct GNUNET_PeerIdentity path[nhops + 1];
6836 struct GNUNET_TIME_Relative host_latency_sum; 6758 struct GNUNET_TIME_Relative host_latency_sum;
6837 struct GNUNET_TIME_Relative latency; 6759 struct GNUNET_TIME_Relative latency;
6838 struct GNUNET_TIME_Relative network_latency; 6760 struct GNUNET_TIME_Relative network_latency;
6839 6761
6840 /* We initiated this, learn the forward path! */ 6762 /* We initiated this, learn the forward path! */
6841 path[0] = GST_my_identity; 6763 path[0] = GST_my_identity;
6842 path[1] = hops[0].hop; 6764 path[1] = hops[0].hop;
6843 host_latency_sum = GNUNET_TIME_relative_ntoh (dvl->non_network_delay); 6765 host_latency_sum = GNUNET_TIME_relative_ntoh(dvl->non_network_delay);
6844 6766
6845 // Need also something to lookup initiation time 6767 // Need also something to lookup initiation time
6846 // to compute RTT! -> add RTT argument here? 6768 // to compute RTT! -> add RTT argument here?
6847 latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly 6769 latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly
6848 // (based on dvl->challenge, we can identify time of origin!) 6770 // (based on dvl->challenge, we can identify time of origin!)
6849 6771
6850 network_latency = GNUNET_TIME_relative_subtract (latency, host_latency_sum); 6772 network_latency = GNUNET_TIME_relative_subtract(latency, host_latency_sum);
6851 /* assumption: latency on all links is the same */ 6773 /* assumption: latency on all links is the same */
6852 network_latency = GNUNET_TIME_relative_divide (network_latency, nhops); 6774 network_latency = GNUNET_TIME_relative_divide(network_latency, nhops);
6853 6775
6854 for (unsigned int i = 2; i <= nhops; i++) 6776 for (unsigned int i = 2; i <= nhops; i++)
6855 { 6777 {
6856 struct GNUNET_TIME_Relative ilat; 6778 struct GNUNET_TIME_Relative ilat;
6857 6779
6858 /* assumption: linear latency increase per hop */ 6780 /* assumption: linear latency increase per hop */
6859 ilat = GNUNET_TIME_relative_multiply (network_latency, i); 6781 ilat = GNUNET_TIME_relative_multiply(network_latency, i);
6860 path[i] = hops[i - 1].hop; 6782 path[i] = hops[i - 1].hop;
6861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6783 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6862 "Learned path with %u hops to %s with latency %s\n", 6784 "Learned path with %u hops to %s with latency %s\n",
6863 i,
6864 GNUNET_i2s (&path[i]),
6865 GNUNET_STRINGS_relative_time_to_string (ilat, GNUNET_YES));
6866 learn_dv_path (path,
6867 i, 6785 i,
6868 ilat, 6786 GNUNET_i2s(&path[i]),
6869 GNUNET_TIME_relative_to_absolute ( 6787 GNUNET_STRINGS_relative_time_to_string(ilat, GNUNET_YES));
6870 ADDRESS_VALIDATION_LIFETIME)); 6788 learn_dv_path(path,
6789 i,
6790 ilat,
6791 GNUNET_TIME_relative_to_absolute(
6792 ADDRESS_VALIDATION_LIFETIME));
6793 }
6794 /* as we initiated, do not forward again (would be circular!) */
6795 do_fwd = GNUNET_NO;
6796 return;
6871 } 6797 }
6872 /* as we initiated, do not forward again (would be circular!) */
6873 do_fwd = GNUNET_NO;
6874 return;
6875 }
6876 if (bi_hop) 6798 if (bi_hop)
6877 {
6878 /* last hop was bi-directional, we could learn something here! */
6879 struct GNUNET_PeerIdentity path[nhops + 2];
6880
6881 path[0] = GST_my_identity;
6882 path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */
6883 for (unsigned int i = 0; i < nhops; i++)
6884 { 6799 {
6885 int iret; 6800 /* last hop was bi-directional, we could learn something here! */
6886 6801 struct GNUNET_PeerIdentity path[nhops + 2];
6887 if (0 == (bi_history & (1 << i)))
6888 break; /* i-th hop not bi-directional, stop learning! */
6889 if (i == nhops - 1)
6890 {
6891 path[i + 2] = dvl->initiator;
6892 }
6893 else
6894 {
6895 path[i + 2] = hops[nhops - i - 2].hop;
6896 }
6897 6802
6898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6803 path[0] = GST_my_identity;
6899 "Learned inverse path with %u hops to %s\n", 6804 path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */
6900 i + 1, 6805 for (unsigned int i = 0; i < nhops; i++)
6901 GNUNET_i2s (&path[i + 2])); 6806 {
6902 iret = learn_dv_path (path, 6807 int iret;
6903 i + 2, 6808
6904 GNUNET_TIME_UNIT_FOREVER_REL, 6809 if (0 == (bi_history & (1 << i)))
6905 GNUNET_TIME_UNIT_ZERO_ABS); 6810 break; /* i-th hop not bi-directional, stop learning! */
6906 if (GNUNET_SYSERR == iret) 6811 if (i == nhops - 1)
6907 { 6812 {
6908 /* path invalid or too long to be interesting for US, thus should also 6813 path[i + 2] = dvl->initiator;
6909 not be interesting to our neighbours, cut path when forwarding to 6814 }
6910 'i' hops, except of course for the one that goes back to the 6815 else
6911 initiator */ 6816 {
6912 GNUNET_STATISTICS_update (GST_stats, 6817 path[i + 2] = hops[nhops - i - 2].hop;
6913 "# DV learn not forwarded due invalidity of path", 6818 }
6914 1, 6819
6915 GNUNET_NO); 6820 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6916 do_fwd = GNUNET_NO; 6821 "Learned inverse path with %u hops to %s\n",
6917 break; 6822 i + 1,
6918 } 6823 GNUNET_i2s(&path[i + 2]));
6919 if ((GNUNET_NO == iret) && (nhops == i + 1)) 6824 iret = learn_dv_path(path,
6920 { 6825 i + 2,
6921 /* we have better paths, and this is the longest target, 6826 GNUNET_TIME_UNIT_FOREVER_REL,
6922 so there cannot be anything interesting later */ 6827 GNUNET_TIME_UNIT_ZERO_ABS);
6923 GNUNET_STATISTICS_update (GST_stats, 6828 if (GNUNET_SYSERR == iret)
6924 "# DV learn not forwarded, got better paths", 6829 {
6925 1, 6830 /* path invalid or too long to be interesting for US, thus should also
6926 GNUNET_NO); 6831 not be interesting to our neighbours, cut path when forwarding to
6927 do_fwd = GNUNET_NO; 6832 'i' hops, except of course for the one that goes back to the
6928 break; 6833 initiator */
6929 } 6834 GNUNET_STATISTICS_update(GST_stats,
6835 "# DV learn not forwarded due invalidity of path",
6836 1,
6837 GNUNET_NO);
6838 do_fwd = GNUNET_NO;
6839 break;
6840 }
6841 if ((GNUNET_NO == iret) && (nhops == i + 1))
6842 {
6843 /* we have better paths, and this is the longest target,
6844 so there cannot be anything interesting later */
6845 GNUNET_STATISTICS_update(GST_stats,
6846 "# DV learn not forwarded, got better paths",
6847 1,
6848 GNUNET_NO);
6849 do_fwd = GNUNET_NO;
6850 break;
6851 }
6852 }
6930 } 6853 }
6931 }
6932 6854
6933 if (MAX_DV_HOPS_ALLOWED == nhops) 6855 if (MAX_DV_HOPS_ALLOWED == nhops)
6934 { 6856 {
6935 /* At limit, we're out of here! */ 6857 /* At limit, we're out of here! */
6936 finish_cmc_handling (cmc); 6858 finish_cmc_handling(cmc);
6937 return; 6859 return;
6938 } 6860 }
6939 6861
6940 /* Forward to initiator, if path non-trivial and possible */ 6862 /* Forward to initiator, if path non-trivial and possible */
6941 bi_history = (bi_history << 1) | (bi_hop ? 1 : 0); 6863 bi_history = (bi_history << 1) | (bi_hop ? 1 : 0);
6942 did_initiator = GNUNET_NO; 6864 did_initiator = GNUNET_NO;
6943 if ((1 < nhops) && 6865 if ((1 < nhops) &&
6944 (GNUNET_YES == 6866 (GNUNET_YES ==
6945 GNUNET_CONTAINER_multipeermap_contains (neighbours, &dvl->initiator))) 6867 GNUNET_CONTAINER_multipeermap_contains(neighbours, &dvl->initiator)))
6946 { 6868 {
6947 /* send back to origin! */ 6869 /* send back to origin! */
6948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6870 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6949 "Sending DVL back to initiator %s\n", 6871 "Sending DVL back to initiator %s\n",
6950 GNUNET_i2s (&dvl->initiator)); 6872 GNUNET_i2s(&dvl->initiator));
6951 forward_dv_learn (&dvl->initiator, dvl, bi_history, nhops, hops, in_time); 6873 forward_dv_learn(&dvl->initiator, dvl, bi_history, nhops, hops, in_time);
6952 did_initiator = GNUNET_YES; 6874 did_initiator = GNUNET_YES;
6953 } 6875 }
6954 /* We forward under two conditions: either we still learned something 6876 /* We forward under two conditions: either we still learned something
6955 ourselves (do_fwd), or the path was darn short and thus the initiator is 6877 ourselves (do_fwd), or the path was darn short and thus the initiator is
6956 likely to still be very interested in this (and we did NOT already 6878 likely to still be very interested in this (and we did NOT already
6957 send it back to the initiator) */ 6879 send it back to the initiator) */
6958 if ((do_fwd) || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) && 6880 if ((do_fwd) || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) &&
6959 (GNUNET_NO == did_initiator))) 6881 (GNUNET_NO == did_initiator)))
6960 { 6882 {
6961 /* Pick random neighbours that are not yet on the path */ 6883 /* Pick random neighbours that are not yet on the path */
6962 struct NeighbourSelectionContext nsc; 6884 struct NeighbourSelectionContext nsc;
6963 unsigned int n_cnt; 6885 unsigned int n_cnt;
6964 6886
6965 n_cnt = GNUNET_CONTAINER_multipeermap_size (neighbours); 6887 n_cnt = GNUNET_CONTAINER_multipeermap_size(neighbours);
6966 nsc.nhops = nhops; 6888 nsc.nhops = nhops;
6967 nsc.dvl = dvl; 6889 nsc.dvl = dvl;
6968 nsc.bi_history = bi_history; 6890 nsc.bi_history = bi_history;
6969 nsc.hops = hops; 6891 nsc.hops = hops;
6970 nsc.in_time = in_time; 6892 nsc.in_time = in_time;
6971 nsc.num_eligible = 0; 6893 nsc.num_eligible = 0;
6972 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 6894 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
6973 &dv_neighbour_selection, 6895 &dv_neighbour_selection,
6974 &nsc); 6896 &nsc);
6975 if (0 == nsc.num_eligible) 6897 if (0 == nsc.num_eligible)
6976 return; /* done here, cannot forward to anyone else */ 6898 return; /* done here, cannot forward to anyone else */
6977 nsc.num_selections = calculate_fork_degree (nhops, n_cnt, nsc.num_eligible); 6899 nsc.num_selections = calculate_fork_degree(nhops, n_cnt, nsc.num_eligible);
6978 nsc.num_selections = 6900 nsc.num_selections =
6979 GNUNET_MIN (MAX_DV_DISCOVERY_SELECTION, nsc.num_selections); 6901 GNUNET_MIN(MAX_DV_DISCOVERY_SELECTION, nsc.num_selections);
6980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6902 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6981 "Forwarding DVL to %u other peers\n", 6903 "Forwarding DVL to %u other peers\n",
6982 nsc.num_selections); 6904 nsc.num_selections);
6983 for (unsigned int i = 0; i < nsc.num_selections; i++) 6905 for (unsigned int i = 0; i < nsc.num_selections; i++)
6984 nsc.selections[i] = 6906 nsc.selections[i] =
6985 (nsc.num_selections == n_cnt) 6907 (nsc.num_selections == n_cnt)
6986 ? i /* all were selected, avoid collisions by chance */ 6908 ? i /* all were selected, avoid collisions by chance */
6987 : GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, n_cnt); 6909 : GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, n_cnt);
6988 nsc.num_eligible = 0; 6910 nsc.num_eligible = 0;
6989 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 6911 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
6990 &dv_neighbour_transmission, 6912 &dv_neighbour_transmission,
6991 &nsc); 6913 &nsc);
6992 } 6914 }
6993} 6915}
6994 6916
6995 6917
@@ -7001,27 +6923,27 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
7001 * @return #GNUNET_YES if message is well-formed 6923 * @return #GNUNET_YES if message is well-formed
7002 */ 6924 */
7003static int 6925static int
7004check_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) 6926check_dv_box(void *cls, const struct TransportDVBoxMessage *dvb)
7005{ 6927{
7006 uint16_t size = ntohs (dvb->header.size); 6928 uint16_t size = ntohs(dvb->header.size);
7007 uint16_t num_hops = ntohs (dvb->num_hops); 6929 uint16_t num_hops = ntohs(dvb->num_hops);
7008 const struct GNUNET_PeerIdentity *hops = 6930 const struct GNUNET_PeerIdentity *hops =
7009 (const struct GNUNET_PeerIdentity *) &dvb[1]; 6931 (const struct GNUNET_PeerIdentity *)&dvb[1];
7010 6932
7011 (void) cls; 6933 (void)cls;
7012 if (size < sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + 6934 if (size < sizeof(*dvb) + num_hops * sizeof(struct GNUNET_PeerIdentity) +
7013 sizeof (struct GNUNET_MessageHeader)) 6935 sizeof(struct GNUNET_MessageHeader))
7014 {
7015 GNUNET_break_op (0);
7016 return GNUNET_SYSERR;
7017 }
7018 /* This peer must not be on the path */
7019 for (unsigned int i = 0; i < num_hops; i++)
7020 if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity))
7021 { 6936 {
7022 GNUNET_break_op (0); 6937 GNUNET_break_op(0);
7023 return GNUNET_SYSERR; 6938 return GNUNET_SYSERR;
7024 } 6939 }
6940 /* This peer must not be on the path */
6941 for (unsigned int i = 0; i < num_hops; i++)
6942 if (0 == GNUNET_memcmp(&hops[i], &GST_my_identity))
6943 {
6944 GNUNET_break_op(0);
6945 return GNUNET_SYSERR;
6946 }
7025 return GNUNET_YES; 6947 return GNUNET_YES;
7026} 6948}
7027 6949
@@ -7039,13 +6961,13 @@ check_dv_box (void *cls, const struct TransportDVBoxMessage *dvb)
7039 * @param payload_size number of bytes in @a payload 6961 * @param payload_size number of bytes in @a payload
7040 */ 6962 */
7041static void 6963static void
7042forward_dv_box (struct Neighbour *next_hop, 6964forward_dv_box(struct Neighbour *next_hop,
7043 const struct TransportDVBoxMessage *hdr, 6965 const struct TransportDVBoxMessage *hdr,
7044 uint16_t total_hops, 6966 uint16_t total_hops,
7045 uint16_t num_hops, 6967 uint16_t num_hops,
7046 const struct GNUNET_PeerIdentity *hops, 6968 const struct GNUNET_PeerIdentity *hops,
7047 const void *enc_payload, 6969 const void *enc_payload,
7048 uint16_t enc_payload_size) 6970 uint16_t enc_payload_size)
7049{ 6971{
7050 struct VirtualLink *vl = next_hop->vl; 6972 struct VirtualLink *vl = next_hop->vl;
7051 struct PendingMessage *pm; 6973 struct PendingMessage *pm;
@@ -7053,33 +6975,33 @@ forward_dv_box (struct Neighbour *next_hop,
7053 char *buf; 6975 char *buf;
7054 struct GNUNET_PeerIdentity *dhops; 6976 struct GNUNET_PeerIdentity *dhops;
7055 6977
7056 GNUNET_assert (NULL != vl); 6978 GNUNET_assert(NULL != vl);
7057 msg_size = sizeof (struct TransportDVBoxMessage) + 6979 msg_size = sizeof(struct TransportDVBoxMessage) +
7058 num_hops * sizeof (struct GNUNET_PeerIdentity) + enc_payload_size; 6980 num_hops * sizeof(struct GNUNET_PeerIdentity) + enc_payload_size;
7059 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); 6981 pm = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size);
7060 pm->pmt = PMT_DV_BOX; 6982 pm->pmt = PMT_DV_BOX;
7061 pm->vl = vl; 6983 pm->vl = vl;
7062 pm->timeout = GNUNET_TIME_relative_to_absolute (DV_FORWARD_TIMEOUT); 6984 pm->timeout = GNUNET_TIME_relative_to_absolute(DV_FORWARD_TIMEOUT);
7063 pm->logging_uuid = logging_uuid_gen++; 6985 pm->logging_uuid = logging_uuid_gen++;
7064 pm->prefs = GNUNET_MQ_PRIO_BACKGROUND; 6986 pm->prefs = GNUNET_MQ_PRIO_BACKGROUND;
7065 pm->bytes_msg = msg_size; 6987 pm->bytes_msg = msg_size;
7066 buf = (char *) &pm[1]; 6988 buf = (char *)&pm[1];
7067 memcpy (buf, hdr, sizeof (*hdr)); 6989 memcpy(buf, hdr, sizeof(*hdr));
7068 dhops = 6990 dhops =
7069 (struct GNUNET_PeerIdentity *) &buf[sizeof (struct TransportDVBoxMessage)]; 6991 (struct GNUNET_PeerIdentity *)&buf[sizeof(struct TransportDVBoxMessage)];
7070 memcpy (dhops, hops, num_hops * sizeof (struct GNUNET_PeerIdentity)); 6992 memcpy(dhops, hops, num_hops * sizeof(struct GNUNET_PeerIdentity));
7071 memcpy (&dhops[num_hops], enc_payload, enc_payload_size); 6993 memcpy(&dhops[num_hops], enc_payload, enc_payload_size);
7072 GNUNET_CONTAINER_MDLL_insert (vl, 6994 GNUNET_CONTAINER_MDLL_insert(vl,
7073 vl->pending_msg_head, 6995 vl->pending_msg_head,
7074 vl->pending_msg_tail, 6996 vl->pending_msg_tail,
7075 pm); 6997 pm);
7076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6998 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7077 "Created pending message %llu for DV Box with next hop %s (%u/%u)\n", 6999 "Created pending message %llu for DV Box with next hop %s (%u/%u)\n",
7078 pm->logging_uuid, 7000 pm->logging_uuid,
7079 GNUNET_i2s (&next_hop->pid), 7001 GNUNET_i2s(&next_hop->pid),
7080 (unsigned int) num_hops, 7002 (unsigned int)num_hops,
7081 (unsigned int) total_hops); 7003 (unsigned int)total_hops);
7082 check_vl_transmission (vl); 7004 check_vl_transmission(vl);
7083} 7005}
7084 7006
7085 7007
@@ -7089,30 +7011,30 @@ forward_dv_box (struct Neighbour *next_hop,
7089 * @param b data structure to release 7011 * @param b data structure to release
7090 */ 7012 */
7091static void 7013static void
7092free_backtalker (struct Backtalker *b) 7014free_backtalker(struct Backtalker *b)
7093{ 7015{
7094 if (NULL != b->get) 7016 if (NULL != b->get)
7095 { 7017 {
7096 GNUNET_PEERSTORE_iterate_cancel (b->get); 7018 GNUNET_PEERSTORE_iterate_cancel(b->get);
7097 b->get = NULL; 7019 b->get = NULL;
7098 GNUNET_assert (NULL != b->cmc); 7020 GNUNET_assert(NULL != b->cmc);
7099 finish_cmc_handling (b->cmc); 7021 finish_cmc_handling(b->cmc);
7100 b->cmc = NULL; 7022 b->cmc = NULL;
7101 } 7023 }
7102 if (NULL != b->task) 7024 if (NULL != b->task)
7103 { 7025 {
7104 GNUNET_SCHEDULER_cancel (b->task); 7026 GNUNET_SCHEDULER_cancel(b->task);
7105 b->task = NULL; 7027 b->task = NULL;
7106 } 7028 }
7107 if (NULL != b->sc) 7029 if (NULL != b->sc)
7108 { 7030 {
7109 GNUNET_PEERSTORE_store_cancel (b->sc); 7031 GNUNET_PEERSTORE_store_cancel(b->sc);
7110 b->sc = NULL; 7032 b->sc = NULL;
7111 } 7033 }
7112 GNUNET_assert ( 7034 GNUNET_assert(
7113 GNUNET_YES == 7035 GNUNET_YES ==
7114 GNUNET_CONTAINER_multipeermap_remove (backtalkers, &b->pid, b)); 7036 GNUNET_CONTAINER_multipeermap_remove(backtalkers, &b->pid, b));
7115 GNUNET_free (b); 7037 GNUNET_free(b);
7116} 7038}
7117 7039
7118 7040
@@ -7125,15 +7047,15 @@ free_backtalker (struct Backtalker *b)
7125 * @return #GNUNET_OK (always) 7047 * @return #GNUNET_OK (always)
7126 */ 7048 */
7127static int 7049static int
7128free_backtalker_cb (void *cls, 7050free_backtalker_cb(void *cls,
7129 const struct GNUNET_PeerIdentity *pid, 7051 const struct GNUNET_PeerIdentity *pid,
7130 void *value) 7052 void *value)
7131{ 7053{
7132 struct Backtalker *b = value; 7054 struct Backtalker *b = value;
7133 7055
7134 (void) cls; 7056 (void)cls;
7135 (void) pid; 7057 (void)pid;
7136 free_backtalker (b); 7058 free_backtalker(b);
7137 return GNUNET_OK; 7059 return GNUNET_OK;
7138} 7060}
7139 7061
@@ -7144,18 +7066,18 @@ free_backtalker_cb (void *cls,
7144 * @param cls a `struct Backtalker` 7066 * @param cls a `struct Backtalker`
7145 */ 7067 */
7146static void 7068static void
7147backtalker_timeout_cb (void *cls) 7069backtalker_timeout_cb(void *cls)
7148{ 7070{
7149 struct Backtalker *b = cls; 7071 struct Backtalker *b = cls;
7150 7072
7151 b->task = NULL; 7073 b->task = NULL;
7152 if (0 != GNUNET_TIME_absolute_get_remaining (b->timeout).rel_value_us) 7074 if (0 != GNUNET_TIME_absolute_get_remaining(b->timeout).rel_value_us)
7153 { 7075 {
7154 b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); 7076 b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b);
7155 return; 7077 return;
7156 } 7078 }
7157 GNUNET_assert (NULL == b->sc); 7079 GNUNET_assert(NULL == b->sc);
7158 free_backtalker (b); 7080 free_backtalker(b);
7159} 7081}
7160 7082
7161 7083
@@ -7168,52 +7090,52 @@ backtalker_timeout_cb (void *cls)
7168 * @param emsg error message 7090 * @param emsg error message
7169 */ 7091 */
7170static void 7092static void
7171backtalker_monotime_cb (void *cls, 7093backtalker_monotime_cb(void *cls,
7172 const struct GNUNET_PEERSTORE_Record *record, 7094 const struct GNUNET_PEERSTORE_Record *record,
7173 const char *emsg) 7095 const char *emsg)
7174{ 7096{
7175 struct Backtalker *b = cls; 7097 struct Backtalker *b = cls;
7176 struct GNUNET_TIME_AbsoluteNBO *mtbe; 7098 struct GNUNET_TIME_AbsoluteNBO *mtbe;
7177 struct GNUNET_TIME_Absolute mt; 7099 struct GNUNET_TIME_Absolute mt;
7178 7100
7179 (void) emsg; 7101 (void)emsg;
7180 if (NULL == record) 7102 if (NULL == record)
7181 { 7103 {
7182 /* we're done with #backtalker_monotime_cb() invocations, 7104 /* we're done with #backtalker_monotime_cb() invocations,
7183 continue normal processing */ 7105 continue normal processing */
7184 b->get = NULL; 7106 b->get = NULL;
7185 GNUNET_assert (NULL != b->cmc); 7107 GNUNET_assert(NULL != b->cmc);
7186 if (0 != b->body_size) 7108 if (0 != b->body_size)
7187 demultiplex_with_cmc (b->cmc, 7109 demultiplex_with_cmc(b->cmc,
7188 (const struct GNUNET_MessageHeader *) &b[1]); 7110 (const struct GNUNET_MessageHeader *)&b[1]);
7189 else 7111 else
7190 finish_cmc_handling (b->cmc); 7112 finish_cmc_handling(b->cmc);
7191 b->cmc = NULL; 7113 b->cmc = NULL;
7192 return; 7114 return;
7193 } 7115 }
7194 if (sizeof (*mtbe) != record->value_size) 7116 if (sizeof(*mtbe) != record->value_size)
7195 { 7117 {
7196 GNUNET_break (0); 7118 GNUNET_break(0);
7197 return; 7119 return;
7198 } 7120 }
7199 mtbe = record->value; 7121 mtbe = record->value;
7200 mt = GNUNET_TIME_absolute_ntoh (*mtbe); 7122 mt = GNUNET_TIME_absolute_ntoh(*mtbe);
7201 if (mt.abs_value_us > b->monotonic_time.abs_value_us) 7123 if (mt.abs_value_us > b->monotonic_time.abs_value_us)
7202 { 7124 {
7203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7125 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7204 "Backtalker message from %s dropped, monotime in the past\n", 7126 "Backtalker message from %s dropped, monotime in the past\n",
7205 GNUNET_i2s (&b->pid)); 7127 GNUNET_i2s(&b->pid));
7206 GNUNET_STATISTICS_update ( 7128 GNUNET_STATISTICS_update(
7207 GST_stats, 7129 GST_stats,
7208 "# Backchannel messages dropped: monotonic time not increasing", 7130 "# Backchannel messages dropped: monotonic time not increasing",
7209 1, 7131 1,
7210 GNUNET_NO); 7132 GNUNET_NO);
7211 b->monotonic_time = mt; 7133 b->monotonic_time = mt;
7212 /* Setting body_size to 0 prevents call to #forward_backchannel_payload() 7134 /* Setting body_size to 0 prevents call to #forward_backchannel_payload()
7213 */ 7135 */
7214 b->body_size = 0; 7136 b->body_size = 0;
7215 return; 7137 return;
7216 } 7138 }
7217} 7139}
7218 7140
7219 7141
@@ -7225,17 +7147,17 @@ backtalker_monotime_cb (void *cls,
7225 * @param success #GNUNET_OK on success 7147 * @param success #GNUNET_OK on success
7226 */ 7148 */
7227static void 7149static void
7228backtalker_monotime_store_cb (void *cls, int success) 7150backtalker_monotime_store_cb(void *cls, int success)
7229{ 7151{
7230 struct Backtalker *b = cls; 7152 struct Backtalker *b = cls;
7231 7153
7232 if (GNUNET_OK != success) 7154 if (GNUNET_OK != success)
7233 { 7155 {
7234 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 7156 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
7235 "Failed to store backtalker's monotonic time in PEERSTORE!\n"); 7157 "Failed to store backtalker's monotonic time in PEERSTORE!\n");
7236 } 7158 }
7237 b->sc = NULL; 7159 b->sc = NULL;
7238 b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); 7160 b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b);
7239} 7161}
7240 7162
7241 7163
@@ -7245,32 +7167,32 @@ backtalker_monotime_store_cb (void *cls, int success)
7245 * @param b a backtalker with updated monotonic time 7167 * @param b a backtalker with updated monotonic time
7246 */ 7168 */
7247static void 7169static void
7248update_backtalker_monotime (struct Backtalker *b) 7170update_backtalker_monotime(struct Backtalker *b)
7249{ 7171{
7250 struct GNUNET_TIME_AbsoluteNBO mtbe; 7172 struct GNUNET_TIME_AbsoluteNBO mtbe;
7251 7173
7252 if (NULL != b->sc) 7174 if (NULL != b->sc)
7253 { 7175 {
7254 GNUNET_PEERSTORE_store_cancel (b->sc); 7176 GNUNET_PEERSTORE_store_cancel(b->sc);
7255 b->sc = NULL; 7177 b->sc = NULL;
7256 } 7178 }
7257 else 7179 else
7258 { 7180 {
7259 GNUNET_SCHEDULER_cancel (b->task); 7181 GNUNET_SCHEDULER_cancel(b->task);
7260 b->task = NULL; 7182 b->task = NULL;
7261 } 7183 }
7262 mtbe = GNUNET_TIME_absolute_hton (b->monotonic_time); 7184 mtbe = GNUNET_TIME_absolute_hton(b->monotonic_time);
7263 b->sc = 7185 b->sc =
7264 GNUNET_PEERSTORE_store (peerstore, 7186 GNUNET_PEERSTORE_store(peerstore,
7265 "transport", 7187 "transport",
7266 &b->pid, 7188 &b->pid,
7267 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, 7189 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME,
7268 &mtbe, 7190 &mtbe,
7269 sizeof (mtbe), 7191 sizeof(mtbe),
7270 GNUNET_TIME_UNIT_FOREVER_ABS, 7192 GNUNET_TIME_UNIT_FOREVER_ABS,
7271 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 7193 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
7272 &backtalker_monotime_store_cb, 7194 &backtalker_monotime_store_cb,
7273 b); 7195 b);
7274} 7196}
7275 7197
7276 7198
@@ -7282,221 +7204,223 @@ update_backtalker_monotime (struct Backtalker *b)
7282 * @param dvb the message that was received 7204 * @param dvb the message that was received
7283 */ 7205 */
7284static void 7206static void
7285handle_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) 7207handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb)
7286{ 7208{
7287 struct CommunicatorMessageContext *cmc = cls; 7209 struct CommunicatorMessageContext *cmc = cls;
7288 uint16_t size = ntohs (dvb->header.size) - sizeof (*dvb); 7210 uint16_t size = ntohs(dvb->header.size) - sizeof(*dvb);
7289 uint16_t num_hops = ntohs (dvb->num_hops); 7211 uint16_t num_hops = ntohs(dvb->num_hops);
7290 const struct GNUNET_PeerIdentity *hops = 7212 const struct GNUNET_PeerIdentity *hops =
7291 (const struct GNUNET_PeerIdentity *) &dvb[1]; 7213 (const struct GNUNET_PeerIdentity *)&dvb[1];
7292 const char *enc_payload = (const char *) &hops[num_hops]; 7214 const char *enc_payload = (const char *)&hops[num_hops];
7293 uint16_t enc_payload_size = 7215 uint16_t enc_payload_size =
7294 size - (num_hops * sizeof (struct GNUNET_PeerIdentity)); 7216 size - (num_hops * sizeof(struct GNUNET_PeerIdentity));
7295 struct DVKeyState key; 7217 struct DVKeyState key;
7296 struct GNUNET_HashCode hmac; 7218 struct GNUNET_HashCode hmac;
7297 const char *hdr; 7219 const char *hdr;
7298 size_t hdr_len; 7220 size_t hdr_len;
7299 7221
7300 if (GNUNET_EXTRA_LOGGING > 0) 7222 if (GNUNET_EXTRA_LOGGING > 0)
7301 {
7302 char *path;
7303
7304 path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity));
7305 for (unsigned int i = 0; i < num_hops; i++)
7306 { 7223 {
7307 char *tmp; 7224 char *path;
7225
7226 path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity));
7227 for (unsigned int i = 0; i < num_hops; i++)
7228 {
7229 char *tmp;
7308 7230
7309 GNUNET_asprintf (&tmp, "%s->%s", path, GNUNET_i2s (&hops[i])); 7231 GNUNET_asprintf(&tmp, "%s->%s", path, GNUNET_i2s(&hops[i]));
7310 GNUNET_free (path); 7232 GNUNET_free(path);
7311 path = tmp; 7233 path = tmp;
7234 }
7235 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7236 "Received DVBox with remainig path %s\n",
7237 path);
7238 GNUNET_free(path);
7312 } 7239 }
7313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7314 "Received DVBox with remainig path %s\n",
7315 path);
7316 GNUNET_free (path);
7317 }
7318 7240
7319 if (num_hops > 0) 7241 if (num_hops > 0)
7320 {
7321 /* We're trying from the end of the hops array, as we may be
7322 able to find a shortcut unknown to the origin that way */
7323 for (int i = num_hops - 1; i >= 0; i--)
7324 { 7242 {
7325 struct Neighbour *n; 7243 /* We're trying from the end of the hops array, as we may be
7326 7244 able to find a shortcut unknown to the origin that way */
7327 if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity)) 7245 for (int i = num_hops - 1; i >= 0; i--)
7328 { 7246 {
7329 GNUNET_break_op (0); 7247 struct Neighbour *n;
7330 finish_cmc_handling (cmc); 7248
7331 return; 7249 if (0 == GNUNET_memcmp(&hops[i], &GST_my_identity))
7332 } 7250 {
7333 n = lookup_neighbour (&hops[i]); 7251 GNUNET_break_op(0);
7334 if (NULL == n) 7252 finish_cmc_handling(cmc);
7335 continue; 7253 return;
7336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7254 }
7337 "Skipping %u/%u hops ahead while routing DV Box\n", 7255 n = lookup_neighbour(&hops[i]);
7338 i, 7256 if (NULL == n)
7339 num_hops); 7257 continue;
7340 forward_dv_box (n, 7258 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7341 dvb, 7259 "Skipping %u/%u hops ahead while routing DV Box\n",
7342 ntohs (dvb->total_hops) + 1, 7260 i,
7343 num_hops - i - 1, /* number of hops left */ 7261 num_hops);
7344 &hops[i + 1], /* remaining hops */ 7262 forward_dv_box(n,
7345 enc_payload, 7263 dvb,
7346 enc_payload_size); 7264 ntohs(dvb->total_hops) + 1,
7347 GNUNET_STATISTICS_update (GST_stats, 7265 num_hops - i - 1, /* number of hops left */
7348 "# DV hops skipped routing boxes", 7266 &hops[i + 1], /* remaining hops */
7349 i, 7267 enc_payload,
7350 GNUNET_NO); 7268 enc_payload_size);
7351 GNUNET_STATISTICS_update (GST_stats, 7269 GNUNET_STATISTICS_update(GST_stats,
7352 "# DV boxes routed (total)", 7270 "# DV hops skipped routing boxes",
7353 1, 7271 i,
7354 GNUNET_NO); 7272 GNUNET_NO);
7355 finish_cmc_handling (cmc); 7273 GNUNET_STATISTICS_update(GST_stats,
7274 "# DV boxes routed (total)",
7275 1,
7276 GNUNET_NO);
7277 finish_cmc_handling(cmc);
7278 return;
7279 }
7280 /* Woopsie, next hop not in neighbours, drop! */
7281 GNUNET_STATISTICS_update(GST_stats,
7282 "# DV Boxes dropped: next hop unknown",
7283 1,
7284 GNUNET_NO);
7285 finish_cmc_handling(cmc);
7356 return; 7286 return;
7357 } 7287 }
7358 /* Woopsie, next hop not in neighbours, drop! */
7359 GNUNET_STATISTICS_update (GST_stats,
7360 "# DV Boxes dropped: next hop unknown",
7361 1,
7362 GNUNET_NO);
7363 finish_cmc_handling (cmc);
7364 return;
7365 }
7366 /* We are the target. Unbox and handle message. */ 7288 /* We are the target. Unbox and handle message. */
7367 GNUNET_STATISTICS_update (GST_stats, 7289 GNUNET_STATISTICS_update(GST_stats,
7368 "# DV boxes opened (ultimate target)", 7290 "# DV boxes opened (ultimate target)",
7369 1, 7291 1,
7370 GNUNET_NO); 7292 GNUNET_NO);
7371 cmc->total_hops = ntohs (dvb->total_hops); 7293 cmc->total_hops = ntohs(dvb->total_hops);
7372 7294
7373 dh_key_derive_eph_pub (&dvb->ephemeral_key, &dvb->iv, &key); 7295 dh_key_derive_eph_pub(&dvb->ephemeral_key, &dvb->iv, &key);
7374 hdr = (const char *) &dvb[1]; 7296 hdr = (const char *)&dvb[1];
7375 hdr_len = ntohs (dvb->header.size) - sizeof (*dvb); 7297 hdr_len = ntohs(dvb->header.size) - sizeof(*dvb);
7376 dv_hmac (&key, &hmac, hdr, hdr_len); 7298 dv_hmac(&key, &hmac, hdr, hdr_len);
7377 if (0 != GNUNET_memcmp (&hmac, &dvb->hmac)) 7299 if (0 != GNUNET_memcmp(&hmac, &dvb->hmac))
7378 { 7300 {
7379 /* HMAC missmatch, disard! */ 7301 /* HMAC missmatch, disard! */
7380 GNUNET_break_op (0); 7302 GNUNET_break_op(0);
7381 finish_cmc_handling (cmc); 7303 finish_cmc_handling(cmc);
7382 return; 7304 return;
7383 } 7305 }
7384 /* begin actual decryption */ 7306 /* begin actual decryption */
7385 { 7307 {
7386 struct Backtalker *b; 7308 struct Backtalker *b;
7387 struct GNUNET_TIME_Absolute monotime; 7309 struct GNUNET_TIME_Absolute monotime;
7388 struct TransportDVBoxPayloadP ppay; 7310 struct TransportDVBoxPayloadP ppay;
7389 char body[hdr_len - sizeof (ppay)] GNUNET_ALIGN; 7311 char body[hdr_len - sizeof(ppay)] GNUNET_ALIGN;
7390 const struct GNUNET_MessageHeader *mh = 7312 const struct GNUNET_MessageHeader *mh =
7391 (const struct GNUNET_MessageHeader *) body; 7313 (const struct GNUNET_MessageHeader *)body;
7392 7314
7393 GNUNET_assert (hdr_len >= 7315 GNUNET_assert(hdr_len >=
7394 sizeof (ppay) + sizeof (struct GNUNET_MessageHeader)); 7316 sizeof(ppay) + sizeof(struct GNUNET_MessageHeader));
7395 dv_decrypt (&key, &ppay, hdr, sizeof (ppay)); 7317 dv_decrypt(&key, &ppay, hdr, sizeof(ppay));
7396 dv_decrypt (&key, &body, &hdr[sizeof (ppay)], hdr_len - sizeof (ppay)); 7318 dv_decrypt(&key, &body, &hdr[sizeof(ppay)], hdr_len - sizeof(ppay));
7397 dv_key_clean (&key); 7319 dv_key_clean(&key);
7398 if (ntohs (mh->size) != sizeof (body)) 7320 if (ntohs(mh->size) != sizeof(body))
7399 { 7321 {
7400 GNUNET_break_op (0); 7322 GNUNET_break_op(0);
7401 finish_cmc_handling (cmc); 7323 finish_cmc_handling(cmc);
7402 return; 7324 return;
7403 } 7325 }
7404 /* need to prevent box-in-a-box (and DV_LEARN) so check inbox type! */ 7326 /* need to prevent box-in-a-box (and DV_LEARN) so check inbox type! */
7405 switch (ntohs (mh->type)) 7327 switch (ntohs(mh->type))
7406 { 7328 {
7407 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX: 7329 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX:
7408 GNUNET_break_op (0); 7330 GNUNET_break_op(0);
7409 finish_cmc_handling (cmc); 7331 finish_cmc_handling(cmc);
7410 return; 7332 return;
7411 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN: 7333
7412 GNUNET_break_op (0); 7334 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN:
7413 finish_cmc_handling (cmc); 7335 GNUNET_break_op(0);
7414 return; 7336 finish_cmc_handling(cmc);
7415 default: 7337 return;
7416 /* permitted, continue */ 7338
7417 break; 7339 default:
7418 } 7340 /* permitted, continue */
7419 monotime = GNUNET_TIME_absolute_ntoh (ppay.monotonic_time); 7341 break;
7420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7342 }
7421 "Decrypted backtalk from %s\n", 7343 monotime = GNUNET_TIME_absolute_ntoh(ppay.monotonic_time);
7422 GNUNET_i2s (&ppay.sender)); 7344 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7423 b = GNUNET_CONTAINER_multipeermap_get (backtalkers, &ppay.sender); 7345 "Decrypted backtalk from %s\n",
7346 GNUNET_i2s(&ppay.sender));
7347 b = GNUNET_CONTAINER_multipeermap_get(backtalkers, &ppay.sender);
7424 if ((NULL != b) && (monotime.abs_value_us < b->monotonic_time.abs_value_us)) 7348 if ((NULL != b) && (monotime.abs_value_us < b->monotonic_time.abs_value_us))
7425 {
7426 GNUNET_STATISTICS_update (
7427 GST_stats,
7428 "# Backchannel messages dropped: monotonic time not increasing",
7429 1,
7430 GNUNET_NO);
7431 finish_cmc_handling (cmc);
7432 return;
7433 }
7434 if ((NULL == b) ||
7435 (0 != GNUNET_memcmp (&b->last_ephemeral, &dvb->ephemeral_key)))
7436 {
7437 /* Check signature */
7438 struct EphemeralConfirmationPS ec;
7439
7440 ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
7441 ec.purpose.size = htonl (sizeof (ec));
7442 ec.target = GST_my_identity;
7443 ec.ephemeral_key = dvb->ephemeral_key;
7444 if (
7445 GNUNET_OK !=
7446 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL,
7447 &ec.purpose,
7448 &ppay.sender_sig,
7449 &ppay.sender.public_key))
7450 { 7349 {
7451 /* Signature invalid, disard! */ 7350 GNUNET_STATISTICS_update(
7452 GNUNET_break_op (0); 7351 GST_stats,
7453 finish_cmc_handling (cmc); 7352 "# Backchannel messages dropped: monotonic time not increasing",
7353 1,
7354 GNUNET_NO);
7355 finish_cmc_handling(cmc);
7454 return; 7356 return;
7455 } 7357 }
7456 } 7358 if ((NULL == b) ||
7359 (0 != GNUNET_memcmp(&b->last_ephemeral, &dvb->ephemeral_key)))
7360 {
7361 /* Check signature */
7362 struct EphemeralConfirmationPS ec;
7363
7364 ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
7365 ec.purpose.size = htonl(sizeof(ec));
7366 ec.target = GST_my_identity;
7367 ec.ephemeral_key = dvb->ephemeral_key;
7368 if (
7369 GNUNET_OK !=
7370 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL,
7371 &ec.purpose,
7372 &ppay.sender_sig,
7373 &ppay.sender.public_key))
7374 {
7375 /* Signature invalid, disard! */
7376 GNUNET_break_op(0);
7377 finish_cmc_handling(cmc);
7378 return;
7379 }
7380 }
7457 /* Update sender, we now know the real origin! */ 7381 /* Update sender, we now know the real origin! */
7458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7382 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7459 "DVBox received for me from %s via %s\n", 7383 "DVBox received for me from %s via %s\n",
7460 GNUNET_i2s2 (&ppay.sender), 7384 GNUNET_i2s2(&ppay.sender),
7461 GNUNET_i2s (&cmc->im.sender)); 7385 GNUNET_i2s(&cmc->im.sender));
7462 cmc->im.sender = ppay.sender; 7386 cmc->im.sender = ppay.sender;
7463 7387
7464 if (NULL != b) 7388 if (NULL != b)
7465 { 7389 {
7466 /* update key cache and mono time */ 7390 /* update key cache and mono time */
7467 b->last_ephemeral = dvb->ephemeral_key; 7391 b->last_ephemeral = dvb->ephemeral_key;
7468 b->monotonic_time = monotime; 7392 b->monotonic_time = monotime;
7469 update_backtalker_monotime (b); 7393 update_backtalker_monotime(b);
7470 b->timeout = 7394 b->timeout =
7471 GNUNET_TIME_relative_to_absolute (BACKCHANNEL_INACTIVITY_TIMEOUT); 7395 GNUNET_TIME_relative_to_absolute(BACKCHANNEL_INACTIVITY_TIMEOUT);
7472 7396
7473 demultiplex_with_cmc (cmc, mh); 7397 demultiplex_with_cmc(cmc, mh);
7474 return; 7398 return;
7475 } 7399 }
7476 /* setup data structure to cache signature AND check 7400 /* setup data structure to cache signature AND check
7477 monotonic time with PEERSTORE before forwarding backchannel payload */ 7401 monotonic time with PEERSTORE before forwarding backchannel payload */
7478 b = GNUNET_malloc (sizeof (struct Backtalker) + sizeof (body)); 7402 b = GNUNET_malloc(sizeof(struct Backtalker) + sizeof(body));
7479 b->pid = ppay.sender; 7403 b->pid = ppay.sender;
7480 b->body_size = sizeof (body); 7404 b->body_size = sizeof(body);
7481 memcpy (&b[1], body, sizeof (body)); 7405 memcpy(&b[1], body, sizeof(body));
7482 GNUNET_assert (GNUNET_YES == 7406 GNUNET_assert(GNUNET_YES ==
7483 GNUNET_CONTAINER_multipeermap_put ( 7407 GNUNET_CONTAINER_multipeermap_put(
7484 backtalkers, 7408 backtalkers,
7485 &b->pid, 7409 &b->pid,
7486 b, 7410 b,
7487 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 7411 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
7488 b->monotonic_time = monotime; /* NOTE: to be checked still! */ 7412 b->monotonic_time = monotime; /* NOTE: to be checked still! */
7489 b->cmc = cmc; 7413 b->cmc = cmc;
7490 b->timeout = 7414 b->timeout =
7491 GNUNET_TIME_relative_to_absolute (BACKCHANNEL_INACTIVITY_TIMEOUT); 7415 GNUNET_TIME_relative_to_absolute(BACKCHANNEL_INACTIVITY_TIMEOUT);
7492 b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); 7416 b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b);
7493 b->get = 7417 b->get =
7494 GNUNET_PEERSTORE_iterate (peerstore, 7418 GNUNET_PEERSTORE_iterate(peerstore,
7495 "transport", 7419 "transport",
7496 &b->pid, 7420 &b->pid,
7497 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, 7421 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME,
7498 &backtalker_monotime_cb, 7422 &backtalker_monotime_cb,
7499 b); 7423 b);
7500 } /* end actual decryption */ 7424 } /* end actual decryption */
7501} 7425}
7502 7426
@@ -7509,17 +7433,17 @@ handle_dv_box (void *cls, const struct TransportDVBoxMessage *dvb)
7509 * @return #GNUNET_YES if message is well-formed 7433 * @return #GNUNET_YES if message is well-formed
7510 */ 7434 */
7511static int 7435static int
7512check_incoming_msg (void *cls, 7436check_incoming_msg(void *cls,
7513 const struct GNUNET_TRANSPORT_IncomingMessage *im) 7437 const struct GNUNET_TRANSPORT_IncomingMessage *im)
7514{ 7438{
7515 struct TransportClient *tc = cls; 7439 struct TransportClient *tc = cls;
7516 7440
7517 if (CT_COMMUNICATOR != tc->type) 7441 if (CT_COMMUNICATOR != tc->type)
7518 { 7442 {
7519 GNUNET_break (0); 7443 GNUNET_break(0);
7520 return GNUNET_SYSERR; 7444 return GNUNET_SYSERR;
7521 } 7445 }
7522 GNUNET_MQ_check_boxed_message (im); 7446 GNUNET_MQ_check_boxed_message(im);
7523 return GNUNET_OK; 7447 return GNUNET_OK;
7524} 7448}
7525 7449
@@ -7527,8 +7451,7 @@ check_incoming_msg (void *cls,
7527/** 7451/**
7528 * Closure for #check_known_address. 7452 * Closure for #check_known_address.
7529 */ 7453 */
7530struct CheckKnownAddressContext 7454struct CheckKnownAddressContext {
7531{
7532 /** 7455 /**
7533 * Set to the address we are looking for. 7456 * Set to the address we are looking for.
7534 */ 7457 */
@@ -7551,15 +7474,15 @@ struct CheckKnownAddressContext
7551 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found 7474 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found
7552 */ 7475 */
7553static int 7476static int
7554check_known_address (void *cls, 7477check_known_address(void *cls,
7555 const struct GNUNET_PeerIdentity *pid, 7478 const struct GNUNET_PeerIdentity *pid,
7556 void *value) 7479 void *value)
7557{ 7480{
7558 struct CheckKnownAddressContext *ckac = cls; 7481 struct CheckKnownAddressContext *ckac = cls;
7559 struct ValidationState *vs = value; 7482 struct ValidationState *vs = value;
7560 7483
7561 (void) pid; 7484 (void)pid;
7562 if (0 != strcmp (vs->address, ckac->address)) 7485 if (0 != strcmp(vs->address, ckac->address))
7563 return GNUNET_OK; 7486 return GNUNET_OK;
7564 ckac->vs = vs; 7487 ckac->vs = vs;
7565 return GNUNET_NO; 7488 return GNUNET_NO;
@@ -7572,7 +7495,7 @@ check_known_address (void *cls,
7572 * @param cls NULL 7495 * @param cls NULL
7573 */ 7496 */
7574static void 7497static void
7575validation_start_cb (void *cls); 7498validation_start_cb(void *cls);
7576 7499
7577 7500
7578/** 7501/**
@@ -7583,8 +7506,8 @@ validation_start_cb (void *cls);
7583 * @param new_time new time for revalidation 7506 * @param new_time new time for revalidation
7584 */ 7507 */
7585static void 7508static void
7586update_next_challenge_time (struct ValidationState *vs, 7509update_next_challenge_time(struct ValidationState *vs,
7587 struct GNUNET_TIME_Absolute new_time) 7510 struct GNUNET_TIME_Absolute new_time)
7588{ 7511{
7589 struct GNUNET_TIME_Relative delta; 7512 struct GNUNET_TIME_Relative delta;
7590 7513
@@ -7593,21 +7516,21 @@ update_next_challenge_time (struct ValidationState *vs,
7593 vs->next_challenge = new_time; 7516 vs->next_challenge = new_time;
7594 if (NULL == vs->hn) 7517 if (NULL == vs->hn)
7595 vs->hn = 7518 vs->hn =
7596 GNUNET_CONTAINER_heap_insert (validation_heap, vs, new_time.abs_value_us); 7519 GNUNET_CONTAINER_heap_insert(validation_heap, vs, new_time.abs_value_us);
7597 else 7520 else
7598 GNUNET_CONTAINER_heap_update_cost (vs->hn, new_time.abs_value_us); 7521 GNUNET_CONTAINER_heap_update_cost(vs->hn, new_time.abs_value_us);
7599 if ((vs != GNUNET_CONTAINER_heap_peek (validation_heap)) && 7522 if ((vs != GNUNET_CONTAINER_heap_peek(validation_heap)) &&
7600 (NULL != validation_task)) 7523 (NULL != validation_task))
7601 return; 7524 return;
7602 if (NULL != validation_task) 7525 if (NULL != validation_task)
7603 GNUNET_SCHEDULER_cancel (validation_task); 7526 GNUNET_SCHEDULER_cancel(validation_task);
7604 /* randomize a bit */ 7527 /* randomize a bit */
7605 delta.rel_value_us = 7528 delta.rel_value_us =
7606 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 7529 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
7607 MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); 7530 MIN_DELAY_ADDRESS_VALIDATION.rel_value_us);
7608 new_time = GNUNET_TIME_absolute_add (new_time, delta); 7531 new_time = GNUNET_TIME_absolute_add(new_time, delta);
7609 validation_task = 7532 validation_task =
7610 GNUNET_SCHEDULER_add_at (new_time, &validation_start_cb, NULL); 7533 GNUNET_SCHEDULER_add_at(new_time, &validation_start_cb, NULL);
7611} 7534}
7612 7535
7613 7536
@@ -7618,57 +7541,57 @@ update_next_challenge_time (struct ValidationState *vs,
7618 * @param address an address to reach @a pid (presumably) 7541 * @param address an address to reach @a pid (presumably)
7619 */ 7542 */
7620static void 7543static void
7621start_address_validation (const struct GNUNET_PeerIdentity *pid, 7544start_address_validation(const struct GNUNET_PeerIdentity *pid,
7622 const char *address) 7545 const char *address)
7623{ 7546{
7624 struct GNUNET_TIME_Absolute now; 7547 struct GNUNET_TIME_Absolute now;
7625 struct ValidationState *vs; 7548 struct ValidationState *vs;
7626 struct CheckKnownAddressContext ckac = {.address = address, .vs = NULL}; 7549 struct CheckKnownAddressContext ckac = { .address = address, .vs = NULL };
7627 7550
7628 (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, 7551 (void)GNUNET_CONTAINER_multipeermap_get_multiple(validation_map,
7629 pid, 7552 pid,
7630 &check_known_address, 7553 &check_known_address,
7631 &ckac); 7554 &ckac);
7632 if (NULL != (vs = ckac.vs)) 7555 if (NULL != (vs = ckac.vs))
7633 { 7556 {
7634 /* if 'vs' is not currently valid, we need to speed up retrying the 7557 /* if 'vs' is not currently valid, we need to speed up retrying the
7635 * validation */ 7558 * validation */
7636 if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) 7559 if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us)
7637 { 7560 {
7638 /* reduce backoff as we got a fresh advertisement */ 7561 /* reduce backoff as we got a fresh advertisement */
7639 vs->challenge_backoff = 7562 vs->challenge_backoff =
7640 GNUNET_TIME_relative_min (FAST_VALIDATION_CHALLENGE_FREQ, 7563 GNUNET_TIME_relative_min(FAST_VALIDATION_CHALLENGE_FREQ,
7641 GNUNET_TIME_relative_divide (vs->challenge_backoff, 7564 GNUNET_TIME_relative_divide(vs->challenge_backoff,
7642 2)); 7565 2));
7643 update_next_challenge_time (vs, 7566 update_next_challenge_time(vs,
7644 GNUNET_TIME_relative_to_absolute ( 7567 GNUNET_TIME_relative_to_absolute(
7645 vs->challenge_backoff)); 7568 vs->challenge_backoff));
7569 }
7570 return;
7646 } 7571 }
7647 return; 7572 now = GNUNET_TIME_absolute_get();
7648 } 7573 vs = GNUNET_new(struct ValidationState);
7649 now = GNUNET_TIME_absolute_get ();
7650 vs = GNUNET_new (struct ValidationState);
7651 vs->pid = *pid; 7574 vs->pid = *pid;
7652 vs->valid_until = 7575 vs->valid_until =
7653 GNUNET_TIME_relative_to_absolute (ADDRESS_VALIDATION_LIFETIME); 7576 GNUNET_TIME_relative_to_absolute(ADDRESS_VALIDATION_LIFETIME);
7654 vs->first_challenge_use = now; 7577 vs->first_challenge_use = now;
7655 vs->validation_rtt = GNUNET_TIME_UNIT_FOREVER_REL; 7578 vs->validation_rtt = GNUNET_TIME_UNIT_FOREVER_REL;
7656 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 7579 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
7657 &vs->challenge, 7580 &vs->challenge,
7658 sizeof (vs->challenge)); 7581 sizeof(vs->challenge));
7659 vs->address = GNUNET_strdup (address); 7582 vs->address = GNUNET_strdup(address);
7660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7583 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7661 "Starting address validation `%s' of peer %s using challenge %s\n", 7584 "Starting address validation `%s' of peer %s using challenge %s\n",
7662 address, 7585 address,
7663 GNUNET_i2s (pid), 7586 GNUNET_i2s(pid),
7664 GNUNET_sh2s (&vs->challenge.value)); 7587 GNUNET_sh2s(&vs->challenge.value));
7665 GNUNET_assert (GNUNET_YES == 7588 GNUNET_assert(GNUNET_YES ==
7666 GNUNET_CONTAINER_multipeermap_put ( 7589 GNUNET_CONTAINER_multipeermap_put(
7667 validation_map, 7590 validation_map,
7668 &vs->pid, 7591 &vs->pid,
7669 vs, 7592 vs,
7670 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 7593 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
7671 update_next_challenge_time (vs, now); 7594 update_next_challenge_time(vs, now);
7672} 7595}
7673 7596
7674 7597
@@ -7680,27 +7603,27 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
7680 * @param emsg error message, or NULL if no errors 7603 * @param emsg error message, or NULL if no errors
7681 */ 7604 */
7682static void 7605static void
7683handle_hello_for_incoming (void *cls, 7606handle_hello_for_incoming(void *cls,
7684 const struct GNUNET_PEERSTORE_Record *record, 7607 const struct GNUNET_PEERSTORE_Record *record,
7685 const char *emsg) 7608 const char *emsg)
7686{ 7609{
7687 struct IncomingRequest *ir = cls; 7610 struct IncomingRequest *ir = cls;
7688 const char *val; 7611 const char *val;
7689 7612
7690 if (NULL != emsg) 7613 if (NULL != emsg)
7691 { 7614 {
7692 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 7615 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
7693 "Got failure from PEERSTORE: %s\n", 7616 "Got failure from PEERSTORE: %s\n",
7694 emsg); 7617 emsg);
7695 return; 7618 return;
7696 } 7619 }
7697 val = record->value; 7620 val = record->value;
7698 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) 7621 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1]))
7699 { 7622 {
7700 GNUNET_break (0); 7623 GNUNET_break(0);
7701 return; 7624 return;
7702 } 7625 }
7703 start_address_validation (&ir->pid, (const char *) record->value); 7626 start_address_validation(&ir->pid, (const char *)record->value);
7704} 7627}
7705 7628
7706 7629
@@ -7713,7 +7636,7 @@ handle_hello_for_incoming (void *cls,
7713 * @param tvc the message that was received 7636 * @param tvc the message that was received
7714 */ 7637 */
7715static void 7638static void
7716handle_validation_challenge ( 7639handle_validation_challenge(
7717 void *cls, 7640 void *cls,
7718 const struct TransportValidationChallengeMessage *tvc) 7641 const struct TransportValidationChallengeMessage *tvc)
7719{ 7642{
@@ -7727,44 +7650,44 @@ handle_validation_challenge (
7727 7650
7728 /* DV-routed messages are not allowed for validation challenges */ 7651 /* DV-routed messages are not allowed for validation challenges */
7729 if (cmc->total_hops > 0) 7652 if (cmc->total_hops > 0)
7730 { 7653 {
7731 GNUNET_break_op (0); 7654 GNUNET_break_op(0);
7732 finish_cmc_handling (cmc); 7655 finish_cmc_handling(cmc);
7733 return; 7656 return;
7734 } 7657 }
7735 validity_duration = cmc->im.expected_address_validity; 7658 validity_duration = cmc->im.expected_address_validity;
7736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7659 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7737 "Received address validation challenge %s\n", 7660 "Received address validation challenge %s\n",
7738 GNUNET_sh2s (&tvc->challenge.value)); 7661 GNUNET_sh2s(&tvc->challenge.value));
7739 /* If we have a virtual link, we use this mechanism to signal the 7662 /* If we have a virtual link, we use this mechanism to signal the
7740 size of the flow control window, and to allow the sender 7663 size of the flow control window, and to allow the sender
7741 to ask for increases. If for us the virtual link is still down, 7664 to ask for increases. If for us the virtual link is still down,
7742 we will always give a window size of zero. */ 7665 we will always give a window size of zero. */
7743 tvr.header.type = 7666 tvr.header.type =
7744 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); 7667 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE);
7745 tvr.header.size = htons (sizeof (tvr)); 7668 tvr.header.size = htons(sizeof(tvr));
7746 tvr.reserved = htonl (0); 7669 tvr.reserved = htonl(0);
7747 tvr.challenge = tvc->challenge; 7670 tvr.challenge = tvc->challenge;
7748 tvr.origin_time = tvc->sender_time; 7671 tvr.origin_time = tvc->sender_time;
7749 tvr.validity_duration = validity_duration; 7672 tvr.validity_duration = validity_duration;
7750 { 7673 {
7751 /* create signature */ 7674 /* create signature */
7752 struct TransportValidationPS tvp = 7675 struct TransportValidationPS tvp =
7753 {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), 7676 { .purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
7754 .purpose.size = htonl (sizeof (tvp)), 7677 .purpose.size = htonl(sizeof(tvp)),
7755 .validity_duration = validity_duration, 7678 .validity_duration = validity_duration,
7756 .challenge = tvc->challenge}; 7679 .challenge = tvc->challenge };
7757 7680
7758 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 7681 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key,
7759 &tvp.purpose, 7682 &tvp.purpose,
7760 &tvr.signature)); 7683 &tvr.signature));
7761 } 7684 }
7762 route_control_message_without_fc (&cmc->im.sender, 7685 route_control_message_without_fc(&cmc->im.sender,
7763 &tvr.header, 7686 &tvr.header,
7764 RMO_ANYTHING_GOES | RMO_REDUNDANT); 7687 RMO_ANYTHING_GOES | RMO_REDUNDANT);
7765 sender = cmc->im.sender; 7688 sender = cmc->im.sender;
7766 finish_cmc_handling (cmc); 7689 finish_cmc_handling(cmc);
7767 vl = lookup_virtual_link (&sender); 7690 vl = lookup_virtual_link(&sender);
7768 if (NULL != vl) 7691 if (NULL != vl)
7769 return; 7692 return;
7770 7693
@@ -7773,36 +7696,36 @@ handle_validation_challenge (
7773 CORE), so we must try to bring the link up! */ 7696 CORE), so we must try to bring the link up! */
7774 7697
7775 /* (1) Check existing queues, if any, we may be lucky! */ 7698 /* (1) Check existing queues, if any, we may be lucky! */
7776 n = lookup_neighbour (&sender); 7699 n = lookup_neighbour(&sender);
7777 if (NULL != n) 7700 if (NULL != n)
7778 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) 7701 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
7779 start_address_validation (&sender, q->address); 7702 start_address_validation(&sender, q->address);
7780 /* (2) Also try to see if we have addresses in PEERSTORE for this peer 7703 /* (2) Also try to see if we have addresses in PEERSTORE for this peer
7781 we could use */ 7704 we could use */
7782 for (ir = ir_head; NULL != ir; ir = ir->next) 7705 for (ir = ir_head; NULL != ir; ir = ir->next)
7783 if (0 == GNUNET_memcmp (&ir->pid, &sender)) 7706 if (0 == GNUNET_memcmp(&ir->pid, &sender))
7784 return; /* we are already trying */ 7707 return;
7785 ir = GNUNET_new (struct IncomingRequest); 7708 /* we are already trying */
7709 ir = GNUNET_new(struct IncomingRequest);
7786 ir->pid = sender; 7710 ir->pid = sender;
7787 GNUNET_CONTAINER_DLL_insert (ir_head, ir_tail, ir); 7711 GNUNET_CONTAINER_DLL_insert(ir_head, ir_tail, ir);
7788 ir->wc = GNUNET_PEERSTORE_watch (peerstore, 7712 ir->wc = GNUNET_PEERSTORE_watch(peerstore,
7789 "transport", 7713 "transport",
7790 &ir->pid, 7714 &ir->pid,
7791 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, 7715 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
7792 &handle_hello_for_incoming, 7716 &handle_hello_for_incoming,
7793 ir); 7717 ir);
7794 ir_total++; 7718 ir_total++;
7795 /* Bound attempts we do in parallel here, might otherwise get excessive */ 7719 /* Bound attempts we do in parallel here, might otherwise get excessive */
7796 while (ir_total > MAX_INCOMING_REQUEST) 7720 while (ir_total > MAX_INCOMING_REQUEST)
7797 free_incoming_request (ir_head); 7721 free_incoming_request(ir_head);
7798} 7722}
7799 7723
7800 7724
7801/** 7725/**
7802 * Closure for #check_known_challenge. 7726 * Closure for #check_known_challenge.
7803 */ 7727 */
7804struct CheckKnownChallengeContext 7728struct CheckKnownChallengeContext {
7805{
7806 /** 7729 /**
7807 * Set to the challenge we are looking for. 7730 * Set to the challenge we are looking for.
7808 */ 7731 */
@@ -7825,15 +7748,15 @@ struct CheckKnownChallengeContext
7825 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found 7748 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found
7826 */ 7749 */
7827static int 7750static int
7828check_known_challenge (void *cls, 7751check_known_challenge(void *cls,
7829 const struct GNUNET_PeerIdentity *pid, 7752 const struct GNUNET_PeerIdentity *pid,
7830 void *value) 7753 void *value)
7831{ 7754{
7832 struct CheckKnownChallengeContext *ckac = cls; 7755 struct CheckKnownChallengeContext *ckac = cls;
7833 struct ValidationState *vs = value; 7756 struct ValidationState *vs = value;
7834 7757
7835 (void) pid; 7758 (void)pid;
7836 if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge)) 7759 if (0 != GNUNET_memcmp(&vs->challenge, ckac->challenge))
7837 return GNUNET_OK; 7760 return GNUNET_OK;
7838 ckac->vs = vs; 7761 ckac->vs = vs;
7839 return GNUNET_NO; 7762 return GNUNET_NO;
@@ -7848,17 +7771,17 @@ check_known_challenge (void *cls,
7848 * @param success #GNUNET_YES on success 7771 * @param success #GNUNET_YES on success
7849 */ 7772 */
7850static void 7773static void
7851peerstore_store_validation_cb (void *cls, int success) 7774peerstore_store_validation_cb(void *cls, int success)
7852{ 7775{
7853 struct ValidationState *vs = cls; 7776 struct ValidationState *vs = cls;
7854 7777
7855 vs->sc = NULL; 7778 vs->sc = NULL;
7856 if (GNUNET_YES == success) 7779 if (GNUNET_YES == success)
7857 return; 7780 return;
7858 GNUNET_STATISTICS_update (GST_stats, 7781 GNUNET_STATISTICS_update(GST_stats,
7859 "# Peerstore failed to store foreign address", 7782 "# Peerstore failed to store foreign address",
7860 1, 7783 1,
7861 GNUNET_NO); 7784 GNUNET_NO);
7862} 7785}
7863 7786
7864 7787
@@ -7870,19 +7793,19 @@ peerstore_store_validation_cb (void *cls, int success)
7870 * @return NULL if no such queue exists 7793 * @return NULL if no such queue exists
7871 */ 7794 */
7872static struct Queue * 7795static struct Queue *
7873find_queue (const struct GNUNET_PeerIdentity *pid, const char *address) 7796find_queue(const struct GNUNET_PeerIdentity *pid, const char *address)
7874{ 7797{
7875 struct Neighbour *n; 7798 struct Neighbour *n;
7876 7799
7877 n = lookup_neighbour (pid); 7800 n = lookup_neighbour(pid);
7878 if (NULL == n) 7801 if (NULL == n)
7879 return NULL; 7802 return NULL;
7880 for (struct Queue *pos = n->queue_head; NULL != pos; 7803 for (struct Queue *pos = n->queue_head; NULL != pos;
7881 pos = pos->next_neighbour) 7804 pos = pos->next_neighbour)
7882 { 7805 {
7883 if (0 == strcmp (pos->address, address)) 7806 if (0 == strcmp(pos->address, address))
7884 return pos; 7807 return pos;
7885 } 7808 }
7886 return NULL; 7809 return NULL;
7887} 7810}
7888 7811
@@ -7896,161 +7819,161 @@ find_queue (const struct GNUNET_PeerIdentity *pid, const char *address)
7896 * @param tvr the message that was received 7819 * @param tvr the message that was received
7897 */ 7820 */
7898static void 7821static void
7899handle_validation_response ( 7822handle_validation_response(
7900 void *cls, 7823 void *cls,
7901 const struct TransportValidationResponseMessage *tvr) 7824 const struct TransportValidationResponseMessage *tvr)
7902{ 7825{
7903 struct CommunicatorMessageContext *cmc = cls; 7826 struct CommunicatorMessageContext *cmc = cls;
7904 struct ValidationState *vs; 7827 struct ValidationState *vs;
7905 struct CheckKnownChallengeContext ckac = {.challenge = &tvr->challenge, 7828 struct CheckKnownChallengeContext ckac = { .challenge = &tvr->challenge,
7906 .vs = NULL}; 7829 .vs = NULL };
7907 struct GNUNET_TIME_Absolute origin_time; 7830 struct GNUNET_TIME_Absolute origin_time;
7908 struct Queue *q; 7831 struct Queue *q;
7909 struct Neighbour *n; 7832 struct Neighbour *n;
7910 struct VirtualLink *vl; 7833 struct VirtualLink *vl;
7911 7834
7912 /* check this is one of our challenges */ 7835 /* check this is one of our challenges */
7913 (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, 7836 (void)GNUNET_CONTAINER_multipeermap_get_multiple(validation_map,
7914 &cmc->im.sender, 7837 &cmc->im.sender,
7915 &check_known_challenge, 7838 &check_known_challenge,
7916 &ckac); 7839 &ckac);
7917 if (NULL == (vs = ckac.vs)) 7840 if (NULL == (vs = ckac.vs))
7918 { 7841 {
7919 /* This can happen simply if we 'forgot' the challenge by now, 7842 /* This can happen simply if we 'forgot' the challenge by now,
7920 i.e. because we received the validation response twice */ 7843 i.e. because we received the validation response twice */
7921 GNUNET_STATISTICS_update (GST_stats, 7844 GNUNET_STATISTICS_update(GST_stats,
7922 "# Validations dropped, challenge unknown", 7845 "# Validations dropped, challenge unknown",
7923 1, 7846 1,
7924 GNUNET_NO); 7847 GNUNET_NO);
7925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7848 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7926 "Validation response %s dropped, challenge unknown\n", 7849 "Validation response %s dropped, challenge unknown\n",
7927 GNUNET_sh2s (&tvr->challenge.value)); 7850 GNUNET_sh2s(&tvr->challenge.value));
7928 finish_cmc_handling (cmc); 7851 finish_cmc_handling(cmc);
7929 return; 7852 return;
7930 } 7853 }
7931 7854
7932 /* sanity check on origin time */ 7855 /* sanity check on origin time */
7933 origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time); 7856 origin_time = GNUNET_TIME_absolute_ntoh(tvr->origin_time);
7934 if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) || 7857 if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) ||
7935 (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us)) 7858 (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us))
7936 { 7859 {
7937 GNUNET_break_op (0); 7860 GNUNET_break_op(0);
7938 finish_cmc_handling (cmc); 7861 finish_cmc_handling(cmc);
7939 return; 7862 return;
7940 } 7863 }
7941 7864
7942 { 7865 {
7943 /* check signature */ 7866 /* check signature */
7944 struct TransportValidationPS tvp = 7867 struct TransportValidationPS tvp =
7945 {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), 7868 { .purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
7946 .purpose.size = htonl (sizeof (tvp)), 7869 .purpose.size = htonl(sizeof(tvp)),
7947 .validity_duration = tvr->validity_duration, 7870 .validity_duration = tvr->validity_duration,
7948 .challenge = tvr->challenge}; 7871 .challenge = tvr->challenge };
7949 7872
7950 if ( 7873 if (
7951 GNUNET_OK != 7874 GNUNET_OK !=
7952 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, 7875 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE,
7953 &tvp.purpose, 7876 &tvp.purpose,
7954 &tvr->signature, 7877 &tvr->signature,
7955 &cmc->im.sender.public_key)) 7878 &cmc->im.sender.public_key))
7956 { 7879 {
7957 GNUNET_break_op (0); 7880 GNUNET_break_op(0);
7958 finish_cmc_handling (cmc); 7881 finish_cmc_handling(cmc);
7959 return; 7882 return;
7960 } 7883 }
7961 } 7884 }
7962 7885
7963 /* validity is capped by our willingness to keep track of the 7886 /* validity is capped by our willingness to keep track of the
7964 validation entry and the maximum the other peer allows */ 7887 validation entry and the maximum the other peer allows */
7965 vs->valid_until = GNUNET_TIME_relative_to_absolute ( 7888 vs->valid_until = GNUNET_TIME_relative_to_absolute(
7966 GNUNET_TIME_relative_min (GNUNET_TIME_relative_ntoh ( 7889 GNUNET_TIME_relative_min(GNUNET_TIME_relative_ntoh(
7967 tvr->validity_duration), 7890 tvr->validity_duration),
7968 MAX_ADDRESS_VALID_UNTIL)); 7891 MAX_ADDRESS_VALID_UNTIL));
7969 vs->validated_until = 7892 vs->validated_until =
7970 GNUNET_TIME_absolute_min (vs->valid_until, 7893 GNUNET_TIME_absolute_min(vs->valid_until,
7971 GNUNET_TIME_relative_to_absolute ( 7894 GNUNET_TIME_relative_to_absolute(
7972 ADDRESS_VALIDATION_LIFETIME)); 7895 ADDRESS_VALIDATION_LIFETIME));
7973 vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time); 7896 vs->validation_rtt = GNUNET_TIME_absolute_get_duration(origin_time);
7974 vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO; 7897 vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO;
7975 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 7898 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
7976 &vs->challenge, 7899 &vs->challenge,
7977 sizeof (vs->challenge)); 7900 sizeof(vs->challenge));
7978 vs->first_challenge_use = GNUNET_TIME_absolute_subtract ( 7901 vs->first_challenge_use = GNUNET_TIME_absolute_subtract(
7979 vs->validated_until, 7902 vs->validated_until,
7980 GNUNET_TIME_relative_multiply (vs->validation_rtt, 7903 GNUNET_TIME_relative_multiply(vs->validation_rtt,
7981 VALIDATION_RTT_BUFFER_FACTOR)); 7904 VALIDATION_RTT_BUFFER_FACTOR));
7982 vs->last_challenge_use = 7905 vs->last_challenge_use =
7983 GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */ 7906 GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */
7984 update_next_challenge_time (vs, vs->first_challenge_use); 7907 update_next_challenge_time(vs, vs->first_challenge_use);
7985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7986 "Validation response %s accepted, address valid until %s\n", 7909 "Validation response %s accepted, address valid until %s\n",
7987 GNUNET_sh2s (&tvr->challenge.value), 7910 GNUNET_sh2s(&tvr->challenge.value),
7988 GNUNET_STRINGS_absolute_time_to_string (vs->valid_until)); 7911 GNUNET_STRINGS_absolute_time_to_string(vs->valid_until));
7989 vs->sc = GNUNET_PEERSTORE_store (peerstore, 7912 vs->sc = GNUNET_PEERSTORE_store(peerstore,
7990 "transport", 7913 "transport",
7991 &cmc->im.sender, 7914 &cmc->im.sender,
7992 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, 7915 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
7993 vs->address, 7916 vs->address,
7994 strlen (vs->address) + 1, 7917 strlen(vs->address) + 1,
7995 vs->valid_until, 7918 vs->valid_until,
7996 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, 7919 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
7997 &peerstore_store_validation_cb, 7920 &peerstore_store_validation_cb,
7998 vs); 7921 vs);
7999 finish_cmc_handling (cmc); 7922 finish_cmc_handling(cmc);
8000 7923
8001 /* Finally, we now possibly have a confirmed (!) working queue, 7924 /* Finally, we now possibly have a confirmed (!) working queue,
8002 update queue status (if queue still is around) */ 7925 update queue status (if queue still is around) */
8003 q = find_queue (&vs->pid, vs->address); 7926 q = find_queue(&vs->pid, vs->address);
8004 if (NULL == q) 7927 if (NULL == q)
8005 { 7928 {
8006 GNUNET_STATISTICS_update (GST_stats, 7929 GNUNET_STATISTICS_update(GST_stats,
8007 "# Queues lost at time of successful validation", 7930 "# Queues lost at time of successful validation",
8008 1, 7931 1,
8009 GNUNET_NO); 7932 GNUNET_NO);
8010 return; 7933 return;
8011 } 7934 }
8012 q->validated_until = vs->validated_until; 7935 q->validated_until = vs->validated_until;
8013 q->pd.aged_rtt = vs->validation_rtt; 7936 q->pd.aged_rtt = vs->validation_rtt;
8014 n = q->neighbour; 7937 n = q->neighbour;
8015 vl = lookup_virtual_link (&vs->pid); 7938 vl = lookup_virtual_link(&vs->pid);
8016 if (NULL != vl) 7939 if (NULL != vl)
8017 {
8018 /* Link was already up, remember n is also now available and we are done */
8019 if (NULL == vl->n)
8020 {
8021 vl->n = n;
8022 n->vl = vl;
8023 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8024 "Virtual link to %s could now also direct neighbour!\n",
8025 GNUNET_i2s (&vs->pid));
8026 }
8027 else
8028 { 7940 {
8029 GNUNET_assert (n == vl->n); 7941 /* Link was already up, remember n is also now available and we are done */
7942 if (NULL == vl->n)
7943 {
7944 vl->n = n;
7945 n->vl = vl;
7946 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7947 "Virtual link to %s could now also direct neighbour!\n",
7948 GNUNET_i2s(&vs->pid));
7949 }
7950 else
7951 {
7952 GNUNET_assert(n == vl->n);
7953 }
7954 return;
8030 } 7955 }
8031 return; 7956 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8032 } 7957 "Creating new virtual link to %s using direct neighbour!\n",
8033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7958 GNUNET_i2s(&vs->pid));
8034 "Creating new virtual link to %s using direct neighbour!\n", 7959 vl = GNUNET_new(struct VirtualLink);
8035 GNUNET_i2s (&vs->pid));
8036 vl = GNUNET_new (struct VirtualLink);
8037 vl->target = n->pid; 7960 vl->target = n->pid;
8038 vl->n = n; 7961 vl->n = n;
8039 n->vl = vl; 7962 n->vl = vl;
8040 vl->core_recv_window = RECV_WINDOW_SIZE; 7963 vl->core_recv_window = RECV_WINDOW_SIZE;
8041 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; 7964 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE;
8042 vl->visibility_task = 7965 vl->visibility_task =
8043 GNUNET_SCHEDULER_add_at (q->validated_until, &check_link_down, vl); 7966 GNUNET_SCHEDULER_add_at(q->validated_until, &check_link_down, vl);
8044 GNUNET_break (GNUNET_YES == 7967 GNUNET_break(GNUNET_YES ==
8045 GNUNET_CONTAINER_multipeermap_put ( 7968 GNUNET_CONTAINER_multipeermap_put(
8046 links, 7969 links,
8047 &vl->target, 7970 &vl->target,
8048 vl, 7971 vl,
8049 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 7972 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
8050 consider_sending_fc (vl); 7973 consider_sending_fc(vl);
8051 /* We lacked a confirmed connection to the target 7974 /* We lacked a confirmed connection to the target
8052 before, so tell CORE about it (finally!) */ 7975 before, so tell CORE about it (finally!) */
8053 cores_send_connect_info (&n->pid); 7976 cores_send_connect_info(&n->pid);
8054} 7977}
8055 7978
8056 7979
@@ -8060,19 +7983,19 @@ handle_validation_response (
8060 * @param im the send message that was received 7983 * @param im the send message that was received
8061 */ 7984 */
8062static void 7985static void
8063handle_incoming_msg (void *cls, 7986handle_incoming_msg(void *cls,
8064 const struct GNUNET_TRANSPORT_IncomingMessage *im) 7987 const struct GNUNET_TRANSPORT_IncomingMessage *im)
8065{ 7988{
8066 struct TransportClient *tc = cls; 7989 struct TransportClient *tc = cls;
8067 struct CommunicatorMessageContext *cmc = 7990 struct CommunicatorMessageContext *cmc =
8068 GNUNET_new (struct CommunicatorMessageContext); 7991 GNUNET_new(struct CommunicatorMessageContext);
8069 7992
8070 cmc->tc = tc; 7993 cmc->tc = tc;
8071 cmc->im = *im; 7994 cmc->im = *im;
8072 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7995 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8073 "Received message via communicator from peer %s\n", 7996 "Received message via communicator from peer %s\n",
8074 GNUNET_i2s (&im->sender)); 7997 GNUNET_i2s(&im->sender));
8075 demultiplex_with_cmc (cmc, (const struct GNUNET_MessageHeader *) &im[1]); 7998 demultiplex_with_cmc(cmc, (const struct GNUNET_MessageHeader *)&im[1]);
8076} 7999}
8077 8000
8078 8001
@@ -8085,7 +8008,7 @@ handle_incoming_msg (void *cls,
8085 * @param fc the message that was received 8008 * @param fc the message that was received
8086 */ 8009 */
8087static void 8010static void
8088handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc) 8011handle_flow_control(void *cls, const struct TransportFlowControlMessage *fc)
8089{ 8012{
8090 struct CommunicatorMessageContext *cmc = cls; 8013 struct CommunicatorMessageContext *cmc = cls;
8091 struct VirtualLink *vl; 8014 struct VirtualLink *vl;
@@ -8094,70 +8017,70 @@ handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc)
8094 uint64_t os; 8017 uint64_t os;
8095 uint64_t wnd; 8018 uint64_t wnd;
8096 8019
8097 vl = lookup_virtual_link (&cmc->im.sender); 8020 vl = lookup_virtual_link(&cmc->im.sender);
8098 if (NULL == vl) 8021 if (NULL == vl)
8099 { 8022 {
8100 GNUNET_STATISTICS_update (GST_stats, 8023 GNUNET_STATISTICS_update(GST_stats,
8101 "# FC dropped: virtual link unknown", 8024 "# FC dropped: virtual link unknown",
8102 1, 8025 1,
8103 GNUNET_NO); 8026 GNUNET_NO);
8104 finish_cmc_handling (cmc); 8027 finish_cmc_handling(cmc);
8105 return; 8028 return;
8106 } 8029 }
8107 st = GNUNET_TIME_absolute_ntoh (fc->sender_time); 8030 st = GNUNET_TIME_absolute_ntoh(fc->sender_time);
8108 if (st.abs_value_us < vl->last_fc_timestamp.abs_value_us) 8031 if (st.abs_value_us < vl->last_fc_timestamp.abs_value_us)
8109 { 8032 {
8110 /* out of order, drop */ 8033 /* out of order, drop */
8111 GNUNET_STATISTICS_update (GST_stats, 8034 GNUNET_STATISTICS_update(GST_stats,
8112 "# FC dropped: message out of order", 8035 "# FC dropped: message out of order",
8113 1, 8036 1,
8114 GNUNET_NO); 8037 GNUNET_NO);
8115 finish_cmc_handling (cmc); 8038 finish_cmc_handling(cmc);
8116 return; 8039 return;
8117 } 8040 }
8118 seq = ntohl (fc->seq); 8041 seq = ntohl(fc->seq);
8119 if (seq < vl->last_fc_seq) 8042 if (seq < vl->last_fc_seq)
8120 { 8043 {
8121 /* Wrap-around/reset of other peer; start all counters from zero */ 8044 /* Wrap-around/reset of other peer; start all counters from zero */
8122 vl->outbound_fc_window_size_used = 0; 8045 vl->outbound_fc_window_size_used = 0;
8123 } 8046 }
8124 vl->last_fc_seq = seq; 8047 vl->last_fc_seq = seq;
8125 vl->last_fc_timestamp = st; 8048 vl->last_fc_timestamp = st;
8126 vl->outbound_fc_window_size = GNUNET_ntohll (fc->inbound_window_size); 8049 vl->outbound_fc_window_size = GNUNET_ntohll(fc->inbound_window_size);
8127 os = GNUNET_ntohll (fc->outbound_sent); 8050 os = GNUNET_ntohll(fc->outbound_sent);
8128 vl->incoming_fc_window_size_loss = 8051 vl->incoming_fc_window_size_loss =
8129 (int64_t) (os - vl->incoming_fc_window_size_used); 8052 (int64_t)(os - vl->incoming_fc_window_size_used);
8130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8053 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8131 "Received FC from %s, seq %u, new window %llu (loss at %lld)\n", 8054 "Received FC from %s, seq %u, new window %llu (loss at %lld)\n",
8132 GNUNET_i2s (&vl->target), 8055 GNUNET_i2s(&vl->target),
8133 (unsigned int) seq, 8056 (unsigned int)seq,
8134 (unsigned long long) vl->outbound_fc_window_size, 8057 (unsigned long long)vl->outbound_fc_window_size,
8135 (long long) vl->incoming_fc_window_size_loss); 8058 (long long)vl->incoming_fc_window_size_loss);
8136 wnd = GNUNET_ntohll (fc->outbound_window_size); 8059 wnd = GNUNET_ntohll(fc->outbound_window_size);
8137 if ((wnd < vl->incoming_fc_window_size) || 8060 if ((wnd < vl->incoming_fc_window_size) ||
8138 (vl->last_outbound_window_size_received != wnd) || 8061 (vl->last_outbound_window_size_received != wnd) ||
8139 (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) % 8062 (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) %
8140 FC_NO_CHANGE_REPLY_PROBABILITY)) 8063 FC_NO_CHANGE_REPLY_PROBABILITY))
8141 { 8064 {
8142 /* Consider re-sending our FC message, as clearly the 8065 /* Consider re-sending our FC message, as clearly the
8143 other peer's idea of the window is not up-to-date */ 8066 other peer's idea of the window is not up-to-date */
8144 consider_sending_fc (vl); 8067 consider_sending_fc(vl);
8145 } 8068 }
8146 if ((wnd == vl->incoming_fc_window_size) && 8069 if ((wnd == vl->incoming_fc_window_size) &&
8147 (vl->last_outbound_window_size_received == wnd) && 8070 (vl->last_outbound_window_size_received == wnd) &&
8148 (NULL != vl->fc_retransmit_task)) 8071 (NULL != vl->fc_retransmit_task))
8149 { 8072 {
8150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8073 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8151 "Stopping FC retransmission to %s: peer is current at window %llu\n", 8074 "Stopping FC retransmission to %s: peer is current at window %llu\n",
8152 GNUNET_i2s (&vl->target), 8075 GNUNET_i2s(&vl->target),
8153 (unsigned long long) wnd); 8076 (unsigned long long)wnd);
8154 GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); 8077 GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task);
8155 vl->fc_retransmit_task = NULL; 8078 vl->fc_retransmit_task = NULL;
8156 } 8079 }
8157 vl->last_outbound_window_size_received = wnd; 8080 vl->last_outbound_window_size_received = wnd;
8158 /* FC window likely increased, check transmission possibilities! */ 8081 /* FC window likely increased, check transmission possibilities! */
8159 check_vl_transmission (vl); 8082 check_vl_transmission(vl);
8160 finish_cmc_handling (cmc); 8083 finish_cmc_handling(cmc);
8161} 8084}
8162 8085
8163 8086
@@ -8169,68 +8092,68 @@ handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc)
8169 * @param msg message to demultiplex 8092 * @param msg message to demultiplex
8170 */ 8093 */
8171static void 8094static void
8172demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, 8095demultiplex_with_cmc(struct CommunicatorMessageContext *cmc,
8173 const struct GNUNET_MessageHeader *msg) 8096 const struct GNUNET_MessageHeader *msg)
8174{ 8097{
8175 struct GNUNET_MQ_MessageHandler handlers[] = 8098 struct GNUNET_MQ_MessageHandler handlers[] =
8176 {GNUNET_MQ_hd_var_size (fragment_box, 8099 { GNUNET_MQ_hd_var_size(fragment_box,
8177 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, 8100 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT,
8178 struct TransportFragmentBoxMessage, 8101 struct TransportFragmentBoxMessage,
8179 &cmc), 8102 &cmc),
8180 GNUNET_MQ_hd_var_size (reliability_box, 8103 GNUNET_MQ_hd_var_size(reliability_box,
8181 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, 8104 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX,
8182 struct TransportReliabilityBoxMessage, 8105 struct TransportReliabilityBoxMessage,
8183 &cmc), 8106 &cmc),
8184 GNUNET_MQ_hd_var_size (reliability_ack, 8107 GNUNET_MQ_hd_var_size(reliability_ack,
8185 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, 8108 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK,
8186 struct TransportReliabilityAckMessage, 8109 struct TransportReliabilityAckMessage,
8187 &cmc), 8110 &cmc),
8188 GNUNET_MQ_hd_var_size (backchannel_encapsulation, 8111 GNUNET_MQ_hd_var_size(backchannel_encapsulation,
8189 GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, 8112 GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION,
8190 struct TransportBackchannelEncapsulationMessage, 8113 struct TransportBackchannelEncapsulationMessage,
8114 &cmc),
8115 GNUNET_MQ_hd_var_size(dv_learn,
8116 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN,
8117 struct TransportDVLearnMessage,
8118 &cmc),
8119 GNUNET_MQ_hd_var_size(dv_box,
8120 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX,
8121 struct TransportDVBoxMessage,
8122 &cmc),
8123 GNUNET_MQ_hd_fixed_size(
8124 validation_challenge,
8125 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE,
8126 struct TransportValidationChallengeMessage,
8127 &cmc),
8128 GNUNET_MQ_hd_fixed_size(flow_control,
8129 GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL,
8130 struct TransportFlowControlMessage,
8191 &cmc), 8131 &cmc),
8192 GNUNET_MQ_hd_var_size (dv_learn, 8132 GNUNET_MQ_hd_fixed_size(
8193 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, 8133 validation_response,
8194 struct TransportDVLearnMessage, 8134 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE,
8195 &cmc), 8135 struct TransportValidationResponseMessage,
8196 GNUNET_MQ_hd_var_size (dv_box, 8136 &cmc),
8197 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, 8137 GNUNET_MQ_handler_end() };
8198 struct TransportDVBoxMessage,
8199 &cmc),
8200 GNUNET_MQ_hd_fixed_size (
8201 validation_challenge,
8202 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE,
8203 struct TransportValidationChallengeMessage,
8204 &cmc),
8205 GNUNET_MQ_hd_fixed_size (flow_control,
8206 GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL,
8207 struct TransportFlowControlMessage,
8208 &cmc),
8209 GNUNET_MQ_hd_fixed_size (
8210 validation_response,
8211 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE,
8212 struct TransportValidationResponseMessage,
8213 &cmc),
8214 GNUNET_MQ_handler_end ()};
8215 int ret; 8138 int ret;
8216 8139
8217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8140 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8218 "Handling message of type %u with %u bytes\n", 8141 "Handling message of type %u with %u bytes\n",
8219 (unsigned int) ntohs (msg->type), 8142 (unsigned int)ntohs(msg->type),
8220 (unsigned int) ntohs (msg->size)); 8143 (unsigned int)ntohs(msg->size));
8221 ret = GNUNET_MQ_handle_message (handlers, msg); 8144 ret = GNUNET_MQ_handle_message(handlers, msg);
8222 if (GNUNET_SYSERR == ret) 8145 if (GNUNET_SYSERR == ret)
8223 { 8146 {
8224 GNUNET_break (0); 8147 GNUNET_break(0);
8225 GNUNET_SERVICE_client_drop (cmc->tc->client); 8148 GNUNET_SERVICE_client_drop(cmc->tc->client);
8226 GNUNET_free (cmc); 8149 GNUNET_free(cmc);
8227 return; 8150 return;
8228 } 8151 }
8229 if (GNUNET_NO == ret) 8152 if (GNUNET_NO == ret)
8230 { 8153 {
8231 /* unencapsulated 'raw' message */ 8154 /* unencapsulated 'raw' message */
8232 handle_raw_message (&cmc, msg); 8155 handle_raw_message(&cmc, msg);
8233 } 8156 }
8234} 8157}
8235 8158
8236 8159
@@ -8241,17 +8164,17 @@ demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
8241 * @param aqm the send message that was sent 8164 * @param aqm the send message that was sent
8242 */ 8165 */
8243static int 8166static int
8244check_add_queue_message (void *cls, 8167check_add_queue_message(void *cls,
8245 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) 8168 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
8246{ 8169{
8247 struct TransportClient *tc = cls; 8170 struct TransportClient *tc = cls;
8248 8171
8249 if (CT_COMMUNICATOR != tc->type) 8172 if (CT_COMMUNICATOR != tc->type)
8250 { 8173 {
8251 GNUNET_break (0); 8174 GNUNET_break(0);
8252 return GNUNET_SYSERR; 8175 return GNUNET_SYSERR;
8253 } 8176 }
8254 GNUNET_MQ_check_zero_termination (aqm); 8177 GNUNET_MQ_check_zero_termination(aqm);
8255 return GNUNET_OK; 8178 return GNUNET_OK;
8256} 8179}
8257 8180
@@ -8262,7 +8185,7 @@ check_add_queue_message (void *cls,
8262 * @param pm pending message to generate UUID for. 8185 * @param pm pending message to generate UUID for.
8263 */ 8186 */
8264static void 8187static void
8265set_pending_message_uuid (struct PendingMessage *pm) 8188set_pending_message_uuid(struct PendingMessage *pm)
8266{ 8189{
8267 if (pm->msg_uuid_set) 8190 if (pm->msg_uuid_set)
8268 return; 8191 return;
@@ -8280,36 +8203,37 @@ set_pending_message_uuid (struct PendingMessage *pm)
8280 * @return corresponding fresh pending acknowledgement 8203 * @return corresponding fresh pending acknowledgement
8281 */ 8204 */
8282static struct PendingAcknowledgement * 8205static struct PendingAcknowledgement *
8283prepare_pending_acknowledgement (struct Queue *queue, 8206prepare_pending_acknowledgement(struct Queue *queue,
8284 struct DistanceVectorHop *dvh, 8207 struct DistanceVectorHop *dvh,
8285 struct PendingMessage *pm) 8208 struct PendingMessage *pm)
8286{ 8209{
8287 struct PendingAcknowledgement *pa; 8210 struct PendingAcknowledgement *pa;
8288 8211
8289 pa = GNUNET_new (struct PendingAcknowledgement); 8212 pa = GNUNET_new(struct PendingAcknowledgement);
8290 pa->queue = queue; 8213 pa->queue = queue;
8291 pa->dvh = dvh; 8214 pa->dvh = dvh;
8292 pa->pm = pm; 8215 pa->pm = pm;
8293 do 8216 do
8294 { 8217 {
8295 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 8218 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
8296 &pa->ack_uuid, 8219 &pa->ack_uuid,
8297 sizeof (pa->ack_uuid)); 8220 sizeof(pa->ack_uuid));
8298 } while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put ( 8221 }
8299 pending_acks, 8222 while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put(
8300 &pa->ack_uuid.value, 8223 pending_acks,
8301 pa, 8224 &pa->ack_uuid.value,
8302 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 8225 pa,
8303 GNUNET_CONTAINER_MDLL_insert (queue, queue->pa_head, queue->pa_tail, pa); 8226 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
8304 GNUNET_CONTAINER_MDLL_insert (pm, pm->pa_head, pm->pa_tail, pa); 8227 GNUNET_CONTAINER_MDLL_insert(queue, queue->pa_head, queue->pa_tail, pa);
8228 GNUNET_CONTAINER_MDLL_insert(pm, pm->pa_head, pm->pa_tail, pa);
8305 if (NULL != dvh) 8229 if (NULL != dvh)
8306 GNUNET_CONTAINER_MDLL_insert (dvh, dvh->pa_head, dvh->pa_tail, pa); 8230 GNUNET_CONTAINER_MDLL_insert(dvh, dvh->pa_head, dvh->pa_tail, pa);
8307 pa->transmission_time = GNUNET_TIME_absolute_get (); 8231 pa->transmission_time = GNUNET_TIME_absolute_get();
8308 pa->message_size = pm->bytes_msg; 8232 pa->message_size = pm->bytes_msg;
8309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8233 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8310 "Waiting for ACKnowledgment `%s' for <%llu>\n", 8234 "Waiting for ACKnowledgment `%s' for <%llu>\n",
8311 GNUNET_uuid2s (&pa->ack_uuid.value), 8235 GNUNET_uuid2s(&pa->ack_uuid.value),
8312 pm->logging_uuid); 8236 pm->logging_uuid);
8313 return pa; 8237 return pa;
8314} 8238}
8315 8239
@@ -8326,28 +8250,28 @@ prepare_pending_acknowledgement (struct Queue *queue,
8326 * @return new message to transmit 8250 * @return new message to transmit
8327 */ 8251 */
8328static struct PendingMessage * 8252static struct PendingMessage *
8329fragment_message (struct Queue *queue, 8253fragment_message(struct Queue *queue,
8330 struct DistanceVectorHop *dvh, 8254 struct DistanceVectorHop *dvh,
8331 struct PendingMessage *pm) 8255 struct PendingMessage *pm)
8332{ 8256{
8333 struct PendingAcknowledgement *pa; 8257 struct PendingAcknowledgement *pa;
8334 struct PendingMessage *ff; 8258 struct PendingMessage *ff;
8335 uint16_t mtu; 8259 uint16_t mtu;
8336 8260
8337 mtu = (0 == queue->mtu) 8261 mtu = (0 == queue->mtu)
8338 ? UINT16_MAX - sizeof (struct GNUNET_TRANSPORT_SendMessageTo) 8262 ? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)
8339 : queue->mtu; 8263 : queue->mtu;
8340 set_pending_message_uuid (pm); 8264 set_pending_message_uuid(pm);
8341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8265 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8342 "Fragmenting message %llu <%llu> to %s for MTU %u\n", 8266 "Fragmenting message %llu <%llu> to %s for MTU %u\n",
8343 (unsigned long long) pm->msg_uuid.uuid, 8267 (unsigned long long)pm->msg_uuid.uuid,
8344 pm->logging_uuid, 8268 pm->logging_uuid,
8345 GNUNET_i2s (&pm->vl->target), 8269 GNUNET_i2s(&pm->vl->target),
8346 (unsigned int) mtu); 8270 (unsigned int)mtu);
8347 pa = prepare_pending_acknowledgement (queue, dvh, pm); 8271 pa = prepare_pending_acknowledgement(queue, dvh, pm);
8348 8272
8349 /* This invariant is established in #handle_add_queue_message() */ 8273 /* This invariant is established in #handle_add_queue_message() */
8350 GNUNET_assert (mtu > sizeof (struct TransportFragmentBoxMessage)); 8274 GNUNET_assert(mtu > sizeof(struct TransportFragmentBoxMessage));
8351 8275
8352 /* select fragment for transmission, descending the tree if it has 8276 /* select fragment for transmission, descending the tree if it has
8353 been expanded until we are at a leaf or at a fragment that is small 8277 been expanded until we are at a leaf or at a fragment that is small
@@ -8356,68 +8280,68 @@ fragment_message (struct Queue *queue,
8356 ff = pm; 8280 ff = pm;
8357 while (((ff->bytes_msg > mtu) || (pm == ff)) && 8281 while (((ff->bytes_msg > mtu) || (pm == ff)) &&
8358 (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag)) 8282 (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag))
8359 { 8283 {
8360 ff = ff->head_frag; /* descent into fragmented fragments */ 8284 ff = ff->head_frag; /* descent into fragmented fragments */
8361 } 8285 }
8362 8286
8363 if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg)) 8287 if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg))
8364 { 8288 {
8365 /* Did not yet calculate all fragments, calculate next fragment */ 8289 /* Did not yet calculate all fragments, calculate next fragment */
8366 struct PendingMessage *frag; 8290 struct PendingMessage *frag;
8367 struct TransportFragmentBoxMessage tfb; 8291 struct TransportFragmentBoxMessage tfb;
8368 const char *orig; 8292 const char *orig;
8369 char *msg; 8293 char *msg;
8370 uint16_t fragmax; 8294 uint16_t fragmax;
8371 uint16_t fragsize; 8295 uint16_t fragsize;
8372 uint16_t msize; 8296 uint16_t msize;
8373 uint16_t xoff = 0; 8297 uint16_t xoff = 0;
8374 8298
8375 orig = (const char *) &ff[1]; 8299 orig = (const char *)&ff[1];
8376 msize = ff->bytes_msg; 8300 msize = ff->bytes_msg;
8377 if (pm != ff) 8301 if (pm != ff)
8378 { 8302 {
8379 const struct TransportFragmentBoxMessage *tfbo; 8303 const struct TransportFragmentBoxMessage *tfbo;
8380 8304
8381 tfbo = (const struct TransportFragmentBoxMessage *) orig; 8305 tfbo = (const struct TransportFragmentBoxMessage *)orig;
8382 orig += sizeof (struct TransportFragmentBoxMessage); 8306 orig += sizeof(struct TransportFragmentBoxMessage);
8383 msize -= sizeof (struct TransportFragmentBoxMessage); 8307 msize -= sizeof(struct TransportFragmentBoxMessage);
8384 xoff = ntohs (tfbo->frag_off); 8308 xoff = ntohs(tfbo->frag_off);
8385 } 8309 }
8386 fragmax = mtu - sizeof (struct TransportFragmentBoxMessage); 8310 fragmax = mtu - sizeof(struct TransportFragmentBoxMessage);
8387 fragsize = GNUNET_MIN (msize - ff->frag_off, fragmax); 8311 fragsize = GNUNET_MIN(msize - ff->frag_off, fragmax);
8388 frag = 8312 frag =
8389 GNUNET_malloc (sizeof (struct PendingMessage) + 8313 GNUNET_malloc(sizeof(struct PendingMessage) +
8390 sizeof (struct TransportFragmentBoxMessage) + fragsize); 8314 sizeof(struct TransportFragmentBoxMessage) + fragsize);
8391 frag->logging_uuid = logging_uuid_gen++; 8315 frag->logging_uuid = logging_uuid_gen++;
8392 frag->vl = pm->vl; 8316 frag->vl = pm->vl;
8393 frag->frag_parent = ff; 8317 frag->frag_parent = ff;
8394 frag->timeout = pm->timeout; 8318 frag->timeout = pm->timeout;
8395 frag->bytes_msg = sizeof (struct TransportFragmentBoxMessage) + fragsize; 8319 frag->bytes_msg = sizeof(struct TransportFragmentBoxMessage) + fragsize;
8396 frag->pmt = PMT_FRAGMENT_BOX; 8320 frag->pmt = PMT_FRAGMENT_BOX;
8397 msg = (char *) &frag[1]; 8321 msg = (char *)&frag[1];
8398 tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); 8322 tfb.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT);
8399 tfb.header.size = 8323 tfb.header.size =
8400 htons (sizeof (struct TransportFragmentBoxMessage) + fragsize); 8324 htons(sizeof(struct TransportFragmentBoxMessage) + fragsize);
8401 tfb.ack_uuid = pa->ack_uuid; 8325 tfb.ack_uuid = pa->ack_uuid;
8402 tfb.msg_uuid = pm->msg_uuid; 8326 tfb.msg_uuid = pm->msg_uuid;
8403 tfb.frag_off = htons (ff->frag_off + xoff); 8327 tfb.frag_off = htons(ff->frag_off + xoff);
8404 tfb.msg_size = htons (pm->bytes_msg); 8328 tfb.msg_size = htons(pm->bytes_msg);
8405 memcpy (msg, &tfb, sizeof (tfb)); 8329 memcpy(msg, &tfb, sizeof(tfb));
8406 memcpy (&msg[sizeof (tfb)], &orig[ff->frag_off], fragsize); 8330 memcpy(&msg[sizeof(tfb)], &orig[ff->frag_off], fragsize);
8407 GNUNET_CONTAINER_MDLL_insert (frag, ff->head_frag, ff->tail_frag, frag); 8331 GNUNET_CONTAINER_MDLL_insert(frag, ff->head_frag, ff->tail_frag, frag);
8408 ff->frag_off += fragsize; 8332 ff->frag_off += fragsize;
8409 ff = frag; 8333 ff = frag;
8410 } 8334 }
8411 8335
8412 /* Move head to the tail and return it */ 8336 /* Move head to the tail and return it */
8413 GNUNET_CONTAINER_MDLL_remove (frag, 8337 GNUNET_CONTAINER_MDLL_remove(frag,
8414 ff->frag_parent->head_frag, 8338 ff->frag_parent->head_frag,
8415 ff->frag_parent->tail_frag, 8339 ff->frag_parent->tail_frag,
8416 ff); 8340 ff);
8417 GNUNET_CONTAINER_MDLL_insert_tail (frag, 8341 GNUNET_CONTAINER_MDLL_insert_tail(frag,
8418 ff->frag_parent->head_frag, 8342 ff->frag_parent->head_frag,
8419 ff->frag_parent->tail_frag, 8343 ff->frag_parent->tail_frag,
8420 ff); 8344 ff);
8421 return ff; 8345 return ff;
8422} 8346}
8423 8347
@@ -8435,9 +8359,9 @@ fragment_message (struct Queue *queue,
8435 * @return new message to transmit 8359 * @return new message to transmit
8436 */ 8360 */
8437static struct PendingMessage * 8361static struct PendingMessage *
8438reliability_box_message (struct Queue *queue, 8362reliability_box_message(struct Queue *queue,
8439 struct DistanceVectorHop *dvh, 8363 struct DistanceVectorHop *dvh,
8440 struct PendingMessage *pm) 8364 struct PendingMessage *pm)
8441{ 8365{
8442 struct TransportReliabilityBoxMessage rbox; 8366 struct TransportReliabilityBoxMessage rbox;
8443 struct PendingAcknowledgement *pa; 8367 struct PendingAcknowledgement *pa;
@@ -8449,39 +8373,39 @@ reliability_box_message (struct Queue *queue,
8449 do nothing */ 8373 do nothing */
8450 if (NULL != pm->bpm) 8374 if (NULL != pm->bpm)
8451 return pm->bpm; /* already computed earlier: do nothing */ 8375 return pm->bpm; /* already computed earlier: do nothing */
8452 GNUNET_assert (NULL == pm->head_frag); 8376 GNUNET_assert(NULL == pm->head_frag);
8453 if (pm->bytes_msg + sizeof (rbox) > UINT16_MAX) 8377 if (pm->bytes_msg + sizeof(rbox) > UINT16_MAX)
8454 { 8378 {
8455 /* failed hard */ 8379 /* failed hard */
8456 GNUNET_break (0); 8380 GNUNET_break(0);
8457 client_send_response (pm); 8381 client_send_response(pm);
8458 return NULL; 8382 return NULL;
8459 } 8383 }
8460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8384 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8461 "Preparing reliability box for message <%llu> to %s on queue %s\n", 8385 "Preparing reliability box for message <%llu> to %s on queue %s\n",
8462 pm->logging_uuid, 8386 pm->logging_uuid,
8463 GNUNET_i2s (&pm->vl->target), 8387 GNUNET_i2s(&pm->vl->target),
8464 queue->address); 8388 queue->address);
8465 pa = prepare_pending_acknowledgement (queue, dvh, pm); 8389 pa = prepare_pending_acknowledgement(queue, dvh, pm);
8466 8390
8467 bpm = GNUNET_malloc (sizeof (struct PendingMessage) + sizeof (rbox) + 8391 bpm = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(rbox) +
8468 pm->bytes_msg); 8392 pm->bytes_msg);
8469 bpm->logging_uuid = logging_uuid_gen++; 8393 bpm->logging_uuid = logging_uuid_gen++;
8470 bpm->vl = pm->vl; 8394 bpm->vl = pm->vl;
8471 bpm->frag_parent = pm; 8395 bpm->frag_parent = pm;
8472 GNUNET_CONTAINER_MDLL_insert (frag, pm->head_frag, pm->tail_frag, bpm); 8396 GNUNET_CONTAINER_MDLL_insert(frag, pm->head_frag, pm->tail_frag, bpm);
8473 bpm->timeout = pm->timeout; 8397 bpm->timeout = pm->timeout;
8474 bpm->pmt = PMT_RELIABILITY_BOX; 8398 bpm->pmt = PMT_RELIABILITY_BOX;
8475 bpm->bytes_msg = pm->bytes_msg + sizeof (rbox); 8399 bpm->bytes_msg = pm->bytes_msg + sizeof(rbox);
8476 set_pending_message_uuid (bpm); 8400 set_pending_message_uuid(bpm);
8477 rbox.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX); 8401 rbox.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX);
8478 rbox.header.size = htons (sizeof (rbox) + pm->bytes_msg); 8402 rbox.header.size = htons(sizeof(rbox) + pm->bytes_msg);
8479 rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support 8403 rbox.ack_countdown = htonl(0); // FIXME: implement ACK countdown support
8480 8404
8481 rbox.ack_uuid = pa->ack_uuid; 8405 rbox.ack_uuid = pa->ack_uuid;
8482 msg = (char *) &bpm[1]; 8406 msg = (char *)&bpm[1];
8483 memcpy (msg, &rbox, sizeof (rbox)); 8407 memcpy(msg, &rbox, sizeof(rbox));
8484 memcpy (&msg[sizeof (rbox)], &pm[1], pm->bytes_msg); 8408 memcpy(&msg[sizeof(rbox)], &pm[1], pm->bytes_msg);
8485 pm->bpm = bpm; 8409 pm->bpm = bpm;
8486 return bpm; 8410 return bpm;
8487} 8411}
@@ -8496,61 +8420,60 @@ reliability_box_message (struct Queue *queue,
8496 * @param next_attempt timestamp to use 8420 * @param next_attempt timestamp to use
8497 */ 8421 */
8498static void 8422static void
8499update_pm_next_attempt (struct PendingMessage *pm, 8423update_pm_next_attempt(struct PendingMessage *pm,
8500 struct GNUNET_TIME_Absolute next_attempt) 8424 struct GNUNET_TIME_Absolute next_attempt)
8501{ 8425{
8502 struct VirtualLink *vl = pm->vl; 8426 struct VirtualLink *vl = pm->vl;
8503 8427
8504 pm->next_attempt = next_attempt; 8428 pm->next_attempt = next_attempt;
8505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8429 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8506 "Next attempt for message <%llu> set to %s\n", 8430 "Next attempt for message <%llu> set to %s\n",
8507 pm->logging_uuid, 8431 pm->logging_uuid,
8508 GNUNET_STRINGS_absolute_time_to_string (next_attempt)); 8432 GNUNET_STRINGS_absolute_time_to_string(next_attempt));
8509 8433
8510 if (NULL == pm->frag_parent) 8434 if (NULL == pm->frag_parent)
8511 { 8435 {
8512 struct PendingMessage *pos; 8436 struct PendingMessage *pos;
8513 8437
8514 /* re-insert sort in neighbour list */ 8438 /* re-insert sort in neighbour list */
8515 GNUNET_CONTAINER_MDLL_remove (vl, 8439 GNUNET_CONTAINER_MDLL_remove(vl,
8516 vl->pending_msg_head, 8440 vl->pending_msg_head,
8517 vl->pending_msg_tail, 8441 vl->pending_msg_tail,
8518 pm); 8442 pm);
8519 pos = vl->pending_msg_tail; 8443 pos = vl->pending_msg_tail;
8520 while ((NULL != pos) && 8444 while ((NULL != pos) &&
8521 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) 8445 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us))
8522 pos = pos->prev_vl; 8446 pos = pos->prev_vl;
8523 GNUNET_CONTAINER_MDLL_insert_after (vl, 8447 GNUNET_CONTAINER_MDLL_insert_after(vl,
8524 vl->pending_msg_head, 8448 vl->pending_msg_head,
8525 vl->pending_msg_tail, 8449 vl->pending_msg_tail,
8526 pos, 8450 pos,
8527 pm); 8451 pm);
8528 } 8452 }
8529 else 8453 else
8530 { 8454 {
8531 /* re-insert sort in fragment list */ 8455 /* re-insert sort in fragment list */
8532 struct PendingMessage *fp = pm->frag_parent; 8456 struct PendingMessage *fp = pm->frag_parent;
8533 struct PendingMessage *pos; 8457 struct PendingMessage *pos;
8534 8458
8535 GNUNET_CONTAINER_MDLL_remove (frag, fp->head_frag, fp->tail_frag, pm); 8459 GNUNET_CONTAINER_MDLL_remove(frag, fp->head_frag, fp->tail_frag, pm);
8536 pos = fp->tail_frag; 8460 pos = fp->tail_frag;
8537 while ((NULL != pos) && 8461 while ((NULL != pos) &&
8538 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) 8462 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us))
8539 pos = pos->prev_frag; 8463 pos = pos->prev_frag;
8540 GNUNET_CONTAINER_MDLL_insert_after (frag, 8464 GNUNET_CONTAINER_MDLL_insert_after(frag,
8541 fp->head_frag, 8465 fp->head_frag,
8542 fp->tail_frag, 8466 fp->tail_frag,
8543 pos, 8467 pos,
8544 pm); 8468 pm);
8545 } 8469 }
8546} 8470}
8547 8471
8548 8472
8549/** 8473/**
8550 * Context for #select_best_pending_from_link(). 8474 * Context for #select_best_pending_from_link().
8551 */ 8475 */
8552struct PendingMessageScoreContext 8476struct PendingMessageScoreContext {
8553{
8554 /** 8477 /**
8555 * Set to the best message that was found, NULL for none. 8478 * Set to the best message that was found, NULL for none.
8556 */ 8479 */
@@ -8595,107 +8518,107 @@ struct PendingMessageScoreContext
8595 * from DV encapsulation (0 for without DV) 8518 * from DV encapsulation (0 for without DV)
8596 */ 8519 */
8597static void 8520static void
8598select_best_pending_from_link (struct PendingMessageScoreContext *sc, 8521select_best_pending_from_link(struct PendingMessageScoreContext *sc,
8599 struct Queue *queue, 8522 struct Queue *queue,
8600 struct VirtualLink *vl, 8523 struct VirtualLink *vl,
8601 struct DistanceVectorHop *dvh, 8524 struct DistanceVectorHop *dvh,
8602 size_t overhead) 8525 size_t overhead)
8603{ 8526{
8604 struct GNUNET_TIME_Absolute now; 8527 struct GNUNET_TIME_Absolute now;
8605 8528
8606 now = GNUNET_TIME_absolute_get (); 8529 now = GNUNET_TIME_absolute_get();
8607 for (struct PendingMessage *pos = vl->pending_msg_head; NULL != pos; 8530 for (struct PendingMessage *pos = vl->pending_msg_head; NULL != pos;
8608 pos = pos->next_vl) 8531 pos = pos->next_vl)
8609 { 8532 {
8610 size_t real_overhead = overhead; 8533 size_t real_overhead = overhead;
8611 int frag; 8534 int frag;
8612 int relb; 8535 int relb;
8613 8536
8614 if ((NULL != dvh) && (PMT_DV_BOX == pos->pmt)) 8537 if ((NULL != dvh) && (PMT_DV_BOX == pos->pmt))
8615 continue; /* DV messages must not be DV-routed to next hop! */ 8538 continue; /* DV messages must not be DV-routed to next hop! */
8616 if (pos->next_attempt.abs_value_us > now.abs_value_us) 8539 if (pos->next_attempt.abs_value_us > now.abs_value_us)
8617 break; /* too early for all messages, they are sorted by next_attempt */ 8540 break; /* too early for all messages, they are sorted by next_attempt */
8618 if (NULL != pos->qe) 8541 if (NULL != pos->qe)
8619 continue; /* not eligible */ 8542 continue; /* not eligible */
8620 sc->consideration_counter++; 8543 sc->consideration_counter++;
8621 /* determine if we have to fragment, if so add fragmentation 8544 /* determine if we have to fragment, if so add fragmentation
8622 overhead! */ 8545 overhead! */
8623 frag = GNUNET_NO; 8546 frag = GNUNET_NO;
8624 if ( ( (0 != queue->mtu) && 8547 if (((0 != queue->mtu) &&
8625 (pos->bytes_msg + real_overhead > queue->mtu) ) || 8548 (pos->bytes_msg + real_overhead > queue->mtu)) ||
8626 (pos->bytes_msg > UINT16_MAX - sizeof (struct GNUNET_TRANSPORT_SendMessageTo)) || 8549 (pos->bytes_msg > UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)) ||
8627 (NULL != pos->head_frag /* fragments already exist, should 8550 (NULL != pos->head_frag /* fragments already exist, should
8628 respect that even if MTU is 0 for 8551 respect that even if MTU is 0 for
8629 this queue */) ) 8552 this queue */))
8630 { 8553 {
8631 frag = GNUNET_YES; 8554 frag = GNUNET_YES;
8632 if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) 8555 if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)
8633 { 8556 {
8634 /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation 8557 /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation
8635 header without the ACK UUID when using a *reliable* channel! */ 8558 header without the ACK UUID when using a *reliable* channel! */
8636 } 8559 }
8637 real_overhead = overhead + sizeof (struct TransportFragmentBoxMessage); 8560 real_overhead = overhead + sizeof(struct TransportFragmentBoxMessage);
8638 } 8561 }
8639 /* determine if we have to reliability-box, if so add reliability box 8562 /* determine if we have to reliability-box, if so add reliability box
8640 overhead */ 8563 overhead */
8641 relb = GNUNET_NO; 8564 relb = GNUNET_NO;
8642 if ((GNUNET_NO == frag) && 8565 if ((GNUNET_NO == frag) &&
8643 (0 == (pos->prefs & GNUNET_MQ_PREF_UNRELIABLE)) && 8566 (0 == (pos->prefs & GNUNET_MQ_PREF_UNRELIABLE)) &&
8644 (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc)) 8567 (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc))
8645 { 8568 {
8646 relb = GNUNET_YES; 8569 relb = GNUNET_YES;
8647 real_overhead += sizeof (struct TransportReliabilityBoxMessage); 8570 real_overhead += sizeof(struct TransportReliabilityBoxMessage);
8648 } 8571 }
8649 8572
8650 /* Finally, compare to existing 'best' in sc to see if this 'pos' pending 8573 /* Finally, compare to existing 'best' in sc to see if this 'pos' pending
8651 message would beat it! */ 8574 message would beat it! */
8652 if (NULL != sc->best) 8575 if (NULL != sc->best)
8653 { 8576 {
8654 /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue; 8577 /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue;
8655 OPTIMIZE-ME: This is a heuristic, which so far has NOT been 8578 OPTIMIZE-ME: This is a heuristic, which so far has NOT been
8656 experimentally validated. There may be some huge potential for 8579 experimentally validated. There may be some huge potential for
8657 improvement here. Also, we right now only compare how well the 8580 improvement here. Also, we right now only compare how well the
8658 given message fits _this_ queue, and do not consider how well other 8581 given message fits _this_ queue, and do not consider how well other
8659 queues might suit the message. Taking other queues into consideration 8582 queues might suit the message. Taking other queues into consideration
8660 may further improve the result, but could also be expensive 8583 may further improve the result, but could also be expensive
8661 in terms of CPU time. */ 8584 in terms of CPU time. */
8662 long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead; 8585 long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead;
8663 long long pm_score = frag * 40 + relb * 20 + real_overhead; 8586 long long pm_score = frag * 40 + relb * 20 + real_overhead;
8664 long long time_delta = 8587 long long time_delta =
8665 (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us) / 8588 (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us) /
8666 1000LL; 8589 1000LL;
8667 8590
8668 /* "time_delta" considers which message has been 'ready' for transmission 8591 /* "time_delta" considers which message has been 'ready' for transmission
8669 for longer, if a message has a preference for low latency, increase 8592 for longer, if a message has a preference for low latency, increase
8670 the weight of the time_delta by 10x if it is favorable for that message */ 8593 the weight of the time_delta by 10x if it is favorable for that message */
8671 if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && 8594 if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
8672 (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY))) 8595 (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)))
8673 time_delta *= 10; /* increase weight (always, both are low latency) */ 8596 time_delta *= 10; /* increase weight (always, both are low latency) */
8674 else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && 8597 else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
8675 (time_delta > 0)) 8598 (time_delta > 0))
8676 time_delta *= 8599 time_delta *=
8677 10; /* increase weight, favors 'pos', which is low latency */ 8600 10; /* increase weight, favors 'pos', which is low latency */
8678 else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && 8601 else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
8679 (time_delta < 0)) 8602 (time_delta < 0))
8680 time_delta *= 8603 time_delta *=
8681 10; /* increase weight, favors 'sc->best', which is low latency */ 8604 10; /* increase weight, favors 'sc->best', which is low latency */
8682 if (0 != queue->mtu) 8605 if (0 != queue->mtu)
8683 { 8606 {
8684 /* Grant bonus if we are bellow MTU, larger bonus the closer we will 8607 /* Grant bonus if we are bellow MTU, larger bonus the closer we will
8685 be to the MTU */ 8608 be to the MTU */
8686 if (queue->mtu > sc->real_overhead + sc->best->bytes_msg) 8609 if (queue->mtu > sc->real_overhead + sc->best->bytes_msg)
8687 sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg); 8610 sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg);
8688 if (queue->mtu > real_overhead + pos->bytes_msg) 8611 if (queue->mtu > real_overhead + pos->bytes_msg)
8689 pm_score -= queue->mtu - (real_overhead + pos->bytes_msg); 8612 pm_score -= queue->mtu - (real_overhead + pos->bytes_msg);
8690 } 8613 }
8691 if (sc_score + time_delta > pm_score) 8614 if (sc_score + time_delta > pm_score)
8692 continue; /* sc_score larger, keep sc->best */ 8615 continue; /* sc_score larger, keep sc->best */
8616 }
8617 sc->best = pos;
8618 sc->dvh = dvh;
8619 sc->frag = frag;
8620 sc->relb = relb;
8693 } 8621 }
8694 sc->best = pos;
8695 sc->dvh = dvh;
8696 sc->frag = frag;
8697 sc->relb = relb;
8698 }
8699} 8622}
8700 8623
8701 8624
@@ -8710,26 +8633,26 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc,
8710 * @param options options of the original message 8633 * @param options options of the original message
8711 */ 8634 */
8712static void 8635static void
8713extract_box_cb (void *cls, 8636extract_box_cb(void *cls,
8714 struct Neighbour *next_hop, 8637 struct Neighbour *next_hop,
8715 const struct GNUNET_MessageHeader *hdr, 8638 const struct GNUNET_MessageHeader *hdr,
8716 enum RouteMessageOptions options) 8639 enum RouteMessageOptions options)
8717{ 8640{
8718 struct PendingMessageScoreContext *sc = cls; 8641 struct PendingMessageScoreContext *sc = cls;
8719 struct PendingMessage *pm = sc->best; 8642 struct PendingMessage *pm = sc->best;
8720 struct PendingMessage *bpm; 8643 struct PendingMessage *bpm;
8721 uint16_t bsize = ntohs (hdr->size); 8644 uint16_t bsize = ntohs(hdr->size);
8722 8645
8723 GNUNET_assert (NULL == pm->bpm); 8646 GNUNET_assert(NULL == pm->bpm);
8724 bpm = GNUNET_malloc (sizeof (struct PendingMessage) + bsize); 8647 bpm = GNUNET_malloc(sizeof(struct PendingMessage) + bsize);
8725 bpm->logging_uuid = logging_uuid_gen++; 8648 bpm->logging_uuid = logging_uuid_gen++;
8726 bpm->pmt = PMT_DV_BOX; 8649 bpm->pmt = PMT_DV_BOX;
8727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8650 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8728 "Creating DV Box %llu for original message %llu (next hop is %s)\n", 8651 "Creating DV Box %llu for original message %llu (next hop is %s)\n",
8729 bpm->logging_uuid, 8652 bpm->logging_uuid,
8730 pm->logging_uuid, 8653 pm->logging_uuid,
8731 GNUNET_i2s (&next_hop->pid)); 8654 GNUNET_i2s(&next_hop->pid));
8732 memcpy (&bpm[1], hdr, bsize); 8655 memcpy(&bpm[1], hdr, bsize);
8733 pm->bpm = bpm; 8656 pm->bpm = bpm;
8734} 8657}
8735 8658
@@ -8750,7 +8673,7 @@ extract_box_cb (void *cls,
8750 * @param cls the `struct Queue` to process transmissions for 8673 * @param cls the `struct Queue` to process transmissions for
8751 */ 8674 */
8752static void 8675static void
8753transmit_on_queue (void *cls) 8676transmit_on_queue(void *cls)
8754{ 8677{
8755 struct Queue *queue = cls; 8678 struct Queue *queue = cls;
8756 struct Neighbour *n = queue->neighbour; 8679 struct Neighbour *n = queue->neighbour;
@@ -8759,104 +8682,104 @@ transmit_on_queue (void *cls)
8759 8682
8760 queue->transmit_task = NULL; 8683 queue->transmit_task = NULL;
8761 if (NULL == n->vl) 8684 if (NULL == n->vl)
8762 { 8685 {
8763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8686 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8764 "Virtual link `%s' is down, cannot have PM for queue `%s'\n", 8687 "Virtual link `%s' is down, cannot have PM for queue `%s'\n",
8765 GNUNET_i2s (&n->pid), 8688 GNUNET_i2s(&n->pid),
8766 queue->address); 8689 queue->address);
8767 queue->idle = GNUNET_YES; 8690 queue->idle = GNUNET_YES;
8768 return; 8691 return;
8769 } 8692 }
8770 memset (&sc, 0, sizeof (sc)); 8693 memset(&sc, 0, sizeof(sc));
8771 select_best_pending_from_link (&sc, queue, n->vl, NULL, 0); 8694 select_best_pending_from_link(&sc, queue, n->vl, NULL, 0);
8772 if (NULL == sc.best) 8695 if (NULL == sc.best)
8773 { 8696 {
8774 /* Also look at DVH that have the n as first hop! */ 8697 /* Also look at DVH that have the n as first hop! */
8775 for (struct DistanceVectorHop *dvh = n->dv_head; NULL != dvh; 8698 for (struct DistanceVectorHop *dvh = n->dv_head; NULL != dvh;
8776 dvh = dvh->next_neighbour) 8699 dvh = dvh->next_neighbour)
8777 { 8700 {
8778 select_best_pending_from_link (&sc, 8701 select_best_pending_from_link(&sc,
8779 queue, 8702 queue,
8780 dvh->dv->vl, 8703 dvh->dv->vl,
8781 dvh, 8704 dvh,
8782 sizeof (struct GNUNET_PeerIdentity) * 8705 sizeof(struct GNUNET_PeerIdentity) *
8783 (1 + dvh->distance) + 8706 (1 + dvh->distance) +
8784 sizeof (struct TransportDVBoxMessage) + 8707 sizeof(struct TransportDVBoxMessage) +
8785 sizeof (struct TransportDVBoxPayloadP)); 8708 sizeof(struct TransportDVBoxPayloadP));
8709 }
8786 } 8710 }
8787 }
8788 if (NULL == sc.best) 8711 if (NULL == sc.best)
8789 { 8712 {
8790 /* no message pending, nothing to do here! */ 8713 /* no message pending, nothing to do here! */
8791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8714 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8792 "No pending messages, queue `%s' to %s now idle\n", 8715 "No pending messages, queue `%s' to %s now idle\n",
8793 queue->address, 8716 queue->address,
8794 GNUNET_i2s (&n->pid)); 8717 GNUNET_i2s(&n->pid));
8795 queue->idle = GNUNET_YES; 8718 queue->idle = GNUNET_YES;
8796 return; 8719 return;
8797 } 8720 }
8798 8721
8799 /* Given selection in `sc`, do transmission */ 8722 /* Given selection in `sc`, do transmission */
8800 pm = sc.best; 8723 pm = sc.best;
8801 if (NULL != sc.dvh) 8724 if (NULL != sc.dvh)
8802 { 8725 {
8803 GNUNET_assert (PMT_DV_BOX != pm->pmt); 8726 GNUNET_assert(PMT_DV_BOX != pm->pmt);
8804 if (NULL != sc.best->bpm) 8727 if (NULL != sc.best->bpm)
8805 { 8728 {
8806 /* We did this boxing before, but possibly for a different path! 8729 /* We did this boxing before, but possibly for a different path!
8807 Discard old DV box! OPTIMIZE-ME: we might want to check if 8730 Discard old DV box! OPTIMIZE-ME: we might want to check if
8808 it is the same and then not re-build the message... */ 8731 it is the same and then not re-build the message... */
8809 free_pending_message (sc.best->bpm); 8732 free_pending_message(sc.best->bpm);
8810 sc.best->bpm = NULL; 8733 sc.best->bpm = NULL;
8811 } 8734 }
8812 encapsulate_for_dv (sc.dvh->dv, 8735 encapsulate_for_dv(sc.dvh->dv,
8813 1, 8736 1,
8814 &sc.dvh, 8737 &sc.dvh,
8815 (const struct GNUNET_MessageHeader *) &sc.best[1], 8738 (const struct GNUNET_MessageHeader *)&sc.best[1],
8816 &extract_box_cb, 8739 &extract_box_cb,
8817 &sc, 8740 &sc,
8818 RMO_NONE); 8741 RMO_NONE);
8819 GNUNET_assert (NULL != sc.best->bpm); 8742 GNUNET_assert(NULL != sc.best->bpm);
8820 pm = sc.best->bpm; 8743 pm = sc.best->bpm;
8821 } 8744 }
8822 if (GNUNET_YES == sc.frag) 8745 if (GNUNET_YES == sc.frag)
8823 { 8746 {
8824 pm = fragment_message (queue, sc.dvh, pm); 8747 pm = fragment_message(queue, sc.dvh, pm);
8825 if (NULL == pm) 8748 if (NULL == pm)
8826 { 8749 {
8827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8750 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8828 "Fragmentation failed queue %s to %s for <%llu>, trying again\n", 8751 "Fragmentation failed queue %s to %s for <%llu>, trying again\n",
8829 queue->address, 8752 queue->address,
8830 GNUNET_i2s (&n->pid), 8753 GNUNET_i2s(&n->pid),
8831 sc.best->logging_uuid); 8754 sc.best->logging_uuid);
8832 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8755 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8833 return; 8756 return;
8757 }
8834 } 8758 }
8835 }
8836 else if (GNUNET_YES == sc.relb) 8759 else if (GNUNET_YES == sc.relb)
8837 { 8760 {
8838 pm = reliability_box_message (queue, sc.dvh, pm); 8761 pm = reliability_box_message(queue, sc.dvh, pm);
8839 if (NULL == pm) 8762 if (NULL == pm)
8840 { 8763 {
8841 /* Reliability boxing failed, try next message... */ 8764 /* Reliability boxing failed, try next message... */
8842 GNUNET_log ( 8765 GNUNET_log(
8843 GNUNET_ERROR_TYPE_DEBUG, 8766 GNUNET_ERROR_TYPE_DEBUG,
8844 "Reliability boxing failed queue %s to %s for <%llu>, trying again\n", 8767 "Reliability boxing failed queue %s to %s for <%llu>, trying again\n",
8845 queue->address, 8768 queue->address,
8846 GNUNET_i2s (&n->pid), 8769 GNUNET_i2s(&n->pid),
8847 sc.best->logging_uuid); 8770 sc.best->logging_uuid);
8848 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8771 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8849 return; 8772 return;
8773 }
8850 } 8774 }
8851 }
8852 8775
8853 /* Pass 'pm' for transission to the communicator */ 8776 /* Pass 'pm' for transission to the communicator */
8854 GNUNET_log ( 8777 GNUNET_log(
8855 GNUNET_ERROR_TYPE_DEBUG, 8778 GNUNET_ERROR_TYPE_DEBUG,
8856 "Passing message <%llu> to queue %s for peer %s (considered %u others)\n", 8779 "Passing message <%llu> to queue %s for peer %s (considered %u others)\n",
8857 pm->logging_uuid, 8780 pm->logging_uuid,
8858 queue->address, 8781 queue->address,
8859 GNUNET_i2s (&n->pid), 8782 GNUNET_i2s(&n->pid),
8860 sc.consideration_counter); 8783 sc.consideration_counter);
8861 8784
8862 /* Flow control: increment amount of traffic sent; if we are routing 8785 /* Flow control: increment amount of traffic sent; if we are routing
@@ -8867,50 +8790,50 @@ transmit_on_queue (void *cls)
8867 pm->vl->outbound_fc_window_size_used += pm->bytes_msg; 8790 pm->vl->outbound_fc_window_size_used += pm->bytes_msg;
8868 8791
8869 if (pm->vl != queue->neighbour->vl) 8792 if (pm->vl != queue->neighbour->vl)
8870 { 8793 {
8871 /* If the virtual link of the queue differs, this better be distance 8794 /* If the virtual link of the queue differs, this better be distance
8872 vector routing! */ 8795 vector routing! */
8873 GNUNET_assert (NULL != sc.dvh); 8796 GNUNET_assert(NULL != sc.dvh);
8874 /* If we do distance vector routing, we better not do this for a 8797 /* If we do distance vector routing, we better not do this for a
8875 message that was itself DV-routed */ 8798 message that was itself DV-routed */
8876 GNUNET_assert (PMT_DV_BOX != sc.best->pmt); 8799 GNUNET_assert(PMT_DV_BOX != sc.best->pmt);
8877 /* We use the size of the unboxed message here, to avoid counting 8800 /* We use the size of the unboxed message here, to avoid counting
8878 the DV-Box header which is eaten up on the way by intermediaries */ 8801 the DV-Box header which is eaten up on the way by intermediaries */
8879 queue->neighbour->vl->outbound_fc_window_size_used += sc.best->bytes_msg; 8802 queue->neighbour->vl->outbound_fc_window_size_used += sc.best->bytes_msg;
8880 } 8803 }
8881 else 8804 else
8882 { 8805 {
8883 GNUNET_assert (NULL == sc.dvh); 8806 GNUNET_assert(NULL == sc.dvh);
8884 } 8807 }
8885 8808
8886 queue_send_msg (queue, pm, &pm[1], pm->bytes_msg); 8809 queue_send_msg(queue, pm, &pm[1], pm->bytes_msg);
8887 8810
8888 /* Check if this transmission somehow conclusively finished handing 'pm' 8811 /* Check if this transmission somehow conclusively finished handing 'pm'
8889 even without any explicit ACKs */ 8812 even without any explicit ACKs */
8890 if ((PMT_CORE == pm->pmt) || 8813 if ((PMT_CORE == pm->pmt) ||
8891 (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)) 8814 (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc))
8892 { 8815 {
8893 completed_pending_message (pm); 8816 completed_pending_message(pm);
8894 } 8817 }
8895 else 8818 else
8896 { 8819 {
8897 /* Message not finished, waiting for acknowledgement. 8820 /* Message not finished, waiting for acknowledgement.
8898 Update time by which we might retransmit 's' based on queue 8821 Update time by which we might retransmit 's' based on queue
8899 characteristics (i.e. RTT); it takes one RTT for the message to 8822 characteristics (i.e. RTT); it takes one RTT for the message to
8900 arrive and the ACK to come back in the best case; but the other 8823 arrive and the ACK to come back in the best case; but the other
8901 side is allowed to delay ACKs by 2 RTTs, so we use 4 RTT before 8824 side is allowed to delay ACKs by 2 RTTs, so we use 4 RTT before
8902 retransmitting. 8825 retransmitting.
8903 8826
8904 OPTIMIZE: Note that in the future this heuristic should likely 8827 OPTIMIZE: Note that in the future this heuristic should likely
8905 be improved further (measure RTT stability, consider message 8828 be improved further (measure RTT stability, consider message
8906 urgency and size when delaying ACKs, etc.) */ 8829 urgency and size when delaying ACKs, etc.) */
8907 update_pm_next_attempt (pm, 8830 update_pm_next_attempt(pm,
8908 GNUNET_TIME_relative_to_absolute ( 8831 GNUNET_TIME_relative_to_absolute(
8909 GNUNET_TIME_relative_multiply (queue->pd.aged_rtt, 8832 GNUNET_TIME_relative_multiply(queue->pd.aged_rtt,
8910 4))); 8833 4)));
8911 } 8834 }
8912 /* finally, re-schedule queue transmission task itself */ 8835 /* finally, re-schedule queue transmission task itself */
8913 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8836 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8914} 8837}
8915 8838
8916 8839
@@ -8921,35 +8844,35 @@ transmit_on_queue (void *cls)
8921 * @param dqm the send message that was sent 8844 * @param dqm the send message that was sent
8922 */ 8845 */
8923static void 8846static void
8924handle_del_queue_message (void *cls, 8847handle_del_queue_message(void *cls,
8925 const struct GNUNET_TRANSPORT_DelQueueMessage *dqm) 8848 const struct GNUNET_TRANSPORT_DelQueueMessage *dqm)
8926{ 8849{
8927 struct TransportClient *tc = cls; 8850 struct TransportClient *tc = cls;
8928 8851
8929 if (CT_COMMUNICATOR != tc->type) 8852 if (CT_COMMUNICATOR != tc->type)
8930 { 8853 {
8931 GNUNET_break (0); 8854 GNUNET_break(0);
8932 GNUNET_SERVICE_client_drop (tc->client); 8855 GNUNET_SERVICE_client_drop(tc->client);
8933 return; 8856 return;
8934 } 8857 }
8935 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; 8858 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue;
8936 queue = queue->next_client) 8859 queue = queue->next_client)
8937 { 8860 {
8938 struct Neighbour *neighbour = queue->neighbour; 8861 struct Neighbour *neighbour = queue->neighbour;
8939 8862
8940 if ((dqm->qid != queue->qid) || 8863 if ((dqm->qid != queue->qid) ||
8941 (0 != GNUNET_memcmp (&dqm->receiver, &neighbour->pid))) 8864 (0 != GNUNET_memcmp(&dqm->receiver, &neighbour->pid)))
8942 continue; 8865 continue;
8943 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8866 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8944 "Dropped queue %s to peer %s\n", 8867 "Dropped queue %s to peer %s\n",
8945 queue->address, 8868 queue->address,
8946 GNUNET_i2s (&neighbour->pid)); 8869 GNUNET_i2s(&neighbour->pid));
8947 free_queue (queue); 8870 free_queue(queue);
8948 GNUNET_SERVICE_client_continue (tc->client); 8871 GNUNET_SERVICE_client_continue(tc->client);
8949 return; 8872 return;
8950 } 8873 }
8951 GNUNET_break (0); 8874 GNUNET_break(0);
8952 GNUNET_SERVICE_client_drop (tc->client); 8875 GNUNET_SERVICE_client_drop(tc->client);
8953} 8876}
8954 8877
8955 8878
@@ -8960,97 +8883,97 @@ handle_del_queue_message (void *cls,
8960 * @param sma the send message that was sent 8883 * @param sma the send message that was sent
8961 */ 8884 */
8962static void 8885static void
8963handle_send_message_ack (void *cls, 8886handle_send_message_ack(void *cls,
8964 const struct GNUNET_TRANSPORT_SendMessageToAck *sma) 8887 const struct GNUNET_TRANSPORT_SendMessageToAck *sma)
8965{ 8888{
8966 struct TransportClient *tc = cls; 8889 struct TransportClient *tc = cls;
8967 struct QueueEntry *qe; 8890 struct QueueEntry *qe;
8968 struct PendingMessage *pm; 8891 struct PendingMessage *pm;
8969 8892
8970 if (CT_COMMUNICATOR != tc->type) 8893 if (CT_COMMUNICATOR != tc->type)
8971 { 8894 {
8972 GNUNET_break (0); 8895 GNUNET_break(0);
8973 GNUNET_SERVICE_client_drop (tc->client); 8896 GNUNET_SERVICE_client_drop(tc->client);
8974 return; 8897 return;
8975 } 8898 }
8976 8899
8977 /* find our queue entry matching the ACK */ 8900 /* find our queue entry matching the ACK */
8978 qe = NULL; 8901 qe = NULL;
8979 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; 8902 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue;
8980 queue = queue->next_client) 8903 queue = queue->next_client)
8981 {
8982 if (0 != GNUNET_memcmp (&queue->neighbour->pid, &sma->receiver))
8983 continue;
8984 for (struct QueueEntry *qep = queue->queue_head; NULL != qep;
8985 qep = qep->next)
8986 { 8904 {
8987 if (qep->mid != sma->mid) 8905 if (0 != GNUNET_memcmp(&queue->neighbour->pid, &sma->receiver))
8988 continue; 8906 continue;
8989 qe = qep; 8907 for (struct QueueEntry *qep = queue->queue_head; NULL != qep;
8908 qep = qep->next)
8909 {
8910 if (qep->mid != sma->mid)
8911 continue;
8912 qe = qep;
8913 break;
8914 }
8990 break; 8915 break;
8991 } 8916 }
8992 break;
8993 }
8994 if (NULL == qe) 8917 if (NULL == qe)
8995 { 8918 {
8996 /* this should never happen */ 8919 /* this should never happen */
8997 GNUNET_break (0); 8920 GNUNET_break(0);
8998 GNUNET_SERVICE_client_drop (tc->client); 8921 GNUNET_SERVICE_client_drop(tc->client);
8999 return; 8922 return;
9000 } 8923 }
9001 GNUNET_CONTAINER_DLL_remove (qe->queue->queue_head, 8924 GNUNET_CONTAINER_DLL_remove(qe->queue->queue_head,
9002 qe->queue->queue_tail, 8925 qe->queue->queue_tail,
9003 qe); 8926 qe);
9004 qe->queue->queue_length--; 8927 qe->queue->queue_length--;
9005 tc->details.communicator.total_queue_length--; 8928 tc->details.communicator.total_queue_length--;
9006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8929 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9007 "Received ACK on queue %s to peer %s (new length: %u/%u)\n", 8930 "Received ACK on queue %s to peer %s (new length: %u/%u)\n",
9008 qe->queue->address, 8931 qe->queue->address,
9009 GNUNET_i2s (&qe->queue->neighbour->pid), 8932 GNUNET_i2s(&qe->queue->neighbour->pid),
9010 qe->queue->queue_length, 8933 qe->queue->queue_length,
9011 tc->details.communicator.total_queue_length); 8934 tc->details.communicator.total_queue_length);
9012 GNUNET_SERVICE_client_continue (tc->client); 8935 GNUNET_SERVICE_client_continue(tc->client);
9013 8936
9014 /* if applicable, resume transmissions that waited on ACK */ 8937 /* if applicable, resume transmissions that waited on ACK */
9015 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 == 8938 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 ==
9016 tc->details.communicator.total_queue_length) 8939 tc->details.communicator.total_queue_length)
9017 { 8940 {
9018 /* Communicator dropped below threshold, resume all queues 8941 /* Communicator dropped below threshold, resume all queues
9019 incident with this client! */ 8942 incident with this client! */
9020 GNUNET_STATISTICS_update ( 8943 GNUNET_STATISTICS_update(
9021 GST_stats, 8944 GST_stats,
9022 "# Transmission throttled due to communicator queue limit", 8945 "# Transmission throttled due to communicator queue limit",
9023 -1, 8946 -1,
9024 GNUNET_NO); 8947 GNUNET_NO);
9025 for (struct Queue *queue = tc->details.communicator.queue_head; 8948 for (struct Queue *queue = tc->details.communicator.queue_head;
9026 NULL != queue; 8949 NULL != queue;
9027 queue = queue->next_client) 8950 queue = queue->next_client)
9028 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8951 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9029 } 8952 }
9030 else if (QUEUE_LENGTH_LIMIT - 1 == qe->queue->queue_length) 8953 else if (QUEUE_LENGTH_LIMIT - 1 == qe->queue->queue_length)
9031 { 8954 {
9032 /* queue dropped below threshold; only resume this one queue */ 8955 /* queue dropped below threshold; only resume this one queue */
9033 GNUNET_STATISTICS_update (GST_stats, 8956 GNUNET_STATISTICS_update(GST_stats,
9034 "# Transmission throttled due to queue queue limit", 8957 "# Transmission throttled due to queue queue limit",
9035 -1, 8958 -1,
9036 GNUNET_NO); 8959 GNUNET_NO);
9037 schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8960 schedule_transmit_on_queue(qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9038 } 8961 }
9039 8962
9040 if (NULL != (pm = qe->pm)) 8963 if (NULL != (pm = qe->pm))
9041 { 8964 {
9042 struct VirtualLink *vl; 8965 struct VirtualLink *vl;
9043 8966
9044 GNUNET_assert (qe == pm->qe); 8967 GNUNET_assert(qe == pm->qe);
9045 pm->qe = NULL; 8968 pm->qe = NULL;
9046 /* If waiting for this communicator may have blocked transmission 8969 /* If waiting for this communicator may have blocked transmission
9047 of pm on other queues for this neighbour, force schedule 8970 of pm on other queues for this neighbour, force schedule
9048 transmit on queue for queues of the neighbour */ 8971 transmit on queue for queues of the neighbour */
9049 vl = pm->vl; 8972 vl = pm->vl;
9050 if (vl->pending_msg_head == pm) 8973 if (vl->pending_msg_head == pm)
9051 check_vl_transmission (vl); 8974 check_vl_transmission(vl);
9052 } 8975 }
9053 GNUNET_free (qe); 8976 GNUNET_free(qe);
9054} 8977}
9055 8978
9056 8979
@@ -9064,24 +8987,24 @@ handle_send_message_ack (void *cls,
9064 * @return #GNUNET_OK (continue to iterate) 8987 * @return #GNUNET_OK (continue to iterate)
9065 */ 8988 */
9066static int 8989static int
9067notify_client_queues (void *cls, 8990notify_client_queues(void *cls,
9068 const struct GNUNET_PeerIdentity *pid, 8991 const struct GNUNET_PeerIdentity *pid,
9069 void *value) 8992 void *value)
9070{ 8993{
9071 struct TransportClient *tc = cls; 8994 struct TransportClient *tc = cls;
9072 struct Neighbour *neighbour = value; 8995 struct Neighbour *neighbour = value;
9073 8996
9074 GNUNET_assert (CT_MONITOR == tc->type); 8997 GNUNET_assert(CT_MONITOR == tc->type);
9075 for (struct Queue *q = neighbour->queue_head; NULL != q; 8998 for (struct Queue *q = neighbour->queue_head; NULL != q;
9076 q = q->next_neighbour) 8999 q = q->next_neighbour)
9077 { 9000 {
9078 struct MonitorEvent me = {.rtt = q->pd.aged_rtt, 9001 struct MonitorEvent me = { .rtt = q->pd.aged_rtt,
9079 .cs = q->cs, 9002 .cs = q->cs,
9080 .num_msg_pending = q->num_msg_pending, 9003 .num_msg_pending = q->num_msg_pending,
9081 .num_bytes_pending = q->num_bytes_pending}; 9004 .num_bytes_pending = q->num_bytes_pending };
9082 9005
9083 notify_monitor (tc, pid, q->address, q->nt, &me); 9006 notify_monitor(tc, pid, q->address, q->nt, &me);
9084 } 9007 }
9085 return GNUNET_OK; 9008 return GNUNET_OK;
9086} 9009}
9087 9010
@@ -9093,23 +9016,23 @@ notify_client_queues (void *cls,
9093 * @param start the start message that was sent 9016 * @param start the start message that was sent
9094 */ 9017 */
9095static void 9018static void
9096handle_monitor_start (void *cls, 9019handle_monitor_start(void *cls,
9097 const struct GNUNET_TRANSPORT_MonitorStart *start) 9020 const struct GNUNET_TRANSPORT_MonitorStart *start)
9098{ 9021{
9099 struct TransportClient *tc = cls; 9022 struct TransportClient *tc = cls;
9100 9023
9101 if (CT_NONE != tc->type) 9024 if (CT_NONE != tc->type)
9102 { 9025 {
9103 GNUNET_break (0); 9026 GNUNET_break(0);
9104 GNUNET_SERVICE_client_drop (tc->client); 9027 GNUNET_SERVICE_client_drop(tc->client);
9105 return; 9028 return;
9106 } 9029 }
9107 tc->type = CT_MONITOR; 9030 tc->type = CT_MONITOR;
9108 tc->details.monitor.peer = start->peer; 9031 tc->details.monitor.peer = start->peer;
9109 tc->details.monitor.one_shot = ntohl (start->one_shot); 9032 tc->details.monitor.one_shot = ntohl(start->one_shot);
9110 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &notify_client_queues, tc); 9033 GNUNET_CONTAINER_multipeermap_iterate(neighbours, &notify_client_queues, tc);
9111 GNUNET_SERVICE_client_mark_monitor (tc->client); 9034 GNUNET_SERVICE_client_mark_monitor(tc->client);
9112 GNUNET_SERVICE_client_continue (tc->client); 9035 GNUNET_SERVICE_client_continue(tc->client);
9113} 9036}
9114 9037
9115 9038
@@ -9121,16 +9044,16 @@ handle_monitor_start (void *cls,
9121 * @return NULL if no such transport client is available 9044 * @return NULL if no such transport client is available
9122 */ 9045 */
9123static struct TransportClient * 9046static struct TransportClient *
9124lookup_communicator (const char *prefix) 9047lookup_communicator(const char *prefix)
9125{ 9048{
9126 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 9049 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
9127 { 9050 {
9128 if (CT_COMMUNICATOR != tc->type) 9051 if (CT_COMMUNICATOR != tc->type)
9129 continue; 9052 continue;
9130 if (0 == strcmp (prefix, tc->details.communicator.address_prefix)) 9053 if (0 == strcmp(prefix, tc->details.communicator.address_prefix))
9131 return tc; 9054 return tc;
9132 } 9055 }
9133 GNUNET_log ( 9056 GNUNET_log(
9134 GNUNET_ERROR_TYPE_WARNING, 9057 GNUNET_ERROR_TYPE_WARNING,
9135 "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n", 9058 "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n",
9136 prefix); 9059 prefix);
@@ -9146,7 +9069,7 @@ lookup_communicator (const char *prefix)
9146 * @param address the address to try 9069 * @param address the address to try
9147 */ 9070 */
9148static void 9071static void
9149suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address) 9072suggest_to_connect(const struct GNUNET_PeerIdentity *pid, const char *address)
9150{ 9073{
9151 static uint32_t idgen; 9074 static uint32_t idgen;
9152 struct TransportClient *tc; 9075 struct TransportClient *tc;
@@ -9155,40 +9078,40 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address)
9155 struct GNUNET_MQ_Envelope *env; 9078 struct GNUNET_MQ_Envelope *env;
9156 size_t alen; 9079 size_t alen;
9157 9080
9158 prefix = GNUNET_HELLO_address_to_prefix (address); 9081 prefix = GNUNET_HELLO_address_to_prefix(address);
9159 if (NULL == prefix) 9082 if (NULL == prefix)
9160 { 9083 {
9161 GNUNET_break (0); /* We got an invalid address!? */ 9084 GNUNET_break(0); /* We got an invalid address!? */
9162 return; 9085 return;
9163 } 9086 }
9164 tc = lookup_communicator (prefix); 9087 tc = lookup_communicator(prefix);
9165 if (NULL == tc) 9088 if (NULL == tc)
9166 { 9089 {
9167 GNUNET_STATISTICS_update (GST_stats, 9090 GNUNET_STATISTICS_update(GST_stats,
9168 "# Suggestions ignored due to missing communicator", 9091 "# Suggestions ignored due to missing communicator",
9169 1, 9092 1,
9170 GNUNET_NO); 9093 GNUNET_NO);
9171 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 9094 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
9172 "Cannot connect to %s at `%s', no matching communicator present\n", 9095 "Cannot connect to %s at `%s', no matching communicator present\n",
9173 GNUNET_i2s (pid), 9096 GNUNET_i2s(pid),
9174 address); 9097 address);
9175 GNUNET_free (prefix); 9098 GNUNET_free(prefix);
9176 return; 9099 return;
9177 } 9100 }
9178 /* forward suggestion for queue creation to communicator */ 9101 /* forward suggestion for queue creation to communicator */
9179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9102 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9180 "Request #%u for `%s' communicator to create queue to `%s'\n", 9103 "Request #%u for `%s' communicator to create queue to `%s'\n",
9181 (unsigned int) idgen, 9104 (unsigned int)idgen,
9182 prefix, 9105 prefix,
9183 address); 9106 address);
9184 GNUNET_free (prefix); 9107 GNUNET_free(prefix);
9185 alen = strlen (address) + 1; 9108 alen = strlen(address) + 1;
9186 env = 9109 env =
9187 GNUNET_MQ_msg_extra (cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); 9110 GNUNET_MQ_msg_extra(cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
9188 cqm->request_id = htonl (idgen++); 9111 cqm->request_id = htonl(idgen++);
9189 cqm->receiver = *pid; 9112 cqm->receiver = *pid;
9190 memcpy (&cqm[1], address, alen); 9113 memcpy(&cqm[1], address, alen);
9191 GNUNET_MQ_send (tc->mq, env); 9114 GNUNET_MQ_send(tc->mq, env);
9192} 9115}
9193 9116
9194 9117
@@ -9200,22 +9123,22 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address)
9200 * @param vs state to derive validation challenge from 9123 * @param vs state to derive validation challenge from
9201 */ 9124 */
9202static void 9125static void
9203validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs) 9126validation_transmit_on_queue(struct Queue *q, struct ValidationState *vs)
9204{ 9127{
9205 struct TransportValidationChallengeMessage tvc; 9128 struct TransportValidationChallengeMessage tvc;
9206 9129
9207 vs->last_challenge_use = GNUNET_TIME_absolute_get_monotonic (GST_cfg); 9130 vs->last_challenge_use = GNUNET_TIME_absolute_get_monotonic(GST_cfg);
9208 tvc.header.type = 9131 tvc.header.type =
9209 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); 9132 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE);
9210 tvc.header.size = htons (sizeof (tvc)); 9133 tvc.header.size = htons(sizeof(tvc));
9211 tvc.reserved = htonl (0); 9134 tvc.reserved = htonl(0);
9212 tvc.challenge = vs->challenge; 9135 tvc.challenge = vs->challenge;
9213 tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); 9136 tvc.sender_time = GNUNET_TIME_absolute_hton(vs->last_challenge_use);
9214 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 9137 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
9215 "Sending address validation challenge %s to %s\n", 9138 "Sending address validation challenge %s to %s\n",
9216 GNUNET_sh2s (&tvc.challenge.value), 9139 GNUNET_sh2s(&tvc.challenge.value),
9217 GNUNET_i2s (&q->neighbour->pid)); 9140 GNUNET_i2s(&q->neighbour->pid));
9218 queue_send_msg (q, NULL, &tvc, sizeof (tvc)); 9141 queue_send_msg(q, NULL, &tvc, sizeof(tvc));
9219} 9142}
9220 9143
9221 9144
@@ -9225,56 +9148,55 @@ validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs)
9225 * @param cls NULL 9148 * @param cls NULL
9226 */ 9149 */
9227static void 9150static void
9228validation_start_cb (void *cls) 9151validation_start_cb(void *cls)
9229{ 9152{
9230 struct ValidationState *vs; 9153 struct ValidationState *vs;
9231 struct Queue *q; 9154 struct Queue *q;
9232 9155
9233 (void) cls; 9156 (void)cls;
9234 validation_task = NULL; 9157 validation_task = NULL;
9235 vs = GNUNET_CONTAINER_heap_peek (validation_heap); 9158 vs = GNUNET_CONTAINER_heap_peek(validation_heap);
9236 /* drop validations past their expiration */ 9159 /* drop validations past their expiration */
9237 while ( 9160 while (
9238 (NULL != vs) && 9161 (NULL != vs) &&
9239 (0 == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us)) 9162 (0 == GNUNET_TIME_absolute_get_remaining(vs->valid_until).rel_value_us))
9240 { 9163 {
9241 free_validation_state (vs); 9164 free_validation_state(vs);
9242 vs = GNUNET_CONTAINER_heap_peek (validation_heap); 9165 vs = GNUNET_CONTAINER_heap_peek(validation_heap);
9243 } 9166 }
9244 if (NULL == vs) 9167 if (NULL == vs)
9245 { 9168 {
9246 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 9169 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
9247 "Address validation task not scheduled anymore, nothing to do\n"); 9170 "Address validation task not scheduled anymore, nothing to do\n");
9248 return; /* woopsie, no more addresses known, should only 9171 return; /* woopsie, no more addresses known, should only
9249 happen if we're really a lonely peer */ 9172 happen if we're really a lonely peer */
9250 } 9173 }
9251 q = find_queue (&vs->pid, vs->address); 9174 q = find_queue(&vs->pid, vs->address);
9252 if (NULL == q) 9175 if (NULL == q)
9253 { 9176 {
9254 vs->awaiting_queue = GNUNET_YES; 9177 vs->awaiting_queue = GNUNET_YES;
9255 suggest_to_connect (&vs->pid, vs->address); 9178 suggest_to_connect(&vs->pid, vs->address);
9256 } 9179 }
9257 else 9180 else
9258 validation_transmit_on_queue (q, vs); 9181 validation_transmit_on_queue(q, vs);
9259 /* Finally, reschedule next attempt */ 9182 /* Finally, reschedule next attempt */
9260 vs->challenge_backoff = 9183 vs->challenge_backoff =
9261 GNUNET_TIME_randomized_backoff (vs->challenge_backoff, 9184 GNUNET_TIME_randomized_backoff(vs->challenge_backoff,
9262 MAX_VALIDATION_CHALLENGE_FREQ); 9185 MAX_VALIDATION_CHALLENGE_FREQ);
9263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9186 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9264 "Address validation task will run again in %s\n", 9187 "Address validation task will run again in %s\n",
9265 GNUNET_STRINGS_relative_time_to_string (vs->challenge_backoff, 9188 GNUNET_STRINGS_relative_time_to_string(vs->challenge_backoff,
9266 GNUNET_YES)); 9189 GNUNET_YES));
9267 update_next_challenge_time (vs, 9190 update_next_challenge_time(vs,
9268 GNUNET_TIME_relative_to_absolute ( 9191 GNUNET_TIME_relative_to_absolute(
9269 vs->challenge_backoff)); 9192 vs->challenge_backoff));
9270} 9193}
9271 9194
9272 9195
9273/** 9196/**
9274 * Closure for #check_connection_quality. 9197 * Closure for #check_connection_quality.
9275 */ 9198 */
9276struct QueueQualityContext 9199struct QueueQualityContext {
9277{
9278 /** 9200 /**
9279 * Set to the @e k'th queue encountered. 9201 * Set to the @e k'th queue encountered.
9280 */ 9202 */
@@ -9310,26 +9232,26 @@ struct QueueQualityContext
9310 * @return #GNUNET_OK (continue to iterate) 9232 * @return #GNUNET_OK (continue to iterate)
9311 */ 9233 */
9312static int 9234static int
9313check_connection_quality (void *cls, 9235check_connection_quality(void *cls,
9314 const struct GNUNET_PeerIdentity *pid, 9236 const struct GNUNET_PeerIdentity *pid,
9315 void *value) 9237 void *value)
9316{ 9238{
9317 struct QueueQualityContext *ctx = cls; 9239 struct QueueQualityContext *ctx = cls;
9318 struct Neighbour *n = value; 9240 struct Neighbour *n = value;
9319 int do_inc; 9241 int do_inc;
9320 9242
9321 (void) pid; 9243 (void)pid;
9322 do_inc = GNUNET_NO; 9244 do_inc = GNUNET_NO;
9323 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) 9245 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
9324 { 9246 {
9325 ctx->num_queues++; 9247 ctx->num_queues++;
9326 if (0 == ctx->k--) 9248 if (0 == ctx->k--)
9327 ctx->q = q; 9249 ctx->q = q;
9328 /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput 9250 /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput
9329 statistics and consider those as well here? */ 9251 statistics and consider those as well here? */
9330 if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us) 9252 if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us)
9331 do_inc = GNUNET_YES; 9253 do_inc = GNUNET_YES;
9332 } 9254 }
9333 if (GNUNET_YES == do_inc) 9255 if (GNUNET_YES == do_inc)
9334 ctx->quality_count++; 9256 ctx->quality_count++;
9335 return GNUNET_OK; 9257 return GNUNET_OK;
@@ -9348,103 +9270,103 @@ check_connection_quality (void *cls,
9348 * @param cls NULL 9270 * @param cls NULL
9349 */ 9271 */
9350static void 9272static void
9351start_dv_learn (void *cls) 9273start_dv_learn(void *cls)
9352{ 9274{
9353 struct LearnLaunchEntry *lle; 9275 struct LearnLaunchEntry *lle;
9354 struct QueueQualityContext qqc; 9276 struct QueueQualityContext qqc;
9355 struct TransportDVLearnMessage dvl; 9277 struct TransportDVLearnMessage dvl;
9356 9278
9357 (void) cls; 9279 (void)cls;
9358 dvlearn_task = NULL; 9280 dvlearn_task = NULL;
9359 if (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)) 9281 if (0 == GNUNET_CONTAINER_multipeermap_size(neighbours))
9360 return; /* lost all connectivity, cannot do learning */ 9282 return; /* lost all connectivity, cannot do learning */
9361 qqc.quality_count = 0; 9283 qqc.quality_count = 0;
9362 qqc.num_queues = 0; 9284 qqc.num_queues = 0;
9363 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 9285 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
9364 &check_connection_quality, 9286 &check_connection_quality,
9365 &qqc); 9287 &qqc);
9366 if (qqc.quality_count > DV_LEARN_QUALITY_THRESHOLD) 9288 if (qqc.quality_count > DV_LEARN_QUALITY_THRESHOLD)
9367 { 9289 {
9368 struct GNUNET_TIME_Relative delay; 9290 struct GNUNET_TIME_Relative delay;
9369 unsigned int factor; 9291 unsigned int factor;
9370 9292
9371 /* scale our retries by how far we are above the threshold */ 9293 /* scale our retries by how far we are above the threshold */
9372 factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; 9294 factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD;
9373 delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, factor); 9295 delay = GNUNET_TIME_relative_multiply(DV_LEARN_BASE_FREQUENCY, factor);
9374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9296 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9375 "At connection quality %u, will launch DV learn in %s\n", 9297 "At connection quality %u, will launch DV learn in %s\n",
9376 qqc.quality_count, 9298 qqc.quality_count,
9377 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 9299 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES));
9378 dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay, &start_dv_learn, NULL); 9300 dvlearn_task = GNUNET_SCHEDULER_add_delayed(delay, &start_dv_learn, NULL);
9379 return; 9301 return;
9380 } 9302 }
9381 /* remove old entries in #dvlearn_map if it has grown too big */ 9303 /* remove old entries in #dvlearn_map if it has grown too big */
9382 while (MAX_DV_LEARN_PENDING >= 9304 while (MAX_DV_LEARN_PENDING >=
9383 GNUNET_CONTAINER_multishortmap_size (dvlearn_map)) 9305 GNUNET_CONTAINER_multishortmap_size(dvlearn_map))
9384 { 9306 {
9385 lle = lle_tail; 9307 lle = lle_tail;
9386 GNUNET_assert (GNUNET_YES == 9308 GNUNET_assert(GNUNET_YES ==
9387 GNUNET_CONTAINER_multishortmap_remove (dvlearn_map, 9309 GNUNET_CONTAINER_multishortmap_remove(dvlearn_map,
9388 &lle->challenge.value, 9310 &lle->challenge.value,
9389 lle)); 9311 lle));
9390 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); 9312 GNUNET_CONTAINER_DLL_remove(lle_head, lle_tail, lle);
9391 GNUNET_free (lle); 9313 GNUNET_free(lle);
9392 } 9314 }
9393 /* setup data structure for learning */ 9315 /* setup data structure for learning */
9394 lle = GNUNET_new (struct LearnLaunchEntry); 9316 lle = GNUNET_new(struct LearnLaunchEntry);
9395 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 9317 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
9396 &lle->challenge, 9318 &lle->challenge,
9397 sizeof (lle->challenge)); 9319 sizeof(lle->challenge));
9398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9399 "Starting launch DV learn with challenge %s\n", 9321 "Starting launch DV learn with challenge %s\n",
9400 GNUNET_sh2s (&lle->challenge.value)); 9322 GNUNET_sh2s(&lle->challenge.value));
9401 GNUNET_CONTAINER_DLL_insert (lle_head, lle_tail, lle); 9323 GNUNET_CONTAINER_DLL_insert(lle_head, lle_tail, lle);
9402 GNUNET_break (GNUNET_YES == 9324 GNUNET_break(GNUNET_YES ==
9403 GNUNET_CONTAINER_multishortmap_put ( 9325 GNUNET_CONTAINER_multishortmap_put(
9404 dvlearn_map, 9326 dvlearn_map,
9405 &lle->challenge.value, 9327 &lle->challenge.value,
9406 lle, 9328 lle,
9407 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 9329 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
9408 dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); 9330 dvl.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN);
9409 dvl.header.size = htons (sizeof (dvl)); 9331 dvl.header.size = htons(sizeof(dvl));
9410 dvl.num_hops = htons (0); 9332 dvl.num_hops = htons(0);
9411 dvl.bidirectional = htons (0); 9333 dvl.bidirectional = htons(0);
9412 dvl.non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); 9334 dvl.non_network_delay = GNUNET_TIME_relative_hton(GNUNET_TIME_UNIT_ZERO);
9413 dvl.monotonic_time = 9335 dvl.monotonic_time =
9414 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg)); 9336 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(GST_cfg));
9415 { 9337 {
9416 struct DvInitPS dvip = {.purpose.purpose = htonl ( 9338 struct DvInitPS dvip = { .purpose.purpose = htonl(
9417 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), 9339 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR),
9418 .purpose.size = htonl (sizeof (dvip)), 9340 .purpose.size = htonl(sizeof(dvip)),
9419 .monotonic_time = dvl.monotonic_time, 9341 .monotonic_time = dvl.monotonic_time,
9420 .challenge = lle->challenge}; 9342 .challenge = lle->challenge };
9421 9343
9422 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 9344 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key,
9423 &dvip.purpose, 9345 &dvip.purpose,
9424 &dvl.init_sig)); 9346 &dvl.init_sig));
9425 } 9347 }
9426 dvl.initiator = GST_my_identity; 9348 dvl.initiator = GST_my_identity;
9427 dvl.challenge = lle->challenge; 9349 dvl.challenge = lle->challenge;
9428 9350
9429 qqc.quality_count = 0; 9351 qqc.quality_count = 0;
9430 qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues); 9352 qqc.k = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues);
9431 qqc.num_queues = 0; 9353 qqc.num_queues = 0;
9432 qqc.q = NULL; 9354 qqc.q = NULL;
9433 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 9355 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
9434 &check_connection_quality, 9356 &check_connection_quality,
9435 &qqc); 9357 &qqc);
9436 GNUNET_assert (NULL != qqc.q); 9358 GNUNET_assert(NULL != qqc.q);
9437 9359
9438 /* Do this as close to transmission time as possible! */ 9360 /* Do this as close to transmission time as possible! */
9439 lle->launch_time = GNUNET_TIME_absolute_get (); 9361 lle->launch_time = GNUNET_TIME_absolute_get();
9440 9362
9441 queue_send_msg (qqc.q, NULL, &dvl, sizeof (dvl)); 9363 queue_send_msg(qqc.q, NULL, &dvl, sizeof(dvl));
9442 /* reschedule this job, randomizing the time it runs (but no 9364 /* reschedule this job, randomizing the time it runs (but no
9443 actual backoff!) */ 9365 actual backoff!) */
9444 dvlearn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_randomize ( 9366 dvlearn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_randomize(
9445 DV_LEARN_BASE_FREQUENCY), 9367 DV_LEARN_BASE_FREQUENCY),
9446 &start_dv_learn, 9368 &start_dv_learn,
9447 NULL); 9369 NULL);
9448} 9370}
9449 9371
9450 9372
@@ -9458,21 +9380,21 @@ start_dv_learn (void *cls)
9458 * @return #GNUNET_NO if a match was found and we can stop looking 9380 * @return #GNUNET_NO if a match was found and we can stop looking
9459 */ 9381 */
9460static int 9382static int
9461check_validation_request_pending (void *cls, 9383check_validation_request_pending(void *cls,
9462 const struct GNUNET_PeerIdentity *pid, 9384 const struct GNUNET_PeerIdentity *pid,
9463 void *value) 9385 void *value)
9464{ 9386{
9465 struct Queue *q = cls; 9387 struct Queue *q = cls;
9466 struct ValidationState *vs = value; 9388 struct ValidationState *vs = value;
9467 9389
9468 (void) pid; 9390 (void)pid;
9469 if ((GNUNET_YES == vs->awaiting_queue) && 9391 if ((GNUNET_YES == vs->awaiting_queue) &&
9470 (0 == strcmp (vs->address, q->address))) 9392 (0 == strcmp(vs->address, q->address)))
9471 { 9393 {
9472 vs->awaiting_queue = GNUNET_NO; 9394 vs->awaiting_queue = GNUNET_NO;
9473 validation_transmit_on_queue (q, vs); 9395 validation_transmit_on_queue(q, vs);
9474 return GNUNET_NO; 9396 return GNUNET_NO;
9475 } 9397 }
9476 return GNUNET_OK; 9398 return GNUNET_OK;
9477} 9399}
9478 9400
@@ -9486,31 +9408,31 @@ check_validation_request_pending (void *cls,
9486 * @param emsg error message 9408 * @param emsg error message
9487 */ 9409 */
9488static void 9410static void
9489neighbour_dv_monotime_cb (void *cls, 9411neighbour_dv_monotime_cb(void *cls,
9490 const struct GNUNET_PEERSTORE_Record *record, 9412 const struct GNUNET_PEERSTORE_Record *record,
9491 const char *emsg) 9413 const char *emsg)
9492{ 9414{
9493 struct Neighbour *n = cls; 9415 struct Neighbour *n = cls;
9494 struct GNUNET_TIME_AbsoluteNBO *mtbe; 9416 struct GNUNET_TIME_AbsoluteNBO *mtbe;
9495 9417
9496 (void) emsg; 9418 (void)emsg;
9497 if (NULL == record) 9419 if (NULL == record)
9498 { 9420 {
9499 /* we're done with #neighbour_dv_monotime_cb() invocations, 9421 /* we're done with #neighbour_dv_monotime_cb() invocations,
9500 continue normal processing */ 9422 continue normal processing */
9501 n->get = NULL; 9423 n->get = NULL;
9502 n->dv_monotime_available = GNUNET_YES; 9424 n->dv_monotime_available = GNUNET_YES;
9503 return; 9425 return;
9504 } 9426 }
9505 if (sizeof (*mtbe) != record->value_size) 9427 if (sizeof(*mtbe) != record->value_size)
9506 { 9428 {
9507 GNUNET_break (0); 9429 GNUNET_break(0);
9508 return; 9430 return;
9509 } 9431 }
9510 mtbe = record->value; 9432 mtbe = record->value;
9511 n->last_dv_learn_monotime = 9433 n->last_dv_learn_monotime =
9512 GNUNET_TIME_absolute_max (n->last_dv_learn_monotime, 9434 GNUNET_TIME_absolute_max(n->last_dv_learn_monotime,
9513 GNUNET_TIME_absolute_ntoh (*mtbe)); 9435 GNUNET_TIME_absolute_ntoh(*mtbe));
9514} 9436}
9515 9437
9516 9438
@@ -9521,8 +9443,8 @@ neighbour_dv_monotime_cb (void *cls,
9521 * @param aqm the send message that was sent 9443 * @param aqm the send message that was sent
9522 */ 9444 */
9523static void 9445static void
9524handle_add_queue_message (void *cls, 9446handle_add_queue_message(void *cls,
9525 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) 9447 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
9526{ 9448{
9527 struct TransportClient *tc = cls; 9449 struct TransportClient *tc = cls;
9528 struct Queue *queue; 9450 struct Queue *queue;
@@ -9530,77 +9452,77 @@ handle_add_queue_message (void *cls,
9530 const char *addr; 9452 const char *addr;
9531 uint16_t addr_len; 9453 uint16_t addr_len;
9532 9454
9533 if (ntohl (aqm->mtu) <= sizeof (struct TransportFragmentBoxMessage)) 9455 if (ntohl(aqm->mtu) <= sizeof(struct TransportFragmentBoxMessage))
9534 { 9456 {
9535 /* MTU so small as to be useless for transmissions, 9457 /* MTU so small as to be useless for transmissions,
9536 required for #fragment_message()! */ 9458 required for #fragment_message()! */
9537 GNUNET_break_op (0); 9459 GNUNET_break_op(0);
9538 GNUNET_SERVICE_client_drop (tc->client); 9460 GNUNET_SERVICE_client_drop(tc->client);
9539 return; 9461 return;
9540 } 9462 }
9541 neighbour = lookup_neighbour (&aqm->receiver); 9463 neighbour = lookup_neighbour(&aqm->receiver);
9542 if (NULL == neighbour) 9464 if (NULL == neighbour)
9543 { 9465 {
9544 neighbour = GNUNET_new (struct Neighbour); 9466 neighbour = GNUNET_new(struct Neighbour);
9545 neighbour->pid = aqm->receiver; 9467 neighbour->pid = aqm->receiver;
9546 GNUNET_assert (GNUNET_OK == 9468 GNUNET_assert(GNUNET_OK ==
9547 GNUNET_CONTAINER_multipeermap_put ( 9469 GNUNET_CONTAINER_multipeermap_put(
9548 neighbours, 9470 neighbours,
9549 &neighbour->pid, 9471 &neighbour->pid,
9550 neighbour, 9472 neighbour,
9551 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 9473 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
9552 neighbour->get = 9474 neighbour->get =
9553 GNUNET_PEERSTORE_iterate (peerstore, 9475 GNUNET_PEERSTORE_iterate(peerstore,
9554 "transport", 9476 "transport",
9555 &neighbour->pid, 9477 &neighbour->pid,
9556 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, 9478 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME,
9557 &neighbour_dv_monotime_cb, 9479 &neighbour_dv_monotime_cb,
9558 neighbour); 9480 neighbour);
9559 } 9481 }
9560 addr_len = ntohs (aqm->header.size) - sizeof (*aqm); 9482 addr_len = ntohs(aqm->header.size) - sizeof(*aqm);
9561 addr = (const char *) &aqm[1]; 9483 addr = (const char *)&aqm[1];
9562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9484 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9563 "New queue %s to %s available with QID %llu\n", 9485 "New queue %s to %s available with QID %llu\n",
9564 addr, 9486 addr,
9565 GNUNET_i2s (&aqm->receiver), 9487 GNUNET_i2s(&aqm->receiver),
9566 (unsigned long long) aqm->qid); 9488 (unsigned long long)aqm->qid);
9567 queue = GNUNET_malloc (sizeof (struct Queue) + addr_len); 9489 queue = GNUNET_malloc(sizeof(struct Queue) + addr_len);
9568 queue->tc = tc; 9490 queue->tc = tc;
9569 queue->address = (const char *) &queue[1]; 9491 queue->address = (const char *)&queue[1];
9570 queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL; 9492 queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL;
9571 queue->qid = aqm->qid; 9493 queue->qid = aqm->qid;
9572 queue->mtu = ntohl (aqm->mtu); 9494 queue->mtu = ntohl(aqm->mtu);
9573 queue->nt = (enum GNUNET_NetworkType) ntohl (aqm->nt); 9495 queue->nt = (enum GNUNET_NetworkType)ntohl(aqm->nt);
9574 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs); 9496 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl(aqm->cs);
9575 queue->neighbour = neighbour; 9497 queue->neighbour = neighbour;
9576 queue->idle = GNUNET_YES; 9498 queue->idle = GNUNET_YES;
9577 memcpy (&queue[1], addr, addr_len); 9499 memcpy(&queue[1], addr, addr_len);
9578 /* notify monitors about new queue */ 9500 /* notify monitors about new queue */
9579 { 9501 {
9580 struct MonitorEvent me = {.rtt = queue->pd.aged_rtt, .cs = queue->cs}; 9502 struct MonitorEvent me = { .rtt = queue->pd.aged_rtt, .cs = queue->cs };
9581 9503
9582 notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); 9504 notify_monitors(&neighbour->pid, queue->address, queue->nt, &me);
9583 } 9505 }
9584 GNUNET_CONTAINER_MDLL_insert (neighbour, 9506 GNUNET_CONTAINER_MDLL_insert(neighbour,
9585 neighbour->queue_head, 9507 neighbour->queue_head,
9586 neighbour->queue_tail, 9508 neighbour->queue_tail,
9587 queue); 9509 queue);
9588 GNUNET_CONTAINER_MDLL_insert (client, 9510 GNUNET_CONTAINER_MDLL_insert(client,
9589 tc->details.communicator.queue_head, 9511 tc->details.communicator.queue_head,
9590 tc->details.communicator.queue_tail, 9512 tc->details.communicator.queue_tail,
9591 queue); 9513 queue);
9592 /* check if valdiations are waiting for the queue */ 9514 /* check if valdiations are waiting for the queue */
9593 (void) 9515 (void)
9594 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, 9516 GNUNET_CONTAINER_multipeermap_get_multiple(validation_map,
9595 &aqm->receiver, 9517 &aqm->receiver,
9596 &check_validation_request_pending, 9518 &check_validation_request_pending,
9597 queue); 9519 queue);
9598 /* look for traffic for this queue */ 9520 /* look for traffic for this queue */
9599 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 9521 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9600 /* might be our first queue, try launching DV learning */ 9522 /* might be our first queue, try launching DV learning */
9601 if (NULL == dvlearn_task) 9523 if (NULL == dvlearn_task)
9602 dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, NULL); 9524 dvlearn_task = GNUNET_SCHEDULER_add_now(&start_dv_learn, NULL);
9603 GNUNET_SERVICE_client_continue (tc->client); 9525 GNUNET_SERVICE_client_continue(tc->client);
9604} 9526}
9605 9527
9606 9528
@@ -9612,25 +9534,25 @@ handle_add_queue_message (void *cls,
9612 * @param cqr confirmation message 9534 * @param cqr confirmation message
9613 */ 9535 */
9614static void 9536static void
9615handle_queue_create_ok (void *cls, 9537handle_queue_create_ok(void *cls,
9616 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) 9538 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr)
9617{ 9539{
9618 struct TransportClient *tc = cls; 9540 struct TransportClient *tc = cls;
9619 9541
9620 if (CT_COMMUNICATOR != tc->type) 9542 if (CT_COMMUNICATOR != tc->type)
9621 { 9543 {
9622 GNUNET_break (0); 9544 GNUNET_break(0);
9623 GNUNET_SERVICE_client_drop (tc->client); 9545 GNUNET_SERVICE_client_drop(tc->client);
9624 return; 9546 return;
9625 } 9547 }
9626 GNUNET_STATISTICS_update (GST_stats, 9548 GNUNET_STATISTICS_update(GST_stats,
9627 "# Suggestions succeeded at communicator", 9549 "# Suggestions succeeded at communicator",
9628 1, 9550 1,
9629 GNUNET_NO); 9551 GNUNET_NO);
9630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9552 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9631 "Request #%u for communicator to create queue succeeded\n", 9553 "Request #%u for communicator to create queue succeeded\n",
9632 (unsigned int) ntohs (cqr->request_id)); 9554 (unsigned int)ntohs(cqr->request_id));
9633 GNUNET_SERVICE_client_continue (tc->client); 9555 GNUNET_SERVICE_client_continue(tc->client);
9634} 9556}
9635 9557
9636 9558
@@ -9643,26 +9565,26 @@ handle_queue_create_ok (void *cls,
9643 * @param cqr failure message 9565 * @param cqr failure message
9644 */ 9566 */
9645static void 9567static void
9646handle_queue_create_fail ( 9568handle_queue_create_fail(
9647 void *cls, 9569 void *cls,
9648 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) 9570 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr)
9649{ 9571{
9650 struct TransportClient *tc = cls; 9572 struct TransportClient *tc = cls;
9651 9573
9652 if (CT_COMMUNICATOR != tc->type) 9574 if (CT_COMMUNICATOR != tc->type)
9653 { 9575 {
9654 GNUNET_break (0); 9576 GNUNET_break(0);
9655 GNUNET_SERVICE_client_drop (tc->client); 9577 GNUNET_SERVICE_client_drop(tc->client);
9656 return; 9578 return;
9657 } 9579 }
9658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9580 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9659 "Request #%u for communicator to create queue failed\n", 9581 "Request #%u for communicator to create queue failed\n",
9660 (unsigned int) ntohs (cqr->request_id)); 9582 (unsigned int)ntohs(cqr->request_id));
9661 GNUNET_STATISTICS_update (GST_stats, 9583 GNUNET_STATISTICS_update(GST_stats,
9662 "# Suggestions failed in queue creation at communicator", 9584 "# Suggestions failed in queue creation at communicator",
9663 1, 9585 1,
9664 GNUNET_NO); 9586 GNUNET_NO);
9665 GNUNET_SERVICE_client_continue (tc->client); 9587 GNUNET_SERVICE_client_continue(tc->client);
9666} 9588}
9667 9589
9668 9590
@@ -9674,27 +9596,27 @@ handle_queue_create_fail (
9674 * @param msg the start message 9596 * @param msg the start message
9675 */ 9597 */
9676static void 9598static void
9677handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg) 9599handle_suggest_cancel(void *cls, const struct ExpressPreferenceMessage *msg)
9678{ 9600{
9679 struct TransportClient *tc = cls; 9601 struct TransportClient *tc = cls;
9680 struct PeerRequest *pr; 9602 struct PeerRequest *pr;
9681 9603
9682 if (CT_APPLICATION != tc->type) 9604 if (CT_APPLICATION != tc->type)
9683 { 9605 {
9684 GNUNET_break (0); 9606 GNUNET_break(0);
9685 GNUNET_SERVICE_client_drop (tc->client); 9607 GNUNET_SERVICE_client_drop(tc->client);
9686 return; 9608 return;
9687 } 9609 }
9688 pr = GNUNET_CONTAINER_multipeermap_get (tc->details.application.requests, 9610 pr = GNUNET_CONTAINER_multipeermap_get(tc->details.application.requests,
9689 &msg->peer); 9611 &msg->peer);
9690 if (NULL == pr) 9612 if (NULL == pr)
9691 { 9613 {
9692 GNUNET_break (0); 9614 GNUNET_break(0);
9693 GNUNET_SERVICE_client_drop (tc->client); 9615 GNUNET_SERVICE_client_drop(tc->client);
9694 return; 9616 return;
9695 } 9617 }
9696 (void) stop_peer_request (tc, &pr->pid, pr); 9618 (void)stop_peer_request(tc, &pr->pid, pr);
9697 GNUNET_SERVICE_client_continue (tc->client); 9619 GNUNET_SERVICE_client_continue(tc->client);
9698} 9620}
9699 9621
9700 9622
@@ -9706,27 +9628,27 @@ handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg)
9706 * @param emsg error message, or NULL if no errors 9628 * @param emsg error message, or NULL if no errors
9707 */ 9629 */
9708static void 9630static void
9709handle_hello_for_client (void *cls, 9631handle_hello_for_client(void *cls,
9710 const struct GNUNET_PEERSTORE_Record *record, 9632 const struct GNUNET_PEERSTORE_Record *record,
9711 const char *emsg) 9633 const char *emsg)
9712{ 9634{
9713 struct PeerRequest *pr = cls; 9635 struct PeerRequest *pr = cls;
9714 const char *val; 9636 const char *val;
9715 9637
9716 if (NULL != emsg) 9638 if (NULL != emsg)
9717 { 9639 {
9718 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 9640 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
9719 "Got failure from PEERSTORE: %s\n", 9641 "Got failure from PEERSTORE: %s\n",
9720 emsg); 9642 emsg);
9721 return; 9643 return;
9722 } 9644 }
9723 val = record->value; 9645 val = record->value;
9724 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) 9646 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1]))
9725 { 9647 {
9726 GNUNET_break (0); 9648 GNUNET_break(0);
9727 return; 9649 return;
9728 } 9650 }
9729 start_address_validation (&pr->pid, (const char *) record->value); 9651 start_address_validation(&pr->pid, (const char *)record->value);
9730} 9652}
9731 9653
9732 9654
@@ -9738,51 +9660,51 @@ handle_hello_for_client (void *cls,
9738 * @param msg the start message 9660 * @param msg the start message
9739 */ 9661 */
9740static void 9662static void
9741handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg) 9663handle_suggest(void *cls, const struct ExpressPreferenceMessage *msg)
9742{ 9664{
9743 struct TransportClient *tc = cls; 9665 struct TransportClient *tc = cls;
9744 struct PeerRequest *pr; 9666 struct PeerRequest *pr;
9745 9667
9746 if (CT_NONE == tc->type) 9668 if (CT_NONE == tc->type)
9747 { 9669 {
9748 tc->type = CT_APPLICATION; 9670 tc->type = CT_APPLICATION;
9749 tc->details.application.requests = 9671 tc->details.application.requests =
9750 GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); 9672 GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES);
9751 } 9673 }
9752 if (CT_APPLICATION != tc->type) 9674 if (CT_APPLICATION != tc->type)
9753 { 9675 {
9754 GNUNET_break (0); 9676 GNUNET_break(0);
9755 GNUNET_SERVICE_client_drop (tc->client); 9677 GNUNET_SERVICE_client_drop(tc->client);
9756 return; 9678 return;
9757 } 9679 }
9758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9680 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9759 "Client suggested we talk to %s with preference %d at rate %u\n", 9681 "Client suggested we talk to %s with preference %d at rate %u\n",
9760 GNUNET_i2s (&msg->peer), 9682 GNUNET_i2s(&msg->peer),
9761 (int) ntohl (msg->pk), 9683 (int)ntohl(msg->pk),
9762 (int) ntohl (msg->bw.value__)); 9684 (int)ntohl(msg->bw.value__));
9763 pr = GNUNET_new (struct PeerRequest); 9685 pr = GNUNET_new(struct PeerRequest);
9764 pr->tc = tc; 9686 pr->tc = tc;
9765 pr->pid = msg->peer; 9687 pr->pid = msg->peer;
9766 pr->bw = msg->bw; 9688 pr->bw = msg->bw;
9767 pr->pk = (enum GNUNET_MQ_PriorityPreferences) ntohl (msg->pk); 9689 pr->pk = (enum GNUNET_MQ_PriorityPreferences)ntohl(msg->pk);
9768 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put ( 9690 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put(
9769 tc->details.application.requests, 9691 tc->details.application.requests,
9770 &pr->pid, 9692 &pr->pid,
9771 pr, 9693 pr,
9772 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 9694 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
9773 { 9695 {
9774 GNUNET_break (0); 9696 GNUNET_break(0);
9775 GNUNET_free (pr); 9697 GNUNET_free(pr);
9776 GNUNET_SERVICE_client_drop (tc->client); 9698 GNUNET_SERVICE_client_drop(tc->client);
9777 return; 9699 return;
9778 } 9700 }
9779 pr->wc = GNUNET_PEERSTORE_watch (peerstore, 9701 pr->wc = GNUNET_PEERSTORE_watch(peerstore,
9780 "transport", 9702 "transport",
9781 &pr->pid, 9703 &pr->pid,
9782 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, 9704 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
9783 &handle_hello_for_client, 9705 &handle_hello_for_client,
9784 pr); 9706 pr);
9785 GNUNET_SERVICE_client_continue (tc->client); 9707 GNUNET_SERVICE_client_continue(tc->client);
9786} 9708}
9787 9709
9788 9710
@@ -9795,11 +9717,11 @@ handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg)
9795 * @return #GNUNET_OK on success 9717 * @return #GNUNET_OK on success
9796 */ 9718 */
9797static int 9719static int
9798check_request_hello_validation (void *cls, 9720check_request_hello_validation(void *cls,
9799 const struct RequestHelloValidationMessage *m) 9721 const struct RequestHelloValidationMessage *m)
9800{ 9722{
9801 (void) cls; 9723 (void)cls;
9802 GNUNET_MQ_check_zero_termination (m); 9724 GNUNET_MQ_check_zero_termination(m);
9803 return GNUNET_OK; 9725 return GNUNET_OK;
9804} 9726}
9805 9727
@@ -9812,13 +9734,13 @@ check_request_hello_validation (void *cls,
9812 * @param m message to verify 9734 * @param m message to verify
9813 */ 9735 */
9814static void 9736static void
9815handle_request_hello_validation (void *cls, 9737handle_request_hello_validation(void *cls,
9816 const struct RequestHelloValidationMessage *m) 9738 const struct RequestHelloValidationMessage *m)
9817{ 9739{
9818 struct TransportClient *tc = cls; 9740 struct TransportClient *tc = cls;
9819 9741
9820 start_address_validation (&m->peer, (const char *) &m[1]); 9742 start_address_validation(&m->peer, (const char *)&m[1]);
9821 GNUNET_SERVICE_client_continue (tc->client); 9743 GNUNET_SERVICE_client_continue(tc->client);
9822} 9744}
9823 9745
9824 9746
@@ -9831,16 +9753,16 @@ handle_request_hello_validation (void *cls,
9831 * @return #GNUNET_OK (always) 9753 * @return #GNUNET_OK (always)
9832 */ 9754 */
9833static int 9755static int
9834free_neighbour_cb (void *cls, 9756free_neighbour_cb(void *cls,
9835 const struct GNUNET_PeerIdentity *pid, 9757 const struct GNUNET_PeerIdentity *pid,
9836 void *value) 9758 void *value)
9837{ 9759{
9838 struct Neighbour *neighbour = value; 9760 struct Neighbour *neighbour = value;
9839 9761
9840 (void) cls; 9762 (void)cls;
9841 (void) pid; 9763 (void)pid;
9842 GNUNET_break (0); // should this ever happen? 9764 GNUNET_break(0); // should this ever happen?
9843 free_neighbour (neighbour); 9765 free_neighbour(neighbour);
9844 9766
9845 return GNUNET_OK; 9767 return GNUNET_OK;
9846} 9768}
@@ -9855,15 +9777,15 @@ free_neighbour_cb (void *cls,
9855 * @return #GNUNET_OK (always) 9777 * @return #GNUNET_OK (always)
9856 */ 9778 */
9857static int 9779static int
9858free_dv_routes_cb (void *cls, 9780free_dv_routes_cb(void *cls,
9859 const struct GNUNET_PeerIdentity *pid, 9781 const struct GNUNET_PeerIdentity *pid,
9860 void *value) 9782 void *value)
9861{ 9783{
9862 struct DistanceVector *dv = value; 9784 struct DistanceVector *dv = value;
9863 9785
9864 (void) cls; 9786 (void)cls;
9865 (void) pid; 9787 (void)pid;
9866 free_dv_route (dv); 9788 free_dv_route(dv);
9867 9789
9868 return GNUNET_OK; 9790 return GNUNET_OK;
9869} 9791}
@@ -9878,15 +9800,15 @@ free_dv_routes_cb (void *cls,
9878 * @return #GNUNET_OK (always) 9800 * @return #GNUNET_OK (always)
9879 */ 9801 */
9880static int 9802static int
9881free_validation_state_cb (void *cls, 9803free_validation_state_cb(void *cls,
9882 const struct GNUNET_PeerIdentity *pid, 9804 const struct GNUNET_PeerIdentity *pid,
9883 void *value) 9805 void *value)
9884{ 9806{
9885 struct ValidationState *vs = value; 9807 struct ValidationState *vs = value;
9886 9808
9887 (void) cls; 9809 (void)cls;
9888 (void) pid; 9810 (void)pid;
9889 free_validation_state (vs); 9811 free_validation_state(vs);
9890 return GNUNET_OK; 9812 return GNUNET_OK;
9891} 9813}
9892 9814
@@ -9900,13 +9822,13 @@ free_validation_state_cb (void *cls,
9900 * @return #GNUNET_OK (always) 9822 * @return #GNUNET_OK (always)
9901 */ 9823 */
9902static int 9824static int
9903free_pending_ack_cb (void *cls, const struct GNUNET_Uuid *key, void *value) 9825free_pending_ack_cb(void *cls, const struct GNUNET_Uuid *key, void *value)
9904{ 9826{
9905 struct PendingAcknowledgement *pa = value; 9827 struct PendingAcknowledgement *pa = value;
9906 9828
9907 (void) cls; 9829 (void)cls;
9908 (void) key; 9830 (void)key;
9909 free_pending_acknowledgement (pa); 9831 free_pending_acknowledgement(pa);
9910 return GNUNET_OK; 9832 return GNUNET_OK;
9911} 9833}
9912 9834
@@ -9920,15 +9842,15 @@ free_pending_ack_cb (void *cls, const struct GNUNET_Uuid *key, void *value)
9920 * @return #GNUNET_OK (always) 9842 * @return #GNUNET_OK (always)
9921 */ 9843 */
9922static int 9844static int
9923free_ack_cummulator_cb (void *cls, 9845free_ack_cummulator_cb(void *cls,
9924 const struct GNUNET_PeerIdentity *pid, 9846 const struct GNUNET_PeerIdentity *pid,
9925 void *value) 9847 void *value)
9926{ 9848{
9927 struct AcknowledgementCummulator *ac = value; 9849 struct AcknowledgementCummulator *ac = value;
9928 9850
9929 (void) cls; 9851 (void)cls;
9930 (void) pid; 9852 (void)pid;
9931 GNUNET_free (ac); 9853 GNUNET_free(ac);
9932 return GNUNET_OK; 9854 return GNUNET_OK;
9933} 9855}
9934 9856
@@ -9940,67 +9862,68 @@ free_ack_cummulator_cb (void *cls,
9940 * @param cls closure, unused 9862 * @param cls closure, unused
9941 */ 9863 */
9942static void 9864static void
9943do_shutdown (void *cls) 9865do_shutdown(void *cls)
9944{ 9866{
9945 struct LearnLaunchEntry *lle; 9867 struct LearnLaunchEntry *lle;
9946 (void) cls;
9947 9868
9948 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &free_neighbour_cb, NULL); 9869 (void)cls;
9870
9871 GNUNET_CONTAINER_multipeermap_iterate(neighbours, &free_neighbour_cb, NULL);
9949 if (NULL != peerstore) 9872 if (NULL != peerstore)
9950 { 9873 {
9951 GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO); 9874 GNUNET_PEERSTORE_disconnect(peerstore, GNUNET_NO);
9952 peerstore = NULL; 9875 peerstore = NULL;
9953 } 9876 }
9954 if (NULL != GST_stats) 9877 if (NULL != GST_stats)
9955 { 9878 {
9956 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); 9879 GNUNET_STATISTICS_destroy(GST_stats, GNUNET_NO);
9957 GST_stats = NULL; 9880 GST_stats = NULL;
9958 } 9881 }
9959 if (NULL != GST_my_private_key) 9882 if (NULL != GST_my_private_key)
9960 { 9883 {
9961 GNUNET_free (GST_my_private_key); 9884 GNUNET_free(GST_my_private_key);
9962 GST_my_private_key = NULL; 9885 GST_my_private_key = NULL;
9963 } 9886 }
9964 GNUNET_CONTAINER_multipeermap_iterate (ack_cummulators, 9887 GNUNET_CONTAINER_multipeermap_iterate(ack_cummulators,
9965 &free_ack_cummulator_cb, 9888 &free_ack_cummulator_cb,
9966 NULL); 9889 NULL);
9967 GNUNET_CONTAINER_multipeermap_destroy (ack_cummulators); 9890 GNUNET_CONTAINER_multipeermap_destroy(ack_cummulators);
9968 ack_cummulators = NULL; 9891 ack_cummulators = NULL;
9969 GNUNET_CONTAINER_multiuuidmap_iterate (pending_acks, 9892 GNUNET_CONTAINER_multiuuidmap_iterate(pending_acks,
9970 &free_pending_ack_cb, 9893 &free_pending_ack_cb,
9971 NULL); 9894 NULL);
9972 GNUNET_CONTAINER_multiuuidmap_destroy (pending_acks); 9895 GNUNET_CONTAINER_multiuuidmap_destroy(pending_acks);
9973 pending_acks = NULL; 9896 pending_acks = NULL;
9974 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)); 9897 GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(neighbours));
9975 GNUNET_CONTAINER_multipeermap_destroy (neighbours); 9898 GNUNET_CONTAINER_multipeermap_destroy(neighbours);
9976 neighbours = NULL; 9899 neighbours = NULL;
9977 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (links)); 9900 GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(links));
9978 GNUNET_CONTAINER_multipeermap_destroy (links); 9901 GNUNET_CONTAINER_multipeermap_destroy(links);
9979 links = NULL; 9902 links = NULL;
9980 GNUNET_CONTAINER_multipeermap_iterate (backtalkers, 9903 GNUNET_CONTAINER_multipeermap_iterate(backtalkers,
9981 &free_backtalker_cb, 9904 &free_backtalker_cb,
9982 NULL); 9905 NULL);
9983 GNUNET_CONTAINER_multipeermap_destroy (backtalkers); 9906 GNUNET_CONTAINER_multipeermap_destroy(backtalkers);
9984 backtalkers = NULL; 9907 backtalkers = NULL;
9985 GNUNET_CONTAINER_multipeermap_iterate (validation_map, 9908 GNUNET_CONTAINER_multipeermap_iterate(validation_map,
9986 &free_validation_state_cb, 9909 &free_validation_state_cb,
9987 NULL); 9910 NULL);
9988 GNUNET_CONTAINER_multipeermap_destroy (validation_map); 9911 GNUNET_CONTAINER_multipeermap_destroy(validation_map);
9989 validation_map = NULL; 9912 validation_map = NULL;
9990 while (NULL != ir_head) 9913 while (NULL != ir_head)
9991 free_incoming_request (ir_head); 9914 free_incoming_request(ir_head);
9992 GNUNET_assert (0 == ir_total); 9915 GNUNET_assert(0 == ir_total);
9993 while (NULL != (lle = lle_head)) 9916 while (NULL != (lle = lle_head))
9994 { 9917 {
9995 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); 9918 GNUNET_CONTAINER_DLL_remove(lle_head, lle_tail, lle);
9996 GNUNET_free (lle); 9919 GNUNET_free(lle);
9997 } 9920 }
9998 GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map); 9921 GNUNET_CONTAINER_multishortmap_destroy(dvlearn_map);
9999 dvlearn_map = NULL; 9922 dvlearn_map = NULL;
10000 GNUNET_CONTAINER_heap_destroy (validation_heap); 9923 GNUNET_CONTAINER_heap_destroy(validation_heap);
10001 validation_heap = NULL; 9924 validation_heap = NULL;
10002 GNUNET_CONTAINER_multipeermap_iterate (dv_routes, &free_dv_routes_cb, NULL); 9925 GNUNET_CONTAINER_multipeermap_iterate(dv_routes, &free_dv_routes_cb, NULL);
10003 GNUNET_CONTAINER_multipeermap_destroy (dv_routes); 9926 GNUNET_CONTAINER_multipeermap_destroy(dv_routes);
10004 dv_routes = NULL; 9927 dv_routes = NULL;
10005} 9928}
10006 9929
@@ -10013,58 +9936,58 @@ do_shutdown (void *cls)
10013 * @param service the initialized service 9936 * @param service the initialized service
10014 */ 9937 */
10015static void 9938static void
10016run (void *cls, 9939run(void *cls,
10017 const struct GNUNET_CONFIGURATION_Handle *c, 9940 const struct GNUNET_CONFIGURATION_Handle *c,
10018 struct GNUNET_SERVICE_Handle *service) 9941 struct GNUNET_SERVICE_Handle *service)
10019{ 9942{
10020 (void) cls; 9943 (void)cls;
10021 (void) service; 9944 (void)service;
10022 /* setup globals */ 9945 /* setup globals */
10023 hello_mono_time = GNUNET_TIME_absolute_get_monotonic (c); 9946 hello_mono_time = GNUNET_TIME_absolute_get_monotonic(c);
10024 GST_cfg = c; 9947 GST_cfg = c;
10025 backtalkers = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); 9948 backtalkers = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES);
10026 pending_acks = GNUNET_CONTAINER_multiuuidmap_create (32768, GNUNET_YES); 9949 pending_acks = GNUNET_CONTAINER_multiuuidmap_create(32768, GNUNET_YES);
10027 ack_cummulators = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_YES); 9950 ack_cummulators = GNUNET_CONTAINER_multipeermap_create(256, GNUNET_YES);
10028 neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); 9951 neighbours = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES);
10029 links = GNUNET_CONTAINER_multipeermap_create (512, GNUNET_YES); 9952 links = GNUNET_CONTAINER_multipeermap_create(512, GNUNET_YES);
10030 dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); 9953 dv_routes = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES);
10031 dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING, 9954 dvlearn_map = GNUNET_CONTAINER_multishortmap_create(2 * MAX_DV_LEARN_PENDING,
10032 GNUNET_YES); 9955 GNUNET_YES);
10033 validation_map = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); 9956 validation_map = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES);
10034 validation_heap = 9957 validation_heap =
10035 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 9958 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
10036 GST_my_private_key = 9959 GST_my_private_key =
10037 GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); 9960 GNUNET_CRYPTO_eddsa_key_create_from_configuration(GST_cfg);
10038 if (NULL == GST_my_private_key) 9961 if (NULL == GST_my_private_key)
10039 { 9962 {
10040 GNUNET_log ( 9963 GNUNET_log(
10041 GNUNET_ERROR_TYPE_ERROR, 9964 GNUNET_ERROR_TYPE_ERROR,
10042 _ ( 9965 _(
10043 "Transport service is lacking key configuration settings. Exiting.\n")); 9966 "Transport service is lacking key configuration settings. Exiting.\n"));
10044 GNUNET_SCHEDULER_shutdown (); 9967 GNUNET_SCHEDULER_shutdown();
10045 return; 9968 return;
10046 } 9969 }
10047 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, 9970 GNUNET_CRYPTO_eddsa_key_get_public(GST_my_private_key,
10048 &GST_my_identity.public_key); 9971 &GST_my_identity.public_key);
10049 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 9972 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
10050 "My identity is `%s'\n", 9973 "My identity is `%s'\n",
10051 GNUNET_i2s_full (&GST_my_identity)); 9974 GNUNET_i2s_full(&GST_my_identity));
10052 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); 9975 GST_stats = GNUNET_STATISTICS_create("transport", GST_cfg);
10053 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 9976 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
10054 peerstore = GNUNET_PEERSTORE_connect (GST_cfg); 9977 peerstore = GNUNET_PEERSTORE_connect(GST_cfg);
10055 if (NULL == peerstore) 9978 if (NULL == peerstore)
10056 { 9979 {
10057 GNUNET_break (0); 9980 GNUNET_break(0);
10058 GNUNET_SCHEDULER_shutdown (); 9981 GNUNET_SCHEDULER_shutdown();
10059 return; 9982 return;
10060 } 9983 }
10061} 9984}
10062 9985
10063 9986
10064/** 9987/**
10065 * Define "main" method using service macro. 9988 * Define "main" method using service macro.
10066 */ 9989 */
10067GNUNET_SERVICE_MAIN ( 9990GNUNET_SERVICE_MAIN(
10068 "transport", 9991 "transport",
10069 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, 9992 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
10070 &run, 9993 &run,
@@ -10072,78 +9995,78 @@ GNUNET_SERVICE_MAIN (
10072 &client_disconnect_cb, 9995 &client_disconnect_cb,
10073 NULL, 9996 NULL,
10074 /* communication with applications */ 9997 /* communication with applications */
10075 GNUNET_MQ_hd_fixed_size (suggest, 9998 GNUNET_MQ_hd_fixed_size(suggest,
10076 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, 9999 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST,
10077 struct ExpressPreferenceMessage, 10000 struct ExpressPreferenceMessage,
10078 NULL), 10001 NULL),
10079 GNUNET_MQ_hd_fixed_size (suggest_cancel, 10002 GNUNET_MQ_hd_fixed_size(suggest_cancel,
10080 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, 10003 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL,
10081 struct ExpressPreferenceMessage, 10004 struct ExpressPreferenceMessage,
10082 NULL), 10005 NULL),
10083 GNUNET_MQ_hd_var_size (request_hello_validation, 10006 GNUNET_MQ_hd_var_size(request_hello_validation,
10084 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, 10007 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION,
10085 struct RequestHelloValidationMessage, 10008 struct RequestHelloValidationMessage,
10086 NULL), 10009 NULL),
10087 /* communication with core */ 10010 /* communication with core */
10088 GNUNET_MQ_hd_fixed_size (client_start, 10011 GNUNET_MQ_hd_fixed_size(client_start,
10089 GNUNET_MESSAGE_TYPE_TRANSPORT_START, 10012 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
10090 struct StartMessage, 10013 struct StartMessage,
10091 NULL), 10014 NULL),
10092 GNUNET_MQ_hd_var_size (client_send, 10015 GNUNET_MQ_hd_var_size(client_send,
10093 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 10016 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
10094 struct OutboundMessage, 10017 struct OutboundMessage,
10095 NULL), 10018 NULL),
10096 GNUNET_MQ_hd_fixed_size (client_recv_ok, 10019 GNUNET_MQ_hd_fixed_size(client_recv_ok,
10097 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK, 10020 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK,
10098 struct RecvOkMessage, 10021 struct RecvOkMessage,
10099 NULL), 10022 NULL),
10100 /* communication with communicators */ 10023 /* communication with communicators */
10101 GNUNET_MQ_hd_var_size (communicator_available, 10024 GNUNET_MQ_hd_var_size(communicator_available,
10102 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, 10025 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR,
10103 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, 10026 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
10104 NULL), 10027 NULL),
10105 GNUNET_MQ_hd_var_size (communicator_backchannel, 10028 GNUNET_MQ_hd_var_size(communicator_backchannel,
10106 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, 10029 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
10107 struct GNUNET_TRANSPORT_CommunicatorBackchannel, 10030 struct GNUNET_TRANSPORT_CommunicatorBackchannel,
10108 NULL), 10031 NULL),
10109 GNUNET_MQ_hd_var_size (add_address, 10032 GNUNET_MQ_hd_var_size(add_address,
10110 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, 10033 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
10111 struct GNUNET_TRANSPORT_AddAddressMessage, 10034 struct GNUNET_TRANSPORT_AddAddressMessage,
10112 NULL), 10035 NULL),
10113 GNUNET_MQ_hd_fixed_size (del_address, 10036 GNUNET_MQ_hd_fixed_size(del_address,
10114 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, 10037 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
10115 struct GNUNET_TRANSPORT_DelAddressMessage, 10038 struct GNUNET_TRANSPORT_DelAddressMessage,
10116 NULL), 10039 NULL),
10117 GNUNET_MQ_hd_var_size (incoming_msg, 10040 GNUNET_MQ_hd_var_size(incoming_msg,
10118 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, 10041 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
10119 struct GNUNET_TRANSPORT_IncomingMessage, 10042 struct GNUNET_TRANSPORT_IncomingMessage,
10120 NULL), 10043 NULL),
10121 GNUNET_MQ_hd_fixed_size (queue_create_ok, 10044 GNUNET_MQ_hd_fixed_size(queue_create_ok,
10122 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, 10045 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
10123 struct GNUNET_TRANSPORT_CreateQueueResponse, 10046 struct GNUNET_TRANSPORT_CreateQueueResponse,
10124 NULL), 10047 NULL),
10125 GNUNET_MQ_hd_fixed_size (queue_create_fail, 10048 GNUNET_MQ_hd_fixed_size(queue_create_fail,
10126 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, 10049 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
10127 struct GNUNET_TRANSPORT_CreateQueueResponse, 10050 struct GNUNET_TRANSPORT_CreateQueueResponse,
10128 NULL), 10051 NULL),
10129 GNUNET_MQ_hd_var_size (add_queue_message, 10052 GNUNET_MQ_hd_var_size(add_queue_message,
10130 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, 10053 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
10131 struct GNUNET_TRANSPORT_AddQueueMessage, 10054 struct GNUNET_TRANSPORT_AddQueueMessage,
10132 NULL), 10055 NULL),
10133 GNUNET_MQ_hd_fixed_size (del_queue_message, 10056 GNUNET_MQ_hd_fixed_size(del_queue_message,
10134 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, 10057 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
10135 struct GNUNET_TRANSPORT_DelQueueMessage, 10058 struct GNUNET_TRANSPORT_DelQueueMessage,
10136 NULL), 10059 NULL),
10137 GNUNET_MQ_hd_fixed_size (send_message_ack, 10060 GNUNET_MQ_hd_fixed_size(send_message_ack,
10138 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, 10061 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK,
10139 struct GNUNET_TRANSPORT_SendMessageToAck, 10062 struct GNUNET_TRANSPORT_SendMessageToAck,
10140 NULL), 10063 NULL),
10141 /* communication with monitors */ 10064 /* communication with monitors */
10142 GNUNET_MQ_hd_fixed_size (monitor_start, 10065 GNUNET_MQ_hd_fixed_size(monitor_start,
10143 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, 10066 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START,
10144 struct GNUNET_TRANSPORT_MonitorStart, 10067 struct GNUNET_TRANSPORT_MonitorStart,
10145 NULL), 10068 NULL),
10146 GNUNET_MQ_handler_end ()); 10069 GNUNET_MQ_handler_end());
10147 10070
10148 10071
10149/* end of file gnunet-service-transport.c */ 10072/* end of file gnunet-service-transport.c */