From d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb Mon Sep 17 00:00:00 2001 From: ng0 Date: Sun, 8 Sep 2019 12:33:09 +0000 Subject: uncrustify as demanded. --- src/transport/gnunet-service-tng.c | 7783 ++++++++++++++++++------------------ 1 file changed, 3853 insertions(+), 3930 deletions(-) (limited to 'src/transport/gnunet-service-tng.c') 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 @@ /* - This file is part of GNUnet. - Copyright (C) 2010-2016, 2018, 2019 GNUnet e.V. + This file is part of GNUnet. + Copyright (C) 2010-2016, 2018, 2019 GNUnet e.V. - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later */ @@ -176,14 +176,14 @@ * the value chosen here might be too aggressively low! */ #define DELAY_WARN_THRESHOLD \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) /** * If a DVBox could not be forwarded after this number of * seconds we drop it. */ #define DV_FORWARD_TIMEOUT \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) /** * We only consider queues as "quality" connections when @@ -191,53 +191,53 @@ * the latency of the queue is below this threshold. */ #define DV_QUALITY_RTT_THRESHOLD \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) /** * How long do we consider a DV path valid if we see no * further updates on it? Note: the value chosen here might be too low! */ #define DV_PATH_VALIDITY_TIMEOUT \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) /** * How long do we cache backchannel (struct Backtalker) information * after a backchannel goes inactive? */ #define BACKCHANNEL_INACTIVITY_TIMEOUT \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) /** * How long before paths expire would we like to (re)discover DV paths? Should * be below #DV_PATH_VALIDITY_TIMEOUT. */ #define DV_PATH_DISCOVERY_FREQUENCY \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 4) /** * How long are ephemeral keys valid? */ #define EPHEMERAL_VALIDITY \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) /** * How long do we keep partially reassembled messages around before giving up? */ #define REASSEMBLY_EXPIRATION \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 4) /** * What is the fastest rate at which we send challenges *if* we keep learning * an address (gossip, DHT, etc.)? */ #define FAST_VALIDATION_CHALLENGE_FREQ \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) /** * What is the slowest rate at which we send challenges? */ #define MAX_VALIDATION_CHALLENGE_FREQ \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 1) /** * How long until we forget about historic accumulators and thus @@ -245,7 +245,7 @@ * active connection experiences without an ACK. */ #define ACK_CUMMULATOR_TIMEOUT \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) /** * What is the non-randomized base frequency at which we @@ -263,13 +263,13 @@ * When do we forget an invalid address for sure? */ #define MAX_ADDRESS_VALID_UNTIL \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MONTHS, 1) /** * How long do we consider an address valid if we just checked? */ #define ADDRESS_VALIDATION_LIFETIME \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) /** * What is the maximum frequency at which we do address validation? @@ -308,8 +308,7 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Unique identifier we attach to a message. */ -struct MessageUUIDP -{ +struct MessageUUIDP { /** * Unique value, generated by incrementing the * `message_uuid_ctr` of `struct Neighbour`. @@ -321,8 +320,7 @@ struct MessageUUIDP /** * Unique identifier to map an acknowledgement to a transmission. */ -struct AcknowledgementUUIDP -{ +struct AcknowledgementUUIDP { /** * The UUID value. */ @@ -333,8 +331,7 @@ struct AcknowledgementUUIDP /** * Type of a nonce used for challenges. */ -struct ChallengeNonceP -{ +struct ChallengeNonceP { /** * The value of the nonce. Note that this is NOT a hash. */ @@ -345,8 +342,7 @@ struct ChallengeNonceP /** * Outer layer of an encapsulated backchannel message. */ -struct TransportBackchannelEncapsulationMessage -{ +struct TransportBackchannelEncapsulationMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION. */ @@ -362,9 +358,7 @@ struct TransportBackchannelEncapsulationMessage /** * Body by which a peer confirms that it is using an ephemeral key. */ -struct EphemeralConfirmationPS -{ - +struct EphemeralConfirmationPS { /** * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL */ @@ -403,9 +397,7 @@ struct EphemeralConfirmationPS * Plaintext of the variable-size payload that is encrypted * within a `struct TransportBackchannelEncapsulationMessage` */ -struct TransportDVBoxPayloadP -{ - +struct TransportDVBoxPayloadP { /** * Sender's peer identity. */ @@ -438,8 +430,7 @@ struct TransportDVBoxPayloadP * Outer layer of an encapsulated unfragmented application message sent * over an unreliable channel. */ -struct TransportReliabilityBoxMessage -{ +struct TransportReliabilityBoxMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX */ @@ -465,8 +456,7 @@ struct TransportReliabilityBoxMessage /** * Acknowledgement payload. */ -struct TransportCummulativeAckPayloadP -{ +struct TransportCummulativeAckPayloadP { /** * How long was the ACK delayed for generating cummulative ACKs? * Used to calculate the correct network RTT by taking the receipt @@ -489,8 +479,7 @@ struct TransportCummulativeAckPayloadP * so ACKs are identified by a combination of PID of sender and * message UUID, without the queue playing any role! */ -struct TransportReliabilityAckMessage -{ +struct TransportReliabilityAckMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK */ @@ -510,8 +499,7 @@ struct TransportReliabilityAckMessage /** * Outer layer of an encapsulated fragmented application message. */ -struct TransportFragmentBoxMessage -{ +struct TransportFragmentBoxMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT */ @@ -561,8 +549,7 @@ struct TransportFragmentBoxMessage * potential amplificator will check the @e monotonic_time and only respond * (at most) once per message. */ -struct DvInitPS -{ +struct DvInitPS { /** * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR */ @@ -605,8 +592,7 @@ struct DvInitPS * replay old messages. Thus, passively learned paths should always be * immediately marked as "potentially stale". */ -struct DvHopPS -{ +struct DvHopPS { /** * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP */ @@ -633,8 +619,7 @@ struct DvHopPS * An entry describing a peer on a path in a * `struct TransportDVLearnMessage` message. */ -struct DVPathEntryP -{ +struct DVPathEntryP { /** * Identity of a peer on the path. */ @@ -661,8 +646,7 @@ struct DVPathEntryP * zero, peers that can forward to the initator should always try to * forward to the initiator. */ -struct TransportDVLearnMessage -{ +struct TransportDVLearnMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN */ @@ -749,8 +733,7 @@ struct TransportDVLearnMessage * the predecessor must be the origin (so this is not really useful * for anonymization). */ -struct TransportDVBoxMessage -{ +struct TransportDVBoxMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX */ @@ -808,9 +791,7 @@ struct TransportDVBoxMessage * Message send to another peer to validate that it can indeed * receive messages at a particular address. */ -struct TransportValidationChallengeMessage -{ - +struct TransportValidationChallengeMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE */ @@ -838,9 +819,7 @@ struct TransportValidationChallengeMessage * Message signed by a peer to confirm that it can indeed * receive messages at a particular address. */ -struct TransportValidationPS -{ - +struct TransportValidationPS { /** * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE */ @@ -863,9 +842,7 @@ struct TransportValidationPS * Message send to a peer to respond to a * #GNUNET_MESSAGE_TYPE_ADDRESS_VALIDATION_CHALLENGE */ -struct TransportValidationResponseMessage -{ - +struct TransportValidationResponseMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE */ @@ -909,8 +886,7 @@ struct TransportValidationResponseMessage * send to us, and how much data we already received from the other * peer. */ -struct TransportFlowControlMessage -{ +struct TransportFlowControlMessage { /** * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL */ @@ -966,8 +942,7 @@ GNUNET_NETWORK_STRUCT_END /** * What type of client is the `struct TransportClient` about? */ -enum ClientType -{ +enum ClientType { /** * We do not know yet (client is fresh). */ @@ -999,8 +974,7 @@ enum ClientType * Which transmission options are allowable for transmission? * Interpreted bit-wise! */ -enum RouteMessageOptions -{ +enum RouteMessageOptions { /** * Only confirmed, non-DV direct neighbours. */ @@ -1033,9 +1007,7 @@ enum RouteMessageOptions /** * When did we launch this DV learning activity? */ -struct LearnLaunchEntry -{ - +struct LearnLaunchEntry { /** * Kept (also) in a DLL sorted by launch time. */ @@ -1063,8 +1035,7 @@ struct LearnLaunchEntry * Information we keep per #GOODPUT_AGING_SLOTS about historic * (or current) transmission performance. */ -struct TransmissionHistoryEntry -{ +struct TransmissionHistoryEntry { /** * Number of bytes actually sent in the interval. */ @@ -1081,8 +1052,7 @@ struct TransmissionHistoryEntry /** * Performance data for a transmission possibility. */ -struct PerformanceData -{ +struct PerformanceData { /** * Weighted average for the RTT. */ @@ -1149,9 +1119,7 @@ struct VirtualLink; * Context from #handle_incoming_msg(). Closure for many * message handlers below. */ -struct CommunicatorMessageContext -{ - +struct CommunicatorMessageContext { /** * Kept in a DLL of `struct VirtualLink` if waiting for CORE * flow control to unchoke. @@ -1185,9 +1153,7 @@ struct CommunicatorMessageContext /** * Closure for #core_env_sent_cb. */ -struct CoreSentContext -{ - +struct CoreSentContext { /** * Kept in a DLL to clear @e vl in case @e vl is lost. */ @@ -1226,8 +1192,7 @@ struct CoreSentContext * data that is per neighbour that is not specific to how the * connectivity is established. */ -struct VirtualLink -{ +struct VirtualLink { /** * Identity of the peer at the other end of the link. */ @@ -1425,9 +1390,7 @@ struct VirtualLink /** * Data structure kept when we are waiting for an acknowledgement. */ -struct PendingAcknowledgement -{ - +struct PendingAcknowledgement { /** * If @e pm is non-NULL, this is the DLL in which this acknowledgement * is kept in relation to its pending message. @@ -1520,9 +1483,7 @@ struct PendingAcknowledgement /** * One possible hop towards a DV target. */ -struct DistanceVectorHop -{ - +struct DistanceVectorHop { /** * Kept in a MDLL, sorted by @e timeout. */ @@ -1603,9 +1564,7 @@ struct DistanceVectorHop * Entry in our #dv_routes table, representing a (set of) distance * vector routes to a particular peer. */ -struct DistanceVector -{ - +struct DistanceVector { /** * To which peer is this a route? */ @@ -1669,9 +1628,7 @@ struct DistanceVector * what the communicator can actually provide towards a particular * peer/target). */ -struct QueueEntry -{ - +struct QueueEntry { /** * Kept as a DLL. */ @@ -1703,8 +1660,7 @@ struct QueueEntry * A queue is a message queue provided by a communicator * via which we can reach a particular neighbour. */ -struct Queue -{ +struct Queue { /** * Kept in a MDLL. */ @@ -1832,9 +1788,7 @@ struct Queue /** * Information we keep for a message that we are reassembling. */ -struct ReassemblyContext -{ - +struct ReassemblyContext { /** * Original message ID for of the message that all the fragments * belong to. @@ -1892,9 +1846,7 @@ struct ReassemblyContext /** * A neighbour that at least one communicator is connected to. */ -struct Neighbour -{ - +struct Neighbour { /** * Which peer is this about? */ @@ -1977,9 +1929,7 @@ struct Neighbour * Another peer attempted to talk to us, we should try to establish * a connection in the other direction. */ -struct IncomingRequest -{ - +struct IncomingRequest { /** * Kept in a DLL. */ @@ -2005,9 +1955,7 @@ struct IncomingRequest /** * A peer that an application (client) would like us to talk to directly. */ -struct PeerRequest -{ - +struct PeerRequest { /** * Which peer is this about? */ @@ -2040,9 +1988,7 @@ struct PeerRequest /** * Types of different pending messages. */ -enum PendingMessageType -{ - +enum PendingMessageType { /** * Ordinary message received from the CORE service. */ @@ -2062,7 +2008,6 @@ enum PendingMessageType * Pending message created during #forward_dv_box(). */ PMT_DV_BOX = 3 - }; @@ -2092,8 +2037,7 @@ enum PendingMessageType * is never again transmitted (even if it fits below the MTU), and * only (remaining) fragments are sent. */ -struct PendingMessage -{ +struct PendingMessage { /** * Kept in a MDLL of messages for this @a vl. */ @@ -2232,8 +2176,7 @@ struct PendingMessage /** * Acknowledgement payload. */ -struct TransportCummulativeAckPayload -{ +struct TransportCummulativeAckPayload { /** * When did we receive the message we are ACKing? Used to calculate * the delay we introduced by cummulating ACKs. @@ -2251,8 +2194,7 @@ struct TransportCummulativeAckPayload * Data structure in which we track acknowledgements still to * be sent to the */ -struct AcknowledgementCummulator -{ +struct AcknowledgementCummulator { /** * Target peer for which we are accumulating ACKs here. */ @@ -2292,9 +2234,7 @@ struct AcknowledgementCummulator /** * One of the addresses of this peer. */ -struct AddressListEntry -{ - +struct AddressListEntry { /** * Kept in a DLL. */ @@ -2346,9 +2286,7 @@ struct AddressListEntry /** * Client connected to the transport service. */ -struct TransportClient -{ - +struct TransportClient { /** * Kept in a DLL. */ @@ -2374,15 +2312,11 @@ struct TransportClient */ enum ClientType type; - union - { - + union { /** * Information for @e type #CT_CORE. */ - struct - { - + struct { /** * Head of list of messages pending for this client, sorted by * transmission time ("next_attempt" + possibly internal prioritization). @@ -2393,15 +2327,12 @@ struct TransportClient * Tail of list of messages pending for this client. */ struct PendingMessage *pending_msg_tail; - } core; /** * Information for @e type #CT_MONITOR. */ - struct - { - + struct { /** * Peer identity to monitor the addresses of. * Zero to monitor all neighbours. Valid if @@ -2413,15 +2344,13 @@ struct TransportClient * Is this a one-shot monitor? */ int one_shot; - } monitor; /** * Information for @e type #CT_COMMUNICATOR. */ - struct - { + struct { /** * If @e type is #CT_COMMUNICATOR, this communicator * supports communicating using these addresses. @@ -2461,23 +2390,18 @@ struct TransportClient * Characteristics of this communicator. */ enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; - } communicator; /** * Information for @e type #CT_APPLICATION */ - struct - { - + struct { /** * Map of requests for peers the given client application would like to * see connections for. Maps from PIDs to `struct PeerRequest`. */ struct GNUNET_CONTAINER_MultiPeerMap *requests; - } application; - } details; }; @@ -2486,9 +2410,7 @@ struct TransportClient * State we keep for validation activities. Each of these * is both in the #validation_heap and the #validation_map. */ -struct ValidationState -{ - +struct ValidationState { /** * For which peer is @a address to be validated (or possibly valid)? * Serves as key in the #validation_map. @@ -2598,8 +2520,7 @@ struct ValidationState * material (to avoid repeatedly checking signatures), and to synchronize * monotonic time with the PEERSTORE. */ -struct Backtalker -{ +struct Backtalker { /** * Peer this is about. */ @@ -2822,11 +2743,11 @@ static struct GNUNET_TIME_Absolute hello_mono_time; * @return current age of the world */ static unsigned int -get_age () +get_age() { struct GNUNET_TIME_Absolute now; - now = GNUNET_TIME_absolute_get (); + now = GNUNET_TIME_absolute_get(); return now.abs_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us / 15; } @@ -2837,13 +2758,13 @@ get_age () * @param ir data structure to release */ static void -free_incoming_request (struct IncomingRequest *ir) +free_incoming_request(struct IncomingRequest *ir) { - GNUNET_CONTAINER_DLL_remove (ir_head, ir_tail, ir); - GNUNET_assert (ir_total > 0); + GNUNET_CONTAINER_DLL_remove(ir_head, ir_tail, ir); + GNUNET_assert(ir_total > 0); ir_total--; - GNUNET_PEERSTORE_watch_cancel (ir->wc); - GNUNET_free (ir); + GNUNET_PEERSTORE_watch_cancel(ir->wc); + GNUNET_free(ir); } @@ -2853,34 +2774,34 @@ free_incoming_request (struct IncomingRequest *ir) * @param pa data structure to release */ static void -free_pending_acknowledgement (struct PendingAcknowledgement *pa) +free_pending_acknowledgement(struct PendingAcknowledgement *pa) { struct Queue *q = pa->queue; struct PendingMessage *pm = pa->pm; struct DistanceVectorHop *dvh = pa->dvh; - GNUNET_CONTAINER_MDLL_remove (pa, pa_head, pa_tail, pa); + GNUNET_CONTAINER_MDLL_remove(pa, pa_head, pa_tail, pa); pa_count--; if (NULL != q) - { - GNUNET_CONTAINER_MDLL_remove (queue, q->pa_head, q->pa_tail, pa); - pa->queue = NULL; - } + { + GNUNET_CONTAINER_MDLL_remove(queue, q->pa_head, q->pa_tail, pa); + pa->queue = NULL; + } if (NULL != pm) - { - GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa); - pa->pm = NULL; - } + { + GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa); + pa->pm = NULL; + } if (NULL != dvh) - { - GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa); - pa->queue = NULL; - } - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multiuuidmap_remove (pending_acks, - &pa->ack_uuid.value, - pa)); - GNUNET_free (pa); + { + GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa); + pa->queue = NULL; + } + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multiuuidmap_remove(pending_acks, + &pa->ack_uuid.value, + pa)); + GNUNET_free(pa); } @@ -2893,23 +2814,23 @@ free_pending_acknowledgement (struct PendingAcknowledgement *pa) * @param root root of the tree to free */ static void -free_fragment_tree (struct PendingMessage *root) +free_fragment_tree(struct PendingMessage *root) { struct PendingMessage *frag; while (NULL != (frag = root->head_frag)) - { - struct PendingAcknowledgement *pa; - - free_fragment_tree (frag); - while (NULL != (pa = frag->pa_head)) { - GNUNET_CONTAINER_MDLL_remove (pm, frag->pa_head, frag->pa_tail, pa); - pa->pm = NULL; + struct PendingAcknowledgement *pa; + + free_fragment_tree(frag); + while (NULL != (pa = frag->pa_head)) + { + GNUNET_CONTAINER_MDLL_remove(pm, frag->pa_head, frag->pa_tail, pa); + pa->pm = NULL; + } + GNUNET_CONTAINER_MDLL_remove(frag, root->head_frag, root->tail_frag, frag); + GNUNET_free(frag); } - GNUNET_CONTAINER_MDLL_remove (frag, root->head_frag, root->tail_frag, frag); - GNUNET_free (frag); - } } @@ -2921,44 +2842,44 @@ free_fragment_tree (struct PendingMessage *root) * @param pm the pending message to free */ static void -free_pending_message (struct PendingMessage *pm) +free_pending_message(struct PendingMessage *pm) { struct TransportClient *tc = pm->client; struct VirtualLink *vl = pm->vl; struct PendingAcknowledgement *pa; if (NULL != tc) - { - GNUNET_CONTAINER_MDLL_remove (client, - tc->details.core.pending_msg_head, - tc->details.core.pending_msg_tail, - pm); - } + { + GNUNET_CONTAINER_MDLL_remove(client, + tc->details.core.pending_msg_head, + tc->details.core.pending_msg_tail, + pm); + } if (NULL != vl) - { - GNUNET_CONTAINER_MDLL_remove (vl, - vl->pending_msg_head, - vl->pending_msg_tail, - pm); - } + { + GNUNET_CONTAINER_MDLL_remove(vl, + vl->pending_msg_head, + vl->pending_msg_tail, + pm); + } while (NULL != (pa = pm->pa_head)) - { - GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa); - pa->pm = NULL; - } + { + GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa); + pa->pm = NULL; + } - free_fragment_tree (pm); + free_fragment_tree(pm); if (NULL != pm->qe) - { - GNUNET_assert (pm == pm->qe->pm); - pm->qe->pm = NULL; - } + { + GNUNET_assert(pm == pm->qe->pm); + pm->qe->pm = NULL; + } if (NULL != pm->bpm) - { - free_fragment_tree (pm->bpm); - GNUNET_free (pm->bpm); - } - GNUNET_free (pm); + { + free_fragment_tree(pm->bpm); + GNUNET_free(pm->bpm); + } + GNUNET_free(pm); } @@ -2968,34 +2889,34 @@ free_pending_message (struct PendingMessage *pm) * @param vl link data to free */ static void -free_virtual_link (struct VirtualLink *vl) +free_virtual_link(struct VirtualLink *vl) { struct PendingMessage *pm; struct CoreSentContext *csc; while (NULL != (pm = vl->pending_msg_head)) - free_pending_message (pm); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (links, &vl->target, vl)); + free_pending_message(pm); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove(links, &vl->target, vl)); if (NULL != vl->visibility_task) - { - GNUNET_SCHEDULER_cancel (vl->visibility_task); - vl->visibility_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(vl->visibility_task); + vl->visibility_task = NULL; + } if (NULL != vl->fc_retransmit_task) - { - GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); - vl->fc_retransmit_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task); + vl->fc_retransmit_task = NULL; + } while (NULL != (csc = vl->csc_head)) - { - GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, csc); - GNUNET_assert (vl == csc->vl); - csc->vl = NULL; - } - GNUNET_break (NULL == vl->n); - GNUNET_break (NULL == vl->dv); - GNUNET_free (vl); + { + GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, csc); + GNUNET_assert(vl == csc->vl); + csc->vl = NULL; + } + GNUNET_break(NULL == vl->n); + GNUNET_break(NULL == vl->dv); + GNUNET_free(vl); } @@ -3005,20 +2926,20 @@ free_virtual_link (struct VirtualLink *vl) * @param vs validation state to free */ static void -free_validation_state (struct ValidationState *vs) +free_validation_state(struct ValidationState *vs) { - GNUNET_assert ( + GNUNET_assert( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs)); - GNUNET_CONTAINER_heap_remove_node (vs->hn); + GNUNET_CONTAINER_multipeermap_remove(validation_map, &vs->pid, vs)); + GNUNET_CONTAINER_heap_remove_node(vs->hn); vs->hn = NULL; if (NULL != vs->sc) - { - GNUNET_PEERSTORE_store_cancel (vs->sc); - vs->sc = NULL; - } - GNUNET_free (vs->address); - GNUNET_free (vs); + { + GNUNET_PEERSTORE_store_cancel(vs->sc); + vs->sc = NULL; + } + GNUNET_free(vs->address); + GNUNET_free(vs); } @@ -3029,9 +2950,9 @@ free_validation_state (struct ValidationState *vs) * @return NULL if we do not have this peer as a neighbour */ static struct Neighbour * -lookup_neighbour (const struct GNUNET_PeerIdentity *pid) +lookup_neighbour(const struct GNUNET_PeerIdentity *pid) { - return GNUNET_CONTAINER_multipeermap_get (neighbours, pid); + return GNUNET_CONTAINER_multipeermap_get(neighbours, pid); } @@ -3042,17 +2963,16 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid) * @return NULL if we do not have this peer as a virtual link */ static struct VirtualLink * -lookup_virtual_link (const struct GNUNET_PeerIdentity *pid) +lookup_virtual_link(const struct GNUNET_PeerIdentity *pid) { - return GNUNET_CONTAINER_multipeermap_get (links, pid); + return GNUNET_CONTAINER_multipeermap_get(links, pid); } /** * Details about what to notify monitors about. */ -struct MonitorEvent -{ +struct MonitorEvent { /** * @deprecated To be discussed if we keep these... */ @@ -3091,20 +3011,20 @@ struct MonitorEvent * @param dvh hop to free */ static void -free_distance_vector_hop (struct DistanceVectorHop *dvh) +free_distance_vector_hop(struct DistanceVectorHop *dvh) { struct Neighbour *n = dvh->next_hop; struct DistanceVector *dv = dvh->dv; struct PendingAcknowledgement *pa; while (NULL != (pa = dvh->pa_head)) - { - GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa); - pa->dvh = NULL; - } - GNUNET_CONTAINER_MDLL_remove (neighbour, n->dv_head, n->dv_tail, dvh); - GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, dvh); - GNUNET_free (dvh); + { + GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa); + pa->dvh = NULL; + } + GNUNET_CONTAINER_MDLL_remove(neighbour, n->dv_head, n->dv_tail, dvh); + GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, dvh); + GNUNET_free(dvh); } @@ -3115,7 +3035,7 @@ free_distance_vector_hop (struct DistanceVectorHop *dvh) * @param cls a `struct VirtualLink` */ static void -check_link_down (void *cls); +check_link_down(void *cls); /** @@ -3124,22 +3044,22 @@ check_link_down (void *cls); * @param pid peer the connection was for */ static void -cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid) +cores_send_disconnect_info(const struct GNUNET_PeerIdentity *pid) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Informing CORE clients about disconnect from %s\n", - GNUNET_i2s (pid)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Informing CORE clients about disconnect from %s\n", + GNUNET_i2s(pid)); for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - struct GNUNET_MQ_Envelope *env; - struct DisconnectInfoMessage *dim; - - if (CT_CORE != tc->type) - continue; - env = GNUNET_MQ_msg (dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); - dim->peer = *pid; - GNUNET_MQ_send (tc->mq, env); - } + { + struct GNUNET_MQ_Envelope *env; + struct DisconnectInfoMessage *dim; + + if (CT_CORE != tc->type) + continue; + env = GNUNET_MQ_msg(dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); + dim->peer = *pid; + GNUNET_MQ_send(tc->mq, env); + } } @@ -3150,43 +3070,43 @@ cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid) * @param dv route to free */ static void -free_dv_route (struct DistanceVector *dv) +free_dv_route(struct DistanceVector *dv) { struct DistanceVectorHop *dvh; while (NULL != (dvh = dv->dv_head)) - free_distance_vector_hop (dvh); + free_distance_vector_hop(dvh); if (NULL == dv->dv_head) - { - struct VirtualLink *vl; - - GNUNET_assert ( - GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv)); - if (NULL != (vl = dv->vl)) { - GNUNET_assert (dv == vl->dv); - vl->dv = NULL; - if (NULL == vl->n) - { - cores_send_disconnect_info (&dv->target); - free_virtual_link (vl); - } - else - { - GNUNET_SCHEDULER_cancel (vl->visibility_task); - vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl); - } - dv->vl = NULL; - } + struct VirtualLink *vl; - if (NULL != dv->timeout_task) - { - GNUNET_SCHEDULER_cancel (dv->timeout_task); - dv->timeout_task = NULL; + GNUNET_assert( + GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove(dv_routes, &dv->target, dv)); + if (NULL != (vl = dv->vl)) + { + GNUNET_assert(dv == vl->dv); + vl->dv = NULL; + if (NULL == vl->n) + { + cores_send_disconnect_info(&dv->target); + free_virtual_link(vl); + } + else + { + GNUNET_SCHEDULER_cancel(vl->visibility_task); + vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl); + } + dv->vl = NULL; + } + + if (NULL != dv->timeout_task) + { + GNUNET_SCHEDULER_cancel(dv->timeout_task); + dv->timeout_task = NULL; + } + GNUNET_free(dv); } - GNUNET_free (dv); - } } @@ -3204,30 +3124,30 @@ free_dv_route (struct DistanceVector *dv) * @param me detailed information to transmit */ static void -notify_monitor (struct TransportClient *tc, - const struct GNUNET_PeerIdentity *peer, - const char *address, - enum GNUNET_NetworkType nt, - const struct MonitorEvent *me) +notify_monitor(struct TransportClient *tc, + const struct GNUNET_PeerIdentity *peer, + const char *address, + enum GNUNET_NetworkType nt, + const struct MonitorEvent *me) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_MonitorData *md; - size_t addr_len = strlen (address) + 1; + size_t addr_len = strlen(address) + 1; - env = GNUNET_MQ_msg_extra (md, - addr_len, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA); - md->nt = htonl ((uint32_t) nt); + env = GNUNET_MQ_msg_extra(md, + addr_len, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA); + md->nt = htonl((uint32_t)nt); md->peer = *peer; - md->last_validation = GNUNET_TIME_absolute_hton (me->last_validation); - md->valid_until = GNUNET_TIME_absolute_hton (me->valid_until); - md->next_validation = GNUNET_TIME_absolute_hton (me->next_validation); - md->rtt = GNUNET_TIME_relative_hton (me->rtt); - md->cs = htonl ((uint32_t) me->cs); - md->num_msg_pending = htonl (me->num_msg_pending); - md->num_bytes_pending = htonl (me->num_bytes_pending); - memcpy (&md[1], address, addr_len); - GNUNET_MQ_send (tc->mq, env); + md->last_validation = GNUNET_TIME_absolute_hton(me->last_validation); + md->valid_until = GNUNET_TIME_absolute_hton(me->valid_until); + md->next_validation = GNUNET_TIME_absolute_hton(me->next_validation); + md->rtt = GNUNET_TIME_relative_hton(me->rtt); + md->cs = htonl((uint32_t)me->cs); + md->num_msg_pending = htonl(me->num_msg_pending); + md->num_bytes_pending = htonl(me->num_bytes_pending); + memcpy(&md[1], address, addr_len); + GNUNET_MQ_send(tc->mq, env); } @@ -3241,22 +3161,22 @@ notify_monitor (struct TransportClient *tc, * @param me detailed information to transmit */ static void -notify_monitors (const struct GNUNET_PeerIdentity *peer, - const char *address, - enum GNUNET_NetworkType nt, - const struct MonitorEvent *me) +notify_monitors(const struct GNUNET_PeerIdentity *peer, + const char *address, + enum GNUNET_NetworkType nt, + const struct MonitorEvent *me) { for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - if (CT_MONITOR != tc->type) - continue; - if (tc->details.monitor.one_shot) - continue; - if ((0 != GNUNET_is_zero (&tc->details.monitor.peer)) && - (0 != GNUNET_memcmp (&tc->details.monitor.peer, peer))) - continue; - notify_monitor (tc, peer, address, nt, me); - } + { + if (CT_MONITOR != tc->type) + continue; + if (tc->details.monitor.one_shot) + continue; + if ((0 != GNUNET_is_zero(&tc->details.monitor.peer)) && + (0 != GNUNET_memcmp(&tc->details.monitor.peer, peer))) + continue; + notify_monitor(tc, peer, address, nt, me); + } } @@ -3270,18 +3190,18 @@ notify_monitors (const struct GNUNET_PeerIdentity *peer, * @return our `struct TransportClient` */ static void * -client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +client_connect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct TransportClient *tc; - (void) cls; - tc = GNUNET_new (struct TransportClient); + (void)cls; + tc = GNUNET_new(struct TransportClient); tc->client = client; tc->mq = mq; - GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); + GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); return tc; } @@ -3292,16 +3212,16 @@ client_connect_cb (void *cls, * @param rc data structure to free */ static void -free_reassembly_context (struct ReassemblyContext *rc) +free_reassembly_context(struct ReassemblyContext *rc) { struct Neighbour *n = rc->neighbour; - GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn)); - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_remove (n->reassembly_map, - rc->msg_uuid.uuid, - rc)); - GNUNET_free (rc); + GNUNET_assert(rc == GNUNET_CONTAINER_heap_remove_node(rc->hn)); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap32_remove(n->reassembly_map, + rc->msg_uuid.uuid, + rc)); + GNUNET_free(rc); } @@ -3311,27 +3231,27 @@ free_reassembly_context (struct ReassemblyContext *rc) * @param cls a `struct Neighbour` */ static void -reassembly_cleanup_task (void *cls) +reassembly_cleanup_task(void *cls) { struct Neighbour *n = cls; struct ReassemblyContext *rc; n->reassembly_timeout_task = NULL; - while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap))) - { - if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout) - .rel_value_us) + while (NULL != (rc = GNUNET_CONTAINER_heap_peek(n->reassembly_heap))) { - free_reassembly_context (rc); - continue; + if (0 == GNUNET_TIME_absolute_get_remaining(rc->reassembly_timeout) + .rel_value_us) + { + free_reassembly_context(rc); + continue; + } + GNUNET_assert(NULL == n->reassembly_timeout_task); + n->reassembly_timeout_task = + GNUNET_SCHEDULER_add_at(rc->reassembly_timeout, + &reassembly_cleanup_task, + n); + return; } - GNUNET_assert (NULL == n->reassembly_timeout_task); - n->reassembly_timeout_task = - GNUNET_SCHEDULER_add_at (rc->reassembly_timeout, - &reassembly_cleanup_task, - n); - return; - } } @@ -3344,13 +3264,13 @@ reassembly_cleanup_task (void *cls) * @return #GNUNET_OK (continue iteration) */ static int -free_reassembly_cb (void *cls, uint32_t key, void *value) +free_reassembly_cb(void *cls, uint32_t key, void *value) { struct ReassemblyContext *rc = value; - (void) cls; - (void) key; - free_reassembly_context (rc); + (void)cls; + (void)key; + free_reassembly_context(rc); return GNUNET_OK; } @@ -3361,66 +3281,66 @@ free_reassembly_cb (void *cls, uint32_t key, void *value) * @param neighbour neighbour entry to free */ static void -free_neighbour (struct Neighbour *neighbour) +free_neighbour(struct Neighbour *neighbour) { struct DistanceVectorHop *dvh; struct VirtualLink *vl; - GNUNET_assert (NULL == neighbour->queue_head); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (neighbours, - &neighbour->pid, - neighbour)); + GNUNET_assert(NULL == neighbour->queue_head); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove(neighbours, + &neighbour->pid, + neighbour)); if (NULL != neighbour->reassembly_map) - { - GNUNET_CONTAINER_multihashmap32_iterate (neighbour->reassembly_map, - &free_reassembly_cb, - NULL); - GNUNET_CONTAINER_multihashmap32_destroy (neighbour->reassembly_map); - neighbour->reassembly_map = NULL; - GNUNET_CONTAINER_heap_destroy (neighbour->reassembly_heap); - neighbour->reassembly_heap = NULL; - } + { + GNUNET_CONTAINER_multihashmap32_iterate(neighbour->reassembly_map, + &free_reassembly_cb, + NULL); + GNUNET_CONTAINER_multihashmap32_destroy(neighbour->reassembly_map); + neighbour->reassembly_map = NULL; + GNUNET_CONTAINER_heap_destroy(neighbour->reassembly_heap); + neighbour->reassembly_heap = NULL; + } while (NULL != (dvh = neighbour->dv_head)) - { - struct DistanceVector *dv = dvh->dv; + { + struct DistanceVector *dv = dvh->dv; - free_distance_vector_hop (dvh); - if (NULL == dv->dv_head) - free_dv_route (dv); - } + free_distance_vector_hop(dvh); + if (NULL == dv->dv_head) + free_dv_route(dv); + } if (NULL != neighbour->reassembly_timeout_task) - { - GNUNET_SCHEDULER_cancel (neighbour->reassembly_timeout_task); - neighbour->reassembly_timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(neighbour->reassembly_timeout_task); + neighbour->reassembly_timeout_task = NULL; + } if (NULL != neighbour->get) - { - GNUNET_PEERSTORE_iterate_cancel (neighbour->get); - neighbour->get = NULL; - } + { + GNUNET_PEERSTORE_iterate_cancel(neighbour->get); + neighbour->get = NULL; + } if (NULL != neighbour->sc) - { - GNUNET_PEERSTORE_store_cancel (neighbour->sc); - neighbour->sc = NULL; - } - if (NULL != (vl = neighbour->vl)) - { - GNUNET_assert (neighbour == vl->n); - vl->n = NULL; - if (NULL == vl->dv) { - cores_send_disconnect_info (&vl->target); - free_virtual_link (vl); + GNUNET_PEERSTORE_store_cancel(neighbour->sc); + neighbour->sc = NULL; } - else + if (NULL != (vl = neighbour->vl)) { - GNUNET_SCHEDULER_cancel (vl->visibility_task); - vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl); + GNUNET_assert(neighbour == vl->n); + vl->n = NULL; + if (NULL == vl->dv) + { + cores_send_disconnect_info(&vl->target); + free_virtual_link(vl); + } + else + { + GNUNET_SCHEDULER_cancel(vl->visibility_task); + vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl); + } + neighbour->vl = NULL; } - neighbour->vl = NULL; - } - GNUNET_free (neighbour); + GNUNET_free(neighbour); } @@ -3431,16 +3351,16 @@ free_neighbour (struct Neighbour *neighbour) * @param pid peer the connection is for */ static void -core_send_connect_info (struct TransportClient *tc, - const struct GNUNET_PeerIdentity *pid) +core_send_connect_info(struct TransportClient *tc, + const struct GNUNET_PeerIdentity *pid) { struct GNUNET_MQ_Envelope *env; struct ConnectInfoMessage *cim; - GNUNET_assert (CT_CORE == tc->type); - env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); + GNUNET_assert(CT_CORE == tc->type); + env = GNUNET_MQ_msg(cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); cim->id = *pid; - GNUNET_MQ_send (tc->mq, env); + GNUNET_MQ_send(tc->mq, env); } @@ -3450,17 +3370,17 @@ core_send_connect_info (struct TransportClient *tc, * @param pid peer the queue was for */ static void -cores_send_connect_info (const struct GNUNET_PeerIdentity *pid) +cores_send_connect_info(const struct GNUNET_PeerIdentity *pid) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Informing CORE clients about connection to %s\n", - GNUNET_i2s (pid)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Informing CORE clients about connection to %s\n", + GNUNET_i2s(pid)); for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - if (CT_CORE != tc->type) - continue; - core_send_connect_info (tc, pid); - } + { + if (CT_CORE != tc->type) + continue; + core_send_connect_info(tc, pid); + } } @@ -3472,7 +3392,7 @@ cores_send_connect_info (const struct GNUNET_PeerIdentity *pid) * @param cls the `struct Queue` to process transmissions for */ static void -transmit_on_queue (void *cls); +transmit_on_queue(void *cls); /** @@ -3483,38 +3403,38 @@ transmit_on_queue (void *cls); * @param p task priority to use, if @a queue is scheduled */ static void -schedule_transmit_on_queue (struct Queue *queue, - enum GNUNET_SCHEDULER_Priority p) +schedule_transmit_on_queue(struct Queue *queue, + enum GNUNET_SCHEDULER_Priority p) { if (queue->tc->details.communicator.total_queue_length >= COMMUNICATOR_TOTAL_QUEUE_LIMIT) - { - GNUNET_STATISTICS_update ( - GST_stats, - "# Transmission throttled due to communicator queue limit", - 1, - GNUNET_NO); - queue->idle = GNUNET_NO; - return; - } + { + GNUNET_STATISTICS_update( + GST_stats, + "# Transmission throttled due to communicator queue limit", + 1, + GNUNET_NO); + queue->idle = GNUNET_NO; + return; + } if (queue->queue_length >= QUEUE_LENGTH_LIMIT) - { - GNUNET_STATISTICS_update (GST_stats, - "# Transmission throttled due to queue queue limit", - 1, - GNUNET_NO); - queue->idle = GNUNET_NO; - return; - } + { + GNUNET_STATISTICS_update(GST_stats, + "# Transmission throttled due to queue queue limit", + 1, + GNUNET_NO); + queue->idle = GNUNET_NO; + return; + } /* queue might indeed be ready, schedule it */ if (NULL != queue->transmit_task) - GNUNET_SCHEDULER_cancel (queue->transmit_task); + GNUNET_SCHEDULER_cancel(queue->transmit_task); queue->transmit_task = - GNUNET_SCHEDULER_add_with_priority (p, &transmit_on_queue, queue); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Considering transmission on queue `%s' to %s\n", - queue->address, - GNUNET_i2s (&queue->neighbour->pid)); + GNUNET_SCHEDULER_add_with_priority(p, &transmit_on_queue, queue); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Considering transmission on queue `%s' to %s\n", + queue->address, + GNUNET_i2s(&queue->neighbour->pid)); } @@ -3525,7 +3445,7 @@ schedule_transmit_on_queue (struct Queue *queue, * @param cls a `struct VirtualLink` */ static void -check_link_down (void *cls) +check_link_down(void *cls) { struct VirtualLink *vl = cls; struct DistanceVector *dv = vl->dv; @@ -3537,30 +3457,30 @@ check_link_down (void *cls) dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS; for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; pos = pos->next_dv) - dvh_timeout = GNUNET_TIME_absolute_max (dvh_timeout, pos->path_valid_until); - if (0 == GNUNET_TIME_absolute_get_remaining (dvh_timeout).rel_value_us) - { - vl->dv->vl = NULL; - vl->dv = NULL; - } + dvh_timeout = GNUNET_TIME_absolute_max(dvh_timeout, pos->path_valid_until); + if (0 == GNUNET_TIME_absolute_get_remaining(dvh_timeout).rel_value_us) + { + vl->dv->vl = NULL; + vl->dv = NULL; + } q_timeout = GNUNET_TIME_UNIT_ZERO_ABS; for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) - q_timeout = GNUNET_TIME_absolute_max (q_timeout, q->validated_until); - if (0 == GNUNET_TIME_absolute_get_remaining (q_timeout).rel_value_us) - { - vl->n->vl = NULL; - vl->n = NULL; - } + q_timeout = GNUNET_TIME_absolute_max(q_timeout, q->validated_until); + if (0 == GNUNET_TIME_absolute_get_remaining(q_timeout).rel_value_us) + { + vl->n->vl = NULL; + vl->n = NULL; + } if ((NULL == vl->n) && (NULL == vl->dv)) - { - cores_send_disconnect_info (&vl->target); - free_virtual_link (vl); - return; - } + { + cores_send_disconnect_info(&vl->target); + free_virtual_link(vl); + return; + } vl->visibility_task = - GNUNET_SCHEDULER_add_at (GNUNET_TIME_absolute_max (q_timeout, dvh_timeout), - &check_link_down, - vl); + GNUNET_SCHEDULER_add_at(GNUNET_TIME_absolute_max(q_timeout, dvh_timeout), + &check_link_down, + vl); } @@ -3570,77 +3490,77 @@ check_link_down (void *cls) * @param queue the queue to free */ static void -free_queue (struct Queue *queue) +free_queue(struct Queue *queue) { struct Neighbour *neighbour = queue->neighbour; struct TransportClient *tc = queue->tc; - struct MonitorEvent me = {.cs = GNUNET_TRANSPORT_CS_DOWN, - .rtt = GNUNET_TIME_UNIT_FOREVER_REL}; + struct MonitorEvent me = { .cs = GNUNET_TRANSPORT_CS_DOWN, + .rtt = GNUNET_TIME_UNIT_FOREVER_REL }; struct QueueEntry *qe; int maxxed; struct PendingAcknowledgement *pa; struct VirtualLink *vl; if (NULL != queue->transmit_task) - { - GNUNET_SCHEDULER_cancel (queue->transmit_task); - queue->transmit_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(queue->transmit_task); + queue->transmit_task = NULL; + } while (NULL != (pa = queue->pa_head)) - { - GNUNET_CONTAINER_MDLL_remove (queue, queue->pa_head, queue->pa_tail, pa); - pa->queue = NULL; - } + { + GNUNET_CONTAINER_MDLL_remove(queue, queue->pa_head, queue->pa_tail, pa); + pa->queue = NULL; + } - GNUNET_CONTAINER_MDLL_remove (neighbour, - neighbour->queue_head, - neighbour->queue_tail, - queue); - GNUNET_CONTAINER_MDLL_remove (client, - tc->details.communicator.queue_head, - tc->details.communicator.queue_tail, - queue); + GNUNET_CONTAINER_MDLL_remove(neighbour, + neighbour->queue_head, + neighbour->queue_tail, + queue); + GNUNET_CONTAINER_MDLL_remove(client, + tc->details.communicator.queue_head, + tc->details.communicator.queue_tail, + queue); maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >= tc->details.communicator.total_queue_length); while (NULL != (qe = queue->queue_head)) - { - GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe); - queue->queue_length--; - tc->details.communicator.total_queue_length--; - if (NULL != qe->pm) { - GNUNET_assert (qe == qe->pm->qe); - qe->pm->qe = NULL; + GNUNET_CONTAINER_DLL_remove(queue->queue_head, queue->queue_tail, qe); + queue->queue_length--; + tc->details.communicator.total_queue_length--; + if (NULL != qe->pm) + { + GNUNET_assert(qe == qe->pm->qe); + qe->pm->qe = NULL; + } + GNUNET_free(qe); } - GNUNET_free (qe); - } - GNUNET_assert (0 == queue->queue_length); + GNUNET_assert(0 == queue->queue_length); if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT < tc->details.communicator.total_queue_length)) - { - /* Communicator dropped below threshold, resume all _other_ queues */ - GNUNET_STATISTICS_update ( - GST_stats, - "# Transmission throttled due to communicator queue limit", - -1, - GNUNET_NO); - for (struct Queue *s = tc->details.communicator.queue_head; NULL != s; - s = s->next_client) - schedule_transmit_on_queue (s, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - } - notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); - GNUNET_free (queue); + { + /* Communicator dropped below threshold, resume all _other_ queues */ + GNUNET_STATISTICS_update( + GST_stats, + "# Transmission throttled due to communicator queue limit", + -1, + GNUNET_NO); + for (struct Queue *s = tc->details.communicator.queue_head; NULL != s; + s = s->next_client) + schedule_transmit_on_queue(s, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + } + notify_monitors(&neighbour->pid, queue->address, queue->nt, &me); + GNUNET_free(queue); - vl = lookup_virtual_link (&neighbour->pid); + vl = lookup_virtual_link(&neighbour->pid); if ((NULL != vl) && (neighbour == vl->n)) - { - GNUNET_SCHEDULER_cancel (vl->visibility_task); - check_link_down (vl); - } + { + GNUNET_SCHEDULER_cancel(vl->visibility_task); + check_link_down(vl); + } if (NULL == neighbour->queue_head) - { - free_neighbour (neighbour); - } + { + free_neighbour(neighbour); + } } @@ -3650,24 +3570,24 @@ free_queue (struct Queue *queue) * @param ale address list entry to free */ static void -free_address_list_entry (struct AddressListEntry *ale) +free_address_list_entry(struct AddressListEntry *ale) { struct TransportClient *tc = ale->tc; - GNUNET_CONTAINER_DLL_remove (tc->details.communicator.addr_head, - tc->details.communicator.addr_tail, - ale); + GNUNET_CONTAINER_DLL_remove(tc->details.communicator.addr_head, + tc->details.communicator.addr_tail, + ale); if (NULL != ale->sc) - { - GNUNET_PEERSTORE_store_cancel (ale->sc); - ale->sc = NULL; - } + { + GNUNET_PEERSTORE_store_cancel(ale->sc); + ale->sc = NULL; + } if (NULL != ale->st) - { - GNUNET_SCHEDULER_cancel (ale->st); - ale->st = NULL; - } - GNUNET_free (ale); + { + GNUNET_SCHEDULER_cancel(ale->st); + ale->st = NULL; + } + GNUNET_free(ale); } @@ -3680,20 +3600,20 @@ free_address_list_entry (struct AddressListEntry *ale) * @return #GNUNET_YES (always) */ static int -stop_peer_request (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +stop_peer_request(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct TransportClient *tc = cls; struct PeerRequest *pr = value; - GNUNET_PEERSTORE_watch_cancel (pr->wc); - GNUNET_assert ( + GNUNET_PEERSTORE_watch_cancel(pr->wc); + GNUNET_assert( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, - pid, - pr)); - GNUNET_free (pr); + GNUNET_CONTAINER_multipeermap_remove(tc->details.application.requests, + pid, + pr)); + GNUNET_free(pr); return GNUNET_OK; } @@ -3708,56 +3628,60 @@ stop_peer_request (void *cls, * @param app_ctx our `struct TransportClient` */ static void -client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_ctx) +client_disconnect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + void *app_ctx) { struct TransportClient *tc = app_ctx; - (void) cls; - (void) client; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client %p disconnected, cleaning up.\n", - tc); - GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); + (void)cls; + (void)client; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client %p disconnected, cleaning up.\n", + tc); + GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc); switch (tc->type) - { - case CT_NONE: - break; - case CT_CORE: { - struct PendingMessage *pm; - - while (NULL != (pm = tc->details.core.pending_msg_head)) { - GNUNET_CONTAINER_MDLL_remove (client, - tc->details.core.pending_msg_head, - tc->details.core.pending_msg_tail, - pm); - pm->client = NULL; + case CT_NONE: + break; + + case CT_CORE: { + struct PendingMessage *pm; + + while (NULL != (pm = tc->details.core.pending_msg_head)) + { + GNUNET_CONTAINER_MDLL_remove(client, + tc->details.core.pending_msg_head, + tc->details.core.pending_msg_tail, + pm); + pm->client = NULL; + } } - } - break; - case CT_MONITOR: break; - case CT_COMMUNICATOR: { - struct Queue *q; - struct AddressListEntry *ale; - - while (NULL != (q = tc->details.communicator.queue_head)) - free_queue (q); - while (NULL != (ale = tc->details.communicator.addr_head)) - free_address_list_entry (ale); - GNUNET_free (tc->details.communicator.address_prefix); - } - break; - case CT_APPLICATION: - GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests, - &stop_peer_request, - tc); - GNUNET_CONTAINER_multipeermap_destroy (tc->details.application.requests); + + case CT_MONITOR: + break; + + case CT_COMMUNICATOR: { + struct Queue *q; + struct AddressListEntry *ale; + + while (NULL != (q = tc->details.communicator.queue_head)) + free_queue(q); + while (NULL != (ale = tc->details.communicator.addr_head)) + free_address_list_entry(ale); + GNUNET_free(tc->details.communicator.address_prefix); + } break; - } - GNUNET_free (tc); + + case CT_APPLICATION: + GNUNET_CONTAINER_multipeermap_iterate(tc->details.application.requests, + &stop_peer_request, + tc); + GNUNET_CONTAINER_multipeermap_destroy(tc->details.application.requests); + break; + } + GNUNET_free(tc); } @@ -3771,17 +3695,17 @@ client_disconnect_cb (void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -notify_client_connect_info (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +notify_client_connect_info(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct TransportClient *tc = cls; - (void) value; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Telling new CORE client about existing connection to %s\n", - GNUNET_i2s (pid)); - core_send_connect_info (tc, pid); + (void)value; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Telling new CORE client about existing connection to %s\n", + GNUNET_i2s(pid)); + core_send_connect_info(tc, pid); return GNUNET_OK; } @@ -3795,34 +3719,34 @@ notify_client_connect_info (void *cls, * @param start the start message that was sent */ static void -handle_client_start (void *cls, const struct StartMessage *start) +handle_client_start(void *cls, const struct StartMessage *start) { struct TransportClient *tc = cls; uint32_t options; - options = ntohl (start->options); + options = ntohl(start->options); if ((0 != (1 & options)) && - (0 != GNUNET_memcmp (&start->self, &GST_my_identity))) - { - /* client thinks this is a different peer, reject */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } + (0 != GNUNET_memcmp(&start->self, &GST_my_identity))) + { + /* client thinks this is a different peer, reject */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } if (CT_NONE != tc->type) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } tc->type = CT_CORE; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "New CORE client with PID %s registered\n", - GNUNET_i2s (&start->self)); - GNUNET_CONTAINER_multipeermap_iterate (neighbours, - ¬ify_client_connect_info, - tc); - GNUNET_SERVICE_client_continue (tc->client); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "New CORE client with PID %s registered\n", + GNUNET_i2s(&start->self)); + GNUNET_CONTAINER_multipeermap_iterate(neighbours, + ¬ify_client_connect_info, + tc); + GNUNET_SERVICE_client_continue(tc->client); } @@ -3833,29 +3757,29 @@ handle_client_start (void *cls, const struct StartMessage *start) * @param obm the send message that was sent */ static int -check_client_send (void *cls, const struct OutboundMessage *obm) +check_client_send(void *cls, const struct OutboundMessage *obm) { struct TransportClient *tc = cls; uint16_t size; const struct GNUNET_MessageHeader *obmm; if (CT_CORE != tc->type) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - size = ntohs (obm->header.size) - sizeof (struct OutboundMessage); - if (size < sizeof (struct GNUNET_MessageHeader)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - obmm = (const struct GNUNET_MessageHeader *) &obm[1]; - if (size != ntohs (obmm->size)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + size = ntohs(obm->header.size) - sizeof(struct OutboundMessage); + if (size < sizeof(struct GNUNET_MessageHeader)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + obmm = (const struct GNUNET_MessageHeader *)&obm[1]; + if (size != ntohs(obmm->size)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -3868,25 +3792,25 @@ check_client_send (void *cls, const struct OutboundMessage *obm) * @param pm handle to the original pending message */ static void -client_send_response (struct PendingMessage *pm) +client_send_response(struct PendingMessage *pm) { struct TransportClient *tc = pm->client; struct VirtualLink *vl = pm->vl; if (NULL != tc) - { - struct GNUNET_MQ_Envelope *env; - struct SendOkMessage *som; - - env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); - som->peer = vl->target; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Confirming transmission of <%llu> to %s\n", - pm->logging_uuid, - GNUNET_i2s (&vl->target)); - GNUNET_MQ_send (tc->mq, env); - } - free_pending_message (pm); + { + struct GNUNET_MQ_Envelope *env; + struct SendOkMessage *som; + + env = GNUNET_MQ_msg(som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); + som->peer = vl->target; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Confirming transmission of <%llu> to %s\n", + pm->logging_uuid, + GNUNET_i2s(&vl->target)); + GNUNET_MQ_send(tc->mq, env); + } + free_pending_message(pm); } @@ -3900,10 +3824,10 @@ client_send_response (struct PendingMessage *pm) * @return number of entries set in @a hops_array */ static unsigned int -pick_random_dv_hops (const struct DistanceVector *dv, - enum RouteMessageOptions options, - struct DistanceVectorHop **hops_array, - unsigned int hops_array_length) +pick_random_dv_hops(const struct DistanceVector *dv, + enum RouteMessageOptions options, + struct DistanceVectorHop **hops_array, + unsigned int hops_array_length) { uint64_t choices[hops_array_length]; uint64_t num_dv; @@ -3915,56 +3839,56 @@ pick_random_dv_hops (const struct DistanceVector *dv, dv_count = 0; for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; pos = pos->next_dv) - { - if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && - (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until) + { + if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && + (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until) .rel_value_us == 0)) - continue; /* pos unconfirmed and confirmed required */ - num_dv += MAX_DV_HOPS_ALLOWED - pos->distance; - dv_count++; - } + continue; /* pos unconfirmed and confirmed required */ + num_dv += MAX_DV_HOPS_ALLOWED - pos->distance; + dv_count++; + } if (0 == dv_count) return 0; if (dv_count <= hops_array_length) - { - dv_count = 0; - for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; - pos = pos->next_dv) - hops_array[dv_count++] = pos; - return dv_count; - } + { + dv_count = 0; + for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; + pos = pos->next_dv) + hops_array[dv_count++] = pos; + return dv_count; + } for (unsigned int i = 0; i < hops_array_length; i++) - { - int ok = GNUNET_NO; - while (GNUNET_NO == ok) - { - choices[i] = - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, num_dv); - ok = GNUNET_YES; - for (unsigned int j = 0; j < i; j++) - if (choices[i] == choices[j]) + { + int ok = GNUNET_NO; + while (GNUNET_NO == ok) { - ok = GNUNET_NO; - break; + choices[i] = + GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, num_dv); + ok = GNUNET_YES; + for (unsigned int j = 0; j < i; j++) + if (choices[i] == choices[j]) + { + ok = GNUNET_NO; + break; + } } } - } dv_count = 0; num_dv = 0; for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; pos = pos->next_dv) - { - uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance; + { + uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance; - if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && - (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until) + if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && + (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until) .rel_value_us == 0)) - continue; /* pos unconfirmed and confirmed required */ - for (unsigned int i = 0; i < hops_array_length; i++) - if ((num_dv <= choices[i]) && (num_dv + delta > choices[i])) - hops_array[dv_count++] = pos; - num_dv += delta; - } + continue; /* pos unconfirmed and confirmed required */ + for (unsigned int i = 0; i < hops_array_length; i++) + if ((num_dv <= choices[i]) && (num_dv + delta > choices[i])) + hops_array[dv_count++] = pos; + num_dv += delta; + } return dv_count; } @@ -3976,7 +3900,7 @@ pick_random_dv_hops (const struct DistanceVector *dv, * @param cam the send message that was sent */ static int -check_communicator_available ( +check_communicator_available( void *cls, const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) { @@ -3984,15 +3908,15 @@ check_communicator_available ( uint16_t size; if (CT_NONE != tc->type) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } tc->type = CT_COMMUNICATOR; - size = ntohs (cam->header.size) - sizeof (*cam); + size = ntohs(cam->header.size) - sizeof(*cam); if (0 == size) return GNUNET_OK; /* receive-only communicator */ - GNUNET_MQ_check_zero_termination (cam); + GNUNET_MQ_check_zero_termination(cam); return GNUNET_OK; } @@ -4003,22 +3927,22 @@ check_communicator_available ( * @param cmc context for which we are done handling the message */ static void -finish_cmc_handling (struct CommunicatorMessageContext *cmc) +finish_cmc_handling(struct CommunicatorMessageContext *cmc) { - if (0 != ntohl (cmc->im.fc_on)) - { - /* send ACK when done to communicator for flow control! */ - struct GNUNET_MQ_Envelope *env; - struct GNUNET_TRANSPORT_IncomingMessageAck *ack; - - env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); - ack->reserved = htonl (0); - ack->fc_id = cmc->im.fc_id; - ack->sender = cmc->im.sender; - GNUNET_MQ_send (cmc->tc->mq, env); - } - GNUNET_SERVICE_client_continue (cmc->tc->client); - GNUNET_free (cmc); + if (0 != ntohl(cmc->im.fc_on)) + { + /* send ACK when done to communicator for flow control! */ + struct GNUNET_MQ_Envelope *env; + struct GNUNET_TRANSPORT_IncomingMessageAck *ack; + + env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); + ack->reserved = htonl(0); + ack->fc_id = cmc->im.fc_id; + ack->sender = cmc->im.sender; + GNUNET_MQ_send(cmc->tc->mq, env); + } + GNUNET_SERVICE_client_continue(cmc->tc->client); + GNUNET_free(cmc); } @@ -4032,7 +3956,7 @@ finish_cmc_handling (struct CommunicatorMessageContext *cmc) * @param rom the message that was sent */ static void -handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom) +handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom) { struct TransportClient *tc = cls; struct VirtualLink *vl; @@ -4040,31 +3964,31 @@ handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom) struct CommunicatorMessageContext *cmc; if (CT_CORE != tc->type) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } - vl = lookup_virtual_link (&rom->peer); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } + vl = lookup_virtual_link(&rom->peer); if (NULL == vl) - { - GNUNET_STATISTICS_update (GST_stats, - "# RECV_OK dropped: virtual link unknown", - 1, - GNUNET_NO); - GNUNET_SERVICE_client_continue (tc->client); - return; - } - delta = ntohl (rom->increase_window_delta); + { + GNUNET_STATISTICS_update(GST_stats, + "# RECV_OK dropped: virtual link unknown", + 1, + GNUNET_NO); + GNUNET_SERVICE_client_continue(tc->client); + return; + } + delta = ntohl(rom->increase_window_delta); vl->core_recv_window += delta; if (vl->core_recv_window <= 0) return; /* resume communicators */ while (NULL != (cmc = vl->cmc_tail)) - { - GNUNET_CONTAINER_DLL_remove (vl->cmc_head, vl->cmc_tail, cmc); - finish_cmc_handling (cmc); - } + { + GNUNET_CONTAINER_DLL_remove(vl->cmc_head, vl->cmc_tail, cmc); + finish_cmc_handling(cmc); + } } @@ -4075,28 +3999,28 @@ handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom) * @param cam the send message that was sent */ static void -handle_communicator_available ( +handle_communicator_available( void *cls, const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) { struct TransportClient *tc = cls; uint16_t size; - size = ntohs (cam->header.size) - sizeof (*cam); + size = ntohs(cam->header.size) - sizeof(*cam); if (0 == size) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Receive-only communicator connected\n"); - return; /* receive-only communicator */ - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Receive-only communicator connected\n"); + return; /* receive-only communicator */ + } tc->details.communicator.address_prefix = - GNUNET_strdup ((const char *) &cam[1]); + GNUNET_strdup((const char *)&cam[1]); tc->details.communicator.cc = - (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Communicator with prefix `%s' connected\n", - tc->details.communicator.address_prefix); - GNUNET_SERVICE_client_continue (tc->client); + (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(cam->cc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Communicator with prefix `%s' connected\n", + tc->details.communicator.address_prefix); + GNUNET_SERVICE_client_continue(tc->client); } @@ -4108,7 +4032,7 @@ handle_communicator_available ( * @return #GNUNET_OK if message is well-formed */ static int -check_communicator_backchannel ( +check_communicator_backchannel( void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) { @@ -4117,24 +4041,24 @@ check_communicator_backchannel ( uint16_t msize; uint16_t isize; - (void) cls; - msize = ntohs (cb->header.size) - sizeof (*cb); - inbox = (const struct GNUNET_MessageHeader *) &cb[1]; - isize = ntohs (inbox->size); + (void)cls; + msize = ntohs(cb->header.size) - sizeof(*cb); + inbox = (const struct GNUNET_MessageHeader *)&cb[1]; + isize = ntohs(inbox->size); if (isize >= msize) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - is = (const char *) inbox; + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + is = (const char *)inbox; is += isize; msize -= isize; - GNUNET_assert (0 < msize); + GNUNET_assert(0 < msize); if ('\0' != is[msize - 1]) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -4146,26 +4070,26 @@ check_communicator_backchannel ( * @param dv[in,out] virtual link to update ephemeral for */ static void -update_ephemeral (struct DistanceVector *dv) +update_ephemeral(struct DistanceVector *dv) { struct EphemeralConfirmationPS ec; if (0 != - GNUNET_TIME_absolute_get_remaining (dv->ephemeral_validity).rel_value_us) + GNUNET_TIME_absolute_get_remaining(dv->ephemeral_validity).rel_value_us) return; - dv->monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); + dv->monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg); dv->ephemeral_validity = - GNUNET_TIME_absolute_add (dv->monotime, EPHEMERAL_VALIDITY); - GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_ecdhe_key_create2 (&dv->private_key)); - GNUNET_CRYPTO_ecdhe_key_get_public (&dv->private_key, &dv->ephemeral_key); - ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); - ec.purpose.size = htonl (sizeof (ec)); + GNUNET_TIME_absolute_add(dv->monotime, EPHEMERAL_VALIDITY); + GNUNET_assert(GNUNET_OK == + GNUNET_CRYPTO_ecdhe_key_create2(&dv->private_key)); + GNUNET_CRYPTO_ecdhe_key_get_public(&dv->private_key, &dv->ephemeral_key); + ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); + ec.purpose.size = htonl(sizeof(ec)); ec.target = dv->target; ec.ephemeral_key = dv->ephemeral_key; - GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, - &ec.purpose, - &dv->sender_sig)); + GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, + &ec.purpose, + &dv->sender_sig)); } @@ -4179,45 +4103,45 @@ update_ephemeral (struct DistanceVector *dv) * @param payload_size number of bytes in @a payload */ static void -queue_send_msg (struct Queue *queue, - struct PendingMessage *pm, - const void *payload, - size_t payload_size) +queue_send_msg(struct Queue *queue, + struct PendingMessage *pm, + const void *payload, + size_t payload_size) { struct Neighbour *n = queue->neighbour; struct GNUNET_TRANSPORT_SendMessageTo *smt; struct GNUNET_MQ_Envelope *env; queue->idle = GNUNET_NO; - GNUNET_log ( + GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n", - (unsigned int) payload_size, + (unsigned int)payload_size, (NULL == pm) ? 0 : pm->logging_uuid, - (unsigned long long) queue->qid, - GNUNET_i2s (&queue->neighbour->pid)); - env = GNUNET_MQ_msg_extra (smt, - payload_size, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); + (unsigned long long)queue->qid, + GNUNET_i2s(&queue->neighbour->pid)); + env = GNUNET_MQ_msg_extra(smt, + payload_size, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); smt->qid = queue->qid; smt->mid = queue->mid_gen; smt->receiver = n->pid; - memcpy (&smt[1], payload, payload_size); + memcpy(&smt[1], payload, payload_size); { /* Pass the env to the communicator of queue for transmission. */ struct QueueEntry *qe; - qe = GNUNET_new (struct QueueEntry); + qe = GNUNET_new(struct QueueEntry); qe->mid = queue->mid_gen++; qe->queue = queue; if (NULL != pm) - { - qe->pm = pm; - GNUNET_assert (NULL == pm->qe); - pm->qe = qe; - } - GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe); - GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); + { + qe->pm = pm; + GNUNET_assert(NULL == pm->qe); + pm->qe = qe; + } + GNUNET_CONTAINER_DLL_insert(queue->queue_head, queue->queue_tail, qe); + GNUNET_assert(CT_COMMUNICATOR == queue->tc->type); queue->queue_length++; queue->tc->details.communicator.total_queue_length++; if (COMMUNICATOR_TOTAL_QUEUE_LIMIT == @@ -4225,7 +4149,7 @@ queue_send_msg (struct Queue *queue, queue->idle = GNUNET_NO; if (QUEUE_LENGTH_LIMIT == queue->queue_length) queue->idle = GNUNET_NO; - GNUNET_MQ_send (queue->tc->mq, env); + GNUNET_MQ_send(queue->tc->mq, env); } } @@ -4241,9 +4165,9 @@ queue_send_msg (struct Queue *queue, * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed */ static struct GNUNET_TIME_Relative -route_via_neighbour (const struct Neighbour *n, - const struct GNUNET_MessageHeader *hdr, - enum RouteMessageOptions options) +route_via_neighbour(const struct Neighbour *n, + const struct GNUNET_MessageHeader *hdr, + enum RouteMessageOptions options) { struct GNUNET_TIME_Absolute now; unsigned int candidates; @@ -4252,7 +4176,7 @@ route_via_neighbour (const struct Neighbour *n, struct GNUNET_TIME_Relative rtt; /* Pick one or two 'random' queues from n (under constraints of options) */ - now = GNUNET_TIME_absolute_get (); + now = GNUNET_TIME_absolute_get(); /* FIXME-OPTIMIZE: give queues 'weights' and pick proportional to weight in the future; weight could be assigned by observed bandwidth (note: not sure if we should do this for this type @@ -4260,53 +4184,53 @@ route_via_neighbour (const struct Neighbour *n, candidates = 0; for (struct Queue *pos = n->queue_head; NULL != pos; pos = pos->next_neighbour) - { - if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || - (pos->validated_until.abs_value_us > now.abs_value_us)) - candidates++; - } + { + if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || + (pos->validated_until.abs_value_us > now.abs_value_us)) + candidates++; + } if (0 == candidates) - { - /* This can happen rarely if the last confirmed queue timed - out just as we were beginning to process this message. */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Could not route message of type %u to %s: no valid queue\n", - ntohs (hdr->type), - GNUNET_i2s (&n->pid)); - GNUNET_STATISTICS_update (GST_stats, - "# route selection failed (all no valid queue)", - 1, - GNUNET_NO); - return GNUNET_TIME_UNIT_FOREVER_REL; - } + { + /* This can happen rarely if the last confirmed queue timed + out just as we were beginning to process this message. */ + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Could not route message of type %u to %s: no valid queue\n", + ntohs(hdr->type), + GNUNET_i2s(&n->pid)); + GNUNET_STATISTICS_update(GST_stats, + "# route selection failed (all no valid queue)", + 1, + GNUNET_NO); + return GNUNET_TIME_UNIT_FOREVER_REL; + } rtt = GNUNET_TIME_UNIT_FOREVER_REL; - sel1 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates); + sel1 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates); if (0 == (options & RMO_REDUNDANT)) sel2 = candidates; /* picks none! */ else - sel2 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates); + sel2 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates); candidates = 0; for (struct Queue *pos = n->queue_head; NULL != pos; pos = pos->next_neighbour) - { - if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || - (pos->validated_until.abs_value_us > now.abs_value_us)) { - if ((sel1 == candidates) || (sel2 == candidates)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Routing message of type %u to %s using %s (#%u)\n", - ntohs (hdr->type), - GNUNET_i2s (&n->pid), - pos->address, - (sel1 == candidates) ? 1 : 2); - rtt = GNUNET_TIME_relative_min (rtt, pos->pd.aged_rtt); - queue_send_msg (pos, NULL, hdr, ntohs (hdr->size)); - } - candidates++; + if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || + (pos->validated_until.abs_value_us > now.abs_value_us)) + { + if ((sel1 == candidates) || (sel2 == candidates)) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Routing message of type %u to %s using %s (#%u)\n", + ntohs(hdr->type), + GNUNET_i2s(&n->pid), + pos->address, + (sel1 == candidates) ? 1 : 2); + rtt = GNUNET_TIME_relative_min(rtt, pos->pd.aged_rtt); + queue_send_msg(pos, NULL, hdr, ntohs(hdr->size)); + } + candidates++; + } } - } return rtt; } @@ -4314,8 +4238,7 @@ route_via_neighbour (const struct Neighbour *n, /** * Structure of the key material used to encrypt backchannel messages. */ -struct DVKeyState -{ +struct DVKeyState { /** * State of our block cipher. */ @@ -4324,9 +4247,7 @@ struct DVKeyState /** * Actual key material. */ - struct - { - + struct { /** * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()). */ @@ -4341,7 +4262,6 @@ struct DVKeyState * Counter value to use during setup. */ char aes_ctr[128 / 8]; - } material; }; @@ -4355,34 +4275,34 @@ struct DVKeyState * @param key[out] symmetric cipher and HMAC state to generate */ static void -dv_setup_key_state_from_km (const struct GNUNET_HashCode *km, - const struct GNUNET_ShortHashCode *iv, - struct DVKeyState *key) +dv_setup_key_state_from_km(const struct GNUNET_HashCode *km, + const struct GNUNET_ShortHashCode *iv, + struct DVKeyState *key) { /* must match #dh_key_derive_eph_pub */ - GNUNET_assert (GNUNET_YES == - GNUNET_CRYPTO_kdf (&key->material, - sizeof (key->material), - "transport-backchannel-key", - strlen ("transport-backchannel-key"), - &km, - sizeof (km), - iv, - sizeof (*iv))); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Deriving backchannel key based on KM %s and IV %s\n", - GNUNET_h2s (km), - GNUNET_sh2s (iv)); - gcry_cipher_open (&key->cipher, - GCRY_CIPHER_AES256 /* low level: go for speed */, - GCRY_CIPHER_MODE_CTR, - 0 /* flags */); - gcry_cipher_setkey (key->cipher, - &key->material.aes_key, - sizeof (key->material.aes_key)); - gcry_cipher_setctr (key->cipher, - &key->material.aes_ctr, - sizeof (key->material.aes_ctr)); + GNUNET_assert(GNUNET_YES == + GNUNET_CRYPTO_kdf(&key->material, + sizeof(key->material), + "transport-backchannel-key", + strlen("transport-backchannel-key"), + &km, + sizeof(km), + iv, + sizeof(*iv))); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Deriving backchannel key based on KM %s and IV %s\n", + GNUNET_h2s(km), + GNUNET_sh2s(iv)); + gcry_cipher_open(&key->cipher, + GCRY_CIPHER_AES256 /* low level: go for speed */, + GCRY_CIPHER_MODE_CTR, + 0 /* flags */); + gcry_cipher_setkey(key->cipher, + &key->material.aes_key, + sizeof(key->material.aes_key)); + gcry_cipher_setctr(key->cipher, + &key->material.aes_ctr, + sizeof(key->material.aes_ctr)); } @@ -4396,7 +4316,7 @@ dv_setup_key_state_from_km (const struct GNUNET_HashCode *km, * @param key[out] set to the key material */ static void -dh_key_derive_eph_pid ( +dh_key_derive_eph_pid( const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, const struct GNUNET_PeerIdentity *target, const struct GNUNET_ShortHashCode *iv, @@ -4404,10 +4324,10 @@ dh_key_derive_eph_pid ( { struct GNUNET_HashCode km; - GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral, - &target->public_key, - &km)); - dv_setup_key_state_from_km (&km, iv, key); + GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa(priv_ephemeral, + &target->public_key, + &km)); + dv_setup_key_state_from_km(&km, iv, key); } @@ -4421,16 +4341,16 @@ dh_key_derive_eph_pid ( * @param key[out] set to the key material */ static void -dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, - const struct GNUNET_ShortHashCode *iv, - struct DVKeyState *key) +dh_key_derive_eph_pub(const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, + const struct GNUNET_ShortHashCode *iv, + struct DVKeyState *key) { struct GNUNET_HashCode km; - GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key, - pub_ephemeral, - &km)); - dv_setup_key_state_from_km (&km, iv, key); + GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh(GST_my_private_key, + pub_ephemeral, + &km)); + dv_setup_key_state_from_km(&km, iv, key); } @@ -4444,12 +4364,12 @@ dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, * @param data_size number of bytes in @a data */ static void -dv_hmac (const struct DVKeyState *key, - struct GNUNET_HashCode *hmac, - const void *data, - size_t data_size) +dv_hmac(const struct DVKeyState *key, + struct GNUNET_HashCode *hmac, + const void *data, + size_t data_size) { - GNUNET_CRYPTO_hmac (&key->material.hmac_key, data, data_size, hmac); + GNUNET_CRYPTO_hmac(&key->material.hmac_key, data, data_size, hmac); } @@ -4463,10 +4383,10 @@ dv_hmac (const struct DVKeyState *key, * @param in_size number of bytes of input in @a in and available at @a dst */ static void -dv_encrypt (struct DVKeyState *key, const void *in, void *dst, size_t in_size) +dv_encrypt(struct DVKeyState *key, const void *in, void *dst, size_t in_size) { - GNUNET_assert (0 == - gcry_cipher_encrypt (key->cipher, dst, in_size, in, in_size)); + GNUNET_assert(0 == + gcry_cipher_encrypt(key->cipher, dst, in_size, in, in_size)); } @@ -4480,13 +4400,13 @@ dv_encrypt (struct DVKeyState *key, const void *in, void *dst, size_t in_size) * @param out_size number of bytes of input in @a ciph and available in @a out */ static void -dv_decrypt (struct DVKeyState *key, - void *out, - const void *ciph, - size_t out_size) +dv_decrypt(struct DVKeyState *key, + void *out, + const void *ciph, + size_t out_size) { - GNUNET_assert ( - 0 == gcry_cipher_decrypt (key->cipher, out, out_size, ciph, out_size)); + GNUNET_assert( + 0 == gcry_cipher_decrypt(key->cipher, out, out_size, ciph, out_size)); } @@ -4496,10 +4416,10 @@ dv_decrypt (struct DVKeyState *key, * @param key key material to clean up (memory must not be free'd!) */ static void -dv_key_clean (struct DVKeyState *key) +dv_key_clean(struct DVKeyState *key) { - gcry_cipher_close (key->cipher); - GNUNET_CRYPTO_zero_keys (&key->material, sizeof (key->material)); + gcry_cipher_close(key->cipher); + GNUNET_CRYPTO_zero_keys(&key->material, sizeof(key->material)); } @@ -4532,92 +4452,92 @@ typedef void (*DVMessageHandler) (void *cls, * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed */ static struct GNUNET_TIME_Relative -encapsulate_for_dv (struct DistanceVector *dv, - unsigned int num_dvhs, - struct DistanceVectorHop **dvhs, - const struct GNUNET_MessageHeader *hdr, - DVMessageHandler use, - void *use_cls, - enum RouteMessageOptions options) +encapsulate_for_dv(struct DistanceVector *dv, + unsigned int num_dvhs, + struct DistanceVectorHop **dvhs, + const struct GNUNET_MessageHeader *hdr, + DVMessageHandler use, + void *use_cls, + enum RouteMessageOptions options) { struct TransportDVBoxMessage box_hdr; struct TransportDVBoxPayloadP payload_hdr; - uint16_t enc_body_size = ntohs (hdr->size); - char enc[sizeof (struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN; + uint16_t enc_body_size = ntohs(hdr->size); + char enc[sizeof(struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN; struct TransportDVBoxPayloadP *enc_payload_hdr = - (struct TransportDVBoxPayloadP *) enc; + (struct TransportDVBoxPayloadP *)enc; struct DVKeyState key; struct GNUNET_TIME_Relative rtt; /* Encrypt payload */ - box_hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX); - box_hdr.total_hops = htons (0); - update_ephemeral (dv); + box_hdr.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX); + box_hdr.total_hops = htons(0); + update_ephemeral(dv); box_hdr.ephemeral_key = dv->ephemeral_key; payload_hdr.sender_sig = dv->sender_sig; - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, - &box_hdr.iv, - sizeof (box_hdr.iv)); - dh_key_derive_eph_pid (&dv->private_key, &dv->target, &box_hdr.iv, &key); + GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, + &box_hdr.iv, + sizeof(box_hdr.iv)); + dh_key_derive_eph_pid(&dv->private_key, &dv->target, &box_hdr.iv, &key); payload_hdr.sender = GST_my_identity; - payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton (dv->monotime); - dv_encrypt (&key, &payload_hdr, enc_payload_hdr, sizeof (payload_hdr)); - dv_encrypt (&key, - hdr, - &enc[sizeof (struct TransportDVBoxPayloadP)], - enc_body_size); - dv_hmac (&key, &box_hdr.hmac, enc, sizeof (enc)); - dv_key_clean (&key); + payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton(dv->monotime); + dv_encrypt(&key, &payload_hdr, enc_payload_hdr, sizeof(payload_hdr)); + dv_encrypt(&key, + hdr, + &enc[sizeof(struct TransportDVBoxPayloadP)], + enc_body_size); + dv_hmac(&key, &box_hdr.hmac, enc, sizeof(enc)); + dv_key_clean(&key); rtt = GNUNET_TIME_UNIT_FOREVER_REL; /* For each selected path, take the pre-computed header and body and add the path in the middle of the message; then send it. */ for (unsigned int i = 0; i < num_dvhs; i++) - { - struct DistanceVectorHop *dvh = dvhs[i]; - unsigned int num_hops = dvh->distance + 1; - char buf[sizeof (struct TransportDVBoxMessage) + - sizeof (struct GNUNET_PeerIdentity) * num_hops + - sizeof (struct TransportDVBoxPayloadP) + - enc_body_size] GNUNET_ALIGN; - struct GNUNET_PeerIdentity *dhops; - - box_hdr.header.size = htons (sizeof (buf)); - box_hdr.num_hops = htons (num_hops); - memcpy (buf, &box_hdr, sizeof (box_hdr)); - dhops = (struct GNUNET_PeerIdentity *) &buf[sizeof (box_hdr)]; - memcpy (dhops, - dvh->path, - dvh->distance * sizeof (struct GNUNET_PeerIdentity)); - dhops[dvh->distance] = dv->target; - if (GNUNET_EXTRA_LOGGING > 0) { - char *path; - - path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity)); - for (unsigned int j = 0; j <= num_hops; j++) - { - char *tmp; - - GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[j])); - GNUNET_free (path); - path = tmp; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Routing message of type %u to %s using DV (#%u/%u) via %s\n", - ntohs (hdr->type), - GNUNET_i2s (&dv->target), - i + 1, - num_dvhs + 1, - path); - GNUNET_free (path); - } - rtt = GNUNET_TIME_relative_min (rtt, dvh->pd.aged_rtt); - memcpy (&dhops[num_hops], enc, sizeof (enc)); - use (use_cls, - dvh->next_hop, - (const struct GNUNET_MessageHeader *) buf, - options); - } + struct DistanceVectorHop *dvh = dvhs[i]; + unsigned int num_hops = dvh->distance + 1; + char buf[sizeof(struct TransportDVBoxMessage) + + sizeof(struct GNUNET_PeerIdentity) * num_hops + + sizeof(struct TransportDVBoxPayloadP) + + enc_body_size] GNUNET_ALIGN; + struct GNUNET_PeerIdentity *dhops; + + box_hdr.header.size = htons(sizeof(buf)); + box_hdr.num_hops = htons(num_hops); + memcpy(buf, &box_hdr, sizeof(box_hdr)); + dhops = (struct GNUNET_PeerIdentity *)&buf[sizeof(box_hdr)]; + memcpy(dhops, + dvh->path, + dvh->distance * sizeof(struct GNUNET_PeerIdentity)); + dhops[dvh->distance] = dv->target; + if (GNUNET_EXTRA_LOGGING > 0) + { + char *path; + + path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity)); + for (unsigned int j = 0; j <= num_hops; j++) + { + char *tmp; + + GNUNET_asprintf(&tmp, "%s-%s", path, GNUNET_i2s(&dhops[j])); + GNUNET_free(path); + path = tmp; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Routing message of type %u to %s using DV (#%u/%u) via %s\n", + ntohs(hdr->type), + GNUNET_i2s(&dv->target), + i + 1, + num_dvhs + 1, + path); + GNUNET_free(path); + } + rtt = GNUNET_TIME_relative_min(rtt, dvh->pd.aged_rtt); + memcpy(&dhops[num_hops], enc, sizeof(enc)); + use(use_cls, + dvh->next_hop, + (const struct GNUNET_MessageHeader *)buf, + options); + } return rtt; } @@ -4632,13 +4552,13 @@ encapsulate_for_dv (struct DistanceVector *dv, * @param options message options for queue selection */ static void -send_dv_to_neighbour (void *cls, - struct Neighbour *next_hop, - const struct GNUNET_MessageHeader *hdr, - enum RouteMessageOptions options) +send_dv_to_neighbour(void *cls, + struct Neighbour *next_hop, + const struct GNUNET_MessageHeader *hdr, + enum RouteMessageOptions options) { - (void) cls; - (void) route_via_neighbour (next_hop, hdr, options); + (void)cls; + (void)route_via_neighbour(next_hop, hdr, options); } @@ -4654,9 +4574,9 @@ send_dv_to_neighbour (void *cls, * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed */ static struct GNUNET_TIME_Relative -route_control_message_without_fc (const struct GNUNET_PeerIdentity *target, - const struct GNUNET_MessageHeader *hdr, - enum RouteMessageOptions options) +route_control_message_without_fc(const struct GNUNET_PeerIdentity *target, + const struct GNUNET_MessageHeader *hdr, + enum RouteMessageOptions options) { struct VirtualLink *vl; struct Neighbour *n; @@ -4664,78 +4584,78 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target, struct GNUNET_TIME_Relative rtt1; struct GNUNET_TIME_Relative rtt2; - vl = lookup_virtual_link (target); - GNUNET_assert (NULL != vl); + vl = lookup_virtual_link(target); + GNUNET_assert(NULL != vl); n = vl->n; dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL; if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) - { - /* if confirmed is required, and we do not have anything - confirmed, drop respective options */ - if (NULL == n) - n = lookup_neighbour (target); - if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED))) - dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, target); - } + { + /* if confirmed is required, and we do not have anything + confirmed, drop respective options */ + if (NULL == n) + n = lookup_neighbour(target); + if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED))) + dv = GNUNET_CONTAINER_multipeermap_get(dv_routes, target); + } if ((NULL == n) && (NULL == dv)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Cannot route message of type %u to %s: no route\n", - ntohs (hdr->type), - GNUNET_i2s (target)); - GNUNET_STATISTICS_update (GST_stats, - "# Messages dropped in routing: no acceptable method", - 1, - GNUNET_NO); - return GNUNET_TIME_UNIT_FOREVER_REL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Routing message of type %u to %s with options %X\n", - ntohs (hdr->type), - GNUNET_i2s (target), - (unsigned int) options); + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Cannot route message of type %u to %s: no route\n", + ntohs(hdr->type), + GNUNET_i2s(target)); + GNUNET_STATISTICS_update(GST_stats, + "# Messages dropped in routing: no acceptable method", + 1, + GNUNET_NO); + return GNUNET_TIME_UNIT_FOREVER_REL; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Routing message of type %u to %s with options %X\n", + ntohs(hdr->type), + GNUNET_i2s(target), + (unsigned int)options); /* If both dv and n are possible and we must choose: flip a coin for the choice between the two; for now 50/50 */ if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT))) - { - if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2)) - n = NULL; - else - dv = NULL; - } + { + if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2)) + n = NULL; + else + dv = NULL; + } if ((NULL != n) && (NULL != dv)) options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's enough for redunancy, so clear the flag. */ rtt1 = GNUNET_TIME_UNIT_FOREVER_REL; rtt2 = GNUNET_TIME_UNIT_FOREVER_REL; if (NULL != n) - { - rtt1 = route_via_neighbour (n, hdr, options); - } + { + rtt1 = route_via_neighbour(n, hdr, options); + } if (NULL != dv) - { - struct DistanceVectorHop *hops[2]; - unsigned int res; - - res = pick_random_dv_hops (dv, - options, - hops, - (0 == (options & RMO_REDUNDANT)) ? 1 : 2); - if (0 == res) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Failed to route message, could not determine DV path\n"); - return rtt1; - } - rtt2 = encapsulate_for_dv (dv, - res, - hops, - hdr, - &send_dv_to_neighbour, - NULL, - options & (~RMO_REDUNDANT)); - } - return GNUNET_TIME_relative_min (rtt1, rtt2); + { + struct DistanceVectorHop *hops[2]; + unsigned int res; + + res = pick_random_dv_hops(dv, + options, + hops, + (0 == (options & RMO_REDUNDANT)) ? 1 : 2); + if (0 == res) + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Failed to route message, could not determine DV path\n"); + return rtt1; + } + rtt2 = encapsulate_for_dv(dv, + res, + hops, + hdr, + &send_dv_to_neighbour, + NULL, + options & (~RMO_REDUNDANT)); + } + return GNUNET_TIME_relative_min(rtt1, rtt2); } @@ -4746,7 +4666,7 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target, * @param cls a `struct VirtualLink` to work with */ static void -consider_sending_fc (void *cls) +consider_sending_fc(void *cls) { struct VirtualLink *vl = cls; struct GNUNET_TIME_Absolute monotime; @@ -4754,7 +4674,7 @@ consider_sending_fc (void *cls) struct GNUNET_TIME_Relative duration; struct GNUNET_TIME_Relative rtt; - duration = GNUNET_TIME_absolute_get_duration (vl->last_fc_transmission); + duration = GNUNET_TIME_absolute_get_duration(vl->last_fc_transmission); /* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing it always! */ /* For example, we should probably ONLY do this if a bit more than @@ -4763,41 +4683,41 @@ consider_sending_fc (void *cls) need an estimate for the bandwidth-delay-product for the entire VL, as that determines "significantly". We have the delay, but the bandwidth statistics need to be added for the VL!*/ - (void) duration; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending FC seq %u to %s with new window %llu\n", - (unsigned int) vl->fc_seq_gen, - GNUNET_i2s (&vl->target), - (unsigned long long) vl->incoming_fc_window_size); - monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); + (void)duration; + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending FC seq %u to %s with new window %llu\n", + (unsigned int)vl->fc_seq_gen, + GNUNET_i2s(&vl->target), + (unsigned long long)vl->incoming_fc_window_size); + monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg); vl->last_fc_transmission = monotime; - fc.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL); - fc.header.size = htons (sizeof (fc)); - fc.seq = htonl (vl->fc_seq_gen++); - fc.inbound_window_size = GNUNET_htonll (vl->incoming_fc_window_size); - fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used); - fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size); - fc.sender_time = GNUNET_TIME_absolute_hton (monotime); - rtt = route_control_message_without_fc (&vl->target, &fc.header, RMO_NONE); + fc.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL); + fc.header.size = htons(sizeof(fc)); + fc.seq = htonl(vl->fc_seq_gen++); + fc.inbound_window_size = GNUNET_htonll(vl->incoming_fc_window_size); + fc.outbound_sent = GNUNET_htonll(vl->outbound_fc_window_size_used); + fc.outbound_window_size = GNUNET_htonll(vl->outbound_fc_window_size); + fc.sender_time = GNUNET_TIME_absolute_hton(monotime); + rtt = route_control_message_without_fc(&vl->target, &fc.header, RMO_NONE); if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us) - { - rtt = GNUNET_TIME_UNIT_SECONDS; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "FC retransmission to %s failed, will retry in %s\n", - GNUNET_i2s (&vl->target), - GNUNET_STRINGS_relative_time_to_string (rtt, GNUNET_YES)); - vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO; - } + { + rtt = GNUNET_TIME_UNIT_SECONDS; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "FC retransmission to %s failed, will retry in %s\n", + GNUNET_i2s(&vl->target), + GNUNET_STRINGS_relative_time_to_string(rtt, GNUNET_YES)); + vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO; + } else - { - /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */ - vl->last_fc_rtt = rtt; - } + { + /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */ + vl->last_fc_rtt = rtt; + } if (NULL != vl->fc_retransmit_task) - GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); + GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task); vl->fc_retransmit_task = - GNUNET_SCHEDULER_add_delayed (rtt, &consider_sending_fc, vl); + GNUNET_SCHEDULER_add_delayed(rtt, &consider_sending_fc, vl); } @@ -4818,7 +4738,7 @@ consider_sending_fc (void *cls) * @param vl virtual link where we should check for transmission */ static void -check_vl_transmission (struct VirtualLink *vl) +check_vl_transmission(struct VirtualLink *vl) { struct Neighbour *n = vl->n; struct DistanceVector *dv = vl->dv; @@ -4830,57 +4750,57 @@ check_vl_transmission (struct VirtualLink *vl) elig = GNUNET_NO; for (struct PendingMessage *pm = vl->pending_msg_head; NULL != pm; pm = pm->next_vl) - { - if (NULL != pm->qe) - continue; /* not eligible, is in a queue! */ - if (pm->bytes_msg + vl->outbound_fc_window_size_used > - vl->outbound_fc_window_size) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Stalled transmision on VL %s due to flow control: %llu < %llu\n", - GNUNET_i2s (&vl->target), - (unsigned long long) vl->outbound_fc_window_size, - (unsigned long long) (pm->bytes_msg + - vl->outbound_fc_window_size_used)); - consider_sending_fc (vl); - return; /* We have a message, but flow control says "nope" */ - } - elig = GNUNET_YES; - break; - } + { + if (NULL != pm->qe) + continue; /* not eligible, is in a queue! */ + if (pm->bytes_msg + vl->outbound_fc_window_size_used > + vl->outbound_fc_window_size) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Stalled transmision on VL %s due to flow control: %llu < %llu\n", + GNUNET_i2s(&vl->target), + (unsigned long long)vl->outbound_fc_window_size, + (unsigned long long)(pm->bytes_msg + + vl->outbound_fc_window_size_used)); + consider_sending_fc(vl); + return; /* We have a message, but flow control says "nope" */ + } + elig = GNUNET_YES; + break; + } if (GNUNET_NO == elig) return; /* Notify queues at direct neighbours that we are interested */ - now = GNUNET_TIME_absolute_get (); + now = GNUNET_TIME_absolute_get(); if (NULL != n) - { - for (struct Queue *queue = n->queue_head; NULL != queue; - queue = queue->next_neighbour) - if ((GNUNET_YES == queue->idle) && - (queue->validated_until.abs_value_us > now.abs_value_us)) - schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - } - /* Notify queues via DV that we are interested */ - if (NULL != dv) - { - /* Do DV with lower scheduler priority, which effectively means that - IF a neighbour exists and is available, we prefer it. */ - for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; - pos = pos->next_dv) { - struct Neighbour *nh = pos->next_hop; - - if (pos->path_valid_until.abs_value_us <= now.abs_value_us) - continue; /* skip this one: path not validated */ - for (struct Queue *queue = nh->queue_head; NULL != queue; + for (struct Queue *queue = n->queue_head; NULL != queue; queue = queue->next_neighbour) if ((GNUNET_YES == queue->idle) && (queue->validated_until.abs_value_us > now.abs_value_us)) - schedule_transmit_on_queue (queue, - GNUNET_SCHEDULER_PRIORITY_BACKGROUND); + schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + } + /* Notify queues via DV that we are interested */ + if (NULL != dv) + { + /* Do DV with lower scheduler priority, which effectively means that + IF a neighbour exists and is available, we prefer it. */ + for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; + pos = pos->next_dv) + { + struct Neighbour *nh = pos->next_hop; + + if (pos->path_valid_until.abs_value_us <= now.abs_value_us) + continue; /* skip this one: path not validated */ + for (struct Queue *queue = nh->queue_head; NULL != queue; + queue = queue->next_neighbour) + if ((GNUNET_YES == queue->idle) && + (queue->validated_until.abs_value_us > now.abs_value_us)) + schedule_transmit_on_queue(queue, + GNUNET_SCHEDULER_PRIORITY_BACKGROUND); + } } - } } @@ -4891,7 +4811,7 @@ check_vl_transmission (struct VirtualLink *vl) * @param obm the send message that was sent */ static void -handle_client_send (void *cls, const struct OutboundMessage *obm) +handle_client_send(void *cls, const struct OutboundMessage *obm) { struct TransportClient *tc = cls; struct PendingMessage *pm; @@ -4900,46 +4820,46 @@ handle_client_send (void *cls, const struct OutboundMessage *obm) struct VirtualLink *vl; enum GNUNET_MQ_PriorityPreferences pp; - GNUNET_assert (CT_CORE == tc->type); - obmm = (const struct GNUNET_MessageHeader *) &obm[1]; - bytes_msg = ntohs (obmm->size); - pp = (enum GNUNET_MQ_PriorityPreferences) ntohl (obm->priority); - vl = lookup_virtual_link (&obm->peer); + GNUNET_assert(CT_CORE == tc->type); + obmm = (const struct GNUNET_MessageHeader *)&obm[1]; + bytes_msg = ntohs(obmm->size); + pp = (enum GNUNET_MQ_PriorityPreferences)ntohl(obm->priority); + vl = lookup_virtual_link(&obm->peer); if (NULL == vl) - { - /* Failure: don't have this peer as a neighbour (anymore). - Might have gone down asynchronously, so this is NOT - a protocol violation by CORE. Still count the event, - as this should be rare. */ - GNUNET_SERVICE_client_continue (tc->client); - GNUNET_STATISTICS_update (GST_stats, - "# messages dropped (neighbour unknown)", - 1, - GNUNET_NO); - return; - } + { + /* Failure: don't have this peer as a neighbour (anymore). + Might have gone down asynchronously, so this is NOT + a protocol violation by CORE. Still count the event, + as this should be rare. */ + GNUNET_SERVICE_client_continue(tc->client); + GNUNET_STATISTICS_update(GST_stats, + "# messages dropped (neighbour unknown)", + 1, + GNUNET_NO); + return; + } - pm = GNUNET_malloc (sizeof (struct PendingMessage) + bytes_msg); + pm = GNUNET_malloc(sizeof(struct PendingMessage) + bytes_msg); pm->logging_uuid = logging_uuid_gen++; pm->prefs = pp; pm->client = tc; pm->vl = vl; pm->bytes_msg = bytes_msg; - memcpy (&pm[1], obmm, bytes_msg); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending %u bytes as <%llu> to %s\n", - bytes_msg, - pm->logging_uuid, - GNUNET_i2s (&obm->peer)); - GNUNET_CONTAINER_MDLL_insert (client, - tc->details.core.pending_msg_head, - tc->details.core.pending_msg_tail, - pm); - GNUNET_CONTAINER_MDLL_insert (vl, - vl->pending_msg_head, - vl->pending_msg_tail, - pm); - check_vl_transmission (vl); + memcpy(&pm[1], obmm, bytes_msg); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending %u bytes as <%llu> to %s\n", + bytes_msg, + pm->logging_uuid, + GNUNET_i2s(&obm->peer)); + GNUNET_CONTAINER_MDLL_insert(client, + tc->details.core.pending_msg_head, + tc->details.core.pending_msg_tail, + pm); + GNUNET_CONTAINER_MDLL_insert(vl, + vl->pending_msg_head, + vl->pending_msg_tail, + pm); + check_vl_transmission(vl); } @@ -4953,39 +4873,39 @@ handle_client_send (void *cls, const struct OutboundMessage *obm) * @param cb the send message that was sent */ static void -handle_communicator_backchannel ( +handle_communicator_backchannel( void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) { struct TransportClient *tc = cls; const struct GNUNET_MessageHeader *inbox = - (const struct GNUNET_MessageHeader *) &cb[1]; - uint16_t isize = ntohs (inbox->size); - const char *is = ((const char *) &cb[1]) + isize; + (const struct GNUNET_MessageHeader *)&cb[1]; + uint16_t isize = ntohs(inbox->size); + const char *is = ((const char *)&cb[1]) + isize; char mbuf[isize + - sizeof (struct TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN; + sizeof(struct TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN; struct TransportBackchannelEncapsulationMessage *be = - (struct TransportBackchannelEncapsulationMessage *) mbuf; + (struct TransportBackchannelEncapsulationMessage *)mbuf; /* 0-termination of 'is' was checked already in - #check_communicator_backchannel() */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Preparing backchannel transmission to %s:%s of type %u\n", - GNUNET_i2s (&cb->pid), - is, - ntohs (inbox->size)); + #check_communicator_backchannel() */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Preparing backchannel transmission to %s:%s of type %u\n", + GNUNET_i2s(&cb->pid), + is, + ntohs(inbox->size)); /* encapsulate and encrypt message */ be->header.type = - htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); - be->header.size = htons (sizeof (mbuf)); - memcpy (&be[1], inbox, isize); - memcpy (&mbuf[sizeof (struct TransportBackchannelEncapsulationMessage) + - isize], - is, - strlen (is) + 1); - route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED); - GNUNET_SERVICE_client_continue (tc->client); + htons(GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); + be->header.size = htons(sizeof(mbuf)); + memcpy(&be[1], inbox, isize); + memcpy(&mbuf[sizeof(struct TransportBackchannelEncapsulationMessage) + + isize], + is, + strlen(is) + 1); + route_control_message_without_fc(&cb->pid, &be->header, RMO_DV_ALLOWED); + GNUNET_SERVICE_client_continue(tc->client); } @@ -4997,17 +4917,17 @@ handle_communicator_backchannel ( * @return #GNUNET_OK if message is well-formed */ static int -check_add_address (void *cls, - const struct GNUNET_TRANSPORT_AddAddressMessage *aam) +check_add_address(void *cls, + const struct GNUNET_TRANSPORT_AddAddressMessage *aam) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - GNUNET_MQ_check_zero_termination (aam); + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + GNUNET_MQ_check_zero_termination(aam); return GNUNET_OK; } @@ -5018,7 +4938,7 @@ check_add_address (void *cls, * @param cls an `struct AddressListEntry *` */ static void -store_pi (void *cls); +store_pi(void *cls); /** @@ -5028,26 +4948,26 @@ store_pi (void *cls); * @param success #GNUNET_YES if peerstore was successful */ static void -peerstore_store_own_cb (void *cls, int success) +peerstore_store_own_cb(void *cls, int success) { struct AddressListEntry *ale = cls; ale->sc = NULL; if (GNUNET_YES != success) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to store our own address `%s' in peerstore!\n", - ale->address); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to store our own address `%s' in peerstore!\n", + ale->address); else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Successfully stored our own address `%s' in peerstore!\n", - ale->address); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Successfully stored our own address `%s' in peerstore!\n", + ale->address); /* refresh period is 1/4 of expiration time, that should be plenty without being excessive. */ ale->st = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration, - 4ULL), - &store_pi, - ale); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(ale->expiration, + 4ULL), + &store_pi, + ale); } @@ -5057,7 +4977,7 @@ peerstore_store_own_cb (void *cls, int success) * @param cls an `struct AddressListEntry *` */ static void -store_pi (void *cls) +store_pi(void *cls) { struct AddressListEntry *ale = cls; void *addr; @@ -5065,36 +4985,36 @@ store_pi (void *cls) struct GNUNET_TIME_Absolute expiration; ale->st = NULL; - expiration = GNUNET_TIME_relative_to_absolute (ale->expiration); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Storing our address `%s' in peerstore until %s!\n", - ale->address, - GNUNET_STRINGS_absolute_time_to_string (expiration)); - GNUNET_HELLO_sign_address (ale->address, - ale->nt, - hello_mono_time, - GST_my_private_key, - &addr, - &addr_len); - ale->sc = GNUNET_PEERSTORE_store (peerstore, - "transport", - &GST_my_identity, - GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, - addr, - addr_len, - expiration, - GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, - &peerstore_store_own_cb, - ale); - GNUNET_free (addr); + expiration = GNUNET_TIME_relative_to_absolute(ale->expiration); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Storing our address `%s' in peerstore until %s!\n", + ale->address, + GNUNET_STRINGS_absolute_time_to_string(expiration)); + GNUNET_HELLO_sign_address(ale->address, + ale->nt, + hello_mono_time, + GST_my_private_key, + &addr, + &addr_len); + ale->sc = GNUNET_PEERSTORE_store(peerstore, + "transport", + &GST_my_identity, + GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, + addr, + addr_len, + expiration, + GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, + &peerstore_store_own_cb, + ale); + GNUNET_free(addr); if (NULL == ale->sc) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to store our address `%s' with peerstore\n", - ale->address); - ale->st = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &store_pi, ale); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Failed to store our address `%s' with peerstore\n", + ale->address); + ale->st = + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &store_pi, ale); + } } @@ -5105,30 +5025,30 @@ store_pi (void *cls) * @param aam the send message that was sent */ static void -handle_add_address (void *cls, - const struct GNUNET_TRANSPORT_AddAddressMessage *aam) +handle_add_address(void *cls, + const struct GNUNET_TRANSPORT_AddAddressMessage *aam) { struct TransportClient *tc = cls; struct AddressListEntry *ale; size_t slen; /* 0-termination of &aam[1] was checked in #check_add_address */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Communicator added address `%s'!\n", - (const char *) &aam[1]); - slen = ntohs (aam->header.size) - sizeof (*aam); - ale = GNUNET_malloc (sizeof (struct AddressListEntry) + slen); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Communicator added address `%s'!\n", + (const char *)&aam[1]); + slen = ntohs(aam->header.size) - sizeof(*aam); + ale = GNUNET_malloc(sizeof(struct AddressListEntry) + slen); ale->tc = tc; - ale->address = (const char *) &ale[1]; - ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration); + ale->address = (const char *)&ale[1]; + ale->expiration = GNUNET_TIME_relative_ntoh(aam->expiration); ale->aid = aam->aid; - ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt); - memcpy (&ale[1], &aam[1], slen); - GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head, - tc->details.communicator.addr_tail, - ale); - ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale); - GNUNET_SERVICE_client_continue (tc->client); + ale->nt = (enum GNUNET_NetworkType)ntohl(aam->nt); + memcpy(&ale[1], &aam[1], slen); + GNUNET_CONTAINER_DLL_insert(tc->details.communicator.addr_head, + tc->details.communicator.addr_tail, + ale); + ale->st = GNUNET_SCHEDULER_add_now(&store_pi, ale); + GNUNET_SERVICE_client_continue(tc->client); } @@ -5139,34 +5059,34 @@ handle_add_address (void *cls, * @param dam the send message that was sent */ static void -handle_del_address (void *cls, - const struct GNUNET_TRANSPORT_DelAddressMessage *dam) +handle_del_address(void *cls, + const struct GNUNET_TRANSPORT_DelAddressMessage *dam) { struct TransportClient *tc = cls; struct AddressListEntry *alen; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } for (struct AddressListEntry *ale = tc->details.communicator.addr_head; NULL != ale; ale = alen) - { - alen = ale->next; - if (dam->aid != ale->aid) - continue; - GNUNET_assert (ale->tc == tc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Communicator deleted address `%s'!\n", - ale->address); - free_address_list_entry (ale); - GNUNET_SERVICE_client_continue (tc->client); - } - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); + { + alen = ale->next; + if (dam->aid != ale->aid) + continue; + GNUNET_assert(ale->tc == tc); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Communicator deleted address `%s'!\n", + ale->address); + free_address_list_entry(ale); + GNUNET_SERVICE_client_continue(tc->client); + } + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); } @@ -5178,8 +5098,8 @@ handle_del_address (void *cls, * @param msg message to demultiplex */ static void -demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, - const struct GNUNET_MessageHeader *msg); +demultiplex_with_cmc(struct CommunicatorMessageContext *cmc, + const struct GNUNET_MessageHeader *msg); /** @@ -5190,23 +5110,23 @@ demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, * @param cls a `struct CoreSentContext` */ static void -core_env_sent_cb (void *cls) +core_env_sent_cb(void *cls) { struct CoreSentContext *ctx = cls; struct VirtualLink *vl = ctx->vl; if (NULL == vl) - { - /* lost the link in the meantime, ignore */ - GNUNET_free (ctx); - return; - } - GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, ctx); - GNUNET_assert (vl->incoming_fc_window_size_ram >= ctx->size); + { + /* lost the link in the meantime, ignore */ + GNUNET_free(ctx); + return; + } + GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, ctx); + GNUNET_assert(vl->incoming_fc_window_size_ram >= ctx->size); vl->incoming_fc_window_size_ram -= ctx->size; vl->incoming_fc_window_size_used += ctx->isize; - consider_sending_fc (vl); - GNUNET_free (ctx); + consider_sending_fc(vl); + GNUNET_free(ctx); } @@ -5219,109 +5139,109 @@ core_env_sent_cb (void *cls) * @param mh the message that was received */ static void -handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh) +handle_raw_message(void *cls, const struct GNUNET_MessageHeader *mh) { struct CommunicatorMessageContext *cmc = cls; struct VirtualLink *vl; - uint16_t size = ntohs (mh->size); + uint16_t size = ntohs(mh->size); int have_core; - if ((size > UINT16_MAX - sizeof (struct InboundMessage)) || - (size < sizeof (struct GNUNET_MessageHeader))) - { - struct GNUNET_SERVICE_Client *client = cmc->tc->client; + if ((size > UINT16_MAX - sizeof(struct InboundMessage)) || + (size < sizeof(struct GNUNET_MessageHeader))) + { + struct GNUNET_SERVICE_Client *client = cmc->tc->client; - GNUNET_break (0); - finish_cmc_handling (cmc); - GNUNET_SERVICE_client_drop (client); - return; - } - vl = lookup_virtual_link (&cmc->im.sender); + GNUNET_break(0); + finish_cmc_handling(cmc); + GNUNET_SERVICE_client_drop(client); + return; + } + vl = lookup_virtual_link(&cmc->im.sender); if (NULL == vl) - { - /* FIXME: sender is giving us messages for CORE but we don't have - the link up yet! I *suspect* this can happen right now (i.e. - sender has verified us, but we didn't verify sender), but if - we pass this on, CORE would be confused (link down, messages - arrive). We should investigate more if this happens often, - or in a persistent manner, and possibly do "something" about - it. Thus logging as error for now. */ - GNUNET_break_op (0); - GNUNET_STATISTICS_update (GST_stats, - "# CORE messages droped (virtual link still down)", - 1, - GNUNET_NO); - - finish_cmc_handling (cmc); - return; - } + { + /* FIXME: sender is giving us messages for CORE but we don't have + the link up yet! I *suspect* this can happen right now (i.e. + sender has verified us, but we didn't verify sender), but if + we pass this on, CORE would be confused (link down, messages + arrive). We should investigate more if this happens often, + or in a persistent manner, and possibly do "something" about + it. Thus logging as error for now. */ + GNUNET_break_op(0); + GNUNET_STATISTICS_update(GST_stats, + "# CORE messages droped (virtual link still down)", + 1, + GNUNET_NO); + + finish_cmc_handling(cmc); + return; + } if (vl->incoming_fc_window_size_ram > UINT_MAX - size) - { - GNUNET_STATISTICS_update (GST_stats, - "# CORE messages droped (FC arithmetic overflow)", - 1, - GNUNET_NO); + { + GNUNET_STATISTICS_update(GST_stats, + "# CORE messages droped (FC arithmetic overflow)", + 1, + GNUNET_NO); - finish_cmc_handling (cmc); - return; - } + finish_cmc_handling(cmc); + return; + } if (vl->incoming_fc_window_size_ram + size > vl->available_fc_window_size) - { - GNUNET_STATISTICS_update (GST_stats, - "# CORE messages droped (FC window overflow)", - 1, - GNUNET_NO); - finish_cmc_handling (cmc); - return; - } + { + GNUNET_STATISTICS_update(GST_stats, + "# CORE messages droped (FC window overflow)", + 1, + GNUNET_NO); + finish_cmc_handling(cmc); + return; + } /* Forward to all CORE clients */ have_core = GNUNET_NO; for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - struct GNUNET_MQ_Envelope *env; - struct InboundMessage *im; - struct CoreSentContext *ctx; - - if (CT_CORE != tc->type) - continue; - vl->incoming_fc_window_size_ram += size; - env = GNUNET_MQ_msg_extra (im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); - ctx = GNUNET_new (struct CoreSentContext); - ctx->vl = vl; - ctx->size = size; - ctx->isize = (GNUNET_NO == have_core) ? size : 0; - have_core = GNUNET_YES; - GNUNET_CONTAINER_DLL_insert (vl->csc_head, vl->csc_tail, ctx); - GNUNET_MQ_notify_sent (env, &core_env_sent_cb, ctx); - im->peer = cmc->im.sender; - memcpy (&im[1], mh, size); - GNUNET_MQ_send (tc->mq, env); - vl->core_recv_window--; - } + { + struct GNUNET_MQ_Envelope *env; + struct InboundMessage *im; + struct CoreSentContext *ctx; + + if (CT_CORE != tc->type) + continue; + vl->incoming_fc_window_size_ram += size; + env = GNUNET_MQ_msg_extra(im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); + ctx = GNUNET_new(struct CoreSentContext); + ctx->vl = vl; + ctx->size = size; + ctx->isize = (GNUNET_NO == have_core) ? size : 0; + have_core = GNUNET_YES; + GNUNET_CONTAINER_DLL_insert(vl->csc_head, vl->csc_tail, ctx); + GNUNET_MQ_notify_sent(env, &core_env_sent_cb, ctx); + im->peer = cmc->im.sender; + memcpy(&im[1], mh, size); + GNUNET_MQ_send(tc->mq, env); + vl->core_recv_window--; + } if (GNUNET_NO == have_core) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Dropped message to CORE: no CORE client connected!\n"); - /* Nevertheless, count window as used, as it is from the - perspective of the other peer! */ - vl->incoming_fc_window_size_used += size; - /* TODO-M1 */ - finish_cmc_handling (cmc); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Delivered message from %s of type %u to CORE\n", - GNUNET_i2s (&cmc->im.sender), - ntohs (mh->type)); + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Dropped message to CORE: no CORE client connected!\n"); + /* Nevertheless, count window as used, as it is from the + perspective of the other peer! */ + vl->incoming_fc_window_size_used += size; + /* TODO-M1 */ + finish_cmc_handling(cmc); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Delivered message from %s of type %u to CORE\n", + GNUNET_i2s(&cmc->im.sender), + ntohs(mh->type)); if (vl->core_recv_window > 0) - { - finish_cmc_handling (cmc); - return; - } + { + finish_cmc_handling(cmc); + return; + } /* Wait with calling #finish_cmc_handling(cmc) until the message was processed by CORE MQs (for CORE flow control)! */ - GNUNET_CONTAINER_DLL_insert (vl->cmc_head, vl->cmc_tail, cmc); + GNUNET_CONTAINER_DLL_insert(vl->cmc_head, vl->cmc_tail, cmc); } @@ -5333,27 +5253,27 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh) * @return #GNUNET_YES if message is well-formed */ static int -check_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) +check_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb) { - uint16_t size = ntohs (fb->header.size); - uint16_t bsize = size - sizeof (*fb); + uint16_t size = ntohs(fb->header.size); + uint16_t bsize = size - sizeof(*fb); - (void) cls; + (void)cls; if (0 == bsize) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (bsize + ntohs (fb->frag_off) > ntohs (fb->msg_size)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (ntohs (fb->frag_off) >= ntohs (fb->msg_size)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + if (bsize + ntohs(fb->frag_off) > ntohs(fb->msg_size)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + if (ntohs(fb->frag_off) >= ntohs(fb->msg_size)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_YES; } @@ -5364,16 +5284,16 @@ check_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) * @param cls a `struct AcknowledgementCummulator *` */ static void -destroy_ack_cummulator (void *cls) +destroy_ack_cummulator(void *cls) { struct AcknowledgementCummulator *ac = cls; ac->task = NULL; - GNUNET_assert (0 == ac->num_acks); - GNUNET_assert ( + GNUNET_assert(0 == ac->num_acks); + GNUNET_assert( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (ack_cummulators, &ac->target, ac)); - GNUNET_free (ac); + GNUNET_CONTAINER_multipeermap_remove(ack_cummulators, &ac->target, ac)); + GNUNET_free(ac); } @@ -5383,39 +5303,39 @@ destroy_ack_cummulator (void *cls) * @param cls a `struct AcknowledgementCummulator *` */ static void -transmit_cummulative_ack_cb (void *cls) +transmit_cummulative_ack_cb(void *cls) { struct AcknowledgementCummulator *ac = cls; - char buf[sizeof (struct TransportReliabilityAckMessage) + + char buf[sizeof(struct TransportReliabilityAckMessage) + ac->ack_counter * - sizeof (struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN; + sizeof(struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN; struct TransportReliabilityAckMessage *ack = - (struct TransportReliabilityAckMessage *) buf; + (struct TransportReliabilityAckMessage *)buf; struct TransportCummulativeAckPayloadP *ap; ac->task = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending ACK with %u components to %s\n", - ac->ack_counter, - GNUNET_i2s (&ac->target)); - GNUNET_assert (0 < ac->ack_counter); - ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending ACK with %u components to %s\n", + ac->ack_counter, + GNUNET_i2s(&ac->target)); + GNUNET_assert(0 < ac->ack_counter); + ack->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); ack->header.size = - htons (sizeof (*ack) + - ac->ack_counter * sizeof (struct TransportCummulativeAckPayloadP)); - ack->ack_counter = htonl (ac->ack_counter++); - ap = (struct TransportCummulativeAckPayloadP *) &ack[1]; + htons(sizeof(*ack) + + ac->ack_counter * sizeof(struct TransportCummulativeAckPayloadP)); + ack->ack_counter = htonl(ac->ack_counter++); + ap = (struct TransportCummulativeAckPayloadP *)&ack[1]; for (unsigned int i = 0; i < ac->ack_counter; i++) - { - ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid; - ap[i].ack_delay = GNUNET_TIME_relative_hton ( - GNUNET_TIME_absolute_get_duration (ac->ack_uuids[i].receive_time)); - } - route_control_message_without_fc (&ac->target, &ack->header, RMO_DV_ALLOWED); + { + ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid; + ap[i].ack_delay = GNUNET_TIME_relative_hton( + GNUNET_TIME_absolute_get_duration(ac->ack_uuids[i].receive_time)); + } + route_control_message_without_fc(&ac->target, &ack->header, RMO_DV_ALLOWED); ac->num_acks = 0; - ac->task = GNUNET_SCHEDULER_add_delayed (ACK_CUMMULATOR_TIMEOUT, - &destroy_ack_cummulator, - ac); + ac->task = GNUNET_SCHEDULER_add_delayed(ACK_CUMMULATOR_TIMEOUT, + &destroy_ack_cummulator, + ac); } @@ -5428,56 +5348,55 @@ transmit_cummulative_ack_cb (void *cls) * @param max_delay how long can the ACK wait */ static void -cummulative_ack (const struct GNUNET_PeerIdentity *pid, - const struct AcknowledgementUUIDP *ack_uuid, - struct GNUNET_TIME_Absolute max_delay) +cummulative_ack(const struct GNUNET_PeerIdentity *pid, + const struct AcknowledgementUUIDP *ack_uuid, + struct GNUNET_TIME_Absolute max_delay) { struct AcknowledgementCummulator *ac; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Scheduling ACK %s for transmission to %s\n", - GNUNET_uuid2s (&ack_uuid->value), - GNUNET_i2s (pid)); - ac = GNUNET_CONTAINER_multipeermap_get (ack_cummulators, pid); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Scheduling ACK %s for transmission to %s\n", + GNUNET_uuid2s(&ack_uuid->value), + GNUNET_i2s(pid)); + ac = GNUNET_CONTAINER_multipeermap_get(ack_cummulators, pid); if (NULL == ac) - { - ac = GNUNET_new (struct AcknowledgementCummulator); - ac->target = *pid; - ac->min_transmission_time = max_delay; - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put ( - ack_cummulators, - &ac->target, - ac, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } + { + ac = GNUNET_new(struct AcknowledgementCummulator); + ac->target = *pid; + ac->min_transmission_time = max_delay; + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put( + ack_cummulators, + &ac->target, + ac, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } else - { - if (MAX_CUMMULATIVE_ACKS == ac->num_acks) { - /* must run immediately, ack buffer full! */ - GNUNET_SCHEDULER_cancel (ac->task); - transmit_cummulative_ack_cb (ac); + if (MAX_CUMMULATIVE_ACKS == ac->num_acks) + { + /* must run immediately, ack buffer full! */ + GNUNET_SCHEDULER_cancel(ac->task); + transmit_cummulative_ack_cb(ac); + } + GNUNET_SCHEDULER_cancel(ac->task); + ac->min_transmission_time = + GNUNET_TIME_absolute_min(ac->min_transmission_time, max_delay); } - GNUNET_SCHEDULER_cancel (ac->task); - ac->min_transmission_time = - GNUNET_TIME_absolute_min (ac->min_transmission_time, max_delay); - } - GNUNET_assert (ac->num_acks < MAX_CUMMULATIVE_ACKS); - ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get (); + GNUNET_assert(ac->num_acks < MAX_CUMMULATIVE_ACKS); + ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get(); ac->ack_uuids[ac->num_acks].ack_uuid = *ack_uuid; ac->num_acks++; - ac->task = GNUNET_SCHEDULER_add_at (ac->min_transmission_time, - &transmit_cummulative_ack_cb, - ac); + ac->task = GNUNET_SCHEDULER_add_at(ac->min_transmission_time, + &transmit_cummulative_ack_cb, + ac); } /** * Closure for #find_by_message_uuid. */ -struct FindByMessageUuidContext -{ +struct FindByMessageUuidContext { /** * UUID to look for. */ @@ -5500,17 +5419,17 @@ struct FindByMessageUuidContext * @return #GNUNET_YES if not found, #GNUNET_NO if found */ static int -find_by_message_uuid (void *cls, uint32_t key, void *value) +find_by_message_uuid(void *cls, uint32_t key, void *value) { struct FindByMessageUuidContext *fc = cls; struct ReassemblyContext *rc = value; - (void) key; - if (0 == GNUNET_memcmp (&fc->message_uuid, &rc->msg_uuid)) - { - fc->rc = rc; - return GNUNET_NO; - } + (void)key; + if (0 == GNUNET_memcmp(&fc->message_uuid, &rc->msg_uuid)) + { + fc->rc = rc; + return GNUNET_NO; + } return GNUNET_YES; } @@ -5523,7 +5442,7 @@ find_by_message_uuid (void *cls, uint32_t key, void *value) * @param fb the message that was received */ static void -handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) +handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb) { struct CommunicatorMessageContext *cmc = cls; struct Neighbour *n; @@ -5536,142 +5455,142 @@ handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) struct GNUNET_TIME_Relative cdelay; struct FindByMessageUuidContext fc; - n = lookup_neighbour (&cmc->im.sender); + n = lookup_neighbour(&cmc->im.sender); if (NULL == n) - { - struct GNUNET_SERVICE_Client *client = cmc->tc->client; + { + struct GNUNET_SERVICE_Client *client = cmc->tc->client; - GNUNET_break (0); - finish_cmc_handling (cmc); - GNUNET_SERVICE_client_drop (client); - return; - } + GNUNET_break(0); + finish_cmc_handling(cmc); + GNUNET_SERVICE_client_drop(client); + return; + } if (NULL == n->reassembly_map) - { - n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create (8); - n->reassembly_heap = - GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); - n->reassembly_timeout_task = - GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION, - &reassembly_cleanup_task, - n); - } - msize = ntohs (fb->msg_size); + { + n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create(8); + n->reassembly_heap = + GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); + n->reassembly_timeout_task = + GNUNET_SCHEDULER_add_delayed(REASSEMBLY_EXPIRATION, + &reassembly_cleanup_task, + n); + } + msize = ntohs(fb->msg_size); fc.message_uuid = fb->msg_uuid; fc.rc = NULL; - (void) GNUNET_CONTAINER_multihashmap32_get_multiple (n->reassembly_map, - fb->msg_uuid.uuid, - &find_by_message_uuid, - &fc); + (void)GNUNET_CONTAINER_multihashmap32_get_multiple(n->reassembly_map, + fb->msg_uuid.uuid, + &find_by_message_uuid, + &fc); if (NULL == (rc = fc.rc)) - { - rc = GNUNET_malloc (sizeof (*rc) + msize + /* reassembly payload buffer */ - (msize + 7) / 8 * sizeof (uint8_t) /* bitfield */); - rc->msg_uuid = fb->msg_uuid; - rc->neighbour = n; - rc->msg_size = msize; - rc->reassembly_timeout = - GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION); - rc->last_frag = GNUNET_TIME_absolute_get (); - rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap, - rc, - rc->reassembly_timeout.abs_value_us); - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap32_put ( - n->reassembly_map, - rc->msg_uuid.uuid, - rc, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - target = (char *) &rc[1]; - rc->bitfield = (uint8_t *) (target + rc->msg_size); - rc->msg_missing = rc->msg_size; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received fragment at offset %u/%u from %s for NEW message %u\n", - ntohs (fb->frag_off), - msize, - GNUNET_i2s (&cmc->im.sender), - (unsigned int) fb->msg_uuid.uuid); - } + { + rc = GNUNET_malloc(sizeof(*rc) + msize + /* reassembly payload buffer */ + (msize + 7) / 8 * sizeof(uint8_t) /* bitfield */); + rc->msg_uuid = fb->msg_uuid; + rc->neighbour = n; + rc->msg_size = msize; + rc->reassembly_timeout = + GNUNET_TIME_relative_to_absolute(REASSEMBLY_EXPIRATION); + rc->last_frag = GNUNET_TIME_absolute_get(); + rc->hn = GNUNET_CONTAINER_heap_insert(n->reassembly_heap, + rc, + rc->reassembly_timeout.abs_value_us); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multihashmap32_put( + n->reassembly_map, + rc->msg_uuid.uuid, + rc, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + target = (char *)&rc[1]; + rc->bitfield = (uint8_t *)(target + rc->msg_size); + rc->msg_missing = rc->msg_size; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received fragment at offset %u/%u from %s for NEW message %u\n", + ntohs(fb->frag_off), + msize, + GNUNET_i2s(&cmc->im.sender), + (unsigned int)fb->msg_uuid.uuid); + } else - { - target = (char *) &rc[1]; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received fragment at offset %u/%u from %s for message %u\n", - ntohs (fb->frag_off), - msize, - GNUNET_i2s (&cmc->im.sender), - (unsigned int) fb->msg_uuid.uuid); - } + { + target = (char *)&rc[1]; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received fragment at offset %u/%u from %s for message %u\n", + ntohs(fb->frag_off), + msize, + GNUNET_i2s(&cmc->im.sender), + (unsigned int)fb->msg_uuid.uuid); + } if (msize != rc->msg_size) - { - GNUNET_break (0); - finish_cmc_handling (cmc); - return; - } + { + GNUNET_break(0); + finish_cmc_handling(cmc); + return; + } /* reassemble */ - fsize = ntohs (fb->header.size) - sizeof (*fb); + fsize = ntohs(fb->header.size) - sizeof(*fb); if (0 == fsize) - { - GNUNET_break (0); - finish_cmc_handling (cmc); - return; - } - frag_off = ntohs (fb->frag_off); + { + GNUNET_break(0); + finish_cmc_handling(cmc); + return; + } + frag_off = ntohs(fb->frag_off); if (frag_off + fsize > msize) - { - /* Fragment (plus fragment size) exceeds message size! */ - GNUNET_break_op (0); - finish_cmc_handling (cmc); - return; - } - memcpy (&target[frag_off], &fb[1], fsize); + { + /* Fragment (plus fragment size) exceeds message size! */ + GNUNET_break_op(0); + finish_cmc_handling(cmc); + return; + } + memcpy(&target[frag_off], &fb[1], fsize); /* update bitfield and msg_missing */ for (unsigned int i = frag_off; i < frag_off + fsize; i++) - { - if (0 == (rc->bitfield[i / 8] & (1 << (i % 8)))) { - rc->bitfield[i / 8] |= (1 << (i % 8)); - rc->msg_missing--; + if (0 == (rc->bitfield[i / 8] & (1 << (i % 8)))) + { + rc->bitfield[i / 8] |= (1 << (i % 8)); + rc->msg_missing--; + } } - } /* Compute cummulative ACK */ - cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag); - cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->msg_missing / fsize); + cdelay = GNUNET_TIME_absolute_get_duration(rc->last_frag); + cdelay = GNUNET_TIME_relative_multiply(cdelay, rc->msg_missing / fsize); if (0 == rc->msg_missing) cdelay = GNUNET_TIME_UNIT_ZERO; - cummulative_ack (&cmc->im.sender, - &fb->ack_uuid, - GNUNET_TIME_relative_to_absolute (cdelay)); - rc->last_frag = GNUNET_TIME_absolute_get (); + cummulative_ack(&cmc->im.sender, + &fb->ack_uuid, + GNUNET_TIME_relative_to_absolute(cdelay)); + rc->last_frag = GNUNET_TIME_absolute_get(); /* is reassembly complete? */ if (0 != rc->msg_missing) - { - finish_cmc_handling (cmc); - return; - } + { + finish_cmc_handling(cmc); + return; + } /* reassembly is complete, verify result */ - msg = (const struct GNUNET_MessageHeader *) &rc[1]; - if (ntohs (msg->size) != rc->msg_size) - { - GNUNET_break (0); - free_reassembly_context (rc); - finish_cmc_handling (cmc); - return; - } + msg = (const struct GNUNET_MessageHeader *)&rc[1]; + if (ntohs(msg->size) != rc->msg_size) + { + GNUNET_break(0); + free_reassembly_context(rc); + finish_cmc_handling(cmc); + return; + } /* successful reassembly */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Fragment reassembly complete for message %u\n", - (unsigned int) fb->msg_uuid.uuid); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Fragment reassembly complete for message %u\n", + (unsigned int)fb->msg_uuid.uuid); /* FIXME: check that the resulting msg is NOT a DV Box or Reliability Box, as that is NOT allowed! */ - demultiplex_with_cmc (cmc, msg); + demultiplex_with_cmc(cmc, msg); /* FIXME-OPTIMIZE: really free here? Might be bad if fragments are still en-route and we forget that we finished this reassembly immediately! -> keep around until timeout? -> shorten timeout based on ACK? */ - free_reassembly_context (rc); + free_reassembly_context(rc); } @@ -5683,11 +5602,11 @@ handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) * @return #GNUNET_YES if message is well-formed */ static int -check_reliability_box (void *cls, - const struct TransportReliabilityBoxMessage *rb) +check_reliability_box(void *cls, + const struct TransportReliabilityBoxMessage *rb) { - (void) cls; - GNUNET_MQ_check_boxed_message (rb); + (void)cls; + GNUNET_MQ_check_boxed_message(rb); return GNUNET_YES; } @@ -5700,34 +5619,34 @@ check_reliability_box (void *cls, * @param rb the message that was received */ static void -handle_reliability_box (void *cls, - const struct TransportReliabilityBoxMessage *rb) +handle_reliability_box(void *cls, + const struct TransportReliabilityBoxMessage *rb) { struct CommunicatorMessageContext *cmc = cls; const struct GNUNET_MessageHeader *inbox = - (const struct GNUNET_MessageHeader *) &rb[1]; + (const struct GNUNET_MessageHeader *)&rb[1]; struct GNUNET_TIME_Relative rtt; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received reliability box from %s with UUID %s of type %u\n", - GNUNET_i2s (&cmc->im.sender), - GNUNET_uuid2s (&rb->ack_uuid.value), - (unsigned int) ntohs (inbox->type)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received reliability box from %s with UUID %s of type %u\n", + GNUNET_i2s(&cmc->im.sender), + GNUNET_uuid2s(&rb->ack_uuid.value), + (unsigned int)ntohs(inbox->type)); rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we do not really have an RTT for the - *incoming* queue (should we have + * incoming* queue (should we have the sender add it to the rb message?) */ - cummulative_ack ( + cummulative_ack( &cmc->im.sender, &rb->ack_uuid, - (0 == ntohl (rb->ack_countdown)) - ? GNUNET_TIME_UNIT_ZERO_ABS - : GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_relative_divide (rtt, 8 /* FIXME: magic constant */))); + (0 == ntohl(rb->ack_countdown)) + ? GNUNET_TIME_UNIT_ZERO_ABS + : GNUNET_TIME_relative_to_absolute( + GNUNET_TIME_relative_divide(rtt, 8 /* FIXME: magic constant */))); /* continue with inner message */ /* FIXME: check that inbox is NOT a DV Box, fragment or another reliability box (not allowed!) */ - demultiplex_with_cmc (cmc, inbox); + demultiplex_with_cmc(cmc, inbox); } @@ -5740,20 +5659,20 @@ handle_reliability_box (void *cls, * @param age current age */ static void -update_pd_age (struct PerformanceData *pd, unsigned int age) +update_pd_age(struct PerformanceData *pd, unsigned int age) { unsigned int sage; if (age == pd->last_age) return; /* nothing to do */ - sage = GNUNET_MAX (pd->last_age, age - 2 * GOODPUT_AGING_SLOTS); + sage = GNUNET_MAX(pd->last_age, age - 2 * GOODPUT_AGING_SLOTS); for (unsigned int i = sage; i <= age - GOODPUT_AGING_SLOTS; i++) - { - struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS]; + { + struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS]; - the->bytes_sent = 0; - the->bytes_received = 0; - } + the->bytes_sent = 0; + the->bytes_received = 0; + } pd->last_age = age; } @@ -5767,20 +5686,20 @@ update_pd_age (struct PerformanceData *pd, unsigned int age) * @param bytes_transmitted_ok number of bytes receiver confirmed as received */ static void -update_performance_data (struct PerformanceData *pd, - struct GNUNET_TIME_Relative rtt, - uint16_t bytes_transmitted_ok) +update_performance_data(struct PerformanceData *pd, + struct GNUNET_TIME_Relative rtt, + uint16_t bytes_transmitted_ok) { uint64_t nval = rtt.rel_value_us; uint64_t oval = pd->aged_rtt.rel_value_us; - unsigned int age = get_age (); + unsigned int age = get_age(); struct TransmissionHistoryEntry *the = &pd->the[age % GOODPUT_AGING_SLOTS]; if (oval == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) pd->aged_rtt = rtt; else pd->aged_rtt.rel_value_us = (nval + 7 * oval) / 8; - update_pd_age (pd, age); + update_pd_age(pd, age); the->bytes_received += bytes_transmitted_ok; } @@ -5793,11 +5712,11 @@ update_performance_data (struct PerformanceData *pd, * @param bytes_transmitted_ok number of bytes successfully transmitted */ static void -update_queue_performance (struct Queue *q, - struct GNUNET_TIME_Relative rtt, - uint16_t bytes_transmitted_ok) +update_queue_performance(struct Queue *q, + struct GNUNET_TIME_Relative rtt, + uint16_t bytes_transmitted_ok) { - update_performance_data (&q->pd, rtt, bytes_transmitted_ok); + update_performance_data(&q->pd, rtt, bytes_transmitted_ok); } @@ -5809,11 +5728,11 @@ update_queue_performance (struct Queue *q, * @param bytes_transmitted_ok number of bytes successfully transmitted */ static void -update_dvh_performance (struct DistanceVectorHop *dvh, - struct GNUNET_TIME_Relative rtt, - uint16_t bytes_transmitted_ok) +update_dvh_performance(struct DistanceVectorHop *dvh, + struct GNUNET_TIME_Relative rtt, + uint16_t bytes_transmitted_ok) { - update_performance_data (&dvh->pd, rtt, bytes_transmitted_ok); + update_performance_data(&dvh->pd, rtt, bytes_transmitted_ok); } @@ -5825,45 +5744,47 @@ update_dvh_performance (struct DistanceVectorHop *dvh, * @param pm pending message that was transmitted */ static void -completed_pending_message (struct PendingMessage *pm) +completed_pending_message(struct PendingMessage *pm) { struct PendingMessage *pos; switch (pm->pmt) - { - case PMT_CORE: - case PMT_RELIABILITY_BOX: - /* Full message sent, we are done */ - client_send_response (pm); - return; - case PMT_FRAGMENT_BOX: - /* Fragment sent over reliabile channel */ - free_fragment_tree (pm); - pos = pm->frag_parent; - GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm); - GNUNET_free (pm); - /* check if subtree is done */ - while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) && - (pos != pm)) - { - pm = pos; + { + case PMT_CORE: + case PMT_RELIABILITY_BOX: + /* Full message sent, we are done */ + client_send_response(pm); + return; + + case PMT_FRAGMENT_BOX: + /* Fragment sent over reliabile channel */ + free_fragment_tree(pm); pos = pm->frag_parent; - GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm); - GNUNET_free (pm); - } + GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm); + GNUNET_free(pm); + /* check if subtree is done */ + while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) && + (pos != pm)) + { + pm = pos; + pos = pm->frag_parent; + GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm); + GNUNET_free(pm); + } - /* Was this the last applicable fragmment? */ - if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) && - (pos->frag_off == pos->bytes_msg)) - client_send_response (pos); - return; - case PMT_DV_BOX: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Completed transmission of message %llu (DV Box)\n", - pm->logging_uuid); - free_pending_message (pm); - return; - } + /* Was this the last applicable fragmment? */ + if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) && + (pos->frag_off == pos->bytes_msg)) + client_send_response(pos); + return; + + case PMT_DV_BOX: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Completed transmission of message %llu (DV Box)\n", + pm->logging_uuid); + free_pending_message(pm); + return; + } } @@ -5875,23 +5796,23 @@ completed_pending_message (struct PendingMessage *pm) * other peer */ static void -handle_acknowledged (struct PendingAcknowledgement *pa, - struct GNUNET_TIME_Relative ack_delay) +handle_acknowledged(struct PendingAcknowledgement *pa, + struct GNUNET_TIME_Relative ack_delay) { struct GNUNET_TIME_Relative delay; - delay = GNUNET_TIME_absolute_get_duration (pa->transmission_time); + delay = GNUNET_TIME_absolute_get_duration(pa->transmission_time); if (delay.rel_value_us > ack_delay.rel_value_us) delay = GNUNET_TIME_UNIT_ZERO; else - delay = GNUNET_TIME_relative_subtract (delay, ack_delay); + delay = GNUNET_TIME_relative_subtract(delay, ack_delay); if (NULL != pa->queue) - update_queue_performance (pa->queue, delay, pa->message_size); + update_queue_performance(pa->queue, delay, pa->message_size); if (NULL != pa->dvh) - update_dvh_performance (pa->dvh, delay, pa->message_size); + update_dvh_performance(pa->dvh, delay, pa->message_size); if (NULL != pa->pm) - completed_pending_message (pa->pm); - free_pending_acknowledgement (pa); + completed_pending_message(pa->pm); + free_pending_acknowledgement(pa); } @@ -5903,25 +5824,25 @@ handle_acknowledged (struct PendingAcknowledgement *pa, * @return #GNUNET_Ok if @a ra is well-formed */ static int -check_reliability_ack (void *cls, - const struct TransportReliabilityAckMessage *ra) +check_reliability_ack(void *cls, + const struct TransportReliabilityAckMessage *ra) { unsigned int n_acks; - (void) cls; - n_acks = (ntohs (ra->header.size) - sizeof (*ra)) / - sizeof (struct TransportCummulativeAckPayloadP); + (void)cls; + n_acks = (ntohs(ra->header.size) - sizeof(*ra)) / + sizeof(struct TransportCummulativeAckPayloadP); if (0 == n_acks) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if ((ntohs (ra->header.size) - sizeof (*ra)) != - n_acks * sizeof (struct TransportCummulativeAckPayloadP)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + if ((ntohs(ra->header.size) - sizeof(*ra)) != + n_acks * sizeof(struct TransportCummulativeAckPayloadP)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -5934,46 +5855,46 @@ check_reliability_ack (void *cls, * @param ra the message that was received */ static void -handle_reliability_ack (void *cls, - const struct TransportReliabilityAckMessage *ra) +handle_reliability_ack(void *cls, + const struct TransportReliabilityAckMessage *ra) { struct CommunicatorMessageContext *cmc = cls; const struct TransportCummulativeAckPayloadP *ack; unsigned int n_acks; uint32_t ack_counter; - n_acks = (ntohs (ra->header.size) - sizeof (*ra)) / - sizeof (struct TransportCummulativeAckPayloadP); - ack = (const struct TransportCummulativeAckPayloadP *) &ra[1]; + n_acks = (ntohs(ra->header.size) - sizeof(*ra)) / + sizeof(struct TransportCummulativeAckPayloadP); + ack = (const struct TransportCummulativeAckPayloadP *)&ra[1]; for (unsigned int i = 0; i < n_acks; i++) - { - struct PendingAcknowledgement *pa = - GNUNET_CONTAINER_multiuuidmap_get (pending_acks, &ack[i].ack_uuid.value); - if (NULL == pa) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received ACK from %s with UUID %s which is unknown to us!\n", - GNUNET_i2s (&cmc->im.sender), - GNUNET_uuid2s (&ack[i].ack_uuid.value)); - GNUNET_STATISTICS_update ( - GST_stats, - "# FRAGMENT_ACKS dropped, no matching pending message", - 1, - GNUNET_NO); - continue; + { + struct PendingAcknowledgement *pa = + GNUNET_CONTAINER_multiuuidmap_get(pending_acks, &ack[i].ack_uuid.value); + if (NULL == pa) + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Received ACK from %s with UUID %s which is unknown to us!\n", + GNUNET_i2s(&cmc->im.sender), + GNUNET_uuid2s(&ack[i].ack_uuid.value)); + GNUNET_STATISTICS_update( + GST_stats, + "# FRAGMENT_ACKS dropped, no matching pending message", + 1, + GNUNET_NO); + continue; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received ACK from %s with UUID %s\n", + GNUNET_i2s(&cmc->im.sender), + GNUNET_uuid2s(&ack[i].ack_uuid.value)); + handle_acknowledged(pa, GNUNET_TIME_relative_ntoh(ack[i].ack_delay)); } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received ACK from %s with UUID %s\n", - GNUNET_i2s (&cmc->im.sender), - GNUNET_uuid2s (&ack[i].ack_uuid.value)); - handle_acknowledged (pa, GNUNET_TIME_relative_ntoh (ack[i].ack_delay)); - } - ack_counter = htonl (ra->ack_counter); - (void) ack_counter; /* silence compiler warning for now */ + ack_counter = htonl(ra->ack_counter); + (void)ack_counter; /* silence compiler warning for now */ // FIXME-OPTIMIZE: track ACK losses based on ack_counter somewhere! // (DV and/or Neighbour?) - finish_cmc_handling (cmc); + finish_cmc_handling(cmc); } @@ -5985,30 +5906,30 @@ handle_reliability_ack (void *cls, * @return #GNUNET_YES if message is well-formed */ static int -check_backchannel_encapsulation ( +check_backchannel_encapsulation( void *cls, const struct TransportBackchannelEncapsulationMessage *be) { - uint16_t size = ntohs (be->header.size) - sizeof (*be); + uint16_t size = ntohs(be->header.size) - sizeof(*be); const struct GNUNET_MessageHeader *inbox = - (const struct GNUNET_MessageHeader *) &be[1]; + (const struct GNUNET_MessageHeader *)&be[1]; const char *is; uint16_t isize; - (void) cls; - if (ntohs (inbox->size) >= size) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - isize = ntohs (inbox->size); - is = ((const char *) inbox) + isize; + (void)cls; + if (ntohs(inbox->size) >= size) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + isize = ntohs(inbox->size); + is = ((const char *)inbox) + isize; size -= isize; if ('\0' != is[size - 1]) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_YES; } @@ -6022,7 +5943,7 @@ check_backchannel_encapsulation ( * @param be the message that was received */ static void -handle_backchannel_encapsulation ( +handle_backchannel_encapsulation( void *cls, const struct TransportBackchannelEncapsulationMessage *be) { @@ -6031,41 +5952,41 @@ handle_backchannel_encapsulation ( struct GNUNET_MQ_Envelope *env; struct TransportClient *tc; const struct GNUNET_MessageHeader *inbox = - (const struct GNUNET_MessageHeader *) &be[1]; - uint16_t isize = ntohs (inbox->size); - const char *target_communicator = ((const char *) inbox) + isize; + (const struct GNUNET_MessageHeader *)&be[1]; + uint16_t isize = ntohs(inbox->size); + const char *target_communicator = ((const char *)inbox) + isize; /* Find client providing this communicator */ for (tc = clients_head; NULL != tc; tc = tc->next) if ((CT_COMMUNICATOR == tc->type) && (0 == - strcmp (tc->details.communicator.address_prefix, target_communicator))) + strcmp(tc->details.communicator.address_prefix, target_communicator))) break; if (NULL == tc) - { - char *stastr; - - GNUNET_asprintf ( - &stastr, - "# Backchannel message dropped: target communicator `%s' unknown", - target_communicator); - GNUNET_STATISTICS_update (GST_stats, stastr, 1, GNUNET_NO); - GNUNET_free (stastr); - return; - } + { + char *stastr; + + GNUNET_asprintf( + &stastr, + "# Backchannel message dropped: target communicator `%s' unknown", + target_communicator); + GNUNET_STATISTICS_update(GST_stats, stastr, 1, GNUNET_NO); + GNUNET_free(stastr); + return; + } /* Finally, deliver backchannel message to communicator */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Delivering backchannel message from %s of type %u to %s\n", - GNUNET_i2s (&cmc->im.sender), - ntohs (inbox->type), - target_communicator); - env = GNUNET_MQ_msg_extra ( + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Delivering backchannel message from %s of type %u to %s\n", + GNUNET_i2s(&cmc->im.sender), + ntohs(inbox->type), + target_communicator); + env = GNUNET_MQ_msg_extra( cbi, isize, GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING); cbi->pid = cmc->im.sender; - memcpy (&cbi[1], inbox, isize); - GNUNET_MQ_send (tc->mq, env); + memcpy(&cbi[1], inbox, isize); + GNUNET_MQ_send(tc->mq, env); } @@ -6079,26 +6000,26 @@ handle_backchannel_encapsulation ( * @param cls a `struct DistanceVector` */ static void -path_cleanup_cb (void *cls) +path_cleanup_cb(void *cls) { struct DistanceVector *dv = cls; struct DistanceVectorHop *pos; dv->timeout_task = NULL; while (NULL != (pos = dv->dv_head)) - { - GNUNET_assert (dv == pos->dv); - if (GNUNET_TIME_absolute_get_remaining (pos->timeout).rel_value_us > 0) - break; - free_distance_vector_hop (pos); - } + { + GNUNET_assert(dv == pos->dv); + if (GNUNET_TIME_absolute_get_remaining(pos->timeout).rel_value_us > 0) + break; + free_distance_vector_hop(pos); + } if (NULL == pos) - { - free_dv_route (dv); - return; - } + { + free_dv_route(dv); + return; + } dv->timeout_task = - GNUNET_SCHEDULER_add_at (pos->timeout, &path_cleanup_cb, dv); + GNUNET_SCHEDULER_add_at(pos->timeout, &path_cleanup_cb, dv); } @@ -6110,44 +6031,44 @@ path_cleanup_cb (void *cls) * @param hop a path to some peer that is the reason for activation */ static void -activate_core_visible_dv_path (struct DistanceVectorHop *hop) +activate_core_visible_dv_path(struct DistanceVectorHop *hop) { struct DistanceVector *dv = hop->dv; struct VirtualLink *vl; - vl = lookup_virtual_link (&dv->target); + vl = lookup_virtual_link(&dv->target); if (NULL != vl) - { - /* Link was already up, remember dv is also now available and we are done */ - vl->dv = dv; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Virtual link to %s could now also use DV!\n", - GNUNET_i2s (&dv->target)); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating new virtual link to %s using DV!\n", - GNUNET_i2s (&dv->target)); - vl = GNUNET_new (struct VirtualLink); + { + /* Link was already up, remember dv is also now available and we are done */ + vl->dv = dv; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Virtual link to %s could now also use DV!\n", + GNUNET_i2s(&dv->target)); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Creating new virtual link to %s using DV!\n", + GNUNET_i2s(&dv->target)); + vl = GNUNET_new(struct VirtualLink); vl->message_uuid_ctr = - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); + GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); vl->target = dv->target; vl->dv = dv; dv->vl = vl; vl->core_recv_window = RECV_WINDOW_SIZE; vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; vl->visibility_task = - GNUNET_SCHEDULER_add_at (hop->path_valid_until, &check_link_down, vl); - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put ( - links, - &vl->target, - vl, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - consider_sending_fc (vl); + GNUNET_SCHEDULER_add_at(hop->path_valid_until, &check_link_down, vl); + GNUNET_break(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put( + links, + &vl->target, + vl, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + consider_sending_fc(vl); /* We lacked a confirmed connection to the target before, so tell CORE about it (finally!) */ - cores_send_connect_info (&dv->target); + cores_send_connect_info(&dv->target); } @@ -6177,10 +6098,10 @@ activate_core_visible_dv_path (struct DistanceVectorHop *hop) * or path[i+1] is a direct neighbour for i>0) */ static int -learn_dv_path (const struct GNUNET_PeerIdentity *path, - unsigned int path_len, - struct GNUNET_TIME_Relative network_latency, - struct GNUNET_TIME_Absolute path_valid_until) +learn_dv_path(const struct GNUNET_PeerIdentity *path, + unsigned int path_len, + struct GNUNET_TIME_Relative network_latency, + struct GNUNET_TIME_Absolute path_valid_until) { struct DistanceVectorHop *hop; struct DistanceVector *dv; @@ -6188,143 +6109,143 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path, unsigned int shorter_distance; if (path_len < 3) - { - /* what a boring path! not allowed! */ - GNUNET_break (0); - return GNUNET_SYSERR; - } - GNUNET_assert (0 == GNUNET_memcmp (&GST_my_identity, &path[0])); - next_hop = lookup_neighbour (&path[1]); + { + /* what a boring path! not allowed! */ + GNUNET_break(0); + return GNUNET_SYSERR; + } + GNUNET_assert(0 == GNUNET_memcmp(&GST_my_identity, &path[0])); + next_hop = lookup_neighbour(&path[1]); if (NULL == next_hop) - { - /* next hop must be a neighbour, otherwise this whole thing is useless! */ - GNUNET_break (0); - return GNUNET_SYSERR; - } - for (unsigned int i = 2; i < path_len; i++) - if (NULL != lookup_neighbour (&path[i])) - { - /* Useless path: we have a direct connection to some hop - in the middle of the path, so this one is not even - terribly useful for redundancy */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Path of %u hops useless: directly link to hop %u (%s)\n", - path_len, - i, - GNUNET_i2s (&path[i])); - GNUNET_STATISTICS_update (GST_stats, - "# Useless DV path ignored: hop is neighbour", - 1, - GNUNET_NO); + { + /* next hop must be a neighbour, otherwise this whole thing is useless! */ + GNUNET_break(0); return GNUNET_SYSERR; } - dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &path[path_len - 1]); + for (unsigned int i = 2; i < path_len; i++) + if (NULL != lookup_neighbour(&path[i])) + { + /* Useless path: we have a direct connection to some hop + in the middle of the path, so this one is not even + terribly useful for redundancy */ + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Path of %u hops useless: directly link to hop %u (%s)\n", + path_len, + i, + GNUNET_i2s(&path[i])); + GNUNET_STATISTICS_update(GST_stats, + "# Useless DV path ignored: hop is neighbour", + 1, + GNUNET_NO); + return GNUNET_SYSERR; + } + dv = GNUNET_CONTAINER_multipeermap_get(dv_routes, &path[path_len - 1]); if (NULL == dv) - { - dv = GNUNET_new (struct DistanceVector); - dv->target = path[path_len - 1]; - dv->timeout_task = GNUNET_SCHEDULER_add_delayed (DV_PATH_VALIDITY_TIMEOUT, - &path_cleanup_cb, - dv); - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put ( - dv_routes, - &dv->target, - dv, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } + { + dv = GNUNET_new(struct DistanceVector); + dv->target = path[path_len - 1]; + dv->timeout_task = GNUNET_SCHEDULER_add_delayed(DV_PATH_VALIDITY_TIMEOUT, + &path_cleanup_cb, + dv); + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put( + dv_routes, + &dv->target, + dv, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } /* Check if we have this path already! */ shorter_distance = 0; for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; pos = pos->next_dv) - { - if (pos->distance < path_len - 2) - shorter_distance++; - /* Note that the distances in 'pos' excludes us (path[0]) and - the next_hop (path[1]), so we need to subtract two - and check next_hop explicitly */ - if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop)) { - int match = GNUNET_YES; - - for (unsigned int i = 0; i < pos->distance; i++) - { - if (0 != GNUNET_memcmp (&pos->path[i], &path[i + 2])) + if (pos->distance < path_len - 2) + shorter_distance++; + /* Note that the distances in 'pos' excludes us (path[0]) and + the next_hop (path[1]), so we need to subtract two + and check next_hop explicitly */ + if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop)) { - match = GNUNET_NO; - break; + int match = GNUNET_YES; + + for (unsigned int i = 0; i < pos->distance; i++) + { + if (0 != GNUNET_memcmp(&pos->path[i], &path[i + 2])) + { + match = GNUNET_NO; + break; + } + } + if (GNUNET_YES == match) + { + struct GNUNET_TIME_Relative last_timeout; + + /* Re-discovered known path, update timeout */ + GNUNET_STATISTICS_update(GST_stats, + "# Known DV path refreshed", + 1, + GNUNET_NO); + last_timeout = GNUNET_TIME_absolute_get_remaining(pos->timeout); + pos->timeout = + GNUNET_TIME_relative_to_absolute(DV_PATH_VALIDITY_TIMEOUT); + pos->path_valid_until = + GNUNET_TIME_absolute_max(pos->path_valid_until, path_valid_until); + GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, pos); + GNUNET_CONTAINER_MDLL_insert(dv, dv->dv_head, dv->dv_tail, pos); + if (0 < + GNUNET_TIME_absolute_get_remaining(path_valid_until).rel_value_us) + activate_core_visible_dv_path(pos); + if (last_timeout.rel_value_us < + GNUNET_TIME_relative_subtract(DV_PATH_VALIDITY_TIMEOUT, + DV_PATH_DISCOVERY_FREQUENCY) + .rel_value_us) + { + /* Some peer send DV learn messages too often, we are learning + the same path faster than it would be useful; do not forward! */ + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Rediscovered path too quickly, not forwarding further\n"); + return GNUNET_NO; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Refreshed known path to %s, forwarding further\n", + GNUNET_i2s(&dv->target)); + return GNUNET_YES; + } } - } - if (GNUNET_YES == match) - { - struct GNUNET_TIME_Relative last_timeout; - - /* Re-discovered known path, update timeout */ - GNUNET_STATISTICS_update (GST_stats, - "# Known DV path refreshed", - 1, - GNUNET_NO); - last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout); - pos->timeout = - GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); - pos->path_valid_until = - GNUNET_TIME_absolute_max (pos->path_valid_until, path_valid_until); - GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, pos); - GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, pos); - if (0 < - GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us) - activate_core_visible_dv_path (pos); - if (last_timeout.rel_value_us < - GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT, - DV_PATH_DISCOVERY_FREQUENCY) - .rel_value_us) - { - /* Some peer send DV learn messages too often, we are learning - the same path faster than it would be useful; do not forward! */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Rediscovered path too quickly, not forwarding further\n"); - return GNUNET_NO; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Refreshed known path to %s, forwarding further\n", - GNUNET_i2s (&dv->target)); - return GNUNET_YES; - } } - } /* Count how many shorter paths we have (incl. direct neighbours) before simply giving up on this one! */ if (shorter_distance >= MAX_DV_PATHS_TO_TARGET) - { - /* We have a shorter path already! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Have many shorter DV paths %s, not forwarding further\n", - GNUNET_i2s (&dv->target)); - return GNUNET_NO; - } + { + /* We have a shorter path already! */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Have many shorter DV paths %s, not forwarding further\n", + GNUNET_i2s(&dv->target)); + return GNUNET_NO; + } /* create new DV path entry */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Discovered new DV path to %s\n", - GNUNET_i2s (&dv->target)); - hop = GNUNET_malloc (sizeof (struct DistanceVectorHop) + - sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Discovered new DV path to %s\n", + GNUNET_i2s(&dv->target)); + hop = GNUNET_malloc(sizeof(struct DistanceVectorHop) + + sizeof(struct GNUNET_PeerIdentity) * (path_len - 2)); hop->next_hop = next_hop; hop->dv = dv; - hop->path = (const struct GNUNET_PeerIdentity *) &hop[1]; - memcpy (&hop[1], - &path[2], - sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); - hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); + hop->path = (const struct GNUNET_PeerIdentity *)&hop[1]; + memcpy(&hop[1], + &path[2], + sizeof(struct GNUNET_PeerIdentity) * (path_len - 2)); + hop->timeout = GNUNET_TIME_relative_to_absolute(DV_PATH_VALIDITY_TIMEOUT); hop->path_valid_until = path_valid_until; hop->distance = path_len - 2; hop->pd.aged_rtt = network_latency; - GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, hop); - GNUNET_CONTAINER_MDLL_insert (neighbour, - next_hop->dv_head, - next_hop->dv_tail, - hop); - if (0 < GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us) - activate_core_visible_dv_path (hop); + GNUNET_CONTAINER_MDLL_insert(dv, dv->dv_head, dv->dv_tail, hop); + GNUNET_CONTAINER_MDLL_insert(neighbour, + next_hop->dv_head, + next_hop->dv_tail, + hop); + if (0 < GNUNET_TIME_absolute_get_remaining(path_valid_until).rel_value_us) + activate_core_visible_dv_path(hop); return GNUNET_YES; } @@ -6337,36 +6258,36 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path, * @return #GNUNET_YES if message is well-formed */ static int -check_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) +check_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl) { - uint16_t size = ntohs (dvl->header.size); - uint16_t num_hops = ntohs (dvl->num_hops); - const struct DVPathEntryP *hops = (const struct DVPathEntryP *) &dvl[1]; + uint16_t size = ntohs(dvl->header.size); + uint16_t num_hops = ntohs(dvl->num_hops); + const struct DVPathEntryP *hops = (const struct DVPathEntryP *)&dvl[1]; - (void) cls; - if (size != sizeof (*dvl) + num_hops * sizeof (struct DVPathEntryP)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - if (num_hops > MAX_DV_HOPS_ALLOWED) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - for (unsigned int i = 0; i < num_hops; i++) - { - if (0 == GNUNET_memcmp (&dvl->initiator, &hops[i].hop)) + (void)cls; + if (size != sizeof(*dvl) + num_hops * sizeof(struct DVPathEntryP)) { - GNUNET_break_op (0); + GNUNET_break_op(0); return GNUNET_SYSERR; } - if (0 == GNUNET_memcmp (&GST_my_identity, &hops[i].hop)) + if (num_hops > MAX_DV_HOPS_ALLOWED) { - GNUNET_break_op (0); + GNUNET_break_op(0); return GNUNET_SYSERR; } - } + for (unsigned int i = 0; i < num_hops; i++) + { + if (0 == GNUNET_memcmp(&dvl->initiator, &hops[i].hop)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + if (0 == GNUNET_memcmp(&GST_my_identity, &hops[i].hop)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } + } return GNUNET_YES; } @@ -6383,56 +6304,56 @@ check_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) * delay */ static void -forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, - const struct TransportDVLearnMessage *msg, - uint16_t bi_history, - uint16_t nhops, - const struct DVPathEntryP *hops, - struct GNUNET_TIME_Absolute in_time) +forward_dv_learn(const struct GNUNET_PeerIdentity *next_hop, + const struct TransportDVLearnMessage *msg, + uint16_t bi_history, + uint16_t nhops, + const struct DVPathEntryP *hops, + struct GNUNET_TIME_Absolute in_time) { struct DVPathEntryP *dhops; - char buf[sizeof (struct TransportDVLearnMessage) + - (nhops + 1) * sizeof (struct DVPathEntryP)] GNUNET_ALIGN; - struct TransportDVLearnMessage *fwd = (struct TransportDVLearnMessage *) buf; + char buf[sizeof(struct TransportDVLearnMessage) + + (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN; + struct TransportDVLearnMessage *fwd = (struct TransportDVLearnMessage *)buf; struct GNUNET_TIME_Relative nnd; /* compute message for forwarding */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Forwarding DV learn message originating from %s to %s\n", - GNUNET_i2s (&msg->initiator), - GNUNET_i2s2 (next_hop)); - GNUNET_assert (nhops < MAX_DV_HOPS_ALLOWED); - fwd->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); - fwd->header.size = htons (sizeof (struct TransportDVLearnMessage) + - (nhops + 1) * sizeof (struct DVPathEntryP)); - fwd->num_hops = htons (nhops + 1); - fwd->bidirectional = htons (bi_history); - nnd = GNUNET_TIME_relative_add (GNUNET_TIME_absolute_get_duration (in_time), - GNUNET_TIME_relative_ntoh ( - msg->non_network_delay)); - fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Forwarding DV learn message originating from %s to %s\n", + GNUNET_i2s(&msg->initiator), + GNUNET_i2s2(next_hop)); + GNUNET_assert(nhops < MAX_DV_HOPS_ALLOWED); + fwd->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); + fwd->header.size = htons(sizeof(struct TransportDVLearnMessage) + + (nhops + 1) * sizeof(struct DVPathEntryP)); + fwd->num_hops = htons(nhops + 1); + fwd->bidirectional = htons(bi_history); + nnd = GNUNET_TIME_relative_add(GNUNET_TIME_absolute_get_duration(in_time), + GNUNET_TIME_relative_ntoh( + msg->non_network_delay)); + fwd->non_network_delay = GNUNET_TIME_relative_hton(nnd); fwd->init_sig = msg->init_sig; fwd->initiator = msg->initiator; fwd->challenge = msg->challenge; - dhops = (struct DVPathEntryP *) &fwd[1]; - GNUNET_memcpy (dhops, hops, sizeof (struct DVPathEntryP) * nhops); + dhops = (struct DVPathEntryP *)&fwd[1]; + GNUNET_memcpy(dhops, hops, sizeof(struct DVPathEntryP) * nhops); dhops[nhops].hop = GST_my_identity; { - struct DvHopPS dhp = {.purpose.purpose = - htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), - .purpose.size = htonl (sizeof (dhp)), - .pred = dhops[nhops - 1].hop, - .succ = *next_hop, - .challenge = msg->challenge}; - - GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, - &dhp.purpose, - &dhops[nhops].hop_sig)); + struct DvHopPS dhp = { .purpose.purpose = + htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), + .purpose.size = htonl(sizeof(dhp)), + .pred = dhops[nhops - 1].hop, + .succ = *next_hop, + .challenge = msg->challenge }; + + GNUNET_assert(GNUNET_OK == + GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, + &dhp.purpose, + &dhops[nhops].hop_sig)); } - route_control_message_without_fc (next_hop, - &fwd->header, - RMO_UNCONFIRMED_ALLOWED); + route_control_message_without_fc(next_hop, + &fwd->header, + RMO_UNCONFIRMED_ALLOWED); } @@ -6446,28 +6367,28 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, * @return #GNUNET_OK if the signature is valid */ static int -validate_dv_initiator_signature ( +validate_dv_initiator_signature( struct GNUNET_TIME_AbsoluteNBO sender_monotonic_time, const struct GNUNET_PeerIdentity *init, const struct ChallengeNonceP *challenge, const struct GNUNET_CRYPTO_EddsaSignature *init_sig) { - struct DvInitPS ip = {.purpose.purpose = htonl ( - GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), - .purpose.size = htonl (sizeof (ip)), - .monotonic_time = sender_monotonic_time, - .challenge = *challenge}; + struct DvInitPS ip = { .purpose.purpose = htonl( + GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), + .purpose.size = htonl(sizeof(ip)), + .monotonic_time = sender_monotonic_time, + .challenge = *challenge }; if ( GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, - &ip.purpose, - init_sig, - &init->public_key)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, + &ip.purpose, + init_sig, + &init->public_key)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -6475,8 +6396,7 @@ validate_dv_initiator_signature ( /** * Closure for #dv_neighbour_selection and #dv_neighbour_transmission. */ -struct NeighbourSelectionContext -{ +struct NeighbourSelectionContext { /** * Original message we received. */ @@ -6528,18 +6448,19 @@ struct NeighbourSelectionContext * @return #GNUNET_YES (always) */ static int -dv_neighbour_selection (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +dv_neighbour_selection(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct NeighbourSelectionContext *nsc = cls; - (void) value; - if (0 == GNUNET_memcmp (pid, &nsc->dvl->initiator)) + (void)value; + if (0 == GNUNET_memcmp(pid, &nsc->dvl->initiator)) return GNUNET_YES; /* skip initiator */ for (unsigned int i = 0; i < nsc->nhops; i++) - if (0 == GNUNET_memcmp (pid, &nsc->hops[i].hop)) - return GNUNET_YES; /* skip peers on path */ + if (0 == GNUNET_memcmp(pid, &nsc->hops[i].hop)) + return GNUNET_YES; + /* skip peers on path */ nsc->num_eligible++; return GNUNET_YES; } @@ -6556,31 +6477,32 @@ dv_neighbour_selection (void *cls, * @return #GNUNET_YES (always) */ static int -dv_neighbour_transmission (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +dv_neighbour_transmission(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct NeighbourSelectionContext *nsc = cls; - (void) value; - if (0 == GNUNET_memcmp (pid, &nsc->dvl->initiator)) + (void)value; + if (0 == GNUNET_memcmp(pid, &nsc->dvl->initiator)) return GNUNET_YES; /* skip initiator */ for (unsigned int i = 0; i < nsc->nhops; i++) - if (0 == GNUNET_memcmp (pid, &nsc->hops[i].hop)) - return GNUNET_YES; /* skip peers on path */ + if (0 == GNUNET_memcmp(pid, &nsc->hops[i].hop)) + return GNUNET_YES; + /* skip peers on path */ for (unsigned int i = 0; i < nsc->num_selections; i++) - { - if (nsc->selections[i] == nsc->num_eligible) - { - forward_dv_learn (pid, - nsc->dvl, - nsc->bi_history, - nsc->nhops, - nsc->hops, - nsc->in_time); - break; + { + if (nsc->selections[i] == nsc->num_eligible) + { + forward_dv_learn(pid, + nsc->dvl, + nsc->bi_history, + nsc->nhops, + nsc->hops, + nsc->in_time); + break; + } } - } nsc->num_eligible++; return GNUNET_YES; } @@ -6630,42 +6552,42 @@ dv_neighbour_transmission (void *cls, * theory forward to */ static unsigned int -calculate_fork_degree (unsigned int hops_taken, - unsigned int neighbour_count, - unsigned int eligible_count) +calculate_fork_degree(unsigned int hops_taken, + unsigned int neighbour_count, + unsigned int eligible_count) { double target_total = 50.0; /* FIXME: use LOG(NSE)? */ double eligible_ratio = - ((double) eligible_count) / ((double) neighbour_count); + ((double)eligible_count) / ((double)neighbour_count); double boost_factor = eligible_ratio * eligible_ratio; unsigned int rnd; double left; if (hops_taken >= 64) - { - GNUNET_break (0); - return 0; /* precaution given bitshift below */ - } + { + GNUNET_break(0); + return 0; /* precaution given bitshift below */ + } for (unsigned int i = 1; i < hops_taken; i++) - { - /* For each hop, subtract the expected number of targets - reached at distance d (so what remains divided by 2^d) */ - target_total -= (target_total * boost_factor / (1LLU << i)); - } + { + /* For each hop, subtract the expected number of targets + reached at distance d (so what remains divided by 2^d) */ + target_total -= (target_total * boost_factor / (1LLU << i)); + } rnd = - (unsigned int) floor (target_total * boost_factor / (1LLU << hops_taken)); + (unsigned int)floor(target_total * boost_factor / (1LLU << hops_taken)); /* round up or down probabilistically depending on how close we were when floor()ing to rnd */ - left = target_total - (double) rnd; + left = target_total - (double)rnd; if (UINT32_MAX * left > - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)) + GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)) rnd++; /* round up */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Forwarding DV learn message of %u hops %u(/%u/%u) times\n", - hops_taken, - rnd, - eligible_count, - neighbour_count); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Forwarding DV learn message of %u hops %u(/%u/%u) times\n", + hops_taken, + rnd, + eligible_count, + neighbour_count); return rnd; } @@ -6677,14 +6599,14 @@ calculate_fork_degree (unsigned int hops_taken, * @param success #GNUNET_YES if peerstore was successful */ static void -neighbour_store_dvmono_cb (void *cls, int success) +neighbour_store_dvmono_cb(void *cls, int success) { struct Neighbour *n = cls; n->sc = NULL; if (GNUNET_YES != success) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to store other peer's monotonic time in peerstore!\n"); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to store other peer's monotonic time in peerstore!\n"); } @@ -6696,7 +6618,7 @@ neighbour_store_dvmono_cb (void *cls, int success) * @param dvl the message that was received */ static void -handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) +handle_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl) { struct CommunicatorMessageContext *cmc = cls; enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; @@ -6709,287 +6631,287 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) struct GNUNET_TIME_Absolute in_time; struct Neighbour *n; - nhops = ntohs (dvl->bidirectional); /* 0 = sender is initiator */ - bi_history = ntohs (dvl->bidirectional); - hops = (const struct DVPathEntryP *) &dvl[1]; + nhops = ntohs(dvl->bidirectional); /* 0 = sender is initiator */ + bi_history = ntohs(dvl->bidirectional); + hops = (const struct DVPathEntryP *)&dvl[1]; if (0 == nhops) - { - /* sanity check */ - if (0 != GNUNET_memcmp (&dvl->initiator, &cmc->im.sender)) { - GNUNET_break (0); - finish_cmc_handling (cmc); - return; + /* sanity check */ + if (0 != GNUNET_memcmp(&dvl->initiator, &cmc->im.sender)) + { + GNUNET_break(0); + finish_cmc_handling(cmc); + return; + } } - } else - { - /* sanity check */ - if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, &cmc->im.sender)) { - GNUNET_break (0); - finish_cmc_handling (cmc); - return; + /* sanity check */ + if (0 != GNUNET_memcmp(&hops[nhops - 1].hop, &cmc->im.sender)) + { + GNUNET_break(0); + finish_cmc_handling(cmc); + return; + } } - } - GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type); + GNUNET_assert(CT_COMMUNICATOR == cmc->tc->type); cc = cmc->tc->details.communicator.cc; bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE == cc); // FIXME: add bi-directional flag to cc? - in_time = GNUNET_TIME_absolute_get (); + in_time = GNUNET_TIME_absolute_get(); /* continue communicator here, everything else can happen asynchronous! */ - finish_cmc_handling (cmc); + finish_cmc_handling(cmc); - n = lookup_neighbour (&dvl->initiator); + n = lookup_neighbour(&dvl->initiator); if (NULL != n) - { - if ((n->dv_monotime_available == GNUNET_YES) && - (GNUNET_TIME_absolute_ntoh (dvl->monotonic_time).abs_value_us < - n->last_dv_learn_monotime.abs_value_us)) - { - GNUNET_STATISTICS_update (GST_stats, - "# DV learn discarded due to time travel", - 1, - GNUNET_NO); - return; - } - if (GNUNET_OK != validate_dv_initiator_signature (dvl->monotonic_time, - &dvl->initiator, - &dvl->challenge, - &dvl->init_sig)) { - GNUNET_break_op (0); - return; - } - n->last_dv_learn_monotime = GNUNET_TIME_absolute_ntoh (dvl->monotonic_time); - if (GNUNET_YES == n->dv_monotime_available) - { - if (NULL != n->sc) - GNUNET_PEERSTORE_store_cancel (n->sc); - n->sc = - GNUNET_PEERSTORE_store (peerstore, - "transport", - &dvl->initiator, - GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, - &dvl->monotonic_time, - sizeof (dvl->monotonic_time), - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - &neighbour_store_dvmono_cb, - n); + if ((n->dv_monotime_available == GNUNET_YES) && + (GNUNET_TIME_absolute_ntoh(dvl->monotonic_time).abs_value_us < + n->last_dv_learn_monotime.abs_value_us)) + { + GNUNET_STATISTICS_update(GST_stats, + "# DV learn discarded due to time travel", + 1, + GNUNET_NO); + return; + } + if (GNUNET_OK != validate_dv_initiator_signature(dvl->monotonic_time, + &dvl->initiator, + &dvl->challenge, + &dvl->init_sig)) + { + GNUNET_break_op(0); + return; + } + n->last_dv_learn_monotime = GNUNET_TIME_absolute_ntoh(dvl->monotonic_time); + if (GNUNET_YES == n->dv_monotime_available) + { + if (NULL != n->sc) + GNUNET_PEERSTORE_store_cancel(n->sc); + n->sc = + GNUNET_PEERSTORE_store(peerstore, + "transport", + &dvl->initiator, + GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, + &dvl->monotonic_time, + sizeof(dvl->monotonic_time), + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + &neighbour_store_dvmono_cb, + n); + } } - } /* OPTIMIZE-FIXME: asynchronously (!) verify signatures!, If signature verification load too high, implement random drop strategy */ for (unsigned int i = 0; i < nhops; i++) - { - struct DvHopPS dhp = {.purpose.purpose = - htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), - .purpose.size = htonl (sizeof (dhp)), - .pred = (0 == i) ? dvl->initiator : hops[i - 1].hop, - .succ = (nhops == i + 1) ? GST_my_identity - : hops[i + 1].hop, - .challenge = dvl->challenge}; - - if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP, - &dhp.purpose, - &hops[i].hop_sig, - &hops[i].hop.public_key)) - { - GNUNET_break_op (0); - return; + { + struct DvHopPS dhp = { .purpose.purpose = + htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), + .purpose.size = htonl(sizeof(dhp)), + .pred = (0 == i) ? dvl->initiator : hops[i - 1].hop, + .succ = (nhops == i + 1) ? GST_my_identity + : hops[i + 1].hop, + .challenge = dvl->challenge }; + + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP, + &dhp.purpose, + &hops[i].hop_sig, + &hops[i].hop.public_key)) + { + GNUNET_break_op(0); + return; + } } - } if (GNUNET_EXTRA_LOGGING > 0) - { - char *path; - - path = GNUNET_strdup (GNUNET_i2s (&dvl->initiator)); - for (unsigned int i = 0; i < nhops; i++) - { - char *tmp; - - GNUNET_asprintf (&tmp, - "%s%s%s", - path, - (bi_history & (1 << (nhops - i))) ? "<->" : "-->", - GNUNET_i2s (&hops[i].hop)); - GNUNET_free (path); - path = tmp; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received DVInit via %s%s%s\n", - path, - bi_hop ? "<->" : "-->", - GNUNET_i2s (&GST_my_identity)); - GNUNET_free (path); - } + { + char *path; + + path = GNUNET_strdup(GNUNET_i2s(&dvl->initiator)); + for (unsigned int i = 0; i < nhops; i++) + { + char *tmp; + + GNUNET_asprintf(&tmp, + "%s%s%s", + path, + (bi_history & (1 << (nhops - i))) ? "<->" : "-->", + GNUNET_i2s(&hops[i].hop)); + GNUNET_free(path); + path = tmp; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received DVInit via %s%s%s\n", + path, + bi_hop ? "<->" : "-->", + GNUNET_i2s(&GST_my_identity)); + GNUNET_free(path); + } do_fwd = GNUNET_YES; - if (0 == GNUNET_memcmp (&GST_my_identity, &dvl->initiator)) - { - struct GNUNET_PeerIdentity path[nhops + 1]; - struct GNUNET_TIME_Relative host_latency_sum; - struct GNUNET_TIME_Relative latency; - struct GNUNET_TIME_Relative network_latency; - - /* We initiated this, learn the forward path! */ - path[0] = GST_my_identity; - path[1] = hops[0].hop; - host_latency_sum = GNUNET_TIME_relative_ntoh (dvl->non_network_delay); - - // Need also something to lookup initiation time - // to compute RTT! -> add RTT argument here? - latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly - // (based on dvl->challenge, we can identify time of origin!) - - network_latency = GNUNET_TIME_relative_subtract (latency, host_latency_sum); - /* assumption: latency on all links is the same */ - network_latency = GNUNET_TIME_relative_divide (network_latency, nhops); - - for (unsigned int i = 2; i <= nhops; i++) - { - struct GNUNET_TIME_Relative ilat; - - /* assumption: linear latency increase per hop */ - ilat = GNUNET_TIME_relative_multiply (network_latency, i); - path[i] = hops[i - 1].hop; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Learned path with %u hops to %s with latency %s\n", - i, - GNUNET_i2s (&path[i]), - GNUNET_STRINGS_relative_time_to_string (ilat, GNUNET_YES)); - learn_dv_path (path, + if (0 == GNUNET_memcmp(&GST_my_identity, &dvl->initiator)) + { + struct GNUNET_PeerIdentity path[nhops + 1]; + struct GNUNET_TIME_Relative host_latency_sum; + struct GNUNET_TIME_Relative latency; + struct GNUNET_TIME_Relative network_latency; + + /* We initiated this, learn the forward path! */ + path[0] = GST_my_identity; + path[1] = hops[0].hop; + host_latency_sum = GNUNET_TIME_relative_ntoh(dvl->non_network_delay); + + // Need also something to lookup initiation time + // to compute RTT! -> add RTT argument here? + latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly + // (based on dvl->challenge, we can identify time of origin!) + + network_latency = GNUNET_TIME_relative_subtract(latency, host_latency_sum); + /* assumption: latency on all links is the same */ + network_latency = GNUNET_TIME_relative_divide(network_latency, nhops); + + for (unsigned int i = 2; i <= nhops; i++) + { + struct GNUNET_TIME_Relative ilat; + + /* assumption: linear latency increase per hop */ + ilat = GNUNET_TIME_relative_multiply(network_latency, i); + path[i] = hops[i - 1].hop; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Learned path with %u hops to %s with latency %s\n", i, - ilat, - GNUNET_TIME_relative_to_absolute ( - ADDRESS_VALIDATION_LIFETIME)); + GNUNET_i2s(&path[i]), + GNUNET_STRINGS_relative_time_to_string(ilat, GNUNET_YES)); + learn_dv_path(path, + i, + ilat, + GNUNET_TIME_relative_to_absolute( + ADDRESS_VALIDATION_LIFETIME)); + } + /* as we initiated, do not forward again (would be circular!) */ + do_fwd = GNUNET_NO; + return; } - /* as we initiated, do not forward again (would be circular!) */ - do_fwd = GNUNET_NO; - return; - } if (bi_hop) - { - /* last hop was bi-directional, we could learn something here! */ - struct GNUNET_PeerIdentity path[nhops + 2]; - - path[0] = GST_my_identity; - path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */ - for (unsigned int i = 0; i < nhops; i++) { - int iret; + /* last hop was bi-directional, we could learn something here! */ + struct GNUNET_PeerIdentity path[nhops + 2]; - if (0 == (bi_history & (1 << i))) - break; /* i-th hop not bi-directional, stop learning! */ - if (i == nhops - 1) - { - path[i + 2] = dvl->initiator; - } - else - { - path[i + 2] = hops[nhops - i - 2].hop; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Learned inverse path with %u hops to %s\n", - i + 1, - GNUNET_i2s (&path[i + 2])); - iret = learn_dv_path (path, - i + 2, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_TIME_UNIT_ZERO_ABS); - if (GNUNET_SYSERR == iret) - { - /* path invalid or too long to be interesting for US, thus should also - not be interesting to our neighbours, cut path when forwarding to - 'i' hops, except of course for the one that goes back to the - initiator */ - GNUNET_STATISTICS_update (GST_stats, - "# DV learn not forwarded due invalidity of path", - 1, - GNUNET_NO); - do_fwd = GNUNET_NO; - break; - } - if ((GNUNET_NO == iret) && (nhops == i + 1)) - { - /* we have better paths, and this is the longest target, - so there cannot be anything interesting later */ - GNUNET_STATISTICS_update (GST_stats, - "# DV learn not forwarded, got better paths", - 1, - GNUNET_NO); - do_fwd = GNUNET_NO; - break; - } + path[0] = GST_my_identity; + path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */ + for (unsigned int i = 0; i < nhops; i++) + { + int iret; + + if (0 == (bi_history & (1 << i))) + break; /* i-th hop not bi-directional, stop learning! */ + if (i == nhops - 1) + { + path[i + 2] = dvl->initiator; + } + else + { + path[i + 2] = hops[nhops - i - 2].hop; + } + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Learned inverse path with %u hops to %s\n", + i + 1, + GNUNET_i2s(&path[i + 2])); + iret = learn_dv_path(path, + i + 2, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_TIME_UNIT_ZERO_ABS); + if (GNUNET_SYSERR == iret) + { + /* path invalid or too long to be interesting for US, thus should also + not be interesting to our neighbours, cut path when forwarding to + 'i' hops, except of course for the one that goes back to the + initiator */ + GNUNET_STATISTICS_update(GST_stats, + "# DV learn not forwarded due invalidity of path", + 1, + GNUNET_NO); + do_fwd = GNUNET_NO; + break; + } + if ((GNUNET_NO == iret) && (nhops == i + 1)) + { + /* we have better paths, and this is the longest target, + so there cannot be anything interesting later */ + GNUNET_STATISTICS_update(GST_stats, + "# DV learn not forwarded, got better paths", + 1, + GNUNET_NO); + do_fwd = GNUNET_NO; + break; + } + } } - } if (MAX_DV_HOPS_ALLOWED == nhops) - { - /* At limit, we're out of here! */ - finish_cmc_handling (cmc); - return; - } + { + /* At limit, we're out of here! */ + finish_cmc_handling(cmc); + return; + } /* Forward to initiator, if path non-trivial and possible */ bi_history = (bi_history << 1) | (bi_hop ? 1 : 0); did_initiator = GNUNET_NO; if ((1 < nhops) && (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_contains (neighbours, &dvl->initiator))) - { - /* send back to origin! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending DVL back to initiator %s\n", - GNUNET_i2s (&dvl->initiator)); - forward_dv_learn (&dvl->initiator, dvl, bi_history, nhops, hops, in_time); - did_initiator = GNUNET_YES; - } + GNUNET_CONTAINER_multipeermap_contains(neighbours, &dvl->initiator))) + { + /* send back to origin! */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending DVL back to initiator %s\n", + GNUNET_i2s(&dvl->initiator)); + forward_dv_learn(&dvl->initiator, dvl, bi_history, nhops, hops, in_time); + did_initiator = GNUNET_YES; + } /* We forward under two conditions: either we still learned something ourselves (do_fwd), or the path was darn short and thus the initiator is likely to still be very interested in this (and we did NOT already send it back to the initiator) */ if ((do_fwd) || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) && (GNUNET_NO == did_initiator))) - { - /* Pick random neighbours that are not yet on the path */ - struct NeighbourSelectionContext nsc; - unsigned int n_cnt; - - n_cnt = GNUNET_CONTAINER_multipeermap_size (neighbours); - nsc.nhops = nhops; - nsc.dvl = dvl; - nsc.bi_history = bi_history; - nsc.hops = hops; - nsc.in_time = in_time; - nsc.num_eligible = 0; - GNUNET_CONTAINER_multipeermap_iterate (neighbours, - &dv_neighbour_selection, - &nsc); - if (0 == nsc.num_eligible) - return; /* done here, cannot forward to anyone else */ - nsc.num_selections = calculate_fork_degree (nhops, n_cnt, nsc.num_eligible); - nsc.num_selections = - GNUNET_MIN (MAX_DV_DISCOVERY_SELECTION, nsc.num_selections); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Forwarding DVL to %u other peers\n", - nsc.num_selections); - for (unsigned int i = 0; i < nsc.num_selections; i++) - nsc.selections[i] = - (nsc.num_selections == n_cnt) + { + /* Pick random neighbours that are not yet on the path */ + struct NeighbourSelectionContext nsc; + unsigned int n_cnt; + + n_cnt = GNUNET_CONTAINER_multipeermap_size(neighbours); + nsc.nhops = nhops; + nsc.dvl = dvl; + nsc.bi_history = bi_history; + nsc.hops = hops; + nsc.in_time = in_time; + nsc.num_eligible = 0; + GNUNET_CONTAINER_multipeermap_iterate(neighbours, + &dv_neighbour_selection, + &nsc); + if (0 == nsc.num_eligible) + return; /* done here, cannot forward to anyone else */ + nsc.num_selections = calculate_fork_degree(nhops, n_cnt, nsc.num_eligible); + nsc.num_selections = + GNUNET_MIN(MAX_DV_DISCOVERY_SELECTION, nsc.num_selections); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Forwarding DVL to %u other peers\n", + nsc.num_selections); + for (unsigned int i = 0; i < nsc.num_selections; i++) + nsc.selections[i] = + (nsc.num_selections == n_cnt) ? i /* all were selected, avoid collisions by chance */ - : GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, n_cnt); - nsc.num_eligible = 0; - GNUNET_CONTAINER_multipeermap_iterate (neighbours, - &dv_neighbour_transmission, - &nsc); - } + : GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, n_cnt); + nsc.num_eligible = 0; + GNUNET_CONTAINER_multipeermap_iterate(neighbours, + &dv_neighbour_transmission, + &nsc); + } } @@ -7001,27 +6923,27 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) * @return #GNUNET_YES if message is well-formed */ static int -check_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) +check_dv_box(void *cls, const struct TransportDVBoxMessage *dvb) { - uint16_t size = ntohs (dvb->header.size); - uint16_t num_hops = ntohs (dvb->num_hops); + uint16_t size = ntohs(dvb->header.size); + uint16_t num_hops = ntohs(dvb->num_hops); const struct GNUNET_PeerIdentity *hops = - (const struct GNUNET_PeerIdentity *) &dvb[1]; + (const struct GNUNET_PeerIdentity *)&dvb[1]; - (void) cls; - if (size < sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + - sizeof (struct GNUNET_MessageHeader)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - /* This peer must not be on the path */ - for (unsigned int i = 0; i < num_hops; i++) - if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity)) + (void)cls; + if (size < sizeof(*dvb) + num_hops * sizeof(struct GNUNET_PeerIdentity) + + sizeof(struct GNUNET_MessageHeader)) { - GNUNET_break_op (0); + GNUNET_break_op(0); return GNUNET_SYSERR; } + /* This peer must not be on the path */ + for (unsigned int i = 0; i < num_hops; i++) + if (0 == GNUNET_memcmp(&hops[i], &GST_my_identity)) + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_YES; } @@ -7039,13 +6961,13 @@ check_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) * @param payload_size number of bytes in @a payload */ static void -forward_dv_box (struct Neighbour *next_hop, - const struct TransportDVBoxMessage *hdr, - uint16_t total_hops, - uint16_t num_hops, - const struct GNUNET_PeerIdentity *hops, - const void *enc_payload, - uint16_t enc_payload_size) +forward_dv_box(struct Neighbour *next_hop, + const struct TransportDVBoxMessage *hdr, + uint16_t total_hops, + uint16_t num_hops, + const struct GNUNET_PeerIdentity *hops, + const void *enc_payload, + uint16_t enc_payload_size) { struct VirtualLink *vl = next_hop->vl; struct PendingMessage *pm; @@ -7053,33 +6975,33 @@ forward_dv_box (struct Neighbour *next_hop, char *buf; struct GNUNET_PeerIdentity *dhops; - GNUNET_assert (NULL != vl); - msg_size = sizeof (struct TransportDVBoxMessage) + - num_hops * sizeof (struct GNUNET_PeerIdentity) + enc_payload_size; - pm = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); + GNUNET_assert(NULL != vl); + msg_size = sizeof(struct TransportDVBoxMessage) + + num_hops * sizeof(struct GNUNET_PeerIdentity) + enc_payload_size; + pm = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size); pm->pmt = PMT_DV_BOX; pm->vl = vl; - pm->timeout = GNUNET_TIME_relative_to_absolute (DV_FORWARD_TIMEOUT); + pm->timeout = GNUNET_TIME_relative_to_absolute(DV_FORWARD_TIMEOUT); pm->logging_uuid = logging_uuid_gen++; pm->prefs = GNUNET_MQ_PRIO_BACKGROUND; pm->bytes_msg = msg_size; - buf = (char *) &pm[1]; - memcpy (buf, hdr, sizeof (*hdr)); + buf = (char *)&pm[1]; + memcpy(buf, hdr, sizeof(*hdr)); dhops = - (struct GNUNET_PeerIdentity *) &buf[sizeof (struct TransportDVBoxMessage)]; - memcpy (dhops, hops, num_hops * sizeof (struct GNUNET_PeerIdentity)); - memcpy (&dhops[num_hops], enc_payload, enc_payload_size); - GNUNET_CONTAINER_MDLL_insert (vl, - vl->pending_msg_head, - vl->pending_msg_tail, - pm); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created pending message %llu for DV Box with next hop %s (%u/%u)\n", - pm->logging_uuid, - GNUNET_i2s (&next_hop->pid), - (unsigned int) num_hops, - (unsigned int) total_hops); - check_vl_transmission (vl); + (struct GNUNET_PeerIdentity *)&buf[sizeof(struct TransportDVBoxMessage)]; + memcpy(dhops, hops, num_hops * sizeof(struct GNUNET_PeerIdentity)); + memcpy(&dhops[num_hops], enc_payload, enc_payload_size); + GNUNET_CONTAINER_MDLL_insert(vl, + vl->pending_msg_head, + vl->pending_msg_tail, + pm); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Created pending message %llu for DV Box with next hop %s (%u/%u)\n", + pm->logging_uuid, + GNUNET_i2s(&next_hop->pid), + (unsigned int)num_hops, + (unsigned int)total_hops); + check_vl_transmission(vl); } @@ -7089,30 +7011,30 @@ forward_dv_box (struct Neighbour *next_hop, * @param b data structure to release */ static void -free_backtalker (struct Backtalker *b) +free_backtalker(struct Backtalker *b) { if (NULL != b->get) - { - GNUNET_PEERSTORE_iterate_cancel (b->get); - b->get = NULL; - GNUNET_assert (NULL != b->cmc); - finish_cmc_handling (b->cmc); - b->cmc = NULL; - } + { + GNUNET_PEERSTORE_iterate_cancel(b->get); + b->get = NULL; + GNUNET_assert(NULL != b->cmc); + finish_cmc_handling(b->cmc); + b->cmc = NULL; + } if (NULL != b->task) - { - GNUNET_SCHEDULER_cancel (b->task); - b->task = NULL; - } + { + GNUNET_SCHEDULER_cancel(b->task); + b->task = NULL; + } if (NULL != b->sc) - { - GNUNET_PEERSTORE_store_cancel (b->sc); - b->sc = NULL; - } - GNUNET_assert ( + { + GNUNET_PEERSTORE_store_cancel(b->sc); + b->sc = NULL; + } + GNUNET_assert( GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (backtalkers, &b->pid, b)); - GNUNET_free (b); + GNUNET_CONTAINER_multipeermap_remove(backtalkers, &b->pid, b)); + GNUNET_free(b); } @@ -7125,15 +7047,15 @@ free_backtalker (struct Backtalker *b) * @return #GNUNET_OK (always) */ static int -free_backtalker_cb (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +free_backtalker_cb(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct Backtalker *b = value; - (void) cls; - (void) pid; - free_backtalker (b); + (void)cls; + (void)pid; + free_backtalker(b); return GNUNET_OK; } @@ -7144,18 +7066,18 @@ free_backtalker_cb (void *cls, * @param cls a `struct Backtalker` */ static void -backtalker_timeout_cb (void *cls) +backtalker_timeout_cb(void *cls) { struct Backtalker *b = cls; b->task = NULL; - if (0 != GNUNET_TIME_absolute_get_remaining (b->timeout).rel_value_us) - { - b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); - return; - } - GNUNET_assert (NULL == b->sc); - free_backtalker (b); + if (0 != GNUNET_TIME_absolute_get_remaining(b->timeout).rel_value_us) + { + b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b); + return; + } + GNUNET_assert(NULL == b->sc); + free_backtalker(b); } @@ -7168,52 +7090,52 @@ backtalker_timeout_cb (void *cls) * @param emsg error message */ static void -backtalker_monotime_cb (void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +backtalker_monotime_cb(void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { struct Backtalker *b = cls; struct GNUNET_TIME_AbsoluteNBO *mtbe; struct GNUNET_TIME_Absolute mt; - (void) emsg; + (void)emsg; if (NULL == record) - { - /* we're done with #backtalker_monotime_cb() invocations, - continue normal processing */ - b->get = NULL; - GNUNET_assert (NULL != b->cmc); - if (0 != b->body_size) - demultiplex_with_cmc (b->cmc, - (const struct GNUNET_MessageHeader *) &b[1]); - else - finish_cmc_handling (b->cmc); - b->cmc = NULL; - return; - } - if (sizeof (*mtbe) != record->value_size) - { - GNUNET_break (0); - return; - } + { + /* we're done with #backtalker_monotime_cb() invocations, + continue normal processing */ + b->get = NULL; + GNUNET_assert(NULL != b->cmc); + if (0 != b->body_size) + demultiplex_with_cmc(b->cmc, + (const struct GNUNET_MessageHeader *)&b[1]); + else + finish_cmc_handling(b->cmc); + b->cmc = NULL; + return; + } + if (sizeof(*mtbe) != record->value_size) + { + GNUNET_break(0); + return; + } mtbe = record->value; - mt = GNUNET_TIME_absolute_ntoh (*mtbe); + mt = GNUNET_TIME_absolute_ntoh(*mtbe); if (mt.abs_value_us > b->monotonic_time.abs_value_us) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Backtalker message from %s dropped, monotime in the past\n", - GNUNET_i2s (&b->pid)); - GNUNET_STATISTICS_update ( - GST_stats, - "# Backchannel messages dropped: monotonic time not increasing", - 1, - GNUNET_NO); - b->monotonic_time = mt; - /* Setting body_size to 0 prevents call to #forward_backchannel_payload() - */ - b->body_size = 0; - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Backtalker message from %s dropped, monotime in the past\n", + GNUNET_i2s(&b->pid)); + GNUNET_STATISTICS_update( + GST_stats, + "# Backchannel messages dropped: monotonic time not increasing", + 1, + GNUNET_NO); + b->monotonic_time = mt; + /* Setting body_size to 0 prevents call to #forward_backchannel_payload() + */ + b->body_size = 0; + return; + } } @@ -7225,17 +7147,17 @@ backtalker_monotime_cb (void *cls, * @param success #GNUNET_OK on success */ static void -backtalker_monotime_store_cb (void *cls, int success) +backtalker_monotime_store_cb(void *cls, int success) { struct Backtalker *b = cls; if (GNUNET_OK != success) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to store backtalker's monotonic time in PEERSTORE!\n"); - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to store backtalker's monotonic time in PEERSTORE!\n"); + } b->sc = NULL; - b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); + b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b); } @@ -7245,32 +7167,32 @@ backtalker_monotime_store_cb (void *cls, int success) * @param b a backtalker with updated monotonic time */ static void -update_backtalker_monotime (struct Backtalker *b) +update_backtalker_monotime(struct Backtalker *b) { struct GNUNET_TIME_AbsoluteNBO mtbe; if (NULL != b->sc) - { - GNUNET_PEERSTORE_store_cancel (b->sc); - b->sc = NULL; - } + { + GNUNET_PEERSTORE_store_cancel(b->sc); + b->sc = NULL; + } else - { - GNUNET_SCHEDULER_cancel (b->task); - b->task = NULL; - } - mtbe = GNUNET_TIME_absolute_hton (b->monotonic_time); + { + GNUNET_SCHEDULER_cancel(b->task); + b->task = NULL; + } + mtbe = GNUNET_TIME_absolute_hton(b->monotonic_time); b->sc = - GNUNET_PEERSTORE_store (peerstore, - "transport", - &b->pid, - GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, - &mtbe, - sizeof (mtbe), - GNUNET_TIME_UNIT_FOREVER_ABS, - GNUNET_PEERSTORE_STOREOPTION_REPLACE, - &backtalker_monotime_store_cb, - b); + GNUNET_PEERSTORE_store(peerstore, + "transport", + &b->pid, + GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, + &mtbe, + sizeof(mtbe), + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_PEERSTORE_STOREOPTION_REPLACE, + &backtalker_monotime_store_cb, + b); } @@ -7282,221 +7204,223 @@ update_backtalker_monotime (struct Backtalker *b) * @param dvb the message that was received */ static void -handle_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) +handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb) { struct CommunicatorMessageContext *cmc = cls; - uint16_t size = ntohs (dvb->header.size) - sizeof (*dvb); - uint16_t num_hops = ntohs (dvb->num_hops); + uint16_t size = ntohs(dvb->header.size) - sizeof(*dvb); + uint16_t num_hops = ntohs(dvb->num_hops); const struct GNUNET_PeerIdentity *hops = - (const struct GNUNET_PeerIdentity *) &dvb[1]; - const char *enc_payload = (const char *) &hops[num_hops]; + (const struct GNUNET_PeerIdentity *)&dvb[1]; + const char *enc_payload = (const char *)&hops[num_hops]; uint16_t enc_payload_size = - size - (num_hops * sizeof (struct GNUNET_PeerIdentity)); + size - (num_hops * sizeof(struct GNUNET_PeerIdentity)); struct DVKeyState key; struct GNUNET_HashCode hmac; const char *hdr; size_t hdr_len; if (GNUNET_EXTRA_LOGGING > 0) - { - char *path; - - path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity)); - for (unsigned int i = 0; i < num_hops; i++) { - char *tmp; + char *path; - GNUNET_asprintf (&tmp, "%s->%s", path, GNUNET_i2s (&hops[i])); - GNUNET_free (path); - path = tmp; + path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity)); + for (unsigned int i = 0; i < num_hops; i++) + { + char *tmp; + + GNUNET_asprintf(&tmp, "%s->%s", path, GNUNET_i2s(&hops[i])); + GNUNET_free(path); + path = tmp; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received DVBox with remainig path %s\n", + path); + GNUNET_free(path); } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received DVBox with remainig path %s\n", - path); - GNUNET_free (path); - } if (num_hops > 0) - { - /* We're trying from the end of the hops array, as we may be - able to find a shortcut unknown to the origin that way */ - for (int i = num_hops - 1; i >= 0; i--) { - struct Neighbour *n; - - if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity)) - { - GNUNET_break_op (0); - finish_cmc_handling (cmc); - return; - } - n = lookup_neighbour (&hops[i]); - if (NULL == n) - continue; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Skipping %u/%u hops ahead while routing DV Box\n", - i, - num_hops); - forward_dv_box (n, - dvb, - ntohs (dvb->total_hops) + 1, - num_hops - i - 1, /* number of hops left */ - &hops[i + 1], /* remaining hops */ - enc_payload, - enc_payload_size); - GNUNET_STATISTICS_update (GST_stats, - "# DV hops skipped routing boxes", - i, - GNUNET_NO); - GNUNET_STATISTICS_update (GST_stats, - "# DV boxes routed (total)", - 1, - GNUNET_NO); - finish_cmc_handling (cmc); + /* We're trying from the end of the hops array, as we may be + able to find a shortcut unknown to the origin that way */ + for (int i = num_hops - 1; i >= 0; i--) + { + struct Neighbour *n; + + if (0 == GNUNET_memcmp(&hops[i], &GST_my_identity)) + { + GNUNET_break_op(0); + finish_cmc_handling(cmc); + return; + } + n = lookup_neighbour(&hops[i]); + if (NULL == n) + continue; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Skipping %u/%u hops ahead while routing DV Box\n", + i, + num_hops); + forward_dv_box(n, + dvb, + ntohs(dvb->total_hops) + 1, + num_hops - i - 1, /* number of hops left */ + &hops[i + 1], /* remaining hops */ + enc_payload, + enc_payload_size); + GNUNET_STATISTICS_update(GST_stats, + "# DV hops skipped routing boxes", + i, + GNUNET_NO); + GNUNET_STATISTICS_update(GST_stats, + "# DV boxes routed (total)", + 1, + GNUNET_NO); + finish_cmc_handling(cmc); + return; + } + /* Woopsie, next hop not in neighbours, drop! */ + GNUNET_STATISTICS_update(GST_stats, + "# DV Boxes dropped: next hop unknown", + 1, + GNUNET_NO); + finish_cmc_handling(cmc); return; } - /* Woopsie, next hop not in neighbours, drop! */ - GNUNET_STATISTICS_update (GST_stats, - "# DV Boxes dropped: next hop unknown", - 1, - GNUNET_NO); - finish_cmc_handling (cmc); - return; - } /* We are the target. Unbox and handle message. */ - GNUNET_STATISTICS_update (GST_stats, - "# DV boxes opened (ultimate target)", - 1, - GNUNET_NO); - cmc->total_hops = ntohs (dvb->total_hops); - - dh_key_derive_eph_pub (&dvb->ephemeral_key, &dvb->iv, &key); - hdr = (const char *) &dvb[1]; - hdr_len = ntohs (dvb->header.size) - sizeof (*dvb); - dv_hmac (&key, &hmac, hdr, hdr_len); - if (0 != GNUNET_memcmp (&hmac, &dvb->hmac)) - { - /* HMAC missmatch, disard! */ - GNUNET_break_op (0); - finish_cmc_handling (cmc); - return; - } + GNUNET_STATISTICS_update(GST_stats, + "# DV boxes opened (ultimate target)", + 1, + GNUNET_NO); + cmc->total_hops = ntohs(dvb->total_hops); + + dh_key_derive_eph_pub(&dvb->ephemeral_key, &dvb->iv, &key); + hdr = (const char *)&dvb[1]; + hdr_len = ntohs(dvb->header.size) - sizeof(*dvb); + dv_hmac(&key, &hmac, hdr, hdr_len); + if (0 != GNUNET_memcmp(&hmac, &dvb->hmac)) + { + /* HMAC missmatch, disard! */ + GNUNET_break_op(0); + finish_cmc_handling(cmc); + return; + } /* begin actual decryption */ { struct Backtalker *b; struct GNUNET_TIME_Absolute monotime; struct TransportDVBoxPayloadP ppay; - char body[hdr_len - sizeof (ppay)] GNUNET_ALIGN; + char body[hdr_len - sizeof(ppay)] GNUNET_ALIGN; const struct GNUNET_MessageHeader *mh = - (const struct GNUNET_MessageHeader *) body; - - GNUNET_assert (hdr_len >= - sizeof (ppay) + sizeof (struct GNUNET_MessageHeader)); - dv_decrypt (&key, &ppay, hdr, sizeof (ppay)); - dv_decrypt (&key, &body, &hdr[sizeof (ppay)], hdr_len - sizeof (ppay)); - dv_key_clean (&key); - if (ntohs (mh->size) != sizeof (body)) - { - GNUNET_break_op (0); - finish_cmc_handling (cmc); - return; - } + (const struct GNUNET_MessageHeader *)body; + + GNUNET_assert(hdr_len >= + sizeof(ppay) + sizeof(struct GNUNET_MessageHeader)); + dv_decrypt(&key, &ppay, hdr, sizeof(ppay)); + dv_decrypt(&key, &body, &hdr[sizeof(ppay)], hdr_len - sizeof(ppay)); + dv_key_clean(&key); + if (ntohs(mh->size) != sizeof(body)) + { + GNUNET_break_op(0); + finish_cmc_handling(cmc); + return; + } /* need to prevent box-in-a-box (and DV_LEARN) so check inbox type! */ - switch (ntohs (mh->type)) - { - case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX: - GNUNET_break_op (0); - finish_cmc_handling (cmc); - return; - case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN: - GNUNET_break_op (0); - finish_cmc_handling (cmc); - return; - default: - /* permitted, continue */ - break; - } - monotime = GNUNET_TIME_absolute_ntoh (ppay.monotonic_time); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Decrypted backtalk from %s\n", - GNUNET_i2s (&ppay.sender)); - b = GNUNET_CONTAINER_multipeermap_get (backtalkers, &ppay.sender); + switch (ntohs(mh->type)) + { + case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX: + GNUNET_break_op(0); + finish_cmc_handling(cmc); + return; + + case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN: + GNUNET_break_op(0); + finish_cmc_handling(cmc); + return; + + default: + /* permitted, continue */ + break; + } + monotime = GNUNET_TIME_absolute_ntoh(ppay.monotonic_time); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Decrypted backtalk from %s\n", + GNUNET_i2s(&ppay.sender)); + b = GNUNET_CONTAINER_multipeermap_get(backtalkers, &ppay.sender); if ((NULL != b) && (monotime.abs_value_us < b->monotonic_time.abs_value_us)) - { - GNUNET_STATISTICS_update ( - GST_stats, - "# Backchannel messages dropped: monotonic time not increasing", - 1, - GNUNET_NO); - finish_cmc_handling (cmc); - return; - } - if ((NULL == b) || - (0 != GNUNET_memcmp (&b->last_ephemeral, &dvb->ephemeral_key))) - { - /* Check signature */ - struct EphemeralConfirmationPS ec; - - ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); - ec.purpose.size = htonl (sizeof (ec)); - ec.target = GST_my_identity; - ec.ephemeral_key = dvb->ephemeral_key; - if ( - GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL, - &ec.purpose, - &ppay.sender_sig, - &ppay.sender.public_key)) { - /* Signature invalid, disard! */ - GNUNET_break_op (0); - finish_cmc_handling (cmc); + GNUNET_STATISTICS_update( + GST_stats, + "# Backchannel messages dropped: monotonic time not increasing", + 1, + GNUNET_NO); + finish_cmc_handling(cmc); return; } - } + if ((NULL == b) || + (0 != GNUNET_memcmp(&b->last_ephemeral, &dvb->ephemeral_key))) + { + /* Check signature */ + struct EphemeralConfirmationPS ec; + + ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); + ec.purpose.size = htonl(sizeof(ec)); + ec.target = GST_my_identity; + ec.ephemeral_key = dvb->ephemeral_key; + if ( + GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL, + &ec.purpose, + &ppay.sender_sig, + &ppay.sender.public_key)) + { + /* Signature invalid, disard! */ + GNUNET_break_op(0); + finish_cmc_handling(cmc); + return; + } + } /* Update sender, we now know the real origin! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "DVBox received for me from %s via %s\n", - GNUNET_i2s2 (&ppay.sender), - GNUNET_i2s (&cmc->im.sender)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "DVBox received for me from %s via %s\n", + GNUNET_i2s2(&ppay.sender), + GNUNET_i2s(&cmc->im.sender)); cmc->im.sender = ppay.sender; if (NULL != b) - { - /* update key cache and mono time */ - b->last_ephemeral = dvb->ephemeral_key; - b->monotonic_time = monotime; - update_backtalker_monotime (b); - b->timeout = - GNUNET_TIME_relative_to_absolute (BACKCHANNEL_INACTIVITY_TIMEOUT); - - demultiplex_with_cmc (cmc, mh); - return; - } + { + /* update key cache and mono time */ + b->last_ephemeral = dvb->ephemeral_key; + b->monotonic_time = monotime; + update_backtalker_monotime(b); + b->timeout = + GNUNET_TIME_relative_to_absolute(BACKCHANNEL_INACTIVITY_TIMEOUT); + + demultiplex_with_cmc(cmc, mh); + return; + } /* setup data structure to cache signature AND check monotonic time with PEERSTORE before forwarding backchannel payload */ - b = GNUNET_malloc (sizeof (struct Backtalker) + sizeof (body)); + b = GNUNET_malloc(sizeof(struct Backtalker) + sizeof(body)); b->pid = ppay.sender; - b->body_size = sizeof (body); - memcpy (&b[1], body, sizeof (body)); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put ( - backtalkers, - &b->pid, - b, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + b->body_size = sizeof(body); + memcpy(&b[1], body, sizeof(body)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put( + backtalkers, + &b->pid, + b, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); b->monotonic_time = monotime; /* NOTE: to be checked still! */ b->cmc = cmc; b->timeout = - GNUNET_TIME_relative_to_absolute (BACKCHANNEL_INACTIVITY_TIMEOUT); - b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); + GNUNET_TIME_relative_to_absolute(BACKCHANNEL_INACTIVITY_TIMEOUT); + b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b); b->get = - GNUNET_PEERSTORE_iterate (peerstore, - "transport", - &b->pid, - GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, - &backtalker_monotime_cb, - b); + GNUNET_PEERSTORE_iterate(peerstore, + "transport", + &b->pid, + GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, + &backtalker_monotime_cb, + b); } /* end actual decryption */ } @@ -7509,17 +7433,17 @@ handle_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) * @return #GNUNET_YES if message is well-formed */ static int -check_incoming_msg (void *cls, - const struct GNUNET_TRANSPORT_IncomingMessage *im) +check_incoming_msg(void *cls, + const struct GNUNET_TRANSPORT_IncomingMessage *im) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - GNUNET_MQ_check_boxed_message (im); + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + GNUNET_MQ_check_boxed_message(im); return GNUNET_OK; } @@ -7527,8 +7451,7 @@ check_incoming_msg (void *cls, /** * Closure for #check_known_address. */ -struct CheckKnownAddressContext -{ +struct CheckKnownAddressContext { /** * Set to the address we are looking for. */ @@ -7551,15 +7474,15 @@ struct CheckKnownAddressContext * @return #GNUNET_OK if not matching, #GNUNET_NO if match found */ static int -check_known_address (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +check_known_address(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct CheckKnownAddressContext *ckac = cls; struct ValidationState *vs = value; - (void) pid; - if (0 != strcmp (vs->address, ckac->address)) + (void)pid; + if (0 != strcmp(vs->address, ckac->address)) return GNUNET_OK; ckac->vs = vs; return GNUNET_NO; @@ -7572,7 +7495,7 @@ check_known_address (void *cls, * @param cls NULL */ static void -validation_start_cb (void *cls); +validation_start_cb(void *cls); /** @@ -7583,8 +7506,8 @@ validation_start_cb (void *cls); * @param new_time new time for revalidation */ static void -update_next_challenge_time (struct ValidationState *vs, - struct GNUNET_TIME_Absolute new_time) +update_next_challenge_time(struct ValidationState *vs, + struct GNUNET_TIME_Absolute new_time) { struct GNUNET_TIME_Relative delta; @@ -7593,21 +7516,21 @@ update_next_challenge_time (struct ValidationState *vs, vs->next_challenge = new_time; if (NULL == vs->hn) vs->hn = - GNUNET_CONTAINER_heap_insert (validation_heap, vs, new_time.abs_value_us); + GNUNET_CONTAINER_heap_insert(validation_heap, vs, new_time.abs_value_us); else - GNUNET_CONTAINER_heap_update_cost (vs->hn, new_time.abs_value_us); - if ((vs != GNUNET_CONTAINER_heap_peek (validation_heap)) && + GNUNET_CONTAINER_heap_update_cost(vs->hn, new_time.abs_value_us); + if ((vs != GNUNET_CONTAINER_heap_peek(validation_heap)) && (NULL != validation_task)) return; if (NULL != validation_task) - GNUNET_SCHEDULER_cancel (validation_task); + GNUNET_SCHEDULER_cancel(validation_task); /* randomize a bit */ delta.rel_value_us = - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, - MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); - new_time = GNUNET_TIME_absolute_add (new_time, delta); + GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, + MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); + new_time = GNUNET_TIME_absolute_add(new_time, delta); validation_task = - GNUNET_SCHEDULER_add_at (new_time, &validation_start_cb, NULL); + GNUNET_SCHEDULER_add_at(new_time, &validation_start_cb, NULL); } @@ -7618,57 +7541,57 @@ update_next_challenge_time (struct ValidationState *vs, * @param address an address to reach @a pid (presumably) */ static void -start_address_validation (const struct GNUNET_PeerIdentity *pid, - const char *address) +start_address_validation(const struct GNUNET_PeerIdentity *pid, + const char *address) { struct GNUNET_TIME_Absolute now; struct ValidationState *vs; - struct CheckKnownAddressContext ckac = {.address = address, .vs = NULL}; + struct CheckKnownAddressContext ckac = { .address = address, .vs = NULL }; - (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, - pid, - &check_known_address, - &ckac); + (void)GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, + pid, + &check_known_address, + &ckac); if (NULL != (vs = ckac.vs)) - { - /* if 'vs' is not currently valid, we need to speed up retrying the - * validation */ - if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) - { - /* reduce backoff as we got a fresh advertisement */ - vs->challenge_backoff = - GNUNET_TIME_relative_min (FAST_VALIDATION_CHALLENGE_FREQ, - GNUNET_TIME_relative_divide (vs->challenge_backoff, - 2)); - update_next_challenge_time (vs, - GNUNET_TIME_relative_to_absolute ( - vs->challenge_backoff)); + { + /* if 'vs' is not currently valid, we need to speed up retrying the + * validation */ + if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) + { + /* reduce backoff as we got a fresh advertisement */ + vs->challenge_backoff = + GNUNET_TIME_relative_min(FAST_VALIDATION_CHALLENGE_FREQ, + GNUNET_TIME_relative_divide(vs->challenge_backoff, + 2)); + update_next_challenge_time(vs, + GNUNET_TIME_relative_to_absolute( + vs->challenge_backoff)); + } + return; } - return; - } - now = GNUNET_TIME_absolute_get (); - vs = GNUNET_new (struct ValidationState); + now = GNUNET_TIME_absolute_get(); + vs = GNUNET_new(struct ValidationState); vs->pid = *pid; vs->valid_until = - GNUNET_TIME_relative_to_absolute (ADDRESS_VALIDATION_LIFETIME); + GNUNET_TIME_relative_to_absolute(ADDRESS_VALIDATION_LIFETIME); vs->first_challenge_use = now; vs->validation_rtt = GNUNET_TIME_UNIT_FOREVER_REL; - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, - &vs->challenge, - sizeof (vs->challenge)); - vs->address = GNUNET_strdup (address); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting address validation `%s' of peer %s using challenge %s\n", - address, - GNUNET_i2s (pid), - GNUNET_sh2s (&vs->challenge.value)); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put ( - validation_map, - &vs->pid, - vs, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - update_next_challenge_time (vs, now); + GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, + &vs->challenge, + sizeof(vs->challenge)); + vs->address = GNUNET_strdup(address); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting address validation `%s' of peer %s using challenge %s\n", + address, + GNUNET_i2s(pid), + GNUNET_sh2s(&vs->challenge.value)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put( + validation_map, + &vs->pid, + vs, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + update_next_challenge_time(vs, now); } @@ -7680,27 +7603,27 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid, * @param emsg error message, or NULL if no errors */ static void -handle_hello_for_incoming (void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +handle_hello_for_incoming(void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { struct IncomingRequest *ir = cls; const char *val; if (NULL != emsg) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Got failure from PEERSTORE: %s\n", - emsg); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Got failure from PEERSTORE: %s\n", + emsg); + return; + } val = record->value; if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) - { - GNUNET_break (0); - return; - } - start_address_validation (&ir->pid, (const char *) record->value); + { + GNUNET_break(0); + return; + } + start_address_validation(&ir->pid, (const char *)record->value); } @@ -7713,7 +7636,7 @@ handle_hello_for_incoming (void *cls, * @param tvc the message that was received */ static void -handle_validation_challenge ( +handle_validation_challenge( void *cls, const struct TransportValidationChallengeMessage *tvc) { @@ -7727,44 +7650,44 @@ handle_validation_challenge ( /* DV-routed messages are not allowed for validation challenges */ if (cmc->total_hops > 0) - { - GNUNET_break_op (0); - finish_cmc_handling (cmc); - return; - } + { + GNUNET_break_op(0); + finish_cmc_handling(cmc); + return; + } validity_duration = cmc->im.expected_address_validity; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received address validation challenge %s\n", - GNUNET_sh2s (&tvc->challenge.value)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received address validation challenge %s\n", + GNUNET_sh2s(&tvc->challenge.value)); /* If we have a virtual link, we use this mechanism to signal the size of the flow control window, and to allow the sender to ask for increases. If for us the virtual link is still down, we will always give a window size of zero. */ tvr.header.type = - htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); - tvr.header.size = htons (sizeof (tvr)); - tvr.reserved = htonl (0); + htons(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); + tvr.header.size = htons(sizeof(tvr)); + tvr.reserved = htonl(0); tvr.challenge = tvc->challenge; tvr.origin_time = tvc->sender_time; tvr.validity_duration = validity_duration; { /* create signature */ struct TransportValidationPS tvp = - {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), - .purpose.size = htonl (sizeof (tvp)), - .validity_duration = validity_duration, - .challenge = tvc->challenge}; - - GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, - &tvp.purpose, - &tvr.signature)); - } - route_control_message_without_fc (&cmc->im.sender, - &tvr.header, - RMO_ANYTHING_GOES | RMO_REDUNDANT); + { .purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), + .purpose.size = htonl(sizeof(tvp)), + .validity_duration = validity_duration, + .challenge = tvc->challenge }; + + GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, + &tvp.purpose, + &tvr.signature)); + } + route_control_message_without_fc(&cmc->im.sender, + &tvr.header, + RMO_ANYTHING_GOES | RMO_REDUNDANT); sender = cmc->im.sender; - finish_cmc_handling (cmc); - vl = lookup_virtual_link (&sender); + finish_cmc_handling(cmc); + vl = lookup_virtual_link(&sender); if (NULL != vl) return; @@ -7773,36 +7696,36 @@ handle_validation_challenge ( CORE), so we must try to bring the link up! */ /* (1) Check existing queues, if any, we may be lucky! */ - n = lookup_neighbour (&sender); + n = lookup_neighbour(&sender); if (NULL != n) for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) - start_address_validation (&sender, q->address); + start_address_validation(&sender, q->address); /* (2) Also try to see if we have addresses in PEERSTORE for this peer we could use */ for (ir = ir_head; NULL != ir; ir = ir->next) - if (0 == GNUNET_memcmp (&ir->pid, &sender)) - return; /* we are already trying */ - ir = GNUNET_new (struct IncomingRequest); + if (0 == GNUNET_memcmp(&ir->pid, &sender)) + return; + /* we are already trying */ + ir = GNUNET_new(struct IncomingRequest); ir->pid = sender; - GNUNET_CONTAINER_DLL_insert (ir_head, ir_tail, ir); - ir->wc = GNUNET_PEERSTORE_watch (peerstore, - "transport", - &ir->pid, - GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, - &handle_hello_for_incoming, - ir); + GNUNET_CONTAINER_DLL_insert(ir_head, ir_tail, ir); + ir->wc = GNUNET_PEERSTORE_watch(peerstore, + "transport", + &ir->pid, + GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, + &handle_hello_for_incoming, + ir); ir_total++; /* Bound attempts we do in parallel here, might otherwise get excessive */ while (ir_total > MAX_INCOMING_REQUEST) - free_incoming_request (ir_head); + free_incoming_request(ir_head); } /** * Closure for #check_known_challenge. */ -struct CheckKnownChallengeContext -{ +struct CheckKnownChallengeContext { /** * Set to the challenge we are looking for. */ @@ -7825,15 +7748,15 @@ struct CheckKnownChallengeContext * @return #GNUNET_OK if not matching, #GNUNET_NO if match found */ static int -check_known_challenge (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +check_known_challenge(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct CheckKnownChallengeContext *ckac = cls; struct ValidationState *vs = value; - (void) pid; - if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge)) + (void)pid; + if (0 != GNUNET_memcmp(&vs->challenge, ckac->challenge)) return GNUNET_OK; ckac->vs = vs; return GNUNET_NO; @@ -7848,17 +7771,17 @@ check_known_challenge (void *cls, * @param success #GNUNET_YES on success */ static void -peerstore_store_validation_cb (void *cls, int success) +peerstore_store_validation_cb(void *cls, int success) { struct ValidationState *vs = cls; vs->sc = NULL; if (GNUNET_YES == success) return; - GNUNET_STATISTICS_update (GST_stats, - "# Peerstore failed to store foreign address", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update(GST_stats, + "# Peerstore failed to store foreign address", + 1, + GNUNET_NO); } @@ -7870,19 +7793,19 @@ peerstore_store_validation_cb (void *cls, int success) * @return NULL if no such queue exists */ static struct Queue * -find_queue (const struct GNUNET_PeerIdentity *pid, const char *address) +find_queue(const struct GNUNET_PeerIdentity *pid, const char *address) { struct Neighbour *n; - n = lookup_neighbour (pid); + n = lookup_neighbour(pid); if (NULL == n) return NULL; for (struct Queue *pos = n->queue_head; NULL != pos; pos = pos->next_neighbour) - { - if (0 == strcmp (pos->address, address)) - return pos; - } + { + if (0 == strcmp(pos->address, address)) + return pos; + } return NULL; } @@ -7896,161 +7819,161 @@ find_queue (const struct GNUNET_PeerIdentity *pid, const char *address) * @param tvr the message that was received */ static void -handle_validation_response ( +handle_validation_response( void *cls, const struct TransportValidationResponseMessage *tvr) { struct CommunicatorMessageContext *cmc = cls; struct ValidationState *vs; - struct CheckKnownChallengeContext ckac = {.challenge = &tvr->challenge, - .vs = NULL}; + struct CheckKnownChallengeContext ckac = { .challenge = &tvr->challenge, + .vs = NULL }; struct GNUNET_TIME_Absolute origin_time; struct Queue *q; struct Neighbour *n; struct VirtualLink *vl; /* check this is one of our challenges */ - (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, - &cmc->im.sender, - &check_known_challenge, - &ckac); + (void)GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, + &cmc->im.sender, + &check_known_challenge, + &ckac); if (NULL == (vs = ckac.vs)) - { - /* This can happen simply if we 'forgot' the challenge by now, - i.e. because we received the validation response twice */ - GNUNET_STATISTICS_update (GST_stats, - "# Validations dropped, challenge unknown", - 1, - GNUNET_NO); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Validation response %s dropped, challenge unknown\n", - GNUNET_sh2s (&tvr->challenge.value)); - finish_cmc_handling (cmc); - return; - } + { + /* This can happen simply if we 'forgot' the challenge by now, + i.e. because we received the validation response twice */ + GNUNET_STATISTICS_update(GST_stats, + "# Validations dropped, challenge unknown", + 1, + GNUNET_NO); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Validation response %s dropped, challenge unknown\n", + GNUNET_sh2s(&tvr->challenge.value)); + finish_cmc_handling(cmc); + return; + } /* sanity check on origin time */ - origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time); + origin_time = GNUNET_TIME_absolute_ntoh(tvr->origin_time); if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) || (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us)) - { - GNUNET_break_op (0); - finish_cmc_handling (cmc); - return; - } + { + GNUNET_break_op(0); + finish_cmc_handling(cmc); + return; + } { /* check signature */ struct TransportValidationPS tvp = - {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), - .purpose.size = htonl (sizeof (tvp)), - .validity_duration = tvr->validity_duration, - .challenge = tvr->challenge}; + { .purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), + .purpose.size = htonl(sizeof(tvp)), + .validity_duration = tvr->validity_duration, + .challenge = tvr->challenge }; if ( GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, - &tvp.purpose, - &tvr->signature, - &cmc->im.sender.public_key)) - { - GNUNET_break_op (0); - finish_cmc_handling (cmc); - return; - } + GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, + &tvp.purpose, + &tvr->signature, + &cmc->im.sender.public_key)) + { + GNUNET_break_op(0); + finish_cmc_handling(cmc); + return; + } } /* validity is capped by our willingness to keep track of the validation entry and the maximum the other peer allows */ - vs->valid_until = GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_relative_min (GNUNET_TIME_relative_ntoh ( - tvr->validity_duration), - MAX_ADDRESS_VALID_UNTIL)); + vs->valid_until = GNUNET_TIME_relative_to_absolute( + GNUNET_TIME_relative_min(GNUNET_TIME_relative_ntoh( + tvr->validity_duration), + MAX_ADDRESS_VALID_UNTIL)); vs->validated_until = - GNUNET_TIME_absolute_min (vs->valid_until, - GNUNET_TIME_relative_to_absolute ( - ADDRESS_VALIDATION_LIFETIME)); - vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time); + GNUNET_TIME_absolute_min(vs->valid_until, + GNUNET_TIME_relative_to_absolute( + ADDRESS_VALIDATION_LIFETIME)); + vs->validation_rtt = GNUNET_TIME_absolute_get_duration(origin_time); vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO; - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, - &vs->challenge, - sizeof (vs->challenge)); - vs->first_challenge_use = GNUNET_TIME_absolute_subtract ( + GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, + &vs->challenge, + sizeof(vs->challenge)); + vs->first_challenge_use = GNUNET_TIME_absolute_subtract( vs->validated_until, - GNUNET_TIME_relative_multiply (vs->validation_rtt, - VALIDATION_RTT_BUFFER_FACTOR)); + GNUNET_TIME_relative_multiply(vs->validation_rtt, + VALIDATION_RTT_BUFFER_FACTOR)); vs->last_challenge_use = GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */ - update_next_challenge_time (vs, vs->first_challenge_use); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Validation response %s accepted, address valid until %s\n", - GNUNET_sh2s (&tvr->challenge.value), - GNUNET_STRINGS_absolute_time_to_string (vs->valid_until)); - vs->sc = GNUNET_PEERSTORE_store (peerstore, - "transport", - &cmc->im.sender, - GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, - vs->address, - strlen (vs->address) + 1, - vs->valid_until, - GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, - &peerstore_store_validation_cb, - vs); - finish_cmc_handling (cmc); + update_next_challenge_time(vs, vs->first_challenge_use); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Validation response %s accepted, address valid until %s\n", + GNUNET_sh2s(&tvr->challenge.value), + GNUNET_STRINGS_absolute_time_to_string(vs->valid_until)); + vs->sc = GNUNET_PEERSTORE_store(peerstore, + "transport", + &cmc->im.sender, + GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, + vs->address, + strlen(vs->address) + 1, + vs->valid_until, + GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, + &peerstore_store_validation_cb, + vs); + finish_cmc_handling(cmc); /* Finally, we now possibly have a confirmed (!) working queue, update queue status (if queue still is around) */ - q = find_queue (&vs->pid, vs->address); + q = find_queue(&vs->pid, vs->address); if (NULL == q) - { - GNUNET_STATISTICS_update (GST_stats, - "# Queues lost at time of successful validation", - 1, - GNUNET_NO); - return; - } + { + GNUNET_STATISTICS_update(GST_stats, + "# Queues lost at time of successful validation", + 1, + GNUNET_NO); + return; + } q->validated_until = vs->validated_until; q->pd.aged_rtt = vs->validation_rtt; n = q->neighbour; - vl = lookup_virtual_link (&vs->pid); + vl = lookup_virtual_link(&vs->pid); if (NULL != vl) - { - /* Link was already up, remember n is also now available and we are done */ - if (NULL == vl->n) { - vl->n = n; - n->vl = vl; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Virtual link to %s could now also direct neighbour!\n", - GNUNET_i2s (&vs->pid)); - } - else - { - GNUNET_assert (n == vl->n); + /* Link was already up, remember n is also now available and we are done */ + if (NULL == vl->n) + { + vl->n = n; + n->vl = vl; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Virtual link to %s could now also direct neighbour!\n", + GNUNET_i2s(&vs->pid)); + } + else + { + GNUNET_assert(n == vl->n); + } + return; } - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating new virtual link to %s using direct neighbour!\n", - GNUNET_i2s (&vs->pid)); - vl = GNUNET_new (struct VirtualLink); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Creating new virtual link to %s using direct neighbour!\n", + GNUNET_i2s(&vs->pid)); + vl = GNUNET_new(struct VirtualLink); vl->target = n->pid; vl->n = n; n->vl = vl; vl->core_recv_window = RECV_WINDOW_SIZE; vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; vl->visibility_task = - GNUNET_SCHEDULER_add_at (q->validated_until, &check_link_down, vl); - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_put ( - links, - &vl->target, - vl, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - consider_sending_fc (vl); + GNUNET_SCHEDULER_add_at(q->validated_until, &check_link_down, vl); + GNUNET_break(GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put( + links, + &vl->target, + vl, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + consider_sending_fc(vl); /* We lacked a confirmed connection to the target before, so tell CORE about it (finally!) */ - cores_send_connect_info (&n->pid); + cores_send_connect_info(&n->pid); } @@ -8060,19 +7983,19 @@ handle_validation_response ( * @param im the send message that was received */ static void -handle_incoming_msg (void *cls, - const struct GNUNET_TRANSPORT_IncomingMessage *im) +handle_incoming_msg(void *cls, + const struct GNUNET_TRANSPORT_IncomingMessage *im) { struct TransportClient *tc = cls; struct CommunicatorMessageContext *cmc = - GNUNET_new (struct CommunicatorMessageContext); + GNUNET_new(struct CommunicatorMessageContext); cmc->tc = tc; cmc->im = *im; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received message via communicator from peer %s\n", - GNUNET_i2s (&im->sender)); - demultiplex_with_cmc (cmc, (const struct GNUNET_MessageHeader *) &im[1]); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received message via communicator from peer %s\n", + GNUNET_i2s(&im->sender)); + demultiplex_with_cmc(cmc, (const struct GNUNET_MessageHeader *)&im[1]); } @@ -8085,7 +8008,7 @@ handle_incoming_msg (void *cls, * @param fc the message that was received */ static void -handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc) +handle_flow_control(void *cls, const struct TransportFlowControlMessage *fc) { struct CommunicatorMessageContext *cmc = cls; struct VirtualLink *vl; @@ -8094,70 +8017,70 @@ handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc) uint64_t os; uint64_t wnd; - vl = lookup_virtual_link (&cmc->im.sender); + vl = lookup_virtual_link(&cmc->im.sender); if (NULL == vl) - { - GNUNET_STATISTICS_update (GST_stats, - "# FC dropped: virtual link unknown", - 1, - GNUNET_NO); - finish_cmc_handling (cmc); - return; - } - st = GNUNET_TIME_absolute_ntoh (fc->sender_time); + { + GNUNET_STATISTICS_update(GST_stats, + "# FC dropped: virtual link unknown", + 1, + GNUNET_NO); + finish_cmc_handling(cmc); + return; + } + st = GNUNET_TIME_absolute_ntoh(fc->sender_time); if (st.abs_value_us < vl->last_fc_timestamp.abs_value_us) - { - /* out of order, drop */ - GNUNET_STATISTICS_update (GST_stats, - "# FC dropped: message out of order", - 1, - GNUNET_NO); - finish_cmc_handling (cmc); - return; - } - seq = ntohl (fc->seq); + { + /* out of order, drop */ + GNUNET_STATISTICS_update(GST_stats, + "# FC dropped: message out of order", + 1, + GNUNET_NO); + finish_cmc_handling(cmc); + return; + } + seq = ntohl(fc->seq); if (seq < vl->last_fc_seq) - { - /* Wrap-around/reset of other peer; start all counters from zero */ - vl->outbound_fc_window_size_used = 0; - } + { + /* Wrap-around/reset of other peer; start all counters from zero */ + vl->outbound_fc_window_size_used = 0; + } vl->last_fc_seq = seq; vl->last_fc_timestamp = st; - vl->outbound_fc_window_size = GNUNET_ntohll (fc->inbound_window_size); - os = GNUNET_ntohll (fc->outbound_sent); + vl->outbound_fc_window_size = GNUNET_ntohll(fc->inbound_window_size); + os = GNUNET_ntohll(fc->outbound_sent); vl->incoming_fc_window_size_loss = - (int64_t) (os - vl->incoming_fc_window_size_used); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received FC from %s, seq %u, new window %llu (loss at %lld)\n", - GNUNET_i2s (&vl->target), - (unsigned int) seq, - (unsigned long long) vl->outbound_fc_window_size, - (long long) vl->incoming_fc_window_size_loss); - wnd = GNUNET_ntohll (fc->outbound_window_size); + (int64_t)(os - vl->incoming_fc_window_size_used); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received FC from %s, seq %u, new window %llu (loss at %lld)\n", + GNUNET_i2s(&vl->target), + (unsigned int)seq, + (unsigned long long)vl->outbound_fc_window_size, + (long long)vl->incoming_fc_window_size_loss); + wnd = GNUNET_ntohll(fc->outbound_window_size); if ((wnd < vl->incoming_fc_window_size) || (vl->last_outbound_window_size_received != wnd) || - (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) % - FC_NO_CHANGE_REPLY_PROBABILITY)) - { - /* Consider re-sending our FC message, as clearly the - other peer's idea of the window is not up-to-date */ - consider_sending_fc (vl); - } + (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) % + FC_NO_CHANGE_REPLY_PROBABILITY)) + { + /* Consider re-sending our FC message, as clearly the + other peer's idea of the window is not up-to-date */ + consider_sending_fc(vl); + } if ((wnd == vl->incoming_fc_window_size) && (vl->last_outbound_window_size_received == wnd) && (NULL != vl->fc_retransmit_task)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Stopping FC retransmission to %s: peer is current at window %llu\n", - GNUNET_i2s (&vl->target), - (unsigned long long) wnd); - GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); - vl->fc_retransmit_task = NULL; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Stopping FC retransmission to %s: peer is current at window %llu\n", + GNUNET_i2s(&vl->target), + (unsigned long long)wnd); + GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task); + vl->fc_retransmit_task = NULL; + } vl->last_outbound_window_size_received = wnd; /* FC window likely increased, check transmission possibilities! */ - check_vl_transmission (vl); - finish_cmc_handling (cmc); + check_vl_transmission(vl); + finish_cmc_handling(cmc); } @@ -8169,68 +8092,68 @@ handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc) * @param msg message to demultiplex */ static void -demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, - const struct GNUNET_MessageHeader *msg) +demultiplex_with_cmc(struct CommunicatorMessageContext *cmc, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_MQ_MessageHandler handlers[] = - {GNUNET_MQ_hd_var_size (fragment_box, - GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, - struct TransportFragmentBoxMessage, - &cmc), - GNUNET_MQ_hd_var_size (reliability_box, - GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, - struct TransportReliabilityBoxMessage, - &cmc), - GNUNET_MQ_hd_var_size (reliability_ack, - GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, - struct TransportReliabilityAckMessage, - &cmc), - GNUNET_MQ_hd_var_size (backchannel_encapsulation, - GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, - struct TransportBackchannelEncapsulationMessage, + { GNUNET_MQ_hd_var_size(fragment_box, + GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, + struct TransportFragmentBoxMessage, + &cmc), + GNUNET_MQ_hd_var_size(reliability_box, + GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, + struct TransportReliabilityBoxMessage, + &cmc), + GNUNET_MQ_hd_var_size(reliability_ack, + GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, + struct TransportReliabilityAckMessage, + &cmc), + GNUNET_MQ_hd_var_size(backchannel_encapsulation, + GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, + struct TransportBackchannelEncapsulationMessage, + &cmc), + GNUNET_MQ_hd_var_size(dv_learn, + GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, + struct TransportDVLearnMessage, + &cmc), + GNUNET_MQ_hd_var_size(dv_box, + GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, + struct TransportDVBoxMessage, + &cmc), + GNUNET_MQ_hd_fixed_size( + validation_challenge, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE, + struct TransportValidationChallengeMessage, + &cmc), + GNUNET_MQ_hd_fixed_size(flow_control, + GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL, + struct TransportFlowControlMessage, &cmc), - GNUNET_MQ_hd_var_size (dv_learn, - GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, - struct TransportDVLearnMessage, - &cmc), - GNUNET_MQ_hd_var_size (dv_box, - GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, - struct TransportDVBoxMessage, - &cmc), - GNUNET_MQ_hd_fixed_size ( - validation_challenge, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE, - struct TransportValidationChallengeMessage, - &cmc), - GNUNET_MQ_hd_fixed_size (flow_control, - GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL, - struct TransportFlowControlMessage, - &cmc), - GNUNET_MQ_hd_fixed_size ( - validation_response, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE, - struct TransportValidationResponseMessage, - &cmc), - GNUNET_MQ_handler_end ()}; + GNUNET_MQ_hd_fixed_size( + validation_response, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE, + struct TransportValidationResponseMessage, + &cmc), + GNUNET_MQ_handler_end() }; int ret; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Handling message of type %u with %u bytes\n", - (unsigned int) ntohs (msg->type), - (unsigned int) ntohs (msg->size)); - ret = GNUNET_MQ_handle_message (handlers, msg); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Handling message of type %u with %u bytes\n", + (unsigned int)ntohs(msg->type), + (unsigned int)ntohs(msg->size)); + ret = GNUNET_MQ_handle_message(handlers, msg); if (GNUNET_SYSERR == ret) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cmc->tc->client); - GNUNET_free (cmc); - return; - } + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cmc->tc->client); + GNUNET_free(cmc); + return; + } if (GNUNET_NO == ret) - { - /* unencapsulated 'raw' message */ - handle_raw_message (&cmc, msg); - } + { + /* unencapsulated 'raw' message */ + handle_raw_message(&cmc, msg); + } } @@ -8241,17 +8164,17 @@ demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, * @param aqm the send message that was sent */ static int -check_add_queue_message (void *cls, - const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) +check_add_queue_message(void *cls, + const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - GNUNET_MQ_check_zero_termination (aqm); + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + GNUNET_MQ_check_zero_termination(aqm); return GNUNET_OK; } @@ -8262,7 +8185,7 @@ check_add_queue_message (void *cls, * @param pm pending message to generate UUID for. */ static void -set_pending_message_uuid (struct PendingMessage *pm) +set_pending_message_uuid(struct PendingMessage *pm) { if (pm->msg_uuid_set) return; @@ -8280,36 +8203,37 @@ set_pending_message_uuid (struct PendingMessage *pm) * @return corresponding fresh pending acknowledgement */ static struct PendingAcknowledgement * -prepare_pending_acknowledgement (struct Queue *queue, - struct DistanceVectorHop *dvh, - struct PendingMessage *pm) +prepare_pending_acknowledgement(struct Queue *queue, + struct DistanceVectorHop *dvh, + struct PendingMessage *pm) { struct PendingAcknowledgement *pa; - pa = GNUNET_new (struct PendingAcknowledgement); + pa = GNUNET_new(struct PendingAcknowledgement); pa->queue = queue; pa->dvh = dvh; pa->pm = pm; do - { - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, - &pa->ack_uuid, - sizeof (pa->ack_uuid)); - } while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put ( - pending_acks, - &pa->ack_uuid.value, - pa, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - GNUNET_CONTAINER_MDLL_insert (queue, queue->pa_head, queue->pa_tail, pa); - GNUNET_CONTAINER_MDLL_insert (pm, pm->pa_head, pm->pa_tail, pa); + { + GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, + &pa->ack_uuid, + sizeof(pa->ack_uuid)); + } + while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put( + pending_acks, + &pa->ack_uuid.value, + pa, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_MDLL_insert(queue, queue->pa_head, queue->pa_tail, pa); + GNUNET_CONTAINER_MDLL_insert(pm, pm->pa_head, pm->pa_tail, pa); if (NULL != dvh) - GNUNET_CONTAINER_MDLL_insert (dvh, dvh->pa_head, dvh->pa_tail, pa); - pa->transmission_time = GNUNET_TIME_absolute_get (); + GNUNET_CONTAINER_MDLL_insert(dvh, dvh->pa_head, dvh->pa_tail, pa); + pa->transmission_time = GNUNET_TIME_absolute_get(); pa->message_size = pm->bytes_msg; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Waiting for ACKnowledgment `%s' for <%llu>\n", - GNUNET_uuid2s (&pa->ack_uuid.value), - pm->logging_uuid); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Waiting for ACKnowledgment `%s' for <%llu>\n", + GNUNET_uuid2s(&pa->ack_uuid.value), + pm->logging_uuid); return pa; } @@ -8326,28 +8250,28 @@ prepare_pending_acknowledgement (struct Queue *queue, * @return new message to transmit */ static struct PendingMessage * -fragment_message (struct Queue *queue, - struct DistanceVectorHop *dvh, - struct PendingMessage *pm) +fragment_message(struct Queue *queue, + struct DistanceVectorHop *dvh, + struct PendingMessage *pm) { struct PendingAcknowledgement *pa; struct PendingMessage *ff; uint16_t mtu; mtu = (0 == queue->mtu) - ? UINT16_MAX - sizeof (struct GNUNET_TRANSPORT_SendMessageTo) - : queue->mtu; - set_pending_message_uuid (pm); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Fragmenting message %llu <%llu> to %s for MTU %u\n", - (unsigned long long) pm->msg_uuid.uuid, - pm->logging_uuid, - GNUNET_i2s (&pm->vl->target), - (unsigned int) mtu); - pa = prepare_pending_acknowledgement (queue, dvh, pm); + ? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo) + : queue->mtu; + set_pending_message_uuid(pm); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Fragmenting message %llu <%llu> to %s for MTU %u\n", + (unsigned long long)pm->msg_uuid.uuid, + pm->logging_uuid, + GNUNET_i2s(&pm->vl->target), + (unsigned int)mtu); + pa = prepare_pending_acknowledgement(queue, dvh, pm); /* This invariant is established in #handle_add_queue_message() */ - GNUNET_assert (mtu > sizeof (struct TransportFragmentBoxMessage)); + GNUNET_assert(mtu > sizeof(struct TransportFragmentBoxMessage)); /* select fragment for transmission, descending the tree if it has been expanded until we are at a leaf or at a fragment that is small @@ -8356,68 +8280,68 @@ fragment_message (struct Queue *queue, ff = pm; while (((ff->bytes_msg > mtu) || (pm == ff)) && (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag)) - { - ff = ff->head_frag; /* descent into fragmented fragments */ - } + { + ff = ff->head_frag; /* descent into fragmented fragments */ + } if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg)) - { - /* Did not yet calculate all fragments, calculate next fragment */ - struct PendingMessage *frag; - struct TransportFragmentBoxMessage tfb; - const char *orig; - char *msg; - uint16_t fragmax; - uint16_t fragsize; - uint16_t msize; - uint16_t xoff = 0; - - orig = (const char *) &ff[1]; - msize = ff->bytes_msg; - if (pm != ff) - { - const struct TransportFragmentBoxMessage *tfbo; - - tfbo = (const struct TransportFragmentBoxMessage *) orig; - orig += sizeof (struct TransportFragmentBoxMessage); - msize -= sizeof (struct TransportFragmentBoxMessage); - xoff = ntohs (tfbo->frag_off); - } - fragmax = mtu - sizeof (struct TransportFragmentBoxMessage); - fragsize = GNUNET_MIN (msize - ff->frag_off, fragmax); - frag = - GNUNET_malloc (sizeof (struct PendingMessage) + - sizeof (struct TransportFragmentBoxMessage) + fragsize); - frag->logging_uuid = logging_uuid_gen++; - frag->vl = pm->vl; - frag->frag_parent = ff; - frag->timeout = pm->timeout; - frag->bytes_msg = sizeof (struct TransportFragmentBoxMessage) + fragsize; - frag->pmt = PMT_FRAGMENT_BOX; - msg = (char *) &frag[1]; - tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); - tfb.header.size = - htons (sizeof (struct TransportFragmentBoxMessage) + fragsize); - tfb.ack_uuid = pa->ack_uuid; - tfb.msg_uuid = pm->msg_uuid; - tfb.frag_off = htons (ff->frag_off + xoff); - tfb.msg_size = htons (pm->bytes_msg); - memcpy (msg, &tfb, sizeof (tfb)); - memcpy (&msg[sizeof (tfb)], &orig[ff->frag_off], fragsize); - GNUNET_CONTAINER_MDLL_insert (frag, ff->head_frag, ff->tail_frag, frag); - ff->frag_off += fragsize; - ff = frag; - } + { + /* Did not yet calculate all fragments, calculate next fragment */ + struct PendingMessage *frag; + struct TransportFragmentBoxMessage tfb; + const char *orig; + char *msg; + uint16_t fragmax; + uint16_t fragsize; + uint16_t msize; + uint16_t xoff = 0; + + orig = (const char *)&ff[1]; + msize = ff->bytes_msg; + if (pm != ff) + { + const struct TransportFragmentBoxMessage *tfbo; + + tfbo = (const struct TransportFragmentBoxMessage *)orig; + orig += sizeof(struct TransportFragmentBoxMessage); + msize -= sizeof(struct TransportFragmentBoxMessage); + xoff = ntohs(tfbo->frag_off); + } + fragmax = mtu - sizeof(struct TransportFragmentBoxMessage); + fragsize = GNUNET_MIN(msize - ff->frag_off, fragmax); + frag = + GNUNET_malloc(sizeof(struct PendingMessage) + + sizeof(struct TransportFragmentBoxMessage) + fragsize); + frag->logging_uuid = logging_uuid_gen++; + frag->vl = pm->vl; + frag->frag_parent = ff; + frag->timeout = pm->timeout; + frag->bytes_msg = sizeof(struct TransportFragmentBoxMessage) + fragsize; + frag->pmt = PMT_FRAGMENT_BOX; + msg = (char *)&frag[1]; + tfb.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); + tfb.header.size = + htons(sizeof(struct TransportFragmentBoxMessage) + fragsize); + tfb.ack_uuid = pa->ack_uuid; + tfb.msg_uuid = pm->msg_uuid; + tfb.frag_off = htons(ff->frag_off + xoff); + tfb.msg_size = htons(pm->bytes_msg); + memcpy(msg, &tfb, sizeof(tfb)); + memcpy(&msg[sizeof(tfb)], &orig[ff->frag_off], fragsize); + GNUNET_CONTAINER_MDLL_insert(frag, ff->head_frag, ff->tail_frag, frag); + ff->frag_off += fragsize; + ff = frag; + } /* Move head to the tail and return it */ - GNUNET_CONTAINER_MDLL_remove (frag, - ff->frag_parent->head_frag, - ff->frag_parent->tail_frag, - ff); - GNUNET_CONTAINER_MDLL_insert_tail (frag, - ff->frag_parent->head_frag, - ff->frag_parent->tail_frag, - ff); + GNUNET_CONTAINER_MDLL_remove(frag, + ff->frag_parent->head_frag, + ff->frag_parent->tail_frag, + ff); + GNUNET_CONTAINER_MDLL_insert_tail(frag, + ff->frag_parent->head_frag, + ff->frag_parent->tail_frag, + ff); return ff; } @@ -8435,9 +8359,9 @@ fragment_message (struct Queue *queue, * @return new message to transmit */ static struct PendingMessage * -reliability_box_message (struct Queue *queue, - struct DistanceVectorHop *dvh, - struct PendingMessage *pm) +reliability_box_message(struct Queue *queue, + struct DistanceVectorHop *dvh, + struct PendingMessage *pm) { struct TransportReliabilityBoxMessage rbox; struct PendingAcknowledgement *pa; @@ -8449,39 +8373,39 @@ reliability_box_message (struct Queue *queue, do nothing */ if (NULL != pm->bpm) return pm->bpm; /* already computed earlier: do nothing */ - GNUNET_assert (NULL == pm->head_frag); - if (pm->bytes_msg + sizeof (rbox) > UINT16_MAX) - { - /* failed hard */ - GNUNET_break (0); - client_send_response (pm); - return NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Preparing reliability box for message <%llu> to %s on queue %s\n", - pm->logging_uuid, - GNUNET_i2s (&pm->vl->target), - queue->address); - pa = prepare_pending_acknowledgement (queue, dvh, pm); - - bpm = GNUNET_malloc (sizeof (struct PendingMessage) + sizeof (rbox) + - pm->bytes_msg); + GNUNET_assert(NULL == pm->head_frag); + if (pm->bytes_msg + sizeof(rbox) > UINT16_MAX) + { + /* failed hard */ + GNUNET_break(0); + client_send_response(pm); + return NULL; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Preparing reliability box for message <%llu> to %s on queue %s\n", + pm->logging_uuid, + GNUNET_i2s(&pm->vl->target), + queue->address); + pa = prepare_pending_acknowledgement(queue, dvh, pm); + + bpm = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(rbox) + + pm->bytes_msg); bpm->logging_uuid = logging_uuid_gen++; bpm->vl = pm->vl; bpm->frag_parent = pm; - GNUNET_CONTAINER_MDLL_insert (frag, pm->head_frag, pm->tail_frag, bpm); + GNUNET_CONTAINER_MDLL_insert(frag, pm->head_frag, pm->tail_frag, bpm); bpm->timeout = pm->timeout; bpm->pmt = PMT_RELIABILITY_BOX; - bpm->bytes_msg = pm->bytes_msg + sizeof (rbox); - set_pending_message_uuid (bpm); - rbox.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX); - rbox.header.size = htons (sizeof (rbox) + pm->bytes_msg); - rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support + bpm->bytes_msg = pm->bytes_msg + sizeof(rbox); + set_pending_message_uuid(bpm); + rbox.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX); + rbox.header.size = htons(sizeof(rbox) + pm->bytes_msg); + rbox.ack_countdown = htonl(0); // FIXME: implement ACK countdown support rbox.ack_uuid = pa->ack_uuid; - msg = (char *) &bpm[1]; - memcpy (msg, &rbox, sizeof (rbox)); - memcpy (&msg[sizeof (rbox)], &pm[1], pm->bytes_msg); + msg = (char *)&bpm[1]; + memcpy(msg, &rbox, sizeof(rbox)); + memcpy(&msg[sizeof(rbox)], &pm[1], pm->bytes_msg); pm->bpm = bpm; return bpm; } @@ -8496,61 +8420,60 @@ reliability_box_message (struct Queue *queue, * @param next_attempt timestamp to use */ static void -update_pm_next_attempt (struct PendingMessage *pm, - struct GNUNET_TIME_Absolute next_attempt) +update_pm_next_attempt(struct PendingMessage *pm, + struct GNUNET_TIME_Absolute next_attempt) { struct VirtualLink *vl = pm->vl; pm->next_attempt = next_attempt; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Next attempt for message <%llu> set to %s\n", - pm->logging_uuid, - GNUNET_STRINGS_absolute_time_to_string (next_attempt)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Next attempt for message <%llu> set to %s\n", + pm->logging_uuid, + GNUNET_STRINGS_absolute_time_to_string(next_attempt)); if (NULL == pm->frag_parent) - { - struct PendingMessage *pos; - - /* re-insert sort in neighbour list */ - GNUNET_CONTAINER_MDLL_remove (vl, - vl->pending_msg_head, - vl->pending_msg_tail, - pm); - pos = vl->pending_msg_tail; - while ((NULL != pos) && - (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) - pos = pos->prev_vl; - GNUNET_CONTAINER_MDLL_insert_after (vl, - vl->pending_msg_head, - vl->pending_msg_tail, - pos, - pm); - } + { + struct PendingMessage *pos; + + /* re-insert sort in neighbour list */ + GNUNET_CONTAINER_MDLL_remove(vl, + vl->pending_msg_head, + vl->pending_msg_tail, + pm); + pos = vl->pending_msg_tail; + while ((NULL != pos) && + (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) + pos = pos->prev_vl; + GNUNET_CONTAINER_MDLL_insert_after(vl, + vl->pending_msg_head, + vl->pending_msg_tail, + pos, + pm); + } else - { - /* re-insert sort in fragment list */ - struct PendingMessage *fp = pm->frag_parent; - struct PendingMessage *pos; - - GNUNET_CONTAINER_MDLL_remove (frag, fp->head_frag, fp->tail_frag, pm); - pos = fp->tail_frag; - while ((NULL != pos) && - (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) - pos = pos->prev_frag; - GNUNET_CONTAINER_MDLL_insert_after (frag, - fp->head_frag, - fp->tail_frag, - pos, - pm); - } + { + /* re-insert sort in fragment list */ + struct PendingMessage *fp = pm->frag_parent; + struct PendingMessage *pos; + + GNUNET_CONTAINER_MDLL_remove(frag, fp->head_frag, fp->tail_frag, pm); + pos = fp->tail_frag; + while ((NULL != pos) && + (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) + pos = pos->prev_frag; + GNUNET_CONTAINER_MDLL_insert_after(frag, + fp->head_frag, + fp->tail_frag, + pos, + pm); + } } /** * Context for #select_best_pending_from_link(). */ -struct PendingMessageScoreContext -{ +struct PendingMessageScoreContext { /** * Set to the best message that was found, NULL for none. */ @@ -8595,107 +8518,107 @@ struct PendingMessageScoreContext * from DV encapsulation (0 for without DV) */ static void -select_best_pending_from_link (struct PendingMessageScoreContext *sc, - struct Queue *queue, - struct VirtualLink *vl, - struct DistanceVectorHop *dvh, - size_t overhead) +select_best_pending_from_link(struct PendingMessageScoreContext *sc, + struct Queue *queue, + struct VirtualLink *vl, + struct DistanceVectorHop *dvh, + size_t overhead) { struct GNUNET_TIME_Absolute now; - now = GNUNET_TIME_absolute_get (); + now = GNUNET_TIME_absolute_get(); for (struct PendingMessage *pos = vl->pending_msg_head; NULL != pos; pos = pos->next_vl) - { - size_t real_overhead = overhead; - int frag; - int relb; - - if ((NULL != dvh) && (PMT_DV_BOX == pos->pmt)) - continue; /* DV messages must not be DV-routed to next hop! */ - if (pos->next_attempt.abs_value_us > now.abs_value_us) - break; /* too early for all messages, they are sorted by next_attempt */ - if (NULL != pos->qe) - continue; /* not eligible */ - sc->consideration_counter++; - /* determine if we have to fragment, if so add fragmentation - overhead! */ - frag = GNUNET_NO; - if ( ( (0 != queue->mtu) && - (pos->bytes_msg + real_overhead > queue->mtu) ) || - (pos->bytes_msg > UINT16_MAX - sizeof (struct GNUNET_TRANSPORT_SendMessageTo)) || - (NULL != pos->head_frag /* fragments already exist, should - respect that even if MTU is 0 for - this queue */) ) - { - frag = GNUNET_YES; - if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) - { - /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation - header without the ACK UUID when using a *reliable* channel! */ - } - real_overhead = overhead + sizeof (struct TransportFragmentBoxMessage); - } - /* determine if we have to reliability-box, if so add reliability box - overhead */ - relb = GNUNET_NO; - if ((GNUNET_NO == frag) && - (0 == (pos->prefs & GNUNET_MQ_PREF_UNRELIABLE)) && - (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc)) - { - relb = GNUNET_YES; - real_overhead += sizeof (struct TransportReliabilityBoxMessage); - } - - /* Finally, compare to existing 'best' in sc to see if this 'pos' pending - message would beat it! */ - if (NULL != sc->best) - { - /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue; - OPTIMIZE-ME: This is a heuristic, which so far has NOT been - experimentally validated. There may be some huge potential for - improvement here. Also, we right now only compare how well the - given message fits _this_ queue, and do not consider how well other - queues might suit the message. Taking other queues into consideration - may further improve the result, but could also be expensive - in terms of CPU time. */ - long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead; - long long pm_score = frag * 40 + relb * 20 + real_overhead; - long long time_delta = - (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us) / - 1000LL; - - /* "time_delta" considers which message has been 'ready' for transmission - for longer, if a message has a preference for low latency, increase - the weight of the time_delta by 10x if it is favorable for that message */ - if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && - (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY))) - time_delta *= 10; /* increase weight (always, both are low latency) */ - else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && - (time_delta > 0)) - time_delta *= - 10; /* increase weight, favors 'pos', which is low latency */ - else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && - (time_delta < 0)) - time_delta *= - 10; /* increase weight, favors 'sc->best', which is low latency */ - if (0 != queue->mtu) - { - /* Grant bonus if we are bellow MTU, larger bonus the closer we will - be to the MTU */ - if (queue->mtu > sc->real_overhead + sc->best->bytes_msg) - sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg); - if (queue->mtu > real_overhead + pos->bytes_msg) - pm_score -= queue->mtu - (real_overhead + pos->bytes_msg); - } - if (sc_score + time_delta > pm_score) - continue; /* sc_score larger, keep sc->best */ + { + size_t real_overhead = overhead; + int frag; + int relb; + + if ((NULL != dvh) && (PMT_DV_BOX == pos->pmt)) + continue; /* DV messages must not be DV-routed to next hop! */ + if (pos->next_attempt.abs_value_us > now.abs_value_us) + break; /* too early for all messages, they are sorted by next_attempt */ + if (NULL != pos->qe) + continue; /* not eligible */ + sc->consideration_counter++; + /* determine if we have to fragment, if so add fragmentation + overhead! */ + frag = GNUNET_NO; + if (((0 != queue->mtu) && + (pos->bytes_msg + real_overhead > queue->mtu)) || + (pos->bytes_msg > UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)) || + (NULL != pos->head_frag /* fragments already exist, should + respect that even if MTU is 0 for + this queue */)) + { + frag = GNUNET_YES; + if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) + { + /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation + header without the ACK UUID when using a *reliable* channel! */ + } + real_overhead = overhead + sizeof(struct TransportFragmentBoxMessage); + } + /* determine if we have to reliability-box, if so add reliability box + overhead */ + relb = GNUNET_NO; + if ((GNUNET_NO == frag) && + (0 == (pos->prefs & GNUNET_MQ_PREF_UNRELIABLE)) && + (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc)) + { + relb = GNUNET_YES; + real_overhead += sizeof(struct TransportReliabilityBoxMessage); + } + + /* Finally, compare to existing 'best' in sc to see if this 'pos' pending + message would beat it! */ + if (NULL != sc->best) + { + /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue; + OPTIMIZE-ME: This is a heuristic, which so far has NOT been + experimentally validated. There may be some huge potential for + improvement here. Also, we right now only compare how well the + given message fits _this_ queue, and do not consider how well other + queues might suit the message. Taking other queues into consideration + may further improve the result, but could also be expensive + in terms of CPU time. */ + long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead; + long long pm_score = frag * 40 + relb * 20 + real_overhead; + long long time_delta = + (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us) / + 1000LL; + + /* "time_delta" considers which message has been 'ready' for transmission + for longer, if a message has a preference for low latency, increase + the weight of the time_delta by 10x if it is favorable for that message */ + if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && + (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY))) + time_delta *= 10; /* increase weight (always, both are low latency) */ + else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && + (time_delta > 0)) + time_delta *= + 10; /* increase weight, favors 'pos', which is low latency */ + else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && + (time_delta < 0)) + time_delta *= + 10; /* increase weight, favors 'sc->best', which is low latency */ + if (0 != queue->mtu) + { + /* Grant bonus if we are bellow MTU, larger bonus the closer we will + be to the MTU */ + if (queue->mtu > sc->real_overhead + sc->best->bytes_msg) + sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg); + if (queue->mtu > real_overhead + pos->bytes_msg) + pm_score -= queue->mtu - (real_overhead + pos->bytes_msg); + } + if (sc_score + time_delta > pm_score) + continue; /* sc_score larger, keep sc->best */ + } + sc->best = pos; + sc->dvh = dvh; + sc->frag = frag; + sc->relb = relb; } - sc->best = pos; - sc->dvh = dvh; - sc->frag = frag; - sc->relb = relb; - } } @@ -8710,26 +8633,26 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc, * @param options options of the original message */ static void -extract_box_cb (void *cls, - struct Neighbour *next_hop, - const struct GNUNET_MessageHeader *hdr, - enum RouteMessageOptions options) +extract_box_cb(void *cls, + struct Neighbour *next_hop, + const struct GNUNET_MessageHeader *hdr, + enum RouteMessageOptions options) { struct PendingMessageScoreContext *sc = cls; struct PendingMessage *pm = sc->best; struct PendingMessage *bpm; - uint16_t bsize = ntohs (hdr->size); + uint16_t bsize = ntohs(hdr->size); - GNUNET_assert (NULL == pm->bpm); - bpm = GNUNET_malloc (sizeof (struct PendingMessage) + bsize); + GNUNET_assert(NULL == pm->bpm); + bpm = GNUNET_malloc(sizeof(struct PendingMessage) + bsize); bpm->logging_uuid = logging_uuid_gen++; bpm->pmt = PMT_DV_BOX; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating DV Box %llu for original message %llu (next hop is %s)\n", - bpm->logging_uuid, - pm->logging_uuid, - GNUNET_i2s (&next_hop->pid)); - memcpy (&bpm[1], hdr, bsize); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Creating DV Box %llu for original message %llu (next hop is %s)\n", + bpm->logging_uuid, + pm->logging_uuid, + GNUNET_i2s(&next_hop->pid)); + memcpy(&bpm[1], hdr, bsize); pm->bpm = bpm; } @@ -8750,7 +8673,7 @@ extract_box_cb (void *cls, * @param cls the `struct Queue` to process transmissions for */ static void -transmit_on_queue (void *cls) +transmit_on_queue(void *cls) { struct Queue *queue = cls; struct Neighbour *n = queue->neighbour; @@ -8759,104 +8682,104 @@ transmit_on_queue (void *cls) queue->transmit_task = NULL; if (NULL == n->vl) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Virtual link `%s' is down, cannot have PM for queue `%s'\n", - GNUNET_i2s (&n->pid), - queue->address); - queue->idle = GNUNET_YES; - return; - } - memset (&sc, 0, sizeof (sc)); - select_best_pending_from_link (&sc, queue, n->vl, NULL, 0); + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Virtual link `%s' is down, cannot have PM for queue `%s'\n", + GNUNET_i2s(&n->pid), + queue->address); + queue->idle = GNUNET_YES; + return; + } + memset(&sc, 0, sizeof(sc)); + select_best_pending_from_link(&sc, queue, n->vl, NULL, 0); if (NULL == sc.best) - { - /* Also look at DVH that have the n as first hop! */ - for (struct DistanceVectorHop *dvh = n->dv_head; NULL != dvh; - dvh = dvh->next_neighbour) - { - select_best_pending_from_link (&sc, - queue, - dvh->dv->vl, - dvh, - sizeof (struct GNUNET_PeerIdentity) * - (1 + dvh->distance) + - sizeof (struct TransportDVBoxMessage) + - sizeof (struct TransportDVBoxPayloadP)); + { + /* Also look at DVH that have the n as first hop! */ + for (struct DistanceVectorHop *dvh = n->dv_head; NULL != dvh; + dvh = dvh->next_neighbour) + { + select_best_pending_from_link(&sc, + queue, + dvh->dv->vl, + dvh, + sizeof(struct GNUNET_PeerIdentity) * + (1 + dvh->distance) + + sizeof(struct TransportDVBoxMessage) + + sizeof(struct TransportDVBoxPayloadP)); + } } - } if (NULL == sc.best) - { - /* no message pending, nothing to do here! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No pending messages, queue `%s' to %s now idle\n", - queue->address, - GNUNET_i2s (&n->pid)); - queue->idle = GNUNET_YES; - return; - } + { + /* no message pending, nothing to do here! */ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "No pending messages, queue `%s' to %s now idle\n", + queue->address, + GNUNET_i2s(&n->pid)); + queue->idle = GNUNET_YES; + return; + } /* Given selection in `sc`, do transmission */ pm = sc.best; if (NULL != sc.dvh) - { - GNUNET_assert (PMT_DV_BOX != pm->pmt); - if (NULL != sc.best->bpm) - { - /* We did this boxing before, but possibly for a different path! - Discard old DV box! OPTIMIZE-ME: we might want to check if - it is the same and then not re-build the message... */ - free_pending_message (sc.best->bpm); - sc.best->bpm = NULL; - } - encapsulate_for_dv (sc.dvh->dv, - 1, - &sc.dvh, - (const struct GNUNET_MessageHeader *) &sc.best[1], - &extract_box_cb, - &sc, - RMO_NONE); - GNUNET_assert (NULL != sc.best->bpm); - pm = sc.best->bpm; - } + { + GNUNET_assert(PMT_DV_BOX != pm->pmt); + if (NULL != sc.best->bpm) + { + /* We did this boxing before, but possibly for a different path! + Discard old DV box! OPTIMIZE-ME: we might want to check if + it is the same and then not re-build the message... */ + free_pending_message(sc.best->bpm); + sc.best->bpm = NULL; + } + encapsulate_for_dv(sc.dvh->dv, + 1, + &sc.dvh, + (const struct GNUNET_MessageHeader *)&sc.best[1], + &extract_box_cb, + &sc, + RMO_NONE); + GNUNET_assert(NULL != sc.best->bpm); + pm = sc.best->bpm; + } if (GNUNET_YES == sc.frag) - { - pm = fragment_message (queue, sc.dvh, pm); - if (NULL == pm) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Fragmentation failed queue %s to %s for <%llu>, trying again\n", - queue->address, - GNUNET_i2s (&n->pid), - sc.best->logging_uuid); - schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - return; + { + pm = fragment_message(queue, sc.dvh, pm); + if (NULL == pm) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Fragmentation failed queue %s to %s for <%llu>, trying again\n", + queue->address, + GNUNET_i2s(&n->pid), + sc.best->logging_uuid); + schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + return; + } } - } - else if (GNUNET_YES == sc.relb) - { - pm = reliability_box_message (queue, sc.dvh, pm); - if (NULL == pm) - { - /* Reliability boxing failed, try next message... */ - GNUNET_log ( - GNUNET_ERROR_TYPE_DEBUG, - "Reliability boxing failed queue %s to %s for <%llu>, trying again\n", - queue->address, - GNUNET_i2s (&n->pid), - sc.best->logging_uuid); - schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - return; + else if (GNUNET_YES == sc.relb) + { + pm = reliability_box_message(queue, sc.dvh, pm); + if (NULL == pm) + { + /* Reliability boxing failed, try next message... */ + GNUNET_log( + GNUNET_ERROR_TYPE_DEBUG, + "Reliability boxing failed queue %s to %s for <%llu>, trying again\n", + queue->address, + GNUNET_i2s(&n->pid), + sc.best->logging_uuid); + schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + return; + } } - } /* Pass 'pm' for transission to the communicator */ - GNUNET_log ( + GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, "Passing message <%llu> to queue %s for peer %s (considered %u others)\n", pm->logging_uuid, queue->address, - GNUNET_i2s (&n->pid), + GNUNET_i2s(&n->pid), sc.consideration_counter); /* Flow control: increment amount of traffic sent; if we are routing @@ -8867,50 +8790,50 @@ transmit_on_queue (void *cls) pm->vl->outbound_fc_window_size_used += pm->bytes_msg; if (pm->vl != queue->neighbour->vl) - { - /* If the virtual link of the queue differs, this better be distance - vector routing! */ - GNUNET_assert (NULL != sc.dvh); - /* If we do distance vector routing, we better not do this for a - message that was itself DV-routed */ - GNUNET_assert (PMT_DV_BOX != sc.best->pmt); - /* We use the size of the unboxed message here, to avoid counting - the DV-Box header which is eaten up on the way by intermediaries */ - queue->neighbour->vl->outbound_fc_window_size_used += sc.best->bytes_msg; - } + { + /* If the virtual link of the queue differs, this better be distance + vector routing! */ + GNUNET_assert(NULL != sc.dvh); + /* If we do distance vector routing, we better not do this for a + message that was itself DV-routed */ + GNUNET_assert(PMT_DV_BOX != sc.best->pmt); + /* We use the size of the unboxed message here, to avoid counting + the DV-Box header which is eaten up on the way by intermediaries */ + queue->neighbour->vl->outbound_fc_window_size_used += sc.best->bytes_msg; + } else - { - GNUNET_assert (NULL == sc.dvh); - } + { + GNUNET_assert(NULL == sc.dvh); + } - queue_send_msg (queue, pm, &pm[1], pm->bytes_msg); + queue_send_msg(queue, pm, &pm[1], pm->bytes_msg); /* Check if this transmission somehow conclusively finished handing 'pm' even without any explicit ACKs */ if ((PMT_CORE == pm->pmt) || (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)) - { - completed_pending_message (pm); - } + { + completed_pending_message(pm); + } else - { - /* Message not finished, waiting for acknowledgement. - Update time by which we might retransmit 's' based on queue - characteristics (i.e. RTT); it takes one RTT for the message to - arrive and the ACK to come back in the best case; but the other - side is allowed to delay ACKs by 2 RTTs, so we use 4 RTT before - retransmitting. - - OPTIMIZE: Note that in the future this heuristic should likely - be improved further (measure RTT stability, consider message - urgency and size when delaying ACKs, etc.) */ - update_pm_next_attempt (pm, - GNUNET_TIME_relative_to_absolute ( - GNUNET_TIME_relative_multiply (queue->pd.aged_rtt, + { + /* Message not finished, waiting for acknowledgement. + Update time by which we might retransmit 's' based on queue + characteristics (i.e. RTT); it takes one RTT for the message to + arrive and the ACK to come back in the best case; but the other + side is allowed to delay ACKs by 2 RTTs, so we use 4 RTT before + retransmitting. + + OPTIMIZE: Note that in the future this heuristic should likely + be improved further (measure RTT stability, consider message + urgency and size when delaying ACKs, etc.) */ + update_pm_next_attempt(pm, + GNUNET_TIME_relative_to_absolute( + GNUNET_TIME_relative_multiply(queue->pd.aged_rtt, 4))); - } + } /* finally, re-schedule queue transmission task itself */ - schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); } @@ -8921,35 +8844,35 @@ transmit_on_queue (void *cls) * @param dqm the send message that was sent */ static void -handle_del_queue_message (void *cls, - const struct GNUNET_TRANSPORT_DelQueueMessage *dqm) +handle_del_queue_message(void *cls, + const struct GNUNET_TRANSPORT_DelQueueMessage *dqm) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; queue = queue->next_client) - { - struct Neighbour *neighbour = queue->neighbour; - - if ((dqm->qid != queue->qid) || - (0 != GNUNET_memcmp (&dqm->receiver, &neighbour->pid))) - continue; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Dropped queue %s to peer %s\n", - queue->address, - GNUNET_i2s (&neighbour->pid)); - free_queue (queue); - GNUNET_SERVICE_client_continue (tc->client); - return; - } - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); + { + struct Neighbour *neighbour = queue->neighbour; + + if ((dqm->qid != queue->qid) || + (0 != GNUNET_memcmp(&dqm->receiver, &neighbour->pid))) + continue; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Dropped queue %s to peer %s\n", + queue->address, + GNUNET_i2s(&neighbour->pid)); + free_queue(queue); + GNUNET_SERVICE_client_continue(tc->client); + return; + } + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); } @@ -8960,97 +8883,97 @@ handle_del_queue_message (void *cls, * @param sma the send message that was sent */ static void -handle_send_message_ack (void *cls, - const struct GNUNET_TRANSPORT_SendMessageToAck *sma) +handle_send_message_ack(void *cls, + const struct GNUNET_TRANSPORT_SendMessageToAck *sma) { struct TransportClient *tc = cls; struct QueueEntry *qe; struct PendingMessage *pm; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } /* find our queue entry matching the ACK */ qe = NULL; for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; queue = queue->next_client) - { - if (0 != GNUNET_memcmp (&queue->neighbour->pid, &sma->receiver)) - continue; - for (struct QueueEntry *qep = queue->queue_head; NULL != qep; - qep = qep->next) { - if (qep->mid != sma->mid) + if (0 != GNUNET_memcmp(&queue->neighbour->pid, &sma->receiver)) continue; - qe = qep; + for (struct QueueEntry *qep = queue->queue_head; NULL != qep; + qep = qep->next) + { + if (qep->mid != sma->mid) + continue; + qe = qep; + break; + } break; } - break; - } if (NULL == qe) - { - /* this should never happen */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } - GNUNET_CONTAINER_DLL_remove (qe->queue->queue_head, - qe->queue->queue_tail, - qe); + { + /* this should never happen */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } + GNUNET_CONTAINER_DLL_remove(qe->queue->queue_head, + qe->queue->queue_tail, + qe); qe->queue->queue_length--; tc->details.communicator.total_queue_length--; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received ACK on queue %s to peer %s (new length: %u/%u)\n", - qe->queue->address, - GNUNET_i2s (&qe->queue->neighbour->pid), - qe->queue->queue_length, - tc->details.communicator.total_queue_length); - GNUNET_SERVICE_client_continue (tc->client); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received ACK on queue %s to peer %s (new length: %u/%u)\n", + qe->queue->address, + GNUNET_i2s(&qe->queue->neighbour->pid), + qe->queue->queue_length, + tc->details.communicator.total_queue_length); + GNUNET_SERVICE_client_continue(tc->client); /* if applicable, resume transmissions that waited on ACK */ if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 == tc->details.communicator.total_queue_length) - { - /* Communicator dropped below threshold, resume all queues - incident with this client! */ - GNUNET_STATISTICS_update ( - GST_stats, - "# Transmission throttled due to communicator queue limit", - -1, - GNUNET_NO); - for (struct Queue *queue = tc->details.communicator.queue_head; - NULL != queue; - queue = queue->next_client) - schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - } + { + /* Communicator dropped below threshold, resume all queues + incident with this client! */ + GNUNET_STATISTICS_update( + GST_stats, + "# Transmission throttled due to communicator queue limit", + -1, + GNUNET_NO); + for (struct Queue *queue = tc->details.communicator.queue_head; + NULL != queue; + queue = queue->next_client) + schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + } else if (QUEUE_LENGTH_LIMIT - 1 == qe->queue->queue_length) - { - /* queue dropped below threshold; only resume this one queue */ - GNUNET_STATISTICS_update (GST_stats, - "# Transmission throttled due to queue queue limit", - -1, - GNUNET_NO); - schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); - } + { + /* queue dropped below threshold; only resume this one queue */ + GNUNET_STATISTICS_update(GST_stats, + "# Transmission throttled due to queue queue limit", + -1, + GNUNET_NO); + schedule_transmit_on_queue(qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + } if (NULL != (pm = qe->pm)) - { - struct VirtualLink *vl; - - GNUNET_assert (qe == pm->qe); - pm->qe = NULL; - /* If waiting for this communicator may have blocked transmission - of pm on other queues for this neighbour, force schedule - transmit on queue for queues of the neighbour */ - vl = pm->vl; - if (vl->pending_msg_head == pm) - check_vl_transmission (vl); - } - GNUNET_free (qe); + { + struct VirtualLink *vl; + + GNUNET_assert(qe == pm->qe); + pm->qe = NULL; + /* If waiting for this communicator may have blocked transmission + of pm on other queues for this neighbour, force schedule + transmit on queue for queues of the neighbour */ + vl = pm->vl; + if (vl->pending_msg_head == pm) + check_vl_transmission(vl); + } + GNUNET_free(qe); } @@ -9064,24 +8987,24 @@ handle_send_message_ack (void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -notify_client_queues (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +notify_client_queues(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct TransportClient *tc = cls; struct Neighbour *neighbour = value; - GNUNET_assert (CT_MONITOR == tc->type); + GNUNET_assert(CT_MONITOR == tc->type); for (struct Queue *q = neighbour->queue_head; NULL != q; q = q->next_neighbour) - { - struct MonitorEvent me = {.rtt = q->pd.aged_rtt, - .cs = q->cs, - .num_msg_pending = q->num_msg_pending, - .num_bytes_pending = q->num_bytes_pending}; + { + struct MonitorEvent me = { .rtt = q->pd.aged_rtt, + .cs = q->cs, + .num_msg_pending = q->num_msg_pending, + .num_bytes_pending = q->num_bytes_pending }; - notify_monitor (tc, pid, q->address, q->nt, &me); - } + notify_monitor(tc, pid, q->address, q->nt, &me); + } return GNUNET_OK; } @@ -9093,23 +9016,23 @@ notify_client_queues (void *cls, * @param start the start message that was sent */ static void -handle_monitor_start (void *cls, - const struct GNUNET_TRANSPORT_MonitorStart *start) +handle_monitor_start(void *cls, + const struct GNUNET_TRANSPORT_MonitorStart *start) { struct TransportClient *tc = cls; if (CT_NONE != tc->type) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } tc->type = CT_MONITOR; tc->details.monitor.peer = start->peer; - tc->details.monitor.one_shot = ntohl (start->one_shot); - GNUNET_CONTAINER_multipeermap_iterate (neighbours, ¬ify_client_queues, tc); - GNUNET_SERVICE_client_mark_monitor (tc->client); - GNUNET_SERVICE_client_continue (tc->client); + tc->details.monitor.one_shot = ntohl(start->one_shot); + GNUNET_CONTAINER_multipeermap_iterate(neighbours, ¬ify_client_queues, tc); + GNUNET_SERVICE_client_mark_monitor(tc->client); + GNUNET_SERVICE_client_continue(tc->client); } @@ -9121,16 +9044,16 @@ handle_monitor_start (void *cls, * @return NULL if no such transport client is available */ static struct TransportClient * -lookup_communicator (const char *prefix) +lookup_communicator(const char *prefix) { for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) - { - if (CT_COMMUNICATOR != tc->type) - continue; - if (0 == strcmp (prefix, tc->details.communicator.address_prefix)) - return tc; - } - GNUNET_log ( + { + if (CT_COMMUNICATOR != tc->type) + continue; + if (0 == strcmp(prefix, tc->details.communicator.address_prefix)) + return tc; + } + GNUNET_log( GNUNET_ERROR_TYPE_WARNING, "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n", prefix); @@ -9146,7 +9069,7 @@ lookup_communicator (const char *prefix) * @param address the address to try */ static void -suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address) +suggest_to_connect(const struct GNUNET_PeerIdentity *pid, const char *address) { static uint32_t idgen; struct TransportClient *tc; @@ -9155,40 +9078,40 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address) struct GNUNET_MQ_Envelope *env; size_t alen; - prefix = GNUNET_HELLO_address_to_prefix (address); + prefix = GNUNET_HELLO_address_to_prefix(address); if (NULL == prefix) - { - GNUNET_break (0); /* We got an invalid address!? */ - return; - } - tc = lookup_communicator (prefix); + { + GNUNET_break(0); /* We got an invalid address!? */ + return; + } + tc = lookup_communicator(prefix); if (NULL == tc) - { - GNUNET_STATISTICS_update (GST_stats, - "# Suggestions ignored due to missing communicator", - 1, - GNUNET_NO); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Cannot connect to %s at `%s', no matching communicator present\n", - GNUNET_i2s (pid), - address); - GNUNET_free (prefix); - return; - } + { + GNUNET_STATISTICS_update(GST_stats, + "# Suggestions ignored due to missing communicator", + 1, + GNUNET_NO); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Cannot connect to %s at `%s', no matching communicator present\n", + GNUNET_i2s(pid), + address); + GNUNET_free(prefix); + return; + } /* forward suggestion for queue creation to communicator */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Request #%u for `%s' communicator to create queue to `%s'\n", - (unsigned int) idgen, - prefix, - address); - GNUNET_free (prefix); - alen = strlen (address) + 1; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Request #%u for `%s' communicator to create queue to `%s'\n", + (unsigned int)idgen, + prefix, + address); + GNUNET_free(prefix); + alen = strlen(address) + 1; env = - GNUNET_MQ_msg_extra (cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); - cqm->request_id = htonl (idgen++); + GNUNET_MQ_msg_extra(cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); + cqm->request_id = htonl(idgen++); cqm->receiver = *pid; - memcpy (&cqm[1], address, alen); - GNUNET_MQ_send (tc->mq, env); + memcpy(&cqm[1], address, alen); + GNUNET_MQ_send(tc->mq, env); } @@ -9200,22 +9123,22 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address) * @param vs state to derive validation challenge from */ static void -validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs) +validation_transmit_on_queue(struct Queue *q, struct ValidationState *vs) { struct TransportValidationChallengeMessage tvc; - vs->last_challenge_use = GNUNET_TIME_absolute_get_monotonic (GST_cfg); + vs->last_challenge_use = GNUNET_TIME_absolute_get_monotonic(GST_cfg); tvc.header.type = - htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); - tvc.header.size = htons (sizeof (tvc)); - tvc.reserved = htonl (0); + htons(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); + tvc.header.size = htons(sizeof(tvc)); + tvc.reserved = htonl(0); tvc.challenge = vs->challenge; - tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Sending address validation challenge %s to %s\n", - GNUNET_sh2s (&tvc.challenge.value), - GNUNET_i2s (&q->neighbour->pid)); - queue_send_msg (q, NULL, &tvc, sizeof (tvc)); + tvc.sender_time = GNUNET_TIME_absolute_hton(vs->last_challenge_use); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Sending address validation challenge %s to %s\n", + GNUNET_sh2s(&tvc.challenge.value), + GNUNET_i2s(&q->neighbour->pid)); + queue_send_msg(q, NULL, &tvc, sizeof(tvc)); } @@ -9225,56 +9148,55 @@ validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs) * @param cls NULL */ static void -validation_start_cb (void *cls) +validation_start_cb(void *cls) { struct ValidationState *vs; struct Queue *q; - (void) cls; + (void)cls; validation_task = NULL; - vs = GNUNET_CONTAINER_heap_peek (validation_heap); + vs = GNUNET_CONTAINER_heap_peek(validation_heap); /* drop validations past their expiration */ while ( (NULL != vs) && - (0 == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us)) - { - free_validation_state (vs); - vs = GNUNET_CONTAINER_heap_peek (validation_heap); - } + (0 == GNUNET_TIME_absolute_get_remaining(vs->valid_until).rel_value_us)) + { + free_validation_state(vs); + vs = GNUNET_CONTAINER_heap_peek(validation_heap); + } if (NULL == vs) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Address validation task not scheduled anymore, nothing to do\n"); - return; /* woopsie, no more addresses known, should only - happen if we're really a lonely peer */ - } - q = find_queue (&vs->pid, vs->address); + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Address validation task not scheduled anymore, nothing to do\n"); + return; /* woopsie, no more addresses known, should only + happen if we're really a lonely peer */ + } + q = find_queue(&vs->pid, vs->address); if (NULL == q) - { - vs->awaiting_queue = GNUNET_YES; - suggest_to_connect (&vs->pid, vs->address); - } + { + vs->awaiting_queue = GNUNET_YES; + suggest_to_connect(&vs->pid, vs->address); + } else - validation_transmit_on_queue (q, vs); + validation_transmit_on_queue(q, vs); /* Finally, reschedule next attempt */ vs->challenge_backoff = - GNUNET_TIME_randomized_backoff (vs->challenge_backoff, - MAX_VALIDATION_CHALLENGE_FREQ); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Address validation task will run again in %s\n", - GNUNET_STRINGS_relative_time_to_string (vs->challenge_backoff, - GNUNET_YES)); - update_next_challenge_time (vs, - GNUNET_TIME_relative_to_absolute ( - vs->challenge_backoff)); + GNUNET_TIME_randomized_backoff(vs->challenge_backoff, + MAX_VALIDATION_CHALLENGE_FREQ); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Address validation task will run again in %s\n", + GNUNET_STRINGS_relative_time_to_string(vs->challenge_backoff, + GNUNET_YES)); + update_next_challenge_time(vs, + GNUNET_TIME_relative_to_absolute( + vs->challenge_backoff)); } /** * Closure for #check_connection_quality. */ -struct QueueQualityContext -{ +struct QueueQualityContext { /** * Set to the @e k'th queue encountered. */ @@ -9310,26 +9232,26 @@ struct QueueQualityContext * @return #GNUNET_OK (continue to iterate) */ static int -check_connection_quality (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +check_connection_quality(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct QueueQualityContext *ctx = cls; struct Neighbour *n = value; int do_inc; - (void) pid; + (void)pid; do_inc = GNUNET_NO; for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) - { - ctx->num_queues++; - if (0 == ctx->k--) - ctx->q = q; - /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput - statistics and consider those as well here? */ - if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us) - do_inc = GNUNET_YES; - } + { + ctx->num_queues++; + if (0 == ctx->k--) + ctx->q = q; + /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput + statistics and consider those as well here? */ + if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us) + do_inc = GNUNET_YES; + } if (GNUNET_YES == do_inc) ctx->quality_count++; return GNUNET_OK; @@ -9348,103 +9270,103 @@ check_connection_quality (void *cls, * @param cls NULL */ static void -start_dv_learn (void *cls) +start_dv_learn(void *cls) { struct LearnLaunchEntry *lle; struct QueueQualityContext qqc; struct TransportDVLearnMessage dvl; - (void) cls; + (void)cls; dvlearn_task = NULL; - if (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)) + if (0 == GNUNET_CONTAINER_multipeermap_size(neighbours)) return; /* lost all connectivity, cannot do learning */ qqc.quality_count = 0; qqc.num_queues = 0; - GNUNET_CONTAINER_multipeermap_iterate (neighbours, - &check_connection_quality, - &qqc); + GNUNET_CONTAINER_multipeermap_iterate(neighbours, + &check_connection_quality, + &qqc); if (qqc.quality_count > DV_LEARN_QUALITY_THRESHOLD) - { - struct GNUNET_TIME_Relative delay; - unsigned int factor; - - /* scale our retries by how far we are above the threshold */ - factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; - delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, factor); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "At connection quality %u, will launch DV learn in %s\n", - qqc.quality_count, - GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); - dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay, &start_dv_learn, NULL); - return; - } + { + struct GNUNET_TIME_Relative delay; + unsigned int factor; + + /* scale our retries by how far we are above the threshold */ + factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; + delay = GNUNET_TIME_relative_multiply(DV_LEARN_BASE_FREQUENCY, factor); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "At connection quality %u, will launch DV learn in %s\n", + qqc.quality_count, + GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); + dvlearn_task = GNUNET_SCHEDULER_add_delayed(delay, &start_dv_learn, NULL); + return; + } /* remove old entries in #dvlearn_map if it has grown too big */ while (MAX_DV_LEARN_PENDING >= - GNUNET_CONTAINER_multishortmap_size (dvlearn_map)) - { - lle = lle_tail; - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multishortmap_remove (dvlearn_map, + GNUNET_CONTAINER_multishortmap_size(dvlearn_map)) + { + lle = lle_tail; + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multishortmap_remove(dvlearn_map, &lle->challenge.value, lle)); - GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); - GNUNET_free (lle); - } + GNUNET_CONTAINER_DLL_remove(lle_head, lle_tail, lle); + GNUNET_free(lle); + } /* setup data structure for learning */ - lle = GNUNET_new (struct LearnLaunchEntry); - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, - &lle->challenge, - sizeof (lle->challenge)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting launch DV learn with challenge %s\n", - GNUNET_sh2s (&lle->challenge.value)); - GNUNET_CONTAINER_DLL_insert (lle_head, lle_tail, lle); - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multishortmap_put ( - dvlearn_map, - &lle->challenge.value, - lle, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); - dvl.header.size = htons (sizeof (dvl)); - dvl.num_hops = htons (0); - dvl.bidirectional = htons (0); - dvl.non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); + lle = GNUNET_new(struct LearnLaunchEntry); + GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, + &lle->challenge, + sizeof(lle->challenge)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Starting launch DV learn with challenge %s\n", + GNUNET_sh2s(&lle->challenge.value)); + GNUNET_CONTAINER_DLL_insert(lle_head, lle_tail, lle); + GNUNET_break(GNUNET_YES == + GNUNET_CONTAINER_multishortmap_put( + dvlearn_map, + &lle->challenge.value, + lle, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + dvl.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); + dvl.header.size = htons(sizeof(dvl)); + dvl.num_hops = htons(0); + dvl.bidirectional = htons(0); + dvl.non_network_delay = GNUNET_TIME_relative_hton(GNUNET_TIME_UNIT_ZERO); dvl.monotonic_time = - GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg)); + GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(GST_cfg)); { - struct DvInitPS dvip = {.purpose.purpose = htonl ( - GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), - .purpose.size = htonl (sizeof (dvip)), - .monotonic_time = dvl.monotonic_time, - .challenge = lle->challenge}; - - GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, - &dvip.purpose, - &dvl.init_sig)); + struct DvInitPS dvip = { .purpose.purpose = htonl( + GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), + .purpose.size = htonl(sizeof(dvip)), + .monotonic_time = dvl.monotonic_time, + .challenge = lle->challenge }; + + GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, + &dvip.purpose, + &dvl.init_sig)); } dvl.initiator = GST_my_identity; dvl.challenge = lle->challenge; qqc.quality_count = 0; - qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues); + qqc.k = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues); qqc.num_queues = 0; qqc.q = NULL; - GNUNET_CONTAINER_multipeermap_iterate (neighbours, - &check_connection_quality, - &qqc); - GNUNET_assert (NULL != qqc.q); + GNUNET_CONTAINER_multipeermap_iterate(neighbours, + &check_connection_quality, + &qqc); + GNUNET_assert(NULL != qqc.q); /* Do this as close to transmission time as possible! */ - lle->launch_time = GNUNET_TIME_absolute_get (); + lle->launch_time = GNUNET_TIME_absolute_get(); - queue_send_msg (qqc.q, NULL, &dvl, sizeof (dvl)); + queue_send_msg(qqc.q, NULL, &dvl, sizeof(dvl)); /* reschedule this job, randomizing the time it runs (but no actual backoff!) */ - dvlearn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_randomize ( - DV_LEARN_BASE_FREQUENCY), - &start_dv_learn, - NULL); + dvlearn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_randomize( + DV_LEARN_BASE_FREQUENCY), + &start_dv_learn, + NULL); } @@ -9458,21 +9380,21 @@ start_dv_learn (void *cls) * @return #GNUNET_NO if a match was found and we can stop looking */ static int -check_validation_request_pending (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +check_validation_request_pending(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct Queue *q = cls; struct ValidationState *vs = value; - (void) pid; + (void)pid; if ((GNUNET_YES == vs->awaiting_queue) && - (0 == strcmp (vs->address, q->address))) - { - vs->awaiting_queue = GNUNET_NO; - validation_transmit_on_queue (q, vs); - return GNUNET_NO; - } + (0 == strcmp(vs->address, q->address))) + { + vs->awaiting_queue = GNUNET_NO; + validation_transmit_on_queue(q, vs); + return GNUNET_NO; + } return GNUNET_OK; } @@ -9486,31 +9408,31 @@ check_validation_request_pending (void *cls, * @param emsg error message */ static void -neighbour_dv_monotime_cb (void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +neighbour_dv_monotime_cb(void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { struct Neighbour *n = cls; struct GNUNET_TIME_AbsoluteNBO *mtbe; - (void) emsg; + (void)emsg; if (NULL == record) - { - /* we're done with #neighbour_dv_monotime_cb() invocations, - continue normal processing */ - n->get = NULL; - n->dv_monotime_available = GNUNET_YES; - return; - } - if (sizeof (*mtbe) != record->value_size) - { - GNUNET_break (0); - return; - } + { + /* we're done with #neighbour_dv_monotime_cb() invocations, + continue normal processing */ + n->get = NULL; + n->dv_monotime_available = GNUNET_YES; + return; + } + if (sizeof(*mtbe) != record->value_size) + { + GNUNET_break(0); + return; + } mtbe = record->value; n->last_dv_learn_monotime = - GNUNET_TIME_absolute_max (n->last_dv_learn_monotime, - GNUNET_TIME_absolute_ntoh (*mtbe)); + GNUNET_TIME_absolute_max(n->last_dv_learn_monotime, + GNUNET_TIME_absolute_ntoh(*mtbe)); } @@ -9521,8 +9443,8 @@ neighbour_dv_monotime_cb (void *cls, * @param aqm the send message that was sent */ static void -handle_add_queue_message (void *cls, - const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) +handle_add_queue_message(void *cls, + const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) { struct TransportClient *tc = cls; struct Queue *queue; @@ -9530,77 +9452,77 @@ handle_add_queue_message (void *cls, const char *addr; uint16_t addr_len; - if (ntohl (aqm->mtu) <= sizeof (struct TransportFragmentBoxMessage)) - { - /* MTU so small as to be useless for transmissions, - required for #fragment_message()! */ - GNUNET_break_op (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } - neighbour = lookup_neighbour (&aqm->receiver); + if (ntohl(aqm->mtu) <= sizeof(struct TransportFragmentBoxMessage)) + { + /* MTU so small as to be useless for transmissions, + required for #fragment_message()! */ + GNUNET_break_op(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } + neighbour = lookup_neighbour(&aqm->receiver); if (NULL == neighbour) - { - neighbour = GNUNET_new (struct Neighbour); - neighbour->pid = aqm->receiver; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put ( - neighbours, - &neighbour->pid, - neighbour, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - neighbour->get = - GNUNET_PEERSTORE_iterate (peerstore, - "transport", - &neighbour->pid, - GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, - &neighbour_dv_monotime_cb, - neighbour); - } - addr_len = ntohs (aqm->header.size) - sizeof (*aqm); - addr = (const char *) &aqm[1]; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "New queue %s to %s available with QID %llu\n", - addr, - GNUNET_i2s (&aqm->receiver), - (unsigned long long) aqm->qid); - queue = GNUNET_malloc (sizeof (struct Queue) + addr_len); + { + neighbour = GNUNET_new(struct Neighbour); + neighbour->pid = aqm->receiver; + GNUNET_assert(GNUNET_OK == + GNUNET_CONTAINER_multipeermap_put( + neighbours, + &neighbour->pid, + neighbour, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + neighbour->get = + GNUNET_PEERSTORE_iterate(peerstore, + "transport", + &neighbour->pid, + GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, + &neighbour_dv_monotime_cb, + neighbour); + } + addr_len = ntohs(aqm->header.size) - sizeof(*aqm); + addr = (const char *)&aqm[1]; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "New queue %s to %s available with QID %llu\n", + addr, + GNUNET_i2s(&aqm->receiver), + (unsigned long long)aqm->qid); + queue = GNUNET_malloc(sizeof(struct Queue) + addr_len); queue->tc = tc; - queue->address = (const char *) &queue[1]; + queue->address = (const char *)&queue[1]; queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL; queue->qid = aqm->qid; - queue->mtu = ntohl (aqm->mtu); - queue->nt = (enum GNUNET_NetworkType) ntohl (aqm->nt); - queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs); + queue->mtu = ntohl(aqm->mtu); + queue->nt = (enum GNUNET_NetworkType)ntohl(aqm->nt); + queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl(aqm->cs); queue->neighbour = neighbour; queue->idle = GNUNET_YES; - memcpy (&queue[1], addr, addr_len); + memcpy(&queue[1], addr, addr_len); /* notify monitors about new queue */ { - struct MonitorEvent me = {.rtt = queue->pd.aged_rtt, .cs = queue->cs}; + struct MonitorEvent me = { .rtt = queue->pd.aged_rtt, .cs = queue->cs }; - notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); + notify_monitors(&neighbour->pid, queue->address, queue->nt, &me); } - GNUNET_CONTAINER_MDLL_insert (neighbour, - neighbour->queue_head, - neighbour->queue_tail, - queue); - GNUNET_CONTAINER_MDLL_insert (client, - tc->details.communicator.queue_head, - tc->details.communicator.queue_tail, - queue); + GNUNET_CONTAINER_MDLL_insert(neighbour, + neighbour->queue_head, + neighbour->queue_tail, + queue); + GNUNET_CONTAINER_MDLL_insert(client, + tc->details.communicator.queue_head, + tc->details.communicator.queue_tail, + queue); /* check if valdiations are waiting for the queue */ (void) - GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, - &aqm->receiver, - &check_validation_request_pending, - queue); + GNUNET_CONTAINER_multipeermap_get_multiple(validation_map, + &aqm->receiver, + &check_validation_request_pending, + queue); /* look for traffic for this queue */ - schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); /* might be our first queue, try launching DV learning */ if (NULL == dvlearn_task) - dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, NULL); - GNUNET_SERVICE_client_continue (tc->client); + dvlearn_task = GNUNET_SCHEDULER_add_now(&start_dv_learn, NULL); + GNUNET_SERVICE_client_continue(tc->client); } @@ -9612,25 +9534,25 @@ handle_add_queue_message (void *cls, * @param cqr confirmation message */ static void -handle_queue_create_ok (void *cls, - const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) +handle_queue_create_ok(void *cls, + const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } - GNUNET_STATISTICS_update (GST_stats, - "# Suggestions succeeded at communicator", - 1, - GNUNET_NO); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Request #%u for communicator to create queue succeeded\n", - (unsigned int) ntohs (cqr->request_id)); - GNUNET_SERVICE_client_continue (tc->client); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } + GNUNET_STATISTICS_update(GST_stats, + "# Suggestions succeeded at communicator", + 1, + GNUNET_NO); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Request #%u for communicator to create queue succeeded\n", + (unsigned int)ntohs(cqr->request_id)); + GNUNET_SERVICE_client_continue(tc->client); } @@ -9643,26 +9565,26 @@ handle_queue_create_ok (void *cls, * @param cqr failure message */ static void -handle_queue_create_fail ( +handle_queue_create_fail( void *cls, const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) { struct TransportClient *tc = cls; if (CT_COMMUNICATOR != tc->type) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Request #%u for communicator to create queue failed\n", - (unsigned int) ntohs (cqr->request_id)); - GNUNET_STATISTICS_update (GST_stats, - "# Suggestions failed in queue creation at communicator", - 1, - GNUNET_NO); - GNUNET_SERVICE_client_continue (tc->client); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Request #%u for communicator to create queue failed\n", + (unsigned int)ntohs(cqr->request_id)); + GNUNET_STATISTICS_update(GST_stats, + "# Suggestions failed in queue creation at communicator", + 1, + GNUNET_NO); + GNUNET_SERVICE_client_continue(tc->client); } @@ -9674,27 +9596,27 @@ handle_queue_create_fail ( * @param msg the start message */ static void -handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg) +handle_suggest_cancel(void *cls, const struct ExpressPreferenceMessage *msg) { struct TransportClient *tc = cls; struct PeerRequest *pr; if (CT_APPLICATION != tc->type) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } - pr = GNUNET_CONTAINER_multipeermap_get (tc->details.application.requests, - &msg->peer); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } + pr = GNUNET_CONTAINER_multipeermap_get(tc->details.application.requests, + &msg->peer); if (NULL == pr) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } - (void) stop_peer_request (tc, &pr->pid, pr); - GNUNET_SERVICE_client_continue (tc->client); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } + (void)stop_peer_request(tc, &pr->pid, pr); + GNUNET_SERVICE_client_continue(tc->client); } @@ -9706,27 +9628,27 @@ handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg) * @param emsg error message, or NULL if no errors */ static void -handle_hello_for_client (void *cls, - const struct GNUNET_PEERSTORE_Record *record, - const char *emsg) +handle_hello_for_client(void *cls, + const struct GNUNET_PEERSTORE_Record *record, + const char *emsg) { struct PeerRequest *pr = cls; const char *val; if (NULL != emsg) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Got failure from PEERSTORE: %s\n", - emsg); - return; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Got failure from PEERSTORE: %s\n", + emsg); + return; + } val = record->value; if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) - { - GNUNET_break (0); - return; - } - start_address_validation (&pr->pid, (const char *) record->value); + { + GNUNET_break(0); + return; + } + start_address_validation(&pr->pid, (const char *)record->value); } @@ -9738,51 +9660,51 @@ handle_hello_for_client (void *cls, * @param msg the start message */ static void -handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg) +handle_suggest(void *cls, const struct ExpressPreferenceMessage *msg) { struct TransportClient *tc = cls; struct PeerRequest *pr; if (CT_NONE == tc->type) - { - tc->type = CT_APPLICATION; - tc->details.application.requests = - GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); - } + { + tc->type = CT_APPLICATION; + tc->details.application.requests = + GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); + } if (CT_APPLICATION != tc->type) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (tc->client); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client suggested we talk to %s with preference %d at rate %u\n", - GNUNET_i2s (&msg->peer), - (int) ntohl (msg->pk), - (int) ntohl (msg->bw.value__)); - pr = GNUNET_new (struct PeerRequest); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(tc->client); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Client suggested we talk to %s with preference %d at rate %u\n", + GNUNET_i2s(&msg->peer), + (int)ntohl(msg->pk), + (int)ntohl(msg->bw.value__)); + pr = GNUNET_new(struct PeerRequest); pr->tc = tc; pr->pid = msg->peer; pr->bw = msg->bw; - pr->pk = (enum GNUNET_MQ_PriorityPreferences) ntohl (msg->pk); - if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put ( - tc->details.application.requests, - &pr->pid, - pr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) - { - GNUNET_break (0); - GNUNET_free (pr); - GNUNET_SERVICE_client_drop (tc->client); - return; - } - pr->wc = GNUNET_PEERSTORE_watch (peerstore, - "transport", - &pr->pid, - GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, - &handle_hello_for_client, - pr); - GNUNET_SERVICE_client_continue (tc->client); + pr->pk = (enum GNUNET_MQ_PriorityPreferences)ntohl(msg->pk); + if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put( + tc->details.application.requests, + &pr->pid, + pr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + { + GNUNET_break(0); + GNUNET_free(pr); + GNUNET_SERVICE_client_drop(tc->client); + return; + } + pr->wc = GNUNET_PEERSTORE_watch(peerstore, + "transport", + &pr->pid, + GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, + &handle_hello_for_client, + pr); + GNUNET_SERVICE_client_continue(tc->client); } @@ -9795,11 +9717,11 @@ handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg) * @return #GNUNET_OK on success */ static int -check_request_hello_validation (void *cls, - const struct RequestHelloValidationMessage *m) +check_request_hello_validation(void *cls, + const struct RequestHelloValidationMessage *m) { - (void) cls; - GNUNET_MQ_check_zero_termination (m); + (void)cls; + GNUNET_MQ_check_zero_termination(m); return GNUNET_OK; } @@ -9812,13 +9734,13 @@ check_request_hello_validation (void *cls, * @param m message to verify */ static void -handle_request_hello_validation (void *cls, - const struct RequestHelloValidationMessage *m) +handle_request_hello_validation(void *cls, + const struct RequestHelloValidationMessage *m) { struct TransportClient *tc = cls; - start_address_validation (&m->peer, (const char *) &m[1]); - GNUNET_SERVICE_client_continue (tc->client); + start_address_validation(&m->peer, (const char *)&m[1]); + GNUNET_SERVICE_client_continue(tc->client); } @@ -9831,16 +9753,16 @@ handle_request_hello_validation (void *cls, * @return #GNUNET_OK (always) */ static int -free_neighbour_cb (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +free_neighbour_cb(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct Neighbour *neighbour = value; - (void) cls; - (void) pid; - GNUNET_break (0); // should this ever happen? - free_neighbour (neighbour); + (void)cls; + (void)pid; + GNUNET_break(0); // should this ever happen? + free_neighbour(neighbour); return GNUNET_OK; } @@ -9855,15 +9777,15 @@ free_neighbour_cb (void *cls, * @return #GNUNET_OK (always) */ static int -free_dv_routes_cb (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +free_dv_routes_cb(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct DistanceVector *dv = value; - (void) cls; - (void) pid; - free_dv_route (dv); + (void)cls; + (void)pid; + free_dv_route(dv); return GNUNET_OK; } @@ -9878,15 +9800,15 @@ free_dv_routes_cb (void *cls, * @return #GNUNET_OK (always) */ static int -free_validation_state_cb (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +free_validation_state_cb(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct ValidationState *vs = value; - (void) cls; - (void) pid; - free_validation_state (vs); + (void)cls; + (void)pid; + free_validation_state(vs); return GNUNET_OK; } @@ -9900,13 +9822,13 @@ free_validation_state_cb (void *cls, * @return #GNUNET_OK (always) */ static int -free_pending_ack_cb (void *cls, const struct GNUNET_Uuid *key, void *value) +free_pending_ack_cb(void *cls, const struct GNUNET_Uuid *key, void *value) { struct PendingAcknowledgement *pa = value; - (void) cls; - (void) key; - free_pending_acknowledgement (pa); + (void)cls; + (void)key; + free_pending_acknowledgement(pa); return GNUNET_OK; } @@ -9920,15 +9842,15 @@ free_pending_ack_cb (void *cls, const struct GNUNET_Uuid *key, void *value) * @return #GNUNET_OK (always) */ static int -free_ack_cummulator_cb (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +free_ack_cummulator_cb(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct AcknowledgementCummulator *ac = value; - (void) cls; - (void) pid; - GNUNET_free (ac); + (void)cls; + (void)pid; + GNUNET_free(ac); return GNUNET_OK; } @@ -9940,67 +9862,68 @@ free_ack_cummulator_cb (void *cls, * @param cls closure, unused */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { struct LearnLaunchEntry *lle; - (void) cls; - GNUNET_CONTAINER_multipeermap_iterate (neighbours, &free_neighbour_cb, NULL); + (void)cls; + + GNUNET_CONTAINER_multipeermap_iterate(neighbours, &free_neighbour_cb, NULL); if (NULL != peerstore) - { - GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO); - peerstore = NULL; - } + { + GNUNET_PEERSTORE_disconnect(peerstore, GNUNET_NO); + peerstore = NULL; + } if (NULL != GST_stats) - { - GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); - GST_stats = NULL; - } + { + GNUNET_STATISTICS_destroy(GST_stats, GNUNET_NO); + GST_stats = NULL; + } if (NULL != GST_my_private_key) - { - GNUNET_free (GST_my_private_key); - GST_my_private_key = NULL; - } - GNUNET_CONTAINER_multipeermap_iterate (ack_cummulators, - &free_ack_cummulator_cb, - NULL); - GNUNET_CONTAINER_multipeermap_destroy (ack_cummulators); + { + GNUNET_free(GST_my_private_key); + GST_my_private_key = NULL; + } + GNUNET_CONTAINER_multipeermap_iterate(ack_cummulators, + &free_ack_cummulator_cb, + NULL); + GNUNET_CONTAINER_multipeermap_destroy(ack_cummulators); ack_cummulators = NULL; - GNUNET_CONTAINER_multiuuidmap_iterate (pending_acks, - &free_pending_ack_cb, - NULL); - GNUNET_CONTAINER_multiuuidmap_destroy (pending_acks); + GNUNET_CONTAINER_multiuuidmap_iterate(pending_acks, + &free_pending_ack_cb, + NULL); + GNUNET_CONTAINER_multiuuidmap_destroy(pending_acks); pending_acks = NULL; - GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)); - GNUNET_CONTAINER_multipeermap_destroy (neighbours); + GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(neighbours)); + GNUNET_CONTAINER_multipeermap_destroy(neighbours); neighbours = NULL; - GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (links)); - GNUNET_CONTAINER_multipeermap_destroy (links); + GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(links)); + GNUNET_CONTAINER_multipeermap_destroy(links); links = NULL; - GNUNET_CONTAINER_multipeermap_iterate (backtalkers, - &free_backtalker_cb, - NULL); - GNUNET_CONTAINER_multipeermap_destroy (backtalkers); + GNUNET_CONTAINER_multipeermap_iterate(backtalkers, + &free_backtalker_cb, + NULL); + GNUNET_CONTAINER_multipeermap_destroy(backtalkers); backtalkers = NULL; - GNUNET_CONTAINER_multipeermap_iterate (validation_map, - &free_validation_state_cb, - NULL); - GNUNET_CONTAINER_multipeermap_destroy (validation_map); + GNUNET_CONTAINER_multipeermap_iterate(validation_map, + &free_validation_state_cb, + NULL); + GNUNET_CONTAINER_multipeermap_destroy(validation_map); validation_map = NULL; while (NULL != ir_head) - free_incoming_request (ir_head); - GNUNET_assert (0 == ir_total); + free_incoming_request(ir_head); + GNUNET_assert(0 == ir_total); while (NULL != (lle = lle_head)) - { - GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); - GNUNET_free (lle); - } - GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map); + { + GNUNET_CONTAINER_DLL_remove(lle_head, lle_tail, lle); + GNUNET_free(lle); + } + GNUNET_CONTAINER_multishortmap_destroy(dvlearn_map); dvlearn_map = NULL; - GNUNET_CONTAINER_heap_destroy (validation_heap); + GNUNET_CONTAINER_heap_destroy(validation_heap); validation_heap = NULL; - GNUNET_CONTAINER_multipeermap_iterate (dv_routes, &free_dv_routes_cb, NULL); - GNUNET_CONTAINER_multipeermap_destroy (dv_routes); + GNUNET_CONTAINER_multipeermap_iterate(dv_routes, &free_dv_routes_cb, NULL); + GNUNET_CONTAINER_multipeermap_destroy(dv_routes); dv_routes = NULL; } @@ -10013,58 +9936,58 @@ do_shutdown (void *cls) * @param service the initialized service */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_SERVICE_Handle *service) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_SERVICE_Handle *service) { - (void) cls; - (void) service; + (void)cls; + (void)service; /* setup globals */ - hello_mono_time = GNUNET_TIME_absolute_get_monotonic (c); + hello_mono_time = GNUNET_TIME_absolute_get_monotonic(c); GST_cfg = c; - backtalkers = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); - pending_acks = GNUNET_CONTAINER_multiuuidmap_create (32768, GNUNET_YES); - ack_cummulators = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_YES); - neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); - links = GNUNET_CONTAINER_multipeermap_create (512, GNUNET_YES); - dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); - dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING, - GNUNET_YES); - validation_map = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); + backtalkers = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); + pending_acks = GNUNET_CONTAINER_multiuuidmap_create(32768, GNUNET_YES); + ack_cummulators = GNUNET_CONTAINER_multipeermap_create(256, GNUNET_YES); + neighbours = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); + links = GNUNET_CONTAINER_multipeermap_create(512, GNUNET_YES); + dv_routes = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); + dvlearn_map = GNUNET_CONTAINER_multishortmap_create(2 * MAX_DV_LEARN_PENDING, + GNUNET_YES); + validation_map = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); validation_heap = - GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); + GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); GST_my_private_key = - GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); + GNUNET_CRYPTO_eddsa_key_create_from_configuration(GST_cfg); if (NULL == GST_my_private_key) - { - GNUNET_log ( - GNUNET_ERROR_TYPE_ERROR, - _ ( - "Transport service is lacking key configuration settings. Exiting.\n")); - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, - &GST_my_identity.public_key); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "My identity is `%s'\n", - GNUNET_i2s_full (&GST_my_identity)); - GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); - peerstore = GNUNET_PEERSTORE_connect (GST_cfg); + { + GNUNET_log( + GNUNET_ERROR_TYPE_ERROR, + _( + "Transport service is lacking key configuration settings. Exiting.\n")); + GNUNET_SCHEDULER_shutdown(); + return; + } + GNUNET_CRYPTO_eddsa_key_get_public(GST_my_private_key, + &GST_my_identity.public_key); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "My identity is `%s'\n", + GNUNET_i2s_full(&GST_my_identity)); + GST_stats = GNUNET_STATISTICS_create("transport", GST_cfg); + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); + peerstore = GNUNET_PEERSTORE_connect(GST_cfg); if (NULL == peerstore) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } + { + GNUNET_break(0); + GNUNET_SCHEDULER_shutdown(); + return; + } } /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN ( +GNUNET_SERVICE_MAIN( "transport", GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, @@ -10072,78 +9995,78 @@ GNUNET_SERVICE_MAIN ( &client_disconnect_cb, NULL, /* communication with applications */ - GNUNET_MQ_hd_fixed_size (suggest, - GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, - struct ExpressPreferenceMessage, - NULL), - GNUNET_MQ_hd_fixed_size (suggest_cancel, - GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, - struct ExpressPreferenceMessage, - NULL), - GNUNET_MQ_hd_var_size (request_hello_validation, - GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, - struct RequestHelloValidationMessage, - NULL), + GNUNET_MQ_hd_fixed_size(suggest, + GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, + struct ExpressPreferenceMessage, + NULL), + GNUNET_MQ_hd_fixed_size(suggest_cancel, + GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, + struct ExpressPreferenceMessage, + NULL), + GNUNET_MQ_hd_var_size(request_hello_validation, + GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, + struct RequestHelloValidationMessage, + NULL), /* communication with core */ - GNUNET_MQ_hd_fixed_size (client_start, - GNUNET_MESSAGE_TYPE_TRANSPORT_START, - struct StartMessage, - NULL), - GNUNET_MQ_hd_var_size (client_send, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, - struct OutboundMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_recv_ok, - GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK, - struct RecvOkMessage, - NULL), + GNUNET_MQ_hd_fixed_size(client_start, + GNUNET_MESSAGE_TYPE_TRANSPORT_START, + struct StartMessage, + NULL), + GNUNET_MQ_hd_var_size(client_send, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, + struct OutboundMessage, + NULL), + GNUNET_MQ_hd_fixed_size(client_recv_ok, + GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK, + struct RecvOkMessage, + NULL), /* communication with communicators */ - GNUNET_MQ_hd_var_size (communicator_available, - GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, - struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, - NULL), - GNUNET_MQ_hd_var_size (communicator_backchannel, - GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, - struct GNUNET_TRANSPORT_CommunicatorBackchannel, - NULL), - GNUNET_MQ_hd_var_size (add_address, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, - struct GNUNET_TRANSPORT_AddAddressMessage, - NULL), - GNUNET_MQ_hd_fixed_size (del_address, - GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, - struct GNUNET_TRANSPORT_DelAddressMessage, - NULL), - GNUNET_MQ_hd_var_size (incoming_msg, - GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, - struct GNUNET_TRANSPORT_IncomingMessage, - NULL), - GNUNET_MQ_hd_fixed_size (queue_create_ok, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, - struct GNUNET_TRANSPORT_CreateQueueResponse, - NULL), - GNUNET_MQ_hd_fixed_size (queue_create_fail, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, - struct GNUNET_TRANSPORT_CreateQueueResponse, - NULL), - GNUNET_MQ_hd_var_size (add_queue_message, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, - struct GNUNET_TRANSPORT_AddQueueMessage, - NULL), - GNUNET_MQ_hd_fixed_size (del_queue_message, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, - struct GNUNET_TRANSPORT_DelQueueMessage, - NULL), - GNUNET_MQ_hd_fixed_size (send_message_ack, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, - struct GNUNET_TRANSPORT_SendMessageToAck, - NULL), + GNUNET_MQ_hd_var_size(communicator_available, + GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, + struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, + NULL), + GNUNET_MQ_hd_var_size(communicator_backchannel, + GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, + struct GNUNET_TRANSPORT_CommunicatorBackchannel, + NULL), + GNUNET_MQ_hd_var_size(add_address, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, + struct GNUNET_TRANSPORT_AddAddressMessage, + NULL), + GNUNET_MQ_hd_fixed_size(del_address, + GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, + struct GNUNET_TRANSPORT_DelAddressMessage, + NULL), + GNUNET_MQ_hd_var_size(incoming_msg, + GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, + struct GNUNET_TRANSPORT_IncomingMessage, + NULL), + GNUNET_MQ_hd_fixed_size(queue_create_ok, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, + struct GNUNET_TRANSPORT_CreateQueueResponse, + NULL), + GNUNET_MQ_hd_fixed_size(queue_create_fail, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, + struct GNUNET_TRANSPORT_CreateQueueResponse, + NULL), + GNUNET_MQ_hd_var_size(add_queue_message, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, + struct GNUNET_TRANSPORT_AddQueueMessage, + NULL), + GNUNET_MQ_hd_fixed_size(del_queue_message, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, + struct GNUNET_TRANSPORT_DelQueueMessage, + NULL), + GNUNET_MQ_hd_fixed_size(send_message_ack, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, + struct GNUNET_TRANSPORT_SendMessageToAck, + NULL), /* communication with monitors */ - GNUNET_MQ_hd_fixed_size (monitor_start, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, - struct GNUNET_TRANSPORT_MonitorStart, - NULL), - GNUNET_MQ_handler_end ()); + GNUNET_MQ_hd_fixed_size(monitor_start, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, + struct GNUNET_TRANSPORT_MonitorStart, + NULL), + GNUNET_MQ_handler_end()); /* end of file gnunet-service-transport.c */ -- cgit v1.2.3