aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-04-18 17:49:27 +0200
committerChristian Grothoff <christian@grothoff.org>2019-04-18 18:44:13 +0200
commit03da5328a30f9e4367e3f5912d02a8472bfaa766 (patch)
tree74ff1965913e865902039cb093efbbf8dfa7ffc5 /src
parent6ea190f42924f74736fe21ec5bd38df105e39562 (diff)
downloadgnunet-03da5328a30f9e4367e3f5912d02a8472bfaa766.tar.gz
gnunet-03da5328a30f9e4367e3f5912d02a8472bfaa766.zip
apply clang format to gnunet-service-tng.c
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-service-tng.c2118
1 files changed, 907 insertions, 1211 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 27c97860e..ccce8bbbc 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -156,47 +156,55 @@
156 * of seconds we log a warning. Note: this is for testing, 156 * of seconds we log a warning. Note: this is for testing,
157 * the value chosen here might be too aggressively low! 157 * the value chosen here might be too aggressively low!
158 */ 158 */
159#define DELAY_WARN_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 159#define DELAY_WARN_THRESHOLD \
160 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
160 161
161/** 162/**
162 * We only consider queues as "quality" connections when 163 * We only consider queues as "quality" connections when
163 * suppressing the generation of DV initiation messages if 164 * suppressing the generation of DV initiation messages if
164 * the latency of the queue is below this threshold. 165 * the latency of the queue is below this threshold.
165 */ 166 */
166#define DV_QUALITY_RTT_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 167#define DV_QUALITY_RTT_THRESHOLD \
168 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
167 169
168/** 170/**
169 * How long do we consider a DV path valid if we see no 171 * How long do we consider a DV path valid if we see no
170 * further updates on it? Note: the value chosen here might be too low! 172 * further updates on it? Note: the value chosen here might be too low!
171 */ 173 */
172#define DV_PATH_VALIDITY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 174#define DV_PATH_VALIDITY_TIMEOUT \
175 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
173 176
174/** 177/**
175 * How long before paths expire would we like to (re)discover DV paths? Should 178 * How long before paths expire would we like to (re)discover DV paths? Should
176 * be below #DV_PATH_VALIDITY_TIMEOUT. 179 * be below #DV_PATH_VALIDITY_TIMEOUT.
177 */ 180 */
178#define DV_PATH_DISCOVERY_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) 181#define DV_PATH_DISCOVERY_FREQUENCY \
182 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4)
179 183
180/** 184/**
181 * How long are ephemeral keys valid? 185 * How long are ephemeral keys valid?
182 */ 186 */
183#define EPHEMERAL_VALIDITY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) 187#define EPHEMERAL_VALIDITY \
188 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
184 189
185/** 190/**
186 * How long do we keep partially reassembled messages around before giving up? 191 * How long do we keep partially reassembled messages around before giving up?
187 */ 192 */
188#define REASSEMBLY_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4) 193#define REASSEMBLY_EXPIRATION \
194 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4)
189 195
190/** 196/**
191 * What is the fastest rate at which we send challenges *if* we keep learning 197 * What is the fastest rate at which we send challenges *if* we keep learning
192 * an address (gossip, DHT, etc.)? 198 * an address (gossip, DHT, etc.)?
193 */ 199 */
194#define FAST_VALIDATION_CHALLENGE_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) 200#define FAST_VALIDATION_CHALLENGE_FREQ \
201 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
195 202
196/** 203/**
197 * What is the slowest rate at which we send challenges? 204 * What is the slowest rate at which we send challenges?
198 */ 205 */
199#define MAX_VALIDATION_CHALLENGE_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1) 206#define MAX_VALIDATION_CHALLENGE_FREQ \
207 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1)
200 208
201/** 209/**
202 * What is the non-randomized base frequency at which we 210 * What is the non-randomized base frequency at which we
@@ -213,11 +221,13 @@
213/** 221/**
214 * When do we forget an invalid address for sure? 222 * When do we forget an invalid address for sure?
215 */ 223 */
216#define MAX_ADDRESS_VALID_UNTIL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1) 224#define MAX_ADDRESS_VALID_UNTIL \
225 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1)
217/** 226/**
218 * How long do we consider an address valid if we just checked? 227 * How long do we consider an address valid if we just checked?
219 */ 228 */
220#define ADDRESS_VALIDATION_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) 229#define ADDRESS_VALIDATION_LIFETIME \
230 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
221 231
222/** 232/**
223 * What is the maximum frequency at which we do address validation? 233 * What is the maximum frequency at which we do address validation?
@@ -337,7 +347,6 @@ struct EphemeralConfirmation
337 * to encrypt the payload. 347 * to encrypt the payload.
338 */ 348 */
339 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; 349 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
340
341}; 350};
342 351
343 352
@@ -392,7 +401,6 @@ struct TransportBackchannelRequestPayload
392 401
393 /* Followed by a 0-termianted string specifying the name of 402 /* Followed by a 0-termianted string specifying the name of
394 the communicator which is to receive the message */ 403 the communicator which is to receive the message */
395
396}; 404};
397 405
398 406
@@ -491,7 +499,6 @@ struct TransportFragmentBox
491 * Total size of the message that is being fragmented. 499 * Total size of the message that is being fragmented.
492 */ 500 */
493 uint16_t msg_size GNUNET_PACKED; 501 uint16_t msg_size GNUNET_PACKED;
494
495}; 502};
496 503
497 504
@@ -585,7 +592,6 @@ struct DvInitPS
585 * Challenge value used by the initiator to re-identify the path. 592 * Challenge value used by the initiator to re-identify the path.
586 */ 593 */
587 struct GNUNET_ShortHashCode challenge; 594 struct GNUNET_ShortHashCode challenge;
588
589}; 595};
590 596
591 597
@@ -626,7 +632,6 @@ struct DvHopPS
626 * Challenge value used by the initiator to re-identify the path. 632 * Challenge value used by the initiator to re-identify the path.
627 */ 633 */
628 struct GNUNET_ShortHashCode challenge; 634 struct GNUNET_ShortHashCode challenge;
629
630}; 635};
631 636
632 637
@@ -646,7 +651,6 @@ struct DVPathEntryP
646 * #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP 651 * #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP
647 */ 652 */
648 struct GNUNET_CRYPTO_EddsaSignature hop_sig; 653 struct GNUNET_CRYPTO_EddsaSignature hop_sig;
649
650}; 654};
651 655
652 656
@@ -712,7 +716,6 @@ struct TransportDVLearn
712 /* Followed by @e num_hops `struct DVPathEntryP` values, 716 /* Followed by @e num_hops `struct DVPathEntryP` values,
713 excluding the initiator of the DV trace; the last entry is the 717 excluding the initiator of the DV trace; the last entry is the
714 current sender; the current peer must not be included. */ 718 current sender; the current peer must not be included. */
715
716}; 719};
717 720
718 721
@@ -817,7 +820,6 @@ struct TransportValidationPS
817 * Challenge signed by the receiving peer. 820 * Challenge signed by the receiving peer.
818 */ 821 */
819 struct GNUNET_ShortHashCode challenge; 822 struct GNUNET_ShortHashCode challenge;
820
821}; 823};
822 824
823 825
@@ -863,7 +865,6 @@ struct TransportValidationResponse
863}; 865};
864 866
865 867
866
867GNUNET_NETWORK_STRUCT_END 868GNUNET_NETWORK_STRUCT_END
868 869
869 870
@@ -925,7 +926,6 @@ struct LearnLaunchEntry
925 * determine freshness of paths learned via this operation. 926 * determine freshness of paths learned via this operation.
926 */ 927 */
927 struct GNUNET_TIME_Absolute launch_time; 928 struct GNUNET_TIME_Absolute launch_time;
928
929}; 929};
930 930
931 931
@@ -1050,8 +1050,9 @@ struct DistanceVectorHop
1050 struct GNUNET_TIME_Absolute freshness; 1050 struct GNUNET_TIME_Absolute freshness;
1051 1051
1052 /** 1052 /**
1053 * How many hops in total to the `target` (excluding @e next_hop and `target` itself), 1053 * How many hops in total to the `target` (excluding @e next_hop and `target`
1054 * thus 0 still means a distance of 2 hops (to @e next_hop and then to `target`)? 1054 * itself), thus 0 still means a distance of 2 hops (to @e next_hop and then
1055 * to `target`)?
1055 */ 1056 */
1056 unsigned int distance; 1057 unsigned int distance;
1057}; 1058};
@@ -1353,7 +1354,8 @@ struct ReassemblyContext
1353 */ 1354 */
1354 uint16_t msg_missing; 1355 uint16_t msg_missing;
1355 1356
1356 /* Followed by @e msg_size bytes of the (partially) defragmented original message */ 1357 /* Followed by @e msg_size bytes of the (partially) defragmented original
1358 * message */
1357 1359
1358 /* Followed by @e bitfield data */ 1360 /* Followed by @e bitfield data */
1359}; 1361};
@@ -1480,7 +1482,6 @@ struct PeerRequest
1480 * How much bandwidth would this @e tc like to see? 1482 * How much bandwidth would this @e tc like to see?
1481 */ 1483 */
1482 struct GNUNET_BANDWIDTH_Value32NBO bw; 1484 struct GNUNET_BANDWIDTH_Value32NBO bw;
1483
1484}; 1485};
1485 1486
1486 1487
@@ -1567,17 +1568,20 @@ struct PendingMessage
1567 struct PendingMessage *prev_client; 1568 struct PendingMessage *prev_client;
1568 1569
1569 /** 1570 /**
1570 * Kept in a MDLL of messages from this @a cpm (if @e pmt is #PMT_FRAGMENT_BOx) 1571 * Kept in a MDLL of messages from this @a cpm (if @e pmt is
1572 * #PMT_FRAGMENT_BOx)
1571 */ 1573 */
1572 struct PendingMessage *next_frag; 1574 struct PendingMessage *next_frag;
1573 1575
1574 /** 1576 /**
1575 * Kept in a MDLL of messages from this @a cpm (if @e pmt is #PMT_FRAGMENT_BOX) 1577 * Kept in a MDLL of messages from this @a cpm (if @e pmt is
1578 * #PMT_FRAGMENT_BOX)
1576 */ 1579 */
1577 struct PendingMessage *prev_frag; 1580 struct PendingMessage *prev_frag;
1578 1581
1579 /** 1582 /**
1580 * This message, reliability boxed. Only possibly available if @e pmt is #PMT_CORE. 1583 * This message, reliability boxed. Only possibly available if @e pmt is
1584 * #PMT_CORE.
1581 */ 1585 */
1582 struct PendingMessage *bpm; 1586 struct PendingMessage *bpm;
1583 1587
@@ -1702,7 +1706,6 @@ struct AddressListEntry
1702 * Network type offered by this address. 1706 * Network type offered by this address.
1703 */ 1707 */
1704 enum GNUNET_NetworkType nt; 1708 enum GNUNET_NetworkType nt;
1705
1706}; 1709};
1707 1710
1708 1711
@@ -1743,7 +1746,8 @@ struct TransportClient
1743 /** 1746 /**
1744 * Information for @e type #CT_CORE. 1747 * Information for @e type #CT_CORE.
1745 */ 1748 */
1746 struct { 1749 struct
1750 {
1747 1751
1748 /** 1752 /**
1749 * Head of list of messages pending for this client, sorted by 1753 * Head of list of messages pending for this client, sorted by
@@ -1761,7 +1765,8 @@ struct TransportClient
1761 /** 1765 /**
1762 * Information for @e type #CT_MONITOR. 1766 * Information for @e type #CT_MONITOR.
1763 */ 1767 */
1764 struct { 1768 struct
1769 {
1765 1770
1766 /** 1771 /**
1767 * Peer identity to monitor the addresses of. 1772 * Peer identity to monitor the addresses of.
@@ -1781,7 +1786,8 @@ struct TransportClient
1781 /** 1786 /**
1782 * Information for @e type #CT_COMMUNICATOR. 1787 * Information for @e type #CT_COMMUNICATOR.
1783 */ 1788 */
1784 struct { 1789 struct
1790 {
1785 /** 1791 /**
1786 * If @e type is #CT_COMMUNICATOR, this communicator 1792 * If @e type is #CT_COMMUNICATOR, this communicator
1787 * supports communicating using these addresses. 1793 * supports communicating using these addresses.
@@ -1799,12 +1805,14 @@ struct TransportClient
1799 struct Queue *queue_tail; 1805 struct Queue *queue_tail;
1800 1806
1801 /** 1807 /**
1802 * Head of list of the addresses of this peer offered by this communicator. 1808 * Head of list of the addresses of this peer offered by this
1809 * communicator.
1803 */ 1810 */
1804 struct AddressListEntry *addr_head; 1811 struct AddressListEntry *addr_head;
1805 1812
1806 /** 1813 /**
1807 * Tail of list of the addresses of this peer offered by this communicator. 1814 * Tail of list of the addresses of this peer offered by this
1815 * communicator.
1808 */ 1816 */
1809 struct AddressListEntry *addr_tail; 1817 struct AddressListEntry *addr_tail;
1810 1818
@@ -1825,7 +1833,8 @@ struct TransportClient
1825 /** 1833 /**
1826 * Information for @e type #CT_APPLICATION 1834 * Information for @e type #CT_APPLICATION
1827 */ 1835 */
1828 struct { 1836 struct
1837 {
1829 1838
1830 /** 1839 /**
1831 * Map of requests for peers the given client application would like to 1840 * Map of requests for peers the given client application would like to
@@ -1836,7 +1845,6 @@ struct TransportClient
1836 } application; 1845 } application;
1837 1846
1838 } details; 1847 } details;
1839
1840}; 1848};
1841 1849
1842 1850
@@ -1940,7 +1948,6 @@ struct ValidationState
1940 * the respective queue to become available for transmission. 1948 * the respective queue to become available for transmission.
1941 */ 1949 */
1942 int awaiting_queue; 1950 int awaiting_queue;
1943
1944}; 1951};
1945 1952
1946 1953
@@ -2058,9 +2065,7 @@ static struct GNUNET_SCHEDULER_Task *validation_task;
2058static void 2065static void
2059free_ephemeral (struct EphemeralCacheEntry *ece) 2066free_ephemeral (struct EphemeralCacheEntry *ece)
2060{ 2067{
2061 GNUNET_CONTAINER_multipeermap_remove (ephemeral_map, 2068 GNUNET_CONTAINER_multipeermap_remove (ephemeral_map, &ece->target, ece);
2062 &ece->target,
2063 ece);
2064 GNUNET_CONTAINER_heap_remove_node (ece->hn); 2069 GNUNET_CONTAINER_heap_remove_node (ece->hn);
2065 GNUNET_free (ece); 2070 GNUNET_free (ece);
2066} 2071}
@@ -2074,9 +2079,7 @@ free_ephemeral (struct EphemeralCacheEntry *ece)
2074static void 2079static void
2075free_validation_state (struct ValidationState *vs) 2080free_validation_state (struct ValidationState *vs)
2076{ 2081{
2077 GNUNET_CONTAINER_multipeermap_remove (validation_map, 2082 GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs);
2078 &vs->pid,
2079 vs);
2080 GNUNET_CONTAINER_heap_remove_node (vs->hn); 2083 GNUNET_CONTAINER_heap_remove_node (vs->hn);
2081 vs->hn = NULL; 2084 vs->hn = NULL;
2082 if (NULL != vs->sc) 2085 if (NULL != vs->sc)
@@ -2098,8 +2101,7 @@ free_validation_state (struct ValidationState *vs)
2098static struct Neighbour * 2101static struct Neighbour *
2099lookup_neighbour (const struct GNUNET_PeerIdentity *pid) 2102lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
2100{ 2103{
2101 return GNUNET_CONTAINER_multipeermap_get (neighbours, 2104 return GNUNET_CONTAINER_multipeermap_get (neighbours, pid);
2102 pid);
2103} 2105}
2104 2106
2105 2107
@@ -2134,8 +2136,6 @@ struct MonitorEvent
2134 * Bytes pending. 2136 * Bytes pending.
2135 */ 2137 */
2136 uint32_t num_bytes_pending; 2138 uint32_t num_bytes_pending;
2137
2138
2139}; 2139};
2140 2140
2141 2141
@@ -2153,14 +2153,8 @@ free_distance_vector_hop (struct DistanceVectorHop *dvh)
2153 struct Neighbour *n = dvh->next_hop; 2153 struct Neighbour *n = dvh->next_hop;
2154 struct DistanceVector *dv = dvh->dv; 2154 struct DistanceVector *dv = dvh->dv;
2155 2155
2156 GNUNET_CONTAINER_MDLL_remove (neighbour, 2156 GNUNET_CONTAINER_MDLL_remove (neighbour, n->dv_head, n->dv_tail, dvh);
2157 n->dv_head, 2157 GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, dvh);
2158 n->dv_tail,
2159 dvh);
2160 GNUNET_CONTAINER_MDLL_remove (dv,
2161 dv->dv_head,
2162 dv->dv_tail,
2163 dvh);
2164 GNUNET_free (dvh); 2158 GNUNET_free (dvh);
2165} 2159}
2166 2160
@@ -2180,10 +2174,9 @@ free_dv_route (struct DistanceVector *dv)
2180 free_distance_vector_hop (dvh); 2174 free_distance_vector_hop (dvh);
2181 if (NULL == dv->dv_head) 2175 if (NULL == dv->dv_head)
2182 { 2176 {
2183 GNUNET_assert (GNUNET_YES == 2177 GNUNET_assert (
2184 GNUNET_CONTAINER_multipeermap_remove (dv_routes, 2178 GNUNET_YES ==
2185 &dv->target, 2179 GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv));
2186 dv));
2187 if (NULL != dv->timeout_task) 2180 if (NULL != dv->timeout_task)
2188 GNUNET_SCHEDULER_cancel (dv->timeout_task); 2181 GNUNET_SCHEDULER_cancel (dv->timeout_task);
2189 GNUNET_free (dv); 2182 GNUNET_free (dv);
@@ -2227,11 +2220,8 @@ notify_monitor (struct TransportClient *tc,
2227 md->cs = htonl ((uint32_t) me->cs); 2220 md->cs = htonl ((uint32_t) me->cs);
2228 md->num_msg_pending = htonl (me->num_msg_pending); 2221 md->num_msg_pending = htonl (me->num_msg_pending);
2229 md->num_bytes_pending = htonl (me->num_bytes_pending); 2222 md->num_bytes_pending = htonl (me->num_bytes_pending);
2230 memcpy (&md[1], 2223 memcpy (&md[1], address, addr_len);
2231 address, 2224 GNUNET_MQ_send (tc->mq, env);
2232 addr_len);
2233 GNUNET_MQ_send (tc->mq,
2234 env);
2235} 2225}
2236 2226
2237 2227
@@ -2250,23 +2240,16 @@ notify_monitors (const struct GNUNET_PeerIdentity *peer,
2250 enum GNUNET_NetworkType nt, 2240 enum GNUNET_NetworkType nt,
2251 const struct MonitorEvent *me) 2241 const struct MonitorEvent *me)
2252{ 2242{
2253 for (struct TransportClient *tc = clients_head; 2243 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
2254 NULL != tc;
2255 tc = tc->next)
2256 { 2244 {
2257 if (CT_MONITOR != tc->type) 2245 if (CT_MONITOR != tc->type)
2258 continue; 2246 continue;
2259 if (tc->details.monitor.one_shot) 2247 if (tc->details.monitor.one_shot)
2260 continue; 2248 continue;
2261 if ( (0 != GNUNET_is_zero (&tc->details.monitor.peer)) && 2249 if ((0 != GNUNET_is_zero (&tc->details.monitor.peer)) &&
2262 (0 != GNUNET_memcmp (&tc->details.monitor.peer, 2250 (0 != GNUNET_memcmp (&tc->details.monitor.peer, peer)))
2263 peer)) )
2264 continue; 2251 continue;
2265 notify_monitor (tc, 2252 notify_monitor (tc, peer, address, nt, me);
2266 peer,
2267 address,
2268 nt,
2269 me);
2270 } 2253 }
2271} 2254}
2272 2255
@@ -2291,12 +2274,8 @@ client_connect_cb (void *cls,
2291 tc = GNUNET_new (struct TransportClient); 2274 tc = GNUNET_new (struct TransportClient);
2292 tc->client = client; 2275 tc->client = client;
2293 tc->mq = mq; 2276 tc->mq = mq;
2294 GNUNET_CONTAINER_DLL_insert (clients_head, 2277 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
2295 clients_tail, 2278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
2296 tc);
2297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2298 "Client %p connected\n",
2299 tc);
2300 return tc; 2279 return tc;
2301} 2280}
2302 2281
@@ -2311,8 +2290,7 @@ free_reassembly_context (struct ReassemblyContext *rc)
2311{ 2290{
2312 struct Neighbour *n = rc->neighbour; 2291 struct Neighbour *n = rc->neighbour;
2313 2292
2314 GNUNET_assert (rc == 2293 GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn));
2315 GNUNET_CONTAINER_heap_remove_node (rc->hn));
2316 GNUNET_assert (GNUNET_OK == 2294 GNUNET_assert (GNUNET_OK ==
2317 GNUNET_CONTAINER_multishortmap_remove (n->reassembly_map, 2295 GNUNET_CONTAINER_multishortmap_remove (n->reassembly_map,
2318 &rc->msg_uuid, 2296 &rc->msg_uuid,
@@ -2335,15 +2313,17 @@ reassembly_cleanup_task (void *cls)
2335 n->reassembly_timeout_task = NULL; 2313 n->reassembly_timeout_task = NULL;
2336 while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap))) 2314 while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap)))
2337 { 2315 {
2338 if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout).rel_value_us) 2316 if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)
2317 .rel_value_us)
2339 { 2318 {
2340 free_reassembly_context (rc); 2319 free_reassembly_context (rc);
2341 continue; 2320 continue;
2342 } 2321 }
2343 GNUNET_assert (NULL == n->reassembly_timeout_task); 2322 GNUNET_assert (NULL == n->reassembly_timeout_task);
2344 n->reassembly_timeout_task = GNUNET_SCHEDULER_add_at (rc->reassembly_timeout, 2323 n->reassembly_timeout_task =
2345 &reassembly_cleanup_task, 2324 GNUNET_SCHEDULER_add_at (rc->reassembly_timeout,
2346 n); 2325 &reassembly_cleanup_task,
2326 n);
2347 return; 2327 return;
2348 } 2328 }
2349} 2329}
@@ -2363,9 +2343,9 @@ free_reassembly_cb (void *cls,
2363 void *value) 2343 void *value)
2364{ 2344{
2365 struct ReassemblyContext *rc = value; 2345 struct ReassemblyContext *rc = value;
2346
2366 (void) cls; 2347 (void) cls;
2367 (void) key; 2348 (void) key;
2368
2369 free_reassembly_context (rc); 2349 free_reassembly_context (rc);
2370 return GNUNET_OK; 2350 return GNUNET_OK;
2371} 2351}
@@ -2428,12 +2408,10 @@ core_send_connect_info (struct TransportClient *tc,
2428 struct ConnectInfoMessage *cim; 2408 struct ConnectInfoMessage *cim;
2429 2409
2430 GNUNET_assert (CT_CORE == tc->type); 2410 GNUNET_assert (CT_CORE == tc->type);
2431 env = GNUNET_MQ_msg (cim, 2411 env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
2432 GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
2433 cim->quota_out = quota_out; 2412 cim->quota_out = quota_out;
2434 cim->id = *pid; 2413 cim->id = *pid;
2435 GNUNET_MQ_send (tc->mq, 2414 GNUNET_MQ_send (tc->mq, env);
2436 env);
2437} 2415}
2438 2416
2439 2417
@@ -2447,15 +2425,11 @@ static void
2447cores_send_connect_info (const struct GNUNET_PeerIdentity *pid, 2425cores_send_connect_info (const struct GNUNET_PeerIdentity *pid,
2448 struct GNUNET_BANDWIDTH_Value32NBO quota_out) 2426 struct GNUNET_BANDWIDTH_Value32NBO quota_out)
2449{ 2427{
2450 for (struct TransportClient *tc = clients_head; 2428 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
2451 NULL != tc;
2452 tc = tc->next)
2453 { 2429 {
2454 if (CT_CORE != tc->type) 2430 if (CT_CORE != tc->type)
2455 continue; 2431 continue;
2456 core_send_connect_info (tc, 2432 core_send_connect_info (tc, pid, quota_out);
2457 pid,
2458 quota_out);
2459 } 2433 }
2460} 2434}
2461 2435
@@ -2468,20 +2442,16 @@ cores_send_connect_info (const struct GNUNET_PeerIdentity *pid,
2468static void 2442static void
2469cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid) 2443cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid)
2470{ 2444{
2471 for (struct TransportClient *tc = clients_head; 2445 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
2472 NULL != tc;
2473 tc = tc->next)
2474 { 2446 {
2475 struct GNUNET_MQ_Envelope *env; 2447 struct GNUNET_MQ_Envelope *env;
2476 struct DisconnectInfoMessage *dim; 2448 struct DisconnectInfoMessage *dim;
2477 2449
2478 if (CT_CORE != tc->type) 2450 if (CT_CORE != tc->type)
2479 continue; 2451 continue;
2480 env = GNUNET_MQ_msg (dim, 2452 env = GNUNET_MQ_msg (dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
2481 GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
2482 dim->peer = *pid; 2453 dim->peer = *pid;
2483 GNUNET_MQ_send (tc->mq, 2454 GNUNET_MQ_send (tc->mq, env);
2484 env);
2485 } 2455 }
2486} 2456}
2487 2457
@@ -2519,10 +2489,11 @@ schedule_transmit_on_queue (struct Queue *queue)
2519 if (queue->tc->details.communicator.total_queue_length >= 2489 if (queue->tc->details.communicator.total_queue_length >=
2520 COMMUNICATOR_TOTAL_QUEUE_LIMIT) 2490 COMMUNICATOR_TOTAL_QUEUE_LIMIT)
2521 { 2491 {
2522 GNUNET_STATISTICS_update (GST_stats, 2492 GNUNET_STATISTICS_update (
2523 "# Transmission throttled due to communicator queue limit", 2493 GST_stats,
2524 1, 2494 "# Transmission throttled due to communicator queue limit",
2525 GNUNET_NO); 2495 1,
2496 GNUNET_NO);
2526 return; 2497 return;
2527 } 2498 }
2528 if (queue->queue_length >= QUEUE_LENGTH_LIMIT) 2499 if (queue->queue_length >= QUEUE_LENGTH_LIMIT)
@@ -2534,32 +2505,27 @@ schedule_transmit_on_queue (struct Queue *queue)
2534 return; 2505 return;
2535 } 2506 }
2536 2507
2537 wsize = (0 == queue->mtu) 2508 wsize = (0 == queue->mtu) ? pm->bytes_msg /* FIXME: add overheads? */
2538 ? pm->bytes_msg /* FIXME: add overheads? */ 2509 : queue->mtu;
2539 : queue->mtu; 2510 out_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_out, wsize);
2540 out_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_out, 2511 out_delay = GNUNET_TIME_relative_max (GNUNET_TIME_absolute_get_remaining (
2541 wsize); 2512 pm->next_attempt),
2542 out_delay = GNUNET_TIME_relative_max (GNUNET_TIME_absolute_get_remaining (pm->next_attempt),
2543 out_delay); 2513 out_delay);
2544 if (0 == out_delay.rel_value_us) 2514 if (0 == out_delay.rel_value_us)
2545 return; /* we should run immediately! */ 2515 return; /* we should run immediately! */
2546 /* queue has changed since we were scheduled, reschedule again */ 2516 /* queue has changed since we were scheduled, reschedule again */
2547 queue->transmit_task 2517 queue->transmit_task =
2548 = GNUNET_SCHEDULER_add_delayed (out_delay, 2518 GNUNET_SCHEDULER_add_delayed (out_delay, &transmit_on_queue, queue);
2549 &transmit_on_queue,
2550 queue);
2551 if (out_delay.rel_value_us > DELAY_WARN_THRESHOLD.rel_value_us) 2519 if (out_delay.rel_value_us > DELAY_WARN_THRESHOLD.rel_value_us)
2552 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2520 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2553 "Next transmission on queue `%s' in %s (high delay)\n", 2521 "Next transmission on queue `%s' in %s (high delay)\n",
2554 queue->address, 2522 queue->address,
2555 GNUNET_STRINGS_relative_time_to_string (out_delay, 2523 GNUNET_STRINGS_relative_time_to_string (out_delay, GNUNET_YES));
2556 GNUNET_YES));
2557 else 2524 else
2558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2559 "Next transmission on queue `%s' in %s\n", 2526 "Next transmission on queue `%s' in %s\n",
2560 queue->address, 2527 queue->address,
2561 GNUNET_STRINGS_relative_time_to_string (out_delay, 2528 GNUNET_STRINGS_relative_time_to_string (out_delay, GNUNET_YES));
2562 GNUNET_YES));
2563} 2529}
2564 2530
2565 2531
@@ -2583,10 +2549,8 @@ free_queue (struct Queue *queue)
2583{ 2549{
2584 struct Neighbour *neighbour = queue->neighbour; 2550 struct Neighbour *neighbour = queue->neighbour;
2585 struct TransportClient *tc = queue->tc; 2551 struct TransportClient *tc = queue->tc;
2586 struct MonitorEvent me = { 2552 struct MonitorEvent me = {.cs = GNUNET_TRANSPORT_CS_DOWN,
2587 .cs = GNUNET_TRANSPORT_CS_DOWN, 2553 .rtt = GNUNET_TIME_UNIT_FOREVER_REL};
2588 .rtt = GNUNET_TIME_UNIT_FOREVER_REL
2589 };
2590 struct QueueEntry *qe; 2554 struct QueueEntry *qe;
2591 int maxxed; 2555 int maxxed;
2592 2556
@@ -2608,40 +2572,36 @@ free_queue (struct Queue *queue)
2608 tc->details.communicator.queue_head, 2572 tc->details.communicator.queue_head,
2609 tc->details.communicator.queue_tail, 2573 tc->details.communicator.queue_tail,
2610 queue); 2574 queue);
2611 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >= tc->details.communicator.total_queue_length); 2575 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >=
2576 tc->details.communicator.total_queue_length);
2612 while (NULL != (qe = queue->queue_head)) 2577 while (NULL != (qe = queue->queue_head))
2613 { 2578 {
2614 GNUNET_CONTAINER_DLL_remove (queue->queue_head, 2579 GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe);
2615 queue->queue_tail,
2616 qe);
2617 queue->queue_length--; 2580 queue->queue_length--;
2618 tc->details.communicator.total_queue_length--; 2581 tc->details.communicator.total_queue_length--;
2619 GNUNET_free (qe); 2582 GNUNET_free (qe);
2620 } 2583 }
2621 GNUNET_assert (0 == queue->queue_length); 2584 GNUNET_assert (0 == queue->queue_length);
2622 if ( (maxxed) && 2585 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT <
2623 (COMMUNICATOR_TOTAL_QUEUE_LIMIT < tc->details.communicator.total_queue_length) ) 2586 tc->details.communicator.total_queue_length))
2624 { 2587 {
2625 /* Communicator dropped below threshold, resume all queues */ 2588 /* Communicator dropped below threshold, resume all queues */
2626 GNUNET_STATISTICS_update (GST_stats, 2589 GNUNET_STATISTICS_update (
2627 "# Transmission throttled due to communicator queue limit", 2590 GST_stats,
2628 -1, 2591 "# Transmission throttled due to communicator queue limit",
2629 GNUNET_NO); 2592 -1,
2630 for (struct Queue *s = tc->details.communicator.queue_head; 2593 GNUNET_NO);
2631 NULL != s; 2594 for (struct Queue *s = tc->details.communicator.queue_head; NULL != s;
2632 s = s->next_client) 2595 s = s->next_client)
2633 schedule_transmit_on_queue (s); 2596 schedule_transmit_on_queue (s);
2634 } 2597 }
2635 notify_monitors (&neighbour->pid, 2598 notify_monitors (&neighbour->pid, queue->address, queue->nt, &me);
2636 queue->address,
2637 queue->nt,
2638 &me);
2639 GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_in); 2599 GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_in);
2640 GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_out); 2600 GNUNET_BANDWIDTH_tracker_notification_stop (&queue->tracker_out);
2641 GNUNET_free (queue); 2601 GNUNET_free (queue);
2642 2602
2643 update_neighbour_core_visibility (neighbour); 2603 update_neighbour_core_visibility (neighbour);
2644 cores_send_disconnect_info (&neighbour->pid); 2604 cores_send_disconnect_info (&neighbour->pid);
2645 2605
2646 if (NULL == neighbour->queue_head) 2606 if (NULL == neighbour->queue_head)
2647 { 2607 {
@@ -2694,10 +2654,11 @@ stop_peer_request (void *cls,
2694 struct PeerRequest *pr = value; 2654 struct PeerRequest *pr = value;
2695 2655
2696 GNUNET_PEERSTORE_watch_cancel (pr->wc); 2656 GNUNET_PEERSTORE_watch_cancel (pr->wc);
2697 GNUNET_assert (GNUNET_YES == 2657 GNUNET_assert (
2698 GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, 2658 GNUNET_YES ==
2699 pid, 2659 GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests,
2700 pr)); 2660 pid,
2661 pr));
2701 GNUNET_free (pr); 2662 GNUNET_free (pr);
2702 2663
2703 return GNUNET_OK; 2664 return GNUNET_OK;
@@ -2723,41 +2684,37 @@ client_disconnect_cb (void *cls,
2723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2724 "Client %p disconnected, cleaning up.\n", 2685 "Client %p disconnected, cleaning up.\n",
2725 tc); 2686 tc);
2726 GNUNET_CONTAINER_DLL_remove (clients_head, 2687 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
2727 clients_tail,
2728 tc);
2729 switch (tc->type) 2688 switch (tc->type)
2730 { 2689 {
2731 case CT_NONE: 2690 case CT_NONE:
2732 break; 2691 break;
2733 case CT_CORE: 2692 case CT_CORE: {
2734 { 2693 struct PendingMessage *pm;
2735 struct PendingMessage *pm;
2736 2694
2737 while (NULL != (pm = tc->details.core.pending_msg_head)) 2695 while (NULL != (pm = tc->details.core.pending_msg_head))
2738 {
2739 GNUNET_CONTAINER_MDLL_remove (client,
2740 tc->details.core.pending_msg_head,
2741 tc->details.core.pending_msg_tail,
2742 pm);
2743 pm->client = NULL;
2744 }
2745 }
2746 break;
2747 case CT_MONITOR:
2748 break;
2749 case CT_COMMUNICATOR:
2750 { 2696 {
2751 struct Queue *q; 2697 GNUNET_CONTAINER_MDLL_remove (client,
2752 struct AddressListEntry *ale; 2698 tc->details.core.pending_msg_head,
2753 2699 tc->details.core.pending_msg_tail,
2754 while (NULL != (q = tc->details.communicator.queue_head)) 2700 pm);
2755 free_queue (q); 2701 pm->client = NULL;
2756 while (NULL != (ale = tc->details.communicator.addr_head))
2757 free_address_list_entry (ale);
2758 GNUNET_free (tc->details.communicator.address_prefix);
2759 } 2702 }
2703 }
2704 break;
2705 case CT_MONITOR:
2760 break; 2706 break;
2707 case CT_COMMUNICATOR: {
2708 struct Queue *q;
2709 struct AddressListEntry *ale;
2710
2711 while (NULL != (q = tc->details.communicator.queue_head))
2712 free_queue (q);
2713 while (NULL != (ale = tc->details.communicator.addr_head))
2714 free_address_list_entry (ale);
2715 GNUNET_free (tc->details.communicator.address_prefix);
2716 }
2717 break;
2761 case CT_APPLICATION: 2718 case CT_APPLICATION:
2762 GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests, 2719 GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests,
2763 &stop_peer_request, 2720 &stop_peer_request,
@@ -2786,9 +2743,7 @@ notify_client_connect_info (void *cls,
2786 struct TransportClient *tc = cls; 2743 struct TransportClient *tc = cls;
2787 struct Neighbour *neighbour = value; 2744 struct Neighbour *neighbour = value;
2788 2745
2789 core_send_connect_info (tc, 2746 core_send_connect_info (tc, pid, neighbour->quota_out);
2790 pid,
2791 neighbour->quota_out);
2792 return GNUNET_OK; 2747 return GNUNET_OK;
2793} 2748}
2794 2749
@@ -2802,17 +2757,14 @@ notify_client_connect_info (void *cls,
2802 * @param start the start message that was sent 2757 * @param start the start message that was sent
2803 */ 2758 */
2804static void 2759static void
2805handle_client_start (void *cls, 2760handle_client_start (void *cls, const struct StartMessage *start)
2806 const struct StartMessage *start)
2807{ 2761{
2808 struct TransportClient *tc = cls; 2762 struct TransportClient *tc = cls;
2809 uint32_t options; 2763 uint32_t options;
2810 2764
2811 options = ntohl (start->options); 2765 options = ntohl (start->options);
2812 if ( (0 != (1 & options)) && 2766 if ((0 != (1 & options)) &&
2813 (0 != 2767 (0 != GNUNET_memcmp (&start->self, &GST_my_identity)))
2814 GNUNET_memcmp (&start->self,
2815 &GST_my_identity)) )
2816 { 2768 {
2817 /* client thinks this is a different peer, reject */ 2769 /* client thinks this is a different peer, reject */
2818 GNUNET_break (0); 2770 GNUNET_break (0);
@@ -2840,8 +2792,7 @@ handle_client_start (void *cls,
2840 * @param obm the send message that was sent 2792 * @param obm the send message that was sent
2841 */ 2793 */
2842static int 2794static int
2843check_client_send (void *cls, 2795check_client_send (void *cls, const struct OutboundMessage *obm)
2844 const struct OutboundMessage *obm)
2845{ 2796{
2846 struct TransportClient *tc = cls; 2797 struct TransportClient *tc = cls;
2847 uint16_t size; 2798 uint16_t size;
@@ -2881,10 +2832,7 @@ free_fragment_tree (struct PendingMessage *root)
2881 while (NULL != (frag = root->head_frag)) 2832 while (NULL != (frag = root->head_frag))
2882 { 2833 {
2883 free_fragment_tree (frag); 2834 free_fragment_tree (frag);
2884 GNUNET_CONTAINER_MDLL_remove (frag, 2835 GNUNET_CONTAINER_MDLL_remove (frag, root->head_frag, root->tail_frag, frag);
2885 root->head_frag,
2886 root->tail_frag,
2887 frag);
2888 GNUNET_free (frag); 2836 GNUNET_free (frag);
2889 } 2837 }
2890} 2838}
@@ -2944,14 +2892,12 @@ client_send_response (struct PendingMessage *pm,
2944 2892
2945 if (NULL != tc) 2893 if (NULL != tc)
2946 { 2894 {
2947 env = GNUNET_MQ_msg (som, 2895 env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
2948 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
2949 som->success = htonl ((uint32_t) success); 2896 som->success = htonl ((uint32_t) success);
2950 som->bytes_msg = htons (pm->bytes_msg); 2897 som->bytes_msg = htons (pm->bytes_msg);
2951 som->bytes_physical = htonl (bytes_physical); 2898 som->bytes_physical = htonl (bytes_physical);
2952 som->peer = target->pid; 2899 som->peer = target->pid;
2953 GNUNET_MQ_send (tc->mq, 2900 GNUNET_MQ_send (tc->mq, env);
2954 env);
2955 } 2901 }
2956 free_pending_message (pm); 2902 free_pending_message (pm);
2957} 2903}
@@ -2974,9 +2920,7 @@ check_queue_timeouts (void *cls)
2974 n->timeout_task = NULL; 2920 n->timeout_task = NULL;
2975 earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 2921 earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
2976 now = GNUNET_TIME_absolute_get (); 2922 now = GNUNET_TIME_absolute_get ();
2977 for (struct PendingMessage *pos = n->pending_msg_head; 2923 for (struct PendingMessage *pos = n->pending_msg_head; NULL != pos; pos = pm)
2978 NULL != pos;
2979 pos = pm)
2980 { 2924 {
2981 pm = pos->next_neighbour; 2925 pm = pos->next_neighbour;
2982 if (pos->timeout.abs_value_us <= now.abs_value_us) 2926 if (pos->timeout.abs_value_us <= now.abs_value_us)
@@ -2985,19 +2929,16 @@ check_queue_timeouts (void *cls)
2985 "# messages dropped (timeout before confirmation)", 2929 "# messages dropped (timeout before confirmation)",
2986 1, 2930 1,
2987 GNUNET_NO); 2931 GNUNET_NO);
2988 client_send_response (pm, 2932 client_send_response (pm, GNUNET_NO, 0);
2989 GNUNET_NO,
2990 0);
2991 continue; 2933 continue;
2992 } 2934 }
2993 earliest_timeout = GNUNET_TIME_absolute_min (earliest_timeout, 2935 earliest_timeout =
2994 pos->timeout); 2936 GNUNET_TIME_absolute_min (earliest_timeout, pos->timeout);
2995 } 2937 }
2996 n->earliest_timeout = earliest_timeout; 2938 n->earliest_timeout = earliest_timeout;
2997 if (NULL != n->pending_msg_head) 2939 if (NULL != n->pending_msg_head)
2998 n->timeout_task = GNUNET_SCHEDULER_add_at (earliest_timeout, 2940 n->timeout_task =
2999 &check_queue_timeouts, 2941 GNUNET_SCHEDULER_add_at (earliest_timeout, &check_queue_timeouts, n);
3000 n);
3001} 2942}
3002 2943
3003 2944
@@ -3008,8 +2949,7 @@ check_queue_timeouts (void *cls)
3008 * @param obm the send message that was sent 2949 * @param obm the send message that was sent
3009 */ 2950 */
3010static void 2951static void
3011handle_client_send (void *cls, 2952handle_client_send (void *cls, const struct OutboundMessage *obm)
3012 const struct OutboundMessage *obm)
3013{ 2953{
3014 struct TransportClient *tc = cls; 2954 struct TransportClient *tc = cls;
3015 struct PendingMessage *pm; 2955 struct PendingMessage *pm;
@@ -3031,14 +2971,12 @@ handle_client_send (void *cls,
3031 struct GNUNET_MQ_Envelope *env; 2971 struct GNUNET_MQ_Envelope *env;
3032 struct SendOkMessage *som; 2972 struct SendOkMessage *som;
3033 2973
3034 env = GNUNET_MQ_msg (som, 2974 env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
3035 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
3036 som->success = htonl (GNUNET_SYSERR); 2975 som->success = htonl (GNUNET_SYSERR);
3037 som->bytes_msg = htonl (bytes_msg); 2976 som->bytes_msg = htonl (bytes_msg);
3038 som->bytes_physical = htonl (0); 2977 som->bytes_physical = htonl (0);
3039 som->peer = obm->peer; 2978 som->peer = obm->peer;
3040 GNUNET_MQ_send (tc->mq, 2979 GNUNET_MQ_send (tc->mq, env);
3041 env);
3042 GNUNET_SERVICE_client_continue (tc->client); 2980 GNUNET_SERVICE_client_continue (tc->client);
3043 GNUNET_STATISTICS_update (GST_stats, 2981 GNUNET_STATISTICS_update (GST_stats,
3044 "# messages dropped (neighbour unknown)", 2982 "# messages dropped (neighbour unknown)",
@@ -3051,10 +2989,9 @@ handle_client_send (void *cls,
3051 pm->client = tc; 2989 pm->client = tc;
3052 pm->target = target; 2990 pm->target = target;
3053 pm->bytes_msg = bytes_msg; 2991 pm->bytes_msg = bytes_msg;
3054 pm->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (obm->timeout)); 2992 pm->timeout =
3055 memcpy (&pm[1], 2993 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (obm->timeout));
3056 &obm[1], 2994 memcpy (&pm[1], &obm[1], bytes_msg);
3057 bytes_msg);
3058 GNUNET_CONTAINER_MDLL_insert (neighbour, 2995 GNUNET_CONTAINER_MDLL_insert (neighbour,
3059 target->pending_msg_head, 2996 target->pending_msg_head,
3060 target->pending_msg_tail, 2997 target->pending_msg_tail,
@@ -3068,21 +3005,19 @@ handle_client_send (void *cls,
3068 target->earliest_timeout.abs_value_us = pm->timeout.abs_value_us; 3005 target->earliest_timeout.abs_value_us = pm->timeout.abs_value_us;
3069 if (NULL != target->timeout_task) 3006 if (NULL != target->timeout_task)
3070 GNUNET_SCHEDULER_cancel (target->timeout_task); 3007 GNUNET_SCHEDULER_cancel (target->timeout_task);
3071 target->timeout_task 3008 target->timeout_task = GNUNET_SCHEDULER_add_at (target->earliest_timeout,
3072 = GNUNET_SCHEDULER_add_at (target->earliest_timeout, 3009 &check_queue_timeouts,
3073 &check_queue_timeouts, 3010 target);
3074 target);
3075 } 3011 }
3076 if (! was_empty) 3012 if (! was_empty)
3077 return; /* all queues must already be busy */ 3013 return; /* all queues must already be busy */
3078 for (struct Queue *queue = target->queue_head; 3014 for (struct Queue *queue = target->queue_head; NULL != queue;
3079 NULL != queue;
3080 queue = queue->next_neighbour) 3015 queue = queue->next_neighbour)
3081 { 3016 {
3082 /* try transmission on any queue that is idle */ 3017 /* try transmission on any queue that is idle */
3083 if (NULL == queue->transmit_task) 3018 if (NULL == queue->transmit_task)
3084 queue->transmit_task = GNUNET_SCHEDULER_add_now (&transmit_on_queue, 3019 queue->transmit_task =
3085 queue); 3020 GNUNET_SCHEDULER_add_now (&transmit_on_queue, queue);
3086 } 3021 }
3087} 3022}
3088 3023
@@ -3094,8 +3029,9 @@ handle_client_send (void *cls,
3094 * @param cam the send message that was sent 3029 * @param cam the send message that was sent
3095 */ 3030 */
3096static int 3031static int
3097check_communicator_available (void *cls, 3032check_communicator_available (
3098 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) 3033 void *cls,
3034 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
3099{ 3035{
3100 struct TransportClient *tc = cls; 3036 struct TransportClient *tc = cls;
3101 uint16_t size; 3037 uint16_t size;
@@ -3121,8 +3057,9 @@ check_communicator_available (void *cls,
3121 * @param cam the send message that was sent 3057 * @param cam the send message that was sent
3122 */ 3058 */
3123static void 3059static void
3124handle_communicator_available (void *cls, 3060handle_communicator_available (
3125 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) 3061 void *cls,
3062 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
3126{ 3063{
3127 struct TransportClient *tc = cls; 3064 struct TransportClient *tc = cls;
3128 uint16_t size; 3065 uint16_t size;
@@ -3130,10 +3067,10 @@ handle_communicator_available (void *cls,
3130 size = ntohs (cam->header.size) - sizeof (*cam); 3067 size = ntohs (cam->header.size) - sizeof (*cam);
3131 if (0 == size) 3068 if (0 == size)
3132 return; /* receive-only communicator */ 3069 return; /* receive-only communicator */
3133 tc->details.communicator.address_prefix 3070 tc->details.communicator.address_prefix =
3134 = GNUNET_strdup ((const char *) &cam[1]); 3071 GNUNET_strdup ((const char *) &cam[1]);
3135 tc->details.communicator.cc 3072 tc->details.communicator.cc =
3136 = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc); 3073 (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc);
3137 GNUNET_SERVICE_client_continue (tc->client); 3074 GNUNET_SERVICE_client_continue (tc->client);
3138} 3075}
3139 3076
@@ -3146,8 +3083,9 @@ handle_communicator_available (void *cls,
3146 * @return #GNUNET_OK if message is well-formed 3083 * @return #GNUNET_OK if message is well-formed
3147 */ 3084 */
3148static int 3085static int
3149check_communicator_backchannel (void *cls, 3086check_communicator_backchannel (
3150 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 3087 void *cls,
3088 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
3151{ 3089{
3152 const struct GNUNET_MessageHeader *inbox; 3090 const struct GNUNET_MessageHeader *inbox;
3153 const char *is; 3091 const char *is;
@@ -3158,7 +3096,7 @@ check_communicator_backchannel (void *cls,
3158 msize = ntohs (cb->header.size) - sizeof (*cb); 3096 msize = ntohs (cb->header.size) - sizeof (*cb);
3159 if (UINT16_MAX - msize > 3097 if (UINT16_MAX - msize >
3160 sizeof (struct TransportBackchannelEncapsulationMessage) + 3098 sizeof (struct TransportBackchannelEncapsulationMessage) +
3161 sizeof (struct TransportBackchannelRequestPayload) ) 3099 sizeof (struct TransportBackchannelRequestPayload))
3162 { 3100 {
3163 GNUNET_break (0); 3101 GNUNET_break (0);
3164 return GNUNET_SYSERR; 3102 return GNUNET_SYSERR;
@@ -3174,7 +3112,7 @@ check_communicator_backchannel (void *cls,
3174 is += isize; 3112 is += isize;
3175 msize -= isize; 3113 msize -= isize;
3176 GNUNET_assert (msize > 0); 3114 GNUNET_assert (msize > 0);
3177 if ('\0' != is[msize-1]) 3115 if ('\0' != is[msize - 1])
3178 { 3116 {
3179 GNUNET_break (0); 3117 GNUNET_break (0);
3180 return GNUNET_SYSERR; 3118 return GNUNET_SYSERR;
@@ -3197,7 +3135,8 @@ expire_ephemerals (void *cls)
3197 ephemeral_task = NULL; 3135 ephemeral_task = NULL;
3198 while (NULL != (ece = GNUNET_CONTAINER_heap_peek (ephemeral_heap))) 3136 while (NULL != (ece = GNUNET_CONTAINER_heap_peek (ephemeral_heap)))
3199 { 3137 {
3200 if (0 == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity).rel_value_us) 3138 if (0 == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity)
3139 .rel_value_us)
3201 { 3140 {
3202 free_ephemeral (ece); 3141 free_ephemeral (ece);
3203 continue; 3142 continue;
@@ -3230,10 +3169,10 @@ lookup_ephemeral (const struct GNUNET_PeerIdentity *pid,
3230 struct EphemeralCacheEntry *ece; 3169 struct EphemeralCacheEntry *ece;
3231 struct EphemeralConfirmation ec; 3170 struct EphemeralConfirmation ec;
3232 3171
3233 ece = GNUNET_CONTAINER_multipeermap_get (ephemeral_map, 3172 ece = GNUNET_CONTAINER_multipeermap_get (ephemeral_map, pid);
3234 pid); 3173 if ((NULL != ece) &&
3235 if ( (NULL != ece) && 3174 (0 == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity)
3236 (0 == GNUNET_TIME_absolute_get_remaining (ece->ephemeral_validity).rel_value_us) ) 3175 .rel_value_us))
3237 { 3176 {
3238 free_ephemeral (ece); 3177 free_ephemeral (ece);
3239 ece = NULL; 3178 ece = NULL;
@@ -3242,28 +3181,29 @@ lookup_ephemeral (const struct GNUNET_PeerIdentity *pid,
3242 { 3181 {
3243 ece = GNUNET_new (struct EphemeralCacheEntry); 3182 ece = GNUNET_new (struct EphemeralCacheEntry);
3244 ece->target = *pid; 3183 ece->target = *pid;
3245 ece->ephemeral_validity = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get_monotonic (GST_cfg), 3184 ece->ephemeral_validity =
3246 EPHEMERAL_VALIDITY); 3185 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get_monotonic (GST_cfg),
3186 EPHEMERAL_VALIDITY);
3247 GNUNET_assert (GNUNET_OK == 3187 GNUNET_assert (GNUNET_OK ==
3248 GNUNET_CRYPTO_ecdhe_key_create2 (&ece->private_key)); 3188 GNUNET_CRYPTO_ecdhe_key_create2 (&ece->private_key));
3249 GNUNET_CRYPTO_ecdhe_key_get_public (&ece->private_key, 3189 GNUNET_CRYPTO_ecdhe_key_get_public (&ece->private_key, &ece->ephemeral_key);
3250 &ece->ephemeral_key);
3251 ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); 3190 ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
3252 ec.purpose.size = htonl (sizeof (ec)); 3191 ec.purpose.size = htonl (sizeof (ec));
3253 ec.target = *pid; 3192 ec.target = *pid;
3254 ec.ephemeral_key = ece->ephemeral_key; 3193 ec.ephemeral_key = ece->ephemeral_key;
3194 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
3195 &ec.purpose,
3196 &ece->sender_sig));
3197 ece->hn =
3198 GNUNET_CONTAINER_heap_insert (ephemeral_heap,
3199 ece,
3200 ece->ephemeral_validity.abs_value_us);
3255 GNUNET_assert (GNUNET_OK == 3201 GNUNET_assert (GNUNET_OK ==
3256 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 3202 GNUNET_CONTAINER_multipeermap_put (
3257 &ec.purpose, 3203 ephemeral_map,
3258 &ece->sender_sig)); 3204 &ece->target,
3259 ece->hn = GNUNET_CONTAINER_heap_insert (ephemeral_heap, 3205 ece,
3260 ece, 3206 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
3261 ece->ephemeral_validity.abs_value_us);
3262 GNUNET_assert (GNUNET_OK ==
3263 GNUNET_CONTAINER_multipeermap_put (ephemeral_map,
3264 &ece->target,
3265 ece,
3266 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
3267 if (NULL == ephemeral_task) 3207 if (NULL == ephemeral_task)
3268 ephemeral_task = GNUNET_SCHEDULER_add_at (ece->ephemeral_validity, 3208 ephemeral_task = GNUNET_SCHEDULER_add_at (ece->ephemeral_validity,
3269 &expire_ephemerals, 3209 &expire_ephemerals,
@@ -3301,9 +3241,7 @@ queue_send_msg (struct Queue *queue,
3301 smt->qid = queue->qid; 3241 smt->qid = queue->qid;
3302 smt->mid = queue->mid_gen; 3242 smt->mid = queue->mid_gen;
3303 smt->receiver = n->pid; 3243 smt->receiver = n->pid;
3304 memcpy (&smt[1], 3244 memcpy (&smt[1], payload, payload_size);
3305 payload,
3306 payload_size);
3307 { 3245 {
3308 /* Pass the env to the communicator of queue for transmission. */ 3246 /* Pass the env to the communicator of queue for transmission. */
3309 struct QueueEntry *qe; 3247 struct QueueEntry *qe;
@@ -3313,14 +3251,11 @@ queue_send_msg (struct Queue *queue,
3313 qe->queue = queue; 3251 qe->queue = queue;
3314 // qe->pm = pm; // FIXME: not so easy, reference management on 'free(s)'! 3252 // qe->pm = pm; // FIXME: not so easy, reference management on 'free(s)'!
3315 // (also, note that pm may be NULL!) 3253 // (also, note that pm may be NULL!)
3316 GNUNET_CONTAINER_DLL_insert (queue->queue_head, 3254 GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe);
3317 queue->queue_tail,
3318 qe);
3319 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); 3255 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type);
3320 queue->queue_length++; 3256 queue->queue_length++;
3321 queue->tc->details.communicator.total_queue_length++; 3257 queue->tc->details.communicator.total_queue_length++;
3322 GNUNET_MQ_send (queue->tc->mq, 3258 GNUNET_MQ_send (queue->tc->mq, env);
3323 env);
3324 } 3259 }
3325} 3260}
3326 3261
@@ -3329,7 +3264,8 @@ queue_send_msg (struct Queue *queue,
3329 * Which transmission options are allowable for transmission? 3264 * Which transmission options are allowable for transmission?
3330 * Interpreted bit-wise! 3265 * Interpreted bit-wise!
3331 */ 3266 */
3332enum RouteMessageOptions { 3267enum RouteMessageOptions
3268{
3333 /** 3269 /**
3334 * Only confirmed, non-DV direct neighbours. 3270 * Only confirmed, non-DV direct neighbours.
3335 */ 3271 */
@@ -3414,25 +3350,20 @@ route_message (const struct GNUNET_PeerIdentity *target,
3414 struct Neighbour *n; 3350 struct Neighbour *n;
3415 struct DistanceVector *dv; 3351 struct DistanceVector *dv;
3416 3352
3417 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 3353 n = GNUNET_CONTAINER_multipeermap_get (neighbours, target);
3418 target);
3419 dv = (0 != (options & RMO_DV_ALLOWED)) 3354 dv = (0 != (options & RMO_DV_ALLOWED))
3420 ? GNUNET_CONTAINER_multipeermap_get (dv_routes, 3355 ? GNUNET_CONTAINER_multipeermap_get (dv_routes, target)
3421 target) 3356 : NULL;
3422 : NULL;
3423 if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) 3357 if (0 == (options & RMO_UNCONFIRMED_ALLOWED))
3424 { 3358 {
3425 /* if confirmed is required, and we do not have anything 3359 /* if confirmed is required, and we do not have anything
3426 confirmed, drop respective options */ 3360 confirmed, drop respective options */
3427 if ( (NULL != n) && 3361 if ((NULL != n) && (GNUNET_NO == n->core_visible))
3428 (GNUNET_NO == n->core_visible) )
3429 n = NULL; 3362 n = NULL;
3430 if ( (NULL != dv) && 3363 if ((NULL != dv) && (GNUNET_NO == dv->core_visible))
3431 (GNUNET_NO == dv->core_visible) )
3432 dv = NULL; 3364 dv = NULL;
3433 } 3365 }
3434 if ( (NULL == n) && 3366 if ((NULL == n) && (NULL == dv))
3435 (NULL == dv) )
3436 { 3367 {
3437 GNUNET_STATISTICS_update (GST_stats, 3368 GNUNET_STATISTICS_update (GST_stats,
3438 "# Messages dropped in routing: no acceptable method", 3369 "# Messages dropped in routing: no acceptable method",
@@ -3443,30 +3374,23 @@ route_message (const struct GNUNET_PeerIdentity *target,
3443 } 3374 }
3444 /* If both dv and n are possible and we must choose: 3375 /* If both dv and n are possible and we must choose:
3445 flip a coin for the choice between the two; for now 50/50 */ 3376 flip a coin for the choice between the two; for now 50/50 */
3446 if ( (NULL != n) && 3377 if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT)))
3447 (NULL != dv) &&
3448 (0 == (options & RMO_REDUNDANT)) )
3449 { 3378 {
3450 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2)) 3379 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2))
3451 n = NULL; 3380 n = NULL;
3452 else 3381 else
3453 dv = NULL; 3382 dv = NULL;
3454 } 3383 }
3455 if ( (NULL != n) && 3384 if ((NULL != n) && (NULL != dv))
3456 (NULL != dv) )
3457 options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's 3385 options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's
3458 enough for redunancy, so clear the flag. */ 3386 enough for redunancy, so clear the flag. */
3459 if (NULL != n) 3387 if (NULL != n)
3460 { 3388 {
3461 route_via_neighbour (n, 3389 route_via_neighbour (n, hdr, options);
3462 hdr,
3463 options);
3464 } 3390 }
3465 if (NULL != dv) 3391 if (NULL != dv)
3466 { 3392 {
3467 route_via_dv (dv, 3393 route_via_dv (dv, hdr, options);
3468 hdr,
3469 options);
3470 } 3394 }
3471 GNUNET_free (hdr); 3395 GNUNET_free (hdr);
3472} 3396}
@@ -3485,7 +3409,8 @@ struct BackchannelKeyState
3485 /** 3409 /**
3486 * Actual key material. 3410 * Actual key material.
3487 */ 3411 */
3488 struct { 3412 struct
3413 {
3489 3414
3490 /** 3415 /**
3491 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()). 3416 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()).
@@ -3495,12 +3420,12 @@ struct BackchannelKeyState
3495 /** 3420 /**
3496 * Symmetric key to use for encryption. 3421 * Symmetric key to use for encryption.
3497 */ 3422 */
3498 char aes_key[256/8]; 3423 char aes_key[256 / 8];
3499 3424
3500 /** 3425 /**
3501 * Counter value to use during setup. 3426 * Counter value to use during setup.
3502 */ 3427 */
3503 char aes_ctr[128/8]; 3428 char aes_ctr[128 / 8];
3504 3429
3505 } material; 3430 } material;
3506}; 3431};
@@ -3544,20 +3469,18 @@ bc_setup_key_state_from_km (const struct GNUNET_HashCode *km,
3544 * @param key[out] set to the key material 3469 * @param key[out] set to the key material
3545 */ 3470 */
3546static void 3471static void
3547dh_key_derive_eph_pid (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, 3472dh_key_derive_eph_pid (
3548 const struct GNUNET_PeerIdentity *target, 3473 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral,
3549 const struct GNUNET_ShortHashCode *iv, 3474 const struct GNUNET_PeerIdentity *target,
3550 struct BackchannelKeyState *key) 3475 const struct GNUNET_ShortHashCode *iv,
3476 struct BackchannelKeyState *key)
3551{ 3477{
3552 struct GNUNET_HashCode km; 3478 struct GNUNET_HashCode km;
3553 3479
3554 GNUNET_assert (GNUNET_YES == 3480 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral,
3555 GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral, 3481 &target->public_key,
3556 &target->public_key, 3482 &km));
3557 &km)); 3483 bc_setup_key_state_from_km (&km, iv, key);
3558 bc_setup_key_state_from_km (&km,
3559 iv,
3560 key);
3561} 3484}
3562 3485
3563 3486
@@ -3577,13 +3500,10 @@ dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
3577{ 3500{
3578 struct GNUNET_HashCode km; 3501 struct GNUNET_HashCode km;
3579 3502
3580 GNUNET_assert (GNUNET_YES == 3503 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key,
3581 GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key, 3504 pub_ephemeral,
3582 pub_ephemeral, 3505 &km));
3583 &km)); 3506 bc_setup_key_state_from_km (&km, iv, key);
3584 bc_setup_key_state_from_km (&km,
3585 iv,
3586 key);
3587} 3507}
3588 3508
3589 3509
@@ -3602,10 +3522,7 @@ bc_hmac (const struct BackchannelKeyState *key,
3602 const void *data, 3522 const void *data,
3603 size_t data_size) 3523 size_t data_size)
3604{ 3524{
3605 GNUNET_CRYPTO_hmac (&key->material.hmac_key, 3525 GNUNET_CRYPTO_hmac (&key->material.hmac_key, data, data_size, hmac);
3606 data,
3607 data_size,
3608 hmac);
3609} 3526}
3610 3527
3611 3528
@@ -3625,11 +3542,7 @@ bc_encrypt (struct BackchannelKeyState *key,
3625 size_t in_size) 3542 size_t in_size)
3626{ 3543{
3627 GNUNET_assert (0 == 3544 GNUNET_assert (0 ==
3628 gcry_cipher_encrypt (key->cipher, 3545 gcry_cipher_encrypt (key->cipher, dst, in_size, in, in_size));
3629 dst,
3630 in_size,
3631 in,
3632 in_size));
3633} 3546}
3634 3547
3635 3548
@@ -3648,12 +3561,8 @@ bc_decrypt (struct BackchannelKeyState *key,
3648 const void *ciph, 3561 const void *ciph,
3649 size_t out_size) 3562 size_t out_size)
3650{ 3563{
3651 GNUNET_assert (0 == 3564 GNUNET_assert (
3652 gcry_cipher_decrypt (key->cipher, 3565 0 == gcry_cipher_decrypt (key->cipher, out, out_size, ciph, out_size));
3653 out,
3654 out_size,
3655 ciph,
3656 out_size));
3657} 3566}
3658 3567
3659 3568
@@ -3666,8 +3575,7 @@ static void
3666bc_key_clean (struct BackchannelKeyState *key) 3575bc_key_clean (struct BackchannelKeyState *key)
3667{ 3576{
3668 gcry_cipher_close (key->cipher); 3577 gcry_cipher_close (key->cipher);
3669 GNUNET_CRYPTO_zero_keys (&key->material, 3578 GNUNET_CRYPTO_zero_keys (&key->material, sizeof (key->material));
3670 sizeof (key->material));
3671} 3579}
3672 3580
3673 3581
@@ -3678,8 +3586,9 @@ bc_key_clean (struct BackchannelKeyState *key)
3678 * @param cb the send message that was sent 3586 * @param cb the send message that was sent
3679 */ 3587 */
3680static void 3588static void
3681handle_communicator_backchannel (void *cls, 3589handle_communicator_backchannel (
3682 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 3590 void *cls,
3591 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
3683{ 3592{
3684 struct TransportClient *tc = cls; 3593 struct TransportClient *tc = cls;
3685 struct GNUNET_CRYPTO_EcdhePrivateKey private_key; 3594 struct GNUNET_CRYPTO_EcdhePrivateKey private_key;
@@ -3691,9 +3600,11 @@ handle_communicator_backchannel (void *cls,
3691 uint16_t msize; 3600 uint16_t msize;
3692 3601
3693 /* encapsulate and encrypt message */ 3602 /* encapsulate and encrypt message */
3694 msize = ntohs (cb->header.size) - sizeof (*cb) + sizeof (struct TransportBackchannelRequestPayload); 3603 msize = ntohs (cb->header.size) - sizeof (*cb) +
3604 sizeof (struct TransportBackchannelRequestPayload);
3695 enc = GNUNET_malloc (sizeof (*enc) + msize); 3605 enc = GNUNET_malloc (sizeof (*enc) + msize);
3696 enc->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); 3606 enc->header.type =
3607 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION);
3697 enc->header.size = htons (sizeof (*enc) + msize); 3608 enc->header.size = htons (sizeof (*enc) + msize);
3698 enc->target = cb->pid; 3609 enc->target = cb->pid;
3699 lookup_ephemeral (&cb->pid, 3610 lookup_ephemeral (&cb->pid,
@@ -3704,17 +3615,12 @@ handle_communicator_backchannel (void *cls,
3704 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 3615 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
3705 &enc->iv, 3616 &enc->iv,
3706 sizeof (enc->iv)); 3617 sizeof (enc->iv));
3707 dh_key_derive_eph_pid (&private_key, 3618 dh_key_derive_eph_pid (&private_key, &cb->pid, &enc->iv, &key);
3708 &cb->pid,
3709 &enc->iv,
3710 &key);
3711 ppay.ephemeral_validity = GNUNET_TIME_absolute_hton (ephemeral_validity); 3619 ppay.ephemeral_validity = GNUNET_TIME_absolute_hton (ephemeral_validity);
3712 ppay.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg)); 3620 ppay.monotonic_time =
3621 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg));
3713 mpos = (char *) &enc[1]; 3622 mpos = (char *) &enc[1];
3714 bc_encrypt (&key, 3623 bc_encrypt (&key, &ppay, mpos, sizeof (ppay));
3715 &ppay,
3716 mpos,
3717 sizeof (ppay));
3718 bc_encrypt (&key, 3624 bc_encrypt (&key,
3719 &cb[1], 3625 &cb[1],
3720 &mpos[sizeof (ppay)], 3626 &mpos[sizeof (ppay)],
@@ -3724,9 +3630,7 @@ handle_communicator_backchannel (void *cls,
3724 mpos, 3630 mpos,
3725 sizeof (ppay) + ntohs (cb->header.size) - sizeof (*cb)); 3631 sizeof (ppay) + ntohs (cb->header.size) - sizeof (*cb));
3726 bc_key_clean (&key); 3632 bc_key_clean (&key);
3727 route_message (&cb->pid, 3633 route_message (&cb->pid, &enc->header, RMO_DV_ALLOWED);
3728 &enc->header,
3729 RMO_DV_ALLOWED);
3730 GNUNET_SERVICE_client_continue (tc->client); 3634 GNUNET_SERVICE_client_continue (tc->client);
3731} 3635}
3732 3636
@@ -3770,8 +3674,7 @@ store_pi (void *cls);
3770 * @param success #GNUNET_YES if peerstore was successful 3674 * @param success #GNUNET_YES if peerstore was successful
3771 */ 3675 */
3772static void 3676static void
3773peerstore_store_own_cb (void *cls, 3677peerstore_store_own_cb (void *cls, int success)
3774 int success)
3775{ 3678{
3776 struct AddressListEntry *ale = cls; 3679 struct AddressListEntry *ale = cls;
3777 3680
@@ -3782,10 +3685,11 @@ peerstore_store_own_cb (void *cls,
3782 ale->address); 3685 ale->address);
3783 /* refresh period is 1/4 of expiration time, that should be plenty 3686 /* refresh period is 1/4 of expiration time, that should be plenty
3784 without being excessive. */ 3687 without being excessive. */
3785 ale->st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration, 3688 ale->st =
3786 4ULL), 3689 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration,
3787 &store_pi, 3690 4ULL),
3788 ale); 3691 &store_pi,
3692 ale);
3789} 3693}
3790 3694
3791 3695
@@ -3826,9 +3730,8 @@ store_pi (void *cls)
3826 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3730 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3827 "Failed to store our address `%s' with peerstore\n", 3731 "Failed to store our address `%s' with peerstore\n",
3828 ale->address); 3732 ale->address);
3829 ale->st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 3733 ale->st =
3830 &store_pi, 3734 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &store_pi, ale);
3831 ale);
3832 } 3735 }
3833} 3736}
3834 3737
@@ -3854,14 +3757,11 @@ handle_add_address (void *cls,
3854 ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration); 3757 ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration);
3855 ale->aid = aam->aid; 3758 ale->aid = aam->aid;
3856 ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt); 3759 ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt);
3857 memcpy (&ale[1], 3760 memcpy (&ale[1], &aam[1], slen);
3858 &aam[1],
3859 slen);
3860 GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head, 3761 GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head,
3861 tc->details.communicator.addr_tail, 3762 tc->details.communicator.addr_tail,
3862 ale); 3763 ale);
3863 ale->st = GNUNET_SCHEDULER_add_now (&store_pi, 3764 ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale);
3864 ale);
3865 GNUNET_SERVICE_client_continue (tc->client); 3765 GNUNET_SERVICE_client_continue (tc->client);
3866} 3766}
3867 3767
@@ -3949,13 +3849,11 @@ finish_cmc_handling (struct CommunicatorMessageContext *cmc)
3949 struct GNUNET_MQ_Envelope *env; 3849 struct GNUNET_MQ_Envelope *env;
3950 struct GNUNET_TRANSPORT_IncomingMessageAck *ack; 3850 struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
3951 3851
3952 env = GNUNET_MQ_msg (ack, 3852 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
3953 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
3954 ack->reserved = htonl (0); 3853 ack->reserved = htonl (0);
3955 ack->fc_id = cmc->im.fc_id; 3854 ack->fc_id = cmc->im.fc_id;
3956 ack->sender = cmc->im.sender; 3855 ack->sender = cmc->im.sender;
3957 GNUNET_MQ_send (cmc->tc->mq, 3856 GNUNET_MQ_send (cmc->tc->mq, env);
3958 env);
3959 } 3857 }
3960 GNUNET_SERVICE_client_continue (cmc->tc->client); 3858 GNUNET_SERVICE_client_continue (cmc->tc->client);
3961 GNUNET_free (cmc); 3859 GNUNET_free (cmc);
@@ -3966,18 +3864,18 @@ finish_cmc_handling (struct CommunicatorMessageContext *cmc)
3966 * Communicator gave us an unencapsulated message to pass as-is to 3864 * Communicator gave us an unencapsulated message to pass as-is to
3967 * CORE. Process the request. 3865 * CORE. Process the request.
3968 * 3866 *
3969 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 3867 * @param cls a `struct CommunicatorMessageContext` (must call
3868 * #finish_cmc_handling() when done)
3970 * @param mh the message that was received 3869 * @param mh the message that was received
3971 */ 3870 */
3972static void 3871static void
3973handle_raw_message (void *cls, 3872handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
3974 const struct GNUNET_MessageHeader *mh)
3975{ 3873{
3976 struct CommunicatorMessageContext *cmc = cls; 3874 struct CommunicatorMessageContext *cmc = cls;
3977 uint16_t size = ntohs (mh->size); 3875 uint16_t size = ntohs (mh->size);
3978 3876
3979 if ( (size > UINT16_MAX - sizeof (struct InboundMessage)) || 3877 if ((size > UINT16_MAX - sizeof (struct InboundMessage)) ||
3980 (size < sizeof (struct GNUNET_MessageHeader)) ) 3878 (size < sizeof (struct GNUNET_MessageHeader)))
3981 { 3879 {
3982 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 3880 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
3983 3881
@@ -3987,24 +3885,17 @@ handle_raw_message (void *cls,
3987 return; 3885 return;
3988 } 3886 }
3989 /* Forward to all CORE clients */ 3887 /* Forward to all CORE clients */
3990 for (struct TransportClient *tc = clients_head; 3888 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3991 NULL != tc;
3992 tc = tc->next)
3993 { 3889 {
3994 struct GNUNET_MQ_Envelope *env; 3890 struct GNUNET_MQ_Envelope *env;
3995 struct InboundMessage *im; 3891 struct InboundMessage *im;
3996 3892
3997 if (CT_CORE != tc->type) 3893 if (CT_CORE != tc->type)
3998 continue; 3894 continue;
3999 env = GNUNET_MQ_msg_extra (im, 3895 env = GNUNET_MQ_msg_extra (im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
4000 size,
4001 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
4002 im->peer = cmc->im.sender; 3896 im->peer = cmc->im.sender;
4003 memcpy (&im[1], 3897 memcpy (&im[1], mh, size);
4004 mh, 3898 GNUNET_MQ_send (tc->mq, env);
4005 size);
4006 GNUNET_MQ_send (tc->mq,
4007 env);
4008 } 3899 }
4009 /* FIXME: consider doing this _only_ once the message 3900 /* FIXME: consider doing this _only_ once the message
4010 was drained from the CORE MQs to extend flow control to CORE! 3901 was drained from the CORE MQs to extend flow control to CORE!
@@ -4021,8 +3912,7 @@ handle_raw_message (void *cls,
4021 * @return #GNUNET_YES if message is well-formed 3912 * @return #GNUNET_YES if message is well-formed
4022 */ 3913 */
4023static int 3914static int
4024check_fragment_box (void *cls, 3915check_fragment_box (void *cls, const struct TransportFragmentBox *fb)
4025 const struct TransportFragmentBox *fb)
4026{ 3916{
4027 uint16_t size = ntohs (fb->header.size); 3917 uint16_t size = ntohs (fb->header.size);
4028 uint16_t bsize = size - sizeof (*fb); 3918 uint16_t bsize = size - sizeof (*fb);
@@ -4064,14 +3954,12 @@ send_fragment_ack (struct ReassemblyContext *rc)
4064 ack->msg_uuid = rc->msg_uuid; 3954 ack->msg_uuid = rc->msg_uuid;
4065 ack->avg_ack_delay = GNUNET_TIME_relative_hton (rc->avg_ack_delay); 3955 ack->avg_ack_delay = GNUNET_TIME_relative_hton (rc->avg_ack_delay);
4066 if (0 == rc->msg_missing) 3956 if (0 == rc->msg_missing)
4067 ack->reassembly_timeout 3957 ack->reassembly_timeout = GNUNET_TIME_relative_hton (
4068 = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL); /* signal completion */ 3958 GNUNET_TIME_UNIT_FOREVER_REL); /* signal completion */
4069 else 3959 else
4070 ack->reassembly_timeout 3960 ack->reassembly_timeout = GNUNET_TIME_relative_hton (
4071 = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)); 3961 GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout));
4072 route_message (&rc->neighbour->pid, 3962 route_message (&rc->neighbour->pid, &ack->header, RMO_DV_ALLOWED);
4073 &ack->header,
4074 RMO_DV_ALLOWED);
4075 rc->avg_ack_delay = GNUNET_TIME_UNIT_ZERO; 3963 rc->avg_ack_delay = GNUNET_TIME_UNIT_ZERO;
4076 rc->num_acks = 0; 3964 rc->num_acks = 0;
4077 rc->extra_acks = 0LLU; 3965 rc->extra_acks = 0LLU;
@@ -4081,12 +3969,12 @@ send_fragment_ack (struct ReassemblyContext *rc)
4081/** 3969/**
4082 * Communicator gave us a fragment. Process the request. 3970 * Communicator gave us a fragment. Process the request.
4083 * 3971 *
4084 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 3972 * @param cls a `struct CommunicatorMessageContext` (must call
3973 * #finish_cmc_handling() when done)
4085 * @param fb the message that was received 3974 * @param fb the message that was received
4086 */ 3975 */
4087static void 3976static void
4088handle_fragment_box (void *cls, 3977handle_fragment_box (void *cls, const struct TransportFragmentBox *fb)
4089 const struct TransportFragmentBox *fb)
4090{ 3978{
4091 struct CommunicatorMessageContext *cmc = cls; 3979 struct CommunicatorMessageContext *cmc = cls;
4092 struct Neighbour *n; 3980 struct Neighbour *n;
@@ -4100,8 +3988,7 @@ handle_fragment_box (void *cls,
4100 struct GNUNET_TIME_Relative cdelay; 3988 struct GNUNET_TIME_Relative cdelay;
4101 int ack_now; 3989 int ack_now;
4102 3990
4103 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 3991 n = GNUNET_CONTAINER_multipeermap_get (neighbours, &cmc->im.sender);
4104 &cmc->im.sender);
4105 if (NULL == n) 3992 if (NULL == n)
4106 { 3993 {
4107 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 3994 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
@@ -4113,34 +4000,35 @@ handle_fragment_box (void *cls,
4113 } 4000 }
4114 if (NULL == n->reassembly_map) 4001 if (NULL == n->reassembly_map)
4115 { 4002 {
4116 n->reassembly_map = GNUNET_CONTAINER_multishortmap_create (8, 4003 n->reassembly_map = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_YES);
4117 GNUNET_YES); 4004 n->reassembly_heap =
4118 n->reassembly_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 4005 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
4119 n->reassembly_timeout_task = GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION, 4006 n->reassembly_timeout_task =
4120 &reassembly_cleanup_task, 4007 GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION,
4121 n); 4008 &reassembly_cleanup_task,
4009 n);
4122 } 4010 }
4123 msize = ntohs (fb->msg_size); 4011 msize = ntohs (fb->msg_size);
4124 rc = GNUNET_CONTAINER_multishortmap_get (n->reassembly_map, 4012 rc = GNUNET_CONTAINER_multishortmap_get (n->reassembly_map, &fb->msg_uuid);
4125 &fb->msg_uuid);
4126 if (NULL == rc) 4013 if (NULL == rc)
4127 { 4014 {
4128 rc = GNUNET_malloc (sizeof (*rc) + 4015 rc = GNUNET_malloc (sizeof (*rc) + msize + /* reassembly payload buffer */
4129 msize + /* reassembly payload buffer */ 4016 (msize + 7) / 8 * sizeof (uint8_t) /* bitfield */);
4130 (msize + 7) / 8 * sizeof (uint8_t) /* bitfield */);
4131 rc->msg_uuid = fb->msg_uuid; 4017 rc->msg_uuid = fb->msg_uuid;
4132 rc->neighbour = n; 4018 rc->neighbour = n;
4133 rc->msg_size = msize; 4019 rc->msg_size = msize;
4134 rc->reassembly_timeout = GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION); 4020 rc->reassembly_timeout =
4021 GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION);
4135 rc->last_frag = GNUNET_TIME_absolute_get (); 4022 rc->last_frag = GNUNET_TIME_absolute_get ();
4136 rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap, 4023 rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap,
4137 rc, 4024 rc,
4138 rc->reassembly_timeout.abs_value_us); 4025 rc->reassembly_timeout.abs_value_us);
4139 GNUNET_assert (GNUNET_OK == 4026 GNUNET_assert (GNUNET_OK ==
4140 GNUNET_CONTAINER_multishortmap_put (n->reassembly_map, 4027 GNUNET_CONTAINER_multishortmap_put (
4141 &rc->msg_uuid, 4028 n->reassembly_map,
4142 rc, 4029 &rc->msg_uuid,
4143 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 4030 rc,
4031 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
4144 target = (char *) &rc[1]; 4032 target = (char *) &rc[1];
4145 rc->bitfield = (uint8_t *) (target + rc->msg_size); 4033 rc->bitfield = (uint8_t *) (target + rc->msg_size);
4146 rc->msg_missing = rc->msg_size; 4034 rc->msg_missing = rc->msg_size;
@@ -4159,11 +4047,9 @@ handle_fragment_box (void *cls,
4159 /* reassemble */ 4047 /* reassemble */
4160 fsize = ntohs (fb->header.size) - sizeof (*fb); 4048 fsize = ntohs (fb->header.size) - sizeof (*fb);
4161 frag_off = ntohs (fb->frag_off); 4049 frag_off = ntohs (fb->frag_off);
4162 memcpy (&target[frag_off], 4050 memcpy (&target[frag_off], &fb[1], fsize);
4163 &fb[1],
4164 fsize);
4165 /* update bitfield and msg_missing */ 4051 /* update bitfield and msg_missing */
4166 for (unsigned int i=frag_off;i<frag_off+fsize;i++) 4052 for (unsigned int i = frag_off; i < frag_off + fsize; i++)
4167 { 4053 {
4168 if (0 == (rc->bitfield[i / 8] & (1 << (i % 8)))) 4054 if (0 == (rc->bitfield[i / 8] & (1 << (i % 8))))
4169 { 4055 {
@@ -4175,11 +4061,9 @@ handle_fragment_box (void *cls,
4175 /* Compute cummulative ACK */ 4061 /* Compute cummulative ACK */
4176 frag_uuid = ntohl (fb->frag_uuid); 4062 frag_uuid = ntohl (fb->frag_uuid);
4177 cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag); 4063 cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag);
4178 cdelay = GNUNET_TIME_relative_multiply (cdelay, 4064 cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->num_acks);
4179 rc->num_acks);
4180 rc->last_frag = GNUNET_TIME_absolute_get (); 4065 rc->last_frag = GNUNET_TIME_absolute_get ();
4181 rc->avg_ack_delay = GNUNET_TIME_relative_add (rc->avg_ack_delay, 4066 rc->avg_ack_delay = GNUNET_TIME_relative_add (rc->avg_ack_delay, cdelay);
4182 cdelay);
4183 ack_now = GNUNET_NO; 4067 ack_now = GNUNET_NO;
4184 if (0 == rc->num_acks) 4068 if (0 == rc->num_acks)
4185 { 4069 {
@@ -4188,12 +4072,11 @@ handle_fragment_box (void *cls,
4188 rc->extra_acks = 0LLU; 4072 rc->extra_acks = 0LLU;
4189 rc->num_acks = 1; 4073 rc->num_acks = 1;
4190 } 4074 }
4191 else if ( (frag_uuid >= rc->frag_uuid) && 4075 else if ((frag_uuid >= rc->frag_uuid) && (frag_uuid <= rc->frag_uuid + 64))
4192 (frag_uuid <= rc->frag_uuid + 64) )
4193 { 4076 {
4194 /* case two: ack fits after existing min UUID */ 4077 /* case two: ack fits after existing min UUID */
4195 if ( (frag_uuid == rc->frag_uuid) || 4078 if ((frag_uuid == rc->frag_uuid) ||
4196 (0 != (rc->extra_acks & (1LLU << (frag_uuid - rc->frag_uuid - 1)))) ) 4079 (0 != (rc->extra_acks & (1LLU << (frag_uuid - rc->frag_uuid - 1)))))
4197 { 4080 {
4198 /* duplicate fragment, ack now! */ 4081 /* duplicate fragment, ack now! */
4199 ack_now = GNUNET_YES; 4082 ack_now = GNUNET_YES;
@@ -4204,11 +4087,12 @@ handle_fragment_box (void *cls,
4204 rc->num_acks++; 4087 rc->num_acks++;
4205 } 4088 }
4206 } 4089 }
4207 else if ( (rc->frag_uuid > frag_uuid) && 4090 else if ((rc->frag_uuid > frag_uuid) &&
4208 ( ( (rc->frag_uuid == frag_uuid + 64) && 4091 (((rc->frag_uuid == frag_uuid + 64) && (0 == rc->extra_acks)) ||
4209 (0 == rc->extra_acks) ) || 4092 ((rc->frag_uuid < frag_uuid + 64) &&
4210 ( (rc->frag_uuid < frag_uuid + 64) && 4093 (rc->extra_acks ==
4211 (rc->extra_acks == (rc->extra_acks & ~ ((1LLU << (64 - (rc->frag_uuid - frag_uuid))) - 1LLU))) ) ) ) 4094 (rc->extra_acks &
4095 ~((1LLU << (64 - (rc->frag_uuid - frag_uuid))) - 1LLU))))))
4212 { 4096 {
4213 /* can fit ack by shifting extra acks and starting at 4097 /* can fit ack by shifting extra acks and starting at
4214 frag_uid, test above esured that the bits we will 4098 frag_uid, test above esured that the bits we will
@@ -4218,7 +4102,8 @@ handle_fragment_box (void *cls,
4218 rc->frag_uuid = frag_uuid; 4102 rc->frag_uuid = frag_uuid;
4219 rc->num_acks++; 4103 rc->num_acks++;
4220 } 4104 }
4221 if (65 == rc->num_acks) /* FIXME: maybe use smaller threshold? This is very aggressive. */ 4105 if (65 == rc->num_acks) /* FIXME: maybe use smaller threshold? This is very
4106 aggressive. */
4222 ack_now = GNUNET_YES; /* maximum acks received */ 4107 ack_now = GNUNET_YES; /* maximum acks received */
4223 // FIXME: possibly also ACK based on RTT (but for that we'd need to 4108 // FIXME: possibly also ACK based on RTT (but for that we'd need to
4224 // determine the queue used for the ACK first!) 4109 // determine the queue used for the ACK first!)
@@ -4242,8 +4127,7 @@ handle_fragment_box (void *cls,
4242 } 4127 }
4243 /* successful reassembly */ 4128 /* successful reassembly */
4244 send_fragment_ack (rc); 4129 send_fragment_ack (rc);
4245 demultiplex_with_cmc (cmc, 4130 demultiplex_with_cmc (cmc, msg);
4246 msg);
4247 /* FIXME: really free here? Might be bad if fragments are still 4131 /* FIXME: really free here? Might be bad if fragments are still
4248 en-route and we forget that we finished this reassembly immediately! 4132 en-route and we forget that we finished this reassembly immediately!
4249 -> keep around until timeout? 4133 -> keep around until timeout?
@@ -4271,21 +4155,17 @@ check_ack_against_pm (struct PendingMessage *pm,
4271 uint64_t xtra = GNUNET_ntohll (fa->extra_acks); 4155 uint64_t xtra = GNUNET_ntohll (fa->extra_acks);
4272 4156
4273 match = GNUNET_NO; 4157 match = GNUNET_NO;
4274 for (struct PendingMessage *frag = pm->head_frag; 4158 for (struct PendingMessage *frag = pm->head_frag; NULL != frag; frag = nxt)
4275 NULL != frag;
4276 frag = nxt)
4277 { 4159 {
4278 const struct TransportFragmentBox *tfb 4160 const struct TransportFragmentBox *tfb =
4279 = (const struct TransportFragmentBox *) &pm[1]; 4161 (const struct TransportFragmentBox *) &pm[1];
4280 uint32_t fu = ntohl (tfb->frag_uuid); 4162 uint32_t fu = ntohl (tfb->frag_uuid);
4281 4163
4282 GNUNET_assert (PMT_FRAGMENT_BOX == frag->pmt); 4164 GNUNET_assert (PMT_FRAGMENT_BOX == frag->pmt);
4283 nxt = frag->next_frag; 4165 nxt = frag->next_frag;
4284 /* Check for exact match or match in the 'xtra' bitmask */ 4166 /* Check for exact match or match in the 'xtra' bitmask */
4285 if ( (fu == fs) || 4167 if ((fu == fs) ||
4286 ( (fu > fs) && 4168 ((fu > fs) && (fu <= fs + 64) && (0 != (1LLU << (fu - fs - 1) & xtra))))
4287 (fu <= fs + 64) &&
4288 (0 != (1LLU << (fu - fs - 1) & xtra)) ) )
4289 { 4169 {
4290 match = GNUNET_YES; 4170 match = GNUNET_YES;
4291 free_fragment_tree (frag); 4171 free_fragment_tree (frag);
@@ -4298,19 +4178,18 @@ check_ack_against_pm (struct PendingMessage *pm,
4298/** 4178/**
4299 * Communicator gave us a fragment acknowledgement. Process the request. 4179 * Communicator gave us a fragment acknowledgement. Process the request.
4300 * 4180 *
4301 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4181 * @param cls a `struct CommunicatorMessageContext` (must call
4182 * #finish_cmc_handling() when done)
4302 * @param fa the message that was received 4183 * @param fa the message that was received
4303 */ 4184 */
4304static void 4185static void
4305handle_fragment_ack (void *cls, 4186handle_fragment_ack (void *cls, const struct TransportFragmentAckMessage *fa)
4306 const struct TransportFragmentAckMessage *fa)
4307{ 4187{
4308 struct CommunicatorMessageContext *cmc = cls; 4188 struct CommunicatorMessageContext *cmc = cls;
4309 struct Neighbour *n; 4189 struct Neighbour *n;
4310 int matched; 4190 int matched;
4311 4191
4312 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 4192 n = GNUNET_CONTAINER_multipeermap_get (neighbours, &cmc->im.sender);
4313 &cmc->im.sender);
4314 if (NULL == n) 4193 if (NULL == n)
4315 { 4194 {
4316 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 4195 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
@@ -4322,21 +4201,16 @@ handle_fragment_ack (void *cls,
4322 } 4201 }
4323 /* FIXME-OPTIMIZE: maybe use another hash map here? */ 4202 /* FIXME-OPTIMIZE: maybe use another hash map here? */
4324 matched = GNUNET_NO; 4203 matched = GNUNET_NO;
4325 for (struct PendingMessage *pm = n->pending_msg_head; 4204 for (struct PendingMessage *pm = n->pending_msg_head; NULL != pm;
4326 NULL != pm;
4327 pm = pm->prev_neighbour) 4205 pm = pm->prev_neighbour)
4328 { 4206 {
4329 if (0 != 4207 if (0 != GNUNET_memcmp (&fa->msg_uuid, &pm->msg_uuid))
4330 GNUNET_memcmp (&fa->msg_uuid,
4331 &pm->msg_uuid))
4332 continue; 4208 continue;
4333 matched = GNUNET_YES; 4209 matched = GNUNET_YES;
4334 if (GNUNET_YES == 4210 if (GNUNET_YES == check_ack_against_pm (pm, fa))
4335 check_ack_against_pm (pm,
4336 fa))
4337 { 4211 {
4338 struct GNUNET_TIME_Relative avg_ack_delay 4212 struct GNUNET_TIME_Relative avg_ack_delay =
4339 = GNUNET_TIME_relative_ntoh (fa->avg_ack_delay); 4213 GNUNET_TIME_relative_ntoh (fa->avg_ack_delay);
4340 // FIXME: update RTT and other reliability data! 4214 // FIXME: update RTT and other reliability data!
4341 // ISSUE: we don't know which of n's queues the message(s) 4215 // ISSUE: we don't know which of n's queues the message(s)
4342 // took (and in fact the different messages might have gone 4216 // took (and in fact the different messages might have gone
@@ -4365,9 +4239,10 @@ handle_fragment_ack (void *cls,
4365 } 4239 }
4366 else 4240 else
4367 { 4241 {
4368 struct GNUNET_TIME_Relative reassembly_timeout 4242 struct GNUNET_TIME_Relative reassembly_timeout =
4369 = GNUNET_TIME_relative_ntoh (fa->reassembly_timeout); 4243 GNUNET_TIME_relative_ntoh (fa->reassembly_timeout);
4370 // OPTIMIZE-FIXME: adjust retransmission strategy based on reassembly_timeout! 4244 // OPTIMIZE-FIXME: adjust retransmission strategy based on
4245 // reassembly_timeout!
4371 (void) reassembly_timeout; 4246 (void) reassembly_timeout;
4372 } 4247 }
4373 break; 4248 break;
@@ -4391,8 +4266,7 @@ handle_fragment_ack (void *cls,
4391 * @return #GNUNET_YES if message is well-formed 4266 * @return #GNUNET_YES if message is well-formed
4392 */ 4267 */
4393static int 4268static int
4394check_reliability_box (void *cls, 4269check_reliability_box (void *cls, const struct TransportReliabilityBox *rb)
4395 const struct TransportReliabilityBox *rb)
4396{ 4270{
4397 GNUNET_MQ_check_boxed_message (rb); 4271 GNUNET_MQ_check_boxed_message (rb);
4398 return GNUNET_YES; 4272 return GNUNET_YES;
@@ -4402,15 +4276,16 @@ check_reliability_box (void *cls,
4402/** 4276/**
4403 * Communicator gave us a reliability box. Process the request. 4277 * Communicator gave us a reliability box. Process the request.
4404 * 4278 *
4405 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4279 * @param cls a `struct CommunicatorMessageContext` (must call
4280 * #finish_cmc_handling() when done)
4406 * @param rb the message that was received 4281 * @param rb the message that was received
4407 */ 4282 */
4408static void 4283static void
4409handle_reliability_box (void *cls, 4284handle_reliability_box (void *cls, const struct TransportReliabilityBox *rb)
4410 const struct TransportReliabilityBox *rb)
4411{ 4285{
4412 struct CommunicatorMessageContext *cmc = cls; 4286 struct CommunicatorMessageContext *cmc = cls;
4413 const struct GNUNET_MessageHeader *inbox = (const struct GNUNET_MessageHeader *) &rb[1]; 4287 const struct GNUNET_MessageHeader *inbox =
4288 (const struct GNUNET_MessageHeader *) &rb[1];
4414 4289
4415 if (0 == ntohl (rb->ack_countdown)) 4290 if (0 == ntohl (rb->ack_countdown))
4416 { 4291 {
@@ -4418,28 +4293,23 @@ handle_reliability_box (void *cls,
4418 4293
4419 /* FIXME: implement cummulative ACKs and ack_countdown, 4294 /* FIXME: implement cummulative ACKs and ack_countdown,
4420 then setting the avg_ack_delay field below: */ 4295 then setting the avg_ack_delay field below: */
4421 ack = GNUNET_malloc (sizeof (*ack) + 4296 ack = GNUNET_malloc (sizeof (*ack) + sizeof (struct GNUNET_ShortHashCode));
4422 sizeof (struct GNUNET_ShortHashCode));
4423 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); 4297 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK);
4424 ack->header.size = htons (sizeof (*ack) + 4298 ack->header.size =
4425 sizeof (struct GNUNET_ShortHashCode)); 4299 htons (sizeof (*ack) + sizeof (struct GNUNET_ShortHashCode));
4426 memcpy (&ack[1], 4300 memcpy (&ack[1], &rb->msg_uuid, sizeof (struct GNUNET_ShortHashCode));
4427 &rb->msg_uuid, 4301 route_message (&cmc->im.sender, &ack->header, RMO_DV_ALLOWED);
4428 sizeof (struct GNUNET_ShortHashCode));
4429 route_message (&cmc->im.sender,
4430 &ack->header,
4431 RMO_DV_ALLOWED);
4432 } 4302 }
4433 /* continue with inner message */ 4303 /* continue with inner message */
4434 demultiplex_with_cmc (cmc, 4304 demultiplex_with_cmc (cmc, inbox);
4435 inbox);
4436} 4305}
4437 4306
4438 4307
4439/** 4308/**
4440 * Communicator gave us a reliability ack. Process the request. 4309 * Communicator gave us a reliability ack. Process the request.
4441 * 4310 *
4442 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4311 * @param cls a `struct CommunicatorMessageContext` (must call
4312 * #finish_cmc_handling() when done)
4443 * @param ra the message that was received 4313 * @param ra the message that was received
4444 */ 4314 */
4445static void 4315static void
@@ -4453,8 +4323,7 @@ handle_reliability_ack (void *cls,
4453 struct PendingMessage *nxt; 4323 struct PendingMessage *nxt;
4454 int matched; 4324 int matched;
4455 4325
4456 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 4326 n = GNUNET_CONTAINER_multipeermap_get (neighbours, &cmc->im.sender);
4457 &cmc->im.sender);
4458 if (NULL == n) 4327 if (NULL == n)
4459 { 4328 {
4460 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 4329 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
@@ -4464,25 +4333,21 @@ handle_reliability_ack (void *cls,
4464 GNUNET_SERVICE_client_drop (client); 4333 GNUNET_SERVICE_client_drop (client);
4465 return; 4334 return;
4466 } 4335 }
4467 n_acks = (ntohs (ra->header.size) - sizeof (*ra)) 4336 n_acks = (ntohs (ra->header.size) - sizeof (*ra)) /
4468 / sizeof (struct GNUNET_ShortHashCode); 4337 sizeof (struct GNUNET_ShortHashCode);
4469 msg_uuids = (const struct GNUNET_ShortHashCode *) &ra[1]; 4338 msg_uuids = (const struct GNUNET_ShortHashCode *) &ra[1];
4470 4339
4471 /* FIXME-OPTIMIZE: maybe use another hash map here? */ 4340 /* FIXME-OPTIMIZE: maybe use another hash map here? */
4472 matched = GNUNET_NO; 4341 matched = GNUNET_NO;
4473 for (struct PendingMessage *pm = n->pending_msg_head; 4342 for (struct PendingMessage *pm = n->pending_msg_head; NULL != pm; pm = nxt)
4474 NULL != pm;
4475 pm = nxt)
4476 { 4343 {
4477 int in_list; 4344 int in_list;
4478 4345
4479 nxt = pm->next_neighbour; 4346 nxt = pm->next_neighbour;
4480 in_list = GNUNET_NO; 4347 in_list = GNUNET_NO;
4481 for (unsigned int i=0;i<n_acks;i++) 4348 for (unsigned int i = 0; i < n_acks; i++)
4482 { 4349 {
4483 if (0 != 4350 if (0 != GNUNET_memcmp (&msg_uuids[i], &pm->msg_uuid))
4484 GNUNET_memcmp (&msg_uuids[i],
4485 &pm->msg_uuid))
4486 continue; 4351 continue;
4487 in_list = GNUNET_YES; 4352 in_list = GNUNET_YES;
4488 break; 4353 break;
@@ -4495,8 +4360,8 @@ handle_reliability_ack (void *cls,
4495 free_pending_message (pm); 4360 free_pending_message (pm);
4496 4361
4497 { 4362 {
4498 struct GNUNET_TIME_Relative avg_ack_delay 4363 struct GNUNET_TIME_Relative avg_ack_delay =
4499 = GNUNET_TIME_relative_ntoh (ra->avg_ack_delay); 4364 GNUNET_TIME_relative_ntoh (ra->avg_ack_delay);
4500 // FIXME: update RTT and other reliability data! 4365 // FIXME: update RTT and other reliability data!
4501 // ISSUE: we don't know which of n's queues the message(s) 4366 // ISSUE: we don't know which of n's queues the message(s)
4502 // took (and in fact the different messages might have gone 4367 // took (and in fact the different messages might have gone
@@ -4528,15 +4393,16 @@ handle_reliability_ack (void *cls,
4528 * @return #GNUNET_YES if message is well-formed 4393 * @return #GNUNET_YES if message is well-formed
4529 */ 4394 */
4530static int 4395static int
4531check_backchannel_encapsulation (void *cls, 4396check_backchannel_encapsulation (
4532 const struct TransportBackchannelEncapsulationMessage *be) 4397 void *cls,
4398 const struct TransportBackchannelEncapsulationMessage *be)
4533{ 4399{
4534 uint16_t size = ntohs (be->header.size); 4400 uint16_t size = ntohs (be->header.size);
4535 4401
4536 (void) cls; 4402 (void) cls;
4537 if (size - sizeof (*be) < 4403 if ((size - sizeof (*be)) <
4538 sizeof (struct TransportBackchannelRequestPayload) + 4404 (sizeof (struct TransportBackchannelRequestPayload) +
4539 sizeof (struct GNUNET_MessageHeader) ) 4405 sizeof (struct GNUNET_MessageHeader)))
4540 { 4406 {
4541 GNUNET_break_op (0); 4407 GNUNET_break_op (0);
4542 return GNUNET_SYSERR; 4408 return GNUNET_SYSERR;
@@ -4550,12 +4416,14 @@ check_backchannel_encapsulation (void *cls,
4550 * (We are not the origin of the backchannel here, the communicator simply 4416 * (We are not the origin of the backchannel here, the communicator simply
4551 * received a backchannel message and we are expected to forward it.) 4417 * received a backchannel message and we are expected to forward it.)
4552 * 4418 *
4553 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4419 * @param cls a `struct CommunicatorMessageContext` (must call
4420 * #finish_cmc_handling() when done)
4554 * @param be the message that was received 4421 * @param be the message that was received
4555 */ 4422 */
4556static void 4423static void
4557handle_backchannel_encapsulation (void *cls, 4424handle_backchannel_encapsulation (
4558 const struct TransportBackchannelEncapsulationMessage *be) 4425 void *cls,
4426 const struct TransportBackchannelEncapsulationMessage *be)
4559{ 4427{
4560 struct CommunicatorMessageContext *cmc = cls; 4428 struct CommunicatorMessageContext *cmc = cls;
4561 struct BackchannelKeyState key; 4429 struct BackchannelKeyState key;
@@ -4563,8 +4431,7 @@ handle_backchannel_encapsulation (void *cls,
4563 const char *hdr; 4431 const char *hdr;
4564 size_t hdr_len; 4432 size_t hdr_len;
4565 4433
4566 if (0 != GNUNET_memcmp (&be->target, 4434 if (0 != GNUNET_memcmp (&be->target, &GST_my_identity))
4567 &GST_my_identity))
4568 { 4435 {
4569 /* not for me, try to route to target */ 4436 /* not for me, try to route to target */
4570 /* FIXME: someone needs to update be->distance! */ 4437 /* FIXME: someone needs to update be->distance! */
@@ -4576,18 +4443,11 @@ handle_backchannel_encapsulation (void *cls,
4576 finish_cmc_handling (cmc); 4443 finish_cmc_handling (cmc);
4577 return; 4444 return;
4578 } 4445 }
4579 dh_key_derive_eph_pub (&be->ephemeral_key, 4446 dh_key_derive_eph_pub (&be->ephemeral_key, &be->iv, &key);
4580 &be->iv,
4581 &key);
4582 hdr = (const char *) &be[1]; 4447 hdr = (const char *) &be[1];
4583 hdr_len = ntohs (be->header.size) - sizeof (*be); 4448 hdr_len = ntohs (be->header.size) - sizeof (*be);
4584 bc_hmac (&key, 4449 bc_hmac (&key, &hmac, hdr, hdr_len);
4585 &hmac, 4450 if (0 != GNUNET_memcmp (&hmac, &be->hmac))
4586 hdr,
4587 hdr_len);
4588 if (0 !=
4589 GNUNET_memcmp (&hmac,
4590 &be->hmac))
4591 { 4451 {
4592 /* HMAC missmatch, disard! */ 4452 /* HMAC missmatch, disard! */
4593 GNUNET_break_op (0); 4453 GNUNET_break_op (0);
@@ -4599,15 +4459,10 @@ handle_backchannel_encapsulation (void *cls,
4599 struct TransportBackchannelRequestPayload ppay; 4459 struct TransportBackchannelRequestPayload ppay;
4600 char body[hdr_len - sizeof (ppay)]; 4460 char body[hdr_len - sizeof (ppay)];
4601 4461
4602 GNUNET_assert (hdr_len >= sizeof (ppay) + sizeof (struct GNUNET_MessageHeader)); 4462 GNUNET_assert (hdr_len >=
4603 bc_decrypt (&key, 4463 sizeof (ppay) + sizeof (struct GNUNET_MessageHeader));
4604 &ppay, 4464 bc_decrypt (&key, &ppay, hdr, sizeof (ppay));
4605 hdr, 4465 bc_decrypt (&key, &body, &hdr[sizeof (ppay)], hdr_len - sizeof (ppay));
4606 sizeof (ppay));
4607 bc_decrypt (&key,
4608 &body,
4609 &hdr[sizeof (ppay)],
4610 hdr_len - sizeof (ppay));
4611 bc_key_clean (&key); 4466 bc_key_clean (&key);
4612 // FIXME: verify signatures in ppay! 4467 // FIXME: verify signatures in ppay!
4613 // => check if ephemeral key is known & valid, if not 4468 // => check if ephemeral key is known & valid, if not
@@ -4649,9 +4504,8 @@ path_cleanup_cb (void *cls)
4649 free_dv_route (dv); 4504 free_dv_route (dv);
4650 return; 4505 return;
4651 } 4506 }
4652 dv->timeout_task = GNUNET_SCHEDULER_add_at (pos->timeout, 4507 dv->timeout_task =
4653 &path_cleanup_cb, 4508 GNUNET_SCHEDULER_add_at (pos->timeout, &path_cleanup_cb, dv);
4654 dv);
4655} 4509}
4656 4510
4657 4511
@@ -4670,8 +4524,8 @@ path_cleanup_cb (void *cls)
4670 * and then path contains a valid path from us to `path[path_len-1]` 4524 * and then path contains a valid path from us to `path[path_len-1]`
4671 * path[1] should be a direct neighbour (we should check!) 4525 * path[1] should be a direct neighbour (we should check!)
4672 * @param path_len number of entries on the @a path, at least three! 4526 * @param path_len number of entries on the @a path, at least three!
4673 * @param network_latency how long does the message take from us to `path[path_len-1]`? 4527 * @param network_latency how long does the message take from us to
4674 * set to "forever" if unknown 4528 * `path[path_len-1]`? set to "forever" if unknown
4675 * @return #GNUNET_YES on success, 4529 * @return #GNUNET_YES on success,
4676 * #GNUNET_NO if we have better path(s) to the target 4530 * #GNUNET_NO if we have better path(s) to the target
4677 * #GNUNET_SYSERR if the path is useless and/or invalid 4531 * #GNUNET_SYSERR if the path is useless and/or invalid
@@ -4694,29 +4548,23 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4694 GNUNET_break (0); 4548 GNUNET_break (0);
4695 return GNUNET_SYSERR; 4549 return GNUNET_SYSERR;
4696 } 4550 }
4697 GNUNET_assert (0 == 4551 GNUNET_assert (0 == GNUNET_memcmp (&GST_my_identity, &path[0]));
4698 GNUNET_memcmp (&GST_my_identity, 4552 next_hop = GNUNET_CONTAINER_multipeermap_get (neighbours, &path[1]);
4699 &path[0]));
4700 next_hop = GNUNET_CONTAINER_multipeermap_get (neighbours,
4701 &path[1]);
4702 if (NULL == next_hop) 4553 if (NULL == next_hop)
4703 { 4554 {
4704 /* next hop must be a neighbour, otherwise this whole thing is useless! */ 4555 /* next hop must be a neighbour, otherwise this whole thing is useless! */
4705 GNUNET_break (0); 4556 GNUNET_break (0);
4706 return GNUNET_SYSERR; 4557 return GNUNET_SYSERR;
4707 } 4558 }
4708 for (unsigned int i=2;i<path_len;i++) 4559 for (unsigned int i = 2; i < path_len; i++)
4709 if (NULL != 4560 if (NULL != GNUNET_CONTAINER_multipeermap_get (neighbours, &path[i]))
4710 GNUNET_CONTAINER_multipeermap_get (neighbours,
4711 &path[i]))
4712 { 4561 {
4713 /* Useless path, we have a direct connection to some hop 4562 /* Useless path, we have a direct connection to some hop
4714 in the middle of the path, so this one doesn't even 4563 in the middle of the path, so this one doesn't even
4715 seem terribly useful for redundancy */ 4564 seem terribly useful for redundancy */
4716 return GNUNET_SYSERR; 4565 return GNUNET_SYSERR;
4717 } 4566 }
4718 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, 4567 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &path[path_len - 1]);
4719 &path[path_len - 1]);
4720 if (NULL == dv) 4568 if (NULL == dv)
4721 { 4569 {
4722 dv = GNUNET_new (struct DistanceVector); 4570 dv = GNUNET_new (struct DistanceVector);
@@ -4725,15 +4573,15 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4725 &path_cleanup_cb, 4573 &path_cleanup_cb,
4726 dv); 4574 dv);
4727 GNUNET_assert (GNUNET_OK == 4575 GNUNET_assert (GNUNET_OK ==
4728 GNUNET_CONTAINER_multipeermap_put (dv_routes, 4576 GNUNET_CONTAINER_multipeermap_put (
4729 &dv->target, 4577 dv_routes,
4730 dv, 4578 &dv->target,
4731 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 4579 dv,
4580 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
4732 } 4581 }
4733 /* Check if we have this path already! */ 4582 /* Check if we have this path already! */
4734 shorter_distance = 0; 4583 shorter_distance = 0;
4735 for (struct DistanceVectorHop *pos = dv->dv_head; 4584 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
4736 NULL != pos;
4737 pos = pos->next_dv) 4585 pos = pos->next_dv)
4738 { 4586 {
4739 if (pos->distance < path_len - 2) 4587 if (pos->distance < path_len - 2)
@@ -4741,16 +4589,13 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4741 /* Note that the distances in 'pos' excludes us (path[0]) and 4589 /* Note that the distances in 'pos' excludes us (path[0]) and
4742 the next_hop (path[1]), so we need to subtract two 4590 the next_hop (path[1]), so we need to subtract two
4743 and check next_hop explicitly */ 4591 and check next_hop explicitly */
4744 if ( (pos->distance == path_len - 2) && 4592 if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop))
4745 (pos->next_hop == next_hop) )
4746 { 4593 {
4747 int match = GNUNET_YES; 4594 int match = GNUNET_YES;
4748 4595
4749 for (unsigned int i=0;i<pos->distance;i++) 4596 for (unsigned int i = 0; i < pos->distance; i++)
4750 { 4597 {
4751 if (0 != 4598 if (0 != GNUNET_memcmp (&pos->path[i], &path[i + 2]))
4752 GNUNET_memcmp (&pos->path[i],
4753 &path[i+2]))
4754 { 4599 {
4755 match = GNUNET_NO; 4600 match = GNUNET_NO;
4756 break; 4601 break;
@@ -4766,19 +4611,14 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4766 1, 4611 1,
4767 GNUNET_NO); 4612 GNUNET_NO);
4768 last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout); 4613 last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout);
4769 pos->timeout 4614 pos->timeout =
4770 = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); 4615 GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT);
4771 GNUNET_CONTAINER_MDLL_remove (dv, 4616 GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, pos);
4772 dv->dv_head, 4617 GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, pos);
4773 dv->dv_tail,
4774 pos);
4775 GNUNET_CONTAINER_MDLL_insert (dv,
4776 dv->dv_head,
4777 dv->dv_tail,
4778 pos);
4779 if (last_timeout.rel_value_us < 4618 if (last_timeout.rel_value_us <
4780 GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT, 4619 GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT,
4781 DV_PATH_DISCOVERY_FREQUENCY).rel_value_us) 4620 DV_PATH_DISCOVERY_FREQUENCY)
4621 .rel_value_us)
4782 { 4622 {
4783 /* Some peer send DV learn messages too often, we are learning 4623 /* Some peer send DV learn messages too often, we are learning
4784 the same path faster than it would be useful; do not forward! */ 4624 the same path faster than it would be useful; do not forward! */
@@ -4806,10 +4646,7 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4806 sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); 4646 sizeof (struct GNUNET_PeerIdentity) * (path_len - 2));
4807 hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); 4647 hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT);
4808 hop->distance = path_len - 2; 4648 hop->distance = path_len - 2;
4809 GNUNET_CONTAINER_MDLL_insert (dv, 4649 GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, hop);
4810 dv->dv_head,
4811 dv->dv_tail,
4812 hop);
4813 GNUNET_CONTAINER_MDLL_insert (neighbour, 4650 GNUNET_CONTAINER_MDLL_insert (neighbour,
4814 next_hop->dv_head, 4651 next_hop->dv_head,
4815 next_hop->dv_tail, 4652 next_hop->dv_tail,
@@ -4826,8 +4663,7 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
4826 * @return #GNUNET_YES if message is well-formed 4663 * @return #GNUNET_YES if message is well-formed
4827 */ 4664 */
4828static int 4665static int
4829check_dv_learn (void *cls, 4666check_dv_learn (void *cls, const struct TransportDVLearn *dvl)
4830 const struct TransportDVLearn *dvl)
4831{ 4667{
4832 uint16_t size = ntohs (dvl->header.size); 4668 uint16_t size = ntohs (dvl->header.size);
4833 uint16_t num_hops = ntohs (dvl->num_hops); 4669 uint16_t num_hops = ntohs (dvl->num_hops);
@@ -4844,16 +4680,14 @@ check_dv_learn (void *cls,
4844 GNUNET_break_op (0); 4680 GNUNET_break_op (0);
4845 return GNUNET_SYSERR; 4681 return GNUNET_SYSERR;
4846 } 4682 }
4847 for (unsigned int i=0;i<num_hops;i++) 4683 for (unsigned int i = 0; i < num_hops; i++)
4848 { 4684 {
4849 if (0 == GNUNET_memcmp (&dvl->initiator, 4685 if (0 == GNUNET_memcmp (&dvl->initiator, &hops[i].hop))
4850 &hops[i].hop))
4851 { 4686 {
4852 GNUNET_break_op (0); 4687 GNUNET_break_op (0);
4853 return GNUNET_SYSERR; 4688 return GNUNET_SYSERR;
4854 } 4689 }
4855 if (0 == GNUNET_memcmp (&GST_my_identity, 4690 if (0 == GNUNET_memcmp (&GST_my_identity, &hops[i].hop))
4856 &hops[i].hop))
4857 { 4691 {
4858 GNUNET_break_op (0); 4692 GNUNET_break_op (0);
4859 return GNUNET_SYSERR; 4693 return GNUNET_SYSERR;
@@ -4871,7 +4705,8 @@ check_dv_learn (void *cls,
4871 * @param bi_history bitmask specifying hops on path that were bidirectional 4705 * @param bi_history bitmask specifying hops on path that were bidirectional
4872 * @param nhops length of the @a hops array 4706 * @param nhops length of the @a hops array
4873 * @param hops path the message traversed so far 4707 * @param hops path the message traversed so far
4874 * @param in_time when did we receive the message, used to calculate network delay 4708 * @param in_time when did we receive the message, used to calculate network
4709 * delay
4875 */ 4710 */
4876static void 4711static void
4877forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, 4712forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
@@ -4895,33 +4730,29 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
4895 fwd->num_hops = htons (nhops + 1); 4730 fwd->num_hops = htons (nhops + 1);
4896 fwd->bidirectional = htons (bi_history); 4731 fwd->bidirectional = htons (bi_history);
4897 nnd = GNUNET_TIME_relative_add (GNUNET_TIME_absolute_get_duration (in_time), 4732 nnd = GNUNET_TIME_relative_add (GNUNET_TIME_absolute_get_duration (in_time),
4898 GNUNET_TIME_relative_ntoh (msg->non_network_delay)); 4733 GNUNET_TIME_relative_ntoh (
4734 msg->non_network_delay));
4899 fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd); 4735 fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd);
4900 fwd->init_sig = msg->init_sig; 4736 fwd->init_sig = msg->init_sig;
4901 fwd->initiator = msg->initiator; 4737 fwd->initiator = msg->initiator;
4902 fwd->challenge = msg->challenge; 4738 fwd->challenge = msg->challenge;
4903 dhops = (struct DVPathEntryP *) &fwd[1]; 4739 dhops = (struct DVPathEntryP *) &fwd[1];
4904 GNUNET_memcpy (dhops, 4740 GNUNET_memcpy (dhops, hops, sizeof (struct DVPathEntryP) * nhops);
4905 hops,
4906 sizeof (struct DVPathEntryP) * nhops);
4907 dhops[nhops].hop = GST_my_identity; 4741 dhops[nhops].hop = GST_my_identity;
4908 { 4742 {
4909 struct DvHopPS dhp = { 4743 struct DvHopPS dhp = {.purpose.purpose =
4910 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), 4744 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP),
4911 .purpose.size = htonl (sizeof (dhp)), 4745 .purpose.size = htonl (sizeof (dhp)),
4912 .pred = dhops[nhops-1].hop, 4746 .pred = dhops[nhops - 1].hop,
4913 .succ = *next_hop, 4747 .succ = *next_hop,
4914 .challenge = msg->challenge 4748 .challenge = msg->challenge};
4915 };
4916 4749
4917 GNUNET_assert (GNUNET_OK == 4750 GNUNET_assert (GNUNET_OK ==
4918 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 4751 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
4919 &dhp.purpose, 4752 &dhp.purpose,
4920 &dhops[nhops].hop_sig)); 4753 &dhops[nhops].hop_sig));
4921 } 4754 }
4922 route_message (next_hop, 4755 route_message (next_hop, &fwd->header, RMO_UNCONFIRMED_ALLOWED);
4923 &fwd->header,
4924 RMO_UNCONFIRMED_ALLOWED);
4925} 4756}
4926 4757
4927 4758
@@ -4934,21 +4765,22 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
4934 * @return #GNUNET_OK if the signature is valid 4765 * @return #GNUNET_OK if the signature is valid
4935 */ 4766 */
4936static int 4767static int
4937validate_dv_initiator_signature (const struct GNUNET_PeerIdentity *init, 4768validate_dv_initiator_signature (
4938 const struct GNUNET_ShortHashCode *challenge, 4769 const struct GNUNET_PeerIdentity *init,
4939 const struct GNUNET_CRYPTO_EddsaSignature *init_sig) 4770 const struct GNUNET_ShortHashCode *challenge,
4940{ 4771 const struct GNUNET_CRYPTO_EddsaSignature *init_sig)
4941 struct DvInitPS ip = { 4772{
4942 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), 4773 struct DvInitPS ip = {.purpose.purpose = htonl (
4943 .purpose.size = htonl (sizeof (ip)), 4774 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR),
4944 .challenge = *challenge 4775 .purpose.size = htonl (sizeof (ip)),
4945 }; 4776 .challenge = *challenge};
4946 4777
4947 if (GNUNET_OK != 4778 if (
4948 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, 4779 GNUNET_OK !=
4949 &ip.purpose, 4780 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR,
4950 init_sig, 4781 &ip.purpose,
4951 &init->public_key)) 4782 init_sig,
4783 &init->public_key))
4952 { 4784 {
4953 GNUNET_break_op (0); 4785 GNUNET_break_op (0);
4954 return GNUNET_SYSERR; 4786 return GNUNET_SYSERR;
@@ -4960,12 +4792,12 @@ validate_dv_initiator_signature (const struct GNUNET_PeerIdentity *init,
4960/** 4792/**
4961 * Communicator gave us a DV learn message. Process the request. 4793 * Communicator gave us a DV learn message. Process the request.
4962 * 4794 *
4963 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 4795 * @param cls a `struct CommunicatorMessageContext` (must call
4796 * #finish_cmc_handling() when done)
4964 * @param dvl the message that was received 4797 * @param dvl the message that was received
4965 */ 4798 */
4966static void 4799static void
4967handle_dv_learn (void *cls, 4800handle_dv_learn (void *cls, const struct TransportDVLearn *dvl)
4968 const struct TransportDVLearn *dvl)
4969{ 4801{
4970 struct CommunicatorMessageContext *cmc = cls; 4802 struct CommunicatorMessageContext *cmc = cls;
4971 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; 4803 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
@@ -4983,8 +4815,7 @@ handle_dv_learn (void *cls,
4983 if (0 == nhops) 4815 if (0 == nhops)
4984 { 4816 {
4985 /* sanity check */ 4817 /* sanity check */
4986 if (0 != GNUNET_memcmp (&dvl->initiator, 4818 if (0 != GNUNET_memcmp (&dvl->initiator, &cmc->im.sender))
4987 &cmc->im.sender))
4988 { 4819 {
4989 GNUNET_break (0); 4820 GNUNET_break (0);
4990 finish_cmc_handling (cmc); 4821 finish_cmc_handling (cmc);
@@ -4994,8 +4825,7 @@ handle_dv_learn (void *cls,
4994 else 4825 else
4995 { 4826 {
4996 /* sanity check */ 4827 /* sanity check */
4997 if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, 4828 if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, &cmc->im.sender))
4998 &cmc->im.sender))
4999 { 4829 {
5000 GNUNET_break (0); 4830 GNUNET_break (0);
5001 finish_cmc_handling (cmc); 4831 finish_cmc_handling (cmc);
@@ -5005,7 +4835,8 @@ handle_dv_learn (void *cls,
5005 4835
5006 GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type); 4836 GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type);
5007 cc = cmc->tc->details.communicator.cc; 4837 cc = cmc->tc->details.communicator.cc;
5008 bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE == cc); // FIXME: add bi-directional flag to cc? 4838 bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE ==
4839 cc); // FIXME: add bi-directional flag to cc?
5009 in_time = GNUNET_TIME_absolute_get (); 4840 in_time = GNUNET_TIME_absolute_get ();
5010 4841
5011 /* continue communicator here, everything else can happen asynchronous! */ 4842 /* continue communicator here, everything else can happen asynchronous! */
@@ -5013,20 +4844,19 @@ handle_dv_learn (void *cls,
5013 4844
5014 /* OPTIMIZE-FIXME: Technically, we only need to bother checking 4845 /* OPTIMIZE-FIXME: Technically, we only need to bother checking
5015 the initiator signature if we send the message back to the initiator... */ 4846 the initiator signature if we send the message back to the initiator... */
5016 if (GNUNET_OK != 4847 if (GNUNET_OK != validate_dv_initiator_signature (&dvl->initiator,
5017 validate_dv_initiator_signature (&dvl->initiator, 4848 &dvl->challenge,
5018 &dvl->challenge, 4849 &dvl->init_sig))
5019 &dvl->init_sig))
5020 { 4850 {
5021 GNUNET_break_op (0); 4851 GNUNET_break_op (0);
5022 return; 4852 return;
5023 } 4853 }
5024 // FIXME: asynchronously (!) verify hop-by-hop signatures! 4854 // FIXME: asynchronously (!) verify hop-by-hop signatures!
5025 // => if signature verification load too high, implement random drop strategy!? 4855 // => if signature verification load too high, implement random drop
4856 // strategy!?
5026 4857
5027 do_fwd = GNUNET_YES; 4858 do_fwd = GNUNET_YES;
5028 if (0 == GNUNET_memcmp (&GST_my_identity, 4859 if (0 == GNUNET_memcmp (&GST_my_identity, &dvl->initiator))
5029 &dvl->initiator))
5030 { 4860 {
5031 struct GNUNET_PeerIdentity path[nhops + 1]; 4861 struct GNUNET_PeerIdentity path[nhops + 1];
5032 struct GNUNET_TIME_Relative host_latency_sum; 4862 struct GNUNET_TIME_Relative host_latency_sum;
@@ -5043,27 +4873,22 @@ handle_dv_learn (void *cls,
5043 latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly 4873 latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly
5044 // (based on dvl->challenge, we can identify time of origin!) 4874 // (based on dvl->challenge, we can identify time of origin!)
5045 4875
5046 network_latency = GNUNET_TIME_relative_subtract (latency, 4876 network_latency = GNUNET_TIME_relative_subtract (latency, host_latency_sum);
5047 host_latency_sum);
5048 /* assumption: latency on all links is the same */ 4877 /* assumption: latency on all links is the same */
5049 network_latency = GNUNET_TIME_relative_divide (network_latency, 4878 network_latency = GNUNET_TIME_relative_divide (network_latency, nhops);
5050 nhops);
5051 4879
5052 for (unsigned int i=2;i<=nhops;i++) 4880 for (unsigned int i = 2; i <= nhops; i++)
5053 { 4881 {
5054 struct GNUNET_TIME_Relative ilat; 4882 struct GNUNET_TIME_Relative ilat;
5055 4883
5056 /* assumption: linear latency increase per hop */ 4884 /* assumption: linear latency increase per hop */
5057 ilat = GNUNET_TIME_relative_multiply (network_latency, 4885 ilat = GNUNET_TIME_relative_multiply (network_latency, i);
5058 i); 4886 path[i] = hops[i - 1].hop;
5059 path[i] = hops[i-1].hop;
5060 // FIXME: mark ALL of these as *confirmed* (with what timeout?) 4887 // FIXME: mark ALL of these as *confirmed* (with what timeout?)
5061 // -- and schedule a job for the confirmation to time out! -- 4888 // -- and schedule a job for the confirmation to time out! --
5062 // and possibly do #cores_send_connect_info() if 4889 // and possibly do #cores_send_connect_info() if
5063 // the respective neighbour is NOT confirmed yet! 4890 // the respective neighbour is NOT confirmed yet!
5064 learn_dv_path (path, 4891 learn_dv_path (path, i, ilat);
5065 i,
5066 ilat);
5067 } 4892 }
5068 /* as we initiated, do not forward again (would be circular!) */ 4893 /* as we initiated, do not forward again (would be circular!) */
5069 do_fwd = GNUNET_NO; 4894 do_fwd = GNUNET_NO;
@@ -5076,7 +4901,7 @@ handle_dv_learn (void *cls,
5076 4901
5077 path[0] = GST_my_identity; 4902 path[0] = GST_my_identity;
5078 path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */ 4903 path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */
5079 for (unsigned int i=0;i<nhops;i++) 4904 for (unsigned int i = 0; i < nhops; i++)
5080 { 4905 {
5081 int iret; 4906 int iret;
5082 4907
@@ -5091,9 +4916,7 @@ handle_dv_learn (void *cls,
5091 path[i + 2] = hops[nhops - i - 2].hop; 4916 path[i + 2] = hops[nhops - i - 2].hop;
5092 } 4917 }
5093 4918
5094 iret = learn_dv_path (path, 4919 iret = learn_dv_path (path, i + 2, GNUNET_TIME_UNIT_FOREVER_REL);
5095 i + 2,
5096 GNUNET_TIME_UNIT_FOREVER_REL);
5097 if (GNUNET_SYSERR == iret) 4920 if (GNUNET_SYSERR == iret)
5098 { 4921 {
5099 /* path invalid or too long to be interesting for US, thus should also 4922 /* path invalid or too long to be interesting for US, thus should also
@@ -5107,8 +4930,7 @@ handle_dv_learn (void *cls,
5107 do_fwd = GNUNET_NO; 4930 do_fwd = GNUNET_NO;
5108 break; 4931 break;
5109 } 4932 }
5110 if ( (GNUNET_NO == iret) && 4933 if ((GNUNET_NO == iret) && (nhops == i + 1))
5111 (nhops == i + 1) )
5112 { 4934 {
5113 /* we have better paths, and this is the longest target, 4935 /* we have better paths, and this is the longest target,
5114 so there cannot be anything interesting later */ 4936 so there cannot be anything interesting later */
@@ -5132,27 +4954,20 @@ handle_dv_learn (void *cls,
5132 /* Forward to initiator, if path non-trivial and possible */ 4954 /* Forward to initiator, if path non-trivial and possible */
5133 bi_history = (bi_history << 1) | (bi_hop ? 1 : 0); 4955 bi_history = (bi_history << 1) | (bi_hop ? 1 : 0);
5134 did_initiator = GNUNET_NO; 4956 did_initiator = GNUNET_NO;
5135 if ( (1 < nhops) && 4957 if ((1 < nhops) &&
5136 (GNUNET_YES == 4958 (GNUNET_YES ==
5137 GNUNET_CONTAINER_multipeermap_contains (neighbours, 4959 GNUNET_CONTAINER_multipeermap_contains (neighbours, &dvl->initiator)))
5138 &dvl->initiator)) )
5139 { 4960 {
5140 /* send back to origin! */ 4961 /* send back to origin! */
5141 forward_dv_learn (&dvl->initiator, 4962 forward_dv_learn (&dvl->initiator, dvl, bi_history, nhops, hops, in_time);
5142 dvl,
5143 bi_history,
5144 nhops,
5145 hops,
5146 in_time);
5147 did_initiator = GNUNET_YES; 4963 did_initiator = GNUNET_YES;
5148 } 4964 }
5149 /* We forward under two conditions: either we still learned something 4965 /* We forward under two conditions: either we still learned something
5150 ourselves (do_fwd), or the path was darn short and thus the initiator is 4966 ourselves (do_fwd), or the path was darn short and thus the initiator is
5151 likely to still be very interested in this (and we did NOT already 4967 likely to still be very interested in this (and we did NOT already
5152 send it back to the initiator) */ 4968 send it back to the initiator) */
5153 if ( (do_fwd) || 4969 if ((do_fwd) || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) &&
5154 ( (nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) && 4970 (GNUNET_NO == did_initiator)))
5155 (GNUNET_NO == did_initiator) ) )
5156 { 4971 {
5157 /* FIXME: loop over all neighbours, pick those with low 4972 /* FIXME: loop over all neighbours, pick those with low
5158 queues AND that are not yet on the path; possibly 4973 queues AND that are not yet on the path; possibly
@@ -5177,38 +4992,39 @@ handle_dv_learn (void *cls,
5177 * @return #GNUNET_YES if message is well-formed 4992 * @return #GNUNET_YES if message is well-formed
5178 */ 4993 */
5179static int 4994static int
5180check_dv_box (void *cls, 4995check_dv_box (void *cls, const struct TransportDVBox *dvb)
5181 const struct TransportDVBox *dvb)
5182{ 4996{
5183 uint16_t size = ntohs (dvb->header.size); 4997 uint16_t size = ntohs (dvb->header.size);
5184 uint16_t num_hops = ntohs (dvb->num_hops); 4998 uint16_t num_hops = ntohs (dvb->num_hops);
5185 const struct GNUNET_PeerIdentity *hops = (const struct GNUNET_PeerIdentity *) &dvb[1]; 4999 const struct GNUNET_PeerIdentity *hops =
5186 const struct GNUNET_MessageHeader *inbox = (const struct GNUNET_MessageHeader *) &hops[num_hops]; 5000 (const struct GNUNET_PeerIdentity *) &dvb[1];
5001 const struct GNUNET_MessageHeader *inbox =
5002 (const struct GNUNET_MessageHeader *) &hops[num_hops];
5187 uint16_t isize; 5003 uint16_t isize;
5188 uint16_t itype; 5004 uint16_t itype;
5189 5005
5190 (void) cls; 5006 (void) cls;
5191 if (size < sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + sizeof (struct GNUNET_MessageHeader)) 5007 if (size < sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) +
5008 sizeof (struct GNUNET_MessageHeader))
5192 { 5009 {
5193 GNUNET_break_op (0); 5010 GNUNET_break_op (0);
5194 return GNUNET_SYSERR; 5011 return GNUNET_SYSERR;
5195 } 5012 }
5196 isize = ntohs (inbox->size); 5013 isize = ntohs (inbox->size);
5197 if (size != sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + isize) 5014 if (size !=
5015 sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + isize)
5198 { 5016 {
5199 GNUNET_break_op (0); 5017 GNUNET_break_op (0);
5200 return GNUNET_SYSERR; 5018 return GNUNET_SYSERR;
5201 } 5019 }
5202 itype = ntohs (inbox->type); 5020 itype = ntohs (inbox->type);
5203 if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX == itype) || 5021 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX == itype) ||
5204 (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN == itype) ) 5022 (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN == itype))
5205 { 5023 {
5206 GNUNET_break_op (0); 5024 GNUNET_break_op (0);
5207 return GNUNET_SYSERR; 5025 return GNUNET_SYSERR;
5208 } 5026 }
5209 if (0 == 5027 if (0 == GNUNET_memcmp (&dvb->origin, &GST_my_identity))
5210 GNUNET_memcmp (&dvb->origin,
5211 &GST_my_identity))
5212 { 5028 {
5213 GNUNET_break_op (0); 5029 GNUNET_break_op (0);
5214 return GNUNET_SYSERR; 5030 return GNUNET_SYSERR;
@@ -5241,74 +5057,66 @@ forward_dv_box (struct Neighbour *next_hop,
5241 struct TransportDVBox *dvb; 5057 struct TransportDVBox *dvb;
5242 struct GNUNET_PeerIdentity *dhops; 5058 struct GNUNET_PeerIdentity *dhops;
5243 5059
5244 GNUNET_assert (UINT16_MAX < 5060 GNUNET_assert (UINT16_MAX < sizeof (struct TransportDVBox) +
5245 sizeof (struct TransportDVBox) + 5061 sizeof (struct GNUNET_PeerIdentity) * num_hops +
5246 sizeof (struct GNUNET_PeerIdentity) * num_hops + 5062 payload_size);
5247 payload_size);
5248 dvb = GNUNET_malloc (sizeof (struct TransportDVBox) + 5063 dvb = GNUNET_malloc (sizeof (struct TransportDVBox) +
5249 sizeof (struct GNUNET_PeerIdentity) * num_hops + 5064 sizeof (struct GNUNET_PeerIdentity) * num_hops +
5250 payload_size); 5065 payload_size);
5251 dvb->header.size = htons (sizeof (struct TransportDVBox) + 5066 dvb->header.size =
5252 sizeof (struct GNUNET_PeerIdentity) * num_hops + 5067 htons (sizeof (struct TransportDVBox) +
5253 payload_size); 5068 sizeof (struct GNUNET_PeerIdentity) * num_hops + payload_size);
5254 dvb->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX); 5069 dvb->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX);
5255 dvb->total_hops = htons (total_hops); 5070 dvb->total_hops = htons (total_hops);
5256 dvb->num_hops = htons (num_hops); 5071 dvb->num_hops = htons (num_hops);
5257 dvb->origin = *origin; 5072 dvb->origin = *origin;
5258 dhops = (struct GNUNET_PeerIdentity *) &dvb[1]; 5073 dhops = (struct GNUNET_PeerIdentity *) &dvb[1];
5259 memcpy (dhops, 5074 memcpy (dhops, hops, num_hops * sizeof (struct GNUNET_PeerIdentity));
5260 hops, 5075 memcpy (&dhops[num_hops], payload, payload_size);
5261 num_hops * sizeof (struct GNUNET_PeerIdentity)); 5076 route_message (&next_hop->pid, &dvb->header, RMO_NONE);
5262 memcpy (&dhops[num_hops],
5263 payload,
5264 payload_size);
5265 route_message (&next_hop->pid,
5266 &dvb->header,
5267 RMO_NONE);
5268} 5077}
5269 5078
5270 5079
5271/** 5080/**
5272 * Communicator gave us a DV box. Process the request. 5081 * Communicator gave us a DV box. Process the request.
5273 * 5082 *
5274 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 5083 * @param cls a `struct CommunicatorMessageContext` (must call
5084 * #finish_cmc_handling() when done)
5275 * @param dvb the message that was received 5085 * @param dvb the message that was received
5276 */ 5086 */
5277static void 5087static void
5278handle_dv_box (void *cls, 5088handle_dv_box (void *cls, const struct TransportDVBox *dvb)
5279 const struct TransportDVBox *dvb)
5280{ 5089{
5281 struct CommunicatorMessageContext *cmc = cls; 5090 struct CommunicatorMessageContext *cmc = cls;
5282 uint16_t size = ntohs (dvb->header.size) - sizeof (*dvb); 5091 uint16_t size = ntohs (dvb->header.size) - sizeof (*dvb);
5283 uint16_t num_hops = ntohs (dvb->num_hops); 5092 uint16_t num_hops = ntohs (dvb->num_hops);
5284 const struct GNUNET_PeerIdentity *hops = (const struct GNUNET_PeerIdentity *) &dvb[1]; 5093 const struct GNUNET_PeerIdentity *hops =
5285 const struct GNUNET_MessageHeader *inbox = (const struct GNUNET_MessageHeader *) &hops[num_hops]; 5094 (const struct GNUNET_PeerIdentity *) &dvb[1];
5095 const struct GNUNET_MessageHeader *inbox =
5096 (const struct GNUNET_MessageHeader *) &hops[num_hops];
5286 5097
5287 if (num_hops > 0) 5098 if (num_hops > 0)
5288 { 5099 {
5289 /* We're trying from the end of the hops array, as we may be 5100 /* We're trying from the end of the hops array, as we may be
5290 able to find a shortcut unknown to the origin that way */ 5101 able to find a shortcut unknown to the origin that way */
5291 for (int i=num_hops-1;i>=0;i--) 5102 for (int i = num_hops - 1; i >= 0; i--)
5292 { 5103 {
5293 struct Neighbour *n; 5104 struct Neighbour *n;
5294 5105
5295 if (0 == 5106 if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity))
5296 GNUNET_memcmp (&hops[i],
5297 &GST_my_identity))
5298 { 5107 {
5299 GNUNET_break_op (0); 5108 GNUNET_break_op (0);
5300 finish_cmc_handling (cmc); 5109 finish_cmc_handling (cmc);
5301 return; 5110 return;
5302 } 5111 }
5303 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 5112 n = GNUNET_CONTAINER_multipeermap_get (neighbours, &hops[i]);
5304 &hops[i]);
5305 if (NULL == n) 5113 if (NULL == n)
5306 continue; 5114 continue;
5307 forward_dv_box (n, 5115 forward_dv_box (n,
5308 ntohs (dvb->total_hops) + 1, 5116 ntohs (dvb->total_hops) + 1,
5309 num_hops - i - 1, /* number of hops left */ 5117 num_hops - i - 1, /* number of hops left */
5310 &dvb->origin, 5118 &dvb->origin,
5311 &hops[i+1], /* remaining hops */ 5119 &hops[i + 1], /* remaining hops */
5312 (const void *) &dvb[1], 5120 (const void *) &dvb[1],
5313 size); 5121 size);
5314 finish_cmc_handling (cmc); 5122 finish_cmc_handling (cmc);
@@ -5325,8 +5133,7 @@ handle_dv_box (void *cls,
5325 /* We are the target. Unbox and handle message. */ 5133 /* We are the target. Unbox and handle message. */
5326 cmc->im.sender = dvb->origin; 5134 cmc->im.sender = dvb->origin;
5327 cmc->total_hops = ntohs (dvb->total_hops); 5135 cmc->total_hops = ntohs (dvb->total_hops);
5328 demultiplex_with_cmc (cmc, 5136 demultiplex_with_cmc (cmc, inbox);
5329 inbox);
5330} 5137}
5331 5138
5332 5139
@@ -5354,9 +5161,11 @@ check_incoming_msg (void *cls,
5354 5161
5355 5162
5356/** 5163/**
5357 * Communicator gave us a transport address validation challenge. Process the request. 5164 * Communicator gave us a transport address validation challenge. Process the
5165 * request.
5358 * 5166 *
5359 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 5167 * @param cls a `struct CommunicatorMessageContext` (must call
5168 * #finish_cmc_handling() when done)
5360 * @param tvc the message that was received 5169 * @param tvc the message that was received
5361 */ 5170 */
5362static void 5171static void
@@ -5374,24 +5183,23 @@ handle_validation_challenge (void *cls,
5374 return; 5183 return;
5375 } 5184 }
5376 tvr = GNUNET_new (struct TransportValidationResponse); 5185 tvr = GNUNET_new (struct TransportValidationResponse);
5377 tvr->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); 5186 tvr->header.type =
5187 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE);
5378 tvr->header.size = htons (sizeof (*tvr)); 5188 tvr->header.size = htons (sizeof (*tvr));
5379 tvr->challenge = tvc->challenge; 5189 tvr->challenge = tvc->challenge;
5380 tvr->origin_time = tvc->sender_time; 5190 tvr->origin_time = tvc->sender_time;
5381 tvr->validity_duration = cmc->im.expected_address_validity; 5191 tvr->validity_duration = cmc->im.expected_address_validity;
5382 { 5192 {
5383 /* create signature */ 5193 /* create signature */
5384 struct TransportValidationPS tvp = { 5194 struct TransportValidationPS tvp =
5385 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), 5195 {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
5386 .purpose.size = htonl (sizeof (tvp)), 5196 .purpose.size = htonl (sizeof (tvp)),
5387 .validity_duration = tvr->validity_duration, 5197 .validity_duration = tvr->validity_duration,
5388 .challenge = tvc->challenge 5198 .challenge = tvc->challenge};
5389 };
5390 5199
5391 GNUNET_assert (GNUNET_OK == 5200 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
5392 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 5201 &tvp.purpose,
5393 &tvp.purpose, 5202 &tvr->signature));
5394 &tvr->signature));
5395 } 5203 }
5396 route_message (&cmc->im.sender, 5204 route_message (&cmc->im.sender,
5397 &tvr->header, 5205 &tvr->header,
@@ -5435,8 +5243,7 @@ check_known_challenge (void *cls,
5435 struct ValidationState *vs = value; 5243 struct ValidationState *vs = value;
5436 5244
5437 (void) pid; 5245 (void) pid;
5438 if (0 != GNUNET_memcmp (&vs->challenge, 5246 if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge))
5439 ckac->challenge))
5440 return GNUNET_OK; 5247 return GNUNET_OK;
5441 ckac->vs = vs; 5248 ckac->vs = vs;
5442 return GNUNET_NO; 5249 return GNUNET_NO;
@@ -5451,8 +5258,7 @@ check_known_challenge (void *cls,
5451 * @param success #GNUNET_YES on success 5258 * @param success #GNUNET_YES on success
5452 */ 5259 */
5453static void 5260static void
5454peerstore_store_validation_cb (void *cls, 5261peerstore_store_validation_cb (void *cls, int success)
5455 int success)
5456{ 5262{
5457 struct ValidationState *vs = cls; 5263 struct ValidationState *vs = cls;
5458 5264
@@ -5492,25 +5298,22 @@ update_next_challenge_time (struct ValidationState *vs,
5492 return; /* be lazy */ 5298 return; /* be lazy */
5493 vs->next_challenge = new_time; 5299 vs->next_challenge = new_time;
5494 if (NULL == vs->hn) 5300 if (NULL == vs->hn)
5495 vs->hn = GNUNET_CONTAINER_heap_insert (validation_heap, 5301 vs->hn =
5496 vs, 5302 GNUNET_CONTAINER_heap_insert (validation_heap, vs, new_time.abs_value_us);
5497 new_time.abs_value_us);
5498 else 5303 else
5499 GNUNET_CONTAINER_heap_update_cost (vs->hn, 5304 GNUNET_CONTAINER_heap_update_cost (vs->hn, new_time.abs_value_us);
5500 new_time.abs_value_us); 5305 if ((vs != GNUNET_CONTAINER_heap_peek (validation_heap)) &&
5501 if ( (vs != GNUNET_CONTAINER_heap_peek (validation_heap)) && 5306 (NULL != validation_task))
5502 (NULL != validation_task) )
5503 return; 5307 return;
5504 if (NULL != validation_task) 5308 if (NULL != validation_task)
5505 GNUNET_SCHEDULER_cancel (validation_task); 5309 GNUNET_SCHEDULER_cancel (validation_task);
5506 /* randomize a bit */ 5310 /* randomize a bit */
5507 delta.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 5311 delta.rel_value_us =
5508 MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); 5312 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
5509 new_time = GNUNET_TIME_absolute_add (new_time, 5313 MIN_DELAY_ADDRESS_VALIDATION.rel_value_us);
5510 delta); 5314 new_time = GNUNET_TIME_absolute_add (new_time, delta);
5511 validation_task = GNUNET_SCHEDULER_add_at (new_time, 5315 validation_task =
5512 &validation_start_cb, 5316 GNUNET_SCHEDULER_add_at (new_time, &validation_start_cb, NULL);
5513 NULL);
5514} 5317}
5515 5318
5516 5319
@@ -5522,21 +5325,17 @@ update_next_challenge_time (struct ValidationState *vs,
5522 * @return NULL if no such queue exists 5325 * @return NULL if no such queue exists
5523 */ 5326 */
5524static struct Queue * 5327static struct Queue *
5525find_queue (const struct GNUNET_PeerIdentity *pid, 5328find_queue (const struct GNUNET_PeerIdentity *pid, const char *address)
5526 const char *address)
5527{ 5329{
5528 struct Neighbour *n; 5330 struct Neighbour *n;
5529 5331
5530 n = GNUNET_CONTAINER_multipeermap_get (neighbours, 5332 n = GNUNET_CONTAINER_multipeermap_get (neighbours, pid);
5531 pid);
5532 if (NULL == n) 5333 if (NULL == n)
5533 return NULL; 5334 return NULL;
5534 for (struct Queue *pos = n->queue_head; 5335 for (struct Queue *pos = n->queue_head; NULL != pos;
5535 NULL != pos;
5536 pos = pos->next_neighbour) 5336 pos = pos->next_neighbour)
5537 { 5337 {
5538 if (0 == strcmp (pos->address, 5338 if (0 == strcmp (pos->address, address))
5539 address))
5540 return pos; 5339 return pos;
5541 } 5340 }
5542 return NULL; 5341 return NULL;
@@ -5559,10 +5358,9 @@ core_queue_visibility_check (void *cls)
5559 q->visibility_task = NULL; 5358 q->visibility_task = NULL;
5560 if (0 != GNUNET_TIME_absolute_get_remaining (q->validated_until).rel_value_us) 5359 if (0 != GNUNET_TIME_absolute_get_remaining (q->validated_until).rel_value_us)
5561 { 5360 {
5562 q->visibility_task 5361 q->visibility_task = GNUNET_SCHEDULER_add_at (q->validated_until,
5563 = GNUNET_SCHEDULER_add_at (q->validated_until, 5362 &core_queue_visibility_check,
5564 &core_queue_visibility_check, 5363 q);
5565 q);
5566 return; 5364 return;
5567 } 5365 }
5568 update_neighbour_core_visibility (q->neighbour); 5366 update_neighbour_core_visibility (q->neighbour);
@@ -5586,17 +5384,16 @@ update_neighbour_core_visibility (struct Neighbour *n)
5586 GNUNET_assert (GNUNET_YES == n->core_visible); 5384 GNUNET_assert (GNUNET_YES == n->core_visible);
5587 /* Check if _any_ queue of this neighbour is still valid, if so, schedule 5385 /* Check if _any_ queue of this neighbour is still valid, if so, schedule
5588 the #core_queue_visibility_check() task for that queue */ 5386 the #core_queue_visibility_check() task for that queue */
5589 for (struct Queue *q = n->queue_head; 5387 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
5590 NULL != q;
5591 q = q->next_neighbour)
5592 { 5388 {
5593 if (0 != GNUNET_TIME_absolute_get_remaining (q->validated_until).rel_value_us) 5389 if (0 !=
5390 GNUNET_TIME_absolute_get_remaining (q->validated_until).rel_value_us)
5594 { 5391 {
5595 /* found a valid queue, use this one */ 5392 /* found a valid queue, use this one */
5596 q->visibility_task 5393 q->visibility_task =
5597 = GNUNET_SCHEDULER_add_at (q->validated_until, 5394 GNUNET_SCHEDULER_add_at (q->validated_until,
5598 &core_queue_visibility_check, 5395 &core_queue_visibility_check,
5599 q); 5396 q);
5600 return; 5397 return;
5601 } 5398 }
5602 } 5399 }
@@ -5605,8 +5402,7 @@ update_neighbour_core_visibility (struct Neighbour *n)
5605 /* Check if _any_ DV route to this neighbour is currently 5402 /* Check if _any_ DV route to this neighbour is currently
5606 valid, if so, do NOT tell core about the loss of direct 5403 valid, if so, do NOT tell core about the loss of direct
5607 connectivity (DV still counts!) */ 5404 connectivity (DV still counts!) */
5608 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, 5405 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &n->pid);
5609 &n->pid);
5610 if (GNUNET_YES == dv->core_visible) 5406 if (GNUNET_YES == dv->core_visible)
5611 return; 5407 return;
5612 /* Nothing works anymore, need to tell CORE about the loss of 5408 /* Nothing works anymore, need to tell CORE about the loss of
@@ -5616,9 +5412,11 @@ update_neighbour_core_visibility (struct Neighbour *n)
5616 5412
5617 5413
5618/** 5414/**
5619 * Communicator gave us a transport address validation response. Process the request. 5415 * Communicator gave us a transport address validation response. Process the
5416 * request.
5620 * 5417 *
5621 * @param cls a `struct CommunicatorMessageContext` (must call #finish_cmc_handling() when done) 5418 * @param cls a `struct CommunicatorMessageContext` (must call
5419 * #finish_cmc_handling() when done)
5622 * @param tvr the message that was received 5420 * @param tvr the message that was received
5623 */ 5421 */
5624static void 5422static void
@@ -5627,10 +5425,8 @@ handle_validation_response (void *cls,
5627{ 5425{
5628 struct CommunicatorMessageContext *cmc = cls; 5426 struct CommunicatorMessageContext *cmc = cls;
5629 struct ValidationState *vs; 5427 struct ValidationState *vs;
5630 struct CheckKnownChallengeContext ckac = { 5428 struct CheckKnownChallengeContext ckac = {.challenge = &tvr->challenge,
5631 .challenge = &tvr->challenge, 5429 .vs = NULL};
5632 .vs = NULL
5633 };
5634 struct GNUNET_TIME_Absolute origin_time; 5430 struct GNUNET_TIME_Absolute origin_time;
5635 struct Queue *q; 5431 struct Queue *q;
5636 struct DistanceVector *dv; 5432 struct DistanceVector *dv;
@@ -5654,8 +5450,8 @@ handle_validation_response (void *cls,
5654 5450
5655 /* sanity check on origin time */ 5451 /* sanity check on origin time */
5656 origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time); 5452 origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time);
5657 if ( (origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) || 5453 if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) ||
5658 (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us) ) 5454 (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us))
5659 { 5455 {
5660 GNUNET_break_op (0); 5456 GNUNET_break_op (0);
5661 finish_cmc_handling (cmc); 5457 finish_cmc_handling (cmc);
@@ -5664,18 +5460,18 @@ handle_validation_response (void *cls,
5664 5460
5665 { 5461 {
5666 /* check signature */ 5462 /* check signature */
5667 struct TransportValidationPS tvp = { 5463 struct TransportValidationPS tvp =
5668 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), 5464 {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
5669 .purpose.size = htonl (sizeof (tvp)), 5465 .purpose.size = htonl (sizeof (tvp)),
5670 .validity_duration = tvr->validity_duration, 5466 .validity_duration = tvr->validity_duration,
5671 .challenge = tvr->challenge 5467 .challenge = tvr->challenge};
5672 }; 5468
5673 5469 if (
5674 if (GNUNET_OK != 5470 GNUNET_OK !=
5675 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, 5471 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE,
5676 &tvp.purpose, 5472 &tvp.purpose,
5677 &tvr->signature, 5473 &tvr->signature,
5678 &cmc->im.sender.public_key)) 5474 &cmc->im.sender.public_key))
5679 { 5475 {
5680 GNUNET_break_op (0); 5476 GNUNET_break_op (0);
5681 finish_cmc_handling (cmc); 5477 finish_cmc_handling (cmc);
@@ -5685,23 +5481,26 @@ handle_validation_response (void *cls,
5685 5481
5686 /* validity is capped by our willingness to keep track of the 5482 /* validity is capped by our willingness to keep track of the
5687 validation entry and the maximum the other peer allows */ 5483 validation entry and the maximum the other peer allows */
5688 vs->valid_until 5484 vs->valid_until = GNUNET_TIME_relative_to_absolute (
5689 = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_min (GNUNET_TIME_relative_ntoh (tvr->validity_duration), 5485 GNUNET_TIME_relative_min (GNUNET_TIME_relative_ntoh (
5690 MAX_ADDRESS_VALID_UNTIL)); 5486 tvr->validity_duration),
5691 vs->validated_until 5487 MAX_ADDRESS_VALID_UNTIL));
5692 = GNUNET_TIME_absolute_min (vs->valid_until, 5488 vs->validated_until =
5693 GNUNET_TIME_relative_to_absolute (ADDRESS_VALIDATION_LIFETIME)); 5489 GNUNET_TIME_absolute_min (vs->valid_until,
5490 GNUNET_TIME_relative_to_absolute (
5491 ADDRESS_VALIDATION_LIFETIME));
5694 vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time); 5492 vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time);
5695 vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO; 5493 vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO;
5696 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 5494 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
5697 &vs->challenge, 5495 &vs->challenge,
5698 sizeof (vs->challenge)); 5496 sizeof (vs->challenge));
5699 vs->first_challenge_use = GNUNET_TIME_absolute_subtract (vs->validated_until, 5497 vs->first_challenge_use = GNUNET_TIME_absolute_subtract (
5700 GNUNET_TIME_relative_multiply (vs->validation_rtt, 5498 vs->validated_until,
5701 VALIDATION_RTT_BUFFER_FACTOR)); 5499 GNUNET_TIME_relative_multiply (vs->validation_rtt,
5702 vs->last_challenge_use = GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */ 5500 VALIDATION_RTT_BUFFER_FACTOR));
5703 update_next_challenge_time (vs, 5501 vs->last_challenge_use =
5704 vs->first_challenge_use); 5502 GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */
5503 update_next_challenge_time (vs, vs->first_challenge_use);
5705 vs->sc = GNUNET_PEERSTORE_store (peerstore, 5504 vs->sc = GNUNET_PEERSTORE_store (peerstore,
5706 "transport", 5505 "transport",
5707 &cmc->im.sender, 5506 &cmc->im.sender,
@@ -5716,8 +5515,7 @@ handle_validation_response (void *cls,
5716 5515
5717 /* Finally, we now possibly have a confirmed (!) working queue, 5516 /* Finally, we now possibly have a confirmed (!) working queue,
5718 update queue status (if queue still is around) */ 5517 update queue status (if queue still is around) */
5719 q = find_queue (&vs->pid, 5518 q = find_queue (&vs->pid, vs->address);
5720 vs->address);
5721 if (NULL == q) 5519 if (NULL == q)
5722 { 5520 {
5723 GNUNET_STATISTICS_update (GST_stats, 5521 GNUNET_STATISTICS_update (GST_stats,
@@ -5731,20 +5529,17 @@ handle_validation_response (void *cls,
5731 if (GNUNET_NO != q->neighbour->core_visible) 5529 if (GNUNET_NO != q->neighbour->core_visible)
5732 return; /* nothing changed, we are done here */ 5530 return; /* nothing changed, we are done here */
5733 q->neighbour->core_visible = GNUNET_YES; 5531 q->neighbour->core_visible = GNUNET_YES;
5734 q->visibility_task 5532 q->visibility_task = GNUNET_SCHEDULER_add_at (q->validated_until,
5735 = GNUNET_SCHEDULER_add_at (q->validated_until, 5533 &core_queue_visibility_check,
5736 &core_queue_visibility_check, 5534 q);
5737 q);
5738 /* Check if _any_ DV route to this neighbour is 5535 /* Check if _any_ DV route to this neighbour is
5739 currently valid, if so, do NOT tell core anything! */ 5536 currently valid, if so, do NOT tell core anything! */
5740 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, 5537 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &q->neighbour->pid);
5741 &q->neighbour->pid);
5742 if (GNUNET_YES == dv->core_visible) 5538 if (GNUNET_YES == dv->core_visible)
5743 return; /* nothing changed, done */ 5539 return; /* nothing changed, done */
5744 /* We lacked a confirmed connection to the neighbour 5540 /* We lacked a confirmed connection to the neighbour
5745 before, so tell CORE about it (finally!) */ 5541 before, so tell CORE about it (finally!) */
5746 cores_send_connect_info (&q->neighbour->pid, 5542 cores_send_connect_info (&q->neighbour->pid, GNUNET_BANDWIDTH_ZERO);
5747 GNUNET_BANDWIDTH_ZERO);
5748} 5543}
5749 5544
5750 5545
@@ -5758,12 +5553,12 @@ handle_incoming_msg (void *cls,
5758 const struct GNUNET_TRANSPORT_IncomingMessage *im) 5553 const struct GNUNET_TRANSPORT_IncomingMessage *im)
5759{ 5554{
5760 struct TransportClient *tc = cls; 5555 struct TransportClient *tc = cls;
5761 struct CommunicatorMessageContext *cmc = GNUNET_new (struct CommunicatorMessageContext); 5556 struct CommunicatorMessageContext *cmc =
5557 GNUNET_new (struct CommunicatorMessageContext);
5762 5558
5763 cmc->tc = tc; 5559 cmc->tc = tc;
5764 cmc->im = *im; 5560 cmc->im = *im;
5765 demultiplex_with_cmc (cmc, 5561 demultiplex_with_cmc (cmc, (const struct GNUNET_MessageHeader *) &im[1]);
5766 (const struct GNUNET_MessageHeader *) &im[1]);
5767} 5562}
5768 5563
5769 5564
@@ -5778,49 +5573,49 @@ static void
5778demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, 5573demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
5779 const struct GNUNET_MessageHeader *msg) 5574 const struct GNUNET_MessageHeader *msg)
5780{ 5575{
5781 struct GNUNET_MQ_MessageHandler handlers[] = { 5576 struct GNUNET_MQ_MessageHandler handlers[] =
5782 GNUNET_MQ_hd_var_size (fragment_box, 5577 {GNUNET_MQ_hd_var_size (fragment_box,
5783 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, 5578 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT,
5784 struct TransportFragmentBox, 5579 struct TransportFragmentBox,
5785 &cmc), 5580 &cmc),
5786 GNUNET_MQ_hd_fixed_size (fragment_ack, 5581 GNUNET_MQ_hd_fixed_size (fragment_ack,
5787 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT_ACK, 5582 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT_ACK,
5788 struct TransportFragmentAckMessage, 5583 struct TransportFragmentAckMessage,
5789 &cmc), 5584 &cmc),
5790 GNUNET_MQ_hd_var_size (reliability_box, 5585 GNUNET_MQ_hd_var_size (reliability_box,
5791 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, 5586 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX,
5792 struct TransportReliabilityBox, 5587 struct TransportReliabilityBox,
5793 &cmc), 5588 &cmc),
5794 GNUNET_MQ_hd_fixed_size (reliability_ack, 5589 GNUNET_MQ_hd_fixed_size (reliability_ack,
5795 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, 5590 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK,
5796 struct TransportReliabilityAckMessage, 5591 struct TransportReliabilityAckMessage,
5797 &cmc), 5592 &cmc),
5798 GNUNET_MQ_hd_var_size (backchannel_encapsulation, 5593 GNUNET_MQ_hd_var_size (backchannel_encapsulation,
5799 GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, 5594 GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION,
5800 struct TransportBackchannelEncapsulationMessage, 5595 struct TransportBackchannelEncapsulationMessage,
5801 &cmc), 5596 &cmc),
5802 GNUNET_MQ_hd_var_size (dv_learn, 5597 GNUNET_MQ_hd_var_size (dv_learn,
5803 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, 5598 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN,
5804 struct TransportDVLearn, 5599 struct TransportDVLearn,
5805 &cmc), 5600 &cmc),
5806 GNUNET_MQ_hd_var_size (dv_box, 5601 GNUNET_MQ_hd_var_size (dv_box,
5807 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, 5602 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX,
5808 struct TransportDVBox, 5603 struct TransportDVBox,
5809 &cmc), 5604 &cmc),
5810 GNUNET_MQ_hd_fixed_size (validation_challenge, 5605 GNUNET_MQ_hd_fixed_size (
5811 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE, 5606 validation_challenge,
5812 struct TransportValidationChallenge, 5607 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE,
5813 &cmc), 5608 struct TransportValidationChallenge,
5814 GNUNET_MQ_hd_fixed_size (validation_response, 5609 &cmc),
5815 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE, 5610 GNUNET_MQ_hd_fixed_size (
5816 struct TransportValidationResponse, 5611 validation_response,
5817 &cmc), 5612 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE,
5818 GNUNET_MQ_handler_end() 5613 struct TransportValidationResponse,
5819 }; 5614 &cmc),
5615 GNUNET_MQ_handler_end ()};
5820 int ret; 5616 int ret;
5821 5617
5822 ret = GNUNET_MQ_handle_message (handlers, 5618 ret = GNUNET_MQ_handle_message (handlers, msg);
5823 msg);
5824 if (GNUNET_SYSERR == ret) 5619 if (GNUNET_SYSERR == ret)
5825 { 5620 {
5826 GNUNET_break (0); 5621 GNUNET_break (0);
@@ -5831,8 +5626,7 @@ demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
5831 if (GNUNET_NO == ret) 5626 if (GNUNET_NO == ret)
5832 { 5627 {
5833 /* unencapsulated 'raw' message */ 5628 /* unencapsulated 'raw' message */
5834 handle_raw_message (&cmc, 5629 handle_raw_message (&cmc, msg);
5835 msg);
5836 } 5630 }
5837} 5631}
5838 5632
@@ -5873,8 +5667,7 @@ tracker_update_in_cb (void *cls)
5873 unsigned int rsize; 5667 unsigned int rsize;
5874 5668
5875 rsize = (0 == queue->mtu) ? IN_PACKET_SIZE_WITHOUT_MTU : queue->mtu; 5669 rsize = (0 == queue->mtu) ? IN_PACKET_SIZE_WITHOUT_MTU : queue->mtu;
5876 in_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_in, 5670 in_delay = GNUNET_BANDWIDTH_tracker_get_delay (&queue->tracker_in, rsize);
5877 rsize);
5878 // FIXME: how exactly do we do inbound flow control? 5671 // FIXME: how exactly do we do inbound flow control?
5879} 5672}
5880 5673
@@ -5907,8 +5700,7 @@ set_pending_message_uuid (struct PendingMessage *pm)
5907 * @return new message to transmit 5700 * @return new message to transmit
5908 */ 5701 */
5909static struct PendingMessage * 5702static struct PendingMessage *
5910fragment_message (struct PendingMessage *pm, 5703fragment_message (struct PendingMessage *pm, uint16_t mtu)
5911 uint16_t mtu)
5912{ 5704{
5913 struct PendingMessage *ff; 5705 struct PendingMessage *ff;
5914 5706
@@ -5918,19 +5710,16 @@ fragment_message (struct PendingMessage *pm,
5918 GNUNET_assert (mtu > sizeof (struct TransportFragmentBox)); 5710 GNUNET_assert (mtu > sizeof (struct TransportFragmentBox));
5919 5711
5920 /* select fragment for transmission, descending the tree if it has 5712 /* select fragment for transmission, descending the tree if it has
5921 been expanded until we are at a leaf or at a fragment that is small enough */ 5713 been expanded until we are at a leaf or at a fragment that is small enough
5714 */
5922 ff = pm; 5715 ff = pm;
5923 while ( ( (ff->bytes_msg > mtu) || 5716 while (((ff->bytes_msg > mtu) || (pm == ff)) &&
5924 (pm == ff) ) && 5717 (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag))
5925 (ff->frag_off == ff->bytes_msg) &&
5926 (NULL != ff->head_frag) )
5927 { 5718 {
5928 ff = ff->head_frag; /* descent into fragmented fragments */ 5719 ff = ff->head_frag; /* descent into fragmented fragments */
5929 } 5720 }
5930 5721
5931 if ( ( (ff->bytes_msg > mtu) || 5722 if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg))
5932 (pm == ff) ) &&
5933 (pm->frag_off < pm->bytes_msg) )
5934 { 5723 {
5935 /* Did not yet calculate all fragments, calculate next fragment */ 5724 /* Did not yet calculate all fragments, calculate next fragment */
5936 struct PendingMessage *frag; 5725 struct PendingMessage *frag;
@@ -5954,11 +5743,9 @@ fragment_message (struct PendingMessage *pm,
5954 xoff = ntohs (tfbo->frag_off); 5743 xoff = ntohs (tfbo->frag_off);
5955 } 5744 }
5956 fragmax = mtu - sizeof (struct TransportFragmentBox); 5745 fragmax = mtu - sizeof (struct TransportFragmentBox);
5957 fragsize = GNUNET_MIN (msize - ff->frag_off, 5746 fragsize = GNUNET_MIN (msize - ff->frag_off, fragmax);
5958 fragmax);
5959 frag = GNUNET_malloc (sizeof (struct PendingMessage) + 5747 frag = GNUNET_malloc (sizeof (struct PendingMessage) +
5960 sizeof (struct TransportFragmentBox) + 5748 sizeof (struct TransportFragmentBox) + fragsize);
5961 fragsize);
5962 frag->target = pm->target; 5749 frag->target = pm->target;
5963 frag->frag_parent = ff; 5750 frag->frag_parent = ff;
5964 frag->timeout = pm->timeout; 5751 frag->timeout = pm->timeout;
@@ -5966,35 +5753,27 @@ fragment_message (struct PendingMessage *pm,
5966 frag->pmt = PMT_FRAGMENT_BOX; 5753 frag->pmt = PMT_FRAGMENT_BOX;
5967 msg = (char *) &frag[1]; 5754 msg = (char *) &frag[1];
5968 tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); 5755 tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT);
5969 tfb.header.size = htons (sizeof (struct TransportFragmentBox) + 5756 tfb.header.size = htons (sizeof (struct TransportFragmentBox) + fragsize);
5970 fragsize);
5971 tfb.frag_uuid = htonl (pm->frag_uuidgen++); 5757 tfb.frag_uuid = htonl (pm->frag_uuidgen++);
5972 tfb.msg_uuid = pm->msg_uuid; 5758 tfb.msg_uuid = pm->msg_uuid;
5973 tfb.frag_off = htons (ff->frag_off + xoff); 5759 tfb.frag_off = htons (ff->frag_off + xoff);
5974 tfb.msg_size = htons (pm->bytes_msg); 5760 tfb.msg_size = htons (pm->bytes_msg);
5975 memcpy (msg, 5761 memcpy (msg, &tfb, sizeof (tfb));
5976 &tfb, 5762 memcpy (&msg[sizeof (tfb)], &orig[ff->frag_off], fragsize);
5977 sizeof (tfb)); 5763 GNUNET_CONTAINER_MDLL_insert (frag, ff->head_frag, ff->tail_frag, frag);
5978 memcpy (&msg[sizeof (tfb)],
5979 &orig[ff->frag_off],
5980 fragsize);
5981 GNUNET_CONTAINER_MDLL_insert (frag,
5982 ff->head_frag,
5983 ff->tail_frag,
5984 frag);
5985 ff->frag_off += fragsize; 5764 ff->frag_off += fragsize;
5986 ff = frag; 5765 ff = frag;
5987 } 5766 }
5988 5767
5989 /* Move head to the tail and return it */ 5768 /* Move head to the tail and return it */
5990 GNUNET_CONTAINER_MDLL_remove (frag, 5769 GNUNET_CONTAINER_MDLL_remove (frag,
5991 ff->frag_parent->head_frag, 5770 ff->frag_parent->head_frag,
5992 ff->frag_parent->tail_frag, 5771 ff->frag_parent->tail_frag,
5993 ff); 5772 ff);
5994 GNUNET_CONTAINER_MDLL_insert_tail (frag, 5773 GNUNET_CONTAINER_MDLL_insert_tail (frag,
5995 ff->frag_parent->head_frag, 5774 ff->frag_parent->head_frag,
5996 ff->frag_parent->tail_frag, 5775 ff->frag_parent->tail_frag,
5997 ff); 5776 ff);
5998 return ff; 5777 return ff;
5999} 5778}
6000 5779
@@ -6017,7 +5796,8 @@ reliability_box_message (struct PendingMessage *pm)
6017 char *msg; 5796 char *msg;
6018 5797
6019 if (PMT_CORE != pm->pmt) 5798 if (PMT_CORE != pm->pmt)
6020 return pm; /* already fragmented or reliability boxed, or control message: do nothing */ 5799 return pm; /* already fragmented or reliability boxed, or control message:
5800 do nothing */
6021 if (NULL != pm->bpm) 5801 if (NULL != pm->bpm)
6022 return pm->bpm; /* already computed earlier: do nothing */ 5802 return pm->bpm; /* already computed earlier: do nothing */
6023 GNUNET_assert (NULL == pm->head_frag); 5803 GNUNET_assert (NULL == pm->head_frag);
@@ -6025,20 +5805,14 @@ reliability_box_message (struct PendingMessage *pm)
6025 { 5805 {
6026 /* failed hard */ 5806 /* failed hard */
6027 GNUNET_break (0); 5807 GNUNET_break (0);
6028 client_send_response (pm, 5808 client_send_response (pm, GNUNET_NO, 0);
6029 GNUNET_NO,
6030 0);
6031 return NULL; 5809 return NULL;
6032 } 5810 }
6033 bpm = GNUNET_malloc (sizeof (struct PendingMessage) + 5811 bpm = GNUNET_malloc (sizeof (struct PendingMessage) + sizeof (rbox) +
6034 sizeof (rbox) +
6035 pm->bytes_msg); 5812 pm->bytes_msg);
6036 bpm->target = pm->target; 5813 bpm->target = pm->target;
6037 bpm->frag_parent = pm; 5814 bpm->frag_parent = pm;
6038 GNUNET_CONTAINER_MDLL_insert (frag, 5815 GNUNET_CONTAINER_MDLL_insert (frag, pm->head_frag, pm->tail_frag, bpm);
6039 pm->head_frag,
6040 pm->tail_frag,
6041 bpm);
6042 bpm->timeout = pm->timeout; 5816 bpm->timeout = pm->timeout;
6043 bpm->pmt = PMT_RELIABILITY_BOX; 5817 bpm->pmt = PMT_RELIABILITY_BOX;
6044 bpm->bytes_msg = pm->bytes_msg + sizeof (rbox); 5818 bpm->bytes_msg = pm->bytes_msg + sizeof (rbox);
@@ -6048,12 +5822,8 @@ reliability_box_message (struct PendingMessage *pm)
6048 rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support 5822 rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support
6049 rbox.msg_uuid = pm->msg_uuid; 5823 rbox.msg_uuid = pm->msg_uuid;
6050 msg = (char *) &bpm[1]; 5824 msg = (char *) &bpm[1];
6051 memcpy (msg, 5825 memcpy (msg, &rbox, sizeof (rbox));
6052 &rbox, 5826 memcpy (&msg[sizeof (rbox)], &pm[1], pm->bytes_msg);
6053 sizeof (rbox));
6054 memcpy (&msg[sizeof (rbox)],
6055 &pm[1],
6056 pm->bytes_msg);
6057 pm->bpm = bpm; 5827 pm->bpm = bpm;
6058 return bpm; 5828 return bpm;
6059} 5829}
@@ -6097,8 +5867,9 @@ transmit_on_queue (void *cls)
6097 this queue */) ) 5867 this queue */) )
6098 s = fragment_message (s, 5868 s = fragment_message (s,
6099 (0 == queue->mtu) 5869 (0 == queue->mtu)
6100 ? UINT16_MAX - sizeof (struct GNUNET_TRANSPORT_SendMessageTo) 5870 ? UINT16_MAX -
6101 : queue->mtu); 5871 sizeof (struct GNUNET_TRANSPORT_SendMessageTo)
5872 : queue->mtu);
6102 if (NULL == s) 5873 if (NULL == s)
6103 { 5874 {
6104 /* Fragmentation failed, try next message... */ 5875 /* Fragmentation failed, try next message... */
@@ -6115,56 +5886,45 @@ transmit_on_queue (void *cls)
6115 } 5886 }
6116 5887
6117 /* Pass 's' for transission to the communicator */ 5888 /* Pass 's' for transission to the communicator */
6118 queue_send_msg (queue, 5889 queue_send_msg (queue, s, &s[1], s->bytes_msg);
6119 s,
6120 &s[1],
6121 s->bytes_msg);
6122 // FIXME: do something similar to the logic below 5890 // FIXME: do something similar to the logic below
6123 // in defragmentation / reliability ACK handling! 5891 // in defragmentation / reliability ACK handling!
6124 5892
6125 /* Check if this transmission somehow conclusively finished handing 'pm' 5893 /* Check if this transmission somehow conclusively finished handing 'pm'
6126 even without any explicit ACKs */ 5894 even without any explicit ACKs */
6127 if ( (PMT_CORE == s->pmt) && 5895 if ((PMT_CORE == s->pmt) &&
6128 (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) ) 5896 (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc))
6129 { 5897 {
6130 /* Full message sent, and over reliabile channel */ 5898 /* Full message sent, and over reliabile channel */
6131 client_send_response (pm, 5899 client_send_response (pm, GNUNET_YES, pm->bytes_msg);
6132 GNUNET_YES,
6133 pm->bytes_msg);
6134 } 5900 }
6135 else if ( (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) && 5901 else if ((GNUNET_TRANSPORT_CC_RELIABLE ==
6136 (PMT_FRAGMENT_BOX == s->pmt) ) 5902 queue->tc->details.communicator.cc) &&
5903 (PMT_FRAGMENT_BOX == s->pmt))
6137 { 5904 {
6138 struct PendingMessage *pos; 5905 struct PendingMessage *pos;
6139 5906
6140 /* Fragment sent over reliabile channel */ 5907 /* Fragment sent over reliabile channel */
6141 free_fragment_tree (s); 5908 free_fragment_tree (s);
6142 pos = s->frag_parent; 5909 pos = s->frag_parent;
6143 GNUNET_CONTAINER_MDLL_remove (frag, 5910 GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, s);
6144 pos->head_frag,
6145 pos->tail_frag,
6146 s);
6147 GNUNET_free (s); 5911 GNUNET_free (s);
6148 /* check if subtree is done */ 5912 /* check if subtree is done */
6149 while ( (NULL == pos->head_frag) && 5913 while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) &&
6150 (pos->frag_off == pos->bytes_msg) && 5914 (pos != pm))
6151 (pos != pm) )
6152 { 5915 {
6153 s = pos; 5916 s = pos;
6154 pos = s->frag_parent; 5917 pos = s->frag_parent;
6155 GNUNET_CONTAINER_MDLL_remove (frag, 5918 GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, s);
6156 pos->head_frag,
6157 pos->tail_frag,
6158 s);
6159 GNUNET_free (s); 5919 GNUNET_free (s);
6160 } 5920 }
6161 5921
6162 /* Was this the last applicable fragmment? */ 5922 /* Was this the last applicable fragmment? */
6163 if ( (NULL == pm->head_frag) && 5923 if ((NULL == pm->head_frag) && (pm->frag_off == pm->bytes_msg))
6164 (pm->frag_off == pm->bytes_msg) ) 5924 client_send_response (
6165 client_send_response (pm, 5925 pm,
6166 GNUNET_YES, 5926 GNUNET_YES,
6167 pm->bytes_msg /* FIXME: calculate and add overheads! */); 5927 pm->bytes_msg /* FIXME: calculate and add overheads! */);
6168 } 5928 }
6169 else if (PMT_CORE != pm->pmt) 5929 else if (PMT_CORE != pm->pmt)
6170 { 5930 {
@@ -6182,9 +5942,8 @@ transmit_on_queue (void *cls)
6182 retransmitting. Note that in the future this heuristic should 5942 retransmitting. Note that in the future this heuristic should
6183 likely be improved further (measure RTT stability, consider 5943 likely be improved further (measure RTT stability, consider
6184 message urgency and size when delaying ACKs, etc.) */ 5944 message urgency and size when delaying ACKs, etc.) */
6185 s->next_attempt = GNUNET_TIME_relative_to_absolute 5945 s->next_attempt = GNUNET_TIME_relative_to_absolute (
6186 (GNUNET_TIME_relative_multiply (queue->rtt, 5946 GNUNET_TIME_relative_multiply (queue->rtt, 4));
6187 4));
6188 if (s == pm) 5947 if (s == pm)
6189 { 5948 {
6190 struct PendingMessage *pos; 5949 struct PendingMessage *pos;
@@ -6195,8 +5954,8 @@ transmit_on_queue (void *cls)
6195 neighbour->pending_msg_tail, 5954 neighbour->pending_msg_tail,
6196 pm); 5955 pm);
6197 pos = neighbour->pending_msg_tail; 5956 pos = neighbour->pending_msg_tail;
6198 while ( (NULL != pos) && 5957 while ((NULL != pos) &&
6199 (pm->next_attempt.abs_value_us > pos->next_attempt.abs_value_us) ) 5958 (pm->next_attempt.abs_value_us > pos->next_attempt.abs_value_us))
6200 pos = pos->prev_neighbour; 5959 pos = pos->prev_neighbour;
6201 GNUNET_CONTAINER_MDLL_insert_after (neighbour, 5960 GNUNET_CONTAINER_MDLL_insert_after (neighbour,
6202 neighbour->pending_msg_head, 5961 neighbour->pending_msg_head,
@@ -6210,13 +5969,10 @@ transmit_on_queue (void *cls)
6210 struct PendingMessage *fp = s->frag_parent; 5969 struct PendingMessage *fp = s->frag_parent;
6211 struct PendingMessage *pos; 5970 struct PendingMessage *pos;
6212 5971
6213 GNUNET_CONTAINER_MDLL_remove (frag, 5972 GNUNET_CONTAINER_MDLL_remove (frag, fp->head_frag, fp->tail_frag, s);
6214 fp->head_frag,
6215 fp->tail_frag,
6216 s);
6217 pos = fp->tail_frag; 5973 pos = fp->tail_frag;
6218 while ( (NULL != pos) && 5974 while ((NULL != pos) &&
6219 (s->next_attempt.abs_value_us > pos->next_attempt.abs_value_us) ) 5975 (s->next_attempt.abs_value_us > pos->next_attempt.abs_value_us))
6220 pos = pos->prev_frag; 5976 pos = pos->prev_frag;
6221 GNUNET_CONTAINER_MDLL_insert_after (frag, 5977 GNUNET_CONTAINER_MDLL_insert_after (frag,
6222 fp->head_frag, 5978 fp->head_frag,
@@ -6246,8 +6002,8 @@ tracker_update_out_cb (void *cls)
6246 if (NULL == n->pending_msg_head) 6002 if (NULL == n->pending_msg_head)
6247 { 6003 {
6248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6249 "Bandwidth allocation updated for empty transmission queue `%s'\n", 6005 "Bandwidth allocation updated for empty transmission queue `%s'\n",
6250 queue->address); 6006 queue->address);
6251 return; /* no message pending, nothing to do here! */ 6007 return; /* no message pending, nothing to do here! */
6252 } 6008 }
6253 GNUNET_SCHEDULER_cancel (queue->transmit_task); 6009 GNUNET_SCHEDULER_cancel (queue->transmit_task);
@@ -6279,7 +6035,6 @@ tracker_excess_out_cb (void *cls)
6279} 6035}
6280 6036
6281 6037
6282
6283/** 6038/**
6284 * Bandwidth tracker informs us that excessive inbound bandwidth was allocated 6039 * Bandwidth tracker informs us that excessive inbound bandwidth was allocated
6285 * which is not being used. 6040 * which is not being used.
@@ -6317,15 +6072,13 @@ handle_del_queue_message (void *cls,
6317 GNUNET_SERVICE_client_drop (tc->client); 6072 GNUNET_SERVICE_client_drop (tc->client);
6318 return; 6073 return;
6319 } 6074 }
6320 for (struct Queue *queue = tc->details.communicator.queue_head; 6075 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue;
6321 NULL != queue;
6322 queue = queue->next_client) 6076 queue = queue->next_client)
6323 { 6077 {
6324 struct Neighbour *neighbour = queue->neighbour; 6078 struct Neighbour *neighbour = queue->neighbour;
6325 6079
6326 if ( (dqm->qid != queue->qid) || 6080 if ((dqm->qid != queue->qid) ||
6327 (0 != GNUNET_memcmp (&dqm->receiver, 6081 (0 != GNUNET_memcmp (&dqm->receiver, &neighbour->pid)))
6328 &neighbour->pid)) )
6329 continue; 6082 continue;
6330 free_queue (queue); 6083 free_queue (queue);
6331 GNUNET_SERVICE_client_continue (tc->client); 6084 GNUNET_SERVICE_client_continue (tc->client);
@@ -6358,15 +6111,12 @@ handle_send_message_ack (void *cls,
6358 6111
6359 /* find our queue entry matching the ACK */ 6112 /* find our queue entry matching the ACK */
6360 qe = NULL; 6113 qe = NULL;
6361 for (struct Queue *queue = tc->details.communicator.queue_head; 6114 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue;
6362 NULL != queue;
6363 queue = queue->next_client) 6115 queue = queue->next_client)
6364 { 6116 {
6365 if (0 != GNUNET_memcmp (&queue->neighbour->pid, 6117 if (0 != GNUNET_memcmp (&queue->neighbour->pid, &sma->receiver))
6366 &sma->receiver))
6367 continue; 6118 continue;
6368 for (struct QueueEntry *qep = queue->queue_head; 6119 for (struct QueueEntry *qep = queue->queue_head; NULL != qep;
6369 NULL != qep;
6370 qep = qep->next) 6120 qep = qep->next)
6371 { 6121 {
6372 if (qep->mid != sma->mid) 6122 if (qep->mid != sma->mid)
@@ -6391,13 +6141,15 @@ handle_send_message_ack (void *cls,
6391 GNUNET_SERVICE_client_continue (tc->client); 6141 GNUNET_SERVICE_client_continue (tc->client);
6392 6142
6393 /* if applicable, resume transmissions that waited on ACK */ 6143 /* if applicable, resume transmissions that waited on ACK */
6394 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 == tc->details.communicator.total_queue_length) 6144 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 ==
6145 tc->details.communicator.total_queue_length)
6395 { 6146 {
6396 /* Communicator dropped below threshold, resume all queues */ 6147 /* Communicator dropped below threshold, resume all queues */
6397 GNUNET_STATISTICS_update (GST_stats, 6148 GNUNET_STATISTICS_update (
6398 "# Transmission throttled due to communicator queue limit", 6149 GST_stats,
6399 -1, 6150 "# Transmission throttled due to communicator queue limit",
6400 GNUNET_NO); 6151 -1,
6152 GNUNET_NO);
6401 for (struct Queue *queue = tc->details.communicator.queue_head; 6153 for (struct Queue *queue = tc->details.communicator.queue_head;
6402 NULL != queue; 6154 NULL != queue;
6403 queue = queue->next_client) 6155 queue = queue->next_client)
@@ -6440,22 +6192,15 @@ notify_client_queues (void *cls,
6440 struct Neighbour *neighbour = value; 6192 struct Neighbour *neighbour = value;
6441 6193
6442 GNUNET_assert (CT_MONITOR == tc->type); 6194 GNUNET_assert (CT_MONITOR == tc->type);
6443 for (struct Queue *q = neighbour->queue_head; 6195 for (struct Queue *q = neighbour->queue_head; NULL != q;
6444 NULL != q;
6445 q = q->next_neighbour) 6196 q = q->next_neighbour)
6446 { 6197 {
6447 struct MonitorEvent me = { 6198 struct MonitorEvent me = {.rtt = q->rtt,
6448 .rtt = q->rtt, 6199 .cs = q->cs,
6449 .cs = q->cs, 6200 .num_msg_pending = q->num_msg_pending,
6450 .num_msg_pending = q->num_msg_pending, 6201 .num_bytes_pending = q->num_bytes_pending};
6451 .num_bytes_pending = q->num_bytes_pending
6452 };
6453 6202
6454 notify_monitor (tc, 6203 notify_monitor (tc, pid, q->address, q->nt, &me);
6455 pid,
6456 q->address,
6457 q->nt,
6458 &me);
6459 } 6204 }
6460 return GNUNET_OK; 6205 return GNUNET_OK;
6461} 6206}
@@ -6482,9 +6227,7 @@ handle_monitor_start (void *cls,
6482 tc->type = CT_MONITOR; 6227 tc->type = CT_MONITOR;
6483 tc->details.monitor.peer = start->peer; 6228 tc->details.monitor.peer = start->peer;
6484 tc->details.monitor.one_shot = ntohl (start->one_shot); 6229 tc->details.monitor.one_shot = ntohl (start->one_shot);
6485 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 6230 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &notify_client_queues, tc);
6486 &notify_client_queues,
6487 tc);
6488 GNUNET_SERVICE_client_mark_monitor (tc->client); 6231 GNUNET_SERVICE_client_mark_monitor (tc->client);
6489 GNUNET_SERVICE_client_continue (tc->client); 6232 GNUNET_SERVICE_client_continue (tc->client);
6490} 6233}
@@ -6500,19 +6243,17 @@ handle_monitor_start (void *cls,
6500static struct TransportClient * 6243static struct TransportClient *
6501lookup_communicator (const char *prefix) 6244lookup_communicator (const char *prefix)
6502{ 6245{
6503 for (struct TransportClient *tc = clients_head; 6246 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
6504 NULL != tc;
6505 tc = tc->next)
6506 { 6247 {
6507 if (CT_COMMUNICATOR != tc->type) 6248 if (CT_COMMUNICATOR != tc->type)
6508 continue; 6249 continue;
6509 if (0 == strcmp (prefix, 6250 if (0 == strcmp (prefix, tc->details.communicator.address_prefix))
6510 tc->details.communicator.address_prefix))
6511 return tc; 6251 return tc;
6512 } 6252 }
6513 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 6253 GNUNET_log (
6514 "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n", 6254 GNUNET_ERROR_TYPE_WARNING,
6515 prefix); 6255 "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n",
6256 prefix);
6516 return NULL; 6257 return NULL;
6517} 6258}
6518 6259
@@ -6525,8 +6266,7 @@ lookup_communicator (const char *prefix)
6525 * @param address the address to try 6266 * @param address the address to try
6526 */ 6267 */
6527static void 6268static void
6528suggest_to_connect (const struct GNUNET_PeerIdentity *pid, 6269suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address)
6529 const char *address)
6530{ 6270{
6531 static uint32_t idgen; 6271 static uint32_t idgen;
6532 struct TransportClient *tc; 6272 struct TransportClient *tc;
@@ -6557,16 +6297,12 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid,
6557 prefix, 6297 prefix,
6558 address); 6298 address);
6559 alen = strlen (address) + 1; 6299 alen = strlen (address) + 1;
6560 env = GNUNET_MQ_msg_extra (cqm, 6300 env =
6561 alen, 6301 GNUNET_MQ_msg_extra (cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
6562 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
6563 cqm->request_id = htonl (idgen++); 6302 cqm->request_id = htonl (idgen++);
6564 cqm->receiver = *pid; 6303 cqm->receiver = *pid;
6565 memcpy (&cqm[1], 6304 memcpy (&cqm[1], address, alen);
6566 address, 6305 GNUNET_MQ_send (tc->mq, env);
6567 alen);
6568 GNUNET_MQ_send (tc->mq,
6569 env);
6570} 6306}
6571 6307
6572 6308
@@ -6578,21 +6314,18 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid,
6578 * @param vs state to derive validation challenge from 6314 * @param vs state to derive validation challenge from
6579 */ 6315 */
6580static void 6316static void
6581validation_transmit_on_queue (struct Queue *q, 6317validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs)
6582 struct ValidationState *vs)
6583{ 6318{
6584 struct TransportValidationChallenge tvc; 6319 struct TransportValidationChallenge tvc;
6585 6320
6586 vs->last_challenge_use = GNUNET_TIME_absolute_get (); 6321 vs->last_challenge_use = GNUNET_TIME_absolute_get ();
6587 tvc.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); 6322 tvc.header.type =
6323 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE);
6588 tvc.header.size = htons (sizeof (tvc)); 6324 tvc.header.size = htons (sizeof (tvc));
6589 tvc.reserved = htonl (0); 6325 tvc.reserved = htonl (0);
6590 tvc.challenge = vs->challenge; 6326 tvc.challenge = vs->challenge;
6591 tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); 6327 tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use);
6592 queue_send_msg (q, 6328 queue_send_msg (q, NULL, &tvc, sizeof (tvc));
6593 NULL,
6594 &tvc,
6595 sizeof (tvc));
6596} 6329}
6597 6330
6598 6331
@@ -6611,8 +6344,9 @@ validation_start_cb (void *cls)
6611 validation_task = NULL; 6344 validation_task = NULL;
6612 vs = GNUNET_CONTAINER_heap_peek (validation_heap); 6345 vs = GNUNET_CONTAINER_heap_peek (validation_heap);
6613 /* drop validations past their expiration */ 6346 /* drop validations past their expiration */
6614 while ( (NULL != vs) && 6347 while (
6615 (0 == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us) ) 6348 (NULL != vs) &&
6349 (0 == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us))
6616 { 6350 {
6617 free_validation_state (vs); 6351 free_validation_state (vs);
6618 vs = GNUNET_CONTAINER_heap_peek (validation_heap); 6352 vs = GNUNET_CONTAINER_heap_peek (validation_heap);
@@ -6620,22 +6354,21 @@ validation_start_cb (void *cls)
6620 if (NULL == vs) 6354 if (NULL == vs)
6621 return; /* woopsie, no more addresses known, should only 6355 return; /* woopsie, no more addresses known, should only
6622 happen if we're really a lonely peer */ 6356 happen if we're really a lonely peer */
6623 q = find_queue (&vs->pid, 6357 q = find_queue (&vs->pid, vs->address);
6624 vs->address);
6625 if (NULL == q) 6358 if (NULL == q)
6626 { 6359 {
6627 vs->awaiting_queue = GNUNET_YES; 6360 vs->awaiting_queue = GNUNET_YES;
6628 suggest_to_connect (&vs->pid, 6361 suggest_to_connect (&vs->pid, vs->address);
6629 vs->address);
6630 } 6362 }
6631 else 6363 else
6632 validation_transmit_on_queue (q, 6364 validation_transmit_on_queue (q, vs);
6633 vs);
6634 /* Finally, reschedule next attempt */ 6365 /* Finally, reschedule next attempt */
6635 vs->challenge_backoff = GNUNET_TIME_randomized_backoff (vs->challenge_backoff, 6366 vs->challenge_backoff =
6636 MAX_VALIDATION_CHALLENGE_FREQ); 6367 GNUNET_TIME_randomized_backoff (vs->challenge_backoff,
6368 MAX_VALIDATION_CHALLENGE_FREQ);
6637 update_next_challenge_time (vs, 6369 update_next_challenge_time (vs,
6638 GNUNET_TIME_relative_to_absolute (vs->challenge_backoff)); 6370 GNUNET_TIME_relative_to_absolute (
6371 vs->challenge_backoff));
6639} 6372}
6640 6373
6641 6374
@@ -6664,7 +6397,6 @@ struct QueueQualityContext
6664 * k-th queue in @e q. 6397 * k-th queue in @e q.
6665 */ 6398 */
6666 unsigned int k; 6399 unsigned int k;
6667
6668}; 6400};
6669 6401
6670 6402
@@ -6690,9 +6422,7 @@ check_connection_quality (void *cls,
6690 6422
6691 (void) pid; 6423 (void) pid;
6692 do_inc = GNUNET_NO; 6424 do_inc = GNUNET_NO;
6693 for (struct Queue *q = n->queue_head; 6425 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
6694 NULL != q;
6695 q = q->next_neighbour)
6696 { 6426 {
6697 if (0 != q->distance) 6427 if (0 != q->distance)
6698 continue; /* DV does not count */ 6428 continue; /* DV does not count */
@@ -6730,8 +6460,7 @@ start_dv_learn (void *cls)
6730 6460
6731 (void) cls; 6461 (void) cls;
6732 dvlearn_task = NULL; 6462 dvlearn_task = NULL;
6733 if (0 == 6463 if (0 == GNUNET_CONTAINER_multipeermap_size (neighbours))
6734 GNUNET_CONTAINER_multipeermap_size (neighbours))
6735 return; /* lost all connectivity, cannot do learning */ 6464 return; /* lost all connectivity, cannot do learning */
6736 qqc.quality_count = 0; 6465 qqc.quality_count = 0;
6737 qqc.num_queues = 0; 6466 qqc.num_queues = 0;
@@ -6745,11 +6474,8 @@ start_dv_learn (void *cls)
6745 6474
6746 /* scale our retries by how far we are above the threshold */ 6475 /* scale our retries by how far we are above the threshold */
6747 factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; 6476 factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD;
6748 delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, 6477 delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, factor);
6749 factor); 6478 dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay, &start_dv_learn, NULL);
6750 dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay,
6751 &start_dv_learn,
6752 NULL);
6753 return; 6479 return;
6754 } 6480 }
6755 /* remove old entries in #dvlearn_map if it has grown too big */ 6481 /* remove old entries in #dvlearn_map if it has grown too big */
@@ -6761,9 +6487,7 @@ start_dv_learn (void *cls)
6761 GNUNET_CONTAINER_multishortmap_remove (dvlearn_map, 6487 GNUNET_CONTAINER_multishortmap_remove (dvlearn_map,
6762 &lle->challenge, 6488 &lle->challenge,
6763 lle)); 6489 lle));
6764 GNUNET_CONTAINER_DLL_remove (lle_head, 6490 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle);
6765 lle_tail,
6766 lle);
6767 GNUNET_free (lle); 6491 GNUNET_free (lle);
6768 } 6492 }
6769 /* setup data structure for learning */ 6493 /* setup data structure for learning */
@@ -6771,37 +6495,33 @@ start_dv_learn (void *cls)
6771 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 6495 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
6772 &lle->challenge, 6496 &lle->challenge,
6773 sizeof (lle->challenge)); 6497 sizeof (lle->challenge));
6774 GNUNET_CONTAINER_DLL_insert (lle_head, 6498 GNUNET_CONTAINER_DLL_insert (lle_head, lle_tail, lle);
6775 lle_tail,
6776 lle);
6777 GNUNET_break (GNUNET_YES == 6499 GNUNET_break (GNUNET_YES ==
6778 GNUNET_CONTAINER_multishortmap_put (dvlearn_map, 6500 GNUNET_CONTAINER_multishortmap_put (
6779 &lle->challenge, 6501 dvlearn_map,
6780 lle, 6502 &lle->challenge,
6781 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6503 lle,
6504 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
6782 dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); 6505 dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN);
6783 dvl.header.size = htons (sizeof (dvl)); 6506 dvl.header.size = htons (sizeof (dvl));
6784 dvl.num_hops = htons (0); 6507 dvl.num_hops = htons (0);
6785 dvl.bidirectional = htons (0); 6508 dvl.bidirectional = htons (0);
6786 dvl.non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); 6509 dvl.non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO);
6787 { 6510 {
6788 struct DvInitPS dvip = { 6511 struct DvInitPS dvip = {.purpose.purpose = htonl (
6789 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), 6512 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR),
6790 .purpose.size = htonl (sizeof (dvip)), 6513 .purpose.size = htonl (sizeof (dvip)),
6791 .challenge = lle->challenge 6514 .challenge = lle->challenge};
6792 };
6793 6515
6794 GNUNET_assert (GNUNET_OK == 6516 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
6795 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 6517 &dvip.purpose,
6796 &dvip.purpose, 6518 &dvl.init_sig));
6797 &dvl.init_sig));
6798 } 6519 }
6799 dvl.initiator = GST_my_identity; 6520 dvl.initiator = GST_my_identity;
6800 dvl.challenge = lle->challenge; 6521 dvl.challenge = lle->challenge;
6801 6522
6802 qqc.quality_count = 0; 6523 qqc.quality_count = 0;
6803 qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 6524 qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues);
6804 qqc.num_queues);
6805 qqc.num_queues = 0; 6525 qqc.num_queues = 0;
6806 qqc.q = NULL; 6526 qqc.q = NULL;
6807 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 6527 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
@@ -6812,16 +6532,13 @@ start_dv_learn (void *cls)
6812 /* Do this as close to transmission time as possible! */ 6532 /* Do this as close to transmission time as possible! */
6813 lle->launch_time = GNUNET_TIME_absolute_get (); 6533 lle->launch_time = GNUNET_TIME_absolute_get ();
6814 6534
6815 queue_send_msg (qqc.q, 6535 queue_send_msg (qqc.q, NULL, &dvl, sizeof (dvl));
6816 NULL,
6817 &dvl,
6818 sizeof (dvl));
6819 /* reschedule this job, randomizing the time it runs (but no 6536 /* reschedule this job, randomizing the time it runs (but no
6820 actual backoff!) */ 6537 actual backoff!) */
6821 dvlearn_task 6538 dvlearn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_randomize (
6822 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_randomize (DV_LEARN_BASE_FREQUENCY), 6539 DV_LEARN_BASE_FREQUENCY),
6823 &start_dv_learn, 6540 &start_dv_learn,
6824 NULL); 6541 NULL);
6825} 6542}
6826 6543
6827 6544
@@ -6843,13 +6560,11 @@ check_validation_request_pending (void *cls,
6843 struct ValidationState *vs = value; 6560 struct ValidationState *vs = value;
6844 6561
6845 (void) pid; 6562 (void) pid;
6846 if ( (GNUNET_YES == vs->awaiting_queue) && 6563 if ((GNUNET_YES == vs->awaiting_queue) &&
6847 (0 == strcmp (vs->address, 6564 (0 == strcmp (vs->address, q->address)))
6848 q->address)) )
6849 { 6565 {
6850 vs->awaiting_queue = GNUNET_NO; 6566 vs->awaiting_queue = GNUNET_NO;
6851 validation_transmit_on_queue (q, 6567 validation_transmit_on_queue (q, vs);
6852 vs);
6853 return GNUNET_NO; 6568 return GNUNET_NO;
6854 } 6569 }
6855 return GNUNET_OK; 6570 return GNUNET_OK;
@@ -6887,10 +6602,11 @@ handle_add_queue_message (void *cls,
6887 neighbour->earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 6602 neighbour->earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
6888 neighbour->pid = aqm->receiver; 6603 neighbour->pid = aqm->receiver;
6889 GNUNET_assert (GNUNET_OK == 6604 GNUNET_assert (GNUNET_OK ==
6890 GNUNET_CONTAINER_multipeermap_put (neighbours, 6605 GNUNET_CONTAINER_multipeermap_put (
6891 &neighbour->pid, 6606 neighbours,
6892 neighbour, 6607 &neighbour->pid,
6893 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6608 neighbour,
6609 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
6894 } 6610 }
6895 addr_len = ntohs (aqm->header.size) - sizeof (*aqm); 6611 addr_len = ntohs (aqm->header.size) - sizeof (*aqm);
6896 addr = (const char *) &aqm[1]; 6612 addr = (const char *) &aqm[1];
@@ -6918,20 +6634,12 @@ handle_add_queue_message (void *cls,
6918 GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S, 6634 GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S,
6919 &tracker_excess_out_cb, 6635 &tracker_excess_out_cb,
6920 queue); 6636 queue);
6921 memcpy (&queue[1], 6637 memcpy (&queue[1], addr, addr_len);
6922 addr,
6923 addr_len);
6924 /* notify monitors about new queue */ 6638 /* notify monitors about new queue */
6925 { 6639 {
6926 struct MonitorEvent me = { 6640 struct MonitorEvent me = {.rtt = queue->rtt, .cs = queue->cs};
6927 .rtt = queue->rtt,
6928 .cs = queue->cs
6929 };
6930 6641
6931 notify_monitors (&neighbour->pid, 6642 notify_monitors (&neighbour->pid, queue->address, queue->nt, &me);
6932 queue->address,
6933 queue->nt,
6934 &me);
6935 } 6643 }
6936 GNUNET_CONTAINER_MDLL_insert (neighbour, 6644 GNUNET_CONTAINER_MDLL_insert (neighbour,
6937 neighbour->queue_head, 6645 neighbour->queue_head,
@@ -6942,14 +6650,14 @@ handle_add_queue_message (void *cls,
6942 tc->details.communicator.queue_tail, 6650 tc->details.communicator.queue_tail,
6943 queue); 6651 queue);
6944 /* check if valdiations are waiting for the queue */ 6652 /* check if valdiations are waiting for the queue */
6945 (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, 6653 (void)
6946 &aqm->receiver, 6654 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
6947 &check_validation_request_pending, 6655 &aqm->receiver,
6948 queue); 6656 &check_validation_request_pending,
6657 queue);
6949 /* might be our first queue, try launching DV learning */ 6658 /* might be our first queue, try launching DV learning */
6950 if (NULL == dvlearn_task) 6659 if (NULL == dvlearn_task)
6951 dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, 6660 dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, NULL);
6952 NULL);
6953 GNUNET_SERVICE_client_continue (tc->client); 6661 GNUNET_SERVICE_client_continue (tc->client);
6954} 6662}
6955 6663
@@ -6986,15 +6694,16 @@ handle_queue_create_ok (void *cls,
6986 6694
6987/** 6695/**
6988 * Communicator tells us that our request to create a queue failed. This usually 6696 * Communicator tells us that our request to create a queue failed. This usually
6989 * indicates that the provided address is simply invalid or that the communicator's 6697 * indicates that the provided address is simply invalid or that the
6990 * resources are exhausted. 6698 * communicator's resources are exhausted.
6991 * 6699 *
6992 * @param cls the `struct TransportClient` 6700 * @param cls the `struct TransportClient`
6993 * @param cqr failure message 6701 * @param cqr failure message
6994 */ 6702 */
6995static void 6703static void
6996handle_queue_create_fail (void *cls, 6704handle_queue_create_fail (
6997 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) 6705 void *cls,
6706 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr)
6998{ 6707{
6999 struct TransportClient *tc = cls; 6708 struct TransportClient *tc = cls;
7000 6709
@@ -7016,14 +6725,14 @@ handle_queue_create_fail (void *cls,
7016 6725
7017 6726
7018/** 6727/**
7019 * We have received a `struct ExpressPreferenceMessage` from an application client. 6728 * We have received a `struct ExpressPreferenceMessage` from an application
6729 * client.
7020 * 6730 *
7021 * @param cls handle to the client 6731 * @param cls handle to the client
7022 * @param msg the start message 6732 * @param msg the start message
7023 */ 6733 */
7024static void 6734static void
7025handle_suggest_cancel (void *cls, 6735handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg)
7026 const struct ExpressPreferenceMessage *msg)
7027{ 6736{
7028 struct TransportClient *tc = cls; 6737 struct TransportClient *tc = cls;
7029 struct PeerRequest *pr; 6738 struct PeerRequest *pr;
@@ -7042,9 +6751,7 @@ handle_suggest_cancel (void *cls,
7042 GNUNET_SERVICE_client_drop (tc->client); 6751 GNUNET_SERVICE_client_drop (tc->client);
7043 return; 6752 return;
7044 } 6753 }
7045 (void) stop_peer_request (tc, 6754 (void) stop_peer_request (tc, &pr->pid, pr);
7046 &pr->pid,
7047 pr);
7048 GNUNET_SERVICE_client_continue (tc->client); 6755 GNUNET_SERVICE_client_continue (tc->client);
7049} 6756}
7050 6757
@@ -7058,8 +6765,9 @@ handle_suggest_cancel (void *cls,
7058 * @return #GNUNET_OK 6765 * @return #GNUNET_OK
7059 */ 6766 */
7060static int 6767static int
7061check_address_consider_verify (void *cls, 6768check_address_consider_verify (
7062 const struct GNUNET_TRANSPORT_AddressToVerify *hdr) 6769 void *cls,
6770 const struct GNUNET_TRANSPORT_AddressToVerify *hdr)
7063{ 6771{
7064 (void) cls; 6772 (void) cls;
7065 (void) hdr; 6773 (void) hdr;
@@ -7102,8 +6810,7 @@ check_known_address (void *cls,
7102 struct ValidationState *vs = value; 6810 struct ValidationState *vs = value;
7103 6811
7104 (void) pid; 6812 (void) pid;
7105 if (0 != strcmp (vs->address, 6813 if (0 != strcmp (vs->address, ckac->address))
7106 ckac->address))
7107 return GNUNET_OK; 6814 return GNUNET_OK;
7108 ckac->vs = vs; 6815 ckac->vs = vs;
7109 return GNUNET_NO; 6816 return GNUNET_NO;
@@ -7124,10 +6831,7 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
7124{ 6831{
7125 struct GNUNET_TIME_Absolute now; 6832 struct GNUNET_TIME_Absolute now;
7126 struct ValidationState *vs; 6833 struct ValidationState *vs;
7127 struct CheckKnownAddressContext ckac = { 6834 struct CheckKnownAddressContext ckac = {.address = address, .vs = NULL};
7128 .address = address,
7129 .vs = NULL
7130 };
7131 6835
7132 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) 6836 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
7133 return; /* expired */ 6837 return; /* expired */
@@ -7137,19 +6841,22 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
7137 &ckac); 6841 &ckac);
7138 if (NULL != (vs = ckac.vs)) 6842 if (NULL != (vs = ckac.vs))
7139 { 6843 {
7140 /* if 'vs' is not currently valid, we need to speed up retrying the validation */ 6844 /* if 'vs' is not currently valid, we need to speed up retrying the
6845 * validation */
7141 if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) 6846 if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us)
7142 { 6847 {
7143 /* reduce backoff as we got a fresh advertisement */ 6848 /* reduce backoff as we got a fresh advertisement */
7144 vs->challenge_backoff = GNUNET_TIME_relative_min (FAST_VALIDATION_CHALLENGE_FREQ, 6849 vs->challenge_backoff =
7145 GNUNET_TIME_relative_divide (vs->challenge_backoff, 6850 GNUNET_TIME_relative_min (FAST_VALIDATION_CHALLENGE_FREQ,
7146 2)); 6851 GNUNET_TIME_relative_divide (vs->challenge_backoff,
6852 2));
7147 update_next_challenge_time (vs, 6853 update_next_challenge_time (vs,
7148 GNUNET_TIME_relative_to_absolute (vs->challenge_backoff)); 6854 GNUNET_TIME_relative_to_absolute (
6855 vs->challenge_backoff));
7149 } 6856 }
7150 return; 6857 return;
7151 } 6858 }
7152 now = GNUNET_TIME_absolute_get(); 6859 now = GNUNET_TIME_absolute_get ();
7153 vs = GNUNET_new (struct ValidationState); 6860 vs = GNUNET_new (struct ValidationState);
7154 vs->pid = *pid; 6861 vs->pid = *pid;
7155 vs->valid_until = expiration; 6862 vs->valid_until = expiration;
@@ -7160,12 +6867,12 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
7160 sizeof (vs->challenge)); 6867 sizeof (vs->challenge));
7161 vs->address = GNUNET_strdup (address); 6868 vs->address = GNUNET_strdup (address);
7162 GNUNET_assert (GNUNET_YES == 6869 GNUNET_assert (GNUNET_YES ==
7163 GNUNET_CONTAINER_multipeermap_put (validation_map, 6870 GNUNET_CONTAINER_multipeermap_put (
7164 &vs->pid, 6871 validation_map,
7165 vs, 6872 &vs->pid,
7166 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6873 vs,
7167 update_next_challenge_time (vs, 6874 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
7168 now); 6875 update_next_challenge_time (vs, now);
7169} 6876}
7170 6877
7171 6878
@@ -7192,8 +6899,7 @@ handle_hello (void *cls,
7192 return; 6899 return;
7193 } 6900 }
7194 val = record->value; 6901 val = record->value;
7195 if ( (0 == record->value_size) || 6902 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1]))
7196 ('\0' != val[record->value_size - 1]) )
7197 { 6903 {
7198 GNUNET_break (0); 6904 GNUNET_break (0);
7199 return; 6905 return;
@@ -7205,14 +6911,14 @@ handle_hello (void *cls,
7205 6911
7206 6912
7207/** 6913/**
7208 * We have received a `struct ExpressPreferenceMessage` from an application client. 6914 * We have received a `struct ExpressPreferenceMessage` from an application
6915 * client.
7209 * 6916 *
7210 * @param cls handle to the client 6917 * @param cls handle to the client
7211 * @param msg the start message 6918 * @param msg the start message
7212 */ 6919 */
7213static void 6920static void
7214handle_suggest (void *cls, 6921handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg)
7215 const struct ExpressPreferenceMessage *msg)
7216{ 6922{
7217 struct TransportClient *tc = cls; 6923 struct TransportClient *tc = cls;
7218 struct PeerRequest *pr; 6924 struct PeerRequest *pr;
@@ -7220,9 +6926,8 @@ handle_suggest (void *cls,
7220 if (CT_NONE == tc->type) 6926 if (CT_NONE == tc->type)
7221 { 6927 {
7222 tc->type = CT_APPLICATION; 6928 tc->type = CT_APPLICATION;
7223 tc->details.application.requests 6929 tc->details.application.requests =
7224 = GNUNET_CONTAINER_multipeermap_create (16, 6930 GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
7225 GNUNET_YES);
7226 } 6931 }
7227 if (CT_APPLICATION != tc->type) 6932 if (CT_APPLICATION != tc->type)
7228 { 6933 {
@@ -7240,11 +6945,11 @@ handle_suggest (void *cls,
7240 pr->pid = msg->peer; 6945 pr->pid = msg->peer;
7241 pr->bw = msg->bw; 6946 pr->bw = msg->bw;
7242 pr->pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk); 6947 pr->pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk);
7243 if (GNUNET_YES != 6948 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put (
7244 GNUNET_CONTAINER_multipeermap_put (tc->details.application.requests, 6949 tc->details.application.requests,
7245 &pr->pid, 6950 &pr->pid,
7246 pr, 6951 pr,
7247 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 6952 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
7248 { 6953 {
7249 GNUNET_break (0); 6954 GNUNET_break (0);
7250 GNUNET_free (pr); 6955 GNUNET_free (pr);
@@ -7270,8 +6975,9 @@ handle_suggest (void *cls,
7270 * signature in the body, see #GNUNET_HELLO_extract_address() 6975 * signature in the body, see #GNUNET_HELLO_extract_address()
7271 */ 6976 */
7272static void 6977static void
7273handle_address_consider_verify (void *cls, 6978handle_address_consider_verify (
7274 const struct GNUNET_TRANSPORT_AddressToVerify *hdr) 6979 void *cls,
6980 const struct GNUNET_TRANSPORT_AddressToVerify *hdr)
7275{ 6981{
7276 struct TransportClient *tc = cls; 6982 struct TransportClient *tc = cls;
7277 char *address; 6983 char *address;
@@ -7282,19 +6988,18 @@ handle_address_consider_verify (void *cls,
7282 // OPTIMIZE-FIXME: checking that we know this address already should 6988 // OPTIMIZE-FIXME: checking that we know this address already should
7283 // be done BEFORE checking the signature => HELLO API change! 6989 // be done BEFORE checking the signature => HELLO API change!
7284 // OPTIMIZE-FIXME: pre-check: rate-limit signature verification / validation?! 6990 // OPTIMIZE-FIXME: pre-check: rate-limit signature verification / validation?!
7285 address = GNUNET_HELLO_extract_address (&hdr[1], 6991 address =
7286 ntohs (hdr->header.size) - sizeof (*hdr), 6992 GNUNET_HELLO_extract_address (&hdr[1],
7287 &hdr->peer, 6993 ntohs (hdr->header.size) - sizeof (*hdr),
7288 &nt, 6994 &hdr->peer,
7289 &expiration); 6995 &nt,
6996 &expiration);
7290 if (NULL == address) 6997 if (NULL == address)
7291 { 6998 {
7292 GNUNET_break_op (0); 6999 GNUNET_break_op (0);
7293 return; 7000 return;
7294 } 7001 }
7295 start_address_validation (&hdr->peer, 7002 start_address_validation (&hdr->peer, address, expiration);
7296 address,
7297 expiration);
7298 GNUNET_free (address); 7003 GNUNET_free (address);
7299 GNUNET_SERVICE_client_continue (tc->client); 7004 GNUNET_SERVICE_client_continue (tc->client);
7300} 7005}
@@ -7446,19 +7151,15 @@ do_shutdown (void *cls)
7446 GNUNET_SCHEDULER_cancel (ephemeral_task); 7151 GNUNET_SCHEDULER_cancel (ephemeral_task);
7447 ephemeral_task = NULL; 7152 ephemeral_task = NULL;
7448 } 7153 }
7449 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 7154 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &free_neighbour_cb, NULL);
7450 &free_neighbour_cb,
7451 NULL);
7452 if (NULL != peerstore) 7155 if (NULL != peerstore)
7453 { 7156 {
7454 GNUNET_PEERSTORE_disconnect (peerstore, 7157 GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO);
7455 GNUNET_NO);
7456 peerstore = NULL; 7158 peerstore = NULL;
7457 } 7159 }
7458 if (NULL != GST_stats) 7160 if (NULL != GST_stats)
7459 { 7161 {
7460 GNUNET_STATISTICS_destroy (GST_stats, 7162 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
7461 GNUNET_NO);
7462 GST_stats = NULL; 7163 GST_stats = NULL;
7463 } 7164 }
7464 if (NULL != GST_my_private_key) 7165 if (NULL != GST_my_private_key)
@@ -7475,18 +7176,14 @@ do_shutdown (void *cls)
7475 validation_map = NULL; 7176 validation_map = NULL;
7476 while (NULL != (lle = lle_head)) 7177 while (NULL != (lle = lle_head))
7477 { 7178 {
7478 GNUNET_CONTAINER_DLL_remove (lle_head, 7179 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle);
7479 lle_tail,
7480 lle);
7481 GNUNET_free (lle); 7180 GNUNET_free (lle);
7482 } 7181 }
7483 GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map); 7182 GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map);
7484 dvlearn_map = NULL; 7183 dvlearn_map = NULL;
7485 GNUNET_CONTAINER_heap_destroy (validation_heap); 7184 GNUNET_CONTAINER_heap_destroy (validation_heap);
7486 validation_heap = NULL; 7185 validation_heap = NULL;
7487 GNUNET_CONTAINER_multipeermap_iterate (dv_routes, 7186 GNUNET_CONTAINER_multipeermap_iterate (dv_routes, &free_dv_routes_cb, NULL);
7488 &free_dv_routes_cb,
7489 NULL);
7490 GNUNET_CONTAINER_multipeermap_destroy (dv_routes); 7187 GNUNET_CONTAINER_multipeermap_destroy (dv_routes);
7491 dv_routes = NULL; 7188 dv_routes = NULL;
7492 GNUNET_CONTAINER_multipeermap_iterate (ephemeral_map, 7189 GNUNET_CONTAINER_multipeermap_iterate (ephemeral_map,
@@ -7515,35 +7212,34 @@ run (void *cls,
7515 (void) service; 7212 (void) service;
7516 /* setup globals */ 7213 /* setup globals */
7517 GST_cfg = c; 7214 GST_cfg = c;
7518 neighbours = GNUNET_CONTAINER_multipeermap_create (1024, 7215 neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
7519 GNUNET_YES); 7216 dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
7520 dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, 7217 ephemeral_map = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES);
7521 GNUNET_YES); 7218 ephemeral_heap =
7522 ephemeral_map = GNUNET_CONTAINER_multipeermap_create (32, 7219 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
7523 GNUNET_YES);
7524 ephemeral_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
7525 dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING, 7220 dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING,
7526 GNUNET_YES); 7221 GNUNET_YES);
7527 validation_map = GNUNET_CONTAINER_multipeermap_create (1024, 7222 validation_map = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
7528 GNUNET_YES); 7223 validation_heap =
7529 validation_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 7224 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
7530 GST_my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); 7225 GST_my_private_key =
7226 GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg);
7531 if (NULL == GST_my_private_key) 7227 if (NULL == GST_my_private_key)
7532 { 7228 {
7533 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 7229 GNUNET_log (
7534 _("Transport service is lacking key configuration settings. Exiting.\n")); 7230 GNUNET_ERROR_TYPE_ERROR,
7231 _ (
7232 "Transport service is lacking key configuration settings. Exiting.\n"));
7535 GNUNET_SCHEDULER_shutdown (); 7233 GNUNET_SCHEDULER_shutdown ();
7536 return; 7234 return;
7537 } 7235 }
7538 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, 7236 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
7539 &GST_my_identity.public_key); 7237 &GST_my_identity.public_key);
7540 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 7238 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
7541 "My identity is `%s'\n", 7239 "My identity is `%s'\n",
7542 GNUNET_i2s_full (&GST_my_identity)); 7240 GNUNET_i2s_full (&GST_my_identity));
7543 GST_stats = GNUNET_STATISTICS_create ("transport", 7241 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
7544 GST_cfg); 7242 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
7545 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
7546 NULL);
7547 peerstore = GNUNET_PEERSTORE_connect (GST_cfg); 7243 peerstore = GNUNET_PEERSTORE_connect (GST_cfg);
7548 if (NULL == peerstore) 7244 if (NULL == peerstore)
7549 { 7245 {
@@ -7557,86 +7253,86 @@ run (void *cls,
7557/** 7253/**
7558 * Define "main" method using service macro. 7254 * Define "main" method using service macro.
7559 */ 7255 */
7560GNUNET_SERVICE_MAIN 7256GNUNET_SERVICE_MAIN (
7561("transport", 7257 "transport",
7562 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, 7258 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
7563 &run, 7259 &run,
7564 &client_connect_cb, 7260 &client_connect_cb,
7565 &client_disconnect_cb, 7261 &client_disconnect_cb,
7566 NULL, 7262 NULL,
7567 /* communication with applications */ 7263 /* communication with applications */
7568 GNUNET_MQ_hd_fixed_size (suggest, 7264 GNUNET_MQ_hd_fixed_size (suggest,
7569 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, 7265 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST,
7570 struct ExpressPreferenceMessage, 7266 struct ExpressPreferenceMessage,
7571 NULL), 7267 NULL),
7572 GNUNET_MQ_hd_fixed_size (suggest_cancel, 7268 GNUNET_MQ_hd_fixed_size (suggest_cancel,
7573 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, 7269 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL,
7574 struct ExpressPreferenceMessage, 7270 struct ExpressPreferenceMessage,
7575 NULL), 7271 NULL),
7576 GNUNET_MQ_hd_var_size (request_hello_validation, 7272 GNUNET_MQ_hd_var_size (request_hello_validation,
7577 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, 7273 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION,
7578 struct RequestHelloValidationMessage, 7274 struct RequestHelloValidationMessage,
7579 NULL), 7275 NULL),
7580 /* communication with core */ 7276 /* communication with core */
7581 GNUNET_MQ_hd_fixed_size (client_start, 7277 GNUNET_MQ_hd_fixed_size (client_start,
7582 GNUNET_MESSAGE_TYPE_TRANSPORT_START, 7278 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
7583 struct StartMessage, 7279 struct StartMessage,
7584 NULL), 7280 NULL),
7585 GNUNET_MQ_hd_var_size (client_send, 7281 GNUNET_MQ_hd_var_size (client_send,
7586 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 7282 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
7587 struct OutboundMessage, 7283 struct OutboundMessage,
7588 NULL), 7284 NULL),
7589 /* communication with communicators */ 7285 /* communication with communicators */
7590 GNUNET_MQ_hd_var_size (communicator_available, 7286 GNUNET_MQ_hd_var_size (communicator_available,
7591 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, 7287 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR,
7592 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, 7288 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
7593 NULL), 7289 NULL),
7594 GNUNET_MQ_hd_var_size (communicator_backchannel, 7290 GNUNET_MQ_hd_var_size (communicator_backchannel,
7595 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, 7291 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
7596 struct GNUNET_TRANSPORT_CommunicatorBackchannel, 7292 struct GNUNET_TRANSPORT_CommunicatorBackchannel,
7597 NULL), 7293 NULL),
7598 GNUNET_MQ_hd_var_size (add_address, 7294 GNUNET_MQ_hd_var_size (add_address,
7599 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, 7295 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
7600 struct GNUNET_TRANSPORT_AddAddressMessage, 7296 struct GNUNET_TRANSPORT_AddAddressMessage,
7601 NULL), 7297 NULL),
7602 GNUNET_MQ_hd_fixed_size (del_address, 7298 GNUNET_MQ_hd_fixed_size (del_address,
7603 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, 7299 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
7604 struct GNUNET_TRANSPORT_DelAddressMessage, 7300 struct GNUNET_TRANSPORT_DelAddressMessage,
7605 NULL), 7301 NULL),
7606 GNUNET_MQ_hd_var_size (incoming_msg, 7302 GNUNET_MQ_hd_var_size (incoming_msg,
7607 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, 7303 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
7608 struct GNUNET_TRANSPORT_IncomingMessage, 7304 struct GNUNET_TRANSPORT_IncomingMessage,
7609 NULL), 7305 NULL),
7610 GNUNET_MQ_hd_fixed_size (queue_create_ok, 7306 GNUNET_MQ_hd_fixed_size (queue_create_ok,
7611 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, 7307 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
7612 struct GNUNET_TRANSPORT_CreateQueueResponse, 7308 struct GNUNET_TRANSPORT_CreateQueueResponse,
7613 NULL), 7309 NULL),
7614 GNUNET_MQ_hd_fixed_size (queue_create_fail, 7310 GNUNET_MQ_hd_fixed_size (queue_create_fail,
7615 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, 7311 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
7616 struct GNUNET_TRANSPORT_CreateQueueResponse, 7312 struct GNUNET_TRANSPORT_CreateQueueResponse,
7617 NULL), 7313 NULL),
7618 GNUNET_MQ_hd_var_size (add_queue_message, 7314 GNUNET_MQ_hd_var_size (add_queue_message,
7619 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, 7315 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
7620 struct GNUNET_TRANSPORT_AddQueueMessage, 7316 struct GNUNET_TRANSPORT_AddQueueMessage,
7621 NULL), 7317 NULL),
7622 GNUNET_MQ_hd_var_size (address_consider_verify, 7318 GNUNET_MQ_hd_var_size (address_consider_verify,
7623 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY, 7319 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY,
7624 struct GNUNET_TRANSPORT_AddressToVerify, 7320 struct GNUNET_TRANSPORT_AddressToVerify,
7625 NULL), 7321 NULL),
7626 GNUNET_MQ_hd_fixed_size (del_queue_message, 7322 GNUNET_MQ_hd_fixed_size (del_queue_message,
7627 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, 7323 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
7628 struct GNUNET_TRANSPORT_DelQueueMessage, 7324 struct GNUNET_TRANSPORT_DelQueueMessage,
7629 NULL), 7325 NULL),
7630 GNUNET_MQ_hd_fixed_size (send_message_ack, 7326 GNUNET_MQ_hd_fixed_size (send_message_ack,
7631 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, 7327 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK,
7632 struct GNUNET_TRANSPORT_SendMessageToAck, 7328 struct GNUNET_TRANSPORT_SendMessageToAck,
7633 NULL), 7329 NULL),
7634 /* communication with monitors */ 7330 /* communication with monitors */
7635 GNUNET_MQ_hd_fixed_size (monitor_start, 7331 GNUNET_MQ_hd_fixed_size (monitor_start,
7636 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, 7332 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START,
7637 struct GNUNET_TRANSPORT_MonitorStart, 7333 struct GNUNET_TRANSPORT_MonitorStart,
7638 NULL), 7334 NULL),
7639 GNUNET_MQ_handler_end ()); 7335 GNUNET_MQ_handler_end ());
7640 7336
7641 7337
7642/* end of file gnunet-service-transport.c */ 7338/* end of file gnunet-service-transport.c */