diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-16 18:46:26 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-16 18:46:26 +0200 |
commit | 0afe7f35883d40fbcef42eab8232d09934af5bf9 (patch) | |
tree | 2c7c35adf9060f3c0c8872af0bcf4bf0d26686ea /src/transport/gnunet-service-tng.c | |
parent | f1422cd5bf05ff27cde0c60c1fb16b6d8d6c0452 (diff) | |
download | gnunet-0afe7f35883d40fbcef42eab8232d09934af5bf9.tar.gz gnunet-0afe7f35883d40fbcef42eab8232d09934af5bf9.zip |
ftbfs fix
Diffstat (limited to 'src/transport/gnunet-service-tng.c')
-rw-r--r-- | src/transport/gnunet-service-tng.c | 2722 |
1 files changed, 1144 insertions, 1578 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index e55491990..45d8086ef 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c | |||
@@ -138,47 +138,55 @@ | |||
138 | * of seconds we log a warning. Note: this is for testing, | 138 | * of seconds we log a warning. Note: this is for testing, |
139 | * the value chosen here might be too aggressively low! | 139 | * the value chosen here might be too aggressively low! |
140 | */ | 140 | */ |
141 | #define DELAY_WARN_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 141 | #define DELAY_WARN_THRESHOLD \ |
142 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
142 | 143 | ||
143 | /** | 144 | /** |
144 | * We only consider queues as "quality" connections when | 145 | * We only consider queues as "quality" connections when |
145 | * suppressing the generation of DV initiation messages if | 146 | * suppressing the generation of DV initiation messages if |
146 | * the latency of the queue is below this threshold. | 147 | * the latency of the queue is below this threshold. |
147 | */ | 148 | */ |
148 | #define DV_QUALITY_RTT_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 149 | #define DV_QUALITY_RTT_THRESHOLD \ |
150 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | ||
149 | 151 | ||
150 | /** | 152 | /** |
151 | * How long do we consider a DV path valid if we see no | 153 | * How long do we consider a DV path valid if we see no |
152 | * further updates on it? Note: the value chosen here might be too low! | 154 | * further updates on it? Note: the value chosen here might be too low! |
153 | */ | 155 | */ |
154 | #define DV_PATH_VALIDITY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | 156 | #define DV_PATH_VALIDITY_TIMEOUT \ |
157 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | ||
155 | 158 | ||
156 | /** | 159 | /** |
157 | * How long before paths expire would we like to (re)discover DV paths? Should | 160 | * How long before paths expire would we like to (re)discover DV paths? Should |
158 | * be below #DV_PATH_VALIDITY_TIMEOUT. | 161 | * be below #DV_PATH_VALIDITY_TIMEOUT. |
159 | */ | 162 | */ |
160 | #define DV_PATH_DISCOVERY_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) | 163 | #define DV_PATH_DISCOVERY_FREQUENCY \ |
164 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) | ||
161 | 165 | ||
162 | /** | 166 | /** |
163 | * How long are ephemeral keys valid? | 167 | * How long are ephemeral keys valid? |
164 | */ | 168 | */ |
165 | #define EPHEMERAL_VALIDITY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) | 169 | #define EPHEMERAL_VALIDITY \ |
170 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) | ||
166 | 171 | ||
167 | /** | 172 | /** |
168 | * How long do we keep partially reassembled messages around before giving up? | 173 | * How long do we keep partially reassembled messages around before giving up? |
169 | */ | 174 | */ |
170 | #define REASSEMBLY_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) | 175 | #define REASSEMBLY_EXPIRATION \ |
176 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) | ||
171 | 177 | ||
172 | /** | 178 | /** |
173 | * What is the fastest rate at which we send challenges *if* we keep learning | 179 | * What is the fastest rate at which we send challenges *if* we keep learning |
174 | * an address (gossip, DHT, etc.)? | 180 | * an address (gossip, DHT, etc.)? |
175 | */ | 181 | */ |
176 | #define FAST_VALIDATION_CHALLENGE_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) | 182 | #define FAST_VALIDATION_CHALLENGE_FREQ \ |
183 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) | ||
177 | 184 | ||
178 | /** | 185 | /** |
179 | * What is the slowest rate at which we send challenges? | 186 | * What is the slowest rate at which we send challenges? |
180 | */ | 187 | */ |
181 | #define MAX_VALIDATION_CHALLENGE_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1) | 188 | #define MAX_VALIDATION_CHALLENGE_FREQ \ |
189 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1) | ||
182 | 190 | ||
183 | /** | 191 | /** |
184 | * What is the non-randomized base frequency at which we | 192 | * What is the non-randomized base frequency at which we |
@@ -195,11 +203,13 @@ | |||
195 | /** | 203 | /** |
196 | * When do we forget an invalid address for sure? | 204 | * When do we forget an invalid address for sure? |
197 | */ | 205 | */ |
198 | #define MAX_ADDRESS_VALID_UNTIL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1) | 206 | #define MAX_ADDRESS_VALID_UNTIL \ |
207 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1) | ||
199 | /** | 208 | /** |
200 | * How long do we consider an address valid if we just checked? | 209 | * How long do we consider an address valid if we just checked? |
201 | */ | 210 | */ |
202 | #define ADDRESS_VALIDATION_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) | 211 | #define ADDRESS_VALIDATION_LIFETIME \ |
212 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) | ||
203 | 213 | ||
204 | /** | 214 | /** |
205 | * What is the maximum frequency at which we do address validation? | 215 | * What is the maximum frequency at which we do address validation? |
@@ -319,7 +329,6 @@ struct EphemeralConfirmation | |||
319 | * to encrypt the payload. | 329 | * to encrypt the payload. |
320 | */ | 330 | */ |
321 | struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; | 331 | struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; |
322 | |||
323 | }; | 332 | }; |
324 | 333 | ||
325 | 334 | ||
@@ -374,7 +383,6 @@ struct TransportBackchannelRequestPayload | |||
374 | 383 | ||
375 | /* Followed by a 0-termianted string specifying the name of | 384 | /* Followed by a 0-termianted string specifying the name of |
376 | the communicator which is to receive the message */ | 385 | the communicator which is to receive the message */ |
377 | |||
378 | }; | 386 | }; |
379 | 387 | ||
380 | 388 | ||
@@ -473,7 +481,6 @@ struct TransportFragmentBox | |||
473 | * Total size of the message that is being fragmented. | 481 | * Total size of the message that is being fragmented. |
474 | */ | 482 | */ |
475 | uint16_t msg_size GNUNET_PACKED; | 483 | uint16_t msg_size GNUNET_PACKED; |
476 | |||
477 | }; | 484 | }; |
478 | 485 | ||
479 | 486 | ||
@@ -567,7 +574,6 @@ struct DvInitPS | |||
567 | * Challenge value used by the initiator to re-identify the path. | 574 | * Challenge value used by the initiator to re-identify the path. |
568 | */ | 575 | */ |
569 | struct GNUNET_ShortHashCode challenge; | 576 | struct GNUNET_ShortHashCode challenge; |
570 | |||
571 | }; | 577 | }; |
572 | 578 | ||
573 | 579 | ||
@@ -608,7 +614,6 @@ struct DvHopPS | |||
608 | * Challenge value used by the initiator to re-identify the path. | 614 | * Challenge value used by the initiator to re-identify the path. |
609 | */ | 615 | */ |
610 | struct GNUNET_ShortHashCode challenge; | 616 | struct GNUNET_ShortHashCode challenge; |
611 | |||
612 | }; | 617 | }; |
613 | 618 | ||
614 | 619 | ||
@@ -628,7 +633,6 @@ struct DVPathEntryP | |||
628 | * #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP | 633 | * #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP |
629 | */ | 634 | */ |
630 | struct GNUNET_CRYPTO_EddsaSignature hop_sig; | 635 | struct GNUNET_CRYPTO_EddsaSignature hop_sig; |
631 | |||
632 | }; | 636 | }; |
633 | 637 | ||
634 | 638 | ||
@@ -694,7 +698,6 @@ struct TransportDVLearn | |||
694 | /* Followed by @e num_hops `struct DVPathEntryP` values, | 698 | /* Followed by @e num_hops `struct DVPathEntryP` values, |
695 | excluding the initiator of the DV trace; the last entry is the | 699 | excluding the initiator of the DV trace; the last entry is the |
696 | current sender; the current peer must not be included. */ | 700 | current sender; the current peer must not be included. */ |
697 | |||
698 | }; | 701 | }; |
699 | 702 | ||
700 | 703 | ||
@@ -799,7 +802,6 @@ struct TransportValidationPS | |||
799 | * Challenge signed by the receiving peer. | 802 | * Challenge signed by the receiving peer. |
800 | */ | 803 | */ |
801 | struct GNUNET_ShortHashCode challenge; | 804 | struct GNUNET_ShortHashCode challenge; |
802 | |||
803 | }; | 805 | }; |
804 | 806 | ||
805 | 807 | ||
@@ -845,15 +847,13 @@ struct TransportValidationResponse | |||
845 | }; | 847 | }; |
846 | 848 | ||
847 | 849 | ||
848 | |||
849 | GNUNET_NETWORK_STRUCT_END | 850 | GNUNET_NETWORK_STRUCT_END |
850 | 851 | ||
851 | 852 | ||
852 | /** | 853 | /** |
853 | * What type of client is the `struct TransportClient` about? | 854 | * What type of client is the `struct TransportClient` about? |
854 | */ | 855 | */ |
855 | enum ClientType | 856 | enum ClientType { |
856 | { | ||
857 | /** | 857 | /** |
858 | * We do not know yet (client is fresh). | 858 | * We do not know yet (client is fresh). |
859 | */ | 859 | */ |
@@ -907,7 +907,6 @@ struct LearnLaunchEntry | |||
907 | * determine freshness of paths learned via this operation. | 907 | * determine freshness of paths learned via this operation. |
908 | */ | 908 | */ |
909 | struct GNUNET_TIME_Absolute launch_time; | 909 | struct GNUNET_TIME_Absolute launch_time; |
910 | |||
911 | }; | 910 | }; |
912 | 911 | ||
913 | 912 | ||
@@ -1032,8 +1031,9 @@ struct DistanceVectorHop | |||
1032 | struct GNUNET_TIME_Absolute freshness; | 1031 | struct GNUNET_TIME_Absolute freshness; |
1033 | 1032 | ||
1034 | /** | 1033 | /** |
1035 | * How many hops in total to the `target` (excluding @e next_hop and `target` itself), | 1034 | * How many hops in total to the `target` (excluding @e next_hop and `target` |
1036 | * thus 0 still means a distance of 2 hops (to @e next_hop and then to `target`)? | 1035 | * itself), thus 0 still means a distance of 2 hops (to @e next_hop and then |
1036 | * to `target`)? | ||
1037 | */ | 1037 | */ |
1038 | unsigned int distance; | 1038 | unsigned int distance; |
1039 | }; | 1039 | }; |
@@ -1313,7 +1313,8 @@ struct ReassemblyContext | |||
1313 | */ | 1313 | */ |
1314 | uint16_t msg_missing; | 1314 | uint16_t msg_missing; |
1315 | 1315 | ||
1316 | /* Followed by @e msg_size bytes of the (partially) defragmented original message */ | 1316 | /* Followed by @e msg_size bytes of the (partially) defragmented original |
1317 | * message */ | ||
1317 | 1318 | ||
1318 | /* Followed by @e bitfield data */ | 1319 | /* Followed by @e bitfield data */ |
1319 | }; | 1320 | }; |
@@ -1401,7 +1402,6 @@ struct Neighbour | |||
1401 | * What is the earliest timeout of any message in @e pending_msg_tail? | 1402 | * What is the earliest timeout of any message in @e pending_msg_tail? |
1402 | */ | 1403 | */ |
1403 | struct GNUNET_TIME_Absolute earliest_timeout; | 1404 | struct GNUNET_TIME_Absolute earliest_timeout; |
1404 | |||
1405 | }; | 1405 | }; |
1406 | 1406 | ||
1407 | 1407 | ||
@@ -1435,15 +1435,13 @@ struct PeerRequest | |||
1435 | * How much bandwidth would this @e tc like to see? | 1435 | * How much bandwidth would this @e tc like to see? |
1436 | */ | 1436 | */ |
1437 | struct GNUNET_BANDWIDTH_Value32NBO bw; | 1437 | struct GNUNET_BANDWIDTH_Value32NBO bw; |
1438 | |||
1439 | }; | 1438 | }; |
1440 | 1439 | ||
1441 | 1440 | ||
1442 | /** | 1441 | /** |
1443 | * Types of different pending messages. | 1442 | * Types of different pending messages. |
1444 | */ | 1443 | */ |
1445 | enum PendingMessageType | 1444 | enum PendingMessageType { |
1446 | { | ||
1447 | 1445 | ||
1448 | /** | 1446 | /** |
1449 | * Ordinary message received from the CORE service. | 1447 | * Ordinary message received from the CORE service. |
@@ -1517,17 +1515,20 @@ struct PendingMessage | |||
1517 | struct PendingMessage *prev_client; | 1515 | struct PendingMessage *prev_client; |
1518 | 1516 | ||
1519 | /** | 1517 | /** |
1520 | * Kept in a MDLL of messages from this @a cpm (if @e pmt is #PMT_FRAGMENT_BOx) | 1518 | * Kept in a MDLL of messages from this @a cpm (if @e pmt is |
1519 | * #PMT_FRAGMENT_BOx) | ||
1521 | */ | 1520 | */ |
1522 | struct PendingMessage *next_frag; | 1521 | struct PendingMessage *next_frag; |
1523 | 1522 | ||
1524 | /** | 1523 | /** |
1525 | * Kept in a MDLL of messages from this @a cpm (if @e pmt is #PMT_FRAGMENT_BOX) | 1524 | * Kept in a MDLL of messages from this @a cpm (if @e pmt is |
1525 | * #PMT_FRAGMENT_BOX) | ||
1526 | */ | 1526 | */ |
1527 | struct PendingMessage *prev_frag; | 1527 | struct PendingMessage *prev_frag; |
1528 | 1528 | ||
1529 | /** | 1529 | /** |
1530 | * This message, reliability boxed. Only possibly available if @e pmt is #PMT_CORE. | 1530 | * This message, reliability boxed. Only possibly available if @e pmt is |
1531 | * #PMT_CORE. | ||
1531 | */ | 1532 | */ |
1532 | struct PendingMessage *bpm; | 1533 | struct PendingMessage *bpm; |
1533 | 1534 | ||
@@ -1652,7 +1653,6 @@ struct AddressListEntry | |||
1652 | * Network type offered by this address. | 1653 | * Network type offered by this address. |
1653 | */ | 1654 | */ |
1654 | enum GNUNET_NetworkType nt; | 1655 | enum GNUNET_NetworkType nt; |
1655 | |||
1656 | }; | 1656 | }; |
1657 | 1657 | ||
1658 | 1658 | ||
@@ -1693,7 +1693,8 @@ struct TransportClient | |||
1693 | /** | 1693 | /** |
1694 | * Information for @e type #CT_CORE. | 1694 | * Information for @e type #CT_CORE. |
1695 | */ | 1695 | */ |
1696 | struct { | 1696 | struct |
1697 | { | ||
1697 | 1698 | ||
1698 | /** | 1699 | /** |
1699 | * Head of list of messages pending for this client, sorted by | 1700 | * Head of list of messages pending for this client, sorted by |
@@ -1711,7 +1712,8 @@ struct TransportClient | |||
1711 | /** | 1712 | /** |
1712 | * Information for @e type #CT_MONITOR. | 1713 | * Information for @e type #CT_MONITOR. |
1713 | */ | 1714 | */ |
1714 | struct { | 1715 | struct |
1716 | { | ||
1715 | 1717 | ||
1716 | /** | 1718 | /** |
1717 | * Peer identity to monitor the addresses of. | 1719 | * Peer identity to monitor the addresses of. |
@@ -1731,7 +1733,8 @@ struct TransportClient | |||
1731 | /** | 1733 | /** |
1732 | * Information for @e type #CT_COMMUNICATOR. | 1734 | * Information for @e type #CT_COMMUNICATOR. |
1733 | */ | 1735 | */ |
1734 | struct { | 1736 | struct |
1737 | { | ||
1735 | /** | 1738 | /** |
1736 | * If @e type is #CT_COMMUNICATOR, this communicator | 1739 | * If @e type is #CT_COMMUNICATOR, this communicator |
1737 | * supports communicating using these addresses. | 1740 | * supports communicating using these addresses. |
@@ -1749,12 +1752,14 @@ struct TransportClient | |||
1749 | struct Queue *queue_tail; | 1752 | struct Queue *queue_tail; |
1750 | 1753 | ||
1751 | /** | 1754 | /** |
1752 | * Head of list of the addresses of this peer offered by this communicator. | 1755 | * Head of list of the addresses of this peer offered by this |
1756 | * communicator. | ||
1753 | */ | 1757 | */ |
1754 | struct AddressListEntry *addr_head; | 1758 | struct AddressListEntry *addr_head; |
1755 | 1759 | ||
1756 | /** | 1760 | /** |
1757 | * Tail of list of the addresses of this peer offered by this communicator. | 1761 | * Tail of list of the addresses of this peer offered by this |
1762 | * communicator. | ||
1758 | */ | 1763 | */ |
1759 | struct AddressListEntry *addr_tail; | 1764 | struct AddressListEntry *addr_tail; |
1760 | 1765 | ||
@@ -1775,7 +1780,8 @@ struct TransportClient | |||
1775 | /** | 1780 | /** |
1776 | * Information for @e type #CT_APPLICATION | 1781 | * Information for @e type #CT_APPLICATION |
1777 | */ | 1782 | */ |
1778 | struct { | 1783 | struct |
1784 | { | ||
1779 | 1785 | ||
1780 | /** | 1786 | /** |
1781 | * Map of requests for peers the given client application would like to | 1787 | * Map of requests for peers the given client application would like to |
@@ -1786,7 +1792,6 @@ struct TransportClient | |||
1786 | } application; | 1792 | } application; |
1787 | 1793 | ||
1788 | } details; | 1794 | } details; |
1789 | |||
1790 | }; | 1795 | }; |
1791 | 1796 | ||
1792 | 1797 | ||
@@ -1890,7 +1895,6 @@ struct ValidationState | |||
1890 | * the respective queue to become available for transmission. | 1895 | * the respective queue to become available for transmission. |
1891 | */ | 1896 | */ |
1892 | int awaiting_queue; | 1897 | int awaiting_queue; |
1893 | |||
1894 | }; | 1898 | }; |
1895 | 1899 | ||
1896 | 1900 | ||
@@ -2008,9 +2012,7 @@ static struct GNUNET_SCHEDULER_Task *validation_task; | |||
2008 | static void | 2012 | static void |
2009 | free_ephemeral (struct EphemeralCacheEntry *ece) | 2013 | free_ephemeral (struct EphemeralCacheEntry *ece) |
2010 | { | 2014 | { |
2011 | GNUNET_CONTAINER_multipeermap_remove (ephemeral_map, | 2015 | GNUNET_CONTAINER_multipeermap_remove (ephemeral_map, &ece->target, ece); |
2012 | &ece->target, | ||
2013 | ece); | ||
2014 | GNUNET_CONTAINER_heap_remove_node (ece->hn); | 2016 | GNUNET_CONTAINER_heap_remove_node (ece->hn); |
2015 | GNUNET_free (ece); | 2017 | GNUNET_free (ece); |
2016 | } | 2018 | } |
@@ -2024,13 +2026,10 @@ free_ephemeral (struct EphemeralCacheEntry *ece) | |||
2024 | static void | 2026 | static void |
2025 | free_validation_state (struct ValidationState *vs) | 2027 | free_validation_state (struct ValidationState *vs) |
2026 | { | 2028 | { |
2027 | GNUNET_CONTAINER_multipeermap_remove (validation_map, | 2029 | GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs); |
2028 | &vs->pid, | ||
2029 | vs); | ||
2030 | GNUNET_CONTAINER_heap_remove_node (vs->hn); | 2030 | GNUNET_CONTAINER_heap_remove_node (vs->hn); |
2031 | vs->hn = NULL; | 2031 | vs->hn = NULL; |
2032 | if (NULL != vs->sc) | 2032 | if (NULL != vs->sc) { |
2033 | { | ||
2034 | GNUNET_PEERSTORE_store_cancel (vs->sc); | 2033 | GNUNET_PEERSTORE_store_cancel (vs->sc); |
2035 | vs->sc = NULL; | 2034 | vs->sc = NULL; |
2036 | } | 2035 | } |
@@ -2048,8 +2047,7 @@ free_validation_state (struct ValidationState *vs) | |||
2048 | static struct Neighbour * | 2047 | static struct Neighbour * |
2049 | lookup_neighbour (const struct GNUNET_PeerIdentity *pid) | 2048 | lookup_neighbour (const struct GNUNET_PeerIdentity *pid) |
2050 | { | 2049 | { |
2051 | return GNUNET_CONTAINER_multipeermap_get (neighbours, | 2050 | return GNUNET_CONTAINER_multipeermap_get (neighbours, pid); |
2052 | pid); | ||
2053 | } | 2051 | } |
2054 | 2052 | ||
2055 | 2053 | ||
@@ -2084,8 +2082,6 @@ struct MonitorEvent | |||
2084 | * Bytes pending. | 2082 | * Bytes pending. |
2085 | */ | 2083 | */ |
2086 | uint32_t num_bytes_pending; | 2084 | uint32_t num_bytes_pending; |
2087 | |||
2088 | |||
2089 | }; | 2085 | }; |
2090 | 2086 | ||
2091 | 2087 | ||
@@ -2103,14 +2099,8 @@ free_distance_vector_hop (struct DistanceVectorHop *dvh) | |||
2103 | struct Neighbour *n = dvh->next_hop; | 2099 | struct Neighbour *n = dvh->next_hop; |
2104 | struct DistanceVector *dv = dvh->dv; | 2100 | struct DistanceVector *dv = dvh->dv; |
2105 | 2101 | ||
2106 | GNUNET_CONTAINER_MDLL_remove (neighbour, | 2102 | GNUNET_CONTAINER_MDLL_remove (neighbour, n->dv_head, n->dv_tail, dvh); |
2107 | n->dv_head, | 2103 | GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, dvh); |
2108 | n->dv_tail, | ||
2109 | dvh); | ||
2110 | GNUNET_CONTAINER_MDLL_remove (dv, | ||
2111 | dv->dv_head, | ||
2112 | dv->dv_tail, | ||
2113 | dvh); | ||
2114 | GNUNET_free (dvh); | 2104 | GNUNET_free (dvh); |
2115 | } | 2105 | } |
2116 | 2106 | ||
@@ -2128,12 +2118,10 @@ free_dv_route (struct DistanceVector *dv) | |||
2128 | 2118 | ||
2129 | while (NULL != (dvh = dv->dv_head)) | 2119 | while (NULL != (dvh = dv->dv_head)) |
2130 | free_distance_vector_hop (dvh); | 2120 | free_distance_vector_hop (dvh); |
2131 | if (NULL == dv->dv_head) | 2121 | if (NULL == dv->dv_head) { |
2132 | { | 2122 | GNUNET_assert ( |
2133 | GNUNET_assert (GNUNET_YES == | 2123 | GNUNET_YES |
2134 | GNUNET_CONTAINER_multipeermap_remove (dv_routes, | 2124 | == GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv)); |
2135 | &dv->target, | ||
2136 | dv)); | ||
2137 | if (NULL != dv->timeout_task) | 2125 | if (NULL != dv->timeout_task) |
2138 | GNUNET_SCHEDULER_cancel (dv->timeout_task); | 2126 | GNUNET_SCHEDULER_cancel (dv->timeout_task); |
2139 | GNUNET_free (dv); | 2127 | GNUNET_free (dv); |
@@ -2168,20 +2156,17 @@ notify_monitor (struct TransportClient *tc, | |||
2168 | env = GNUNET_MQ_msg_extra (md, | 2156 | env = GNUNET_MQ_msg_extra (md, |
2169 | addr_len, | 2157 | addr_len, |
2170 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA); | 2158 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA); |
2171 | md->nt = htonl ((uint32_t) nt); | 2159 | md->nt = htonl ((uint32_t)nt); |
2172 | md->peer = *peer; | 2160 | md->peer = *peer; |
2173 | md->last_validation = GNUNET_TIME_absolute_hton (me->last_validation); | 2161 | md->last_validation = GNUNET_TIME_absolute_hton (me->last_validation); |
2174 | md->valid_until = GNUNET_TIME_absolute_hton (me->valid_until); | 2162 | md->valid_until = GNUNET_TIME_absolute_hton (me->valid_until); |
2175 | md->next_validation = GNUNET_TIME_absolute_hton (me->next_validation); | 2163 | md->next_validation = GNUNET_TIME_absolute_hton (me->next_validation); |
2176 | md->rtt = GNUNET_TIME_relative_hton (me->rtt); | 2164 | md->rtt = GNUNET_TIME_relative_hton (me->rtt); |
2177 | md->cs = htonl ((uint32_t) me->cs); | 2165 | md->cs = htonl ((uint32_t)me->cs); |
2178 | md->num_msg_pending = htonl (me->num_msg_pending); | 2166 | md->num_msg_pending = htonl (me->num_msg_pending); |
2179 | md->num_bytes_pending = htonl (me->num_bytes_pending); | 2167 | md->num_bytes_pending = htonl (me->num_bytes_pending); |
2180 | memcpy (&md[1], | 2168 | memcpy (&md[1], address, addr_len); |
2181 | address, | 2169 | GNUNET_MQ_send (tc->mq, env); |
2182 | addr_len); | ||
2183 | GNUNET_MQ_send (tc->mq, | ||
2184 | env); | ||
2185 | } | 2170 | } |
2186 | 2171 | ||
2187 | 2172 | ||
@@ -2200,23 +2185,15 @@ notify_monitors (const struct GNUNET_PeerIdentity *peer, | |||
2200 | enum GNUNET_NetworkType nt, | 2185 | enum GNUNET_NetworkType nt, |
2201 | const struct MonitorEvent *me) | 2186 | const struct MonitorEvent *me) |
2202 | { | 2187 | { |
2203 | for (struct TransportClient *tc = clients_head; | 2188 | for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) { |
2204 | NULL != tc; | ||
2205 | tc = tc->next) | ||
2206 | { | ||
2207 | if (CT_MONITOR != tc->type) | 2189 | if (CT_MONITOR != tc->type) |
2208 | continue; | 2190 | continue; |
2209 | if (tc->details.monitor.one_shot) | 2191 | if (tc->details.monitor.one_shot) |
2210 | continue; | 2192 | continue; |
2211 | if ( (0 != GNUNET_is_zero (&tc->details.monitor.peer)) && | 2193 | if ((0 != GNUNET_is_zero (&tc->details.monitor.peer)) |
2212 | (0 != GNUNET_memcmp (&tc->details.monitor.peer, | 2194 | && (0 != GNUNET_memcmp (&tc->details.monitor.peer, peer))) |
2213 | peer)) ) | ||
2214 | continue; | 2195 | continue; |
2215 | notify_monitor (tc, | 2196 | notify_monitor (tc, peer, address, nt, me); |
2216 | peer, | ||
2217 | address, | ||
2218 | nt, | ||
2219 | me); | ||
2220 | } | 2197 | } |
2221 | } | 2198 | } |
2222 | 2199 | ||
@@ -2237,16 +2214,12 @@ client_connect_cb (void *cls, | |||
2237 | { | 2214 | { |
2238 | struct TransportClient *tc; | 2215 | struct TransportClient *tc; |
2239 | 2216 | ||
2240 | (void) cls; | 2217 | (void)cls; |
2241 | tc = GNUNET_new (struct TransportClient); | 2218 | tc = GNUNET_new (struct TransportClient); |
2242 | tc->client = client; | 2219 | tc->client = client; |
2243 | tc->mq = mq; | 2220 | tc->mq = mq; |
2244 | GNUNET_CONTAINER_DLL_insert (clients_head, | 2221 | GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc); |
2245 | clients_tail, | 2222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); |
2246 | tc); | ||
2247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2248 | "Client %p connected\n", | ||
2249 | tc); | ||
2250 | return tc; | 2223 | return tc; |
2251 | } | 2224 | } |
2252 | 2225 | ||
@@ -2261,12 +2234,11 @@ free_reassembly_context (struct ReassemblyContext *rc) | |||
2261 | { | 2234 | { |
2262 | struct Neighbour *n = rc->neighbour; | 2235 | struct Neighbour *n = rc->neighbour; |
2263 | 2236 | ||
2264 | GNUNET_assert (rc == | 2237 | GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn)); |
2265 | GNUNET_CONTAINER_heap_remove_node (rc->hn)); | 2238 | GNUNET_assert (GNUNET_OK |
2266 | GNUNET_assert (GNUNET_OK == | 2239 | == GNUNET_CONTAINER_multishortmap_remove (n->reassembly_map, |
2267 | GNUNET_CONTAINER_multishortmap_remove (n->reassembly_map, | 2240 | &rc->msg_uuid, |
2268 | &rc->msg_uuid, | 2241 | rc)); |
2269 | rc)); | ||
2270 | GNUNET_free (rc); | 2242 | GNUNET_free (rc); |
2271 | } | 2243 | } |
2272 | 2244 | ||
@@ -2283,17 +2255,18 @@ reassembly_cleanup_task (void *cls) | |||
2283 | struct ReassemblyContext *rc; | 2255 | struct ReassemblyContext *rc; |
2284 | 2256 | ||
2285 | n->reassembly_timeout_task = NULL; | 2257 | n->reassembly_timeout_task = NULL; |
2286 | while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap))) | 2258 | while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap))) { |
2287 | { | 2259 | if (0 |
2288 | if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout).rel_value_us) | 2260 | == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout) |
2289 | { | 2261 | .rel_value_us) { |
2290 | free_reassembly_context (rc); | 2262 | free_reassembly_context (rc); |
2291 | continue; | 2263 | continue; |
2292 | } | 2264 | } |
2293 | GNUNET_assert (NULL == n->reassembly_timeout_task); | 2265 | GNUNET_assert (NULL == n->reassembly_timeout_task); |
2294 | n->reassembly_timeout_task = GNUNET_SCHEDULER_add_at (rc->reassembly_timeout, | 2266 | n->reassembly_timeout_task |
2295 | &reassembly_cleanup_task, | 2267 | = GNUNET_SCHEDULER_add_at (rc->reassembly_timeout, |
2296 | n); | 2268 | &reassembly_cleanup_task, |
2269 | n); | ||
2297 | return; | 2270 | return; |
2298 | } | 2271 | } |
2299 | } | 2272 | } |
@@ -2313,8 +2286,8 @@ free_reassembly_cb (void *cls, | |||
2313 | void *value) | 2286 | void *value) |
2314 | { | 2287 | { |
2315 | struct ReassemblyContext *rc = value; | 2288 | struct ReassemblyContext *rc = value; |
2316 | (void) cls; | 2289 | (void)cls; |
2317 | (void) key; | 2290 | (void)key; |
2318 | 2291 | ||
2319 | free_reassembly_context (rc); | 2292 | free_reassembly_context (rc); |
2320 | return GNUNET_OK; | 2293 | return GNUNET_OK; |
@@ -2332,14 +2305,13 @@ free_neighbour (struct Neighbour *neighbour) | |||
2332 | struct DistanceVectorHop *dvh; | 2305 | struct DistanceVectorHop *dvh; |
2333 | 2306 | ||
2334 | GNUNET_assert (NULL == neighbour->queue_head); | 2307 | GNUNET_assert (NULL == neighbour->queue_head); |
2335 | GNUNET_assert (GNUNET_YES == | 2308 | GNUNET_assert (GNUNET_YES |
2336 | GNUNET_CONTAINER_multipeermap_remove (neighbours, | 2309 | == GNUNET_CONTAINER_multipeermap_remove (neighbours, |
2337 | &neighbour->pid, | 2310 | &neighbour->pid, |
2338 | neighbour)); | 2311 | neighbour)); |
2339 | if (NULL != neighbour->timeout_task) | 2312 | if (NULL != neighbour->timeout_task) |
2340 | GNUNET_SCHEDULER_cancel (neighbour->timeout_task); | 2313 | GNUNET_SCHEDULER_cancel (neighbour->timeout_task); |
2341 | if (NULL != neighbour->reassembly_map) | 2314 | if (NULL != neighbour->reassembly_map) { |
2342 | { | ||
2343 | GNUNET_CONTAINER_multishortmap_iterate (neighbour->reassembly_map, | 2315 | GNUNET_CONTAINER_multishortmap_iterate (neighbour->reassembly_map, |
2344 | &free_reassembly_cb, | 2316 | &free_reassembly_cb, |
2345 | NULL); | 2317 | NULL); |
@@ -2348,8 +2320,7 @@ free_neighbour (struct Neighbour *neighbour) | |||
2348 | GNUNET_CONTAINER_heap_destroy (neighbour->reassembly_heap); | 2320 | GNUNET_CONTAINER_heap_destroy (neighbour->reassembly_heap); |
2349 | neighbour->reassembly_heap = NULL; | 2321 | neighbour->reassembly_heap = NULL; |
2350 | } | 2322 | } |
2351 | while (NULL != (dvh = neighbour->dv_head)) | 2323 | while (NULL != (dvh = neighbour->dv_head)) { |
2352 | { | ||
2353 | struct DistanceVector *dv = dvh->dv; | 2324 | struct DistanceVector *dv = dvh->dv; |
2354 | 2325 | ||
2355 | free_distance_vector_hop (dvh); | 2326 | free_distance_vector_hop (dvh); |
@@ -2378,12 +2349,10 @@ core_send_connect_info (struct TransportClient *tc, | |||
2378 | struct ConnectInfoMessage *cim; | 2349 | struct ConnectInfoMessage *cim; |
2379 | 2350 | ||
2380 | GNUNET_assert (CT_CORE == tc->type); | 2351 | GNUNET_assert (CT_CORE == tc->type); |
2381 | env = GNUNET_MQ_msg (cim, | 2352 | env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); |
2382 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); | ||
2383 | cim->quota_out = quota_out; | 2353 | cim->quota_out = quota_out; |
2384 | cim->id = *pid; | 2354 | cim->id = *pid; |
2385 | GNUNET_MQ_send (tc->mq, | 2355 | GNUNET_MQ_send (tc->mq, env); |
2386 | env); | ||
2387 | } | 2356 | } |
2388 | 2357 | ||
2389 | 2358 | ||
@@ -2397,15 +2366,10 @@ static void | |||
2397 | cores_send_connect_info (const struct GNUNET_PeerIdentity *pid, | 2366 | cores_send_connect_info (const struct GNUNET_PeerIdentity *pid, |
2398 | struct GNUNET_BANDWIDTH_Value32NBO quota_out) | 2367 | struct GNUNET_BANDWIDTH_Value32NBO quota_out) |
2399 | { | 2368 | { |
2400 | for (struct TransportClient *tc = clients_head; | 2369 | for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) { |
2401 | NULL != tc; | ||
2402 | tc = tc->next) | ||
2403 | { | ||
2404 | if (CT_CORE != tc->type) | 2370 | if (CT_CORE != tc->type) |
2405 | continue; | 2371 | continue; |
2406 | core_send_connect_info (tc, | 2372 | core_send_connect_info (tc, pid, quota_out); |
2407 | pid, | ||
2408 | quota_out); | ||
2409 | } | 2373 | } |
2410 | } | 2374 | } |
2411 | 2375 | ||
@@ -2418,20 +2382,15 @@ cores_send_connect_info (const struct GNUNET_PeerIdentity *pid, | |||
2418 | static void | 2382 | static void |
2419 | cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid) | 2383 | cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid) |
2420 | { | 2384 | { |
2421 | for (struct TransportClient *tc = clients_head; | 2385 | for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) { |
2422 | NULL != tc; | ||
2423 | tc = tc->next) | ||
2424 | { | ||
2425 | struct GNUNET_MQ_Envelope *env; | 2386 | struct GNUNET_MQ_Envelope *env; |
2426 | struct DisconnectInfoMessage *dim; | 2387 | struct DisconnectInfoMessage *dim; |
2427 | 2388 | ||
2428 | if (CT_CORE != tc->type) | 2389 | if (CT_CORE != tc->type) |
2429 | continue; | 2390 | continue; |
2430 | env = GNUNET_MQ_msg (dim, | 2391 | env = GNUNET_MQ_msg (dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); |
2431 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); | ||
2432 | dim->peer = *pid; | 2392 | dim->peer = *pid; |
2433 | GNUNET_MQ_send (tc->mq, | 2393 | GNUNET_MQ_send (tc->mq, env); |
2434 | env); | ||
2435 | } | 2394 | } |
2436 | } | 2395 | } |
2437 | 2396 | ||
@@ -2466,50 +2425,45 @@ schedule_transmit_on_queue (struct Queue *queue) | |||
2466 | unsigned int wsize; | 2425 | unsigned int wsize; |
2467 | 2426 | ||
2468 | GNUNET_assert (NULL != pm); | 2427 | GNUNET_assert (NULL != pm); |
2469 | if (queue->tc->details.communicator.total_queue_length >= | 2428 | if (queue->tc->details.communicator.total_queue_length |
2470 | COMMUNICATOR_TOTAL_QUEUE_LIMIT) | 2429 | >= COMMUNICATOR_TOTAL_QUEUE_LIMIT) { |
2471 | { | 2430 | GNUNET_STATISTICS_update ( |
2472 | GNUNET_STATISTICS_update (GST_stats, | 2431 | GST_stats, |
2473 | "# Transmission throttled due to communicator queue limit", | 2432 | "# Transmission throttled due to communicator queue limit", |
2474 | 1, | 2433 | 1, |
2475 | GNUNET_NO); | 2434 | GNUNET_NO); |
2476 | return; | 2435 | return; |
2477 | } | 2436 | } |
2478 | if (queue->queue_length >= QUEUE_LENGTH_LIMIT) | 2437 | if (queue->queue_length >= QUEUE_LENGTH_LIMIT) { |
2479 | { | 2438 | GNUNET_STATISTICS_update ( |
2480 | GNUNET_STATISTICS_update (GST_stats, | 2439 | GST_stats, |
2481 | "# Transmission throttled due to queue queue limit", | 2440 | "# Transmission throttled due to queue queue limit", |
2482 | 1, | 2441 | 1, |
2483 | GNUNET_NO); | 2442 | GNUNET_NO); |
2484 | return; | 2443 | return; |
2485 | } | 2444 | } |
2486 | 2445 | ||
2487 | wsize = (0 == queue->mtu) | 2446 | wsize = (0 == queue->mtu) ? pm->bytes_msg /* FIXME: add overheads? */ |
2488 | ? pm->bytes_msg /* FIXME: add overheads? */ | 2447 | : queue->mtu; |
2489 | : queue->mtu; | 2448 | out_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_out, wsize); |
2490 | out_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_out, | 2449 | out_delay = GNUNET_TIME_relative_max ( |
2491 | wsize); | 2450 | GNUNET_TIME_absolute_get_remaining (pm->next_attempt), |
2492 | out_delay = GNUNET_TIME_relative_max (GNUNET_TIME_absolute_get_remaining (pm->next_attempt), | 2451 | out_delay); |
2493 | out_delay); | ||
2494 | if (0 == out_delay.rel_value_us) | 2452 | if (0 == out_delay.rel_value_us) |
2495 | return; /* we should run immediately! */ | 2453 | return; /* we should run immediately! */ |
2496 | /* queue has changed since we were scheduled, reschedule again */ | 2454 | /* queue has changed since we were scheduled, reschedule again */ |
2497 | queue->transmit_task | 2455 | queue->transmit_task |
2498 | = GNUNET_SCHEDULER_add_delayed (out_delay, | 2456 | = GNUNET_SCHEDULER_add_delayed (out_delay, &transmit_on_queue, queue); |
2499 | &transmit_on_queue, | ||
2500 | queue); | ||
2501 | if (out_delay.rel_value_us > DELAY_WARN_THRESHOLD.rel_value_us) | 2457 | if (out_delay.rel_value_us > DELAY_WARN_THRESHOLD.rel_value_us) |
2502 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2458 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2503 | "Next transmission on queue `%s' in %s (high delay)\n", | 2459 | "Next transmission on queue `%s' in %s (high delay)\n", |
2504 | queue->address, | 2460 | queue->address, |
2505 | GNUNET_STRINGS_relative_time_to_string (out_delay, | 2461 | GNUNET_STRINGS_relative_time_to_string (out_delay, GNUNET_YES)); |
2506 | GNUNET_YES)); | ||
2507 | else | 2462 | else |
2508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2509 | "Next transmission on queue `%s' in %s\n", | 2464 | "Next transmission on queue `%s' in %s\n", |
2510 | queue->address, | 2465 | queue->address, |
2511 | GNUNET_STRINGS_relative_time_to_string (out_delay, | 2466 | GNUNET_STRINGS_relative_time_to_string (out_delay, GNUNET_YES)); |
2512 | GNUNET_YES)); | ||
2513 | } | 2467 | } |
2514 | 2468 | ||
2515 | 2469 | ||
@@ -2523,15 +2477,12 @@ free_queue (struct Queue *queue) | |||
2523 | { | 2477 | { |
2524 | struct Neighbour *neighbour = queue->neighbour; | 2478 | struct Neighbour *neighbour = queue->neighbour; |
2525 | struct TransportClient *tc = queue->tc; | 2479 | struct TransportClient *tc = queue->tc; |
2526 | struct MonitorEvent me = { | 2480 | struct MonitorEvent me |
2527 | .cs = GNUNET_TRANSPORT_CS_DOWN, | 2481 | = {.cs = GNUNET_TRANSPORT_CS_DOWN, .rtt = GNUNET_TIME_UNIT_FOREVER_REL}; |
2528 | .rtt = GNUNET_TIME_UNIT_FOREVER_REL | ||
2529 | }; | ||
2530 | struct QueueEntry *qe; | 2482 | struct QueueEntry *qe; |
2531 | int maxxed; | 2483 | int maxxed; |
2532 | 2484 | ||
2533 | if (NULL != queue->transmit_task) | 2485 | if (NULL != queue->transmit_task) { |
2534 | { | ||
2535 | GNUNET_SCHEDULER_cancel (queue->transmit_task); | 2486 | GNUNET_SCHEDULER_cancel (queue->transmit_task); |
2536 | queue->transmit_task = NULL; | 2487 | queue->transmit_task = NULL; |
2537 | } | 2488 | } |
@@ -2543,39 +2494,33 @@ free_queue (struct Queue *queue) | |||
2543 | tc->details.communicator.queue_head, | 2494 | tc->details.communicator.queue_head, |
2544 | tc->details.communicator.queue_tail, | 2495 | tc->details.communicator.queue_tail, |
2545 | queue); | 2496 | queue); |
2546 | maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >= tc->details.communicator.total_queue_length); | 2497 | maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT |
2547 | while (NULL != (qe = queue->queue_head)) | 2498 | >= tc->details.communicator.total_queue_length); |
2548 | { | 2499 | while (NULL != (qe = queue->queue_head)) { |
2549 | GNUNET_CONTAINER_DLL_remove (queue->queue_head, | 2500 | GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe); |
2550 | queue->queue_tail, | ||
2551 | qe); | ||
2552 | queue->queue_length--; | 2501 | queue->queue_length--; |
2553 | tc->details.communicator.total_queue_length--; | 2502 | tc->details.communicator.total_queue_length--; |
2554 | GNUNET_free (qe); | 2503 | GNUNET_free (qe); |
2555 | } | 2504 | } |
2556 | GNUNET_assert (0 == queue->queue_length); | 2505 | GNUNET_assert (0 == queue->queue_length); |
2557 | if ( (maxxed) && | 2506 | if ((maxxed) |
2558 | (COMMUNICATOR_TOTAL_QUEUE_LIMIT < tc->details.communicator.total_queue_length) ) | 2507 | && (COMMUNICATOR_TOTAL_QUEUE_LIMIT |
2559 | { | 2508 | < tc->details.communicator.total_queue_length)) { |
2560 | /* Communicator dropped below threshold, resume all queues */ | 2509 | /* Communicator dropped below threshold, resume all queues */ |
2561 | GNUNET_STATISTICS_update (GST_stats, | 2510 | GNUNET_STATISTICS_update ( |
2562 | "# Transmission throttled due to communicator queue limit", | 2511 | GST_stats, |
2563 | -1, | 2512 | "# Transmission throttled due to communicator queue limit", |
2564 | GNUNET_NO); | 2513 | -1, |
2565 | for (struct Queue *s = tc->details.communicator.queue_head; | 2514 | GNUNET_NO); |
2566 | NULL != s; | 2515 | for (struct Queue *s = tc->details.communicator.queue_head; NULL != s; |
2567 | s = s->next_client) | 2516 | s = s->next_client) |
2568 | schedule_transmit_on_queue (s); | 2517 | schedule_transmit_on_queue (s); |
2569 | } | 2518 | } |
2570 | notify_monitors (&neighbour->pid, | 2519 | notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); |
2571 | queue->address, | ||
2572 | queue->nt, | ||
2573 | &me); | ||
2574 | GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_in); | 2520 | GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_in); |
2575 | GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_out); | 2521 | GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_out); |
2576 | GNUNET_free (queue); | 2522 | GNUNET_free (queue); |
2577 | if (NULL == neighbour->queue_head) | 2523 | if (NULL == neighbour->queue_head) { |
2578 | { | ||
2579 | cores_send_disconnect_info (&neighbour->pid); | 2524 | cores_send_disconnect_info (&neighbour->pid); |
2580 | free_neighbour (neighbour); | 2525 | free_neighbour (neighbour); |
2581 | } | 2526 | } |
@@ -2595,13 +2540,11 @@ free_address_list_entry (struct AddressListEntry *ale) | |||
2595 | GNUNET_CONTAINER_DLL_remove (tc->details.communicator.addr_head, | 2540 | GNUNET_CONTAINER_DLL_remove (tc->details.communicator.addr_head, |
2596 | tc->details.communicator.addr_tail, | 2541 | tc->details.communicator.addr_tail, |
2597 | ale); | 2542 | ale); |
2598 | if (NULL != ale->sc) | 2543 | if (NULL != ale->sc) { |
2599 | { | ||
2600 | GNUNET_PEERSTORE_store_cancel (ale->sc); | 2544 | GNUNET_PEERSTORE_store_cancel (ale->sc); |
2601 | ale->sc = NULL; | 2545 | ale->sc = NULL; |
2602 | } | 2546 | } |
2603 | if (NULL != ale->st) | 2547 | if (NULL != ale->st) { |
2604 | { | ||
2605 | GNUNET_SCHEDULER_cancel (ale->st); | 2548 | GNUNET_SCHEDULER_cancel (ale->st); |
2606 | ale->st = NULL; | 2549 | ale->st = NULL; |
2607 | } | 2550 | } |
@@ -2626,10 +2569,11 @@ stop_peer_request (void *cls, | |||
2626 | struct PeerRequest *pr = value; | 2569 | struct PeerRequest *pr = value; |
2627 | 2570 | ||
2628 | GNUNET_PEERSTORE_watch_cancel (pr->wc); | 2571 | GNUNET_PEERSTORE_watch_cancel (pr->wc); |
2629 | GNUNET_assert (GNUNET_YES == | 2572 | GNUNET_assert ( |
2630 | GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, | 2573 | GNUNET_YES |
2631 | pid, | 2574 | == GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, |
2632 | pr)); | 2575 | pid, |
2576 | pr)); | ||
2633 | GNUNET_free (pr); | 2577 | GNUNET_free (pr); |
2634 | 2578 | ||
2635 | return GNUNET_OK; | 2579 | return GNUNET_OK; |
@@ -2651,45 +2595,37 @@ client_disconnect_cb (void *cls, | |||
2651 | { | 2595 | { |
2652 | struct TransportClient *tc = app_ctx; | 2596 | struct TransportClient *tc = app_ctx; |
2653 | 2597 | ||
2654 | (void) cls; | 2598 | (void)cls; |
2655 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2599 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2656 | "Client %p disconnected, cleaning up.\n", | 2600 | "Client %p disconnected, cleaning up.\n", |
2657 | tc); | 2601 | tc); |
2658 | GNUNET_CONTAINER_DLL_remove (clients_head, | 2602 | GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); |
2659 | clients_tail, | 2603 | switch (tc->type) { |
2660 | tc); | ||
2661 | switch (tc->type) | ||
2662 | { | ||
2663 | case CT_NONE: | 2604 | case CT_NONE: |
2664 | break; | 2605 | break; |
2665 | case CT_CORE: | 2606 | case CT_CORE: { |
2666 | { | 2607 | struct PendingMessage *pm; |
2667 | struct PendingMessage *pm; | 2608 | |
2668 | 2609 | while (NULL != (pm = tc->details.core.pending_msg_head)) { | |
2669 | while (NULL != (pm = tc->details.core.pending_msg_head)) | 2610 | GNUNET_CONTAINER_MDLL_remove (client, |
2670 | { | 2611 | tc->details.core.pending_msg_head, |
2671 | GNUNET_CONTAINER_MDLL_remove (client, | 2612 | tc->details.core.pending_msg_tail, |
2672 | tc->details.core.pending_msg_head, | 2613 | pm); |
2673 | tc->details.core.pending_msg_tail, | 2614 | pm->client = NULL; |
2674 | pm); | ||
2675 | pm->client = NULL; | ||
2676 | } | ||
2677 | } | 2615 | } |
2678 | break; | 2616 | } break; |
2679 | case CT_MONITOR: | 2617 | case CT_MONITOR: |
2680 | break; | 2618 | break; |
2681 | case CT_COMMUNICATOR: | 2619 | case CT_COMMUNICATOR: { |
2682 | { | 2620 | struct Queue *q; |
2683 | struct Queue *q; | 2621 | struct AddressListEntry *ale; |
2684 | struct AddressListEntry *ale; | 2622 | |
2685 | 2623 | while (NULL != (q = tc->details.communicator.queue_head)) | |
2686 | while (NULL != (q = tc->details.communicator.queue_head)) | 2624 | free_queue (q); |
2687 | free_queue (q); | 2625 | while (NULL != (ale = tc->details.communicator.addr_head)) |
2688 | while (NULL != (ale = tc->details.communicator.addr_head)) | 2626 | free_address_list_entry (ale); |
2689 | free_address_list_entry (ale); | 2627 | GNUNET_free (tc->details.communicator.address_prefix); |
2690 | GNUNET_free (tc->details.communicator.address_prefix); | 2628 | } break; |
2691 | } | ||
2692 | break; | ||
2693 | case CT_APPLICATION: | 2629 | case CT_APPLICATION: |
2694 | GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests, | 2630 | GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests, |
2695 | &stop_peer_request, | 2631 | &stop_peer_request, |
@@ -2718,9 +2654,7 @@ notify_client_connect_info (void *cls, | |||
2718 | struct TransportClient *tc = cls; | 2654 | struct TransportClient *tc = cls; |
2719 | struct Neighbour *neighbour = value; | 2655 | struct Neighbour *neighbour = value; |
2720 | 2656 | ||
2721 | core_send_connect_info (tc, | 2657 | core_send_connect_info (tc, pid, neighbour->quota_out); |
2722 | pid, | ||
2723 | neighbour->quota_out); | ||
2724 | return GNUNET_OK; | 2658 | return GNUNET_OK; |
2725 | } | 2659 | } |
2726 | 2660 | ||
@@ -2734,25 +2668,20 @@ notify_client_connect_info (void *cls, | |||
2734 | * @param start the start message that was sent | 2668 | * @param start the start message that was sent |
2735 | */ | 2669 | */ |
2736 | static void | 2670 | static void |
2737 | handle_client_start (void *cls, | 2671 | handle_client_start (void *cls, const struct StartMessage *start) |
2738 | const struct StartMessage *start) | ||
2739 | { | 2672 | { |
2740 | struct TransportClient *tc = cls; | 2673 | struct TransportClient *tc = cls; |
2741 | uint32_t options; | 2674 | uint32_t options; |
2742 | 2675 | ||
2743 | options = ntohl (start->options); | 2676 | options = ntohl (start->options); |
2744 | if ( (0 != (1 & options)) && | 2677 | if ((0 != (1 & options)) |
2745 | (0 != | 2678 | && (0 != GNUNET_memcmp (&start->self, &GST_my_identity))) { |
2746 | GNUNET_memcmp (&start->self, | ||
2747 | &GST_my_identity)) ) | ||
2748 | { | ||
2749 | /* client thinks this is a different peer, reject */ | 2679 | /* client thinks this is a different peer, reject */ |
2750 | GNUNET_break (0); | 2680 | GNUNET_break (0); |
2751 | GNUNET_SERVICE_client_drop (tc->client); | 2681 | GNUNET_SERVICE_client_drop (tc->client); |
2752 | return; | 2682 | return; |
2753 | } | 2683 | } |
2754 | if (CT_NONE != tc->type) | 2684 | if (CT_NONE != tc->type) { |
2755 | { | ||
2756 | GNUNET_break (0); | 2685 | GNUNET_break (0); |
2757 | GNUNET_SERVICE_client_drop (tc->client); | 2686 | GNUNET_SERVICE_client_drop (tc->client); |
2758 | return; | 2687 | return; |
@@ -2772,27 +2701,23 @@ handle_client_start (void *cls, | |||
2772 | * @param obm the send message that was sent | 2701 | * @param obm the send message that was sent |
2773 | */ | 2702 | */ |
2774 | static int | 2703 | static int |
2775 | check_client_send (void *cls, | 2704 | check_client_send (void *cls, const struct OutboundMessage *obm) |
2776 | const struct OutboundMessage *obm) | ||
2777 | { | 2705 | { |
2778 | struct TransportClient *tc = cls; | 2706 | struct TransportClient *tc = cls; |
2779 | uint16_t size; | 2707 | uint16_t size; |
2780 | const struct GNUNET_MessageHeader *obmm; | 2708 | const struct GNUNET_MessageHeader *obmm; |
2781 | 2709 | ||
2782 | if (CT_CORE != tc->type) | 2710 | if (CT_CORE != tc->type) { |
2783 | { | ||
2784 | GNUNET_break (0); | 2711 | GNUNET_break (0); |
2785 | return GNUNET_SYSERR; | 2712 | return GNUNET_SYSERR; |
2786 | } | 2713 | } |
2787 | size = ntohs (obm->header.size) - sizeof (struct OutboundMessage); | 2714 | size = ntohs (obm->header.size) - sizeof (struct OutboundMessage); |
2788 | if (size < sizeof (struct GNUNET_MessageHeader)) | 2715 | if (size < sizeof (struct GNUNET_MessageHeader)) { |
2789 | { | ||
2790 | GNUNET_break (0); | 2716 | GNUNET_break (0); |
2791 | return GNUNET_SYSERR; | 2717 | return GNUNET_SYSERR; |
2792 | } | 2718 | } |
2793 | obmm = (const struct GNUNET_MessageHeader *) &obm[1]; | 2719 | obmm = (const struct GNUNET_MessageHeader *)&obm[1]; |
2794 | if (size != ntohs (obmm->size)) | 2720 | if (size != ntohs (obmm->size)) { |
2795 | { | ||
2796 | GNUNET_break (0); | 2721 | GNUNET_break (0); |
2797 | return GNUNET_SYSERR; | 2722 | return GNUNET_SYSERR; |
2798 | } | 2723 | } |
@@ -2810,13 +2735,9 @@ free_fragment_tree (struct PendingMessage *root) | |||
2810 | { | 2735 | { |
2811 | struct PendingMessage *frag; | 2736 | struct PendingMessage *frag; |
2812 | 2737 | ||
2813 | while (NULL != (frag = root->head_frag)) | 2738 | while (NULL != (frag = root->head_frag)) { |
2814 | { | ||
2815 | free_fragment_tree (frag); | 2739 | free_fragment_tree (frag); |
2816 | GNUNET_CONTAINER_MDLL_remove (frag, | 2740 | GNUNET_CONTAINER_MDLL_remove (frag, root->head_frag, root->tail_frag, frag); |
2817 | root->head_frag, | ||
2818 | root->tail_frag, | ||
2819 | frag); | ||
2820 | GNUNET_free (frag); | 2741 | GNUNET_free (frag); |
2821 | } | 2742 | } |
2822 | } | 2743 | } |
@@ -2835,8 +2756,7 @@ free_pending_message (struct PendingMessage *pm) | |||
2835 | struct TransportClient *tc = pm->client; | 2756 | struct TransportClient *tc = pm->client; |
2836 | struct Neighbour *target = pm->target; | 2757 | struct Neighbour *target = pm->target; |
2837 | 2758 | ||
2838 | if (NULL != tc) | 2759 | if (NULL != tc) { |
2839 | { | ||
2840 | GNUNET_CONTAINER_MDLL_remove (client, | 2760 | GNUNET_CONTAINER_MDLL_remove (client, |
2841 | tc->details.core.pending_msg_head, | 2761 | tc->details.core.pending_msg_head, |
2842 | tc->details.core.pending_msg_tail, | 2762 | tc->details.core.pending_msg_tail, |
@@ -2874,16 +2794,13 @@ client_send_response (struct PendingMessage *pm, | |||
2874 | struct GNUNET_MQ_Envelope *env; | 2794 | struct GNUNET_MQ_Envelope *env; |
2875 | struct SendOkMessage *som; | 2795 | struct SendOkMessage *som; |
2876 | 2796 | ||
2877 | if (NULL != tc) | 2797 | if (NULL != tc) { |
2878 | { | 2798 | env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); |
2879 | env = GNUNET_MQ_msg (som, | 2799 | som->success = htonl ((uint32_t)success); |
2880 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); | ||
2881 | som->success = htonl ((uint32_t) success); | ||
2882 | som->bytes_msg = htons (pm->bytes_msg); | 2800 | som->bytes_msg = htons (pm->bytes_msg); |
2883 | som->bytes_physical = htonl (bytes_physical); | 2801 | som->bytes_physical = htonl (bytes_physical); |
2884 | som->peer = target->pid; | 2802 | som->peer = target->pid; |
2885 | GNUNET_MQ_send (tc->mq, | 2803 | GNUNET_MQ_send (tc->mq, env); |
2886 | env); | ||
2887 | } | 2804 | } |
2888 | free_pending_message (pm); | 2805 | free_pending_message (pm); |
2889 | } | 2806 | } |
@@ -2906,30 +2823,25 @@ check_queue_timeouts (void *cls) | |||
2906 | n->timeout_task = NULL; | 2823 | n->timeout_task = NULL; |
2907 | earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 2824 | earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
2908 | now = GNUNET_TIME_absolute_get (); | 2825 | now = GNUNET_TIME_absolute_get (); |
2909 | for (struct PendingMessage *pos = n->pending_msg_head; | 2826 | for (struct PendingMessage *pos = n->pending_msg_head; NULL != pos; |
2910 | NULL != pos; | 2827 | pos = pm) { |
2911 | pos = pm) | ||
2912 | { | ||
2913 | pm = pos->next_neighbour; | 2828 | pm = pos->next_neighbour; |
2914 | if (pos->timeout.abs_value_us <= now.abs_value_us) | 2829 | if (pos->timeout.abs_value_us <= now.abs_value_us) { |
2915 | { | 2830 | GNUNET_STATISTICS_update ( |
2916 | GNUNET_STATISTICS_update (GST_stats, | 2831 | GST_stats, |
2917 | "# messages dropped (timeout before confirmation)", | 2832 | "# messages dropped (timeout before confirmation)", |
2918 | 1, | 2833 | 1, |
2919 | GNUNET_NO); | 2834 | GNUNET_NO); |
2920 | client_send_response (pm, | 2835 | client_send_response (pm, GNUNET_NO, 0); |
2921 | GNUNET_NO, | ||
2922 | 0); | ||
2923 | continue; | 2836 | continue; |
2924 | } | 2837 | } |
2925 | earliest_timeout = GNUNET_TIME_absolute_min (earliest_timeout, | 2838 | earliest_timeout |
2926 | pos->timeout); | 2839 | = GNUNET_TIME_absolute_min (earliest_timeout, pos->timeout); |
2927 | } | 2840 | } |
2928 | n->earliest_timeout = earliest_timeout; | 2841 | n->earliest_timeout = earliest_timeout; |
2929 | if (NULL != n->pending_msg_head) | 2842 | if (NULL != n->pending_msg_head) |
2930 | n->timeout_task = GNUNET_SCHEDULER_add_at (earliest_timeout, | 2843 | n->timeout_task |
2931 | &check_queue_timeouts, | 2844 | = GNUNET_SCHEDULER_add_at (earliest_timeout, &check_queue_timeouts, n); |
2932 | n); | ||
2933 | } | 2845 | } |
2934 | 2846 | ||
2935 | 2847 | ||
@@ -2940,8 +2852,7 @@ check_queue_timeouts (void *cls) | |||
2940 | * @param obm the send message that was sent | 2852 | * @param obm the send message that was sent |
2941 | */ | 2853 | */ |
2942 | static void | 2854 | static void |
2943 | handle_client_send (void *cls, | 2855 | handle_client_send (void *cls, const struct OutboundMessage *obm) |
2944 | const struct OutboundMessage *obm) | ||
2945 | { | 2856 | { |
2946 | struct TransportClient *tc = cls; | 2857 | struct TransportClient *tc = cls; |
2947 | struct PendingMessage *pm; | 2858 | struct PendingMessage *pm; |
@@ -2951,11 +2862,10 @@ handle_client_send (void *cls, | |||
2951 | int was_empty; | 2862 | int was_empty; |
2952 | 2863 | ||
2953 | GNUNET_assert (CT_CORE == tc->type); | 2864 | GNUNET_assert (CT_CORE == tc->type); |
2954 | obmm = (const struct GNUNET_MessageHeader *) &obm[1]; | 2865 | obmm = (const struct GNUNET_MessageHeader *)&obm[1]; |
2955 | bytes_msg = ntohs (obmm->size); | 2866 | bytes_msg = ntohs (obmm->size); |
2956 | target = lookup_neighbour (&obm->peer); | 2867 | target = lookup_neighbour (&obm->peer); |
2957 | if (NULL == target) | 2868 | if (NULL == target) { |
2958 | { | ||
2959 | /* Failure: don't have this peer as a neighbour (anymore). | 2869 | /* Failure: don't have this peer as a neighbour (anymore). |
2960 | Might have gone down asynchronously, so this is NOT | 2870 | Might have gone down asynchronously, so this is NOT |
2961 | a protocol violation by CORE. Still count the event, | 2871 | a protocol violation by CORE. Still count the event, |
@@ -2963,14 +2873,12 @@ handle_client_send (void *cls, | |||
2963 | struct GNUNET_MQ_Envelope *env; | 2873 | struct GNUNET_MQ_Envelope *env; |
2964 | struct SendOkMessage *som; | 2874 | struct SendOkMessage *som; |
2965 | 2875 | ||
2966 | env = GNUNET_MQ_msg (som, | 2876 | env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); |
2967 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); | ||
2968 | som->success = htonl (GNUNET_SYSERR); | 2877 | som->success = htonl (GNUNET_SYSERR); |
2969 | som->bytes_msg = htonl (bytes_msg); | 2878 | som->bytes_msg = htonl (bytes_msg); |
2970 | som->bytes_physical = htonl (0); | 2879 | som->bytes_physical = htonl (0); |
2971 | som->peer = obm->peer; | 2880 | som->peer = obm->peer; |
2972 | GNUNET_MQ_send (tc->mq, | 2881 | GNUNET_MQ_send (tc->mq, env); |
2973 | env); | ||
2974 | GNUNET_SERVICE_client_continue (tc->client); | 2882 | GNUNET_SERVICE_client_continue (tc->client); |
2975 | GNUNET_STATISTICS_update (GST_stats, | 2883 | GNUNET_STATISTICS_update (GST_stats, |
2976 | "# messages dropped (neighbour unknown)", | 2884 | "# messages dropped (neighbour unknown)", |
@@ -2983,10 +2891,9 @@ handle_client_send (void *cls, | |||
2983 | pm->client = tc; | 2891 | pm->client = tc; |
2984 | pm->target = target; | 2892 | pm->target = target; |
2985 | pm->bytes_msg = bytes_msg; | 2893 | pm->bytes_msg = bytes_msg; |
2986 | pm->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (obm->timeout)); | 2894 | pm->timeout = GNUNET_TIME_relative_to_absolute ( |
2987 | memcpy (&pm[1], | 2895 | GNUNET_TIME_relative_ntoh (obm->timeout)); |
2988 | &obm[1], | 2896 | memcpy (&pm[1], &obm[1], bytes_msg); |
2989 | bytes_msg); | ||
2990 | GNUNET_CONTAINER_MDLL_insert (neighbour, | 2897 | GNUNET_CONTAINER_MDLL_insert (neighbour, |
2991 | target->pending_msg_head, | 2898 | target->pending_msg_head, |
2992 | target->pending_msg_tail, | 2899 | target->pending_msg_tail, |
@@ -2995,26 +2902,22 @@ handle_client_send (void *cls, | |||
2995 | tc->details.core.pending_msg_head, | 2902 | tc->details.core.pending_msg_head, |
2996 | tc->details.core.pending_msg_tail, | 2903 | tc->details.core.pending_msg_tail, |
2997 | pm); | 2904 | pm); |
2998 | if (target->earliest_timeout.abs_value_us > pm->timeout.abs_value_us) | 2905 | if (target->earliest_timeout.abs_value_us > pm->timeout.abs_value_us) { |
2999 | { | ||
3000 | target->earliest_timeout.abs_value_us = pm->timeout.abs_value_us; | 2906 | target->earliest_timeout.abs_value_us = pm->timeout.abs_value_us; |
3001 | if (NULL != target->timeout_task) | 2907 | if (NULL != target->timeout_task) |
3002 | GNUNET_SCHEDULER_cancel (target->timeout_task); | 2908 | GNUNET_SCHEDULER_cancel (target->timeout_task); |
3003 | target->timeout_task | 2909 | target->timeout_task = GNUNET_SCHEDULER_add_at (target->earliest_timeout, |
3004 | = GNUNET_SCHEDULER_add_at (target->earliest_timeout, | 2910 | &check_queue_timeouts, |
3005 | &check_queue_timeouts, | 2911 | target); |
3006 | target); | ||
3007 | } | 2912 | } |
3008 | if (! was_empty) | 2913 | if (! was_empty) |
3009 | return; /* all queues must already be busy */ | 2914 | return; /* all queues must already be busy */ |
3010 | for (struct Queue *queue = target->queue_head; | 2915 | for (struct Queue *queue = target->queue_head; NULL != queue; |
3011 | NULL != queue; | 2916 | queue = queue->next_neighbour) { |
3012 | queue = queue->next_neighbour) | ||
3013 | { | ||
3014 | /* try transmission on any queue that is idle */ | 2917 | /* try transmission on any queue that is idle */ |
3015 | if (NULL == queue->transmit_task) | 2918 | if (NULL == queue->transmit_task) |
3016 | queue->transmit_task = GNUNET_SCHEDULER_add_now (&transmit_on_queue, | 2919 | queue->transmit_task |
3017 | queue); | 2920 | = GNUNET_SCHEDULER_add_now (&transmit_on_queue, queue); |
3018 | } | 2921 | } |
3019 | } | 2922 | } |
3020 | 2923 | ||
@@ -3026,14 +2929,14 @@ handle_client_send (void *cls, | |||
3026 | * @param cam the send message that was sent | 2929 | * @param cam the send message that was sent |
3027 | */ | 2930 | */ |
3028 | static int | 2931 | static int |
3029 | check_communicator_available (void *cls, | 2932 | check_communicator_available ( |
3030 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) | 2933 | void *cls, |
2934 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) | ||
3031 | { | 2935 | { |
3032 | struct TransportClient *tc = cls; | 2936 | struct TransportClient *tc = cls; |
3033 | uint16_t size; | 2937 | uint16_t size; |
3034 | 2938 | ||
3035 | if (CT_NONE != tc->type) | 2939 | if (CT_NONE != tc->type) { |
3036 | { | ||
3037 | GNUNET_break (0); | 2940 | GNUNET_break (0); |
3038 | return GNUNET_SYSERR; | 2941 | return GNUNET_SYSERR; |
3039 | } | 2942 | } |
@@ -3053,8 +2956,9 @@ check_communicator_available (void *cls, | |||
3053 | * @param cam the send message that was sent | 2956 | * @param cam the send message that was sent |
3054 | */ | 2957 | */ |
3055 | static void | 2958 | static void |
3056 | handle_communicator_available (void *cls, | 2959 | handle_communicator_available ( |
3057 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) | 2960 | void *cls, |
2961 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) | ||
3058 | { | 2962 | { |
3059 | struct TransportClient *tc = cls; | 2963 | struct TransportClient *tc = cls; |
3060 | uint16_t size; | 2964 | uint16_t size; |
@@ -3063,9 +2967,9 @@ handle_communicator_available (void *cls, | |||
3063 | if (0 == size) | 2967 | if (0 == size) |
3064 | return; /* receive-only communicator */ | 2968 | return; /* receive-only communicator */ |
3065 | tc->details.communicator.address_prefix | 2969 | tc->details.communicator.address_prefix |
3066 | = GNUNET_strdup ((const char *) &cam[1]); | 2970 | = GNUNET_strdup ((const char *)&cam[1]); |
3067 | tc->details.communicator.cc | 2971 | tc->details.communicator.cc |
3068 | = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc); | 2972 | = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl (cam->cc); |
3069 | GNUNET_SERVICE_client_continue (tc->client); | 2973 | GNUNET_SERVICE_client_continue (tc->client); |
3070 | } | 2974 | } |
3071 | 2975 | ||
@@ -3078,36 +2982,34 @@ handle_communicator_available (void *cls, | |||
3078 | * @return #GNUNET_OK if message is well-formed | 2982 | * @return #GNUNET_OK if message is well-formed |
3079 | */ | 2983 | */ |
3080 | static int | 2984 | static int |
3081 | check_communicator_backchannel (void *cls, | 2985 | check_communicator_backchannel ( |
3082 | const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) | 2986 | void *cls, |
2987 | const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) | ||
3083 | { | 2988 | { |
3084 | const struct GNUNET_MessageHeader *inbox; | 2989 | const struct GNUNET_MessageHeader *inbox; |
3085 | const char *is; | 2990 | const char *is; |
3086 | uint16_t msize; | 2991 | uint16_t msize; |
3087 | uint16_t isize; | 2992 | uint16_t isize; |
3088 | 2993 | ||
3089 | (void) cls; | 2994 | (void)cls; |
3090 | msize = ntohs (cb->header.size) - sizeof (*cb); | 2995 | msize = ntohs (cb->header.size) - sizeof (*cb); |
3091 | if (UINT16_MAX - msize > | 2996 | if (UINT16_MAX - msize |
3092 | sizeof (struct TransportBackchannelEncapsulationMessage) + | 2997 | > sizeof (struct TransportBackchannelEncapsulationMessage) |
3093 | sizeof (struct TransportBackchannelRequestPayload) ) | 2998 | + sizeof (struct TransportBackchannelRequestPayload)) { |
3094 | { | ||
3095 | GNUNET_break (0); | 2999 | GNUNET_break (0); |
3096 | return GNUNET_SYSERR; | 3000 | return GNUNET_SYSERR; |
3097 | } | 3001 | } |
3098 | inbox = (const struct GNUNET_MessageHeader *) &cb[1]; | 3002 | inbox = (const struct GNUNET_MessageHeader *)&cb[1]; |
3099 | isize = ntohs (inbox->size); | 3003 | isize = ntohs (inbox->size); |
3100 | if (isize >= msize) | 3004 | if (isize >= msize) { |
3101 | { | ||
3102 | GNUNET_break (0); | 3005 | GNUNET_break (0); |
3103 | return GNUNET_SYSERR; | 3006 | return GNUNET_SYSERR; |
3104 | } | 3007 | } |
3105 | is = (const char *) inbox; | 3008 | is = (const char *)inbox; |
3106 | is += isize; | 3009 | is += isize; |
3107 | msize -= isize; | 3010 | msize -= isize; |
3108 | GNUNET_assert (msize > 0); | 3011 | GNUNET_assert (msize > 0); |
3109 | if ('\0' != is[msize-1]) | 3012 | if ('\0' != is[msize - 1]) { |
3110 | { | ||
3111 | GNUNET_break (0); | 3013 | GNUNET_break (0); |
3112 | return GNUNET_SYSERR; | 3014 | return GNUNET_SYSERR; |
3113 | } | 3015 | } |
@@ -3125,12 +3027,12 @@ expire_ephemerals (void *cls) | |||
3125 | { | 3027 | { |
3126 | struct EphemeralCacheEntry *ece; | 3028 | struct EphemeralCacheEntry *ece; |
3127 | 3029 | ||
3128 | (void) cls; | 3030 | (void)cls; |
3129 | ephemeral_task = NULL; | 3031 | ephemeral_task = NULL; |
3130 | while (NULL != (ece = GNUNET_CONTAINER_heap_peek (ephemeral_heap))) | 3032 | while (NULL != (ece = GNUNET_CONTAINER_heap_peek (ephemeral_heap))) { |
3131 | { | 3033 | if (0 |
3132 | if (0 == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity).rel_value_us) | 3034 | == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity) |
3133 | { | 3035 | .rel_value_us) { |
3134 | free_ephemeral (ece); | 3036 | free_ephemeral (ece); |
3135 | continue; | 3037 | continue; |
3136 | } | 3038 | } |
@@ -3162,40 +3064,41 @@ lookup_ephemeral (const struct GNUNET_PeerIdentity *pid, | |||
3162 | struct EphemeralCacheEntry *ece; | 3064 | struct EphemeralCacheEntry *ece; |
3163 | struct EphemeralConfirmation ec; | 3065 | struct EphemeralConfirmation ec; |
3164 | 3066 | ||
3165 | ece = GNUNET_CONTAINER_multipeermap_get (ephemeral_map, | 3067 | ece = GNUNET_CONTAINER_multipeermap_get (ephemeral_map, pid); |
3166 | pid); | 3068 | if ((NULL != ece) |
3167 | if ( (NULL != ece) && | 3069 | && (0 |
3168 | (0 == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity).rel_value_us) ) | 3070 | == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity) |
3169 | { | 3071 | .rel_value_us)) { |
3170 | free_ephemeral (ece); | 3072 | free_ephemeral (ece); |
3171 | ece = NULL; | 3073 | ece = NULL; |
3172 | } | 3074 | } |
3173 | if (NULL == ece) | 3075 | if (NULL == ece) { |
3174 | { | ||
3175 | ece = GNUNET_new (struct EphemeralCacheEntry); | 3076 | ece = GNUNET_new (struct EphemeralCacheEntry); |
3176 | ece->target = *pid; | 3077 | ece->target = *pid; |
3177 | ece->ephemeral_validity = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get_monotonic (GST_cfg), | 3078 | ece->ephemeral_validity |
3178 | EPHEMERAL_VALIDITY); | 3079 | = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get_monotonic (GST_cfg), |
3179 | GNUNET_assert (GNUNET_OK == | 3080 | EPHEMERAL_VALIDITY); |
3180 | GNUNET_CRYPTO_ecdhe_key_create2 (&ece->private_key)); | 3081 | GNUNET_assert (GNUNET_OK |
3181 | GNUNET_CRYPTO_ecdhe_key_get_public (&ece->private_key, | 3082 | == GNUNET_CRYPTO_ecdhe_key_create2 (&ece->private_key)); |
3182 | &ece->ephemeral_key); | 3083 | GNUNET_CRYPTO_ecdhe_key_get_public (&ece->private_key, &ece->ephemeral_key); |
3183 | ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); | 3084 | ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); |
3184 | ec.purpose.size = htonl (sizeof (ec)); | 3085 | ec.purpose.size = htonl (sizeof (ec)); |
3185 | ec.target = *pid; | 3086 | ec.target = *pid; |
3186 | ec.ephemeral_key = ece->ephemeral_key; | 3087 | ec.ephemeral_key = ece->ephemeral_key; |
3187 | GNUNET_assert (GNUNET_OK == | 3088 | GNUNET_assert (GNUNET_OK |
3188 | GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, | 3089 | == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, |
3189 | &ec.purpose, | 3090 | &ec.purpose, |
3190 | &ece->sender_sig)); | 3091 | &ece->sender_sig)); |
3191 | ece->hn = GNUNET_CONTAINER_heap_insert (ephemeral_heap, | 3092 | ece->hn |
3192 | ece, | 3093 | = GNUNET_CONTAINER_heap_insert (ephemeral_heap, |
3193 | ece->ephemeral_validity.abs_value_us); | 3094 | ece, |
3194 | GNUNET_assert (GNUNET_OK == | 3095 | ece->ephemeral_validity.abs_value_us); |
3195 | GNUNET_CONTAINER_multipeermap_put (ephemeral_map, | 3096 | GNUNET_assert (GNUNET_OK |
3196 | &ece->target, | 3097 | == GNUNET_CONTAINER_multipeermap_put ( |
3197 | ece, | 3098 | ephemeral_map, |
3198 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3099 | &ece->target, |
3100 | ece, | ||
3101 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
3199 | if (NULL == ephemeral_task) | 3102 | if (NULL == ephemeral_task) |
3200 | ephemeral_task = GNUNET_SCHEDULER_add_at (ece->ephemeral_validity, | 3103 | ephemeral_task = GNUNET_SCHEDULER_add_at (ece->ephemeral_validity, |
3201 | &expire_ephemerals, | 3104 | &expire_ephemerals, |
@@ -3228,7 +3131,8 @@ route_message (const struct GNUNET_PeerIdentity *target, | |||
3228 | // a path back! - if all else fails | 3131 | // a path back! - if all else fails |
3229 | // => need more on DV first! | 3132 | // => need more on DV first! |
3230 | 3133 | ||
3231 | // FIXME: send hdr to target, free hdr (possibly using DV, possibly broadcasting) | 3134 | // FIXME: send hdr to target, free hdr (possibly using DV, possibly |
3135 | // broadcasting) | ||
3232 | GNUNET_free (hdr); | 3136 | GNUNET_free (hdr); |
3233 | } | 3137 | } |
3234 | 3138 | ||
@@ -3257,20 +3161,20 @@ struct BackchannelKeyState | |||
3257 | 3161 | ||
3258 | 3162 | ||
3259 | static void | 3163 | static void |
3260 | setup_key_state_from_km (const struct GNUNET_HashCode *km, | 3164 | bc_setup_key_state_from_km (const struct GNUNET_HashCode *km, |
3261 | const struct GNUNET_HashCode *iv, | 3165 | const struct GNUNET_HashCode *iv, |
3262 | struct BackchannelKeyState *key) | 3166 | struct BackchannelKeyState *key) |
3263 | { | 3167 | { |
3264 | /* must match #dh_key_derive_eph_pub */ | 3168 | /* must match #dh_key_derive_eph_pub */ |
3265 | GNUNET_assert (GNUNET_YES == | 3169 | GNUNET_assert (GNUNET_YES |
3266 | GNUNET_CRYPTO_kdf (key, | 3170 | == GNUNET_CRYPTO_kdf (key, |
3267 | sizeof (*key), | 3171 | sizeof (*key), |
3268 | "transport-backchannel-key", | 3172 | "transport-backchannel-key", |
3269 | strlen ("transport-backchannel-key"), | 3173 | strlen ("transport-backchannel-key"), |
3270 | &km, | 3174 | &km, |
3271 | sizeof (km), | 3175 | sizeof (km), |
3272 | iv, | 3176 | iv, |
3273 | sizeof (*iv))); | 3177 | sizeof (*iv))); |
3274 | } | 3178 | } |
3275 | 3179 | ||
3276 | 3180 | ||
@@ -3284,20 +3188,18 @@ setup_key_state_from_km (const struct GNUNET_HashCode *km, | |||
3284 | * @param key[out] set to the key material | 3188 | * @param key[out] set to the key material |
3285 | */ | 3189 | */ |
3286 | static void | 3190 | static void |
3287 | dh_key_derive_eph_pid (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, | 3191 | dh_key_derive_eph_pid ( |
3288 | const struct GNUNET_PeerIdentity *target, | 3192 | const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, |
3289 | const struct GNUNET_ShortHashCode *iv, | 3193 | const struct GNUNET_PeerIdentity *target, |
3290 | struct BackchannelKeyState *key) | 3194 | const struct GNUNET_ShortHashCode *iv, |
3195 | struct BackchannelKeyState *key) | ||
3291 | { | 3196 | { |
3292 | struct GNUNET_HashCode km; | 3197 | struct GNUNET_HashCode km; |
3293 | 3198 | ||
3294 | GNUNET_assert (GNUNET_YES == | 3199 | GNUNET_assert ( |
3295 | GNUNET_CRYPTO_ecdsa_ecdh (priv_ephemeral, | 3200 | GNUNET_YES |
3296 | &target->public_key, | 3201 | == GNUNET_CRYPTO_ecdsa_ecdh (priv_ephemeral, &target->public_key, &km)); |
3297 | &km)); | 3202 | bc_setup_key_state_from_km (&km, iv, key); |
3298 | bc_setup_key_state_from_km (&km, | ||
3299 | iv, | ||
3300 | key); | ||
3301 | } | 3203 | } |
3302 | 3204 | ||
3303 | 3205 | ||
@@ -3317,13 +3219,10 @@ dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, | |||
3317 | { | 3219 | { |
3318 | struct GNUNET_HashCode km; | 3220 | struct GNUNET_HashCode km; |
3319 | 3221 | ||
3320 | GNUNET_assert (GNUNET_YES == | 3222 | GNUNET_assert ( |
3321 | GNUNET_CRYPTO_ecdsa_ecdh (GST_my_private_key, | 3223 | GNUNET_YES |
3322 | pub_ephemeral, | 3224 | == GNUNET_CRYPTO_ecdsa_ecdh (GST_my_private_key, pub_ephemeral, &km)); |
3323 | &km)); | 3225 | bc_setup_key_state_from_km (&km, iv, key); |
3324 | bc_setup_key_state_from_km (&km, | ||
3325 | iv, | ||
3326 | key); | ||
3327 | } | 3226 | } |
3328 | 3227 | ||
3329 | 3228 | ||
@@ -3403,8 +3302,9 @@ bc_key_clean (struct BackchannelKeyState *key) | |||
3403 | * @param cb the send message that was sent | 3302 | * @param cb the send message that was sent |
3404 | */ | 3303 | */ |
3405 | static void | 3304 | static void |
3406 | handle_communicator_backchannel (void *cls, | 3305 | handle_communicator_backchannel ( |
3407 | const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) | 3306 | void *cls, |
3307 | const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) | ||
3408 | { | 3308 | { |
3409 | struct TransportClient *tc = cls; | 3309 | struct TransportClient *tc = cls; |
3410 | struct GNUNET_CRYPTO_EcdhePrivateKey private_key; | 3310 | struct GNUNET_CRYPTO_EcdhePrivateKey private_key; |
@@ -3416,9 +3316,11 @@ handle_communicator_backchannel (void *cls, | |||
3416 | uint16_t msize; | 3316 | uint16_t msize; |
3417 | 3317 | ||
3418 | /* encapsulate and encrypt message */ | 3318 | /* encapsulate and encrypt message */ |
3419 | msize = ntohs (cb->header.size) - sizeof (*cb) + sizeof (struct TransportBackchannelRequestPayload); | 3319 | msize = ntohs (cb->header.size) - sizeof (*cb) |
3320 | + sizeof (struct TransportBackchannelRequestPayload); | ||
3420 | enc = GNUNET_malloc (sizeof (*enc) + msize); | 3321 | enc = GNUNET_malloc (sizeof (*enc) + msize); |
3421 | enc->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); | 3322 | enc->header.type |
3323 | = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); | ||
3422 | enc->header.size = htons (sizeof (*enc) + msize); | 3324 | enc->header.size = htons (sizeof (*enc) + msize); |
3423 | enc->target = cb->pid; | 3325 | enc->target = cb->pid; |
3424 | lookup_ephemeral (&cb->pid, | 3326 | lookup_ephemeral (&cb->pid, |
@@ -3429,17 +3331,12 @@ handle_communicator_backchannel (void *cls, | |||
3429 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, | 3331 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, |
3430 | &enc->iv, | 3332 | &enc->iv, |
3431 | sizeof (enc->iv)); | 3333 | sizeof (enc->iv)); |
3432 | dh_key_derive (&private_key, | 3334 | dh_key_derive_eph_pid (&private_key, &cb->pid, &enc->iv, &key); |
3433 | &cb->pid, | ||
3434 | &enc->iv, | ||
3435 | &key); | ||
3436 | ppay.ephemeral_validity = GNUNET_TIME_absolute_hton (ephemeral_validity); | 3335 | ppay.ephemeral_validity = GNUNET_TIME_absolute_hton (ephemeral_validity); |
3437 | ppay.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg)); | 3336 | ppay.monotonic_time |
3438 | mpos = (char *) &enc[1]; | 3337 | = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg)); |
3439 | bc_encrypt (&key, | 3338 | mpos = (char *)&enc[1]; |
3440 | &ppay, | 3339 | bc_encrypt (&key, &ppay, mpos, sizeof (ppay)); |
3441 | mpos, | ||
3442 | sizeof (ppay)); | ||
3443 | bc_encrypt (&key, | 3340 | bc_encrypt (&key, |
3444 | &cb[1], | 3341 | &cb[1], |
3445 | &mpos[sizeof (ppay)], | 3342 | &mpos[sizeof (ppay)], |
@@ -3449,8 +3346,7 @@ handle_communicator_backchannel (void *cls, | |||
3449 | mpos, | 3346 | mpos, |
3450 | sizeof (ppay) + ntohs (cb->header.size) - sizeof (*cb)); | 3347 | sizeof (ppay) + ntohs (cb->header.size) - sizeof (*cb)); |
3451 | bc_key_clean (&key); | 3348 | bc_key_clean (&key); |
3452 | route_message (&cb->pid, | 3349 | route_message (&cb->pid, &enc->header); |
3453 | &enc->header); | ||
3454 | GNUNET_SERVICE_client_continue (tc->client); | 3350 | GNUNET_SERVICE_client_continue (tc->client); |
3455 | } | 3351 | } |
3456 | 3352 | ||
@@ -3468,8 +3364,7 @@ check_add_address (void *cls, | |||
3468 | { | 3364 | { |
3469 | struct TransportClient *tc = cls; | 3365 | struct TransportClient *tc = cls; |
3470 | 3366 | ||
3471 | if (CT_COMMUNICATOR != tc->type) | 3367 | if (CT_COMMUNICATOR != tc->type) { |
3472 | { | ||
3473 | GNUNET_break (0); | 3368 | GNUNET_break (0); |
3474 | return GNUNET_SYSERR; | 3369 | return GNUNET_SYSERR; |
3475 | } | 3370 | } |
@@ -3494,8 +3389,7 @@ store_pi (void *cls); | |||
3494 | * @param success #GNUNET_YES if peerstore was successful | 3389 | * @param success #GNUNET_YES if peerstore was successful |
3495 | */ | 3390 | */ |
3496 | static void | 3391 | static void |
3497 | peerstore_store_own_cb (void *cls, | 3392 | peerstore_store_own_cb (void *cls, int success) |
3498 | int success) | ||
3499 | { | 3393 | { |
3500 | struct AddressListEntry *ale = cls; | 3394 | struct AddressListEntry *ale = cls; |
3501 | 3395 | ||
@@ -3506,10 +3400,10 @@ peerstore_store_own_cb (void *cls, | |||
3506 | ale->address); | 3400 | ale->address); |
3507 | /* refresh period is 1/4 of expiration time, that should be plenty | 3401 | /* refresh period is 1/4 of expiration time, that should be plenty |
3508 | without being excessive. */ | 3402 | without being excessive. */ |
3509 | ale->st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration, | 3403 | ale->st = GNUNET_SCHEDULER_add_delayed ( |
3510 | 4ULL), | 3404 | GNUNET_TIME_relative_divide (ale->expiration, 4ULL), |
3511 | &store_pi, | 3405 | &store_pi, |
3512 | ale); | 3406 | ale); |
3513 | } | 3407 | } |
3514 | 3408 | ||
3515 | 3409 | ||
@@ -3545,14 +3439,12 @@ store_pi (void *cls) | |||
3545 | &peerstore_store_own_cb, | 3439 | &peerstore_store_own_cb, |
3546 | ale); | 3440 | ale); |
3547 | GNUNET_free (addr); | 3441 | GNUNET_free (addr); |
3548 | if (NULL == ale->sc) | 3442 | if (NULL == ale->sc) { |
3549 | { | ||
3550 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3443 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3551 | "Failed to store our address `%s' with peerstore\n", | 3444 | "Failed to store our address `%s' with peerstore\n", |
3552 | ale->address); | 3445 | ale->address); |
3553 | ale->st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 3446 | ale->st |
3554 | &store_pi, | 3447 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &store_pi, ale); |
3555 | ale); | ||
3556 | } | 3448 | } |
3557 | } | 3449 | } |
3558 | 3450 | ||
@@ -3574,18 +3466,15 @@ handle_add_address (void *cls, | |||
3574 | slen = ntohs (aam->header.size) - sizeof (*aam); | 3466 | slen = ntohs (aam->header.size) - sizeof (*aam); |
3575 | ale = GNUNET_malloc (sizeof (struct AddressListEntry) + slen); | 3467 | ale = GNUNET_malloc (sizeof (struct AddressListEntry) + slen); |
3576 | ale->tc = tc; | 3468 | ale->tc = tc; |
3577 | ale->address = (const char *) &ale[1]; | 3469 | ale->address = (const char *)&ale[1]; |
3578 | ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration); | 3470 | ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration); |
3579 | ale->aid = aam->aid; | 3471 | ale->aid = aam->aid; |
3580 | ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt); | 3472 | ale->nt = (enum GNUNET_NetworkType)ntohl (aam->nt); |
3581 | memcpy (&ale[1], | 3473 | memcpy (&ale[1], &aam[1], slen); |
3582 | &aam[1], | ||
3583 | slen); | ||
3584 | GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head, | 3474 | GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head, |
3585 | tc->details.communicator.addr_tail, | 3475 | tc->details.communicator.addr_tail, |
3586 | ale); | 3476 | ale); |
3587 | ale->st = GNUNET_SCHEDULER_add_now (&store_pi, | 3477 | ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale); |
3588 | ale); | ||
3589 | GNUNET_SERVICE_client_continue (tc->client); | 3478 | GNUNET_SERVICE_client_continue (tc->client); |
3590 | } | 3479 | } |
3591 | 3480 | ||
@@ -3602,16 +3491,14 @@ handle_del_address (void *cls, | |||
3602 | { | 3491 | { |
3603 | struct TransportClient *tc = cls; | 3492 | struct TransportClient *tc = cls; |
3604 | 3493 | ||
3605 | if (CT_COMMUNICATOR != tc->type) | 3494 | if (CT_COMMUNICATOR != tc->type) { |
3606 | { | ||
3607 | GNUNET_break (0); | 3495 | GNUNET_break (0); |
3608 | GNUNET_SERVICE_client_drop (tc->client); | 3496 | GNUNET_SERVICE_client_drop (tc->client); |
3609 | return; | 3497 | return; |
3610 | } | 3498 | } |
3611 | for (struct AddressListEntry *ale = tc->details.communicator.addr_head; | 3499 | for (struct AddressListEntry *ale = tc->details.communicator.addr_head; |
3612 | NULL != ale; | 3500 | NULL != ale; |
3613 | ale = ale->next) | 3501 | ale = ale->next) { |
3614 | { | ||
3615 | if (dam->aid != ale->aid) | 3502 | if (dam->aid != ale->aid) |
3616 | continue; | 3503 | continue; |
3617 | GNUNET_assert (ale->tc == tc); | 3504 | GNUNET_assert (ale->tc == tc); |
@@ -3667,19 +3554,16 @@ demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, | |||
3667 | static void | 3554 | static void |
3668 | finish_cmc_handling (struct CommunicatorMessageContext *cmc) | 3555 | finish_cmc_handling (struct CommunicatorMessageContext *cmc) |
3669 | { | 3556 | { |
3670 | if (0 != ntohl (cmc->im.fc_on)) | 3557 | if (0 != ntohl (cmc->im.fc_on)) { |
3671 | { | ||
3672 | /* send ACK when done to communicator for flow control! */ | 3558 | /* send ACK when done to communicator for flow control! */ |
3673 | struct GNUNET_MQ_Envelope *env; | 3559 | struct GNUNET_MQ_Envelope *env; |
3674 | struct GNUNET_TRANSPORT_IncomingMessageAck *ack; | 3560 | struct GNUNET_TRANSPORT_IncomingMessageAck *ack; |
3675 | 3561 | ||
3676 | env = GNUNET_MQ_msg (ack, | 3562 | env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); |
3677 | GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); | ||
3678 | ack->reserved = htonl (0); | 3563 | ack->reserved = htonl (0); |
3679 | ack->fc_id = cmc->im.fc_id; | 3564 | ack->fc_id = cmc->im.fc_id; |
3680 | ack->sender = cmc->im.sender; | 3565 | ack->sender = cmc->im.sender; |
3681 | GNUNET_MQ_send (cmc->tc->mq, | 3566 | GNUNET_MQ_send (cmc->tc->mq, env); |
3682 | env); | ||
3683 | } | 3567 | } |
3684 | GNUNET_SERVICE_client_continue (cmc->tc->client); | 3568 | GNUNET_SERVICE_client_continue (cmc->tc->client); |
3685 | GNUNET_free (cmc); | 3569 | GNUNET_free (cmc); |
@@ -3690,19 +3574,18 @@ finish_cmc_handling (struct CommunicatorMessageContext *cmc) | |||
3690 | * Communicator gave us an unencapsulated message to pass as-is to | 3574 | * Communicator gave us an unencapsulated message to pass as-is to |
3691 | * CORE. Process the request. | 3575 | * CORE. Process the request. |
3692 | * | 3576 | * |
3693 | * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) | 3577 | * @param cls a `struct CommunicatorMessageContext` (must call |
3578 | * #finish_cmc_handling() when done) | ||
3694 | * @param mh the message that was received | 3579 | * @param mh the message that was received |
3695 | */ | 3580 | */ |
3696 | static void | 3581 | static void |
3697 | handle_raw_message (void *cls, | 3582 | handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh) |
3698 | const struct GNUNET_MessageHeader *mh) | ||
3699 | { | 3583 | { |
3700 | struct CommunicatorMessageContext *cmc = cls; | 3584 | struct CommunicatorMessageContext *cmc = cls; |
3701 | uint16_t size = ntohs (mh->size); | 3585 | uint16_t size = ntohs (mh->size); |
3702 | 3586 | ||
3703 | if ( (size > UINT16_MAX - sizeof (struct InboundMessage)) || | 3587 | if ((size > UINT16_MAX - sizeof (struct InboundMessage)) |
3704 | (size < sizeof (struct GNUNET_MessageHeader)) ) | 3588 | || (size < sizeof (struct GNUNET_MessageHeader))) { |
3705 | { | ||
3706 | struct GNUNET_SERVICE_Client *client = cmc->tc->client; | 3589 | struct GNUNET_SERVICE_Client *client = cmc->tc->client; |
3707 | 3590 | ||
3708 | GNUNET_break (0); | 3591 | GNUNET_break (0); |
@@ -3711,24 +3594,16 @@ handle_raw_message (void *cls, | |||
3711 | return; | 3594 | return; |
3712 | } | 3595 | } |
3713 | /* Forward to all CORE clients */ | 3596 | /* Forward to all CORE clients */ |
3714 | for (struct TransportClient *tc = clients_head; | 3597 | for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) { |
3715 | NULL != tc; | ||
3716 | tc = tc->next) | ||
3717 | { | ||
3718 | struct GNUNET_MQ_Envelope *env; | 3598 | struct GNUNET_MQ_Envelope *env; |
3719 | struct InboundMessage *im; | 3599 | struct InboundMessage *im; |
3720 | 3600 | ||
3721 | if (CT_CORE != tc->type) | 3601 | if (CT_CORE != tc->type) |
3722 | continue; | 3602 | continue; |
3723 | env = GNUNET_MQ_msg_extra (im, | 3603 | env = GNUNET_MQ_msg_extra (im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); |
3724 | size, | ||
3725 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); | ||
3726 | im->peer = cmc->im.sender; | 3604 | im->peer = cmc->im.sender; |
3727 | memcpy (&im[1], | 3605 | memcpy (&im[1], mh, size); |
3728 | mh, | 3606 | GNUNET_MQ_send (tc->mq, env); |
3729 | size); | ||
3730 | GNUNET_MQ_send (tc->mq, | ||
3731 | env); | ||
3732 | } | 3607 | } |
3733 | /* FIXME: consider doing this _only_ once the message | 3608 | /* FIXME: consider doing this _only_ once the message |
3734 | was drained from the CORE MQs to extend flow control to CORE! | 3609 | was drained from the CORE MQs to extend flow control to CORE! |
@@ -3745,24 +3620,20 @@ handle_raw_message (void *cls, | |||
3745 | * @return #GNUNET_YES if message is well-formed | 3620 | * @return #GNUNET_YES if message is well-formed |
3746 | */ | 3621 | */ |
3747 | static int | 3622 | static int |
3748 | check_fragment_box (void *cls, | 3623 | check_fragment_box (void *cls, const struct TransportFragmentBox *fb) |
3749 | const struct TransportFragmentBox *fb) | ||
3750 | { | 3624 | { |
3751 | uint16_t size = ntohs (fb->header.size); | 3625 | uint16_t size = ntohs (fb->header.size); |
3752 | uint16_t bsize = size - sizeof (*fb); | 3626 | uint16_t bsize = size - sizeof (*fb); |
3753 | 3627 | ||
3754 | if (0 == bsize) | 3628 | if (0 == bsize) { |
3755 | { | ||
3756 | GNUNET_break_op (0); | 3629 | GNUNET_break_op (0); |
3757 | return GNUNET_SYSERR; | 3630 | return GNUNET_SYSERR; |
3758 | } | 3631 | } |
3759 | if (bsize + ntohs (fb->frag_off) > ntohs (fb->msg_size)) | 3632 | if (bsize + ntohs (fb->frag_off) > ntohs (fb->msg_size)) { |
3760 | { | ||
3761 | GNUNET_break_op (0); | 3633 | GNUNET_break_op (0); |
3762 | return GNUNET_SYSERR; | 3634 | return GNUNET_SYSERR; |
3763 | } | 3635 | } |
3764 | if (ntohs (fb->frag_off) >= ntohs (fb->msg_size)) | 3636 | if (ntohs (fb->frag_off) >= ntohs (fb->msg_size)) { |
3765 | { | ||
3766 | GNUNET_break_op (0); | 3637 | GNUNET_break_op (0); |
3767 | return GNUNET_SYSERR; | 3638 | return GNUNET_SYSERR; |
3768 | } | 3639 | } |
@@ -3788,13 +3659,12 @@ send_fragment_ack (struct ReassemblyContext *rc) | |||
3788 | ack->msg_uuid = rc->msg_uuid; | 3659 | ack->msg_uuid = rc->msg_uuid; |
3789 | ack->avg_ack_delay = GNUNET_TIME_relative_hton (rc->avg_ack_delay); | 3660 | ack->avg_ack_delay = GNUNET_TIME_relative_hton (rc->avg_ack_delay); |
3790 | if (0 == rc->msg_missing) | 3661 | if (0 == rc->msg_missing) |
3791 | ack->reassembly_timeout | 3662 | ack->reassembly_timeout = GNUNET_TIME_relative_hton ( |
3792 | = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL); /* signal completion */ | 3663 | GNUNET_TIME_UNIT_FOREVER_REL); /* signal completion */ |
3793 | else | 3664 | else |
3794 | ack->reassembly_timeout | 3665 | ack->reassembly_timeout = GNUNET_TIME_relative_hton ( |
3795 | = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)); | 3666 | GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)); |
3796 | route_message (&rc->neighbour->pid, | 3667 | route_message (&rc->neighbour->pid, &ack->header); |
3797 | &ack->header); | ||
3798 | rc->avg_ack_delay = GNUNET_TIME_UNIT_ZERO; | 3668 | rc->avg_ack_delay = GNUNET_TIME_UNIT_ZERO; |
3799 | rc->num_acks = 0; | 3669 | rc->num_acks = 0; |
3800 | rc->extra_acks = 0LLU; | 3670 | rc->extra_acks = 0LLU; |
@@ -3804,12 +3674,12 @@ send_fragment_ack (struct ReassemblyContext *rc) | |||
3804 | /** | 3674 | /** |
3805 | * Communicator gave us a fragment. Process the request. | 3675 | * Communicator gave us a fragment. Process the request. |
3806 | * | 3676 | * |
3807 | * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) | 3677 | * @param cls a `struct CommunicatorMessageContext` (must call |
3678 | * #finish_cmc_handling() when done) | ||
3808 | * @param fb the message that was received | 3679 | * @param fb the message that was received |
3809 | */ | 3680 | */ |
3810 | static void | 3681 | static void |
3811 | handle_fragment_box (void *cls, | 3682 | handle_fragment_box (void *cls, const struct TransportFragmentBox *fb) |
3812 | const struct TransportFragmentBox *fb) | ||
3813 | { | 3683 | { |
3814 | struct CommunicatorMessageContext *cmc = cls; | 3684 | struct CommunicatorMessageContext *cmc = cls; |
3815 | struct Neighbour *n; | 3685 | struct Neighbour *n; |
@@ -3823,10 +3693,8 @@ handle_fragment_box (void *cls, | |||
3823 | struct GNUNET_TIME_Relative cdelay; | 3693 | struct GNUNET_TIME_Relative cdelay; |
3824 | int ack_now; | 3694 | int ack_now; |
3825 | 3695 | ||
3826 | n = GNUNET_CONTAINER_multipeermap_get (neighbours, | 3696 | n = GNUNET_CONTAINER_multipeermap_get (neighbours, &cmc->im.sender); |
3827 | &cmc->im.sender); | 3697 | if (NULL == n) { |
3828 | if (NULL == n) | ||
3829 | { | ||
3830 | struct GNUNET_SERVICE_Client *client = cmc->tc->client; | 3698 | struct GNUNET_SERVICE_Client *client = cmc->tc->client; |
3831 | 3699 | ||
3832 | GNUNET_break (0); | 3700 | GNUNET_break (0); |
@@ -3834,46 +3702,42 @@ handle_fragment_box (void *cls, | |||
3834 | GNUNET_SERVICE_client_drop (client); | 3702 | GNUNET_SERVICE_client_drop (client); |
3835 | return; | 3703 | return; |
3836 | } | 3704 | } |
3837 | if (NULL == n->reassembly_map) | 3705 | if (NULL == n->reassembly_map) { |
3838 | { | 3706 | n->reassembly_map = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_YES); |
3839 | n->reassembly_map = GNUNET_CONTAINER_multishortmap_create (8, | 3707 | n->reassembly_heap |
3840 | GNUNET_YES); | 3708 | = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
3841 | n->reassembly_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 3709 | n->reassembly_timeout_task |
3842 | n->reassembly_timeout_task = GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION, | 3710 | = GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION, |
3843 | &reassembly_cleanup_task, | 3711 | &reassembly_cleanup_task, |
3844 | n); | 3712 | n); |
3845 | } | 3713 | } |
3846 | msize = ntohs (fb->msg_size); | 3714 | msize = ntohs (fb->msg_size); |
3847 | rc = GNUNET_CONTAINER_multishortmap_get (n->reassembly_map, | 3715 | rc = GNUNET_CONTAINER_multishortmap_get (n->reassembly_map, &fb->msg_uuid); |
3848 | &fb->msg_uuid); | 3716 | if (NULL == rc) { |
3849 | if (NULL == rc) | 3717 | rc = GNUNET_malloc (sizeof (*rc) + msize + /* reassembly payload buffer */ |
3850 | { | 3718 | (msize + 7) / 8 * sizeof (uint8_t) /* bitfield */); |
3851 | rc = GNUNET_malloc (sizeof (*rc) + | ||
3852 | msize + /* reassembly payload buffer */ | ||
3853 | (msize + 7) / 8 * sizeof (uint8_t) /* bitfield */); | ||
3854 | rc->msg_uuid = fb->msg_uuid; | 3719 | rc->msg_uuid = fb->msg_uuid; |
3855 | rc->neighbour = n; | 3720 | rc->neighbour = n; |
3856 | rc->msg_size = msize; | 3721 | rc->msg_size = msize; |
3857 | rc->reassembly_timeout = GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION); | 3722 | rc->reassembly_timeout |
3723 | = GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION); | ||
3858 | rc->last_frag = GNUNET_TIME_absolute_get (); | 3724 | rc->last_frag = GNUNET_TIME_absolute_get (); |
3859 | rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap, | 3725 | rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap, |
3860 | rc, | 3726 | rc, |
3861 | rc->reassembly_timeout.abs_value_us); | 3727 | rc->reassembly_timeout.abs_value_us); |
3862 | GNUNET_assert (GNUNET_OK == | 3728 | GNUNET_assert (GNUNET_OK |
3863 | GNUNET_CONTAINER_multishortmap_put (n->reassembly_map, | 3729 | == GNUNET_CONTAINER_multishortmap_put ( |
3864 | &rc->msg_uuid, | 3730 | n->reassembly_map, |
3865 | rc, | 3731 | &rc->msg_uuid, |
3866 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3732 | rc, |
3867 | target = (char *) &rc[1]; | 3733 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
3868 | rc->bitfield = (uint8_t *) (target + rc->msg_size); | 3734 | target = (char *)&rc[1]; |
3735 | rc->bitfield = (uint8_t *)(target + rc->msg_size); | ||
3869 | rc->msg_missing = rc->msg_size; | 3736 | rc->msg_missing = rc->msg_size; |
3737 | } else { | ||
3738 | target = (char *)&rc[1]; | ||
3870 | } | 3739 | } |
3871 | else | 3740 | if (msize != rc->msg_size) { |
3872 | { | ||
3873 | target = (char *) &rc[1]; | ||
3874 | } | ||
3875 | if (msize != rc->msg_size) | ||
3876 | { | ||
3877 | GNUNET_break (0); | 3741 | GNUNET_break (0); |
3878 | finish_cmc_handling (cmc); | 3742 | finish_cmc_handling (cmc); |
3879 | return; | 3743 | return; |
@@ -3882,14 +3746,10 @@ handle_fragment_box (void *cls, | |||
3882 | /* reassemble */ | 3746 | /* reassemble */ |
3883 | fsize = ntohs (fb->header.size) - sizeof (*fb); | 3747 | fsize = ntohs (fb->header.size) - sizeof (*fb); |
3884 | frag_off = ntohs (fb->frag_off); | 3748 | frag_off = ntohs (fb->frag_off); |
3885 | memcpy (&target[frag_off], | 3749 | memcpy (&target[frag_off], &fb[1], fsize); |
3886 | &fb[1], | ||
3887 | fsize); | ||
3888 | /* update bitfield and msg_missing */ | 3750 | /* update bitfield and msg_missing */ |
3889 | for (unsigned int i=frag_off;i<frag_off+fsize;i++) | 3751 | for (unsigned int i = frag_off; i < frag_off + fsize; i++) { |
3890 | { | 3752 | if (0 == (rc->bitfield[i / 8] & (1 << (i % 8)))) { |
3891 | if (0 == (rc->bitfield[i / 8] & (1 << (i % 8)))) | ||
3892 | { | ||
3893 | rc->bitfield[i / 8] |= (1 << (i % 8)); | 3753 | rc->bitfield[i / 8] |= (1 << (i % 8)); |
3894 | rc->msg_missing--; | 3754 | rc->msg_missing--; |
3895 | } | 3755 | } |
@@ -3898,41 +3758,34 @@ handle_fragment_box (void *cls, | |||
3898 | /* Compute cummulative ACK */ | 3758 | /* Compute cummulative ACK */ |
3899 | frag_uuid = ntohl (fb->frag_uuid); | 3759 | frag_uuid = ntohl (fb->frag_uuid); |
3900 | cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag); | 3760 | cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag); |
3901 | cdelay = GNUNET_TIME_relative_multiply (cdelay, | 3761 | cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->num_acks); |
3902 | rc->num_acks); | ||
3903 | rc->last_frag = GNUNET_TIME_absolute_get (); | 3762 | rc->last_frag = GNUNET_TIME_absolute_get (); |
3904 | rc->avg_ack_delay = GNUNET_TIME_relative_add (rc->avg_ack_delay, | 3763 | rc->avg_ack_delay = GNUNET_TIME_relative_add (rc->avg_ack_delay, cdelay); |
3905 | cdelay); | ||
3906 | ack_now = GNUNET_NO; | 3764 | ack_now = GNUNET_NO; |
3907 | if (0 == rc->num_acks) | 3765 | if (0 == rc->num_acks) { |
3908 | { | ||
3909 | /* case one: first ack */ | 3766 | /* case one: first ack */ |
3910 | rc->frag_uuid = frag_uuid; | 3767 | rc->frag_uuid = frag_uuid; |
3911 | rc->extra_acks = 0LLU; | 3768 | rc->extra_acks = 0LLU; |
3912 | rc->num_acks = 1; | 3769 | rc->num_acks = 1; |
3913 | } | 3770 | } else if ((frag_uuid >= rc->frag_uuid) |
3914 | else if ( (frag_uuid >= rc->frag_uuid) && | 3771 | && (frag_uuid <= rc->frag_uuid + 64)) { |
3915 | (frag_uuid <= rc->frag_uuid + 64) ) | ||
3916 | { | ||
3917 | /* case two: ack fits after existing min UUID */ | 3772 | /* case two: ack fits after existing min UUID */ |
3918 | if ( (frag_uuid == rc->frag_uuid) || | 3773 | if ((frag_uuid == rc->frag_uuid) |
3919 | (0 != (rc->extra_acks & (1LLU << (frag_uuid - rc->frag_uuid - 1)))) ) | 3774 | || (0 |
3920 | { | 3775 | != (rc->extra_acks & (1LLU << (frag_uuid - rc->frag_uuid - 1))))) { |
3921 | /* duplicate fragment, ack now! */ | 3776 | /* duplicate fragment, ack now! */ |
3922 | ack_now = GNUNET_YES; | 3777 | ack_now = GNUNET_YES; |
3923 | } | 3778 | } else { |
3924 | else | ||
3925 | { | ||
3926 | rc->extra_acks |= (1LLU << (frag_uuid - rc->frag_uuid - 1)); | 3779 | rc->extra_acks |= (1LLU << (frag_uuid - rc->frag_uuid - 1)); |
3927 | rc->num_acks++; | 3780 | rc->num_acks++; |
3928 | } | 3781 | } |
3929 | } | 3782 | } else if ((rc->frag_uuid > frag_uuid) |
3930 | else if ( (rc->frag_uuid > frag_uuid) && | 3783 | && (((rc->frag_uuid == frag_uuid + 64) && (0 == rc->extra_acks)) |
3931 | ( ( (rc->frag_uuid == frag_uuid + 64) && | 3784 | || ((rc->frag_uuid < frag_uuid + 64) |
3932 | (0 == rc->extra_acks) ) || | 3785 | && (rc->extra_acks |
3933 | ( (rc->frag_uuid < frag_uuid + 64) && | 3786 | == (rc->extra_acks |
3934 | (rc->extra_acks == (rc->extra_acks & ~ ((1LLU << (64 - (rc->frag_uuid - frag_uuid))) - 1LLU))) ) ) ) | 3787 | & ~((1LLU << (64 - (rc->frag_uuid - frag_uuid))) |
3935 | { | 3788 | - 1LLU)))))) { |
3936 | /* can fit ack by shifting extra acks and starting at | 3789 | /* can fit ack by shifting extra acks and starting at |
3937 | frag_uid, test above esured that the bits we will | 3790 | frag_uid, test above esured that the bits we will |
3938 | shift 'extra_acks' by are all zero. */ | 3791 | shift 'extra_acks' by are all zero. */ |
@@ -3941,23 +3794,22 @@ handle_fragment_box (void *cls, | |||
3941 | rc->frag_uuid = frag_uuid; | 3794 | rc->frag_uuid = frag_uuid; |
3942 | rc->num_acks++; | 3795 | rc->num_acks++; |
3943 | } | 3796 | } |
3944 | if (65 == rc->num_acks) /* FIXME: maybe use smaller threshold? This is very aggressive. */ | 3797 | if (65 == rc->num_acks) /* FIXME: maybe use smaller threshold? This is very |
3798 | aggressive. */ | ||
3945 | ack_now = GNUNET_YES; /* maximum acks received */ | 3799 | ack_now = GNUNET_YES; /* maximum acks received */ |
3946 | // FIXME: possibly also ACK based on RTT (but for that we'd need to | 3800 | // FIXME: possibly also ACK based on RTT (but for that we'd need to |
3947 | // determine the queue used for the ACK first!) | 3801 | // determine the queue used for the ACK first!) |
3948 | 3802 | ||
3949 | /* is reassembly complete? */ | 3803 | /* is reassembly complete? */ |
3950 | if (0 != rc->msg_missing) | 3804 | if (0 != rc->msg_missing) { |
3951 | { | ||
3952 | if (ack_now) | 3805 | if (ack_now) |
3953 | send_fragment_ack (rc); | 3806 | send_fragment_ack (rc); |
3954 | finish_cmc_handling (cmc); | 3807 | finish_cmc_handling (cmc); |
3955 | return; | 3808 | return; |
3956 | } | 3809 | } |
3957 | /* reassembly is complete, verify result */ | 3810 | /* reassembly is complete, verify result */ |
3958 | msg = (const struct GNUNET_MessageHeader *) &rc[1]; | 3811 | msg = (const struct GNUNET_MessageHeader *)&rc[1]; |
3959 | if (ntohs (msg->size) != rc->msg_size) | 3812 | if (ntohs (msg->size) != rc->msg_size) { |
3960 | { | ||
3961 | GNUNET_break (0); | 3813 | GNUNET_break (0); |
3962 | free_reassembly_context (rc); | 3814 | free_reassembly_context (rc); |
3963 | finish_cmc_handling (cmc); | 3815 | finish_cmc_handling (cmc); |
@@ -3965,8 +3817,7 @@ handle_fragment_box (void *cls, | |||
3965 | } | 3817 | } |
3966 | /* successful reassembly */ | 3818 | /* successful reassembly */ |
3967 | send_fragment_ack (rc); | 3819 | send_fragment_ack (rc); |
3968 | demultiplex_with_cmc (cmc, | 3820 | demultiplex_with_cmc (cmc, msg); |
3969 | msg); | ||
3970 | /* FIXME: really free here? Might be bad if fragments are still | 3821 | /* FIXME: really free here? Might be bad if fragments are still |
3971 | en-route and we forget that we finished this reassembly immediately! | 3822 | en-route and we forget that we finished this reassembly immediately! |
3972 | -> keep around until timeout? | 3823 | -> keep around until timeout? |
@@ -3994,22 +3845,17 @@ check_ack_against_pm (struct PendingMessage *pm, | |||
3994 | uint64_t xtra = GNUNET_ntohll (fa->extra_acks); | 3845 | uint64_t xtra = GNUNET_ntohll (fa->extra_acks); |
3995 | 3846 | ||
3996 | match = GNUNET_NO; | 3847 | match = GNUNET_NO; |
3997 | for (struct PendingMessage *frag = pm->head_frag; | 3848 | for (struct PendingMessage *frag = pm->head_frag; NULL != frag; frag = nxt) { |
3998 | NULL != frag; | ||
3999 | frag = nxt) | ||
4000 | { | ||
4001 | const struct TransportFragmentBox *tfb | 3849 | const struct TransportFragmentBox *tfb |
4002 | = (const struct TransportFragmentBox *) &pm[1]; | 3850 | = (const struct TransportFragmentBox *)&pm[1]; |
4003 | uint32_t fu = ntohl (tfb->frag_uuid); | 3851 | uint32_t fu = ntohl (tfb->frag_uuid); |
4004 | 3852 | ||
4005 | GNUNET_assert (PMT_FRAGMENT_BOX == frag->pmt); | 3853 | GNUNET_assert (PMT_FRAGMENT_BOX == frag->pmt); |
4006 | nxt = frag->next_frag; | 3854 | nxt = frag->next_frag; |
4007 | /* Check for exact match or match in the 'xtra' bitmask */ | 3855 | /* Check for exact match or match in the 'xtra' bitmask */ |
4008 | if ( (fu == fs) || | 3856 | if ((fu == fs) |
4009 | ( (fu > fs) && | 3857 | || ((fu > fs) && (fu <= fs + 64) |
4010 | (fu <= fs + 64) && | 3858 | && (0 != (1LLU << (fu - fs - 1) & xtra)))) { |
4011 | (0 != (1LLU << (fu - fs - 1) & xtra)) ) ) | ||
4012 | { | ||
4013 | match = GNUNET_YES; | 3859 | match = GNUNET_YES; |
4014 | free_fragment_tree (frag); | 3860 | free_fragment_tree (frag); |
4015 | } | 3861 | } |
@@ -4021,21 +3867,19 @@ check_ack_against_pm (struct PendingMessage *pm, | |||
4021 | /** | 3867 | /** |
4022 | * Communicator gave us a fragment acknowledgement. Process the request. | 3868 | * Communicator gave us a fragment acknowledgement. Process the request. |
4023 | * | 3869 | * |
4024 | * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) | 3870 | * @param cls a `struct CommunicatorMessageContext` (must call |
3871 | * #finish_cmc_handling() when done) | ||
4025 | * @param fa the message that was received | 3872 | * @param fa the message that was received |
4026 | */ | 3873 | */ |
4027 | static void | 3874 | static void |
4028 | handle_fragment_ack (void *cls, | 3875 | handle_fragment_ack (void *cls, const struct TransportFragmentAckMessage *fa) |
4029 | const struct TransportFragmentAckMessage *fa) | ||
4030 | { | 3876 | { |
4031 | struct CommunicatorMessageContext *cmc = cls; | 3877 | struct CommunicatorMessageContext *cmc = cls; |
4032 | struct Neighbour *n; | 3878 | struct Neighbour *n; |
4033 | int matched; | 3879 | int matched; |
4034 | 3880 | ||
4035 | n = GNUNET_CONTAINER_multipeermap_get (neighbours, | 3881 | n = GNUNET_CONTAINER_multipeermap_get (neighbours, &cmc->im.sender); |
4036 | &cmc->im.sender); | 3882 | if (NULL == n) { |
4037 | if (NULL == n) | ||
4038 | { | ||
4039 | struct GNUNET_SERVICE_Client *client = cmc->tc->client; | 3883 | struct GNUNET_SERVICE_Client *client = cmc->tc->client; |
4040 | 3884 | ||
4041 | GNUNET_break (0); | 3885 | GNUNET_break (0); |
@@ -4045,19 +3889,12 @@ handle_fragment_ack (void *cls, | |||
4045 | } | 3889 | } |
4046 | /* FIXME-OPTIMIZE: maybe use another hash map here? */ | 3890 | /* FIXME-OPTIMIZE: maybe use another hash map here? */ |
4047 | matched = GNUNET_NO; | 3891 | matched = GNUNET_NO; |
4048 | for (struct PendingMessage *pm = n->pending_msg_head; | 3892 | for (struct PendingMessage *pm = n->pending_msg_head; NULL != pm; |
4049 | NULL != pm; | 3893 | pm = pm->prev_neighbour) { |
4050 | pm = pm->prev_neighbour) | 3894 | if (0 != GNUNET_memcmp (&fa->msg_uuid, &pm->msg_uuid)) |
4051 | { | ||
4052 | if (0 != | ||
4053 | GNUNET_memcmp (&fa->msg_uuid, | ||
4054 | &pm->msg_uuid)) | ||
4055 | continue; | 3895 | continue; |
4056 | matched = GNUNET_YES; | 3896 | matched = GNUNET_YES; |
4057 | if (GNUNET_YES == | 3897 | if (GNUNET_YES == check_ack_against_pm (pm, fa)) { |
4058 | check_ack_against_pm (pm, | ||
4059 | fa)) | ||
4060 | { | ||
4061 | struct GNUNET_TIME_Relative avg_ack_delay | 3898 | struct GNUNET_TIME_Relative avg_ack_delay |
4062 | = GNUNET_TIME_relative_ntoh (fa->avg_ack_delay); | 3899 | = GNUNET_TIME_relative_ntoh (fa->avg_ack_delay); |
4063 | // FIXME: update RTT and other reliability data! | 3900 | // FIXME: update RTT and other reliability data! |
@@ -4071,36 +3908,32 @@ handle_fragment_ack (void *cls, | |||
4071 | // IDEA: generate MULTIPLE frag-uuids per fragment and track | 3908 | // IDEA: generate MULTIPLE frag-uuids per fragment and track |
4072 | // the queue with the fragment! (-> this logic must | 3909 | // the queue with the fragment! (-> this logic must |
4073 | // be moved into check_ack_against_pm!) | 3910 | // be moved into check_ack_against_pm!) |
4074 | (void) avg_ack_delay; | 3911 | (void)avg_ack_delay; |
4075 | } | 3912 | } else { |
4076 | else | ||
4077 | { | ||
4078 | GNUNET_STATISTICS_update (GST_stats, | 3913 | GNUNET_STATISTICS_update (GST_stats, |
4079 | "# FRAGMENT_ACKS dropped, no matching fragment", | 3914 | "# FRAGMENT_ACKS dropped, no matching fragment", |
4080 | 1, | 3915 | 1, |
4081 | GNUNET_NO); | 3916 | GNUNET_NO); |
4082 | } | 3917 | } |
4083 | if (NULL == pm->head_frag) | 3918 | if (NULL == pm->head_frag) { |
4084 | { | ||
4085 | // if entire message is ACKed, handle that as well. | 3919 | // if entire message is ACKed, handle that as well. |
4086 | // => clean up PM, any post actions? | 3920 | // => clean up PM, any post actions? |
4087 | free_pending_message (pm); | 3921 | free_pending_message (pm); |
4088 | } | 3922 | } else { |
4089 | else | ||
4090 | { | ||
4091 | struct GNUNET_TIME_Relative reassembly_timeout | 3923 | struct GNUNET_TIME_Relative reassembly_timeout |
4092 | = GNUNET_TIME_relative_ntoh (fa->reassembly_timeout); | 3924 | = GNUNET_TIME_relative_ntoh (fa->reassembly_timeout); |
4093 | // OPTIMIZE-FIXME: adjust retransmission strategy based on reassembly_timeout! | 3925 | // OPTIMIZE-FIXME: adjust retransmission strategy based on |
4094 | (void) reassembly_timeout; | 3926 | // reassembly_timeout! |
3927 | (void)reassembly_timeout; | ||
4095 | } | 3928 | } |
4096 | break; | 3929 | break; |
4097 | } | 3930 | } |
4098 | if (GNUNET_NO == matched) | 3931 | if (GNUNET_NO == matched) { |
4099 | { | 3932 | GNUNET_STATISTICS_update ( |
4100 | GNUNET_STATISTICS_update (GST_stats, | 3933 | GST_stats, |
4101 | "# FRAGMENT_ACKS dropped, no matching pending message", | 3934 | "# FRAGMENT_ACKS dropped, no matching pending message", |
4102 | 1, | 3935 | 1, |
4103 | GNUNET_NO); | 3936 | GNUNET_NO); |
4104 | } | 3937 | } |
4105 | finish_cmc_handling (cmc); | 3938 | finish_cmc_handling (cmc); |
4106 | } | 3939 | } |
@@ -4114,8 +3947,7 @@ handle_fragment_ack (void *cls, | |||
4114 | * @return #GNUNET_YES if message is well-formed | 3947 | * @return #GNUNET_YES if message is well-formed |
4115 | */ | 3948 | */ |
4116 | static int | 3949 | static int |
4117 | check_reliability_box (void *cls, | 3950 | check_reliability_box (void *cls, const struct TransportReliabilityBox *rb) |
4118 | const struct TransportReliabilityBox *rb) | ||
4119 | { | 3951 | { |
4120 | GNUNET_MQ_check_boxed_message (rb); | 3952 | GNUNET_MQ_check_boxed_message (rb); |
4121 | return GNUNET_YES; | 3953 | return GNUNET_YES; |
@@ -4125,43 +3957,39 @@ check_reliability_box (void *cls, | |||
4125 | /** | 3957 | /** |
4126 | * Communicator gave us a reliability box. Process the request. | 3958 | * Communicator gave us a reliability box. Process the request. |
4127 | * | 3959 | * |
4128 | * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) | 3960 | * @param cls a `struct CommunicatorMessageContext` (must call |
3961 | * #finish_cmc_handling() when done) | ||
4129 | * @param rb the message that was received | 3962 | * @param rb the message that was received |
4130 | */ | 3963 | */ |
4131 | static void | 3964 | static void |
4132 | handle_reliability_box (void *cls, | 3965 | handle_reliability_box (void *cls, const struct TransportReliabilityBox *rb) |
4133 | const struct TransportReliabilityBox *rb) | ||
4134 | { | 3966 | { |
4135 | struct CommunicatorMessageContext *cmc = cls; | 3967 | struct CommunicatorMessageContext *cmc = cls; |
4136 | const struct GNUNET_MessageHeader *inbox = (const struct GNUNET_MessageHeader *) &rb[1]; | 3968 | const struct GNUNET_MessageHeader *inbox |
3969 | = (const struct GNUNET_MessageHeader *)&rb[1]; | ||
4137 | 3970 | ||
4138 | if (0 == ntohl (rb->ack_countdown)) | 3971 | if (0 == ntohl (rb->ack_countdown)) { |
4139 | { | ||
4140 | struct TransportReliabilityAckMessage *ack; | 3972 | struct TransportReliabilityAckMessage *ack; |
4141 | 3973 | ||
4142 | /* FIXME: implement cummulative ACKs and ack_countdown, | 3974 | /* FIXME: implement cummulative ACKs and ack_countdown, |
4143 | then setting the avg_ack_delay field below: */ | 3975 | then setting the avg_ack_delay field below: */ |
4144 | ack = GNUNET_malloc (sizeof (*ack) + | 3976 | ack = GNUNET_malloc (sizeof (*ack) + sizeof (struct GNUNET_ShortHashCode)); |
4145 | sizeof (struct GNUNET_ShortHashCode)); | ||
4146 | ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); | 3977 | ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); |
4147 | ack->header.size = htons (sizeof (*ack) + | 3978 | ack->header.size |
4148 | sizeof (struct GNUNET_ShortHashCode)); | 3979 | = htons (sizeof (*ack) + sizeof (struct GNUNET_ShortHashCode)); |
4149 | memcpy (&ack[1], | 3980 | memcpy (&ack[1], &rb->msg_uuid, sizeof (struct GNUNET_ShortHashCode)); |
4150 | &rb->msg_uuid, | 3981 | route_message (&cmc->im.sender, &ack->header); |
4151 | sizeof (struct GNUNET_ShortHashCode)); | ||
4152 | route_message (&cmc->im.sender, | ||
4153 | &ack->header); | ||
4154 | } | 3982 | } |
4155 | /* continue with inner message */ | 3983 | /* continue with inner message */ |
4156 | demultiplex_with_cmc (cmc, | 3984 | demultiplex_with_cmc (cmc, inbox); |
4157 | inbox); | ||
4158 | } | 3985 | } |
4159 | 3986 | ||
4160 | 3987 | ||
4161 | /** | 3988 | /** |
4162 | * Communicator gave us a reliability ack. Process the request. | 3989 | * Communicator gave us a reliability ack. Process the request. |
4163 | * | 3990 | * |
4164 | * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) | 3991 | * @param cls a `struct CommunicatorMessageContext` (must call |
3992 | * #finish_cmc_handling() when done) | ||
4165 | * @param ra the message that was received | 3993 | * @param ra the message that was received |
4166 | */ | 3994 | */ |
4167 | static void | 3995 | static void |
@@ -4175,10 +4003,8 @@ handle_reliability_ack (void *cls, | |||
4175 | struct PendingMessage *nxt; | 4003 | struct PendingMessage *nxt; |
4176 | int matched; | 4004 | int matched; |
4177 | 4005 | ||
4178 | n = GNUNET_CONTAINER_multipeermap_get (neighbours, | 4006 | n = GNUNET_CONTAINER_multipeermap_get (neighbours, &cmc->im.sender); |
4179 | &cmc->im.sender); | 4007 | if (NULL == n) { |
4180 | if (NULL == n) | ||
4181 | { | ||
4182 | struct GNUNET_SERVICE_Client *client = cmc->tc->client; | 4008 | struct GNUNET_SERVICE_Client *client = cmc->tc->client; |
4183 | 4009 | ||
4184 | GNUNET_break (0); | 4010 | GNUNET_break (0); |
@@ -4187,24 +4013,18 @@ handle_reliability_ack (void *cls, | |||
4187 | return; | 4013 | return; |
4188 | } | 4014 | } |
4189 | n_acks = (ntohs (ra->header.size) - sizeof (*ra)) | 4015 | n_acks = (ntohs (ra->header.size) - sizeof (*ra)) |
4190 | / sizeof (struct GNUNET_ShortHashCode); | 4016 | / sizeof (struct GNUNET_ShortHashCode); |
4191 | msg_uuids = (const struct GNUNET_ShortHashCode *) &ra[1]; | 4017 | msg_uuids = (const struct GNUNET_ShortHashCode *)&ra[1]; |
4192 | 4018 | ||
4193 | /* FIXME-OPTIMIZE: maybe use another hash map here? */ | 4019 | /* FIXME-OPTIMIZE: maybe use another hash map here? */ |
4194 | matched = GNUNET_NO; | 4020 | matched = GNUNET_NO; |
4195 | for (struct PendingMessage *pm = n->pending_msg_head; | 4021 | for (struct PendingMessage *pm = n->pending_msg_head; NULL != pm; pm = nxt) { |
4196 | NULL != pm; | ||
4197 | pm = nxt) | ||
4198 | { | ||
4199 | int in_list; | 4022 | int in_list; |
4200 | 4023 | ||
4201 | nxt = pm->next_neighbour; | 4024 | nxt = pm->next_neighbour; |
4202 | in_list = GNUNET_NO; | 4025 | in_list = GNUNET_NO; |
4203 | for (unsigned int i=0;i<n_acks;i++) | 4026 | for (unsigned int i = 0; i < n_acks; i++) { |
4204 | { | 4027 | if (0 != GNUNET_memcmp (&msg_uuids[i], &pm->msg_uuid)) |
4205 | if (0 != | ||
4206 | GNUNET_memcmp (&msg_uuids[i], | ||
4207 | &pm->msg_uuid)) | ||
4208 | continue; | 4028 | continue; |
4209 | in_list = GNUNET_YES; | 4029 | in_list = GNUNET_YES; |
4210 | break; | 4030 | break; |
@@ -4228,15 +4048,15 @@ handle_reliability_ack (void *cls, | |||
4228 | // -> how can we get loss rates? | 4048 | // -> how can we get loss rates? |
4229 | // -> or, add extra state to MSG and ACKs to identify queue? | 4049 | // -> or, add extra state to MSG and ACKs to identify queue? |
4230 | // -> if we do this, might just do the same for the avg_ack_delay! | 4050 | // -> if we do this, might just do the same for the avg_ack_delay! |
4231 | (void) avg_ack_delay; | 4051 | (void)avg_ack_delay; |
4232 | } | 4052 | } |
4233 | } | 4053 | } |
4234 | if (GNUNET_NO == matched) | 4054 | if (GNUNET_NO == matched) { |
4235 | { | 4055 | GNUNET_STATISTICS_update ( |
4236 | GNUNET_STATISTICS_update (GST_stats, | 4056 | GST_stats, |
4237 | "# FRAGMENT_ACKS dropped, no matching pending message", | 4057 | "# FRAGMENT_ACKS dropped, no matching pending message", |
4238 | 1, | 4058 | 1, |
4239 | GNUNET_NO); | 4059 | GNUNET_NO); |
4240 | } | 4060 | } |
4241 | finish_cmc_handling (cmc); | 4061 | finish_cmc_handling (cmc); |
4242 | } | 4062 | } |
@@ -4250,16 +4070,15 @@ handle_reliability_ack (void *cls, | |||
4250 | * @return #GNUNET_YES if message is well-formed | 4070 | * @return #GNUNET_YES if message is well-formed |
4251 | */ | 4071 | */ |
4252 | static int | 4072 | static int |
4253 | check_backchannel_encapsulation (void *cls, | 4073 | check_backchannel_encapsulation ( |
4254 | const struct TransportBackchannelEncapsulationMessage *be) | 4074 | void *cls, |
4075 | const struct TransportBackchannelEncapsulationMessage *be) | ||
4255 | { | 4076 | { |
4256 | uint16_t size = ntohs (be->header.size); | 4077 | uint16_t size = ntohs (be->header.size); |
4257 | 4078 | ||
4258 | (void) cls; | 4079 | (void)cls; |
4259 | if (size - sizeof (*be) < | 4080 | if (size - sizeof (*be) < sizeof (struct TransportBackchannelRequestPayload) |
4260 | sizeof (struct TransportBackchannelRequestPayload) + | 4081 | + sizeof (struct GNUNET_MessageHeader)) { |
4261 | sizeof (struct GNUNET_MessageHeader) ) | ||
4262 | { | ||
4263 | GNUNET_break_op (0); | 4082 | GNUNET_break_op (0); |
4264 | return GNUNET_SYSERR; | 4083 | return GNUNET_SYSERR; |
4265 | } | 4084 | } |
@@ -4270,44 +4089,35 @@ check_backchannel_encapsulation (void *cls, | |||
4270 | /** | 4089 | /** |
4271 | * Communicator gave us a backchannel encapsulation. Process the request. | 4090 | * Communicator gave us a backchannel encapsulation. Process the request. |
4272 | * | 4091 | * |
4273 | * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) | 4092 | * @param cls a `struct CommunicatorMessageContext` (must call |
4093 | * #finish_cmc_handling() when done) | ||
4274 | * @param be the message that was received | 4094 | * @param be the message that was received |
4275 | */ | 4095 | */ |
4276 | static void | 4096 | static void |
4277 | handle_backchannel_encapsulation (void *cls, | 4097 | handle_backchannel_encapsulation ( |
4278 | const struct TransportBackchannelEncapsulationMessage *be) | 4098 | void *cls, |
4099 | const struct TransportBackchannelEncapsulationMessage *be) | ||
4279 | { | 4100 | { |
4280 | struct CommunicatorMessageContext *cmc = cls; | 4101 | struct CommunicatorMessageContext *cmc = cls; |
4281 | struct BackchannelKeyState key; | 4102 | struct BackchannelKeyState key; |
4282 | struct GNUNET_HashCode hmac; | 4103 | struct GNUNET_HashCode hmac; |
4283 | const char *hdr; | 4104 | const char *hdr; |
4284 | size_t hrd_len; | 4105 | size_t hdr_len; |
4285 | 4106 | ||
4286 | if (0 != GNUNET_memcmp (&be->target, | 4107 | if (0 != GNUNET_memcmp (&be->target, &GST_my_identity)) { |
4287 | &GST_my_identity)) | ||
4288 | { | ||
4289 | /* not for me, try to route to target */ | 4108 | /* not for me, try to route to target */ |
4290 | /* FIXME: someone needs to update be->distance! */ | 4109 | /* FIXME: someone needs to update be->distance! */ |
4291 | /* FIXME: BE routing can be special, should we put all of this | 4110 | /* FIXME: BE routing can be special, should we put all of this |
4292 | on 'route_message'? Maybe at least pass some more arguments? */ | 4111 | on 'route_message'? Maybe at least pass some more arguments? */ |
4293 | route_message (&be->target, | 4112 | route_message (&be->target, GNUNET_copy_message (&be->header)); |
4294 | GNUNET_copy_message (&be->header)); | ||
4295 | finish_cmc_handling (cmc); | 4113 | finish_cmc_handling (cmc); |
4296 | return; | 4114 | return; |
4297 | } | 4115 | } |
4298 | dh_key_derive_eph_pub (&be->ephemeral_key, | 4116 | dh_key_derive_eph_pub (&be->ephemeral_key, &be->iv, &key); |
4299 | &be->iv, | 4117 | hdr = (const char *)&be[1]; |
4300 | &key); | ||
4301 | hdr = (const char *) &be[1]; | ||
4302 | hdr_len = ntohs (be->header.size) - sizeof (*be); | 4118 | hdr_len = ntohs (be->header.size) - sizeof (*be); |
4303 | bc_hmac (&key, | 4119 | bc_hmac (&key, &hmac, hdr, hdr_len); |
4304 | &hmac, | 4120 | if (0 != GNUNET_memcmp (&hmac, &be->hmac)) { |
4305 | hdr, | ||
4306 | hdr_len); | ||
4307 | if (0 != | ||
4308 | GNUNET_memcmp (&hmac, | ||
4309 | &be->hmac)) | ||
4310 | { | ||
4311 | /* HMAC missmatch, disard! */ | 4121 | /* HMAC missmatch, disard! */ |
4312 | GNUNET_break_op (0); | 4122 | GNUNET_break_op (0); |
4313 | finish_cmc_handling (cmc); | 4123 | finish_cmc_handling (cmc); |
@@ -4318,15 +4128,10 @@ handle_backchannel_encapsulation (void *cls, | |||
4318 | struct TransportBackchannelRequestPayload ppay; | 4128 | struct TransportBackchannelRequestPayload ppay; |
4319 | char body[hdr_len - sizeof (ppay)]; | 4129 | char body[hdr_len - sizeof (ppay)]; |
4320 | 4130 | ||
4321 | GNUNET_assert (hdr_len >= sizeof (ppay) + sizeof (struct GNUNET_MessageHeader)); | 4131 | GNUNET_assert (hdr_len |
4322 | bc_decrypt (&key, | 4132 | >= sizeof (ppay) + sizeof (struct GNUNET_MessageHeader)); |
4323 | &ppay, | 4133 | bc_decrypt (&key, &ppay, hdr, sizeof (ppay)); |
4324 | hdr, | 4134 | bc_decrypt (&key, &body, &hdr[sizeof (ppay)], hdr_len - sizeof (ppay)); |
4325 | sizeof (ppay)); | ||
4326 | bc_decrypt (&key, | ||
4327 | &body, | ||
4328 | &hdr[sizeof (ppay)], | ||
4329 | hdr_len - sizeof (ppay)); | ||
4330 | bc_key_clean (&key); | 4135 | bc_key_clean (&key); |
4331 | // FIXME: verify signatures in ppay! | 4136 | // FIXME: verify signatures in ppay! |
4332 | // => check if ephemeral key is known & valid, if not | 4137 | // => check if ephemeral key is known & valid, if not |
@@ -4356,21 +4161,18 @@ path_cleanup_cb (void *cls) | |||
4356 | struct DistanceVectorHop *pos; | 4161 | struct DistanceVectorHop *pos; |
4357 | 4162 | ||
4358 | dv->timeout_task = NULL; | 4163 | dv->timeout_task = NULL; |
4359 | while (NULL != (pos = dv->dv_head)) | 4164 | while (NULL != (pos = dv->dv_head)) { |
4360 | { | ||
4361 | GNUNET_assert (dv == pos->dv); | 4165 | GNUNET_assert (dv == pos->dv); |
4362 | if (GNUNET_TIME_absolute_get_remaining (pos->timeout).rel_value_us > 0) | 4166 | if (GNUNET_TIME_absolute_get_remaining (pos->timeout).rel_value_us > 0) |
4363 | break; | 4167 | break; |
4364 | free_distance_vector_hop (pos); | 4168 | free_distance_vector_hop (pos); |
4365 | } | 4169 | } |
4366 | if (NULL == pos) | 4170 | if (NULL == pos) { |
4367 | { | ||
4368 | free_dv_route (dv); | 4171 | free_dv_route (dv); |
4369 | return; | 4172 | return; |
4370 | } | 4173 | } |
4371 | dv->timeout_task = GNUNET_SCHEDULER_add_at (pos->timeout, | 4174 | dv->timeout_task |
4372 | &path_cleanup_cb, | 4175 | = GNUNET_SCHEDULER_add_at (pos->timeout, &path_cleanup_cb, dv); |
4373 | dv); | ||
4374 | } | 4176 | } |
4375 | 4177 | ||
4376 | 4178 | ||
@@ -4389,8 +4191,8 @@ path_cleanup_cb (void *cls) | |||
4389 | * and then path contains a valid path from us to `path[path_len-1]` | 4191 | * and then path contains a valid path from us to `path[path_len-1]` |
4390 | * path[1] should be a direct neighbour (we should check!) | 4192 | * path[1] should be a direct neighbour (we should check!) |
4391 | * @param path_len number of entries on the @a path, at least three! | 4193 | * @param path_len number of entries on the @a path, at least three! |
4392 | * @param network_latency how long does the message take from us to `path[path_len-1]`? | 4194 | * @param network_latency how long does the message take from us to |
4393 | * set to "forever" if unknown | 4195 | * `path[path_len-1]`? set to "forever" if unknown |
4394 | * @return #GNUNET_YES on success, | 4196 | * @return #GNUNET_YES on success, |
4395 | * #GNUNET_NO if we have better path(s) to the target | 4197 | * #GNUNET_NO if we have better path(s) to the target |
4396 | * #GNUNET_SYSERR if the path is useless and/or invalid | 4198 | * #GNUNET_SYSERR if the path is useless and/or invalid |
@@ -4407,76 +4209,58 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path, | |||
4407 | struct Neighbour *next_hop; | 4209 | struct Neighbour *next_hop; |
4408 | unsigned int shorter_distance; | 4210 | unsigned int shorter_distance; |
4409 | 4211 | ||
4410 | if (path_len < 3) | 4212 | if (path_len < 3) { |
4411 | { | ||
4412 | /* what a boring path! not allowed! */ | 4213 | /* what a boring path! not allowed! */ |
4413 | GNUNET_break (0); | 4214 | GNUNET_break (0); |
4414 | return GNUNET_SYSERR; | 4215 | return GNUNET_SYSERR; |
4415 | } | 4216 | } |
4416 | GNUNET_assert (0 == | 4217 | GNUNET_assert (0 == GNUNET_memcmp (&GST_my_identity, &path[0])); |
4417 | GNUNET_memcmp (&GST_my_identity, | 4218 | next_hop = GNUNET_CONTAINER_multipeermap_get (neighbours, &path[1]); |
4418 | &path[0])); | 4219 | if (NULL == next_hop) { |
4419 | next_hop = GNUNET_CONTAINER_multipeermap_get (neighbours, | ||
4420 | &path[1]); | ||
4421 | if (NULL == next_hop) | ||
4422 | { | ||
4423 | /* next hop must be a neighbour, otherwise this whole thing is useless! */ | 4220 | /* next hop must be a neighbour, otherwise this whole thing is useless! */ |
4424 | GNUNET_break (0); | 4221 | GNUNET_break (0); |
4425 | return GNUNET_SYSERR; | 4222 | return GNUNET_SYSERR; |
4426 | } | 4223 | } |
4427 | for (unsigned int i=2;i<path_len;i++) | 4224 | for (unsigned int i = 2; i < path_len; i++) |
4428 | if (NULL != | 4225 | if (NULL != GNUNET_CONTAINER_multipeermap_get (neighbours, &path[i])) { |
4429 | GNUNET_CONTAINER_multipeermap_get (neighbours, | ||
4430 | &path[i])) | ||
4431 | { | ||
4432 | /* Useless path, we have a direct connection to some hop | 4226 | /* Useless path, we have a direct connection to some hop |
4433 | in the middle of the path, so this one doesn't even | 4227 | in the middle of the path, so this one doesn't even |
4434 | seem terribly useful for redundancy */ | 4228 | seem terribly useful for redundancy */ |
4435 | return GNUNET_SYSERR; | 4229 | return GNUNET_SYSERR; |
4436 | } | 4230 | } |
4437 | dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, | 4231 | dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &path[path_len - 1]); |
4438 | &path[path_len - 1]); | 4232 | if (NULL == dv) { |
4439 | if (NULL == dv) | ||
4440 | { | ||
4441 | dv = GNUNET_new (struct DistanceVector); | 4233 | dv = GNUNET_new (struct DistanceVector); |
4442 | dv->target = path[path_len - 1]; | 4234 | dv->target = path[path_len - 1]; |
4443 | dv->timeout_task = GNUNET_SCHEDULER_add_delayed (DV_PATH_VALIDITY_TIMEOUT, | 4235 | dv->timeout_task = GNUNET_SCHEDULER_add_delayed (DV_PATH_VALIDITY_TIMEOUT, |
4444 | &path_cleanup_cb, | 4236 | &path_cleanup_cb, |
4445 | dv); | 4237 | dv); |
4446 | GNUNET_assert (GNUNET_OK == | 4238 | GNUNET_assert (GNUNET_OK |
4447 | GNUNET_CONTAINER_multipeermap_put (dv_routes, | 4239 | == GNUNET_CONTAINER_multipeermap_put ( |
4448 | &dv->target, | 4240 | dv_routes, |
4449 | dv, | 4241 | &dv->target, |
4450 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 4242 | dv, |
4243 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
4451 | } | 4244 | } |
4452 | /* Check if we have this path already! */ | 4245 | /* Check if we have this path already! */ |
4453 | shorter_distance = 0; | 4246 | shorter_distance = 0; |
4454 | for (struct DistanceVectorHop *pos = dv->dv_head; | 4247 | for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; |
4455 | NULL != pos; | 4248 | pos = pos->next_dv) { |
4456 | pos = pos->next_dv) | ||
4457 | { | ||
4458 | if (pos->distance < path_len - 2) | 4249 | if (pos->distance < path_len - 2) |
4459 | shorter_distance++; | 4250 | shorter_distance++; |
4460 | /* Note that the distances in 'pos' excludes us (path[0]) and | 4251 | /* Note that the distances in 'pos' excludes us (path[0]) and |
4461 | the next_hop (path[1]), so we need to subtract two | 4252 | the next_hop (path[1]), so we need to subtract two |
4462 | and check next_hop explicitly */ | 4253 | and check next_hop explicitly */ |
4463 | if ( (pos->distance == path_len - 2) && | 4254 | if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop)) { |
4464 | (pos->next_hop == next_hop) ) | ||
4465 | { | ||
4466 | int match = GNUNET_YES; | 4255 | int match = GNUNET_YES; |
4467 | 4256 | ||
4468 | for (unsigned int i=0;i<pos->distance;i++) | 4257 | for (unsigned int i = 0; i < pos->distance; i++) { |
4469 | { | 4258 | if (0 != GNUNET_memcmp (&pos->path[i], &path[i + 2])) { |
4470 | if (0 != | ||
4471 | GNUNET_memcmp (&pos->path[i], | ||
4472 | &path[i+2])) | ||
4473 | { | ||
4474 | match = GNUNET_NO; | 4259 | match = GNUNET_NO; |
4475 | break; | 4260 | break; |
4476 | } | 4261 | } |
4477 | } | 4262 | } |
4478 | if (GNUNET_YES == match) | 4263 | if (GNUNET_YES == match) { |
4479 | { | ||
4480 | struct GNUNET_TIME_Relative last_timeout; | 4264 | struct GNUNET_TIME_Relative last_timeout; |
4481 | 4265 | ||
4482 | /* Re-discovered known path, update timeout */ | 4266 | /* Re-discovered known path, update timeout */ |
@@ -4487,18 +4271,12 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path, | |||
4487 | last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout); | 4271 | last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout); |
4488 | pos->timeout | 4272 | pos->timeout |
4489 | = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); | 4273 | = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); |
4490 | GNUNET_CONTAINER_MDLL_remove (dv, | 4274 | GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, pos); |
4491 | dv->dv_head, | 4275 | GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, pos); |
4492 | dv->dv_tail, | 4276 | if (last_timeout.rel_value_us |
4493 | pos); | 4277 | < GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT, |
4494 | GNUNET_CONTAINER_MDLL_insert (dv, | 4278 | DV_PATH_DISCOVERY_FREQUENCY) |
4495 | dv->dv_head, | 4279 | .rel_value_us) { |
4496 | dv->dv_tail, | ||
4497 | pos); | ||
4498 | if (last_timeout.rel_value_us < | ||
4499 | GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT, | ||
4500 | DV_PATH_DISCOVERY_FREQUENCY).rel_value_us) | ||
4501 | { | ||
4502 | /* Some peer send DV learn messages too often, we are learning | 4280 | /* Some peer send DV learn messages too often, we are learning |
4503 | the same path faster than it would be useful; do not forward! */ | 4281 | the same path faster than it would be useful; do not forward! */ |
4504 | return GNUNET_NO; | 4282 | return GNUNET_NO; |
@@ -4509,26 +4287,22 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path, | |||
4509 | } | 4287 | } |
4510 | /* Count how many shorter paths we have (incl. direct | 4288 | /* Count how many shorter paths we have (incl. direct |
4511 | neighbours) before simply giving up on this one! */ | 4289 | neighbours) before simply giving up on this one! */ |
4512 | if (shorter_distance >= MAX_DV_PATHS_TO_TARGET) | 4290 | if (shorter_distance >= MAX_DV_PATHS_TO_TARGET) { |
4513 | { | ||
4514 | /* We have a shorter path already! */ | 4291 | /* We have a shorter path already! */ |
4515 | return GNUNET_NO; | 4292 | return GNUNET_NO; |
4516 | } | 4293 | } |
4517 | /* create new DV path entry */ | 4294 | /* create new DV path entry */ |
4518 | hop = GNUNET_malloc (sizeof (struct DistanceVectorHop) + | 4295 | hop = GNUNET_malloc (sizeof (struct DistanceVectorHop) |
4519 | sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); | 4296 | + sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); |
4520 | hop->next_hop = next_hop; | 4297 | hop->next_hop = next_hop; |
4521 | hop->dv = dv; | 4298 | hop->dv = dv; |
4522 | hop->path = (const struct GNUNET_PeerIdentity *) &hop[1]; | 4299 | hop->path = (const struct GNUNET_PeerIdentity *)&hop[1]; |
4523 | memcpy (&hop[1], | 4300 | memcpy (&hop[1], |
4524 | &path[2], | 4301 | &path[2], |
4525 | sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); | 4302 | sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); |
4526 | hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); | 4303 | hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); |
4527 | hop->distance = path_len - 2; | 4304 | hop->distance = path_len - 2; |
4528 | GNUNET_CONTAINER_MDLL_insert (dv, | 4305 | GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, hop); |
4529 | dv->dv_head, | ||
4530 | dv->dv_tail, | ||
4531 | hop); | ||
4532 | GNUNET_CONTAINER_MDLL_insert (neighbour, | 4306 | GNUNET_CONTAINER_MDLL_insert (neighbour, |
4533 | next_hop->dv_head, | 4307 | next_hop->dv_head, |
4534 | next_hop->dv_tail, | 4308 | next_hop->dv_tail, |
@@ -4545,35 +4319,27 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path, | |||
4545 | * @return #GNUNET_YES if message is well-formed | 4319 | * @return #GNUNET_YES if message is well-formed |
4546 | */ | 4320 | */ |
4547 | static int | 4321 | static int |
4548 | check_dv_learn (void *cls, | 4322 | check_dv_learn (void *cls, const struct TransportDVLearn *dvl) |
4549 | const struct TransportDVLearn *dvl) | ||
4550 | { | 4323 | { |
4551 | uint16_t size = ntohs (dvl->header.size); | 4324 | uint16_t size = ntohs (dvl->header.size); |
4552 | uint16_t num_hops = ntohs (dvl->num_hops); | 4325 | uint16_t num_hops = ntohs (dvl->num_hops); |
4553 | const struct DVPathEntryP *hops = (const struct DVPathEntryP *) &dvl[1]; | 4326 | const struct DVPathEntryP *hops = (const struct DVPathEntryP *)&dvl[1]; |
4554 | 4327 | ||
4555 | (void) cls; | 4328 | (void)cls; |
4556 | if (size != sizeof (*dvl) + num_hops * sizeof (struct DVPathEntryP)) | 4329 | if (size != sizeof (*dvl) + num_hops * sizeof (struct DVPathEntryP)) { |
4557 | { | ||
4558 | GNUNET_break_op (0); | 4330 | GNUNET_break_op (0); |
4559 | return GNUNET_SYSERR; | 4331 | return GNUNET_SYSERR; |
4560 | } | 4332 | } |
4561 | if (num_hops > MAX_DV_HOPS_ALLOWED) | 4333 | if (num_hops > MAX_DV_HOPS_ALLOWED) { |
4562 | { | ||
4563 | GNUNET_break_op (0); | 4334 | GNUNET_break_op (0); |
4564 | return GNUNET_SYSERR; | 4335 | return GNUNET_SYSERR; |
4565 | } | 4336 | } |
4566 | for (unsigned int i=0;i<num_hops;i++) | 4337 | for (unsigned int i = 0; i < num_hops; i++) { |
4567 | { | 4338 | if (0 == GNUNET_memcmp (&dvl->initiator, &hops[i].hop)) { |
4568 | if (0 == GNUNET_memcmp (&dvl->initiator, | ||
4569 | &hops[i].hop)) | ||
4570 | { | ||
4571 | GNUNET_break_op (0); | 4339 | GNUNET_break_op (0); |
4572 | return GNUNET_SYSERR; | 4340 | return GNUNET_SYSERR; |
4573 | } | 4341 | } |
4574 | if (0 == GNUNET_memcmp (&GST_my_identity, | 4342 | if (0 == GNUNET_memcmp (&GST_my_identity, &hops[i].hop)) { |
4575 | &hops[i].hop)) | ||
4576 | { | ||
4577 | GNUNET_break_op (0); | 4343 | GNUNET_break_op (0); |
4578 | return GNUNET_SYSERR; | 4344 | return GNUNET_SYSERR; |
4579 | } | 4345 | } |
@@ -4590,7 +4356,8 @@ check_dv_learn (void *cls, | |||
4590 | * @param bi_history bitmask specifying hops on path that were bidirectional | 4356 | * @param bi_history bitmask specifying hops on path that were bidirectional |
4591 | * @param nhops length of the @a hops array | 4357 | * @param nhops length of the @a hops array |
4592 | * @param hops path the message traversed so far | 4358 | * @param hops path the message traversed so far |
4593 | * @param in_time when did we receive the message, used to calculate network delay | 4359 | * @param in_time when did we receive the message, used to calculate network |
4360 | * delay | ||
4594 | */ | 4361 | */ |
4595 | static void | 4362 | static void |
4596 | forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, | 4363 | forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, |
@@ -4606,40 +4373,37 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, | |||
4606 | 4373 | ||
4607 | /* compute message for forwarding */ | 4374 | /* compute message for forwarding */ |
4608 | GNUNET_assert (nhops < MAX_DV_HOPS_ALLOWED); | 4375 | GNUNET_assert (nhops < MAX_DV_HOPS_ALLOWED); |
4609 | fwd = GNUNET_malloc (sizeof (struct TransportDVLearn) + | 4376 | fwd = GNUNET_malloc (sizeof (struct TransportDVLearn) |
4610 | (nhops + 1) * sizeof (struct DVPathEntryP)); | 4377 | + (nhops + 1) * sizeof (struct DVPathEntryP)); |
4611 | fwd->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); | 4378 | fwd->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); |
4612 | fwd->header.size = htons (sizeof (struct TransportDVLearn) + | 4379 | fwd->header.size = htons (sizeof (struct TransportDVLearn) |
4613 | (nhops + 1) * sizeof (struct DVPathEntryP)); | 4380 | + (nhops + 1) * sizeof (struct DVPathEntryP)); |
4614 | fwd->num_hops = htons (nhops + 1); | 4381 | fwd->num_hops = htons (nhops + 1); |
4615 | fwd->bidirectional = htons (bi_history); | 4382 | fwd->bidirectional = htons (bi_history); |
4616 | nnd = GNUNET_TIME_relative_add (GNUNET_TIME_absolute_get_duration (in_time), | 4383 | nnd = GNUNET_TIME_relative_add ( |
4617 | GNUNET_TIME_relative_ntoh (msg->non_network_delay)); | 4384 | GNUNET_TIME_absolute_get_duration (in_time), |
4385 | GNUNET_TIME_relative_ntoh (msg->non_network_delay)); | ||
4618 | fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd); | 4386 | fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd); |
4619 | fwd->init_sig = msg->init_sig; | 4387 | fwd->init_sig = msg->init_sig; |
4620 | fwd->initiator = msg->initiator; | 4388 | fwd->initiator = msg->initiator; |
4621 | fwd->challenge = msg->challenge; | 4389 | fwd->challenge = msg->challenge; |
4622 | dhops = (struct DVPathEntryP *) &fwd[1]; | 4390 | dhops = (struct DVPathEntryP *)&fwd[1]; |
4623 | GNUNET_memcpy (dhops, | 4391 | GNUNET_memcpy (dhops, hops, sizeof (struct DVPathEntryP) * nhops); |
4624 | hops, | ||
4625 | sizeof (struct DVPathEntryP) * nhops); | ||
4626 | dhops[nhops].hop = GST_my_identity; | 4392 | dhops[nhops].hop = GST_my_identity; |
4627 | { | 4393 | { |
4628 | struct DvHopPS dhp = { | 4394 | struct DvHopPS dhp |
4629 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), | 4395 | = {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), |
4630 | .purpose.size = htonl (sizeof (dhp)), | 4396 | .purpose.size = htonl (sizeof (dhp)), |
4631 | .pred = dhops[nhops-1].hop, | 4397 | .pred = dhops[nhops - 1].hop, |
4632 | .succ = *next_hop, | 4398 | .succ = *next_hop, |
4633 | .challenge = msg->challenge | 4399 | .challenge = msg->challenge}; |
4634 | }; | 4400 | |
4635 | 4401 | GNUNET_assert (GNUNET_OK | |
4636 | GNUNET_assert (GNUNET_OK == | 4402 | == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, |
4637 | GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, | 4403 | &dhp.purpose, |
4638 | &dhp.purpose, | 4404 | &dhops[nhops].hop_sig)); |
4639 | &dhops[nhops].hop_sig)); | 4405 | } |
4640 | } | 4406 | route_message (next_hop, &fwd->header); |
4641 | route_message (next_hop, | ||
4642 | &fwd->header); | ||
4643 | } | 4407 | } |
4644 | 4408 | ||
4645 | 4409 | ||
@@ -4652,22 +4416,22 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, | |||
4652 | * @return #GNUNET_OK if the signature is valid | 4416 | * @return #GNUNET_OK if the signature is valid |
4653 | */ | 4417 | */ |
4654 | static int | 4418 | static int |
4655 | validate_dv_initiator_signature (const struct GNUNET_PeerIdentity *init, | 4419 | validate_dv_initiator_signature ( |
4656 | const struct GNUNET_ShortHashCode *challenge, | 4420 | const struct GNUNET_PeerIdentity *init, |
4657 | const struct GNUNET_CRYPTO_EddsaSignature *init_sig) | 4421 | const struct GNUNET_ShortHashCode *challenge, |
4422 | const struct GNUNET_CRYPTO_EddsaSignature *init_sig) | ||
4658 | { | 4423 | { |
4659 | struct DvInitPS ip = { | 4424 | struct DvInitPS ip = { |
4660 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), | 4425 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), |
4661 | .purpose.size = htonl (sizeof (ip)), | 4426 | .purpose.size = htonl (sizeof (ip)), |
4662 | .challenge = *challenge | 4427 | .challenge = *challenge}; |
4663 | }; | 4428 | |
4664 | 4429 | if (GNUNET_OK | |
4665 | if (GNUNET_OK != | 4430 | != GNUNET_CRYPTO_eddsa_verify ( |
4666 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, | 4431 | GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, |
4667 | &ip.purpose, | 4432 | &ip.purpose, |
4668 | init_sig, | 4433 | init_sig, |
4669 | &init->public_key)) | 4434 | &init->public_key)) { |
4670 | { | ||
4671 | GNUNET_break_op (0); | 4435 | GNUNET_break_op (0); |
4672 | return GNUNET_SYSERR; | 4436 | return GNUNET_SYSERR; |
4673 | } | 4437 | } |
@@ -4678,12 +4442,12 @@ validate_dv_initiator_signature (const struct GNUNET_PeerIdentity *init, | |||
4678 | /** | 4442 | /** |
4679 | * Communicator gave us a DV learn message. Process the request. | 4443 | * Communicator gave us a DV learn message. Process the request. |
4680 | * | 4444 | * |
4681 | * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) | 4445 | * @param cls a `struct CommunicatorMessageContext` (must call |
4446 | * #finish_cmc_handling() when done) | ||
4682 | * @param dvl the message that was received | 4447 | * @param dvl the message that was received |
4683 | */ | 4448 | */ |
4684 | static void | 4449 | static void |
4685 | handle_dv_learn (void *cls, | 4450 | handle_dv_learn (void *cls, const struct TransportDVLearn *dvl) |
4686 | const struct TransportDVLearn *dvl) | ||
4687 | { | 4451 | { |
4688 | struct CommunicatorMessageContext *cmc = cls; | 4452 | struct CommunicatorMessageContext *cmc = cls; |
4689 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; | 4453 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; |
@@ -4697,24 +4461,17 @@ handle_dv_learn (void *cls, | |||
4697 | 4461 | ||
4698 | nhops = ntohs (dvl->bidirectional); /* 0 = sender is initiator */ | 4462 | nhops = ntohs (dvl->bidirectional); /* 0 = sender is initiator */ |
4699 | bi_history = ntohs (dvl->bidirectional); | 4463 | bi_history = ntohs (dvl->bidirectional); |
4700 | hops = (const struct DVPathEntryP *) &dvl[1]; | 4464 | hops = (const struct DVPathEntryP *)&dvl[1]; |
4701 | if (0 == nhops) | 4465 | if (0 == nhops) { |
4702 | { | ||
4703 | /* sanity check */ | 4466 | /* sanity check */ |
4704 | if (0 != GNUNET_memcmp (&dvl->initiator, | 4467 | if (0 != GNUNET_memcmp (&dvl->initiator, &cmc->im.sender)) { |
4705 | &cmc->im.sender)) | ||
4706 | { | ||
4707 | GNUNET_break (0); | 4468 | GNUNET_break (0); |
4708 | finish_cmc_handling (cmc); | 4469 | finish_cmc_handling (cmc); |
4709 | return; | 4470 | return; |
4710 | } | 4471 | } |
4711 | } | 4472 | } else { |
4712 | else | ||
4713 | { | ||
4714 | /* sanity check */ | 4473 | /* sanity check */ |
4715 | if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, | 4474 | if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, &cmc->im.sender)) { |
4716 | &cmc->im.sender)) | ||
4717 | { | ||
4718 | GNUNET_break (0); | 4475 | GNUNET_break (0); |
4719 | finish_cmc_handling (cmc); | 4476 | finish_cmc_handling (cmc); |
4720 | return; | 4477 | return; |
@@ -4723,18 +4480,18 @@ handle_dv_learn (void *cls, | |||
4723 | 4480 | ||
4724 | GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type); | 4481 | GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type); |
4725 | cc = cmc->tc->details.communicator.cc; | 4482 | cc = cmc->tc->details.communicator.cc; |
4726 | bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE == cc); // FIXME: add bi-directional flag to cc? | 4483 | bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE |
4484 | == cc); // FIXME: add bi-directional flag to cc? | ||
4727 | in_time = GNUNET_TIME_absolute_get (); | 4485 | in_time = GNUNET_TIME_absolute_get (); |
4728 | 4486 | ||
4729 | /* continue communicator here, everything else can happen asynchronous! */ | 4487 | /* continue communicator here, everything else can happen asynchronous! */ |
4730 | finish_cmc_handling (cmc); | 4488 | finish_cmc_handling (cmc); |
4731 | 4489 | ||
4732 | // FIXME: should we bother to verify _every_ DV initiator signature? | 4490 | // FIXME: should we bother to verify _every_ DV initiator signature? |
4733 | if (GNUNET_OK != | 4491 | if (GNUNET_OK |
4734 | validate_dv_initiator_signature (&dvl->initiator, | 4492 | != validate_dv_initiator_signature (&dvl->initiator, |
4735 | &dvl->challenge, | 4493 | &dvl->challenge, |
4736 | &dvl->init_sig)) | 4494 | &dvl->init_sig)) { |
4737 | { | ||
4738 | GNUNET_break_op (0); | 4495 | GNUNET_break_op (0); |
4739 | return; | 4496 | return; |
4740 | } | 4497 | } |
@@ -4742,9 +4499,7 @@ handle_dv_learn (void *cls, | |||
4742 | // => if signature verification load too high, implement random drop strategy! | 4499 | // => if signature verification load too high, implement random drop strategy! |
4743 | 4500 | ||
4744 | do_fwd = GNUNET_YES; | 4501 | do_fwd = GNUNET_YES; |
4745 | if (0 == GNUNET_memcmp (&GST_my_identity, | 4502 | if (0 == GNUNET_memcmp (&GST_my_identity, &dvl->initiator)) { |
4746 | &dvl->initiator)) | ||
4747 | { | ||
4748 | struct GNUNET_PeerIdentity path[nhops + 1]; | 4503 | struct GNUNET_PeerIdentity path[nhops + 1]; |
4749 | struct GNUNET_TIME_Relative host_latency_sum; | 4504 | struct GNUNET_TIME_Relative host_latency_sum; |
4750 | struct GNUNET_TIME_Relative latency; | 4505 | struct GNUNET_TIME_Relative latency; |
@@ -4760,69 +4515,53 @@ handle_dv_learn (void *cls, | |||
4760 | latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly | 4515 | latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly |
4761 | // (based on dvl->challenge, we can identify time of origin!) | 4516 | // (based on dvl->challenge, we can identify time of origin!) |
4762 | 4517 | ||
4763 | network_latency = GNUNET_TIME_relative_subtract (latency, | 4518 | network_latency = GNUNET_TIME_relative_subtract (latency, host_latency_sum); |
4764 | host_latency_sum); | ||
4765 | /* assumption: latency on all links is the same */ | 4519 | /* assumption: latency on all links is the same */ |
4766 | network_latency = GNUNET_TIME_relative_divide (network_latency, | 4520 | network_latency = GNUNET_TIME_relative_divide (network_latency, nhops); |
4767 | nhops); | ||
4768 | 4521 | ||
4769 | for (unsigned int i=2;i<=nhops;i++) | 4522 | for (unsigned int i = 2; i <= nhops; i++) { |
4770 | { | ||
4771 | struct GNUNET_TIME_Relative ilat; | 4523 | struct GNUNET_TIME_Relative ilat; |
4772 | 4524 | ||
4773 | /* assumption: linear latency increase per hop */ | 4525 | /* assumption: linear latency increase per hop */ |
4774 | ilat = GNUNET_TIME_relative_multiply (network_latency, | 4526 | ilat = GNUNET_TIME_relative_multiply (network_latency, i); |
4775 | i); | 4527 | path[i] = hops[i - 1].hop; |
4776 | path[i] = hops[i-1].hop; | 4528 | learn_dv_path (path, i, ilat); |
4777 | learn_dv_path (path, | ||
4778 | i, | ||
4779 | ilat); | ||
4780 | } | 4529 | } |
4781 | /* as we initiated, do not forward again (would be circular!) */ | 4530 | /* as we initiated, do not forward again (would be circular!) */ |
4782 | do_fwd = GNUNET_NO; | 4531 | do_fwd = GNUNET_NO; |
4783 | return; | 4532 | return; |
4784 | } | 4533 | } else if (bi_hop) { |
4785 | else if (bi_hop) | ||
4786 | { | ||
4787 | /* last hop was bi-directional, we could learn something here! */ | 4534 | /* last hop was bi-directional, we could learn something here! */ |
4788 | struct GNUNET_PeerIdentity path[nhops + 2]; | 4535 | struct GNUNET_PeerIdentity path[nhops + 2]; |
4789 | 4536 | ||
4790 | path[0] = GST_my_identity; | 4537 | path[0] = GST_my_identity; |
4791 | path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */ | 4538 | path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */ |
4792 | for (unsigned int i=0;i<nhops;i++) | 4539 | for (unsigned int i = 0; i < nhops; i++) { |
4793 | { | ||
4794 | int iret; | 4540 | int iret; |
4795 | 4541 | ||
4796 | if (0 == (bi_history & (1 << i))) | 4542 | if (0 == (bi_history & (1 << i))) |
4797 | break; /* i-th hop not bi-directional, stop learning! */ | 4543 | break; /* i-th hop not bi-directional, stop learning! */ |
4798 | if (i == nhops) | 4544 | if (i == nhops) { |
4799 | { | ||
4800 | path[i + 2] = dvl->initiator; | 4545 | path[i + 2] = dvl->initiator; |
4801 | } | 4546 | } else { |
4802 | else | ||
4803 | { | ||
4804 | path[i + 2] = hops[nhops - i - 2].hop; | 4547 | path[i + 2] = hops[nhops - i - 2].hop; |
4805 | } | 4548 | } |
4806 | 4549 | ||
4807 | iret = learn_dv_path (path, | 4550 | iret = learn_dv_path (path, i + 2, GNUNET_TIME_UNIT_FOREVER_REL); |
4808 | i + 2, | 4551 | if (GNUNET_SYSERR == iret) { |
4809 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
4810 | if (GNUNET_SYSERR == iret) | ||
4811 | { | ||
4812 | /* path invalid or too long to be interesting for US, thus should also | 4552 | /* path invalid or too long to be interesting for US, thus should also |
4813 | not be interesting to our neighbours, cut path when forwarding to | 4553 | not be interesting to our neighbours, cut path when forwarding to |
4814 | 'i' hops, except of course for the one that goes back to the | 4554 | 'i' hops, except of course for the one that goes back to the |
4815 | initiator */ | 4555 | initiator */ |
4816 | GNUNET_STATISTICS_update (GST_stats, | 4556 | GNUNET_STATISTICS_update ( |
4817 | "# DV learn not forwarded due invalidity of path", | 4557 | GST_stats, |
4818 | 1, | 4558 | "# DV learn not forwarded due invalidity of path", |
4819 | GNUNET_NO); | 4559 | 1, |
4560 | GNUNET_NO); | ||
4820 | do_fwd = GNUNET_NO; | 4561 | do_fwd = GNUNET_NO; |
4821 | break; | 4562 | break; |
4822 | } | 4563 | } |
4823 | if ( (GNUNET_NO == iret) && | 4564 | if ((GNUNET_NO == iret) && (nhops == i + 1)) { |
4824 | (nhops == i + 1) ) | ||
4825 | { | ||
4826 | /* we have better paths, and this is the longest target, | 4565 | /* we have better paths, and this is the longest target, |
4827 | so there cannot be anything interesting later */ | 4566 | so there cannot be anything interesting later */ |
4828 | GNUNET_STATISTICS_update (GST_stats, | 4567 | GNUNET_STATISTICS_update (GST_stats, |
@@ -4835,8 +4574,7 @@ handle_dv_learn (void *cls, | |||
4835 | } | 4574 | } |
4836 | } | 4575 | } |
4837 | 4576 | ||
4838 | if (MAX_DV_HOPS_ALLOWED == nhops) | 4577 | if (MAX_DV_HOPS_ALLOWED == nhops) { |
4839 | { | ||
4840 | /* At limit, we're out of here! */ | 4578 | /* At limit, we're out of here! */ |
4841 | finish_cmc_handling (cmc); | 4579 | finish_cmc_handling (cmc); |
4842 | return; | 4580 | return; |
@@ -4845,28 +4583,21 @@ handle_dv_learn (void *cls, | |||
4845 | /* Forward to initiator, if path non-trivial and possible */ | 4583 | /* Forward to initiator, if path non-trivial and possible */ |
4846 | bi_history = (bi_history << 1) | (bi_hop ? 1 : 0); | 4584 | bi_history = (bi_history << 1) | (bi_hop ? 1 : 0); |
4847 | did_initiator = GNUNET_NO; | 4585 | did_initiator = GNUNET_NO; |
4848 | if ( (1 < nhops) && | 4586 | if ((1 < nhops) |
4849 | (GNUNET_YES == | 4587 | && (GNUNET_YES |
4850 | GNUNET_CONTAINER_multipeermap_contains (neighbours, | 4588 | == GNUNET_CONTAINER_multipeermap_contains (neighbours, |
4851 | &dvl->initiator)) ) | 4589 | &dvl->initiator))) { |
4852 | { | ||
4853 | /* send back to origin! */ | 4590 | /* send back to origin! */ |
4854 | forward_dv_learn (&dvl->initiator, | 4591 | forward_dv_learn (&dvl->initiator, dvl, bi_history, nhops, hops, in_time); |
4855 | dvl, | ||
4856 | bi_history, | ||
4857 | nhops, | ||
4858 | hops, | ||
4859 | in_time); | ||
4860 | did_initiator = GNUNET_YES; | 4592 | did_initiator = GNUNET_YES; |
4861 | } | 4593 | } |
4862 | /* We forward under two conditions: either we still learned something | 4594 | /* We forward under two conditions: either we still learned something |
4863 | ourselves (do_fwd), or the path was darn short and thus the initiator is | 4595 | ourselves (do_fwd), or the path was darn short and thus the initiator is |
4864 | likely to still be very interested in this (and we did NOT already | 4596 | likely to still be very interested in this (and we did NOT already |
4865 | send it back to the initiator) */ | 4597 | send it back to the initiator) */ |
4866 | if ( (do_fwd) || | 4598 | if ((do_fwd) |
4867 | ( (nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) && | 4599 | || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) |
4868 | (GNUNET_NO == did_initiator) ) ) | 4600 | && (GNUNET_NO == did_initiator))) { |
4869 | { | ||
4870 | /* FIXME: loop over all neighbours, pick those with low | 4601 | /* FIXME: loop over all neighbours, pick those with low |
4871 | queues AND that are not yet on the path; possibly | 4602 | queues AND that are not yet on the path; possibly |
4872 | adapt threshold to nhops! */ | 4603 | adapt threshold to nhops! */ |
@@ -4890,32 +4621,33 @@ handle_dv_learn (void *cls, | |||
4890 | * @return #GNUNET_YES if message is well-formed | 4621 | * @return #GNUNET_YES if message is well-formed |
4891 | */ | 4622 | */ |
4892 | static int | 4623 | static int |
4893 | check_dv_box (void *cls, | 4624 | check_dv_box (void *cls, const struct TransportDVBox *dvb) |
4894 | const struct TransportDVBox *dvb) | ||
4895 | { | 4625 | { |
4896 | uint16_t size = ntohs (dvb->header.size); | 4626 | uint16_t size = ntohs (dvb->header.size); |
4897 | uint16_t num_hops = ntohs (dvb->num_hops); | 4627 | uint16_t num_hops = ntohs (dvb->num_hops); |
4898 | const struct GNUNET_PeerIdentity *hops = (const struct GNUNET_PeerIdentity *) &dvb[1]; | 4628 | const struct GNUNET_PeerIdentity *hops |
4899 | const struct GNUNET_MessageHeader *inbox = (const struct GNUNET_MessageHeader *) &hops[num_hops]; | 4629 | = (const struct GNUNET_PeerIdentity *)&dvb[1]; |
4630 | const struct GNUNET_MessageHeader *inbox | ||
4631 | = (const struct GNUNET_MessageHeader *)&hops[num_hops]; | ||
4900 | uint16_t isize; | 4632 | uint16_t isize; |
4901 | uint16_t itype; | 4633 | uint16_t itype; |
4902 | 4634 | ||
4903 | (void) cls; | 4635 | (void)cls; |
4904 | if (size < sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + sizeof (struct GNUNET_MessageHeader)) | 4636 | if (size < sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) |
4905 | { | 4637 | + sizeof (struct GNUNET_MessageHeader)) { |
4906 | GNUNET_break_op (0); | 4638 | GNUNET_break_op (0); |
4907 | return GNUNET_SYSERR; | 4639 | return GNUNET_SYSERR; |
4908 | } | 4640 | } |
4909 | isize = ntohs (inbox->size); | 4641 | isize = ntohs (inbox->size); |
4910 | if (size != sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + isize) | 4642 | if (size |
4911 | { | 4643 | != sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) |
4644 | + isize) { | ||
4912 | GNUNET_break_op (0); | 4645 | GNUNET_break_op (0); |
4913 | return GNUNET_SYSERR; | 4646 | return GNUNET_SYSERR; |
4914 | } | 4647 | } |
4915 | itype = ntohs (inbox->type); | 4648 | itype = ntohs (inbox->type); |
4916 | if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX == itype) || | 4649 | if ((GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX == itype) |
4917 | (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN == itype) ) | 4650 | || (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN == itype)) { |
4918 | { | ||
4919 | GNUNET_break_op (0); | 4651 | GNUNET_break_op (0); |
4920 | return GNUNET_SYSERR; | 4652 | return GNUNET_SYSERR; |
4921 | } | 4653 | } |
@@ -4926,21 +4658,22 @@ check_dv_box (void *cls, | |||
4926 | /** | 4658 | /** |
4927 | * Communicator gave us a DV box. Process the request. | 4659 | * Communicator gave us a DV box. Process the request. |
4928 | * | 4660 | * |
4929 | * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) | 4661 | * @param cls a `struct CommunicatorMessageContext` (must call |
4662 | * #finish_cmc_handling() when done) | ||
4930 | * @param dvb the message that was received | 4663 | * @param dvb the message that was received |
4931 | */ | 4664 | */ |
4932 | static void | 4665 | static void |
4933 | handle_dv_box (void *cls, | 4666 | handle_dv_box (void *cls, const struct TransportDVBox *dvb) |
4934 | const struct TransportDVBox *dvb) | ||
4935 | { | 4667 | { |
4936 | struct CommunicatorMessageContext *cmc = cls; | 4668 | struct CommunicatorMessageContext *cmc = cls; |
4937 | uint16_t size = ntohs (dvb->header.size) - sizeof (*dvb); | 4669 | uint16_t size = ntohs (dvb->header.size) - sizeof (*dvb); |
4938 | uint16_t num_hops = ntohs (dvb->num_hops); | 4670 | uint16_t num_hops = ntohs (dvb->num_hops); |
4939 | const struct GNUNET_PeerIdentity *hops = (const struct GNUNET_PeerIdentity *) &dvb[1]; | 4671 | const struct GNUNET_PeerIdentity *hops |
4940 | const struct GNUNET_MessageHeader *inbox = (const struct GNUNET_MessageHeader *) &hops[num_hops]; | 4672 | = (const struct GNUNET_PeerIdentity *)&dvb[1]; |
4673 | const struct GNUNET_MessageHeader *inbox | ||
4674 | = (const struct GNUNET_MessageHeader *)&hops[num_hops]; | ||
4941 | 4675 | ||
4942 | if (num_hops > 0) | 4676 | if (num_hops > 0) { |
4943 | { | ||
4944 | // FIXME: if we are not the target, shorten path and forward along. | 4677 | // FIXME: if we are not the target, shorten path and forward along. |
4945 | // Try from the _end_ of hops array if we know the given | 4678 | // Try from the _end_ of hops array if we know the given |
4946 | // neighbour (shortening the path!). | 4679 | // neighbour (shortening the path!). |
@@ -4951,8 +4684,7 @@ handle_dv_box (void *cls, | |||
4951 | /* We are the target. Unbox and handle message. */ | 4684 | /* We are the target. Unbox and handle message. */ |
4952 | cmc->im.sender = dvb->origin; | 4685 | cmc->im.sender = dvb->origin; |
4953 | cmc->total_hops = ntohs (dvb->total_hops); | 4686 | cmc->total_hops = ntohs (dvb->total_hops); |
4954 | demultiplex_with_cmc (cmc, | 4687 | demultiplex_with_cmc (cmc, inbox); |
4955 | inbox); | ||
4956 | } | 4688 | } |
4957 | 4689 | ||
4958 | 4690 | ||
@@ -4969,8 +4701,7 @@ check_incoming_msg (void *cls, | |||
4969 | { | 4701 | { |
4970 | struct TransportClient *tc = cls; | 4702 | struct TransportClient *tc = cls; |
4971 | 4703 | ||
4972 | if (CT_COMMUNICATOR != tc->type) | 4704 | if (CT_COMMUNICATOR != tc->type) { |
4973 | { | ||
4974 | GNUNET_break (0); | 4705 | GNUNET_break (0); |
4975 | return GNUNET_SYSERR; | 4706 | return GNUNET_SYSERR; |
4976 | } | 4707 | } |
@@ -4980,9 +4711,11 @@ check_incoming_msg (void *cls, | |||
4980 | 4711 | ||
4981 | 4712 | ||
4982 | /** | 4713 | /** |
4983 | * Communicator gave us a transport address validation challenge. Process the request. | 4714 | * Communicator gave us a transport address validation challenge. Process the |
4715 | * request. | ||
4984 | * | 4716 | * |
4985 | * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) | 4717 | * @param cls a `struct CommunicatorMessageContext` (must call |
4718 | * #finish_cmc_handling() when done) | ||
4986 | * @param tvc the message that was received | 4719 | * @param tvc the message that was received |
4987 | */ | 4720 | */ |
4988 | static void | 4721 | static void |
@@ -4992,15 +4725,15 @@ handle_validation_challenge (void *cls, | |||
4992 | struct CommunicatorMessageContext *cmc = cls; | 4725 | struct CommunicatorMessageContext *cmc = cls; |
4993 | struct TransportValidationResponse *tvr; | 4726 | struct TransportValidationResponse *tvr; |
4994 | 4727 | ||
4995 | if (cmc->total_hops > 0) | 4728 | if (cmc->total_hops > 0) { |
4996 | { | ||
4997 | /* DV routing is not allowed for validation challenges! */ | 4729 | /* DV routing is not allowed for validation challenges! */ |
4998 | GNUNET_break_op (0); | 4730 | GNUNET_break_op (0); |
4999 | finish_cmc_handling (cmc); | 4731 | finish_cmc_handling (cmc); |
5000 | return; | 4732 | return; |
5001 | } | 4733 | } |
5002 | tvr = GNUNET_new (struct TransportValidationResponse); | 4734 | tvr = GNUNET_new (struct TransportValidationResponse); |
5003 | tvr->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); | 4735 | tvr->header.type |
4736 | = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); | ||
5004 | tvr->header.size = htons (sizeof (*tvr)); | 4737 | tvr->header.size = htons (sizeof (*tvr)); |
5005 | tvr->challenge = tvc->challenge; | 4738 | tvr->challenge = tvc->challenge; |
5006 | tvr->origin_time = tvc->sender_time; | 4739 | tvr->origin_time = tvc->sender_time; |
@@ -5011,16 +4744,14 @@ handle_validation_challenge (void *cls, | |||
5011 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), | 4744 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), |
5012 | .purpose.size = htonl (sizeof (tvp)), | 4745 | .purpose.size = htonl (sizeof (tvp)), |
5013 | .validity_duration = tvr->validity_duration, | 4746 | .validity_duration = tvr->validity_duration, |
5014 | .challenge = tvc->challenge | 4747 | .challenge = tvc->challenge}; |
5015 | }; | ||
5016 | 4748 | ||
5017 | GNUNET_assert (GNUNET_OK == | 4749 | GNUNET_assert (GNUNET_OK |
5018 | GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, | 4750 | == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, |
5019 | &tvp.purpose, | 4751 | &tvp.purpose, |
5020 | &tvr->signature)); | 4752 | &tvr->signature)); |
5021 | } | 4753 | } |
5022 | route_message (&cmc->im.sender, | 4754 | route_message (&cmc->im.sender, &tvr->header); |
5023 | &tvr->header); | ||
5024 | finish_cmc_handling (cmc); | 4755 | finish_cmc_handling (cmc); |
5025 | } | 4756 | } |
5026 | 4757 | ||
@@ -5059,9 +4790,8 @@ check_known_challenge (void *cls, | |||
5059 | struct CheckKnownChallengeContext *ckac = cls; | 4790 | struct CheckKnownChallengeContext *ckac = cls; |
5060 | struct ValidationState *vs = value; | 4791 | struct ValidationState *vs = value; |
5061 | 4792 | ||
5062 | (void) pid; | 4793 | (void)pid; |
5063 | if (0 != GNUNET_memcmp (&vs->challenge, | 4794 | if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge)) |
5064 | ckac->challenge)) | ||
5065 | return GNUNET_OK; | 4795 | return GNUNET_OK; |
5066 | ckac->vs = vs; | 4796 | ckac->vs = vs; |
5067 | return GNUNET_NO; | 4797 | return GNUNET_NO; |
@@ -5076,8 +4806,7 @@ check_known_challenge (void *cls, | |||
5076 | * @param success #GNUNET_YES on success | 4806 | * @param success #GNUNET_YES on success |
5077 | */ | 4807 | */ |
5078 | static void | 4808 | static void |
5079 | peerstore_store_validation_cb (void *cls, | 4809 | peerstore_store_validation_cb (void *cls, int success) |
5080 | int success) | ||
5081 | { | 4810 | { |
5082 | struct ValidationState *vs = cls; | 4811 | struct ValidationState *vs = cls; |
5083 | 4812 | ||
@@ -5121,28 +4850,28 @@ update_next_challenge_time (struct ValidationState *vs, | |||
5121 | vs, | 4850 | vs, |
5122 | new_time.abs_value_us); | 4851 | new_time.abs_value_us); |
5123 | else | 4852 | else |
5124 | GNUNET_CONTAINER_heap_update_cost (vs->hn, | 4853 | GNUNET_CONTAINER_heap_update_cost (vs->hn, new_time.abs_value_us); |
5125 | new_time.abs_value_us); | 4854 | if ((vs != GNUNET_CONTAINER_heap_peek (validation_heap)) |
5126 | if ( (vs != GNUNET_CONTAINER_heap_peek (validation_heap)) && | 4855 | && (NULL != validation_task)) |
5127 | (NULL != validation_task) ) | ||
5128 | return; | 4856 | return; |
5129 | if (NULL != validation_task) | 4857 | if (NULL != validation_task) |
5130 | GNUNET_SCHEDULER_cancel (validation_task); | 4858 | GNUNET_SCHEDULER_cancel (validation_task); |
5131 | /* randomize a bit */ | 4859 | /* randomize a bit */ |
5132 | delta.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 4860 | delta.rel_value_us |
5133 | MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); | 4861 | = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
5134 | new_time = GNUNET_TIME_absolute_add (new_time, | 4862 | MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); |
5135 | delta); | 4863 | new_time = GNUNET_TIME_absolute_add (new_time, delta); |
5136 | validation_task = GNUNET_SCHEDULER_add_at (new_time, | 4864 | validation_task |
5137 | &validation_start_cb, | 4865 | = GNUNET_SCHEDULER_add_at (new_time, &validation_start_cb, NULL); |
5138 | NULL); | ||
5139 | } | 4866 | } |
5140 | 4867 | ||
5141 | 4868 | ||
5142 | /** | 4869 | /** |
5143 | * Communicator gave us a transport address validation response. Process the request. | 4870 | * Communicator gave us a transport address validation response. Process the |
4871 | * request. | ||
5144 | * | 4872 | * |
5145 | * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) | 4873 | * @param cls a `struct CommunicatorMessageContext` (must call |
4874 | * #finish_cmc_handling() when done) | ||
5146 | * @param tvr the message that was received | 4875 | * @param tvr the message that was received |
5147 | */ | 4876 | */ |
5148 | static void | 4877 | static void |
@@ -5151,19 +4880,16 @@ handle_validation_response (void *cls, | |||
5151 | { | 4880 | { |
5152 | struct CommunicatorMessageContext *cmc = cls; | 4881 | struct CommunicatorMessageContext *cmc = cls; |
5153 | struct ValidationState *vs; | 4882 | struct ValidationState *vs; |
5154 | struct CheckKnownChallengeContext ckac = { | 4883 | struct CheckKnownChallengeContext ckac |
5155 | .challenge = &tvr->challenge, | 4884 | = {.challenge = &tvr->challenge, .vs = NULL}; |
5156 | .vs = NULL | ||
5157 | }; | ||
5158 | struct GNUNET_TIME_Absolute origin_time; | 4885 | struct GNUNET_TIME_Absolute origin_time; |
5159 | 4886 | ||
5160 | /* check this is one of our challenges */ | 4887 | /* check this is one of our challenges */ |
5161 | (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, | 4888 | (void)GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, |
5162 | &cmc->im.sender, | 4889 | &cmc->im.sender, |
5163 | &check_known_challenge, | 4890 | &check_known_challenge, |
5164 | &ckac); | 4891 | &ckac); |
5165 | if (NULL == (vs = ckac.vs)) | 4892 | if (NULL == (vs = ckac.vs)) { |
5166 | { | ||
5167 | /* This can happen simply if we 'forgot' the challenge by now, | 4893 | /* This can happen simply if we 'forgot' the challenge by now, |
5168 | i.e. because we received the validation response twice */ | 4894 | i.e. because we received the validation response twice */ |
5169 | GNUNET_STATISTICS_update (GST_stats, | 4895 | GNUNET_STATISTICS_update (GST_stats, |
@@ -5176,9 +4902,8 @@ handle_validation_response (void *cls, | |||
5176 | 4902 | ||
5177 | /* sanity check on origin time */ | 4903 | /* sanity check on origin time */ |
5178 | origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time); | 4904 | origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time); |
5179 | if ( (origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) || | 4905 | if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) |
5180 | (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us) ) | 4906 | || (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us)) { |
5181 | { | ||
5182 | GNUNET_break_op (0); | 4907 | GNUNET_break_op (0); |
5183 | finish_cmc_handling (cmc); | 4908 | finish_cmc_handling (cmc); |
5184 | return; | 4909 | return; |
@@ -5190,15 +4915,14 @@ handle_validation_response (void *cls, | |||
5190 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), | 4915 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), |
5191 | .purpose.size = htonl (sizeof (tvp)), | 4916 | .purpose.size = htonl (sizeof (tvp)), |
5192 | .validity_duration = tvr->validity_duration, | 4917 | .validity_duration = tvr->validity_duration, |
5193 | .challenge = tvr->challenge | 4918 | .challenge = tvr->challenge}; |
5194 | }; | 4919 | |
5195 | 4920 | if (GNUNET_OK | |
5196 | if (GNUNET_OK != | 4921 | != GNUNET_CRYPTO_eddsa_verify ( |
5197 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, | 4922 | GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, |
5198 | &tvp.purpose, | 4923 | &tvp.purpose, |
5199 | &tvr->signature, | 4924 | &tvr->signature, |
5200 | &cmc->im.sender.public_key)) | 4925 | &cmc->im.sender.public_key)) { |
5201 | { | ||
5202 | GNUNET_break_op (0); | 4926 | GNUNET_break_op (0); |
5203 | finish_cmc_handling (cmc); | 4927 | finish_cmc_handling (cmc); |
5204 | return; | 4928 | return; |
@@ -5207,23 +4931,24 @@ handle_validation_response (void *cls, | |||
5207 | 4931 | ||
5208 | /* validity is capped by our willingness to keep track of the | 4932 | /* validity is capped by our willingness to keep track of the |
5209 | validation entry and the maximum the other peer allows */ | 4933 | validation entry and the maximum the other peer allows */ |
5210 | vs->valid_until | 4934 | vs->valid_until = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_min ( |
5211 | = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_min (GNUNET_TIME_relative_ntoh (tvr->validity_duration), | 4935 | GNUNET_TIME_relative_ntoh (tvr->validity_duration), |
5212 | MAX_ADDRESS_VALID_UNTIL)); | 4936 | MAX_ADDRESS_VALID_UNTIL)); |
5213 | vs->validated_until | 4937 | vs->validated_until = GNUNET_TIME_absolute_min ( |
5214 | = GNUNET_TIME_absolute_min (vs->valid_until, | 4938 | vs->valid_until, |
5215 | GNUNET_TIME_relative_to_absolute (ADDRESS_VALIDATION_LIFETIME)); | 4939 | GNUNET_TIME_relative_to_absolute (ADDRESS_VALIDATION_LIFETIME)); |
5216 | vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time); | 4940 | vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time); |
5217 | vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO; | 4941 | vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO; |
5218 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, | 4942 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, |
5219 | &vs->challenge, | 4943 | &vs->challenge, |
5220 | sizeof (vs->challenge)); | 4944 | sizeof (vs->challenge)); |
5221 | vs->first_challenge_use = GNUNET_TIME_absolute_subtract (vs->validated_until, | 4945 | vs->first_challenge_use = GNUNET_TIME_absolute_subtract ( |
5222 | GNUNET_TIME_relative_multiply (vs->validation_rtt, | 4946 | vs->validated_until, |
5223 | VALIDATION_RTT_BUFFER_FACTOR)); | 4947 | GNUNET_TIME_relative_multiply (vs->validation_rtt, |
5224 | vs->last_challenge_use = GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */ | 4948 | VALIDATION_RTT_BUFFER_FACTOR)); |
5225 | update_next_challenge_time (vs, | 4949 | vs->last_challenge_use |
5226 | vs->first_challenge_use); | 4950 | = GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */ |
4951 | update_next_challenge_time (vs, vs->first_challenge_use); | ||
5227 | vs->sc = GNUNET_PEERSTORE_store (peerstore, | 4952 | vs->sc = GNUNET_PEERSTORE_store (peerstore, |
5228 | "transport", | 4953 | "transport", |
5229 | &cmc->im.sender, | 4954 | &cmc->im.sender, |
@@ -5249,12 +4974,12 @@ handle_incoming_msg (void *cls, | |||
5249 | const struct GNUNET_TRANSPORT_IncomingMessage *im) | 4974 | const struct GNUNET_TRANSPORT_IncomingMessage *im) |
5250 | { | 4975 | { |
5251 | struct TransportClient *tc = cls; | 4976 | struct TransportClient *tc = cls; |
5252 | struct CommunicatorMessageContext *cmc = GNUNET_new (struct CommunicatorMessageContext); | 4977 | struct CommunicatorMessageContext *cmc |
4978 | = GNUNET_new (struct CommunicatorMessageContext); | ||
5253 | 4979 | ||
5254 | cmc->tc = tc; | 4980 | cmc->tc = tc; |
5255 | cmc->im = *im; | 4981 | cmc->im = *im; |
5256 | demultiplex_with_cmc (cmc, | 4982 | demultiplex_with_cmc (cmc, (const struct GNUNET_MessageHeader *)&im[1]); |
5257 | (const struct GNUNET_MessageHeader *) &im[1]); | ||
5258 | } | 4983 | } |
5259 | 4984 | ||
5260 | 4985 | ||
@@ -5269,61 +4994,59 @@ static void | |||
5269 | demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, | 4994 | demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, |
5270 | const struct GNUNET_MessageHeader *msg) | 4995 | const struct GNUNET_MessageHeader *msg) |
5271 | { | 4996 | { |
5272 | struct GNUNET_MQ_MessageHandler handlers[] = { | 4997 | struct GNUNET_MQ_MessageHandler handlers[] |
5273 | GNUNET_MQ_hd_var_size (fragment_box, | 4998 | = {GNUNET_MQ_hd_var_size (fragment_box, |
5274 | GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, | 4999 | GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, |
5275 | struct TransportFragmentBox, | 5000 | struct TransportFragmentBox, |
5276 | &cmc), | 5001 | &cmc), |
5277 | GNUNET_MQ_hd_fixed_size (fragment_ack, | 5002 | GNUNET_MQ_hd_fixed_size (fragment_ack, |
5278 | GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT_ACK, | 5003 | GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT_ACK, |
5279 | struct TransportFragmentAckMessage, | 5004 | struct TransportFragmentAckMessage, |
5280 | &cmc), | 5005 | &cmc), |
5281 | GNUNET_MQ_hd_var_size (reliability_box, | 5006 | GNUNET_MQ_hd_var_size (reliability_box, |
5282 | GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, | 5007 | GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, |
5283 | struct TransportReliabilityBox, | 5008 | struct TransportReliabilityBox, |
5284 | &cmc), | 5009 | &cmc), |
5285 | GNUNET_MQ_hd_fixed_size (reliability_ack, | 5010 | GNUNET_MQ_hd_fixed_size (reliability_ack, |
5286 | GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, | 5011 | GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, |
5287 | struct TransportReliabilityAckMessage, | 5012 | struct TransportReliabilityAckMessage, |
5288 | &cmc), | 5013 | &cmc), |
5289 | GNUNET_MQ_hd_var_size (backchannel_encapsulation, | 5014 | GNUNET_MQ_hd_var_size ( |
5290 | GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, | 5015 | backchannel_encapsulation, |
5291 | struct TransportBackchannelEncapsulationMessage, | 5016 | GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, |
5292 | &cmc), | 5017 | struct TransportBackchannelEncapsulationMessage, |
5293 | GNUNET_MQ_hd_var_size (dv_learn, | 5018 | &cmc), |
5294 | GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, | 5019 | GNUNET_MQ_hd_var_size (dv_learn, |
5295 | struct TransportDVLearn, | 5020 | GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, |
5296 | &cmc), | 5021 | struct TransportDVLearn, |
5297 | GNUNET_MQ_hd_var_size (dv_box, | 5022 | &cmc), |
5298 | GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, | 5023 | GNUNET_MQ_hd_var_size (dv_box, |
5299 | struct TransportDVBox, | 5024 | GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, |
5300 | &cmc), | 5025 | struct TransportDVBox, |
5301 | GNUNET_MQ_hd_fixed_size (validation_challenge, | 5026 | &cmc), |
5302 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE, | 5027 | GNUNET_MQ_hd_fixed_size ( |
5303 | struct TransportValidationChallenge, | 5028 | validation_challenge, |
5304 | &cmc), | 5029 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE, |
5305 | GNUNET_MQ_hd_fixed_size (validation_response, | 5030 | struct TransportValidationChallenge, |
5306 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE, | 5031 | &cmc), |
5307 | struct TransportValidationResponse, | 5032 | GNUNET_MQ_hd_fixed_size ( |
5308 | &cmc), | 5033 | validation_response, |
5309 | GNUNET_MQ_handler_end() | 5034 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE, |
5310 | }; | 5035 | struct TransportValidationResponse, |
5036 | &cmc), | ||
5037 | GNUNET_MQ_handler_end ()}; | ||
5311 | int ret; | 5038 | int ret; |
5312 | 5039 | ||
5313 | ret = GNUNET_MQ_handle_message (handlers, | 5040 | ret = GNUNET_MQ_handle_message (handlers, msg); |
5314 | msg); | 5041 | if (GNUNET_SYSERR == ret) { |
5315 | if (GNUNET_SYSERR == ret) | ||
5316 | { | ||
5317 | GNUNET_break (0); | 5042 | GNUNET_break (0); |
5318 | GNUNET_SERVICE_client_drop (cmc->tc->client); | 5043 | GNUNET_SERVICE_client_drop (cmc->tc->client); |
5319 | GNUNET_free (cmc); | 5044 | GNUNET_free (cmc); |
5320 | return; | 5045 | return; |
5321 | } | 5046 | } |
5322 | if (GNUNET_NO == ret) | 5047 | if (GNUNET_NO == ret) { |
5323 | { | ||
5324 | /* unencapsulated 'raw' message */ | 5048 | /* unencapsulated 'raw' message */ |
5325 | handle_raw_message (&cmc, | 5049 | handle_raw_message (&cmc, msg); |
5326 | msg); | ||
5327 | } | 5050 | } |
5328 | } | 5051 | } |
5329 | 5052 | ||
@@ -5340,8 +5063,7 @@ check_add_queue_message (void *cls, | |||
5340 | { | 5063 | { |
5341 | struct TransportClient *tc = cls; | 5064 | struct TransportClient *tc = cls; |
5342 | 5065 | ||
5343 | if (CT_COMMUNICATOR != tc->type) | 5066 | if (CT_COMMUNICATOR != tc->type) { |
5344 | { | ||
5345 | GNUNET_break (0); | 5067 | GNUNET_break (0); |
5346 | return GNUNET_SYSERR; | 5068 | return GNUNET_SYSERR; |
5347 | } | 5069 | } |
@@ -5364,8 +5086,7 @@ tracker_update_in_cb (void *cls) | |||
5364 | unsigned int rsize; | 5086 | unsigned int rsize; |
5365 | 5087 | ||
5366 | rsize = (0 == queue->mtu) ? IN_PACKET_SIZE_WITHOUT_MTU : queue->mtu; | 5088 | rsize = (0 == queue->mtu) ? IN_PACKET_SIZE_WITHOUT_MTU : queue->mtu; |
5367 | in_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_in, | 5089 | in_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_in, rsize); |
5368 | rsize); | ||
5369 | // FIXME: how exactly do we do inbound flow control? | 5090 | // FIXME: how exactly do we do inbound flow control? |
5370 | } | 5091 | } |
5371 | 5092 | ||
@@ -5398,8 +5119,7 @@ set_pending_message_uuid (struct PendingMessage *pm) | |||
5398 | * @return new message to transmit | 5119 | * @return new message to transmit |
5399 | */ | 5120 | */ |
5400 | static struct PendingMessage * | 5121 | static struct PendingMessage * |
5401 | fragment_message (struct PendingMessage *pm, | 5122 | fragment_message (struct PendingMessage *pm, uint16_t mtu) |
5402 | uint16_t mtu) | ||
5403 | { | 5123 | { |
5404 | struct PendingMessage *ff; | 5124 | struct PendingMessage *ff; |
5405 | 5125 | ||
@@ -5409,20 +5129,15 @@ fragment_message (struct PendingMessage *pm, | |||
5409 | GNUNET_assert (mtu > sizeof (struct TransportFragmentBox)); | 5129 | GNUNET_assert (mtu > sizeof (struct TransportFragmentBox)); |
5410 | 5130 | ||
5411 | /* select fragment for transmission, descending the tree if it has | 5131 | /* select fragment for transmission, descending the tree if it has |
5412 | been expanded until we are at a leaf or at a fragment that is small enough */ | 5132 | been expanded until we are at a leaf or at a fragment that is small enough |
5133 | */ | ||
5413 | ff = pm; | 5134 | ff = pm; |
5414 | while ( ( (ff->bytes_msg > mtu) || | 5135 | while (((ff->bytes_msg > mtu) || (pm == ff)) |
5415 | (pm == ff) ) && | 5136 | && (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag)) { |
5416 | (ff->frag_off == ff->bytes_msg) && | ||
5417 | (NULL != ff->head_frag) ) | ||
5418 | { | ||
5419 | ff = ff->head_frag; /* descent into fragmented fragments */ | 5137 | ff = ff->head_frag; /* descent into fragmented fragments */ |
5420 | } | 5138 | } |
5421 | 5139 | ||
5422 | if ( ( (ff->bytes_msg > mtu) || | 5140 | if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg)) { |
5423 | (pm == ff) ) && | ||
5424 | (pm->frag_off < pm->bytes_msg) ) | ||
5425 | { | ||
5426 | /* Did not yet calculate all fragments, calculate next fragment */ | 5141 | /* Did not yet calculate all fragments, calculate next fragment */ |
5427 | struct PendingMessage *frag; | 5142 | struct PendingMessage *frag; |
5428 | struct TransportFragmentBox tfb; | 5143 | struct TransportFragmentBox tfb; |
@@ -5433,59 +5148,48 @@ fragment_message (struct PendingMessage *pm, | |||
5433 | uint16_t msize; | 5148 | uint16_t msize; |
5434 | uint16_t xoff = 0; | 5149 | uint16_t xoff = 0; |
5435 | 5150 | ||
5436 | orig = (const char *) &ff[1]; | 5151 | orig = (const char *)&ff[1]; |
5437 | msize = ff->bytes_msg; | 5152 | msize = ff->bytes_msg; |
5438 | if (pm != ff) | 5153 | if (pm != ff) { |
5439 | { | ||
5440 | const struct TransportFragmentBox *tfbo; | 5154 | const struct TransportFragmentBox *tfbo; |
5441 | 5155 | ||
5442 | tfbo = (const struct TransportFragmentBox *) orig; | 5156 | tfbo = (const struct TransportFragmentBox *)orig; |
5443 | orig += sizeof (struct TransportFragmentBox); | 5157 | orig += sizeof (struct TransportFragmentBox); |
5444 | msize -= sizeof (struct TransportFragmentBox); | 5158 | msize -= sizeof (struct TransportFragmentBox); |
5445 | xoff = ntohs (tfbo->frag_off); | 5159 | xoff = ntohs (tfbo->frag_off); |
5446 | } | 5160 | } |
5447 | fragmax = mtu - sizeof (struct TransportFragmentBox); | 5161 | fragmax = mtu - sizeof (struct TransportFragmentBox); |
5448 | fragsize = GNUNET_MIN (msize - ff->frag_off, | 5162 | fragsize = GNUNET_MIN (msize - ff->frag_off, fragmax); |
5449 | fragmax); | 5163 | frag = GNUNET_malloc (sizeof (struct PendingMessage) |
5450 | frag = GNUNET_malloc (sizeof (struct PendingMessage) + | 5164 | + sizeof (struct TransportFragmentBox) + fragsize); |
5451 | sizeof (struct TransportFragmentBox) + | ||
5452 | fragsize); | ||
5453 | frag->target = pm->target; | 5165 | frag->target = pm->target; |
5454 | frag->frag_parent = ff; | 5166 | frag->frag_parent = ff; |
5455 | frag->timeout = pm->timeout; | 5167 | frag->timeout = pm->timeout; |
5456 | frag->bytes_msg = sizeof (struct TransportFragmentBox) + fragsize; | 5168 | frag->bytes_msg = sizeof (struct TransportFragmentBox) + fragsize; |
5457 | frag->pmt = PMT_FRAGMENT_BOX; | 5169 | frag->pmt = PMT_FRAGMENT_BOX; |
5458 | msg = (char *) &frag[1]; | 5170 | msg = (char *)&frag[1]; |
5459 | tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); | 5171 | tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); |
5460 | tfb.header.size = htons (sizeof (struct TransportFragmentBox) + | 5172 | tfb.header.size = htons (sizeof (struct TransportFragmentBox) + fragsize); |
5461 | fragsize); | ||
5462 | tfb.frag_uuid = htonl (pm->frag_uuidgen++); | 5173 | tfb.frag_uuid = htonl (pm->frag_uuidgen++); |
5463 | tfb.msg_uuid = pm->msg_uuid; | 5174 | tfb.msg_uuid = pm->msg_uuid; |
5464 | tfb.frag_off = htons (ff->frag_off + xoff); | 5175 | tfb.frag_off = htons (ff->frag_off + xoff); |
5465 | tfb.msg_size = htons (pm->bytes_msg); | 5176 | tfb.msg_size = htons (pm->bytes_msg); |
5466 | memcpy (msg, | 5177 | memcpy (msg, &tfb, sizeof (tfb)); |
5467 | &tfb, | 5178 | memcpy (&msg[sizeof (tfb)], &orig[ff->frag_off], fragsize); |
5468 | sizeof (tfb)); | 5179 | GNUNET_CONTAINER_MDLL_insert (frag, ff->head_frag, ff->tail_frag, frag); |
5469 | memcpy (&msg[sizeof (tfb)], | ||
5470 | &orig[ff->frag_off], | ||
5471 | fragsize); | ||
5472 | GNUNET_CONTAINER_MDLL_insert (frag, | ||
5473 | ff->head_frag, | ||
5474 | ff->tail_frag, | ||
5475 | frag); | ||
5476 | ff->frag_off += fragsize; | 5180 | ff->frag_off += fragsize; |
5477 | ff = frag; | 5181 | ff = frag; |
5478 | } | 5182 | } |
5479 | 5183 | ||
5480 | /* Move head to the tail and return it */ | 5184 | /* Move head to the tail and return it */ |
5481 | GNUNET_CONTAINER_MDLL_remove (frag, | 5185 | GNUNET_CONTAINER_MDLL_remove (frag, |
5482 | ff->frag_parent->head_frag, | 5186 | ff->frag_parent->head_frag, |
5483 | ff->frag_parent->tail_frag, | 5187 | ff->frag_parent->tail_frag, |
5484 | ff); | 5188 | ff); |
5485 | GNUNET_CONTAINER_MDLL_insert_tail (frag, | 5189 | GNUNET_CONTAINER_MDLL_insert_tail (frag, |
5486 | ff->frag_parent->head_frag, | 5190 | ff->frag_parent->head_frag, |
5487 | ff->frag_parent->tail_frag, | 5191 | ff->frag_parent->tail_frag, |
5488 | ff); | 5192 | ff); |
5489 | return ff; | 5193 | return ff; |
5490 | } | 5194 | } |
5491 | 5195 | ||
@@ -5508,28 +5212,22 @@ reliability_box_message (struct PendingMessage *pm) | |||
5508 | char *msg; | 5212 | char *msg; |
5509 | 5213 | ||
5510 | if (PMT_CORE != pm->pmt) | 5214 | if (PMT_CORE != pm->pmt) |
5511 | return pm; /* already fragmented or reliability boxed, or control message: do nothing */ | 5215 | return pm; /* already fragmented or reliability boxed, or control message: |
5216 | do nothing */ | ||
5512 | if (NULL != pm->bpm) | 5217 | if (NULL != pm->bpm) |
5513 | return pm->bpm; /* already computed earlier: do nothing */ | 5218 | return pm->bpm; /* already computed earlier: do nothing */ |
5514 | GNUNET_assert (NULL == pm->head_frag); | 5219 | GNUNET_assert (NULL == pm->head_frag); |
5515 | if (pm->bytes_msg + sizeof (rbox) > UINT16_MAX) | 5220 | if (pm->bytes_msg + sizeof (rbox) > UINT16_MAX) { |
5516 | { | ||
5517 | /* failed hard */ | 5221 | /* failed hard */ |
5518 | GNUNET_break (0); | 5222 | GNUNET_break (0); |
5519 | client_send_response (pm, | 5223 | client_send_response (pm, GNUNET_NO, 0); |
5520 | GNUNET_NO, | ||
5521 | 0); | ||
5522 | return NULL; | 5224 | return NULL; |
5523 | } | 5225 | } |
5524 | bpm = GNUNET_malloc (sizeof (struct PendingMessage) + | 5226 | bpm = GNUNET_malloc (sizeof (struct PendingMessage) + sizeof (rbox) |
5525 | sizeof (rbox) + | 5227 | + pm->bytes_msg); |
5526 | pm->bytes_msg); | ||
5527 | bpm->target = pm->target; | 5228 | bpm->target = pm->target; |
5528 | bpm->frag_parent = pm; | 5229 | bpm->frag_parent = pm; |
5529 | GNUNET_CONTAINER_MDLL_insert (frag, | 5230 | GNUNET_CONTAINER_MDLL_insert (frag, pm->head_frag, pm->tail_frag, bpm); |
5530 | pm->head_frag, | ||
5531 | pm->tail_frag, | ||
5532 | bpm); | ||
5533 | bpm->timeout = pm->timeout; | 5231 | bpm->timeout = pm->timeout; |
5534 | bpm->pmt = PMT_RELIABILITY_BOX; | 5232 | bpm->pmt = PMT_RELIABILITY_BOX; |
5535 | bpm->bytes_msg = pm->bytes_msg + sizeof (rbox); | 5233 | bpm->bytes_msg = pm->bytes_msg + sizeof (rbox); |
@@ -5538,13 +5236,9 @@ reliability_box_message (struct PendingMessage *pm) | |||
5538 | rbox.header.size = htons (sizeof (rbox) + pm->bytes_msg); | 5236 | rbox.header.size = htons (sizeof (rbox) + pm->bytes_msg); |
5539 | rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support | 5237 | rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support |
5540 | rbox.msg_uuid = pm->msg_uuid; | 5238 | rbox.msg_uuid = pm->msg_uuid; |
5541 | msg = (char *) &bpm[1]; | 5239 | msg = (char *)&bpm[1]; |
5542 | memcpy (msg, | 5240 | memcpy (msg, &rbox, sizeof (rbox)); |
5543 | &rbox, | 5241 | memcpy (&msg[sizeof (rbox)], &pm[1], pm->bytes_msg); |
5544 | sizeof (rbox)); | ||
5545 | memcpy (&msg[sizeof (rbox)], | ||
5546 | &pm[1], | ||
5547 | pm->bytes_msg); | ||
5548 | pm->bpm = bpm; | 5242 | pm->bpm = bpm; |
5549 | return bpm; | 5243 | return bpm; |
5550 | } | 5244 | } |
@@ -5570,8 +5264,7 @@ transmit_on_queue (void *cls) | |||
5570 | struct GNUNET_MQ_Envelope *env; | 5264 | struct GNUNET_MQ_Envelope *env; |
5571 | 5265 | ||
5572 | queue->transmit_task = NULL; | 5266 | queue->transmit_task = NULL; |
5573 | if (NULL == (pm = n->pending_msg_head)) | 5267 | if (NULL == (pm = n->pending_msg_head)) { |
5574 | { | ||
5575 | /* no message pending, nothing to do here! */ | 5268 | /* no message pending, nothing to do here! */ |
5576 | return; | 5269 | return; |
5577 | } | 5270 | } |
@@ -5590,18 +5283,17 @@ transmit_on_queue (void *cls) | |||
5590 | this queue */) ) | 5283 | this queue */) ) |
5591 | s = fragment_message (s, | 5284 | s = fragment_message (s, |
5592 | (0 == queue->mtu) | 5285 | (0 == queue->mtu) |
5593 | ? UINT16_MAX - sizeof (struct GNUNET_TRANSPORT_SendMessageTo) | 5286 | ? UINT16_MAX |
5594 | : queue->mtu); | 5287 | - sizeof (struct GNUNET_TRANSPORT_SendMessageTo) |
5595 | if (NULL == s) | 5288 | : queue->mtu); |
5596 | { | 5289 | if (NULL == s) { |
5597 | /* Fragmentation failed, try next message... */ | 5290 | /* Fragmentation failed, try next message... */ |
5598 | schedule_transmit_on_queue (queue); | 5291 | schedule_transmit_on_queue (queue); |
5599 | return; | 5292 | return; |
5600 | } | 5293 | } |
5601 | if (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc) | 5294 | if (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc) |
5602 | s = reliability_box_message (s); | 5295 | s = reliability_box_message (s); |
5603 | if (NULL == s) | 5296 | if (NULL == s) { |
5604 | { | ||
5605 | /* Reliability boxing failed, try next message... */ | 5297 | /* Reliability boxing failed, try next message... */ |
5606 | schedule_transmit_on_queue (queue); | 5298 | schedule_transmit_on_queue (queue); |
5607 | return; | 5299 | return; |
@@ -5614,9 +5306,7 @@ transmit_on_queue (void *cls) | |||
5614 | smt->qid = queue->qid; | 5306 | smt->qid = queue->qid; |
5615 | smt->mid = queue->mid_gen; | 5307 | smt->mid = queue->mid_gen; |
5616 | smt->receiver = n->pid; | 5308 | smt->receiver = n->pid; |
5617 | memcpy (&smt[1], | 5309 | memcpy (&smt[1], &s[1], s->bytes_msg); |
5618 | &s[1], | ||
5619 | s->bytes_msg); | ||
5620 | { | 5310 | { |
5621 | /* Pass the env to the communicator of queue for transmission. */ | 5311 | /* Pass the env to the communicator of queue for transmission. */ |
5622 | struct QueueEntry *qe; | 5312 | struct QueueEntry *qe; |
@@ -5625,14 +5315,11 @@ transmit_on_queue (void *cls) | |||
5625 | qe->mid = queue->mid_gen++; | 5315 | qe->mid = queue->mid_gen++; |
5626 | qe->queue = queue; | 5316 | qe->queue = queue; |
5627 | // qe->pm = s; // FIXME: not so easy, reference management on 'free(s)'! | 5317 | // qe->pm = s; // FIXME: not so easy, reference management on 'free(s)'! |
5628 | GNUNET_CONTAINER_DLL_insert (queue->queue_head, | 5318 | GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe); |
5629 | queue->queue_tail, | ||
5630 | qe); | ||
5631 | GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); | 5319 | GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); |
5632 | queue->queue_length++; | 5320 | queue->queue_length++; |
5633 | queue->tc->details.communicator.total_queue_length++; | 5321 | queue->tc->details.communicator.total_queue_length++; |
5634 | GNUNET_MQ_send (queue->tc->mq, | 5322 | GNUNET_MQ_send (queue->tc->mq, env); |
5635 | env); | ||
5636 | } | 5323 | } |
5637 | 5324 | ||
5638 | // FIXME: do something similar to the logic below | 5325 | // FIXME: do something similar to the logic below |
@@ -5640,55 +5327,39 @@ transmit_on_queue (void *cls) | |||
5640 | 5327 | ||
5641 | /* Check if this transmission somehow conclusively finished handing 'pm' | 5328 | /* Check if this transmission somehow conclusively finished handing 'pm' |
5642 | even without any explicit ACKs */ | 5329 | even without any explicit ACKs */ |
5643 | if ( (PMT_CORE == s->pmt) && | 5330 | if ((PMT_CORE == s->pmt) |
5644 | (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) ) | 5331 | && (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)) { |
5645 | { | ||
5646 | /* Full message sent, and over reliabile channel */ | 5332 | /* Full message sent, and over reliabile channel */ |
5647 | client_send_response (pm, | 5333 | client_send_response (pm, GNUNET_YES, pm->bytes_msg); |
5648 | GNUNET_YES, | 5334 | } else if ((GNUNET_TRANSPORT_CC_RELIABLE |
5649 | pm->bytes_msg); | 5335 | == queue->tc->details.communicator.cc) |
5650 | } | 5336 | && (PMT_FRAGMENT_BOX == s->pmt)) { |
5651 | else if ( (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) && | ||
5652 | (PMT_FRAGMENT_BOX == s->pmt) ) | ||
5653 | { | ||
5654 | struct PendingMessage *pos; | 5337 | struct PendingMessage *pos; |
5655 | 5338 | ||
5656 | /* Fragment sent over reliabile channel */ | 5339 | /* Fragment sent over reliabile channel */ |
5657 | free_fragment_tree (s); | 5340 | free_fragment_tree (s); |
5658 | pos = s->frag_parent; | 5341 | pos = s->frag_parent; |
5659 | GNUNET_CONTAINER_MDLL_remove (frag, | 5342 | GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, s); |
5660 | pos->head_frag, | ||
5661 | pos->tail_frag, | ||
5662 | s); | ||
5663 | GNUNET_free (s); | 5343 | GNUNET_free (s); |
5664 | /* check if subtree is done */ | 5344 | /* check if subtree is done */ |
5665 | while ( (NULL == pos->head_frag) && | 5345 | while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) |
5666 | (pos->frag_off == pos->bytes_msg) && | 5346 | && (pos != pm)) { |
5667 | (pos != pm) ) | ||
5668 | { | ||
5669 | s = pos; | 5347 | s = pos; |
5670 | pos = s->frag_parent; | 5348 | pos = s->frag_parent; |
5671 | GNUNET_CONTAINER_MDLL_remove (frag, | 5349 | GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, s); |
5672 | pos->head_frag, | ||
5673 | pos->tail_frag, | ||
5674 | s); | ||
5675 | GNUNET_free (s); | 5350 | GNUNET_free (s); |
5676 | } | 5351 | } |
5677 | 5352 | ||
5678 | /* Was this the last applicable fragmment? */ | 5353 | /* Was this the last applicable fragmment? */ |
5679 | if ( (NULL == pm->head_frag) && | 5354 | if ((NULL == pm->head_frag) && (pm->frag_off == pm->bytes_msg)) |
5680 | (pm->frag_off == pm->bytes_msg) ) | 5355 | client_send_response ( |
5681 | client_send_response (pm, | 5356 | pm, |
5682 | GNUNET_YES, | 5357 | GNUNET_YES, |
5683 | pm->bytes_msg /* FIXME: calculate and add overheads! */); | 5358 | pm->bytes_msg /* FIXME: calculate and add overheads! */); |
5684 | } | 5359 | } else if (PMT_CORE != pm->pmt) { |
5685 | else if (PMT_CORE != pm->pmt) | ||
5686 | { | ||
5687 | /* This was an acknowledgement of some type, always free */ | 5360 | /* This was an acknowledgement of some type, always free */ |
5688 | free_pending_message (pm); | 5361 | free_pending_message (pm); |
5689 | } | 5362 | } else { |
5690 | else | ||
5691 | { | ||
5692 | /* message not finished, waiting for acknowledgement */ | 5363 | /* message not finished, waiting for acknowledgement */ |
5693 | struct Neighbour *neighbour = pm->target; | 5364 | struct Neighbour *neighbour = pm->target; |
5694 | /* Update time by which we might retransmit 's' based on queue | 5365 | /* Update time by which we might retransmit 's' based on queue |
@@ -5698,11 +5369,9 @@ transmit_on_queue (void *cls) | |||
5698 | retransmitting. Note that in the future this heuristic should | 5369 | retransmitting. Note that in the future this heuristic should |
5699 | likely be improved further (measure RTT stability, consider | 5370 | likely be improved further (measure RTT stability, consider |
5700 | message urgency and size when delaying ACKs, etc.) */ | 5371 | message urgency and size when delaying ACKs, etc.) */ |
5701 | s->next_attempt = GNUNET_TIME_relative_to_absolute | 5372 | s->next_attempt = GNUNET_TIME_relative_to_absolute ( |
5702 | (GNUNET_TIME_relative_multiply (queue->rtt, | 5373 | GNUNET_TIME_relative_multiply (queue->rtt, 4)); |
5703 | 4)); | 5374 | if (s == pm) { |
5704 | if (s == pm) | ||
5705 | { | ||
5706 | struct PendingMessage *pos; | 5375 | struct PendingMessage *pos; |
5707 | 5376 | ||
5708 | /* re-insert sort in neighbour list */ | 5377 | /* re-insert sort in neighbour list */ |
@@ -5711,28 +5380,24 @@ transmit_on_queue (void *cls) | |||
5711 | neighbour->pending_msg_tail, | 5380 | neighbour->pending_msg_tail, |
5712 | pm); | 5381 | pm); |
5713 | pos = neighbour->pending_msg_tail; | 5382 | pos = neighbour->pending_msg_tail; |
5714 | while ( (NULL != pos) && | 5383 | while ( |
5715 | (pm->next_attempt.abs_value_us > pos->next_attempt.abs_value_us) ) | 5384 | (NULL != pos) |
5385 | && (pm->next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) | ||
5716 | pos = pos->prev_neighbour; | 5386 | pos = pos->prev_neighbour; |
5717 | GNUNET_CONTAINER_MDLL_insert_after (neighbour, | 5387 | GNUNET_CONTAINER_MDLL_insert_after (neighbour, |
5718 | neighbour->pending_msg_head, | 5388 | neighbour->pending_msg_head, |
5719 | neighbour->pending_msg_tail, | 5389 | neighbour->pending_msg_tail, |
5720 | pos, | 5390 | pos, |
5721 | pm); | 5391 | pm); |
5722 | } | 5392 | } else { |
5723 | else | ||
5724 | { | ||
5725 | /* re-insert sort in fragment list */ | 5393 | /* re-insert sort in fragment list */ |
5726 | struct PendingMessage *fp = s->frag_parent; | 5394 | struct PendingMessage *fp = s->frag_parent; |
5727 | struct PendingMessage *pos; | 5395 | struct PendingMessage *pos; |
5728 | 5396 | ||
5729 | GNUNET_CONTAINER_MDLL_remove (frag, | 5397 | GNUNET_CONTAINER_MDLL_remove (frag, fp->head_frag, fp->tail_frag, s); |
5730 | fp->head_frag, | ||
5731 | fp->tail_frag, | ||
5732 | s); | ||
5733 | pos = fp->tail_frag; | 5398 | pos = fp->tail_frag; |
5734 | while ( (NULL != pos) && | 5399 | while ((NULL != pos) |
5735 | (s->next_attempt.abs_value_us > pos->next_attempt.abs_value_us) ) | 5400 | && (s->next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) |
5736 | pos = pos->prev_frag; | 5401 | pos = pos->prev_frag; |
5737 | GNUNET_CONTAINER_MDLL_insert_after (frag, | 5402 | GNUNET_CONTAINER_MDLL_insert_after (frag, |
5738 | fp->head_frag, | 5403 | fp->head_frag, |
@@ -5759,11 +5424,11 @@ tracker_update_out_cb (void *cls) | |||
5759 | struct Queue *queue = cls; | 5424 | struct Queue *queue = cls; |
5760 | struct Neighbour *n = queue->neighbour; | 5425 | struct Neighbour *n = queue->neighbour; |
5761 | 5426 | ||
5762 | if (NULL == n->pending_msg_head) | 5427 | if (NULL == n->pending_msg_head) { |
5763 | { | 5428 | GNUNET_log ( |
5764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5429 | GNUNET_ERROR_TYPE_DEBUG, |
5765 | "Bandwidth allocation updated for empty transmission queue `%s'\n", | 5430 | "Bandwidth allocation updated for empty transmission queue `%s'\n", |
5766 | queue->address); | 5431 | queue->address); |
5767 | return; /* no message pending, nothing to do here! */ | 5432 | return; /* no message pending, nothing to do here! */ |
5768 | } | 5433 | } |
5769 | GNUNET_SCHEDULER_cancel (queue->transmit_task); | 5434 | GNUNET_SCHEDULER_cancel (queue->transmit_task); |
@@ -5781,7 +5446,7 @@ tracker_update_out_cb (void *cls) | |||
5781 | static void | 5446 | static void |
5782 | tracker_excess_out_cb (void *cls) | 5447 | tracker_excess_out_cb (void *cls) |
5783 | { | 5448 | { |
5784 | (void) cls; | 5449 | (void)cls; |
5785 | 5450 | ||
5786 | /* FIXME: trigger excess bandwidth report to core? Right now, | 5451 | /* FIXME: trigger excess bandwidth report to core? Right now, |
5787 | this is done internally within transport_api2_core already, | 5452 | this is done internally within transport_api2_core already, |
@@ -5795,7 +5460,6 @@ tracker_excess_out_cb (void *cls) | |||
5795 | } | 5460 | } |
5796 | 5461 | ||
5797 | 5462 | ||
5798 | |||
5799 | /** | 5463 | /** |
5800 | * Bandwidth tracker informs us that excessive inbound bandwidth was allocated | 5464 | * Bandwidth tracker informs us that excessive inbound bandwidth was allocated |
5801 | * which is not being used. | 5465 | * which is not being used. |
@@ -5805,7 +5469,7 @@ tracker_excess_out_cb (void *cls) | |||
5805 | static void | 5469 | static void |
5806 | tracker_excess_in_cb (void *cls) | 5470 | tracker_excess_in_cb (void *cls) |
5807 | { | 5471 | { |
5808 | (void) cls; | 5472 | (void)cls; |
5809 | 5473 | ||
5810 | /* TODO: maybe inform somone at this point? */ | 5474 | /* TODO: maybe inform somone at this point? */ |
5811 | GNUNET_STATISTICS_update (GST_stats, | 5475 | GNUNET_STATISTICS_update (GST_stats, |
@@ -5827,21 +5491,17 @@ handle_del_queue_message (void *cls, | |||
5827 | { | 5491 | { |
5828 | struct TransportClient *tc = cls; | 5492 | struct TransportClient *tc = cls; |
5829 | 5493 | ||
5830 | if (CT_COMMUNICATOR != tc->type) | 5494 | if (CT_COMMUNICATOR != tc->type) { |
5831 | { | ||
5832 | GNUNET_break (0); | 5495 | GNUNET_break (0); |
5833 | GNUNET_SERVICE_client_drop (tc->client); | 5496 | GNUNET_SERVICE_client_drop (tc->client); |
5834 | return; | 5497 | return; |
5835 | } | 5498 | } |
5836 | for (struct Queue *queue = tc->details.communicator.queue_head; | 5499 | for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; |
5837 | NULL != queue; | 5500 | queue = queue->next_client) { |
5838 | queue = queue->next_client) | ||
5839 | { | ||
5840 | struct Neighbour *neighbour = queue->neighbour; | 5501 | struct Neighbour *neighbour = queue->neighbour; |
5841 | 5502 | ||
5842 | if ( (dqm->qid != queue->qid) || | 5503 | if ((dqm->qid != queue->qid) |
5843 | (0 != GNUNET_memcmp (&dqm->receiver, | 5504 | || (0 != GNUNET_memcmp (&dqm->receiver, &neighbour->pid))) |
5844 | &neighbour->pid)) ) | ||
5845 | continue; | 5505 | continue; |
5846 | free_queue (queue); | 5506 | free_queue (queue); |
5847 | GNUNET_SERVICE_client_continue (tc->client); | 5507 | GNUNET_SERVICE_client_continue (tc->client); |
@@ -5865,8 +5525,7 @@ handle_send_message_ack (void *cls, | |||
5865 | struct TransportClient *tc = cls; | 5525 | struct TransportClient *tc = cls; |
5866 | struct QueueEntry *qe; | 5526 | struct QueueEntry *qe; |
5867 | 5527 | ||
5868 | if (CT_COMMUNICATOR != tc->type) | 5528 | if (CT_COMMUNICATOR != tc->type) { |
5869 | { | ||
5870 | GNUNET_break (0); | 5529 | GNUNET_break (0); |
5871 | GNUNET_SERVICE_client_drop (tc->client); | 5530 | GNUNET_SERVICE_client_drop (tc->client); |
5872 | return; | 5531 | return; |
@@ -5874,17 +5533,12 @@ handle_send_message_ack (void *cls, | |||
5874 | 5533 | ||
5875 | /* find our queue entry matching the ACK */ | 5534 | /* find our queue entry matching the ACK */ |
5876 | qe = NULL; | 5535 | qe = NULL; |
5877 | for (struct Queue *queue = tc->details.communicator.queue_head; | 5536 | for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; |
5878 | NULL != queue; | 5537 | queue = queue->next_client) { |
5879 | queue = queue->next_client) | 5538 | if (0 != GNUNET_memcmp (&queue->neighbour->pid, &sma->receiver)) |
5880 | { | ||
5881 | if (0 != GNUNET_memcmp (&queue->neighbour->pid, | ||
5882 | &sma->receiver)) | ||
5883 | continue; | 5539 | continue; |
5884 | for (struct QueueEntry *qep = queue->queue_head; | 5540 | for (struct QueueEntry *qep = queue->queue_head; NULL != qep; |
5885 | NULL != qep; | 5541 | qep = qep->next) { |
5886 | qep = qep->next) | ||
5887 | { | ||
5888 | if (qep->mid != sma->mid) | 5542 | if (qep->mid != sma->mid) |
5889 | continue; | 5543 | continue; |
5890 | qe = qep; | 5544 | qe = qep; |
@@ -5892,8 +5546,7 @@ handle_send_message_ack (void *cls, | |||
5892 | } | 5546 | } |
5893 | break; | 5547 | break; |
5894 | } | 5548 | } |
5895 | if (NULL == qe) | 5549 | if (NULL == qe) { |
5896 | { | ||
5897 | /* this should never happen */ | 5550 | /* this should never happen */ |
5898 | GNUNET_break (0); | 5551 | GNUNET_break (0); |
5899 | GNUNET_SERVICE_client_drop (tc->client); | 5552 | GNUNET_SERVICE_client_drop (tc->client); |
@@ -5907,25 +5560,25 @@ handle_send_message_ack (void *cls, | |||
5907 | GNUNET_SERVICE_client_continue (tc->client); | 5560 | GNUNET_SERVICE_client_continue (tc->client); |
5908 | 5561 | ||
5909 | /* if applicable, resume transmissions that waited on ACK */ | 5562 | /* if applicable, resume transmissions that waited on ACK */ |
5910 | if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 == tc->details.communicator.total_queue_length) | 5563 | if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 |
5911 | { | 5564 | == tc->details.communicator.total_queue_length) { |
5912 | /* Communicator dropped below threshold, resume all queues */ | 5565 | /* Communicator dropped below threshold, resume all queues */ |
5913 | GNUNET_STATISTICS_update (GST_stats, | 5566 | GNUNET_STATISTICS_update ( |
5914 | "# Transmission throttled due to communicator queue limit", | 5567 | GST_stats, |
5915 | -1, | 5568 | "# Transmission throttled due to communicator queue limit", |
5916 | GNUNET_NO); | 5569 | -1, |
5570 | GNUNET_NO); | ||
5917 | for (struct Queue *queue = tc->details.communicator.queue_head; | 5571 | for (struct Queue *queue = tc->details.communicator.queue_head; |
5918 | NULL != queue; | 5572 | NULL != queue; |
5919 | queue = queue->next_client) | 5573 | queue = queue->next_client) |
5920 | schedule_transmit_on_queue (queue); | 5574 | schedule_transmit_on_queue (queue); |
5921 | } | 5575 | } else if (QUEUE_LENGTH_LIMIT - 1 == qe->queue->queue_length) { |
5922 | else if (QUEUE_LENGTH_LIMIT - 1 == qe->queue->queue_length) | ||
5923 | { | ||
5924 | /* queue dropped below threshold; only resume this one queue */ | 5576 | /* queue dropped below threshold; only resume this one queue */ |
5925 | GNUNET_STATISTICS_update (GST_stats, | 5577 | GNUNET_STATISTICS_update ( |
5926 | "# Transmission throttled due to queue queue limit", | 5578 | GST_stats, |
5927 | -1, | 5579 | "# Transmission throttled due to queue queue limit", |
5928 | GNUNET_NO); | 5580 | -1, |
5581 | GNUNET_NO); | ||
5929 | schedule_transmit_on_queue (qe->queue); | 5582 | schedule_transmit_on_queue (qe->queue); |
5930 | } | 5583 | } |
5931 | 5584 | ||
@@ -5956,22 +5609,14 @@ notify_client_queues (void *cls, | |||
5956 | struct Neighbour *neighbour = value; | 5609 | struct Neighbour *neighbour = value; |
5957 | 5610 | ||
5958 | GNUNET_assert (CT_MONITOR == tc->type); | 5611 | GNUNET_assert (CT_MONITOR == tc->type); |
5959 | for (struct Queue *q = neighbour->queue_head; | 5612 | for (struct Queue *q = neighbour->queue_head; NULL != q; |
5960 | NULL != q; | 5613 | q = q->next_neighbour) { |
5961 | q = q->next_neighbour) | 5614 | struct MonitorEvent me = {.rtt = q->rtt, |
5962 | { | 5615 | .cs = q->cs, |
5963 | struct MonitorEvent me = { | 5616 | .num_msg_pending = q->num_msg_pending, |
5964 | .rtt = q->rtt, | 5617 | .num_bytes_pending = q->num_bytes_pending}; |
5965 | .cs = q->cs, | 5618 | |
5966 | .num_msg_pending = q->num_msg_pending, | 5619 | notify_monitor (tc, pid, q->address, q->nt, &me); |
5967 | .num_bytes_pending = q->num_bytes_pending | ||
5968 | }; | ||
5969 | |||
5970 | notify_monitor (tc, | ||
5971 | pid, | ||
5972 | q->address, | ||
5973 | q->nt, | ||
5974 | &me); | ||
5975 | } | 5620 | } |
5976 | return GNUNET_OK; | 5621 | return GNUNET_OK; |
5977 | } | 5622 | } |
@@ -5989,8 +5634,7 @@ handle_monitor_start (void *cls, | |||
5989 | { | 5634 | { |
5990 | struct TransportClient *tc = cls; | 5635 | struct TransportClient *tc = cls; |
5991 | 5636 | ||
5992 | if (CT_NONE != tc->type) | 5637 | if (CT_NONE != tc->type) { |
5993 | { | ||
5994 | GNUNET_break (0); | 5638 | GNUNET_break (0); |
5995 | GNUNET_SERVICE_client_drop (tc->client); | 5639 | GNUNET_SERVICE_client_drop (tc->client); |
5996 | return; | 5640 | return; |
@@ -5998,9 +5642,7 @@ handle_monitor_start (void *cls, | |||
5998 | tc->type = CT_MONITOR; | 5642 | tc->type = CT_MONITOR; |
5999 | tc->details.monitor.peer = start->peer; | 5643 | tc->details.monitor.peer = start->peer; |
6000 | tc->details.monitor.one_shot = ntohl (start->one_shot); | 5644 | tc->details.monitor.one_shot = ntohl (start->one_shot); |
6001 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, | 5645 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, ¬ify_client_queues, tc); |
6002 | ¬ify_client_queues, | ||
6003 | tc); | ||
6004 | GNUNET_SERVICE_client_mark_monitor (tc->client); | 5646 | GNUNET_SERVICE_client_mark_monitor (tc->client); |
6005 | GNUNET_SERVICE_client_continue (tc->client); | 5647 | GNUNET_SERVICE_client_continue (tc->client); |
6006 | } | 5648 | } |
@@ -6016,19 +5658,16 @@ handle_monitor_start (void *cls, | |||
6016 | static struct TransportClient * | 5658 | static struct TransportClient * |
6017 | lookup_communicator (const char *prefix) | 5659 | lookup_communicator (const char *prefix) |
6018 | { | 5660 | { |
6019 | for (struct TransportClient *tc = clients_head; | 5661 | for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) { |
6020 | NULL != tc; | ||
6021 | tc = tc->next) | ||
6022 | { | ||
6023 | if (CT_COMMUNICATOR != tc->type) | 5662 | if (CT_COMMUNICATOR != tc->type) |
6024 | continue; | 5663 | continue; |
6025 | if (0 == strcmp (prefix, | 5664 | if (0 == strcmp (prefix, tc->details.communicator.address_prefix)) |
6026 | tc->details.communicator.address_prefix)) | ||
6027 | return tc; | 5665 | return tc; |
6028 | } | 5666 | } |
6029 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 5667 | GNUNET_log ( |
6030 | "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n", | 5668 | GNUNET_ERROR_TYPE_WARNING, |
6031 | prefix); | 5669 | "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n", |
5670 | prefix); | ||
6032 | return NULL; | 5671 | return NULL; |
6033 | } | 5672 | } |
6034 | 5673 | ||
@@ -6041,8 +5680,7 @@ lookup_communicator (const char *prefix) | |||
6041 | * @param address the address to try | 5680 | * @param address the address to try |
6042 | */ | 5681 | */ |
6043 | static void | 5682 | static void |
6044 | suggest_to_connect (const struct GNUNET_PeerIdentity *pid, | 5683 | suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address) |
6045 | const char *address) | ||
6046 | { | 5684 | { |
6047 | static uint32_t idgen; | 5685 | static uint32_t idgen; |
6048 | struct TransportClient *tc; | 5686 | struct TransportClient *tc; |
@@ -6052,24 +5690,23 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, | |||
6052 | size_t alen; | 5690 | size_t alen; |
6053 | 5691 | ||
6054 | prefix = GNUNET_HELLO_address_to_prefix (address); | 5692 | prefix = GNUNET_HELLO_address_to_prefix (address); |
6055 | if (NULL == prefix) | 5693 | if (NULL == prefix) { |
6056 | { | ||
6057 | GNUNET_break (0); /* We got an invalid address!? */ | 5694 | GNUNET_break (0); /* We got an invalid address!? */ |
6058 | return; | 5695 | return; |
6059 | } | 5696 | } |
6060 | tc = lookup_communicator (prefix); | 5697 | tc = lookup_communicator (prefix); |
6061 | if (NULL == tc) | 5698 | if (NULL == tc) { |
6062 | { | 5699 | GNUNET_STATISTICS_update ( |
6063 | GNUNET_STATISTICS_update (GST_stats, | 5700 | GST_stats, |
6064 | "# Suggestions ignored due to missing communicator", | 5701 | "# Suggestions ignored due to missing communicator", |
6065 | 1, | 5702 | 1, |
6066 | GNUNET_NO); | 5703 | GNUNET_NO); |
6067 | return; | 5704 | return; |
6068 | } | 5705 | } |
6069 | /* forward suggestion for queue creation to communicator */ | 5706 | /* forward suggestion for queue creation to communicator */ |
6070 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
6071 | "Request #%u for `%s' communicator to create queue to `%s'\n", | 5708 | "Request #%u for `%s' communicator to create queue to `%s'\n", |
6072 | (unsigned int) idgen, | 5709 | (unsigned int)idgen, |
6073 | prefix, | 5710 | prefix, |
6074 | address); | 5711 | address); |
6075 | alen = strlen (address) + 1; | 5712 | alen = strlen (address) + 1; |
@@ -6078,11 +5715,8 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, | |||
6078 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); | 5715 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); |
6079 | cqm->request_id = htonl (idgen++); | 5716 | cqm->request_id = htonl (idgen++); |
6080 | cqm->receiver = *pid; | 5717 | cqm->receiver = *pid; |
6081 | memcpy (&cqm[1], | 5718 | memcpy (&cqm[1], address, alen); |
6082 | address, | 5719 | GNUNET_MQ_send (tc->mq, env); |
6083 | alen); | ||
6084 | GNUNET_MQ_send (tc->mq, | ||
6085 | env); | ||
6086 | } | 5720 | } |
6087 | 5721 | ||
6088 | 5722 | ||
@@ -6094,22 +5728,21 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, | |||
6094 | * @param vs state to derive validation challenge from | 5728 | * @param vs state to derive validation challenge from |
6095 | */ | 5729 | */ |
6096 | static void | 5730 | static void |
6097 | validation_transmit_on_queue (struct Queue *q, | 5731 | validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs) |
6098 | struct ValidationState *vs) | ||
6099 | { | 5732 | { |
6100 | struct GNUNET_MQ_Envelope *env; | 5733 | struct GNUNET_MQ_Envelope *env; |
6101 | struct TransportValidationChallenge *tvc; | 5734 | struct TransportValidationChallenge *tvc; |
6102 | 5735 | ||
6103 | vs->last_challenge_use = GNUNET_TIME_absolute_get (); | 5736 | vs->last_challenge_use = GNUNET_TIME_absolute_get (); |
6104 | env = GNUNET_MQ_msg (tvc, | 5737 | env = GNUNET_MQ_msg ( |
6105 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); | 5738 | tvc, |
5739 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); | ||
6106 | tvc->reserved = htonl (0); | 5740 | tvc->reserved = htonl (0); |
6107 | tvc->challenge = vs->challenge; | 5741 | tvc->challenge = vs->challenge; |
6108 | tvc->sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); | 5742 | tvc->sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); |
6109 | // FIXME: not so easy, need to BOX this message | 5743 | // FIXME: not so easy, need to BOX this message |
6110 | // in a transmission request! (mistake also done elsewhere!) | 5744 | // in a transmission request! (mistake also done elsewhere!) |
6111 | GNUNET_MQ_send (q->tc->mq, | 5745 | GNUNET_MQ_send (q->tc->mq, env); |
6112 | env); | ||
6113 | } | 5746 | } |
6114 | 5747 | ||
6115 | 5748 | ||
@@ -6125,50 +5758,43 @@ validation_start_cb (void *cls) | |||
6125 | struct Neighbour *n; | 5758 | struct Neighbour *n; |
6126 | struct Queue *q; | 5759 | struct Queue *q; |
6127 | 5760 | ||
6128 | (void) cls; | 5761 | (void)cls; |
6129 | validation_task = NULL; | 5762 | validation_task = NULL; |
6130 | vs = GNUNET_CONTAINER_heap_peek (validation_heap); | 5763 | vs = GNUNET_CONTAINER_heap_peek (validation_heap); |
6131 | /* drop validations past their expiration */ | 5764 | /* drop validations past their expiration */ |
6132 | while ( (NULL != vs) && | 5765 | while ( |
6133 | (0 == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us) ) | 5766 | (NULL != vs) |
6134 | { | 5767 | && (0 |
5768 | == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us)) { | ||
6135 | free_validation_state (vs); | 5769 | free_validation_state (vs); |
6136 | vs = GNUNET_CONTAINER_heap_peek (validation_heap); | 5770 | vs = GNUNET_CONTAINER_heap_peek (validation_heap); |
6137 | } | 5771 | } |
6138 | if (NULL == vs) | 5772 | if (NULL == vs) |
6139 | return; /* woopsie, no more addresses known, should only | 5773 | return; /* woopsie, no more addresses known, should only |
6140 | happen if we're really a lonely peer */ | 5774 | happen if we're really a lonely peer */ |
6141 | n = GNUNET_CONTAINER_multipeermap_get (neighbours, | 5775 | n = GNUNET_CONTAINER_multipeermap_get (neighbours, &vs->pid); |
6142 | &vs->pid); | ||
6143 | q = NULL; | 5776 | q = NULL; |
6144 | if (NULL != n) | 5777 | if (NULL != n) { |
6145 | { | 5778 | for (struct Queue *pos = n->queue_head; NULL != pos; |
6146 | for (struct Queue *pos = n->queue_head; | 5779 | pos = pos->next_neighbour) { |
6147 | NULL != pos; | 5780 | if (0 == strcmp (pos->address, vs->address)) { |
6148 | pos = pos->next_neighbour) | ||
6149 | { | ||
6150 | if (0 == strcmp (pos->address, | ||
6151 | vs->address)) | ||
6152 | { | ||
6153 | q = pos; | 5781 | q = pos; |
6154 | break; | 5782 | break; |
6155 | } | 5783 | } |
6156 | } | 5784 | } |
6157 | } | 5785 | } |
6158 | if (NULL == q) | 5786 | if (NULL == q) { |
6159 | { | ||
6160 | vs->awaiting_queue = GNUNET_YES; | 5787 | vs->awaiting_queue = GNUNET_YES; |
6161 | suggest_to_connect (&vs->pid, | 5788 | suggest_to_connect (&vs->pid, vs->address); |
6162 | vs->address); | 5789 | } else |
6163 | } | 5790 | validation_transmit_on_queue (q, vs); |
6164 | else | ||
6165 | validation_transmit_on_queue (q, | ||
6166 | vs); | ||
6167 | /* Finally, reschedule next attempt */ | 5791 | /* Finally, reschedule next attempt */ |
6168 | vs->challenge_backoff = GNUNET_TIME_randomized_backoff (vs->challenge_backoff, | 5792 | vs->challenge_backoff |
6169 | MAX_VALIDATION_CHALLENGE_FREQ); | 5793 | = GNUNET_TIME_randomized_backoff (vs->challenge_backoff, |
6170 | update_next_challenge_time (vs, | 5794 | MAX_VALIDATION_CHALLENGE_FREQ); |
6171 | GNUNET_TIME_relative_to_absolute (vs->challenge_backoff)); | 5795 | update_next_challenge_time ( |
5796 | vs, | ||
5797 | GNUNET_TIME_relative_to_absolute (vs->challenge_backoff)); | ||
6172 | } | 5798 | } |
6173 | 5799 | ||
6174 | 5800 | ||
@@ -6197,7 +5823,6 @@ struct QueueQualityContext | |||
6197 | * k-th queue in @e q. | 5823 | * k-th queue in @e q. |
6198 | */ | 5824 | */ |
6199 | unsigned int k; | 5825 | unsigned int k; |
6200 | |||
6201 | }; | 5826 | }; |
6202 | 5827 | ||
6203 | 5828 | ||
@@ -6221,12 +5846,9 @@ check_connection_quality (void *cls, | |||
6221 | struct Neighbour *n = value; | 5846 | struct Neighbour *n = value; |
6222 | int do_inc; | 5847 | int do_inc; |
6223 | 5848 | ||
6224 | (void) pid; | 5849 | (void)pid; |
6225 | do_inc = GNUNET_NO; | 5850 | do_inc = GNUNET_NO; |
6226 | for (struct Queue *q = n->queue_head; | 5851 | for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) { |
6227 | NULL != q; | ||
6228 | q = q->next_neighbour) | ||
6229 | { | ||
6230 | if (0 != q->distance) | 5852 | if (0 != q->distance) |
6231 | continue; /* DV does not count */ | 5853 | continue; /* DV does not count */ |
6232 | ctx->num_queues++; | 5854 | ctx->num_queues++; |
@@ -6262,42 +5884,34 @@ start_dv_learn (void *cls) | |||
6262 | struct GNUNET_MQ_Envelope *env; | 5884 | struct GNUNET_MQ_Envelope *env; |
6263 | struct TransportDVLearn *dvl; | 5885 | struct TransportDVLearn *dvl; |
6264 | 5886 | ||
6265 | (void) cls; | 5887 | (void)cls; |
6266 | dvlearn_task = NULL; | 5888 | dvlearn_task = NULL; |
6267 | if (0 == | 5889 | if (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)) |
6268 | GNUNET_CONTAINER_multipeermap_size (neighbours)) | ||
6269 | return; /* lost all connectivity, cannot do learning */ | 5890 | return; /* lost all connectivity, cannot do learning */ |
6270 | qqc.quality_count = 0; | 5891 | qqc.quality_count = 0; |
6271 | qqc.num_queues = 0; | 5892 | qqc.num_queues = 0; |
6272 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, | 5893 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, |
6273 | &check_connection_quality, | 5894 | &check_connection_quality, |
6274 | &qqc); | 5895 | &qqc); |
6275 | if (qqc.quality_count > DV_LEARN_QUALITY_THRESHOLD) | 5896 | if (qqc.quality_count > DV_LEARN_QUALITY_THRESHOLD) { |
6276 | { | ||
6277 | struct GNUNET_TIME_Relative delay; | 5897 | struct GNUNET_TIME_Relative delay; |
6278 | unsigned int factor; | 5898 | unsigned int factor; |
6279 | 5899 | ||
6280 | /* scale our retries by how far we are above the threshold */ | 5900 | /* scale our retries by how far we are above the threshold */ |
6281 | factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; | 5901 | factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; |
6282 | delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, | 5902 | delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, factor); |
6283 | factor); | 5903 | dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay, &start_dv_learn, NULL); |
6284 | dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay, | ||
6285 | &start_dv_learn, | ||
6286 | NULL); | ||
6287 | return; | 5904 | return; |
6288 | } | 5905 | } |
6289 | /* remove old entries in #dvlearn_map if it has grown too big */ | 5906 | /* remove old entries in #dvlearn_map if it has grown too big */ |
6290 | while (MAX_DV_LEARN_PENDING >= | 5907 | while (MAX_DV_LEARN_PENDING |
6291 | GNUNET_CONTAINER_multishortmap_size (dvlearn_map)) | 5908 | >= GNUNET_CONTAINER_multishortmap_size (dvlearn_map)) { |
6292 | { | ||
6293 | lle = lle_tail; | 5909 | lle = lle_tail; |
6294 | GNUNET_assert (GNUNET_YES == | 5910 | GNUNET_assert (GNUNET_YES |
6295 | GNUNET_CONTAINER_multishortmap_remove (dvlearn_map, | 5911 | == GNUNET_CONTAINER_multishortmap_remove (dvlearn_map, |
6296 | &lle->challenge, | 5912 | &lle->challenge, |
6297 | lle)); | 5913 | lle)); |
6298 | GNUNET_CONTAINER_DLL_remove (lle_head, | 5914 | GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); |
6299 | lle_tail, | ||
6300 | lle); | ||
6301 | GNUNET_free (lle); | 5915 | GNUNET_free (lle); |
6302 | } | 5916 | } |
6303 | /* setup data structure for learning */ | 5917 | /* setup data structure for learning */ |
@@ -6305,37 +5919,33 @@ start_dv_learn (void *cls) | |||
6305 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, | 5919 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, |
6306 | &lle->challenge, | 5920 | &lle->challenge, |
6307 | sizeof (lle->challenge)); | 5921 | sizeof (lle->challenge)); |
6308 | GNUNET_CONTAINER_DLL_insert (lle_head, | 5922 | GNUNET_CONTAINER_DLL_insert (lle_head, lle_tail, lle); |
6309 | lle_tail, | 5923 | GNUNET_break (GNUNET_YES |
6310 | lle); | 5924 | == GNUNET_CONTAINER_multishortmap_put ( |
6311 | GNUNET_break (GNUNET_YES == | 5925 | dvlearn_map, |
6312 | GNUNET_CONTAINER_multishortmap_put (dvlearn_map, | 5926 | &lle->challenge, |
6313 | &lle->challenge, | 5927 | lle, |
6314 | lle, | 5928 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
6315 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 5929 | env = GNUNET_MQ_msg (dvl, GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); |
6316 | env = GNUNET_MQ_msg (dvl, | ||
6317 | GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); | ||
6318 | dvl->num_hops = htons (0); | 5930 | dvl->num_hops = htons (0); |
6319 | dvl->bidirectional = htons (0); | 5931 | dvl->bidirectional = htons (0); |
6320 | dvl->non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); | 5932 | dvl->non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); |
6321 | { | 5933 | { |
6322 | struct DvInitPS dvip = { | 5934 | struct DvInitPS dvip = {.purpose.purpose = htonl ( |
6323 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), | 5935 | GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), |
6324 | .purpose.size = htonl (sizeof (dvip)), | 5936 | .purpose.size = htonl (sizeof (dvip)), |
6325 | .challenge = lle->challenge | 5937 | .challenge = lle->challenge}; |
6326 | }; | ||
6327 | 5938 | ||
6328 | GNUNET_assert (GNUNET_OK == | 5939 | GNUNET_assert (GNUNET_OK |
6329 | GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, | 5940 | == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, |
6330 | &dvip.purpose, | 5941 | &dvip.purpose, |
6331 | &dvl->init_sig)); | 5942 | &dvl->init_sig)); |
6332 | } | 5943 | } |
6333 | dvl->initiator = GST_my_identity; | 5944 | dvl->initiator = GST_my_identity; |
6334 | dvl->challenge = lle->challenge; | 5945 | dvl->challenge = lle->challenge; |
6335 | 5946 | ||
6336 | qqc.quality_count = 0; | 5947 | qqc.quality_count = 0; |
6337 | qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 5948 | qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues); |
6338 | qqc.num_queues); | ||
6339 | qqc.num_queues = 0; | 5949 | qqc.num_queues = 0; |
6340 | qqc.q = NULL; | 5950 | qqc.q = NULL; |
6341 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, | 5951 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, |
@@ -6347,15 +5957,14 @@ start_dv_learn (void *cls) | |||
6347 | lle->launch_time = GNUNET_TIME_absolute_get (); | 5957 | lle->launch_time = GNUNET_TIME_absolute_get (); |
6348 | // FIXME: not so easy, need to BOX this message | 5958 | // FIXME: not so easy, need to BOX this message |
6349 | // in a transmission request! (mistake also done elsewhere!) | 5959 | // in a transmission request! (mistake also done elsewhere!) |
6350 | GNUNET_MQ_send (qqc.q->tc->mq, | 5960 | GNUNET_MQ_send (qqc.q->tc->mq, env); |
6351 | env); | ||
6352 | 5961 | ||
6353 | /* reschedule this job, randomizing the time it runs (but no | 5962 | /* reschedule this job, randomizing the time it runs (but no |
6354 | actual backoff!) */ | 5963 | actual backoff!) */ |
6355 | dvlearn_task | 5964 | dvlearn_task = GNUNET_SCHEDULER_add_delayed ( |
6356 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_randomize (DV_LEARN_BASE_FREQUENCY), | 5965 | GNUNET_TIME_randomize (DV_LEARN_BASE_FREQUENCY), |
6357 | &start_dv_learn, | 5966 | &start_dv_learn, |
6358 | NULL); | 5967 | NULL); |
6359 | } | 5968 | } |
6360 | 5969 | ||
6361 | 5970 | ||
@@ -6376,14 +5985,11 @@ check_validation_request_pending (void *cls, | |||
6376 | struct Queue *q = cls; | 5985 | struct Queue *q = cls; |
6377 | struct ValidationState *vs = value; | 5986 | struct ValidationState *vs = value; |
6378 | 5987 | ||
6379 | (void) pid; | 5988 | (void)pid; |
6380 | if ( (GNUNET_YES == vs->awaiting_queue) && | 5989 | if ((GNUNET_YES == vs->awaiting_queue) |
6381 | (0 == strcmp (vs->address, | 5990 | && (0 == strcmp (vs->address, q->address))) { |
6382 | q->address)) ) | ||
6383 | { | ||
6384 | vs->awaiting_queue = GNUNET_NO; | 5991 | vs->awaiting_queue = GNUNET_NO; |
6385 | validation_transmit_on_queue (q, | 5992 | validation_transmit_on_queue (q, vs); |
6386 | vs); | ||
6387 | return GNUNET_NO; | 5993 | return GNUNET_NO; |
6388 | } | 5994 | } |
6389 | return GNUNET_OK; | 5995 | return GNUNET_OK; |
@@ -6406,8 +6012,7 @@ handle_add_queue_message (void *cls, | |||
6406 | const char *addr; | 6012 | const char *addr; |
6407 | uint16_t addr_len; | 6013 | uint16_t addr_len; |
6408 | 6014 | ||
6409 | if (ntohl (aqm->mtu) <= sizeof (struct TransportFragmentBox)) | 6015 | if (ntohl (aqm->mtu) <= sizeof (struct TransportFragmentBox)) { |
6410 | { | ||
6411 | /* MTU so small as to be useless for transmissions, | 6016 | /* MTU so small as to be useless for transmissions, |
6412 | required for #fragment_message()! */ | 6017 | required for #fragment_message()! */ |
6413 | GNUNET_break_op (0); | 6018 | GNUNET_break_op (0); |
@@ -6415,30 +6020,29 @@ handle_add_queue_message (void *cls, | |||
6415 | return; | 6020 | return; |
6416 | } | 6021 | } |
6417 | neighbour = lookup_neighbour (&aqm->receiver); | 6022 | neighbour = lookup_neighbour (&aqm->receiver); |
6418 | if (NULL == neighbour) | 6023 | if (NULL == neighbour) { |
6419 | { | ||
6420 | neighbour = GNUNET_new (struct Neighbour); | 6024 | neighbour = GNUNET_new (struct Neighbour); |
6421 | neighbour->earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 6025 | neighbour->earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
6422 | neighbour->pid = aqm->receiver; | 6026 | neighbour->pid = aqm->receiver; |
6423 | GNUNET_assert (GNUNET_OK == | 6027 | GNUNET_assert (GNUNET_OK |
6424 | GNUNET_CONTAINER_multipeermap_put (neighbours, | 6028 | == GNUNET_CONTAINER_multipeermap_put ( |
6425 | &neighbour->pid, | 6029 | neighbours, |
6426 | neighbour, | 6030 | &neighbour->pid, |
6427 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 6031 | neighbour, |
6428 | cores_send_connect_info (&neighbour->pid, | 6032 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
6429 | GNUNET_BANDWIDTH_ZERO); | 6033 | cores_send_connect_info (&neighbour->pid, GNUNET_BANDWIDTH_ZERO); |
6430 | } | 6034 | } |
6431 | addr_len = ntohs (aqm->header.size) - sizeof (*aqm); | 6035 | addr_len = ntohs (aqm->header.size) - sizeof (*aqm); |
6432 | addr = (const char *) &aqm[1]; | 6036 | addr = (const char *)&aqm[1]; |
6433 | 6037 | ||
6434 | queue = GNUNET_malloc (sizeof (struct Queue) + addr_len); | 6038 | queue = GNUNET_malloc (sizeof (struct Queue) + addr_len); |
6435 | queue->tc = tc; | 6039 | queue->tc = tc; |
6436 | queue->address = (const char *) &queue[1]; | 6040 | queue->address = (const char *)&queue[1]; |
6437 | queue->rtt = GNUNET_TIME_UNIT_FOREVER_REL; | 6041 | queue->rtt = GNUNET_TIME_UNIT_FOREVER_REL; |
6438 | queue->qid = aqm->qid; | 6042 | queue->qid = aqm->qid; |
6439 | queue->mtu = ntohl (aqm->mtu); | 6043 | queue->mtu = ntohl (aqm->mtu); |
6440 | queue->nt = (enum GNUNET_NetworkType) ntohl (aqm->nt); | 6044 | queue->nt = (enum GNUNET_NetworkType)ntohl (aqm->nt); |
6441 | queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs); | 6045 | queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl (aqm->cs); |
6442 | queue->neighbour = neighbour; | 6046 | queue->neighbour = neighbour; |
6443 | GNUNET_BANDWIDTH_tracker_init2 (&queue->tracker_in, | 6047 | GNUNET_BANDWIDTH_tracker_init2 (&queue->tracker_in, |
6444 | &tracker_update_in_cb, | 6048 | &tracker_update_in_cb, |
@@ -6454,20 +6058,12 @@ handle_add_queue_message (void *cls, | |||
6454 | GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S, | 6058 | GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S, |
6455 | &tracker_excess_out_cb, | 6059 | &tracker_excess_out_cb, |
6456 | queue); | 6060 | queue); |
6457 | memcpy (&queue[1], | 6061 | memcpy (&queue[1], addr, addr_len); |
6458 | addr, | ||
6459 | addr_len); | ||
6460 | /* notify monitors about new queue */ | 6062 | /* notify monitors about new queue */ |
6461 | { | 6063 | { |
6462 | struct MonitorEvent me = { | 6064 | struct MonitorEvent me = {.rtt = queue->rtt, .cs = queue->cs}; |
6463 | .rtt = queue->rtt, | ||
6464 | .cs = queue->cs | ||
6465 | }; | ||
6466 | 6065 | ||
6467 | notify_monitors (&neighbour->pid, | 6066 | notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); |
6468 | queue->address, | ||
6469 | queue->nt, | ||
6470 | &me); | ||
6471 | } | 6067 | } |
6472 | GNUNET_CONTAINER_MDLL_insert (neighbour, | 6068 | GNUNET_CONTAINER_MDLL_insert (neighbour, |
6473 | neighbour->queue_head, | 6069 | neighbour->queue_head, |
@@ -6478,14 +6074,14 @@ handle_add_queue_message (void *cls, | |||
6478 | tc->details.communicator.queue_tail, | 6074 | tc->details.communicator.queue_tail, |
6479 | queue); | 6075 | queue); |
6480 | /* check if valdiations are waiting for the queue */ | 6076 | /* check if valdiations are waiting for the queue */ |
6481 | (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, | 6077 | (void)GNUNET_CONTAINER_multipeermap_get_multiple ( |
6482 | &aqm->receiver, | 6078 | validation_map, |
6483 | &check_validation_request_pending, | 6079 | &aqm->receiver, |
6484 | queue); | 6080 | &check_validation_request_pending, |
6081 | queue); | ||
6485 | /* might be our first queue, try launching DV learning */ | 6082 | /* might be our first queue, try launching DV learning */ |
6486 | if (NULL == dvlearn_task) | 6083 | if (NULL == dvlearn_task) |
6487 | dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, | 6084 | dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, NULL); |
6488 | NULL); | ||
6489 | GNUNET_SERVICE_client_continue (tc->client); | 6085 | GNUNET_SERVICE_client_continue (tc->client); |
6490 | } | 6086 | } |
6491 | 6087 | ||
@@ -6503,8 +6099,7 @@ handle_queue_create_ok (void *cls, | |||
6503 | { | 6099 | { |
6504 | struct TransportClient *tc = cls; | 6100 | struct TransportClient *tc = cls; |
6505 | 6101 | ||
6506 | if (CT_COMMUNICATOR != tc->type) | 6102 | if (CT_COMMUNICATOR != tc->type) { |
6507 | { | ||
6508 | GNUNET_break (0); | 6103 | GNUNET_break (0); |
6509 | GNUNET_SERVICE_client_drop (tc->client); | 6104 | GNUNET_SERVICE_client_drop (tc->client); |
6510 | return; | 6105 | return; |
@@ -6515,72 +6110,69 @@ handle_queue_create_ok (void *cls, | |||
6515 | GNUNET_NO); | 6110 | GNUNET_NO); |
6516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 6111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
6517 | "Request #%u for communicator to create queue succeeded\n", | 6112 | "Request #%u for communicator to create queue succeeded\n", |
6518 | (unsigned int) ntohs (cqr->request_id)); | 6113 | (unsigned int)ntohs (cqr->request_id)); |
6519 | GNUNET_SERVICE_client_continue (tc->client); | 6114 | GNUNET_SERVICE_client_continue (tc->client); |
6520 | } | 6115 | } |
6521 | 6116 | ||
6522 | 6117 | ||
6523 | /** | 6118 | /** |
6524 | * Communicator tells us that our request to create a queue failed. This usually | 6119 | * Communicator tells us that our request to create a queue failed. This usually |
6525 | * indicates that the provided address is simply invalid or that the communicator's | 6120 | * indicates that the provided address is simply invalid or that the |
6526 | * resources are exhausted. | 6121 | * communicator's resources are exhausted. |
6527 | * | 6122 | * |
6528 | * @param cls the `struct TransportClient` | 6123 | * @param cls the `struct TransportClient` |
6529 | * @param cqr failure message | 6124 | * @param cqr failure message |
6530 | */ | 6125 | */ |
6531 | static void | 6126 | static void |
6532 | handle_queue_create_fail (void *cls, | 6127 | handle_queue_create_fail ( |
6533 | const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) | 6128 | void *cls, |
6129 | const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) | ||
6534 | { | 6130 | { |
6535 | struct TransportClient *tc = cls; | 6131 | struct TransportClient *tc = cls; |
6536 | 6132 | ||
6537 | if (CT_COMMUNICATOR != tc->type) | 6133 | if (CT_COMMUNICATOR != tc->type) { |
6538 | { | ||
6539 | GNUNET_break (0); | 6134 | GNUNET_break (0); |
6540 | GNUNET_SERVICE_client_drop (tc->client); | 6135 | GNUNET_SERVICE_client_drop (tc->client); |
6541 | return; | 6136 | return; |
6542 | } | 6137 | } |
6543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 6138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
6544 | "Request #%u for communicator to create queue failed\n", | 6139 | "Request #%u for communicator to create queue failed\n", |
6545 | (unsigned int) ntohs (cqr->request_id)); | 6140 | (unsigned int)ntohs (cqr->request_id)); |
6546 | GNUNET_STATISTICS_update (GST_stats, | 6141 | GNUNET_STATISTICS_update ( |
6547 | "# Suggestions failed in queue creation at communicator", | 6142 | GST_stats, |
6548 | 1, | 6143 | "# Suggestions failed in queue creation at communicator", |
6549 | GNUNET_NO); | 6144 | 1, |
6145 | GNUNET_NO); | ||
6550 | GNUNET_SERVICE_client_continue (tc->client); | 6146 | GNUNET_SERVICE_client_continue (tc->client); |
6551 | } | 6147 | } |
6552 | 6148 | ||
6553 | 6149 | ||
6554 | /** | 6150 | /** |
6555 | * We have received a `struct ExpressPreferenceMessage` from an application client. | 6151 | * We have received a `struct ExpressPreferenceMessage` from an application |
6152 | * client. | ||
6556 | * | 6153 | * |
6557 | * @param cls handle to the client | 6154 | * @param cls handle to the client |
6558 | * @param msg the start message | 6155 | * @param msg the start message |
6559 | */ | 6156 | */ |
6560 | static void | 6157 | static void |
6561 | handle_suggest_cancel (void *cls, | 6158 | handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg) |
6562 | const struct ExpressPreferenceMessage *msg) | ||
6563 | { | 6159 | { |
6564 | struct TransportClient *tc = cls; | 6160 | struct TransportClient *tc = cls; |
6565 | struct PeerRequest *pr; | 6161 | struct PeerRequest *pr; |
6566 | 6162 | ||
6567 | if (CT_APPLICATION != tc->type) | 6163 | if (CT_APPLICATION != tc->type) { |
6568 | { | ||
6569 | GNUNET_break (0); | 6164 | GNUNET_break (0); |
6570 | GNUNET_SERVICE_client_drop (tc->client); | 6165 | GNUNET_SERVICE_client_drop (tc->client); |
6571 | return; | 6166 | return; |
6572 | } | 6167 | } |
6573 | pr = GNUNET_CONTAINER_multipeermap_get (tc->details.application.requests, | 6168 | pr = GNUNET_CONTAINER_multipeermap_get (tc->details.application.requests, |
6574 | &msg->peer); | 6169 | &msg->peer); |
6575 | if (NULL == pr) | 6170 | if (NULL == pr) { |
6576 | { | ||
6577 | GNUNET_break (0); | 6171 | GNUNET_break (0); |
6578 | GNUNET_SERVICE_client_drop (tc->client); | 6172 | GNUNET_SERVICE_client_drop (tc->client); |
6579 | return; | 6173 | return; |
6580 | } | 6174 | } |
6581 | (void) stop_peer_request (tc, | 6175 | (void)stop_peer_request (tc, &pr->pid, pr); |
6582 | &pr->pid, | ||
6583 | pr); | ||
6584 | GNUNET_SERVICE_client_continue (tc->client); | 6176 | GNUNET_SERVICE_client_continue (tc->client); |
6585 | } | 6177 | } |
6586 | 6178 | ||
@@ -6594,11 +6186,12 @@ handle_suggest_cancel (void *cls, | |||
6594 | * @return #GNUNET_OK | 6186 | * @return #GNUNET_OK |
6595 | */ | 6187 | */ |
6596 | static int | 6188 | static int |
6597 | check_address_consider_verify (void *cls, | 6189 | check_address_consider_verify ( |
6598 | const struct GNUNET_TRANSPORT_AddressToVerify *hdr) | 6190 | void *cls, |
6191 | const struct GNUNET_TRANSPORT_AddressToVerify *hdr) | ||
6599 | { | 6192 | { |
6600 | (void) cls; | 6193 | (void)cls; |
6601 | (void) hdr; | 6194 | (void)hdr; |
6602 | return GNUNET_OK; | 6195 | return GNUNET_OK; |
6603 | } | 6196 | } |
6604 | 6197 | ||
@@ -6637,9 +6230,8 @@ check_known_address (void *cls, | |||
6637 | struct CheckKnownAddressContext *ckac = cls; | 6230 | struct CheckKnownAddressContext *ckac = cls; |
6638 | struct ValidationState *vs = value; | 6231 | struct ValidationState *vs = value; |
6639 | 6232 | ||
6640 | (void) pid; | 6233 | (void)pid; |
6641 | if (0 != strcmp (vs->address, | 6234 | if (0 != strcmp (vs->address, ckac->address)) |
6642 | ckac->address)) | ||
6643 | return GNUNET_OK; | 6235 | return GNUNET_OK; |
6644 | ckac->vs = vs; | 6236 | ckac->vs = vs; |
6645 | return GNUNET_NO; | 6237 | return GNUNET_NO; |
@@ -6660,32 +6252,29 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid, | |||
6660 | { | 6252 | { |
6661 | struct GNUNET_TIME_Absolute now; | 6253 | struct GNUNET_TIME_Absolute now; |
6662 | struct ValidationState *vs; | 6254 | struct ValidationState *vs; |
6663 | struct CheckKnownAddressContext ckac = { | 6255 | struct CheckKnownAddressContext ckac = {.address = address, .vs = NULL}; |
6664 | .address = address, | ||
6665 | .vs = NULL | ||
6666 | }; | ||
6667 | 6256 | ||
6668 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) | 6257 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) |
6669 | return; /* expired */ | 6258 | return; /* expired */ |
6670 | (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, | 6259 | (void)GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, |
6671 | pid, | 6260 | pid, |
6672 | &check_known_address, | 6261 | &check_known_address, |
6673 | &ckac); | 6262 | &ckac); |
6674 | if (NULL != (vs = ckac.vs)) | 6263 | if (NULL != (vs = ckac.vs)) { |
6675 | { | 6264 | /* if 'vs' is not currently valid, we need to speed up retrying the |
6676 | /* if 'vs' is not currently valid, we need to speed up retrying the validation */ | 6265 | * validation */ |
6677 | if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) | 6266 | if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) { |
6678 | { | ||
6679 | /* reduce backoff as we got a fresh advertisement */ | 6267 | /* reduce backoff as we got a fresh advertisement */ |
6680 | vs->challenge_backoff = GNUNET_TIME_relative_min (FAST_VALIDATION_CHALLENGE_FREQ, | 6268 | vs->challenge_backoff = GNUNET_TIME_relative_min ( |
6681 | GNUNET_TIME_relative_divide (vs->challenge_backoff, | 6269 | FAST_VALIDATION_CHALLENGE_FREQ, |
6682 | 2)); | 6270 | GNUNET_TIME_relative_divide (vs->challenge_backoff, 2)); |
6683 | update_next_challenge_time (vs, | 6271 | update_next_challenge_time ( |
6684 | GNUNET_TIME_relative_to_absolute (vs->challenge_backoff)); | 6272 | vs, |
6273 | GNUNET_TIME_relative_to_absolute (vs->challenge_backoff)); | ||
6685 | } | 6274 | } |
6686 | return; | 6275 | return; |
6687 | } | 6276 | } |
6688 | now = GNUNET_TIME_absolute_get(); | 6277 | now = GNUNET_TIME_absolute_get (); |
6689 | vs = GNUNET_new (struct ValidationState); | 6278 | vs = GNUNET_new (struct ValidationState); |
6690 | vs->pid = *pid; | 6279 | vs->pid = *pid; |
6691 | vs->valid_until = expiration; | 6280 | vs->valid_until = expiration; |
@@ -6695,13 +6284,13 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid, | |||
6695 | &vs->challenge, | 6284 | &vs->challenge, |
6696 | sizeof (vs->challenge)); | 6285 | sizeof (vs->challenge)); |
6697 | vs->address = GNUNET_strdup (address); | 6286 | vs->address = GNUNET_strdup (address); |
6698 | GNUNET_assert (GNUNET_YES == | 6287 | GNUNET_assert (GNUNET_YES |
6699 | GNUNET_CONTAINER_multipeermap_put (validation_map, | 6288 | == GNUNET_CONTAINER_multipeermap_put ( |
6700 | &vs->pid, | 6289 | validation_map, |
6701 | vs, | 6290 | &vs->pid, |
6702 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 6291 | vs, |
6703 | update_next_challenge_time (vs, | 6292 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
6704 | now); | 6293 | update_next_challenge_time (vs, now); |
6705 | } | 6294 | } |
6706 | 6295 | ||
6707 | 6296 | ||
@@ -6720,48 +6309,42 @@ handle_hello (void *cls, | |||
6720 | struct PeerRequest *pr = cls; | 6309 | struct PeerRequest *pr = cls; |
6721 | const char *val; | 6310 | const char *val; |
6722 | 6311 | ||
6723 | if (NULL != emsg) | 6312 | if (NULL != emsg) { |
6724 | { | ||
6725 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 6313 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
6726 | "Got failure from PEERSTORE: %s\n", | 6314 | "Got failure from PEERSTORE: %s\n", |
6727 | emsg); | 6315 | emsg); |
6728 | return; | 6316 | return; |
6729 | } | 6317 | } |
6730 | val = record->value; | 6318 | val = record->value; |
6731 | if ( (0 == record->value_size) || | 6319 | if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) { |
6732 | ('\0' != val[record->value_size - 1]) ) | ||
6733 | { | ||
6734 | GNUNET_break (0); | 6320 | GNUNET_break (0); |
6735 | return; | 6321 | return; |
6736 | } | 6322 | } |
6737 | start_address_validation (&pr->pid, | 6323 | start_address_validation (&pr->pid, |
6738 | (const char *) record->value, | 6324 | (const char *)record->value, |
6739 | record->expiry); | 6325 | record->expiry); |
6740 | } | 6326 | } |
6741 | 6327 | ||
6742 | 6328 | ||
6743 | /** | 6329 | /** |
6744 | * We have received a `struct ExpressPreferenceMessage` from an application client. | 6330 | * We have received a `struct ExpressPreferenceMessage` from an application |
6331 | * client. | ||
6745 | * | 6332 | * |
6746 | * @param cls handle to the client | 6333 | * @param cls handle to the client |
6747 | * @param msg the start message | 6334 | * @param msg the start message |
6748 | */ | 6335 | */ |
6749 | static void | 6336 | static void |
6750 | handle_suggest (void *cls, | 6337 | handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg) |
6751 | const struct ExpressPreferenceMessage *msg) | ||
6752 | { | 6338 | { |
6753 | struct TransportClient *tc = cls; | 6339 | struct TransportClient *tc = cls; |
6754 | struct PeerRequest *pr; | 6340 | struct PeerRequest *pr; |
6755 | 6341 | ||
6756 | if (CT_NONE == tc->type) | 6342 | if (CT_NONE == tc->type) { |
6757 | { | ||
6758 | tc->type = CT_APPLICATION; | 6343 | tc->type = CT_APPLICATION; |
6759 | tc->details.application.requests | 6344 | tc->details.application.requests |
6760 | = GNUNET_CONTAINER_multipeermap_create (16, | 6345 | = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); |
6761 | GNUNET_YES); | ||
6762 | } | 6346 | } |
6763 | if (CT_APPLICATION != tc->type) | 6347 | if (CT_APPLICATION != tc->type) { |
6764 | { | ||
6765 | GNUNET_break (0); | 6348 | GNUNET_break (0); |
6766 | GNUNET_SERVICE_client_drop (tc->client); | 6349 | GNUNET_SERVICE_client_drop (tc->client); |
6767 | return; | 6350 | return; |
@@ -6769,19 +6352,19 @@ handle_suggest (void *cls, | |||
6769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 6352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
6770 | "Client suggested we talk to %s with preference %d at rate %u\n", | 6353 | "Client suggested we talk to %s with preference %d at rate %u\n", |
6771 | GNUNET_i2s (&msg->peer), | 6354 | GNUNET_i2s (&msg->peer), |
6772 | (int) ntohl (msg->pk), | 6355 | (int)ntohl (msg->pk), |
6773 | (int) ntohl (msg->bw.value__)); | 6356 | (int)ntohl (msg->bw.value__)); |
6774 | pr = GNUNET_new (struct PeerRequest); | 6357 | pr = GNUNET_new (struct PeerRequest); |
6775 | pr->tc = tc; | 6358 | pr->tc = tc; |
6776 | pr->pid = msg->peer; | 6359 | pr->pid = msg->peer; |
6777 | pr->bw = msg->bw; | 6360 | pr->bw = msg->bw; |
6778 | pr->pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk); | 6361 | pr->pk = (enum GNUNET_MQ_PreferenceKind)ntohl (msg->pk); |
6779 | if (GNUNET_YES != | 6362 | if (GNUNET_YES |
6780 | GNUNET_CONTAINER_multipeermap_put (tc->details.application.requests, | 6363 | != GNUNET_CONTAINER_multipeermap_put ( |
6781 | &pr->pid, | 6364 | tc->details.application.requests, |
6782 | pr, | 6365 | &pr->pid, |
6783 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 6366 | pr, |
6784 | { | 6367 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { |
6785 | GNUNET_break (0); | 6368 | GNUNET_break (0); |
6786 | GNUNET_free (pr); | 6369 | GNUNET_free (pr); |
6787 | GNUNET_SERVICE_client_drop (tc->client); | 6370 | GNUNET_SERVICE_client_drop (tc->client); |
@@ -6806,31 +6389,30 @@ handle_suggest (void *cls, | |||
6806 | * signature in the body, see #GNUNET_HELLO_extract_address() | 6389 | * signature in the body, see #GNUNET_HELLO_extract_address() |
6807 | */ | 6390 | */ |
6808 | static void | 6391 | static void |
6809 | handle_address_consider_verify (void *cls, | 6392 | handle_address_consider_verify ( |
6810 | const struct GNUNET_TRANSPORT_AddressToVerify *hdr) | 6393 | void *cls, |
6394 | const struct GNUNET_TRANSPORT_AddressToVerify *hdr) | ||
6811 | { | 6395 | { |
6812 | struct TransportClient *tc = cls; | 6396 | struct TransportClient *tc = cls; |
6813 | char *address; | 6397 | char *address; |
6814 | enum GNUNET_NetworkType nt; | 6398 | enum GNUNET_NetworkType nt; |
6815 | struct GNUNET_TIME_Absolute expiration; | 6399 | struct GNUNET_TIME_Absolute expiration; |
6816 | 6400 | ||
6817 | (void) cls; | 6401 | (void)cls; |
6818 | // FIXME: checking that we know this address already should | 6402 | // FIXME: checking that we know this address already should |
6819 | // be done BEFORE checking the signature => HELLO API change! | 6403 | // be done BEFORE checking the signature => HELLO API change! |
6820 | // FIXME: pre-check: rate-limit signature verification / validation?! | 6404 | // FIXME: pre-check: rate-limit signature verification / validation?! |
6821 | address = GNUNET_HELLO_extract_address (&hdr[1], | 6405 | address |
6822 | ntohs (hdr->header.size) - sizeof (*hdr), | 6406 | = GNUNET_HELLO_extract_address (&hdr[1], |
6823 | &hdr->peer, | 6407 | ntohs (hdr->header.size) - sizeof (*hdr), |
6824 | &nt, | 6408 | &hdr->peer, |
6825 | &expiration); | 6409 | &nt, |
6826 | if (NULL == address) | 6410 | &expiration); |
6827 | { | 6411 | if (NULL == address) { |
6828 | GNUNET_break_op (0); | 6412 | GNUNET_break_op (0); |
6829 | return; | 6413 | return; |
6830 | } | 6414 | } |
6831 | start_address_validation (&hdr->peer, | 6415 | start_address_validation (&hdr->peer, address, expiration); |
6832 | address, | ||
6833 | expiration); | ||
6834 | GNUNET_free (address); | 6416 | GNUNET_free (address); |
6835 | GNUNET_SERVICE_client_continue (tc->client); | 6417 | GNUNET_SERVICE_client_continue (tc->client); |
6836 | } | 6418 | } |
@@ -6848,7 +6430,7 @@ static int | |||
6848 | check_request_hello_validation (void *cls, | 6430 | check_request_hello_validation (void *cls, |
6849 | const struct RequestHelloValidationMessage *m) | 6431 | const struct RequestHelloValidationMessage *m) |
6850 | { | 6432 | { |
6851 | (void) cls; | 6433 | (void)cls; |
6852 | GNUNET_MQ_check_zero_termination (m); | 6434 | GNUNET_MQ_check_zero_termination (m); |
6853 | return GNUNET_OK; | 6435 | return GNUNET_OK; |
6854 | } | 6436 | } |
@@ -6868,7 +6450,7 @@ handle_request_hello_validation (void *cls, | |||
6868 | struct TransportClient *tc = cls; | 6450 | struct TransportClient *tc = cls; |
6869 | 6451 | ||
6870 | start_address_validation (&m->peer, | 6452 | start_address_validation (&m->peer, |
6871 | (const char *) &m[1], | 6453 | (const char *)&m[1], |
6872 | GNUNET_TIME_absolute_ntoh (m->expiration)); | 6454 | GNUNET_TIME_absolute_ntoh (m->expiration)); |
6873 | GNUNET_SERVICE_client_continue (tc->client); | 6455 | GNUNET_SERVICE_client_continue (tc->client); |
6874 | } | 6456 | } |
@@ -6889,8 +6471,8 @@ free_neighbour_cb (void *cls, | |||
6889 | { | 6471 | { |
6890 | struct Neighbour *neighbour = value; | 6472 | struct Neighbour *neighbour = value; |
6891 | 6473 | ||
6892 | (void) cls; | 6474 | (void)cls; |
6893 | (void) pid; | 6475 | (void)pid; |
6894 | GNUNET_break (0); // should this ever happen? | 6476 | GNUNET_break (0); // should this ever happen? |
6895 | free_neighbour (neighbour); | 6477 | free_neighbour (neighbour); |
6896 | 6478 | ||
@@ -6913,8 +6495,8 @@ free_dv_routes_cb (void *cls, | |||
6913 | { | 6495 | { |
6914 | struct DistanceVector *dv = value; | 6496 | struct DistanceVector *dv = value; |
6915 | 6497 | ||
6916 | (void) cls; | 6498 | (void)cls; |
6917 | (void) pid; | 6499 | (void)pid; |
6918 | free_dv_route (dv); | 6500 | free_dv_route (dv); |
6919 | 6501 | ||
6920 | return GNUNET_OK; | 6502 | return GNUNET_OK; |
@@ -6936,8 +6518,8 @@ free_ephemeral_cb (void *cls, | |||
6936 | { | 6518 | { |
6937 | struct EphemeralCacheEntry *ece = value; | 6519 | struct EphemeralCacheEntry *ece = value; |
6938 | 6520 | ||
6939 | (void) cls; | 6521 | (void)cls; |
6940 | (void) pid; | 6522 | (void)pid; |
6941 | free_ephemeral (ece); | 6523 | free_ephemeral (ece); |
6942 | return GNUNET_OK; | 6524 | return GNUNET_OK; |
6943 | } | 6525 | } |
@@ -6958,8 +6540,8 @@ free_validation_state_cb (void *cls, | |||
6958 | { | 6540 | { |
6959 | struct ValidationState *vs = value; | 6541 | struct ValidationState *vs = value; |
6960 | 6542 | ||
6961 | (void) cls; | 6543 | (void)cls; |
6962 | (void) pid; | 6544 | (void)pid; |
6963 | free_validation_state (vs); | 6545 | free_validation_state (vs); |
6964 | return GNUNET_OK; | 6546 | return GNUNET_OK; |
6965 | } | 6547 | } |
@@ -6975,30 +6557,22 @@ static void | |||
6975 | do_shutdown (void *cls) | 6557 | do_shutdown (void *cls) |
6976 | { | 6558 | { |
6977 | struct LearnLaunchEntry *lle; | 6559 | struct LearnLaunchEntry *lle; |
6978 | (void) cls; | 6560 | (void)cls; |
6979 | 6561 | ||
6980 | if (NULL != ephemeral_task) | 6562 | if (NULL != ephemeral_task) { |
6981 | { | ||
6982 | GNUNET_SCHEDULER_cancel (ephemeral_task); | 6563 | GNUNET_SCHEDULER_cancel (ephemeral_task); |
6983 | ephemeral_task = NULL; | 6564 | ephemeral_task = NULL; |
6984 | } | 6565 | } |
6985 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, | 6566 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, &free_neighbour_cb, NULL); |
6986 | &free_neighbour_cb, | 6567 | if (NULL != peerstore) { |
6987 | NULL); | 6568 | GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO); |
6988 | if (NULL != peerstore) | ||
6989 | { | ||
6990 | GNUNET_PEERSTORE_disconnect (peerstore, | ||
6991 | GNUNET_NO); | ||
6992 | peerstore = NULL; | 6569 | peerstore = NULL; |
6993 | } | 6570 | } |
6994 | if (NULL != GST_stats) | 6571 | if (NULL != GST_stats) { |
6995 | { | 6572 | GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); |
6996 | GNUNET_STATISTICS_destroy (GST_stats, | ||
6997 | GNUNET_NO); | ||
6998 | GST_stats = NULL; | 6573 | GST_stats = NULL; |
6999 | } | 6574 | } |
7000 | if (NULL != GST_my_private_key) | 6575 | if (NULL != GST_my_private_key) { |
7001 | { | ||
7002 | GNUNET_free (GST_my_private_key); | 6576 | GNUNET_free (GST_my_private_key); |
7003 | GST_my_private_key = NULL; | 6577 | GST_my_private_key = NULL; |
7004 | } | 6578 | } |
@@ -7009,20 +6583,15 @@ do_shutdown (void *cls) | |||
7009 | NULL); | 6583 | NULL); |
7010 | GNUNET_CONTAINER_multipeermap_destroy (validation_map); | 6584 | GNUNET_CONTAINER_multipeermap_destroy (validation_map); |
7011 | validation_map = NULL; | 6585 | validation_map = NULL; |
7012 | while (NULL != (lle = lle_head)) | 6586 | while (NULL != (lle = lle_head)) { |
7013 | { | 6587 | GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); |
7014 | GNUNET_CONTAINER_DLL_remove (lle_head, | ||
7015 | lle_tail, | ||
7016 | lle); | ||
7017 | GNUNET_free (lle); | 6588 | GNUNET_free (lle); |
7018 | } | 6589 | } |
7019 | GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map); | 6590 | GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map); |
7020 | dvlearn_map = NULL; | 6591 | dvlearn_map = NULL; |
7021 | GNUNET_CONTAINER_heap_destroy (validation_heap); | 6592 | GNUNET_CONTAINER_heap_destroy (validation_heap); |
7022 | validation_heap = NULL; | 6593 | validation_heap = NULL; |
7023 | GNUNET_CONTAINER_multipeermap_iterate (dv_routes, | 6594 | GNUNET_CONTAINER_multipeermap_iterate (dv_routes, &free_dv_routes_cb, NULL); |
7024 | &free_dv_routes_cb, | ||
7025 | NULL); | ||
7026 | GNUNET_CONTAINER_multipeermap_destroy (dv_routes); | 6595 | GNUNET_CONTAINER_multipeermap_destroy (dv_routes); |
7027 | dv_routes = NULL; | 6596 | dv_routes = NULL; |
7028 | GNUNET_CONTAINER_multipeermap_iterate (ephemeral_map, | 6597 | GNUNET_CONTAINER_multipeermap_iterate (ephemeral_map, |
@@ -7047,42 +6616,39 @@ run (void *cls, | |||
7047 | const struct GNUNET_CONFIGURATION_Handle *c, | 6616 | const struct GNUNET_CONFIGURATION_Handle *c, |
7048 | struct GNUNET_SERVICE_Handle *service) | 6617 | struct GNUNET_SERVICE_Handle *service) |
7049 | { | 6618 | { |
7050 | (void) cls; | 6619 | (void)cls; |
7051 | (void) service; | 6620 | (void)service; |
7052 | /* setup globals */ | 6621 | /* setup globals */ |
7053 | GST_cfg = c; | 6622 | GST_cfg = c; |
7054 | neighbours = GNUNET_CONTAINER_multipeermap_create (1024, | 6623 | neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); |
7055 | GNUNET_YES); | 6624 | dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); |
7056 | dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, | 6625 | ephemeral_map = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); |
7057 | GNUNET_YES); | 6626 | ephemeral_heap |
7058 | ephemeral_map = GNUNET_CONTAINER_multipeermap_create (32, | 6627 | = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
7059 | GNUNET_YES); | ||
7060 | ephemeral_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | ||
7061 | dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING, | 6628 | dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING, |
7062 | GNUNET_YES); | 6629 | GNUNET_YES); |
7063 | validation_map = GNUNET_CONTAINER_multipeermap_create (1024, | 6630 | validation_map = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); |
7064 | GNUNET_YES); | 6631 | validation_heap |
7065 | validation_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 6632 | = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
7066 | GST_my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); | 6633 | GST_my_private_key |
7067 | if (NULL == GST_my_private_key) | 6634 | = GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); |
7068 | { | 6635 | if (NULL == GST_my_private_key) { |
7069 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 6636 | GNUNET_log ( |
7070 | _("Transport service is lacking key configuration settings. Exiting.\n")); | 6637 | GNUNET_ERROR_TYPE_ERROR, |
6638 | _ ( | ||
6639 | "Transport service is lacking key configuration settings. Exiting.\n")); | ||
7071 | GNUNET_SCHEDULER_shutdown (); | 6640 | GNUNET_SCHEDULER_shutdown (); |
7072 | return; | 6641 | return; |
7073 | } | 6642 | } |
7074 | GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, | 6643 | GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, |
7075 | &GST_my_identity.public_key); | 6644 | &GST_my_identity.public_key); |
7076 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 6645 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
7077 | "My identity is `%s'\n", | 6646 | "My identity is `%s'\n", |
7078 | GNUNET_i2s_full (&GST_my_identity)); | 6647 | GNUNET_i2s_full (&GST_my_identity)); |
7079 | GST_stats = GNUNET_STATISTICS_create ("transport", | 6648 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); |
7080 | GST_cfg); | 6649 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
7081 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
7082 | NULL); | ||
7083 | peerstore = GNUNET_PEERSTORE_connect (GST_cfg); | 6650 | peerstore = GNUNET_PEERSTORE_connect (GST_cfg); |
7084 | if (NULL == peerstore) | 6651 | if (NULL == peerstore) { |
7085 | { | ||
7086 | GNUNET_break (0); | 6652 | GNUNET_break (0); |
7087 | GNUNET_SCHEDULER_shutdown (); | 6653 | GNUNET_SCHEDULER_shutdown (); |
7088 | return; | 6654 | return; |
@@ -7093,86 +6659,86 @@ run (void *cls, | |||
7093 | /** | 6659 | /** |
7094 | * Define "main" method using service macro. | 6660 | * Define "main" method using service macro. |
7095 | */ | 6661 | */ |
7096 | GNUNET_SERVICE_MAIN | 6662 | GNUNET_SERVICE_MAIN ( |
7097 | ("transport", | 6663 | "transport", |
7098 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, | 6664 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, |
7099 | &run, | 6665 | &run, |
7100 | &client_connect_cb, | 6666 | &client_connect_cb, |
7101 | &client_disconnect_cb, | 6667 | &client_disconnect_cb, |
7102 | NULL, | 6668 | NULL, |
7103 | /* communication with applications */ | 6669 | /* communication with applications */ |
7104 | GNUNET_MQ_hd_fixed_size (suggest, | 6670 | GNUNET_MQ_hd_fixed_size (suggest, |
7105 | GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, | 6671 | GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, |
7106 | struct ExpressPreferenceMessage, | 6672 | struct ExpressPreferenceMessage, |
7107 | NULL), | 6673 | NULL), |
7108 | GNUNET_MQ_hd_fixed_size (suggest_cancel, | 6674 | GNUNET_MQ_hd_fixed_size (suggest_cancel, |
7109 | GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, | 6675 | GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, |
7110 | struct ExpressPreferenceMessage, | 6676 | struct ExpressPreferenceMessage, |
7111 | NULL), | 6677 | NULL), |
7112 | GNUNET_MQ_hd_var_size (request_hello_validation, | 6678 | GNUNET_MQ_hd_var_size (request_hello_validation, |
7113 | GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, | 6679 | GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, |
7114 | struct RequestHelloValidationMessage, | 6680 | struct RequestHelloValidationMessage, |
7115 | NULL), | 6681 | NULL), |
7116 | /* communication with core */ | 6682 | /* communication with core */ |
7117 | GNUNET_MQ_hd_fixed_size (client_start, | 6683 | GNUNET_MQ_hd_fixed_size (client_start, |
7118 | GNUNET_MESSAGE_TYPE_TRANSPORT_START, | 6684 | GNUNET_MESSAGE_TYPE_TRANSPORT_START, |
7119 | struct StartMessage, | 6685 | struct StartMessage, |
7120 | NULL), | 6686 | NULL), |
7121 | GNUNET_MQ_hd_var_size (client_send, | 6687 | GNUNET_MQ_hd_var_size (client_send, |
7122 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, | 6688 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, |
7123 | struct OutboundMessage, | 6689 | struct OutboundMessage, |
7124 | NULL), | 6690 | NULL), |
7125 | /* communication with communicators */ | 6691 | /* communication with communicators */ |
7126 | GNUNET_MQ_hd_var_size (communicator_available, | 6692 | GNUNET_MQ_hd_var_size (communicator_available, |
7127 | GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, | 6693 | GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, |
7128 | struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, | 6694 | struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, |
7129 | NULL), | 6695 | NULL), |
7130 | GNUNET_MQ_hd_var_size (communicator_backchannel, | 6696 | GNUNET_MQ_hd_var_size (communicator_backchannel, |
7131 | GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, | 6697 | GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, |
7132 | struct GNUNET_TRANSPORT_CommunicatorBackchannel, | 6698 | struct GNUNET_TRANSPORT_CommunicatorBackchannel, |
7133 | NULL), | 6699 | NULL), |
7134 | GNUNET_MQ_hd_var_size (add_address, | 6700 | GNUNET_MQ_hd_var_size (add_address, |
7135 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, | 6701 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, |
7136 | struct GNUNET_TRANSPORT_AddAddressMessage, | 6702 | struct GNUNET_TRANSPORT_AddAddressMessage, |
7137 | NULL), | 6703 | NULL), |
7138 | GNUNET_MQ_hd_fixed_size (del_address, | 6704 | GNUNET_MQ_hd_fixed_size (del_address, |
7139 | GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, | 6705 | GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, |
7140 | struct GNUNET_TRANSPORT_DelAddressMessage, | 6706 | struct GNUNET_TRANSPORT_DelAddressMessage, |
7141 | NULL), | 6707 | NULL), |
7142 | GNUNET_MQ_hd_var_size (incoming_msg, | 6708 | GNUNET_MQ_hd_var_size (incoming_msg, |
7143 | GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, | 6709 | GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, |
7144 | struct GNUNET_TRANSPORT_IncomingMessage, | 6710 | struct GNUNET_TRANSPORT_IncomingMessage, |
7145 | NULL), | 6711 | NULL), |
7146 | GNUNET_MQ_hd_fixed_size (queue_create_ok, | 6712 | GNUNET_MQ_hd_fixed_size (queue_create_ok, |
7147 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, | 6713 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, |
7148 | struct GNUNET_TRANSPORT_CreateQueueResponse, | 6714 | struct GNUNET_TRANSPORT_CreateQueueResponse, |
7149 | NULL), | 6715 | NULL), |
7150 | GNUNET_MQ_hd_fixed_size (queue_create_fail, | 6716 | GNUNET_MQ_hd_fixed_size (queue_create_fail, |
7151 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, | 6717 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, |
7152 | struct GNUNET_TRANSPORT_CreateQueueResponse, | 6718 | struct GNUNET_TRANSPORT_CreateQueueResponse, |
7153 | NULL), | 6719 | NULL), |
7154 | GNUNET_MQ_hd_var_size (add_queue_message, | 6720 | GNUNET_MQ_hd_var_size (add_queue_message, |
7155 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, | 6721 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, |
7156 | struct GNUNET_TRANSPORT_AddQueueMessage, | 6722 | struct GNUNET_TRANSPORT_AddQueueMessage, |
7157 | NULL), | 6723 | NULL), |
7158 | GNUNET_MQ_hd_var_size (address_consider_verify, | 6724 | GNUNET_MQ_hd_var_size (address_consider_verify, |
7159 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY, | 6725 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY, |
7160 | struct GNUNET_TRANSPORT_AddressToVerify, | 6726 | struct GNUNET_TRANSPORT_AddressToVerify, |
7161 | NULL), | 6727 | NULL), |
7162 | GNUNET_MQ_hd_fixed_size (del_queue_message, | 6728 | GNUNET_MQ_hd_fixed_size (del_queue_message, |
7163 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, | 6729 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, |
7164 | struct GNUNET_TRANSPORT_DelQueueMessage, | 6730 | struct GNUNET_TRANSPORT_DelQueueMessage, |
7165 | NULL), | 6731 | NULL), |
7166 | GNUNET_MQ_hd_fixed_size (send_message_ack, | 6732 | GNUNET_MQ_hd_fixed_size (send_message_ack, |
7167 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, | 6733 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, |
7168 | struct GNUNET_TRANSPORT_SendMessageToAck, | 6734 | struct GNUNET_TRANSPORT_SendMessageToAck, |
7169 | NULL), | 6735 | NULL), |
7170 | /* communication with monitors */ | 6736 | /* communication with monitors */ |
7171 | GNUNET_MQ_hd_fixed_size (monitor_start, | 6737 | GNUNET_MQ_hd_fixed_size (monitor_start, |
7172 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, | 6738 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, |
7173 | struct GNUNET_TRANSPORT_MonitorStart, | 6739 | struct GNUNET_TRANSPORT_MonitorStart, |
7174 | NULL), | 6740 | NULL), |
7175 | GNUNET_MQ_handler_end ()); | 6741 | GNUNET_MQ_handler_end ()); |
7176 | 6742 | ||
7177 | 6743 | ||
7178 | /* end of file gnunet-service-transport.c */ | 6744 | /* end of file gnunet-service-transport.c */ |