aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet.h65
-rw-r--r--src/cadet/cadet_api.c753
-rw-r--r--src/cadet/cadet_api_get_channel.c121
-rw-r--r--src/cadet/cadet_api_get_path.c145
-rw-r--r--src/cadet/cadet_api_helper.c13
-rw-r--r--src/cadet/cadet_api_list_peers.c119
-rw-r--r--src/cadet/cadet_api_list_tunnels.c121
-rw-r--r--src/cadet/cadet_protocol.h48
-rw-r--r--src/cadet/cadet_test_lib.c260
-rw-r--r--src/cadet/cadet_test_lib.h22
-rw-r--r--src/cadet/desirability_table.c34
-rw-r--r--src/cadet/gnunet-cadet-profiler.c834
-rw-r--r--src/cadet/gnunet-cadet.c685
-rw-r--r--src/cadet/gnunet-service-cadet.c1209
-rw-r--r--src/cadet/gnunet-service-cadet.h36
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c1874
-rw-r--r--src/cadet/gnunet-service-cadet_channel.h92
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c766
-rw-r--r--src/cadet/gnunet-service-cadet_connection.h78
-rw-r--r--src/cadet/gnunet-service-cadet_core.c1162
-rw-r--r--src/cadet/gnunet-service-cadet_core.h4
-rw-r--r--src/cadet/gnunet-service-cadet_dht.c303
-rw-r--r--src/cadet/gnunet-service-cadet_dht.h10
-rw-r--r--src/cadet/gnunet-service-cadet_hello.c89
-rw-r--r--src/cadet/gnunet-service-cadet_hello.h6
-rw-r--r--src/cadet/gnunet-service-cadet_paths.c701
-rw-r--r--src/cadet/gnunet-service-cadet_paths.h47
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c1201
-rw-r--r--src/cadet/gnunet-service-cadet_peer.h112
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.c3506
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.h89
-rw-r--r--src/cadet/test_cadet.c1207
-rw-r--r--src/cadet/test_cadet_flow.c741
-rw-r--r--src/cadet/test_cadet_local_mq.c257
34 files changed, 8414 insertions, 8296 deletions
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h
index 9b2050e67..29400e39f 100644
--- a/src/cadet/cadet.h
+++ b/src/cadet/cadet.h
@@ -35,18 +35,18 @@ extern "C" {
35 35
36#include <stdint.h> 36#include <stdint.h>
37 37
38#if !defined(GNUNET_CULL_LOGGING) 38#if ! defined(GNUNET_CULL_LOGGING)
39#define CADET_TIMING_START \ 39#define CADET_TIMING_START \
40 struct GNUNET_TIME_Absolute __timestamp; \ 40 struct GNUNET_TIME_Absolute __timestamp; \
41 __timestamp = GNUNET_TIME_absolute_get() 41 __timestamp = GNUNET_TIME_absolute_get ()
42 42
43#define CADET_TIMING_END \ 43#define CADET_TIMING_END \
44 struct GNUNET_TIME_Relative __duration; \ 44 struct GNUNET_TIME_Relative __duration; \
45 __duration = GNUNET_TIME_absolute_get_duration(__timestamp); \ 45 __duration = GNUNET_TIME_absolute_get_duration (__timestamp); \
46 LOG(GNUNET_ERROR_TYPE_INFO, \ 46 LOG (GNUNET_ERROR_TYPE_INFO, \
47 " %s duration %s\n", \ 47 " %s duration %s\n", \
48 __FUNCTION__, \ 48 __FUNCTION__, \
49 GNUNET_STRINGS_relative_time_to_string(__duration, GNUNET_YES)); 49 GNUNET_STRINGS_relative_time_to_string (__duration, GNUNET_YES));
50#else 50#else
51#define CADET_TIMING_START 51#define CADET_TIMING_START
52#define CADET_TIMING_END 52#define CADET_TIMING_END
@@ -99,7 +99,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
99/** 99/**
100 * Number uniquely identifying a channel of a client. 100 * Number uniquely identifying a channel of a client.
101 */ 101 */
102struct GNUNET_CADET_ClientChannelNumber { 102struct GNUNET_CADET_ClientChannelNumber
103{
103 /** 104 /**
104 * Values for channel numbering. 105 * Values for channel numbering.
105 * Local channel numbers given by the service (incoming) are 106 * Local channel numbers given by the service (incoming) are
@@ -114,7 +115,8 @@ struct GNUNET_CADET_ClientChannelNumber {
114/** 115/**
115 * Message for a client to create and destroy channels. 116 * Message for a client to create and destroy channels.
116 */ 117 */
117struct GNUNET_CADET_PortMessage { 118struct GNUNET_CADET_PortMessage
119{
118 /** 120 /**
119 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN 121 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
120 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE 122 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
@@ -133,7 +135,8 @@ struct GNUNET_CADET_PortMessage {
133/** 135/**
134 * Message for a client to create channels. 136 * Message for a client to create channels.
135 */ 137 */
136struct GNUNET_CADET_LocalChannelCreateMessage { 138struct GNUNET_CADET_LocalChannelCreateMessage
139{
137 /** 140 /**
138 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE 141 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
139 * 142 *
@@ -166,7 +169,8 @@ struct GNUNET_CADET_LocalChannelCreateMessage {
166/** 169/**
167 * Message for or to a client to destroy tunnel. 170 * Message for or to a client to destroy tunnel.
168 */ 171 */
169struct GNUNET_CADET_LocalChannelDestroyMessage { 172struct GNUNET_CADET_LocalChannelDestroyMessage
173{
170 /** 174 /**
171 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY 175 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
172 */ 176 */
@@ -182,7 +186,8 @@ struct GNUNET_CADET_LocalChannelDestroyMessage {
182/** 186/**
183 * Message for cadet data traffic. 187 * Message for cadet data traffic.
184 */ 188 */
185struct GNUNET_CADET_LocalData { 189struct GNUNET_CADET_LocalData
190{
186 /** 191 /**
187 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA 192 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
188 */ 193 */
@@ -209,7 +214,8 @@ struct GNUNET_CADET_LocalData {
209 * Message to allow the client send more data to the service 214 * Message to allow the client send more data to the service
210 * (always service -> client). 215 * (always service -> client).
211 */ 216 */
212struct GNUNET_CADET_LocalAck { 217struct GNUNET_CADET_LocalAck
218{
213 /** 219 /**
214 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK 220 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
215 */ 221 */
@@ -227,7 +233,8 @@ struct GNUNET_CADET_LocalAck {
227 * 233 *
228 * TODO: split into two messages! 234 * TODO: split into two messages!
229 */ 235 */
230struct GNUNET_CADET_LocalInfo { 236struct GNUNET_CADET_LocalInfo
237{
231 /** 238 /**
232 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or 239 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or
233 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER 240 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER
@@ -249,7 +256,8 @@ struct GNUNET_CADET_LocalInfo {
249/** 256/**
250 * Message to inform the client about channels in the service. 257 * Message to inform the client about channels in the service.
251 */ 258 */
252struct GNUNET_CADET_RequestPathInfoMessage { 259struct GNUNET_CADET_RequestPathInfoMessage
260{
253 /** 261 /**
254 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH 262 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH
255 */ 263 */
@@ -270,7 +278,8 @@ struct GNUNET_CADET_RequestPathInfoMessage {
270/** 278/**
271 * Message to inform the client about channels in the service. 279 * Message to inform the client about channels in the service.
272 */ 280 */
273struct GNUNET_CADET_ChannelInfoMessage { 281struct GNUNET_CADET_ChannelInfoMessage
282{
274 /** 283 /**
275 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL. 284 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL.
276 */ 285 */
@@ -293,7 +302,8 @@ struct GNUNET_CADET_ChannelInfoMessage {
293/** 302/**
294 * Message to as the service about information on a channel. 303 * Message to as the service about information on a channel.
295 */ 304 */
296struct GNUNET_CADET_RequestChannelInfoMessage { 305struct GNUNET_CADET_RequestChannelInfoMessage
306{
297 /** 307 /**
298 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL. 308 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL.
299 */ 309 */
@@ -309,7 +319,8 @@ struct GNUNET_CADET_RequestChannelInfoMessage {
309/** 319/**
310 * Message to inform the client about one of the paths known to the service. 320 * Message to inform the client about one of the paths known to the service.
311 */ 321 */
312struct GNUNET_CADET_LocalInfoPath { 322struct GNUNET_CADET_LocalInfoPath
323{
313 /** 324 /**
314 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH. 325 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH.
315 */ 326 */
@@ -325,7 +336,8 @@ struct GNUNET_CADET_LocalInfoPath {
325/** 336/**
326 * Message to inform the client about one of the peers in the service. 337 * Message to inform the client about one of the peers in the service.
327 */ 338 */
328struct GNUNET_CADET_LocalInfoPeers { 339struct GNUNET_CADET_LocalInfoPeers
340{
329 /** 341 /**
330 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS 342 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
331 */ 343 */
@@ -358,7 +370,8 @@ struct GNUNET_CADET_LocalInfoPeers {
358 * 370 *
359 * TODO: split into two messages! 371 * TODO: split into two messages!
360 */ 372 */
361struct GNUNET_CADET_LocalInfoTunnel { 373struct GNUNET_CADET_LocalInfoTunnel
374{
362 /** 375 /**
363 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL 376 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
364 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS 377 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
@@ -406,7 +419,7 @@ GNUNET_NETWORK_STRUCT_END
406 * @return String representing FWD or BCK. 419 * @return String representing FWD or BCK.
407 */ 420 */
408char * 421char *
409GC_f2s(int fwd); 422GC_f2s (int fwd);
410 423
411 424
412/** 425/**
@@ -418,7 +431,7 @@ GC_f2s(int fwd);
418 * @return True if bigger (arg1) has a higher value than smaller (arg 2). 431 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
419 */ 432 */
420int 433int
421GC_is_pid_bigger(uint32_t bigger, uint32_t smaller); 434GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
422 435
423 436
424/** 437/**
@@ -430,7 +443,7 @@ GC_is_pid_bigger(uint32_t bigger, uint32_t smaller);
430 * @return Highest ACK value from the two. 443 * @return Highest ACK value from the two.
431 */ 444 */
432uint32_t 445uint32_t
433GC_max_pid(uint32_t a, uint32_t b); 446GC_max_pid (uint32_t a, uint32_t b);
434 447
435 448
436/** 449/**
@@ -442,7 +455,7 @@ GC_max_pid(uint32_t a, uint32_t b);
442 * @return Lowest ACK value from the two. 455 * @return Lowest ACK value from the two.
443 */ 456 */
444uint32_t 457uint32_t
445GC_min_pid(uint32_t a, uint32_t b); 458GC_min_pid (uint32_t a, uint32_t b);
446 459
447 460
448/** 461/**
@@ -455,7 +468,7 @@ GC_min_pid(uint32_t a, uint32_t b);
455 * @return The size of the output. 468 * @return The size of the output.
456 */ 469 */
457size_t 470size_t
458GC_bin2s(void *bin, unsigned int len, char **output); 471GC_bin2s (void *bin, unsigned int len, char **output);
459 472
460 473
461/** 474/**
@@ -469,7 +482,7 @@ GC_bin2s(void *bin, unsigned int len, char **output);
469 * @return Human readable string description. 482 * @return Human readable string description.
470 */ 483 */
471const char * 484const char *
472GC_m2s(uint16_t m); 485GC_m2s (uint16_t m);
473 486
474#if 0 /* keep Emacsens' auto-indent happy */ 487#if 0 /* keep Emacsens' auto-indent happy */
475{ 488{
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 61ff71b31..9aeedb616 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -30,12 +30,13 @@
30#include "cadet.h" 30#include "cadet.h"
31#include "cadet_protocol.h" 31#include "cadet_protocol.h"
32 32
33#define LOG(kind, ...) GNUNET_log_from(kind, "cadet-api", __VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log_from (kind, "cadet-api", __VA_ARGS__)
34 34
35/** 35/**
36 * Opaque handle to the service. 36 * Opaque handle to the service.
37 */ 37 */
38struct GNUNET_CADET_Handle { 38struct GNUNET_CADET_Handle
39{
39 /** 40 /**
40 * Message queue. 41 * Message queue.
41 */ 42 */
@@ -76,7 +77,8 @@ struct GNUNET_CADET_Handle {
76/** 77/**
77 * Opaque handle to a channel. 78 * Opaque handle to a channel.
78 */ 79 */
79struct GNUNET_CADET_Channel { 80struct GNUNET_CADET_Channel
81{
80 /** 82 /**
81 * Other end of the channel. 83 * Other end of the channel.
82 */ 84 */
@@ -140,7 +142,8 @@ struct GNUNET_CADET_Channel {
140/** 142/**
141 * Opaque handle to a port. 143 * Opaque handle to a port.
142 */ 144 */
143struct GNUNET_CADET_Port { 145struct GNUNET_CADET_Port
146{
144 /** 147 /**
145 * Port "number" 148 * Port "number"
146 */ 149 */
@@ -191,10 +194,10 @@ struct GNUNET_CADET_Port {
191 * @return The port handle if known, NULL otherwise. 194 * @return The port handle if known, NULL otherwise.
192 */ 195 */
193static struct GNUNET_CADET_Port * 196static struct GNUNET_CADET_Port *
194find_port(const struct GNUNET_CADET_Handle *h, 197find_port (const struct GNUNET_CADET_Handle *h,
195 const struct GNUNET_HashCode *hash) 198 const struct GNUNET_HashCode *hash)
196{ 199{
197 return GNUNET_CONTAINER_multihashmap_get(h->ports, hash); 200 return GNUNET_CONTAINER_multihashmap_get (h->ports, hash);
198} 201}
199 202
200 203
@@ -206,11 +209,11 @@ find_port(const struct GNUNET_CADET_Handle *h,
206 * @return handle to the required channel or NULL if not found 209 * @return handle to the required channel or NULL if not found
207 */ 210 */
208static struct GNUNET_CADET_Channel * 211static struct GNUNET_CADET_Channel *
209find_channel(struct GNUNET_CADET_Handle *h, 212find_channel (struct GNUNET_CADET_Handle *h,
210 struct GNUNET_CADET_ClientChannelNumber ccn) 213 struct GNUNET_CADET_ClientChannelNumber ccn)
211{ 214{
212 return GNUNET_CONTAINER_multihashmap32_get(h->channels, 215 return GNUNET_CONTAINER_multihashmap32_get (h->channels,
213 ntohl(ccn.channel_of_client)); 216 ntohl (ccn.channel_of_client));
214} 217}
215 218
216 219
@@ -222,33 +225,33 @@ find_channel(struct GNUNET_CADET_Handle *h,
222 * @return Handle to the created channel. 225 * @return Handle to the created channel.
223 */ 226 */
224static struct GNUNET_CADET_Channel * 227static struct GNUNET_CADET_Channel *
225create_channel(struct GNUNET_CADET_Handle *h, 228create_channel (struct GNUNET_CADET_Handle *h,
226 const struct GNUNET_CADET_ClientChannelNumber *ccnp) 229 const struct GNUNET_CADET_ClientChannelNumber *ccnp)
227{ 230{
228 struct GNUNET_CADET_Channel *ch; 231 struct GNUNET_CADET_Channel *ch;
229 struct GNUNET_CADET_ClientChannelNumber ccn; 232 struct GNUNET_CADET_ClientChannelNumber ccn;
230 233
231 ch = GNUNET_new(struct GNUNET_CADET_Channel); 234 ch = GNUNET_new (struct GNUNET_CADET_Channel);
232 ch->cadet = h; 235 ch->cadet = h;
233 if (NULL == ccnp) 236 if (NULL == ccnp)
234 { 237 {
235 while (NULL != find_channel(h, h->next_ccn)) 238 while (NULL != find_channel (h, h->next_ccn))
236 h->next_ccn.channel_of_client = 239 h->next_ccn.channel_of_client =
237 htonl(GNUNET_CADET_LOCAL_CHANNEL_ID_CLI | 240 htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI
238 (1 + ntohl(h->next_ccn.channel_of_client))); 241 | (1 + ntohl (h->next_ccn.channel_of_client)));
239 ccn = h->next_ccn; 242 ccn = h->next_ccn;
240 } 243 }
241 else 244 else
242 { 245 {
243 ccn = *ccnp; 246 ccn = *ccnp;
244 } 247 }
245 ch->ccn = ccn; 248 ch->ccn = ccn;
246 GNUNET_assert(GNUNET_OK == 249 GNUNET_assert (GNUNET_OK ==
247 GNUNET_CONTAINER_multihashmap32_put( 250 GNUNET_CONTAINER_multihashmap32_put (
248 h->channels, 251 h->channels,
249 ntohl(ch->ccn.channel_of_client), 252 ntohl (ch->ccn.channel_of_client),
250 ch, 253 ch,
251 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 254 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
252 return ch; 255 return ch;
253} 256}
254 257
@@ -264,31 +267,31 @@ create_channel(struct GNUNET_CADET_Handle *h,
264 * @param call_cleaner Whether to call the cleaner handler. 267 * @param call_cleaner Whether to call the cleaner handler.
265 */ 268 */
266static void 269static void
267destroy_channel(struct GNUNET_CADET_Channel *ch) 270destroy_channel (struct GNUNET_CADET_Channel *ch)
268{ 271{
269 struct GNUNET_CADET_Handle *h = ch->cadet; 272 struct GNUNET_CADET_Handle *h = ch->cadet;
270 273
271 LOG(GNUNET_ERROR_TYPE_DEBUG, 274 LOG (GNUNET_ERROR_TYPE_DEBUG,
272 "Destroying channel %X of %p\n", 275 "Destroying channel %X of %p\n",
273 htonl(ch->ccn.channel_of_client), 276 htonl (ch->ccn.channel_of_client),
274 h); 277 h);
275 GNUNET_assert( 278 GNUNET_assert (
276 GNUNET_YES == 279 GNUNET_YES ==
277 GNUNET_CONTAINER_multihashmap32_remove(h->channels, 280 GNUNET_CONTAINER_multihashmap32_remove (h->channels,
278 ntohl(ch->ccn.channel_of_client), 281 ntohl (ch->ccn.channel_of_client),
279 ch)); 282 ch));
280 if (NULL != ch->mq_cont) 283 if (NULL != ch->mq_cont)
281 { 284 {
282 GNUNET_SCHEDULER_cancel(ch->mq_cont); 285 GNUNET_SCHEDULER_cancel (ch->mq_cont);
283 ch->mq_cont = NULL; 286 ch->mq_cont = NULL;
284 } 287 }
285 /* signal channel destruction */ 288 /* signal channel destruction */
286 if (NULL != ch->disconnects) 289 if (NULL != ch->disconnects)
287 ch->disconnects(ch->ctx, ch); 290 ch->disconnects (ch->ctx, ch);
288 if (NULL != ch->pending_env) 291 if (NULL != ch->pending_env)
289 GNUNET_MQ_discard(ch->pending_env); 292 GNUNET_MQ_discard (ch->pending_env);
290 GNUNET_MQ_destroy(ch->mq); 293 GNUNET_MQ_destroy (ch->mq);
291 GNUNET_free(ch); 294 GNUNET_free (ch);
292} 295}
293 296
294 297
@@ -299,7 +302,7 @@ destroy_channel(struct GNUNET_CADET_Channel *ch)
299 * @param h handle to the cadet 302 * @param h handle to the cadet
300 */ 303 */
301static void 304static void
302reconnect(struct GNUNET_CADET_Handle *h); 305reconnect (struct GNUNET_CADET_Handle *h);
303 306
304 307
305/** 308/**
@@ -312,17 +315,17 @@ reconnect(struct GNUNET_CADET_Handle *h);
312 * @return #GNUNET_OK (continue to iterate) 315 * @return #GNUNET_OK (continue to iterate)
313 */ 316 */
314static int 317static int
315open_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value) 318open_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value)
316{ 319{
317 struct GNUNET_CADET_Handle *h = cls; 320 struct GNUNET_CADET_Handle *h = cls;
318 struct GNUNET_CADET_Port *port = value; 321 struct GNUNET_CADET_Port *port = value;
319 struct GNUNET_CADET_PortMessage *msg; 322 struct GNUNET_CADET_PortMessage *msg;
320 struct GNUNET_MQ_Envelope *env; 323 struct GNUNET_MQ_Envelope *env;
321 324
322 (void)id; 325 (void) id;
323 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN); 326 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN);
324 msg->port = port->id; 327 msg->port = port->id;
325 GNUNET_MQ_send(h->mq, env); 328 GNUNET_MQ_send (h->mq, env);
326 return GNUNET_OK; 329 return GNUNET_OK;
327} 330}
328 331
@@ -334,14 +337,14 @@ open_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value)
334 * @param cls closure (cadet handle) 337 * @param cls closure (cadet handle)
335 */ 338 */
336static void 339static void
337reconnect_cbk(void *cls) 340reconnect_cbk (void *cls)
338{ 341{
339 struct GNUNET_CADET_Handle *h = cls; 342 struct GNUNET_CADET_Handle *h = cls;
340 343
341 h->reconnect_task = NULL; 344 h->reconnect_task = NULL;
342 h->reconnect_time = GNUNET_TIME_STD_BACKOFF(h->reconnect_time); 345 h->reconnect_time = GNUNET_TIME_STD_BACKOFF (h->reconnect_time);
343 reconnect(h); 346 reconnect (h);
344 GNUNET_CONTAINER_multihashmap_iterate(h->ports, &open_port_cb, h); 347 GNUNET_CONTAINER_multihashmap_iterate (h->ports, &open_port_cb, h);
345} 348}
346 349
347 350
@@ -351,12 +354,12 @@ reconnect_cbk(void *cls)
351 * @param ch Channel to notify about. 354 * @param ch Channel to notify about.
352 */ 355 */
353static void 356static void
354notify_window_size(struct GNUNET_CADET_Channel *ch) 357notify_window_size (struct GNUNET_CADET_Channel *ch)
355{ 358{
356 if (NULL != ch->window_changes) 359 if (NULL != ch->window_changes)
357 ch->window_changes(ch->ctx, 360 ch->window_changes (ch->ctx,
358 ch, /* FIXME: remove 'ch'? */ 361 ch, /* FIXME: remove 'ch'? */
359 ch->allow_send); 362 ch->allow_send);
360} 363}
361 364
362 365
@@ -366,32 +369,32 @@ notify_window_size(struct GNUNET_CADET_Channel *ch)
366 * @param cls Closure (channel whose mq to activate). 369 * @param cls Closure (channel whose mq to activate).
367 */ 370 */
368static void 371static void
369cadet_mq_send_now(void *cls) 372cadet_mq_send_now (void *cls)
370{ 373{
371 struct GNUNET_CADET_Channel *ch = cls; 374 struct GNUNET_CADET_Channel *ch = cls;
372 struct GNUNET_MQ_Envelope *env = ch->pending_env; 375 struct GNUNET_MQ_Envelope *env = ch->pending_env;
373 376
374 ch->mq_cont = NULL; 377 ch->mq_cont = NULL;
375 if (0 == ch->allow_send) 378 if (0 == ch->allow_send)
376 { 379 {
377 /* how did we get here? */ 380 /* how did we get here? */
378 GNUNET_break(0); 381 GNUNET_break (0);
379 return; 382 return;
380 } 383 }
381 if (NULL == env) 384 if (NULL == env)
382 { 385 {
383 /* how did we get here? */ 386 /* how did we get here? */
384 GNUNET_break(0); 387 GNUNET_break (0);
385 return; 388 return;
386 } 389 }
387 ch->allow_send--; 390 ch->allow_send--;
388 ch->pending_env = NULL; 391 ch->pending_env = NULL;
389 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
390 "Sending message on channel %s to CADET, new window size is %u\n", 393 "Sending message on channel %s to CADET, new window size is %u\n",
391 GNUNET_i2s(&ch->peer), 394 GNUNET_i2s (&ch->peer),
392 ch->allow_send); 395 ch->allow_send);
393 GNUNET_MQ_send(ch->cadet->mq, env); 396 GNUNET_MQ_send (ch->cadet->mq, env);
394 GNUNET_MQ_impl_send_continue(ch->mq); 397 GNUNET_MQ_impl_send_continue (ch->mq);
395} 398}
396 399
397 400
@@ -408,9 +411,9 @@ cadet_mq_send_now(void *cls)
408 * @param impl_state state of the implementation 411 * @param impl_state state of the implementation
409 */ 412 */
410static void 413static void
411cadet_mq_send_impl(struct GNUNET_MQ_Handle *mq, 414cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq,
412 const struct GNUNET_MessageHeader *msg, 415 const struct GNUNET_MessageHeader *msg,
413 void *impl_state) 416 void *impl_state)
414{ 417{
415 struct GNUNET_CADET_Channel *ch = impl_state; 418 struct GNUNET_CADET_Channel *ch = impl_state;
416 struct GNUNET_CADET_Handle *h = ch->cadet; 419 struct GNUNET_CADET_Handle *h = ch->cadet;
@@ -421,31 +424,31 @@ cadet_mq_send_impl(struct GNUNET_MQ_Handle *mq,
421 enum GNUNET_MQ_PriorityPreferences pp; 424 enum GNUNET_MQ_PriorityPreferences pp;
422 425
423 if (NULL == h->mq) 426 if (NULL == h->mq)
424 { 427 {
425 /* We're currently reconnecting, pretend this worked */ 428 /* We're currently reconnecting, pretend this worked */
426 GNUNET_MQ_impl_send_continue(mq); 429 GNUNET_MQ_impl_send_continue (mq);
427 return; 430 return;
428 } 431 }
429 orig_env = GNUNET_MQ_get_current_envelope(mq); 432 orig_env = GNUNET_MQ_get_current_envelope (mq);
430 pp = GNUNET_MQ_env_get_options(orig_env); 433 pp = GNUNET_MQ_env_get_options (orig_env);
431 434
432 /* check message size for sanity */ 435 /* check message size for sanity */
433 msize = ntohs(msg->size); 436 msize = ntohs (msg->size);
434 if (msize > GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE) 437 if (msize > GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE)
435 { 438 {
436 GNUNET_break(0); 439 GNUNET_break (0);
437 GNUNET_MQ_impl_send_continue(mq); 440 GNUNET_MQ_impl_send_continue (mq);
438 return; 441 return;
439 } 442 }
440 env = GNUNET_MQ_msg_nested_mh(cadet_msg, 443 env = GNUNET_MQ_msg_nested_mh (cadet_msg,
441 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, 444 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
442 msg); 445 msg);
443 cadet_msg->ccn = ch->ccn; 446 cadet_msg->ccn = ch->ccn;
444 cadet_msg->pp = htonl((uint32_t)pp); 447 cadet_msg->pp = htonl ((uint32_t) pp);
445 GNUNET_assert(NULL == ch->pending_env); 448 GNUNET_assert (NULL == ch->pending_env);
446 ch->pending_env = env; 449 ch->pending_env = env;
447 if (0 < ch->allow_send) 450 if (0 < ch->allow_send)
448 ch->mq_cont = GNUNET_SCHEDULER_add_now(&cadet_mq_send_now, ch); 451 ch->mq_cont = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, ch);
449} 452}
450 453
451 454
@@ -457,11 +460,11 @@ cadet_mq_send_impl(struct GNUNET_MQ_Handle *mq,
457 * @param impl_state state of the implementation 460 * @param impl_state state of the implementation
458 */ 461 */
459static void 462static void
460cadet_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) 463cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
461{ 464{
462 struct GNUNET_CADET_Channel *ch = impl_state; 465 struct GNUNET_CADET_Channel *ch = impl_state;
463 466
464 GNUNET_assert(mq == ch->mq); 467 GNUNET_assert (mq == ch->mq);
465 ch->mq = NULL; 468 ch->mq = NULL;
466} 469}
467 470
@@ -475,25 +478,25 @@ cadet_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
475 * @param error error code 478 * @param error error code
476 */ 479 */
477static void 480static void
478cadet_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) 481cadet_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
479{ 482{
480 struct GNUNET_CADET_Channel *ch = cls; 483 struct GNUNET_CADET_Channel *ch = cls;
481 484
482 if (GNUNET_MQ_ERROR_NO_MATCH == error) 485 if (GNUNET_MQ_ERROR_NO_MATCH == error)
483 { 486 {
484 /* Got a message we did not understand, still try to continue! */ 487 /* Got a message we did not understand, still try to continue! */
485 GNUNET_break_op(0); 488 GNUNET_break_op (0);
486 GNUNET_CADET_receive_done(ch); 489 GNUNET_CADET_receive_done (ch);
487 } 490 }
488 else 491 else
489 { 492 {
490 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 493 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
491 "MQ error in communication with CADET: %d\n", 494 "MQ error in communication with CADET: %d\n",
492 error); 495 error);
493 if (NULL != ch->disconnects) 496 if (NULL != ch->disconnects)
494 ch->disconnects(ch->ctx, ch); 497 ch->disconnects (ch->ctx, ch);
495 GNUNET_CADET_channel_destroy(ch); 498 GNUNET_CADET_channel_destroy (ch);
496 } 499 }
497} 500}
498 501
499 502
@@ -505,19 +508,19 @@ cadet_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
505 * @param impl_state state specific to the implementation 508 * @param impl_state state specific to the implementation
506 */ 509 */
507static void 510static void
508cadet_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) 511cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
509{ 512{
510 struct GNUNET_CADET_Channel *ch = impl_state; 513 struct GNUNET_CADET_Channel *ch = impl_state;
511 514
512 (void)mq; 515 (void) mq;
513 GNUNET_assert(NULL != ch->pending_env); 516 GNUNET_assert (NULL != ch->pending_env);
514 GNUNET_MQ_discard(ch->pending_env); 517 GNUNET_MQ_discard (ch->pending_env);
515 ch->pending_env = NULL; 518 ch->pending_env = NULL;
516 if (NULL != ch->mq_cont) 519 if (NULL != ch->mq_cont)
517 { 520 {
518 GNUNET_SCHEDULER_cancel(ch->mq_cont); 521 GNUNET_SCHEDULER_cancel (ch->mq_cont);
519 ch->mq_cont = NULL; 522 ch->mq_cont = NULL;
520 } 523 }
521} 524}
522 525
523 526
@@ -528,7 +531,7 @@ cadet_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
528 * @param msg A message with the details of the new incoming channel 531 * @param msg A message with the details of the new incoming channel
529 */ 532 */
530static void 533static void
531handle_channel_created( 534handle_channel_created (
532 void *cls, 535 void *cls,
533 const struct GNUNET_CADET_LocalChannelCreateMessage *msg) 536 const struct GNUNET_CADET_LocalChannelCreateMessage *msg)
534{ 537{
@@ -540,52 +543,52 @@ handle_channel_created(
540 543
541 ccn = msg->ccn; 544 ccn = msg->ccn;
542 port_number = &msg->port; 545 port_number = &msg->port;
543 if (ntohl(ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 546 if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
544 { 547 {
545 GNUNET_break(0); 548 GNUNET_break (0);
546 return; 549 return;
547 } 550 }
548 port = find_port(h, port_number); 551 port = find_port (h, port_number);
549 if (NULL == port) 552 if (NULL == port)
550 { 553 {
551 /* We could have closed the port but the service didn't know about it yet 554 /* We could have closed the port but the service didn't know about it yet
552 * This is not an error. 555 * This is not an error.
553 */ 556 */
554 struct GNUNET_CADET_LocalChannelDestroyMessage *d_msg; 557 struct GNUNET_CADET_LocalChannelDestroyMessage *d_msg;
555 struct GNUNET_MQ_Envelope *env; 558 struct GNUNET_MQ_Envelope *env;
556 559
557 LOG(GNUNET_ERROR_TYPE_DEBUG, 560 LOG (GNUNET_ERROR_TYPE_DEBUG,
558 "No handler for incoming channel %X (on port %s, recently closed?)\n", 561 "No handler for incoming channel %X (on port %s, recently closed?)\n",
559 ntohl(ccn.channel_of_client), 562 ntohl (ccn.channel_of_client),
560 GNUNET_h2s(port_number)); 563 GNUNET_h2s (port_number));
561 env = 564 env =
562 GNUNET_MQ_msg(d_msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); 565 GNUNET_MQ_msg (d_msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
563 d_msg->ccn = msg->ccn; 566 d_msg->ccn = msg->ccn;
564 GNUNET_MQ_send(h->mq, env); 567 GNUNET_MQ_send (h->mq, env);
565 return; 568 return;
566 } 569 }
567 570
568 ch = create_channel(h, &ccn); 571 ch = create_channel (h, &ccn);
569 ch->peer = msg->peer; 572 ch->peer = msg->peer;
570 ch->incoming_port = port; 573 ch->incoming_port = port;
571 LOG(GNUNET_ERROR_TYPE_DEBUG, 574 LOG (GNUNET_ERROR_TYPE_DEBUG,
572 "Creating incoming channel %X [%s] %p\n", 575 "Creating incoming channel %X [%s] %p\n",
573 ntohl(ccn.channel_of_client), 576 ntohl (ccn.channel_of_client),
574 GNUNET_h2s(port_number), 577 GNUNET_h2s (port_number),
575 ch); 578 ch);
576 579
577 GNUNET_assert(NULL != port->connects); 580 GNUNET_assert (NULL != port->connects);
578 ch->window_changes = port->window_changes; 581 ch->window_changes = port->window_changes;
579 ch->disconnects = port->disconnects; 582 ch->disconnects = port->disconnects;
580 ch->mq = GNUNET_MQ_queue_for_callbacks(&cadet_mq_send_impl, 583 ch->mq = GNUNET_MQ_queue_for_callbacks (&cadet_mq_send_impl,
581 &cadet_mq_destroy_impl, 584 &cadet_mq_destroy_impl,
582 &cadet_mq_cancel_impl, 585 &cadet_mq_cancel_impl,
583 ch, 586 ch,
584 port->handlers, 587 port->handlers,
585 &cadet_mq_error_handler, 588 &cadet_mq_error_handler,
586 ch); 589 ch);
587 ch->ctx = port->connects(port->cls, ch, &msg->peer); 590 ch->ctx = port->connects (port->cls, ch, &msg->peer);
588 GNUNET_MQ_set_handlers_closure(ch->mq, ch->ctx); 591 GNUNET_MQ_set_handlers_closure (ch->mq, ch->ctx);
589} 592}
590 593
591 594
@@ -596,25 +599,25 @@ handle_channel_created(
596 * @param msg A message with the details of the channel being destroyed 599 * @param msg A message with the details of the channel being destroyed
597 */ 600 */
598static void 601static void
599handle_channel_destroy( 602handle_channel_destroy (
600 void *cls, 603 void *cls,
601 const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) 604 const struct GNUNET_CADET_LocalChannelDestroyMessage *msg)
602{ 605{
603 struct GNUNET_CADET_Handle *h = cls; 606 struct GNUNET_CADET_Handle *h = cls;
604 struct GNUNET_CADET_Channel *ch; 607 struct GNUNET_CADET_Channel *ch;
605 608
606 ch = find_channel(h, msg->ccn); 609 ch = find_channel (h, msg->ccn);
607 if (NULL == ch) 610 if (NULL == ch)
608 { 611 {
609 LOG(GNUNET_ERROR_TYPE_DEBUG, 612 LOG (GNUNET_ERROR_TYPE_DEBUG,
610 "Received channel destroy for unknown channel %X from CADET service (recently close?)\n", 613 "Received channel destroy for unknown channel %X from CADET service (recently close?)\n",
611 ntohl(msg->ccn.channel_of_client)); 614 ntohl (msg->ccn.channel_of_client));
612 return; 615 return;
613 } 616 }
614 LOG(GNUNET_ERROR_TYPE_DEBUG, 617 LOG (GNUNET_ERROR_TYPE_DEBUG,
615 "Received channel destroy for channel %X from CADET service\n", 618 "Received channel destroy for channel %X from CADET service\n",
616 ntohl(msg->ccn.channel_of_client)); 619 ntohl (msg->ccn.channel_of_client));
617 destroy_channel(ch); 620 destroy_channel (ch);
618} 621}
619 622
620 623
@@ -627,17 +630,17 @@ handle_channel_destroy(
627 * #GNUNET_SYSERR otherwise 630 * #GNUNET_SYSERR otherwise
628 */ 631 */
629static int 632static int
630check_local_data(void *cls, const struct GNUNET_CADET_LocalData *message) 633check_local_data (void *cls, const struct GNUNET_CADET_LocalData *message)
631{ 634{
632 uint16_t size; 635 uint16_t size;
633 636
634 (void)cls; 637 (void) cls;
635 size = ntohs(message->header.size); 638 size = ntohs (message->header.size);
636 if (sizeof(*message) + sizeof(struct GNUNET_MessageHeader) > size) 639 if (sizeof(*message) + sizeof(struct GNUNET_MessageHeader) > size)
637 { 640 {
638 GNUNET_break(0); 641 GNUNET_break (0);
639 return GNUNET_SYSERR; 642 return GNUNET_SYSERR;
640 } 643 }
641 return GNUNET_OK; 644 return GNUNET_OK;
642} 645}
643 646
@@ -649,7 +652,7 @@ check_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
649 * @param message A message encapsulating the data 652 * @param message A message encapsulating the data
650 */ 653 */
651static void 654static void
652handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message) 655handle_local_data (void *cls, const struct GNUNET_CADET_LocalData *message)
653{ 656{
654 struct GNUNET_CADET_Handle *h = cls; 657 struct GNUNET_CADET_Handle *h = cls;
655 const struct GNUNET_MessageHeader *payload; 658 const struct GNUNET_MessageHeader *payload;
@@ -657,25 +660,25 @@ handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
657 uint16_t type; 660 uint16_t type;
658 int fwd; 661 int fwd;
659 662
660 ch = find_channel(h, message->ccn); 663 ch = find_channel (h, message->ccn);
661 if (NULL == ch) 664 if (NULL == ch)
662 { 665 {
663 LOG(GNUNET_ERROR_TYPE_DEBUG, 666 LOG (GNUNET_ERROR_TYPE_DEBUG,
664 "Unknown channel %X for incoming data (recently closed?)\n", 667 "Unknown channel %X for incoming data (recently closed?)\n",
665 ntohl(message->ccn.channel_of_client)); 668 ntohl (message->ccn.channel_of_client));
666 return; 669 return;
667 } 670 }
668 671
669 payload = (const struct GNUNET_MessageHeader *)&message[1]; 672 payload = (const struct GNUNET_MessageHeader *) &message[1];
670 type = ntohs(payload->type); 673 type = ntohs (payload->type);
671 fwd = ntohl(ch->ccn.channel_of_client) <= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 674 fwd = ntohl (ch->ccn.channel_of_client) <= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI;
672 LOG(GNUNET_ERROR_TYPE_DEBUG, 675 LOG (GNUNET_ERROR_TYPE_DEBUG,
673 "Got a %s data on channel %s [%X] of type %u\n", 676 "Got a %s data on channel %s [%X] of type %u\n",
674 fwd ? "FWD" : "BWD", 677 fwd ? "FWD" : "BWD",
675 GNUNET_i2s(&ch->peer), 678 GNUNET_i2s (&ch->peer),
676 ntohl(message->ccn.channel_of_client), 679 ntohl (message->ccn.channel_of_client),
677 type); 680 type);
678 GNUNET_MQ_inject_message(ch->mq, payload); 681 GNUNET_MQ_inject_message (ch->mq, payload);
679} 682}
680 683
681 684
@@ -687,37 +690,37 @@ handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
687 * @param message Message itself. 690 * @param message Message itself.
688 */ 691 */
689static void 692static void
690handle_local_ack(void *cls, const struct GNUNET_CADET_LocalAck *message) 693handle_local_ack (void *cls, const struct GNUNET_CADET_LocalAck *message)
691{ 694{
692 struct GNUNET_CADET_Handle *h = cls; 695 struct GNUNET_CADET_Handle *h = cls;
693 struct GNUNET_CADET_Channel *ch; 696 struct GNUNET_CADET_Channel *ch;
694 697
695 ch = find_channel(h, message->ccn); 698 ch = find_channel (h, message->ccn);
696 if (NULL == ch) 699 if (NULL == ch)
697 { 700 {
698 LOG(GNUNET_ERROR_TYPE_DEBUG, 701 LOG (GNUNET_ERROR_TYPE_DEBUG,
699 "ACK on unknown channel %X\n", 702 "ACK on unknown channel %X\n",
700 ntohl(message->ccn.channel_of_client)); 703 ntohl (message->ccn.channel_of_client));
701 return; 704 return;
702 } 705 }
703 ch->allow_send++; 706 ch->allow_send++;
704 LOG(GNUNET_ERROR_TYPE_DEBUG, 707 LOG (GNUNET_ERROR_TYPE_DEBUG,
705 "Got an ACK on mq channel %X (peer %s); new window size is %u!\n", 708 "Got an ACK on mq channel %X (peer %s); new window size is %u!\n",
706 ntohl(ch->ccn.channel_of_client), 709 ntohl (ch->ccn.channel_of_client),
707 GNUNET_i2s(&ch->peer), 710 GNUNET_i2s (&ch->peer),
708 ch->allow_send); 711 ch->allow_send);
709 if (NULL == ch->pending_env) 712 if (NULL == ch->pending_env)
710 { 713 {
711 LOG(GNUNET_ERROR_TYPE_DEBUG, 714 LOG (GNUNET_ERROR_TYPE_DEBUG,
712 "Got an ACK on mq channel %X, allow send now %u!\n", 715 "Got an ACK on mq channel %X, allow send now %u!\n",
713 ntohl(ch->ccn.channel_of_client), 716 ntohl (ch->ccn.channel_of_client),
714 ch->allow_send); 717 ch->allow_send);
715 notify_window_size(ch); 718 notify_window_size (ch);
716 return; 719 return;
717 } 720 }
718 if (NULL != ch->mq_cont) 721 if (NULL != ch->mq_cont)
719 return; /* already working on it! */ 722 return; /* already working on it! */
720 ch->mq_cont = GNUNET_SCHEDULER_add_now(&cadet_mq_send_now, ch); 723 ch->mq_cont = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, ch);
721} 724}
722 725
723 726
@@ -731,16 +734,16 @@ handle_local_ack(void *cls, const struct GNUNET_CADET_LocalAck *message)
731 * @return #GNUNET_OK (continue to iterate) 734 * @return #GNUNET_OK (continue to iterate)
732 */ 735 */
733static int 736static int
734destroy_channel_cb(void *cls, uint32_t cid, void *value) 737destroy_channel_cb (void *cls, uint32_t cid, void *value)
735{ 738{
736 /* struct GNUNET_CADET_Handle *handle = cls; */ 739 /* struct GNUNET_CADET_Handle *handle = cls; */
737 struct GNUNET_CADET_Channel *ch = value; 740 struct GNUNET_CADET_Channel *ch = value;
738 741
739 (void)cls; 742 (void) cls;
740 (void)cid; 743 (void) cid;
741 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 744 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
742 "Destroying channel due to GNUNET_CADET_disconnect()\n"); 745 "Destroying channel due to GNUNET_CADET_disconnect()\n");
743 destroy_channel(ch); 746 destroy_channel (ch);
744 return GNUNET_OK; 747 return GNUNET_OK;
745} 748}
746 749
@@ -754,17 +757,17 @@ destroy_channel_cb(void *cls, uint32_t cid, void *value)
754 * @param error error code 757 * @param error error code
755 */ 758 */
756static void 759static void
757handle_mq_error(void *cls, enum GNUNET_MQ_Error error) 760handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
758{ 761{
759 struct GNUNET_CADET_Handle *h = cls; 762 struct GNUNET_CADET_Handle *h = cls;
760 763
761 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error); 764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error);
762 GNUNET_CONTAINER_multihashmap32_iterate(h->channels, &destroy_channel_cb, h); 765 GNUNET_CONTAINER_multihashmap32_iterate (h->channels, &destroy_channel_cb, h);
763 GNUNET_MQ_destroy(h->mq); 766 GNUNET_MQ_destroy (h->mq);
764 h->mq = NULL; 767 h->mq = NULL;
765 GNUNET_assert(NULL == h->reconnect_task); 768 GNUNET_assert (NULL == h->reconnect_task);
766 h->reconnect_task = 769 h->reconnect_task =
767 GNUNET_SCHEDULER_add_delayed(h->reconnect_time, &reconnect_cbk, h); 770 GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h);
768} 771}
769 772
770 773
@@ -775,30 +778,30 @@ handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
775 * @param h handle to the cadet 778 * @param h handle to the cadet
776 */ 779 */
777static void 780static void
778reconnect(struct GNUNET_CADET_Handle *h) 781reconnect (struct GNUNET_CADET_Handle *h)
779{ 782{
780 struct GNUNET_MQ_MessageHandler handlers[] = 783 struct GNUNET_MQ_MessageHandler handlers[] =
781 { GNUNET_MQ_hd_fixed_size(channel_created, 784 { GNUNET_MQ_hd_fixed_size (channel_created,
782 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, 785 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE,
783 struct GNUNET_CADET_LocalChannelCreateMessage, 786 struct GNUNET_CADET_LocalChannelCreateMessage,
784 h), 787 h),
785 GNUNET_MQ_hd_fixed_size(channel_destroy, 788 GNUNET_MQ_hd_fixed_size (channel_destroy,
786 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, 789 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY,
787 struct GNUNET_CADET_LocalChannelDestroyMessage, 790 struct GNUNET_CADET_LocalChannelDestroyMessage,
788 h), 791 h),
789 GNUNET_MQ_hd_var_size(local_data, 792 GNUNET_MQ_hd_var_size (local_data,
790 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, 793 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
791 struct GNUNET_CADET_LocalData, 794 struct GNUNET_CADET_LocalData,
792 h), 795 h),
793 GNUNET_MQ_hd_fixed_size(local_ack, 796 GNUNET_MQ_hd_fixed_size (local_ack,
794 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, 797 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK,
795 struct GNUNET_CADET_LocalAck, 798 struct GNUNET_CADET_LocalAck,
796 h), 799 h),
797 GNUNET_MQ_handler_end() }; 800 GNUNET_MQ_handler_end () };
798 801
799 GNUNET_assert(NULL == h->mq); 802 GNUNET_assert (NULL == h->mq);
800 h->mq = 803 h->mq =
801 GNUNET_CLIENT_connect(h->cfg, "cadet", handlers, &handle_mq_error, h); 804 GNUNET_CLIENT_connect (h->cfg, "cadet", handlers, &handle_mq_error, h);
802} 805}
803 806
804 807
@@ -812,16 +815,16 @@ reconnect(struct GNUNET_CADET_Handle *h)
812 * @return #GNUNET_OK (continue to iterate) 815 * @return #GNUNET_OK (continue to iterate)
813 */ 816 */
814static int 817static int
815destroy_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value) 818destroy_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value)
816{ 819{
817 /* struct GNUNET_CADET_Handle *handle = cls; */ 820 /* struct GNUNET_CADET_Handle *handle = cls; */
818 struct GNUNET_CADET_Port *port = value; 821 struct GNUNET_CADET_Port *port = value;
819 822
820 (void)cls; 823 (void) cls;
821 (void)id; 824 (void) id;
822 /* This is a warning, the app should have cleanly closed all open ports */ 825 /* This is a warning, the app should have cleanly closed all open ports */
823 GNUNET_break(0); 826 GNUNET_break (0);
824 GNUNET_CADET_close_port(port); 827 GNUNET_CADET_close_port (port);
825 return GNUNET_OK; 828 return GNUNET_OK;
826} 829}
827 830
@@ -835,29 +838,29 @@ destroy_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value)
835 * @param handle connection to cadet to disconnect 838 * @param handle connection to cadet to disconnect
836 */ 839 */
837void 840void
838GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle) 841GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle)
839{ 842{
840 GNUNET_CONTAINER_multihashmap_iterate(handle->ports, 843 GNUNET_CONTAINER_multihashmap_iterate (handle->ports,
841 &destroy_port_cb, 844 &destroy_port_cb,
842 handle); 845 handle);
843 GNUNET_CONTAINER_multihashmap_destroy(handle->ports); 846 GNUNET_CONTAINER_multihashmap_destroy (handle->ports);
844 handle->ports = NULL; 847 handle->ports = NULL;
845 GNUNET_CONTAINER_multihashmap32_iterate(handle->channels, 848 GNUNET_CONTAINER_multihashmap32_iterate (handle->channels,
846 &destroy_channel_cb, 849 &destroy_channel_cb,
847 handle); 850 handle);
848 GNUNET_CONTAINER_multihashmap32_destroy(handle->channels); 851 GNUNET_CONTAINER_multihashmap32_destroy (handle->channels);
849 handle->channels = NULL; 852 handle->channels = NULL;
850 if (NULL != handle->mq) 853 if (NULL != handle->mq)
851 { 854 {
852 GNUNET_MQ_destroy(handle->mq); 855 GNUNET_MQ_destroy (handle->mq);
853 handle->mq = NULL; 856 handle->mq = NULL;
854 } 857 }
855 if (NULL != handle->reconnect_task) 858 if (NULL != handle->reconnect_task)
856 { 859 {
857 GNUNET_SCHEDULER_cancel(handle->reconnect_task); 860 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
858 handle->reconnect_task = NULL; 861 handle->reconnect_task = NULL;
859 } 862 }
860 GNUNET_free(handle); 863 GNUNET_free (handle);
861} 864}
862 865
863 866
@@ -868,22 +871,22 @@ GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
868 * @param p Port handle. 871 * @param p Port handle.
869 */ 872 */
870void 873void
871GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p) 874GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p)
872{ 875{
873 GNUNET_assert( 876 GNUNET_assert (
874 GNUNET_YES == 877 GNUNET_YES ==
875 GNUNET_CONTAINER_multihashmap_remove(p->cadet->ports, &p->id, p)); 878 GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports, &p->id, p));
876 if (NULL != p->cadet->mq) 879 if (NULL != p->cadet->mq)
877 { 880 {
878 struct GNUNET_CADET_PortMessage *msg; 881 struct GNUNET_CADET_PortMessage *msg;
879 struct GNUNET_MQ_Envelope *env; 882 struct GNUNET_MQ_Envelope *env;
880 883
881 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE); 884 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE);
882 msg->port = p->id; 885 msg->port = p->id;
883 GNUNET_MQ_send(p->cadet->mq, env); 886 GNUNET_MQ_send (p->cadet->mq, env);
884 } 887 }
885 GNUNET_free_non_null(p->handlers); 888 GNUNET_free_non_null (p->handlers);
886 GNUNET_free(p); 889 GNUNET_free (p);
887} 890}
888 891
889 892
@@ -897,22 +900,22 @@ GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
897 * @param channel Channel handle, becomes invalid after this call. 900 * @param channel Channel handle, becomes invalid after this call.
898 */ 901 */
899void 902void
900GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel) 903GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
901{ 904{
902 struct GNUNET_CADET_Handle *h = channel->cadet; 905 struct GNUNET_CADET_Handle *h = channel->cadet;
903 struct GNUNET_CADET_LocalChannelDestroyMessage *msg; 906 struct GNUNET_CADET_LocalChannelDestroyMessage *msg;
904 struct GNUNET_MQ_Envelope *env; 907 struct GNUNET_MQ_Envelope *env;
905 908
906 if (NULL != h->mq) 909 if (NULL != h->mq)
907 { 910 {
908 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); 911 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
909 msg->ccn = channel->ccn; 912 msg->ccn = channel->ccn;
910 GNUNET_MQ_send(h->mq, env); 913 GNUNET_MQ_send (h->mq, env);
911 } 914 }
912 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 915 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
913 "Destroying channel due to GNUNET_CADET_channel_destroy()\n"); 916 "Destroying channel due to GNUNET_CADET_channel_destroy()\n");
914 channel->disconnects = NULL; 917 channel->disconnects = NULL;
915 destroy_channel(channel); 918 destroy_channel (channel);
916} 919}
917 920
918 921
@@ -926,19 +929,19 @@ GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
926 * @return Union with an answer to the query. 929 * @return Union with an answer to the query.
927 */ 930 */
928const union GNUNET_CADET_ChannelInfo * 931const union GNUNET_CADET_ChannelInfo *
929GNUNET_CADET_channel_get_info(struct GNUNET_CADET_Channel *channel, 932GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel,
930 enum GNUNET_CADET_ChannelInfoOption option, 933 enum GNUNET_CADET_ChannelInfoOption option,
931 ...) 934 ...)
932{ 935{
933 switch (option) 936 switch (option)
934 { 937 {
935 case GNUNET_CADET_OPTION_PEER: 938 case GNUNET_CADET_OPTION_PEER:
936 return (const union GNUNET_CADET_ChannelInfo *)&channel->peer; 939 return (const union GNUNET_CADET_ChannelInfo *) &channel->peer;
937 940
938 default: 941 default:
939 GNUNET_break(0); 942 GNUNET_break (0);
940 return NULL; 943 return NULL;
941 } 944 }
942} 945}
943 946
944 947
@@ -948,17 +951,17 @@ GNUNET_CADET_channel_get_info(struct GNUNET_CADET_Channel *channel,
948 * @param ch Channel on which to send the ACK. 951 * @param ch Channel on which to send the ACK.
949 */ 952 */
950void 953void
951GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel) 954GNUNET_CADET_receive_done (struct GNUNET_CADET_Channel *channel)
952{ 955{
953 struct GNUNET_CADET_LocalAck *msg; 956 struct GNUNET_CADET_LocalAck *msg;
954 struct GNUNET_MQ_Envelope *env; 957 struct GNUNET_MQ_Envelope *env;
955 958
956 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 959 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
957 LOG(GNUNET_ERROR_TYPE_DEBUG, 960 LOG (GNUNET_ERROR_TYPE_DEBUG,
958 "Sending ACK on channel %X\n", 961 "Sending ACK on channel %X\n",
959 ntohl(channel->ccn.channel_of_client)); 962 ntohl (channel->ccn.channel_of_client));
960 msg->ccn = channel->ccn; 963 msg->ccn = channel->ccn;
961 GNUNET_MQ_send(channel->cadet->mq, env); 964 GNUNET_MQ_send (channel->cadet->mq, env);
962} 965}
963 966
964 967
@@ -970,23 +973,23 @@ GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
970 * @return Handle to the cadet service NULL on error. 973 * @return Handle to the cadet service NULL on error.
971 */ 974 */
972struct GNUNET_CADET_Handle * 975struct GNUNET_CADET_Handle *
973GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) 976GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
974{ 977{
975 struct GNUNET_CADET_Handle *h; 978 struct GNUNET_CADET_Handle *h;
976 979
977 LOG(GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n"); 980 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n");
978 h = GNUNET_new(struct GNUNET_CADET_Handle); 981 h = GNUNET_new (struct GNUNET_CADET_Handle);
979 h->cfg = cfg; 982 h->cfg = cfg;
980 h->ports = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_YES); 983 h->ports = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_YES);
981 h->channels = GNUNET_CONTAINER_multihashmap32_create(4); 984 h->channels = GNUNET_CONTAINER_multihashmap32_create (4);
982 reconnect(h); 985 reconnect (h);
983 if (NULL == h->mq) 986 if (NULL == h->mq)
984 { 987 {
985 GNUNET_break(0); 988 GNUNET_break (0);
986 GNUNET_CADET_disconnect(h); 989 GNUNET_CADET_disconnect (h);
987 return NULL; 990 return NULL;
988 } 991 }
989 h->next_ccn.channel_of_client = htonl(GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); 992 h->next_ccn.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
990 return h; 993 return h;
991} 994}
992 995
@@ -1004,41 +1007,41 @@ GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
1004 * @return Port handle, NULL if port is in use 1007 * @return Port handle, NULL if port is in use
1005 */ 1008 */
1006struct GNUNET_CADET_Port * 1009struct GNUNET_CADET_Port *
1007GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, 1010GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
1008 const struct GNUNET_HashCode *port, 1011 const struct GNUNET_HashCode *port,
1009 GNUNET_CADET_ConnectEventHandler connects, 1012 GNUNET_CADET_ConnectEventHandler connects,
1010 void *connects_cls, 1013 void *connects_cls,
1011 GNUNET_CADET_WindowSizeEventHandler window_changes, 1014 GNUNET_CADET_WindowSizeEventHandler window_changes,
1012 GNUNET_CADET_DisconnectEventHandler disconnects, 1015 GNUNET_CADET_DisconnectEventHandler disconnects,
1013 const struct GNUNET_MQ_MessageHandler *handlers) 1016 const struct GNUNET_MQ_MessageHandler *handlers)
1014{ 1017{
1015 struct GNUNET_CADET_Port *p; 1018 struct GNUNET_CADET_Port *p;
1016 1019
1017 GNUNET_assert(NULL != connects); 1020 GNUNET_assert (NULL != connects);
1018 GNUNET_assert(NULL != disconnects); 1021 GNUNET_assert (NULL != disconnects);
1019 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1020 "Listening to CADET port %s\n", 1023 "Listening to CADET port %s\n",
1021 GNUNET_h2s(port)); 1024 GNUNET_h2s (port));
1022 1025
1023 p = GNUNET_new(struct GNUNET_CADET_Port); 1026 p = GNUNET_new (struct GNUNET_CADET_Port);
1024 p->cadet = h; 1027 p->cadet = h;
1025 p->id = *port; 1028 p->id = *port;
1026 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( 1029 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (
1027 h->ports, 1030 h->ports,
1028 &p->id, 1031 &p->id,
1029 p, 1032 p,
1030 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1033 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1031 { 1034 {
1032 GNUNET_free(p); 1035 GNUNET_free (p);
1033 return NULL; 1036 return NULL;
1034 } 1037 }
1035 p->connects = connects; 1038 p->connects = connects;
1036 p->cls = connects_cls; 1039 p->cls = connects_cls;
1037 p->window_changes = window_changes; 1040 p->window_changes = window_changes;
1038 p->disconnects = disconnects; 1041 p->disconnects = disconnects;
1039 p->handlers = GNUNET_MQ_copy_handlers(handlers); 1042 p->handlers = GNUNET_MQ_copy_handlers (handlers);
1040 1043
1041 GNUNET_assert(GNUNET_OK == open_port_cb(h, &p->id, p)); 1044 GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p));
1042 return p; 1045 return p;
1043} 1046}
1044 1047
@@ -1062,45 +1065,45 @@ GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h,
1062 * @return Handle to the channel. 1065 * @return Handle to the channel.
1063 */ 1066 */
1064struct GNUNET_CADET_Channel * 1067struct GNUNET_CADET_Channel *
1065GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h, 1068GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
1066 void *channel_cls, 1069 void *channel_cls,
1067 const struct GNUNET_PeerIdentity *destination, 1070 const struct GNUNET_PeerIdentity *destination,
1068 const struct GNUNET_HashCode *port, 1071 const struct GNUNET_HashCode *port,
1069 GNUNET_CADET_WindowSizeEventHandler window_changes, 1072 GNUNET_CADET_WindowSizeEventHandler window_changes,
1070 GNUNET_CADET_DisconnectEventHandler disconnects, 1073 GNUNET_CADET_DisconnectEventHandler disconnects,
1071 const struct GNUNET_MQ_MessageHandler *handlers) 1074 const struct GNUNET_MQ_MessageHandler *handlers)
1072{ 1075{
1073 struct GNUNET_CADET_Channel *ch; 1076 struct GNUNET_CADET_Channel *ch;
1074 struct GNUNET_CADET_LocalChannelCreateMessage *msg; 1077 struct GNUNET_CADET_LocalChannelCreateMessage *msg;
1075 struct GNUNET_MQ_Envelope *env; 1078 struct GNUNET_MQ_Envelope *env;
1076 1079
1077 GNUNET_assert(NULL != disconnects); 1080 GNUNET_assert (NULL != disconnects);
1078 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079 "Creating channel to peer %s at port %s\n", 1082 "Creating channel to peer %s at port %s\n",
1080 GNUNET_i2s(destination), 1083 GNUNET_i2s (destination),
1081 GNUNET_h2s(port)); 1084 GNUNET_h2s (port));
1082 ch = create_channel(h, NULL); 1085 ch = create_channel (h, NULL);
1083 ch->ctx = channel_cls; 1086 ch->ctx = channel_cls;
1084 ch->peer = *destination; 1087 ch->peer = *destination;
1085 ch->window_changes = window_changes; 1088 ch->window_changes = window_changes;
1086 ch->disconnects = disconnects; 1089 ch->disconnects = disconnects;
1087 1090
1088 /* Create MQ for channel */ 1091 /* Create MQ for channel */
1089 ch->mq = GNUNET_MQ_queue_for_callbacks(&cadet_mq_send_impl, 1092 ch->mq = GNUNET_MQ_queue_for_callbacks (&cadet_mq_send_impl,
1090 &cadet_mq_destroy_impl, 1093 &cadet_mq_destroy_impl,
1091 &cadet_mq_cancel_impl, 1094 &cadet_mq_cancel_impl,
1092 ch, 1095 ch,
1093 handlers, 1096 handlers,
1094 &cadet_mq_error_handler, 1097 &cadet_mq_error_handler,
1095 ch); 1098 ch);
1096 GNUNET_MQ_set_handlers_closure(ch->mq, channel_cls); 1099 GNUNET_MQ_set_handlers_closure (ch->mq, channel_cls);
1097 1100
1098 /* Request channel creation to service */ 1101 /* Request channel creation to service */
1099 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); 1102 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
1100 msg->ccn = ch->ccn; 1103 msg->ccn = ch->ccn;
1101 msg->port = *port; 1104 msg->port = *port;
1102 msg->peer = *destination; 1105 msg->peer = *destination;
1103 GNUNET_MQ_send(h->mq, env); 1106 GNUNET_MQ_send (h->mq, env);
1104 return ch; 1107 return ch;
1105} 1108}
1106 1109
@@ -1113,7 +1116,7 @@ GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h,
1113 * @return NULL if @a channel is not yet connected. 1116 * @return NULL if @a channel is not yet connected.
1114 */ 1117 */
1115struct GNUNET_MQ_Handle * 1118struct GNUNET_MQ_Handle *
1116GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel) 1119GNUNET_CADET_get_mq (const struct GNUNET_CADET_Channel *channel)
1117{ 1120{
1118 return channel->mq; 1121 return channel->mq;
1119} 1122}
diff --git a/src/cadet/cadet_api_get_channel.c b/src/cadet/cadet_api_get_channel.c
index 5479f4238..6d86e8e81 100644
--- a/src/cadet/cadet_api_get_channel.c
+++ b/src/cadet/cadet_api_get_channel.c
@@ -34,7 +34,8 @@
34/** 34/**
35 * Operation handle. 35 * Operation handle.
36 */ 36 */
37struct GNUNET_CADET_ChannelMonitor { 37struct GNUNET_CADET_ChannelMonitor
38{
38 /** 39 /**
39 * Channel callback. 40 * Channel callback.
40 */ 41 */
@@ -81,10 +82,10 @@ struct GNUNET_CADET_ChannelMonitor {
81 * #GNUNET_SYSERR otherwise 82 * #GNUNET_SYSERR otherwise
82 */ 83 */
83static int 84static int
84check_channel_info(void *cls, 85check_channel_info (void *cls,
85 const struct GNUNET_CADET_ChannelInfoMessage *message) 86 const struct GNUNET_CADET_ChannelInfoMessage *message)
86{ 87{
87 (void)cls; 88 (void) cls;
88 89
89 return GNUNET_OK; 90 return GNUNET_OK;
90} 91}
@@ -97,17 +98,17 @@ check_channel_info(void *cls,
97 * @param message Message itself. 98 * @param message Message itself.
98 */ 99 */
99static void 100static void
100handle_channel_info(void *cls, 101handle_channel_info (void *cls,
101 const struct GNUNET_CADET_ChannelInfoMessage *message) 102 const struct GNUNET_CADET_ChannelInfoMessage *message)
102{ 103{
103 struct GNUNET_CADET_ChannelMonitor *cm = cls; 104 struct GNUNET_CADET_ChannelMonitor *cm = cls;
104 struct GNUNET_CADET_ChannelInternals ci; 105 struct GNUNET_CADET_ChannelInternals ci;
105 106
106 ci.root = message->root; 107 ci.root = message->root;
107 ci.dest = message->dest; 108 ci.dest = message->dest;
108 cm->channel_cb(cm->channel_cb_cls, 109 cm->channel_cb (cm->channel_cb_cls,
109 &ci); 110 &ci);
110 GNUNET_CADET_get_channel_cancel(cm); 111 GNUNET_CADET_get_channel_cancel (cm);
111} 112}
112 113
113 114
@@ -118,14 +119,14 @@ handle_channel_info(void *cls,
118 * @param message Message itself. 119 * @param message Message itself.
119 */ 120 */
120static void 121static void
121handle_channel_info_end(void *cls, 122handle_channel_info_end (void *cls,
122 const struct GNUNET_MessageHeader *message) 123 const struct GNUNET_MessageHeader *message)
123{ 124{
124 struct GNUNET_CADET_ChannelMonitor *cm = cls; 125 struct GNUNET_CADET_ChannelMonitor *cm = cls;
125 126
126 cm->channel_cb(cm->channel_cb_cls, 127 cm->channel_cb (cm->channel_cb_cls,
127 NULL); 128 NULL);
128 GNUNET_CADET_get_channel_cancel(cm); 129 GNUNET_CADET_get_channel_cancel (cm);
129} 130}
130 131
131 132
@@ -135,7 +136,7 @@ handle_channel_info_end(void *cls,
135 * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation 136 * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation
136 */ 137 */
137static void 138static void
138reconnect(void *cls); 139reconnect (void *cls);
139 140
140 141
141/** 142/**
@@ -145,18 +146,18 @@ reconnect(void *cls);
145 * @param error error code from MQ 146 * @param error error code from MQ
146 */ 147 */
147static void 148static void
148error_handler(void *cls, 149error_handler (void *cls,
149 enum GNUNET_MQ_Error error) 150 enum GNUNET_MQ_Error error)
150{ 151{
151 struct GNUNET_CADET_ChannelMonitor *cm = cls; 152 struct GNUNET_CADET_ChannelMonitor *cm = cls;
152 153
153 GNUNET_MQ_destroy(cm->mq); 154 GNUNET_MQ_destroy (cm->mq);
154 cm->mq = NULL; 155 cm->mq = NULL;
155 cm->backoff = GNUNET_TIME_randomized_backoff(cm->backoff, 156 cm->backoff = GNUNET_TIME_randomized_backoff (cm->backoff,
156 GNUNET_TIME_UNIT_MINUTES); 157 GNUNET_TIME_UNIT_MINUTES);
157 cm->reconnect_task = GNUNET_SCHEDULER_add_delayed(cm->backoff, 158 cm->reconnect_task = GNUNET_SCHEDULER_add_delayed (cm->backoff,
158 &reconnect, 159 &reconnect,
159 cm); 160 cm);
160} 161}
161 162
162 163
@@ -166,36 +167,36 @@ error_handler(void *cls,
166 * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation 167 * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation
167 */ 168 */
168static void 169static void
169reconnect(void *cls) 170reconnect (void *cls)
170{ 171{
171 struct GNUNET_CADET_ChannelMonitor *cm = cls; 172 struct GNUNET_CADET_ChannelMonitor *cm = cls;
172 struct GNUNET_MQ_MessageHandler handlers[] = { 173 struct GNUNET_MQ_MessageHandler handlers[] = {
173 GNUNET_MQ_hd_fixed_size(channel_info_end, 174 GNUNET_MQ_hd_fixed_size (channel_info_end,
174 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END, 175 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END,
175 struct GNUNET_MessageHeader, 176 struct GNUNET_MessageHeader,
176 cm), 177 cm),
177 GNUNET_MQ_hd_var_size(channel_info, 178 GNUNET_MQ_hd_var_size (channel_info,
178 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL, 179 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL,
179 struct GNUNET_CADET_ChannelInfoMessage, 180 struct GNUNET_CADET_ChannelInfoMessage,
180 cm), 181 cm),
181 GNUNET_MQ_handler_end() 182 GNUNET_MQ_handler_end ()
182 }; 183 };
183 struct GNUNET_CADET_RequestChannelInfoMessage *msg; 184 struct GNUNET_CADET_RequestChannelInfoMessage *msg;
184 struct GNUNET_MQ_Envelope *env; 185 struct GNUNET_MQ_Envelope *env;
185 186
186 cm->reconnect_task = NULL; 187 cm->reconnect_task = NULL;
187 cm->mq = GNUNET_CLIENT_connect(cm->cfg, 188 cm->mq = GNUNET_CLIENT_connect (cm->cfg,
188 "cadet", 189 "cadet",
189 handlers, 190 handlers,
190 &error_handler, 191 &error_handler,
191 cm); 192 cm);
192 if (NULL == cm->mq) 193 if (NULL == cm->mq)
193 return; 194 return;
194 env = GNUNET_MQ_msg(msg, 195 env = GNUNET_MQ_msg (msg,
195 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL); 196 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL);
196 msg->target = cm->peer; 197 msg->target = cm->peer;
197 GNUNET_MQ_send(cm->mq, 198 GNUNET_MQ_send (cm->mq,
198 env); 199 env);
199} 200}
200 201
201 202
@@ -209,29 +210,29 @@ reconnect(void *cls)
209 * @return NULL on error 210 * @return NULL on error
210 */ 211 */
211struct GNUNET_CADET_ChannelMonitor * 212struct GNUNET_CADET_ChannelMonitor *
212GNUNET_CADET_get_channel(const struct GNUNET_CONFIGURATION_Handle *cfg, 213GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg,
213 struct GNUNET_PeerIdentity *peer, 214 struct GNUNET_PeerIdentity *peer,
214 GNUNET_CADET_ChannelCB callback, 215 GNUNET_CADET_ChannelCB callback,
215 void *callback_cls) 216 void *callback_cls)
216{ 217{
217 struct GNUNET_CADET_ChannelMonitor *cm; 218 struct GNUNET_CADET_ChannelMonitor *cm;
218 219
219 if (NULL == callback) 220 if (NULL == callback)
220 { 221 {
221 GNUNET_break(0); 222 GNUNET_break (0);
222 return NULL; 223 return NULL;
223 } 224 }
224 cm = GNUNET_new(struct GNUNET_CADET_ChannelMonitor); 225 cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor);
225 cm->channel_cb = callback; 226 cm->channel_cb = callback;
226 cm->channel_cb_cls = callback_cls; 227 cm->channel_cb_cls = callback_cls;
227 cm->cfg = cfg; 228 cm->cfg = cfg;
228 cm->peer = *peer; 229 cm->peer = *peer;
229 reconnect(cm); 230 reconnect (cm);
230 if (NULL == cm->mq) 231 if (NULL == cm->mq)
231 { 232 {
232 GNUNET_free(cm); 233 GNUNET_free (cm);
233 return NULL; 234 return NULL;
234 } 235 }
235 return cm; 236 return cm;
236} 237}
237 238
@@ -243,15 +244,15 @@ GNUNET_CADET_get_channel(const struct GNUNET_CONFIGURATION_Handle *cfg,
243 * @return Closure that was given to #GNUNET_CADET_get_channel(). 244 * @return Closure that was given to #GNUNET_CADET_get_channel().
244 */ 245 */
245void * 246void *
246GNUNET_CADET_get_channel_cancel(struct GNUNET_CADET_ChannelMonitor *cm) 247GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm)
247{ 248{
248 void *ret = cm->channel_cb_cls; 249 void *ret = cm->channel_cb_cls;
249 250
250 if (NULL != cm->mq) 251 if (NULL != cm->mq)
251 GNUNET_MQ_destroy(cm->mq); 252 GNUNET_MQ_destroy (cm->mq);
252 if (NULL != cm->reconnect_task) 253 if (NULL != cm->reconnect_task)
253 GNUNET_SCHEDULER_cancel(cm->reconnect_task); 254 GNUNET_SCHEDULER_cancel (cm->reconnect_task);
254 GNUNET_free(cm); 255 GNUNET_free (cm);
255 return ret; 256 return ret;
256} 257}
257 258
diff --git a/src/cadet/cadet_api_get_path.c b/src/cadet/cadet_api_get_path.c
index 0f18014c3..68070eab2 100644
--- a/src/cadet/cadet_api_get_path.c
+++ b/src/cadet/cadet_api_get_path.c
@@ -34,7 +34,8 @@
34/** 34/**
35 * Operation handle. 35 * Operation handle.
36 */ 36 */
37struct GNUNET_CADET_GetPath { 37struct GNUNET_CADET_GetPath
38{
38 /** 39 /**
39 * Monitor callback 40 * Monitor callback
40 */ 41 */
@@ -81,24 +82,24 @@ struct GNUNET_CADET_GetPath {
81 * #GNUNET_SYSERR otherwise 82 * #GNUNET_SYSERR otherwise
82 */ 83 */
83static int 84static int
84check_get_path(void *cls, 85check_get_path (void *cls,
85 const struct GNUNET_CADET_LocalInfoPath *message) 86 const struct GNUNET_CADET_LocalInfoPath *message)
86{ 87{
87 size_t msize = sizeof(struct GNUNET_CADET_LocalInfoPath); 88 size_t msize = sizeof(struct GNUNET_CADET_LocalInfoPath);
88 size_t esize; 89 size_t esize;
89 90
90 (void)cls; 91 (void) cls;
91 esize = ntohs(message->header.size); 92 esize = ntohs (message->header.size);
92 if (esize < msize) 93 if (esize < msize)
93 { 94 {
94 GNUNET_break(0); 95 GNUNET_break (0);
95 return GNUNET_SYSERR; 96 return GNUNET_SYSERR;
96 } 97 }
97 if (0 != ((esize - msize) % sizeof(struct GNUNET_PeerIdentity))) 98 if (0 != ((esize - msize) % sizeof(struct GNUNET_PeerIdentity)))
98 { 99 {
99 GNUNET_break(0); 100 GNUNET_break (0);
100 return GNUNET_SYSERR; 101 return GNUNET_SYSERR;
101 } 102 }
102 return GNUNET_OK; 103 return GNUNET_OK;
103} 104}
104 105
@@ -110,19 +111,19 @@ check_get_path(void *cls,
110 * @param message Message itself. 111 * @param message Message itself.
111 */ 112 */
112static void 113static void
113handle_get_path(void *cls, 114handle_get_path (void *cls,
114 const struct GNUNET_CADET_LocalInfoPath *message) 115 const struct GNUNET_CADET_LocalInfoPath *message)
115{ 116{
116 struct GNUNET_CADET_GetPath *gp = cls; 117 struct GNUNET_CADET_GetPath *gp = cls;
117 struct GNUNET_CADET_PeerPathDetail ppd; 118 struct GNUNET_CADET_PeerPathDetail ppd;
118 119
119 ppd.peer = gp->id; 120 ppd.peer = gp->id;
120 ppd.path = (const struct GNUNET_PeerIdentity *)&message[1]; 121 ppd.path = (const struct GNUNET_PeerIdentity *) &message[1];
121 ppd.target_offset = ntohl(message->off); 122 ppd.target_offset = ntohl (message->off);
122 ppd.path_length = (ntohs(message->header.size) - sizeof(*message)) 123 ppd.path_length = (ntohs (message->header.size) - sizeof(*message))
123 / sizeof(struct GNUNET_PeerIdentity); 124 / sizeof(struct GNUNET_PeerIdentity);
124 gp->path_cb(gp->path_cb_cls, 125 gp->path_cb (gp->path_cb_cls,
125 &ppd); 126 &ppd);
126} 127}
127 128
128 129
@@ -133,15 +134,15 @@ handle_get_path(void *cls,
133 * @param message Message itself. 134 * @param message Message itself.
134 */ 135 */
135static void 136static void
136handle_get_path_end(void *cls, 137handle_get_path_end (void *cls,
137 const struct GNUNET_MessageHeader *message) 138 const struct GNUNET_MessageHeader *message)
138{ 139{
139 struct GNUNET_CADET_GetPath *gp = cls; 140 struct GNUNET_CADET_GetPath *gp = cls;
140 141
141 (void)message; 142 (void) message;
142 gp->path_cb(gp->path_cb_cls, 143 gp->path_cb (gp->path_cb_cls,
143 NULL); 144 NULL);
144 GNUNET_CADET_get_path_cancel(gp); 145 GNUNET_CADET_get_path_cancel (gp);
145} 146}
146 147
147 148
@@ -151,7 +152,7 @@ handle_get_path_end(void *cls,
151 * @param cls a `struct GNUNET_CADET_GetPath` operation 152 * @param cls a `struct GNUNET_CADET_GetPath` operation
152 */ 153 */
153static void 154static void
154reconnect(void *cls); 155reconnect (void *cls);
155 156
156 157
157/** 158/**
@@ -161,18 +162,18 @@ reconnect(void *cls);
161 * @param error error code from MQ 162 * @param error error code from MQ
162 */ 163 */
163static void 164static void
164error_handler(void *cls, 165error_handler (void *cls,
165 enum GNUNET_MQ_Error error) 166 enum GNUNET_MQ_Error error)
166{ 167{
167 struct GNUNET_CADET_GetPath *gp = cls; 168 struct GNUNET_CADET_GetPath *gp = cls;
168 169
169 GNUNET_MQ_destroy(gp->mq); 170 GNUNET_MQ_destroy (gp->mq);
170 gp->mq = NULL; 171 gp->mq = NULL;
171 gp->backoff = GNUNET_TIME_randomized_backoff(gp->backoff, 172 gp->backoff = GNUNET_TIME_randomized_backoff (gp->backoff,
172 GNUNET_TIME_UNIT_MINUTES); 173 GNUNET_TIME_UNIT_MINUTES);
173 gp->reconnect_task = GNUNET_SCHEDULER_add_delayed(gp->backoff, 174 gp->reconnect_task = GNUNET_SCHEDULER_add_delayed (gp->backoff,
174 &reconnect, 175 &reconnect,
175 gp); 176 gp);
176} 177}
177 178
178 179
@@ -182,36 +183,36 @@ error_handler(void *cls,
182 * @param cls a `struct GNUNET_CADET_GetPath` operation 183 * @param cls a `struct GNUNET_CADET_GetPath` operation
183 */ 184 */
184static void 185static void
185reconnect(void *cls) 186reconnect (void *cls)
186{ 187{
187 struct GNUNET_CADET_GetPath *gp = cls; 188 struct GNUNET_CADET_GetPath *gp = cls;
188 struct GNUNET_MQ_MessageHandler handlers[] = { 189 struct GNUNET_MQ_MessageHandler handlers[] = {
189 GNUNET_MQ_hd_var_size(get_path, 190 GNUNET_MQ_hd_var_size (get_path,
190 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH, 191 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH,
191 struct GNUNET_CADET_LocalInfoPath, 192 struct GNUNET_CADET_LocalInfoPath,
192 gp), 193 gp),
193 GNUNET_MQ_hd_fixed_size(get_path_end, 194 GNUNET_MQ_hd_fixed_size (get_path_end,
194 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END, 195 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END,
195 struct GNUNET_MessageHeader, 196 struct GNUNET_MessageHeader,
196 gp), 197 gp),
197 GNUNET_MQ_handler_end() 198 GNUNET_MQ_handler_end ()
198 }; 199 };
199 struct GNUNET_CADET_RequestPathInfoMessage *msg; 200 struct GNUNET_CADET_RequestPathInfoMessage *msg;
200 struct GNUNET_MQ_Envelope *env; 201 struct GNUNET_MQ_Envelope *env;
201 202
202 gp->reconnect_task = NULL; 203 gp->reconnect_task = NULL;
203 gp->mq = GNUNET_CLIENT_connect(gp->cfg, 204 gp->mq = GNUNET_CLIENT_connect (gp->cfg,
204 "cadet", 205 "cadet",
205 handlers, 206 handlers,
206 &error_handler, 207 &error_handler,
207 gp); 208 gp);
208 if (NULL == gp->mq) 209 if (NULL == gp->mq)
209 return; 210 return;
210 env = GNUNET_MQ_msg(msg, 211 env = GNUNET_MQ_msg (msg,
211 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH); 212 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH);
212 msg->peer = gp->id; 213 msg->peer = gp->id;
213 GNUNET_MQ_send(gp->mq, 214 GNUNET_MQ_send (gp->mq,
214 env); 215 env);
215} 216}
216 217
217 218
@@ -225,29 +226,29 @@ reconnect(void *cls)
225 * @return NULL on error 226 * @return NULL on error
226 */ 227 */
227struct GNUNET_CADET_GetPath * 228struct GNUNET_CADET_GetPath *
228GNUNET_CADET_get_path(const struct GNUNET_CONFIGURATION_Handle *cfg, 229GNUNET_CADET_get_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
229 const struct GNUNET_PeerIdentity *id, 230 const struct GNUNET_PeerIdentity *id,
230 GNUNET_CADET_PathCB callback, 231 GNUNET_CADET_PathCB callback,
231 void *callback_cls) 232 void *callback_cls)
232{ 233{
233 struct GNUNET_CADET_GetPath *gp; 234 struct GNUNET_CADET_GetPath *gp;
234 235
235 if (NULL == callback) 236 if (NULL == callback)
236 { 237 {
237 GNUNET_break(0); 238 GNUNET_break (0);
238 return NULL; 239 return NULL;
239 } 240 }
240 gp = GNUNET_new(struct GNUNET_CADET_GetPath); 241 gp = GNUNET_new (struct GNUNET_CADET_GetPath);
241 gp->path_cb = callback; 242 gp->path_cb = callback;
242 gp->path_cb_cls = callback_cls; 243 gp->path_cb_cls = callback_cls;
243 gp->cfg = cfg; 244 gp->cfg = cfg;
244 gp->id = *id; 245 gp->id = *id;
245 reconnect(gp); 246 reconnect (gp);
246 if (NULL == gp->mq) 247 if (NULL == gp->mq)
247 { 248 {
248 GNUNET_free(gp); 249 GNUNET_free (gp);
249 return NULL; 250 return NULL;
250 } 251 }
251 return gp; 252 return gp;
252} 253}
253 254
@@ -259,15 +260,15 @@ GNUNET_CADET_get_path(const struct GNUNET_CONFIGURATION_Handle *cfg,
259 * @return closure from #GNUNET_CADET_get_path(). 260 * @return closure from #GNUNET_CADET_get_path().
260 */ 261 */
261void * 262void *
262GNUNET_CADET_get_path_cancel(struct GNUNET_CADET_GetPath *gp) 263GNUNET_CADET_get_path_cancel (struct GNUNET_CADET_GetPath *gp)
263{ 264{
264 void *ret = gp->path_cb_cls; 265 void *ret = gp->path_cb_cls;
265 266
266 if (NULL != gp->mq) 267 if (NULL != gp->mq)
267 GNUNET_MQ_destroy(gp->mq); 268 GNUNET_MQ_destroy (gp->mq);
268 if (NULL != gp->reconnect_task) 269 if (NULL != gp->reconnect_task)
269 GNUNET_SCHEDULER_cancel(gp->reconnect_task); 270 GNUNET_SCHEDULER_cancel (gp->reconnect_task);
270 GNUNET_free(gp); 271 GNUNET_free (gp);
271 return ret; 272 return ret;
272} 273}
273 274
diff --git a/src/cadet/cadet_api_helper.c b/src/cadet/cadet_api_helper.c
index 78e5eb45c..52aec6cc9 100644
--- a/src/cadet/cadet_api_helper.c
+++ b/src/cadet/cadet_api_helper.c
@@ -41,15 +41,14 @@
41 * @return A GNUNET_HashCode usable for the new CADET API. 41 * @return A GNUNET_HashCode usable for the new CADET API.
42 */ 42 */
43const struct GNUNET_HashCode * 43const struct GNUNET_HashCode *
44GC_u2h(uint32_t port) 44GC_u2h (uint32_t port)
45{ 45{
46 static struct GNUNET_HashCode hash; 46 static struct GNUNET_HashCode hash;
47 47
48 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 48 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
49 "This is a transitional function, use proper crypto hashes as CADET ports\n"); 49 "This is a transitional function, use proper crypto hashes as CADET ports\n");
50 GNUNET_CRYPTO_hash(&port, 50 GNUNET_CRYPTO_hash (&port,
51 sizeof(port), 51 sizeof(port),
52 &hash); 52 &hash);
53 return &hash; 53 return &hash;
54} 54}
55
diff --git a/src/cadet/cadet_api_list_peers.c b/src/cadet/cadet_api_list_peers.c
index 65e9ad4da..8865b6f57 100644
--- a/src/cadet/cadet_api_list_peers.c
+++ b/src/cadet/cadet_api_list_peers.c
@@ -34,7 +34,8 @@
34/** 34/**
35 * Operation handle. 35 * Operation handle.
36 */ 36 */
37struct GNUNET_CADET_PeersLister { 37struct GNUNET_CADET_PeersLister
38{
38 /** 39 /**
39 * Monitor callback 40 * Monitor callback
40 */ 41 */
@@ -74,18 +75,18 @@ struct GNUNET_CADET_PeersLister {
74 * @param info Message itself. 75 * @param info Message itself.
75 */ 76 */
76static void 77static void
77handle_get_peers(void *cls, 78handle_get_peers (void *cls,
78 const struct GNUNET_CADET_LocalInfoPeers *info) 79 const struct GNUNET_CADET_LocalInfoPeers *info)
79{ 80{
80 struct GNUNET_CADET_PeersLister *pl = cls; 81 struct GNUNET_CADET_PeersLister *pl = cls;
81 struct GNUNET_CADET_PeerListEntry ple; 82 struct GNUNET_CADET_PeerListEntry ple;
82 83
83 ple.peer = info->destination; 84 ple.peer = info->destination;
84 ple.have_tunnel = (int)ntohs(info->tunnel); 85 ple.have_tunnel = (int) ntohs (info->tunnel);
85 ple.n_paths = (unsigned int)ntohs(info->paths); 86 ple.n_paths = (unsigned int) ntohs (info->paths);
86 ple.best_path_length = (unsigned int)ntohl(info->best_path_length); 87 ple.best_path_length = (unsigned int) ntohl (info->best_path_length);
87 pl->peers_cb(pl->peers_cb_cls, 88 pl->peers_cb (pl->peers_cb_cls,
88 &ple); 89 &ple);
89} 90}
90 91
91 92
@@ -96,16 +97,16 @@ handle_get_peers(void *cls,
96 * @param msg Message itself. 97 * @param msg Message itself.
97 */ 98 */
98static void 99static void
99handle_get_peers_end(void *cls, 100handle_get_peers_end (void *cls,
100 const struct GNUNET_MessageHeader *msg) 101 const struct GNUNET_MessageHeader *msg)
101{ 102{
102 struct GNUNET_CADET_PeersLister *pl = cls; 103 struct GNUNET_CADET_PeersLister *pl = cls;
103 104
104 (void)msg; 105 (void) msg;
105 106
106 pl->peers_cb(pl->peers_cb_cls, 107 pl->peers_cb (pl->peers_cb_cls,
107 NULL); 108 NULL);
108 GNUNET_CADET_list_peers_cancel(pl); 109 GNUNET_CADET_list_peers_cancel (pl);
109} 110}
110 111
111 112
@@ -115,7 +116,7 @@ handle_get_peers_end(void *cls,
115 * @param cls a `struct GNUNET_CADET_PeersLister` operation 116 * @param cls a `struct GNUNET_CADET_PeersLister` operation
116 */ 117 */
117static void 118static void
118reconnect(void *cls); 119reconnect (void *cls);
119 120
120 121
121/** 122/**
@@ -125,18 +126,18 @@ reconnect(void *cls);
125 * @param error error code from MQ 126 * @param error error code from MQ
126 */ 127 */
127static void 128static void
128error_handler(void *cls, 129error_handler (void *cls,
129 enum GNUNET_MQ_Error error) 130 enum GNUNET_MQ_Error error)
130{ 131{
131 struct GNUNET_CADET_PeersLister *pl = cls; 132 struct GNUNET_CADET_PeersLister *pl = cls;
132 133
133 GNUNET_MQ_destroy(pl->mq); 134 GNUNET_MQ_destroy (pl->mq);
134 pl->mq = NULL; 135 pl->mq = NULL;
135 pl->backoff = GNUNET_TIME_randomized_backoff(pl->backoff, 136 pl->backoff = GNUNET_TIME_randomized_backoff (pl->backoff,
136 GNUNET_TIME_UNIT_MINUTES); 137 GNUNET_TIME_UNIT_MINUTES);
137 pl->reconnect_task = GNUNET_SCHEDULER_add_delayed(pl->backoff, 138 pl->reconnect_task = GNUNET_SCHEDULER_add_delayed (pl->backoff,
138 &reconnect, 139 &reconnect,
139 pl); 140 pl);
140} 141}
141 142
142 143
@@ -146,35 +147,35 @@ error_handler(void *cls,
146 * @param cls a `struct GNUNET_CADET_PeersLister` operation 147 * @param cls a `struct GNUNET_CADET_PeersLister` operation
147 */ 148 */
148static void 149static void
149reconnect(void *cls) 150reconnect (void *cls)
150{ 151{
151 struct GNUNET_CADET_PeersLister *pl = cls; 152 struct GNUNET_CADET_PeersLister *pl = cls;
152 struct GNUNET_MQ_MessageHandler handlers[] = { 153 struct GNUNET_MQ_MessageHandler handlers[] = {
153 GNUNET_MQ_hd_fixed_size(get_peers, 154 GNUNET_MQ_hd_fixed_size (get_peers,
154 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, 155 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
155 struct GNUNET_CADET_LocalInfoPeers, 156 struct GNUNET_CADET_LocalInfoPeers,
156 pl), 157 pl),
157 GNUNET_MQ_hd_fixed_size(get_peers_end, 158 GNUNET_MQ_hd_fixed_size (get_peers_end,
158 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END, 159 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END,
159 struct GNUNET_MessageHeader, 160 struct GNUNET_MessageHeader,
160 pl), 161 pl),
161 GNUNET_MQ_handler_end() 162 GNUNET_MQ_handler_end ()
162 }; 163 };
163 struct GNUNET_MessageHeader *msg; 164 struct GNUNET_MessageHeader *msg;
164 struct GNUNET_MQ_Envelope *env; 165 struct GNUNET_MQ_Envelope *env;
165 166
166 pl->reconnect_task = NULL; 167 pl->reconnect_task = NULL;
167 pl->mq = GNUNET_CLIENT_connect(pl->cfg, 168 pl->mq = GNUNET_CLIENT_connect (pl->cfg,
168 "cadet", 169 "cadet",
169 handlers, 170 handlers,
170 &error_handler, 171 &error_handler,
171 pl); 172 pl);
172 if (NULL == pl->mq) 173 if (NULL == pl->mq)
173 return; 174 return;
174 env = GNUNET_MQ_msg(msg, 175 env = GNUNET_MQ_msg (msg,
175 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS); 176 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS);
176 GNUNET_MQ_send(pl->mq, 177 GNUNET_MQ_send (pl->mq,
177 env); 178 env);
178} 179}
179 180
180 181
@@ -189,27 +190,27 @@ reconnect(void *cls)
189 * @return NULL on error 190 * @return NULL on error
190 */ 191 */
191struct GNUNET_CADET_PeersLister * 192struct GNUNET_CADET_PeersLister *
192GNUNET_CADET_list_peers(const struct GNUNET_CONFIGURATION_Handle *cfg, 193GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
193 GNUNET_CADET_PeersCB callback, 194 GNUNET_CADET_PeersCB callback,
194 void *callback_cls) 195 void *callback_cls)
195{ 196{
196 struct GNUNET_CADET_PeersLister *pl; 197 struct GNUNET_CADET_PeersLister *pl;
197 198
198 if (NULL == callback) 199 if (NULL == callback)
199 { 200 {
200 GNUNET_break(0); 201 GNUNET_break (0);
201 return NULL; 202 return NULL;
202 } 203 }
203 pl = GNUNET_new(struct GNUNET_CADET_PeersLister); 204 pl = GNUNET_new (struct GNUNET_CADET_PeersLister);
204 pl->peers_cb = callback; 205 pl->peers_cb = callback;
205 pl->peers_cb_cls = callback_cls; 206 pl->peers_cb_cls = callback_cls;
206 pl->cfg = cfg; 207 pl->cfg = cfg;
207 reconnect(pl); 208 reconnect (pl);
208 if (NULL == pl->mq) 209 if (NULL == pl->mq)
209 { 210 {
210 GNUNET_free(pl); 211 GNUNET_free (pl);
211 return NULL; 212 return NULL;
212 } 213 }
213 return pl; 214 return pl;
214} 215}
215 216
@@ -221,15 +222,15 @@ GNUNET_CADET_list_peers(const struct GNUNET_CONFIGURATION_Handle *cfg,
221 * @return Closure given to GNUNET_CADET_get_peers(). 222 * @return Closure given to GNUNET_CADET_get_peers().
222 */ 223 */
223void * 224void *
224GNUNET_CADET_list_peers_cancel(struct GNUNET_CADET_PeersLister *pl) 225GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_PeersLister *pl)
225{ 226{
226 void *ret = pl->peers_cb_cls; 227 void *ret = pl->peers_cb_cls;
227 228
228 if (NULL != pl->mq) 229 if (NULL != pl->mq)
229 GNUNET_MQ_destroy(pl->mq); 230 GNUNET_MQ_destroy (pl->mq);
230 if (NULL != pl->reconnect_task) 231 if (NULL != pl->reconnect_task)
231 GNUNET_SCHEDULER_cancel(pl->reconnect_task); 232 GNUNET_SCHEDULER_cancel (pl->reconnect_task);
232 GNUNET_free(pl); 233 GNUNET_free (pl);
233 return ret; 234 return ret;
234} 235}
235 236
diff --git a/src/cadet/cadet_api_list_tunnels.c b/src/cadet/cadet_api_list_tunnels.c
index 2ea8cf26c..e9ae069bb 100644
--- a/src/cadet/cadet_api_list_tunnels.c
+++ b/src/cadet/cadet_api_list_tunnels.c
@@ -34,7 +34,8 @@
34/** 34/**
35 * Operation handle. 35 * Operation handle.
36 */ 36 */
37struct GNUNET_CADET_ListTunnels { 37struct GNUNET_CADET_ListTunnels
38{
38 /** 39 /**
39 * Monitor callback 40 * Monitor callback
40 */ 41 */
@@ -74,19 +75,19 @@ struct GNUNET_CADET_ListTunnels {
74 * @param info Message itself. 75 * @param info Message itself.
75 */ 76 */
76static void 77static void
77handle_get_tunnels(void *cls, 78handle_get_tunnels (void *cls,
78 const struct GNUNET_CADET_LocalInfoTunnel *info) 79 const struct GNUNET_CADET_LocalInfoTunnel *info)
79{ 80{
80 struct GNUNET_CADET_ListTunnels *lt = cls; 81 struct GNUNET_CADET_ListTunnels *lt = cls;
81 struct GNUNET_CADET_TunnelDetails td; 82 struct GNUNET_CADET_TunnelDetails td;
82 83
83 td.peer = info->destination; 84 td.peer = info->destination;
84 td.channels = ntohl(info->channels); 85 td.channels = ntohl (info->channels);
85 td.connections = ntohl(info->connections); 86 td.connections = ntohl (info->connections);
86 td.estate = ntohs(info->estate); 87 td.estate = ntohs (info->estate);
87 td.cstate = ntohs(info->cstate); 88 td.cstate = ntohs (info->cstate);
88 lt->tunnels_cb(lt->tunnels_cb_cls, 89 lt->tunnels_cb (lt->tunnels_cb_cls,
89 &td); 90 &td);
90} 91}
91 92
92 93
@@ -97,16 +98,16 @@ handle_get_tunnels(void *cls,
97 * @param message Message itself. 98 * @param message Message itself.
98 */ 99 */
99static void 100static void
100handle_get_tunnels_end(void *cls, 101handle_get_tunnels_end (void *cls,
101 const struct GNUNET_MessageHeader *msg) 102 const struct GNUNET_MessageHeader *msg)
102{ 103{
103 struct GNUNET_CADET_ListTunnels *lt = cls; 104 struct GNUNET_CADET_ListTunnels *lt = cls;
104 105
105 (void)msg; 106 (void) msg;
106 107
107 lt->tunnels_cb(lt->tunnels_cb_cls, 108 lt->tunnels_cb (lt->tunnels_cb_cls,
108 NULL); 109 NULL);
109 GNUNET_CADET_list_tunnels_cancel(lt); 110 GNUNET_CADET_list_tunnels_cancel (lt);
110} 111}
111 112
112 113
@@ -116,7 +117,7 @@ handle_get_tunnels_end(void *cls,
116 * @param cls a `struct GNUNET_CADET_ListTunnels` operation 117 * @param cls a `struct GNUNET_CADET_ListTunnels` operation
117 */ 118 */
118static void 119static void
119reconnect(void *cls); 120reconnect (void *cls);
120 121
121 122
122/** 123/**
@@ -126,18 +127,18 @@ reconnect(void *cls);
126 * @param error error code from MQ 127 * @param error error code from MQ
127 */ 128 */
128static void 129static void
129error_handler(void *cls, 130error_handler (void *cls,
130 enum GNUNET_MQ_Error error) 131 enum GNUNET_MQ_Error error)
131{ 132{
132 struct GNUNET_CADET_ListTunnels *lt = cls; 133 struct GNUNET_CADET_ListTunnels *lt = cls;
133 134
134 GNUNET_MQ_destroy(lt->mq); 135 GNUNET_MQ_destroy (lt->mq);
135 lt->mq = NULL; 136 lt->mq = NULL;
136 lt->backoff = GNUNET_TIME_randomized_backoff(lt->backoff, 137 lt->backoff = GNUNET_TIME_randomized_backoff (lt->backoff,
137 GNUNET_TIME_UNIT_MINUTES); 138 GNUNET_TIME_UNIT_MINUTES);
138 lt->reconnect_task = GNUNET_SCHEDULER_add_delayed(lt->backoff, 139 lt->reconnect_task = GNUNET_SCHEDULER_add_delayed (lt->backoff,
139 &reconnect, 140 &reconnect,
140 lt); 141 lt);
141} 142}
142 143
143 144
@@ -147,35 +148,35 @@ error_handler(void *cls,
147 * @param cls a `struct GNUNET_CADET_ListTunnels` operation 148 * @param cls a `struct GNUNET_CADET_ListTunnels` operation
148 */ 149 */
149static void 150static void
150reconnect(void *cls) 151reconnect (void *cls)
151{ 152{
152 struct GNUNET_CADET_ListTunnels *lt = cls; 153 struct GNUNET_CADET_ListTunnels *lt = cls;
153 struct GNUNET_MQ_MessageHandler handlers[] = { 154 struct GNUNET_MQ_MessageHandler handlers[] = {
154 GNUNET_MQ_hd_fixed_size(get_tunnels, 155 GNUNET_MQ_hd_fixed_size (get_tunnels,
155 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, 156 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
156 struct GNUNET_CADET_LocalInfoTunnel, 157 struct GNUNET_CADET_LocalInfoTunnel,
157 lt), 158 lt),
158 GNUNET_MQ_hd_fixed_size(get_tunnels_end, 159 GNUNET_MQ_hd_fixed_size (get_tunnels_end,
159 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END, 160 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END,
160 struct GNUNET_MessageHeader, 161 struct GNUNET_MessageHeader,
161 lt), 162 lt),
162 GNUNET_MQ_handler_end() 163 GNUNET_MQ_handler_end ()
163 }; 164 };
164 struct GNUNET_MessageHeader *msg; 165 struct GNUNET_MessageHeader *msg;
165 struct GNUNET_MQ_Envelope *env; 166 struct GNUNET_MQ_Envelope *env;
166 167
167 lt->reconnect_task = NULL; 168 lt->reconnect_task = NULL;
168 lt->mq = GNUNET_CLIENT_connect(lt->cfg, 169 lt->mq = GNUNET_CLIENT_connect (lt->cfg,
169 "cadet", 170 "cadet",
170 handlers, 171 handlers,
171 &error_handler, 172 &error_handler,
172 lt); 173 lt);
173 if (NULL == lt->mq) 174 if (NULL == lt->mq)
174 return; 175 return;
175 env = GNUNET_MQ_msg(msg, 176 env = GNUNET_MQ_msg (msg,
176 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS); 177 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS);
177 GNUNET_MQ_send(lt->mq, 178 GNUNET_MQ_send (lt->mq,
178 env); 179 env);
179} 180}
180 181
181 182
@@ -190,27 +191,27 @@ reconnect(void *cls)
190 * @return NULL on error 191 * @return NULL on error
191 */ 192 */
192struct GNUNET_CADET_ListTunnels * 193struct GNUNET_CADET_ListTunnels *
193GNUNET_CADET_list_tunnels(const struct GNUNET_CONFIGURATION_Handle *cfg, 194GNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg,
194 GNUNET_CADET_TunnelsCB callback, 195 GNUNET_CADET_TunnelsCB callback,
195 void *callback_cls) 196 void *callback_cls)
196{ 197{
197 struct GNUNET_CADET_ListTunnels *lt; 198 struct GNUNET_CADET_ListTunnels *lt;
198 199
199 if (NULL == callback) 200 if (NULL == callback)
200 { 201 {
201 GNUNET_break(0); 202 GNUNET_break (0);
202 return NULL; 203 return NULL;
203 } 204 }
204 lt = GNUNET_new(struct GNUNET_CADET_ListTunnels); 205 lt = GNUNET_new (struct GNUNET_CADET_ListTunnels);
205 lt->tunnels_cb = callback; 206 lt->tunnels_cb = callback;
206 lt->tunnels_cb_cls = callback_cls; 207 lt->tunnels_cb_cls = callback_cls;
207 lt->cfg = cfg; 208 lt->cfg = cfg;
208 reconnect(lt); 209 reconnect (lt);
209 if (NULL == lt->mq) 210 if (NULL == lt->mq)
210 { 211 {
211 GNUNET_free(lt); 212 GNUNET_free (lt);
212 return NULL; 213 return NULL;
213 } 214 }
214 return lt; 215 return lt;
215} 216}
216 217
@@ -222,15 +223,15 @@ GNUNET_CADET_list_tunnels(const struct GNUNET_CONFIGURATION_Handle *cfg,
222 * @return Closure given to GNUNET_CADET_list_tunnels(). 223 * @return Closure given to GNUNET_CADET_list_tunnels().
223 */ 224 */
224void * 225void *
225GNUNET_CADET_list_tunnels_cancel(struct GNUNET_CADET_ListTunnels *lt) 226GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt)
226{ 227{
227 void *ret = lt->tunnels_cb_cls; 228 void *ret = lt->tunnels_cb_cls;
228 229
229 if (NULL != lt->mq) 230 if (NULL != lt->mq)
230 GNUNET_MQ_destroy(lt->mq); 231 GNUNET_MQ_destroy (lt->mq);
231 if (NULL != lt->reconnect_task) 232 if (NULL != lt->reconnect_task)
232 GNUNET_SCHEDULER_cancel(lt->reconnect_task); 233 GNUNET_SCHEDULER_cancel (lt->reconnect_task);
233 GNUNET_free(lt); 234 GNUNET_free (lt);
234 return ret; 235 return ret;
235} 236}
236 237
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index 6252a1da5..e3417f8c4 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -66,7 +66,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
66/** 66/**
67 * Message for cadet connection creation. 67 * Message for cadet connection creation.
68 */ 68 */
69struct GNUNET_CADET_ConnectionCreateMessage { 69struct GNUNET_CADET_ConnectionCreateMessage
70{
70 /** 71 /**
71 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE 72 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
72 * 73 *
@@ -99,7 +100,8 @@ struct GNUNET_CADET_ConnectionCreateMessage {
99/** 100/**
100 * Message for ack'ing a connection 101 * Message for ack'ing a connection
101 */ 102 */
102struct GNUNET_CADET_ConnectionCreateAckMessage { 103struct GNUNET_CADET_ConnectionCreateAckMessage
104{
103 /** 105 /**
104 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK 106 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
105 */ 107 */
@@ -120,7 +122,8 @@ struct GNUNET_CADET_ConnectionCreateAckMessage {
120/** 122/**
121 * Message for notifying a disconnection in a path 123 * Message for notifying a disconnection in a path
122 */ 124 */
123struct GNUNET_CADET_ConnectionBrokenMessage { 125struct GNUNET_CADET_ConnectionBrokenMessage
126{
124 /** 127 /**
125 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN. 128 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
126 */ 129 */
@@ -151,7 +154,8 @@ struct GNUNET_CADET_ConnectionBrokenMessage {
151/** 154/**
152 * Message to destroy a connection. 155 * Message to destroy a connection.
153 */ 156 */
154struct GNUNET_CADET_ConnectionDestroyMessage { 157struct GNUNET_CADET_ConnectionDestroyMessage
158{
155 /** 159 /**
156 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY 160 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
157 */ 161 */
@@ -180,7 +184,8 @@ struct GNUNET_CADET_ConnectionDestroyMessage {
180 * against the respective #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED 184 * against the respective #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
181 * messages. 185 * messages.
182 */ 186 */
183struct CadetEncryptedMessageIdentifier { 187struct CadetEncryptedMessageIdentifier
188{
184 /** 189 /**
185 * This number is incremented by one per message. It may wrap around. 190 * This number is incremented by one per message. It may wrap around.
186 * In network byte order. 191 * In network byte order.
@@ -192,7 +197,8 @@ struct CadetEncryptedMessageIdentifier {
192/** 197/**
193 * Flags to be used in GNUNET_CADET_KX. 198 * Flags to be used in GNUNET_CADET_KX.
194 */ 199 */
195enum GNUNET_CADET_KX_Flags { 200enum GNUNET_CADET_KX_Flags
201{
196 /** 202 /**
197 * Should the peer reply with its KX details? 203 * Should the peer reply with its KX details?
198 */ 204 */
@@ -208,7 +214,8 @@ enum GNUNET_CADET_KX_Flags {
208/** 214/**
209 * Message for a Key eXchange for a tunnel. 215 * Message for a Key eXchange for a tunnel.
210 */ 216 */
211struct GNUNET_CADET_TunnelKeyExchangeMessage { 217struct GNUNET_CADET_TunnelKeyExchangeMessage
218{
212 /** 219 /**
213 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or 220 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or
214 * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part 221 * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part
@@ -263,7 +270,8 @@ struct GNUNET_CADET_TunnelKeyExchangeMessage {
263 * Message for a Key eXchange for a tunnel, with authentication. 270 * Message for a Key eXchange for a tunnel, with authentication.
264 * Used as a response to the initial KX as well as for rekeying. 271 * Used as a response to the initial KX as well as for rekeying.
265 */ 272 */
266struct GNUNET_CADET_TunnelKeyExchangeAuthMessage { 273struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
274{
267 /** 275 /**
268 * Message header with key material. 276 * Message header with key material.
269 */ 277 */
@@ -290,7 +298,8 @@ struct GNUNET_CADET_TunnelKeyExchangeAuthMessage {
290 * Encrypted axolotl header with numbers that identify which 298 * Encrypted axolotl header with numbers that identify which
291 * keys in which ratchet are to be used to decrypt the body. 299 * keys in which ratchet are to be used to decrypt the body.
292 */ 300 */
293struct GNUNET_CADET_AxHeader { 301struct GNUNET_CADET_AxHeader
302{
294 /** 303 /**
295 * Number of messages sent with the current ratchet key. 304 * Number of messages sent with the current ratchet key.
296 */ 305 */
@@ -311,7 +320,8 @@ struct GNUNET_CADET_AxHeader {
311/** 320/**
312 * Axolotl-encrypted tunnel message with application payload. 321 * Axolotl-encrypted tunnel message with application payload.
313 */ 322 */
314struct GNUNET_CADET_TunnelEncryptedMessage { 323struct GNUNET_CADET_TunnelEncryptedMessage
324{
315 /** 325 /**
316 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED 326 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
317 */ 327 */
@@ -354,7 +364,8 @@ struct GNUNET_CADET_TunnelEncryptedMessage {
354/** 364/**
355 * Message to create a Channel. 365 * Message to create a Channel.
356 */ 366 */
357struct GNUNET_CADET_ChannelOpenMessage { 367struct GNUNET_CADET_ChannelOpenMessage
368{
358 /** 369 /**
359 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN 370 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
360 */ 371 */
@@ -381,7 +392,8 @@ struct GNUNET_CADET_ChannelOpenMessage {
381 * Message to acknowledge opening a channel of type 392 * Message to acknowledge opening a channel of type
382 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK. 393 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
383 */ 394 */
384struct GNUNET_CADET_ChannelOpenAckMessage { 395struct GNUNET_CADET_ChannelOpenAckMessage
396{
385 /** 397 /**
386 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK 398 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
387 */ 399 */
@@ -409,7 +421,8 @@ struct GNUNET_CADET_ChannelOpenAckMessage {
409 * Message to destroy a channel of type 421 * Message to destroy a channel of type
410 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY. 422 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
411 */ 423 */
412struct GNUNET_CADET_ChannelDestroyMessage { 424struct GNUNET_CADET_ChannelDestroyMessage
425{
413 /** 426 /**
414 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY 427 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
415 */ 428 */
@@ -430,7 +443,8 @@ struct GNUNET_CADET_ChannelDestroyMessage {
430/** 443/**
431 * Number used to uniquely identify messages in a CADET Channel. 444 * Number used to uniquely identify messages in a CADET Channel.
432 */ 445 */
433struct ChannelMessageIdentifier { 446struct ChannelMessageIdentifier
447{
434 /** 448 /**
435 * Unique ID of the message, cycles around, in NBO. 449 * Unique ID of the message, cycles around, in NBO.
436 */ 450 */
@@ -441,7 +455,8 @@ struct ChannelMessageIdentifier {
441/** 455/**
442 * Message for cadet data traffic. 456 * Message for cadet data traffic.
443 */ 457 */
444struct GNUNET_CADET_ChannelAppDataMessage { 458struct GNUNET_CADET_ChannelAppDataMessage
459{
445 /** 460 /**
446 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA. 461 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
447 */ 462 */
@@ -466,7 +481,8 @@ struct GNUNET_CADET_ChannelAppDataMessage {
466/** 481/**
467 * Message to acknowledge end-to-end data. 482 * Message to acknowledge end-to-end data.
468 */ 483 */
469struct GNUNET_CADET_ChannelDataAckMessage { 484struct GNUNET_CADET_ChannelDataAckMessage
485{
470 /** 486 /**
471 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK 487 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
472 */ 488 */
diff --git a/src/cadet/cadet_test_lib.c b/src/cadet/cadet_test_lib.c
index ae1eb6f00..490e6539b 100644
--- a/src/cadet/cadet_test_lib.c
+++ b/src/cadet/cadet_test_lib.c
@@ -31,7 +31,8 @@
31/** 31/**
32 * Test context for a CADET Test. 32 * Test context for a CADET Test.
33 */ 33 */
34struct GNUNET_CADET_TEST_Context { 34struct GNUNET_CADET_TEST_Context
35{
35 /** 36 /**
36 * Array of running peers. 37 * Array of running peers.
37 */ 38 */
@@ -97,7 +98,8 @@ struct GNUNET_CADET_TEST_Context {
97/** 98/**
98 * Context for a cadet adapter callback. 99 * Context for a cadet adapter callback.
99 */ 100 */
100struct GNUNET_CADET_TEST_AdapterContext { 101struct GNUNET_CADET_TEST_AdapterContext
102{
101 /** 103 /**
102 * Peer number for the particular peer. 104 * Peer number for the particular peer.
103 */ 105 */
@@ -126,33 +128,33 @@ struct GNUNET_CADET_TEST_AdapterContext {
126 * @return service handle to return in 'op_result', NULL on error 128 * @return service handle to return in 'op_result', NULL on error
127 */ 129 */
128static void * 130static void *
129cadet_connect_adapter(void *cls, 131cadet_connect_adapter (void *cls,
130 const struct GNUNET_CONFIGURATION_Handle *cfg) 132 const struct GNUNET_CONFIGURATION_Handle *cfg)
131{ 133{
132 struct GNUNET_CADET_TEST_AdapterContext *actx = cls; 134 struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
133 struct GNUNET_CADET_TEST_Context *ctx = actx->ctx; 135 struct GNUNET_CADET_TEST_Context *ctx = actx->ctx;
134 struct GNUNET_CADET_Handle *h; 136 struct GNUNET_CADET_Handle *h;
135 137
136 h = GNUNET_CADET_connect(cfg); 138 h = GNUNET_CADET_connect (cfg);
137 if (NULL == h) 139 if (NULL == h)
138 { 140 {
139 GNUNET_break(0); 141 GNUNET_break (0);
140 return NULL; 142 return NULL;
141 } 143 }
142 if (NULL == ctx->ports) 144 if (NULL == ctx->ports)
143 return h; 145 return h;
144 actx->ports = GNUNET_new_array(ctx->port_count, 146 actx->ports = GNUNET_new_array (ctx->port_count,
145 struct GNUNET_CADET_Port *); 147 struct GNUNET_CADET_Port *);
146 for (unsigned int i = 0; i < ctx->port_count; i++) 148 for (unsigned int i = 0; i < ctx->port_count; i++)
147 { 149 {
148 actx->ports[i] = GNUNET_CADET_open_port(h, 150 actx->ports[i] = GNUNET_CADET_open_port (h,
149 ctx->ports[i], 151 ctx->ports[i],
150 ctx->connects, 152 ctx->connects,
151 (void *)(long)actx->peer, 153 (void *) (long) actx->peer,
152 ctx->window_changes, 154 ctx->window_changes,
153 ctx->disconnects, 155 ctx->disconnects,
154 ctx->handlers); 156 ctx->handlers);
155 } 157 }
156 return h; 158 return h;
157} 159}
158 160
@@ -165,23 +167,23 @@ cadet_connect_adapter(void *cls,
165 * @param op_result service handle returned from the connect adapter 167 * @param op_result service handle returned from the connect adapter
166 */ 168 */
167static void 169static void
168cadet_disconnect_adapter(void *cls, 170cadet_disconnect_adapter (void *cls,
169 void *op_result) 171 void *op_result)
170{ 172{
171 struct GNUNET_CADET_Handle *cadet = op_result; 173 struct GNUNET_CADET_Handle *cadet = op_result;
172 struct GNUNET_CADET_TEST_AdapterContext *actx = cls; 174 struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
173 175
174 if (NULL != actx->ports) 176 if (NULL != actx->ports)
177 {
178 for (unsigned int i = 0; i < actx->ctx->port_count; i++)
175 { 179 {
176 for (unsigned int i = 0; i < actx->ctx->port_count; i++) 180 GNUNET_CADET_close_port (actx->ports[i]);
177 { 181 actx->ports[i] = NULL;
178 GNUNET_CADET_close_port(actx->ports[i]);
179 actx->ports[i] = NULL;
180 }
181 GNUNET_free(actx->ports);
182 } 182 }
183 GNUNET_free(actx); 183 GNUNET_free (actx->ports);
184 GNUNET_CADET_disconnect(cadet); 184 }
185 GNUNET_free (actx);
186 GNUNET_CADET_disconnect (cadet);
185} 187}
186 188
187 189
@@ -196,56 +198,56 @@ cadet_disconnect_adapter(void *cls,
196 * NULL if operation has executed successfully. 198 * NULL if operation has executed successfully.
197 */ 199 */
198static void 200static void
199cadet_connect_cb(void *cls, 201cadet_connect_cb (void *cls,
200 struct GNUNET_TESTBED_Operation *op, 202 struct GNUNET_TESTBED_Operation *op,
201 void *ca_result, 203 void *ca_result,
202 const char *emsg) 204 const char *emsg)
203{ 205{
204 struct GNUNET_CADET_TEST_Context *ctx = cls; 206 struct GNUNET_CADET_TEST_Context *ctx = cls;
205 207
206 if (NULL != emsg) 208 if (NULL != emsg)
207 { 209 {
208 fprintf(stderr, 210 fprintf (stderr,
209 "Failed to connect to CADET service: %s\n", 211 "Failed to connect to CADET service: %s\n",
210 emsg); 212 emsg);
211 GNUNET_SCHEDULER_shutdown(); 213 GNUNET_SCHEDULER_shutdown ();
212 return; 214 return;
213 } 215 }
214 for (unsigned int i = 0; i < ctx->num_peers; i++) 216 for (unsigned int i = 0; i < ctx->num_peers; i++)
215 if (op == ctx->ops[i]) 217 if (op == ctx->ops[i])
216 { 218 {
217 ctx->cadets[i] = ca_result; 219 ctx->cadets[i] = ca_result;
218 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 220 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
219 "...cadet %u connected\n", 221 "...cadet %u connected\n",
220 i); 222 i);
221 } 223 }
222 for (unsigned int i = 0; i < ctx->num_peers; i++) 224 for (unsigned int i = 0; i < ctx->num_peers; i++)
223 if (NULL == ctx->cadets[i]) 225 if (NULL == ctx->cadets[i])
224 return; 226 return;
225 /* still some CADET connections missing */ 227 /* still some CADET connections missing */
226 /* all CADET connections ready! */ 228 /* all CADET connections ready! */
227 ctx->app_main(ctx->app_main_cls, 229 ctx->app_main (ctx->app_main_cls,
228 ctx, 230 ctx,
229 ctx->num_peers, 231 ctx->num_peers,
230 ctx->peers, 232 ctx->peers,
231 ctx->cadets); 233 ctx->cadets);
232} 234}
233 235
234 236
235void 237void
236GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx) 238GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx)
237{ 239{
238 for (unsigned int i = 0; i < ctx->num_peers; i++) 240 for (unsigned int i = 0; i < ctx->num_peers; i++)
239 { 241 {
240 GNUNET_assert(NULL != ctx->ops[i]); 242 GNUNET_assert (NULL != ctx->ops[i]);
241 GNUNET_TESTBED_operation_done(ctx->ops[i]); 243 GNUNET_TESTBED_operation_done (ctx->ops[i]);
242 ctx->ops[i] = NULL; 244 ctx->ops[i] = NULL;
243 } 245 }
244 GNUNET_free(ctx->ops); 246 GNUNET_free (ctx->ops);
245 GNUNET_free(ctx->cadets); 247 GNUNET_free (ctx->cadets);
246 GNUNET_free(ctx->handlers); 248 GNUNET_free (ctx->handlers);
247 GNUNET_free(ctx); 249 GNUNET_free (ctx);
248 GNUNET_SCHEDULER_shutdown(); 250 GNUNET_SCHEDULER_shutdown ();
249} 251}
250 252
251 253
@@ -263,57 +265,57 @@ GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx)
263 * failed 265 * failed
264 */ 266 */
265static void 267static void
266cadet_test_run(void *cls, 268cadet_test_run (void *cls,
267 struct GNUNET_TESTBED_RunHandle *h, 269 struct GNUNET_TESTBED_RunHandle *h,
268 unsigned int num_peers, 270 unsigned int num_peers,
269 struct GNUNET_TESTBED_Peer **peers, 271 struct GNUNET_TESTBED_Peer **peers,
270 unsigned int links_succeeded, 272 unsigned int links_succeeded,
271 unsigned int links_failed) 273 unsigned int links_failed)
272{ 274{
273 struct GNUNET_CADET_TEST_Context *ctx = cls; 275 struct GNUNET_CADET_TEST_Context *ctx = cls;
274 276
275 if (0 != links_failed) 277 if (0 != links_failed)
276 { 278 {
277 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
278 "Some links failed (%u), ending\n", 280 "Some links failed (%u), ending\n",
279 links_failed); 281 links_failed);
280 exit(77); 282 exit (77);
281 } 283 }
282 if (num_peers != ctx->num_peers) 284 if (num_peers != ctx->num_peers)
283 { 285 {
284 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 286 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
285 "Peers started %u/%u, ending\n", 287 "Peers started %u/%u, ending\n",
286 num_peers, 288 num_peers,
287 ctx->num_peers); 289 ctx->num_peers);
288 exit(1); 290 exit (1);
289 } 291 }
290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
291 "Testbed up, %u peers and %u links\n", 293 "Testbed up, %u peers and %u links\n",
292 num_peers, 294 num_peers,
293 links_succeeded); 295 links_succeeded);
294 ctx->peers = peers; 296 ctx->peers = peers;
295 for (unsigned int i = 0; i < num_peers; i++) 297 for (unsigned int i = 0; i < num_peers; i++)
296 { 298 {
297 struct GNUNET_CADET_TEST_AdapterContext *newctx; 299 struct GNUNET_CADET_TEST_AdapterContext *newctx;
298 300
299 newctx = GNUNET_new(struct GNUNET_CADET_TEST_AdapterContext); 301 newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext);
300 newctx->peer = i; 302 newctx->peer = i;
301 newctx->ctx = ctx; 303 newctx->ctx = ctx;
302 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 304 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
303 "Connecting to cadet %u\n", 305 "Connecting to cadet %u\n",
304 i); 306 i);
305 ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx, 307 ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx,
306 peers[i], 308 peers[i],
307 "cadet", 309 "cadet",
308 &cadet_connect_cb, 310 &cadet_connect_cb,
309 ctx, 311 ctx,
310 &cadet_connect_adapter, 312 &cadet_connect_adapter,
311 &cadet_disconnect_adapter, 313 &cadet_disconnect_adapter,
312 newctx); 314 newctx);
313 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
314 "op handle %p\n", 316 "op handle %p\n",
315 ctx->ops[i]); 317 ctx->ops[i]);
316 } 318 }
317} 319}
318 320
319 321
@@ -333,41 +335,41 @@ cadet_test_run(void *cls,
333 * @param ports Ports the peers offer, NULL-terminated. 335 * @param ports Ports the peers offer, NULL-terminated.
334 */ 336 */
335void 337void
336GNUNET_CADET_TEST_ruN(const char *testname, 338GNUNET_CADET_TEST_ruN (const char *testname,
337 const char *cfgfile, 339 const char *cfgfile,
338 unsigned int num_peers, 340 unsigned int num_peers,
339 GNUNET_CADET_TEST_AppMain tmain, 341 GNUNET_CADET_TEST_AppMain tmain,
340 void *tmain_cls, 342 void *tmain_cls,
341 GNUNET_CADET_ConnectEventHandler connects, 343 GNUNET_CADET_ConnectEventHandler connects,
342 GNUNET_CADET_WindowSizeEventHandler window_changes, 344 GNUNET_CADET_WindowSizeEventHandler window_changes,
343 GNUNET_CADET_DisconnectEventHandler disconnects, 345 GNUNET_CADET_DisconnectEventHandler disconnects,
344 struct GNUNET_MQ_MessageHandler *handlers, 346 struct GNUNET_MQ_MessageHandler *handlers,
345 const struct GNUNET_HashCode **ports) 347 const struct GNUNET_HashCode **ports)
346{ 348{
347 struct GNUNET_CADET_TEST_Context *ctx; 349 struct GNUNET_CADET_TEST_Context *ctx;
348 350
349 ctx = GNUNET_new(struct GNUNET_CADET_TEST_Context); 351 ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context);
350 ctx->num_peers = num_peers; 352 ctx->num_peers = num_peers;
351 ctx->ops = GNUNET_new_array(num_peers, 353 ctx->ops = GNUNET_new_array (num_peers,
352 struct GNUNET_TESTBED_Operation *); 354 struct GNUNET_TESTBED_Operation *);
353 ctx->cadets = GNUNET_new_array(num_peers, 355 ctx->cadets = GNUNET_new_array (num_peers,
354 struct GNUNET_CADET_Handle *); 356 struct GNUNET_CADET_Handle *);
355 ctx->app_main = tmain; 357 ctx->app_main = tmain;
356 ctx->app_main_cls = tmain_cls; 358 ctx->app_main_cls = tmain_cls;
357 ctx->connects = connects; 359 ctx->connects = connects;
358 ctx->window_changes = window_changes; 360 ctx->window_changes = window_changes;
359 ctx->disconnects = disconnects; 361 ctx->disconnects = disconnects;
360 ctx->handlers = GNUNET_MQ_copy_handlers(handlers); 362 ctx->handlers = GNUNET_MQ_copy_handlers (handlers);
361 ctx->ports = ports; 363 ctx->ports = ports;
362 ctx->port_count = 0; 364 ctx->port_count = 0;
363 while (NULL != ctx->ports[ctx->port_count]) 365 while (NULL != ctx->ports[ctx->port_count])
364 ctx->port_count++; 366 ctx->port_count++;
365 GNUNET_TESTBED_test_run(testname, 367 GNUNET_TESTBED_test_run (testname,
366 cfgfile, 368 cfgfile,
367 num_peers, 369 num_peers,
368 0LL, NULL, NULL, 370 0LL, NULL, NULL,
369 &cadet_test_run, 371 &cadet_test_run,
370 ctx); 372 ctx);
371} 373}
372 374
373/* end of cadet_test_lib.c */ 375/* end of cadet_test_lib.c */
diff --git a/src/cadet/cadet_test_lib.h b/src/cadet/cadet_test_lib.h
index f526831a6..7d446801a 100644
--- a/src/cadet/cadet_test_lib.h
+++ b/src/cadet/cadet_test_lib.h
@@ -74,16 +74,16 @@ typedef void (*GNUNET_CADET_TEST_AppMain) (void *cls,
74 * @param ports Ports the peers offer, NULL-terminated. 74 * @param ports Ports the peers offer, NULL-terminated.
75 */ 75 */
76void 76void
77GNUNET_CADET_TEST_ruN(const char *testname, 77GNUNET_CADET_TEST_ruN (const char *testname,
78 const char *cfgfile, 78 const char *cfgfile,
79 unsigned int num_peers, 79 unsigned int num_peers,
80 GNUNET_CADET_TEST_AppMain tmain, 80 GNUNET_CADET_TEST_AppMain tmain,
81 void *tmain_cls, 81 void *tmain_cls,
82 GNUNET_CADET_ConnectEventHandler connects, 82 GNUNET_CADET_ConnectEventHandler connects,
83 GNUNET_CADET_WindowSizeEventHandler window_changes, 83 GNUNET_CADET_WindowSizeEventHandler window_changes,
84 GNUNET_CADET_DisconnectEventHandler disconnects, 84 GNUNET_CADET_DisconnectEventHandler disconnects,
85 struct GNUNET_MQ_MessageHandler *handlers, 85 struct GNUNET_MQ_MessageHandler *handlers,
86 const struct GNUNET_HashCode **ports); 86 const struct GNUNET_HashCode **ports);
87 87
88/** 88/**
89 * Clean up the testbed. 89 * Clean up the testbed.
@@ -91,7 +91,7 @@ GNUNET_CADET_TEST_ruN(const char *testname,
91 * @param ctx handle for the testbed 91 * @param ctx handle for the testbed
92 */ 92 */
93void 93void
94GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx); 94GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx);
95 95
96 96
97#if 0 /* keep Emacsens' auto-indent happy */ 97#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/cadet/desirability_table.c b/src/cadet/desirability_table.c
index 5c23de76b..829c618af 100644
--- a/src/cadet/desirability_table.c
+++ b/src/cadet/desirability_table.c
@@ -8,26 +8,26 @@
8#include <stdio.h> 8#include <stdio.h>
9 9
10int 10int
11main() 11main ()
12{ 12{
13 for (unsigned int num_alts = 1; num_alts < 10; num_alts++) 13 for (unsigned int num_alts = 1; num_alts < 10; num_alts++)
14 for (unsigned int off = 0; off < 10; off++) 14 for (unsigned int off = 0; off < 10; off++)
15 for (double delta = -(int)off; delta <= 5; delta += 0.25) 15 for (double delta = -(int) off; delta <= 5; delta += 0.25)
16 { 16 {
17 double weight_alts; 17 double weight_alts;
18 18
19 if (delta <= -1.0) 19 if (delta <= -1.0)
20 weight_alts = -1.0 * num_alts / delta; /* discount alternative paths */ 20 weight_alts = -1.0 * num_alts / delta; /* discount alternative paths */
21 else if (delta >= 1.0) 21 else if (delta >= 1.0)
22 weight_alts = 1.0 * num_alts * delta; /* overcount alternative paths */ 22 weight_alts = 1.0 * num_alts * delta; /* overcount alternative paths */
23 else 23 else
24 weight_alts = 1.0 * num_alts; /* count alternative paths normally */ 24 weight_alts = 1.0 * num_alts; /* count alternative paths normally */
25 25
26 fprintf(stderr, 26 fprintf (stderr,
27 "Paths: %u Offset: %u Delta: %5.2f SCORE: %f\n", 27 "Paths: %u Offset: %u Delta: %5.2f SCORE: %f\n",
28 num_alts, 28 num_alts,
29 off, 29 off,
30 delta, 30 delta,
31 ((off + 1.0) / (weight_alts * weight_alts))); 31 ((off + 1.0) / (weight_alts * weight_alts)));
32 } 32 }
33} 33}
diff --git a/src/cadet/gnunet-cadet-profiler.c b/src/cadet/gnunet-cadet-profiler.c
index b3e7fa30d..e66761e1e 100644
--- a/src/cadet/gnunet-cadet-profiler.c
+++ b/src/cadet/gnunet-cadet-profiler.c
@@ -41,12 +41,12 @@
41/** 41/**
42 * How long until we give up on connecting the peers? 42 * How long until we give up on connecting the peers?
43 */ 43 */
44#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
45 45
46/** 46/**
47 * Time to wait for stuff that should be rather fast 47 * Time to wait for stuff that should be rather fast
48 */ 48 */
49#define SHORT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) 49#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
50 50
51/** 51/**
52 * Total number of rounds. 52 * Total number of rounds.
@@ -61,7 +61,8 @@ static float rounds[] = { 0.8, 0.6, 0.8, 0.5, 0.3, 0.8, 0.0 };
61/** 61/**
62 * Message type for pings. 62 * Message type for pings.
63 */ 63 */
64struct CadetPingMessage { 64struct CadetPingMessage
65{
65 /** 66 /**
66 * Header. Type PING/PONG. 67 * Header. Type PING/PONG.
67 */ 68 */
@@ -86,7 +87,8 @@ struct CadetPingMessage {
86/** 87/**
87 * Peer description. 88 * Peer description.
88 */ 89 */
89struct CadetPeer { 90struct CadetPeer
91{
90 /** 92 /**
91 * Testbed Operation (to get peer id, etc). 93 * Testbed Operation (to get peer id, etc).
92 */ 94 */
@@ -253,7 +255,7 @@ static struct GNUNET_SCHEDULER_Task *round_task;
253 * @param cls Closure (unsued). 255 * @param cls Closure (unsued).
254 */ 256 */
255static void 257static void
256start_test(void *cls); 258start_test (void *cls);
257 259
258 260
259/** 261/**
@@ -264,12 +266,12 @@ start_test(void *cls);
264 * @return A time between 0 a max-1 ms. 266 * @return A time between 0 a max-1 ms.
265 */ 267 */
266static struct GNUNET_TIME_Relative 268static struct GNUNET_TIME_Relative
267delay_ms_rnd(unsigned int max) 269delay_ms_rnd (unsigned int max)
268{ 270{
269 unsigned int rnd; 271 unsigned int rnd;
270 272
271 rnd = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, max); 273 rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max);
272 return GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, rnd); 274 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd);
273} 275}
274 276
275 277
@@ -281,7 +283,7 @@ delay_ms_rnd(unsigned int max)
281 * @return Index of peer in peers. 283 * @return Index of peer in peers.
282 */ 284 */
283static unsigned int 285static unsigned int
284get_index(struct CadetPeer *peer) 286get_index (struct CadetPeer *peer)
285{ 287{
286 return peer - peers; 288 return peer - peers;
287} 289}
@@ -291,23 +293,23 @@ get_index(struct CadetPeer *peer)
291 * Show the results of the test (banwidth acheived) and log them to GAUGER 293 * Show the results of the test (banwidth acheived) and log them to GAUGER
292 */ 294 */
293static void 295static void
294show_end_data(void) 296show_end_data (void)
295{ 297{
296 struct CadetPeer *peer; 298 struct CadetPeer *peer;
297 unsigned int i; 299 unsigned int i;
298 unsigned int j; 300 unsigned int j;
299 301
300 for (i = 0; i < number_rounds; i++) 302 for (i = 0; i < number_rounds; i++)
303 {
304 for (j = 0; j < peers_pinging; j++)
301 { 305 {
302 for (j = 0; j < peers_pinging; j++) 306 peer = &peers[j];
303 { 307 fprintf (stdout,
304 peer = &peers[j]; 308 "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
305 fprintf(stdout, 309 i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)),
306 "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n", 310 peer->pings[i], peer->pongs[i]);
307 i, j, peer->mean[i], sqrt(peer->var[i] / (peer->pongs[i] - 1)),
308 peer->pings[i], peer->pongs[i]);
309 }
310 } 311 }
312 }
311} 313}
312 314
313 315
@@ -317,46 +319,46 @@ show_end_data(void)
317 * @param cls Closure (unused). 319 * @param cls Closure (unused).
318 */ 320 */
319static void 321static void
320disconnect_cadet_peers(void *cls) 322disconnect_cadet_peers (void *cls)
321{ 323{
322 long line = (long)cls; 324 long line = (long) cls;
323 unsigned int i; 325 unsigned int i;
324 326
325 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
326 "disconnecting cadet service, called from line %ld\n", 328 "disconnecting cadet service, called from line %ld\n",
327 line); 329 line);
328 disconnect_task = NULL; 330 disconnect_task = NULL;
329 for (i = 0; i < peers_total; i++) 331 for (i = 0; i < peers_total; i++)
332 {
333 if (NULL != peers[i].op)
334 GNUNET_TESTBED_operation_done (peers[i].op);
335
336 if (peers[i].up != GNUNET_YES)
337 continue;
338
339 if (NULL != peers[i].ch)
340 {
341 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
342 "%u: channel %p\n", i, peers[i].ch);
343 GNUNET_CADET_channel_destroy (peers[i].ch);
344 }
345 if (NULL != peers[i].warmup_ch)
346 {
347 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
348 "%u: warmup channel %p\n",
349 i, peers[i].warmup_ch);
350 GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
351 }
352 if (NULL != peers[i].incoming_ch)
330 { 353 {
331 if (NULL != peers[i].op) 354 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
332 GNUNET_TESTBED_operation_done(peers[i].op); 355 "%u: incoming channel %p\n",
333 356 i, peers[i].incoming_ch);
334 if (peers[i].up != GNUNET_YES) 357 GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
335 continue;
336
337 if (NULL != peers[i].ch)
338 {
339 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
340 "%u: channel %p\n", i, peers[i].ch);
341 GNUNET_CADET_channel_destroy(peers[i].ch);
342 }
343 if (NULL != peers[i].warmup_ch)
344 {
345 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
346 "%u: warmup channel %p\n",
347 i, peers[i].warmup_ch);
348 GNUNET_CADET_channel_destroy(peers[i].warmup_ch);
349 }
350 if (NULL != peers[i].incoming_ch)
351 {
352 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
353 "%u: incoming channel %p\n",
354 i, peers[i].incoming_ch);
355 GNUNET_CADET_channel_destroy(peers[i].incoming_ch);
356 }
357 } 358 }
358 GNUNET_CADET_TEST_cleanup(test_ctx); 359 }
359 GNUNET_SCHEDULER_shutdown(); 360 GNUNET_CADET_TEST_cleanup (test_ctx);
361 GNUNET_SCHEDULER_shutdown ();
360} 362}
361 363
362 364
@@ -366,26 +368,26 @@ disconnect_cadet_peers(void *cls)
366 * @param cls Closure (unused). 368 * @param cls Closure (unused).
367 */ 369 */
368static void 370static void
369shutdown_task(void *cls) 371shutdown_task (void *cls)
370{ 372{
371 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 373 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
372 "Ending test.\n"); 374 "Ending test.\n");
373 if (NULL != disconnect_task) 375 if (NULL != disconnect_task)
374 { 376 {
375 GNUNET_SCHEDULER_cancel(disconnect_task); 377 GNUNET_SCHEDULER_cancel (disconnect_task);
376 disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 378 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
377 (void *)__LINE__); 379 (void *) __LINE__);
378 } 380 }
379 if (NULL != round_task) 381 if (NULL != round_task)
380 { 382 {
381 GNUNET_SCHEDULER_cancel(round_task); 383 GNUNET_SCHEDULER_cancel (round_task);
382 round_task = NULL; 384 round_task = NULL;
383 } 385 }
384 if (NULL != test_task) 386 if (NULL != test_task)
385 { 387 {
386 GNUNET_SCHEDULER_cancel(test_task); 388 GNUNET_SCHEDULER_cancel (test_task);
387 test_task = NULL; 389 test_task = NULL;
388 } 390 }
389} 391}
390 392
391 393
@@ -395,14 +397,14 @@ shutdown_task(void *cls)
395 * @param line Line in the code the abort is requested from (__LINE__). 397 * @param line Line in the code the abort is requested from (__LINE__).
396 */ 398 */
397static void 399static void
398abort_test(long line) 400abort_test (long line)
399{ 401{
400 if (disconnect_task != NULL) 402 if (disconnect_task != NULL)
401 { 403 {
402 GNUNET_SCHEDULER_cancel(disconnect_task); 404 GNUNET_SCHEDULER_cancel (disconnect_task);
403 disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 405 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
404 (void *)line); 406 (void *) line);
405 } 407 }
406} 408}
407 409
408/** 410/**
@@ -415,15 +417,15 @@ abort_test(long line)
415 * operation has executed successfully. 417 * operation has executed successfully.
416 */ 418 */
417static void 419static void
418stats_cont(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) 420stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
419{ 421{
420 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n"); 422 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n");
421 GNUNET_TESTBED_operation_done(stats_op); 423 GNUNET_TESTBED_operation_done (stats_op);
422 424
423 if (NULL != disconnect_task) 425 if (NULL != disconnect_task)
424 GNUNET_SCHEDULER_cancel(disconnect_task); 426 GNUNET_SCHEDULER_cancel (disconnect_task);
425 disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 427 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
426 (void *)__LINE__); 428 (void *) __LINE__);
427} 429}
428 430
429 431
@@ -439,20 +441,20 @@ stats_cont(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
439 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 441 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
440 */ 442 */
441static int 443static int
442stats_iterator(void *cls, 444stats_iterator (void *cls,
443 const struct GNUNET_TESTBED_Peer *peer, 445 const struct GNUNET_TESTBED_Peer *peer,
444 const char *subsystem, 446 const char *subsystem,
445 const char *name, 447 const char *name,
446 uint64_t value, 448 uint64_t value,
447 int is_persistent) 449 int is_persistent)
448{ 450{
449 uint32_t i; 451 uint32_t i;
450 452
451 i = GNUNET_TESTBED_get_index(peer); 453 i = GNUNET_TESTBED_get_index (peer);
452 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
453 " STATS %u - %s [%s]: %llu\n", 455 " STATS %u - %s [%s]: %llu\n",
454 i, subsystem, name, 456 i, subsystem, name,
455 (unsigned long long)value); 457 (unsigned long long) value);
456 458
457 return GNUNET_OK; 459 return GNUNET_OK;
458} 460}
@@ -464,15 +466,15 @@ stats_iterator(void *cls,
464 * @param cls Closure (NULL). 466 * @param cls Closure (NULL).
465 */ 467 */
466static void 468static void
467collect_stats(void *cls) 469collect_stats (void *cls)
468{ 470{
469 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 471 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
470 "Start collecting statistics...\n"); 472 "Start collecting statistics...\n");
471 stats_op = GNUNET_TESTBED_get_statistics(peers_total, 473 stats_op = GNUNET_TESTBED_get_statistics (peers_total,
472 testbed_handles, 474 testbed_handles,
473 NULL, NULL, 475 NULL, NULL,
474 &stats_iterator, 476 &stats_iterator,
475 &stats_cont, NULL); 477 &stats_cont, NULL);
476} 478}
477 479
478 480
@@ -482,11 +484,11 @@ collect_stats(void *cls)
482 * @param cls Closure (unused). 484 * @param cls Closure (unused).
483 */ 485 */
484static void 486static void
485finish_profiler(void *cls) 487finish_profiler (void *cls)
486{ 488{
487 test_finished = GNUNET_YES; 489 test_finished = GNUNET_YES;
488 show_end_data(); 490 show_end_data ();
489 GNUNET_SCHEDULER_add_now(&collect_stats, NULL); 491 GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
490} 492}
491 493
492 494
@@ -496,7 +498,7 @@ finish_profiler(void *cls)
496 * @param target Desired number of running peers. 498 * @param target Desired number of running peers.
497 */ 499 */
498static void 500static void
499adjust_running_peers(unsigned int target) 501adjust_running_peers (unsigned int target)
500{ 502{
501 struct GNUNET_TESTBED_Operation *op; 503 struct GNUNET_TESTBED_Operation *op;
502 unsigned int delta; 504 unsigned int delta;
@@ -504,60 +506,60 @@ adjust_running_peers(unsigned int target)
504 unsigned int i; 506 unsigned int i;
505 unsigned int r; 507 unsigned int r;
506 508
507 GNUNET_assert(target <= peers_total); 509 GNUNET_assert (target <= peers_total);
508 510
509 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target); 511 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target);
510 if (target > peers_running) 512 if (target > peers_running)
513 {
514 delta = target - peers_running;
515 run = GNUNET_YES;
516 }
517 else
518 {
519 delta = peers_running - target;
520 run = GNUNET_NO;
521 }
522
523 for (i = 0; i < delta; i++)
524 {
525 do
511 { 526 {
512 delta = target - peers_running; 527 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
513 run = GNUNET_YES; 528 peers_total - peers_pinging);
529 r += peers_pinging;
514 } 530 }
515 else 531 while (peers[r].up == run || NULL != peers[r].incoming);
532 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n",
533 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
534
535 if (NULL != peers[r].ping_task)
536 {
537 GNUNET_SCHEDULER_cancel (peers[r].ping_task);
538 peers[r].ping_task = NULL;
539 }
540 if (NULL != peers[r].ping_ntr)
516 { 541 {
517 delta = peers_running - target; 542 GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
518 run = GNUNET_NO; 543 peers[r].ping_ntr = NULL;
519 } 544 }
545 peers[r].up = run;
520 546
521 for (i = 0; i < delta; i++) 547 if (NULL != peers[r].ch)
548 GNUNET_CADET_channel_destroy (peers[r].ch);
549 peers[r].ch = NULL;
550 if (NULL != peers[r].dest)
522 { 551 {
523 do 552 if (NULL != peers[r].dest->incoming_ch)
524 { 553 GNUNET_CADET_channel_destroy (peers[r].dest->incoming_ch);
525 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 554 peers[r].dest->incoming_ch = NULL;
526 peers_total - peers_pinging);
527 r += peers_pinging;
528 }
529 while (peers[r].up == run || NULL != peers[r].incoming);
530 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n",
531 run ? "arting" : "opping", r, GNUNET_i2s(&peers[r].id));
532
533 if (NULL != peers[r].ping_task)
534 {
535 GNUNET_SCHEDULER_cancel(peers[r].ping_task);
536 peers[r].ping_task = NULL;
537 }
538 if (NULL != peers[r].ping_ntr)
539 {
540 GNUNET_CADET_notify_transmit_ready_cancel(peers[r].ping_ntr);
541 peers[r].ping_ntr = NULL;
542 }
543 peers[r].up = run;
544
545 if (NULL != peers[r].ch)
546 GNUNET_CADET_channel_destroy(peers[r].ch);
547 peers[r].ch = NULL;
548 if (NULL != peers[r].dest)
549 {
550 if (NULL != peers[r].dest->incoming_ch)
551 GNUNET_CADET_channel_destroy(peers[r].dest->incoming_ch);
552 peers[r].dest->incoming_ch = NULL;
553 }
554
555 op = GNUNET_TESTBED_peer_manage_service(&peers[r], testbed_handles[r],
556 "cadet", NULL, NULL, run);
557 GNUNET_break(NULL != op);
558 peers_running += run ? 1 : -1;
559 GNUNET_assert(peers_running > 0);
560 } 555 }
556
557 op = GNUNET_TESTBED_peer_manage_service (&peers[r], testbed_handles[r],
558 "cadet", NULL, NULL, run);
559 GNUNET_break (NULL != op);
560 peers_running += run ? 1 : -1;
561 GNUNET_assert (peers_running > 0);
562 }
561} 563}
562 564
563 565
@@ -567,23 +569,23 @@ adjust_running_peers(unsigned int target)
567 * @param cls Closure (round #). 569 * @param cls Closure (round #).
568 */ 570 */
569static void 571static void
570next_rnd(void *cls) 572next_rnd (void *cls)
571{ 573{
572 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 574 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
573 "ROUND %u\n", 575 "ROUND %u\n",
574 current_round); 576 current_round);
575 if (0.0 == rounds[current_round]) 577 if (0.0 == rounds[current_round])
576 { 578 {
577 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Finishing\n"); 579 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n");
578 GNUNET_SCHEDULER_add_now(&finish_profiler, NULL); 580 GNUNET_SCHEDULER_add_now (&finish_profiler, NULL);
579 return; 581 return;
580 } 582 }
581 adjust_running_peers(rounds[current_round] * peers_total); 583 adjust_running_peers (rounds[current_round] * peers_total);
582 current_round++; 584 current_round++;
583 585
584 round_task = GNUNET_SCHEDULER_add_delayed(round_time, 586 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
585 &next_rnd, 587 &next_rnd,
586 NULL); 588 NULL);
587} 589}
588 590
589 591
@@ -597,7 +599,7 @@ next_rnd(void *cls)
597 * @return Number of bytes written to buf. 599 * @return Number of bytes written to buf.
598 */ 600 */
599static size_t 601static size_t
600tmt_rdy_ping(void *cls, size_t size, void *buf); 602tmt_rdy_ping (void *cls, size_t size, void *buf);
601 603
602 604
603/** 605/**
@@ -608,21 +610,21 @@ tmt_rdy_ping(void *cls, size_t size, void *buf);
608 * @param buf Buffer to copy data to. 610 * @param buf Buffer to copy data to.
609 */ 611 */
610static size_t 612static size_t
611tmt_rdy_pong(void *cls, size_t size, void *buf) 613tmt_rdy_pong (void *cls, size_t size, void *buf)
612{ 614{
613 struct CadetPingMessage *ping = cls; 615 struct CadetPingMessage *ping = cls;
614 struct CadetPingMessage *pong; 616 struct CadetPingMessage *pong;
615 617
616 if (0 == size || NULL == buf) 618 if ((0 == size)||(NULL == buf))
617 { 619 {
618 GNUNET_free(ping); 620 GNUNET_free (ping);
619 return 0; 621 return 0;
620 } 622 }
621 pong = (struct CadetPingMessage *)buf; 623 pong = (struct CadetPingMessage *) buf;
622 GNUNET_memcpy(pong, ping, sizeof(*ping)); 624 GNUNET_memcpy (pong, ping, sizeof(*ping));
623 pong->header.type = htons(PONG); 625 pong->header.type = htons (PONG);
624 626
625 GNUNET_free(ping); 627 GNUNET_free (ping);
626 return sizeof(*ping); 628 return sizeof(*ping);
627} 629}
628 630
@@ -633,22 +635,23 @@ tmt_rdy_pong(void *cls, size_t size, void *buf)
633 * @param cls Closure (peer). 635 * @param cls Closure (peer).
634 */ 636 */
635static void 637static void
636ping(void *cls) 638ping (void *cls)
637{ 639{
638 struct CadetPeer *peer = cls; 640 struct CadetPeer *peer = cls;
639 641
640 peer->ping_task = NULL; 642 peer->ping_task = NULL;
641 if (GNUNET_YES == test_finished) 643 if (GNUNET_YES == test_finished)
642 return; 644 return;
643 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 645 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
644 "%u -> %u (%u)\n", 646 "%u -> %u (%u)\n",
645 get_index(peer), 647 get_index (peer),
646 get_index(peer->dest), 648 get_index (peer->dest),
647 peer->data_sent); 649 peer->data_sent);
648 peer->ping_ntr = GNUNET_CADET_notify_transmit_ready(peer->ch, GNUNET_NO, 650 peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
649 GNUNET_TIME_UNIT_FOREVER_REL, 651 GNUNET_TIME_UNIT_FOREVER_REL,
650 sizeof(struct CadetPingMessage), 652 sizeof(struct
651 &tmt_rdy_ping, peer); 653 CadetPingMessage),
654 &tmt_rdy_ping, peer);
652} 655}
653 656
654/** 657/**
@@ -658,17 +661,17 @@ ping(void *cls)
658 * @param tc Task context. 661 * @param tc Task context.
659 */ 662 */
660static void 663static void
661pong(struct GNUNET_CADET_Channel *channel, 664pong (struct GNUNET_CADET_Channel *channel,
662 const struct CadetPingMessage *ping) 665 const struct CadetPingMessage *ping)
663{ 666{
664 struct CadetPingMessage *copy; 667 struct CadetPingMessage *copy;
665 668
666 copy = GNUNET_new(struct CadetPingMessage); 669 copy = GNUNET_new (struct CadetPingMessage);
667 *copy = *ping; 670 *copy = *ping;
668 GNUNET_CADET_notify_transmit_ready(channel, GNUNET_NO, 671 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
669 GNUNET_TIME_UNIT_FOREVER_REL, 672 GNUNET_TIME_UNIT_FOREVER_REL,
670 sizeof(struct CadetPingMessage), 673 sizeof(struct CadetPingMessage),
671 &tmt_rdy_pong, copy); 674 &tmt_rdy_pong, copy);
672} 675}
673 676
674 677
@@ -680,37 +683,37 @@ pong(struct GNUNET_CADET_Channel *channel,
680 * @param buf Buffer to copy data to. 683 * @param buf Buffer to copy data to.
681 */ 684 */
682static size_t 685static size_t
683tmt_rdy_ping(void *cls, size_t size, void *buf) 686tmt_rdy_ping (void *cls, size_t size, void *buf)
684{ 687{
685 struct CadetPeer *peer = cls; 688 struct CadetPeer *peer = cls;
686 struct CadetPingMessage *msg = buf; 689 struct CadetPingMessage *msg = buf;
687 690
688 peer->ping_ntr = NULL; 691 peer->ping_ntr = NULL;
689 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
690 "tmt_rdy called, filling buffer\n"); 693 "tmt_rdy called, filling buffer\n");
691 if (size < sizeof(struct CadetPingMessage) || NULL == buf) 694 if ((size < sizeof(struct CadetPingMessage))||(NULL == buf))
692 { 695 {
693 GNUNET_break(GNUNET_YES == test_finished); 696 GNUNET_break (GNUNET_YES == test_finished);
694 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
695 "size %u, buf %p, data_sent %u, data_received %u\n", 698 "size %u, buf %p, data_sent %u, data_received %u\n",
696 (unsigned int)size, 699 (unsigned int) size,
697 buf, 700 buf,
698 peer->data_sent, 701 peer->data_sent,
699 peer->data_received); 702 peer->data_received);
700 703
701 return 0; 704 return 0;
702 } 705 }
703 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
704 "Sending: msg %d\n", 707 "Sending: msg %d\n",
705 peer->data_sent); 708 peer->data_sent);
706 msg->header.size = htons(size); 709 msg->header.size = htons (size);
707 msg->header.type = htons(PING); 710 msg->header.type = htons (PING);
708 msg->counter = htonl(peer->data_sent++); 711 msg->counter = htonl (peer->data_sent++);
709 msg->round_number = htonl(current_round); 712 msg->round_number = htonl (current_round);
710 msg->timestamp = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get()); 713 msg->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
711 peer->pings[current_round]++; 714 peer->pings[current_round]++;
712 peer->ping_task = GNUNET_SCHEDULER_add_delayed(delay_ms_rnd(PING_PERIOD), 715 peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD),
713 &ping, peer); 716 &ping, peer);
714 717
715 return sizeof(struct CadetPingMessage); 718 return sizeof(struct CadetPingMessage);
716} 719}
@@ -727,18 +730,18 @@ tmt_rdy_ping(void *cls, size_t size, void *buf)
727 * GNUNET_SYSERR to close it (signal serious error) 730 * GNUNET_SYSERR to close it (signal serious error)
728 */ 731 */
729int 732int
730ping_handler(void *cls, struct GNUNET_CADET_Channel *channel, 733ping_handler (void *cls, struct GNUNET_CADET_Channel *channel,
731 void **channel_ctx, 734 void **channel_ctx,
732 const struct GNUNET_MessageHeader *message) 735 const struct GNUNET_MessageHeader *message)
733{ 736{
734 long n = (long)cls; 737 long n = (long) cls;
735 738
736 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "%u got PING\n", 740 "%u got PING\n",
738 (unsigned int)n); 741 (unsigned int) n);
739 GNUNET_CADET_receive_done(channel); 742 GNUNET_CADET_receive_done (channel);
740 if (GNUNET_NO == test_finished) 743 if (GNUNET_NO == test_finished)
741 pong(channel, (struct CadetPingMessage *)message); 744 pong (channel, (struct CadetPingMessage *) message);
742 745
743 return GNUNET_OK; 746 return GNUNET_OK;
744} 747}
@@ -755,11 +758,11 @@ ping_handler(void *cls, struct GNUNET_CADET_Channel *channel,
755 * GNUNET_SYSERR to close it (signal serious error) 758 * GNUNET_SYSERR to close it (signal serious error)
756 */ 759 */
757int 760int
758pong_handler(void *cls, struct GNUNET_CADET_Channel *channel, 761pong_handler (void *cls, struct GNUNET_CADET_Channel *channel,
759 void **channel_ctx, 762 void **channel_ctx,
760 const struct GNUNET_MessageHeader *message) 763 const struct GNUNET_MessageHeader *message)
761{ 764{
762 long n = (long)cls; 765 long n = (long) cls;
763 struct CadetPeer *peer; 766 struct CadetPeer *peer;
764 struct CadetPingMessage *msg; 767 struct CadetPingMessage *msg;
765 struct GNUNET_TIME_Absolute send_time; 768 struct GNUNET_TIME_Absolute send_time;
@@ -767,19 +770,19 @@ pong_handler(void *cls, struct GNUNET_CADET_Channel *channel,
767 unsigned int r /* Ping round */; 770 unsigned int r /* Ping round */;
768 float delta; 771 float delta;
769 772
770 GNUNET_CADET_receive_done(channel); 773 GNUNET_CADET_receive_done (channel);
771 peer = &peers[n]; 774 peer = &peers[n];
772 775
773 msg = (struct CadetPingMessage *)message; 776 msg = (struct CadetPingMessage *) message;
774 777
775 send_time = GNUNET_TIME_absolute_ntoh(msg->timestamp); 778 send_time = GNUNET_TIME_absolute_ntoh (msg->timestamp);
776 latency = GNUNET_TIME_absolute_get_duration(send_time); 779 latency = GNUNET_TIME_absolute_get_duration (send_time);
777 r = ntohl(msg->round_number); 780 r = ntohl (msg->round_number);
778 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n", 781 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
779 get_index(peer), 782 get_index (peer),
780 get_index(peer->dest), 783 get_index (peer->dest),
781 (uint32_t)ntohl(msg->counter), 784 (uint32_t) ntohl (msg->counter),
782 GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_NO)); 785 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
783 786
784 /* Online variance calculation */ 787 /* Online variance calculation */
785 peer->pongs[r]++; 788 peer->pongs[r]++;
@@ -814,41 +817,41 @@ static struct GNUNET_CADET_MessageHandler handlers[] = {
814 * (can be NULL -- that's not an error). 817 * (can be NULL -- that's not an error).
815 */ 818 */
816static void * 819static void *
817incoming_channel(void *cls, struct GNUNET_CADET_Channel *channel, 820incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
818 const struct GNUNET_PeerIdentity *initiator, 821 const struct GNUNET_PeerIdentity *initiator,
819 const struct GNUNET_HashCode *port, 822 const struct GNUNET_HashCode *port,
820 enum GNUNET_CADET_ChannelOption options) 823 enum GNUNET_CADET_ChannelOption options)
821{ 824{
822 long n = (long)cls; 825 long n = (long) cls;
823 struct CadetPeer *peer; 826 struct CadetPeer *peer;
824 827
825 peer = GNUNET_CONTAINER_multipeermap_get(ids, initiator); 828 peer = GNUNET_CONTAINER_multipeermap_get (ids, initiator);
826 GNUNET_assert(NULL != peer); 829 GNUNET_assert (NULL != peer);
827 if (NULL == peers[n].incoming) 830 if (NULL == peers[n].incoming)
828 { 831 {
829 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 832 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
830 "WARMUP %3u: %u <= %u\n", 833 "WARMUP %3u: %u <= %u\n",
831 peers_warmup, 834 peers_warmup,
832 (unsigned int)n, 835 (unsigned int) n,
833 get_index(peer)); 836 get_index (peer));
834 peers_warmup++; 837 peers_warmup++;
835 if (peers_warmup < peers_total) 838 if (peers_warmup < peers_total)
836 return NULL;
837 if (NULL != test_task)
838 {
839 GNUNET_SCHEDULER_cancel(test_task);
840 test_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
841 &start_test, NULL);
842 }
843 return NULL; 839 return NULL;
840 if (NULL != test_task)
841 {
842 GNUNET_SCHEDULER_cancel (test_task);
843 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
844 &start_test, NULL);
844 } 845 }
845 GNUNET_assert(peer == peers[n].incoming); 846 return NULL;
846 GNUNET_assert(peer->dest == &peers[n]); 847 }
847 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 848 GNUNET_assert (peer == peers[n].incoming);
848 "%u <= %u %p\n", 849 GNUNET_assert (peer->dest == &peers[n]);
849 (unsigned int)n, 850 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
850 get_index(peer), 851 "%u <= %u %p\n",
851 channel); 852 (unsigned int) n,
853 get_index (peer),
854 channel);
852 peers[n].incoming_ch = channel; 855 peers[n].incoming_ch = channel;
853 856
854 return NULL; 857 return NULL;
@@ -864,15 +867,15 @@ incoming_channel(void *cls, struct GNUNET_CADET_Channel *channel,
864 * with the channel is stored 867 * with the channel is stored
865 */ 868 */
866static void 869static void
867channel_cleaner(void *cls, 870channel_cleaner (void *cls,
868 const struct GNUNET_CADET_Channel *channel, 871 const struct GNUNET_CADET_Channel *channel,
869 void *channel_ctx) 872 void *channel_ctx)
870{ 873{
871 long n = (long)cls; 874 long n = (long) cls;
872 struct CadetPeer *peer = &peers[n]; 875 struct CadetPeer *peer = &peers[n];
873 876
874 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 877 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
875 "Channel %p disconnected at peer %ld\n", channel, n); 878 "Channel %p disconnected at peer %ld\n", channel, n);
876 if (peer->ch == channel) 879 if (peer->ch == channel)
877 peer->ch = NULL; 880 peer->ch = NULL;
878} 881}
@@ -886,14 +889,14 @@ channel_cleaner(void *cls,
886 * @return Random peer not yet connected to. 889 * @return Random peer not yet connected to.
887 */ 890 */
888static struct CadetPeer * 891static struct CadetPeer *
889select_random_peer(struct CadetPeer *peer) 892select_random_peer (struct CadetPeer *peer)
890{ 893{
891 unsigned int r; 894 unsigned int r;
892 895
893 do 896 do
894 { 897 {
895 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, peers_total); 898 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, peers_total);
896 } 899 }
897 while (NULL != peers[r].incoming); 900 while (NULL != peers[r].incoming);
898 peers[r].incoming = peer; 901 peers[r].incoming = peer;
899 902
@@ -909,45 +912,46 @@ select_random_peer(struct CadetPeer *peer)
909 * @param cls Closure (unsued). 912 * @param cls Closure (unsued).
910 */ 913 */
911static void 914static void
912start_test(void *cls) 915start_test (void *cls)
913{ 916{
914 unsigned long i; 917 unsigned long i;
915 918
916 test_task = NULL; 919 test_task = NULL;
917 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Start profiler\n"); 920 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
918 921
919 922
920 for (i = 0; i < peers_pinging; i++) 923 for (i = 0; i < peers_pinging; i++)
924 {
925 peers[i].dest = select_random_peer (&peers[i]);
926 peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
927 &peers[i].dest->id,
928 GC_u2h (1));
929 if (NULL == peers[i].ch)
921 { 930 {
922 peers[i].dest = select_random_peer(&peers[i]); 931 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
923 peers[i].ch = GNUNET_CADET_channel_create(peers[i].cadet, NULL, 932 GNUNET_CADET_TEST_cleanup (test_ctx);
924 &peers[i].dest->id, 933 return;
925 GC_u2h(1));
926 if (NULL == peers[i].ch)
927 {
928 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
929 GNUNET_CADET_TEST_cleanup(test_ctx);
930 return;
931 }
932 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
933 "%lu => %u %p\n",
934 i,
935 get_index(peers[i].dest),
936 peers[i].ch);
937 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed(delay_ms_rnd(2000),
938 &ping, &peers[i]);
939 } 934 }
935 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
936 "%lu => %u %p\n",
937 i,
938 get_index (peers[i].dest),
939 peers[i].ch);
940 peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
941 &ping, &peers[i]);
942 }
940 peers_running = peers_total; 943 peers_running = peers_total;
941 if (NULL != disconnect_task) 944 if (NULL != disconnect_task)
942 GNUNET_SCHEDULER_cancel(disconnect_task); 945 GNUNET_SCHEDULER_cancel (disconnect_task);
943 disconnect_task = 946 disconnect_task =
944 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(round_time, 947 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (round_time,
945 number_rounds + 1), 948 number_rounds
946 &disconnect_cadet_peers, 949 + 1),
947 (void *)__LINE__); 950 &disconnect_cadet_peers,
948 round_task = GNUNET_SCHEDULER_add_delayed(round_time, 951 (void *) __LINE__);
949 &next_rnd, 952 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
950 NULL); 953 &next_rnd,
954 NULL);
951} 955}
952 956
953 957
@@ -955,26 +959,26 @@ start_test(void *cls)
955 * Do warmup: create some channels to spread information about the topology. 959 * Do warmup: create some channels to spread information about the topology.
956 */ 960 */
957static void 961static void
958warmup(void) 962warmup (void)
959{ 963{
960 struct CadetPeer *peer; 964 struct CadetPeer *peer;
961 unsigned int i; 965 unsigned int i;
962 966
963 for (i = 0; i < peers_total; i++) 967 for (i = 0; i < peers_total; i++)
968 {
969 peer = select_random_peer (NULL);
970 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "WARMUP %u => %u\n",
971 i, get_index (peer));
972 peers[i].warmup_ch =
973 GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id,
974 GC_u2h (1));
975 if (NULL == peers[i].warmup_ch)
964 { 976 {
965 peer = select_random_peer(NULL); 977 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
966 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WARMUP %u => %u\n", 978 GNUNET_CADET_TEST_cleanup (test_ctx);
967 i, get_index(peer)); 979 return;
968 peers[i].warmup_ch =
969 GNUNET_CADET_channel_create(peers[i].cadet, NULL, &peer->id,
970 GC_u2h(1));
971 if (NULL == peers[i].warmup_ch)
972 {
973 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
974 GNUNET_CADET_TEST_cleanup(test_ctx);
975 return;
976 }
977 } 980 }
981 }
978} 982}
979 983
980 984
@@ -988,48 +992,48 @@ warmup(void)
988 * NULL if the operation is successfull 992 * NULL if the operation is successfull
989 */ 993 */
990static void 994static void
991peer_id_cb(void *cls, 995peer_id_cb (void *cls,
992 struct GNUNET_TESTBED_Operation *op, 996 struct GNUNET_TESTBED_Operation *op,
993 const struct GNUNET_TESTBED_PeerInformation *pinfo, 997 const struct GNUNET_TESTBED_PeerInformation *pinfo,
994 const char *emsg) 998 const char *emsg)
995{ 999{
996 long n = (long)cls; 1000 long n = (long) cls;
997 1001
998 if (NULL == pinfo || NULL != emsg) 1002 if ((NULL == pinfo)||(NULL != emsg))
999 { 1003 {
1000 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg); 1004 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg);
1001 abort_test(__LINE__); 1005 abort_test (__LINE__);
1002 return; 1006 return;
1003 } 1007 }
1004 peers[n].id = *(pinfo->result.id); 1008 peers[n].id = *(pinfo->result.id);
1005 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1009 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1006 "%ld id: %s\n", 1010 "%ld id: %s\n",
1007 n, 1011 n,
1008 GNUNET_i2s(&peers[n].id)); 1012 GNUNET_i2s (&peers[n].id));
1009 GNUNET_break(GNUNET_OK == 1013 GNUNET_break (GNUNET_OK ==
1010 GNUNET_CONTAINER_multipeermap_put(ids, &peers[n].id, &peers[n], 1014 GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
1011 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 1015 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
1012 1016
1013 GNUNET_TESTBED_operation_done(peers[n].op); 1017 GNUNET_TESTBED_operation_done (peers[n].op);
1014 peers[n].op = NULL; 1018 peers[n].op = NULL;
1015 1019
1016 p_ids++; 1020 p_ids++;
1017 if (p_ids < peers_total) 1021 if (p_ids < peers_total)
1018 return; 1022 return;
1019 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n"); 1023 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
1020 if (do_warmup) 1024 if (do_warmup)
1021 { 1025 {
1022 struct GNUNET_TIME_Relative delay; 1026 struct GNUNET_TIME_Relative delay;
1023 1027
1024 warmup(); 1028 warmup ();
1025 delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1029 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1026 100 * peers_total); 1030 100 * peers_total);
1027 test_task = GNUNET_SCHEDULER_add_delayed(delay, &start_test, NULL); 1031 test_task = GNUNET_SCHEDULER_add_delayed (delay, &start_test, NULL);
1028 return; /* start_test from incoming_channel */ 1032 return; /* start_test from incoming_channel */
1029 } 1033 }
1030 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Starting in a second...\n"); 1034 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting in a second...\n");
1031 test_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 1035 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1032 &start_test, NULL); 1036 &start_test, NULL);
1033} 1037}
1034 1038
1035 1039
@@ -1043,37 +1047,37 @@ peer_id_cb(void *cls,
1043 * @param cadetes Handle to each of the CADETs of the peers. 1047 * @param cadetes Handle to each of the CADETs of the peers.
1044 */ 1048 */
1045static void 1049static void
1046tmain(void *cls, 1050tmain (void *cls,
1047 struct GNUNET_CADET_TEST_Context *ctx, 1051 struct GNUNET_CADET_TEST_Context *ctx,
1048 unsigned int num_peers, 1052 unsigned int num_peers,
1049 struct GNUNET_TESTBED_Peer **testbed_peers, 1053 struct GNUNET_TESTBED_Peer **testbed_peers,
1050 struct GNUNET_CADET_Handle **cadetes) 1054 struct GNUNET_CADET_Handle **cadetes)
1051{ 1055{
1052 unsigned long i; 1056 unsigned long i;
1053 1057
1054 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1055 "test main\n"); 1059 "test main\n");
1056 test_ctx = ctx; 1060 test_ctx = ctx;
1057 GNUNET_assert(peers_total == num_peers); 1061 GNUNET_assert (peers_total == num_peers);
1058 peers_running = num_peers; 1062 peers_running = num_peers;
1059 testbed_handles = testbed_peers; 1063 testbed_handles = testbed_peers;
1060 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, 1064 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
1061 &disconnect_cadet_peers, 1065 &disconnect_cadet_peers,
1062 (void *)__LINE__); 1066 (void *) __LINE__);
1063 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 1067 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1064 for (i = 0; i < peers_total; i++) 1068 for (i = 0; i < peers_total; i++)
1065 { 1069 {
1066 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1067 "requesting id %ld\n", 1071 "requesting id %ld\n",
1068 i); 1072 i);
1069 peers[i].up = GNUNET_YES; 1073 peers[i].up = GNUNET_YES;
1070 peers[i].cadet = cadetes[i]; 1074 peers[i].cadet = cadetes[i];
1071 peers[i].op = 1075 peers[i].op =
1072 GNUNET_TESTBED_peer_get_information(testbed_handles[i], 1076 GNUNET_TESTBED_peer_get_information (testbed_handles[i],
1073 GNUNET_TESTBED_PIT_IDENTITY, 1077 GNUNET_TESTBED_PIT_IDENTITY,
1074 &peer_id_cb, (void *)i); 1078 &peer_id_cb, (void *) i);
1075 } 1079 }
1076 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "requested peer ids\n"); 1080 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "requested peer ids\n");
1077 /* Continues from pi_cb -> do_test */ 1081 /* Continues from pi_cb -> do_test */
1078} 1082}
1079 1083
@@ -1082,7 +1086,7 @@ tmain(void *cls,
1082 * Main: start profiler. 1086 * Main: start profiler.
1083 */ 1087 */
1084int 1088int
1085main(int argc, char *argv[]) 1089main (int argc, char *argv[])
1086{ 1090{
1087 static const struct GNUNET_HashCode *ports[2]; 1091 static const struct GNUNET_HashCode *ports[2];
1088 const char *config_file; 1092 const char *config_file;
@@ -1090,59 +1094,59 @@ main(int argc, char *argv[])
1090 config_file = ".profiler.conf"; 1094 config_file = ".profiler.conf";
1091 1095
1092 if (4 > argc) 1096 if (4 > argc)
1093 { 1097 {
1094 fprintf(stderr, 1098 fprintf (stderr,
1095 "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n", 1099 "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
1096 argv[0]); 1100 argv[0]);
1097 fprintf(stderr, 1101 fprintf (stderr,
1098 "example: %s 30s 16 1 Y\n", 1102 "example: %s 30s 16 1 Y\n",
1099 argv[0]); 1103 argv[0]);
1100 return 1; 1104 return 1;
1101 } 1105 }
1102 1106
1103 if (GNUNET_OK != 1107 if (GNUNET_OK !=
1104 GNUNET_STRINGS_fancy_time_to_relative(argv[1], 1108 GNUNET_STRINGS_fancy_time_to_relative (argv[1],
1105 &round_time)) 1109 &round_time))
1106 { 1110 {
1107 fprintf(stderr, 1111 fprintf (stderr,
1108 "%s is not a valid time\n", 1112 "%s is not a valid time\n",
1109 argv[1]); 1113 argv[1]);
1110 return 1; 1114 return 1;
1111 } 1115 }
1112 1116
1113 peers_total = atoll(argv[2]); 1117 peers_total = atoll (argv[2]);
1114 if (2 > peers_total) 1118 if (2 > peers_total)
1115 { 1119 {
1116 fprintf(stderr, 1120 fprintf (stderr,
1117 "%s peers is not valid (> 2)\n", 1121 "%s peers is not valid (> 2)\n",
1118 argv[1]); 1122 argv[1]);
1119 return 1; 1123 return 1;
1120 } 1124 }
1121 peers = GNUNET_new_array(peers_total, 1125 peers = GNUNET_new_array (peers_total,
1122 struct CadetPeer); 1126 struct CadetPeer);
1123 peers_pinging = atoll(argv[3]); 1127 peers_pinging = atoll (argv[3]);
1124 1128
1125 if (peers_total < 2 * peers_pinging) 1129 if (peers_total < 2 * peers_pinging)
1126 { 1130 {
1127 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1128 "not enough peers, total should be > 2 * peers_pinging\n"); 1132 "not enough peers, total should be > 2 * peers_pinging\n");
1129 return 1; 1133 return 1;
1130 } 1134 }
1131 1135
1132 do_warmup = (5 > argc || argv[4][0] != 'N'); 1136 do_warmup = (5 > argc || argv[4][0] != 'N');
1133 1137
1134 ids = GNUNET_CONTAINER_multipeermap_create(2 * peers_total, 1138 ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
1135 GNUNET_YES); 1139 GNUNET_YES);
1136 GNUNET_assert(NULL != ids); 1140 GNUNET_assert (NULL != ids);
1137 p_ids = 0; 1141 p_ids = 0;
1138 test_finished = GNUNET_NO; 1142 test_finished = GNUNET_NO;
1139 ports[0] = GC_u2h(1); 1143 ports[0] = GC_u2h (1);
1140 ports[1] = 0; 1144 ports[1] = 0;
1141 GNUNET_CADET_TEST_run("cadet-profiler", config_file, peers_total, 1145 GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total,
1142 &tmain, NULL, /* tmain cls */ 1146 &tmain, NULL, /* tmain cls */
1143 &incoming_channel, &channel_cleaner, 1147 &incoming_channel, &channel_cleaner,
1144 handlers, ports); 1148 handlers, ports);
1145 GNUNET_free(peers); 1149 GNUNET_free (peers);
1146 1150
1147 return 0; 1151 return 0;
1148} 1152}
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index f5cf86211..d85a3c6ba 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -143,7 +143,7 @@ static unsigned int sent_pkt;
143 * Wait for input on STDIO and send it out over the #ch. 143 * Wait for input on STDIO and send it out over the #ch.
144 */ 144 */
145static void 145static void
146listen_stdio(void); 146listen_stdio (void);
147 147
148 148
149/** 149/**
@@ -154,25 +154,25 @@ listen_stdio(void);
154 * @return Human readable string. 154 * @return Human readable string.
155 */ 155 */
156static const char * 156static const char *
157enc_2s(uint16_t status) 157enc_2s (uint16_t status)
158{ 158{
159 switch (status) 159 switch (status)
160 { 160 {
161 case 0: 161 case 0:
162 return "NULL "; 162 return "NULL ";
163 163
164 case 1: 164 case 1:
165 return "KSENT"; 165 return "KSENT";
166 166
167 case 2: 167 case 2:
168 return "KRECV"; 168 return "KRECV";
169 169
170 case 3: 170 case 3:
171 return "READY"; 171 return "READY";
172 172
173 default: 173 default:
174 return ""; 174 return "";
175 } 175 }
176} 176}
177 177
178 178
@@ -184,28 +184,28 @@ enc_2s(uint16_t status)
184 * @return Human readable string. 184 * @return Human readable string.
185 */ 185 */
186static const char * 186static const char *
187conn_2s(uint16_t status) 187conn_2s (uint16_t status)
188{ 188{
189 switch (status) 189 switch (status)
190 { 190 {
191 case 0: 191 case 0:
192 return "NEW "; 192 return "NEW ";
193 193
194 case 1: 194 case 1:
195 return "SRCH "; 195 return "SRCH ";
196 196
197 case 2: 197 case 2:
198 return "WAIT "; 198 return "WAIT ";
199 199
200 case 3: 200 case 3:
201 return "READY"; 201 return "READY";
202 202
203 case 4: 203 case 4:
204 return "SHUTD"; 204 return "SHUTD";
205 205
206 default: 206 default:
207 return ""; 207 return "";
208 } 208 }
209} 209}
210 210
211 211
@@ -215,60 +215,60 @@ conn_2s(uint16_t status)
215 * @param cls Closure (unused). 215 * @param cls Closure (unused).
216 */ 216 */
217static void 217static void
218shutdown_task(void *cls) 218shutdown_task (void *cls)
219{ 219{
220 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n"); 220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
221 if (NULL != lp) 221 if (NULL != lp)
222 { 222 {
223 GNUNET_CADET_close_port(lp); 223 GNUNET_CADET_close_port (lp);
224 lp = NULL; 224 lp = NULL;
225 } 225 }
226 if (NULL != ch) 226 if (NULL != ch)
227 { 227 {
228 GNUNET_CADET_channel_destroy(ch); 228 GNUNET_CADET_channel_destroy (ch);
229 ch = NULL; 229 ch = NULL;
230 } 230 }
231 if (NULL != gpo) 231 if (NULL != gpo)
232 { 232 {
233 GNUNET_CADET_get_path_cancel(gpo); 233 GNUNET_CADET_get_path_cancel (gpo);
234 gpo = NULL; 234 gpo = NULL;
235 } 235 }
236 if (NULL != plo) 236 if (NULL != plo)
237 { 237 {
238 GNUNET_CADET_list_peers_cancel(plo); 238 GNUNET_CADET_list_peers_cancel (plo);
239 plo = NULL; 239 plo = NULL;
240 } 240 }
241 if (NULL != tio) 241 if (NULL != tio)
242 { 242 {
243 GNUNET_CADET_list_tunnels_cancel(tio); 243 GNUNET_CADET_list_tunnels_cancel (tio);
244 tio = NULL; 244 tio = NULL;
245 } 245 }
246 if (NULL != mh) 246 if (NULL != mh)
247 { 247 {
248 GNUNET_CADET_disconnect(mh); 248 GNUNET_CADET_disconnect (mh);
249 mh = NULL; 249 mh = NULL;
250 } 250 }
251 if (NULL != rd_task) 251 if (NULL != rd_task)
252 { 252 {
253 GNUNET_SCHEDULER_cancel(rd_task); 253 GNUNET_SCHEDULER_cancel (rd_task);
254 rd_task = NULL; 254 rd_task = NULL;
255 } 255 }
256 if (NULL != echo_task) 256 if (NULL != echo_task)
257 { 257 {
258 GNUNET_SCHEDULER_cancel(echo_task); 258 GNUNET_SCHEDULER_cancel (echo_task);
259 echo_task = NULL; 259 echo_task = NULL;
260 } 260 }
261 if (NULL != job) 261 if (NULL != job)
262 { 262 {
263 GNUNET_SCHEDULER_cancel(job); 263 GNUNET_SCHEDULER_cancel (job);
264 job = NULL; 264 job = NULL;
265 } 265 }
266} 266}
267 267
268void 268void
269mq_cb(void *cls) 269mq_cb (void *cls)
270{ 270{
271 listen_stdio(); 271 listen_stdio ();
272} 272}
273 273
274 274
@@ -278,7 +278,7 @@ mq_cb(void *cls)
278 * @param cls Closure (unused). 278 * @param cls Closure (unused).
279 */ 279 */
280static void 280static void
281read_stdio(void *cls) 281read_stdio (void *cls)
282{ 282{
283 struct GNUNET_MQ_Envelope *env; 283 struct GNUNET_MQ_Envelope *env;
284 struct GNUNET_MessageHeader *msg; 284 struct GNUNET_MessageHeader *msg;
@@ -286,41 +286,41 @@ read_stdio(void *cls)
286 ssize_t data_size; 286 ssize_t data_size;
287 287
288 rd_task = NULL; 288 rd_task = NULL;
289 data_size = read(0, buf, 60000); 289 data_size = read (0, buf, 60000);
290 if (data_size < 1) 290 if (data_size < 1)
291 { 291 {
292 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "read() returned %s\n", 293 "read() returned %s\n",
294 strerror(errno)); 294 strerror (errno));
295 GNUNET_SCHEDULER_shutdown(); 295 GNUNET_SCHEDULER_shutdown ();
296 return; 296 return;
297 } 297 }
298 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
299 "Read %u bytes from stdio\n", 299 "Read %u bytes from stdio\n",
300 (unsigned int)data_size); 300 (unsigned int) data_size);
301 env = GNUNET_MQ_msg_extra(msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI); 301 env = GNUNET_MQ_msg_extra (msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
302 GNUNET_memcpy(&msg[1], buf, data_size); 302 GNUNET_memcpy (&msg[1], buf, data_size);
303 GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env); 303 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
304 304
305 sent_pkt++; 305 sent_pkt++;
306 306
307 if (GNUNET_NO == echo) 307 if (GNUNET_NO == echo)
308 {
309 // Use MQ's notification if too much data of stdin is pooring in too fast.
310 if (STREAM_BUFFER_SIZE < sent_pkt)
308 { 311 {
309 // Use MQ's notification if too much data of stdin is pooring in too fast. 312 GNUNET_MQ_notify_sent (env, mq_cb, cls);
310 if (STREAM_BUFFER_SIZE < sent_pkt) 313 sent_pkt = 0;
311 {
312 GNUNET_MQ_notify_sent(env, mq_cb, cls);
313 sent_pkt = 0;
314 }
315 else
316 {
317 listen_stdio();
318 }
319 } 314 }
320 else 315 else
321 { 316 {
322 echo_time = GNUNET_TIME_absolute_get(); 317 listen_stdio ();
323 } 318 }
319 }
320 else
321 {
322 echo_time = GNUNET_TIME_absolute_get ();
323 }
324} 324}
325 325
326 326
@@ -328,20 +328,20 @@ read_stdio(void *cls)
328 * Wait for input on STDIO and send it out over the #ch. 328 * Wait for input on STDIO and send it out over the #ch.
329 */ 329 */
330static void 330static void
331listen_stdio() 331listen_stdio ()
332{ 332{
333 struct GNUNET_NETWORK_FDSet *rs; 333 struct GNUNET_NETWORK_FDSet *rs;
334 334
335 /* FIXME: why use 'rs' here, seems overly complicated... */ 335 /* FIXME: why use 'rs' here, seems overly complicated... */
336 rs = GNUNET_NETWORK_fdset_create(); 336 rs = GNUNET_NETWORK_fdset_create ();
337 GNUNET_NETWORK_fdset_set_native(rs, 0); /* STDIN */ 337 GNUNET_NETWORK_fdset_set_native (rs, 0); /* STDIN */
338 rd_task = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, 338 rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
339 GNUNET_TIME_UNIT_FOREVER_REL, 339 GNUNET_TIME_UNIT_FOREVER_REL,
340 rs, 340 rs,
341 NULL, 341 NULL,
342 &read_stdio, 342 &read_stdio,
343 NULL); 343 NULL);
344 GNUNET_NETWORK_fdset_destroy(rs); 344 GNUNET_NETWORK_fdset_destroy (rs);
345} 345}
346 346
347 347
@@ -355,12 +355,12 @@ listen_stdio()
355 * @param channel connection to the other end (henceforth invalid) 355 * @param channel connection to the other end (henceforth invalid)
356 */ 356 */
357static void 357static void
358channel_ended(void *cls, const struct GNUNET_CADET_Channel *channel) 358channel_ended (void *cls, const struct GNUNET_CADET_Channel *channel)
359{ 359{
360 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n"); 360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n");
361 GNUNET_assert(channel == ch); 361 GNUNET_assert (channel == ch);
362 ch = NULL; 362 ch = NULL;
363 GNUNET_SCHEDULER_shutdown(); 363 GNUNET_SCHEDULER_shutdown ();
364} 364}
365 365
366 366
@@ -379,20 +379,20 @@ channel_ended(void *cls, const struct GNUNET_CADET_Channel *channel)
379 * @return initial channel context for the channel, we use @a channel 379 * @return initial channel context for the channel, we use @a channel
380 */ 380 */
381static void * 381static void *
382channel_incoming(void *cls, 382channel_incoming (void *cls,
383 struct GNUNET_CADET_Channel *channel, 383 struct GNUNET_CADET_Channel *channel,
384 const struct GNUNET_PeerIdentity *initiator) 384 const struct GNUNET_PeerIdentity *initiator)
385{ 385{
386 GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, 386 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
387 "Incoming connection from %s\n", 387 "Incoming connection from %s\n",
388 GNUNET_i2s_full(initiator)); 388 GNUNET_i2s_full (initiator));
389 GNUNET_assert(NULL == ch); 389 GNUNET_assert (NULL == ch);
390 GNUNET_assert(NULL != lp); 390 GNUNET_assert (NULL != lp);
391 GNUNET_CADET_close_port(lp); 391 GNUNET_CADET_close_port (lp);
392 lp = NULL; 392 lp = NULL;
393 ch = channel; 393 ch = channel;
394 if (GNUNET_NO == echo) 394 if (GNUNET_NO == echo)
395 listen_stdio(); 395 listen_stdio ();
396 return channel; 396 return channel;
397} 397}
398 398
@@ -403,7 +403,7 @@ channel_incoming(void *cls,
403 * @param cls Closure (NULL). 403 * @param cls Closure (NULL).
404 */ 404 */
405static void 405static void
406send_echo(void *cls) 406send_echo (void *cls)
407{ 407{
408 struct GNUNET_MQ_Envelope *env; 408 struct GNUNET_MQ_Envelope *env;
409 struct GNUNET_MessageHeader *msg; 409 struct GNUNET_MessageHeader *msg;
@@ -411,8 +411,8 @@ send_echo(void *cls)
411 echo_task = NULL; 411 echo_task = NULL;
412 if (NULL == ch) 412 if (NULL == ch)
413 return; 413 return;
414 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_CLI); 414 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CLI);
415 GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env); 415 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
416} 416}
417 417
418 418
@@ -425,7 +425,7 @@ send_echo(void *cls)
425 * #GNUNET_SYSERR to close it (signal serious error). 425 * #GNUNET_SYSERR to close it (signal serious error).
426 */ 426 */
427static int 427static int
428check_data(void *cls, const struct GNUNET_MessageHeader *message) 428check_data (void *cls, const struct GNUNET_MessageHeader *message)
429{ 429{
430 return GNUNET_OK; /* all is well-formed */ 430 return GNUNET_OK; /* all is well-formed */
431} 431}
@@ -442,59 +442,59 @@ check_data(void *cls, const struct GNUNET_MessageHeader *message)
442 * @param message The actual message. 442 * @param message The actual message.
443 */ 443 */
444static void 444static void
445handle_data(void *cls, const struct GNUNET_MessageHeader *message) 445handle_data (void *cls, const struct GNUNET_MessageHeader *message)
446{ 446{
447 size_t payload_size = ntohs(message->size) - sizeof(*message); 447 size_t payload_size = ntohs (message->size) - sizeof(*message);
448 uint16_t len; 448 uint16_t len;
449 ssize_t done; 449 ssize_t done;
450 uint16_t off; 450 uint16_t off;
451 const char *buf; 451 const char *buf;
452 452
453 GNUNET_CADET_receive_done(ch); 453 GNUNET_CADET_receive_done (ch);
454 if (GNUNET_YES == echo) 454 if (GNUNET_YES == echo)
455 {
456 if (NULL != listen_port)
455 { 457 {
456 if (NULL != listen_port) 458 struct GNUNET_MQ_Envelope *env;
457 { 459 struct GNUNET_MessageHeader *msg;
458 struct GNUNET_MQ_Envelope *env; 460
459 struct GNUNET_MessageHeader *msg; 461 env =
460 462 GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
461 env = 463 GNUNET_memcpy (&msg[1], &message[1], payload_size);
462 GNUNET_MQ_msg_extra(msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI); 464 GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
463 GNUNET_memcpy(&msg[1], &message[1], payload_size); 465 return;
464 GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env);
465 return;
466 }
467 else
468 {
469 struct GNUNET_TIME_Relative latency;
470
471 latency = GNUNET_TIME_absolute_get_duration(echo_time);
472 echo_time = GNUNET_TIME_UNIT_FOREVER_ABS;
473 GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE,
474 "time: %s\n",
475 GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_NO));
476 echo_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
477 &send_echo,
478 NULL);
479 }
480 } 466 }
467 else
468 {
469 struct GNUNET_TIME_Relative latency;
470
471 latency = GNUNET_TIME_absolute_get_duration (echo_time);
472 echo_time = GNUNET_TIME_UNIT_FOREVER_ABS;
473 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
474 "time: %s\n",
475 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
476 echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
477 &send_echo,
478 NULL);
479 }
480 }
481 481
482 len = ntohs(message->size) - sizeof(*message); 482 len = ntohs (message->size) - sizeof(*message);
483 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len); 483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len);
484 buf = (const char *)&message[1]; 484 buf = (const char *) &message[1];
485 off = 0; 485 off = 0;
486 while (off < len) 486 while (off < len)
487 {
488 done = write (1, &buf[off], len - off);
489 if (done <= 0)
487 { 490 {
488 done = write(1, &buf[off], len - off); 491 if (-1 == done)
489 if (done <= 0) 492 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
490 { 493 GNUNET_SCHEDULER_shutdown ();
491 if (-1 == done) 494 return;
492 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "write");
493 GNUNET_SCHEDULER_shutdown();
494 return;
495 }
496 off += done;
497 } 495 }
496 off += done;
497 }
498} 498}
499 499
500 500
@@ -508,19 +508,19 @@ handle_data(void *cls, const struct GNUNET_MessageHeader *message)
508 * @param ple information about peer, or NULL on "EOF". 508 * @param ple information about peer, or NULL on "EOF".
509 */ 509 */
510static void 510static void
511peers_callback(void *cls, const struct GNUNET_CADET_PeerListEntry *ple) 511peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
512{ 512{
513 if (NULL == ple) 513 if (NULL == ple)
514 { 514 {
515 plo = NULL; 515 plo = NULL;
516 GNUNET_SCHEDULER_shutdown(); 516 GNUNET_SCHEDULER_shutdown ();
517 return; 517 return;
518 } 518 }
519 fprintf(stdout, 519 fprintf (stdout,
520 "%s tunnel: %c, paths: %u\n", 520 "%s tunnel: %c, paths: %u\n",
521 GNUNET_i2s_full(&ple->peer), 521 GNUNET_i2s_full (&ple->peer),
522 ple->have_tunnel ? 'Y' : 'N', 522 ple->have_tunnel ? 'Y' : 'N',
523 ple->n_paths); 523 ple->n_paths);
524} 524}
525 525
526 526
@@ -532,20 +532,20 @@ peers_callback(void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
532 * @param ppd path detail 532 * @param ppd path detail
533 */ 533 */
534static void 534static void
535path_callback(void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd) 535path_callback (void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
536{ 536{
537 if (NULL == ppd) 537 if (NULL == ppd)
538 { 538 {
539 gpo = NULL; 539 gpo = NULL;
540 GNUNET_SCHEDULER_shutdown(); 540 GNUNET_SCHEDULER_shutdown ();
541 return; 541 return;
542 } 542 }
543 fprintf(stdout, "Path of length %u: ", ppd->path_length); 543 fprintf (stdout, "Path of length %u: ", ppd->path_length);
544 for (unsigned int i = 0; i < ppd->path_length; i++) 544 for (unsigned int i = 0; i < ppd->path_length; i++)
545 fprintf(stdout, 545 fprintf (stdout,
546 (i == ppd->target_offset) ? "*%s* " : "%s ", 546 (i == ppd->target_offset) ? "*%s* " : "%s ",
547 GNUNET_i2s(&ppd->path[i])); 547 GNUNET_i2s (&ppd->path[i]));
548 fprintf(stdout, "\n"); 548 fprintf (stdout, "\n");
549} 549}
550 550
551 551
@@ -556,21 +556,21 @@ path_callback(void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
556 * @param td tunnel details 556 * @param td tunnel details
557 */ 557 */
558static void 558static void
559tunnels_callback(void *cls, const struct GNUNET_CADET_TunnelDetails *td) 559tunnels_callback (void *cls, const struct GNUNET_CADET_TunnelDetails *td)
560{ 560{
561 if (NULL == td) 561 if (NULL == td)
562 { 562 {
563 tio = NULL; 563 tio = NULL;
564 GNUNET_SCHEDULER_shutdown(); 564 GNUNET_SCHEDULER_shutdown ();
565 return; 565 return;
566 } 566 }
567 fprintf(stdout, 567 fprintf (stdout,
568 "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n", 568 "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
569 GNUNET_i2s_full(&td->peer), 569 GNUNET_i2s_full (&td->peer),
570 enc_2s(td->estate), 570 enc_2s (td->estate),
571 conn_2s(td->cstate), 571 conn_2s (td->cstate),
572 td->channels, 572 td->channels,
573 td->connections); 573 td->connections);
574} 574}
575 575
576 576
@@ -580,10 +580,10 @@ tunnels_callback(void *cls, const struct GNUNET_CADET_TunnelDetails *td)
580 * @param cls Closure (unused). 580 * @param cls Closure (unused).
581 */ 581 */
582static void 582static void
583get_peers(void *cls) 583get_peers (void *cls)
584{ 584{
585 job = NULL; 585 job = NULL;
586 plo = GNUNET_CADET_list_peers(my_cfg, &peers_callback, NULL); 586 plo = GNUNET_CADET_list_peers (my_cfg, &peers_callback, NULL);
587} 587}
588 588
589 589
@@ -593,20 +593,20 @@ get_peers(void *cls)
593 * @param cls Closure (unused). 593 * @param cls Closure (unused).
594 */ 594 */
595static void 595static void
596show_peer(void *cls) 596show_peer (void *cls)
597{ 597{
598 struct GNUNET_PeerIdentity pid; 598 struct GNUNET_PeerIdentity pid;
599 599
600 job = NULL; 600 job = NULL;
601 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string(peer_id, 601 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
602 strlen(peer_id), 602 strlen (peer_id),
603 &pid.public_key)) 603 &pid.public_key))
604 { 604 {
605 fprintf(stderr, _("Invalid peer ID `%s'\n"), peer_id); 605 fprintf (stderr, _ ("Invalid peer ID `%s'\n"), peer_id);
606 GNUNET_SCHEDULER_shutdown(); 606 GNUNET_SCHEDULER_shutdown ();
607 return; 607 return;
608 } 608 }
609 gpo = GNUNET_CADET_get_path(my_cfg, &pid, &path_callback, NULL); 609 gpo = GNUNET_CADET_get_path (my_cfg, &pid, &path_callback, NULL);
610} 610}
611 611
612 612
@@ -616,10 +616,10 @@ show_peer(void *cls)
616 * @param cls Closure (unused). 616 * @param cls Closure (unused).
617 */ 617 */
618static void 618static void
619get_tunnels(void *cls) 619get_tunnels (void *cls)
620{ 620{
621 job = NULL; 621 job = NULL;
622 tio = GNUNET_CADET_list_tunnels(my_cfg, &tunnels_callback, NULL); 622 tio = GNUNET_CADET_list_tunnels (my_cfg, &tunnels_callback, NULL);
623} 623}
624 624
625 625
@@ -629,10 +629,10 @@ get_tunnels(void *cls)
629 * @param cls Closure (unused). 629 * @param cls Closure (unused).
630 */ 630 */
631static void 631static void
632show_channel(void *cls) 632show_channel (void *cls)
633{ 633{
634 job = NULL; 634 job = NULL;
635 GNUNET_break(0); 635 GNUNET_break (0);
636} 636}
637 637
638 638
@@ -642,10 +642,10 @@ show_channel(void *cls)
642 * @param cls Closure (unused). 642 * @param cls Closure (unused).
643 */ 643 */
644static void 644static void
645show_connection(void *cls) 645show_connection (void *cls)
646{ 646{
647 job = NULL; 647 job = NULL;
648 GNUNET_break(0); 648 GNUNET_break (0);
649} 649}
650 650
651 651
@@ -658,17 +658,17 @@ show_connection(void *cls)
658 * @param cfg configuration 658 * @param cfg configuration
659 */ 659 */
660static void 660static void
661run(void *cls, 661run (void *cls,
662 char *const *args, 662 char *const *args,
663 const char *cfgfile, 663 const char *cfgfile,
664 const struct GNUNET_CONFIGURATION_Handle *cfg) 664 const struct GNUNET_CONFIGURATION_Handle *cfg)
665{ 665{
666 struct GNUNET_MQ_MessageHandler handlers[] = 666 struct GNUNET_MQ_MessageHandler handlers[] =
667 { GNUNET_MQ_hd_var_size(data, 667 { GNUNET_MQ_hd_var_size (data,
668 GNUNET_MESSAGE_TYPE_CADET_CLI, 668 GNUNET_MESSAGE_TYPE_CADET_CLI,
669 struct GNUNET_MessageHeader, 669 struct GNUNET_MessageHeader,
670 NULL), 670 NULL),
671 GNUNET_MQ_handler_end() }; 671 GNUNET_MQ_handler_end () };
672 672
673 /* FIXME add option to monitor apps */ 673 /* FIXME add option to monitor apps */
674 my_cfg = cfg; 674 my_cfg = cfg;
@@ -676,105 +676,105 @@ run(void *cls,
676 if (target_id && args[1]) 676 if (target_id && args[1])
677 target_port = args[1]; 677 target_port = args[1];
678 678
679 if ((0 != (request_peers | request_tunnels) || NULL != conn_id || 679 if (((0 != (request_peers | request_tunnels))||(NULL != conn_id)||
680 NULL != channel_id) && 680 (NULL != channel_id) ) &&
681 target_id != NULL) 681 (target_id != NULL) )
682 { 682 {
683 fprintf(stderr, 683 fprintf (stderr,
684 _("Extra arguments are not applicable " 684 _ ("Extra arguments are not applicable "
685 "in combination with this option.\n")); 685 "in combination with this option.\n"));
686 return; 686 return;
687 } 687 }
688 688
689 if (NULL != peer_id) 689 if (NULL != peer_id)
690 { 690 {
691 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show peer\n"); 691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
692 job = GNUNET_SCHEDULER_add_now(&show_peer, NULL); 692 job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
693 } 693 }
694 else if (NULL != channel_id) 694 else if (NULL != channel_id)
695 { 695 {
696 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show channel\n"); 696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
697 job = GNUNET_SCHEDULER_add_now(&show_channel, NULL); 697 job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
698 } 698 }
699 else if (NULL != conn_id) 699 else if (NULL != conn_id)
700 { 700 {
701 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show connection\n"); 701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
702 job = GNUNET_SCHEDULER_add_now(&show_connection, NULL); 702 job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
703 } 703 }
704 else if (GNUNET_YES == request_peers) 704 else if (GNUNET_YES == request_peers)
705 { 705 {
706 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n"); 706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
707 job = GNUNET_SCHEDULER_add_now(&get_peers, NULL); 707 job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
708 } 708 }
709 else if (GNUNET_YES == request_tunnels) 709 else if (GNUNET_YES == request_tunnels)
710 { 710 {
711 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n"); 711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
712 job = GNUNET_SCHEDULER_add_now(&get_tunnels, NULL); 712 job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
713 } 713 }
714 714
715 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n"); 715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n");
716 mh = GNUNET_CADET_connect(cfg); 716 mh = GNUNET_CADET_connect (cfg);
717 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 717 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
718 if (NULL == mh) 718 if (NULL == mh)
719 {
720 GNUNET_SCHEDULER_shutdown ();
721 return;
722 }
723 if (NULL != listen_port)
724 {
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n");
726 GNUNET_CRYPTO_hash (listen_port, strlen (listen_port), &porthash);
727 lp = GNUNET_CADET_open_port (mh,
728 &porthash,
729 &channel_incoming,
730 NULL,
731 NULL /* window changes */,
732 &channel_ended,
733 handlers);
734 }
735 if (NULL != target_id)
736 {
737 struct GNUNET_PeerIdentity pid;
738
739 if (GNUNET_OK !=
740 GNUNET_CRYPTO_eddsa_public_key_from_string (target_id,
741 strlen (target_id),
742 &pid.public_key))
719 { 743 {
720 GNUNET_SCHEDULER_shutdown(); 744 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
745 _ ("Invalid target `%s'\n"),
746 target_id);
747 GNUNET_SCHEDULER_shutdown ();
721 return; 748 return;
722 } 749 }
723 if (NULL != listen_port) 750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
751 "Connecting to `%s:%s'\n",
752 target_id,
753 target_port);
754 GNUNET_CRYPTO_hash (target_port, strlen (target_port), &porthash);
755 ch = GNUNET_CADET_channel_create (mh,
756 NULL,
757 &pid,
758 &porthash,
759 NULL /* window changes */,
760 &channel_ended,
761 handlers);
762 if (GNUNET_YES == echo)
724 { 763 {
725 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n"); 764 echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
726 GNUNET_CRYPTO_hash(listen_port, strlen(listen_port), &porthash);
727 lp = GNUNET_CADET_open_port(mh,
728 &porthash,
729 &channel_incoming,
730 NULL,
731 NULL /* window changes */,
732 &channel_ended,
733 handlers);
734 } 765 }
735 if (NULL != target_id) 766 else
736 { 767 {
737 struct GNUNET_PeerIdentity pid; 768 listen_stdio ();
738
739 if (GNUNET_OK !=
740 GNUNET_CRYPTO_eddsa_public_key_from_string(target_id,
741 strlen(target_id),
742 &pid.public_key))
743 {
744 GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE,
745 _("Invalid target `%s'\n"),
746 target_id);
747 GNUNET_SCHEDULER_shutdown();
748 return;
749 }
750 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
751 "Connecting to `%s:%s'\n",
752 target_id,
753 target_port);
754 GNUNET_CRYPTO_hash(target_port, strlen(target_port), &porthash);
755 ch = GNUNET_CADET_channel_create(mh,
756 NULL,
757 &pid,
758 &porthash,
759 NULL /* window changes */,
760 &channel_ended,
761 handlers);
762 if (GNUNET_YES == echo)
763 {
764 echo_task = GNUNET_SCHEDULER_add_now(&send_echo, NULL);
765 }
766 else
767 {
768 listen_stdio();
769 }
770 } 769 }
770 }
771 771
772 if ((NULL == lp) && (NULL == job) && (NULL == ch)) 772 if ((NULL == lp) && (NULL == job) && (NULL == ch))
773 { 773 {
774 GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, _("No action requested\n")); 774 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _ ("No action requested\n"));
775 GNUNET_SCHEDULER_shutdown(); 775 GNUNET_SCHEDULER_shutdown ();
776 return; 776 return;
777 } 777 }
778} 778}
779 779
780 780
@@ -786,61 +786,60 @@ run(void *cls,
786 * @return 0 ok, 1 on error 786 * @return 0 ok, 1 on error
787 */ 787 */
788int 788int
789main(int argc, char *const *argv) 789main (int argc, char *const *argv)
790{ 790{
791 int res; 791 int res;
792 const char helpstr[] = 792 const char helpstr[] =
793 "Create tunnels and retrieve info about CADET's status."; 793 "Create tunnels and retrieve info about CADET's status.";
794 struct GNUNET_GETOPT_CommandLineOption options[] = 794 struct GNUNET_GETOPT_CommandLineOption options[] = { /* I would use the terminology 'circuit' here... --lynX */
795 { /* I would use the terminology 'circuit' here... --lynX */ 795 GNUNET_GETOPT_option_string (
796 GNUNET_GETOPT_option_string(
797 'C', 796 'C',
798 "connection", 797 "connection",
799 "CONNECTION_ID", 798 "CONNECTION_ID",
800 gettext_noop("Provide information about a particular connection"), 799 gettext_noop ("Provide information about a particular connection"),
801 &conn_id), 800 &conn_id),
802 GNUNET_GETOPT_option_flag('e', 801 GNUNET_GETOPT_option_flag ('e',
803 "echo", 802 "echo",
804 gettext_noop("Activate echo mode"), 803 gettext_noop ("Activate echo mode"),
805 &echo), 804 &echo),
806 GNUNET_GETOPT_option_string( 805 GNUNET_GETOPT_option_string (
807 'o', 806 'o',
808 "open-port", 807 "open-port",
809 "SHARED_SECRET", 808 "SHARED_SECRET",
810 gettext_noop( 809 gettext_noop (
811 "Listen for connections using a shared secret among sender and recipient"), 810 "Listen for connections using a shared secret among sender and recipient"),
812 &listen_port), 811 &listen_port),
813 GNUNET_GETOPT_option_string('p', 812 GNUNET_GETOPT_option_string ('p',
814 "peer", 813 "peer",
815 "PEER_ID", 814 "PEER_ID",
816 gettext_noop( 815 gettext_noop (
817 "Provide information about a patricular peer"), 816 "Provide information about a patricular peer"),
818 &peer_id), 817 &peer_id),
819 GNUNET_GETOPT_option_flag('P', 818 GNUNET_GETOPT_option_flag ('P',
820 "peers", 819 "peers",
821 gettext_noop( 820 gettext_noop (
822 "Provide information about all peers"), 821 "Provide information about all peers"),
823 &request_peers), 822 &request_peers),
824 GNUNET_GETOPT_option_flag('T', 823 GNUNET_GETOPT_option_flag ('T',
825 "tunnels", 824 "tunnels",
826 gettext_noop( 825 gettext_noop (
827 "Provide information about all tunnels"), 826 "Provide information about all tunnels"),
828 &request_tunnels), 827 &request_tunnels),
829 GNUNET_GETOPT_OPTION_END 828 GNUNET_GETOPT_OPTION_END
830 }; 829 };
831 830
832 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 831 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
833 return 2; 832 return 2;
834 833
835 res = GNUNET_PROGRAM_run(argc, 834 res = GNUNET_PROGRAM_run (argc,
836 argv, 835 argv,
837 "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)", 836 "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)",
838 gettext_noop(helpstr), 837 gettext_noop (helpstr),
839 options, 838 options,
840 &run, 839 &run,
841 NULL); 840 NULL);
842 841
843 GNUNET_free((void *)argv); 842 GNUNET_free ((void *) argv);
844 843
845 if (GNUNET_OK == res) 844 if (GNUNET_OK == res)
846 return 0; 845 return 0;
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c
index a06cd184f..c64da33e2 100644
--- a/src/cadet/gnunet-service-cadet.c
+++ b/src/cadet/gnunet-service-cadet.c
@@ -46,13 +46,14 @@
46#include "gnunet-service-cadet_peer.h" 46#include "gnunet-service-cadet_peer.h"
47#include "gnunet-service-cadet_paths.h" 47#include "gnunet-service-cadet_paths.h"
48 48
49#define LOG(level, ...) GNUNET_log(level, __VA_ARGS__) 49#define LOG(level, ...) GNUNET_log (level, __VA_ARGS__)
50 50
51 51
52/** 52/**
53 * Struct containing information about a client of the service 53 * Struct containing information about a client of the service
54 */ 54 */
55struct CadetClient { 55struct CadetClient
56{
56 /** 57 /**
57 * Linked list next 58 * Linked list next
58 */ 59 */
@@ -201,11 +202,11 @@ unsigned long long drop_percent;
201 * @param env envelope with the message 202 * @param env envelope with the message
202 */ 203 */
203void 204void
204GSC_send_to_client(struct CadetClient *c, 205GSC_send_to_client (struct CadetClient *c,
205 struct GNUNET_MQ_Envelope *env) 206 struct GNUNET_MQ_Envelope *env)
206{ 207{
207 GNUNET_MQ_send(c->mq, 208 GNUNET_MQ_send (c->mq,
208 env); 209 env);
209} 210}
210 211
211 212
@@ -216,14 +217,14 @@ GSC_send_to_client(struct CadetClient *c,
216 * @return string for debugging 217 * @return string for debugging
217 */ 218 */
218const char * 219const char *
219GSC_2s(struct CadetClient *c) 220GSC_2s (struct CadetClient *c)
220{ 221{
221 static char buf[32]; 222 static char buf[32];
222 223
223 GNUNET_snprintf(buf, 224 GNUNET_snprintf (buf,
224 sizeof(buf), 225 sizeof(buf),
225 "Client(%u)", 226 "Client(%u)",
226 c->id); 227 c->id);
227 return buf; 228 return buf;
228} 229}
229 230
@@ -236,11 +237,11 @@ GSC_2s(struct CadetClient *c)
236 * @return NULL if no such channel exists 237 * @return NULL if no such channel exists
237 */ 238 */
238static struct CadetChannel * 239static struct CadetChannel *
239lookup_channel(struct CadetClient *c, 240lookup_channel (struct CadetClient *c,
240 struct GNUNET_CADET_ClientChannelNumber ccn) 241 struct GNUNET_CADET_ClientChannelNumber ccn)
241{ 242{
242 return GNUNET_CONTAINER_multihashmap32_get(c->channels, 243 return GNUNET_CONTAINER_multihashmap32_get (c->channels,
243 ntohl(ccn.channel_of_client)); 244 ntohl (ccn.channel_of_client));
244} 245}
245 246
246 247
@@ -251,23 +252,23 @@ lookup_channel(struct CadetClient *c,
251 * @param c client handle 252 * @param c client handle
252 */ 253 */
253static struct GNUNET_CADET_ClientChannelNumber 254static struct GNUNET_CADET_ClientChannelNumber
254client_get_next_ccn(struct CadetClient *c) 255client_get_next_ccn (struct CadetClient *c)
255{ 256{
256 struct GNUNET_CADET_ClientChannelNumber ccn = c->next_ccn; 257 struct GNUNET_CADET_ClientChannelNumber ccn = c->next_ccn;
257 258
258 /* increment until we have a free one... */ 259 /* increment until we have a free one... */
259 while (NULL != 260 while (NULL !=
260 lookup_channel(c, 261 lookup_channel (c,
261 ccn)) 262 ccn))
262 { 263 {
263 ccn.channel_of_client 264 ccn.channel_of_client
264 = htonl(1 + (ntohl(ccn.channel_of_client))); 265 = htonl (1 + (ntohl (ccn.channel_of_client)));
265 if (ntohl(ccn.channel_of_client) >= 266 if (ntohl (ccn.channel_of_client) >=
266 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 267 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
267 ccn.channel_of_client = htonl(0); 268 ccn.channel_of_client = htonl (0);
268 } 269 }
269 c->next_ccn.channel_of_client 270 c->next_ccn.channel_of_client
270 = htonl(1 + (ntohl(ccn.channel_of_client))); 271 = htonl (1 + (ntohl (ccn.channel_of_client)));
271 return ccn; 272 return ccn;
272} 273}
273 274
@@ -285,38 +286,39 @@ client_get_next_ccn(struct CadetClient *c)
285 * @return local channel number assigned to the new client 286 * @return local channel number assigned to the new client
286 */ 287 */
287struct GNUNET_CADET_ClientChannelNumber 288struct GNUNET_CADET_ClientChannelNumber
288GSC_bind(struct CadetClient *c, 289GSC_bind (struct CadetClient *c,
289 struct CadetChannel *ch, 290 struct CadetChannel *ch,
290 struct CadetPeer *dest, 291 struct CadetPeer *dest,
291 const struct GNUNET_HashCode *port, 292 const struct GNUNET_HashCode *port,
292 uint32_t options) 293 uint32_t options)
293{ 294{
294 struct GNUNET_MQ_Envelope *env; 295 struct GNUNET_MQ_Envelope *env;
295 struct GNUNET_CADET_LocalChannelCreateMessage *cm; 296 struct GNUNET_CADET_LocalChannelCreateMessage *cm;
296 struct GNUNET_CADET_ClientChannelNumber ccn; 297 struct GNUNET_CADET_ClientChannelNumber ccn;
297 298
298 ccn = client_get_next_ccn(c); 299 ccn = client_get_next_ccn (c);
299 GNUNET_assert(GNUNET_YES == 300 GNUNET_assert (GNUNET_YES ==
300 GNUNET_CONTAINER_multihashmap32_put(c->channels, 301 GNUNET_CONTAINER_multihashmap32_put (c->channels,
301 ntohl(ccn.channel_of_client), 302 ntohl (
302 ch, 303 ccn.channel_of_client),
303 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 304 ch,
304 LOG(GNUNET_ERROR_TYPE_DEBUG, 305 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
305 "Accepting incoming %s from %s on open port %s (%u), assigning ccn %X\n", 306 LOG (GNUNET_ERROR_TYPE_DEBUG,
306 GCCH_2s(ch), 307 "Accepting incoming %s from %s on open port %s (%u), assigning ccn %X\n",
307 GCP_2s(dest), 308 GCCH_2s (ch),
308 GNUNET_h2s(port), 309 GCP_2s (dest),
309 (uint32_t)ntohl(options), 310 GNUNET_h2s (port),
310 (uint32_t)ntohl(ccn.channel_of_client)); 311 (uint32_t) ntohl (options),
312 (uint32_t) ntohl (ccn.channel_of_client));
311 /* notify local client about incoming connection! */ 313 /* notify local client about incoming connection! */
312 env = GNUNET_MQ_msg(cm, 314 env = GNUNET_MQ_msg (cm,
313 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); 315 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
314 cm->ccn = ccn; 316 cm->ccn = ccn;
315 cm->port = *port; 317 cm->port = *port;
316 cm->opt = htonl(options); 318 cm->opt = htonl (options);
317 cm->peer = *GCP_get_id(dest); 319 cm->peer = *GCP_get_id (dest);
318 GSC_send_to_client(c, 320 GSC_send_to_client (c,
319 env); 321 env);
320 return ccn; 322 return ccn;
321} 323}
322 324
@@ -331,16 +333,16 @@ GSC_bind(struct CadetClient *c,
331 * @return #GNUNET_OK (iterate over all entries) 333 * @return #GNUNET_OK (iterate over all entries)
332 */ 334 */
333static int 335static int
334destroy_tunnels_now(void *cls, 336destroy_tunnels_now (void *cls,
335 const struct GNUNET_PeerIdentity *pid, 337 const struct GNUNET_PeerIdentity *pid,
336 void *value) 338 void *value)
337{ 339{
338 struct CadetPeer *cp = value; 340 struct CadetPeer *cp = value;
339 struct CadetTunnel *t = GCP_get_tunnel(cp, 341 struct CadetTunnel *t = GCP_get_tunnel (cp,
340 GNUNET_NO); 342 GNUNET_NO);
341 343
342 if (NULL != t) 344 if (NULL != t)
343 GCT_destroy_tunnel_now(t); 345 GCT_destroy_tunnel_now (t);
344 return GNUNET_OK; 346 return GNUNET_OK;
345} 347}
346 348
@@ -355,13 +357,13 @@ destroy_tunnels_now(void *cls,
355 * @return #GNUNET_OK (iterate over all entries) 357 * @return #GNUNET_OK (iterate over all entries)
356 */ 358 */
357static int 359static int
358destroy_paths_now(void *cls, 360destroy_paths_now (void *cls,
359 const struct GNUNET_PeerIdentity *pid, 361 const struct GNUNET_PeerIdentity *pid,
360 void *value) 362 void *value)
361{ 363{
362 struct CadetPeer *cp = value; 364 struct CadetPeer *cp = value;
363 365
364 GCP_drop_owned_paths(cp); 366 GCP_drop_owned_paths (cp);
365 return GNUNET_OK; 367 return GNUNET_OK;
366} 368}
367 369
@@ -370,50 +372,50 @@ destroy_paths_now(void *cls,
370 * Shutdown everything once the clients have disconnected. 372 * Shutdown everything once the clients have disconnected.
371 */ 373 */
372static void 374static void
373shutdown_rest() 375shutdown_rest ()
374{ 376{
375 if (NULL != stats) 377 if (NULL != stats)
376 { 378 {
377 GNUNET_STATISTICS_destroy(stats, 379 GNUNET_STATISTICS_destroy (stats,
378 GNUNET_NO); 380 GNUNET_NO);
379 stats = NULL; 381 stats = NULL;
380 } 382 }
381 /* Destroy tunnels. Note that all channels must be destroyed first! */ 383 /* Destroy tunnels. Note that all channels must be destroyed first! */
382 GCP_iterate_all(&destroy_tunnels_now, 384 GCP_iterate_all (&destroy_tunnels_now,
383 NULL); 385 NULL);
384 /* All tunnels, channels, connections and CORE must be down before this point. */ 386 /* All tunnels, channels, connections and CORE must be down before this point. */
385 GCP_iterate_all(&destroy_paths_now, 387 GCP_iterate_all (&destroy_paths_now,
386 NULL); 388 NULL);
387 /* All paths, tunnels, channels, connections and CORE must be down before this point. */ 389 /* All paths, tunnels, channels, connections and CORE must be down before this point. */
388 GCP_destroy_all_peers(); 390 GCP_destroy_all_peers ();
389 if (NULL != open_ports) 391 if (NULL != open_ports)
390 { 392 {
391 GNUNET_CONTAINER_multihashmap_destroy(open_ports); 393 GNUNET_CONTAINER_multihashmap_destroy (open_ports);
392 open_ports = NULL; 394 open_ports = NULL;
393 } 395 }
394 if (NULL != loose_channels) 396 if (NULL != loose_channels)
395 { 397 {
396 GNUNET_CONTAINER_multihashmap_destroy(loose_channels); 398 GNUNET_CONTAINER_multihashmap_destroy (loose_channels);
397 loose_channels = NULL; 399 loose_channels = NULL;
398 } 400 }
399 if (NULL != peers) 401 if (NULL != peers)
400 { 402 {
401 GNUNET_CONTAINER_multipeermap_destroy(peers); 403 GNUNET_CONTAINER_multipeermap_destroy (peers);
402 peers = NULL; 404 peers = NULL;
403 } 405 }
404 if (NULL != connections) 406 if (NULL != connections)
405 { 407 {
406 GNUNET_CONTAINER_multishortmap_destroy(connections); 408 GNUNET_CONTAINER_multishortmap_destroy (connections);
407 connections = NULL; 409 connections = NULL;
408 } 410 }
409 if (NULL != ats_ch) 411 if (NULL != ats_ch)
410 { 412 {
411 GNUNET_ATS_connectivity_done(ats_ch); 413 GNUNET_ATS_connectivity_done (ats_ch);
412 ats_ch = NULL; 414 ats_ch = NULL;
413 } 415 }
414 GCD_shutdown(); 416 GCD_shutdown ();
415 GCH_shutdown(); 417 GCH_shutdown ();
416 GNUNET_free_non_null(my_private_key); 418 GNUNET_free_non_null (my_private_key);
417 my_private_key = NULL; 419 my_private_key = NULL;
418} 420}
419 421
@@ -424,14 +426,14 @@ shutdown_rest()
424 * @param cls unused 426 * @param cls unused
425 */ 427 */
426static void 428static void
427shutdown_task(void *cls) 429shutdown_task (void *cls)
428{ 430{
429 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
430 "Shutting down\n"); 432 "Shutting down\n");
431 shutting_down = GNUNET_YES; 433 shutting_down = GNUNET_YES;
432 GCO_shutdown(); 434 GCO_shutdown ();
433 if (NULL == clients_head) 435 if (NULL == clients_head)
434 shutdown_rest(); 436 shutdown_rest ();
435} 437}
436 438
437 439
@@ -445,20 +447,20 @@ shutdown_task(void *cls)
445 * @return #GNUNET_YES (iterate over all such channels) 447 * @return #GNUNET_YES (iterate over all such channels)
446 */ 448 */
447static int 449static int
448bind_loose_channel(void *cls, 450bind_loose_channel (void *cls,
449 const struct GNUNET_HashCode *port, 451 const struct GNUNET_HashCode *port,
450 void *value) 452 void *value)
451{ 453{
452 struct OpenPort *op = cls; 454 struct OpenPort *op = cls;
453 struct CadetChannel *ch = value; 455 struct CadetChannel *ch = value;
454 456
455 GCCH_bind(ch, 457 GCCH_bind (ch,
456 op->c, 458 op->c,
457 &op->port); 459 &op->port);
458 GNUNET_assert(GNUNET_YES == 460 GNUNET_assert (GNUNET_YES ==
459 GNUNET_CONTAINER_multihashmap_remove(loose_channels, 461 GNUNET_CONTAINER_multihashmap_remove (loose_channels,
460 &op->h_port, 462 &op->h_port,
461 ch)); 463 ch));
462 return GNUNET_YES; 464 return GNUNET_YES;
463} 465}
464 466
@@ -473,44 +475,44 @@ bind_loose_channel(void *cls,
473 * @param pmsg The actual message. 475 * @param pmsg The actual message.
474 */ 476 */
475static void 477static void
476handle_port_open(void *cls, 478handle_port_open (void *cls,
477 const struct GNUNET_CADET_PortMessage *pmsg) 479 const struct GNUNET_CADET_PortMessage *pmsg)
478{ 480{
479 struct CadetClient *c = cls; 481 struct CadetClient *c = cls;
480 struct OpenPort *op; 482 struct OpenPort *op;
481 483
482 LOG(GNUNET_ERROR_TYPE_DEBUG, 484 LOG (GNUNET_ERROR_TYPE_DEBUG,
483 "Open port %s requested by %s\n", 485 "Open port %s requested by %s\n",
484 GNUNET_h2s(&pmsg->port), 486 GNUNET_h2s (&pmsg->port),
485 GSC_2s(c)); 487 GSC_2s (c));
486 if (NULL == c->ports) 488 if (NULL == c->ports)
487 c->ports = GNUNET_CONTAINER_multihashmap_create(4, 489 c->ports = GNUNET_CONTAINER_multihashmap_create (4,
488 GNUNET_NO); 490 GNUNET_NO);
489 op = GNUNET_new(struct OpenPort); 491 op = GNUNET_new (struct OpenPort);
490 op->c = c; 492 op->c = c;
491 op->port = pmsg->port; 493 op->port = pmsg->port;
492 GCCH_hash_port(&op->h_port, 494 GCCH_hash_port (&op->h_port,
493 &pmsg->port, 495 &pmsg->port,
494 &my_full_id); 496 &my_full_id);
495 if (GNUNET_OK != 497 if (GNUNET_OK !=
496 GNUNET_CONTAINER_multihashmap_put(c->ports, 498 GNUNET_CONTAINER_multihashmap_put (c->ports,
497 &op->port, 499 &op->port,
498 op, 500 op,
499 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 501 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
500 { 502 {
501 GNUNET_break(0); 503 GNUNET_break (0);
502 GNUNET_SERVICE_client_drop(c->client); 504 GNUNET_SERVICE_client_drop (c->client);
503 return; 505 return;
504 } 506 }
505 (void)GNUNET_CONTAINER_multihashmap_put(open_ports, 507 (void) GNUNET_CONTAINER_multihashmap_put (open_ports,
506 &op->h_port, 508 &op->h_port,
507 op, 509 op,
508 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 510 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
509 GNUNET_CONTAINER_multihashmap_get_multiple(loose_channels, 511 GNUNET_CONTAINER_multihashmap_get_multiple (loose_channels,
510 &op->h_port, 512 &op->h_port,
511 &bind_loose_channel, 513 &bind_loose_channel,
512 op); 514 op);
513 GNUNET_SERVICE_client_continue(c->client); 515 GNUNET_SERVICE_client_continue (c->client);
514} 516}
515 517
516 518
@@ -524,41 +526,41 @@ handle_port_open(void *cls,
524 * @param pmsg The actual message. 526 * @param pmsg The actual message.
525 */ 527 */
526static void 528static void
527handle_port_close(void *cls, 529handle_port_close (void *cls,
528 const struct GNUNET_CADET_PortMessage *pmsg) 530 const struct GNUNET_CADET_PortMessage *pmsg)
529{ 531{
530 struct CadetClient *c = cls; 532 struct CadetClient *c = cls;
531 struct OpenPort *op; 533 struct OpenPort *op;
532 534
533 LOG(GNUNET_ERROR_TYPE_DEBUG, 535 LOG (GNUNET_ERROR_TYPE_DEBUG,
534 "Closing port %s as requested by %s\n", 536 "Closing port %s as requested by %s\n",
535 GNUNET_h2s(&pmsg->port), 537 GNUNET_h2s (&pmsg->port),
536 GSC_2s(c)); 538 GSC_2s (c));
537 if (NULL == c->ports) 539 if (NULL == c->ports)
538 { 540 {
539 /* Client closed a port despite _never_ having opened one? */ 541 /* Client closed a port despite _never_ having opened one? */
540 GNUNET_break(0); 542 GNUNET_break (0);
541 GNUNET_SERVICE_client_drop(c->client); 543 GNUNET_SERVICE_client_drop (c->client);
542 return; 544 return;
543 } 545 }
544 op = GNUNET_CONTAINER_multihashmap_get(c->ports, 546 op = GNUNET_CONTAINER_multihashmap_get (c->ports,
545 &pmsg->port); 547 &pmsg->port);
546 if (NULL == op) 548 if (NULL == op)
547 { 549 {
548 GNUNET_break(0); 550 GNUNET_break (0);
549 GNUNET_SERVICE_client_drop(c->client); 551 GNUNET_SERVICE_client_drop (c->client);
550 return; 552 return;
551 } 553 }
552 GNUNET_assert(GNUNET_YES == 554 GNUNET_assert (GNUNET_YES ==
553 GNUNET_CONTAINER_multihashmap_remove(c->ports, 555 GNUNET_CONTAINER_multihashmap_remove (c->ports,
554 &op->port, 556 &op->port,
555 op)); 557 op));
556 GNUNET_assert(GNUNET_YES == 558 GNUNET_assert (GNUNET_YES ==
557 GNUNET_CONTAINER_multihashmap_remove(open_ports, 559 GNUNET_CONTAINER_multihashmap_remove (open_ports,
558 &op->h_port, 560 &op->h_port,
559 op)); 561 op));
560 GNUNET_free(op); 562 GNUNET_free (op);
561 GNUNET_SERVICE_client_continue(c->client); 563 GNUNET_SERVICE_client_continue (c->client);
562} 564}
563 565
564 566
@@ -569,54 +571,56 @@ handle_port_close(void *cls,
569 * @param tcm The actual message. 571 * @param tcm The actual message.
570 */ 572 */
571static void 573static void
572handle_channel_create(void *cls, 574handle_channel_create (void *cls,
573 const struct GNUNET_CADET_LocalChannelCreateMessage *tcm) 575 const struct GNUNET_CADET_LocalChannelCreateMessage *tcm)
574{ 576{
575 struct CadetClient *c = cls; 577 struct CadetClient *c = cls;
576 struct CadetChannel *ch; 578 struct CadetChannel *ch;
577 579
578 if (ntohl(tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 580 if (ntohl (tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
579 { 581 {
580 /* Channel ID not in allowed range. */ 582 /* Channel ID not in allowed range. */
581 GNUNET_break(0); 583 GNUNET_break (0);
582 GNUNET_SERVICE_client_drop(c->client); 584 GNUNET_SERVICE_client_drop (c->client);
583 return; 585 return;
584 } 586 }
585 ch = lookup_channel(c, 587 ch = lookup_channel (c,
586 tcm->ccn); 588 tcm->ccn);
587 if (NULL != ch) 589 if (NULL != ch)
588 { 590 {
589 /* Channel ID already in use. Not allowed. */ 591 /* Channel ID already in use. Not allowed. */
590 GNUNET_break(0); 592 GNUNET_break (0);
591 GNUNET_SERVICE_client_drop(c->client); 593 GNUNET_SERVICE_client_drop (c->client);
592 return; 594 return;
593 } 595 }
594 LOG(GNUNET_ERROR_TYPE_DEBUG, 596 LOG (GNUNET_ERROR_TYPE_DEBUG,
595 "New channel to %s at port %s requested by %s\n", 597 "New channel to %s at port %s requested by %s\n",
596 GNUNET_i2s(&tcm->peer), 598 GNUNET_i2s (&tcm->peer),
597 GNUNET_h2s(&tcm->port), 599 GNUNET_h2s (&tcm->port),
598 GSC_2s(c)); 600 GSC_2s (c));
599 601
600 /* Create channel */ 602 /* Create channel */
601 ch = GCCH_channel_local_new(c, 603 ch = GCCH_channel_local_new (c,
602 tcm->ccn, 604 tcm->ccn,
603 GCP_get(&tcm->peer, 605 GCP_get (&tcm->peer,
604 GNUNET_YES), 606 GNUNET_YES),
605 &tcm->port, 607 &tcm->port,
606 ntohl(tcm->opt)); 608 ntohl (tcm->opt));
607 if (NULL == ch) 609 if (NULL == ch)
608 { 610 {
609 GNUNET_break(0); 611 GNUNET_break (0);
610 GNUNET_SERVICE_client_drop(c->client); 612 GNUNET_SERVICE_client_drop (c->client);
611 return; 613 return;
612 } 614 }
613 GNUNET_assert(GNUNET_YES == 615 GNUNET_assert (GNUNET_YES ==
614 GNUNET_CONTAINER_multihashmap32_put(c->channels, 616 GNUNET_CONTAINER_multihashmap32_put (c->channels,
615 ntohl(tcm->ccn.channel_of_client), 617 ntohl (
616 ch, 618 tcm->ccn.
617 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 619 channel_of_client),
618 620 ch,
619 GNUNET_SERVICE_client_continue(c->client); 621 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
622
623 GNUNET_SERVICE_client_continue (c->client);
620} 624}
621 625
622 626
@@ -627,37 +631,40 @@ handle_channel_create(void *cls,
627 * @param msg the actual message 631 * @param msg the actual message
628 */ 632 */
629static void 633static void
630handle_channel_destroy(void *cls, 634handle_channel_destroy (void *cls,
631 const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) 635 const struct
636 GNUNET_CADET_LocalChannelDestroyMessage *msg)
632{ 637{
633 struct CadetClient *c = cls; 638 struct CadetClient *c = cls;
634 struct CadetChannel *ch; 639 struct CadetChannel *ch;
635 640
636 ch = lookup_channel(c, 641 ch = lookup_channel (c,
637 msg->ccn); 642 msg->ccn);
638 if (NULL == ch) 643 if (NULL == ch)
639 { 644 {
640 /* Client attempted to destroy unknown channel. 645 /* Client attempted to destroy unknown channel.
641 Can happen if the other side went down at the same time.*/ 646 Can happen if the other side went down at the same time.*/
642 LOG(GNUNET_ERROR_TYPE_DEBUG, 647 LOG (GNUNET_ERROR_TYPE_DEBUG,
643 "%s tried to destroy unknown channel %X\n", 648 "%s tried to destroy unknown channel %X\n",
644 GSC_2s(c), 649 GSC_2s (c),
645 (uint32_t)ntohl(msg->ccn.channel_of_client)); 650 (uint32_t) ntohl (msg->ccn.channel_of_client));
646 GNUNET_SERVICE_client_continue(c->client); 651 GNUNET_SERVICE_client_continue (c->client);
647 return; 652 return;
648 } 653 }
649 LOG(GNUNET_ERROR_TYPE_DEBUG, 654 LOG (GNUNET_ERROR_TYPE_DEBUG,
650 "%s is destroying %s\n", 655 "%s is destroying %s\n",
651 GSC_2s(c), 656 GSC_2s (c),
652 GCCH_2s(ch)); 657 GCCH_2s (ch));
653 GNUNET_assert(GNUNET_YES == 658 GNUNET_assert (GNUNET_YES ==
654 GNUNET_CONTAINER_multihashmap32_remove(c->channels, 659 GNUNET_CONTAINER_multihashmap32_remove (c->channels,
655 ntohl(msg->ccn.channel_of_client), 660 ntohl (
656 ch)); 661 msg->ccn.
657 GCCH_channel_local_destroy(ch, 662 channel_of_client),
658 c, 663 ch));
659 msg->ccn); 664 GCCH_channel_local_destroy (ch,
660 GNUNET_SERVICE_client_continue(c->client); 665 c,
666 msg->ccn);
667 GNUNET_SERVICE_client_continue (c->client);
661} 668}
662 669
663 670
@@ -669,8 +676,8 @@ handle_channel_destroy(void *cls,
669 * @return #GNUNET_OK if @a msg is OK, #GNUNET_SYSERR if not 676 * @return #GNUNET_OK if @a msg is OK, #GNUNET_SYSERR if not
670 */ 677 */
671static int 678static int
672check_local_data(void *cls, 679check_local_data (void *cls,
673 const struct GNUNET_CADET_LocalData *msg) 680 const struct GNUNET_CADET_LocalData *msg)
674{ 681{
675 size_t payload_size; 682 size_t payload_size;
676 size_t payload_claimed_size; 683 size_t payload_claimed_size;
@@ -683,36 +690,36 @@ check_local_data(void *cls,
683 cadet_api will likely no more, so we could then 690 cadet_api will likely no more, so we could then
684 simplify this mess again. */ 691 simplify this mess again. */
685 /* Sanity check for message size */ 692 /* Sanity check for message size */
686 payload_size = ntohs(msg->header.size) - sizeof(*msg); 693 payload_size = ntohs (msg->header.size) - sizeof(*msg);
687 buf = (const char *)&msg[1]; 694 buf = (const char *) &msg[1];
688 while (payload_size >= sizeof(struct GNUNET_MessageHeader)) 695 while (payload_size >= sizeof(struct GNUNET_MessageHeader))
696 {
697 /* need to memcpy() for alignment */
698 GNUNET_memcpy (&pa,
699 buf,
700 sizeof(pa));
701 payload_claimed_size = ntohs (pa.size);
702 if ((payload_size < payload_claimed_size) ||
703 (payload_claimed_size < sizeof(struct GNUNET_MessageHeader)) ||
704 (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < payload_claimed_size))
689 { 705 {
690 /* need to memcpy() for alignment */ 706 GNUNET_break (0);
691 GNUNET_memcpy(&pa, 707 LOG (GNUNET_ERROR_TYPE_DEBUG,
692 buf, 708 "Local data of %u total size had sub-message %u at %u with %u bytes\n",
693 sizeof(pa)); 709 ntohs (msg->header.size),
694 payload_claimed_size = ntohs(pa.size); 710 ntohs (pa.type),
695 if ((payload_size < payload_claimed_size) || 711 (unsigned int) (buf - (const char *) &msg[1]),
696 (payload_claimed_size < sizeof(struct GNUNET_MessageHeader)) || 712 (unsigned int) payload_claimed_size);
697 (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < payload_claimed_size))
698 {
699 GNUNET_break(0);
700 LOG(GNUNET_ERROR_TYPE_DEBUG,
701 "Local data of %u total size had sub-message %u at %u with %u bytes\n",
702 ntohs(msg->header.size),
703 ntohs(pa.type),
704 (unsigned int)(buf - (const char *)&msg[1]),
705 (unsigned int)payload_claimed_size);
706 return GNUNET_SYSERR;
707 }
708 payload_size -= payload_claimed_size;
709 buf += payload_claimed_size;
710 }
711 if (0 != payload_size)
712 {
713 GNUNET_break_op(0);
714 return GNUNET_SYSERR; 713 return GNUNET_SYSERR;
715 } 714 }
715 payload_size -= payload_claimed_size;
716 buf += payload_claimed_size;
717 }
718 if (0 != payload_size)
719 {
720 GNUNET_break_op (0);
721 return GNUNET_SYSERR;
722 }
716 return GNUNET_OK; 723 return GNUNET_OK;
717} 724}
718 725
@@ -725,47 +732,47 @@ check_local_data(void *cls,
725 * @param msg the actual message 732 * @param msg the actual message
726 */ 733 */
727static void 734static void
728handle_local_data(void *cls, 735handle_local_data (void *cls,
729 const struct GNUNET_CADET_LocalData *msg) 736 const struct GNUNET_CADET_LocalData *msg)
730{ 737{
731 struct CadetClient *c = cls; 738 struct CadetClient *c = cls;
732 struct CadetChannel *ch; 739 struct CadetChannel *ch;
733 size_t payload_size; 740 size_t payload_size;
734 const char *buf; 741 const char *buf;
735 742
736 ch = lookup_channel(c, 743 ch = lookup_channel (c,
737 msg->ccn); 744 msg->ccn);
738 if (NULL == ch) 745 if (NULL == ch)
739 { 746 {
740 /* Channel does not exist (anymore) */ 747 /* Channel does not exist (anymore) */
741 LOG(GNUNET_ERROR_TYPE_WARNING, 748 LOG (GNUNET_ERROR_TYPE_WARNING,
742 "Dropping payload for channel %u from client (channel unknown, other endpoint may have disconnected)\n", 749 "Dropping payload for channel %u from client (channel unknown, other endpoint may have disconnected)\n",
743 (unsigned int)ntohl(msg->ccn.channel_of_client)); 750 (unsigned int) ntohl (msg->ccn.channel_of_client));
744 GNUNET_SERVICE_client_continue(c->client); 751 GNUNET_SERVICE_client_continue (c->client);
745 return; 752 return;
746 } 753 }
747 payload_size = ntohs(msg->header.size) - sizeof(*msg); 754 payload_size = ntohs (msg->header.size) - sizeof(*msg);
748 GNUNET_STATISTICS_update(stats, 755 GNUNET_STATISTICS_update (stats,
749 "# payload received from clients", 756 "# payload received from clients",
750 payload_size, 757 payload_size,
751 GNUNET_NO); 758 GNUNET_NO);
752 buf = (const char *)&msg[1]; 759 buf = (const char *) &msg[1];
753 LOG(GNUNET_ERROR_TYPE_DEBUG, 760 LOG (GNUNET_ERROR_TYPE_DEBUG,
754 "Received %u bytes payload from %s for %s\n", 761 "Received %u bytes payload from %s for %s\n",
755 (unsigned int)payload_size, 762 (unsigned int) payload_size,
756 GSC_2s(c), 763 GSC_2s (c),
757 GCCH_2s(ch)); 764 GCCH_2s (ch));
758 if (GNUNET_OK != 765 if (GNUNET_OK !=
759 GCCH_handle_local_data(ch, 766 GCCH_handle_local_data (ch,
760 msg->ccn, 767 msg->ccn,
761 buf, 768 buf,
762 payload_size)) 769 payload_size))
763 { 770 {
764 GNUNET_break(0); 771 GNUNET_break (0);
765 GNUNET_SERVICE_client_drop(c->client); 772 GNUNET_SERVICE_client_drop (c->client);
766 return; 773 return;
767 } 774 }
768 GNUNET_SERVICE_client_continue(c->client); 775 GNUNET_SERVICE_client_continue (c->client);
769} 776}
770 777
771 778
@@ -776,30 +783,30 @@ handle_local_data(void *cls,
776 * @param msg The actual message. 783 * @param msg The actual message.
777 */ 784 */
778static void 785static void
779handle_local_ack(void *cls, 786handle_local_ack (void *cls,
780 const struct GNUNET_CADET_LocalAck *msg) 787 const struct GNUNET_CADET_LocalAck *msg)
781{ 788{
782 struct CadetClient *c = cls; 789 struct CadetClient *c = cls;
783 struct CadetChannel *ch; 790 struct CadetChannel *ch;
784 791
785 ch = lookup_channel(c, 792 ch = lookup_channel (c,
786 msg->ccn); 793 msg->ccn);
787 if (NULL == ch) 794 if (NULL == ch)
788 { 795 {
789 /* Channel does not exist (anymore) */ 796 /* Channel does not exist (anymore) */
790 LOG(GNUNET_ERROR_TYPE_WARNING, 797 LOG (GNUNET_ERROR_TYPE_WARNING,
791 "Ignoring local ACK for channel %u from client (channel unknown, other endpoint may have disconnected)\n", 798 "Ignoring local ACK for channel %u from client (channel unknown, other endpoint may have disconnected)\n",
792 (unsigned int)ntohl(msg->ccn.channel_of_client)); 799 (unsigned int) ntohl (msg->ccn.channel_of_client));
793 GNUNET_SERVICE_client_continue(c->client); 800 GNUNET_SERVICE_client_continue (c->client);
794 return; 801 return;
795 } 802 }
796 LOG(GNUNET_ERROR_TYPE_DEBUG, 803 LOG (GNUNET_ERROR_TYPE_DEBUG,
797 "Got a local ACK from %s for %s\n", 804 "Got a local ACK from %s for %s\n",
798 GSC_2s(c), 805 GSC_2s (c),
799 GCCH_2s(ch)); 806 GCCH_2s (ch));
800 GCCH_handle_local_ack(ch, 807 GCCH_handle_local_ack (ch,
801 msg->ccn); 808 msg->ccn);
802 GNUNET_SERVICE_client_continue(c->client); 809 GNUNET_SERVICE_client_continue (c->client);
803} 810}
804 811
805 812
@@ -812,24 +819,24 @@ handle_local_ack(void *cls,
812 * @return #GNUNET_YES, to keep iterating. 819 * @return #GNUNET_YES, to keep iterating.
813 */ 820 */
814static int 821static int
815get_all_peers_iterator(void *cls, 822get_all_peers_iterator (void *cls,
816 const struct GNUNET_PeerIdentity *peer, 823 const struct GNUNET_PeerIdentity *peer,
817 void *value) 824 void *value)
818{ 825{
819 struct CadetClient *c = cls; 826 struct CadetClient *c = cls;
820 struct CadetPeer *p = value; 827 struct CadetPeer *p = value;
821 struct GNUNET_MQ_Envelope *env; 828 struct GNUNET_MQ_Envelope *env;
822 struct GNUNET_CADET_LocalInfoPeers *msg; 829 struct GNUNET_CADET_LocalInfoPeers *msg;
823 830
824 env = GNUNET_MQ_msg(msg, 831 env = GNUNET_MQ_msg (msg,
825 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); 832 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS);
826 msg->destination = *peer; 833 msg->destination = *peer;
827 msg->paths = htons(GCP_count_paths(p)); 834 msg->paths = htons (GCP_count_paths (p));
828 msg->tunnel = htons(NULL != GCP_get_tunnel(p, 835 msg->tunnel = htons (NULL != GCP_get_tunnel (p,
829 GNUNET_NO)); 836 GNUNET_NO));
830 msg->best_path_length = htonl(0); // FIXME: get length of shortest known path! 837 msg->best_path_length = htonl (0); // FIXME: get length of shortest known path!
831 GNUNET_MQ_send(c->mq, 838 GNUNET_MQ_send (c->mq,
832 env); 839 env);
833 return GNUNET_YES; 840 return GNUNET_YES;
834} 841}
835 842
@@ -841,20 +848,20 @@ get_all_peers_iterator(void *cls,
841 * @param message The actual message. 848 * @param message The actual message.
842 */ 849 */
843static void 850static void
844handle_get_peers(void *cls, 851handle_get_peers (void *cls,
845 const struct GNUNET_MessageHeader *message) 852 const struct GNUNET_MessageHeader *message)
846{ 853{
847 struct CadetClient *c = cls; 854 struct CadetClient *c = cls;
848 struct GNUNET_MQ_Envelope *env; 855 struct GNUNET_MQ_Envelope *env;
849 struct GNUNET_MessageHeader *reply; 856 struct GNUNET_MessageHeader *reply;
850 857
851 GCP_iterate_all(&get_all_peers_iterator, 858 GCP_iterate_all (&get_all_peers_iterator,
852 c); 859 c);
853 env = GNUNET_MQ_msg(reply, 860 env = GNUNET_MQ_msg (reply,
854 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END); 861 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END);
855 GNUNET_MQ_send(c->mq, 862 GNUNET_MQ_send (c->mq,
856 env); 863 env);
857 GNUNET_SERVICE_client_continue(c->client); 864 GNUNET_SERVICE_client_continue (c->client);
858} 865}
859 866
860 867
@@ -869,9 +876,9 @@ handle_get_peers(void *cls,
869 * #GNUNET_NO otherwise. 876 * #GNUNET_NO otherwise.
870 */ 877 */
871static int 878static int
872path_info_iterator(void *cls, 879path_info_iterator (void *cls,
873 struct CadetPeerPath *path, 880 struct CadetPeerPath *path,
874 unsigned int off) 881 unsigned int off)
875{ 882{
876 struct GNUNET_MQ_Handle *mq = cls; 883 struct GNUNET_MQ_Handle *mq = cls;
877 struct GNUNET_MQ_Envelope *env; 884 struct GNUNET_MQ_Envelope *env;
@@ -880,36 +887,37 @@ path_info_iterator(void *cls,
880 size_t path_size; 887 size_t path_size;
881 unsigned int path_length; 888 unsigned int path_length;
882 889
883 path_length = GCPP_get_length(path); 890 path_length = GCPP_get_length (path);
884 path_size = sizeof(struct GNUNET_PeerIdentity) * path_length; 891 path_size = sizeof(struct GNUNET_PeerIdentity) * path_length;
885 if (sizeof(*resp) + path_size > UINT16_MAX) 892 if (sizeof(*resp) + path_size > UINT16_MAX)
886 { 893 {
887 /* try just giving the relevant path */ 894 /* try just giving the relevant path */
888 path_length = GNUNET_MIN((UINT16_MAX - sizeof(*resp)) / sizeof(struct GNUNET_PeerIdentity), 895 path_length = GNUNET_MIN ((UINT16_MAX - sizeof(*resp)) / sizeof(struct
889 off); 896 GNUNET_PeerIdentity),
890 path_size = sizeof(struct GNUNET_PeerIdentity) * path_length; 897 off);
891 } 898 path_size = sizeof(struct GNUNET_PeerIdentity) * path_length;
899 }
892 if (sizeof(*resp) + path_size > UINT16_MAX) 900 if (sizeof(*resp) + path_size > UINT16_MAX)
893 { 901 {
894 LOG(GNUNET_ERROR_TYPE_WARNING, 902 LOG (GNUNET_ERROR_TYPE_WARNING,
895 "Path of %u entries is too long for info message\n", 903 "Path of %u entries is too long for info message\n",
896 path_length); 904 path_length);
897 return GNUNET_YES; 905 return GNUNET_YES;
898 } 906 }
899 env = GNUNET_MQ_msg_extra(resp, 907 env = GNUNET_MQ_msg_extra (resp,
900 path_size, 908 path_size,
901 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH); 909 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH);
902 id = (struct GNUNET_PeerIdentity *)&resp[1]; 910 id = (struct GNUNET_PeerIdentity *) &resp[1];
903 911
904 /* Don't copy first peer. First peer is always the local one. Last 912 /* Don't copy first peer. First peer is always the local one. Last
905 * peer is always the destination (leave as 0, EOL). 913 * peer is always the destination (leave as 0, EOL).
906 */ 914 */
907 for (unsigned int i = 0; i < path_length; i++) 915 for (unsigned int i = 0; i < path_length; i++)
908 id[i] = *GCP_get_id(GCPP_get_peer_at_offset(path, 916 id[i] = *GCP_get_id (GCPP_get_peer_at_offset (path,
909 i)); 917 i));
910 resp->off = htonl(off); 918 resp->off = htonl (off);
911 GNUNET_MQ_send(mq, 919 GNUNET_MQ_send (mq,
912 env); 920 env);
913 return GNUNET_YES; 921 return GNUNET_YES;
914} 922}
915 923
@@ -921,25 +929,25 @@ path_info_iterator(void *cls,
921 * @param msg The actual message. 929 * @param msg The actual message.
922 */ 930 */
923static void 931static void
924handle_show_path(void *cls, 932handle_show_path (void *cls,
925 const struct GNUNET_CADET_RequestPathInfoMessage *msg) 933 const struct GNUNET_CADET_RequestPathInfoMessage *msg)
926{ 934{
927 struct CadetClient *c = cls; 935 struct CadetClient *c = cls;
928 struct CadetPeer *p; 936 struct CadetPeer *p;
929 struct GNUNET_MQ_Envelope *env; 937 struct GNUNET_MQ_Envelope *env;
930 struct GNUNET_MessageHeader *resp; 938 struct GNUNET_MessageHeader *resp;
931 939
932 p = GCP_get(&msg->peer, 940 p = GCP_get (&msg->peer,
933 GNUNET_NO); 941 GNUNET_NO);
934 if (NULL != p) 942 if (NULL != p)
935 GCP_iterate_indirect_paths(p, 943 GCP_iterate_indirect_paths (p,
936 &path_info_iterator, 944 &path_info_iterator,
937 c->mq); 945 c->mq);
938 env = GNUNET_MQ_msg(resp, 946 env = GNUNET_MQ_msg (resp,
939 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END); 947 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END);
940 GNUNET_MQ_send(c->mq, 948 GNUNET_MQ_send (c->mq,
941 env); 949 env);
942 GNUNET_SERVICE_client_continue(c->client); 950 GNUNET_SERVICE_client_continue (c->client);
943} 951}
944 952
945 953
@@ -952,9 +960,9 @@ handle_show_path(void *cls,
952 * @return #GNUNET_YES, to keep iterating. 960 * @return #GNUNET_YES, to keep iterating.
953 */ 961 */
954static int 962static int
955get_all_tunnels_iterator(void *cls, 963get_all_tunnels_iterator (void *cls,
956 const struct GNUNET_PeerIdentity *peer, 964 const struct GNUNET_PeerIdentity *peer,
957 void *value) 965 void *value)
958{ 966{
959 struct CadetClient *c = cls; 967 struct CadetClient *c = cls;
960 struct CadetPeer *p = value; 968 struct CadetPeer *p = value;
@@ -962,19 +970,19 @@ get_all_tunnels_iterator(void *cls,
962 struct GNUNET_CADET_LocalInfoTunnel *msg; 970 struct GNUNET_CADET_LocalInfoTunnel *msg;
963 struct CadetTunnel *t; 971 struct CadetTunnel *t;
964 972
965 t = GCP_get_tunnel(p, 973 t = GCP_get_tunnel (p,
966 GNUNET_NO); 974 GNUNET_NO);
967 if (NULL == t) 975 if (NULL == t)
968 return GNUNET_YES; 976 return GNUNET_YES;
969 env = GNUNET_MQ_msg(msg, 977 env = GNUNET_MQ_msg (msg,
970 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS); 978 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS);
971 msg->destination = *peer; 979 msg->destination = *peer;
972 msg->channels = htonl(GCT_count_channels(t)); 980 msg->channels = htonl (GCT_count_channels (t));
973 msg->connections = htonl(GCT_count_any_connections(t)); 981 msg->connections = htonl (GCT_count_any_connections (t));
974 msg->cstate = htons(0); 982 msg->cstate = htons (0);
975 msg->estate = htons((uint16_t)GCT_get_estate(t)); 983 msg->estate = htons ((uint16_t) GCT_get_estate (t));
976 GNUNET_MQ_send(c->mq, 984 GNUNET_MQ_send (c->mq,
977 env); 985 env);
978 return GNUNET_YES; 986 return GNUNET_YES;
979} 987}
980 988
@@ -986,20 +994,20 @@ get_all_tunnels_iterator(void *cls,
986 * @param message The actual message. 994 * @param message The actual message.
987 */ 995 */
988static void 996static void
989handle_info_tunnels(void *cls, 997handle_info_tunnels (void *cls,
990 const struct GNUNET_MessageHeader *message) 998 const struct GNUNET_MessageHeader *message)
991{ 999{
992 struct CadetClient *c = cls; 1000 struct CadetClient *c = cls;
993 struct GNUNET_MQ_Envelope *env; 1001 struct GNUNET_MQ_Envelope *env;
994 struct GNUNET_MessageHeader *reply; 1002 struct GNUNET_MessageHeader *reply;
995 1003
996 GCP_iterate_all(&get_all_tunnels_iterator, 1004 GCP_iterate_all (&get_all_tunnels_iterator,
997 c); 1005 c);
998 env = GNUNET_MQ_msg(reply, 1006 env = GNUNET_MQ_msg (reply,
999 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END); 1007 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END);
1000 GNUNET_MQ_send(c->mq, 1008 GNUNET_MQ_send (c->mq,
1001 env); 1009 env);
1002 GNUNET_SERVICE_client_continue(c->client); 1010 GNUNET_SERVICE_client_continue (c->client);
1003} 1011}
1004 1012
1005 1013
@@ -1012,28 +1020,28 @@ handle_info_tunnels(void *cls,
1012 * @return @a c 1020 * @return @a c
1013 */ 1021 */
1014static void * 1022static void *
1015client_connect_cb(void *cls, 1023client_connect_cb (void *cls,
1016 struct GNUNET_SERVICE_Client *client, 1024 struct GNUNET_SERVICE_Client *client,
1017 struct GNUNET_MQ_Handle *mq) 1025 struct GNUNET_MQ_Handle *mq)
1018{ 1026{
1019 struct CadetClient *c; 1027 struct CadetClient *c;
1020 1028
1021 c = GNUNET_new(struct CadetClient); 1029 c = GNUNET_new (struct CadetClient);
1022 c->client = client; 1030 c->client = client;
1023 c->mq = mq; 1031 c->mq = mq;
1024 c->id = next_client_id++; /* overflow not important: just for debug */ 1032 c->id = next_client_id++; /* overflow not important: just for debug */
1025 c->channels 1033 c->channels
1026 = GNUNET_CONTAINER_multihashmap32_create(32); 1034 = GNUNET_CONTAINER_multihashmap32_create (32);
1027 GNUNET_CONTAINER_DLL_insert(clients_head, 1035 GNUNET_CONTAINER_DLL_insert (clients_head,
1028 clients_tail, 1036 clients_tail,
1029 c); 1037 c);
1030 GNUNET_STATISTICS_update(stats, 1038 GNUNET_STATISTICS_update (stats,
1031 "# clients", 1039 "# clients",
1032 +1, 1040 +1,
1033 GNUNET_NO); 1041 GNUNET_NO);
1034 LOG(GNUNET_ERROR_TYPE_DEBUG, 1042 LOG (GNUNET_ERROR_TYPE_DEBUG,
1035 "%s connected\n", 1043 "%s connected\n",
1036 GSC_2s(c)); 1044 GSC_2s (c));
1037 return c; 1045 return c;
1038} 1046}
1039 1047
@@ -1046,22 +1054,23 @@ client_connect_cb(void *cls,
1046 * @param ch the channel object 1054 * @param ch the channel object
1047 */ 1055 */
1048void 1056void
1049GSC_handle_remote_channel_destroy(struct CadetClient *c, 1057GSC_handle_remote_channel_destroy (struct CadetClient *c,
1050 struct GNUNET_CADET_ClientChannelNumber ccn, 1058 struct GNUNET_CADET_ClientChannelNumber ccn,
1051 struct CadetChannel *ch) 1059 struct CadetChannel *ch)
1052{ 1060{
1053 struct GNUNET_MQ_Envelope *env; 1061 struct GNUNET_MQ_Envelope *env;
1054 struct GNUNET_CADET_LocalChannelDestroyMessage *tdm; 1062 struct GNUNET_CADET_LocalChannelDestroyMessage *tdm;
1055 1063
1056 env = GNUNET_MQ_msg(tdm, 1064 env = GNUNET_MQ_msg (tdm,
1057 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); 1065 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
1058 tdm->ccn = ccn; 1066 tdm->ccn = ccn;
1059 GSC_send_to_client(c, 1067 GSC_send_to_client (c,
1060 env); 1068 env);
1061 GNUNET_assert(GNUNET_YES == 1069 GNUNET_assert (GNUNET_YES ==
1062 GNUNET_CONTAINER_multihashmap32_remove(c->channels, 1070 GNUNET_CONTAINER_multihashmap32_remove (c->channels,
1063 ntohl(ccn.channel_of_client), 1071 ntohl (
1064 ch)); 1072 ccn.channel_of_client),
1073 ch));
1065} 1074}
1066 1075
1067 1076
@@ -1073,13 +1082,13 @@ GSC_handle_remote_channel_destroy(struct CadetClient *c,
1073 * @param ch the channel that was lost 1082 * @param ch the channel that was lost
1074 */ 1083 */
1075void 1084void
1076GSC_drop_loose_channel(const struct GNUNET_HashCode *h_port, 1085GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port,
1077 struct CadetChannel *ch) 1086 struct CadetChannel *ch)
1078{ 1087{
1079 GNUNET_assert(GNUNET_YES == 1088 GNUNET_assert (GNUNET_YES ==
1080 GNUNET_CONTAINER_multihashmap_remove(loose_channels, 1089 GNUNET_CONTAINER_multihashmap_remove (loose_channels,
1081 h_port, 1090 h_port,
1082 ch)); 1091 ch));
1083} 1092}
1084 1093
1085 1094
@@ -1092,26 +1101,26 @@ GSC_drop_loose_channel(const struct GNUNET_HashCode *h_port,
1092 * @return #GNUNET_OK, keep iterating. 1101 * @return #GNUNET_OK, keep iterating.
1093 */ 1102 */
1094static int 1103static int
1095channel_destroy_iterator(void *cls, 1104channel_destroy_iterator (void *cls,
1096 uint32_t key, 1105 uint32_t key,
1097 void *value) 1106 void *value)
1098{ 1107{
1099 struct CadetClient *c = cls; 1108 struct CadetClient *c = cls;
1100 struct GNUNET_CADET_ClientChannelNumber ccn; 1109 struct GNUNET_CADET_ClientChannelNumber ccn;
1101 struct CadetChannel *ch = value; 1110 struct CadetChannel *ch = value;
1102 1111
1103 LOG(GNUNET_ERROR_TYPE_DEBUG, 1112 LOG (GNUNET_ERROR_TYPE_DEBUG,
1104 "Destroying %s, due to %s disconnecting.\n", 1113 "Destroying %s, due to %s disconnecting.\n",
1105 GCCH_2s(ch), 1114 GCCH_2s (ch),
1106 GSC_2s(c)); 1115 GSC_2s (c));
1107 ccn.channel_of_client = htonl(key); 1116 ccn.channel_of_client = htonl (key);
1108 GCCH_channel_local_destroy(ch, 1117 GCCH_channel_local_destroy (ch,
1109 c, 1118 c,
1110 ccn); 1119 ccn);
1111 GNUNET_assert(GNUNET_YES == 1120 GNUNET_assert (GNUNET_YES ==
1112 GNUNET_CONTAINER_multihashmap32_remove(c->channels, 1121 GNUNET_CONTAINER_multihashmap32_remove (c->channels,
1113 key, 1122 key,
1114 ch)); 1123 ch));
1115 return GNUNET_OK; 1124 return GNUNET_OK;
1116} 1125}
1117 1126
@@ -1125,27 +1134,27 @@ channel_destroy_iterator(void *cls,
1125 * @return #GNUNET_OK, keep iterating. 1134 * @return #GNUNET_OK, keep iterating.
1126 */ 1135 */
1127static int 1136static int
1128client_release_ports(void *cls, 1137client_release_ports (void *cls,
1129 const struct GNUNET_HashCode *port, 1138 const struct GNUNET_HashCode *port,
1130 void *value) 1139 void *value)
1131{ 1140{
1132 struct CadetClient *c = cls; 1141 struct CadetClient *c = cls;
1133 struct OpenPort *op = value; 1142 struct OpenPort *op = value;
1134 1143
1135 GNUNET_assert(c == op->c); 1144 GNUNET_assert (c == op->c);
1136 LOG(GNUNET_ERROR_TYPE_DEBUG, 1145 LOG (GNUNET_ERROR_TYPE_DEBUG,
1137 "Closing port %s due to %s disconnect.\n", 1146 "Closing port %s due to %s disconnect.\n",
1138 GNUNET_h2s(port), 1147 GNUNET_h2s (port),
1139 GSC_2s(c)); 1148 GSC_2s (c));
1140 GNUNET_assert(GNUNET_YES == 1149 GNUNET_assert (GNUNET_YES ==
1141 GNUNET_CONTAINER_multihashmap_remove(open_ports, 1150 GNUNET_CONTAINER_multihashmap_remove (open_ports,
1142 &op->h_port, 1151 &op->h_port,
1143 op)); 1152 op));
1144 GNUNET_assert(GNUNET_YES == 1153 GNUNET_assert (GNUNET_YES ==
1145 GNUNET_CONTAINER_multihashmap_remove(c->ports, 1154 GNUNET_CONTAINER_multihashmap_remove (c->ports,
1146 port, 1155 port,
1147 op)); 1156 op));
1148 GNUNET_free(op); 1157 GNUNET_free (op);
1149 return GNUNET_OK; 1158 return GNUNET_OK;
1150} 1159}
1151 1160
@@ -1158,42 +1167,42 @@ client_release_ports(void *cls,
1158 * @param internal_cls should be equal to @a c 1167 * @param internal_cls should be equal to @a c
1159 */ 1168 */
1160static void 1169static void
1161client_disconnect_cb(void *cls, 1170client_disconnect_cb (void *cls,
1162 struct GNUNET_SERVICE_Client *client, 1171 struct GNUNET_SERVICE_Client *client,
1163 void *internal_cls) 1172 void *internal_cls)
1164{ 1173{
1165 struct CadetClient *c = internal_cls; 1174 struct CadetClient *c = internal_cls;
1166 1175
1167 GNUNET_assert(c->client == client); 1176 GNUNET_assert (c->client == client);
1168 LOG(GNUNET_ERROR_TYPE_DEBUG, 1177 LOG (GNUNET_ERROR_TYPE_DEBUG,
1169 "%s is disconnecting.\n", 1178 "%s is disconnecting.\n",
1170 GSC_2s(c)); 1179 GSC_2s (c));
1171 if (NULL != c->channels) 1180 if (NULL != c->channels)
1172 { 1181 {
1173 GNUNET_CONTAINER_multihashmap32_iterate(c->channels, 1182 GNUNET_CONTAINER_multihashmap32_iterate (c->channels,
1174 &channel_destroy_iterator, 1183 &channel_destroy_iterator,
1175 c); 1184 c);
1176 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(c->channels)); 1185 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (c->channels));
1177 GNUNET_CONTAINER_multihashmap32_destroy(c->channels); 1186 GNUNET_CONTAINER_multihashmap32_destroy (c->channels);
1178 } 1187 }
1179 if (NULL != c->ports) 1188 if (NULL != c->ports)
1180 { 1189 {
1181 GNUNET_CONTAINER_multihashmap_iterate(c->ports, 1190 GNUNET_CONTAINER_multihashmap_iterate (c->ports,
1182 &client_release_ports, 1191 &client_release_ports,
1183 c); 1192 c);
1184 GNUNET_CONTAINER_multihashmap_destroy(c->ports); 1193 GNUNET_CONTAINER_multihashmap_destroy (c->ports);
1185 } 1194 }
1186 GNUNET_CONTAINER_DLL_remove(clients_head, 1195 GNUNET_CONTAINER_DLL_remove (clients_head,
1187 clients_tail, 1196 clients_tail,
1188 c); 1197 c);
1189 GNUNET_STATISTICS_update(stats, 1198 GNUNET_STATISTICS_update (stats,
1190 "# clients", 1199 "# clients",
1191 -1, 1200 -1,
1192 GNUNET_NO); 1201 GNUNET_NO);
1193 GNUNET_free(c); 1202 GNUNET_free (c);
1194 if ((NULL == clients_head) && 1203 if ((NULL == clients_head) &&
1195 (GNUNET_YES == shutting_down)) 1204 (GNUNET_YES == shutting_down))
1196 shutdown_rest(); 1205 shutdown_rest ();
1197} 1206}
1198 1207
1199 1208
@@ -1205,92 +1214,92 @@ client_disconnect_cb(void *cls,
1205 * @param c configuration to use 1214 * @param c configuration to use
1206 */ 1215 */
1207static void 1216static void
1208run(void *cls, 1217run (void *cls,
1209 const struct GNUNET_CONFIGURATION_Handle *c, 1218 const struct GNUNET_CONFIGURATION_Handle *c,
1210 struct GNUNET_SERVICE_Handle *service) 1219 struct GNUNET_SERVICE_Handle *service)
1211{ 1220{
1212 cfg = c; 1221 cfg = c;
1213 if (GNUNET_OK != 1222 if (GNUNET_OK !=
1214 GNUNET_CONFIGURATION_get_value_number(c, 1223 GNUNET_CONFIGURATION_get_value_number (c,
1215 "CADET", 1224 "CADET",
1216 "RATCHET_MESSAGES", 1225 "RATCHET_MESSAGES",
1217 &ratchet_messages)) 1226 &ratchet_messages))
1218 { 1227 {
1219 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, 1228 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
1220 "CADET", 1229 "CADET",
1221 "RATCHET_MESSAGES", 1230 "RATCHET_MESSAGES",
1222 "needs to be a number"); 1231 "needs to be a number");
1223 ratchet_messages = 64; 1232 ratchet_messages = 64;
1224 } 1233 }
1225 if (GNUNET_OK != 1234 if (GNUNET_OK !=
1226 GNUNET_CONFIGURATION_get_value_time(c, 1235 GNUNET_CONFIGURATION_get_value_time (c,
1227 "CADET", 1236 "CADET",
1228 "RATCHET_TIME", 1237 "RATCHET_TIME",
1229 &ratchet_time)) 1238 &ratchet_time))
1230 { 1239 {
1231 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, 1240 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
1232 "CADET", 1241 "CADET",
1233 "RATCHET_TIME", 1242 "RATCHET_TIME",
1234 "need delay value"); 1243 "need delay value");
1235 ratchet_time = GNUNET_TIME_UNIT_HOURS; 1244 ratchet_time = GNUNET_TIME_UNIT_HOURS;
1236 } 1245 }
1237 if (GNUNET_OK != 1246 if (GNUNET_OK !=
1238 GNUNET_CONFIGURATION_get_value_time(c, 1247 GNUNET_CONFIGURATION_get_value_time (c,
1239 "CADET", 1248 "CADET",
1240 "REFRESH_CONNECTION_TIME", 1249 "REFRESH_CONNECTION_TIME",
1241 &keepalive_period)) 1250 &keepalive_period))
1242 { 1251 {
1243 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, 1252 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
1244 "CADET", 1253 "CADET",
1245 "REFRESH_CONNECTION_TIME", 1254 "REFRESH_CONNECTION_TIME",
1246 "need delay value"); 1255 "need delay value");
1247 keepalive_period = GNUNET_TIME_UNIT_MINUTES; 1256 keepalive_period = GNUNET_TIME_UNIT_MINUTES;
1248 } 1257 }
1249 if (GNUNET_OK != 1258 if (GNUNET_OK !=
1250 GNUNET_CONFIGURATION_get_value_number(c, 1259 GNUNET_CONFIGURATION_get_value_number (c,
1251 "CADET", 1260 "CADET",
1252 "DROP_PERCENT", 1261 "DROP_PERCENT",
1253 &drop_percent)) 1262 &drop_percent))
1254 { 1263 {
1255 drop_percent = 0; 1264 drop_percent = 0;
1256 } 1265 }
1257 else 1266 else
1258 { 1267 {
1259 LOG(GNUNET_ERROR_TYPE_WARNING, "**************************************\n"); 1268 LOG (GNUNET_ERROR_TYPE_WARNING, "**************************************\n");
1260 LOG(GNUNET_ERROR_TYPE_WARNING, "Cadet is running with DROP enabled.\n"); 1269 LOG (GNUNET_ERROR_TYPE_WARNING, "Cadet is running with DROP enabled.\n");
1261 LOG(GNUNET_ERROR_TYPE_WARNING, "This is NOT a good idea!\n"); 1270 LOG (GNUNET_ERROR_TYPE_WARNING, "This is NOT a good idea!\n");
1262 LOG(GNUNET_ERROR_TYPE_WARNING, "Remove DROP_PERCENT from config file.\n"); 1271 LOG (GNUNET_ERROR_TYPE_WARNING, "Remove DROP_PERCENT from config file.\n");
1263 LOG(GNUNET_ERROR_TYPE_WARNING, "**************************************\n"); 1272 LOG (GNUNET_ERROR_TYPE_WARNING, "**************************************\n");
1264 } 1273 }
1265 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(c); 1274 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c);
1266 if (NULL == my_private_key) 1275 if (NULL == my_private_key)
1267 { 1276 {
1268 GNUNET_break(0); 1277 GNUNET_break (0);
1269 GNUNET_SCHEDULER_shutdown(); 1278 GNUNET_SCHEDULER_shutdown ();
1270 return; 1279 return;
1271 } 1280 }
1272 GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, 1281 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
1273 &my_full_id.public_key); 1282 &my_full_id.public_key);
1274 stats = GNUNET_STATISTICS_create("cadet", 1283 stats = GNUNET_STATISTICS_create ("cadet",
1275 c); 1284 c);
1276 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, 1285 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1277 NULL); 1286 NULL);
1278 ats_ch = GNUNET_ATS_connectivity_init(c); 1287 ats_ch = GNUNET_ATS_connectivity_init (c);
1279 /* FIXME: optimize code to allow GNUNET_YES here! */ 1288 /* FIXME: optimize code to allow GNUNET_YES here! */
1280 open_ports = GNUNET_CONTAINER_multihashmap_create(16, 1289 open_ports = GNUNET_CONTAINER_multihashmap_create (16,
1281 GNUNET_NO); 1290 GNUNET_NO);
1282 loose_channels = GNUNET_CONTAINER_multihashmap_create(16, 1291 loose_channels = GNUNET_CONTAINER_multihashmap_create (16,
1283 GNUNET_NO); 1292 GNUNET_NO);
1284 peers = GNUNET_CONTAINER_multipeermap_create(16, 1293 peers = GNUNET_CONTAINER_multipeermap_create (16,
1285 GNUNET_YES); 1294 GNUNET_YES);
1286 connections = GNUNET_CONTAINER_multishortmap_create(256, 1295 connections = GNUNET_CONTAINER_multishortmap_create (256,
1287 GNUNET_YES); 1296 GNUNET_YES);
1288 GCH_init(c); 1297 GCH_init (c);
1289 GCD_init(c); 1298 GCD_init (c);
1290 GCO_init(c); 1299 GCO_init (c);
1291 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1300 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1292 "CADET started for peer %s\n", 1301 "CADET started for peer %s\n",
1293 GNUNET_i2s(&my_full_id)); 1302 GNUNET_i2s (&my_full_id));
1294} 1303}
1295 1304
1296 1305
@@ -1304,42 +1313,42 @@ GNUNET_SERVICE_MAIN
1304 &client_connect_cb, 1313 &client_connect_cb,
1305 &client_disconnect_cb, 1314 &client_disconnect_cb,
1306 NULL, 1315 NULL,
1307 GNUNET_MQ_hd_fixed_size(port_open, 1316 GNUNET_MQ_hd_fixed_size (port_open,
1308 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN, 1317 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN,
1309 struct GNUNET_CADET_PortMessage, 1318 struct GNUNET_CADET_PortMessage,
1310 NULL), 1319 NULL),
1311 GNUNET_MQ_hd_fixed_size(port_close, 1320 GNUNET_MQ_hd_fixed_size (port_close,
1312 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE, 1321 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE,
1313 struct GNUNET_CADET_PortMessage, 1322 struct GNUNET_CADET_PortMessage,
1314 NULL), 1323 NULL),
1315 GNUNET_MQ_hd_fixed_size(channel_create, 1324 GNUNET_MQ_hd_fixed_size (channel_create,
1316 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, 1325 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE,
1317 struct GNUNET_CADET_LocalChannelCreateMessage, 1326 struct GNUNET_CADET_LocalChannelCreateMessage,
1318 NULL), 1327 NULL),
1319 GNUNET_MQ_hd_fixed_size(channel_destroy, 1328 GNUNET_MQ_hd_fixed_size (channel_destroy,
1320 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, 1329 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY,
1321 struct GNUNET_CADET_LocalChannelDestroyMessage, 1330 struct GNUNET_CADET_LocalChannelDestroyMessage,
1322 NULL), 1331 NULL),
1323 GNUNET_MQ_hd_var_size(local_data, 1332 GNUNET_MQ_hd_var_size (local_data,
1324 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, 1333 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
1325 struct GNUNET_CADET_LocalData, 1334 struct GNUNET_CADET_LocalData,
1326 NULL), 1335 NULL),
1327 GNUNET_MQ_hd_fixed_size(local_ack, 1336 GNUNET_MQ_hd_fixed_size (local_ack,
1328 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, 1337 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK,
1329 struct GNUNET_CADET_LocalAck, 1338 struct GNUNET_CADET_LocalAck,
1330 NULL), 1339 NULL),
1331 GNUNET_MQ_hd_fixed_size(get_peers, 1340 GNUNET_MQ_hd_fixed_size (get_peers,
1332 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS, 1341 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS,
1333 struct GNUNET_MessageHeader, 1342 struct GNUNET_MessageHeader,
1334 NULL), 1343 NULL),
1335 GNUNET_MQ_hd_fixed_size(show_path, 1344 GNUNET_MQ_hd_fixed_size (show_path,
1336 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH, 1345 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH,
1337 struct GNUNET_CADET_RequestPathInfoMessage, 1346 struct GNUNET_CADET_RequestPathInfoMessage,
1338 NULL), 1347 NULL),
1339 GNUNET_MQ_hd_fixed_size(info_tunnels, 1348 GNUNET_MQ_hd_fixed_size (info_tunnels,
1340 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS, 1349 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS,
1341 struct GNUNET_MessageHeader, 1350 struct GNUNET_MessageHeader,
1342 NULL), 1351 NULL),
1343 GNUNET_MQ_handler_end()); 1352 GNUNET_MQ_handler_end ());
1344 1353
1345/* end of gnunet-service-cadet-new.c */ 1354/* end of gnunet-service-cadet-new.c */
diff --git a/src/cadet/gnunet-service-cadet.h b/src/cadet/gnunet-service-cadet.h
index 8decdba0d..6da0950f1 100644
--- a/src/cadet/gnunet-service-cadet.h
+++ b/src/cadet/gnunet-service-cadet.h
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of GNUnet. 2 This file is part of GNUnet.
4 Copyright (C) 2001-2017 GNUnet e.V. 3 Copyright (C) 2001-2017 GNUnet e.V.
@@ -64,7 +63,8 @@ struct CadetPeerPath;
64/** 63/**
65 * Entry in a peer path. 64 * Entry in a peer path.
66 */ 65 */
67struct CadetPeerPathEntry { 66struct CadetPeerPathEntry
67{
68 /** 68 /**
69 * DLL of paths where the same @e peer is at the same offset. 69 * DLL of paths where the same @e peer is at the same offset.
70 */ 70 */
@@ -103,7 +103,8 @@ struct CadetPeerPathEntry {
103/** 103/**
104 * Entry in list of connections used by tunnel, with metadata. 104 * Entry in list of connections used by tunnel, with metadata.
105 */ 105 */
106struct CadetTConnection { 106struct CadetTConnection
107{
107 /** 108 /**
108 * Next in DLL. 109 * Next in DLL.
109 */ 110 */
@@ -144,7 +145,8 @@ struct CadetTConnection {
144/** 145/**
145 * Port opened by a client. 146 * Port opened by a client.
146 */ 147 */
147struct OpenPort { 148struct OpenPort
149{
148 /** 150 /**
149 * Client that opened the port. 151 * Client that opened the port.
150 */ 152 */
@@ -266,8 +268,8 @@ extern unsigned long long drop_percent;
266 * @param env envelope with the message 268 * @param env envelope with the message
267 */ 269 */
268void 270void
269GSC_send_to_client(struct CadetClient *c, 271GSC_send_to_client (struct CadetClient *c,
270 struct GNUNET_MQ_Envelope *env); 272 struct GNUNET_MQ_Envelope *env);
271 273
272 274
273/** 275/**
@@ -278,9 +280,9 @@ GSC_send_to_client(struct CadetClient *c,
278 * @param ch the channel object 280 * @param ch the channel object
279 */ 281 */
280void 282void
281GSC_handle_remote_channel_destroy(struct CadetClient *c, 283GSC_handle_remote_channel_destroy (struct CadetClient *c,
282 struct GNUNET_CADET_ClientChannelNumber ccn, 284 struct GNUNET_CADET_ClientChannelNumber ccn,
283 struct CadetChannel *ch); 285 struct CadetChannel *ch);
284 286
285/** 287/**
286 * A client that created a loose channel that was not bound to a port 288 * A client that created a loose channel that was not bound to a port
@@ -290,8 +292,8 @@ GSC_handle_remote_channel_destroy(struct CadetClient *c,
290 * @param ch the channel that was lost 292 * @param ch the channel that was lost
291 */ 293 */
292void 294void
293GSC_drop_loose_channel(const struct GNUNET_HashCode *h_port, 295GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port,
294 struct CadetChannel *ch); 296 struct CadetChannel *ch);
295 297
296 298
297/** 299/**
@@ -306,11 +308,11 @@ GSC_drop_loose_channel(const struct GNUNET_HashCode *h_port,
306 * @return local channel number assigned to the new client 308 * @return local channel number assigned to the new client
307 */ 309 */
308struct GNUNET_CADET_ClientChannelNumber 310struct GNUNET_CADET_ClientChannelNumber
309GSC_bind(struct CadetClient *c, 311GSC_bind (struct CadetClient *c,
310 struct CadetChannel *ch, 312 struct CadetChannel *ch,
311 struct CadetPeer *dest, 313 struct CadetPeer *dest,
312 const struct GNUNET_HashCode *port, 314 const struct GNUNET_HashCode *port,
313 uint32_t options); 315 uint32_t options);
314 316
315 317
316/** 318/**
@@ -320,7 +322,7 @@ GSC_bind(struct CadetClient *c,
320 * @return string for debugging 322 * @return string for debugging
321 */ 323 */
322const char * 324const char *
323GSC_2s(struct CadetClient *c); 325GSC_2s (struct CadetClient *c);
324 326
325 327
326#endif 328#endif
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index dad5325fc..0a261039c 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -41,26 +41,26 @@
41#include "gnunet-service-cadet_tunnels.h" 41#include "gnunet-service-cadet_tunnels.h"
42#include "gnunet-service-cadet_paths.h" 42#include "gnunet-service-cadet_paths.h"
43 43
44#define LOG(level, ...) GNUNET_log_from(level, "cadet-chn", __VA_ARGS__) 44#define LOG(level, ...) GNUNET_log_from (level, "cadet-chn", __VA_ARGS__)
45 45
46/** 46/**
47 * How long do we initially wait before retransmitting? 47 * How long do we initially wait before retransmitting?
48 */ 48 */
49#define CADET_INITIAL_RETRANSMIT_TIME \ 49#define CADET_INITIAL_RETRANSMIT_TIME \
50 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) 50 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
51 51
52/** 52/**
53 * How long do we wait before dropping state about incoming 53 * How long do we wait before dropping state about incoming
54 * connection to closed port? 54 * connection to closed port?
55 */ 55 */
56#define TIMEOUT_CLOSED_PORT \ 56#define TIMEOUT_CLOSED_PORT \
57 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 57 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
58 58
59/** 59/**
60 * How long do we wait at least before retransmitting ever? 60 * How long do we wait at least before retransmitting ever?
61 */ 61 */
62#define MIN_RTT_DELAY \ 62#define MIN_RTT_DELAY \
63 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 75) 63 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 75)
64 64
65/** 65/**
66 * Maximum message ID into the future we accept for out-of-order messages. 66 * Maximum message ID into the future we accept for out-of-order messages.
@@ -78,7 +78,8 @@
78/** 78/**
79 * All the states a channel can be in. 79 * All the states a channel can be in.
80 */ 80 */
81enum CadetChannelState { 81enum CadetChannelState
82{
82 /** 83 /**
83 * Uninitialized status, should never appear in operation. 84 * Uninitialized status, should never appear in operation.
84 */ 85 */
@@ -107,7 +108,8 @@ enum CadetChannelState {
107 * Note that we DO use this structure also for unreliable 108 * Note that we DO use this structure also for unreliable
108 * messages. 109 * messages.
109 */ 110 */
110struct CadetReliableMessage { 111struct CadetReliableMessage
112{
111 /** 113 /**
112 * Double linked list, FIFO style 114 * Double linked list, FIFO style
113 */ 115 */
@@ -171,7 +173,8 @@ struct CadetReliableMessage {
171/** 173/**
172 * List of received out-of-order data messages. 174 * List of received out-of-order data messages.
173 */ 175 */
174struct CadetOutOfOrderMessage { 176struct CadetOutOfOrderMessage
177{
175 /** 178 /**
176 * Double linked list, FIFO style 179 * Double linked list, FIFO style
177 */ 180 */
@@ -200,7 +203,8 @@ struct CadetOutOfOrderMessage {
200 * loopback channel, in which case it has two of these endpoints. 203 * loopback channel, in which case it has two of these endpoints.
201 * Note that flow control also is required in both directions. 204 * Note that flow control also is required in both directions.
202 */ 205 */
203struct CadetChannelClient { 206struct CadetChannelClient
207{
204 /** 208 /**
205 * Client handle. Not by itself sufficient to designate 209 * Client handle. Not by itself sufficient to designate
206 * the client endpoint, as the same client handle may 210 * the client endpoint, as the same client handle may
@@ -241,7 +245,8 @@ struct CadetChannelClient {
241/** 245/**
242 * Struct containing all information regarding a channel to a remote client. 246 * Struct containing all information regarding a channel to a remote client.
243 */ 247 */
244struct CadetChannel { 248struct CadetChannel
249{
245 /** 250 /**
246 * Tunnel this channel is in. 251 * Tunnel this channel is in.
247 */ 252 */
@@ -386,24 +391,24 @@ struct CadetChannel {
386 * @return Static string with the channel IDs. 391 * @return Static string with the channel IDs.
387 */ 392 */
388const char * 393const char *
389GCCH_2s(const struct CadetChannel *ch) 394GCCH_2s (const struct CadetChannel *ch)
390{ 395{
391 static char buf[128]; 396 static char buf[128];
392 397
393 GNUNET_snprintf(buf, 398 GNUNET_snprintf (buf,
394 sizeof(buf), 399 sizeof(buf),
395 "Channel %s:%s ctn:%X(%X/%X)", 400 "Channel %s:%s ctn:%X(%X/%X)",
396 (GNUNET_YES == ch->is_loopback) 401 (GNUNET_YES == ch->is_loopback)
397 ? "loopback" 402 ? "loopback"
398 : GNUNET_i2s(GCP_get_id(GCT_get_destination(ch->t))), 403 : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))),
399 GNUNET_h2s(&ch->port), 404 GNUNET_h2s (&ch->port),
400 ch->ctn, 405 ch->ctn,
401 (NULL == ch->owner) 406 (NULL == ch->owner)
402 ? 0 407 ? 0
403 : ntohl(ch->owner->ccn.channel_of_client), 408 : ntohl (ch->owner->ccn.channel_of_client),
404 (NULL == ch->dest) 409 (NULL == ch->dest)
405 ? 0 410 ? 0
406 : ntohl(ch->dest->ccn.channel_of_client)); 411 : ntohl (ch->dest->ccn.channel_of_client));
407 return buf; 412 return buf;
408} 413}
409 414
@@ -418,19 +423,19 @@ GCCH_2s(const struct CadetChannel *ch)
418 * @param listener peer that is listining on @a port 423 * @param listener peer that is listining on @a port
419 */ 424 */
420void 425void
421GCCH_hash_port(struct GNUNET_HashCode *h_port, 426GCCH_hash_port (struct GNUNET_HashCode *h_port,
422 const struct GNUNET_HashCode *port, 427 const struct GNUNET_HashCode *port,
423 const struct GNUNET_PeerIdentity *listener) 428 const struct GNUNET_PeerIdentity *listener)
424{ 429{
425 struct GNUNET_HashContext *hc; 430 struct GNUNET_HashContext *hc;
426 431
427 hc = GNUNET_CRYPTO_hash_context_start(); 432 hc = GNUNET_CRYPTO_hash_context_start ();
428 GNUNET_CRYPTO_hash_context_read(hc, port, sizeof(*port)); 433 GNUNET_CRYPTO_hash_context_read (hc, port, sizeof(*port));
429 GNUNET_CRYPTO_hash_context_read(hc, listener, sizeof(*listener)); 434 GNUNET_CRYPTO_hash_context_read (hc, listener, sizeof(*listener));
430 GNUNET_CRYPTO_hash_context_finish(hc, h_port); 435 GNUNET_CRYPTO_hash_context_finish (hc, h_port);
431 LOG(GNUNET_ERROR_TYPE_DEBUG, 436 LOG (GNUNET_ERROR_TYPE_DEBUG,
432 "Calculated port hash %s\n", 437 "Calculated port hash %s\n",
433 GNUNET_h2s(h_port)); 438 GNUNET_h2s (h_port));
434} 439}
435 440
436 441
@@ -442,7 +447,7 @@ GCCH_hash_port(struct GNUNET_HashCode *h_port,
442 * @return ID used to identify the channel with the remote peer. 447 * @return ID used to identify the channel with the remote peer.
443 */ 448 */
444struct GNUNET_CADET_ChannelTunnelNumber 449struct GNUNET_CADET_ChannelTunnelNumber
445GCCH_get_id(const struct CadetChannel *ch) 450GCCH_get_id (const struct CadetChannel *ch)
446{ 451{
447 return ch->ctn; 452 return ch->ctn;
448} 453}
@@ -454,18 +459,18 @@ GCCH_get_id(const struct CadetChannel *ch)
454 * @param ccc data structure to clean up 459 * @param ccc data structure to clean up
455 */ 460 */
456static void 461static void
457free_channel_client(struct CadetChannelClient *ccc) 462free_channel_client (struct CadetChannelClient *ccc)
458{ 463{
459 struct CadetOutOfOrderMessage *com; 464 struct CadetOutOfOrderMessage *com;
460 465
461 while (NULL != (com = ccc->head_recv)) 466 while (NULL != (com = ccc->head_recv))
462 { 467 {
463 GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); 468 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
464 ccc->num_recv--; 469 ccc->num_recv--;
465 GNUNET_MQ_discard(com->env); 470 GNUNET_MQ_discard (com->env);
466 GNUNET_free(com); 471 GNUNET_free (com);
467 } 472 }
468 GNUNET_free(ccc); 473 GNUNET_free (ccc);
469} 474}
470 475
471 476
@@ -475,57 +480,57 @@ free_channel_client(struct CadetChannelClient *ccc)
475 * @param ch channel to destroy 480 * @param ch channel to destroy
476 */ 481 */
477static void 482static void
478channel_destroy(struct CadetChannel *ch) 483channel_destroy (struct CadetChannel *ch)
479{ 484{
480 struct CadetReliableMessage *crm; 485 struct CadetReliableMessage *crm;
481 486
482 while (NULL != (crm = ch->head_sent)) 487 while (NULL != (crm = ch->head_sent))
488 {
489 GNUNET_assert (ch == crm->ch);
490 if (NULL != crm->qe)
483 { 491 {
484 GNUNET_assert(ch == crm->ch); 492 GCT_send_cancel (crm->qe);
485 if (NULL != crm->qe) 493 crm->qe = NULL;
486 {
487 GCT_send_cancel(crm->qe);
488 crm->qe = NULL;
489 }
490 GNUNET_CONTAINER_DLL_remove(ch->head_sent, ch->tail_sent, crm);
491 GNUNET_free(crm->data_message);
492 GNUNET_free(crm);
493 } 494 }
495 GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm);
496 GNUNET_free (crm->data_message);
497 GNUNET_free (crm);
498 }
494 if (CADET_CHANNEL_LOOSE == ch->state) 499 if (CADET_CHANNEL_LOOSE == ch->state)
495 { 500 {
496 GSC_drop_loose_channel(&ch->h_port, ch); 501 GSC_drop_loose_channel (&ch->h_port, ch);
497 } 502 }
498 if (NULL != ch->owner) 503 if (NULL != ch->owner)
499 { 504 {
500 free_channel_client(ch->owner); 505 free_channel_client (ch->owner);
501 ch->owner = NULL; 506 ch->owner = NULL;
502 } 507 }
503 if (NULL != ch->dest) 508 if (NULL != ch->dest)
504 { 509 {
505 free_channel_client(ch->dest); 510 free_channel_client (ch->dest);
506 ch->dest = NULL; 511 ch->dest = NULL;
507 } 512 }
508 if (NULL != ch->last_control_qe) 513 if (NULL != ch->last_control_qe)
509 { 514 {
510 GCT_send_cancel(ch->last_control_qe); 515 GCT_send_cancel (ch->last_control_qe);
511 ch->last_control_qe = NULL; 516 ch->last_control_qe = NULL;
512 } 517 }
513 if (NULL != ch->retry_data_task) 518 if (NULL != ch->retry_data_task)
514 { 519 {
515 GNUNET_SCHEDULER_cancel(ch->retry_data_task); 520 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
516 ch->retry_data_task = NULL; 521 ch->retry_data_task = NULL;
517 } 522 }
518 if (NULL != ch->retry_control_task) 523 if (NULL != ch->retry_control_task)
519 { 524 {
520 GNUNET_SCHEDULER_cancel(ch->retry_control_task); 525 GNUNET_SCHEDULER_cancel (ch->retry_control_task);
521 ch->retry_control_task = NULL; 526 ch->retry_control_task = NULL;
522 } 527 }
523 if (GNUNET_NO == ch->is_loopback) 528 if (GNUNET_NO == ch->is_loopback)
524 { 529 {
525 GCT_remove_channel(ch->t, ch, ch->ctn); 530 GCT_remove_channel (ch->t, ch, ch->ctn);
526 ch->t = NULL; 531 ch->t = NULL;
527 } 532 }
528 GNUNET_free(ch); 533 GNUNET_free (ch);
529} 534}
530 535
531 536
@@ -535,7 +540,7 @@ channel_destroy(struct CadetChannel *ch)
535 * @param cls Channel for which to send. 540 * @param cls Channel for which to send.
536 */ 541 */
537static void 542static void
538send_channel_open(void *cls); 543send_channel_open (void *cls);
539 544
540 545
541/** 546/**
@@ -547,20 +552,20 @@ send_channel_open(void *cls);
547 * if transmission failed 552 * if transmission failed
548 */ 553 */
549static void 554static void
550channel_open_sent_cb(void *cls, 555channel_open_sent_cb (void *cls,
551 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) 556 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
552{ 557{
553 struct CadetChannel *ch = cls; 558 struct CadetChannel *ch = cls;
554 559
555 GNUNET_assert(NULL != ch->last_control_qe); 560 GNUNET_assert (NULL != ch->last_control_qe);
556 ch->last_control_qe = NULL; 561 ch->last_control_qe = NULL;
557 ch->retry_time = GNUNET_TIME_STD_BACKOFF(ch->retry_time); 562 ch->retry_time = GNUNET_TIME_STD_BACKOFF (ch->retry_time);
558 LOG(GNUNET_ERROR_TYPE_DEBUG, 563 LOG (GNUNET_ERROR_TYPE_DEBUG,
559 "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n", 564 "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n",
560 GCCH_2s(ch), 565 GCCH_2s (ch),
561 GNUNET_STRINGS_relative_time_to_string(ch->retry_time, GNUNET_YES)); 566 GNUNET_STRINGS_relative_time_to_string (ch->retry_time, GNUNET_YES));
562 ch->retry_control_task = 567 ch->retry_control_task =
563 GNUNET_SCHEDULER_add_delayed(ch->retry_time, &send_channel_open, ch); 568 GNUNET_SCHEDULER_add_delayed (ch->retry_time, &send_channel_open, ch);
564} 569}
565 570
566 571
@@ -570,27 +575,27 @@ channel_open_sent_cb(void *cls,
570 * @param cls Channel for which to send. 575 * @param cls Channel for which to send.
571 */ 576 */
572static void 577static void
573send_channel_open(void *cls) 578send_channel_open (void *cls)
574{ 579{
575 struct CadetChannel *ch = cls; 580 struct CadetChannel *ch = cls;
576 struct GNUNET_CADET_ChannelOpenMessage msgcc; 581 struct GNUNET_CADET_ChannelOpenMessage msgcc;
577 582
578 ch->retry_control_task = NULL; 583 ch->retry_control_task = NULL;
579 LOG(GNUNET_ERROR_TYPE_DEBUG, 584 LOG (GNUNET_ERROR_TYPE_DEBUG,
580 "Sending CHANNEL_OPEN message for %s\n", 585 "Sending CHANNEL_OPEN message for %s\n",
581 GCCH_2s(ch)); 586 GCCH_2s (ch));
582 msgcc.header.size = htons(sizeof(msgcc)); 587 msgcc.header.size = htons (sizeof(msgcc));
583 msgcc.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); 588 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
584 //TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated "reliable" bit here that was removed. 589 // TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated "reliable" bit here that was removed.
585 msgcc.opt = 2; 590 msgcc.opt = 2;
586 msgcc.h_port = ch->h_port; 591 msgcc.h_port = ch->h_port;
587 msgcc.ctn = ch->ctn; 592 msgcc.ctn = ch->ctn;
588 ch->state = CADET_CHANNEL_OPEN_SENT; 593 ch->state = CADET_CHANNEL_OPEN_SENT;
589 if (NULL != ch->last_control_qe) 594 if (NULL != ch->last_control_qe)
590 GCT_send_cancel(ch->last_control_qe); 595 GCT_send_cancel (ch->last_control_qe);
591 ch->last_control_qe = 596 ch->last_control_qe =
592 GCT_send(ch->t, &msgcc.header, &channel_open_sent_cb, ch); 597 GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch);
593 GNUNET_assert(NULL == ch->retry_control_task); 598 GNUNET_assert (NULL == ch->retry_control_task);
594} 599}
595 600
596 601
@@ -605,13 +610,13 @@ send_channel_open(void *cls)
605 * @param ch the channel for which the tunnel is now ready 610 * @param ch the channel for which the tunnel is now ready
606 */ 611 */
607void 612void
608GCCH_tunnel_up(struct CadetChannel *ch) 613GCCH_tunnel_up (struct CadetChannel *ch)
609{ 614{
610 GNUNET_assert(NULL == ch->retry_control_task); 615 GNUNET_assert (NULL == ch->retry_control_task);
611 LOG(GNUNET_ERROR_TYPE_DEBUG, 616 LOG (GNUNET_ERROR_TYPE_DEBUG,
612 "Tunnel up, sending CHANNEL_OPEN on %s now\n", 617 "Tunnel up, sending CHANNEL_OPEN on %s now\n",
613 GCCH_2s(ch)); 618 GCCH_2s (ch));
614 ch->retry_control_task = GNUNET_SCHEDULER_add_now(&send_channel_open, ch); 619 ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_channel_open, ch);
615} 620}
616 621
617 622
@@ -626,22 +631,22 @@ GCCH_tunnel_up(struct CadetChannel *ch)
626 * @return handle to the new channel 631 * @return handle to the new channel
627 */ 632 */
628struct CadetChannel * 633struct CadetChannel *
629GCCH_channel_local_new(struct CadetClient *owner, 634GCCH_channel_local_new (struct CadetClient *owner,
630 struct GNUNET_CADET_ClientChannelNumber ccn, 635 struct GNUNET_CADET_ClientChannelNumber ccn,
631 struct CadetPeer *destination, 636 struct CadetPeer *destination,
632 const struct GNUNET_HashCode *port, 637 const struct GNUNET_HashCode *port,
633 uint32_t options) 638 uint32_t options)
634{ 639{
635 struct CadetChannel *ch; 640 struct CadetChannel *ch;
636 struct CadetChannelClient *ccco; 641 struct CadetChannelClient *ccco;
637 642
638 ccco = GNUNET_new(struct CadetChannelClient); 643 ccco = GNUNET_new (struct CadetChannelClient);
639 ccco->c = owner; 644 ccco->c = owner;
640 ccco->ccn = ccn; 645 ccco->ccn = ccn;
641 ccco->client_ready = GNUNET_YES; 646 ccco->client_ready = GNUNET_YES;
642 647
643 ch = GNUNET_new(struct CadetChannel); 648 ch = GNUNET_new (struct CadetChannel);
644 ch->mid_recv.mid = htonl(1); /* The OPEN_ACK counts as message 0! */ 649 ch->mid_recv.mid = htonl (1); /* The OPEN_ACK counts as message 0! */
645 ch->nobuffer = GNUNET_NO; 650 ch->nobuffer = GNUNET_NO;
646 ch->reliable = GNUNET_YES; 651 ch->reliable = GNUNET_YES;
647 ch->out_of_order = GNUNET_NO; 652 ch->out_of_order = GNUNET_NO;
@@ -649,44 +654,44 @@ GCCH_channel_local_new(struct CadetClient *owner,
649 (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ 654 (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */
650 ch->owner = ccco; 655 ch->owner = ccco;
651 ch->port = *port; 656 ch->port = *port;
652 GCCH_hash_port(&ch->h_port, port, GCP_get_id(destination)); 657 GCCH_hash_port (&ch->h_port, port, GCP_get_id (destination));
653 if (0 == GNUNET_memcmp(&my_full_id, GCP_get_id(destination))) 658 if (0 == GNUNET_memcmp (&my_full_id, GCP_get_id (destination)))
659 {
660 struct OpenPort *op;
661
662 ch->is_loopback = GNUNET_YES;
663 op = GNUNET_CONTAINER_multihashmap_get (open_ports, &ch->h_port);
664 if (NULL == op)
654 { 665 {
655 struct OpenPort *op; 666 /* port closed, wait for it to possibly open */
656 667 ch->state = CADET_CHANNEL_LOOSE;
657 ch->is_loopback = GNUNET_YES; 668 (void) GNUNET_CONTAINER_multihashmap_put (
658 op = GNUNET_CONTAINER_multihashmap_get(open_ports, &ch->h_port); 669 loose_channels,
659 if (NULL == op) 670 &ch->h_port,
660 { 671 ch,
661 /* port closed, wait for it to possibly open */ 672 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
662 ch->state = CADET_CHANNEL_LOOSE; 673 LOG (GNUNET_ERROR_TYPE_DEBUG,
663 (void)GNUNET_CONTAINER_multihashmap_put( 674 "Created loose incoming loopback channel to port %s\n",
664 loose_channels, 675 GNUNET_h2s (&ch->port));
665 &ch->h_port,
666 ch,
667 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
668 LOG(GNUNET_ERROR_TYPE_DEBUG,
669 "Created loose incoming loopback channel to port %s\n",
670 GNUNET_h2s(&ch->port));
671 }
672 else
673 {
674 GCCH_bind(ch, op->c, &op->port);
675 }
676 } 676 }
677 else 677 else
678 { 678 {
679 ch->t = GCP_get_tunnel(destination, GNUNET_YES); 679 GCCH_bind (ch, op->c, &op->port);
680 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
681 ch->ctn = GCT_add_channel(ch->t, ch);
682 } 680 }
683 GNUNET_STATISTICS_update(stats, "# channels", 1, GNUNET_NO); 681 }
684 LOG(GNUNET_ERROR_TYPE_DEBUG, 682 else
685 "Created channel to port %s at peer %s for %s using %s\n", 683 {
686 GNUNET_h2s(port), 684 ch->t = GCP_get_tunnel (destination, GNUNET_YES);
687 GCP_2s(destination), 685 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
688 GSC_2s(owner), 686 ch->ctn = GCT_add_channel (ch->t, ch);
689 (GNUNET_YES == ch->is_loopback) ? "loopback" : GCT_2s(ch->t)); 687 }
688 GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
689 LOG (GNUNET_ERROR_TYPE_DEBUG,
690 "Created channel to port %s at peer %s for %s using %s\n",
691 GNUNET_h2s (port),
692 GCP_2s (destination),
693 GSC_2s (owner),
694 (GNUNET_YES == ch->is_loopback) ? "loopback" : GCT_2s (ch->t));
690 return ch; 695 return ch;
691} 696}
692 697
@@ -698,16 +703,16 @@ GCCH_channel_local_new(struct CadetClient *owner,
698 * @param cls the channel to drop 703 * @param cls the channel to drop
699 */ 704 */
700static void 705static void
701timeout_closed_cb(void *cls) 706timeout_closed_cb (void *cls)
702{ 707{
703 struct CadetChannel *ch = cls; 708 struct CadetChannel *ch = cls;
704 709
705 ch->retry_control_task = NULL; 710 ch->retry_control_task = NULL;
706 LOG(GNUNET_ERROR_TYPE_DEBUG, 711 LOG (GNUNET_ERROR_TYPE_DEBUG,
707 "Closing incoming channel to port %s from peer %s due to timeout\n", 712 "Closing incoming channel to port %s from peer %s due to timeout\n",
708 GNUNET_h2s(&ch->port), 713 GNUNET_h2s (&ch->port),
709 GCP_2s(GCT_get_destination(ch->t))); 714 GCP_2s (GCT_get_destination (ch->t)));
710 channel_destroy(ch); 715 channel_destroy (ch);
711} 716}
712 717
713 718
@@ -721,15 +726,15 @@ timeout_closed_cb(void *cls)
721 * @return handle to the new channel 726 * @return handle to the new channel
722 */ 727 */
723struct CadetChannel * 728struct CadetChannel *
724GCCH_channel_incoming_new(struct CadetTunnel *t, 729GCCH_channel_incoming_new (struct CadetTunnel *t,
725 struct GNUNET_CADET_ChannelTunnelNumber ctn, 730 struct GNUNET_CADET_ChannelTunnelNumber ctn,
726 const struct GNUNET_HashCode *h_port, 731 const struct GNUNET_HashCode *h_port,
727 uint32_t options) 732 uint32_t options)
728{ 733{
729 struct CadetChannel *ch; 734 struct CadetChannel *ch;
730 struct OpenPort *op; 735 struct OpenPort *op;
731 736
732 ch = GNUNET_new(struct CadetChannel); 737 ch = GNUNET_new (struct CadetChannel);
733 ch->h_port = *h_port; 738 ch->h_port = *h_port;
734 ch->t = t; 739 ch->t = t;
735 ch->ctn = ctn; 740 ch->ctn = ctn;
@@ -739,32 +744,32 @@ GCCH_channel_incoming_new(struct CadetTunnel *t,
739 ch->out_of_order = GNUNET_NO; 744 ch->out_of_order = GNUNET_NO;
740 ch->max_pending_messages = 745 ch->max_pending_messages =
741 (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ 746 (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */
742 GNUNET_STATISTICS_update(stats, "# channels", 1, GNUNET_NO); 747 GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
743 748
744 op = GNUNET_CONTAINER_multihashmap_get(open_ports, h_port); 749 op = GNUNET_CONTAINER_multihashmap_get (open_ports, h_port);
745 if (NULL == op) 750 if (NULL == op)
746 { 751 {
747 /* port closed, wait for it to possibly open */ 752 /* port closed, wait for it to possibly open */
748 ch->state = CADET_CHANNEL_LOOSE; 753 ch->state = CADET_CHANNEL_LOOSE;
749 (void)GNUNET_CONTAINER_multihashmap_put( 754 (void) GNUNET_CONTAINER_multihashmap_put (
750 loose_channels, 755 loose_channels,
751 &ch->h_port, 756 &ch->h_port,
752 ch, 757 ch,
753 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 758 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
754 GNUNET_assert(NULL == ch->retry_control_task); 759 GNUNET_assert (NULL == ch->retry_control_task);
755 ch->retry_control_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT_CLOSED_PORT, 760 ch->retry_control_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT,
756 &timeout_closed_cb, 761 &timeout_closed_cb,
757 ch); 762 ch);
758 LOG(GNUNET_ERROR_TYPE_DEBUG, 763 LOG (GNUNET_ERROR_TYPE_DEBUG,
759 "Created loose incoming channel to port %s from peer %s\n", 764 "Created loose incoming channel to port %s from peer %s\n",
760 GNUNET_h2s(&ch->port), 765 GNUNET_h2s (&ch->port),
761 GCP_2s(GCT_get_destination(ch->t))); 766 GCP_2s (GCT_get_destination (ch->t)));
762 } 767 }
763 else 768 else
764 { 769 {
765 GCCH_bind(ch, op->c, &op->port); 770 GCCH_bind (ch, op->c, &op->port);
766 } 771 }
767 GNUNET_STATISTICS_update(stats, "# channels", 1, GNUNET_NO); 772 GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
768 return ch; 773 return ch;
769} 774}
770 775
@@ -779,12 +784,12 @@ GCCH_channel_incoming_new(struct CadetTunnel *t,
779 * if transmission failed 784 * if transmission failed
780 */ 785 */
781static void 786static void
782send_ack_cb(void *cls, 787send_ack_cb (void *cls,
783 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) 788 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
784{ 789{
785 struct CadetChannel *ch = cls; 790 struct CadetChannel *ch = cls;
786 791
787 GNUNET_assert(NULL != ch->last_control_qe); 792 GNUNET_assert (NULL != ch->last_control_qe);
788 ch->last_control_qe = NULL; 793 ch->last_control_qe = NULL;
789} 794}
790 795
@@ -795,25 +800,25 @@ send_ack_cb(void *cls,
795 * @param ch channel to send the #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK for 800 * @param ch channel to send the #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK for
796 */ 801 */
797static void 802static void
798send_channel_data_ack(struct CadetChannel *ch) 803send_channel_data_ack (struct CadetChannel *ch)
799{ 804{
800 struct GNUNET_CADET_ChannelDataAckMessage msg; 805 struct GNUNET_CADET_ChannelDataAckMessage msg;
801 806
802 if (GNUNET_NO == ch->reliable) 807 if (GNUNET_NO == ch->reliable)
803 return; /* no ACKs */ 808 return; /* no ACKs */
804 msg.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); 809 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK);
805 msg.header.size = htons(sizeof(msg)); 810 msg.header.size = htons (sizeof(msg));
806 msg.ctn = ch->ctn; 811 msg.ctn = ch->ctn;
807 msg.mid.mid = htonl(ntohl(ch->mid_recv.mid)); 812 msg.mid.mid = htonl (ntohl (ch->mid_recv.mid));
808 msg.futures = GNUNET_htonll(ch->mid_futures); 813 msg.futures = GNUNET_htonll (ch->mid_futures);
809 LOG(GNUNET_ERROR_TYPE_DEBUG, 814 LOG (GNUNET_ERROR_TYPE_DEBUG,
810 "Sending DATA_ACK %u:%llX via %s\n", 815 "Sending DATA_ACK %u:%llX via %s\n",
811 (unsigned int)ntohl(msg.mid.mid), 816 (unsigned int) ntohl (msg.mid.mid),
812 (unsigned long long)ch->mid_futures, 817 (unsigned long long) ch->mid_futures,
813 GCCH_2s(ch)); 818 GCCH_2s (ch));
814 if (NULL != ch->last_control_qe) 819 if (NULL != ch->last_control_qe)
815 GCT_send_cancel(ch->last_control_qe); 820 GCT_send_cancel (ch->last_control_qe);
816 ch->last_control_qe = GCT_send(ch->t, &msg.header, &send_ack_cb, ch); 821 ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch);
817} 822}
818 823
819 824
@@ -824,23 +829,23 @@ send_channel_data_ack(struct CadetChannel *ch)
824 * @param cls the `struct CadetChannel` 829 * @param cls the `struct CadetChannel`
825 */ 830 */
826static void 831static void
827send_open_ack(void *cls) 832send_open_ack (void *cls)
828{ 833{
829 struct CadetChannel *ch = cls; 834 struct CadetChannel *ch = cls;
830 struct GNUNET_CADET_ChannelOpenAckMessage msg; 835 struct GNUNET_CADET_ChannelOpenAckMessage msg;
831 836
832 ch->retry_control_task = NULL; 837 ch->retry_control_task = NULL;
833 LOG(GNUNET_ERROR_TYPE_DEBUG, 838 LOG (GNUNET_ERROR_TYPE_DEBUG,
834 "Sending CHANNEL_OPEN_ACK on %s\n", 839 "Sending CHANNEL_OPEN_ACK on %s\n",
835 GCCH_2s(ch)); 840 GCCH_2s (ch));
836 msg.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK); 841 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK);
837 msg.header.size = htons(sizeof(msg)); 842 msg.header.size = htons (sizeof(msg));
838 msg.reserved = htonl(0); 843 msg.reserved = htonl (0);
839 msg.ctn = ch->ctn; 844 msg.ctn = ch->ctn;
840 msg.port = ch->port; 845 msg.port = ch->port;
841 if (NULL != ch->last_control_qe) 846 if (NULL != ch->last_control_qe)
842 GCT_send_cancel(ch->last_control_qe); 847 GCT_send_cancel (ch->last_control_qe);
843 ch->last_control_qe = GCT_send(ch->t, &msg.header, &send_ack_cb, ch); 848 ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch);
844} 849}
845 850
846 851
@@ -853,28 +858,28 @@ send_open_ack(void *cls)
853 * @param cti identifier of the connection that delivered the message 858 * @param cti identifier of the connection that delivered the message
854 */ 859 */
855void 860void
856GCCH_handle_duplicate_open( 861GCCH_handle_duplicate_open (
857 struct CadetChannel *ch, 862 struct CadetChannel *ch,
858 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) 863 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti)
859{ 864{
860 if (NULL == ch->dest) 865 if (NULL == ch->dest)
861 { 866 {
862 LOG(GNUNET_ERROR_TYPE_DEBUG, 867 LOG (GNUNET_ERROR_TYPE_DEBUG,
863 "Ignoring duplicate CHANNEL_OPEN on %s: port is closed\n", 868 "Ignoring duplicate CHANNEL_OPEN on %s: port is closed\n",
864 GCCH_2s(ch)); 869 GCCH_2s (ch));
865 return; 870 return;
866 } 871 }
867 if (NULL != ch->retry_control_task) 872 if (NULL != ch->retry_control_task)
868 { 873 {
869 LOG(GNUNET_ERROR_TYPE_DEBUG, 874 LOG (GNUNET_ERROR_TYPE_DEBUG,
870 "Ignoring duplicate CHANNEL_OPEN on %s: control message is pending\n", 875 "Ignoring duplicate CHANNEL_OPEN on %s: control message is pending\n",
871 GCCH_2s(ch)); 876 GCCH_2s (ch));
872 return; 877 return;
873 } 878 }
874 LOG(GNUNET_ERROR_TYPE_DEBUG, 879 LOG (GNUNET_ERROR_TYPE_DEBUG,
875 "Retransmitting CHANNEL_OPEN_ACK on %s\n", 880 "Retransmitting CHANNEL_OPEN_ACK on %s\n",
876 GCCH_2s(ch)); 881 GCCH_2s (ch));
877 ch->retry_control_task = GNUNET_SCHEDULER_add_now(&send_open_ack, ch); 882 ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch);
878} 883}
879 884
880 885
@@ -886,7 +891,7 @@ GCCH_handle_duplicate_open(
886 * #GNUNET_NO to send to dest 891 * #GNUNET_NO to send to dest
887 */ 892 */
888static void 893static void
889send_ack_to_client(struct CadetChannel *ch, int to_owner) 894send_ack_to_client (struct CadetChannel *ch, int to_owner)
890{ 895{
891 struct GNUNET_MQ_Envelope *env; 896 struct GNUNET_MQ_Envelope *env;
892 struct GNUNET_CADET_LocalAck *ack; 897 struct GNUNET_CADET_LocalAck *ack;
@@ -894,22 +899,22 @@ send_ack_to_client(struct CadetChannel *ch, int to_owner)
894 899
895 ccc = (GNUNET_YES == to_owner) ? ch->owner : ch->dest; 900 ccc = (GNUNET_YES == to_owner) ? ch->owner : ch->dest;
896 if (NULL == ccc) 901 if (NULL == ccc)
897 { 902 {
898 /* This can happen if we are just getting ACKs after 903 /* This can happen if we are just getting ACKs after
899 our local client already disconnected. */ 904 our local client already disconnected. */
900 GNUNET_assert(GNUNET_YES == ch->destroy); 905 GNUNET_assert (GNUNET_YES == ch->destroy);
901 return; 906 return;
902 } 907 }
903 env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 908 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
904 ack->ccn = ccc->ccn; 909 ack->ccn = ccc->ccn;
905 LOG(GNUNET_ERROR_TYPE_DEBUG, 910 LOG (GNUNET_ERROR_TYPE_DEBUG,
906 "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n", 911 "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n",
907 GSC_2s(ccc->c), 912 GSC_2s (ccc->c),
908 (GNUNET_YES == to_owner) ? "owner" : "dest", 913 (GNUNET_YES == to_owner) ? "owner" : "dest",
909 ntohl(ack->ccn.channel_of_client), 914 ntohl (ack->ccn.channel_of_client),
910 ch->pending_messages, 915 ch->pending_messages,
911 ch->max_pending_messages); 916 ch->max_pending_messages);
912 GSC_send_to_client(ccc->c, env); 917 GSC_send_to_client (ccc->c, env);
913} 918}
914 919
915 920
@@ -923,58 +928,58 @@ send_ack_to_client(struct CadetChannel *ch, int to_owner)
923 * @param port the port @a is listening on 928 * @param port the port @a is listening on
924 */ 929 */
925void 930void
926GCCH_bind(struct CadetChannel *ch, 931GCCH_bind (struct CadetChannel *ch,
927 struct CadetClient *c, 932 struct CadetClient *c,
928 const struct GNUNET_HashCode *port) 933 const struct GNUNET_HashCode *port)
929{ 934{
930 uint32_t options; 935 uint32_t options;
931 struct CadetChannelClient *cccd; 936 struct CadetChannelClient *cccd;
932 937
933 LOG(GNUNET_ERROR_TYPE_DEBUG, 938 LOG (GNUNET_ERROR_TYPE_DEBUG,
934 "Binding %s from %s to port %s of %s\n", 939 "Binding %s from %s to port %s of %s\n",
935 GCCH_2s(ch), 940 GCCH_2s (ch),
936 GCT_2s(ch->t), 941 GCT_2s (ch->t),
937 GNUNET_h2s(&ch->port), 942 GNUNET_h2s (&ch->port),
938 GSC_2s(c)); 943 GSC_2s (c));
939 if (NULL != ch->retry_control_task) 944 if (NULL != ch->retry_control_task)
940 { 945 {
941 /* there might be a timeout task here */ 946 /* there might be a timeout task here */
942 GNUNET_SCHEDULER_cancel(ch->retry_control_task); 947 GNUNET_SCHEDULER_cancel (ch->retry_control_task);
943 ch->retry_control_task = NULL; 948 ch->retry_control_task = NULL;
944 } 949 }
945 options = 0; 950 options = 0;
946 cccd = GNUNET_new(struct CadetChannelClient); 951 cccd = GNUNET_new (struct CadetChannelClient);
947 GNUNET_assert(NULL == ch->dest); 952 GNUNET_assert (NULL == ch->dest);
948 ch->dest = cccd; 953 ch->dest = cccd;
949 ch->port = *port; 954 ch->port = *port;
950 cccd->c = c; 955 cccd->c = c;
951 cccd->client_ready = GNUNET_YES; 956 cccd->client_ready = GNUNET_YES;
952 cccd->ccn = GSC_bind(c, 957 cccd->ccn = GSC_bind (c,
953 ch, 958 ch,
954 (GNUNET_YES == ch->is_loopback) 959 (GNUNET_YES == ch->is_loopback)
955 ? GCP_get(&my_full_id, GNUNET_YES) 960 ? GCP_get (&my_full_id, GNUNET_YES)
956 : GCT_get_destination(ch->t), 961 : GCT_get_destination (ch->t),
957 port, 962 port,
958 options); 963 options);
959 GNUNET_assert(ntohl(cccd->ccn.channel_of_client) < 964 GNUNET_assert (ntohl (cccd->ccn.channel_of_client) <
960 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); 965 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
961 ch->mid_recv.mid = htonl(1); /* The OPEN counts as message 0! */ 966 ch->mid_recv.mid = htonl (1); /* The OPEN counts as message 0! */
962 if (GNUNET_YES == ch->is_loopback) 967 if (GNUNET_YES == ch->is_loopback)
963 { 968 {
964 ch->state = CADET_CHANNEL_OPEN_SENT; 969 ch->state = CADET_CHANNEL_OPEN_SENT;
965 GCCH_handle_channel_open_ack(ch, NULL, port); 970 GCCH_handle_channel_open_ack (ch, NULL, port);
966 } 971 }
967 else 972 else
968 { 973 {
969 /* notify other peer that we accepted the connection */ 974 /* notify other peer that we accepted the connection */
970 ch->state = CADET_CHANNEL_READY; 975 ch->state = CADET_CHANNEL_READY;
971 ch->retry_control_task = GNUNET_SCHEDULER_add_now(&send_open_ack, ch); 976 ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch);
972 } 977 }
973 /* give client it's initial supply of ACKs */ 978 /* give client it's initial supply of ACKs */
974 GNUNET_assert(ntohl(cccd->ccn.channel_of_client) < 979 GNUNET_assert (ntohl (cccd->ccn.channel_of_client) <
975 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); 980 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
976 for (unsigned int i = 0; i < ch->max_pending_messages; i++) 981 for (unsigned int i = 0; i < ch->max_pending_messages; i++)
977 send_ack_to_client(ch, GNUNET_NO); 982 send_ack_to_client (ch, GNUNET_NO);
978} 983}
979 984
980 985
@@ -986,7 +991,7 @@ GCCH_bind(struct CadetChannel *ch,
986 * @param cls the `struct CadetChannel` where one of the ends is now dead 991 * @param cls the `struct CadetChannel` where one of the ends is now dead
987 */ 992 */
988static void 993static void
989signal_remote_destroy_cb(void *cls) 994signal_remote_destroy_cb (void *cls)
990{ 995{
991 struct CadetChannel *ch = cls; 996 struct CadetChannel *ch = cls;
992 struct CadetChannelClient *ccc; 997 struct CadetChannelClient *ccc;
@@ -994,8 +999,8 @@ signal_remote_destroy_cb(void *cls)
994 /* Find which end is left... */ 999 /* Find which end is left... */
995 ch->retry_control_task = NULL; 1000 ch->retry_control_task = NULL;
996 ccc = (NULL != ch->owner) ? ch->owner : ch->dest; 1001 ccc = (NULL != ch->owner) ? ch->owner : ch->dest;
997 GSC_handle_remote_channel_destroy(ccc->c, ccc->ccn, ch); 1002 GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch);
998 channel_destroy(ch); 1003 channel_destroy (ch);
999} 1004}
1000 1005
1001 1006
@@ -1008,74 +1013,74 @@ signal_remote_destroy_cb(void *cls)
1008 * @param ccn client number of the client @a c 1013 * @param ccn client number of the client @a c
1009 */ 1014 */
1010void 1015void
1011GCCH_channel_local_destroy(struct CadetChannel *ch, 1016GCCH_channel_local_destroy (struct CadetChannel *ch,
1012 struct CadetClient *c, 1017 struct CadetClient *c,
1013 struct GNUNET_CADET_ClientChannelNumber ccn) 1018 struct GNUNET_CADET_ClientChannelNumber ccn)
1014{ 1019{
1015 LOG(GNUNET_ERROR_TYPE_DEBUG, 1020 LOG (GNUNET_ERROR_TYPE_DEBUG,
1016 "%s asks for destruction of %s\n", 1021 "%s asks for destruction of %s\n",
1017 GSC_2s(c), 1022 GSC_2s (c),
1018 GCCH_2s(ch)); 1023 GCCH_2s (ch));
1019 GNUNET_assert(NULL != c); 1024 GNUNET_assert (NULL != c);
1020 if ((NULL != ch->owner) && (c == ch->owner->c) && 1025 if ((NULL != ch->owner) && (c == ch->owner->c) &&
1021 (ccn.channel_of_client == ch->owner->ccn.channel_of_client)) 1026 (ccn.channel_of_client == ch->owner->ccn.channel_of_client))
1022 { 1027 {
1023 free_channel_client(ch->owner); 1028 free_channel_client (ch->owner);
1024 ch->owner = NULL; 1029 ch->owner = NULL;
1025 } 1030 }
1026 else if ((NULL != ch->dest) && (c == ch->dest->c) && 1031 else if ((NULL != ch->dest) && (c == ch->dest->c) &&
1027 (ccn.channel_of_client == ch->dest->ccn.channel_of_client)) 1032 (ccn.channel_of_client == ch->dest->ccn.channel_of_client))
1028 { 1033 {
1029 free_channel_client(ch->dest); 1034 free_channel_client (ch->dest);
1030 ch->dest = NULL; 1035 ch->dest = NULL;
1031 } 1036 }
1032 else 1037 else
1033 { 1038 {
1034 GNUNET_assert(0); 1039 GNUNET_assert (0);
1035 } 1040 }
1036 1041
1037 if (GNUNET_YES == ch->destroy) 1042 if (GNUNET_YES == ch->destroy)
1038 { 1043 {
1039 /* other end already destroyed, with the local client gone, no need 1044 /* other end already destroyed, with the local client gone, no need
1040 to finish transmissions, just destroy immediately. */ 1045 to finish transmissions, just destroy immediately. */
1041 channel_destroy(ch); 1046 channel_destroy (ch);
1042 return; 1047 return;
1043 } 1048 }
1044 if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest))) 1049 if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest)))
1045 { 1050 {
1046 /* Wait for other end to destroy us as well, 1051 /* Wait for other end to destroy us as well,
1047 and otherwise allow send queue to be transmitted first */ 1052 and otherwise allow send queue to be transmitted first */
1048 ch->destroy = GNUNET_YES; 1053 ch->destroy = GNUNET_YES;
1049 return; 1054 return;
1050 } 1055 }
1051 if ((GNUNET_YES == ch->is_loopback) && 1056 if ((GNUNET_YES == ch->is_loopback) &&
1052 ((NULL != ch->owner) || (NULL != ch->dest))) 1057 ((NULL != ch->owner) || (NULL != ch->dest)))
1053 { 1058 {
1054 if (NULL != ch->retry_control_task) 1059 if (NULL != ch->retry_control_task)
1055 GNUNET_SCHEDULER_cancel(ch->retry_control_task); 1060 GNUNET_SCHEDULER_cancel (ch->retry_control_task);
1056 ch->retry_control_task = 1061 ch->retry_control_task =
1057 GNUNET_SCHEDULER_add_now(&signal_remote_destroy_cb, ch); 1062 GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, ch);
1058 return; 1063 return;
1059 } 1064 }
1060 if (GNUNET_NO == ch->is_loopback) 1065 if (GNUNET_NO == ch->is_loopback)
1066 {
1067 /* If the we ever sent the CHANNEL_CREATE, we need to send a destroy message. */
1068 switch (ch->state)
1061 { 1069 {
1062 /* If the we ever sent the CHANNEL_CREATE, we need to send a destroy message. */ 1070 case CADET_CHANNEL_NEW:
1063 switch (ch->state) 1071 /* We gave up on a channel that we created as a client to a remote
1064 { 1072 target, but that never went anywhere. Nothing to do here. */
1065 case CADET_CHANNEL_NEW: 1073 break;
1066 /* We gave up on a channel that we created as a client to a remote 1074
1067 target, but that never went anywhere. Nothing to do here. */ 1075 case CADET_CHANNEL_LOOSE:
1068 break; 1076 break;
1069 1077
1070 case CADET_CHANNEL_LOOSE: 1078 default:
1071 break; 1079 GCT_send_channel_destroy (ch->t, ch->ctn);
1072
1073 default:
1074 GCT_send_channel_destroy(ch->t, ch->ctn);
1075 }
1076 } 1080 }
1081 }
1077 /* Nothing left to do, just finish destruction */ 1082 /* Nothing left to do, just finish destruction */
1078 channel_destroy(ch); 1083 channel_destroy (ch);
1079} 1084}
1080 1085
1081 1086
@@ -1089,60 +1094,60 @@ GCCH_channel_local_destroy(struct CadetChannel *ch,
1089 * @param port port number (needed to verify receiver knows the port) 1094 * @param port port number (needed to verify receiver knows the port)
1090 */ 1095 */
1091void 1096void
1092GCCH_handle_channel_open_ack( 1097GCCH_handle_channel_open_ack (
1093 struct CadetChannel *ch, 1098 struct CadetChannel *ch,
1094 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1099 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1095 const struct GNUNET_HashCode *port) 1100 const struct GNUNET_HashCode *port)
1096{ 1101{
1097 switch (ch->state) 1102 switch (ch->state)
1103 {
1104 case CADET_CHANNEL_NEW:
1105 /* this should be impossible */
1106 GNUNET_break (0);
1107 break;
1108
1109 case CADET_CHANNEL_LOOSE:
1110 /* This makes no sense. */
1111 GNUNET_break_op (0);
1112 break;
1113
1114 case CADET_CHANNEL_OPEN_SENT:
1115 if (NULL == ch->owner)
1098 { 1116 {
1099 case CADET_CHANNEL_NEW: 1117 /* We're not the owner, wrong direction! */
1100 /* this should be impossible */ 1118 GNUNET_break_op (0);
1101 GNUNET_break(0); 1119 return;
1102 break; 1120 }
1103 1121 if (0 != GNUNET_memcmp (&ch->port, port))
1104 case CADET_CHANNEL_LOOSE: 1122 {
1105 /* This makes no sense. */ 1123 /* Other peer failed to provide the right port,
1106 GNUNET_break_op(0); 1124 refuse connection. */
1107 break; 1125 GNUNET_break_op (0);
1108 1126 return;
1109 case CADET_CHANNEL_OPEN_SENT:
1110 if (NULL == ch->owner)
1111 {
1112 /* We're not the owner, wrong direction! */
1113 GNUNET_break_op(0);
1114 return;
1115 }
1116 if (0 != GNUNET_memcmp(&ch->port, port))
1117 {
1118 /* Other peer failed to provide the right port,
1119 refuse connection. */
1120 GNUNET_break_op(0);
1121 return;
1122 }
1123 LOG(GNUNET_ERROR_TYPE_DEBUG,
1124 "Received CHANNEL_OPEN_ACK for waiting %s, entering READY state\n",
1125 GCCH_2s(ch));
1126 if (NULL != ch->retry_control_task) /* can be NULL if ch->is_loopback */
1127 {
1128 GNUNET_SCHEDULER_cancel(ch->retry_control_task);
1129 ch->retry_control_task = NULL;
1130 }
1131 ch->state = CADET_CHANNEL_READY;
1132 /* On first connect, send client as many ACKs as we allow messages
1133 to be buffered! */
1134 for (unsigned int i = 0; i < ch->max_pending_messages; i++)
1135 send_ack_to_client(ch, GNUNET_YES);
1136 break;
1137
1138 case CADET_CHANNEL_READY:
1139 /* duplicate ACK, maybe we retried the CREATE. Ignore. */
1140 LOG(GNUNET_ERROR_TYPE_DEBUG,
1141 "Received duplicate channel OPEN_ACK for %s\n",
1142 GCCH_2s(ch));
1143 GNUNET_STATISTICS_update(stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO);
1144 break;
1145 } 1127 }
1128 LOG (GNUNET_ERROR_TYPE_DEBUG,
1129 "Received CHANNEL_OPEN_ACK for waiting %s, entering READY state\n",
1130 GCCH_2s (ch));
1131 if (NULL != ch->retry_control_task) /* can be NULL if ch->is_loopback */
1132 {
1133 GNUNET_SCHEDULER_cancel (ch->retry_control_task);
1134 ch->retry_control_task = NULL;
1135 }
1136 ch->state = CADET_CHANNEL_READY;
1137 /* On first connect, send client as many ACKs as we allow messages
1138 to be buffered! */
1139 for (unsigned int i = 0; i < ch->max_pending_messages; i++)
1140 send_ack_to_client (ch, GNUNET_YES);
1141 break;
1142
1143 case CADET_CHANNEL_READY:
1144 /* duplicate ACK, maybe we retried the CREATE. Ignore. */
1145 LOG (GNUNET_ERROR_TYPE_DEBUG,
1146 "Received duplicate channel OPEN_ACK for %s\n",
1147 GCCH_2s (ch));
1148 GNUNET_STATISTICS_update (stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO);
1149 break;
1150 }
1146} 1151}
1147 1152
1148 1153
@@ -1155,28 +1160,28 @@ GCCH_handle_channel_open_ack(
1155 * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO 1160 * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO
1156 */ 1161 */
1157static int 1162static int
1158is_before(void *cls, 1163is_before (void *cls,
1159 struct CadetOutOfOrderMessage *m1, 1164 struct CadetOutOfOrderMessage *m1,
1160 struct CadetOutOfOrderMessage *m2) 1165 struct CadetOutOfOrderMessage *m2)
1161{ 1166{
1162 int *duplicate = cls; 1167 int *duplicate = cls;
1163 uint32_t v1 = ntohl(m1->mid.mid); 1168 uint32_t v1 = ntohl (m1->mid.mid);
1164 uint32_t v2 = ntohl(m2->mid.mid); 1169 uint32_t v2 = ntohl (m2->mid.mid);
1165 uint32_t delta; 1170 uint32_t delta;
1166 1171
1167 delta = v2 - v1; 1172 delta = v2 - v1;
1168 if (0 == delta) 1173 if (0 == delta)
1169 *duplicate = GNUNET_YES; 1174 *duplicate = GNUNET_YES;
1170 if (delta > (uint32_t)INT_MAX) 1175 if (delta > (uint32_t) INT_MAX)
1171 { 1176 {
1172 /* in overflow range, we can safely assume we wrapped around */ 1177 /* in overflow range, we can safely assume we wrapped around */
1173 return GNUNET_NO; 1178 return GNUNET_NO;
1174 } 1179 }
1175 else 1180 else
1176 { 1181 {
1177 /* result is small, thus v2 > v1, thus m1 < m2 */ 1182 /* result is small, thus v2 > v1, thus m1 < m2 */
1178 return GNUNET_YES; 1183 return GNUNET_YES;
1179 } 1184 }
1180} 1185}
1181 1186
1182 1187
@@ -1189,7 +1194,7 @@ is_before(void *cls,
1189 * @param msg message that was received 1194 * @param msg message that was received
1190 */ 1195 */
1191void 1196void
1192GCCH_handle_channel_plaintext_data( 1197GCCH_handle_channel_plaintext_data (
1193 struct CadetChannel *ch, 1198 struct CadetChannel *ch,
1194 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1199 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1195 const struct GNUNET_CADET_ChannelAppDataMessage *msg) 1200 const struct GNUNET_CADET_ChannelAppDataMessage *msg)
@@ -1205,239 +1210,239 @@ GCCH_handle_channel_plaintext_data(
1205 uint32_t mid_msg; 1210 uint32_t mid_msg;
1206 uint32_t delta; 1211 uint32_t delta;
1207 1212
1208 GNUNET_assert(GNUNET_NO == ch->is_loopback); 1213 GNUNET_assert (GNUNET_NO == ch->is_loopback);
1209 if ((NULL == ch->owner) && (NULL == ch->dest)) 1214 if ((NULL == ch->owner) && (NULL == ch->dest))
1210 { 1215 {
1211 /* This client is gone, but we still have messages to send to 1216 /* This client is gone, but we still have messages to send to
1212 the other end (which is why @a ch is not yet dead). However, 1217 the other end (which is why @a ch is not yet dead). However,
1213 we cannot pass messages to our client anymore. */ 1218 we cannot pass messages to our client anymore. */
1214 LOG(GNUNET_ERROR_TYPE_DEBUG, 1219 LOG (GNUNET_ERROR_TYPE_DEBUG,
1215 "Dropping incoming payload on %s as this end is already closed\n", 1220 "Dropping incoming payload on %s as this end is already closed\n",
1216 GCCH_2s(ch)); 1221 GCCH_2s (ch));
1217 /* send back DESTROY notification to stop further retransmissions! */ 1222 /* send back DESTROY notification to stop further retransmissions! */
1218 if (GNUNET_YES == ch->destroy) 1223 if (GNUNET_YES == ch->destroy)
1219 GCT_send_channel_destroy(ch->t, ch->ctn); 1224 GCT_send_channel_destroy (ch->t, ch->ctn);
1220 return; 1225 return;
1221 } 1226 }
1222 payload_size = ntohs(msg->header.size) - sizeof(*msg); 1227 payload_size = ntohs (msg->header.size) - sizeof(*msg);
1223 env = GNUNET_MQ_msg_extra(ld, 1228 env = GNUNET_MQ_msg_extra (ld,
1224 payload_size, 1229 payload_size,
1225 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 1230 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
1226 ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; 1231 ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn;
1227 GNUNET_memcpy(&ld[1], &msg[1], payload_size); 1232 GNUNET_memcpy (&ld[1], &msg[1], payload_size);
1228 ccc = (NULL != ch->owner) ? ch->owner : ch->dest; 1233 ccc = (NULL != ch->owner) ? ch->owner : ch->dest;
1229 if (GNUNET_YES == ccc->client_ready) 1234 if (GNUNET_YES == ccc->client_ready)
1235 {
1236 /*
1237 * We ad-hoc send the message if
1238 * - The channel is out-of-order
1239 * - The channel is reliable and MID matches next expected MID
1240 * - The channel is unreliable and MID is before lowest seen MID
1241 */
1242 if ((GNUNET_YES == ch->out_of_order) ||
1243 ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) ||
1244 ((GNUNET_NO == ch->reliable) &&
1245 (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) &&
1246 ((NULL == ccc->head_recv) ||
1247 (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid)))))
1230 { 1248 {
1231 /* 1249 LOG (GNUNET_ERROR_TYPE_DEBUG,
1232 * We ad-hoc send the message if 1250 "Giving %u bytes of payload with MID %u from %s to client %s\n",
1233 * - The channel is out-of-order 1251 (unsigned int) payload_size,
1234 * - The channel is reliable and MID matches next expected MID 1252 ntohl (msg->mid.mid),
1235 * - The channel is unreliable and MID is before lowest seen MID 1253 GCCH_2s (ch),
1236 */ 1254 GSC_2s (ccc->c));
1237 if ((GNUNET_YES == ch->out_of_order) || 1255 ccc->client_ready = GNUNET_NO;
1238 ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) || 1256 GSC_send_to_client (ccc->c, env);
1239 ((GNUNET_NO == ch->reliable) && 1257 if (GNUNET_NO == ch->out_of_order)
1240 (ntohl(msg->mid.mid) >= ntohl(ch->mid_recv.mid)) && 1258 ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid));
1241 ((NULL == ccc->head_recv) || 1259 else
1242 (ntohl(msg->mid.mid) < ntohl(ccc->head_recv->mid.mid))))) 1260 ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid));
1243 { 1261 ch->mid_futures >>= 1;
1244 LOG(GNUNET_ERROR_TYPE_DEBUG, 1262 if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable))
1245 "Giving %u bytes of payload with MID %u from %s to client %s\n", 1263 {
1246 (unsigned int)payload_size, 1264 /* possibly shift by more if we skipped messages */
1247 ntohl(msg->mid.mid), 1265 uint64_t delta = htonl (msg->mid.mid) - 1 - ntohl (ch->mid_recv.mid);
1248 GCCH_2s(ch), 1266
1249 GSC_2s(ccc->c)); 1267 if (delta > 63)
1250 ccc->client_ready = GNUNET_NO; 1268 ch->mid_futures = 0;
1251 GSC_send_to_client(ccc->c, env); 1269 else
1252 if (GNUNET_NO == ch->out_of_order) 1270 ch->mid_futures >>= delta;
1253 ch->mid_recv.mid = htonl(1 + ntohl(msg->mid.mid)); 1271 ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid));
1254 else 1272 }
1255 ch->mid_recv.mid = htonl(1 + ntohl(ch->mid_recv.mid)); 1273 send_channel_data_ack (ch);
1256 ch->mid_futures >>= 1; 1274 return;
1257 if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable))
1258 {
1259 /* possibly shift by more if we skipped messages */
1260 uint64_t delta = htonl(msg->mid.mid) - 1 - ntohl(ch->mid_recv.mid);
1261
1262 if (delta > 63)
1263 ch->mid_futures = 0;
1264 else
1265 ch->mid_futures >>= delta;
1266 ch->mid_recv.mid = htonl(1 + ntohl(msg->mid.mid));
1267 }
1268 send_channel_data_ack(ch);
1269 return;
1270 }
1271 } 1275 }
1276 }
1272 1277
1273 if (GNUNET_YES == ch->reliable) 1278 if (GNUNET_YES == ch->reliable)
1279 {
1280 /* check if message ought to be dropped because it is ancient/too distant/duplicate */
1281 mid_min = ntohl (ch->mid_recv.mid);
1282 mid_max = mid_min + ch->max_pending_messages;
1283 mid_msg = ntohl (msg->mid.mid);
1284 if (((uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) ||
1285 ((uint32_t) (mid_max - mid_msg) > ch->max_pending_messages))
1286 {
1287 LOG (GNUNET_ERROR_TYPE_DEBUG,
1288 "%s at %u drops ancient or far-future message %u\n",
1289 GCCH_2s (ch),
1290 (unsigned int) mid_min,
1291 ntohl (msg->mid.mid));
1292
1293 GNUNET_STATISTICS_update (stats,
1294 "# duplicate DATA (ancient or future)",
1295 1,
1296 GNUNET_NO);
1297 GNUNET_MQ_discard (env);
1298 send_channel_data_ack (ch);
1299 return;
1300 }
1301 /* mark bit for future ACKs */
1302 delta = mid_msg - mid_min - 1; /* overflow/underflow are OK here */
1303 if (delta < 64)
1274 { 1304 {
1275 /* check if message ought to be dropped because it is ancient/too distant/duplicate */ 1305 if (0 != (ch->mid_futures & (1LLU << delta)))
1276 mid_min = ntohl(ch->mid_recv.mid); 1306 {
1277 mid_max = mid_min + ch->max_pending_messages; 1307 /* Duplicate within the queue, drop also */
1278 mid_msg = ntohl(msg->mid.mid); 1308 LOG (GNUNET_ERROR_TYPE_DEBUG,
1279 if (((uint32_t)(mid_msg - mid_min) > ch->max_pending_messages) || 1309 "Duplicate payload of %u bytes on %s (mid %u) dropped\n",
1280 ((uint32_t)(mid_max - mid_msg) > ch->max_pending_messages)) 1310 (unsigned int) payload_size,
1281 { 1311 GCCH_2s (ch),
1282 LOG(GNUNET_ERROR_TYPE_DEBUG, 1312 ntohl (msg->mid.mid));
1283 "%s at %u drops ancient or far-future message %u\n", 1313 GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO);
1284 GCCH_2s(ch), 1314 GNUNET_MQ_discard (env);
1285 (unsigned int)mid_min, 1315 send_channel_data_ack (ch);
1286 ntohl(msg->mid.mid)); 1316 return;
1287 1317 }
1288 GNUNET_STATISTICS_update(stats, 1318 ch->mid_futures |= (1LLU << delta);
1289 "# duplicate DATA (ancient or future)", 1319 LOG (GNUNET_ERROR_TYPE_DEBUG,
1290 1, 1320 "Marked bit %llX for mid %u (base: %u); now: %llX\n",
1291 GNUNET_NO); 1321 (1LLU << delta),
1292 GNUNET_MQ_discard(env); 1322 mid_msg,
1293 send_channel_data_ack(ch); 1323 mid_min,
1294 return; 1324 ch->mid_futures);
1295 }
1296 /* mark bit for future ACKs */
1297 delta = mid_msg - mid_min - 1; /* overflow/underflow are OK here */
1298 if (delta < 64)
1299 {
1300 if (0 != (ch->mid_futures & (1LLU << delta)))
1301 {
1302 /* Duplicate within the queue, drop also */
1303 LOG(GNUNET_ERROR_TYPE_DEBUG,
1304 "Duplicate payload of %u bytes on %s (mid %u) dropped\n",
1305 (unsigned int)payload_size,
1306 GCCH_2s(ch),
1307 ntohl(msg->mid.mid));
1308 GNUNET_STATISTICS_update(stats, "# duplicate DATA", 1, GNUNET_NO);
1309 GNUNET_MQ_discard(env);
1310 send_channel_data_ack(ch);
1311 return;
1312 }
1313 ch->mid_futures |= (1LLU << delta);
1314 LOG(GNUNET_ERROR_TYPE_DEBUG,
1315 "Marked bit %llX for mid %u (base: %u); now: %llX\n",
1316 (1LLU << delta),
1317 mid_msg,
1318 mid_min,
1319 ch->mid_futures);
1320 }
1321 } 1325 }
1326 }
1322 else /* ! ch->reliable */ 1327 else /* ! ch->reliable */
1328 {
1329 struct CadetOutOfOrderMessage *next_msg;
1330
1331 /**
1332 * We always send if possible in this case.
1333 * It is guaranteed that the queued MID < received MID
1334 **/
1335 if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready))
1336 {
1337 next_msg = ccc->head_recv;
1338 LOG (GNUNET_ERROR_TYPE_DEBUG,
1339 "Giving queued MID %u from %s to client %s\n",
1340 ntohl (next_msg->mid.mid),
1341 GCCH_2s (ch),
1342 GSC_2s (ccc->c));
1343 ccc->client_ready = GNUNET_NO;
1344 GSC_send_to_client (ccc->c, next_msg->env);
1345 ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid));
1346 ch->mid_futures >>= 1;
1347 send_channel_data_ack (ch);
1348 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, next_msg);
1349 ccc->num_recv--;
1350 /* Do not process duplicate MID */
1351 if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */
1352 {
1353 /* Duplicate within the queue, drop */
1354 LOG (GNUNET_ERROR_TYPE_DEBUG,
1355 "Message on %s (mid %u) dropped, duplicate\n",
1356 GCCH_2s (ch),
1357 ntohl (msg->mid.mid));
1358 GNUNET_free (next_msg);
1359 GNUNET_MQ_discard (env);
1360 return;
1361 }
1362 GNUNET_free (next_msg);
1363 }
1364
1365 if (ntohl (msg->mid.mid) < ntohl (ch->mid_recv.mid)) /* Old */
1366 {
1367 /* Duplicate within the queue, drop */
1368 LOG (GNUNET_ERROR_TYPE_DEBUG,
1369 "Message on %s (mid %u) dropped, old.\n",
1370 GCCH_2s (ch),
1371 ntohl (msg->mid.mid));
1372 GNUNET_MQ_discard (env);
1373 return;
1374 }
1375
1376 /* Channel is unreliable, so we do not ACK. But we also cannot
1377 allow buffering everything, so check if we have space... */
1378 if (ccc->num_recv >= ch->max_pending_messages)
1323 { 1379 {
1324 struct CadetOutOfOrderMessage *next_msg; 1380 struct CadetOutOfOrderMessage *drop;
1325 1381
1326 /** 1382 /* Yep, need to drop. Drop the oldest message in
1327 * We always send if possible in this case. 1383 the buffer. */
1328 * It is guaranteed that the queued MID < received MID 1384 LOG (GNUNET_ERROR_TYPE_DEBUG,
1329 **/ 1385 "Queue full due slow client on %s, dropping oldest message\n",
1330 if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready)) 1386 GCCH_2s (ch));
1331 { 1387 GNUNET_STATISTICS_update (stats,
1332 next_msg = ccc->head_recv; 1388 "# messages dropped due to slow client",
1333 LOG(GNUNET_ERROR_TYPE_DEBUG, 1389 1,
1334 "Giving queued MID %u from %s to client %s\n", 1390 GNUNET_NO);
1335 ntohl(next_msg->mid.mid), 1391 drop = ccc->head_recv;
1336 GCCH_2s(ch), 1392 GNUNET_assert (NULL != drop);
1337 GSC_2s(ccc->c)); 1393 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, drop);
1338 ccc->client_ready = GNUNET_NO; 1394 ccc->num_recv--;
1339 GSC_send_to_client(ccc->c, next_msg->env); 1395 GNUNET_MQ_discard (drop->env);
1340 ch->mid_recv.mid = htonl(1 + ntohl(next_msg->mid.mid)); 1396 GNUNET_free (drop);
1341 ch->mid_futures >>= 1;
1342 send_channel_data_ack(ch);
1343 GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, next_msg);
1344 ccc->num_recv--;
1345 /* Do not process duplicate MID */
1346 if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */
1347 {
1348 /* Duplicate within the queue, drop */
1349 LOG(GNUNET_ERROR_TYPE_DEBUG,
1350 "Message on %s (mid %u) dropped, duplicate\n",
1351 GCCH_2s(ch),
1352 ntohl(msg->mid.mid));
1353 GNUNET_free(next_msg);
1354 GNUNET_MQ_discard(env);
1355 return;
1356 }
1357 GNUNET_free(next_msg);
1358 }
1359
1360 if (ntohl(msg->mid.mid) < ntohl(ch->mid_recv.mid)) /* Old */
1361 {
1362 /* Duplicate within the queue, drop */
1363 LOG(GNUNET_ERROR_TYPE_DEBUG,
1364 "Message on %s (mid %u) dropped, old.\n",
1365 GCCH_2s(ch),
1366 ntohl(msg->mid.mid));
1367 GNUNET_MQ_discard(env);
1368 return;
1369 }
1370
1371 /* Channel is unreliable, so we do not ACK. But we also cannot
1372 allow buffering everything, so check if we have space... */
1373 if (ccc->num_recv >= ch->max_pending_messages)
1374 {
1375 struct CadetOutOfOrderMessage *drop;
1376
1377 /* Yep, need to drop. Drop the oldest message in
1378 the buffer. */
1379 LOG(GNUNET_ERROR_TYPE_DEBUG,
1380 "Queue full due slow client on %s, dropping oldest message\n",
1381 GCCH_2s(ch));
1382 GNUNET_STATISTICS_update(stats,
1383 "# messages dropped due to slow client",
1384 1,
1385 GNUNET_NO);
1386 drop = ccc->head_recv;
1387 GNUNET_assert(NULL != drop);
1388 GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, drop);
1389 ccc->num_recv--;
1390 GNUNET_MQ_discard(drop->env);
1391 GNUNET_free(drop);
1392 }
1393 } 1397 }
1398 }
1394 1399
1395 /* Insert message into sorted out-of-order queue */ 1400 /* Insert message into sorted out-of-order queue */
1396 com = GNUNET_new(struct CadetOutOfOrderMessage); 1401 com = GNUNET_new (struct CadetOutOfOrderMessage);
1397 com->mid = msg->mid; 1402 com->mid = msg->mid;
1398 com->env = env; 1403 com->env = env;
1399 duplicate = GNUNET_NO; 1404 duplicate = GNUNET_NO;
1400 GNUNET_CONTAINER_DLL_insert_sorted(struct CadetOutOfOrderMessage, 1405 GNUNET_CONTAINER_DLL_insert_sorted (struct CadetOutOfOrderMessage,
1401 is_before, 1406 is_before,
1402 &duplicate, 1407 &duplicate,
1403 ccc->head_recv, 1408 ccc->head_recv,
1404 ccc->tail_recv, 1409 ccc->tail_recv,
1405 com); 1410 com);
1406 ccc->num_recv++; 1411 ccc->num_recv++;
1407 if (GNUNET_YES == duplicate) 1412 if (GNUNET_YES == duplicate)
1408 { 1413 {
1409 /* Duplicate within the queue, drop also (this is not covered by 1414 /* Duplicate within the queue, drop also (this is not covered by
1410 the case above if "delta" >= 64, which could be the case if 1415 the case above if "delta" >= 64, which could be the case if
1411 max_pending_messages is also >= 64 or if our client is unready 1416 max_pending_messages is also >= 64 or if our client is unready
1412 and we are seeing retransmissions of the message our client is 1417 and we are seeing retransmissions of the message our client is
1413 blocked on. */ 1418 blocked on. */
1414 LOG(GNUNET_ERROR_TYPE_DEBUG, 1419 LOG (GNUNET_ERROR_TYPE_DEBUG,
1415 "Duplicate payload of %u bytes on %s (mid %u) dropped\n", 1420 "Duplicate payload of %u bytes on %s (mid %u) dropped\n",
1416 (unsigned int)payload_size, 1421 (unsigned int) payload_size,
1417 GCCH_2s(ch), 1422 GCCH_2s (ch),
1418 ntohl(msg->mid.mid)); 1423 ntohl (msg->mid.mid));
1419 GNUNET_STATISTICS_update(stats, "# duplicate DATA", 1, GNUNET_NO); 1424 GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO);
1420 GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); 1425 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
1421 ccc->num_recv--; 1426 ccc->num_recv--;
1422 GNUNET_MQ_discard(com->env); 1427 GNUNET_MQ_discard (com->env);
1423 GNUNET_free(com); 1428 GNUNET_free (com);
1424 send_channel_data_ack(ch); 1429 send_channel_data_ack (ch);
1425 return; 1430 return;
1426 } 1431 }
1427 LOG(GNUNET_ERROR_TYPE_DEBUG, 1432 LOG (GNUNET_ERROR_TYPE_DEBUG,
1428 "Queued %s payload of %u bytes on %s-%X(%p) (mid %u, need %u first)\n", 1433 "Queued %s payload of %u bytes on %s-%X(%p) (mid %u, need %u first)\n",
1429 (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready", 1434 (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready",
1430 (unsigned int)payload_size, 1435 (unsigned int) payload_size,
1431 GCCH_2s(ch), 1436 GCCH_2s (ch),
1432 ntohl(ccc->ccn.channel_of_client), 1437 ntohl (ccc->ccn.channel_of_client),
1433 ccc, 1438 ccc,
1434 ntohl(msg->mid.mid), 1439 ntohl (msg->mid.mid),
1435 ntohl(ch->mid_recv.mid)); 1440 ntohl (ch->mid_recv.mid));
1436 /* NOTE: this ACK we _could_ skip, as the packet is out-of-order and 1441 /* NOTE: this ACK we _could_ skip, as the packet is out-of-order and
1437 the sender may already be transmitting the previous one. Needs 1442 the sender may already be transmitting the previous one. Needs
1438 experimental evaluation to see if/when this ACK helps or 1443 experimental evaluation to see if/when this ACK helps or
1439 hurts. (We might even want another option.) */ 1444 hurts. (We might even want another option.) */
1440 send_channel_data_ack(ch); 1445 send_channel_data_ack (ch);
1441} 1446}
1442 1447
1443 1448
@@ -1452,8 +1457,8 @@ GCCH_handle_channel_plaintext_data(
1452 * if transmission failed 1457 * if transmission failed
1453 */ 1458 */
1454static void 1459static void
1455data_sent_cb(void *cls, 1460data_sent_cb (void *cls,
1456 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid); 1461 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
1457 1462
1458 1463
1459/** 1464/**
@@ -1463,19 +1468,19 @@ data_sent_cb(void *cls,
1463 * @param cls the `struct CadetChannel` where we need to retransmit 1468 * @param cls the `struct CadetChannel` where we need to retransmit
1464 */ 1469 */
1465static void 1470static void
1466retry_transmission(void *cls) 1471retry_transmission (void *cls)
1467{ 1472{
1468 struct CadetChannel *ch = cls; 1473 struct CadetChannel *ch = cls;
1469 struct CadetReliableMessage *crm = ch->head_sent; 1474 struct CadetReliableMessage *crm = ch->head_sent;
1470 1475
1471 ch->retry_data_task = NULL; 1476 ch->retry_data_task = NULL;
1472 GNUNET_assert(NULL == crm->qe); 1477 GNUNET_assert (NULL == crm->qe);
1473 LOG(GNUNET_ERROR_TYPE_DEBUG, 1478 LOG (GNUNET_ERROR_TYPE_DEBUG,
1474 "Retrying transmission on %s of message %u\n", 1479 "Retrying transmission on %s of message %u\n",
1475 GCCH_2s(ch), 1480 GCCH_2s (ch),
1476 (unsigned int)ntohl(crm->data_message->mid.mid)); 1481 (unsigned int) ntohl (crm->data_message->mid.mid));
1477 crm->qe = GCT_send(ch->t, &crm->data_message->header, &data_sent_cb, crm); 1482 crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm);
1478 GNUNET_assert(NULL == ch->retry_data_task); 1483 GNUNET_assert (NULL == ch->retry_data_task);
1479} 1484}
1480 1485
1481 1486
@@ -1488,36 +1493,36 @@ retry_transmission(void *cls)
1488 * @param crm the message that got acknowledged 1493 * @param crm the message that got acknowledged
1489 */ 1494 */
1490static void 1495static void
1491handle_matching_ack(struct CadetChannel *ch, 1496handle_matching_ack (struct CadetChannel *ch,
1492 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1497 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1493 struct CadetReliableMessage *crm) 1498 struct CadetReliableMessage *crm)
1494{ 1499{
1495 GNUNET_CONTAINER_DLL_remove(ch->head_sent, ch->tail_sent, crm); 1500 GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm);
1496 ch->pending_messages--; 1501 ch->pending_messages--;
1497 GNUNET_assert(ch->pending_messages < ch->max_pending_messages); 1502 GNUNET_assert (ch->pending_messages < ch->max_pending_messages);
1498 LOG(GNUNET_ERROR_TYPE_DEBUG, 1503 LOG (GNUNET_ERROR_TYPE_DEBUG,
1499 "Received DATA_ACK on %s for message %u (%u ACKs pending)\n", 1504 "Received DATA_ACK on %s for message %u (%u ACKs pending)\n",
1500 GCCH_2s(ch), 1505 GCCH_2s (ch),
1501 (unsigned int)ntohl(crm->data_message->mid.mid), 1506 (unsigned int) ntohl (crm->data_message->mid.mid),
1502 ch->pending_messages); 1507 ch->pending_messages);
1503 if (NULL != crm->qe) 1508 if (NULL != crm->qe)
1504 { 1509 {
1505 GCT_send_cancel(crm->qe); 1510 GCT_send_cancel (crm->qe);
1506 crm->qe = NULL; 1511 crm->qe = NULL;
1507 } 1512 }
1508 if ((1 == crm->num_transmissions) && (NULL != cti)) 1513 if ((1 == crm->num_transmissions) && (NULL != cti))
1514 {
1515 GCC_ack_observed (cti);
1516 if (0 == GNUNET_memcmp (cti, &crm->connection_taken))
1509 { 1517 {
1510 GCC_ack_observed(cti); 1518 GCC_latency_observed (cti,
1511 if (0 == GNUNET_memcmp(cti, &crm->connection_taken)) 1519 GNUNET_TIME_absolute_get_duration (
1512 { 1520 crm->first_transmission_time));
1513 GCC_latency_observed(cti,
1514 GNUNET_TIME_absolute_get_duration(
1515 crm->first_transmission_time));
1516 }
1517 } 1521 }
1518 GNUNET_free(crm->data_message); 1522 }
1519 GNUNET_free(crm); 1523 GNUNET_free (crm->data_message);
1520 send_ack_to_client(ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); 1524 GNUNET_free (crm);
1525 send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES);
1521} 1526}
1522 1527
1523 1528
@@ -1530,7 +1535,7 @@ handle_matching_ack(struct CadetChannel *ch,
1530 * @param ack details about what was received 1535 * @param ack details about what was received
1531 */ 1536 */
1532void 1537void
1533GCCH_handle_channel_plaintext_data_ack( 1538GCCH_handle_channel_plaintext_data_ack (
1534 struct CadetChannel *ch, 1539 struct CadetChannel *ch,
1535 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1540 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1536 const struct GNUNET_CADET_ChannelDataAckMessage *ack) 1541 const struct GNUNET_CADET_ChannelDataAckMessage *ack)
@@ -1542,72 +1547,72 @@ GCCH_handle_channel_plaintext_data_ack(
1542 uint64_t mid_mask; 1547 uint64_t mid_mask;
1543 unsigned int delta; 1548 unsigned int delta;
1544 1549
1545 GNUNET_break(GNUNET_NO == ch->is_loopback); 1550 GNUNET_break (GNUNET_NO == ch->is_loopback);
1546 if (GNUNET_NO == ch->reliable) 1551 if (GNUNET_NO == ch->reliable)
1547 { 1552 {
1548 /* not expecting ACKs on unreliable channel, odd */ 1553 /* not expecting ACKs on unreliable channel, odd */
1549 GNUNET_break_op(0); 1554 GNUNET_break_op (0);
1550 return; 1555 return;
1551 } 1556 }
1552 /* mid_base is the MID of the next message that the 1557 /* mid_base is the MID of the next message that the
1553 other peer expects (i.e. that is missing!), everything 1558 other peer expects (i.e. that is missing!), everything
1554 LOWER (but excluding mid_base itself) was received. */ 1559 LOWER (but excluding mid_base itself) was received. */
1555 mid_base = ntohl(ack->mid.mid); 1560 mid_base = ntohl (ack->mid.mid);
1556 mid_mask = GNUNET_htonll(ack->futures); 1561 mid_mask = GNUNET_htonll (ack->futures);
1557 found = GNUNET_NO; 1562 found = GNUNET_NO;
1558 for (crm = ch->head_sent; NULL != crm; crm = crmn) 1563 for (crm = ch->head_sent; NULL != crm; crm = crmn)
1564 {
1565 crmn = crm->next;
1566 delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base);
1567 if (delta >= UINT_MAX - ch->max_pending_messages)
1559 { 1568 {
1560 crmn = crm->next; 1569 /* overflow, means crm was a bit in the past, so this ACK counts for it. */
1561 delta = (unsigned int)(ntohl(crm->data_message->mid.mid) - mid_base); 1570 LOG (GNUNET_ERROR_TYPE_DEBUG,
1562 if (delta >= UINT_MAX - ch->max_pending_messages) 1571 "Got DATA_ACK with base %u satisfying past message %u on %s\n",
1563 { 1572 (unsigned int) mid_base,
1564 /* overflow, means crm was a bit in the past, so this ACK counts for it. */ 1573 ntohl (crm->data_message->mid.mid),
1565 LOG(GNUNET_ERROR_TYPE_DEBUG, 1574 GCCH_2s (ch));
1566 "Got DATA_ACK with base %u satisfying past message %u on %s\n", 1575 handle_matching_ack (ch, cti, crm);
1567 (unsigned int)mid_base, 1576 found = GNUNET_YES;
1568 ntohl(crm->data_message->mid.mid), 1577 continue;
1569 GCCH_2s(ch));
1570 handle_matching_ack(ch, cti, crm);
1571 found = GNUNET_YES;
1572 continue;
1573 }
1574 delta--;
1575 if (delta >= 64)
1576 continue;
1577 LOG(GNUNET_ERROR_TYPE_DEBUG,
1578 "Testing bit %llX for mid %u (base: %u)\n",
1579 (1LLU << delta),
1580 ntohl(crm->data_message->mid.mid),
1581 mid_base);
1582 if (0 != (mid_mask & (1LLU << delta)))
1583 {
1584 LOG(GNUNET_ERROR_TYPE_DEBUG,
1585 "Got DATA_ACK with mask for %u on %s\n",
1586 ntohl(crm->data_message->mid.mid),
1587 GCCH_2s(ch));
1588 handle_matching_ack(ch, cti, crm);
1589 found = GNUNET_YES;
1590 }
1591 } 1578 }
1592 if (GNUNET_NO == found) 1579 delta--;
1580 if (delta >= 64)
1581 continue;
1582 LOG (GNUNET_ERROR_TYPE_DEBUG,
1583 "Testing bit %llX for mid %u (base: %u)\n",
1584 (1LLU << delta),
1585 ntohl (crm->data_message->mid.mid),
1586 mid_base);
1587 if (0 != (mid_mask & (1LLU << delta)))
1593 { 1588 {
1594 /* ACK for message we already dropped, might have been a 1589 LOG (GNUNET_ERROR_TYPE_DEBUG,
1595 duplicate ACK? Ignore. */ 1590 "Got DATA_ACK with mask for %u on %s\n",
1596 LOG(GNUNET_ERROR_TYPE_DEBUG, 1591 ntohl (crm->data_message->mid.mid),
1597 "Duplicate DATA_ACK on %s, ignoring\n", 1592 GCCH_2s (ch));
1598 GCCH_2s(ch)); 1593 handle_matching_ack (ch, cti, crm);
1599 GNUNET_STATISTICS_update(stats, "# duplicate DATA_ACKs", 1, GNUNET_NO); 1594 found = GNUNET_YES;
1600 return;
1601 } 1595 }
1596 }
1597 if (GNUNET_NO == found)
1598 {
1599 /* ACK for message we already dropped, might have been a
1600 duplicate ACK? Ignore. */
1601 LOG (GNUNET_ERROR_TYPE_DEBUG,
1602 "Duplicate DATA_ACK on %s, ignoring\n",
1603 GCCH_2s (ch));
1604 GNUNET_STATISTICS_update (stats, "# duplicate DATA_ACKs", 1, GNUNET_NO);
1605 return;
1606 }
1602 if (NULL != ch->retry_data_task) 1607 if (NULL != ch->retry_data_task)
1603 { 1608 {
1604 GNUNET_SCHEDULER_cancel(ch->retry_data_task); 1609 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
1605 ch->retry_data_task = NULL; 1610 ch->retry_data_task = NULL;
1606 } 1611 }
1607 if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe)) 1612 if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe))
1608 ch->retry_data_task = GNUNET_SCHEDULER_add_at(ch->head_sent->next_retry, 1613 ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry,
1609 &retry_transmission, 1614 &retry_transmission,
1610 ch); 1615 ch);
1611} 1616}
1612 1617
1613 1618
@@ -1621,34 +1626,34 @@ GCCH_handle_channel_plaintext_data_ack(
1621 * NULL if we are simulating receiving a destroy due to shutdown 1626 * NULL if we are simulating receiving a destroy due to shutdown
1622 */ 1627 */
1623void 1628void
1624GCCH_handle_remote_destroy( 1629GCCH_handle_remote_destroy (
1625 struct CadetChannel *ch, 1630 struct CadetChannel *ch,
1626 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) 1631 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti)
1627{ 1632{
1628 struct CadetChannelClient *ccc; 1633 struct CadetChannelClient *ccc;
1629 1634
1630 GNUNET_assert(GNUNET_NO == ch->is_loopback); 1635 GNUNET_assert (GNUNET_NO == ch->is_loopback);
1631 LOG(GNUNET_ERROR_TYPE_DEBUG, 1636 LOG (GNUNET_ERROR_TYPE_DEBUG,
1632 "Received remote channel DESTROY for %s\n", 1637 "Received remote channel DESTROY for %s\n",
1633 GCCH_2s(ch)); 1638 GCCH_2s (ch));
1634 if (GNUNET_YES == ch->destroy) 1639 if (GNUNET_YES == ch->destroy)
1635 { 1640 {
1636 /* Local client already gone, this is instant-death. */ 1641 /* Local client already gone, this is instant-death. */
1637 channel_destroy(ch); 1642 channel_destroy (ch);
1638 return; 1643 return;
1639 } 1644 }
1640 ccc = (NULL != ch->owner) ? ch->owner : ch->dest; 1645 ccc = (NULL != ch->owner) ? ch->owner : ch->dest;
1641 if ((NULL != ccc) && (NULL != ccc->head_recv)) 1646 if ((NULL != ccc) && (NULL != ccc->head_recv))
1642 { 1647 {
1643 LOG(GNUNET_ERROR_TYPE_WARNING, 1648 LOG (GNUNET_ERROR_TYPE_WARNING,
1644 "Lost end of transmission due to remote shutdown on %s\n", 1649 "Lost end of transmission due to remote shutdown on %s\n",
1645 GCCH_2s(ch)); 1650 GCCH_2s (ch));
1646 /* FIXME: change API to notify client about truncated transmission! */ 1651 /* FIXME: change API to notify client about truncated transmission! */
1647 } 1652 }
1648 ch->destroy = GNUNET_YES; 1653 ch->destroy = GNUNET_YES;
1649 if (NULL != ccc) 1654 if (NULL != ccc)
1650 GSC_handle_remote_channel_destroy(ccc->c, ccc->ccn, ch); 1655 GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch);
1651 channel_destroy(ch); 1656 channel_destroy (ch);
1652} 1657}
1653 1658
1654 1659
@@ -1661,9 +1666,9 @@ GCCH_handle_remote_destroy(
1661 * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO 1666 * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO
1662 */ 1667 */
1663static int 1668static int
1664cmp_crm_by_next_retry(void *cls, 1669cmp_crm_by_next_retry (void *cls,
1665 struct CadetReliableMessage *crm1, 1670 struct CadetReliableMessage *crm1,
1666 struct CadetReliableMessage *crm2) 1671 struct CadetReliableMessage *crm2)
1667{ 1672{
1668 if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us) 1673 if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us)
1669 return GNUNET_YES; 1674 return GNUNET_YES;
@@ -1682,75 +1687,76 @@ cmp_crm_by_next_retry(void *cls,
1682 * if transmission failed 1687 * if transmission failed
1683 */ 1688 */
1684static void 1689static void
1685data_sent_cb(void *cls, 1690data_sent_cb (void *cls,
1686 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) 1691 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
1687{ 1692{
1688 struct CadetReliableMessage *crm = cls; 1693 struct CadetReliableMessage *crm = cls;
1689 struct CadetChannel *ch = crm->ch; 1694 struct CadetChannel *ch = crm->ch;
1690 1695
1691 GNUNET_assert(GNUNET_NO == ch->is_loopback); 1696 GNUNET_assert (GNUNET_NO == ch->is_loopback);
1692 GNUNET_assert(NULL != crm->qe); 1697 GNUNET_assert (NULL != crm->qe);
1693 crm->qe = NULL; 1698 crm->qe = NULL;
1694 GNUNET_CONTAINER_DLL_remove(ch->head_sent, ch->tail_sent, crm); 1699 GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm);
1695 if (GNUNET_NO == ch->reliable) 1700 if (GNUNET_NO == ch->reliable)
1696 { 1701 {
1697 GNUNET_free(crm->data_message); 1702 GNUNET_free (crm->data_message);
1698 GNUNET_free(crm); 1703 GNUNET_free (crm);
1699 ch->pending_messages--; 1704 ch->pending_messages--;
1700 send_ack_to_client(ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); 1705 send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES);
1701 return; 1706 return;
1702 } 1707 }
1703 if (NULL == cid) 1708 if (NULL == cid)
1704 { 1709 {
1705 /* There was an error sending. */ 1710 /* There was an error sending. */
1706 crm->num_transmissions = GNUNET_SYSERR; 1711 crm->num_transmissions = GNUNET_SYSERR;
1707 } 1712 }
1708 else if (GNUNET_SYSERR != crm->num_transmissions) 1713 else if (GNUNET_SYSERR != crm->num_transmissions)
1714 {
1715 /* Increment transmission counter, and possibly store @a cid
1716 if this was the first transmission. */
1717 crm->num_transmissions++;
1718 if (1 == crm->num_transmissions)
1709 { 1719 {
1710 /* Increment transmission counter, and possibly store @a cid 1720 crm->first_transmission_time = GNUNET_TIME_absolute_get ();
1711 if this was the first transmission. */ 1721 crm->connection_taken = *cid;
1712 crm->num_transmissions++; 1722 GCC_ack_expected (cid);
1713 if (1 == crm->num_transmissions)
1714 {
1715 crm->first_transmission_time = GNUNET_TIME_absolute_get();
1716 crm->connection_taken = *cid;
1717 GCC_ack_expected(cid);
1718 }
1719 } 1723 }
1724 }
1720 if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid)) 1725 if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid))
1721 { 1726 {
1722 struct CadetConnection *cc = GCC_lookup(cid); 1727 struct CadetConnection *cc = GCC_lookup (cid);
1723 1728
1724 if (NULL != cc) 1729 if (NULL != cc)
1725 crm->retry_delay = GCC_get_metrics(cc)->aged_latency; 1730 crm->retry_delay = GCC_get_metrics (cc)->aged_latency;
1726 else 1731 else
1727 crm->retry_delay = ch->retry_time; 1732 crm->retry_delay = ch->retry_time;
1728 } 1733 }
1729 crm->retry_delay = GNUNET_TIME_STD_BACKOFF(crm->retry_delay); 1734 crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay);
1730 crm->retry_delay = GNUNET_TIME_relative_max(crm->retry_delay, MIN_RTT_DELAY); 1735 crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, MIN_RTT_DELAY);
1731 crm->next_retry = GNUNET_TIME_relative_to_absolute(crm->retry_delay); 1736 crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay);
1732 1737
1733 GNUNET_CONTAINER_DLL_insert_sorted(struct CadetReliableMessage, 1738 GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage,
1734 cmp_crm_by_next_retry, 1739 cmp_crm_by_next_retry,
1735 NULL, 1740 NULL,
1736 ch->head_sent, 1741 ch->head_sent,
1737 ch->tail_sent, 1742 ch->tail_sent,
1738 crm); 1743 crm);
1739 LOG(GNUNET_ERROR_TYPE_DEBUG, 1744 LOG (GNUNET_ERROR_TYPE_DEBUG,
1740 "Message %u sent, next transmission on %s in %s\n", 1745 "Message %u sent, next transmission on %s in %s\n",
1741 (unsigned int)ntohl(crm->data_message->mid.mid), 1746 (unsigned int) ntohl (crm->data_message->mid.mid),
1742 GCCH_2s(ch), 1747 GCCH_2s (ch),
1743 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining( 1748 GNUNET_STRINGS_relative_time_to_string (
1744 ch->head_sent->next_retry), 1749 GNUNET_TIME_absolute_get_remaining (
1745 GNUNET_YES)); 1750 ch->head_sent->next_retry),
1751 GNUNET_YES));
1746 if (NULL == ch->head_sent->qe) 1752 if (NULL == ch->head_sent->qe)
1747 { 1753 {
1748 if (NULL != ch->retry_data_task) 1754 if (NULL != ch->retry_data_task)
1749 GNUNET_SCHEDULER_cancel(ch->retry_data_task); 1755 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
1750 ch->retry_data_task = GNUNET_SCHEDULER_add_at(ch->head_sent->next_retry, 1756 ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry,
1751 &retry_transmission, 1757 &retry_transmission,
1752 ch); 1758 ch);
1753 } 1759 }
1754} 1760}
1755 1761
1756 1762
@@ -1769,100 +1775,100 @@ data_sent_cb(void *cls,
1769 * #GNUNET_SYSERR in case of an error. 1775 * #GNUNET_SYSERR in case of an error.
1770 */ 1776 */
1771int 1777int
1772GCCH_handle_local_data(struct CadetChannel *ch, 1778GCCH_handle_local_data (struct CadetChannel *ch,
1773 struct GNUNET_CADET_ClientChannelNumber sender_ccn, 1779 struct GNUNET_CADET_ClientChannelNumber sender_ccn,
1774 const char *buf, 1780 const char *buf,
1775 size_t buf_len) 1781 size_t buf_len)
1776{ 1782{
1777 struct CadetReliableMessage *crm; 1783 struct CadetReliableMessage *crm;
1778 1784
1779 if (ch->pending_messages >= ch->max_pending_messages) 1785 if (ch->pending_messages >= ch->max_pending_messages)
1786 {
1787 GNUNET_break (0); /* Fails: #5370 */
1788 return GNUNET_SYSERR;
1789 }
1790 if (GNUNET_YES == ch->destroy)
1791 {
1792 /* we are going down, drop messages */
1793 return GNUNET_OK;
1794 }
1795 ch->pending_messages++;
1796
1797 if (GNUNET_YES == ch->is_loopback)
1798 {
1799 struct CadetChannelClient *receiver;
1800 struct GNUNET_MQ_Envelope *env;
1801 struct GNUNET_CADET_LocalData *ld;
1802 int ack_to_owner;
1803
1804 env =
1805 GNUNET_MQ_msg_extra (ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
1806 if ((NULL != ch->owner) &&
1807 (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client))
1808 {
1809 receiver = ch->dest;
1810 ack_to_owner = GNUNET_YES;
1811 }
1812 else if ((NULL != ch->dest) &&
1813 (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client))
1814 {
1815 receiver = ch->owner;
1816 ack_to_owner = GNUNET_NO;
1817 }
1818 else
1780 { 1819 {
1781 GNUNET_break(0); /* Fails: #5370 */ 1820 GNUNET_break (0);
1782 return GNUNET_SYSERR; 1821 return GNUNET_SYSERR;
1783 } 1822 }
1784 if (GNUNET_YES == ch->destroy) 1823 GNUNET_assert (NULL != receiver);
1824 ld->ccn = receiver->ccn;
1825 GNUNET_memcpy (&ld[1], buf, buf_len);
1826 if (GNUNET_YES == receiver->client_ready)
1785 { 1827 {
1786 /* we are going down, drop messages */ 1828 ch->pending_messages--;
1787 return GNUNET_OK; 1829 GSC_send_to_client (receiver->c, env);
1830 send_ack_to_client (ch, ack_to_owner);
1788 } 1831 }
1789 ch->pending_messages++; 1832 else
1790
1791 if (GNUNET_YES == ch->is_loopback)
1792 { 1833 {
1793 struct CadetChannelClient *receiver; 1834 struct CadetOutOfOrderMessage *oom;
1794 struct GNUNET_MQ_Envelope *env; 1835
1795 struct GNUNET_CADET_LocalData *ld; 1836 oom = GNUNET_new (struct CadetOutOfOrderMessage);
1796 int ack_to_owner; 1837 oom->env = env;
1797 1838 GNUNET_CONTAINER_DLL_insert_tail (receiver->head_recv,
1798 env = 1839 receiver->tail_recv,
1799 GNUNET_MQ_msg_extra(ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 1840 oom);
1800 if ((NULL != ch->owner) && 1841 receiver->num_recv++;
1801 (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client))
1802 {
1803 receiver = ch->dest;
1804 ack_to_owner = GNUNET_YES;
1805 }
1806 else if ((NULL != ch->dest) &&
1807 (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client))
1808 {
1809 receiver = ch->owner;
1810 ack_to_owner = GNUNET_NO;
1811 }
1812 else
1813 {
1814 GNUNET_break(0);
1815 return GNUNET_SYSERR;
1816 }
1817 GNUNET_assert(NULL != receiver);
1818 ld->ccn = receiver->ccn;
1819 GNUNET_memcpy(&ld[1], buf, buf_len);
1820 if (GNUNET_YES == receiver->client_ready)
1821 {
1822 ch->pending_messages--;
1823 GSC_send_to_client(receiver->c, env);
1824 send_ack_to_client(ch, ack_to_owner);
1825 }
1826 else
1827 {
1828 struct CadetOutOfOrderMessage *oom;
1829
1830 oom = GNUNET_new(struct CadetOutOfOrderMessage);
1831 oom->env = env;
1832 GNUNET_CONTAINER_DLL_insert_tail(receiver->head_recv,
1833 receiver->tail_recv,
1834 oom);
1835 receiver->num_recv++;
1836 }
1837 return GNUNET_OK;
1838 } 1842 }
1843 return GNUNET_OK;
1844 }
1839 1845
1840 /* Everything is correct, send the message. */ 1846 /* Everything is correct, send the message. */
1841 crm = GNUNET_malloc(sizeof(*crm)); 1847 crm = GNUNET_malloc (sizeof(*crm));
1842 crm->ch = ch; 1848 crm->ch = ch;
1843 crm->data_message = GNUNET_malloc( 1849 crm->data_message = GNUNET_malloc (
1844 sizeof(struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); 1850 sizeof(struct GNUNET_CADET_ChannelAppDataMessage) + buf_len);
1845 crm->data_message->header.size = 1851 crm->data_message->header.size =
1846 htons(sizeof(struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); 1852 htons (sizeof(struct GNUNET_CADET_ChannelAppDataMessage) + buf_len);
1847 crm->data_message->header.type = 1853 crm->data_message->header.type =
1848 htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); 1854 htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA);
1849 ch->mid_send.mid = htonl(ntohl(ch->mid_send.mid) + 1); 1855 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1);
1850 crm->data_message->mid = ch->mid_send; 1856 crm->data_message->mid = ch->mid_send;
1851 crm->data_message->ctn = ch->ctn; 1857 crm->data_message->ctn = ch->ctn;
1852 GNUNET_memcpy(&crm->data_message[1], buf, buf_len); 1858 GNUNET_memcpy (&crm->data_message[1], buf, buf_len);
1853 GNUNET_CONTAINER_DLL_insert_tail(ch->head_sent, ch->tail_sent, crm); 1859 GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, ch->tail_sent, crm);
1854 LOG(GNUNET_ERROR_TYPE_DEBUG, 1860 LOG (GNUNET_ERROR_TYPE_DEBUG,
1855 "Sending message %u from local client to %s with %u bytes\n", 1861 "Sending message %u from local client to %s with %u bytes\n",
1856 ntohl(crm->data_message->mid.mid), 1862 ntohl (crm->data_message->mid.mid),
1857 GCCH_2s(ch), 1863 GCCH_2s (ch),
1858 buf_len); 1864 buf_len);
1859 if (NULL != ch->retry_data_task) 1865 if (NULL != ch->retry_data_task)
1860 { 1866 {
1861 GNUNET_SCHEDULER_cancel(ch->retry_data_task); 1867 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
1862 ch->retry_data_task = NULL; 1868 ch->retry_data_task = NULL;
1863 } 1869 }
1864 crm->qe = GCT_send(ch->t, &crm->data_message->header, &data_sent_cb, crm); 1870 crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm);
1865 GNUNET_assert(NULL == ch->retry_data_task); 1871 GNUNET_assert (NULL == ch->retry_data_task);
1866 return GNUNET_OK; 1872 return GNUNET_OK;
1867} 1873}
1868 1874
@@ -1875,8 +1881,8 @@ GCCH_handle_local_data(struct CadetChannel *ch,
1875 * @param client_ccn ccn of the client sending the ack 1881 * @param client_ccn ccn of the client sending the ack
1876 */ 1882 */
1877void 1883void
1878GCCH_handle_local_ack(struct CadetChannel *ch, 1884GCCH_handle_local_ack (struct CadetChannel *ch,
1879 struct GNUNET_CADET_ClientChannelNumber client_ccn) 1885 struct GNUNET_CADET_ClientChannelNumber client_ccn)
1880{ 1886{
1881 struct CadetChannelClient *ccc; 1887 struct CadetChannelClient *ccc;
1882 struct CadetOutOfOrderMessage *com; 1888 struct CadetOutOfOrderMessage *com;
@@ -1888,87 +1894,87 @@ GCCH_handle_local_ack(struct CadetChannel *ch,
1888 (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client)) 1894 (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client))
1889 ccc = ch->dest; 1895 ccc = ch->dest;
1890 else 1896 else
1891 GNUNET_assert(0); 1897 GNUNET_assert (0);
1892 ccc->client_ready = GNUNET_YES; 1898 ccc->client_ready = GNUNET_YES;
1893 com = ccc->head_recv; 1899 com = ccc->head_recv;
1894 if (NULL == com) 1900 if (NULL == com)
1901 {
1902 LOG (GNUNET_ERROR_TYPE_DEBUG,
1903 "Got LOCAL_ACK, %s-%X ready to receive more data, but none pending on %s-%X(%p)!\n",
1904 GSC_2s (ccc->c),
1905 ntohl (client_ccn.channel_of_client),
1906 GCCH_2s (ch),
1907 ntohl (ccc->ccn.channel_of_client),
1908 ccc);
1909 return; /* none pending */
1910 }
1911 if (GNUNET_YES == ch->is_loopback)
1912 {
1913 int to_owner;
1914
1915 /* Messages are always in-order, just send */
1916 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
1917 ccc->num_recv--;
1918 GSC_send_to_client (ccc->c, com->env);
1919 /* Notify sender that we can receive more */
1920 if ((NULL != ch->owner) &&
1921 (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client))
1895 { 1922 {
1896 LOG(GNUNET_ERROR_TYPE_DEBUG, 1923 to_owner = GNUNET_NO;
1897 "Got LOCAL_ACK, %s-%X ready to receive more data, but none pending on %s-%X(%p)!\n",
1898 GSC_2s(ccc->c),
1899 ntohl(client_ccn.channel_of_client),
1900 GCCH_2s(ch),
1901 ntohl(ccc->ccn.channel_of_client),
1902 ccc);
1903 return; /* none pending */
1904 } 1924 }
1905 if (GNUNET_YES == ch->is_loopback) 1925 else
1906 { 1926 {
1907 int to_owner; 1927 GNUNET_assert ((NULL != ch->dest) && (ccc->ccn.channel_of_client ==
1908 1928 ch->dest->ccn.channel_of_client));
1909 /* Messages are always in-order, just send */ 1929 to_owner = GNUNET_YES;
1910 GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com);
1911 ccc->num_recv--;
1912 GSC_send_to_client(ccc->c, com->env);
1913 /* Notify sender that we can receive more */
1914 if ((NULL != ch->owner) &&
1915 (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client))
1916 {
1917 to_owner = GNUNET_NO;
1918 }
1919 else
1920 {
1921 GNUNET_assert((NULL != ch->dest) && (ccc->ccn.channel_of_client ==
1922 ch->dest->ccn.channel_of_client));
1923 to_owner = GNUNET_YES;
1924 }
1925 send_ack_to_client(ch, to_owner);
1926 GNUNET_free(com);
1927 return;
1928 } 1930 }
1931 send_ack_to_client (ch, to_owner);
1932 GNUNET_free (com);
1933 return;
1934 }
1929 1935
1930 if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) && 1936 if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) &&
1931 (GNUNET_YES == ch->reliable)) 1937 (GNUNET_YES == ch->reliable))
1932 { 1938 {
1933 LOG(GNUNET_ERROR_TYPE_DEBUG, 1939 LOG (GNUNET_ERROR_TYPE_DEBUG,
1934 "Got LOCAL_ACK, %s-%X ready to receive more data (but next one is out-of-order %u vs. %u)!\n", 1940 "Got LOCAL_ACK, %s-%X ready to receive more data (but next one is out-of-order %u vs. %u)!\n",
1935 GSC_2s(ccc->c), 1941 GSC_2s (ccc->c),
1936 ntohl(ccc->ccn.channel_of_client), 1942 ntohl (ccc->ccn.channel_of_client),
1937 ntohl(com->mid.mid), 1943 ntohl (com->mid.mid),
1938 ntohl(ch->mid_recv.mid)); 1944 ntohl (ch->mid_recv.mid));
1939 return; /* missing next one in-order */ 1945 return; /* missing next one in-order */
1940 } 1946 }
1941 1947
1942 LOG(GNUNET_ERROR_TYPE_DEBUG, 1948 LOG (GNUNET_ERROR_TYPE_DEBUG,
1943 "Got LOCAL_ACK, giving payload message %u to %s-%X on %s\n", 1949 "Got LOCAL_ACK, giving payload message %u to %s-%X on %s\n",
1944 ntohl(com->mid.mid), 1950 ntohl (com->mid.mid),
1945 GSC_2s(ccc->c), 1951 GSC_2s (ccc->c),
1946 ntohl(ccc->ccn.channel_of_client), 1952 ntohl (ccc->ccn.channel_of_client),
1947 GCCH_2s(ch)); 1953 GCCH_2s (ch));
1948 1954
1949 /* all good, pass next message to client */ 1955 /* all good, pass next message to client */
1950 GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); 1956 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
1951 ccc->num_recv--; 1957 ccc->num_recv--;
1952 /* FIXME: if unreliable, this is not aggressive 1958 /* FIXME: if unreliable, this is not aggressive
1953 enough, as it would be OK to have lost some! */ 1959 enough, as it would be OK to have lost some! */
1954 1960
1955 ch->mid_recv.mid = htonl(1 + ntohl(com->mid.mid)); 1961 ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid));
1956 ch->mid_futures >>= 1; /* equivalent to division by 2 */ 1962 ch->mid_futures >>= 1; /* equivalent to division by 2 */
1957 ccc->client_ready = GNUNET_NO; 1963 ccc->client_ready = GNUNET_NO;
1958 GSC_send_to_client(ccc->c, com->env); 1964 GSC_send_to_client (ccc->c, com->env);
1959 GNUNET_free(com); 1965 GNUNET_free (com);
1960 send_channel_data_ack(ch); 1966 send_channel_data_ack (ch);
1961 if (NULL != ccc->head_recv) 1967 if (NULL != ccc->head_recv)
1962 return; 1968 return;
1963 if (GNUNET_NO == ch->destroy) 1969 if (GNUNET_NO == ch->destroy)
1964 return; 1970 return;
1965 GCT_send_channel_destroy(ch->t, ch->ctn); 1971 GCT_send_channel_destroy (ch->t, ch->ctn);
1966 channel_destroy(ch); 1972 channel_destroy (ch);
1967} 1973}
1968 1974
1969 1975
1970#define LOG2(level, ...) \ 1976#define LOG2(level, ...) \
1971 GNUNET_log_from_nocheck(level, "cadet-chn", __VA_ARGS__) 1977 GNUNET_log_from_nocheck (level, "cadet-chn", __VA_ARGS__)
1972 1978
1973 1979
1974/** 1980/**
@@ -1978,46 +1984,46 @@ GCCH_handle_local_ack(struct CadetChannel *ch,
1978 * @param level Debug level to use. 1984 * @param level Debug level to use.
1979 */ 1985 */
1980void 1986void
1981GCCH_debug(struct CadetChannel *ch, enum GNUNET_ErrorType level) 1987GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level)
1982{ 1988{
1983#if !defined(GNUNET_CULL_LOGGING) 1989#if ! defined(GNUNET_CULL_LOGGING)
1984 int do_log; 1990 int do_log;
1985 1991
1986 do_log = GNUNET_get_log_call_status(level & (~GNUNET_ERROR_TYPE_BULK), 1992 do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK),
1987 "cadet-chn", 1993 "cadet-chn",
1988 __FILE__, 1994 __FILE__,
1989 __FUNCTION__, 1995 __FUNCTION__,
1990 __LINE__); 1996 __LINE__);
1991 if (0 == do_log) 1997 if (0 == do_log)
1992 return; 1998 return;
1993 1999
1994 if (NULL == ch) 2000 if (NULL == ch)
1995 { 2001 {
1996 LOG2(level, "CHN *** DEBUG NULL CHANNEL ***\n"); 2002 LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n");
1997 return; 2003 return;
1998 } 2004 }
1999 LOG2(level, "CHN %s:%X (%p)\n", GCT_2s(ch->t), ch->ctn, ch); 2005 LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn, ch);
2000 if (NULL != ch->owner) 2006 if (NULL != ch->owner)
2001 { 2007 {
2002 LOG2(level, 2008 LOG2 (level,
2003 "CHN origin %s ready %s local-id: %u\n", 2009 "CHN origin %s ready %s local-id: %u\n",
2004 GSC_2s(ch->owner->c), 2010 GSC_2s (ch->owner->c),
2005 ch->owner->client_ready ? "YES" : "NO", 2011 ch->owner->client_ready ? "YES" : "NO",
2006 ntohl(ch->owner->ccn.channel_of_client)); 2012 ntohl (ch->owner->ccn.channel_of_client));
2007 } 2013 }
2008 if (NULL != ch->dest) 2014 if (NULL != ch->dest)
2009 { 2015 {
2010 LOG2(level, 2016 LOG2 (level,
2011 "CHN destination %s ready %s local-id: %u\n", 2017 "CHN destination %s ready %s local-id: %u\n",
2012 GSC_2s(ch->dest->c), 2018 GSC_2s (ch->dest->c),
2013 ch->dest->client_ready ? "YES" : "NO", 2019 ch->dest->client_ready ? "YES" : "NO",
2014 ntohl(ch->dest->ccn.channel_of_client)); 2020 ntohl (ch->dest->ccn.channel_of_client));
2015 } 2021 }
2016 LOG2(level, 2022 LOG2 (level,
2017 "CHN Message IDs recv: %d (%LLX), send: %d\n", 2023 "CHN Message IDs recv: %d (%LLX), send: %d\n",
2018 ntohl(ch->mid_recv.mid), 2024 ntohl (ch->mid_recv.mid),
2019 (unsigned long long)ch->mid_futures, 2025 (unsigned long long) ch->mid_futures,
2020 ntohl(ch->mid_send.mid)); 2026 ntohl (ch->mid_send.mid));
2021#endif 2027#endif
2022} 2028}
2023 2029
diff --git a/src/cadet/gnunet-service-cadet_channel.h b/src/cadet/gnunet-service-cadet_channel.h
index a64d4058e..181c6e88b 100644
--- a/src/cadet/gnunet-service-cadet_channel.h
+++ b/src/cadet/gnunet-service-cadet_channel.h
@@ -53,9 +53,9 @@ struct CadetChannel;
53 * @param listener peer that is listining on @a port 53 * @param listener peer that is listining on @a port
54 */ 54 */
55void 55void
56GCCH_hash_port(struct GNUNET_HashCode *h_port, 56GCCH_hash_port (struct GNUNET_HashCode *h_port,
57 const struct GNUNET_HashCode *port, 57 const struct GNUNET_HashCode *port,
58 const struct GNUNET_PeerIdentity *listener); 58 const struct GNUNET_PeerIdentity *listener);
59 59
60 60
61/** 61/**
@@ -66,7 +66,7 @@ GCCH_hash_port(struct GNUNET_HashCode *h_port,
66 * @return Static string with the channel IDs. 66 * @return Static string with the channel IDs.
67 */ 67 */
68const char * 68const char *
69GCCH_2s(const struct CadetChannel *ch); 69GCCH_2s (const struct CadetChannel *ch);
70 70
71 71
72/** 72/**
@@ -76,8 +76,8 @@ GCCH_2s(const struct CadetChannel *ch);
76 * @param level Debug level to use. 76 * @param level Debug level to use.
77 */ 77 */
78void 78void
79GCCH_debug(struct CadetChannel *ch, 79GCCH_debug (struct CadetChannel *ch,
80 enum GNUNET_ErrorType level); 80 enum GNUNET_ErrorType level);
81 81
82 82
83/** 83/**
@@ -88,7 +88,7 @@ GCCH_debug(struct CadetChannel *ch,
88 * @return ID used to identify the channel with the remote peer. 88 * @return ID used to identify the channel with the remote peer.
89 */ 89 */
90struct GNUNET_CADET_ChannelTunnelNumber 90struct GNUNET_CADET_ChannelTunnelNumber
91GCCH_get_id(const struct CadetChannel *ch); 91GCCH_get_id (const struct CadetChannel *ch);
92 92
93 93
94/** 94/**
@@ -102,11 +102,11 @@ GCCH_get_id(const struct CadetChannel *ch);
102 * @return handle to the new channel 102 * @return handle to the new channel
103 */ 103 */
104struct CadetChannel * 104struct CadetChannel *
105GCCH_channel_local_new(struct CadetClient *owner, 105GCCH_channel_local_new (struct CadetClient *owner,
106 struct GNUNET_CADET_ClientChannelNumber owner_id, 106 struct GNUNET_CADET_ClientChannelNumber owner_id,
107 struct CadetPeer *destination, 107 struct CadetPeer *destination,
108 const struct GNUNET_HashCode *port, 108 const struct GNUNET_HashCode *port,
109 uint32_t options); 109 uint32_t options);
110 110
111 111
112/** 112/**
@@ -119,9 +119,9 @@ GCCH_channel_local_new(struct CadetClient *owner,
119 * @param port port number @a c is listening on 119 * @param port port number @a c is listening on
120 */ 120 */
121void 121void
122GCCH_bind(struct CadetChannel *ch, 122GCCH_bind (struct CadetChannel *ch,
123 struct CadetClient *c, 123 struct CadetClient *c,
124 const struct GNUNET_HashCode *port); 124 const struct GNUNET_HashCode *port);
125 125
126 126
127/** 127/**
@@ -133,9 +133,9 @@ GCCH_bind(struct CadetChannel *ch,
133 * @param ccn client number of the client @a c 133 * @param ccn client number of the client @a c
134 */ 134 */
135void 135void
136GCCH_channel_local_destroy(struct CadetChannel *ch, 136GCCH_channel_local_destroy (struct CadetChannel *ch,
137 struct CadetClient *c, 137 struct CadetClient *c,
138 struct GNUNET_CADET_ClientChannelNumber ccn); 138 struct GNUNET_CADET_ClientChannelNumber ccn);
139 139
140 140
141/** 141/**
@@ -149,7 +149,7 @@ GCCH_channel_local_destroy(struct CadetChannel *ch,
149 * @param ch the channel for which the tunnel is now ready 149 * @param ch the channel for which the tunnel is now ready
150 */ 150 */
151void 151void
152GCCH_tunnel_up(struct CadetChannel *ch); 152GCCH_tunnel_up (struct CadetChannel *ch);
153 153
154 154
155/** 155/**
@@ -163,10 +163,10 @@ GCCH_tunnel_up(struct CadetChannel *ch);
163 * @return handle to the new channel 163 * @return handle to the new channel
164 */ 164 */
165struct CadetChannel * 165struct CadetChannel *
166GCCH_channel_incoming_new(struct CadetTunnel *t, 166GCCH_channel_incoming_new (struct CadetTunnel *t,
167 struct GNUNET_CADET_ChannelTunnelNumber chid, 167 struct GNUNET_CADET_ChannelTunnelNumber chid,
168 const struct GNUNET_HashCode *h_port, 168 const struct GNUNET_HashCode *h_port,
169 uint32_t options); 169 uint32_t options);
170 170
171 171
172/** 172/**
@@ -178,8 +178,9 @@ GCCH_channel_incoming_new(struct CadetTunnel *t,
178 * @param cti identifier of the connection that delivered the message 178 * @param cti identifier of the connection that delivered the message
179 */ 179 */
180void 180void
181GCCH_handle_duplicate_open(struct CadetChannel *ch, 181GCCH_handle_duplicate_open (struct CadetChannel *ch,
182 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti); 182 const struct
183 GNUNET_CADET_ConnectionTunnelIdentifier *cti);
183 184
184 185
185 186
@@ -191,9 +192,11 @@ GCCH_handle_duplicate_open(struct CadetChannel *ch,
191 * @param msg message that was received 192 * @param msg message that was received
192 */ 193 */
193void 194void
194GCCH_handle_channel_plaintext_data(struct CadetChannel *ch, 195GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
195 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 196 const struct
196 const struct GNUNET_CADET_ChannelAppDataMessage *msg); 197 GNUNET_CADET_ConnectionTunnelIdentifier *cti,
198 const struct
199 GNUNET_CADET_ChannelAppDataMessage *msg);
197 200
198 201
199/** 202/**
@@ -205,9 +208,12 @@ GCCH_handle_channel_plaintext_data(struct CadetChannel *ch,
205 * @param ack details about what was received 208 * @param ack details about what was received
206 */ 209 */
207void 210void
208GCCH_handle_channel_plaintext_data_ack(struct CadetChannel *ch, 211GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
209 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 212 const struct
210 const struct GNUNET_CADET_ChannelDataAckMessage *ack); 213 GNUNET_CADET_ConnectionTunnelIdentifier
214 *cti,
215 const struct
216 GNUNET_CADET_ChannelDataAckMessage *ack);
211 217
212 218
213/** 219/**
@@ -220,9 +226,10 @@ GCCH_handle_channel_plaintext_data_ack(struct CadetChannel *ch,
220 * @param port port number (needed to verify receiver knows the port) 226 * @param port port number (needed to verify receiver knows the port)
221 */ 227 */
222void 228void
223GCCH_handle_channel_open_ack(struct CadetChannel *ch, 229GCCH_handle_channel_open_ack (struct CadetChannel *ch,
224 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 230 const struct
225 const struct GNUNET_HashCode *port); 231 GNUNET_CADET_ConnectionTunnelIdentifier *cti,
232 const struct GNUNET_HashCode *port);
226 233
227 234
228/** 235/**
@@ -242,8 +249,9 @@ GCCH_handle_channel_open_ack(struct CadetChannel *ch,
242 * NULL during shutdown 249 * NULL during shutdown
243 */ 250 */
244void 251void
245GCCH_handle_remote_destroy(struct CadetChannel *ch, 252GCCH_handle_remote_destroy (struct CadetChannel *ch,
246 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti); 253 const struct
254 GNUNET_CADET_ConnectionTunnelIdentifier *cti);
247 255
248 256
249/** 257/**
@@ -261,10 +269,10 @@ GCCH_handle_remote_destroy(struct CadetChannel *ch,
261 * #GNUNET_SYSERR in case of an error. 269 * #GNUNET_SYSERR in case of an error.
262 */ 270 */
263int 271int
264GCCH_handle_local_data(struct CadetChannel *ch, 272GCCH_handle_local_data (struct CadetChannel *ch,
265 struct GNUNET_CADET_ClientChannelNumber sender_ccn, 273 struct GNUNET_CADET_ClientChannelNumber sender_ccn,
266 const char *buf, 274 const char *buf,
267 size_t buf_len); 275 size_t buf_len);
268 276
269 277
270/** 278/**
@@ -274,7 +282,7 @@ GCCH_handle_local_data(struct CadetChannel *ch,
274 * @param client_ccn ccn of the client sending the ack 282 * @param client_ccn ccn of the client sending the ack
275 */ 283 */
276void 284void
277GCCH_handle_local_ack(struct CadetChannel *ch, 285GCCH_handle_local_ack (struct CadetChannel *ch,
278 struct GNUNET_CADET_ClientChannelNumber client_ccn); 286 struct GNUNET_CADET_ClientChannelNumber client_ccn);
279 287
280#endif 288#endif
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index e3c1a4124..66dc20481 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -35,7 +35,7 @@
35#include "cadet_protocol.h" 35#include "cadet_protocol.h"
36 36
37 37
38#define LOG(level, ...) GNUNET_log_from(level, "cadet-con", __VA_ARGS__) 38#define LOG(level, ...) GNUNET_log_from (level, "cadet-con", __VA_ARGS__)
39 39
40 40
41/** 41/**
@@ -43,13 +43,14 @@
43 * TODO: replace by 2 RTT if/once we have connection-level RTT data! 43 * TODO: replace by 2 RTT if/once we have connection-level RTT data!
44 */ 44 */
45#define INITIAL_CONNECTION_CREATE_RETRY_DELAY \ 45#define INITIAL_CONNECTION_CREATE_RETRY_DELAY \
46 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) 46 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
47 47
48 48
49/** 49/**
50 * All the states a connection can be in. 50 * All the states a connection can be in.
51 */ 51 */
52enum CadetConnectionState { 52enum CadetConnectionState
53{
53 /** 54 /**
54 * Uninitialized status, we have not yet even gotten the message queue. 55 * Uninitialized status, we have not yet even gotten the message queue.
55 */ 56 */
@@ -81,7 +82,8 @@ enum CadetConnectionState {
81/** 82/**
82 * Low-level connection to a destination. 83 * Low-level connection to a destination.
83 */ 84 */
84struct CadetConnection { 85struct CadetConnection
86{
85 /** 87 /**
86 * ID of the connection. 88 * ID of the connection.
87 */ 89 */
@@ -181,10 +183,10 @@ struct CadetConnection {
181 * @return NULL if connection was not found 183 * @return NULL if connection was not found
182 */ 184 */
183struct CadetConnection * 185struct CadetConnection *
184GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) 186GCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
185{ 187{
186 return GNUNET_CONTAINER_multishortmap_get(connections, 188 return GNUNET_CONTAINER_multishortmap_get (connections,
187 &cid->connection_of_tunnel); 189 &cid->connection_of_tunnel);
188} 190}
189 191
190 192
@@ -197,9 +199,9 @@ GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
197 * @param new_mqm_ready new `mqm_ready` state for @a cc 199 * @param new_mqm_ready new `mqm_ready` state for @a cc
198 */ 200 */
199static void 201static void
200update_state(struct CadetConnection *cc, 202update_state (struct CadetConnection *cc,
201 enum CadetConnectionState new_state, 203 enum CadetConnectionState new_state,
202 int new_mqm_ready) 204 int new_mqm_ready)
203{ 205{
204 int old_ready; 206 int old_ready;
205 int new_ready; 207 int new_ready;
@@ -213,7 +215,7 @@ update_state(struct CadetConnection *cc,
213 cc->state = new_state; 215 cc->state = new_state;
214 cc->mqm_ready = new_mqm_ready; 216 cc->mqm_ready = new_mqm_ready;
215 if (old_ready != new_ready) 217 if (old_ready != new_ready)
216 cc->ready_cb(cc->ready_cb_cls, new_ready); 218 cc->ready_cb (cc->ready_cb_cls, new_ready);
217} 219}
218 220
219 221
@@ -224,34 +226,34 @@ update_state(struct CadetConnection *cc,
224 * @param cc connection to destroy 226 * @param cc connection to destroy
225 */ 227 */
226static void 228static void
227GCC_destroy(struct CadetConnection *cc) 229GCC_destroy (struct CadetConnection *cc)
228{ 230{
229 LOG(GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s(cc)); 231 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s (cc));
230 if (NULL != cc->mq_man) 232 if (NULL != cc->mq_man)
231 { 233 {
232 GCP_request_mq_cancel(cc->mq_man, NULL); 234 GCP_request_mq_cancel (cc->mq_man, NULL);
233 cc->mq_man = NULL; 235 cc->mq_man = NULL;
234 } 236 }
235 if (NULL != cc->task) 237 if (NULL != cc->task)
236 { 238 {
237 GNUNET_SCHEDULER_cancel(cc->task); 239 GNUNET_SCHEDULER_cancel (cc->task);
238 cc->task = NULL; 240 cc->task = NULL;
239 } 241 }
240 if (NULL != cc->keepalive_qe) 242 if (NULL != cc->keepalive_qe)
241 { 243 {
242 GCT_send_cancel(cc->keepalive_qe); 244 GCT_send_cancel (cc->keepalive_qe);
243 cc->keepalive_qe = NULL; 245 cc->keepalive_qe = NULL;
244 } 246 }
245 GCPP_del_connection(cc->path, cc->off, cc); 247 GCPP_del_connection (cc->path, cc->off, cc);
246 for (unsigned int i = 0; i < cc->off; i++) 248 for (unsigned int i = 0; i < cc->off; i++)
247 GCP_remove_connection(GCPP_get_peer_at_offset(cc->path, i), cc); 249 GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, i), cc);
248 GNUNET_assert( 250 GNUNET_assert (
249 GNUNET_YES == 251 GNUNET_YES ==
250 GNUNET_CONTAINER_multishortmap_remove(connections, 252 GNUNET_CONTAINER_multishortmap_remove (connections,
251 &GCC_get_id(cc) 253 &GCC_get_id (cc)
252 ->connection_of_tunnel, 254 ->connection_of_tunnel,
253 cc)); 255 cc));
254 GNUNET_free(cc); 256 GNUNET_free (cc);
255} 257}
256 258
257 259
@@ -264,14 +266,14 @@ GCC_destroy(struct CadetConnection *cc)
264 * @param cc connection to destroy 266 * @param cc connection to destroy
265 */ 267 */
266void 268void
267GCC_destroy_without_core(struct CadetConnection *cc) 269GCC_destroy_without_core (struct CadetConnection *cc)
268{ 270{
269 if (NULL != cc->ct) 271 if (NULL != cc->ct)
270 { 272 {
271 GCT_connection_lost(cc->ct); 273 GCT_connection_lost (cc->ct);
272 cc->ct = NULL; 274 cc->ct = NULL;
273 } 275 }
274 GCC_destroy(cc); 276 GCC_destroy (cc);
275} 277}
276 278
277 279
@@ -283,22 +285,22 @@ GCC_destroy_without_core(struct CadetConnection *cc)
283 * @param cc connection to destroy 285 * @param cc connection to destroy
284 */ 286 */
285void 287void
286GCC_destroy_without_tunnel(struct CadetConnection *cc) 288GCC_destroy_without_tunnel (struct CadetConnection *cc)
287{ 289{
288 cc->ct = NULL; 290 cc->ct = NULL;
289 if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man)) 291 if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man))
290 { 292 {
291 struct GNUNET_MQ_Envelope *env; 293 struct GNUNET_MQ_Envelope *env;
292 struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg; 294 struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg;
293 295
294 /* Need to notify next hop that we are down. */ 296 /* Need to notify next hop that we are down. */
295 env = 297 env =
296 GNUNET_MQ_msg(destroy_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); 298 GNUNET_MQ_msg (destroy_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY);
297 destroy_msg->cid = cc->cid; 299 destroy_msg->cid = cc->cid;
298 GCP_request_mq_cancel(cc->mq_man, env); 300 GCP_request_mq_cancel (cc->mq_man, env);
299 cc->mq_man = NULL; 301 cc->mq_man = NULL;
300 } 302 }
301 GCC_destroy(cc); 303 GCC_destroy (cc);
302} 304}
303 305
304 306
@@ -309,7 +311,7 @@ GCC_destroy_without_tunnel(struct CadetConnection *cc)
309 * @return corresponding entry in the tunnel's connection list 311 * @return corresponding entry in the tunnel's connection list
310 */ 312 */
311struct CadetTConnection * 313struct CadetTConnection *
312GCC_get_ct(struct CadetConnection *cc) 314GCC_get_ct (struct CadetConnection *cc)
313{ 315{
314 return cc->ct; 316 return cc->ct;
315} 317}
@@ -322,7 +324,7 @@ GCC_get_ct(struct CadetConnection *cc)
322 * @return the metrics 324 * @return the metrics
323 */ 325 */
324const struct CadetConnectionMetrics * 326const struct CadetConnectionMetrics *
325GCC_get_metrics(struct CadetConnection *cc) 327GCC_get_metrics (struct CadetConnection *cc)
326{ 328{
327 return &cc->metrics; 329 return &cc->metrics;
328} 330}
@@ -335,7 +337,7 @@ GCC_get_metrics(struct CadetConnection *cc)
335 * @param cls the `struct CadetConnection` to keep alive. 337 * @param cls the `struct CadetConnection` to keep alive.
336 */ 338 */
337static void 339static void
338send_keepalive(void *cls); 340send_keepalive (void *cls);
339 341
340 342
341/** 343/**
@@ -347,15 +349,15 @@ send_keepalive(void *cls);
347 * if transmission failed 349 * if transmission failed
348 */ 350 */
349static void 351static void
350keepalive_done(void *cls, 352keepalive_done (void *cls,
351 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) 353 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
352{ 354{
353 struct CadetConnection *cc = cls; 355 struct CadetConnection *cc = cls;
354 356
355 cc->keepalive_qe = NULL; 357 cc->keepalive_qe = NULL;
356 if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task)) 358 if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task))
357 cc->task = 359 cc->task =
358 GNUNET_SCHEDULER_add_delayed(keepalive_period, &send_keepalive, cc); 360 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
359} 361}
360 362
361 363
@@ -366,31 +368,31 @@ keepalive_done(void *cls,
366 * @param cls the `struct CadetConnection` to keep alive. 368 * @param cls the `struct CadetConnection` to keep alive.
367 */ 369 */
368static void 370static void
369send_keepalive(void *cls) 371send_keepalive (void *cls)
370{ 372{
371 struct CadetConnection *cc = cls; 373 struct CadetConnection *cc = cls;
372 struct GNUNET_MessageHeader msg; 374 struct GNUNET_MessageHeader msg;
373 375
374 cc->task = NULL; 376 cc->task = NULL;
375 if (CADET_TUNNEL_KEY_OK != GCT_get_estate(cc->ct->t)) 377 if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t))
376 { 378 {
377 /* Tunnel not yet ready, wait with keepalives... */ 379 /* Tunnel not yet ready, wait with keepalives... */
378 cc->task = 380 cc->task =
379 GNUNET_SCHEDULER_add_delayed(keepalive_period, &send_keepalive, cc); 381 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
380 return; 382 return;
381 } 383 }
382 GNUNET_assert(NULL != cc->ct); 384 GNUNET_assert (NULL != cc->ct);
383 GNUNET_assert(GNUNET_YES == cc->mqm_ready); 385 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
384 GNUNET_assert(NULL == cc->keepalive_qe); 386 GNUNET_assert (NULL == cc->keepalive_qe);
385 LOG(GNUNET_ERROR_TYPE_INFO, 387 LOG (GNUNET_ERROR_TYPE_INFO,
386 "Sending KEEPALIVE on behalf of %s via %s\n", 388 "Sending KEEPALIVE on behalf of %s via %s\n",
387 GCC_2s(cc), 389 GCC_2s (cc),
388 GCT_2s(cc->ct->t)); 390 GCT_2s (cc->ct->t));
389 GNUNET_STATISTICS_update(stats, "# keepalives sent", 1, GNUNET_NO); 391 GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO);
390 msg.size = htons(sizeof(msg)); 392 msg.size = htons (sizeof(msg));
391 msg.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); 393 msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE);
392 394
393 cc->keepalive_qe = GCT_send(cc->ct->t, &msg, &keepalive_done, cc); 395 cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc);
394} 396}
395 397
396 398
@@ -401,11 +403,11 @@ send_keepalive(void *cls)
401 * @param cid connection identifier where we expect an ACK 403 * @param cid connection identifier where we expect an ACK
402 */ 404 */
403void 405void
404GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) 406GCC_ack_expected (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
405{ 407{
406 struct CadetConnection *cc; 408 struct CadetConnection *cc;
407 409
408 cc = GCC_lookup(cid); 410 cc = GCC_lookup (cid);
409 if (NULL == cc) 411 if (NULL == cc)
410 return; /* whopise, connection alredy down? */ 412 return; /* whopise, connection alredy down? */
411 cc->metrics.num_acked_transmissions++; 413 cc->metrics.num_acked_transmissions++;
@@ -421,11 +423,11 @@ GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
421 * may have gotten back to us via a different connection). 423 * may have gotten back to us via a different connection).
422 */ 424 */
423void 425void
424GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) 426GCC_ack_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
425{ 427{
426 struct CadetConnection *cc; 428 struct CadetConnection *cc;
427 429
428 cc = GCC_lookup(cid); 430 cc = GCC_lookup (cid);
429 if (NULL == cc) 431 if (NULL == cc)
430 return; /* whopise, connection alredy down? */ 432 return; /* whopise, connection alredy down? */
431 cc->metrics.num_successes++; 433 cc->metrics.num_successes++;
@@ -441,17 +443,17 @@ GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
441 * @param latency the observed latency 443 * @param latency the observed latency
442 */ 444 */
443void 445void
444GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 446GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
445 struct GNUNET_TIME_Relative latency) 447 struct GNUNET_TIME_Relative latency)
446{ 448{
447 struct CadetConnection *cc; 449 struct CadetConnection *cc;
448 double weight; 450 double weight;
449 double result; 451 double result;
450 452
451 cc = GCC_lookup(cid); 453 cc = GCC_lookup (cid);
452 if (NULL == cc) 454 if (NULL == cc)
453 return; /* whopise, connection alredy down? */ 455 return; /* whopise, connection alredy down? */
454 GNUNET_STATISTICS_update(stats, "# latencies observed", 1, GNUNET_NO); 456 GNUNET_STATISTICS_update (stats, "# latencies observed", 1, GNUNET_NO);
455 cc->latency_datapoints++; 457 cc->latency_datapoints++;
456 if (cc->latency_datapoints >= 7) 458 if (cc->latency_datapoints >= 7)
457 weight = 7.0; 459 weight = 7.0;
@@ -460,10 +462,10 @@ GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
460 /* Compute weighted average, giving at MOST weight 7 to the 462 /* Compute weighted average, giving at MOST weight 7 to the
461 existing values, or less if that value is based on fewer than 7 463 existing values, or less if that value is based on fewer than 7
462 measurements. */ 464 measurements. */
463 result = (weight * cc->metrics.aged_latency.rel_value_us) + 465 result = (weight * cc->metrics.aged_latency.rel_value_us)
464 1.0 * latency.rel_value_us; 466 + 1.0 * latency.rel_value_us;
465 result /= (weight + 1.0); 467 result /= (weight + 1.0);
466 cc->metrics.aged_latency.rel_value_us = (uint64_t)result; 468 cc->metrics.aged_latency.rel_value_us = (uint64_t) result;
467} 469}
468 470
469 471
@@ -475,26 +477,26 @@ GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
475 * @param cc the connection that got the ACK. 477 * @param cc the connection that got the ACK.
476 */ 478 */
477void 479void
478GCC_handle_connection_create_ack(struct CadetConnection *cc) 480GCC_handle_connection_create_ack (struct CadetConnection *cc)
479{ 481{
480 LOG(GNUNET_ERROR_TYPE_DEBUG, 482 LOG (GNUNET_ERROR_TYPE_DEBUG,
481 "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n", 483 "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n",
482 GCC_2s(cc), 484 GCC_2s (cc),
483 cc->state, 485 cc->state,
484 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); 486 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
485 if (CADET_CONNECTION_READY == cc->state) 487 if (CADET_CONNECTION_READY == cc->state)
486 return; /* Duplicate ACK, ignore */ 488 return; /* Duplicate ACK, ignore */
487 if (NULL != cc->task) 489 if (NULL != cc->task)
488 { 490 {
489 GNUNET_SCHEDULER_cancel(cc->task); 491 GNUNET_SCHEDULER_cancel (cc->task);
490 cc->task = NULL; 492 cc->task = NULL;
491 } 493 }
492 cc->metrics.age = GNUNET_TIME_absolute_get(); 494 cc->metrics.age = GNUNET_TIME_absolute_get ();
493 update_state(cc, CADET_CONNECTION_READY, cc->mqm_ready); 495 update_state (cc, CADET_CONNECTION_READY, cc->mqm_ready);
494 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && 496 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
495 (NULL == cc->task)) 497 (NULL == cc->task))
496 cc->task = 498 cc->task =
497 GNUNET_SCHEDULER_add_delayed(keepalive_period, &send_keepalive, cc); 499 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
498} 500}
499 501
500 502
@@ -505,24 +507,24 @@ GCC_handle_connection_create_ack(struct CadetConnection *cc)
505 * @param msg the key exchange message 507 * @param msg the key exchange message
506 */ 508 */
507void 509void
508GCC_handle_kx(struct CadetConnection *cc, 510GCC_handle_kx (struct CadetConnection *cc,
509 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) 511 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
510{ 512{
511 LOG(GNUNET_ERROR_TYPE_DEBUG, 513 LOG (GNUNET_ERROR_TYPE_DEBUG,
512 "Received KX message with ephermal %s on CC %s in state %d\n", 514 "Received KX message with ephermal %s on CC %s in state %d\n",
513 GNUNET_e2s(&msg->ephemeral_key), 515 GNUNET_e2s (&msg->ephemeral_key),
514 GNUNET_sh2s(&cc->cid.connection_of_tunnel), 516 GNUNET_sh2s (&cc->cid.connection_of_tunnel),
515 cc->state); 517 cc->state);
516 if (CADET_CONNECTION_SENT == cc->state) 518 if (CADET_CONNECTION_SENT == cc->state)
517 { 519 {
518 /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine, 520 /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
519 clearly something is working, so pretend we got an ACK. */ 521 clearly something is working, so pretend we got an ACK. */
520 LOG(GNUNET_ERROR_TYPE_DEBUG, 522 LOG (GNUNET_ERROR_TYPE_DEBUG,
521 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n", 523 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
522 GCC_2s(cc)); 524 GCC_2s (cc));
523 GCC_handle_connection_create_ack(cc); 525 GCC_handle_connection_create_ack (cc);
524 } 526 }
525 GCT_handle_kx(cc->ct, msg); 527 GCT_handle_kx (cc->ct, msg);
526} 528}
527 529
528 530
@@ -533,24 +535,24 @@ GCC_handle_kx(struct CadetConnection *cc,
533 * @param msg the key exchange message 535 * @param msg the key exchange message
534 */ 536 */
535void 537void
536GCC_handle_kx_auth(struct CadetConnection *cc, 538GCC_handle_kx_auth (struct CadetConnection *cc,
537 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) 539 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
538{ 540{
539 LOG(GNUNET_ERROR_TYPE_DEBUG, 541 LOG (GNUNET_ERROR_TYPE_DEBUG,
540 "Received KX AUTH message with ephermal %s on CC %s in state %d\n", 542 "Received KX AUTH message with ephermal %s on CC %s in state %d\n",
541 GNUNET_e2s(&msg->kx.ephemeral_key), 543 GNUNET_e2s (&msg->kx.ephemeral_key),
542 GNUNET_sh2s(&cc->cid.connection_of_tunnel), 544 GNUNET_sh2s (&cc->cid.connection_of_tunnel),
543 cc->state); 545 cc->state);
544 if (CADET_CONNECTION_SENT == cc->state) 546 if (CADET_CONNECTION_SENT == cc->state)
545 { 547 {
546 /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine, 548 /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
547 clearly something is working, so pretend we got an ACK. */ 549 clearly something is working, so pretend we got an ACK. */
548 LOG(GNUNET_ERROR_TYPE_DEBUG, 550 LOG (GNUNET_ERROR_TYPE_DEBUG,
549 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n", 551 "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
550 GCC_2s(cc)); 552 GCC_2s (cc));
551 GCC_handle_connection_create_ack(cc); 553 GCC_handle_connection_create_ack (cc);
552 } 554 }
553 GCT_handle_kx_auth(cc->ct, msg); 555 GCT_handle_kx_auth (cc->ct, msg);
554} 556}
555 557
556 558
@@ -561,20 +563,20 @@ GCC_handle_kx_auth(struct CadetConnection *cc,
561 * @param msg the encrypted message to decrypt 563 * @param msg the encrypted message to decrypt
562 */ 564 */
563void 565void
564GCC_handle_encrypted(struct CadetConnection *cc, 566GCC_handle_encrypted (struct CadetConnection *cc,
565 const struct GNUNET_CADET_TunnelEncryptedMessage *msg) 567 const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
566{ 568{
567 if (CADET_CONNECTION_SENT == cc->state) 569 if (CADET_CONNECTION_SENT == cc->state)
568 { 570 {
569 /* We didn't get the CREATE_ACK, but instead got payload. That's fine, 571 /* We didn't get the CREATE_ACK, but instead got payload. That's fine,
570 clearly something is working, so pretend we got an ACK. */ 572 clearly something is working, so pretend we got an ACK. */
571 LOG(GNUNET_ERROR_TYPE_DEBUG, 573 LOG (GNUNET_ERROR_TYPE_DEBUG,
572 "Faking connection ACK for %s due to ENCRYPTED payload\n", 574 "Faking connection ACK for %s due to ENCRYPTED payload\n",
573 GCC_2s(cc)); 575 GCC_2s (cc));
574 GCC_handle_connection_create_ack(cc); 576 GCC_handle_connection_create_ack (cc);
575 } 577 }
576 cc->metrics.last_use = GNUNET_TIME_absolute_get(); 578 cc->metrics.last_use = GNUNET_TIME_absolute_get ();
577 GCT_handle_encrypted(cc->ct, msg); 579 GCT_handle_encrypted (cc->ct, msg);
578} 580}
579 581
580 582
@@ -585,7 +587,7 @@ GCC_handle_encrypted(struct CadetConnection *cc,
585 * @param cls the `struct CadetConnection` to initiate 587 * @param cls the `struct CadetConnection` to initiate
586 */ 588 */
587static void 589static void
588send_create(void *cls) 590send_create (void *cls)
589{ 591{
590 struct CadetConnection *cc = cls; 592 struct CadetConnection *cc = cls;
591 struct GNUNET_CADET_ConnectionCreateMessage *create_msg; 593 struct GNUNET_CADET_ConnectionCreateMessage *create_msg;
@@ -593,27 +595,27 @@ send_create(void *cls)
593 struct GNUNET_MQ_Envelope *env; 595 struct GNUNET_MQ_Envelope *env;
594 596
595 cc->task = NULL; 597 cc->task = NULL;
596 GNUNET_assert(GNUNET_YES == cc->mqm_ready); 598 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
597 env = 599 env =
598 GNUNET_MQ_msg_extra(create_msg, 600 GNUNET_MQ_msg_extra (create_msg,
599 (2 + cc->off) * sizeof(struct GNUNET_PeerIdentity), 601 (2 + cc->off) * sizeof(struct GNUNET_PeerIdentity),
600 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); 602 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE);
601 //TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated 'reliable' bit here that was removed. 603 // TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated 'reliable' bit here that was removed.
602 create_msg->options = 2; 604 create_msg->options = 2;
603 create_msg->cid = cc->cid; 605 create_msg->cid = cc->cid;
604 pids = (struct GNUNET_PeerIdentity *)&create_msg[1]; 606 pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
605 pids[0] = my_full_id; 607 pids[0] = my_full_id;
606 for (unsigned int i = 0; i <= cc->off; i++) 608 for (unsigned int i = 0; i <= cc->off; i++)
607 pids[i + 1] = *GCP_get_id(GCPP_get_peer_at_offset(cc->path, i)); 609 pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, i));
608 LOG(GNUNET_ERROR_TYPE_DEBUG, 610 LOG (GNUNET_ERROR_TYPE_DEBUG,
609 "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", 611 "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n",
610 GCC_2s(cc), 612 GCC_2s (cc),
611 cc->off + 2); 613 cc->off + 2);
612 cc->env = env; 614 cc->env = env;
613 cc->retry_delay = GNUNET_TIME_STD_BACKOFF(cc->retry_delay); 615 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay);
614 cc->create_at = GNUNET_TIME_relative_to_absolute(cc->retry_delay); 616 cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay);
615 update_state(cc, CADET_CONNECTION_SENT, GNUNET_NO); 617 update_state (cc, CADET_CONNECTION_SENT, GNUNET_NO);
616 GCP_send(cc->mq_man, env); 618 GCP_send (cc->mq_man, env);
617} 619}
618 620
619 621
@@ -623,29 +625,29 @@ send_create(void *cls)
623 * @param cls the `struct CadetConnection` to initiate 625 * @param cls the `struct CadetConnection` to initiate
624 */ 626 */
625static void 627static void
626send_create_ack(void *cls) 628send_create_ack (void *cls)
627{ 629{
628 struct CadetConnection *cc = cls; 630 struct CadetConnection *cc = cls;
629 struct GNUNET_CADET_ConnectionCreateAckMessage *ack_msg; 631 struct GNUNET_CADET_ConnectionCreateAckMessage *ack_msg;
630 struct GNUNET_MQ_Envelope *env; 632 struct GNUNET_MQ_Envelope *env;
631 633
632 cc->task = NULL; 634 cc->task = NULL;
633 LOG(GNUNET_ERROR_TYPE_DEBUG, 635 LOG (GNUNET_ERROR_TYPE_DEBUG,
634 "Sending CONNECTION_CREATE_ACK message for %s\n", 636 "Sending CONNECTION_CREATE_ACK message for %s\n",
635 GCC_2s(cc)); 637 GCC_2s (cc));
636 GNUNET_assert(GNUNET_YES == cc->mqm_ready); 638 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
637 env = 639 env =
638 GNUNET_MQ_msg(ack_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); 640 GNUNET_MQ_msg (ack_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK);
639 ack_msg->cid = cc->cid; 641 ack_msg->cid = cc->cid;
640 cc->env = env; 642 cc->env = env;
641 cc->retry_delay = GNUNET_TIME_STD_BACKOFF(cc->retry_delay); 643 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay);
642 cc->create_ack_at = GNUNET_TIME_relative_to_absolute(cc->retry_delay); 644 cc->create_ack_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay);
643 if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) 645 if (CADET_CONNECTION_CREATE_RECEIVED == cc->state)
644 update_state(cc, CADET_CONNECTION_READY, GNUNET_NO); 646 update_state (cc, CADET_CONNECTION_READY, GNUNET_NO);
645 if (CADET_CONNECTION_READY == cc->state) 647 if (CADET_CONNECTION_READY == cc->state)
646 cc->task = 648 cc->task =
647 GNUNET_SCHEDULER_add_delayed(keepalive_period, &send_keepalive, cc); 649 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
648 GCP_send(cc->mq_man, env); 650 GCP_send (cc->mq_man, env);
649} 651}
650 652
651 653
@@ -657,31 +659,31 @@ send_create_ack(void *cls)
657 * @param cc connection that got the duplicate CREATE 659 * @param cc connection that got the duplicate CREATE
658 */ 660 */
659void 661void
660GCC_handle_duplicate_create(struct CadetConnection *cc) 662GCC_handle_duplicate_create (struct CadetConnection *cc)
661{ 663{
662 if (GNUNET_YES == cc->mqm_ready) 664 if (GNUNET_YES == cc->mqm_ready)
663 { 665 {
664 LOG(GNUNET_ERROR_TYPE_DEBUG, 666 LOG (GNUNET_ERROR_TYPE_DEBUG,
665 "Got duplicate CREATE for %s, scheduling another ACK (%s)\n", 667 "Got duplicate CREATE for %s, scheduling another ACK (%s)\n",
666 GCC_2s(cc), 668 GCC_2s (cc),
667 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); 669 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
668 /* Revert back to the state of having only received the 'CREATE', 670 /* Revert back to the state of having only received the 'CREATE',
669 and immediately proceed to send the CREATE_ACK. */ 671 and immediately proceed to send the CREATE_ACK. */
670 update_state(cc, CADET_CONNECTION_CREATE_RECEIVED, cc->mqm_ready); 672 update_state (cc, CADET_CONNECTION_CREATE_RECEIVED, cc->mqm_ready);
671 if (NULL != cc->task) 673 if (NULL != cc->task)
672 GNUNET_SCHEDULER_cancel(cc->task); 674 GNUNET_SCHEDULER_cancel (cc->task);
673 cc->task = 675 cc->task =
674 GNUNET_SCHEDULER_add_at(cc->create_ack_at, &send_create_ack, cc); 676 GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc);
675 } 677 }
676 else 678 else
677 { 679 {
678 /* We are currently sending something else back, which 680 /* We are currently sending something else back, which
679 can only be an ACK or payload, either of which would 681 can only be an ACK or payload, either of which would
680 do. So actually no need to do anything. */ 682 do. So actually no need to do anything. */
681 LOG(GNUNET_ERROR_TYPE_DEBUG, 683 LOG (GNUNET_ERROR_TYPE_DEBUG,
682 "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n", 684 "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n",
683 GCC_2s(cc)); 685 GCC_2s (cc));
684 } 686 }
685} 687}
686 688
687 689
@@ -696,67 +698,67 @@ GCC_handle_duplicate_create(struct CadetConnection *cc)
696 * and the last envelope was discarded 698 * and the last envelope was discarded
697 */ 699 */
698static void 700static void
699manage_first_hop_mq(void *cls, int available) 701manage_first_hop_mq (void *cls, int available)
700{ 702{
701 struct CadetConnection *cc = cls; 703 struct CadetConnection *cc = cls;
702 704
703 if (GNUNET_YES != available) 705 if (GNUNET_YES != available)
706 {
707 /* Connection is down, for now... */
708 LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s (cc));
709 update_state (cc, CADET_CONNECTION_NEW, GNUNET_NO);
710 cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY;
711 if (NULL != cc->task)
704 { 712 {
705 /* Connection is down, for now... */ 713 GNUNET_SCHEDULER_cancel (cc->task);
706 LOG(GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s(cc)); 714 cc->task = NULL;
707 update_state(cc, CADET_CONNECTION_NEW, GNUNET_NO);
708 cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY;
709 if (NULL != cc->task)
710 {
711 GNUNET_SCHEDULER_cancel(cc->task);
712 cc->task = NULL;
713 }
714 return;
715 } 715 }
716 return;
717 }
716 718
717 update_state(cc, cc->state, GNUNET_YES); 719 update_state (cc, cc->state, GNUNET_YES);
718 LOG(GNUNET_ERROR_TYPE_DEBUG, 720 LOG (GNUNET_ERROR_TYPE_DEBUG,
719 "Core MQ for %s became available in state %d\n", 721 "Core MQ for %s became available in state %d\n",
720 GCC_2s(cc), 722 GCC_2s (cc),
721 cc->state); 723 cc->state);
722 switch (cc->state) 724 switch (cc->state)
725 {
726 case CADET_CONNECTION_NEW:
727 /* Transmit immediately */
728 cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc);
729 break;
730
731 case CADET_CONNECTION_SENDING_CREATE:
732 /* Should not be possible to be called in this state. */
733 GNUNET_assert (0);
734 break;
735
736 case CADET_CONNECTION_SENT:
737 /* Retry a bit later... */
738 cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc);
739 break;
740
741 case CADET_CONNECTION_CREATE_RECEIVED:
742 /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */
743 cc->metrics.age = GNUNET_TIME_absolute_get ();
744 cc->task =
745 GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc);
746 break;
747
748 case CADET_CONNECTION_READY:
749 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
750 (NULL == cc->task))
723 { 751 {
724 case CADET_CONNECTION_NEW: 752 LOG (GNUNET_ERROR_TYPE_DEBUG,
725 /* Transmit immediately */ 753 "Scheduling keepalive for %s in %s\n",
726 cc->task = GNUNET_SCHEDULER_add_at(cc->create_at, &send_create, cc); 754 GCC_2s (cc),
727 break; 755 GNUNET_STRINGS_relative_time_to_string (keepalive_period,
728 756 GNUNET_YES));
729 case CADET_CONNECTION_SENDING_CREATE:
730 /* Should not be possible to be called in this state. */
731 GNUNET_assert(0);
732 break;
733
734 case CADET_CONNECTION_SENT:
735 /* Retry a bit later... */
736 cc->task = GNUNET_SCHEDULER_add_at(cc->create_at, &send_create, cc);
737 break;
738
739 case CADET_CONNECTION_CREATE_RECEIVED:
740 /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */
741 cc->metrics.age = GNUNET_TIME_absolute_get();
742 cc->task = 757 cc->task =
743 GNUNET_SCHEDULER_add_at(cc->create_ack_at, &send_create_ack, cc); 758 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
744 break;
745
746 case CADET_CONNECTION_READY:
747 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
748 (NULL == cc->task))
749 {
750 LOG(GNUNET_ERROR_TYPE_DEBUG,
751 "Scheduling keepalive for %s in %s\n",
752 GCC_2s(cc),
753 GNUNET_STRINGS_relative_time_to_string(keepalive_period,
754 GNUNET_YES));
755 cc->task =
756 GNUNET_SCHEDULER_add_delayed(keepalive_period, &send_keepalive, cc);
757 }
758 break;
759 } 759 }
760 break;
761 }
760} 762}
761 763
762 764
@@ -775,44 +777,44 @@ manage_first_hop_mq(void *cls, int available)
775 * @return handle to the connection 777 * @return handle to the connection
776 */ 778 */
777static struct CadetConnection * 779static struct CadetConnection *
778connection_create(struct CadetPeer *destination, 780connection_create (struct CadetPeer *destination,
779 struct CadetPeerPath *path, 781 struct CadetPeerPath *path,
780 unsigned int off, 782 unsigned int off,
781 struct CadetTConnection *ct, 783 struct CadetTConnection *ct,
782 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 784 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
783 enum CadetConnectionState init_state, 785 enum CadetConnectionState init_state,
784 GCC_ReadyCallback ready_cb, 786 GCC_ReadyCallback ready_cb,
785 void *ready_cb_cls) 787 void *ready_cb_cls)
786{ 788{
787 struct CadetConnection *cc; 789 struct CadetConnection *cc;
788 struct CadetPeer *first_hop; 790 struct CadetPeer *first_hop;
789 791
790 cc = GNUNET_new(struct CadetConnection); 792 cc = GNUNET_new (struct CadetConnection);
791 cc->state = init_state; 793 cc->state = init_state;
792 cc->ct = ct; 794 cc->ct = ct;
793 cc->cid = *cid; 795 cc->cid = *cid;
794 cc->retry_delay = 796 cc->retry_delay =
795 GNUNET_TIME_relative_multiply(INITIAL_CONNECTION_CREATE_RETRY_DELAY, off); 797 GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off);
796 GNUNET_assert(GNUNET_OK == 798 GNUNET_assert (GNUNET_OK ==
797 GNUNET_CONTAINER_multishortmap_put( 799 GNUNET_CONTAINER_multishortmap_put (
798 connections, 800 connections,
799 &GCC_get_id(cc)->connection_of_tunnel, 801 &GCC_get_id (cc)->connection_of_tunnel,
800 cc, 802 cc,
801 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 803 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
802 cc->ready_cb = ready_cb; 804 cc->ready_cb = ready_cb;
803 cc->ready_cb_cls = ready_cb_cls; 805 cc->ready_cb_cls = ready_cb_cls;
804 cc->path = path; 806 cc->path = path;
805 cc->off = off; 807 cc->off = off;
806 LOG(GNUNET_ERROR_TYPE_DEBUG, 808 LOG (GNUNET_ERROR_TYPE_DEBUG,
807 "Creating %s using path %s (offset: %u)\n", 809 "Creating %s using path %s (offset: %u)\n",
808 GCC_2s(cc), 810 GCC_2s (cc),
809 GCPP_2s(path), 811 GCPP_2s (path),
810 off); 812 off);
811 GCPP_add_connection(path, off, cc); 813 GCPP_add_connection (path, off, cc);
812 for (unsigned int i = 0; i < off; i++) 814 for (unsigned int i = 0; i < off; i++)
813 GCP_add_connection(GCPP_get_peer_at_offset(path, i), cc); 815 GCP_add_connection (GCPP_get_peer_at_offset (path, i), cc);
814 first_hop = GCPP_get_peer_at_offset(path, 0); 816 first_hop = GCPP_get_peer_at_offset (path, 0);
815 cc->mq_man = GCP_request_mq(first_hop, &manage_first_hop_mq, cc); 817 cc->mq_man = GCP_request_mq (first_hop, &manage_first_hop_mq, cc);
816 return cc; 818 return cc;
817} 819}
818 820
@@ -831,64 +833,64 @@ connection_create(struct CadetPeer *destination,
831 * a connection that takes precedence on @a path 833 * a connection that takes precedence on @a path
832 */ 834 */
833struct CadetConnection * 835struct CadetConnection *
834GCC_create_inbound(struct CadetPeer *destination, 836GCC_create_inbound (struct CadetPeer *destination,
835 struct CadetPeerPath *path, 837 struct CadetPeerPath *path,
836 struct CadetTConnection *ct, 838 struct CadetTConnection *ct,
837 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 839 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
838 GCC_ReadyCallback ready_cb, 840 GCC_ReadyCallback ready_cb,
839 void *ready_cb_cls) 841 void *ready_cb_cls)
840{ 842{
841 struct CadetConnection *cc; 843 struct CadetConnection *cc;
842 unsigned int off; 844 unsigned int off;
843 845
844 off = GCPP_find_peer(path, destination); 846 off = GCPP_find_peer (path, destination);
845 GNUNET_assert(UINT_MAX != off); 847 GNUNET_assert (UINT_MAX != off);
846 cc = GCPP_get_connection(path, destination, off); 848 cc = GCPP_get_connection (path, destination, off);
847 if (NULL != cc) 849 if (NULL != cc)
850 {
851 int cmp;
852
853 cmp = GNUNET_memcmp (cid, &cc->cid);
854 if (0 == cmp)
848 { 855 {
849 int cmp; 856 /* Two peers picked the SAME random connection identifier at the
850 857 same time for the same path? Must be malicious. Drop
851 cmp = GNUNET_memcmp(cid, &cc->cid); 858 connection (existing and inbound), even if it is the only
852 if (0 == cmp) 859 one. */
853 { 860 GNUNET_break_op (0);
854 /* Two peers picked the SAME random connection identifier at the 861 GCT_connection_lost (cc->ct);
855 same time for the same path? Must be malicious. Drop 862 GCC_destroy_without_tunnel (cc);
856 connection (existing and inbound), even if it is the only 863 return NULL;
857 one. */
858 GNUNET_break_op(0);
859 GCT_connection_lost(cc->ct);
860 GCC_destroy_without_tunnel(cc);
861 return NULL;
862 }
863 if (0 < cmp)
864 {
865 /* drop existing */
866 LOG(GNUNET_ERROR_TYPE_DEBUG,
867 "Got two connections on %s, dropping my existing %s\n",
868 GCPP_2s(path),
869 GCC_2s(cc));
870 GCT_connection_lost(cc->ct);
871 GCC_destroy_without_tunnel(cc);
872 }
873 else
874 {
875 /* keep existing */
876 LOG(GNUNET_ERROR_TYPE_DEBUG,
877 "Got two connections on %s, keeping my existing %s\n",
878 GCPP_2s(path),
879 GCC_2s(cc));
880 return NULL;
881 }
882 } 864 }
883 865 if (0 < cmp)
884 return connection_create(destination, 866 {
885 path, 867 /* drop existing */
886 off, 868 LOG (GNUNET_ERROR_TYPE_DEBUG,
887 ct, 869 "Got two connections on %s, dropping my existing %s\n",
888 cid, 870 GCPP_2s (path),
889 CADET_CONNECTION_CREATE_RECEIVED, 871 GCC_2s (cc));
890 ready_cb, 872 GCT_connection_lost (cc->ct);
891 ready_cb_cls); 873 GCC_destroy_without_tunnel (cc);
874 }
875 else
876 {
877 /* keep existing */
878 LOG (GNUNET_ERROR_TYPE_DEBUG,
879 "Got two connections on %s, keeping my existing %s\n",
880 GCPP_2s (path),
881 GCC_2s (cc));
882 return NULL;
883 }
884 }
885
886 return connection_create (destination,
887 path,
888 off,
889 ct,
890 cid,
891 CADET_CONNECTION_CREATE_RECEIVED,
892 ready_cb,
893 ready_cb_cls);
892} 894}
893 895
894 896
@@ -905,24 +907,24 @@ GCC_create_inbound(struct CadetPeer *destination,
905 * @return handle to the connection 907 * @return handle to the connection
906 */ 908 */
907struct CadetConnection * 909struct CadetConnection *
908GCC_create(struct CadetPeer *destination, 910GCC_create (struct CadetPeer *destination,
909 struct CadetPeerPath *path, 911 struct CadetPeerPath *path,
910 unsigned int off, 912 unsigned int off,
911 struct CadetTConnection *ct, 913 struct CadetTConnection *ct,
912 GCC_ReadyCallback ready_cb, 914 GCC_ReadyCallback ready_cb,
913 void *ready_cb_cls) 915 void *ready_cb_cls)
914{ 916{
915 struct GNUNET_CADET_ConnectionTunnelIdentifier cid; 917 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
916 918
917 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof(cid)); 919 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof(cid));
918 return connection_create(destination, 920 return connection_create (destination,
919 path, 921 path,
920 off, 922 off,
921 ct, 923 ct,
922 &cid, 924 &cid,
923 CADET_CONNECTION_NEW, 925 CADET_CONNECTION_NEW,
924 ready_cb, 926 ready_cb,
925 ready_cb_cls); 927 ready_cb_cls);
926} 928}
927 929
928 930
@@ -937,21 +939,21 @@ GCC_create(struct CadetPeer *destination,
937 * yet have a #GNUNET_MQ_notify_sent() callback attached to it 939 * yet have a #GNUNET_MQ_notify_sent() callback attached to it
938 */ 940 */
939void 941void
940GCC_transmit(struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env) 942GCC_transmit (struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
941{ 943{
942 LOG(GNUNET_ERROR_TYPE_DEBUG, 944 LOG (GNUNET_ERROR_TYPE_DEBUG,
943 "Scheduling message for transmission on %s\n", 945 "Scheduling message for transmission on %s\n",
944 GCC_2s(cc)); 946 GCC_2s (cc));
945 GNUNET_assert(GNUNET_YES == cc->mqm_ready); 947 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
946 GNUNET_assert(CADET_CONNECTION_READY == cc->state); 948 GNUNET_assert (CADET_CONNECTION_READY == cc->state);
947 cc->metrics.last_use = GNUNET_TIME_absolute_get(); 949 cc->metrics.last_use = GNUNET_TIME_absolute_get ();
948 cc->mqm_ready = GNUNET_NO; 950 cc->mqm_ready = GNUNET_NO;
949 if (NULL != cc->task) 951 if (NULL != cc->task)
950 { 952 {
951 GNUNET_SCHEDULER_cancel(cc->task); 953 GNUNET_SCHEDULER_cancel (cc->task);
952 cc->task = NULL; 954 cc->task = NULL;
953 } 955 }
954 GCP_send(cc->mq_man, env); 956 GCP_send (cc->mq_man, env);
955} 957}
956 958
957 959
@@ -963,7 +965,7 @@ GCC_transmit(struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
963 * @return path to @a cc 965 * @return path to @a cc
964 */ 966 */
965struct CadetPeerPath * 967struct CadetPeerPath *
966GCC_get_path(struct CadetConnection *cc, unsigned int *off) 968GCC_get_path (struct CadetConnection *cc, unsigned int *off)
967{ 969{
968 *off = cc->off; 970 *off = cc->off;
969 return cc->path; 971 return cc->path;
@@ -977,7 +979,7 @@ GCC_get_path(struct CadetConnection *cc, unsigned int *off)
977 * @return unique number of the connection 979 * @return unique number of the connection
978 */ 980 */
979const struct GNUNET_CADET_ConnectionTunnelIdentifier * 981const struct GNUNET_CADET_ConnectionTunnelIdentifier *
980GCC_get_id(struct CadetConnection *cc) 982GCC_get_id (struct CadetConnection *cc)
981{ 983{
982 return &cc->cid; 984 return &cc->cid;
983} 985}
@@ -989,7 +991,7 @@ GCC_get_id(struct CadetConnection *cc)
989 * @param cc Connection. 991 * @param cc Connection.
990 */ 992 */
991const char * 993const char *
992GCC_2s(const struct CadetConnection *cc) 994GCC_2s (const struct CadetConnection *cc)
993{ 995{
994 static char buf[128]; 996 static char buf[128];
995 997
@@ -997,24 +999,24 @@ GCC_2s(const struct CadetConnection *cc)
997 return "Connection(NULL)"; 999 return "Connection(NULL)";
998 1000
999 if (NULL != cc->ct) 1001 if (NULL != cc->ct)
1000 { 1002 {
1001 GNUNET_snprintf(buf, 1003 GNUNET_snprintf (buf,
1002 sizeof(buf), 1004 sizeof(buf),
1003 "Connection %s (%s)", 1005 "Connection %s (%s)",
1004 GNUNET_sh2s(&cc->cid.connection_of_tunnel), 1006 GNUNET_sh2s (&cc->cid.connection_of_tunnel),
1005 GCT_2s(cc->ct->t)); 1007 GCT_2s (cc->ct->t));
1006 return buf; 1008 return buf;
1007 } 1009 }
1008 GNUNET_snprintf(buf, 1010 GNUNET_snprintf (buf,
1009 sizeof(buf), 1011 sizeof(buf),
1010 "Connection %s", 1012 "Connection %s",
1011 GNUNET_sh2s(&cc->cid.connection_of_tunnel)); 1013 GNUNET_sh2s (&cc->cid.connection_of_tunnel));
1012 return buf; 1014 return buf;
1013} 1015}
1014 1016
1015 1017
1016#define LOG2(level, ...) \ 1018#define LOG2(level, ...) \
1017 GNUNET_log_from_nocheck(level, "cadet-con", __VA_ARGS__) 1019 GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__)
1018 1020
1019 1021
1020/** 1022/**
@@ -1024,30 +1026,30 @@ GCC_2s(const struct CadetConnection *cc)
1024 * @param level Debug level to use. 1026 * @param level Debug level to use.
1025 */ 1027 */
1026void 1028void
1027GCC_debug(struct CadetConnection *cc, enum GNUNET_ErrorType level) 1029GCC_debug (struct CadetConnection *cc, enum GNUNET_ErrorType level)
1028{ 1030{
1029#if !defined(GNUNET_CULL_LOGGING) 1031#if ! defined(GNUNET_CULL_LOGGING)
1030 int do_log; 1032 int do_log;
1031 1033
1032 do_log = GNUNET_get_log_call_status(level & (~GNUNET_ERROR_TYPE_BULK), 1034 do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK),
1033 "cadet-con", 1035 "cadet-con",
1034 __FILE__, 1036 __FILE__,
1035 __FUNCTION__, 1037 __FUNCTION__,
1036 __LINE__); 1038 __LINE__);
1037 if (0 == do_log) 1039 if (0 == do_log)
1038 return; 1040 return;
1039 if (NULL == cc) 1041 if (NULL == cc)
1040 { 1042 {
1041 LOG2(level, "Connection (NULL)\n"); 1043 LOG2 (level, "Connection (NULL)\n");
1042 return; 1044 return;
1043 } 1045 }
1044 LOG2(level, 1046 LOG2 (level,
1045 "%s to %s via path %s in state %d is %s\n", 1047 "%s to %s via path %s in state %d is %s\n",
1046 GCC_2s(cc), 1048 GCC_2s (cc),
1047 GCP_2s(cc->destination), 1049 GCP_2s (cc->destination),
1048 GCPP_2s(cc->path), 1050 GCPP_2s (cc->path),
1049 cc->state, 1051 cc->state,
1050 (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy"); 1052 (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy");
1051#endif 1053#endif
1052} 1054}
1053 1055
diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h
index 47b654cbb..b05c3b72c 100644
--- a/src/cadet/gnunet-service-cadet_connection.h
+++ b/src/cadet/gnunet-service-cadet_connection.h
@@ -57,7 +57,7 @@ typedef void
57 * @param cc connection to destroy 57 * @param cc connection to destroy
58 */ 58 */
59void 59void
60GCC_destroy_without_core(struct CadetConnection *cc); 60GCC_destroy_without_core (struct CadetConnection *cc);
61 61
62 62
63/** 63/**
@@ -68,7 +68,7 @@ GCC_destroy_without_core(struct CadetConnection *cc);
68 * @param cc connection to destroy 68 * @param cc connection to destroy
69 */ 69 */
70void 70void
71GCC_destroy_without_tunnel(struct CadetConnection *cc); 71GCC_destroy_without_tunnel (struct CadetConnection *cc);
72 72
73 73
74/** 74/**
@@ -78,7 +78,7 @@ GCC_destroy_without_tunnel(struct CadetConnection *cc);
78 * @return NULL if connection was not found 78 * @return NULL if connection was not found
79 */ 79 */
80struct CadetConnection * 80struct CadetConnection *
81GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid); 81GCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
82 82
83 83
84/** 84/**
@@ -94,12 +94,12 @@ GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
94 * @return handle to the connection 94 * @return handle to the connection
95 */ 95 */
96struct CadetConnection * 96struct CadetConnection *
97GCC_create(struct CadetPeer *destination, 97GCC_create (struct CadetPeer *destination,
98 struct CadetPeerPath *path, 98 struct CadetPeerPath *path,
99 unsigned int off, 99 unsigned int off,
100 struct CadetTConnection *ct, 100 struct CadetTConnection *ct,
101 GCC_ReadyCallback ready_cb, 101 GCC_ReadyCallback ready_cb,
102 void *ready_cb_cls); 102 void *ready_cb_cls);
103 103
104 104
105/** 105/**
@@ -116,12 +116,12 @@ GCC_create(struct CadetPeer *destination,
116 * a connection that takes precedence on @a path 116 * a connection that takes precedence on @a path
117 */ 117 */
118struct CadetConnection * 118struct CadetConnection *
119GCC_create_inbound(struct CadetPeer *destination, 119GCC_create_inbound (struct CadetPeer *destination,
120 struct CadetPeerPath *path, 120 struct CadetPeerPath *path,
121 struct CadetTConnection *ct, 121 struct CadetTConnection *ct,
122 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 122 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
123 GCC_ReadyCallback ready_cb, 123 GCC_ReadyCallback ready_cb,
124 void *ready_cb_cls); 124 void *ready_cb_cls);
125 125
126 126
127/** 127/**
@@ -137,8 +137,8 @@ GCC_create_inbound(struct CadetPeer *destination,
137 * connection identifier of this connection... 137 * connection identifier of this connection...
138 */ 138 */
139void 139void
140GCC_transmit(struct CadetConnection *cc, 140GCC_transmit (struct CadetConnection *cc,
141 struct GNUNET_MQ_Envelope *env); 141 struct GNUNET_MQ_Envelope *env);
142 142
143 143
144/** 144/**
@@ -147,7 +147,7 @@ GCC_transmit(struct CadetConnection *cc,
147 * @param cc the connection that got the ACK. 147 * @param cc the connection that got the ACK.
148 */ 148 */
149void 149void
150GCC_handle_connection_create_ack(struct CadetConnection *cc); 150GCC_handle_connection_create_ack (struct CadetConnection *cc);
151 151
152 152
153/** 153/**
@@ -158,7 +158,7 @@ GCC_handle_connection_create_ack(struct CadetConnection *cc);
158 * @param cc connection that got the duplicate CREATE 158 * @param cc connection that got the duplicate CREATE
159 */ 159 */
160void 160void
161GCC_handle_duplicate_create(struct CadetConnection *cc); 161GCC_handle_duplicate_create (struct CadetConnection *cc);
162 162
163 163
164/** 164/**
@@ -168,8 +168,8 @@ GCC_handle_duplicate_create(struct CadetConnection *cc);
168 * @param msg the key exchange message 168 * @param msg the key exchange message
169 */ 169 */
170void 170void
171GCC_handle_kx(struct CadetConnection *cc, 171GCC_handle_kx (struct CadetConnection *cc,
172 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg); 172 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
173 173
174 174
175/** 175/**
@@ -179,14 +179,16 @@ GCC_handle_kx(struct CadetConnection *cc,
179 * @param msg the key exchange message 179 * @param msg the key exchange message
180 */ 180 */
181void 181void
182GCC_handle_kx_auth(struct CadetConnection *cc, 182GCC_handle_kx_auth (struct CadetConnection *cc,
183 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg); 183 const struct
184 GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
184 185
185 186
186/** 187/**
187 * Performance metrics for a connection. 188 * Performance metrics for a connection.
188 */ 189 */
189struct CadetConnectionMetrics { 190struct CadetConnectionMetrics
191{
190 /** 192 /**
191 * Our current best estimate of the latency, based on a weighted 193 * Our current best estimate of the latency, based on a weighted
192 * average of at least @a latency_datapoints values. 194 * average of at least @a latency_datapoints values.
@@ -229,7 +231,7 @@ struct CadetConnectionMetrics {
229 * @return the metrics 231 * @return the metrics
230 */ 232 */
231const struct CadetConnectionMetrics * 233const struct CadetConnectionMetrics *
232GCC_get_metrics(struct CadetConnection *cc); 234GCC_get_metrics (struct CadetConnection *cc);
233 235
234 236
235/** 237/**
@@ -239,8 +241,8 @@ GCC_get_metrics(struct CadetConnection *cc);
239 * @param msg the encrypted message to decrypt 241 * @param msg the encrypted message to decrypt
240 */ 242 */
241void 243void
242GCC_handle_encrypted(struct CadetConnection *cc, 244GCC_handle_encrypted (struct CadetConnection *cc,
243 const struct GNUNET_CADET_TunnelEncryptedMessage *msg); 245 const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
244 246
245 247
246/** 248/**
@@ -250,7 +252,7 @@ GCC_handle_encrypted(struct CadetConnection *cc,
250 * @param cid connection identifier where we expect an ACK 252 * @param cid connection identifier where we expect an ACK
251 */ 253 */
252void 254void
253GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid); 255GCC_ack_expected (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
254 256
255 257
256/** 258/**
@@ -262,7 +264,7 @@ GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
262 * may have gotten back to us via a different connection). 264 * may have gotten back to us via a different connection).
263 */ 265 */
264void 266void
265GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid); 267GCC_ack_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
266 268
267 269
268/** 270/**
@@ -274,8 +276,8 @@ GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
274 * @param latency the observed latency 276 * @param latency the observed latency
275 */ 277 */
276void 278void
277GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 279GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
278 struct GNUNET_TIME_Relative latency); 280 struct GNUNET_TIME_Relative latency);
279 281
280 282
281/** 283/**
@@ -285,7 +287,7 @@ GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
285 * @return corresponding entry in the tunnel's connection list 287 * @return corresponding entry in the tunnel's connection list
286 */ 288 */
287struct CadetTConnection * 289struct CadetTConnection *
288GCC_get_ct(struct CadetConnection *cc); 290GCC_get_ct (struct CadetConnection *cc);
289 291
290 292
291/** 293/**
@@ -296,8 +298,8 @@ GCC_get_ct(struct CadetConnection *cc);
296 * @return path to @a cc 298 * @return path to @a cc
297 */ 299 */
298struct CadetPeerPath * 300struct CadetPeerPath *
299GCC_get_path(struct CadetConnection *cc, 301GCC_get_path (struct CadetConnection *cc,
300 unsigned int *off); 302 unsigned int *off);
301 303
302 304
303/** 305/**
@@ -307,7 +309,7 @@ GCC_get_path(struct CadetConnection *cc,
307 * @return unique number of the connection 309 * @return unique number of the connection
308 */ 310 */
309const struct GNUNET_CADET_ConnectionTunnelIdentifier * 311const struct GNUNET_CADET_ConnectionTunnelIdentifier *
310GCC_get_id(struct CadetConnection *cc); 312GCC_get_id (struct CadetConnection *cc);
311 313
312 314
313/** 315/**
@@ -316,7 +318,7 @@ GCC_get_id(struct CadetConnection *cc);
316 * @param cc Connection. 318 * @param cc Connection.
317 */ 319 */
318const char * 320const char *
319GCC_2s(const struct CadetConnection *cc); 321GCC_2s (const struct CadetConnection *cc);
320 322
321 323
322/** 324/**
@@ -326,8 +328,8 @@ GCC_2s(const struct CadetConnection *cc);
326 * @param level Debug level to use. 328 * @param level Debug level to use.
327 */ 329 */
328void 330void
329GCC_debug(struct CadetConnection *cc, 331GCC_debug (struct CadetConnection *cc,
330 enum GNUNET_ErrorType level); 332 enum GNUNET_ErrorType level);
331 333
332 334
333#endif 335#endif
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c
index a08c80aae..7d1791f3c 100644
--- a/src/cadet/gnunet-service-cadet_core.c
+++ b/src/cadet/gnunet-service-cadet_core.c
@@ -39,7 +39,7 @@
39#include "gnunet_statistics_service.h" 39#include "gnunet_statistics_service.h"
40#include "cadet_protocol.h" 40#include "cadet_protocol.h"
41 41
42#define LOG(level, ...) GNUNET_log_from(level, "cadet-cor", __VA_ARGS__) 42#define LOG(level, ...) GNUNET_log_from (level, "cadet-cor", __VA_ARGS__)
43 43
44/** 44/**
45 * Information we keep per direction for a route. 45 * Information we keep per direction for a route.
@@ -52,7 +52,8 @@ struct RouteDirection;
52 * routes that have the current maximum of messages in the buffer (in 52 * routes that have the current maximum of messages in the buffer (in
53 * case we have to purge). 53 * case we have to purge).
54 */ 54 */
55struct Rung { 55struct Rung
56{
56 /** 57 /**
57 * Rung of RouteDirections with one more buffer entry each. 58 * Rung of RouteDirections with one more buffer entry each.
58 */ 59 */
@@ -89,7 +90,8 @@ struct Rung {
89/** 90/**
90 * Information we keep per direction for a route. 91 * Information we keep per direction for a route.
91 */ 92 */
92struct RouteDirection { 93struct RouteDirection
94{
93 /** 95 /**
94 * DLL of other route directions within the same `struct Rung`. 96 * DLL of other route directions within the same `struct Rung`.
95 */ 97 */
@@ -145,7 +147,8 @@ struct RouteDirection {
145 * the complete `struct CadetPath` that is formed by the individual 147 * the complete `struct CadetPath` that is formed by the individual
146 * routes. 148 * routes.
147 */ 149 */
148struct CadetRoute { 150struct CadetRoute
151{
149 /** 152 /**
150 * Information about the next hop on this route. 153 * Information about the next hop on this route.
151 */ 154 */
@@ -231,10 +234,10 @@ static struct GNUNET_SCHEDULER_Task *timeout_task;
231 * @param cid hash generated from the connection identifier 234 * @param cid hash generated from the connection identifier
232 */ 235 */
233static struct CadetRoute * 236static struct CadetRoute *
234get_route(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) 237get_route (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
235{ 238{
236 return GNUNET_CONTAINER_multishortmap_get(routes, 239 return GNUNET_CONTAINER_multishortmap_get (routes,
237 &cid->connection_of_tunnel); 240 &cid->connection_of_tunnel);
238} 241}
239 242
240 243
@@ -244,22 +247,22 @@ get_route(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
244 * @param dir direction to lower in rung. 247 * @param dir direction to lower in rung.
245 */ 248 */
246static void 249static void
247lower_rung(struct RouteDirection *dir) 250lower_rung (struct RouteDirection *dir)
248{ 251{
249 struct Rung *rung = dir->rung; 252 struct Rung *rung = dir->rung;
250 struct Rung *prev; 253 struct Rung *prev;
251 254
252 GNUNET_CONTAINER_DLL_remove(rung->rd_head, rung->rd_tail, dir); 255 GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir);
253 prev = rung->prev; 256 prev = rung->prev;
254 GNUNET_assert(NULL != prev); 257 GNUNET_assert (NULL != prev);
255 if (prev->rung_off != rung->rung_off - 1) 258 if (prev->rung_off != rung->rung_off - 1)
256 { 259 {
257 prev = GNUNET_new(struct Rung); 260 prev = GNUNET_new (struct Rung);
258 prev->rung_off = rung->rung_off - 1; 261 prev->rung_off = rung->rung_off - 1;
259 GNUNET_CONTAINER_DLL_insert_after(rung_head, rung_tail, rung->prev, prev); 262 GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung->prev, prev);
260 } 263 }
261 GNUNET_assert(NULL != prev); 264 GNUNET_assert (NULL != prev);
262 GNUNET_CONTAINER_DLL_insert(prev->rd_head, prev->rd_tail, dir); 265 GNUNET_CONTAINER_DLL_insert (prev->rd_head, prev->rd_tail, dir);
263 dir->rung = prev; 266 dir->rung = prev;
264} 267}
265 268
@@ -272,13 +275,13 @@ lower_rung(struct RouteDirection *dir)
272 * @param env envelope to discard 275 * @param env envelope to discard
273 */ 276 */
274static void 277static void
275discard_buffer(struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env) 278discard_buffer (struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env)
276{ 279{
277 GNUNET_MQ_dll_remove(&dir->env_head, &dir->env_tail, env); 280 GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env);
278 cur_buffers--; 281 cur_buffers--;
279 GNUNET_MQ_discard(env); 282 GNUNET_MQ_discard (env);
280 lower_rung(dir); 283 lower_rung (dir);
281 GNUNET_STATISTICS_set(stats, "# buffer use", cur_buffers, GNUNET_NO); 284 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
282} 285}
283 286
284 287
@@ -286,24 +289,24 @@ discard_buffer(struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env)
286 * Discard all messages from the highest rung, to make space. 289 * Discard all messages from the highest rung, to make space.
287 */ 290 */
288static void 291static void
289discard_all_from_rung_tail() 292discard_all_from_rung_tail ()
290{ 293{
291 struct Rung *tail = rung_tail; 294 struct Rung *tail = rung_tail;
292 struct RouteDirection *dir; 295 struct RouteDirection *dir;
293 296
294 while (NULL != (dir = tail->rd_head)) 297 while (NULL != (dir = tail->rd_head))
295 { 298 {
296 LOG(GNUNET_ERROR_TYPE_DEBUG, 299 LOG (GNUNET_ERROR_TYPE_DEBUG,
297 "Queue full due new message %s on connection %s, dropping old message\n", 300 "Queue full due new message %s on connection %s, dropping old message\n",
298 GNUNET_sh2s(&dir->my_route->cid.connection_of_tunnel)); 301 GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel));
299 GNUNET_STATISTICS_update(stats, 302 GNUNET_STATISTICS_update (stats,
300 "# messages dropped due to full buffer", 303 "# messages dropped due to full buffer",
301 1, 304 1,
302 GNUNET_NO); 305 GNUNET_NO);
303 discard_buffer(dir, dir->env_head); 306 discard_buffer (dir, dir->env_head);
304 } 307 }
305 GNUNET_CONTAINER_DLL_remove(rung_head, rung_tail, tail); 308 GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, tail);
306 GNUNET_free(tail); 309 GNUNET_free (tail);
307} 310}
308 311
309 312
@@ -317,10 +320,10 @@ discard_all_from_rung_tail()
317 * @param msg the message to forward 320 * @param msg the message to forward
318 */ 321 */
319static void 322static void
320route_message(struct CadetPeer *prev, 323route_message (struct CadetPeer *prev,
321 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 324 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
322 const struct GNUNET_MessageHeader *msg, 325 const struct GNUNET_MessageHeader *msg,
323 const enum GNUNET_MQ_PriorityPreferences priority) 326 const enum GNUNET_MQ_PriorityPreferences priority)
324{ 327{
325 struct CadetRoute *route; 328 struct CadetRoute *route;
326 struct RouteDirection *dir; 329 struct RouteDirection *dir;
@@ -328,133 +331,133 @@ route_message(struct CadetPeer *prev,
328 struct Rung *nxt; 331 struct Rung *nxt;
329 struct GNUNET_MQ_Envelope *env; 332 struct GNUNET_MQ_Envelope *env;
330 333
331 route = get_route(cid); 334 route = get_route (cid);
332 if (NULL == route) 335 if (NULL == route)
336 {
337 struct GNUNET_MQ_Envelope *env;
338 struct GNUNET_CADET_ConnectionBrokenMessage *bm;
339
340 LOG (GNUNET_ERROR_TYPE_DEBUG,
341 "Failed to route message of type %u from %s on connection %s: no route\n",
342 ntohs (msg->type),
343 GCP_2s (prev),
344 GNUNET_sh2s (&cid->connection_of_tunnel));
345 switch (ntohs (msg->type))
333 { 346 {
334 struct GNUNET_MQ_Envelope *env; 347 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY:
335 struct GNUNET_CADET_ConnectionBrokenMessage *bm; 348 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN:
336 349 /* No need to respond to these! */
337 LOG(GNUNET_ERROR_TYPE_DEBUG,
338 "Failed to route message of type %u from %s on connection %s: no route\n",
339 ntohs(msg->type),
340 GCP_2s(prev),
341 GNUNET_sh2s(&cid->connection_of_tunnel));
342 switch (ntohs(msg->type))
343 {
344 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY:
345 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN:
346 /* No need to respond to these! */
347 return;
348 }
349 env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
350 bm->cid = *cid;
351 bm->peer1 = my_full_id;
352 GCP_send_ooo(prev, env);
353 return; 350 return;
354 } 351 }
355 route->last_use = GNUNET_TIME_absolute_get(); 352 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
356 GNUNET_CONTAINER_heap_update_cost(route->hn, route->last_use.abs_value_us); 353 bm->cid = *cid;
354 bm->peer1 = my_full_id;
355 GCP_send_ooo (prev, env);
356 return;
357 }
358 route->last_use = GNUNET_TIME_absolute_get ();
359 GNUNET_CONTAINER_heap_update_cost (route->hn, route->last_use.abs_value_us);
357 dir = (prev == route->prev.hop) ? &route->next : &route->prev; 360 dir = (prev == route->prev.hop) ? &route->next : &route->prev;
358 if (GNUNET_YES == dir->is_ready) 361 if (GNUNET_YES == dir->is_ready)
359 { 362 {
360 LOG(GNUNET_ERROR_TYPE_DEBUG, 363 LOG (GNUNET_ERROR_TYPE_DEBUG,
361 "Routing message of type %u from %s to %s on connection %s\n", 364 "Routing message of type %u from %s to %s on connection %s\n",
362 ntohs(msg->type), 365 ntohs (msg->type),
363 GCP_2s(prev), 366 GCP_2s (prev),
364 GNUNET_i2s(GCP_get_id(dir->hop)), 367 GNUNET_i2s (GCP_get_id (dir->hop)),
365 GNUNET_sh2s(&cid->connection_of_tunnel)); 368 GNUNET_sh2s (&cid->connection_of_tunnel));
366 dir->is_ready = GNUNET_NO; 369 dir->is_ready = GNUNET_NO;
367 GCP_send(dir->mqm, GNUNET_MQ_msg_copy(msg)); 370 GCP_send (dir->mqm, GNUNET_MQ_msg_copy (msg));
368 return; 371 return;
369 } 372 }
370 /* Check if low latency is required and if the previous message was 373 /* Check if low latency is required and if the previous message was
371 unreliable; if so, make sure we only queue one message per 374 unreliable; if so, make sure we only queue one message per
372 direction (no buffering). */ 375 direction (no buffering). */
373 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && 376 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) &&
374 (NULL != dir->env_head) && 377 (NULL != dir->env_head) &&
375 (0 == 378 (0 ==
376 (GNUNET_MQ_env_get_options(dir->env_head) & GNUNET_MQ_PREF_UNRELIABLE))) 379 (GNUNET_MQ_env_get_options (dir->env_head) & GNUNET_MQ_PREF_UNRELIABLE)))
377 discard_buffer(dir, dir->env_head); 380 discard_buffer (dir, dir->env_head);
378 /* Check for duplicates */ 381 /* Check for duplicates */
379 for (const struct GNUNET_MQ_Envelope *env = dir->env_head; NULL != env; 382 for (const struct GNUNET_MQ_Envelope *env = dir->env_head; NULL != env;
380 env = GNUNET_MQ_env_next(env)) 383 env = GNUNET_MQ_env_next (env))
384 {
385 const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env);
386
387 if ((hdr->size == msg->size) && (0 == memcmp (hdr, msg, ntohs (msg->size))))
381 { 388 {
382 const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg(env); 389 LOG (GNUNET_ERROR_TYPE_DEBUG,
383 390 "Received duplicate of message already in buffer, dropping\n");
384 if ((hdr->size == msg->size) && (0 == memcmp(hdr, msg, ntohs(msg->size)))) 391 GNUNET_STATISTICS_update (stats,
385 { 392 "# messages dropped due to duplicate in buffer",
386 LOG(GNUNET_ERROR_TYPE_DEBUG, 393 1,
387 "Received duplicate of message already in buffer, dropping\n"); 394 GNUNET_NO);
388 GNUNET_STATISTICS_update(stats, 395 return;
389 "# messages dropped due to duplicate in buffer",
390 1,
391 GNUNET_NO);
392 return;
393 }
394 } 396 }
397 }
395 398
396 rung = dir->rung; 399 rung = dir->rung;
397 if (cur_buffers == max_buffers) 400 if (cur_buffers == max_buffers)
401 {
402 /* Need to make room. */
403 if (NULL != rung->next)
398 { 404 {
399 /* Need to make room. */ 405 /* Easy case, drop messages from route directions in highest rung */
400 if (NULL != rung->next) 406 discard_all_from_rung_tail ();
401 {
402 /* Easy case, drop messages from route directions in highest rung */
403 discard_all_from_rung_tail();
404 }
405 else
406 {
407 /* We are in the highest rung, drop our own! */
408 LOG(GNUNET_ERROR_TYPE_DEBUG,
409 "Queue full due new message %s on connection %s, dropping old message\n",
410 GNUNET_sh2s(&dir->my_route->cid.connection_of_tunnel));
411 GNUNET_STATISTICS_update(stats,
412 "# messages dropped due to full buffer",
413 1,
414 GNUNET_NO);
415 discard_buffer(dir, dir->env_head);
416 rung = dir->rung;
417 }
418 } 407 }
408 else
409 {
410 /* We are in the highest rung, drop our own! */
411 LOG (GNUNET_ERROR_TYPE_DEBUG,
412 "Queue full due new message %s on connection %s, dropping old message\n",
413 GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel));
414 GNUNET_STATISTICS_update (stats,
415 "# messages dropped due to full buffer",
416 1,
417 GNUNET_NO);
418 discard_buffer (dir, dir->env_head);
419 rung = dir->rung;
420 }
421 }
419 /* remove 'dir' from current rung */ 422 /* remove 'dir' from current rung */
420 GNUNET_CONTAINER_DLL_remove(rung->rd_head, rung->rd_tail, dir); 423 GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir);
421 /* make 'nxt' point to the next higher rung, create if necessary */ 424 /* make 'nxt' point to the next higher rung, create if necessary */
422 nxt = rung->next; 425 nxt = rung->next;
423 if ((NULL == nxt) || (rung->rung_off + 1 != nxt->rung_off)) 426 if ((NULL == nxt) || (rung->rung_off + 1 != nxt->rung_off))
424 { 427 {
425 nxt = GNUNET_new(struct Rung); 428 nxt = GNUNET_new (struct Rung);
426 nxt->rung_off = rung->rung_off + 1; 429 nxt->rung_off = rung->rung_off + 1;
427 GNUNET_CONTAINER_DLL_insert_after(rung_head, rung_tail, rung, nxt); 430 GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung, nxt);
428 } 431 }
429 /* insert 'dir' into next higher rung */ 432 /* insert 'dir' into next higher rung */
430 GNUNET_CONTAINER_DLL_insert(nxt->rd_head, nxt->rd_tail, dir); 433 GNUNET_CONTAINER_DLL_insert (nxt->rd_head, nxt->rd_tail, dir);
431 dir->rung = nxt; 434 dir->rung = nxt;
432 435
433 /* add message into 'dir' buffer */ 436 /* add message into 'dir' buffer */
434 LOG(GNUNET_ERROR_TYPE_DEBUG, 437 LOG (GNUNET_ERROR_TYPE_DEBUG,
435 "Queueing new message of type %u from %s to %s on connection %s\n", 438 "Queueing new message of type %u from %s to %s on connection %s\n",
436 ntohs(msg->type), 439 ntohs (msg->type),
437 GCP_2s(prev), 440 GCP_2s (prev),
438 GNUNET_i2s(GCP_get_id(dir->hop)), 441 GNUNET_i2s (GCP_get_id (dir->hop)),
439 GNUNET_sh2s(&cid->connection_of_tunnel)); 442 GNUNET_sh2s (&cid->connection_of_tunnel));
440 env = GNUNET_MQ_msg_copy(msg); 443 env = GNUNET_MQ_msg_copy (msg);
441 GNUNET_MQ_env_set_options(env, priority); 444 GNUNET_MQ_env_set_options (env, priority);
442 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && 445 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) &&
443 (0 != (priority & GNUNET_MQ_PREF_OUT_OF_ORDER)) && 446 (0 != (priority & GNUNET_MQ_PREF_OUT_OF_ORDER)) &&
444 (NULL != dir->env_head) && 447 (NULL != dir->env_head) &&
445 (0 == (GNUNET_MQ_env_get_options(dir->env_head) & 448 (0 == (GNUNET_MQ_env_get_options (dir->env_head)
446 GNUNET_MQ_PREF_LOW_LATENCY))) 449 & GNUNET_MQ_PREF_LOW_LATENCY)))
447 GNUNET_MQ_dll_insert_head(&dir->env_head, &dir->env_tail, env); 450 GNUNET_MQ_dll_insert_head (&dir->env_head, &dir->env_tail, env);
448 else 451 else
449 GNUNET_MQ_dll_insert_tail(&dir->env_head, &dir->env_tail, env); 452 GNUNET_MQ_dll_insert_tail (&dir->env_head, &dir->env_tail, env);
450 cur_buffers++; 453 cur_buffers++;
451 GNUNET_STATISTICS_set(stats, "# buffer use", cur_buffers, GNUNET_NO); 454 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
452 /* Clean up 'rung' if now empty (and not head) */ 455 /* Clean up 'rung' if now empty (and not head) */
453 if ((NULL == rung->rd_head) && (rung != rung_head)) 456 if ((NULL == rung->rd_head) && (rung != rung_head))
454 { 457 {
455 GNUNET_CONTAINER_DLL_remove(rung_head, rung_tail, rung); 458 GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, rung);
456 GNUNET_free(rung); 459 GNUNET_free (rung);
457 } 460 }
458} 461}
459 462
460 463
@@ -467,16 +470,16 @@ route_message(struct CadetPeer *prev,
467 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. 470 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise.
468 */ 471 */
469static int 472static int
470check_connection_create(void *cls, 473check_connection_create (void *cls,
471 const struct GNUNET_CADET_ConnectionCreateMessage *msg) 474 const struct GNUNET_CADET_ConnectionCreateMessage *msg)
472{ 475{
473 uint16_t size = ntohs(msg->header.size) - sizeof(*msg); 476 uint16_t size = ntohs (msg->header.size) - sizeof(*msg);
474 477
475 if (0 != (size % sizeof(struct GNUNET_PeerIdentity))) 478 if (0 != (size % sizeof(struct GNUNET_PeerIdentity)))
476 { 479 {
477 GNUNET_break_op(0); 480 GNUNET_break_op (0);
478 return GNUNET_NO; 481 return GNUNET_NO;
479 } 482 }
480 return GNUNET_YES; 483 return GNUNET_YES;
481} 484}
482 485
@@ -487,24 +490,24 @@ check_connection_create(void *cls,
487 * @param dir direction to destroy (do NOT free memory of 'dir' itself) 490 * @param dir direction to destroy (do NOT free memory of 'dir' itself)
488 */ 491 */
489static void 492static void
490destroy_direction(struct RouteDirection *dir) 493destroy_direction (struct RouteDirection *dir)
491{ 494{
492 struct GNUNET_MQ_Envelope *env; 495 struct GNUNET_MQ_Envelope *env;
493 496
494 while (NULL != (env = dir->env_head)) 497 while (NULL != (env = dir->env_head))
495 { 498 {
496 GNUNET_STATISTICS_update(stats, 499 GNUNET_STATISTICS_update (stats,
497 "# messages dropped due to route destruction", 500 "# messages dropped due to route destruction",
498 1, 501 1,
499 GNUNET_NO); 502 GNUNET_NO);
500 discard_buffer(dir, env); 503 discard_buffer (dir, env);
501 } 504 }
502 if (NULL != dir->mqm) 505 if (NULL != dir->mqm)
503 { 506 {
504 GCP_request_mq_cancel(dir->mqm, NULL); 507 GCP_request_mq_cancel (dir->mqm, NULL);
505 dir->mqm = NULL; 508 dir->mqm = NULL;
506 } 509 }
507 GNUNET_CONTAINER_DLL_remove(rung_head->rd_head, rung_head->rd_tail, dir); 510 GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, rung_head->rd_tail, dir);
508} 511}
509 512
510 513
@@ -514,26 +517,26 @@ destroy_direction(struct RouteDirection *dir)
514 * @param route route to destroy 517 * @param route route to destroy
515 */ 518 */
516static void 519static void
517destroy_route(struct CadetRoute *route) 520destroy_route (struct CadetRoute *route)
518{ 521{
519 LOG(GNUNET_ERROR_TYPE_DEBUG, 522 LOG (GNUNET_ERROR_TYPE_DEBUG,
520 "Destroying route from %s to %s of connection %s\n", 523 "Destroying route from %s to %s of connection %s\n",
521 GNUNET_i2s(GCP_get_id(route->prev.hop)), 524 GNUNET_i2s (GCP_get_id (route->prev.hop)),
522 GNUNET_i2s2(GCP_get_id(route->next.hop)), 525 GNUNET_i2s2 (GCP_get_id (route->next.hop)),
523 GNUNET_sh2s(&route->cid.connection_of_tunnel)); 526 GNUNET_sh2s (&route->cid.connection_of_tunnel));
524 GNUNET_assert(route == GNUNET_CONTAINER_heap_remove_node(route->hn)); 527 GNUNET_assert (route == GNUNET_CONTAINER_heap_remove_node (route->hn));
525 GNUNET_assert( 528 GNUNET_assert (
526 GNUNET_YES == 529 GNUNET_YES ==
527 GNUNET_CONTAINER_multishortmap_remove(routes, 530 GNUNET_CONTAINER_multishortmap_remove (routes,
528 &route->cid.connection_of_tunnel, 531 &route->cid.connection_of_tunnel,
529 route)); 532 route));
530 GNUNET_STATISTICS_set(stats, 533 GNUNET_STATISTICS_set (stats,
531 "# routes", 534 "# routes",
532 GNUNET_CONTAINER_multishortmap_size(routes), 535 GNUNET_CONTAINER_multishortmap_size (routes),
533 GNUNET_NO); 536 GNUNET_NO);
534 destroy_direction(&route->prev); 537 destroy_direction (&route->prev);
535 destroy_direction(&route->next); 538 destroy_direction (&route->next);
536 GNUNET_free(route); 539 GNUNET_free (route);
537} 540}
538 541
539 542
@@ -546,30 +549,30 @@ destroy_route(struct CadetRoute *route)
546 * @param peer2 another one of the peers where a link is broken 549 * @param peer2 another one of the peers where a link is broken
547 */ 550 */
548static void 551static void
549send_broken(struct RouteDirection *target, 552send_broken (struct RouteDirection *target,
550 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 553 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
551 const struct GNUNET_PeerIdentity *peer1, 554 const struct GNUNET_PeerIdentity *peer1,
552 const struct GNUNET_PeerIdentity *peer2) 555 const struct GNUNET_PeerIdentity *peer2)
553{ 556{
554 struct GNUNET_MQ_Envelope *env; 557 struct GNUNET_MQ_Envelope *env;
555 struct GNUNET_CADET_ConnectionBrokenMessage *bm; 558 struct GNUNET_CADET_ConnectionBrokenMessage *bm;
556 559
557 if (NULL == target->mqm) 560 if (NULL == target->mqm)
558 return; /* Can't send notification, connection is down! */ 561 return; /* Can't send notification, connection is down! */
559 LOG(GNUNET_ERROR_TYPE_DEBUG, 562 LOG (GNUNET_ERROR_TYPE_DEBUG,
560 "Notifying %s about BROKEN route at %s-%s of connection %s\n", 563 "Notifying %s about BROKEN route at %s-%s of connection %s\n",
561 GCP_2s(target->hop), 564 GCP_2s (target->hop),
562 GNUNET_i2s(peer1), 565 GNUNET_i2s (peer1),
563 GNUNET_i2s2(peer2), 566 GNUNET_i2s2 (peer2),
564 GNUNET_sh2s(&cid->connection_of_tunnel)); 567 GNUNET_sh2s (&cid->connection_of_tunnel));
565 568
566 env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); 569 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
567 bm->cid = *cid; 570 bm->cid = *cid;
568 if (NULL != peer1) 571 if (NULL != peer1)
569 bm->peer1 = *peer1; 572 bm->peer1 = *peer1;
570 if (NULL != peer2) 573 if (NULL != peer2)
571 bm->peer2 = *peer2; 574 bm->peer2 = *peer2;
572 GCP_request_mq_cancel(target->mqm, env); 575 GCP_request_mq_cancel (target->mqm, env);
573 target->mqm = NULL; 576 target->mqm = NULL;
574} 577}
575 578
@@ -582,31 +585,31 @@ send_broken(struct RouteDirection *target,
582 * @param cls NULL 585 * @param cls NULL
583 */ 586 */
584static void 587static void
585timeout_cb(void *cls) 588timeout_cb (void *cls)
586{ 589{
587 struct CadetRoute *r; 590 struct CadetRoute *r;
588 struct GNUNET_TIME_Relative linger; 591 struct GNUNET_TIME_Relative linger;
589 struct GNUNET_TIME_Absolute exp; 592 struct GNUNET_TIME_Absolute exp;
590 593
591 timeout_task = NULL; 594 timeout_task = NULL;
592 linger = GNUNET_TIME_relative_multiply(keepalive_period, 3); 595 linger = GNUNET_TIME_relative_multiply (keepalive_period, 3);
593 while (NULL != (r = GNUNET_CONTAINER_heap_peek(route_heap))) 596 while (NULL != (r = GNUNET_CONTAINER_heap_peek (route_heap)))
597 {
598 exp = GNUNET_TIME_absolute_add (r->last_use, linger);
599 if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
594 { 600 {
595 exp = GNUNET_TIME_absolute_add(r->last_use, linger); 601 /* Route not yet timed out, wait until it does. */
596 if (0 != GNUNET_TIME_absolute_get_remaining(exp).rel_value_us) 602 timeout_task = GNUNET_SCHEDULER_add_at (exp, &timeout_cb, NULL);
597 { 603 return;
598 /* Route not yet timed out, wait until it does. */
599 timeout_task = GNUNET_SCHEDULER_add_at(exp, &timeout_cb, NULL);
600 return;
601 }
602 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
603 "Sending BROKEN due to timeout (%s was last use, %s linger)\n",
604 GNUNET_STRINGS_absolute_time_to_string(r->last_use),
605 GNUNET_STRINGS_relative_time_to_string(linger, GNUNET_YES));
606 send_broken(&r->prev, &r->cid, NULL, NULL);
607 send_broken(&r->next, &r->cid, NULL, NULL);
608 destroy_route(r);
609 } 604 }
605 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
606 "Sending BROKEN due to timeout (%s was last use, %s linger)\n",
607 GNUNET_STRINGS_absolute_time_to_string (r->last_use),
608 GNUNET_STRINGS_relative_time_to_string (linger, GNUNET_YES));
609 send_broken (&r->prev, &r->cid, NULL, NULL);
610 send_broken (&r->next, &r->cid, NULL, NULL);
611 destroy_route (r);
612 }
610 /* No more routes left, so no need for a #timeout_task */ 613 /* No more routes left, so no need for a #timeout_task */
611} 614}
612 615
@@ -624,32 +627,32 @@ timeout_cb(void *cls)
624 * and the last envelope was discarded 627 * and the last envelope was discarded
625 */ 628 */
626static void 629static void
627dir_ready_cb(void *cls, int ready) 630dir_ready_cb (void *cls, int ready)
628{ 631{
629 struct RouteDirection *dir = cls; 632 struct RouteDirection *dir = cls;
630 struct CadetRoute *route = dir->my_route; 633 struct CadetRoute *route = dir->my_route;
631 struct RouteDirection *odir; 634 struct RouteDirection *odir;
632 635
633 if (GNUNET_YES == ready) 636 if (GNUNET_YES == ready)
637 {
638 struct GNUNET_MQ_Envelope *env;
639
640 dir->is_ready = GNUNET_YES;
641 if (NULL != (env = dir->env_head))
634 { 642 {
635 struct GNUNET_MQ_Envelope *env; 643 GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env);
636 644 cur_buffers--;
637 dir->is_ready = GNUNET_YES; 645 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
638 if (NULL != (env = dir->env_head)) 646 lower_rung (dir);
639 { 647 dir->is_ready = GNUNET_NO;
640 GNUNET_MQ_dll_remove(&dir->env_head, &dir->env_tail, env); 648 GCP_send (dir->mqm, env);
641 cur_buffers--;
642 GNUNET_STATISTICS_set(stats, "# buffer use", cur_buffers, GNUNET_NO);
643 lower_rung(dir);
644 dir->is_ready = GNUNET_NO;
645 GCP_send(dir->mqm, env);
646 }
647 return;
648 } 649 }
650 return;
651 }
649 odir = (dir == &route->next) ? &route->prev : &route->next; 652 odir = (dir == &route->next) ? &route->prev : &route->next;
650 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending BROKEN due to MQ going down\n"); 653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending BROKEN due to MQ going down\n");
651 send_broken(&route->next, &route->cid, GCP_get_id(odir->hop), &my_full_id); 654 send_broken (&route->next, &route->cid, GCP_get_id (odir->hop), &my_full_id);
652 destroy_route(route); 655 destroy_route (route);
653} 656}
654 657
655 658
@@ -661,16 +664,16 @@ dir_ready_cb(void *cls, int ready)
661 * @param hop next hop on in the @a dir 664 * @param hop next hop on in the @a dir
662 */ 665 */
663static void 666static void
664dir_init(struct RouteDirection *dir, 667dir_init (struct RouteDirection *dir,
665 struct CadetRoute *route, 668 struct CadetRoute *route,
666 struct CadetPeer *hop) 669 struct CadetPeer *hop)
667{ 670{
668 dir->hop = hop; 671 dir->hop = hop;
669 dir->my_route = route; 672 dir->my_route = route;
670 dir->mqm = GCP_request_mq(hop, &dir_ready_cb, dir); 673 dir->mqm = GCP_request_mq (hop, &dir_ready_cb, dir);
671 GNUNET_CONTAINER_DLL_insert(rung_head->rd_head, rung_head->rd_tail, dir); 674 GNUNET_CONTAINER_DLL_insert (rung_head->rd_head, rung_head->rd_tail, dir);
672 dir->rung = rung_head; 675 dir->rung = rung_head;
673 GNUNET_assert(GNUNET_YES == dir->is_ready); 676 GNUNET_assert (GNUNET_YES == dir->is_ready);
674} 677}
675 678
676 679
@@ -685,7 +688,7 @@ dir_init(struct RouteDirection *dir,
685 * or NULL. 688 * or NULL.
686 */ 689 */
687static void 690static void
688send_broken_without_mqm( 691send_broken_without_mqm (
689 struct CadetPeer *target, 692 struct CadetPeer *target,
690 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 693 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
691 const struct GNUNET_PeerIdentity *failure_at) 694 const struct GNUNET_PeerIdentity *failure_at)
@@ -693,12 +696,12 @@ send_broken_without_mqm(
693 struct GNUNET_MQ_Envelope *env; 696 struct GNUNET_MQ_Envelope *env;
694 struct GNUNET_CADET_ConnectionBrokenMessage *bm; 697 struct GNUNET_CADET_ConnectionBrokenMessage *bm;
695 698
696 env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); 699 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
697 bm->cid = *cid; 700 bm->cid = *cid;
698 bm->peer1 = my_full_id; 701 bm->peer1 = my_full_id;
699 if (NULL != failure_at) 702 if (NULL != failure_at)
700 bm->peer2 = *failure_at; 703 bm->peer2 = *failure_at;
701 GCP_send_ooo(target, env); 704 GCP_send_ooo (target, env);
702} 705}
703 706
704 707
@@ -709,193 +712,194 @@ send_broken_without_mqm(
709 * @param msg Message itself. 712 * @param msg Message itself.
710 */ 713 */
711static void 714static void
712handle_connection_create( 715handle_connection_create (
713 void *cls, 716 void *cls,
714 const struct GNUNET_CADET_ConnectionCreateMessage *msg) 717 const struct GNUNET_CADET_ConnectionCreateMessage *msg)
715{ 718{
716 struct CadetPeer *sender = cls; 719 struct CadetPeer *sender = cls;
717 struct CadetPeer *next; 720 struct CadetPeer *next;
718 const struct GNUNET_PeerIdentity *pids = 721 const struct GNUNET_PeerIdentity *pids =
719 (const struct GNUNET_PeerIdentity *)&msg[1]; 722 (const struct GNUNET_PeerIdentity *) &msg[1];
720 struct CadetRoute *route; 723 struct CadetRoute *route;
721 uint16_t size = ntohs(msg->header.size) - sizeof(*msg); 724 uint16_t size = ntohs (msg->header.size) - sizeof(*msg);
722 unsigned int path_length; 725 unsigned int path_length;
723 unsigned int off; 726 unsigned int off;
724 727
725 path_length = size / sizeof(struct GNUNET_PeerIdentity); 728 path_length = size / sizeof(struct GNUNET_PeerIdentity);
726 if (0 == path_length) 729 if (0 == path_length)
727 { 730 {
728 LOG(GNUNET_ERROR_TYPE_DEBUG, 731 LOG (GNUNET_ERROR_TYPE_DEBUG,
729 "Dropping CADET_CONNECTION_CREATE with empty path\n"); 732 "Dropping CADET_CONNECTION_CREATE with empty path\n");
730 GNUNET_break_op(0); 733 GNUNET_break_op (0);
731 return; 734 return;
732 } 735 }
733 LOG(GNUNET_ERROR_TYPE_DEBUG, 736 LOG (GNUNET_ERROR_TYPE_DEBUG,
734 "Handling CADET_CONNECTION_CREATE from %s for CID %s with %u hops\n", 737 "Handling CADET_CONNECTION_CREATE from %s for CID %s with %u hops\n",
735 GCP_2s(sender), 738 GCP_2s (sender),
736 GNUNET_sh2s(&msg->cid.connection_of_tunnel), 739 GNUNET_sh2s (&msg->cid.connection_of_tunnel),
737 path_length); 740 path_length);
738 /* Check for loops */ 741 /* Check for loops */
739 { 742 {
740 struct GNUNET_CONTAINER_MultiPeerMap *map; 743 struct GNUNET_CONTAINER_MultiPeerMap *map;
741 744
742 map = GNUNET_CONTAINER_multipeermap_create(path_length * 2, GNUNET_YES); 745 map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, GNUNET_YES);
743 GNUNET_assert(NULL != map); 746 GNUNET_assert (NULL != map);
744 for (unsigned int i = 0; i < path_length; i++) 747 for (unsigned int i = 0; i < path_length; i++)
748 {
749 LOG (GNUNET_ERROR_TYPE_DEBUG,
750 "CADET_CONNECTION_CREATE has peer %s at offset %u\n",
751 GNUNET_i2s (&pids[i]),
752 i);
753 if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (
754 map,
755 &pids[i],
756 NULL,
757 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
745 { 758 {
746 LOG(GNUNET_ERROR_TYPE_DEBUG, 759 /* bogus request */
747 "CADET_CONNECTION_CREATE has peer %s at offset %u\n", 760 GNUNET_CONTAINER_multipeermap_destroy (map);
748 GNUNET_i2s(&pids[i]), 761 LOG (GNUNET_ERROR_TYPE_DEBUG,
749 i); 762 "Dropping CADET_CONNECTION_CREATE with cyclic path\n");
750 if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put( 763 GNUNET_break_op (0);
751 map, 764 return;
752 &pids[i],
753 NULL,
754 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
755 {
756 /* bogus request */
757 GNUNET_CONTAINER_multipeermap_destroy(map);
758 LOG(GNUNET_ERROR_TYPE_DEBUG,
759 "Dropping CADET_CONNECTION_CREATE with cyclic path\n");
760 GNUNET_break_op(0);
761 return;
762 }
763 } 765 }
764 GNUNET_CONTAINER_multipeermap_destroy(map); 766 }
767 GNUNET_CONTAINER_multipeermap_destroy (map);
765 } 768 }
766 /* Initiator is at offset 0, find us */ 769 /* Initiator is at offset 0, find us */
767 for (off = 1; off < path_length; off++) 770 for (off = 1; off < path_length; off++)
768 if (0 == GNUNET_memcmp(&my_full_id, &pids[off])) 771 if (0 == GNUNET_memcmp (&my_full_id, &pids[off]))
769 break; 772 break;
770 if (off == path_length) 773 if (off == path_length)
771 { 774 {
772 LOG(GNUNET_ERROR_TYPE_DEBUG, 775 LOG (GNUNET_ERROR_TYPE_DEBUG,
773 "Dropping CADET_CONNECTION_CREATE without us in the path\n"); 776 "Dropping CADET_CONNECTION_CREATE without us in the path\n");
774 GNUNET_break_op(0); 777 GNUNET_break_op (0);
775 return; 778 return;
776 } 779 }
777 /* Check previous hop */ 780 /* Check previous hop */
778 if (sender != GCP_get(&pids[off - 1], GNUNET_NO)) 781 if (sender != GCP_get (&pids[off - 1], GNUNET_NO))
779 { 782 {
780 LOG(GNUNET_ERROR_TYPE_DEBUG, 783 LOG (GNUNET_ERROR_TYPE_DEBUG,
781 "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n"); 784 "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n");
782 GNUNET_break_op(0); 785 GNUNET_break_op (0);
783 return; 786 return;
784 } 787 }
785 if (NULL != (route = get_route(&msg->cid))) 788 if (NULL != (route = get_route (&msg->cid)))
786 { 789 {
787 /* Duplicate CREATE, pass it on, previous one might have been lost! */ 790 /* Duplicate CREATE, pass it on, previous one might have been lost! */
788 791
789 LOG(GNUNET_ERROR_TYPE_DEBUG, 792 LOG (GNUNET_ERROR_TYPE_DEBUG,
790 "Passing on duplicate CADET_CONNECTION_CREATE message on connection %s\n", 793 "Passing on duplicate CADET_CONNECTION_CREATE message on connection %s\n",
791 GNUNET_sh2s(&msg->cid.connection_of_tunnel)); 794 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
792 route_message(sender, 795 route_message (sender,
793 &msg->cid, 796 &msg->cid,
794 &msg->header, 797 &msg->header,
795 GNUNET_MQ_PRIO_CRITICAL_CONTROL | 798 GNUNET_MQ_PRIO_CRITICAL_CONTROL
796 GNUNET_MQ_PREF_LOW_LATENCY); 799 | GNUNET_MQ_PREF_LOW_LATENCY);
797 return; 800 return;
798 } 801 }
799 if (off == path_length - 1) 802 if (off == path_length - 1)
803 {
804 /* We are the destination, create connection */
805 struct CadetConnection *cc;
806 struct CadetPeerPath *path;
807 struct CadetPeer *origin;
808
809 cc = GCC_lookup (&msg->cid);
810 if (NULL != cc)
800 { 811 {
801 /* We are the destination, create connection */ 812 LOG (GNUNET_ERROR_TYPE_DEBUG,
802 struct CadetConnection *cc; 813 "Received duplicate CADET_CONNECTION_CREATE message on connection %s\n",
803 struct CadetPeerPath *path; 814 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
804 struct CadetPeer *origin; 815 GCC_handle_duplicate_create (cc);
805
806 cc = GCC_lookup(&msg->cid);
807 if (NULL != cc)
808 {
809 LOG(GNUNET_ERROR_TYPE_DEBUG,
810 "Received duplicate CADET_CONNECTION_CREATE message on connection %s\n",
811 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
812 GCC_handle_duplicate_create(cc);
813 return;
814 }
815
816 origin = GCP_get(&pids[0], GNUNET_YES);
817 LOG(GNUNET_ERROR_TYPE_DEBUG,
818 "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n",
819 GCP_2s(origin),
820 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
821 path = GCPP_get_path_from_route(path_length - 1, pids);
822 if (GNUNET_OK !=
823 GCT_add_inbound_connection(GCP_get_tunnel(origin, GNUNET_YES),
824 &msg->cid,
825 path))
826 {
827 /* Send back BROKEN: duplicate connection on the same path,
828 we will use the other one. */
829 LOG(GNUNET_ERROR_TYPE_DEBUG,
830 "Received CADET_CONNECTION_CREATE from %s for %s, but %s already has a connection. Sending BROKEN\n",
831 GCP_2s(sender),
832 GNUNET_sh2s(&msg->cid.connection_of_tunnel),
833 GCPP_2s(path));
834 send_broken_without_mqm(sender, &msg->cid, NULL);
835 return;
836 }
837 return;
838 }
839 /* We are merely a hop on the way, check if we can support the route */
840 next = GCP_get(&pids[off + 1], GNUNET_NO);
841 if ((NULL == next) || (GNUNET_NO == GCP_has_core_connection(next)))
842 {
843 /* unworkable, send back BROKEN notification */
844 LOG(GNUNET_ERROR_TYPE_DEBUG,
845 "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is down. Sending BROKEN\n",
846 GCP_2s(sender),
847 GNUNET_sh2s(&msg->cid.connection_of_tunnel),
848 GNUNET_i2s(&pids[off + 1]),
849 off + 1);
850 send_broken_without_mqm(sender, &msg->cid, &pids[off + 1]);
851 return; 816 return;
852 } 817 }
853 if (max_routes <= GNUNET_CONTAINER_multishortmap_size(routes)) 818
819 origin = GCP_get (&pids[0], GNUNET_YES);
820 LOG (GNUNET_ERROR_TYPE_DEBUG,
821 "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n",
822 GCP_2s (origin),
823 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
824 path = GCPP_get_path_from_route (path_length - 1, pids);
825 if (GNUNET_OK !=
826 GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES),
827 &msg->cid,
828 path))
854 { 829 {
855 LOG(GNUNET_ERROR_TYPE_DEBUG, 830 /* Send back BROKEN: duplicate connection on the same path,
856 "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n", 831 we will use the other one. */
857 GCP_2s(sender), 832 LOG (GNUNET_ERROR_TYPE_DEBUG,
858 GNUNET_sh2s(&msg->cid.connection_of_tunnel)); 833 "Received CADET_CONNECTION_CREATE from %s for %s, but %s already has a connection. Sending BROKEN\n",
859 send_broken_without_mqm(sender, &msg->cid, &pids[off - 1]); 834 GCP_2s (sender),
835 GNUNET_sh2s (&msg->cid.connection_of_tunnel),
836 GCPP_2s (path));
837 send_broken_without_mqm (sender, &msg->cid, NULL);
860 return; 838 return;
861 } 839 }
840 return;
841 }
842 /* We are merely a hop on the way, check if we can support the route */
843 next = GCP_get (&pids[off + 1], GNUNET_NO);
844 if ((NULL == next) || (GNUNET_NO == GCP_has_core_connection (next)))
845 {
846 /* unworkable, send back BROKEN notification */
847 LOG (GNUNET_ERROR_TYPE_DEBUG,
848 "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is down. Sending BROKEN\n",
849 GCP_2s (sender),
850 GNUNET_sh2s (&msg->cid.connection_of_tunnel),
851 GNUNET_i2s (&pids[off + 1]),
852 off + 1);
853 send_broken_without_mqm (sender, &msg->cid, &pids[off + 1]);
854 return;
855 }
856 if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes))
857 {
858 LOG (GNUNET_ERROR_TYPE_DEBUG,
859 "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n",
860 GCP_2s (sender),
861 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
862 send_broken_without_mqm (sender, &msg->cid, &pids[off - 1]);
863 return;
864 }
862 865
863 /* Workable route, create routing entry */ 866 /* Workable route, create routing entry */
864 LOG(GNUNET_ERROR_TYPE_DEBUG, 867 LOG (GNUNET_ERROR_TYPE_DEBUG,
865 "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is up. Creating route\n", 868 "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is up. Creating route\n",
866 GCP_2s(sender), 869 GCP_2s (sender),
867 GNUNET_sh2s(&msg->cid.connection_of_tunnel), 870 GNUNET_sh2s (&msg->cid.connection_of_tunnel),
868 GNUNET_i2s(&pids[off + 1]), 871 GNUNET_i2s (&pids[off + 1]),
869 off + 1); 872 off + 1);
870 route = GNUNET_new(struct CadetRoute); 873 route = GNUNET_new (struct CadetRoute);
871 route->cid = msg->cid; 874 route->cid = msg->cid;
872 route->last_use = GNUNET_TIME_absolute_get(); 875 route->last_use = GNUNET_TIME_absolute_get ();
873 dir_init(&route->prev, route, sender); 876 dir_init (&route->prev, route, sender);
874 dir_init(&route->next, route, next); 877 dir_init (&route->next, route, next);
875 GNUNET_assert(GNUNET_OK == 878 GNUNET_assert (GNUNET_OK ==
876 GNUNET_CONTAINER_multishortmap_put( 879 GNUNET_CONTAINER_multishortmap_put (
877 routes, 880 routes,
878 &route->cid.connection_of_tunnel, 881 &route->cid.connection_of_tunnel,
879 route, 882 route,
880 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 883 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
881 GNUNET_STATISTICS_set(stats, 884 GNUNET_STATISTICS_set (stats,
882 "# routes", 885 "# routes",
883 GNUNET_CONTAINER_multishortmap_size(routes), 886 GNUNET_CONTAINER_multishortmap_size (routes),
884 GNUNET_NO); 887 GNUNET_NO);
885 route->hn = GNUNET_CONTAINER_heap_insert(route_heap, 888 route->hn = GNUNET_CONTAINER_heap_insert (route_heap,
886 route, 889 route,
887 route->last_use.abs_value_us); 890 route->last_use.abs_value_us);
888 if (NULL == timeout_task) 891 if (NULL == timeout_task)
889 timeout_task = 892 timeout_task =
890 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(keepalive_period, 893 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
891 3), 894 keepalive_period,
892 &timeout_cb, 895 3),
893 NULL); 896 &timeout_cb,
897 NULL);
894 /* also pass CREATE message along to next hop */ 898 /* also pass CREATE message along to next hop */
895 route_message(sender, 899 route_message (sender,
896 &msg->cid, 900 &msg->cid,
897 &msg->header, 901 &msg->header,
898 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); 902 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
899} 903}
900 904
901 905
@@ -906,7 +910,7 @@ handle_connection_create(
906 * @param msg Message itself. 910 * @param msg Message itself.
907 */ 911 */
908static void 912static void
909handle_connection_create_ack( 913handle_connection_create_ack (
910 void *cls, 914 void *cls,
911 const struct GNUNET_CADET_ConnectionCreateAckMessage *msg) 915 const struct GNUNET_CADET_ConnectionCreateAckMessage *msg)
912{ 916{
@@ -914,31 +918,31 @@ handle_connection_create_ack(
914 struct CadetConnection *cc; 918 struct CadetConnection *cc;
915 919
916 /* First, check if ACK belongs to a connection that ends here. */ 920 /* First, check if ACK belongs to a connection that ends here. */
917 cc = GCC_lookup(&msg->cid); 921 cc = GCC_lookup (&msg->cid);
918 if (NULL != cc) 922 if (NULL != cc)
923 {
924 /* verify ACK came from the right direction */
925 unsigned int len;
926 struct CadetPeerPath *path = GCC_get_path (cc, &len);
927
928 if (peer != GCPP_get_peer_at_offset (path, 0))
919 { 929 {
920 /* verify ACK came from the right direction */ 930 /* received ACK from unexpected direction, ignore! */
921 unsigned int len; 931 GNUNET_break_op (0);
922 struct CadetPeerPath *path = GCC_get_path(cc, &len);
923
924 if (peer != GCPP_get_peer_at_offset(path, 0))
925 {
926 /* received ACK from unexpected direction, ignore! */
927 GNUNET_break_op(0);
928 return;
929 }
930 LOG(GNUNET_ERROR_TYPE_DEBUG,
931 "Received CONNECTION_CREATE_ACK for connection %s.\n",
932 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
933 GCC_handle_connection_create_ack(cc);
934 return; 932 return;
935 } 933 }
934 LOG (GNUNET_ERROR_TYPE_DEBUG,
935 "Received CONNECTION_CREATE_ACK for connection %s.\n",
936 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
937 GCC_handle_connection_create_ack (cc);
938 return;
939 }
936 940
937 /* We're just an intermediary peer, route the message along its path */ 941 /* We're just an intermediary peer, route the message along its path */
938 route_message(peer, 942 route_message (peer,
939 &msg->cid, 943 &msg->cid,
940 &msg->header, 944 &msg->header,
941 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); 945 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
942} 946}
943 947
944 948
@@ -950,7 +954,7 @@ handle_connection_create_ack(
950 * @deprecated duplicate logic with #handle_destroy(); dedup! 954 * @deprecated duplicate logic with #handle_destroy(); dedup!
951 */ 955 */
952static void 956static void
953handle_connection_broken( 957handle_connection_broken (
954 void *cls, 958 void *cls,
955 const struct GNUNET_CADET_ConnectionBrokenMessage *msg) 959 const struct GNUNET_CADET_ConnectionBrokenMessage *msg)
956{ 960{
@@ -959,36 +963,36 @@ handle_connection_broken(
959 struct CadetRoute *route; 963 struct CadetRoute *route;
960 964
961 /* First, check if message belongs to a connection that ends here. */ 965 /* First, check if message belongs to a connection that ends here. */
962 cc = GCC_lookup(&msg->cid); 966 cc = GCC_lookup (&msg->cid);
963 if (NULL != cc) 967 if (NULL != cc)
968 {
969 /* verify message came from the right direction */
970 unsigned int len;
971 struct CadetPeerPath *path = GCC_get_path (cc, &len);
972
973 if (peer != GCPP_get_peer_at_offset (path, 0))
964 { 974 {
965 /* verify message came from the right direction */ 975 /* received message from unexpected direction, ignore! */
966 unsigned int len; 976 GNUNET_break_op (0);
967 struct CadetPeerPath *path = GCC_get_path(cc, &len);
968
969 if (peer != GCPP_get_peer_at_offset(path, 0))
970 {
971 /* received message from unexpected direction, ignore! */
972 GNUNET_break_op(0);
973 return;
974 }
975 LOG(GNUNET_ERROR_TYPE_DEBUG,
976 "Received CONNECTION_BROKEN for connection %s. Destroying it.\n",
977 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
978 GCC_destroy_without_core(cc);
979
980 /* FIXME: also destroy the path up to the specified link! */
981 return; 977 return;
982 } 978 }
979 LOG (GNUNET_ERROR_TYPE_DEBUG,
980 "Received CONNECTION_BROKEN for connection %s. Destroying it.\n",
981 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
982 GCC_destroy_without_core (cc);
983
984 /* FIXME: also destroy the path up to the specified link! */
985 return;
986 }
983 987
984 /* We're just an intermediary peer, route the message along its path */ 988 /* We're just an intermediary peer, route the message along its path */
985 route_message(peer, 989 route_message (peer,
986 &msg->cid, 990 &msg->cid,
987 &msg->header, 991 &msg->header,
988 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); 992 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
989 route = get_route(&msg->cid); 993 route = get_route (&msg->cid);
990 if (NULL != route) 994 if (NULL != route)
991 destroy_route(route); 995 destroy_route (route);
992 /* FIXME: also destroy paths we MAY have up to the specified link! */ 996 /* FIXME: also destroy paths we MAY have up to the specified link! */
993} 997}
994 998
@@ -1000,7 +1004,7 @@ handle_connection_broken(
1000 * @param msg Message itself. 1004 * @param msg Message itself.
1001 */ 1005 */
1002static void 1006static void
1003handle_connection_destroy( 1007handle_connection_destroy (
1004 void *cls, 1008 void *cls,
1005 const struct GNUNET_CADET_ConnectionDestroyMessage *msg) 1009 const struct GNUNET_CADET_ConnectionDestroyMessage *msg)
1006{ 1010{
@@ -1009,38 +1013,38 @@ handle_connection_destroy(
1009 struct CadetRoute *route; 1013 struct CadetRoute *route;
1010 1014
1011 /* First, check if message belongs to a connection that ends here. */ 1015 /* First, check if message belongs to a connection that ends here. */
1012 cc = GCC_lookup(&msg->cid); 1016 cc = GCC_lookup (&msg->cid);
1013 if (NULL != cc) 1017 if (NULL != cc)
1018 {
1019 /* verify message came from the right direction */
1020 unsigned int len;
1021 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1022
1023 if (peer != GCPP_get_peer_at_offset (path, 0))
1014 { 1024 {
1015 /* verify message came from the right direction */ 1025 /* received message from unexpected direction, ignore! */
1016 unsigned int len; 1026 GNUNET_break_op (0);
1017 struct CadetPeerPath *path = GCC_get_path(cc, &len);
1018
1019 if (peer != GCPP_get_peer_at_offset(path, 0))
1020 {
1021 /* received message from unexpected direction, ignore! */
1022 GNUNET_break_op(0);
1023 return;
1024 }
1025 LOG(GNUNET_ERROR_TYPE_DEBUG,
1026 "Received CONNECTION_DESTROY for connection %s. Destroying connection.\n",
1027 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
1028
1029 GCC_destroy_without_core(cc);
1030 return; 1027 return;
1031 } 1028 }
1029 LOG (GNUNET_ERROR_TYPE_DEBUG,
1030 "Received CONNECTION_DESTROY for connection %s. Destroying connection.\n",
1031 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
1032
1033 GCC_destroy_without_core (cc);
1034 return;
1035 }
1032 1036
1033 /* We're just an intermediary peer, route the message along its path */ 1037 /* We're just an intermediary peer, route the message along its path */
1034 LOG(GNUNET_ERROR_TYPE_DEBUG, 1038 LOG (GNUNET_ERROR_TYPE_DEBUG,
1035 "Received CONNECTION_DESTROY for connection %s. Destroying route.\n", 1039 "Received CONNECTION_DESTROY for connection %s. Destroying route.\n",
1036 GNUNET_sh2s(&msg->cid.connection_of_tunnel)); 1040 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
1037 route_message(peer, 1041 route_message (peer,
1038 &msg->cid, 1042 &msg->cid,
1039 &msg->header, 1043 &msg->header,
1040 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); 1044 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
1041 route = get_route(&msg->cid); 1045 route = get_route (&msg->cid);
1042 if (NULL != route) 1046 if (NULL != route)
1043 destroy_route(route); 1047 destroy_route (route);
1044} 1048}
1045 1049
1046 1050
@@ -1051,41 +1055,41 @@ handle_connection_destroy(
1051 * @param msg Message itself. 1055 * @param msg Message itself.
1052 */ 1056 */
1053static void 1057static void
1054handle_tunnel_kx(void *cls, 1058handle_tunnel_kx (void *cls,
1055 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) 1059 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
1056{ 1060{
1057 struct CadetPeer *peer = cls; 1061 struct CadetPeer *peer = cls;
1058 struct CadetConnection *cc; 1062 struct CadetConnection *cc;
1059 1063
1060 /* First, check if message belongs to a connection that ends here. */ 1064 /* First, check if message belongs to a connection that ends here. */
1061 LOG(GNUNET_ERROR_TYPE_DEBUG, 1065 LOG (GNUNET_ERROR_TYPE_DEBUG,
1062 "Routing KX with ephemeral %s on CID %s\n", 1066 "Routing KX with ephemeral %s on CID %s\n",
1063 GNUNET_e2s(&msg->ephemeral_key), 1067 GNUNET_e2s (&msg->ephemeral_key),
1064 GNUNET_sh2s(&msg->cid.connection_of_tunnel)); 1068 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
1065 1069
1066 1070
1067 cc = GCC_lookup(&msg->cid); 1071 cc = GCC_lookup (&msg->cid);
1068 if (NULL != cc) 1072 if (NULL != cc)
1073 {
1074 /* verify message came from the right direction */
1075 unsigned int len;
1076 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1077
1078 if (peer != GCPP_get_peer_at_offset (path, 0))
1069 { 1079 {
1070 /* verify message came from the right direction */ 1080 /* received message from unexpected direction, ignore! */
1071 unsigned int len; 1081 GNUNET_break_op (0);
1072 struct CadetPeerPath *path = GCC_get_path(cc, &len);
1073
1074 if (peer != GCPP_get_peer_at_offset(path, 0))
1075 {
1076 /* received message from unexpected direction, ignore! */
1077 GNUNET_break_op(0);
1078 return;
1079 }
1080 GCC_handle_kx(cc, msg);
1081 return; 1082 return;
1082 } 1083 }
1084 GCC_handle_kx (cc, msg);
1085 return;
1086 }
1083 1087
1084 /* We're just an intermediary peer, route the message along its path */ 1088 /* We're just an intermediary peer, route the message along its path */
1085 route_message(peer, 1089 route_message (peer,
1086 &msg->cid, 1090 &msg->cid,
1087 &msg->header, 1091 &msg->header,
1088 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); 1092 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
1089} 1093}
1090 1094
1091 1095
@@ -1096,7 +1100,7 @@ handle_tunnel_kx(void *cls,
1096 * @param msg Message itself. 1100 * @param msg Message itself.
1097 */ 1101 */
1098static void 1102static void
1099handle_tunnel_kx_auth( 1103handle_tunnel_kx_auth (
1100 void *cls, 1104 void *cls,
1101 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) 1105 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
1102{ 1106{
@@ -1104,28 +1108,28 @@ handle_tunnel_kx_auth(
1104 struct CadetConnection *cc; 1108 struct CadetConnection *cc;
1105 1109
1106 /* First, check if message belongs to a connection that ends here. */ 1110 /* First, check if message belongs to a connection that ends here. */
1107 cc = GCC_lookup(&msg->kx.cid); 1111 cc = GCC_lookup (&msg->kx.cid);
1108 if (NULL != cc) 1112 if (NULL != cc)
1113 {
1114 /* verify message came from the right direction */
1115 unsigned int len;
1116 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1117
1118 if (peer != GCPP_get_peer_at_offset (path, 0))
1109 { 1119 {
1110 /* verify message came from the right direction */ 1120 /* received message from unexpected direction, ignore! */
1111 unsigned int len; 1121 GNUNET_break_op (0);
1112 struct CadetPeerPath *path = GCC_get_path(cc, &len);
1113
1114 if (peer != GCPP_get_peer_at_offset(path, 0))
1115 {
1116 /* received message from unexpected direction, ignore! */
1117 GNUNET_break_op(0);
1118 return;
1119 }
1120 GCC_handle_kx_auth(cc, msg);
1121 return; 1122 return;
1122 } 1123 }
1124 GCC_handle_kx_auth (cc, msg);
1125 return;
1126 }
1123 1127
1124 /* We're just an intermediary peer, route the message along its path */ 1128 /* We're just an intermediary peer, route the message along its path */
1125 route_message(peer, 1129 route_message (peer,
1126 &msg->kx.cid, 1130 &msg->kx.cid,
1127 &msg->kx.header, 1131 &msg->kx.header,
1128 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); 1132 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
1129} 1133}
1130 1134
1131 1135
@@ -1138,8 +1142,8 @@ handle_tunnel_kx_auth(
1138 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. 1142 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise.
1139 */ 1143 */
1140static int 1144static int
1141check_tunnel_encrypted(void *cls, 1145check_tunnel_encrypted (void *cls,
1142 const struct GNUNET_CADET_TunnelEncryptedMessage *msg) 1146 const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
1143{ 1147{
1144 return GNUNET_YES; 1148 return GNUNET_YES;
1145} 1149}
@@ -1152,31 +1156,31 @@ check_tunnel_encrypted(void *cls,
1152 * @param msg Message itself. 1156 * @param msg Message itself.
1153 */ 1157 */
1154static void 1158static void
1155handle_tunnel_encrypted(void *cls, 1159handle_tunnel_encrypted (void *cls,
1156 const struct GNUNET_CADET_TunnelEncryptedMessage *msg) 1160 const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
1157{ 1161{
1158 struct CadetPeer *peer = cls; 1162 struct CadetPeer *peer = cls;
1159 struct CadetConnection *cc; 1163 struct CadetConnection *cc;
1160 1164
1161 /* First, check if message belongs to a connection that ends here. */ 1165 /* First, check if message belongs to a connection that ends here. */
1162 cc = GCC_lookup(&msg->cid); 1166 cc = GCC_lookup (&msg->cid);
1163 if (NULL != cc) 1167 if (NULL != cc)
1168 {
1169 /* verify message came from the right direction */
1170 unsigned int len;
1171 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1172
1173 if (peer != GCPP_get_peer_at_offset (path, 0))
1164 { 1174 {
1165 /* verify message came from the right direction */ 1175 /* received message from unexpected direction, ignore! */
1166 unsigned int len; 1176 GNUNET_break_op (0);
1167 struct CadetPeerPath *path = GCC_get_path(cc, &len);
1168
1169 if (peer != GCPP_get_peer_at_offset(path, 0))
1170 {
1171 /* received message from unexpected direction, ignore! */
1172 GNUNET_break_op(0);
1173 return;
1174 }
1175 GCC_handle_encrypted(cc, msg);
1176 return; 1177 return;
1177 } 1178 }
1179 GCC_handle_encrypted (cc, msg);
1180 return;
1181 }
1178 /* We're just an intermediary peer, route the message along its path */ 1182 /* We're just an intermediary peer, route the message along its path */
1179 route_message(peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT); 1183 route_message (peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT);
1180} 1184}
1181 1185
1182 1186
@@ -1193,14 +1197,14 @@ handle_tunnel_encrypted(void *cls,
1193 * @param my_identity ID of this peer, NULL if we failed 1197 * @param my_identity ID of this peer, NULL if we failed
1194 */ 1198 */
1195static void 1199static void
1196core_init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity) 1200core_init_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
1197{ 1201{
1198 if (NULL == my_identity) 1202 if (NULL == my_identity)
1199 { 1203 {
1200 GNUNET_break(0); 1204 GNUNET_break (0);
1201 return; 1205 return;
1202 } 1206 }
1203 GNUNET_break(0 == GNUNET_memcmp(my_identity, &my_full_id)); 1207 GNUNET_break (0 == GNUNET_memcmp (my_identity, &my_full_id));
1204} 1208}
1205 1209
1206 1210
@@ -1211,17 +1215,17 @@ core_init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)
1211 * @param peer peer identity this notification is about 1215 * @param peer peer identity this notification is about
1212 */ 1216 */
1213static void * 1217static void *
1214core_connect_cb(void *cls, 1218core_connect_cb (void *cls,
1215 const struct GNUNET_PeerIdentity *peer, 1219 const struct GNUNET_PeerIdentity *peer,
1216 struct GNUNET_MQ_Handle *mq) 1220 struct GNUNET_MQ_Handle *mq)
1217{ 1221{
1218 struct CadetPeer *cp; 1222 struct CadetPeer *cp;
1219 1223
1220 LOG(GNUNET_ERROR_TYPE_DEBUG, 1224 LOG (GNUNET_ERROR_TYPE_DEBUG,
1221 "CORE connection to peer %s was established.\n", 1225 "CORE connection to peer %s was established.\n",
1222 GNUNET_i2s(peer)); 1226 GNUNET_i2s (peer));
1223 cp = GCP_get(peer, GNUNET_YES); 1227 cp = GCP_get (peer, GNUNET_YES);
1224 GCP_set_mq(cp, mq); 1228 GCP_set_mq (cp, mq);
1225 return cp; 1229 return cp;
1226} 1230}
1227 1231
@@ -1233,16 +1237,16 @@ core_connect_cb(void *cls,
1233 * @param peer peer identity this notification is about 1237 * @param peer peer identity this notification is about
1234 */ 1238 */
1235static void 1239static void
1236core_disconnect_cb(void *cls, 1240core_disconnect_cb (void *cls,
1237 const struct GNUNET_PeerIdentity *peer, 1241 const struct GNUNET_PeerIdentity *peer,
1238 void *peer_cls) 1242 void *peer_cls)
1239{ 1243{
1240 struct CadetPeer *cp = peer_cls; 1244 struct CadetPeer *cp = peer_cls;
1241 1245
1242 LOG(GNUNET_ERROR_TYPE_DEBUG, 1246 LOG (GNUNET_ERROR_TYPE_DEBUG,
1243 "CORE connection to peer %s went down.\n", 1247 "CORE connection to peer %s went down.\n",
1244 GNUNET_i2s(peer)); 1248 GNUNET_i2s (peer));
1245 GCP_set_mq(cp, NULL); 1249 GCP_set_mq (cp, NULL);
1246} 1250}
1247 1251
1248 1252
@@ -1252,57 +1256,57 @@ core_disconnect_cb(void *cls,
1252 * @param c Configuration. 1256 * @param c Configuration.
1253 */ 1257 */
1254void 1258void
1255GCO_init(const struct GNUNET_CONFIGURATION_Handle *c) 1259GCO_init (const struct GNUNET_CONFIGURATION_Handle *c)
1256{ 1260{
1257 struct GNUNET_MQ_MessageHandler handlers[] = 1261 struct GNUNET_MQ_MessageHandler handlers[] =
1258 { GNUNET_MQ_hd_var_size(connection_create, 1262 { GNUNET_MQ_hd_var_size (connection_create,
1259 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, 1263 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE,
1260 struct GNUNET_CADET_ConnectionCreateMessage, 1264 struct GNUNET_CADET_ConnectionCreateMessage,
1261 NULL), 1265 NULL),
1262 GNUNET_MQ_hd_fixed_size(connection_create_ack, 1266 GNUNET_MQ_hd_fixed_size (connection_create_ack,
1263 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, 1267 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK,
1264 struct GNUNET_CADET_ConnectionCreateAckMessage, 1268 struct GNUNET_CADET_ConnectionCreateAckMessage,
1265 NULL), 1269 NULL),
1266 GNUNET_MQ_hd_fixed_size(connection_broken, 1270 GNUNET_MQ_hd_fixed_size (connection_broken,
1267 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, 1271 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN,
1268 struct GNUNET_CADET_ConnectionBrokenMessage, 1272 struct GNUNET_CADET_ConnectionBrokenMessage,
1269 NULL), 1273 NULL),
1270 GNUNET_MQ_hd_fixed_size(connection_destroy, 1274 GNUNET_MQ_hd_fixed_size (connection_destroy,
1271 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, 1275 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY,
1272 struct GNUNET_CADET_ConnectionDestroyMessage, 1276 struct GNUNET_CADET_ConnectionDestroyMessage,
1273 NULL), 1277 NULL),
1274 GNUNET_MQ_hd_fixed_size(tunnel_kx, 1278 GNUNET_MQ_hd_fixed_size (tunnel_kx,
1275 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX, 1279 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX,
1276 struct GNUNET_CADET_TunnelKeyExchangeMessage, 1280 struct GNUNET_CADET_TunnelKeyExchangeMessage,
1277 NULL), 1281 NULL),
1278 GNUNET_MQ_hd_fixed_size(tunnel_kx_auth, 1282 GNUNET_MQ_hd_fixed_size (tunnel_kx_auth,
1279 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH, 1283 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH,
1280 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage, 1284 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage,
1281 NULL), 1285 NULL),
1282 GNUNET_MQ_hd_var_size(tunnel_encrypted, 1286 GNUNET_MQ_hd_var_size (tunnel_encrypted,
1283 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED, 1287 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED,
1284 struct GNUNET_CADET_TunnelEncryptedMessage, 1288 struct GNUNET_CADET_TunnelEncryptedMessage,
1285 NULL), 1289 NULL),
1286 GNUNET_MQ_handler_end() }; 1290 GNUNET_MQ_handler_end () };
1287 1291
1288 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(c, 1292 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c,
1289 "CADET", 1293 "CADET",
1290 "MAX_ROUTES", 1294 "MAX_ROUTES",
1291 &max_routes)) 1295 &max_routes))
1292 max_routes = 5000; 1296 max_routes = 5000;
1293 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(c, 1297 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c,
1294 "CADET", 1298 "CADET",
1295 "MAX_MSGS_QUEUE", 1299 "MAX_MSGS_QUEUE",
1296 &max_buffers)) 1300 &max_buffers))
1297 max_buffers = 10000; 1301 max_buffers = 10000;
1298 routes = GNUNET_CONTAINER_multishortmap_create(1024, GNUNET_NO); 1302 routes = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_NO);
1299 route_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 1303 route_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1300 core = GNUNET_CORE_connect(c, 1304 core = GNUNET_CORE_connect (c,
1301 NULL, 1305 NULL,
1302 &core_init_cb, 1306 &core_init_cb,
1303 &core_connect_cb, 1307 &core_connect_cb,
1304 &core_disconnect_cb, 1308 &core_disconnect_cb,
1305 handlers); 1309 handlers);
1306} 1310}
1307 1311
1308 1312
@@ -1310,23 +1314,23 @@ GCO_init(const struct GNUNET_CONFIGURATION_Handle *c)
1310 * Shut down the CORE subsystem. 1314 * Shut down the CORE subsystem.
1311 */ 1315 */
1312void 1316void
1313GCO_shutdown() 1317GCO_shutdown ()
1314{ 1318{
1315 if (NULL != core) 1319 if (NULL != core)
1316 { 1320 {
1317 GNUNET_CORE_disconnect(core); 1321 GNUNET_CORE_disconnect (core);
1318 core = NULL; 1322 core = NULL;
1319 } 1323 }
1320 GNUNET_assert(0 == GNUNET_CONTAINER_multishortmap_size(routes)); 1324 GNUNET_assert (0 == GNUNET_CONTAINER_multishortmap_size (routes));
1321 GNUNET_CONTAINER_multishortmap_destroy(routes); 1325 GNUNET_CONTAINER_multishortmap_destroy (routes);
1322 routes = NULL; 1326 routes = NULL;
1323 GNUNET_CONTAINER_heap_destroy(route_heap); 1327 GNUNET_CONTAINER_heap_destroy (route_heap);
1324 route_heap = NULL; 1328 route_heap = NULL;
1325 if (NULL != timeout_task) 1329 if (NULL != timeout_task)
1326 { 1330 {
1327 GNUNET_SCHEDULER_cancel(timeout_task); 1331 GNUNET_SCHEDULER_cancel (timeout_task);
1328 timeout_task = NULL; 1332 timeout_task = NULL;
1329 } 1333 }
1330} 1334}
1331 1335
1332/* end of gnunet-cadet-service_core.c */ 1336/* end of gnunet-cadet-service_core.c */
diff --git a/src/cadet/gnunet-service-cadet_core.h b/src/cadet/gnunet-service-cadet_core.h
index b049dc2af..3438dcb31 100644
--- a/src/cadet/gnunet-service-cadet_core.h
+++ b/src/cadet/gnunet-service-cadet_core.h
@@ -47,14 +47,14 @@ extern "C"
47 * @param c Configuration. 47 * @param c Configuration.
48 */ 48 */
49void 49void
50GCO_init(const struct GNUNET_CONFIGURATION_Handle *c); 50GCO_init (const struct GNUNET_CONFIGURATION_Handle *c);
51 51
52 52
53/** 53/**
54 * Shut down the CORE subsystem. 54 * Shut down the CORE subsystem.
55 */ 55 */
56void 56void
57GCO_shutdown(void); 57GCO_shutdown (void);
58 58
59 59
60#if 0 /* keep Emacsens' auto-indent happy */ 60#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/cadet/gnunet-service-cadet_dht.c b/src/cadet/gnunet-service-cadet_dht.c
index c208c7f29..3bb86cae4 100644
--- a/src/cadet/gnunet-service-cadet_dht.c
+++ b/src/cadet/gnunet-service-cadet_dht.c
@@ -40,23 +40,26 @@
40 * notifications when our HELLO is ready, so this is just the maximum 40 * notifications when our HELLO is ready, so this is just the maximum
41 * we wait for the first notification. 41 * we wait for the first notification.
42 */ 42 */
43#define STARTUP_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) 43#define STARTUP_DELAY GNUNET_TIME_relative_multiply ( \
44 GNUNET_TIME_UNIT_MILLISECONDS, 500)
44 45
45/** 46/**
46 * How long do we wait after we get an updated HELLO before publishing? 47 * How long do we wait after we get an updated HELLO before publishing?
47 * Allows for the HELLO to be updated again quickly, for example in 48 * Allows for the HELLO to be updated again quickly, for example in
48 * case multiple addresses changed and we got a partial update. 49 * case multiple addresses changed and we got a partial update.
49 */ 50 */
50#define CHANGE_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100) 51#define CHANGE_DELAY GNUNET_TIME_relative_multiply ( \
52 GNUNET_TIME_UNIT_MILLISECONDS, 100)
51 53
52 54
53#define LOG(level, ...) GNUNET_log_from(level, "cadet-dht", __VA_ARGS__) 55#define LOG(level, ...) GNUNET_log_from (level, "cadet-dht", __VA_ARGS__)
54 56
55 57
56/** 58/**
57 * Handle for DHT searches. 59 * Handle for DHT searches.
58 */ 60 */
59struct GCD_search_handle { 61struct GCD_search_handle
62{
60 /** 63 /**
61 * DHT_GET handle. 64 * DHT_GET handle.
62 */ 65 */
@@ -107,35 +110,35 @@ static struct GNUNET_TIME_Relative announce_delay;
107 * @param data pointer to the result data 110 * @param data pointer to the result data
108 */ 111 */
109static void 112static void
110dht_get_id_handler(void *cls, struct GNUNET_TIME_Absolute exp, 113dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
111 const struct GNUNET_HashCode *key, 114 const struct GNUNET_HashCode *key,
112 const struct GNUNET_PeerIdentity *get_path, 115 const struct GNUNET_PeerIdentity *get_path,
113 unsigned int get_path_length, 116 unsigned int get_path_length,
114 const struct GNUNET_PeerIdentity *put_path, 117 const struct GNUNET_PeerIdentity *put_path,
115 unsigned int put_path_length, 118 unsigned int put_path_length,
116 enum GNUNET_BLOCK_Type type, 119 enum GNUNET_BLOCK_Type type,
117 size_t size, 120 size_t size,
118 const void *data) 121 const void *data)
119{ 122{
120 const struct GNUNET_HELLO_Message *hello = data; 123 const struct GNUNET_HELLO_Message *hello = data;
121 struct CadetPeer *peer; 124 struct CadetPeer *peer;
122 125
123 GCPP_try_path_from_dht(get_path, 126 GCPP_try_path_from_dht (get_path,
124 get_path_length, 127 get_path_length,
125 put_path, 128 put_path,
126 put_path_length); 129 put_path_length);
127 if ((size >= sizeof(struct GNUNET_HELLO_Message)) && 130 if ((size >= sizeof(struct GNUNET_HELLO_Message)) &&
128 (ntohs(hello->header.size) == size) && 131 (ntohs (hello->header.size) == size) &&
129 (size == GNUNET_HELLO_size(hello))) 132 (size == GNUNET_HELLO_size (hello)))
130 { 133 {
131 peer = GCP_get(&put_path[0], 134 peer = GCP_get (&put_path[0],
132 GNUNET_YES); 135 GNUNET_YES);
133 LOG(GNUNET_ERROR_TYPE_DEBUG, 136 LOG (GNUNET_ERROR_TYPE_DEBUG,
134 "Got HELLO for %s\n", 137 "Got HELLO for %s\n",
135 GCP_2s(peer)); 138 GCP_2s (peer));
136 GCP_set_hello(peer, 139 GCP_set_hello (peer,
137 hello); 140 hello);
138 } 141 }
139} 142}
140 143
141 144
@@ -145,7 +148,7 @@ dht_get_id_handler(void *cls, struct GNUNET_TIME_Absolute exp,
145 * @param cls closure 148 * @param cls closure
146 */ 149 */
147static void 150static void
148announce_id(void *cls) 151announce_id (void *cls)
149{ 152{
150 struct GNUNET_HashCode phash; 153 struct GNUNET_HashCode phash;
151 const struct GNUNET_HELLO_Message *hello; 154 const struct GNUNET_HELLO_Message *hello;
@@ -153,58 +156,58 @@ announce_id(void *cls)
153 struct GNUNET_TIME_Absolute expiration; 156 struct GNUNET_TIME_Absolute expiration;
154 struct GNUNET_TIME_Relative next_put; 157 struct GNUNET_TIME_Relative next_put;
155 158
156 hello = GCH_get_mine(); 159 hello = GCH_get_mine ();
157 size = (NULL != hello) ? GNUNET_HELLO_size(hello) : 0; 160 size = (NULL != hello) ? GNUNET_HELLO_size (hello) : 0;
158 if (0 == size) 161 if (0 == size)
159 { 162 {
160 expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), 163 expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
161 announce_delay); 164 announce_delay);
162 announce_delay = GNUNET_TIME_STD_BACKOFF(announce_delay); 165 announce_delay = GNUNET_TIME_STD_BACKOFF (announce_delay);
163 } 166 }
164 else 167 else
165 { 168 {
166 expiration = GNUNET_HELLO_get_last_expiration(hello); 169 expiration = GNUNET_HELLO_get_last_expiration (hello);
167 announce_delay = GNUNET_TIME_UNIT_SECONDS; 170 announce_delay = GNUNET_TIME_UNIT_SECONDS;
168 } 171 }
169 172
170 /* Call again in id_announce_time, unless HELLO expires first, 173 /* Call again in id_announce_time, unless HELLO expires first,
171 * but wait at least 1s. */ 174 * but wait at least 1s. */
172 next_put 175 next_put
173 = GNUNET_TIME_absolute_get_remaining(expiration); 176 = GNUNET_TIME_absolute_get_remaining (expiration);
174 next_put 177 next_put
175 = GNUNET_TIME_relative_min(next_put, 178 = GNUNET_TIME_relative_min (next_put,
176 id_announce_time); 179 id_announce_time);
177 next_put 180 next_put
178 = GNUNET_TIME_relative_max(next_put, 181 = GNUNET_TIME_relative_max (next_put,
179 GNUNET_TIME_UNIT_SECONDS); 182 GNUNET_TIME_UNIT_SECONDS);
180 announce_id_task 183 announce_id_task
181 = GNUNET_SCHEDULER_add_delayed(next_put, 184 = GNUNET_SCHEDULER_add_delayed (next_put,
182 &announce_id, 185 &announce_id,
183 cls); 186 cls);
184 GNUNET_STATISTICS_update(stats, 187 GNUNET_STATISTICS_update (stats,
185 "# DHT announce", 188 "# DHT announce",
186 1, 189 1,
187 GNUNET_NO); 190 GNUNET_NO);
188 memset(&phash, 191 memset (&phash,
189 0, 192 0,
190 sizeof(phash)); 193 sizeof(phash));
191 GNUNET_memcpy(&phash, 194 GNUNET_memcpy (&phash,
192 &my_full_id, 195 &my_full_id,
193 sizeof(my_full_id)); 196 sizeof(my_full_id));
194 LOG(GNUNET_ERROR_TYPE_DEBUG, 197 LOG (GNUNET_ERROR_TYPE_DEBUG,
195 "Announcing my HELLO (%u bytes) in the DHT\n", 198 "Announcing my HELLO (%u bytes) in the DHT\n",
196 size); 199 size);
197 GNUNET_DHT_put(dht_handle, /* DHT handle */ 200 GNUNET_DHT_put (dht_handle, /* DHT handle */
198 &phash, /* Key to use */ 201 &phash, /* Key to use */
199 dht_replication_level, /* Replication level */ 202 dht_replication_level, /* Replication level */
200 GNUNET_DHT_RO_RECORD_ROUTE 203 GNUNET_DHT_RO_RECORD_ROUTE
201 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ 204 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
202 GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */ 205 GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */
203 size, /* Size of the data */ 206 size, /* Size of the data */
204 (const char *)hello, /* Data itself */ 207 (const char *) hello, /* Data itself */
205 expiration, /* Data expiration */ 208 expiration, /* Data expiration */
206 NULL, /* Continuation */ 209 NULL, /* Continuation */
207 NULL); /* Continuation closure */ 210 NULL); /* Continuation closure */
208} 211}
209 212
210 213
@@ -213,15 +216,15 @@ announce_id(void *cls)
213 * changes. Re-triggers the DHT PUT immediately. 216 * changes. Re-triggers the DHT PUT immediately.
214 */ 217 */
215void 218void
216GCD_hello_update() 219GCD_hello_update ()
217{ 220{
218 if (NULL == announce_id_task) 221 if (NULL == announce_id_task)
219 return; /* too early */ 222 return; /* too early */
220 GNUNET_SCHEDULER_cancel(announce_id_task); 223 GNUNET_SCHEDULER_cancel (announce_id_task);
221 announce_id_task 224 announce_id_task
222 = GNUNET_SCHEDULER_add_delayed(CHANGE_DELAY, 225 = GNUNET_SCHEDULER_add_delayed (CHANGE_DELAY,
223 &announce_id, 226 &announce_id,
224 NULL); 227 NULL);
225} 228}
226 229
227 230
@@ -231,42 +234,42 @@ GCD_hello_update()
231 * @param c Configuration. 234 * @param c Configuration.
232 */ 235 */
233void 236void
234GCD_init(const struct GNUNET_CONFIGURATION_Handle *c) 237GCD_init (const struct GNUNET_CONFIGURATION_Handle *c)
235{ 238{
236 if (GNUNET_OK != 239 if (GNUNET_OK !=
237 GNUNET_CONFIGURATION_get_value_number(c, 240 GNUNET_CONFIGURATION_get_value_number (c,
238 "CADET", 241 "CADET",
239 "DHT_REPLICATION_LEVEL", 242 "DHT_REPLICATION_LEVEL",
240 &dht_replication_level)) 243 &dht_replication_level))
241 { 244 {
242 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, 245 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
243 "CADET", 246 "CADET",
244 "DHT_REPLICATION_LEVEL", 247 "DHT_REPLICATION_LEVEL",
245 "USING DEFAULT"); 248 "USING DEFAULT");
246 dht_replication_level = 3; 249 dht_replication_level = 3;
247 } 250 }
248 251
249 if (GNUNET_OK != 252 if (GNUNET_OK !=
250 GNUNET_CONFIGURATION_get_value_time(c, 253 GNUNET_CONFIGURATION_get_value_time (c,
251 "CADET", 254 "CADET",
252 "ID_ANNOUNCE_TIME", 255 "ID_ANNOUNCE_TIME",
253 &id_announce_time)) 256 &id_announce_time))
254 { 257 {
255 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, 258 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
256 "CADET", 259 "CADET",
257 "ID_ANNOUNCE_TIME", 260 "ID_ANNOUNCE_TIME",
258 "MISSING"); 261 "MISSING");
259 GNUNET_SCHEDULER_shutdown(); 262 GNUNET_SCHEDULER_shutdown ();
260 return; 263 return;
261 } 264 }
262 265
263 dht_handle = GNUNET_DHT_connect(c, 266 dht_handle = GNUNET_DHT_connect (c,
264 64); 267 64);
265 GNUNET_break(NULL != dht_handle); 268 GNUNET_break (NULL != dht_handle);
266 announce_delay = GNUNET_TIME_UNIT_SECONDS; 269 announce_delay = GNUNET_TIME_UNIT_SECONDS;
267 announce_id_task = GNUNET_SCHEDULER_add_delayed(STARTUP_DELAY, 270 announce_id_task = GNUNET_SCHEDULER_add_delayed (STARTUP_DELAY,
268 &announce_id, 271 &announce_id,
269 NULL); 272 NULL);
270} 273}
271 274
272 275
@@ -274,18 +277,18 @@ GCD_init(const struct GNUNET_CONFIGURATION_Handle *c)
274 * Shut down the DHT subsystem. 277 * Shut down the DHT subsystem.
275 */ 278 */
276void 279void
277GCD_shutdown(void) 280GCD_shutdown (void)
278{ 281{
279 if (NULL != dht_handle) 282 if (NULL != dht_handle)
280 { 283 {
281 GNUNET_DHT_disconnect(dht_handle); 284 GNUNET_DHT_disconnect (dht_handle);
282 dht_handle = NULL; 285 dht_handle = NULL;
283 } 286 }
284 if (NULL != announce_id_task) 287 if (NULL != announce_id_task)
285 { 288 {
286 GNUNET_SCHEDULER_cancel(announce_id_task); 289 GNUNET_SCHEDULER_cancel (announce_id_task);
287 announce_id_task = NULL; 290 announce_id_task = NULL;
288 } 291 }
289} 292}
290 293
291 294
@@ -296,37 +299,37 @@ GCD_shutdown(void)
296 * @return handle to abort search 299 * @return handle to abort search
297 */ 300 */
298struct GCD_search_handle * 301struct GCD_search_handle *
299GCD_search(const struct GNUNET_PeerIdentity *peer_id) 302GCD_search (const struct GNUNET_PeerIdentity *peer_id)
300{ 303{
301 struct GNUNET_HashCode phash; 304 struct GNUNET_HashCode phash;
302 struct GCD_search_handle *h; 305 struct GCD_search_handle *h;
303 306
304 GNUNET_STATISTICS_update(stats, 307 GNUNET_STATISTICS_update (stats,
305 "# DHT search", 308 "# DHT search",
306 1, 309 1,
307 GNUNET_NO); 310 GNUNET_NO);
308 memset(&phash, 311 memset (&phash,
309 0, 312 0,
310 sizeof(phash)); 313 sizeof(phash));
311 GNUNET_memcpy(&phash, 314 GNUNET_memcpy (&phash,
312 peer_id, 315 peer_id,
313 sizeof(*peer_id)); 316 sizeof(*peer_id));
314 317
315 h = GNUNET_new(struct GCD_search_handle); 318 h = GNUNET_new (struct GCD_search_handle);
316 h->dhtget = GNUNET_DHT_get_start(dht_handle, /* handle */ 319 h->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
317 GNUNET_BLOCK_TYPE_DHT_HELLO, /* type */ 320 GNUNET_BLOCK_TYPE_DHT_HELLO, /* type */
318 &phash, /* key to search */ 321 &phash, /* key to search */
319 dht_replication_level, /* replication level */ 322 dht_replication_level, /* replication level */
320 GNUNET_DHT_RO_RECORD_ROUTE | 323 GNUNET_DHT_RO_RECORD_ROUTE
321 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 324 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
322 NULL, /* xquery */ 325 NULL, /* xquery */
323 0, /* xquery bits */ 326 0, /* xquery bits */
324 &dht_get_id_handler, 327 &dht_get_id_handler,
325 h); 328 h);
326 LOG(GNUNET_ERROR_TYPE_DEBUG, 329 LOG (GNUNET_ERROR_TYPE_DEBUG,
327 "Starting DHT GET for peer %s (%p)\n", 330 "Starting DHT GET for peer %s (%p)\n",
328 GNUNET_i2s(peer_id), 331 GNUNET_i2s (peer_id),
329 h); 332 h);
330 return h; 333 return h;
331} 334}
332 335
@@ -337,13 +340,13 @@ GCD_search(const struct GNUNET_PeerIdentity *peer_id)
337 * @param h handle to search to stop 340 * @param h handle to search to stop
338 */ 341 */
339void 342void
340GCD_search_stop(struct GCD_search_handle *h) 343GCD_search_stop (struct GCD_search_handle *h)
341{ 344{
342 LOG(GNUNET_ERROR_TYPE_DEBUG, 345 LOG (GNUNET_ERROR_TYPE_DEBUG,
343 "Stopping DHT GET %p\n", 346 "Stopping DHT GET %p\n",
344 h); 347 h);
345 GNUNET_DHT_get_stop(h->dhtget); 348 GNUNET_DHT_get_stop (h->dhtget);
346 GNUNET_free(h); 349 GNUNET_free (h);
347} 350}
348 351
349/* end of gnunet-service-cadet_dht.c */ 352/* end of gnunet-service-cadet_dht.c */
diff --git a/src/cadet/gnunet-service-cadet_dht.h b/src/cadet/gnunet-service-cadet_dht.h
index 4cb6e9fff..bcc27f5d2 100644
--- a/src/cadet/gnunet-service-cadet_dht.h
+++ b/src/cadet/gnunet-service-cadet_dht.h
@@ -52,14 +52,14 @@ struct GCD_search_handle;
52 * @param c Configuration. 52 * @param c Configuration.
53 */ 53 */
54void 54void
55GCD_init(const struct GNUNET_CONFIGURATION_Handle *c); 55GCD_init (const struct GNUNET_CONFIGURATION_Handle *c);
56 56
57 57
58/** 58/**
59 * Shut down the DHT subsystem. 59 * Shut down the DHT subsystem.
60 */ 60 */
61void 61void
62GCD_shutdown(void); 62GCD_shutdown (void);
63 63
64 64
65/** 65/**
@@ -67,7 +67,7 @@ GCD_shutdown(void);
67 * changes. Re-triggers the DHT PUT immediately. 67 * changes. Re-triggers the DHT PUT immediately.
68 */ 68 */
69void 69void
70GCD_hello_update(void); 70GCD_hello_update (void);
71 71
72/** 72/**
73 * Search DHT for paths to @a peeR_id 73 * Search DHT for paths to @a peeR_id
@@ -76,7 +76,7 @@ GCD_hello_update(void);
76 * @return handle to abort search 76 * @return handle to abort search
77 */ 77 */
78struct GCD_search_handle * 78struct GCD_search_handle *
79GCD_search(const struct GNUNET_PeerIdentity *peer_id); 79GCD_search (const struct GNUNET_PeerIdentity *peer_id);
80 80
81 81
82/** 82/**
@@ -85,7 +85,7 @@ GCD_search(const struct GNUNET_PeerIdentity *peer_id);
85 * @param h handle to search to stop 85 * @param h handle to search to stop
86 */ 86 */
87void 87void
88GCD_search_stop(struct GCD_search_handle *h); 88GCD_search_stop (struct GCD_search_handle *h);
89 89
90 90
91#if 0 /* keep Emacsens' auto-indent happy */ 91#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/cadet/gnunet-service-cadet_hello.c b/src/cadet/gnunet-service-cadet_hello.c
index 7d6d2b0ce..bbe947ad1 100644
--- a/src/cadet/gnunet-service-cadet_hello.c
+++ b/src/cadet/gnunet-service-cadet_hello.c
@@ -35,7 +35,7 @@
35#include "gnunet-service-cadet_hello.h" 35#include "gnunet-service-cadet_hello.h"
36#include "gnunet-service-cadet_peer.h" 36#include "gnunet-service-cadet_peer.h"
37 37
38#define LOG(level, ...) GNUNET_log_from(level, "cadet-hll", __VA_ARGS__) 38#define LOG(level, ...) GNUNET_log_from (level, "cadet-hll", __VA_ARGS__)
39 39
40/** 40/**
41 * Hello message of local peer. 41 * Hello message of local peer.
@@ -62,34 +62,35 @@ static struct GNUNET_PEERINFO_NotifyContext *nc;
62 * @param err_msg Error message. 62 * @param err_msg Error message.
63 */ 63 */
64static void 64static void
65got_hello(void *cls, 65got_hello (void *cls,
66 const struct GNUNET_PeerIdentity *id, 66 const struct GNUNET_PeerIdentity *id,
67 const struct GNUNET_HELLO_Message *hello, 67 const struct GNUNET_HELLO_Message *hello,
68 const char *err_msg) 68 const char *err_msg)
69{ 69{
70 struct CadetPeer *peer; 70 struct CadetPeer *peer;
71 71
72 if ((NULL == id) || 72 if ((NULL == id) ||
73 (NULL == hello)) 73 (NULL == hello))
74 return; 74 return;
75 if (0 == GNUNET_memcmp(id, 75 if (0 == GNUNET_memcmp (id,
76 &my_full_id)) 76 &my_full_id))
77 { 77 {
78 GNUNET_free_non_null(mine); 78 GNUNET_free_non_null (mine);
79 mine = (struct GNUNET_HELLO_Message *)GNUNET_copy_message(&hello->header); 79 mine = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (&hello->header);
80 GCD_hello_update(); 80 GCD_hello_update ();
81 return; 81 return;
82 } 82 }
83 83
84 LOG(GNUNET_ERROR_TYPE_DEBUG, 84 LOG (GNUNET_ERROR_TYPE_DEBUG,
85 "Hello for %s (%d bytes), expires on %s\n", 85 "Hello for %s (%d bytes), expires on %s\n",
86 GNUNET_i2s(id), 86 GNUNET_i2s (id),
87 GNUNET_HELLO_size(hello), 87 GNUNET_HELLO_size (hello),
88 GNUNET_STRINGS_absolute_time_to_string(GNUNET_HELLO_get_last_expiration(hello))); 88 GNUNET_STRINGS_absolute_time_to_string (
89 peer = GCP_get(id, 89 GNUNET_HELLO_get_last_expiration (hello)));
90 GNUNET_YES); 90 peer = GCP_get (id,
91 GCP_set_hello(peer, 91 GNUNET_YES);
92 hello); 92 GCP_set_hello (peer,
93 hello);
93} 94}
94 95
95 96
@@ -99,14 +100,14 @@ got_hello(void *cls,
99 * @param c Configuration. 100 * @param c Configuration.
100 */ 101 */
101void 102void
102GCH_init(const struct GNUNET_CONFIGURATION_Handle *c) 103GCH_init (const struct GNUNET_CONFIGURATION_Handle *c)
103{ 104{
104 GNUNET_assert(NULL == nc); 105 GNUNET_assert (NULL == nc);
105 peerinfo = GNUNET_PEERINFO_connect(c); 106 peerinfo = GNUNET_PEERINFO_connect (c);
106 nc = GNUNET_PEERINFO_notify(c, 107 nc = GNUNET_PEERINFO_notify (c,
107 GNUNET_NO, 108 GNUNET_NO,
108 &got_hello, 109 &got_hello,
109 NULL); 110 NULL);
110} 111}
111 112
112 113
@@ -114,23 +115,23 @@ GCH_init(const struct GNUNET_CONFIGURATION_Handle *c)
114 * Shut down the hello subsystem. 115 * Shut down the hello subsystem.
115 */ 116 */
116void 117void
117GCH_shutdown() 118GCH_shutdown ()
118{ 119{
119 if (NULL != nc) 120 if (NULL != nc)
120 { 121 {
121 GNUNET_PEERINFO_notify_cancel(nc); 122 GNUNET_PEERINFO_notify_cancel (nc);
122 nc = NULL; 123 nc = NULL;
123 } 124 }
124 if (NULL != peerinfo) 125 if (NULL != peerinfo)
125 { 126 {
126 GNUNET_PEERINFO_disconnect(peerinfo); 127 GNUNET_PEERINFO_disconnect (peerinfo);
127 peerinfo = NULL; 128 peerinfo = NULL;
128 } 129 }
129 if (NULL != mine) 130 if (NULL != mine)
130 { 131 {
131 GNUNET_free(mine); 132 GNUNET_free (mine);
132 mine = NULL; 133 mine = NULL;
133 } 134 }
134} 135}
135 136
136 137
@@ -140,7 +141,7 @@ GCH_shutdown()
140 * @return Own hello message. 141 * @return Own hello message.
141 */ 142 */
142const struct GNUNET_HELLO_Message * 143const struct GNUNET_HELLO_Message *
143GCH_get_mine(void) 144GCH_get_mine (void)
144{ 145{
145 return mine; 146 return mine;
146} 147}
diff --git a/src/cadet/gnunet-service-cadet_hello.h b/src/cadet/gnunet-service-cadet_hello.h
index 99b6c807d..2cb444b4a 100644
--- a/src/cadet/gnunet-service-cadet_hello.h
+++ b/src/cadet/gnunet-service-cadet_hello.h
@@ -49,14 +49,14 @@ extern "C"
49 * @param c Configuration. 49 * @param c Configuration.
50 */ 50 */
51void 51void
52GCH_init(const struct GNUNET_CONFIGURATION_Handle *c); 52GCH_init (const struct GNUNET_CONFIGURATION_Handle *c);
53 53
54 54
55/** 55/**
56 * Shut down the hello subsystem. 56 * Shut down the hello subsystem.
57 */ 57 */
58void 58void
59GCH_shutdown(void); 59GCH_shutdown (void);
60 60
61 61
62/** 62/**
@@ -65,7 +65,7 @@ GCH_shutdown(void);
65 * @return Own hello message. 65 * @return Own hello message.
66 */ 66 */
67const struct GNUNET_HELLO_Message * 67const struct GNUNET_HELLO_Message *
68GCH_get_mine(void); 68GCH_get_mine (void);
69 69
70 70
71#if 0 /* keep Emacsens' auto-indent happy */ 71#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/cadet/gnunet-service-cadet_paths.c b/src/cadet/gnunet-service-cadet_paths.c
index 149ac659a..e4a8dc789 100644
--- a/src/cadet/gnunet-service-cadet_paths.c
+++ b/src/cadet/gnunet-service-cadet_paths.c
@@ -30,13 +30,14 @@
30#include "gnunet-service-cadet_paths.h" 30#include "gnunet-service-cadet_paths.h"
31 31
32 32
33#define LOG(level, ...) GNUNET_log_from(level, "cadet-pat", __VA_ARGS__) 33#define LOG(level, ...) GNUNET_log_from (level, "cadet-pat", __VA_ARGS__)
34 34
35 35
36/** 36/**
37 * Information regarding a possible path to reach a peer. 37 * Information regarding a possible path to reach a peer.
38 */ 38 */
39struct CadetPeerPath { 39struct CadetPeerPath
40{
40 /** 41 /**
41 * Array of all the peers on the path. If @e hn is non-NULL, the 42 * Array of all the peers on the path. If @e hn is non-NULL, the
42 * last one is our owner. 43 * last one is our owner.
@@ -68,18 +69,18 @@ struct CadetPeerPath {
68 * @param path path to calculate the score for 69 * @param path path to calculate the score for
69 */ 70 */
70static void 71static void
71recalculate_path_desirability(struct CadetPeerPath *path) 72recalculate_path_desirability (struct CadetPeerPath *path)
72{ 73{
73 double result = 0.0; 74 double result = 0.0;
74 75
75 for (unsigned int i = 0; i < path->entries_length; i++) 76 for (unsigned int i = 0; i < path->entries_length; i++)
76 { 77 {
77 struct CadetPeer *cp = path->entries[i]->peer; 78 struct CadetPeer *cp = path->entries[i]->peer;
78 79
79 result += GCP_get_desirability_of_path(cp, 80 result += GCP_get_desirability_of_path (cp,
80 i); 81 i);
81 } 82 }
82 path->desirability = (GNUNET_CONTAINER_HeapCostType)result; 83 path->desirability = (GNUNET_CONTAINER_HeapCostType) result;
83} 84}
84 85
85 86
@@ -97,7 +98,7 @@ recalculate_path_desirability(struct CadetPeerPath *path)
97 * @return desirability of the path, larger is more desirable 98 * @return desirability of the path, larger is more desirable
98 */ 99 */
99GNUNET_CONTAINER_HeapCostType 100GNUNET_CONTAINER_HeapCostType
100GCPP_get_desirability(const struct CadetPeerPath *path) 101GCPP_get_desirability (const struct CadetPeerPath *path)
101{ 102{
102 return path->desirability; 103 return path->desirability;
103} 104}
@@ -114,15 +115,15 @@ GCPP_get_desirability(const struct CadetPeerPath *path)
114 * otherwise connection from us to @a destination via @a path 115 * otherwise connection from us to @a destination via @a path
115 */ 116 */
116struct CadetConnection * 117struct CadetConnection *
117GCPP_get_connection(struct CadetPeerPath *path, 118GCPP_get_connection (struct CadetPeerPath *path,
118 struct CadetPeer *destination, 119 struct CadetPeer *destination,
119 unsigned int off) 120 unsigned int off)
120{ 121{
121 struct CadetPeerPathEntry *entry; 122 struct CadetPeerPathEntry *entry;
122 123
123 GNUNET_assert(off < path->entries_length); 124 GNUNET_assert (off < path->entries_length);
124 entry = path->entries[off]; 125 entry = path->entries[off];
125 GNUNET_assert(entry->peer == destination); 126 GNUNET_assert (entry->peer == destination);
126 return entry->cc; 127 return entry->cc;
127} 128}
128 129
@@ -136,21 +137,21 @@ GCPP_get_connection(struct CadetPeerPath *path,
136 * @param cc the connection to remember 137 * @param cc the connection to remember
137 */ 138 */
138void 139void
139GCPP_add_connection(struct CadetPeerPath *path, 140GCPP_add_connection (struct CadetPeerPath *path,
140 unsigned int off, 141 unsigned int off,
141 struct CadetConnection *cc) 142 struct CadetConnection *cc)
142{ 143{
143 struct CadetPeerPathEntry *entry; 144 struct CadetPeerPathEntry *entry;
144 145
145 LOG(GNUNET_ERROR_TYPE_DEBUG, 146 LOG (GNUNET_ERROR_TYPE_DEBUG,
146 "Adding %s to path %s at offset %u\n", 147 "Adding %s to path %s at offset %u\n",
147 GCC_2s(cc), 148 GCC_2s (cc),
148 GCPP_2s(path), 149 GCPP_2s (path),
149 off); 150 off);
150 GNUNET_assert(off < path->entries_length); 151 GNUNET_assert (off < path->entries_length);
151 entry = path->entries[off]; 152 entry = path->entries[off];
152 GNUNET_assert(NULL == entry->cc); 153 GNUNET_assert (NULL == entry->cc);
153 GNUNET_assert(NULL != cc); 154 GNUNET_assert (NULL != cc);
154 entry->cc = cc; 155 entry->cc = cc;
155} 156}
156 157
@@ -165,20 +166,20 @@ GCPP_add_connection(struct CadetPeerPath *path,
165 * @param cc the connection to forget 166 * @param cc the connection to forget
166 */ 167 */
167void 168void
168GCPP_del_connection(struct CadetPeerPath *path, 169GCPP_del_connection (struct CadetPeerPath *path,
169 unsigned int off, 170 unsigned int off,
170 struct CadetConnection *cc) 171 struct CadetConnection *cc)
171{ 172{
172 struct CadetPeerPathEntry *entry; 173 struct CadetPeerPathEntry *entry;
173 174
174 LOG(GNUNET_ERROR_TYPE_DEBUG, 175 LOG (GNUNET_ERROR_TYPE_DEBUG,
175 "Removing connection %s to path %s at offset %u\n", 176 "Removing connection %s to path %s at offset %u\n",
176 GCC_2s(cc), 177 GCC_2s (cc),
177 GCPP_2s(path), 178 GCPP_2s (path),
178 off); 179 off);
179 GNUNET_assert(off < path->entries_length); 180 GNUNET_assert (off < path->entries_length);
180 entry = path->entries[off]; 181 entry = path->entries[off];
181 GNUNET_assert(cc == entry->cc); 182 GNUNET_assert (cc == entry->cc);
182 entry->cc = NULL; 183 entry->cc = NULL;
183} 184}
184 185
@@ -193,42 +194,42 @@ GCPP_del_connection(struct CadetPeerPath *path,
193 * @param stop_at the path length at which to stop trying 194 * @param stop_at the path length at which to stop trying
194 */ 195 */
195static void 196static void
196attach_path(struct CadetPeerPath *path, unsigned int stop_at) 197attach_path (struct CadetPeerPath *path, unsigned int stop_at)
197{ 198{
198 GNUNET_assert(NULL == path->hn); 199 GNUNET_assert (NULL == path->hn);
199 200
200 /* Try to attach this path to a peer, working backwards from the end. */ 201 /* Try to attach this path to a peer, working backwards from the end. */
201 while (path->entries_length > stop_at) 202 while (path->entries_length > stop_at)
202 { 203 {
203 unsigned int end = path->entries_length - 1; 204 unsigned int end = path->entries_length - 1;
204 struct CadetPeerPathEntry *entry = path->entries[end]; 205 struct CadetPeerPathEntry *entry = path->entries[end];
205 int force = GNUNET_NO; 206 int force = GNUNET_NO;
206 207
207 recalculate_path_desirability(path); 208 recalculate_path_desirability (path);
208 /* If the entry already has a connection using it, force attach. */ 209 /* If the entry already has a connection using it, force attach. */
209 if (NULL != entry->cc) 210 if (NULL != entry->cc)
210 force = GNUNET_YES; 211 force = GNUNET_YES;
211 path->hn = GCP_attach_path(entry->peer, 212 path->hn = GCP_attach_path (entry->peer,
212 path, 213 path,
213 end, 214 end,
214 force); 215 force);
215 if (NULL != path->hn) 216 if (NULL != path->hn)
216 break; 217 break;
217 218
218 /* Attach failed, trim this entry from the path. */ 219 /* Attach failed, trim this entry from the path. */
219 GNUNET_assert(NULL == entry->cc); 220 GNUNET_assert (NULL == entry->cc);
220 GCP_path_entry_remove(entry->peer, 221 GCP_path_entry_remove (entry->peer,
221 entry, 222 entry,
222 end); 223 end);
223 GNUNET_free(entry); 224 GNUNET_free (entry);
224 path->entries[end] = NULL; 225 path->entries[end] = NULL;
225 path->entries_length--; 226 path->entries_length--;
226 } 227 }
227 228
228 /* Shrink array to actual path length. */ 229 /* Shrink array to actual path length. */
229 GNUNET_array_grow(path->entries, 230 GNUNET_array_grow (path->entries,
230 path->entries_length, 231 path->entries_length,
231 path->entries_length); 232 path->entries_length);
232} 233}
233 234
234 235
@@ -240,33 +241,33 @@ attach_path(struct CadetPeerPath *path, unsigned int stop_at)
240 * @param path the path that is being released 241 * @param path the path that is being released
241 */ 242 */
242void 243void
243GCPP_release(struct CadetPeerPath *path) 244GCPP_release (struct CadetPeerPath *path)
244{ 245{
245 struct CadetPeerPathEntry *entry; 246 struct CadetPeerPathEntry *entry;
246 247
247 LOG(GNUNET_ERROR_TYPE_DEBUG, 248 LOG (GNUNET_ERROR_TYPE_DEBUG,
248 "Owner releases path %s\n", 249 "Owner releases path %s\n",
249 GCPP_2s(path)); 250 GCPP_2s (path));
250 path->hn = NULL; 251 path->hn = NULL;
251 entry = path->entries[path->entries_length - 1]; 252 entry = path->entries[path->entries_length - 1];
252 GNUNET_assert(path == entry->path); 253 GNUNET_assert (path == entry->path);
253 GNUNET_assert(NULL == entry->cc); 254 GNUNET_assert (NULL == entry->cc);
254 /* cut 'off' end of path */ 255 /* cut 'off' end of path */
255 GCP_path_entry_remove(entry->peer, 256 GCP_path_entry_remove (entry->peer,
256 entry, 257 entry,
257 path->entries_length - 1); 258 path->entries_length - 1);
258 GNUNET_free(entry); 259 GNUNET_free (entry);
259 path->entries[path->entries_length - 1] = NULL; 260 path->entries[path->entries_length - 1] = NULL;
260 path->entries_length--; 261 path->entries_length--;
261 /* see if new peer at the end likes this path any better */ 262 /* see if new peer at the end likes this path any better */
262 attach_path(path, 0); 263 attach_path (path, 0);
263 if (NULL == path->hn) 264 if (NULL == path->hn)
264 { 265 {
265 /* nobody wants us, discard the path */ 266 /* nobody wants us, discard the path */
266 GNUNET_assert(0 == path->entries_length); 267 GNUNET_assert (0 == path->entries_length);
267 GNUNET_assert(NULL == path->entries); 268 GNUNET_assert (NULL == path->entries);
268 GNUNET_free(path); 269 GNUNET_free (path);
269 } 270 }
270} 271}
271 272
272 273
@@ -279,38 +280,39 @@ GCPP_release(struct CadetPeerPath *path)
279 * @param delta change in the score to apply 280 * @param delta change in the score to apply
280 */ 281 */
281void 282void
282GCPP_update_score(struct CadetPeerPath *path, 283GCPP_update_score (struct CadetPeerPath *path,
283 unsigned int off, 284 unsigned int off,
284 int delta) 285 int delta)
285{ 286{
286 struct CadetPeerPathEntry *entry; 287 struct CadetPeerPathEntry *entry;
287 288
288 GNUNET_assert(off < path->entries_length); 289 GNUNET_assert (off < path->entries_length);
289 entry = path->entries[off]; 290 entry = path->entries[off];
290 291
291 /* Add delta, with checks for overflows */ 292 /* Add delta, with checks for overflows */
292 if (delta >= 0) 293 if (delta >= 0)
293 { 294 {
294 if (delta + entry->score < entry->score) 295 if (delta + entry->score < entry->score)
295 entry->score = INT_MAX; 296 entry->score = INT_MAX;
296 else 297 else
297 entry->score += delta; 298 entry->score += delta;
298 } 299 }
299 else 300 else
300 { 301 {
301 if (delta + entry->score > entry->score) 302 if (delta + entry->score > entry->score)
302 entry->score = INT_MIN; 303 entry->score = INT_MIN;
303 else 304 else
304 entry->score += delta; 305 entry->score += delta;
305 } 306 }
306 recalculate_path_desirability(path); 307 recalculate_path_desirability (path);
307} 308}
308 309
309 310
310/** 311/**
311 * Closure for #find_peer_at() and #check_match(). 312 * Closure for #find_peer_at() and #check_match().
312 */ 313 */
313struct CheckMatchContext { 314struct CheckMatchContext
315{
314 /** 316 /**
315 * Set to a matching path, if any. 317 * Set to a matching path, if any.
316 */ 318 */
@@ -339,38 +341,38 @@ struct CheckMatchContext {
339 * @return #GNUNET_YES (continue to iterate), or if found #GNUNET_NO 341 * @return #GNUNET_YES (continue to iterate), or if found #GNUNET_NO
340 */ 342 */
341static int 343static int
342check_match(void *cls, 344check_match (void *cls,
343 struct CadetPeerPath *path, 345 struct CadetPeerPath *path,
344 unsigned int off) 346 unsigned int off)
345{ 347{
346 struct CheckMatchContext *cm_ctx = cls; 348 struct CheckMatchContext *cm_ctx = cls;
347 349
348 GNUNET_assert(path->entries_length > off); 350 GNUNET_assert (path->entries_length > off);
349 if ((path->entries_length != off + 1) && 351 if ((path->entries_length != off + 1) &&
350 (off + 1 != cm_ctx->cpath_length)) 352 (off + 1 != cm_ctx->cpath_length))
351 { 353 {
352 LOG(GNUNET_ERROR_TYPE_DEBUG, 354 LOG (GNUNET_ERROR_TYPE_DEBUG,
353 "check_match mismatch because path %s is too long (%u vs. %u vs. %u)\n", 355 "check_match mismatch because path %s is too long (%u vs. %u vs. %u)\n",
354 GCPP_2s(path), 356 GCPP_2s (path),
355 path->entries_length, 357 path->entries_length,
356 off + 1, 358 off + 1,
357 cm_ctx->cpath_length); 359 cm_ctx->cpath_length);
358 return GNUNET_YES; /* too long, goes somewhere else already, thus cannot be useful */ 360 return GNUNET_YES; /* too long, goes somewhere else already, thus cannot be useful */
359 } 361 }
360 for (unsigned int i = 0; i < off; i++) 362 for (unsigned int i = 0; i < off; i++)
361 if (cm_ctx->cpath[i] != 363 if (cm_ctx->cpath[i] !=
362 GCPP_get_peer_at_offset(path, 364 GCPP_get_peer_at_offset (path,
363 i)) 365 i))
364 { 366 {
365 LOG(GNUNET_ERROR_TYPE_DEBUG, 367 LOG (GNUNET_ERROR_TYPE_DEBUG,
366 "check_match path %s mismatches at offset %u\n", 368 "check_match path %s mismatches at offset %u\n",
367 GCPP_2s(path), 369 GCPP_2s (path),
368 i); 370 i);
369 return GNUNET_YES; /* mismatch, ignore */ 371 return GNUNET_YES; /* mismatch, ignore */
370 } 372 }
371 LOG(GNUNET_ERROR_TYPE_DEBUG, 373 LOG (GNUNET_ERROR_TYPE_DEBUG,
372 "check_match found match with path %s\n", 374 "check_match found match with path %s\n",
373 GCPP_2s(path)); 375 GCPP_2s (path));
374 cm_ctx->match = path; 376 cm_ctx->match = path;
375 return GNUNET_NO; /* match, we are done! */ 377 return GNUNET_NO; /* match, we are done! */
376} 378}
@@ -387,70 +389,70 @@ check_match(void *cls,
387 * paths already 389 * paths already
388 */ 390 */
389static void 391static void
390extend_path(struct CadetPeerPath *path, 392extend_path (struct CadetPeerPath *path,
391 struct CadetPeer **peers, 393 struct CadetPeer **peers,
392 unsigned int num_peers, 394 unsigned int num_peers,
393 int force) 395 int force)
394{ 396{
395 unsigned int old_len = path->entries_length; 397 unsigned int old_len = path->entries_length;
396 int i; 398 int i;
397 399
398 /* Expand path */ 400 /* Expand path */
399 GNUNET_array_grow(path->entries, 401 GNUNET_array_grow (path->entries,
400 path->entries_length, 402 path->entries_length,
401 old_len + num_peers); 403 old_len + num_peers);
402 for (i = num_peers - 1; i >= 0; i--) 404 for (i = num_peers - 1; i >= 0; i--)
403 { 405 {
404 struct CadetPeerPathEntry *entry = GNUNET_new(struct CadetPeerPathEntry); 406 struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
405 407
406 path->entries[old_len + i] = entry; 408 path->entries[old_len + i] = entry;
407 entry->peer = peers[i]; 409 entry->peer = peers[i];
408 entry->path = path; 410 entry->path = path;
409 } 411 }
410 for (i = num_peers - 1; i >= 0; i--) 412 for (i = num_peers - 1; i >= 0; i--)
411 { 413 {
412 struct CadetPeerPathEntry *entry = path->entries[old_len + i]; 414 struct CadetPeerPathEntry *entry = path->entries[old_len + i];
413 415
414 GCP_path_entry_add(entry->peer, 416 GCP_path_entry_add (entry->peer,
415 entry, 417 entry,
416 old_len + i); 418 old_len + i);
417 } 419 }
418 420
419 /* If we extend an existing path, detach it from the 421 /* If we extend an existing path, detach it from the
420 old owner and re-attach to the new one */ 422 old owner and re-attach to the new one */
421 GCP_detach_path(path->entries[old_len - 1]->peer, 423 GCP_detach_path (path->entries[old_len - 1]->peer,
422 path, 424 path,
423 path->hn); 425 path->hn);
424 path->hn = NULL; 426 path->hn = NULL;
425 path->entries_length = old_len + num_peers; 427 path->entries_length = old_len + num_peers;
426 if (GNUNET_YES == force) 428 if (GNUNET_YES == force)
427 { 429 {
428 int end = path->entries_length - 1; 430 int end = path->entries_length - 1;
429 431
430 path->hn = GCP_attach_path(path->entries[end]->peer, 432 path->hn = GCP_attach_path (path->entries[end]->peer,
431 path, 433 path,
432 end, 434 end,
433 GNUNET_YES); 435 GNUNET_YES);
434 } 436 }
435 else 437 else
436 { 438 {
437 attach_path(path, old_len); 439 attach_path (path, old_len);
438 } 440 }
439 if (NULL == path->hn) 441 if (NULL == path->hn)
440 { 442 {
441 /* none of the peers is interested in this path; 443 /* none of the peers is interested in this path;
442 re-attach. */ 444 re-attach. */
443 GNUNET_assert(old_len == path->entries_length); 445 GNUNET_assert (old_len == path->entries_length);
444 path->hn = GCP_attach_path(path->entries[old_len - 1]->peer, 446 path->hn = GCP_attach_path (path->entries[old_len - 1]->peer,
445 path, 447 path,
446 old_len - 1, 448 old_len - 1,
447 GNUNET_YES); 449 GNUNET_YES);
448 GNUNET_assert(NULL != path->hn); 450 GNUNET_assert (NULL != path->hn);
449 return; 451 return;
450 } 452 }
451 LOG(GNUNET_ERROR_TYPE_DEBUG, 453 LOG (GNUNET_ERROR_TYPE_DEBUG,
452 "Extended path %s\n", 454 "Extended path %s\n",
453 GCPP_2s(path)); 455 GCPP_2s (path));
454} 456}
455 457
456 458
@@ -467,10 +469,10 @@ extend_path(struct CadetPeerPath *path,
467 * @return a path through the network 469 * @return a path through the network
468 */ 470 */
469void 471void
470GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path, 472GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
471 unsigned int get_path_length, 473 unsigned int get_path_length,
472 const struct GNUNET_PeerIdentity *put_path, 474 const struct GNUNET_PeerIdentity *put_path,
473 unsigned int put_path_length) 475 unsigned int put_path_length)
474{ 476{
475 struct CadetPeer *cpath[get_path_length + put_path_length]; 477 struct CadetPeer *cpath[get_path_length + put_path_length];
476 struct CheckMatchContext cm_ctx; 478 struct CheckMatchContext cm_ctx;
@@ -480,42 +482,42 @@ GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
480 482
481 /* precompute 'cpath' so we can avoid doing the lookups lots of times */ 483 /* precompute 'cpath' so we can avoid doing the lookups lots of times */
482 skip = 0; 484 skip = 0;
483 memset(cpath, 485 memset (cpath,
484 0, 486 0,
485 sizeof(cpath)); /* Just to trigger harder errors later. */ 487 sizeof(cpath)); /* Just to trigger harder errors later. */
486 total_len = get_path_length + put_path_length; 488 total_len = get_path_length + put_path_length;
487 for (unsigned int off = 0; off < total_len; off++) 489 for (unsigned int off = 0; off < total_len; off++)
490 {
491 const struct GNUNET_PeerIdentity *pid;
492
493 pid = (off < get_path_length)
494 ? &get_path[get_path_length - off - 1]
495 : &put_path[get_path_length + put_path_length - off - 1];
496 /* Check that I am not in the path */
497 if (0 == GNUNET_memcmp (&my_full_id,
498 pid))
488 { 499 {
489 const struct GNUNET_PeerIdentity *pid; 500 skip = off + 1;
490 501 continue;
491 pid = (off < get_path_length)
492 ? &get_path[get_path_length - off - 1]
493 : &put_path[get_path_length + put_path_length - off - 1];
494 /* Check that I am not in the path */
495 if (0 == GNUNET_memcmp(&my_full_id,
496 pid))
497 {
498 skip = off + 1;
499 continue;
500 }
501 cpath[off - skip] = GCP_get(pid,
502 GNUNET_YES);
503 /* Check that no peer is twice on the path */
504 for (unsigned int i = 0; i < off - skip; i++)
505 {
506 if (cpath[i] == cpath[off - skip])
507 {
508 skip = off - i;
509 break;
510 }
511 }
512 } 502 }
513 if (skip >= total_len) 503 cpath[off - skip] = GCP_get (pid,
504 GNUNET_YES);
505 /* Check that no peer is twice on the path */
506 for (unsigned int i = 0; i < off - skip; i++)
514 { 507 {
515 LOG(GNUNET_ERROR_TYPE_DEBUG, 508 if (cpath[i] == cpath[off - skip])
516 "Path discovered from DHT is one big cycle?\n"); 509 {
517 return; 510 skip = off - i;
511 break;
512 }
518 } 513 }
514 }
515 if (skip >= total_len)
516 {
517 LOG (GNUNET_ERROR_TYPE_DEBUG,
518 "Path discovered from DHT is one big cycle?\n");
519 return;
520 }
519 total_len -= skip; 521 total_len -= skip;
520 522
521 /* First figure out if this path is a subset of an existing path, an 523 /* First figure out if this path is a subset of an existing path, an
@@ -524,72 +526,72 @@ GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
524 cm_ctx.cpath = cpath; 526 cm_ctx.cpath = cpath;
525 cm_ctx.match = NULL; 527 cm_ctx.match = NULL;
526 for (int i = total_len - 1; i >= 0; i--) 528 for (int i = total_len - 1; i >= 0; i--)
529 {
530 GCP_iterate_paths_at (cpath[i],
531 (unsigned int) i,
532 &check_match,
533 &cm_ctx);
534 if (NULL != cm_ctx.match)
527 { 535 {
528 GCP_iterate_paths_at(cpath[i], 536 if (i == total_len - 1)
529 (unsigned int)i, 537 {
530 &check_match, 538 /* Existing path includes this one, nothing to do! */
531 &cm_ctx); 539 LOG (GNUNET_ERROR_TYPE_DEBUG,
532 if (NULL != cm_ctx.match) 540 "Path discovered from DHT is already known\n");
533 { 541 return;
534 if (i == total_len - 1) 542 }
535 { 543 if (cm_ctx.match->entries_length == i + 1)
536 /* Existing path includes this one, nothing to do! */ 544 {
537 LOG(GNUNET_ERROR_TYPE_DEBUG, 545 /* Existing path ends in the middle of new path, extend it! */
538 "Path discovered from DHT is already known\n"); 546 LOG (GNUNET_ERROR_TYPE_DEBUG,
539 return; 547 "Trying to extend existing path %s by additional links discovered from DHT\n",
540 } 548 GCPP_2s (cm_ctx.match));
541 if (cm_ctx.match->entries_length == i + 1) 549 extend_path (cm_ctx.match,
542 { 550 &cpath[i + 1],
543 /* Existing path ends in the middle of new path, extend it! */ 551 total_len - i - 1,
544 LOG(GNUNET_ERROR_TYPE_DEBUG, 552 GNUNET_NO);
545 "Trying to extend existing path %s by additional links discovered from DHT\n", 553 return;
546 GCPP_2s(cm_ctx.match)); 554 }
547 extend_path(cm_ctx.match,
548 &cpath[i + 1],
549 total_len - i - 1,
550 GNUNET_NO);
551 return;
552 }
553 }
554 } 555 }
556 }
555 557
556 /* No match at all, create completely new path */ 558 /* No match at all, create completely new path */
557 path = GNUNET_new(struct CadetPeerPath); 559 path = GNUNET_new (struct CadetPeerPath);
558 path->entries_length = total_len; 560 path->entries_length = total_len;
559 path->entries = GNUNET_new_array(path->entries_length, 561 path->entries = GNUNET_new_array (path->entries_length,
560 struct CadetPeerPathEntry *); 562 struct CadetPeerPathEntry *);
561 for (int i = path->entries_length - 1; i >= 0; i--) 563 for (int i = path->entries_length - 1; i >= 0; i--)
562 { 564 {
563 struct CadetPeerPathEntry *entry = GNUNET_new(struct CadetPeerPathEntry); 565 struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
564 566
565 path->entries[i] = entry; 567 path->entries[i] = entry;
566 entry->peer = cpath[i]; 568 entry->peer = cpath[i];
567 entry->path = path; 569 entry->path = path;
568 } 570 }
569 for (int i = path->entries_length - 1; i >= 0; i--) 571 for (int i = path->entries_length - 1; i >= 0; i--)
570 { 572 {
571 struct CadetPeerPathEntry *entry = path->entries[i]; 573 struct CadetPeerPathEntry *entry = path->entries[i];
572 574
573 GCP_path_entry_add(entry->peer, 575 GCP_path_entry_add (entry->peer,
574 entry, 576 entry,
575 i); 577 i);
576 } 578 }
577 579
578 /* Finally, try to attach it */ 580 /* Finally, try to attach it */
579 attach_path(path, 0); 581 attach_path (path, 0);
580 if (NULL == path->hn) 582 if (NULL == path->hn)
581 { 583 {
582 /* None of the peers on the path care about it. */ 584 /* None of the peers on the path care about it. */
583 LOG(GNUNET_ERROR_TYPE_DEBUG, 585 LOG (GNUNET_ERROR_TYPE_DEBUG,
584 "Path discovered from DHT is not interesting to us\n"); 586 "Path discovered from DHT is not interesting to us\n");
585 GNUNET_assert(0 == path->entries_length); 587 GNUNET_assert (0 == path->entries_length);
586 GNUNET_assert(NULL == path->entries); 588 GNUNET_assert (NULL == path->entries);
587 GNUNET_free(path); 589 GNUNET_free (path);
588 return; 590 return;
589 } 591 }
590 LOG(GNUNET_ERROR_TYPE_DEBUG, 592 LOG (GNUNET_ERROR_TYPE_DEBUG,
591 "Created new path %s based on information from DHT\n", 593 "Created new path %s based on information from DHT\n",
592 GCPP_2s(path)); 594 GCPP_2s (path));
593} 595}
594 596
595 597
@@ -601,8 +603,8 @@ GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
601 * @return corresponding path object 603 * @return corresponding path object
602 */ 604 */
603struct CadetPeerPath * 605struct CadetPeerPath *
604GCPP_get_path_from_route(unsigned int path_length, 606GCPP_get_path_from_route (unsigned int path_length,
605 const struct GNUNET_PeerIdentity *pids) 607 const struct GNUNET_PeerIdentity *pids)
606{ 608{
607 struct CheckMatchContext cm_ctx; 609 struct CheckMatchContext cm_ctx;
608 struct CadetPeer *cpath[path_length]; 610 struct CadetPeer *cpath[path_length];
@@ -611,8 +613,8 @@ GCPP_get_path_from_route(unsigned int path_length,
611 /* precompute inverted 'cpath' so we can avoid doing the lookups and 613 /* precompute inverted 'cpath' so we can avoid doing the lookups and
612 have the correct order */ 614 have the correct order */
613 for (unsigned int off = 0; off < path_length; off++) 615 for (unsigned int off = 0; off < path_length; off++)
614 cpath[off] = GCP_get(&pids[path_length - 1 - off], 616 cpath[off] = GCP_get (&pids[path_length - 1 - off],
615 GNUNET_YES); 617 GNUNET_YES);
616 618
617 /* First figure out if this path is a subset of an existing path, an 619 /* First figure out if this path is a subset of an existing path, an
618 extension of an existing path, or a new path. */ 620 extension of an existing path, or a new path. */
@@ -620,69 +622,69 @@ GCPP_get_path_from_route(unsigned int path_length,
620 cm_ctx.cpath_length = path_length; 622 cm_ctx.cpath_length = path_length;
621 cm_ctx.match = NULL; 623 cm_ctx.match = NULL;
622 for (int i = path_length - 1; i >= 0; i--) 624 for (int i = path_length - 1; i >= 0; i--)
625 {
626 GCP_iterate_paths_at (cpath[i],
627 (unsigned int) i,
628 &check_match,
629 &cm_ctx);
630 if (NULL != cm_ctx.match)
623 { 631 {
624 GCP_iterate_paths_at(cpath[i], 632 if (i == path_length - 1)
625 (unsigned int)i, 633 {
626 &check_match, 634 /* Existing path includes this one, return the match! */
627 &cm_ctx); 635 LOG (GNUNET_ERROR_TYPE_DEBUG,
628 if (NULL != cm_ctx.match) 636 "Returning existing path %s as inverse for incoming connection\n",
629 { 637 GCPP_2s (cm_ctx.match));
630 if (i == path_length - 1) 638 return cm_ctx.match;
631 { 639 }
632 /* Existing path includes this one, return the match! */ 640 if (cm_ctx.match->entries_length == i + 1)
633 LOG(GNUNET_ERROR_TYPE_DEBUG, 641 {
634 "Returning existing path %s as inverse for incoming connection\n", 642 /* Existing path ends in the middle of new path, extend it! */
635 GCPP_2s(cm_ctx.match)); 643 LOG (GNUNET_ERROR_TYPE_DEBUG,
636 return cm_ctx.match; 644 "Extending existing path %s to create inverse for incoming connection\n",
637 } 645 GCPP_2s (cm_ctx.match));
638 if (cm_ctx.match->entries_length == i + 1) 646 extend_path (cm_ctx.match,
639 { 647 &cpath[i + 1],
640 /* Existing path ends in the middle of new path, extend it! */ 648 path_length - i - 1,
641 LOG(GNUNET_ERROR_TYPE_DEBUG, 649 GNUNET_YES);
642 "Extending existing path %s to create inverse for incoming connection\n", 650 /* Check that extension was successful */
643 GCPP_2s(cm_ctx.match)); 651 GNUNET_assert (cm_ctx.match->entries_length == path_length);
644 extend_path(cm_ctx.match, 652 return cm_ctx.match;
645 &cpath[i + 1], 653 }
646 path_length - i - 1, 654 /* Eh, we found a match but couldn't use it? Something is wrong. */
647 GNUNET_YES); 655 GNUNET_break (0);
648 /* Check that extension was successful */
649 GNUNET_assert(cm_ctx.match->entries_length == path_length);
650 return cm_ctx.match;
651 }
652 /* Eh, we found a match but couldn't use it? Something is wrong. */
653 GNUNET_break(0);
654 }
655 } 656 }
657 }
656 658
657 /* No match at all, create completely new path */ 659 /* No match at all, create completely new path */
658 path = GNUNET_new(struct CadetPeerPath); 660 path = GNUNET_new (struct CadetPeerPath);
659 path->entries_length = path_length; 661 path->entries_length = path_length;
660 path->entries = GNUNET_new_array(path->entries_length, 662 path->entries = GNUNET_new_array (path->entries_length,
661 struct CadetPeerPathEntry *); 663 struct CadetPeerPathEntry *);
662 for (int i = path_length - 1; i >= 0; i--) 664 for (int i = path_length - 1; i >= 0; i--)
663 { 665 {
664 struct CadetPeerPathEntry *entry = GNUNET_new(struct CadetPeerPathEntry); 666 struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
665 667
666 path->entries[i] = entry; 668 path->entries[i] = entry;
667 entry->peer = cpath[i]; 669 entry->peer = cpath[i];
668 entry->path = path; 670 entry->path = path;
669 } 671 }
670 for (int i = path_length - 1; i >= 0; i--) 672 for (int i = path_length - 1; i >= 0; i--)
671 { 673 {
672 struct CadetPeerPathEntry *entry = path->entries[i]; 674 struct CadetPeerPathEntry *entry = path->entries[i];
673 675
674 GCP_path_entry_add(entry->peer, 676 GCP_path_entry_add (entry->peer,
675 entry, 677 entry,
676 i); 678 i);
677 } 679 }
678 recalculate_path_desirability(path); 680 recalculate_path_desirability (path);
679 LOG(GNUNET_ERROR_TYPE_DEBUG, 681 LOG (GNUNET_ERROR_TYPE_DEBUG,
680 "Created new path %s to create inverse for incoming connection\n", 682 "Created new path %s to create inverse for incoming connection\n",
681 GCPP_2s(path)); 683 GCPP_2s (path));
682 path->hn = GCP_attach_path(cpath[path_length - 1], 684 path->hn = GCP_attach_path (cpath[path_length - 1],
683 path, 685 path,
684 path_length - 1, 686 path_length - 1,
685 GNUNET_YES); 687 GNUNET_YES);
686 return path; 688 return path;
687} 689}
688 690
@@ -695,7 +697,7 @@ GCPP_get_path_from_route(unsigned int path_length,
695 * @return number of peers on the path 697 * @return number of peers on the path
696 */ 698 */
697unsigned int 699unsigned int
698GCPP_get_length(struct CadetPeerPath *path) 700GCPP_get_length (struct CadetPeerPath *path)
699{ 701{
700 return path->entries_length; 702 return path->entries_length;
701} 703}
@@ -709,14 +711,14 @@ GCPP_get_length(struct CadetPeerPath *path)
709 * @return offset of @a cp on @a path, or UINT_MAX if not found 711 * @return offset of @a cp on @a path, or UINT_MAX if not found
710 */ 712 */
711unsigned int 713unsigned int
712GCPP_find_peer(struct CadetPeerPath *path, 714GCPP_find_peer (struct CadetPeerPath *path,
713 struct CadetPeer *cp) 715 struct CadetPeer *cp)
714{ 716{
715 for (unsigned int off = 0; 717 for (unsigned int off = 0;
716 off < path->entries_length; 718 off < path->entries_length;
717 off++) 719 off++)
718 if (cp == GCPP_get_peer_at_offset(path, 720 if (cp == GCPP_get_peer_at_offset (path,
719 off)) 721 off))
720 return off; 722 return off;
721 return UINT_MAX; 723 return UINT_MAX;
722} 724}
@@ -730,10 +732,10 @@ GCPP_find_peer(struct CadetPeerPath *path,
730 * @return the peer at offset @a off 732 * @return the peer at offset @a off
731 */ 733 */
732struct CadetPeer * 734struct CadetPeer *
733GCPP_get_peer_at_offset(struct CadetPeerPath *path, 735GCPP_get_peer_at_offset (struct CadetPeerPath *path,
734 unsigned int off) 736 unsigned int off)
735{ 737{
736 GNUNET_assert(off < path->entries_length); 738 GNUNET_assert (off < path->entries_length);
737 return path->entries[off]->peer; 739 return path->entries[off]->peer;
738} 740}
739 741
@@ -745,7 +747,7 @@ GCPP_get_peer_at_offset(struct CadetPeerPath *path,
745 * @return string, to be freed by caller (unlike other *_2s APIs!) 747 * @return string, to be freed by caller (unlike other *_2s APIs!)
746 */ 748 */
747const char * 749const char *
748GCPP_2s(struct CadetPeerPath *path) 750GCPP_2s (struct CadetPeerPath *path)
749{ 751{
750 static char buf[2048]; 752 static char buf[2048];
751 size_t off; 753 size_t off;
@@ -755,27 +757,28 @@ GCPP_2s(struct CadetPeerPath *path)
755 for (unsigned int i = 0; 757 for (unsigned int i = 0;
756 i < path->entries_length; 758 i < path->entries_length;
757 i++) 759 i++)
758 { 760 {
759 if ((path->entries_length > max_plen) && 761 if ((path->entries_length > max_plen) &&
760 (i == max_plen / 2)) 762 (i == max_plen / 2))
761 off += GNUNET_snprintf(&buf[off], 763 off += GNUNET_snprintf (&buf[off],
762 sizeof(buf) - off, 764 sizeof(buf) - off,
763 "...-"); 765 "...-");
764 if ((path->entries_length > max_plen) && 766 if ((path->entries_length > max_plen) &&
765 (i > max_plen / 2) && 767 (i > max_plen / 2) &&
766 (i < path->entries_length - max_plen / 2)) 768 (i < path->entries_length - max_plen / 2))
767 continue; 769 continue;
768 off += GNUNET_snprintf(&buf[off], 770 off += GNUNET_snprintf (&buf[off],
769 sizeof(buf) - off, 771 sizeof(buf) - off,
770 "%s%s", 772 "%s%s",
771 GNUNET_i2s(GCP_get_id(GCPP_get_peer_at_offset(path, 773 GNUNET_i2s (GCP_get_id (GCPP_get_peer_at_offset (
772 i))), 774 path,
773 (i == path->entries_length - 1) ? "" : "-"); 775 i))),
774 } 776 (i == path->entries_length - 1) ? "" : "-");
775 GNUNET_snprintf(&buf[off], 777 }
776 sizeof(buf) - off, 778 GNUNET_snprintf (&buf[off],
777 "(%p)", 779 sizeof(buf) - off,
778 path); 780 "(%p)",
781 path);
779 return buf; 782 return buf;
780} 783}
781 784
diff --git a/src/cadet/gnunet-service-cadet_paths.h b/src/cadet/gnunet-service-cadet_paths.h
index 399f91516..125ea669a 100644
--- a/src/cadet/gnunet-service-cadet_paths.h
+++ b/src/cadet/gnunet-service-cadet_paths.h
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of GNUnet. 2 This file is part of GNUnet.
4 Copyright (C) 2001-2017 GNUnet e.V. 3 Copyright (C) 2001-2017 GNUnet e.V.
@@ -43,10 +42,10 @@
43 * @param put_path_length length of the @a put_path 42 * @param put_path_length length of the @a put_path
44 */ 43 */
45void 44void
46GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path, 45GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
47 unsigned int get_path_length, 46 unsigned int get_path_length,
48 const struct GNUNET_PeerIdentity *put_path, 47 const struct GNUNET_PeerIdentity *put_path,
49 unsigned int put_path_length); 48 unsigned int put_path_length);
50 49
51 50
52/** 51/**
@@ -57,8 +56,8 @@ GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
57 * @return corresponding path object 56 * @return corresponding path object
58 */ 57 */
59struct CadetPeerPath * 58struct CadetPeerPath *
60GCPP_get_path_from_route(unsigned int path_length, 59GCPP_get_path_from_route (unsigned int path_length,
61 const struct GNUNET_PeerIdentity *pids); 60 const struct GNUNET_PeerIdentity *pids);
62 61
63 62
64/** 63/**
@@ -69,7 +68,7 @@ GCPP_get_path_from_route(unsigned int path_length,
69 * @return number of peers on the path 68 * @return number of peers on the path
70 */ 69 */
71unsigned int 70unsigned int
72GCPP_get_length(struct CadetPeerPath *path); 71GCPP_get_length (struct CadetPeerPath *path);
73 72
74 73
75/** 74/**
@@ -83,9 +82,9 @@ GCPP_get_length(struct CadetPeerPath *path);
83 * otherwise connection from us to @a destination via @a path 82 * otherwise connection from us to @a destination via @a path
84 */ 83 */
85struct CadetConnection * 84struct CadetConnection *
86GCPP_get_connection(struct CadetPeerPath *path, 85GCPP_get_connection (struct CadetPeerPath *path,
87 struct CadetPeer *destination, 86 struct CadetPeer *destination,
88 unsigned int off); 87 unsigned int off);
89 88
90 89
91/** 90/**
@@ -97,9 +96,9 @@ GCPP_get_connection(struct CadetPeerPath *path,
97 * @param cc the connection to remember 96 * @param cc the connection to remember
98 */ 97 */
99void 98void
100GCPP_add_connection(struct CadetPeerPath *path, 99GCPP_add_connection (struct CadetPeerPath *path,
101 unsigned int off, 100 unsigned int off,
102 struct CadetConnection *cc); 101 struct CadetConnection *cc);
103 102
104 103
105/** 104/**
@@ -111,9 +110,9 @@ GCPP_add_connection(struct CadetPeerPath *path,
111 * @param cc the connection to forget 110 * @param cc the connection to forget
112 */ 111 */
113void 112void
114GCPP_del_connection(struct CadetPeerPath *path, 113GCPP_del_connection (struct CadetPeerPath *path,
115 unsigned int off, 114 unsigned int off,
116 struct CadetConnection *cc); 115 struct CadetConnection *cc);
117 116
118 117
119/** 118/**
@@ -124,8 +123,8 @@ GCPP_del_connection(struct CadetPeerPath *path,
124 * @return offset of @a cp on @a path, or UINT_MAX if not found 123 * @return offset of @a cp on @a path, or UINT_MAX if not found
125 */ 124 */
126unsigned int 125unsigned int
127GCPP_find_peer(struct CadetPeerPath *path, 126GCPP_find_peer (struct CadetPeerPath *path,
128 struct CadetPeer *cp); 127 struct CadetPeer *cp);
129 128
130 129
131/** 130/**
@@ -142,7 +141,7 @@ GCPP_find_peer(struct CadetPeerPath *path,
142 * @return desirability of the path, larger is more desirable 141 * @return desirability of the path, larger is more desirable
143 */ 142 */
144GNUNET_CONTAINER_HeapCostType 143GNUNET_CONTAINER_HeapCostType
145GCPP_get_desirability(const struct CadetPeerPath *path); 144GCPP_get_desirability (const struct CadetPeerPath *path);
146 145
147 146
148/** 147/**
@@ -154,7 +153,7 @@ GCPP_get_desirability(const struct CadetPeerPath *path);
154 * @param path the path that is being released 153 * @param path the path that is being released
155 */ 154 */
156void 155void
157GCPP_release(struct CadetPeerPath *path); 156GCPP_release (struct CadetPeerPath *path);
158 157
159 158
160/** 159/**
@@ -165,8 +164,8 @@ GCPP_release(struct CadetPeerPath *path);
165 * @return peer at offset @a off 164 * @return peer at offset @a off
166 */ 165 */
167struct CadetPeer * 166struct CadetPeer *
168GCPP_get_peer_at_offset(struct CadetPeerPath *path, 167GCPP_get_peer_at_offset (struct CadetPeerPath *path,
169 unsigned int off); 168 unsigned int off);
170 169
171 170
172/** 171/**
@@ -176,7 +175,7 @@ GCPP_get_peer_at_offset(struct CadetPeerPath *path,
176 * @return string, statically allocated 175 * @return string, statically allocated
177 */ 176 */
178const char * 177const char *
179GCPP_2s(struct CadetPeerPath *p); 178GCPP_2s (struct CadetPeerPath *p);
180 179
181 180
182#endif 181#endif
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 23eb6b225..52a0c2bd3 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -46,18 +46,20 @@
46#include "gnunet-service-cadet_tunnels.h" 46#include "gnunet-service-cadet_tunnels.h"
47 47
48 48
49#define LOG(level, ...) GNUNET_log_from(level, "cadet-per", __VA_ARGS__) 49#define LOG(level, ...) GNUNET_log_from (level, "cadet-per", __VA_ARGS__)
50 50
51 51
52/** 52/**
53 * How long do we wait until tearing down an idle peer? 53 * How long do we wait until tearing down an idle peer?
54 */ 54 */
55#define IDLE_PEER_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) 55#define IDLE_PEER_TIMEOUT GNUNET_TIME_relative_multiply ( \
56 GNUNET_TIME_UNIT_MINUTES, 5)
56 57
57/** 58/**
58 * How long do we keep paths around if we no longer care about the peer? 59 * How long do we keep paths around if we no longer care about the peer?
59 */ 60 */
60#define IDLE_PATH_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) 61#define IDLE_PATH_TIMEOUT GNUNET_TIME_relative_multiply ( \
62 GNUNET_TIME_UNIT_MINUTES, 2)
61 63
62/** 64/**
63 * Queue size when we start dropping OOO messages. 65 * Queue size when we start dropping OOO messages.
@@ -69,7 +71,8 @@
69 * Data structure used to track whom we have to notify about changes 71 * Data structure used to track whom we have to notify about changes
70 * to our message queue. 72 * to our message queue.
71 */ 73 */
72struct GCP_MessageQueueManager { 74struct GCP_MessageQueueManager
75{
73 /** 76 /**
74 * Kept in a DLL. 77 * Kept in a DLL.
75 */ 78 */
@@ -105,7 +108,8 @@ struct GCP_MessageQueueManager {
105/** 108/**
106 * Struct containing all information regarding a given peer 109 * Struct containing all information regarding a given peer
107 */ 110 */
108struct CadetPeer { 111struct CadetPeer
112{
109 /** 113 /**
110 * ID of the peer 114 * ID of the peer
111 */ 115 */
@@ -235,23 +239,23 @@ struct CadetPeer {
235 * @return Static string for it's ID. 239 * @return Static string for it's ID.
236 */ 240 */
237const char * 241const char *
238GCP_2s(const struct CadetPeer *cp) 242GCP_2s (const struct CadetPeer *cp)
239{ 243{
240 static char buf[5]; 244 static char buf[5];
241 char *ret; 245 char *ret;
242 246
243 if ((NULL == cp) || 247 if ((NULL == cp) ||
244 (0 == GNUNET_is_zero(&cp->pid.public_key))) 248 (0 == GNUNET_is_zero (&cp->pid.public_key)))
245 return "NULL"; 249 return "NULL";
246 250
247 ret = GNUNET_CRYPTO_eddsa_public_key_to_string(&cp->pid.public_key); 251 ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&cp->pid.public_key);
248 if (NULL == ret) 252 if (NULL == ret)
249 return "NULL"; 253 return "NULL";
250 254
251 GNUNET_strlcpy(buf, 255 GNUNET_strlcpy (buf,
252 ret, 256 ret,
253 sizeof(buf)); 257 sizeof(buf));
254 GNUNET_free(ret); 258 GNUNET_free (ret);
255 return buf; 259 return buf;
256} 260}
257 261
@@ -272,8 +276,8 @@ GCP_2s(const struct CadetPeer *cp)
272 * positive scores mean path is more desirable 276 * positive scores mean path is more desirable
273 */ 277 */
274double 278double
275GCP_get_desirability_of_path(struct CadetPeer *cp, 279GCP_get_desirability_of_path (struct CadetPeer *cp,
276 unsigned int off) 280 unsigned int off)
277{ 281{
278 unsigned int num_alts = cp->num_paths; 282 unsigned int num_alts = cp->num_paths;
279 unsigned int off_sum; 283 unsigned int off_sum;
@@ -281,8 +285,8 @@ GCP_get_desirability_of_path(struct CadetPeer *cp,
281 double path_delta; 285 double path_delta;
282 double weight_alts; 286 double weight_alts;
283 287
284 GNUNET_assert(num_alts >= 1); /* 'path' should be in there! */ 288 GNUNET_assert (num_alts >= 1); /* 'path' should be in there! */
285 GNUNET_assert(0 != cp->path_dll_length); 289 GNUNET_assert (0 != cp->path_dll_length);
286 290
287 /* We maintain 'off_sum' in 'peer' and thereby 291 /* We maintain 'off_sum' in 'peer' and thereby
288 avoid the SLOW recalculation each time. Kept here 292 avoid the SLOW recalculation each time. Kept here
@@ -294,7 +298,7 @@ GCP_get_desirability_of_path(struct CadetPeer *cp,
294 NULL != pe; 298 NULL != pe;
295 pe = pe->next) 299 pe = pe->next)
296 off_sum += j; 300 off_sum += j;
297 GNUNET_assert(off_sum == cp->off_sum); 301 GNUNET_assert (off_sum == cp->off_sum);
298#else 302#else
299 off_sum = cp->off_sum; 303 off_sum = cp->off_sum;
300#endif 304#endif
@@ -323,63 +327,63 @@ GCP_get_desirability_of_path(struct CadetPeer *cp,
323 * @param cls peer to clean up 327 * @param cls peer to clean up
324 */ 328 */
325static void 329static void
326destroy_peer(void *cls) 330destroy_peer (void *cls)
327{ 331{
328 struct CadetPeer *cp = cls; 332 struct CadetPeer *cp = cls;
329 333
330 LOG(GNUNET_ERROR_TYPE_DEBUG, 334 LOG (GNUNET_ERROR_TYPE_DEBUG,
331 "Destroying state about peer %s\n", 335 "Destroying state about peer %s\n",
332 GCP_2s(cp)); 336 GCP_2s (cp));
333 cp->destroy_task = NULL; 337 cp->destroy_task = NULL;
334 GNUNET_assert(NULL == cp->t); 338 GNUNET_assert (NULL == cp->t);
335 GNUNET_assert(NULL == cp->core_mq); 339 GNUNET_assert (NULL == cp->core_mq);
336 GNUNET_assert(0 == cp->num_paths); 340 GNUNET_assert (0 == cp->num_paths);
337 for (unsigned int i = 0; i < cp->path_dll_length; i++) 341 for (unsigned int i = 0; i < cp->path_dll_length; i++)
338 GNUNET_assert(NULL == cp->path_heads[i]); 342 GNUNET_assert (NULL == cp->path_heads[i]);
339 GNUNET_assert(0 == GNUNET_CONTAINER_multishortmap_size(cp->connections)); 343 GNUNET_assert (0 == GNUNET_CONTAINER_multishortmap_size (cp->connections));
340 GNUNET_assert(GNUNET_YES == 344 GNUNET_assert (GNUNET_YES ==
341 GNUNET_CONTAINER_multipeermap_remove(peers, 345 GNUNET_CONTAINER_multipeermap_remove (peers,
342 &cp->pid, 346 &cp->pid,
343 cp)); 347 cp));
344 GNUNET_free_non_null(cp->path_heads); 348 GNUNET_free_non_null (cp->path_heads);
345 GNUNET_free_non_null(cp->path_tails); 349 GNUNET_free_non_null (cp->path_tails);
346 cp->path_dll_length = 0; 350 cp->path_dll_length = 0;
347 if (NULL != cp->search_h) 351 if (NULL != cp->search_h)
348 { 352 {
349 GCD_search_stop(cp->search_h); 353 GCD_search_stop (cp->search_h);
350 cp->search_h = NULL; 354 cp->search_h = NULL;
351 } 355 }
352 /* FIXME: clean up search_delayedXXX! */ 356 /* FIXME: clean up search_delayedXXX! */
353 357
354 if (NULL != cp->hello_offer) 358 if (NULL != cp->hello_offer)
355 { 359 {
356 GNUNET_TRANSPORT_offer_hello_cancel(cp->hello_offer); 360 GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer);
357 cp->hello_offer = NULL; 361 cp->hello_offer = NULL;
358 } 362 }
359 if (NULL != cp->connectivity_suggestion) 363 if (NULL != cp->connectivity_suggestion)
360 { 364 {
361 GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion); 365 GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion);
362 cp->connectivity_suggestion = NULL; 366 cp->connectivity_suggestion = NULL;
363 } 367 }
364 GNUNET_CONTAINER_multishortmap_destroy(cp->connections); 368 GNUNET_CONTAINER_multishortmap_destroy (cp->connections);
365 if (NULL != cp->path_heap) 369 if (NULL != cp->path_heap)
366 { 370 {
367 GNUNET_CONTAINER_heap_destroy(cp->path_heap); 371 GNUNET_CONTAINER_heap_destroy (cp->path_heap);
368 cp->path_heap = NULL; 372 cp->path_heap = NULL;
369 } 373 }
370 if (NULL != cp->heap_cleanup_task) 374 if (NULL != cp->heap_cleanup_task)
371 { 375 {
372 GNUNET_SCHEDULER_cancel(cp->heap_cleanup_task); 376 GNUNET_SCHEDULER_cancel (cp->heap_cleanup_task);
373 cp->heap_cleanup_task = NULL; 377 cp->heap_cleanup_task = NULL;
374 } 378 }
375 GNUNET_free_non_null(cp->hello); 379 GNUNET_free_non_null (cp->hello);
376 /* Peer should not be freed if paths exist; if there are no paths, 380 /* Peer should not be freed if paths exist; if there are no paths,
377 there ought to be no connections, and without connections, no 381 there ought to be no connections, and without connections, no
378 notifications. Thus we can assert that mqm_head is empty at this 382 notifications. Thus we can assert that mqm_head is empty at this
379 point. */ 383 point. */
380 GNUNET_assert(NULL == cp->mqm_head); 384 GNUNET_assert (NULL == cp->mqm_head);
381 GNUNET_assert(NULL == cp->mqm_ready_ptr); 385 GNUNET_assert (NULL == cp->mqm_ready_ptr);
382 GNUNET_free(cp); 386 GNUNET_free (cp);
383} 387}
384 388
385 389
@@ -389,64 +393,64 @@ destroy_peer(void *cls)
389 * @param cp the more-active peer 393 * @param cp the more-active peer
390 */ 394 */
391static void 395static void
392consider_peer_activate(struct CadetPeer *cp) 396consider_peer_activate (struct CadetPeer *cp)
393{ 397{
394 uint32_t strength; 398 uint32_t strength;
395 399
396 LOG(GNUNET_ERROR_TYPE_DEBUG, 400 LOG (GNUNET_ERROR_TYPE_DEBUG,
397 "Updating peer %s activation state (%u connections)%s%s\n", 401 "Updating peer %s activation state (%u connections)%s%s\n",
398 GCP_2s(cp), 402 GCP_2s (cp),
399 GNUNET_CONTAINER_multishortmap_size(cp->connections), 403 GNUNET_CONTAINER_multishortmap_size (cp->connections),
400 (NULL == cp->t) ? "" : " with tunnel", 404 (NULL == cp->t) ? "" : " with tunnel",
401 (NULL == cp->core_mq) ? "" : " with CORE link"); 405 (NULL == cp->core_mq) ? "" : " with CORE link");
402 if (NULL != cp->destroy_task) 406 if (NULL != cp->destroy_task)
403 { 407 {
404 /* It's active, do not destory! */ 408 /* It's active, do not destory! */
405 GNUNET_SCHEDULER_cancel(cp->destroy_task); 409 GNUNET_SCHEDULER_cancel (cp->destroy_task);
406 cp->destroy_task = NULL; 410 cp->destroy_task = NULL;
407 } 411 }
408 if ((0 == GNUNET_CONTAINER_multishortmap_size(cp->connections)) && 412 if ((0 == GNUNET_CONTAINER_multishortmap_size (cp->connections)) &&
409 (NULL == cp->t)) 413 (NULL == cp->t))
414 {
415 /* We're just on a path or directly connected; don't bother too much */
416 if (NULL != cp->connectivity_suggestion)
410 { 417 {
411 /* We're just on a path or directly connected; don't bother too much */ 418 GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion);
412 if (NULL != cp->connectivity_suggestion) 419 cp->connectivity_suggestion = NULL;
413 {
414 GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion);
415 cp->connectivity_suggestion = NULL;
416 }
417 if (NULL != cp->search_h)
418 {
419 GCD_search_stop(cp->search_h);
420 cp->search_h = NULL;
421 }
422 return;
423 } 420 }
424 if (NULL == cp->core_mq) 421 if (NULL != cp->search_h)
425 { 422 {
426 /* Lacks direct connection, try to create one by querying the DHT */ 423 GCD_search_stop (cp->search_h);
427 if ((NULL == cp->search_h) && 424 cp->search_h = NULL;
428 (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths))
429 cp->search_h
430 = GCD_search(&cp->pid);
431 } 425 }
426 return;
427 }
428 if (NULL == cp->core_mq)
429 {
430 /* Lacks direct connection, try to create one by querying the DHT */
431 if ((NULL == cp->search_h) &&
432 (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths))
433 cp->search_h
434 = GCD_search (&cp->pid);
435 }
432 else 436 else
437 {
438 /* Have direct connection, stop DHT search if active */
439 if (NULL != cp->search_h)
433 { 440 {
434 /* Have direct connection, stop DHT search if active */ 441 GCD_search_stop (cp->search_h);
435 if (NULL != cp->search_h) 442 cp->search_h = NULL;
436 {
437 GCD_search_stop(cp->search_h);
438 cp->search_h = NULL;
439 }
440 } 443 }
444 }
441 445
442 /* If we have a tunnel, our urge for connections is much bigger */ 446 /* If we have a tunnel, our urge for connections is much bigger */
443 strength = (NULL != cp->t) ? 32 : 1; 447 strength = (NULL != cp->t) ? 32 : 1;
444 if (NULL != cp->connectivity_suggestion) 448 if (NULL != cp->connectivity_suggestion)
445 GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion); 449 GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion);
446 cp->connectivity_suggestion 450 cp->connectivity_suggestion
447 = GNUNET_ATS_connectivity_suggest(ats_ch, 451 = GNUNET_ATS_connectivity_suggest (ats_ch,
448 &cp->pid, 452 &cp->pid,
449 strength); 453 strength);
450} 454}
451 455
452 456
@@ -456,7 +460,7 @@ consider_peer_activate(struct CadetPeer *cp)
456 * @param cp peer to clean up 460 * @param cp peer to clean up
457 */ 461 */
458static void 462static void
459consider_peer_destroy(struct CadetPeer *cp); 463consider_peer_destroy (struct CadetPeer *cp);
460 464
461 465
462/** 466/**
@@ -466,15 +470,15 @@ consider_peer_destroy(struct CadetPeer *cp);
466 * @param cls a `struct CadetPeer`. 470 * @param cls a `struct CadetPeer`.
467 */ 471 */
468static void 472static void
469drop_paths(void *cls) 473drop_paths (void *cls)
470{ 474{
471 struct CadetPeer *cp = cls; 475 struct CadetPeer *cp = cls;
472 struct CadetPeerPath *path; 476 struct CadetPeerPath *path;
473 477
474 cp->destroy_task = NULL; 478 cp->destroy_task = NULL;
475 while (NULL != (path = GNUNET_CONTAINER_heap_remove_root(cp->path_heap))) 479 while (NULL != (path = GNUNET_CONTAINER_heap_remove_root (cp->path_heap)))
476 GCPP_release(path); 480 GCPP_release (path);
477 consider_peer_destroy(cp); 481 consider_peer_destroy (cp);
478} 482}
479 483
480 484
@@ -484,43 +488,44 @@ drop_paths(void *cls)
484 * @param cp peer to clean up 488 * @param cp peer to clean up
485 */ 489 */
486static void 490static void
487consider_peer_destroy(struct CadetPeer *cp) 491consider_peer_destroy (struct CadetPeer *cp)
488{ 492{
489 struct GNUNET_TIME_Relative exp; 493 struct GNUNET_TIME_Relative exp;
490 494
491 if (NULL != cp->destroy_task) 495 if (NULL != cp->destroy_task)
492 { 496 {
493 GNUNET_SCHEDULER_cancel(cp->destroy_task); 497 GNUNET_SCHEDULER_cancel (cp->destroy_task);
494 cp->destroy_task = NULL; 498 cp->destroy_task = NULL;
495 } 499 }
496 if (NULL != cp->t) 500 if (NULL != cp->t)
497 return; /* still relevant! */ 501 return; /* still relevant! */
498 if (NULL != cp->core_mq) 502 if (NULL != cp->core_mq)
499 return; /* still relevant! */ 503 return; /* still relevant! */
500 if (0 != GNUNET_CONTAINER_multishortmap_size(cp->connections)) 504 if (0 != GNUNET_CONTAINER_multishortmap_size (cp->connections))
501 return; /* still relevant! */ 505 return; /* still relevant! */
502 if ((NULL != cp->path_heap) && 506 if ((NULL != cp->path_heap) &&
503 (0 < GNUNET_CONTAINER_heap_get_size(cp->path_heap))) 507 (0 < GNUNET_CONTAINER_heap_get_size (cp->path_heap)))
504 { 508 {
505 cp->destroy_task = GNUNET_SCHEDULER_add_delayed(IDLE_PATH_TIMEOUT, 509 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PATH_TIMEOUT,
506 &drop_paths, 510 &drop_paths,
507 cp); 511 cp);
508 return; 512 return;
509 } 513 }
510 if (0 != cp->num_paths) 514 if (0 != cp->num_paths)
511 return; /* still relevant! */ 515 return; /* still relevant! */
512 if (NULL != cp->hello) 516 if (NULL != cp->hello)
513 { 517 {
514 /* relevant only until HELLO expires */ 518 /* relevant only until HELLO expires */
515 exp = GNUNET_TIME_absolute_get_remaining(GNUNET_HELLO_get_last_expiration(cp->hello)); 519 exp = GNUNET_TIME_absolute_get_remaining (GNUNET_HELLO_get_last_expiration (
516 cp->destroy_task = GNUNET_SCHEDULER_add_delayed(exp, 520 cp->hello));
517 &destroy_peer, 521 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (exp,
518 cp); 522 &destroy_peer,
519 return; 523 cp);
520 } 524 return;
521 cp->destroy_task = GNUNET_SCHEDULER_add_delayed(IDLE_PEER_TIMEOUT, 525 }
522 &destroy_peer, 526 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PEER_TIMEOUT,
523 cp); 527 &destroy_peer,
528 cp);
524} 529}
525 530
526 531
@@ -531,60 +536,60 @@ consider_peer_destroy(struct CadetPeer *cp)
531 * @param mq message queue to set (can be NULL) 536 * @param mq message queue to set (can be NULL)
532 */ 537 */
533void 538void
534GCP_set_mq(struct CadetPeer *cp, 539GCP_set_mq (struct CadetPeer *cp,
535 struct GNUNET_MQ_Handle *mq) 540 struct GNUNET_MQ_Handle *mq)
536{ 541{
537 LOG(GNUNET_ERROR_TYPE_DEBUG, 542 LOG (GNUNET_ERROR_TYPE_DEBUG,
538 "Message queue for peer %s is now %p\n", 543 "Message queue for peer %s is now %p\n",
539 GCP_2s(cp), 544 GCP_2s (cp),
540 mq); 545 mq);
541 cp->core_mq = mq; 546 cp->core_mq = mq;
542 for (struct GCP_MessageQueueManager *mqm = cp->mqm_head, *next; 547 for (struct GCP_MessageQueueManager *mqm = cp->mqm_head, *next;
543 NULL != mqm; 548 NULL != mqm;
544 mqm = next) 549 mqm = next)
550 {
551 /* Save next pointer in case mqm gets freed by the callback */
552 next = mqm->next;
553 if (NULL == mq)
545 { 554 {
546 /* Save next pointer in case mqm gets freed by the callback */ 555 if (NULL != mqm->env)
547 next = mqm->next; 556 {
548 if (NULL == mq) 557 GNUNET_MQ_discard (mqm->env);
549 { 558 mqm->env = NULL;
550 if (NULL != mqm->env) 559 mqm->cb (mqm->cb_cls,
551 { 560 GNUNET_SYSERR);
552 GNUNET_MQ_discard(mqm->env); 561 }
553 mqm->env = NULL;
554 mqm->cb(mqm->cb_cls,
555 GNUNET_SYSERR);
556 }
557 else
558 {
559 mqm->cb(mqm->cb_cls,
560 GNUNET_NO);
561 }
562 }
563 else 562 else
564 { 563 {
565 GNUNET_assert(NULL == mqm->env); 564 mqm->cb (mqm->cb_cls,
566 mqm->cb(mqm->cb_cls, 565 GNUNET_NO);
567 GNUNET_YES); 566 }
568 } 567 }
568 else
569 {
570 GNUNET_assert (NULL == mqm->env);
571 mqm->cb (mqm->cb_cls,
572 GNUNET_YES);
569 } 573 }
574 }
570 if ((NULL != mq) || 575 if ((NULL != mq) ||
571 (NULL != cp->t)) 576 (NULL != cp->t))
572 consider_peer_activate(cp); 577 consider_peer_activate (cp);
573 else 578 else
574 consider_peer_destroy(cp); 579 consider_peer_destroy (cp);
575 580
576 if ((NULL != mq) && 581 if ((NULL != mq) &&
577 (NULL != cp->t)) 582 (NULL != cp->t))
578 { 583 {
579 /* have a new, direct path to the target, notify tunnel */ 584 /* have a new, direct path to the target, notify tunnel */
580 struct CadetPeerPath *path; 585 struct CadetPeerPath *path;
581 586
582 path = GCPP_get_path_from_route(1, 587 path = GCPP_get_path_from_route (1,
583 &cp->pid); 588 &cp->pid);
584 GCT_consider_path(cp->t, 589 GCT_consider_path (cp->t,
585 path, 590 path,
586 0); 591 0);
587 } 592 }
588} 593}
589 594
590 595
@@ -595,12 +600,12 @@ GCP_set_mq(struct CadetPeer *cp,
595 * @return #GNUNET_YES or #GNUNET_NO with the decision to drop. 600 * @return #GNUNET_YES or #GNUNET_NO with the decision to drop.
596 */ 601 */
597static int 602static int
598should_I_drop(void) 603should_I_drop (void)
599{ 604{
600 if (0 == drop_percent) 605 if (0 == drop_percent)
601 return GNUNET_NO; 606 return GNUNET_NO;
602 if (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 607 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
603 101) < drop_percent) 608 101) < drop_percent)
604 return GNUNET_YES; 609 return GNUNET_YES;
605 return GNUNET_NO; 610 return GNUNET_NO;
606} 611}
@@ -613,7 +618,7 @@ should_I_drop(void)
613 * @param cls the `struct CadetPeeer` where we made progress 618 * @param cls the `struct CadetPeeer` where we made progress
614 */ 619 */
615static void 620static void
616mqm_send_done(void *cls); 621mqm_send_done (void *cls);
617 622
618 623
619/** 624/**
@@ -622,7 +627,7 @@ mqm_send_done(void *cls);
622 * @param mqm mqm to transmit message for now 627 * @param mqm mqm to transmit message for now
623 */ 628 */
624static void 629static void
625mqm_execute(struct GCP_MessageQueueManager *mqm) 630mqm_execute (struct GCP_MessageQueueManager *mqm)
626{ 631{
627 struct CadetPeer *cp = mqm->cp; 632 struct CadetPeer *cp = mqm->cp;
628 633
@@ -632,59 +637,59 @@ mqm_execute(struct GCP_MessageQueueManager *mqm)
632 cp->mqm_ready_ptr = mqm->next; 637 cp->mqm_ready_ptr = mqm->next;
633 /* Move entry to the end of the DLL, to be fair. */ 638 /* Move entry to the end of the DLL, to be fair. */
634 if (mqm != cp->mqm_tail) 639 if (mqm != cp->mqm_tail)
635 { 640 {
636 GNUNET_CONTAINER_DLL_remove(cp->mqm_head, 641 GNUNET_CONTAINER_DLL_remove (cp->mqm_head,
637 cp->mqm_tail, 642 cp->mqm_tail,
638 mqm); 643 mqm);
639 GNUNET_CONTAINER_DLL_insert_tail(cp->mqm_head, 644 GNUNET_CONTAINER_DLL_insert_tail (cp->mqm_head,
640 cp->mqm_tail, 645 cp->mqm_tail,
641 mqm); 646 mqm);
642 } 647 }
643 cp->mqm_ready_counter--; 648 cp->mqm_ready_counter--;
644 if (GNUNET_YES == should_I_drop()) 649 if (GNUNET_YES == should_I_drop ())
645 { 650 {
646 LOG(GNUNET_ERROR_TYPE_DEBUG, 651 LOG (GNUNET_ERROR_TYPE_DEBUG,
647 "DROPPING message to peer %s from MQM %p\n", 652 "DROPPING message to peer %s from MQM %p\n",
648 GCP_2s(cp), 653 GCP_2s (cp),
649 mqm); 654 mqm);
650 GNUNET_MQ_discard(mqm->env); 655 GNUNET_MQ_discard (mqm->env);
651 mqm->env = NULL; 656 mqm->env = NULL;
652 mqm_send_done(cp); 657 mqm_send_done (cp);
653 } 658 }
654 else 659 else
660 {
655 { 661 {
662 const struct GNUNET_MessageHeader *mh;
663
664 mh = GNUNET_MQ_env_get_msg (mqm->env);
665 switch (ntohs (mh->type))
656 { 666 {
657 const struct GNUNET_MessageHeader *mh; 667 case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX:
658 668 {
659 mh = GNUNET_MQ_env_get_msg(mqm->env); 669 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg
660 switch (ntohs(mh->type)) 670 = (const struct GNUNET_CADET_TunnelKeyExchangeMessage *) mh;
661 { 671 LOG (GNUNET_ERROR_TYPE_DEBUG,
662 case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX: 672 "P2P forwarding KX with ephemeral %s to %s on CID %s\n",
663 { 673 GNUNET_e2s (&msg->ephemeral_key),
664 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg 674 GCP_2s (cp),
665 = (const struct GNUNET_CADET_TunnelKeyExchangeMessage *)mh; 675 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
666 LOG(GNUNET_ERROR_TYPE_DEBUG, 676 }
667 "P2P forwarding KX with ephemeral %s to %s on CID %s\n", 677 break;
668 GNUNET_e2s(&msg->ephemeral_key), 678
669 GCP_2s(cp), 679 default:
670 GNUNET_sh2s(&msg->cid.connection_of_tunnel)); 680 break;
671 }
672 break;
673
674 default:
675 break;
676 }
677 } 681 }
678 LOG(GNUNET_ERROR_TYPE_DEBUG,
679 "Sending to peer %s from MQM %p\n",
680 GCP_2s(cp),
681 mqm);
682 GNUNET_MQ_send(cp->core_mq,
683 mqm->env);
684 mqm->env = NULL;
685 } 682 }
686 mqm->cb(mqm->cb_cls, 683 LOG (GNUNET_ERROR_TYPE_DEBUG,
687 GNUNET_YES); 684 "Sending to peer %s from MQM %p\n",
685 GCP_2s (cp),
686 mqm);
687 GNUNET_MQ_send (cp->core_mq,
688 mqm->env);
689 mqm->env = NULL;
690 }
691 mqm->cb (mqm->cb_cls,
692 GNUNET_YES);
688} 693}
689 694
690 695
@@ -696,7 +701,7 @@ mqm_execute(struct GCP_MessageQueueManager *mqm)
696 * @param cp peer to try to send the next ready message to 701 * @param cp peer to try to send the next ready message to
697 */ 702 */
698static void 703static void
699send_next_ready(struct CadetPeer *cp) 704send_next_ready (struct CadetPeer *cp)
700{ 705{
701 struct GCP_MessageQueueManager *mqm; 706 struct GCP_MessageQueueManager *mqm;
702 707
@@ -707,7 +712,7 @@ send_next_ready(struct CadetPeer *cp)
707 cp->mqm_ready_ptr = mqm->next; 712 cp->mqm_ready_ptr = mqm->next;
708 if (NULL == mqm) 713 if (NULL == mqm)
709 return; /* nothing to do */ 714 return; /* nothing to do */
710 mqm_execute(mqm); 715 mqm_execute (mqm);
711} 716}
712 717
713 718
@@ -718,14 +723,14 @@ send_next_ready(struct CadetPeer *cp)
718 * @param cls the `struct CadetPeeer` where we made progress 723 * @param cls the `struct CadetPeeer` where we made progress
719 */ 724 */
720static void 725static void
721mqm_send_done(void *cls) 726mqm_send_done (void *cls)
722{ 727{
723 struct CadetPeer *cp = cls; 728 struct CadetPeer *cp = cls;
724 729
725 LOG(GNUNET_ERROR_TYPE_DEBUG, 730 LOG (GNUNET_ERROR_TYPE_DEBUG,
726 "Sending to peer %s completed\n", 731 "Sending to peer %s completed\n",
727 GCP_2s(cp)); 732 GCP_2s (cp));
728 send_next_ready(cp); 733 send_next_ready (cp);
729} 734}
730 735
731 736
@@ -737,30 +742,30 @@ mqm_send_done(void *cls)
737 * yet have a #GNUNET_MQ_notify_sent() callback attached to it 742 * yet have a #GNUNET_MQ_notify_sent() callback attached to it
738 */ 743 */
739void 744void
740GCP_send(struct GCP_MessageQueueManager *mqm, 745GCP_send (struct GCP_MessageQueueManager *mqm,
741 struct GNUNET_MQ_Envelope *env) 746 struct GNUNET_MQ_Envelope *env)
742{ 747{
743 struct CadetPeer *cp = mqm->cp; 748 struct CadetPeer *cp = mqm->cp;
744 749
745 GNUNET_assert(NULL != env); 750 GNUNET_assert (NULL != env);
746 LOG(GNUNET_ERROR_TYPE_DEBUG, 751 LOG (GNUNET_ERROR_TYPE_DEBUG,
747 "Queueing message to peer %s in MQM %p\n", 752 "Queueing message to peer %s in MQM %p\n",
748 GCP_2s(cp), 753 GCP_2s (cp),
749 mqm); 754 mqm);
750 GNUNET_assert(NULL != cp->core_mq); 755 GNUNET_assert (NULL != cp->core_mq);
751 GNUNET_assert(NULL == mqm->env); 756 GNUNET_assert (NULL == mqm->env);
752 GNUNET_MQ_notify_sent(env, 757 GNUNET_MQ_notify_sent (env,
753 &mqm_send_done, 758 &mqm_send_done,
754 cp); 759 cp);
755 mqm->env = env; 760 mqm->env = env;
756 cp->mqm_ready_counter++; 761 cp->mqm_ready_counter++;
757 if (mqm != cp->mqm_ready_ptr) 762 if (mqm != cp->mqm_ready_ptr)
758 cp->mqm_ready_ptr = cp->mqm_head; 763 cp->mqm_ready_ptr = cp->mqm_head;
759 if (1 == cp->mqm_ready_counter) 764 if (1 == cp->mqm_ready_counter)
760 cp->mqm_ready_ptr = mqm; 765 cp->mqm_ready_ptr = mqm;
761 if (0 != GNUNET_MQ_get_length(cp->core_mq)) 766 if (0 != GNUNET_MQ_get_length (cp->core_mq))
762 return; 767 return;
763 send_next_ready(cp); 768 send_next_ready (cp);
764} 769}
765 770
766 771
@@ -773,18 +778,18 @@ GCP_send(struct GCP_MessageQueueManager *mqm,
773 * @return #GNUNET_OK (continue to iterate) 778 * @return #GNUNET_OK (continue to iterate)
774 */ 779 */
775static int 780static int
776destroy_iterator_cb(void *cls, 781destroy_iterator_cb (void *cls,
777 const struct GNUNET_PeerIdentity *pid, 782 const struct GNUNET_PeerIdentity *pid,
778 void *value) 783 void *value)
779{ 784{
780 struct CadetPeer *cp = value; 785 struct CadetPeer *cp = value;
781 786
782 if (NULL != cp->destroy_task) 787 if (NULL != cp->destroy_task)
783 { 788 {
784 GNUNET_SCHEDULER_cancel(cp->destroy_task); 789 GNUNET_SCHEDULER_cancel (cp->destroy_task);
785 cp->destroy_task = NULL; 790 cp->destroy_task = NULL;
786 } 791 }
787 destroy_peer(cp); 792 destroy_peer (cp);
788 return GNUNET_OK; 793 return GNUNET_OK;
789} 794}
790 795
@@ -795,13 +800,13 @@ destroy_iterator_cb(void *cls,
795 * connections are down. 800 * connections are down.
796 */ 801 */
797void 802void
798GCP_destroy_all_peers() 803GCP_destroy_all_peers ()
799{ 804{
800 LOG(GNUNET_ERROR_TYPE_DEBUG, 805 LOG (GNUNET_ERROR_TYPE_DEBUG,
801 "Destroying all peers now\n"); 806 "Destroying all peers now\n");
802 GNUNET_CONTAINER_multipeermap_iterate(peers, 807 GNUNET_CONTAINER_multipeermap_iterate (peers,
803 &destroy_iterator_cb, 808 &destroy_iterator_cb,
804 NULL); 809 NULL);
805} 810}
806 811
807 812
@@ -812,17 +817,17 @@ GCP_destroy_all_peers()
812 * @param cp peer to drop paths to 817 * @param cp peer to drop paths to
813 */ 818 */
814void 819void
815GCP_drop_owned_paths(struct CadetPeer *cp) 820GCP_drop_owned_paths (struct CadetPeer *cp)
816{ 821{
817 struct CadetPeerPath *path; 822 struct CadetPeerPath *path;
818 823
819 LOG(GNUNET_ERROR_TYPE_DEBUG, 824 LOG (GNUNET_ERROR_TYPE_DEBUG,
820 "Destroying all paths to %s\n", 825 "Destroying all paths to %s\n",
821 GCP_2s(cp)); 826 GCP_2s (cp));
822 while (NULL != (path = 827 while (NULL != (path =
823 GNUNET_CONTAINER_heap_remove_root(cp->path_heap))) 828 GNUNET_CONTAINER_heap_remove_root (cp->path_heap)))
824 GCPP_release(path); 829 GCPP_release (path);
825 GNUNET_CONTAINER_heap_destroy(cp->path_heap); 830 GNUNET_CONTAINER_heap_destroy (cp->path_heap);
826 cp->path_heap = NULL; 831 cp->path_heap = NULL;
827} 832}
828 833
@@ -835,55 +840,55 @@ GCP_drop_owned_paths(struct CadetPeer *cp)
835 * @param off offset of this peer on the path 840 * @param off offset of this peer on the path
836 */ 841 */
837void 842void
838GCP_path_entry_add(struct CadetPeer *cp, 843GCP_path_entry_add (struct CadetPeer *cp,
839 struct CadetPeerPathEntry *entry, 844 struct CadetPeerPathEntry *entry,
840 unsigned int off) 845 unsigned int off)
841{ 846{
842 GNUNET_assert(cp == GCPP_get_peer_at_offset(entry->path, 847 GNUNET_assert (cp == GCPP_get_peer_at_offset (entry->path,
843 off)); 848 off));
844 LOG(GNUNET_ERROR_TYPE_DEBUG, 849 LOG (GNUNET_ERROR_TYPE_DEBUG,
845 "Discovered that peer %s is on path %s at offset %u\n", 850 "Discovered that peer %s is on path %s at offset %u\n",
846 GCP_2s(cp), 851 GCP_2s (cp),
847 GCPP_2s(entry->path), 852 GCPP_2s (entry->path),
848 off); 853 off);
849 if (off >= cp->path_dll_length) 854 if (off >= cp->path_dll_length)
850 { 855 {
851 unsigned int len = cp->path_dll_length; 856 unsigned int len = cp->path_dll_length;
852 857
853 GNUNET_array_grow(cp->path_heads, 858 GNUNET_array_grow (cp->path_heads,
854 len, 859 len,
855 off + 4); 860 off + 4);
856 GNUNET_array_grow(cp->path_tails, 861 GNUNET_array_grow (cp->path_tails,
857 cp->path_dll_length, 862 cp->path_dll_length,
858 off + 4); 863 off + 4);
859 } 864 }
860 GNUNET_CONTAINER_DLL_insert(cp->path_heads[off], 865 GNUNET_CONTAINER_DLL_insert (cp->path_heads[off],
861 cp->path_tails[off], 866 cp->path_tails[off],
862 entry); 867 entry);
863 cp->off_sum += off; 868 cp->off_sum += off;
864 cp->num_paths++; 869 cp->num_paths++;
865 870
866 /* If we have a tunnel to this peer, tell the tunnel that there is a 871 /* If we have a tunnel to this peer, tell the tunnel that there is a
867 new path available. */ 872 new path available. */
868 if (NULL != cp->t) 873 if (NULL != cp->t)
869 GCT_consider_path(cp->t, 874 GCT_consider_path (cp->t,
870 entry->path, 875 entry->path,
871 off); 876 off);
872 877
873 if ((NULL != cp->search_h) && 878 if ((NULL != cp->search_h) &&
874 (DESIRED_CONNECTIONS_PER_TUNNEL <= cp->num_paths)) 879 (DESIRED_CONNECTIONS_PER_TUNNEL <= cp->num_paths))
875 { 880 {
876 /* Now I have enough paths, stop search */ 881 /* Now I have enough paths, stop search */
877 GCD_search_stop(cp->search_h); 882 GCD_search_stop (cp->search_h);
878 cp->search_h = NULL; 883 cp->search_h = NULL;
879 } 884 }
880 if (NULL != cp->destroy_task) 885 if (NULL != cp->destroy_task)
881 { 886 {
882 /* paths changed, this resets the destroy timeout counter 887 /* paths changed, this resets the destroy timeout counter
883 and aborts a destroy task that may no longer be valid 888 and aborts a destroy task that may no longer be valid
884 to have (as we now have more paths via this peer). */ 889 to have (as we now have more paths via this peer). */
885 consider_peer_destroy(cp); 890 consider_peer_destroy (cp);
886 } 891 }
887} 892}
888 893
889 894
@@ -895,19 +900,19 @@ GCP_path_entry_add(struct CadetPeer *cp,
895 * @param off offset of this peer on the path 900 * @param off offset of this peer on the path
896 */ 901 */
897void 902void
898GCP_path_entry_remove(struct CadetPeer *cp, 903GCP_path_entry_remove (struct CadetPeer *cp,
899 struct CadetPeerPathEntry *entry, 904 struct CadetPeerPathEntry *entry,
900 unsigned int off) 905 unsigned int off)
901{ 906{
902 LOG(GNUNET_ERROR_TYPE_DEBUG, 907 LOG (GNUNET_ERROR_TYPE_DEBUG,
903 "Removing knowledge about peer %s beging on path %s at offset %u\n", 908 "Removing knowledge about peer %s beging on path %s at offset %u\n",
904 GCP_2s(cp), 909 GCP_2s (cp),
905 GCPP_2s(entry->path), 910 GCPP_2s (entry->path),
906 off); 911 off);
907 GNUNET_CONTAINER_DLL_remove(cp->path_heads[off], 912 GNUNET_CONTAINER_DLL_remove (cp->path_heads[off],
908 cp->path_tails[off], 913 cp->path_tails[off],
909 entry); 914 entry);
910 GNUNET_assert(0 < cp->num_paths); 915 GNUNET_assert (0 < cp->num_paths);
911 cp->off_sum -= off; 916 cp->off_sum -= off;
912 cp->num_paths--; 917 cp->num_paths--;
913 if ((NULL == cp->core_mq) && 918 if ((NULL == cp->core_mq) &&
@@ -915,12 +920,12 @@ GCP_path_entry_remove(struct CadetPeer *cp,
915 (NULL == cp->search_h) && 920 (NULL == cp->search_h) &&
916 (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths)) 921 (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths))
917 cp->search_h 922 cp->search_h
918 = GCD_search(&cp->pid); 923 = GCD_search (&cp->pid);
919 if (NULL == cp->destroy_task) 924 if (NULL == cp->destroy_task)
920 { 925 {
921 /* paths changed, we might now be ready for destruction, check again */ 926 /* paths changed, we might now be ready for destruction, check again */
922 consider_peer_destroy(cp); 927 consider_peer_destroy (cp);
923 } 928 }
924} 929}
925 930
926 931
@@ -931,32 +936,32 @@ GCP_path_entry_remove(struct CadetPeer *cp,
931 * @param cls the `struct CadetPeer` to maintain the path heap for 936 * @param cls the `struct CadetPeer` to maintain the path heap for
932 */ 937 */
933static void 938static void
934path_heap_cleanup(void *cls) 939path_heap_cleanup (void *cls)
935{ 940{
936 struct CadetPeer *cp = cls; 941 struct CadetPeer *cp = cls;
937 struct CadetPeerPath *root; 942 struct CadetPeerPath *root;
938 943
939 cp->heap_cleanup_task = NULL; 944 cp->heap_cleanup_task = NULL;
940 while (GNUNET_CONTAINER_heap_get_size(cp->path_heap) >= 945 while (GNUNET_CONTAINER_heap_get_size (cp->path_heap) >=
941 2 * DESIRED_CONNECTIONS_PER_TUNNEL) 946 2 * DESIRED_CONNECTIONS_PER_TUNNEL)
942 { 947 {
943 /* Now we have way too many, drop least desirable UNLESS it is in use! 948 /* Now we have way too many, drop least desirable UNLESS it is in use!
944 (Note that this intentionally keeps highly desireable, but currently 949 (Note that this intentionally keeps highly desireable, but currently
945 unused paths around in the hope that we might be able to switch, even 950 unused paths around in the hope that we might be able to switch, even
946 if the number of paths exceeds the threshold.) */ 951 if the number of paths exceeds the threshold.) */
947 root = GNUNET_CONTAINER_heap_peek(cp->path_heap); 952 root = GNUNET_CONTAINER_heap_peek (cp->path_heap);
948 GNUNET_assert(NULL != root); 953 GNUNET_assert (NULL != root);
949 if (NULL != 954 if (NULL !=
950 GCPP_get_connection(root, 955 GCPP_get_connection (root,
951 cp, 956 cp,
952 GCPP_get_length(root) - 1)) 957 GCPP_get_length (root) - 1))
953 break; /* can't fix */ 958 break; /* can't fix */
954 /* Got plenty of paths to this destination, and this is a low-quality 959 /* Got plenty of paths to this destination, and this is a low-quality
955 one that we don't care about. Allow it to die. */ 960 one that we don't care about. Allow it to die. */
956 GNUNET_assert(root == 961 GNUNET_assert (root ==
957 GNUNET_CONTAINER_heap_remove_root(cp->path_heap)); 962 GNUNET_CONTAINER_heap_remove_root (cp->path_heap));
958 GCPP_release(root); 963 GCPP_release (root);
959 } 964 }
960} 965}
961 966
962 967
@@ -972,66 +977,66 @@ path_heap_cleanup(void *cls)
972 * otherwise the node in the peer's path heap for the @a path. 977 * otherwise the node in the peer's path heap for the @a path.
973 */ 978 */
974struct GNUNET_CONTAINER_HeapNode * 979struct GNUNET_CONTAINER_HeapNode *
975GCP_attach_path(struct CadetPeer *cp, 980GCP_attach_path (struct CadetPeer *cp,
976 struct CadetPeerPath *path, 981 struct CadetPeerPath *path,
977 unsigned int off, 982 unsigned int off,
978 int force) 983 int force)
979{ 984{
980 GNUNET_CONTAINER_HeapCostType desirability; 985 GNUNET_CONTAINER_HeapCostType desirability;
981 struct CadetPeerPath *root; 986 struct CadetPeerPath *root;
982 GNUNET_CONTAINER_HeapCostType root_desirability; 987 GNUNET_CONTAINER_HeapCostType root_desirability;
983 struct GNUNET_CONTAINER_HeapNode *hn; 988 struct GNUNET_CONTAINER_HeapNode *hn;
984 989
985 GNUNET_assert(off == GCPP_get_length(path) - 1); 990 GNUNET_assert (off == GCPP_get_length (path) - 1);
986 GNUNET_assert(cp == GCPP_get_peer_at_offset(path, 991 GNUNET_assert (cp == GCPP_get_peer_at_offset (path,
987 off)); 992 off));
988 if (NULL == cp->path_heap) 993 if (NULL == cp->path_heap)
989 { 994 {
990 /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */ 995 /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */
991 GNUNET_assert(GNUNET_NO == force); 996 GNUNET_assert (GNUNET_NO == force);
992 return NULL; 997 return NULL;
993 } 998 }
994 desirability = GCPP_get_desirability(path); 999 desirability = GCPP_get_desirability (path);
995 if (GNUNET_NO == force) 1000 if (GNUNET_NO == force)
1001 {
1002 /* FIXME: desirability is not yet initialized; tricky! */
1003 if (GNUNET_NO ==
1004 GNUNET_CONTAINER_heap_peek2 (cp->path_heap,
1005 (void **) &root,
1006 &root_desirability))
996 { 1007 {
997 /* FIXME: desirability is not yet initialized; tricky! */ 1008 root = NULL;
998 if (GNUNET_NO == 1009 root_desirability = 0;
999 GNUNET_CONTAINER_heap_peek2(cp->path_heap, 1010 }
1000 (void **)&root,
1001 &root_desirability))
1002 {
1003 root = NULL;
1004 root_desirability = 0;
1005 }
1006 1011
1007 if ((DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths) && 1012 if ((DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths) &&
1008 (desirability < root_desirability)) 1013 (desirability < root_desirability))
1009 { 1014 {
1010 LOG(GNUNET_ERROR_TYPE_DEBUG, 1015 LOG (GNUNET_ERROR_TYPE_DEBUG,
1011 "Decided to not attach path %s to peer %s due to undesirability\n", 1016 "Decided to not attach path %s to peer %s due to undesirability\n",
1012 GCPP_2s(path), 1017 GCPP_2s (path),
1013 GCP_2s(cp)); 1018 GCP_2s (cp));
1014 return NULL; 1019 return NULL;
1015 }
1016 } 1020 }
1021 }
1017 1022
1018 LOG(GNUNET_ERROR_TYPE_DEBUG, 1023 LOG (GNUNET_ERROR_TYPE_DEBUG,
1019 "Attaching path %s to peer %s (%s)\n", 1024 "Attaching path %s to peer %s (%s)\n",
1020 GCPP_2s(path), 1025 GCPP_2s (path),
1021 GCP_2s(cp), 1026 GCP_2s (cp),
1022 (GNUNET_NO == force) ? "desirable" : "forced"); 1027 (GNUNET_NO == force) ? "desirable" : "forced");
1023 1028
1024 /* Yes, we'd like to add this path, add to our heap */ 1029 /* Yes, we'd like to add this path, add to our heap */
1025 hn = GNUNET_CONTAINER_heap_insert(cp->path_heap, 1030 hn = GNUNET_CONTAINER_heap_insert (cp->path_heap,
1026 path, 1031 path,
1027 desirability); 1032 desirability);
1028 1033
1029 /* Consider maybe dropping other paths because of the new one */ 1034 /* Consider maybe dropping other paths because of the new one */
1030 if ((GNUNET_CONTAINER_heap_get_size(cp->path_heap) >= 1035 if ((GNUNET_CONTAINER_heap_get_size (cp->path_heap) >=
1031 2 * DESIRED_CONNECTIONS_PER_TUNNEL) && 1036 2 * DESIRED_CONNECTIONS_PER_TUNNEL) &&
1032 (NULL != cp->heap_cleanup_task)) 1037 (NULL != cp->heap_cleanup_task))
1033 cp->heap_cleanup_task = GNUNET_SCHEDULER_add_now(&path_heap_cleanup, 1038 cp->heap_cleanup_task = GNUNET_SCHEDULER_add_now (&path_heap_cleanup,
1034 cp); 1039 cp);
1035 return hn; 1040 return hn;
1036} 1041}
1037 1042
@@ -1046,16 +1051,16 @@ GCP_attach_path(struct CadetPeer *cp,
1046 * @param hn note in @a cp's path heap that must be deleted 1051 * @param hn note in @a cp's path heap that must be deleted
1047 */ 1052 */
1048void 1053void
1049GCP_detach_path(struct CadetPeer *cp, 1054GCP_detach_path (struct CadetPeer *cp,
1050 struct CadetPeerPath *path, 1055 struct CadetPeerPath *path,
1051 struct GNUNET_CONTAINER_HeapNode *hn) 1056 struct GNUNET_CONTAINER_HeapNode *hn)
1052{ 1057{
1053 LOG(GNUNET_ERROR_TYPE_DEBUG, 1058 LOG (GNUNET_ERROR_TYPE_DEBUG,
1054 "Detatching path %s from peer %s\n", 1059 "Detatching path %s from peer %s\n",
1055 GCPP_2s(path), 1060 GCPP_2s (path),
1056 GCP_2s(cp)); 1061 GCP_2s (cp));
1057 GNUNET_assert(path == 1062 GNUNET_assert (path ==
1058 GNUNET_CONTAINER_heap_remove_node(hn)); 1063 GNUNET_CONTAINER_heap_remove_node (hn));
1059} 1064}
1060 1065
1061 1066
@@ -1066,23 +1071,24 @@ GCP_detach_path(struct CadetPeer *cp,
1066 * @param cc the connection to add 1071 * @param cc the connection to add
1067 */ 1072 */
1068void 1073void
1069GCP_add_connection(struct CadetPeer *cp, 1074GCP_add_connection (struct CadetPeer *cp,
1070 struct CadetConnection *cc) 1075 struct CadetConnection *cc)
1071{ 1076{
1072 LOG(GNUNET_ERROR_TYPE_DEBUG, 1077 LOG (GNUNET_ERROR_TYPE_DEBUG,
1073 "Adding %s to peer %s\n", 1078 "Adding %s to peer %s\n",
1074 GCC_2s(cc), 1079 GCC_2s (cc),
1075 GCP_2s(cp)); 1080 GCP_2s (cp));
1076 GNUNET_assert(GNUNET_OK == 1081 GNUNET_assert (GNUNET_OK ==
1077 GNUNET_CONTAINER_multishortmap_put(cp->connections, 1082 GNUNET_CONTAINER_multishortmap_put (cp->connections,
1078 &GCC_get_id(cc)->connection_of_tunnel, 1083 &GCC_get_id (
1079 cc, 1084 cc)->connection_of_tunnel,
1080 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1085 cc,
1086 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1081 if (NULL != cp->destroy_task) 1087 if (NULL != cp->destroy_task)
1082 { 1088 {
1083 GNUNET_SCHEDULER_cancel(cp->destroy_task); 1089 GNUNET_SCHEDULER_cancel (cp->destroy_task);
1084 cp->destroy_task = NULL; 1090 cp->destroy_task = NULL;
1085 } 1091 }
1086} 1092}
1087 1093
1088 1094
@@ -1093,18 +1099,20 @@ GCP_add_connection(struct CadetPeer *cp,
1093 * @param cc the connection to remove 1099 * @param cc the connection to remove
1094 */ 1100 */
1095void 1101void
1096GCP_remove_connection(struct CadetPeer *cp, 1102GCP_remove_connection (struct CadetPeer *cp,
1097 struct CadetConnection *cc) 1103 struct CadetConnection *cc)
1098{ 1104{
1099 LOG(GNUNET_ERROR_TYPE_DEBUG, 1105 LOG (GNUNET_ERROR_TYPE_DEBUG,
1100 "Removing connection %s from peer %s\n", 1106 "Removing connection %s from peer %s\n",
1101 GCC_2s(cc), 1107 GCC_2s (cc),
1102 GCP_2s(cp)); 1108 GCP_2s (cp));
1103 GNUNET_assert(GNUNET_YES == 1109 GNUNET_assert (GNUNET_YES ==
1104 GNUNET_CONTAINER_multishortmap_remove(cp->connections, 1110 GNUNET_CONTAINER_multishortmap_remove (cp->connections,
1105 &GCC_get_id(cc)->connection_of_tunnel, 1111 &GCC_get_id (
1106 cc)); 1112 cc)->
1107 consider_peer_destroy(cp); 1113 connection_of_tunnel,
1114 cc));
1115 consider_peer_destroy (cp);
1108} 1116}
1109 1117
1110 1118
@@ -1120,30 +1128,31 @@ GCP_remove_connection(struct CadetPeer *cp,
1120 * NULL if unknown and not requested @a create 1128 * NULL if unknown and not requested @a create
1121 */ 1129 */
1122struct CadetPeer * 1130struct CadetPeer *
1123GCP_get(const struct GNUNET_PeerIdentity *peer_id, 1131GCP_get (const struct GNUNET_PeerIdentity *peer_id,
1124 int create) 1132 int create)
1125{ 1133{
1126 struct CadetPeer *cp; 1134 struct CadetPeer *cp;
1127 1135
1128 cp = GNUNET_CONTAINER_multipeermap_get(peers, 1136 cp = GNUNET_CONTAINER_multipeermap_get (peers,
1129 peer_id); 1137 peer_id);
1130 if (NULL != cp) 1138 if (NULL != cp)
1131 return cp; 1139 return cp;
1132 if (GNUNET_NO == create) 1140 if (GNUNET_NO == create)
1133 return NULL; 1141 return NULL;
1134 cp = GNUNET_new(struct CadetPeer); 1142 cp = GNUNET_new (struct CadetPeer);
1135 cp->pid = *peer_id; 1143 cp->pid = *peer_id;
1136 cp->connections = GNUNET_CONTAINER_multishortmap_create(32, 1144 cp->connections = GNUNET_CONTAINER_multishortmap_create (32,
1137 GNUNET_YES); 1145 GNUNET_YES);
1138 cp->path_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 1146 cp->path_heap = GNUNET_CONTAINER_heap_create (
1139 GNUNET_assert(GNUNET_YES == 1147 GNUNET_CONTAINER_HEAP_ORDER_MIN);
1140 GNUNET_CONTAINER_multipeermap_put(peers, 1148 GNUNET_assert (GNUNET_YES ==
1141 &cp->pid, 1149 GNUNET_CONTAINER_multipeermap_put (peers,
1142 cp, 1150 &cp->pid,
1143 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1151 cp,
1144 LOG(GNUNET_ERROR_TYPE_DEBUG, 1152 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1145 "Creating peer %s\n", 1153 LOG (GNUNET_ERROR_TYPE_DEBUG,
1146 GCP_2s(cp)); 1154 "Creating peer %s\n",
1155 GCP_2s (cp));
1147 return cp; 1156 return cp;
1148} 1157}
1149 1158
@@ -1155,7 +1164,7 @@ GCP_get(const struct GNUNET_PeerIdentity *peer_id,
1155 * @return the peer identity 1164 * @return the peer identity
1156 */ 1165 */
1157const struct GNUNET_PeerIdentity * 1166const struct GNUNET_PeerIdentity *
1158GCP_get_id(struct CadetPeer *cp) 1167GCP_get_id (struct CadetPeer *cp)
1159{ 1168{
1160 return &cp->pid; 1169 return &cp->pid;
1161} 1170}
@@ -1168,12 +1177,12 @@ GCP_get_id(struct CadetPeer *cp)
1168 * @param cls Closure for @c iter. 1177 * @param cls Closure for @c iter.
1169 */ 1178 */
1170void 1179void
1171GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter, 1180GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter,
1172 void *cls) 1181 void *cls)
1173{ 1182{
1174 GNUNET_CONTAINER_multipeermap_iterate(peers, 1183 GNUNET_CONTAINER_multipeermap_iterate (peers,
1175 iter, 1184 iter,
1176 cls); 1185 cls);
1177} 1186}
1178 1187
1179 1188
@@ -1184,7 +1193,7 @@ GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter,
1184 * @return Number of known paths. 1193 * @return Number of known paths.
1185 */ 1194 */
1186unsigned int 1195unsigned int
1187GCP_count_paths(const struct CadetPeer *cp) 1196GCP_count_paths (const struct CadetPeer *cp)
1188{ 1197{
1189 return cp->num_paths; 1198 return cp->num_paths;
1190} 1199}
@@ -1199,45 +1208,45 @@ GCP_count_paths(const struct CadetPeer *cp)
1199 * @return Number of iterated paths. 1208 * @return Number of iterated paths.
1200 */ 1209 */
1201unsigned int 1210unsigned int
1202GCP_iterate_paths(struct CadetPeer *cp, 1211GCP_iterate_paths (struct CadetPeer *cp,
1203 GCP_PathIterator callback, 1212 GCP_PathIterator callback,
1204 void *callback_cls) 1213 void *callback_cls)
1205{ 1214{
1206 unsigned int ret = 0; 1215 unsigned int ret = 0;
1207 1216
1208 LOG(GNUNET_ERROR_TYPE_DEBUG, 1217 LOG (GNUNET_ERROR_TYPE_DEBUG,
1209 "Iterating over paths to peer %s%s\n", 1218 "Iterating over paths to peer %s%s\n",
1210 GCP_2s(cp), 1219 GCP_2s (cp),
1211 (NULL == cp->core_mq) ? "" : " including direct link"); 1220 (NULL == cp->core_mq) ? "" : " including direct link");
1212 if (NULL != cp->core_mq) 1221 if (NULL != cp->core_mq)
1222 {
1223 /* FIXME: this branch seems to duplicate the
1224 i=0 case below (direct link). Leave out!??? -CG */
1225 struct CadetPeerPath *path;
1226
1227 path = GCPP_get_path_from_route (1,
1228 &cp->pid);
1229 ret++;
1230 if (GNUNET_NO ==
1231 callback (callback_cls,
1232 path,
1233 0))
1234 return ret;
1235 }
1236 for (unsigned int i = 0; i < cp->path_dll_length; i++)
1237 {
1238 for (struct CadetPeerPathEntry *pe = cp->path_heads[i];
1239 NULL != pe;
1240 pe = pe->next)
1213 { 1241 {
1214 /* FIXME: this branch seems to duplicate the
1215 i=0 case below (direct link). Leave out!??? -CG */
1216 struct CadetPeerPath *path;
1217
1218 path = GCPP_get_path_from_route(1,
1219 &cp->pid);
1220 ret++; 1242 ret++;
1221 if (GNUNET_NO == 1243 if (GNUNET_NO ==
1222 callback(callback_cls, 1244 callback (callback_cls,
1223 path, 1245 pe->path,
1224 0)) 1246 i))
1225 return ret; 1247 return ret;
1226 } 1248 }
1227 for (unsigned int i = 0; i < cp->path_dll_length; i++) 1249 }
1228 {
1229 for (struct CadetPeerPathEntry *pe = cp->path_heads[i];
1230 NULL != pe;
1231 pe = pe->next)
1232 {
1233 ret++;
1234 if (GNUNET_NO ==
1235 callback(callback_cls,
1236 pe->path,
1237 i))
1238 return ret;
1239 }
1240 }
1241 return ret; 1250 return ret;
1242} 1251}
1243 1252
@@ -1250,29 +1259,29 @@ GCP_iterate_paths(struct CadetPeer *cp,
1250 * @return Number of iterated paths. 1259 * @return Number of iterated paths.
1251 */ 1260 */
1252unsigned int 1261unsigned int
1253GCP_iterate_indirect_paths(struct CadetPeer *cp, 1262GCP_iterate_indirect_paths (struct CadetPeer *cp,
1254 GCP_PathIterator callback, 1263 GCP_PathIterator callback,
1255 void *callback_cls) 1264 void *callback_cls)
1256{ 1265{
1257 unsigned int ret = 0; 1266 unsigned int ret = 0;
1258 1267
1259 LOG(GNUNET_ERROR_TYPE_DEBUG, 1268 LOG (GNUNET_ERROR_TYPE_DEBUG,
1260 "Iterating over paths to peer %s without direct link\n", 1269 "Iterating over paths to peer %s without direct link\n",
1261 GCP_2s(cp)); 1270 GCP_2s (cp));
1262 for (unsigned int i = 1; i < cp->path_dll_length; i++) 1271 for (unsigned int i = 1; i < cp->path_dll_length; i++)
1272 {
1273 for (struct CadetPeerPathEntry *pe = cp->path_heads[i];
1274 NULL != pe;
1275 pe = pe->next)
1263 { 1276 {
1264 for (struct CadetPeerPathEntry *pe = cp->path_heads[i]; 1277 ret++;
1265 NULL != pe; 1278 if (GNUNET_NO ==
1266 pe = pe->next) 1279 callback (callback_cls,
1267 { 1280 pe->path,
1268 ret++; 1281 i))
1269 if (GNUNET_NO == 1282 return ret;
1270 callback(callback_cls,
1271 pe->path,
1272 i))
1273 return ret;
1274 }
1275 } 1283 }
1284 }
1276 return ret; 1285 return ret;
1277} 1286}
1278 1287
@@ -1288,32 +1297,32 @@ GCP_iterate_indirect_paths(struct CadetPeer *cp,
1288 * @return Number of iterated paths. 1297 * @return Number of iterated paths.
1289 */ 1298 */
1290unsigned int 1299unsigned int
1291GCP_iterate_paths_at(struct CadetPeer *cp, 1300GCP_iterate_paths_at (struct CadetPeer *cp,
1292 unsigned int dist, 1301 unsigned int dist,
1293 GCP_PathIterator callback, 1302 GCP_PathIterator callback,
1294 void *callback_cls) 1303 void *callback_cls)
1295{ 1304{
1296 unsigned int ret = 0; 1305 unsigned int ret = 0;
1297 1306
1298 if (dist >= cp->path_dll_length) 1307 if (dist >= cp->path_dll_length)
1299 { 1308 {
1300 LOG(GNUNET_ERROR_TYPE_DEBUG, 1309 LOG (GNUNET_ERROR_TYPE_DEBUG,
1301 "Asked to look for paths at distance %u, but maximum for me is < %u\n", 1310 "Asked to look for paths at distance %u, but maximum for me is < %u\n",
1302 dist, 1311 dist,
1303 cp->path_dll_length); 1312 cp->path_dll_length);
1304 return 0; 1313 return 0;
1305 } 1314 }
1306 for (struct CadetPeerPathEntry *pe = cp->path_heads[dist]; 1315 for (struct CadetPeerPathEntry *pe = cp->path_heads[dist];
1307 NULL != pe; 1316 NULL != pe;
1308 pe = pe->next) 1317 pe = pe->next)
1309 { 1318 {
1310 if (GNUNET_NO == 1319 if (GNUNET_NO ==
1311 callback(callback_cls, 1320 callback (callback_cls,
1312 pe->path, 1321 pe->path,
1313 dist)) 1322 dist))
1314 return ret; 1323 return ret;
1315 ret++; 1324 ret++;
1316 } 1325 }
1317 return ret; 1326 return ret;
1318} 1327}
1319 1328
@@ -1326,16 +1335,16 @@ GCP_iterate_paths_at(struct CadetPeer *cp,
1326 * @return Tunnel towards peer. 1335 * @return Tunnel towards peer.
1327 */ 1336 */
1328struct CadetTunnel * 1337struct CadetTunnel *
1329GCP_get_tunnel(struct CadetPeer *cp, 1338GCP_get_tunnel (struct CadetPeer *cp,
1330 int create) 1339 int create)
1331{ 1340{
1332 if (NULL == cp) 1341 if (NULL == cp)
1333 return NULL; 1342 return NULL;
1334 if ((NULL != cp->t) || 1343 if ((NULL != cp->t) ||
1335 (GNUNET_NO == create)) 1344 (GNUNET_NO == create))
1336 return cp->t; 1345 return cp->t;
1337 cp->t = GCT_create_tunnel(cp); 1346 cp->t = GCT_create_tunnel (cp);
1338 consider_peer_activate(cp); 1347 consider_peer_activate (cp);
1339 return cp->t; 1348 return cp->t;
1340} 1349}
1341 1350
@@ -1347,7 +1356,7 @@ GCP_get_tunnel(struct CadetPeer *cp,
1347 * @param cls the `struct CadetPeer` where the offer completed 1356 * @param cls the `struct CadetPeer` where the offer completed
1348 */ 1357 */
1349static void 1358static void
1350hello_offer_done(void *cls) 1359hello_offer_done (void *cls)
1351{ 1360{
1352 struct CadetPeer *cp = cls; 1361 struct CadetPeer *cp = cls;
1353 1362
@@ -1363,39 +1372,39 @@ hello_offer_done(void *cls)
1363 * @param hello the HELLO to remember 1372 * @param hello the HELLO to remember
1364 */ 1373 */
1365void 1374void
1366GCP_set_hello(struct CadetPeer *cp, 1375GCP_set_hello (struct CadetPeer *cp,
1367 const struct GNUNET_HELLO_Message *hello) 1376 const struct GNUNET_HELLO_Message *hello)
1368{ 1377{
1369 struct GNUNET_HELLO_Message *mrg; 1378 struct GNUNET_HELLO_Message *mrg;
1370 1379
1371 LOG(GNUNET_ERROR_TYPE_DEBUG, 1380 LOG (GNUNET_ERROR_TYPE_DEBUG,
1372 "Got %u byte HELLO for peer %s\n", 1381 "Got %u byte HELLO for peer %s\n",
1373 (unsigned int)GNUNET_HELLO_size(hello), 1382 (unsigned int) GNUNET_HELLO_size (hello),
1374 GCP_2s(cp)); 1383 GCP_2s (cp));
1375 if (NULL != cp->hello_offer) 1384 if (NULL != cp->hello_offer)
1376 { 1385 {
1377 GNUNET_TRANSPORT_offer_hello_cancel(cp->hello_offer); 1386 GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer);
1378 cp->hello_offer = NULL; 1387 cp->hello_offer = NULL;
1379 } 1388 }
1380 if (NULL != cp->hello) 1389 if (NULL != cp->hello)
1381 { 1390 {
1382 mrg = GNUNET_HELLO_merge(hello, 1391 mrg = GNUNET_HELLO_merge (hello,
1383 cp->hello); 1392 cp->hello);
1384 GNUNET_free(cp->hello); 1393 GNUNET_free (cp->hello);
1385 cp->hello = mrg; 1394 cp->hello = mrg;
1386 } 1395 }
1387 else 1396 else
1388 { 1397 {
1389 cp->hello = GNUNET_memdup(hello, 1398 cp->hello = GNUNET_memdup (hello,
1390 GNUNET_HELLO_size(hello)); 1399 GNUNET_HELLO_size (hello));
1391 } 1400 }
1392 cp->hello_offer 1401 cp->hello_offer
1393 = GNUNET_TRANSPORT_offer_hello(cfg, 1402 = GNUNET_TRANSPORT_offer_hello (cfg,
1394 GNUNET_HELLO_get_header(cp->hello), 1403 GNUNET_HELLO_get_header (cp->hello),
1395 &hello_offer_done, 1404 &hello_offer_done,
1396 cp); 1405 cp);
1397 /* New HELLO means cp's destruction time may change... */ 1406 /* New HELLO means cp's destruction time may change... */
1398 consider_peer_destroy(cp); 1407 consider_peer_destroy (cp);
1399} 1408}
1400 1409
1401 1410
@@ -1407,16 +1416,16 @@ GCP_set_hello(struct CadetPeer *cp,
1407 * @param t the dead tunnel 1416 * @param t the dead tunnel
1408 */ 1417 */
1409void 1418void
1410GCP_drop_tunnel(struct CadetPeer *cp, 1419GCP_drop_tunnel (struct CadetPeer *cp,
1411 struct CadetTunnel *t) 1420 struct CadetTunnel *t)
1412{ 1421{
1413 LOG(GNUNET_ERROR_TYPE_DEBUG, 1422 LOG (GNUNET_ERROR_TYPE_DEBUG,
1414 "Dropping tunnel %s to peer %s\n", 1423 "Dropping tunnel %s to peer %s\n",
1415 GCT_2s(t), 1424 GCT_2s (t),
1416 GCP_2s(cp)); 1425 GCP_2s (cp));
1417 GNUNET_assert(cp->t == t); 1426 GNUNET_assert (cp->t == t);
1418 cp->t = NULL; 1427 cp->t = NULL;
1419 consider_peer_destroy(cp); 1428 consider_peer_destroy (cp);
1420} 1429}
1421 1430
1422 1431
@@ -1427,7 +1436,7 @@ GCP_drop_tunnel(struct CadetPeer *cp,
1427 * @return #GNUNET_YES if @a cp has a core-level connection 1436 * @return #GNUNET_YES if @a cp has a core-level connection
1428 */ 1437 */
1429int 1438int
1430GCP_has_core_connection(struct CadetPeer *cp) 1439GCP_has_core_connection (struct CadetPeer *cp)
1431{ 1440{
1432 return (NULL != cp->core_mq) ? GNUNET_YES : GNUNET_NO; 1441 return (NULL != cp->core_mq) ? GNUNET_YES : GNUNET_NO;
1433} 1442}
@@ -1442,26 +1451,26 @@ GCP_has_core_connection(struct CadetPeer *cp)
1442 * @return handle to cancel request 1451 * @return handle to cancel request
1443 */ 1452 */
1444struct GCP_MessageQueueManager * 1453struct GCP_MessageQueueManager *
1445GCP_request_mq(struct CadetPeer *cp, 1454GCP_request_mq (struct CadetPeer *cp,
1446 GCP_MessageQueueNotificationCallback cb, 1455 GCP_MessageQueueNotificationCallback cb,
1447 void *cb_cls) 1456 void *cb_cls)
1448{ 1457{
1449 struct GCP_MessageQueueManager *mqm; 1458 struct GCP_MessageQueueManager *mqm;
1450 1459
1451 mqm = GNUNET_new(struct GCP_MessageQueueManager); 1460 mqm = GNUNET_new (struct GCP_MessageQueueManager);
1452 mqm->cb = cb; 1461 mqm->cb = cb;
1453 mqm->cb_cls = cb_cls; 1462 mqm->cb_cls = cb_cls;
1454 mqm->cp = cp; 1463 mqm->cp = cp;
1455 GNUNET_CONTAINER_DLL_insert(cp->mqm_head, 1464 GNUNET_CONTAINER_DLL_insert (cp->mqm_head,
1456 cp->mqm_tail, 1465 cp->mqm_tail,
1457 mqm); 1466 mqm);
1458 LOG(GNUNET_ERROR_TYPE_DEBUG, 1467 LOG (GNUNET_ERROR_TYPE_DEBUG,
1459 "Creating MQM %p for peer %s\n", 1468 "Creating MQM %p for peer %s\n",
1460 mqm, 1469 mqm,
1461 GCP_2s(cp)); 1470 GCP_2s (cp));
1462 if (NULL != cp->core_mq) 1471 if (NULL != cp->core_mq)
1463 cb(cb_cls, 1472 cb (cb_cls,
1464 GNUNET_YES); 1473 GNUNET_YES);
1465 return mqm; 1474 return mqm;
1466} 1475}
1467 1476
@@ -1473,39 +1482,39 @@ GCP_request_mq(struct CadetPeer *cp,
1473 * @param last_env final message to transmit, or NULL 1482 * @param last_env final message to transmit, or NULL
1474 */ 1483 */
1475void 1484void
1476GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm, 1485GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm,
1477 struct GNUNET_MQ_Envelope *last_env) 1486 struct GNUNET_MQ_Envelope *last_env)
1478{ 1487{
1479 struct CadetPeer *cp = mqm->cp; 1488 struct CadetPeer *cp = mqm->cp;
1480 1489
1481 LOG(GNUNET_ERROR_TYPE_DEBUG, 1490 LOG (GNUNET_ERROR_TYPE_DEBUG,
1482 "Destroying MQM %p for peer %s%s\n", 1491 "Destroying MQM %p for peer %s%s\n",
1483 mqm, 1492 mqm,
1484 GCP_2s(cp), 1493 GCP_2s (cp),
1485 (NULL == last_env) ? "" : " with last ditch transmission"); 1494 (NULL == last_env) ? "" : " with last ditch transmission");
1486 if (NULL != mqm->env) 1495 if (NULL != mqm->env)
1487 GNUNET_MQ_discard(mqm->env); 1496 GNUNET_MQ_discard (mqm->env);
1488 if (NULL != last_env) 1497 if (NULL != last_env)
1498 {
1499 if (NULL != cp->core_mq)
1489 { 1500 {
1490 if (NULL != cp->core_mq) 1501 GNUNET_MQ_notify_sent (last_env,
1491 { 1502 &mqm_send_done,
1492 GNUNET_MQ_notify_sent(last_env, 1503 cp);
1493 &mqm_send_done, 1504 GNUNET_MQ_send (cp->core_mq,
1494 cp); 1505 last_env);
1495 GNUNET_MQ_send(cp->core_mq,
1496 last_env);
1497 }
1498 else
1499 {
1500 GNUNET_MQ_discard(last_env);
1501 }
1502 } 1506 }
1507 else
1508 {
1509 GNUNET_MQ_discard (last_env);
1510 }
1511 }
1503 if (cp->mqm_ready_ptr == mqm) 1512 if (cp->mqm_ready_ptr == mqm)
1504 cp->mqm_ready_ptr = mqm->next; 1513 cp->mqm_ready_ptr = mqm->next;
1505 GNUNET_CONTAINER_DLL_remove(cp->mqm_head, 1514 GNUNET_CONTAINER_DLL_remove (cp->mqm_head,
1506 cp->mqm_tail, 1515 cp->mqm_tail,
1507 mqm); 1516 mqm);
1508 GNUNET_free(mqm); 1517 GNUNET_free (mqm);
1509} 1518}
1510 1519
1511 1520
@@ -1519,27 +1528,27 @@ GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm,
1519 * @param env envelope with the message to send 1528 * @param env envelope with the message to send
1520 */ 1529 */
1521void 1530void
1522GCP_send_ooo(struct CadetPeer *cp, 1531GCP_send_ooo (struct CadetPeer *cp,
1523 struct GNUNET_MQ_Envelope *env) 1532 struct GNUNET_MQ_Envelope *env)
1524{ 1533{
1525 LOG(GNUNET_ERROR_TYPE_DEBUG, 1534 LOG (GNUNET_ERROR_TYPE_DEBUG,
1526 "Sending message to %s out of management\n", 1535 "Sending message to %s out of management\n",
1527 GCP_2s(cp)); 1536 GCP_2s (cp));
1528 if (NULL == cp->core_mq) 1537 if (NULL == cp->core_mq)
1529 { 1538 {
1530 GNUNET_MQ_discard(env); 1539 GNUNET_MQ_discard (env);
1531 return; 1540 return;
1532 } 1541 }
1533 if (GNUNET_MQ_get_length(cp->core_mq) > MAX_OOO_QUEUE_SIZE) 1542 if (GNUNET_MQ_get_length (cp->core_mq) > MAX_OOO_QUEUE_SIZE)
1534 { 1543 {
1535 GNUNET_MQ_discard(env); 1544 GNUNET_MQ_discard (env);
1536 return; 1545 return;
1537 } 1546 }
1538 GNUNET_MQ_notify_sent(env, 1547 GNUNET_MQ_notify_sent (env,
1539 &mqm_send_done, 1548 &mqm_send_done,
1540 cp); 1549 cp);
1541 GNUNET_MQ_send(cp->core_mq, 1550 GNUNET_MQ_send (cp->core_mq,
1542 env); 1551 env);
1543} 1552}
1544 1553
1545 1554
diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h
index 09c6f64c9..bec0606a0 100644
--- a/src/cadet/gnunet-service-cadet_peer.h
+++ b/src/cadet/gnunet-service-cadet_peer.h
@@ -39,7 +39,7 @@
39 * @return Static string for it's ID. 39 * @return Static string for it's ID.
40 */ 40 */
41const char * 41const char *
42GCP_2s(const struct CadetPeer *peer); 42GCP_2s (const struct CadetPeer *peer);
43 43
44 44
45/** 45/**
@@ -54,8 +54,8 @@ GCP_2s(const struct CadetPeer *peer);
54 * NULL if unknown and not requested @a create 54 * NULL if unknown and not requested @a create
55 */ 55 */
56struct CadetPeer * 56struct CadetPeer *
57GCP_get(const struct GNUNET_PeerIdentity *peer_id, 57GCP_get (const struct GNUNET_PeerIdentity *peer_id,
58 int create); 58 int create);
59 59
60 60
61/** 61/**
@@ -68,8 +68,8 @@ GCP_get(const struct GNUNET_PeerIdentity *peer_id,
68 * positive scores mean path is more desirable 68 * positive scores mean path is more desirable
69 */ 69 */
70double 70double
71GCP_get_desirability_of_path(struct CadetPeer *cp, 71GCP_get_desirability_of_path (struct CadetPeer *cp,
72 unsigned int off); 72 unsigned int off);
73 73
74 74
75/** 75/**
@@ -79,7 +79,7 @@ GCP_get_desirability_of_path(struct CadetPeer *cp,
79 * @return the peer identity 79 * @return the peer identity
80 */ 80 */
81const struct GNUNET_PeerIdentity * 81const struct GNUNET_PeerIdentity *
82GCP_get_id(struct CadetPeer *cp); 82GCP_get_id (struct CadetPeer *cp);
83 83
84 84
85/** 85/**
@@ -89,8 +89,8 @@ GCP_get_id(struct CadetPeer *cp);
89 * @param cls Closure for @c iter. 89 * @param cls Closure for @c iter.
90 */ 90 */
91void 91void
92GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter, 92GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter,
93 void *cls); 93 void *cls);
94 94
95 95
96/** 96/**
@@ -100,7 +100,7 @@ GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter,
100 * @return Number of known paths. 100 * @return Number of known paths.
101 */ 101 */
102unsigned int 102unsigned int
103GCP_count_paths(const struct CadetPeer *cp); 103GCP_count_paths (const struct CadetPeer *cp);
104 104
105 105
106/** 106/**
@@ -110,7 +110,7 @@ GCP_count_paths(const struct CadetPeer *cp);
110 * @param cp peer to drop paths to 110 * @param cp peer to drop paths to
111 */ 111 */
112void 112void
113GCP_drop_owned_paths(struct CadetPeer *cp); 113GCP_drop_owned_paths (struct CadetPeer *cp);
114 114
115 115
116/** 116/**
@@ -137,9 +137,9 @@ typedef int
137 * @return Number of iterated paths. 137 * @return Number of iterated paths.
138 */ 138 */
139unsigned int 139unsigned int
140GCP_iterate_paths(struct CadetPeer *cp, 140GCP_iterate_paths (struct CadetPeer *cp,
141 GCP_PathIterator callback, 141 GCP_PathIterator callback,
142 void *callback_cls); 142 void *callback_cls);
143 143
144/** 144/**
145 * Iterate over the paths to a peer without direct link. 145 * Iterate over the paths to a peer without direct link.
@@ -150,9 +150,9 @@ GCP_iterate_paths(struct CadetPeer *cp,
150 * @return Number of iterated paths. 150 * @return Number of iterated paths.
151 */ 151 */
152unsigned int 152unsigned int
153GCP_iterate_indirect_paths(struct CadetPeer *cp, 153GCP_iterate_indirect_paths (struct CadetPeer *cp,
154 GCP_PathIterator callback, 154 GCP_PathIterator callback,
155 void *callback_cls); 155 void *callback_cls);
156 156
157 157
158/** 158/**
@@ -166,10 +166,10 @@ GCP_iterate_indirect_paths(struct CadetPeer *cp,
166 * @return Number of iterated paths. 166 * @return Number of iterated paths.
167 */ 167 */
168unsigned int 168unsigned int
169GCP_iterate_paths_at(struct CadetPeer *cp, 169GCP_iterate_paths_at (struct CadetPeer *cp,
170 unsigned int dist, 170 unsigned int dist,
171 GCP_PathIterator callback, 171 GCP_PathIterator callback,
172 void *callback_cls); 172 void *callback_cls);
173 173
174 174
175/** 175/**
@@ -180,9 +180,9 @@ GCP_iterate_paths_at(struct CadetPeer *cp,
180 * @param off offset of this peer on the path 180 * @param off offset of this peer on the path
181 */ 181 */
182void 182void
183GCP_path_entry_remove(struct CadetPeer *cp, 183GCP_path_entry_remove (struct CadetPeer *cp,
184 struct CadetPeerPathEntry *entry, 184 struct CadetPeerPathEntry *entry,
185 unsigned int off); 185 unsigned int off);
186 186
187 187
188/** 188/**
@@ -193,9 +193,9 @@ GCP_path_entry_remove(struct CadetPeer *cp,
193 * @param off offset of this peer on the path 193 * @param off offset of this peer on the path
194 */ 194 */
195void 195void
196GCP_path_entry_add(struct CadetPeer *cp, 196GCP_path_entry_add (struct CadetPeer *cp,
197 struct CadetPeerPathEntry *entry, 197 struct CadetPeerPathEntry *entry,
198 unsigned int off); 198 unsigned int off);
199 199
200 200
201/** 201/**
@@ -206,8 +206,8 @@ GCP_path_entry_add(struct CadetPeer *cp,
206 * @return Tunnel towards peer. 206 * @return Tunnel towards peer.
207 */ 207 */
208struct CadetTunnel * 208struct CadetTunnel *
209GCP_get_tunnel(struct CadetPeer *cp, 209GCP_get_tunnel (struct CadetPeer *cp,
210 int create); 210 int create);
211 211
212 212
213/** 213/**
@@ -218,8 +218,8 @@ GCP_get_tunnel(struct CadetPeer *cp,
218 * @param t the dead tunnel 218 * @param t the dead tunnel
219 */ 219 */
220void 220void
221GCP_drop_tunnel(struct CadetPeer *cp, 221GCP_drop_tunnel (struct CadetPeer *cp,
222 struct CadetTunnel *t); 222 struct CadetTunnel *t);
223 223
224 224
225/** 225/**
@@ -234,10 +234,10 @@ GCP_drop_tunnel(struct CadetPeer *cp,
234 * otherwise the node in the peer's path heap for the @a path. 234 * otherwise the node in the peer's path heap for the @a path.
235 */ 235 */
236struct GNUNET_CONTAINER_HeapNode * 236struct GNUNET_CONTAINER_HeapNode *
237GCP_attach_path(struct CadetPeer *cp, 237GCP_attach_path (struct CadetPeer *cp,
238 struct CadetPeerPath *path, 238 struct CadetPeerPath *path,
239 unsigned int off, 239 unsigned int off,
240 int force); 240 int force);
241 241
242 242
243/** 243/**
@@ -250,9 +250,9 @@ GCP_attach_path(struct CadetPeer *cp,
250 * @param hn note in @a cp's path heap that must be deleted 250 * @param hn note in @a cp's path heap that must be deleted
251 */ 251 */
252void 252void
253GCP_detach_path(struct CadetPeer *cp, 253GCP_detach_path (struct CadetPeer *cp,
254 struct CadetPeerPath *path, 254 struct CadetPeerPath *path,
255 struct GNUNET_CONTAINER_HeapNode *hn); 255 struct GNUNET_CONTAINER_HeapNode *hn);
256 256
257 257
258/** 258/**
@@ -262,8 +262,8 @@ GCP_detach_path(struct CadetPeer *cp,
262 * @param cc the connection to add 262 * @param cc the connection to add
263 */ 263 */
264void 264void
265GCP_add_connection(struct CadetPeer *cp, 265GCP_add_connection (struct CadetPeer *cp,
266 struct CadetConnection *cc); 266 struct CadetConnection *cc);
267 267
268 268
269/** 269/**
@@ -273,8 +273,8 @@ GCP_add_connection(struct CadetPeer *cp,
273 * @param cc the connection to remove 273 * @param cc the connection to remove
274 */ 274 */
275void 275void
276GCP_remove_connection(struct CadetPeer *cp, 276GCP_remove_connection (struct CadetPeer *cp,
277 struct CadetConnection *cc); 277 struct CadetConnection *cc);
278 278
279 279
280/** 280/**
@@ -285,8 +285,8 @@ GCP_remove_connection(struct CadetPeer *cp,
285 * @param hello the HELLO to remember 285 * @param hello the HELLO to remember
286 */ 286 */
287void 287void
288GCP_set_hello(struct CadetPeer *cp, 288GCP_set_hello (struct CadetPeer *cp,
289 const struct GNUNET_HELLO_Message *hello); 289 const struct GNUNET_HELLO_Message *hello);
290 290
291 291
292/** 292/**
@@ -295,7 +295,7 @@ GCP_set_hello(struct CadetPeer *cp,
295 * connections are down. 295 * connections are down.
296 */ 296 */
297void 297void
298GCP_destroy_all_peers(void); 298GCP_destroy_all_peers (void);
299 299
300 300
301/** 301/**
@@ -334,9 +334,9 @@ typedef void
334 * @return handle to cancel request 334 * @return handle to cancel request
335 */ 335 */
336struct GCP_MessageQueueManager * 336struct GCP_MessageQueueManager *
337GCP_request_mq(struct CadetPeer *cp, 337GCP_request_mq (struct CadetPeer *cp,
338 GCP_MessageQueueNotificationCallback cb, 338 GCP_MessageQueueNotificationCallback cb,
339 void *cb_cls); 339 void *cb_cls);
340 340
341 341
342/** 342/**
@@ -346,7 +346,7 @@ GCP_request_mq(struct CadetPeer *cp,
346 * @return #GNUNET_YES if @a cp has a core-level connection 346 * @return #GNUNET_YES if @a cp has a core-level connection
347 */ 347 */
348int 348int
349GCP_has_core_connection(struct CadetPeer *cp); 349GCP_has_core_connection (struct CadetPeer *cp);
350 350
351 351
352/** 352/**
@@ -361,8 +361,8 @@ GCP_has_core_connection(struct CadetPeer *cp);
361 * yet have a #GNUNET_MQ_notify_sent() callback attached to it 361 * yet have a #GNUNET_MQ_notify_sent() callback attached to it
362 */ 362 */
363void 363void
364GCP_send(struct GCP_MessageQueueManager *mqm, 364GCP_send (struct GCP_MessageQueueManager *mqm,
365 struct GNUNET_MQ_Envelope *env); 365 struct GNUNET_MQ_Envelope *env);
366 366
367 367
368/** 368/**
@@ -375,8 +375,8 @@ GCP_send(struct GCP_MessageQueueManager *mqm,
375 * @param env envelope with the message to send 375 * @param env envelope with the message to send
376 */ 376 */
377void 377void
378GCP_send_ooo(struct CadetPeer *cp, 378GCP_send_ooo (struct CadetPeer *cp,
379 struct GNUNET_MQ_Envelope *env); 379 struct GNUNET_MQ_Envelope *env);
380 380
381 381
382/** 382/**
@@ -388,8 +388,8 @@ GCP_send_ooo(struct CadetPeer *cp,
388 * @param last_env final message to transmit, or NULL 388 * @param last_env final message to transmit, or NULL
389 */ 389 */
390void 390void
391GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm, 391GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm,
392 struct GNUNET_MQ_Envelope *last_env); 392 struct GNUNET_MQ_Envelope *last_env);
393 393
394 394
395/** 395/**
@@ -399,8 +399,8 @@ GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm,
399 * @param mq message queue to set (can be NULL) 399 * @param mq message queue to set (can be NULL)
400 */ 400 */
401void 401void
402GCP_set_mq(struct CadetPeer *cp, 402GCP_set_mq (struct CadetPeer *cp,
403 struct GNUNET_MQ_Handle *mq); 403 struct GNUNET_MQ_Handle *mq);
404 404
405 405
406#endif 406#endif
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c
index c73f8cdbe..6f2dd1d8d 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.c
+++ b/src/cadet/gnunet-service-cadet_tunnels.c
@@ -42,7 +42,7 @@
42#include "gnunet-service-cadet_paths.h" 42#include "gnunet-service-cadet_paths.h"
43 43
44 44
45#define LOG(level, ...) GNUNET_log_from(level, "cadet-tun", __VA_ARGS__) 45#define LOG(level, ...) GNUNET_log_from (level, "cadet-tun", __VA_ARGS__)
46 46
47/** 47/**
48 * How often do we try to decrypt payload with unverified key 48 * How often do we try to decrypt payload with unverified key
@@ -54,13 +54,15 @@
54/** 54/**
55 * How long do we wait until tearing down an idle tunnel? 55 * How long do we wait until tearing down an idle tunnel?
56 */ 56 */
57#define IDLE_DESTROY_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) 57#define IDLE_DESTROY_DELAY GNUNET_TIME_relative_multiply ( \
58 GNUNET_TIME_UNIT_SECONDS, 90)
58 59
59/** 60/**
60 * How long do we wait initially before retransmitting the KX? 61 * How long do we wait initially before retransmitting the KX?
61 * TODO: replace by 2 RTT if/once we have connection-level RTT data! 62 * TODO: replace by 2 RTT if/once we have connection-level RTT data!
62 */ 63 */
63#define INITIAL_KX_RETRY_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) 64#define INITIAL_KX_RETRY_DELAY GNUNET_TIME_relative_multiply ( \
65 GNUNET_TIME_UNIT_MILLISECONDS, 250)
64 66
65/** 67/**
66 * Maximum number of skipped keys we keep in memory per tunnel. 68 * Maximum number of skipped keys we keep in memory per tunnel.
@@ -77,7 +79,8 @@
77/** 79/**
78 * Struct to old keys for skipped messages while advancing the Axolotl ratchet. 80 * Struct to old keys for skipped messages while advancing the Axolotl ratchet.
79 */ 81 */
80struct CadetTunnelSkippedKey { 82struct CadetTunnelSkippedKey
83{
81 /** 84 /**
82 * DLL next. 85 * DLL next.
83 */ 86 */
@@ -113,7 +116,8 @@ struct CadetTunnelSkippedKey {
113/** 116/**
114 * Axolotl data, according to https://github.com/trevp/axolotl/wiki . 117 * Axolotl data, according to https://github.com/trevp/axolotl/wiki .
115 */ 118 */
116struct CadetTunnelAxolotl { 119struct CadetTunnelAxolotl
120{
117 /** 121 /**
118 * A (double linked) list of stored message keys and associated header keys 122 * A (double linked) list of stored message keys and associated header keys
119 * for "skipped" messages, i.e. messages that have not been 123 * for "skipped" messages, i.e. messages that have not been
@@ -252,7 +256,8 @@ struct CadetTunnelAxolotl {
252/** 256/**
253 * Struct used to save messages in a non-ready tunnel to send once connected. 257 * Struct used to save messages in a non-ready tunnel to send once connected.
254 */ 258 */
255struct CadetTunnelQueueEntry { 259struct CadetTunnelQueueEntry
260{
256 /** 261 /**
257 * We are entries in a DLL 262 * We are entries in a DLL
258 */ 263 */
@@ -294,7 +299,8 @@ struct CadetTunnelQueueEntry {
294/** 299/**
295 * Struct containing all information regarding a tunnel to a peer. 300 * Struct containing all information regarding a tunnel to a peer.
296 */ 301 */
297struct CadetTunnel { 302struct CadetTunnel
303{
298 /** 304 /**
299 * Destination of the tunnel. 305 * Destination of the tunnel.
300 */ 306 */
@@ -459,19 +465,19 @@ struct CadetTunnel {
459 * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself 465 * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself
460 */ 466 */
461static int 467static int
462alice_or_betty(const struct GNUNET_PeerIdentity *other) 468alice_or_betty (const struct GNUNET_PeerIdentity *other)
463{ 469{
464 if (0 > GNUNET_memcmp(&my_full_id, 470 if (0 > GNUNET_memcmp (&my_full_id,
465 other)) 471 other))
466 return GNUNET_YES; 472 return GNUNET_YES;
467 else if (0 < GNUNET_memcmp(&my_full_id, 473 else if (0 < GNUNET_memcmp (&my_full_id,
468 other)) 474 other))
469 return GNUNET_NO; 475 return GNUNET_NO;
470 else 476 else
471 { 477 {
472 GNUNET_break_op(0); 478 GNUNET_break_op (0);
473 return GNUNET_SYSERR; 479 return GNUNET_SYSERR;
474 } 480 }
475} 481}
476 482
477 483
@@ -482,20 +488,20 @@ alice_or_betty(const struct GNUNET_PeerIdentity *other)
482 * @param ct connection to move to unready status 488 * @param ct connection to move to unready status
483 */ 489 */
484static void 490static void
485mark_connection_unready(struct CadetTConnection *ct) 491mark_connection_unready (struct CadetTConnection *ct)
486{ 492{
487 struct CadetTunnel *t = ct->t; 493 struct CadetTunnel *t = ct->t;
488 494
489 GNUNET_assert(GNUNET_YES == ct->is_ready); 495 GNUNET_assert (GNUNET_YES == ct->is_ready);
490 GNUNET_CONTAINER_DLL_remove(t->connection_ready_head, 496 GNUNET_CONTAINER_DLL_remove (t->connection_ready_head,
491 t->connection_ready_tail, 497 t->connection_ready_tail,
492 ct); 498 ct);
493 GNUNET_assert(0 < t->num_ready_connections); 499 GNUNET_assert (0 < t->num_ready_connections);
494 t->num_ready_connections--; 500 t->num_ready_connections--;
495 ct->is_ready = GNUNET_NO; 501 ct->is_ready = GNUNET_NO;
496 GNUNET_CONTAINER_DLL_insert(t->connection_busy_head, 502 GNUNET_CONTAINER_DLL_insert (t->connection_busy_head,
497 t->connection_busy_tail, 503 t->connection_busy_tail,
498 ct); 504 ct);
499 t->num_busy_connections++; 505 t->num_busy_connections++;
500} 506}
501 507
@@ -508,16 +514,16 @@ mark_connection_unready(struct CadetTConnection *ct)
508 * @return Static string the destination peer's ID. 514 * @return Static string the destination peer's ID.
509 */ 515 */
510const char * 516const char *
511GCT_2s(const struct CadetTunnel *t) 517GCT_2s (const struct CadetTunnel *t)
512{ 518{
513 static char buf[64]; 519 static char buf[64];
514 520
515 if (NULL == t) 521 if (NULL == t)
516 return "Tunnel(NULL)"; 522 return "Tunnel(NULL)";
517 GNUNET_snprintf(buf, 523 GNUNET_snprintf (buf,
518 sizeof(buf), 524 sizeof(buf),
519 "Tunnel %s", 525 "Tunnel %s",
520 GNUNET_i2s(GCP_get_id(t->destination))); 526 GNUNET_i2s (GCP_get_id (t->destination)));
521 return buf; 527 return buf;
522} 528}
523 529
@@ -530,37 +536,37 @@ GCT_2s(const struct CadetTunnel *t)
530 * @return String representation. 536 * @return String representation.
531 */ 537 */
532static const char * 538static const char *
533estate2s(enum CadetTunnelEState es) 539estate2s (enum CadetTunnelEState es)
534{ 540{
535 static char buf[32]; 541 static char buf[32];
536 542
537 switch (es) 543 switch (es)
538 { 544 {
539 case CADET_TUNNEL_KEY_UNINITIALIZED: 545 case CADET_TUNNEL_KEY_UNINITIALIZED:
540 return "CADET_TUNNEL_KEY_UNINITIALIZED"; 546 return "CADET_TUNNEL_KEY_UNINITIALIZED";
541 547
542 case CADET_TUNNEL_KEY_AX_RECV: 548 case CADET_TUNNEL_KEY_AX_RECV:
543 return "CADET_TUNNEL_KEY_AX_RECV"; 549 return "CADET_TUNNEL_KEY_AX_RECV";
544 550
545 case CADET_TUNNEL_KEY_AX_SENT: 551 case CADET_TUNNEL_KEY_AX_SENT:
546 return "CADET_TUNNEL_KEY_AX_SENT"; 552 return "CADET_TUNNEL_KEY_AX_SENT";
547 553
548 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV: 554 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
549 return "CADET_TUNNEL_KEY_AX_SENT_AND_RECV"; 555 return "CADET_TUNNEL_KEY_AX_SENT_AND_RECV";
550 556
551 case CADET_TUNNEL_KEY_AX_AUTH_SENT: 557 case CADET_TUNNEL_KEY_AX_AUTH_SENT:
552 return "CADET_TUNNEL_KEY_AX_AUTH_SENT"; 558 return "CADET_TUNNEL_KEY_AX_AUTH_SENT";
553 559
554 case CADET_TUNNEL_KEY_OK: 560 case CADET_TUNNEL_KEY_OK:
555 return "CADET_TUNNEL_KEY_OK"; 561 return "CADET_TUNNEL_KEY_OK";
556 562
557 default: 563 default:
558 GNUNET_snprintf(buf, 564 GNUNET_snprintf (buf,
559 sizeof(buf), 565 sizeof(buf),
560 "%u (UNKNOWN STATE)", 566 "%u (UNKNOWN STATE)",
561 es); 567 es);
562 return buf; 568 return buf;
563 } 569 }
564} 570}
565 571
566 572
@@ -571,7 +577,7 @@ estate2s(enum CadetTunnelEState es)
571 * @return the destination of the tunnel 577 * @return the destination of the tunnel
572 */ 578 */
573struct CadetPeer * 579struct CadetPeer *
574GCT_get_destination(struct CadetTunnel *t) 580GCT_get_destination (struct CadetTunnel *t)
575{ 581{
576 return t->destination; 582 return t->destination;
577} 583}
@@ -585,9 +591,9 @@ GCT_get_destination(struct CadetTunnel *t)
585 * @return Number of channels. 591 * @return Number of channels.
586 */ 592 */
587unsigned int 593unsigned int
588GCT_count_channels(struct CadetTunnel *t) 594GCT_count_channels (struct CadetTunnel *t)
589{ 595{
590 return GNUNET_CONTAINER_multihashmap32_size(t->channels); 596 return GNUNET_CONTAINER_multihashmap32_size (t->channels);
591} 597}
592 598
593 599
@@ -599,11 +605,11 @@ GCT_count_channels(struct CadetTunnel *t)
599 * @return NULL if channel does not exist 605 * @return NULL if channel does not exist
600 */ 606 */
601struct CadetChannel * 607struct CadetChannel *
602lookup_channel(struct CadetTunnel *t, 608lookup_channel (struct CadetTunnel *t,
603 struct GNUNET_CADET_ChannelTunnelNumber ctn) 609 struct GNUNET_CADET_ChannelTunnelNumber ctn)
604{ 610{
605 return GNUNET_CONTAINER_multihashmap32_get(t->channels, 611 return GNUNET_CONTAINER_multihashmap32_get (t->channels,
606 ntohl(ctn.cn)); 612 ntohl (ctn.cn));
607} 613}
608 614
609 615
@@ -615,7 +621,7 @@ lookup_channel(struct CadetTunnel *t,
615 * @return Number of connections created, either being established or ready. 621 * @return Number of connections created, either being established or ready.
616 */ 622 */
617unsigned int 623unsigned int
618GCT_count_any_connections(const struct CadetTunnel *t) 624GCT_count_any_connections (const struct CadetTunnel *t)
619{ 625{
620 return t->num_ready_connections + t->num_busy_connections; 626 return t->num_ready_connections + t->num_busy_connections;
621} 627}
@@ -629,12 +635,12 @@ GCT_count_any_connections(const struct CadetTunnel *t)
629 * @return NULL if we have no connection that is ready 635 * @return NULL if we have no connection that is ready
630 */ 636 */
631static struct CadetTConnection * 637static struct CadetTConnection *
632get_ready_connection(struct CadetTunnel *t) 638get_ready_connection (struct CadetTunnel *t)
633{ 639{
634 struct CadetTConnection *hd = t->connection_ready_head; 640 struct CadetTConnection *hd = t->connection_ready_head;
635 641
636 GNUNET_assert((NULL == hd) || 642 GNUNET_assert ((NULL == hd) ||
637 (GNUNET_YES == hd->is_ready)); 643 (GNUNET_YES == hd->is_ready));
638 return hd; 644 return hd;
639} 645}
640 646
@@ -647,7 +653,7 @@ get_ready_connection(struct CadetTunnel *t)
647 * @return Tunnel's encryption state. 653 * @return Tunnel's encryption state.
648 */ 654 */
649enum CadetTunnelEState 655enum CadetTunnelEState
650GCT_get_estate(struct CadetTunnel *t) 656GCT_get_estate (struct CadetTunnel *t)
651{ 657{
652 return t->estate; 658 return t->estate;
653} 659}
@@ -662,7 +668,7 @@ GCT_get_estate(struct CadetTunnel *t)
662 * @param cls the `struct CadetTunnel` to process messages on 668 * @param cls the `struct CadetTunnel` to process messages on
663 */ 669 */
664static void 670static void
665trigger_transmissions(void *cls); 671trigger_transmissions (void *cls);
666 672
667 673
668/* ************************************** start core crypto ***************************** */ 674/* ************************************** start core crypto ***************************** */
@@ -674,12 +680,12 @@ trigger_transmissions(void *cls);
674 * @param ax key material to update 680 * @param ax key material to update
675 */ 681 */
676static void 682static void
677new_ephemeral(struct CadetTunnelAxolotl *ax) 683new_ephemeral (struct CadetTunnelAxolotl *ax)
678{ 684{
679 LOG(GNUNET_ERROR_TYPE_DEBUG, 685 LOG (GNUNET_ERROR_TYPE_DEBUG,
680 "Creating new ephemeral ratchet key (DHRs)\n"); 686 "Creating new ephemeral ratchet key (DHRs)\n");
681 GNUNET_assert(GNUNET_OK == 687 GNUNET_assert (GNUNET_OK ==
682 GNUNET_CRYPTO_ecdhe_key_create2(&ax->DHRs)); 688 GNUNET_CRYPTO_ecdhe_key_create2 (&ax->DHRs));
683} 689}
684 690
685 691
@@ -693,31 +699,31 @@ new_ephemeral(struct CadetTunnelAxolotl *ax)
693 * @param hmac[out] Destination to store the HMAC. 699 * @param hmac[out] Destination to store the HMAC.
694 */ 700 */
695static void 701static void
696t_hmac(const void *plaintext, 702t_hmac (const void *plaintext,
697 size_t size, 703 size_t size,
698 uint32_t iv, 704 uint32_t iv,
699 const struct GNUNET_CRYPTO_SymmetricSessionKey *key, 705 const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
700 struct GNUNET_ShortHashCode *hmac) 706 struct GNUNET_ShortHashCode *hmac)
701{ 707{
702 static const char ctx[] = "cadet authentication key"; 708 static const char ctx[] = "cadet authentication key";
703 struct GNUNET_CRYPTO_AuthKey auth_key; 709 struct GNUNET_CRYPTO_AuthKey auth_key;
704 struct GNUNET_HashCode hash; 710 struct GNUNET_HashCode hash;
705 711
706 GNUNET_CRYPTO_hmac_derive_key(&auth_key, 712 GNUNET_CRYPTO_hmac_derive_key (&auth_key,
707 key, 713 key,
708 &iv, sizeof(iv), 714 &iv, sizeof(iv),
709 key, sizeof(*key), 715 key, sizeof(*key),
710 ctx, sizeof(ctx), 716 ctx, sizeof(ctx),
711 NULL); 717 NULL);
712 /* Two step: GNUNET_ShortHash is only 256 bits, 718 /* Two step: GNUNET_ShortHash is only 256 bits,
713 GNUNET_HashCode is 512, so we truncate. */ 719 GNUNET_HashCode is 512, so we truncate. */
714 GNUNET_CRYPTO_hmac(&auth_key, 720 GNUNET_CRYPTO_hmac (&auth_key,
715 plaintext, 721 plaintext,
716 size, 722 size,
717 &hash); 723 &hash);
718 GNUNET_memcpy(hmac, 724 GNUNET_memcpy (hmac,
719 &hash, 725 &hash,
720 sizeof(*hmac)); 726 sizeof(*hmac));
721} 727}
722 728
723 729
@@ -730,22 +736,22 @@ t_hmac(const void *plaintext,
730 * @param len Length of @a source. 736 * @param len Length of @a source.
731 */ 737 */
732static void 738static void
733t_ax_hmac_hash(const struct GNUNET_CRYPTO_SymmetricSessionKey *key, 739t_ax_hmac_hash (const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
734 struct GNUNET_HashCode *hash, 740 struct GNUNET_HashCode *hash,
735 const void *source, 741 const void *source,
736 unsigned int len) 742 unsigned int len)
737{ 743{
738 static const char ctx[] = "axolotl HMAC-HASH"; 744 static const char ctx[] = "axolotl HMAC-HASH";
739 struct GNUNET_CRYPTO_AuthKey auth_key; 745 struct GNUNET_CRYPTO_AuthKey auth_key;
740 746
741 GNUNET_CRYPTO_hmac_derive_key(&auth_key, 747 GNUNET_CRYPTO_hmac_derive_key (&auth_key,
742 key, 748 key,
743 ctx, sizeof(ctx), 749 ctx, sizeof(ctx),
744 NULL); 750 NULL);
745 GNUNET_CRYPTO_hmac(&auth_key, 751 GNUNET_CRYPTO_hmac (&auth_key,
746 source, 752 source,
747 len, 753 len,
748 hash); 754 hash);
749} 755}
750 756
751 757
@@ -758,22 +764,22 @@ t_ax_hmac_hash(const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
758 * @param len Length of @a source. 764 * @param len Length of @a source.
759 */ 765 */
760static void 766static void
761t_hmac_derive_key(const struct GNUNET_CRYPTO_SymmetricSessionKey *key, 767t_hmac_derive_key (const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
762 struct GNUNET_CRYPTO_SymmetricSessionKey *out, 768 struct GNUNET_CRYPTO_SymmetricSessionKey *out,
763 const void *source, 769 const void *source,
764 unsigned int len) 770 unsigned int len)
765{ 771{
766 static const char ctx[] = "axolotl derive key"; 772 static const char ctx[] = "axolotl derive key";
767 struct GNUNET_HashCode h; 773 struct GNUNET_HashCode h;
768 774
769 t_ax_hmac_hash(key, 775 t_ax_hmac_hash (key,
770 &h, 776 &h,
771 source, 777 source,
772 len); 778 len);
773 GNUNET_CRYPTO_kdf(out, sizeof(*out), 779 GNUNET_CRYPTO_kdf (out, sizeof(*out),
774 ctx, sizeof(ctx), 780 ctx, sizeof(ctx),
775 &h, sizeof(h), 781 &h, sizeof(h),
776 NULL); 782 NULL);
777} 783}
778 784
779 785
@@ -786,10 +792,10 @@ t_hmac_derive_key(const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
786 * @param size Size of the buffers at @a src and @a dst 792 * @param size Size of the buffers at @a src and @a dst
787 */ 793 */
788static void 794static void
789t_ax_encrypt(struct CadetTunnelAxolotl *ax, 795t_ax_encrypt (struct CadetTunnelAxolotl *ax,
790 void *dst, 796 void *dst,
791 const void *src, 797 const void *src,
792 size_t size) 798 size_t size)
793{ 799{
794 struct GNUNET_CRYPTO_SymmetricSessionKey MK; 800 struct GNUNET_CRYPTO_SymmetricSessionKey MK;
795 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 801 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
@@ -798,66 +804,67 @@ t_ax_encrypt(struct CadetTunnelAxolotl *ax,
798 ax->ratchet_counter++; 804 ax->ratchet_counter++;
799 if ((GNUNET_YES == ax->ratchet_allowed) && 805 if ((GNUNET_YES == ax->ratchet_allowed) &&
800 ((ratchet_messages <= ax->ratchet_counter) || 806 ((ratchet_messages <= ax->ratchet_counter) ||
801 (0 == GNUNET_TIME_absolute_get_remaining(ax->ratchet_expiration).rel_value_us))) 807 (0 == GNUNET_TIME_absolute_get_remaining (
802 { 808 ax->ratchet_expiration).rel_value_us)))
803 ax->ratchet_flag = GNUNET_YES; 809 {
804 } 810 ax->ratchet_flag = GNUNET_YES;
811 }
805 if (GNUNET_YES == ax->ratchet_flag) 812 if (GNUNET_YES == ax->ratchet_flag)
806 { 813 {
807 /* Advance ratchet */ 814 /* Advance ratchet */
808 struct GNUNET_CRYPTO_SymmetricSessionKey keys[3]; 815 struct GNUNET_CRYPTO_SymmetricSessionKey keys[3];
809 struct GNUNET_HashCode dh; 816 struct GNUNET_HashCode dh;
810 struct GNUNET_HashCode hmac; 817 struct GNUNET_HashCode hmac;
811 static const char ctx[] = "axolotl ratchet"; 818 static const char ctx[] = "axolotl ratchet";
812 819
813 new_ephemeral(ax); 820 new_ephemeral (ax);
814 ax->HKs = ax->NHKs; 821 ax->HKs = ax->NHKs;
815 822
816 /* RK, NHKs, CKs = KDF( HMAC-HASH(RK, DH(DHRs, DHRr)) ) */ 823 /* RK, NHKs, CKs = KDF( HMAC-HASH(RK, DH(DHRs, DHRr)) ) */
817 GNUNET_CRYPTO_ecc_ecdh(&ax->DHRs, 824 GNUNET_CRYPTO_ecc_ecdh (&ax->DHRs,
818 &ax->DHRr, 825 &ax->DHRr,
819 &dh); 826 &dh);
820 t_ax_hmac_hash(&ax->RK, 827 t_ax_hmac_hash (&ax->RK,
821 &hmac, 828 &hmac,
822 &dh, 829 &dh,
823 sizeof(dh)); 830 sizeof(dh));
824 GNUNET_CRYPTO_kdf(keys, sizeof(keys), 831 GNUNET_CRYPTO_kdf (keys, sizeof(keys),
825 ctx, sizeof(ctx), 832 ctx, sizeof(ctx),
826 &hmac, sizeof(hmac), 833 &hmac, sizeof(hmac),
827 NULL); 834 NULL);
828 ax->RK = keys[0]; 835 ax->RK = keys[0];
829 ax->NHKs = keys[1]; 836 ax->NHKs = keys[1];
830 ax->CKs = keys[2]; 837 ax->CKs = keys[2];
831 838
832 ax->PNs = ax->Ns; 839 ax->PNs = ax->Ns;
833 ax->Ns = 0; 840 ax->Ns = 0;
834 ax->ratchet_flag = GNUNET_NO; 841 ax->ratchet_flag = GNUNET_NO;
835 ax->ratchet_allowed = GNUNET_NO; 842 ax->ratchet_allowed = GNUNET_NO;
836 ax->ratchet_counter = 0; 843 ax->ratchet_counter = 0;
837 ax->ratchet_expiration 844 ax->ratchet_expiration
838 = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), 845 = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
839 ratchet_time); 846 ratchet_time);
840 } 847 }
841 848
842 t_hmac_derive_key(&ax->CKs, 849 t_hmac_derive_key (&ax->CKs,
843 &MK, 850 &MK,
844 "0", 851 "0",
845 1); 852 1);
846 GNUNET_CRYPTO_symmetric_derive_iv(&iv, 853 GNUNET_CRYPTO_symmetric_derive_iv (&iv,
847 &MK, 854 &MK,
848 NULL, 0, 855 NULL, 0,
849 NULL); 856 NULL);
850 857
851 out_size = GNUNET_CRYPTO_symmetric_encrypt(src, 858 out_size = GNUNET_CRYPTO_symmetric_encrypt (src,
852 size, 859 size,
853 &MK, 860 &MK,
854 &iv, 861 &iv,
855 dst); 862 dst);
856 GNUNET_assert(size == out_size); 863 GNUNET_assert (size == out_size);
857 t_hmac_derive_key(&ax->CKs, 864 t_hmac_derive_key (&ax->CKs,
858 &ax->CKs, 865 &ax->CKs,
859 "1", 866 "1",
860 1); 867 1);
861} 868}
862 869
863 870
@@ -870,34 +877,34 @@ t_ax_encrypt(struct CadetTunnelAxolotl *ax,
870 * @param size Size of the @a src and @a dst buffers 877 * @param size Size of the @a src and @a dst buffers
871 */ 878 */
872static void 879static void
873t_ax_decrypt(struct CadetTunnelAxolotl *ax, 880t_ax_decrypt (struct CadetTunnelAxolotl *ax,
874 void *dst, 881 void *dst,
875 const void *src, 882 const void *src,
876 size_t size) 883 size_t size)
877{ 884{
878 struct GNUNET_CRYPTO_SymmetricSessionKey MK; 885 struct GNUNET_CRYPTO_SymmetricSessionKey MK;
879 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 886 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
880 size_t out_size; 887 size_t out_size;
881 888
882 t_hmac_derive_key(&ax->CKr, 889 t_hmac_derive_key (&ax->CKr,
883 &MK, 890 &MK,
884 "0", 891 "0",
885 1); 892 1);
886 GNUNET_CRYPTO_symmetric_derive_iv(&iv, 893 GNUNET_CRYPTO_symmetric_derive_iv (&iv,
887 &MK, 894 &MK,
888 NULL, 0, 895 NULL, 0,
889 NULL); 896 NULL);
890 GNUNET_assert(size >= sizeof(struct GNUNET_MessageHeader)); 897 GNUNET_assert (size >= sizeof(struct GNUNET_MessageHeader));
891 out_size = GNUNET_CRYPTO_symmetric_decrypt(src, 898 out_size = GNUNET_CRYPTO_symmetric_decrypt (src,
892 size, 899 size,
893 &MK, 900 &MK,
894 &iv, 901 &iv,
895 dst); 902 dst);
896 GNUNET_assert(out_size == size); 903 GNUNET_assert (out_size == size);
897 t_hmac_derive_key(&ax->CKr, 904 t_hmac_derive_key (&ax->CKr,
898 &ax->CKr, 905 &ax->CKr,
899 "1", 906 "1",
900 1); 907 1);
901} 908}
902 909
903 910
@@ -908,22 +915,23 @@ t_ax_decrypt(struct CadetTunnelAxolotl *ax,
908 * @param[in|out] msg Message whose header to encrypt. 915 * @param[in|out] msg Message whose header to encrypt.
909 */ 916 */
910static void 917static void
911t_h_encrypt(struct CadetTunnelAxolotl *ax, 918t_h_encrypt (struct CadetTunnelAxolotl *ax,
912 struct GNUNET_CADET_TunnelEncryptedMessage *msg) 919 struct GNUNET_CADET_TunnelEncryptedMessage *msg)
913{ 920{
914 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 921 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
915 size_t out_size; 922 size_t out_size;
916 923
917 GNUNET_CRYPTO_symmetric_derive_iv(&iv, 924 GNUNET_CRYPTO_symmetric_derive_iv (&iv,
918 &ax->HKs, 925 &ax->HKs,
919 NULL, 0, 926 NULL, 0,
920 NULL); 927 NULL);
921 out_size = GNUNET_CRYPTO_symmetric_encrypt(&msg->ax_header, 928 out_size = GNUNET_CRYPTO_symmetric_encrypt (&msg->ax_header,
922 sizeof(struct GNUNET_CADET_AxHeader), 929 sizeof(struct
923 &ax->HKs, 930 GNUNET_CADET_AxHeader),
924 &iv, 931 &ax->HKs,
925 &msg->ax_header); 932 &iv,
926 GNUNET_assert(sizeof(struct GNUNET_CADET_AxHeader) == out_size); 933 &msg->ax_header);
934 GNUNET_assert (sizeof(struct GNUNET_CADET_AxHeader) == out_size);
927} 935}
928 936
929 937
@@ -935,23 +943,24 @@ t_h_encrypt(struct CadetTunnelAxolotl *ax,
935 * @param dst Where to decrypt header to. 943 * @param dst Where to decrypt header to.
936 */ 944 */
937static void 945static void
938t_h_decrypt(struct CadetTunnelAxolotl *ax, 946t_h_decrypt (struct CadetTunnelAxolotl *ax,
939 const struct GNUNET_CADET_TunnelEncryptedMessage *src, 947 const struct GNUNET_CADET_TunnelEncryptedMessage *src,
940 struct GNUNET_CADET_TunnelEncryptedMessage *dst) 948 struct GNUNET_CADET_TunnelEncryptedMessage *dst)
941{ 949{
942 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 950 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
943 size_t out_size; 951 size_t out_size;
944 952
945 GNUNET_CRYPTO_symmetric_derive_iv(&iv, 953 GNUNET_CRYPTO_symmetric_derive_iv (&iv,
946 &ax->HKr, 954 &ax->HKr,
947 NULL, 0, 955 NULL, 0,
948 NULL); 956 NULL);
949 out_size = GNUNET_CRYPTO_symmetric_decrypt(&src->ax_header.Ns, 957 out_size = GNUNET_CRYPTO_symmetric_decrypt (&src->ax_header.Ns,
950 sizeof(struct GNUNET_CADET_AxHeader), 958 sizeof(struct
951 &ax->HKr, 959 GNUNET_CADET_AxHeader),
952 &iv, 960 &ax->HKr,
953 &dst->ax_header.Ns); 961 &iv,
954 GNUNET_assert(sizeof(struct GNUNET_CADET_AxHeader) == out_size); 962 &dst->ax_header.Ns);
963 GNUNET_assert (sizeof(struct GNUNET_CADET_AxHeader) == out_size);
955} 964}
956 965
957 966
@@ -962,13 +971,13 @@ t_h_decrypt(struct CadetTunnelAxolotl *ax,
962 * @param key Key to delete. 971 * @param key Key to delete.
963 */ 972 */
964static void 973static void
965delete_skipped_key(struct CadetTunnelAxolotl *ax, 974delete_skipped_key (struct CadetTunnelAxolotl *ax,
966 struct CadetTunnelSkippedKey *key) 975 struct CadetTunnelSkippedKey *key)
967{ 976{
968 GNUNET_CONTAINER_DLL_remove(ax->skipped_head, 977 GNUNET_CONTAINER_DLL_remove (ax->skipped_head,
969 ax->skipped_tail, 978 ax->skipped_tail,
970 key); 979 key);
971 GNUNET_free(key); 980 GNUNET_free (key);
972 ax->skipped--; 981 ax->skipped--;
973} 982}
974 983
@@ -984,10 +993,10 @@ delete_skipped_key(struct CadetTunnelAxolotl *ax,
984 * @return Size of the decrypted data, -1 if an error was encountered. 993 * @return Size of the decrypted data, -1 if an error was encountered.
985 */ 994 */
986static ssize_t 995static ssize_t
987try_old_ax_keys(struct CadetTunnelAxolotl *ax, 996try_old_ax_keys (struct CadetTunnelAxolotl *ax,
988 void *dst, 997 void *dst,
989 const struct GNUNET_CADET_TunnelEncryptedMessage *src, 998 const struct GNUNET_CADET_TunnelEncryptedMessage *src,
990 size_t size) 999 size_t size)
991{ 1000{
992 struct CadetTunnelSkippedKey *key; 1001 struct CadetTunnelSkippedKey *key;
993 struct GNUNET_ShortHashCode *hmac; 1002 struct GNUNET_ShortHashCode *hmac;
@@ -999,70 +1008,70 @@ try_old_ax_keys(struct CadetTunnelAxolotl *ax,
999 size_t len; 1008 size_t len;
1000 unsigned int N; 1009 unsigned int N;
1001 1010
1002 LOG(GNUNET_ERROR_TYPE_DEBUG, 1011 LOG (GNUNET_ERROR_TYPE_DEBUG,
1003 "Trying skipped keys\n"); 1012 "Trying skipped keys\n");
1004 hmac = &plaintext_header.hmac; 1013 hmac = &plaintext_header.hmac;
1005 esize = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage); 1014 esize = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage);
1006 1015
1007 /* Find a correct Header Key */ 1016 /* Find a correct Header Key */
1008 valid_HK = NULL; 1017 valid_HK = NULL;
1009 for (key = ax->skipped_head; NULL != key; key = key->next) 1018 for (key = ax->skipped_head; NULL != key; key = key->next)
1010 { 1019 {
1011 t_hmac(&src->ax_header, 1020 t_hmac (&src->ax_header,
1012 sizeof(struct GNUNET_CADET_AxHeader) + esize, 1021 sizeof(struct GNUNET_CADET_AxHeader) + esize,
1013 0, 1022 0,
1014 &key->HK, 1023 &key->HK,
1015 hmac); 1024 hmac);
1016 if (0 == GNUNET_memcmp(hmac, 1025 if (0 == GNUNET_memcmp (hmac,
1017 &src->hmac)) 1026 &src->hmac))
1018 { 1027 {
1019 valid_HK = &key->HK; 1028 valid_HK = &key->HK;
1020 break; 1029 break;
1021 }
1022 } 1030 }
1031 }
1023 if (NULL == key) 1032 if (NULL == key)
1024 return -1; 1033 return -1;
1025 1034
1026 /* Should've been checked in -cadet_connection.c handle_cadet_encrypted. */ 1035 /* Should've been checked in -cadet_connection.c handle_cadet_encrypted. */
1027 GNUNET_assert(size > sizeof(struct GNUNET_CADET_TunnelEncryptedMessage)); 1036 GNUNET_assert (size > sizeof(struct GNUNET_CADET_TunnelEncryptedMessage));
1028 len = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage); 1037 len = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage);
1029 GNUNET_assert(len >= sizeof(struct GNUNET_MessageHeader)); 1038 GNUNET_assert (len >= sizeof(struct GNUNET_MessageHeader));
1030 1039
1031 /* Decrypt header */ 1040 /* Decrypt header */
1032 GNUNET_CRYPTO_symmetric_derive_iv(&iv, 1041 GNUNET_CRYPTO_symmetric_derive_iv (&iv,
1033 &key->HK, 1042 &key->HK,
1034 NULL, 0, 1043 NULL, 0,
1035 NULL); 1044 NULL);
1036 res = GNUNET_CRYPTO_symmetric_decrypt(&src->ax_header.Ns, 1045 res = GNUNET_CRYPTO_symmetric_decrypt (&src->ax_header.Ns,
1037 sizeof(struct GNUNET_CADET_AxHeader), 1046 sizeof(struct GNUNET_CADET_AxHeader),
1038 &key->HK, 1047 &key->HK,
1039 &iv, 1048 &iv,
1040 &plaintext_header.ax_header.Ns); 1049 &plaintext_header.ax_header.Ns);
1041 GNUNET_assert(sizeof(struct GNUNET_CADET_AxHeader) == res); 1050 GNUNET_assert (sizeof(struct GNUNET_CADET_AxHeader) == res);
1042 1051
1043 /* Find the correct message key */ 1052 /* Find the correct message key */
1044 N = ntohl(plaintext_header.ax_header.Ns); 1053 N = ntohl (plaintext_header.ax_header.Ns);
1045 while ((NULL != key) && 1054 while ((NULL != key) &&
1046 (N != key->Kn)) 1055 (N != key->Kn))
1047 key = key->next; 1056 key = key->next;
1048 if ((NULL == key) || 1057 if ((NULL == key) ||
1049 (0 != GNUNET_memcmp(&key->HK, 1058 (0 != GNUNET_memcmp (&key->HK,
1050 valid_HK))) 1059 valid_HK)))
1051 return -1; 1060 return -1;
1052 1061
1053 /* Decrypt payload */ 1062 /* Decrypt payload */
1054 GNUNET_CRYPTO_symmetric_derive_iv(&iv, 1063 GNUNET_CRYPTO_symmetric_derive_iv (&iv,
1055 &key->MK, 1064 &key->MK,
1056 NULL, 1065 NULL,
1057 0, 1066 0,
1058 NULL); 1067 NULL);
1059 res = GNUNET_CRYPTO_symmetric_decrypt(&src[1], 1068 res = GNUNET_CRYPTO_symmetric_decrypt (&src[1],
1060 len, 1069 len,
1061 &key->MK, 1070 &key->MK,
1062 &iv, 1071 &iv,
1063 dst); 1072 dst);
1064 delete_skipped_key(ax, 1073 delete_skipped_key (ax,
1065 key); 1074 key);
1066 return res; 1075 return res;
1067} 1076}
1068 1077
@@ -1074,26 +1083,26 @@ try_old_ax_keys(struct CadetTunnelAxolotl *ax,
1074 * @param HKr Header Key to use. 1083 * @param HKr Header Key to use.
1075 */ 1084 */
1076static void 1085static void
1077store_skipped_key(struct CadetTunnelAxolotl *ax, 1086store_skipped_key (struct CadetTunnelAxolotl *ax,
1078 const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr) 1087 const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr)
1079{ 1088{
1080 struct CadetTunnelSkippedKey *key; 1089 struct CadetTunnelSkippedKey *key;
1081 1090
1082 key = GNUNET_new(struct CadetTunnelSkippedKey); 1091 key = GNUNET_new (struct CadetTunnelSkippedKey);
1083 key->timestamp = GNUNET_TIME_absolute_get(); 1092 key->timestamp = GNUNET_TIME_absolute_get ();
1084 key->Kn = ax->Nr; 1093 key->Kn = ax->Nr;
1085 key->HK = ax->HKr; 1094 key->HK = ax->HKr;
1086 t_hmac_derive_key(&ax->CKr, 1095 t_hmac_derive_key (&ax->CKr,
1087 &key->MK, 1096 &key->MK,
1088 "0", 1097 "0",
1089 1); 1098 1);
1090 t_hmac_derive_key(&ax->CKr, 1099 t_hmac_derive_key (&ax->CKr,
1091 &ax->CKr, 1100 &ax->CKr,
1092 "1", 1101 "1",
1093 1); 1102 1);
1094 GNUNET_CONTAINER_DLL_insert(ax->skipped_head, 1103 GNUNET_CONTAINER_DLL_insert (ax->skipped_head,
1095 ax->skipped_tail, 1104 ax->skipped_tail,
1096 key); 1105 key);
1097 ax->skipped++; 1106 ax->skipped++;
1098 ax->Nr++; 1107 ax->Nr++;
1099} 1108}
@@ -1110,41 +1119,41 @@ store_skipped_key(struct CadetTunnelAxolotl *ax,
1110 * #GNUNET_SYSERR if an error ocurred (@a Np not expected). 1119 * #GNUNET_SYSERR if an error ocurred (@a Np not expected).
1111 */ 1120 */
1112static int 1121static int
1113store_ax_keys(struct CadetTunnelAxolotl *ax, 1122store_ax_keys (struct CadetTunnelAxolotl *ax,
1114 const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr, 1123 const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr,
1115 uint32_t Np) 1124 uint32_t Np)
1116{ 1125{
1117 int gap; 1126 int gap;
1118 1127
1119 gap = Np - ax->Nr; 1128 gap = Np - ax->Nr;
1120 LOG(GNUNET_ERROR_TYPE_DEBUG, 1129 LOG (GNUNET_ERROR_TYPE_DEBUG,
1121 "Storing skipped keys [%u, %u)\n", 1130 "Storing skipped keys [%u, %u)\n",
1122 ax->Nr, 1131 ax->Nr,
1123 Np); 1132 Np);
1124 if (MAX_KEY_GAP < gap) 1133 if (MAX_KEY_GAP < gap)
1125 { 1134 {
1126 /* Avoid DoS (forcing peer to do more than #MAX_KEY_GAP HMAC operations) */ 1135 /* Avoid DoS (forcing peer to do more than #MAX_KEY_GAP HMAC operations) */
1127 /* TODO: start new key exchange on return */ 1136 /* TODO: start new key exchange on return */
1128 GNUNET_break_op(0); 1137 GNUNET_break_op (0);
1129 LOG(GNUNET_ERROR_TYPE_WARNING, 1138 LOG (GNUNET_ERROR_TYPE_WARNING,
1130 "Got message %u, expected %u+\n", 1139 "Got message %u, expected %u+\n",
1131 Np, 1140 Np,
1132 ax->Nr); 1141 ax->Nr);
1133 return GNUNET_SYSERR; 1142 return GNUNET_SYSERR;
1134 } 1143 }
1135 if (0 > gap) 1144 if (0 > gap)
1136 { 1145 {
1137 /* Delayed message: don't store keys, flag to try old keys. */ 1146 /* Delayed message: don't store keys, flag to try old keys. */
1138 return GNUNET_SYSERR; 1147 return GNUNET_SYSERR;
1139 } 1148 }
1140 1149
1141 while (ax->Nr < Np) 1150 while (ax->Nr < Np)
1142 store_skipped_key(ax, 1151 store_skipped_key (ax,
1143 HKr); 1152 HKr);
1144 1153
1145 while (ax->skipped > MAX_SKIPPED_KEYS) 1154 while (ax->skipped > MAX_SKIPPED_KEYS)
1146 delete_skipped_key(ax, 1155 delete_skipped_key (ax,
1147 ax->skipped_tail); 1156 ax->skipped_tail);
1148 return GNUNET_OK; 1157 return GNUNET_OK;
1149} 1158}
1150 1159
@@ -1160,10 +1169,11 @@ store_ax_keys(struct CadetTunnelAxolotl *ax,
1160 * @return Size of the decrypted data, -1 if an error was encountered. 1169 * @return Size of the decrypted data, -1 if an error was encountered.
1161 */ 1170 */
1162static ssize_t 1171static ssize_t
1163t_ax_decrypt_and_validate(struct CadetTunnelAxolotl *ax, 1172t_ax_decrypt_and_validate (struct CadetTunnelAxolotl *ax,
1164 void *dst, 1173 void *dst,
1165 const struct GNUNET_CADET_TunnelEncryptedMessage *src, 1174 const struct
1166 size_t size) 1175 GNUNET_CADET_TunnelEncryptedMessage *src,
1176 size_t size)
1167{ 1177{
1168 struct GNUNET_ShortHashCode msg_hmac; 1178 struct GNUNET_ShortHashCode msg_hmac;
1169 struct GNUNET_HashCode hmac; 1179 struct GNUNET_HashCode hmac;
@@ -1175,90 +1185,90 @@ t_ax_decrypt_and_validate(struct CadetTunnelAxolotl *ax,
1175 esize = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage); 1185 esize = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage);
1176 1186
1177 /* Try current HK */ 1187 /* Try current HK */
1178 t_hmac(&src->ax_header, 1188 t_hmac (&src->ax_header,
1179 sizeof(struct GNUNET_CADET_AxHeader) + esize, 1189 sizeof(struct GNUNET_CADET_AxHeader) + esize,
1180 0, &ax->HKr, 1190 0, &ax->HKr,
1181 &msg_hmac); 1191 &msg_hmac);
1182 if (0 != GNUNET_memcmp(&msg_hmac, 1192 if (0 != GNUNET_memcmp (&msg_hmac,
1183 &src->hmac)) 1193 &src->hmac))
1194 {
1195 static const char ctx[] = "axolotl ratchet";
1196 struct GNUNET_CRYPTO_SymmetricSessionKey keys[3]; /* RKp, NHKp, CKp */
1197 struct GNUNET_CRYPTO_SymmetricSessionKey HK;
1198 struct GNUNET_HashCode dh;
1199 struct GNUNET_CRYPTO_EcdhePublicKey *DHRp;
1200
1201 /* Try Next HK */
1202 t_hmac (&src->ax_header,
1203 sizeof(struct GNUNET_CADET_AxHeader) + esize,
1204 0,
1205 &ax->NHKr,
1206 &msg_hmac);
1207 if (0 != GNUNET_memcmp (&msg_hmac,
1208 &src->hmac))
1184 { 1209 {
1185 static const char ctx[] = "axolotl ratchet"; 1210 /* Try the skipped keys, if that fails, we're out of luck. */
1186 struct GNUNET_CRYPTO_SymmetricSessionKey keys[3]; /* RKp, NHKp, CKp */ 1211 return try_old_ax_keys (ax,
1187 struct GNUNET_CRYPTO_SymmetricSessionKey HK; 1212 dst,
1188 struct GNUNET_HashCode dh; 1213 src,
1189 struct GNUNET_CRYPTO_EcdhePublicKey *DHRp; 1214 size);
1190 1215 }
1191 /* Try Next HK */ 1216 HK = ax->HKr;
1192 t_hmac(&src->ax_header, 1217 ax->HKr = ax->NHKr;
1193 sizeof(struct GNUNET_CADET_AxHeader) + esize, 1218 t_h_decrypt (ax,
1194 0, 1219 src,
1195 &ax->NHKr, 1220 &plaintext_header);
1196 &msg_hmac); 1221 Np = ntohl (plaintext_header.ax_header.Ns);
1197 if (0 != GNUNET_memcmp(&msg_hmac, 1222 PNp = ntohl (plaintext_header.ax_header.PNs);
1198 &src->hmac)) 1223 DHRp = &plaintext_header.ax_header.DHRs;
1199 { 1224 store_ax_keys (ax,
1200 /* Try the skipped keys, if that fails, we're out of luck. */ 1225 &HK,
1201 return try_old_ax_keys(ax, 1226 PNp);
1202 dst, 1227
1203 src, 1228 /* RKp, NHKp, CKp = KDF (HMAC-HASH (RK, DH (DHRp, DHRs))) */
1204 size); 1229 GNUNET_CRYPTO_ecc_ecdh (&ax->DHRs,
1205 } 1230 DHRp,
1206 HK = ax->HKr; 1231 &dh);
1207 ax->HKr = ax->NHKr; 1232 t_ax_hmac_hash (&ax->RK,
1208 t_h_decrypt(ax, 1233 &hmac,
1209 src, 1234 &dh, sizeof(dh));
1210 &plaintext_header); 1235 GNUNET_CRYPTO_kdf (keys, sizeof(keys),
1211 Np = ntohl(plaintext_header.ax_header.Ns); 1236 ctx, sizeof(ctx),
1212 PNp = ntohl(plaintext_header.ax_header.PNs); 1237 &hmac, sizeof(hmac),
1213 DHRp = &plaintext_header.ax_header.DHRs; 1238 NULL);
1214 store_ax_keys(ax, 1239
1215 &HK, 1240 /* Commit "purported" keys */
1216 PNp); 1241 ax->RK = keys[0];
1217 1242 ax->NHKr = keys[1];
1218 /* RKp, NHKp, CKp = KDF (HMAC-HASH (RK, DH (DHRp, DHRs))) */ 1243 ax->CKr = keys[2];
1219 GNUNET_CRYPTO_ecc_ecdh(&ax->DHRs, 1244 ax->DHRr = *DHRp;
1220 DHRp, 1245 ax->Nr = 0;
1221 &dh); 1246 ax->ratchet_allowed = GNUNET_YES;
1222 t_ax_hmac_hash(&ax->RK, 1247 }
1223 &hmac,
1224 &dh, sizeof(dh));
1225 GNUNET_CRYPTO_kdf(keys, sizeof(keys),
1226 ctx, sizeof(ctx),
1227 &hmac, sizeof(hmac),
1228 NULL);
1229
1230 /* Commit "purported" keys */
1231 ax->RK = keys[0];
1232 ax->NHKr = keys[1];
1233 ax->CKr = keys[2];
1234 ax->DHRr = *DHRp;
1235 ax->Nr = 0;
1236 ax->ratchet_allowed = GNUNET_YES;
1237 }
1238 else 1248 else
1239 { 1249 {
1240 t_h_decrypt(ax, 1250 t_h_decrypt (ax,
1241 src, 1251 src,
1242 &plaintext_header); 1252 &plaintext_header);
1243 Np = ntohl(plaintext_header.ax_header.Ns); 1253 Np = ntohl (plaintext_header.ax_header.Ns);
1244 PNp = ntohl(plaintext_header.ax_header.PNs); 1254 PNp = ntohl (plaintext_header.ax_header.PNs);
1245 } 1255 }
1246 if ((Np != ax->Nr) && 1256 if ((Np != ax->Nr) &&
1247 (GNUNET_OK != store_ax_keys(ax, 1257 (GNUNET_OK != store_ax_keys (ax,
1248 &ax->HKr, 1258 &ax->HKr,
1249 Np))) 1259 Np)))
1250 { 1260 {
1251 /* Try the skipped keys, if that fails, we're out of luck. */ 1261 /* Try the skipped keys, if that fails, we're out of luck. */
1252 return try_old_ax_keys(ax, 1262 return try_old_ax_keys (ax,
1253 dst, 1263 dst,
1254 src, 1264 src,
1255 size); 1265 size);
1256 } 1266 }
1257 1267
1258 t_ax_decrypt(ax, 1268 t_ax_decrypt (ax,
1259 dst, 1269 dst,
1260 &src[1], 1270 &src[1],
1261 esize); 1271 esize);
1262 ax->Nr = Np + 1; 1272 ax->Nr = Np + 1;
1263 return esize; 1273 return esize;
1264} 1274}
@@ -1274,13 +1284,13 @@ t_ax_decrypt_and_validate(struct CadetTunnelAxolotl *ax,
1274 * @return #GNUNET_OK (continue to iterate) 1284 * @return #GNUNET_OK (continue to iterate)
1275 */ 1285 */
1276static int 1286static int
1277notify_tunnel_up_cb(void *cls, 1287notify_tunnel_up_cb (void *cls,
1278 uint32_t key, 1288 uint32_t key,
1279 void *value) 1289 void *value)
1280{ 1290{
1281 struct CadetChannel *ch = value; 1291 struct CadetChannel *ch = value;
1282 1292
1283 GCCH_tunnel_up(ch); 1293 GCCH_tunnel_up (ch);
1284 return GNUNET_OK; 1294 return GNUNET_OK;
1285} 1295}
1286 1296
@@ -1293,35 +1303,35 @@ notify_tunnel_up_cb(void *cls,
1293 * @param state New encryption state. 1303 * @param state New encryption state.
1294 */ 1304 */
1295void 1305void
1296GCT_change_estate(struct CadetTunnel *t, 1306GCT_change_estate (struct CadetTunnel *t,
1297 enum CadetTunnelEState state) 1307 enum CadetTunnelEState state)
1298{ 1308{
1299 enum CadetTunnelEState old = t->estate; 1309 enum CadetTunnelEState old = t->estate;
1300 1310
1301 t->estate = state; 1311 t->estate = state;
1302 LOG(GNUNET_ERROR_TYPE_DEBUG, 1312 LOG (GNUNET_ERROR_TYPE_DEBUG,
1303 "%s estate changed from %s to %s\n", 1313 "%s estate changed from %s to %s\n",
1304 GCT_2s(t), 1314 GCT_2s (t),
1305 estate2s(old), 1315 estate2s (old),
1306 estate2s(state)); 1316 estate2s (state));
1307 1317
1308 if ((CADET_TUNNEL_KEY_OK != old) && 1318 if ((CADET_TUNNEL_KEY_OK != old) &&
1309 (CADET_TUNNEL_KEY_OK == t->estate)) 1319 (CADET_TUNNEL_KEY_OK == t->estate))
1320 {
1321 if (NULL != t->kx_task)
1310 { 1322 {
1311 if (NULL != t->kx_task) 1323 GNUNET_SCHEDULER_cancel (t->kx_task);
1312 { 1324 t->kx_task = NULL;
1313 GNUNET_SCHEDULER_cancel(t->kx_task);
1314 t->kx_task = NULL;
1315 }
1316 /* notify all channels that have been waiting */
1317 GNUNET_CONTAINER_multihashmap32_iterate(t->channels,
1318 &notify_tunnel_up_cb,
1319 t);
1320 if (NULL != t->send_task)
1321 GNUNET_SCHEDULER_cancel(t->send_task);
1322 t->send_task = GNUNET_SCHEDULER_add_now(&trigger_transmissions,
1323 t);
1324 } 1325 }
1326 /* notify all channels that have been waiting */
1327 GNUNET_CONTAINER_multihashmap32_iterate (t->channels,
1328 &notify_tunnel_up_cb,
1329 t);
1330 if (NULL != t->send_task)
1331 GNUNET_SCHEDULER_cancel (t->send_task);
1332 t->send_task = GNUNET_SCHEDULER_add_now (&trigger_transmissions,
1333 t);
1334 }
1325} 1335}
1326 1336
1327 1337
@@ -1334,63 +1344,63 @@ GCT_change_estate(struct CadetTunnel *t,
1334 * @param ax axolotl key context to use 1344 * @param ax axolotl key context to use
1335 */ 1345 */
1336static void 1346static void
1337send_kx(struct CadetTunnel *t, 1347send_kx (struct CadetTunnel *t,
1338 struct CadetTConnection *ct, 1348 struct CadetTConnection *ct,
1339 struct CadetTunnelAxolotl *ax) 1349 struct CadetTunnelAxolotl *ax)
1340{ 1350{
1341 struct CadetConnection *cc; 1351 struct CadetConnection *cc;
1342 struct GNUNET_MQ_Envelope *env; 1352 struct GNUNET_MQ_Envelope *env;
1343 struct GNUNET_CADET_TunnelKeyExchangeMessage *msg; 1353 struct GNUNET_CADET_TunnelKeyExchangeMessage *msg;
1344 enum GNUNET_CADET_KX_Flags flags; 1354 enum GNUNET_CADET_KX_Flags flags;
1345 1355
1346 if (GNUNET_YES != alice_or_betty(GCP_get_id(t->destination))) 1356 if (GNUNET_YES != alice_or_betty (GCP_get_id (t->destination)))
1347 return; /* only Alice may send KX */ 1357 return; /* only Alice may send KX */
1348 if ((NULL == ct) || 1358 if ((NULL == ct) ||
1349 (GNUNET_NO == ct->is_ready)) 1359 (GNUNET_NO == ct->is_ready))
1350 ct = get_ready_connection(t); 1360 ct = get_ready_connection (t);
1351 if (NULL == ct) 1361 if (NULL == ct)
1352 { 1362 {
1353 LOG(GNUNET_ERROR_TYPE_DEBUG, 1363 LOG (GNUNET_ERROR_TYPE_DEBUG,
1354 "Wanted to send %s in state %s, but no connection is ready, deferring\n", 1364 "Wanted to send %s in state %s, but no connection is ready, deferring\n",
1355 GCT_2s(t), 1365 GCT_2s (t),
1356 estate2s(t->estate)); 1366 estate2s (t->estate));
1357 t->next_kx_attempt = GNUNET_TIME_absolute_get(); 1367 t->next_kx_attempt = GNUNET_TIME_absolute_get ();
1358 return; 1368 return;
1359 } 1369 }
1360 cc = ct->cc; 1370 cc = ct->cc;
1361 env = GNUNET_MQ_msg(msg, 1371 env = GNUNET_MQ_msg (msg,
1362 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX); 1372 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX);
1363 flags = GNUNET_CADET_KX_FLAG_FORCE_REPLY; /* always for KX */ 1373 flags = GNUNET_CADET_KX_FLAG_FORCE_REPLY; /* always for KX */
1364 msg->flags = htonl(flags); 1374 msg->flags = htonl (flags);
1365 msg->cid = *GCC_get_id(cc); 1375 msg->cid = *GCC_get_id (cc);
1366 GNUNET_CRYPTO_ecdhe_key_get_public(&ax->kx_0, 1376 GNUNET_CRYPTO_ecdhe_key_get_public (&ax->kx_0,
1367 &msg->ephemeral_key); 1377 &msg->ephemeral_key);
1368#if DEBUG_KX 1378#if DEBUG_KX
1369 msg->ephemeral_key_XXX = ax->kx_0; 1379 msg->ephemeral_key_XXX = ax->kx_0;
1370 msg->private_key_XXX = *my_private_key; 1380 msg->private_key_XXX = *my_private_key;
1371#endif 1381#endif
1372 LOG(GNUNET_ERROR_TYPE_DEBUG, 1382 LOG (GNUNET_ERROR_TYPE_DEBUG,
1373 "Sending KX message to %s with ephemeral %s on CID %s\n", 1383 "Sending KX message to %s with ephemeral %s on CID %s\n",
1374 GCT_2s(t), 1384 GCT_2s (t),
1375 GNUNET_e2s(&msg->ephemeral_key), 1385 GNUNET_e2s (&msg->ephemeral_key),
1376 GNUNET_sh2s(&msg->cid.connection_of_tunnel)); 1386 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
1377 GNUNET_CRYPTO_ecdhe_key_get_public(&ax->DHRs, 1387 GNUNET_CRYPTO_ecdhe_key_get_public (&ax->DHRs,
1378 &msg->ratchet_key); 1388 &msg->ratchet_key);
1379 mark_connection_unready(ct); 1389 mark_connection_unready (ct);
1380 t->kx_retry_delay = GNUNET_TIME_STD_BACKOFF(t->kx_retry_delay); 1390 t->kx_retry_delay = GNUNET_TIME_STD_BACKOFF (t->kx_retry_delay);
1381 t->next_kx_attempt = GNUNET_TIME_relative_to_absolute(t->kx_retry_delay); 1391 t->next_kx_attempt = GNUNET_TIME_relative_to_absolute (t->kx_retry_delay);
1382 if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) 1392 if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate)
1383 GCT_change_estate(t, 1393 GCT_change_estate (t,
1384 CADET_TUNNEL_KEY_AX_SENT); 1394 CADET_TUNNEL_KEY_AX_SENT);
1385 else if (CADET_TUNNEL_KEY_AX_RECV == t->estate) 1395 else if (CADET_TUNNEL_KEY_AX_RECV == t->estate)
1386 GCT_change_estate(t, 1396 GCT_change_estate (t,
1387 CADET_TUNNEL_KEY_AX_SENT_AND_RECV); 1397 CADET_TUNNEL_KEY_AX_SENT_AND_RECV);
1388 GCC_transmit(cc, 1398 GCC_transmit (cc,
1389 env); 1399 env);
1390 GNUNET_STATISTICS_update(stats, 1400 GNUNET_STATISTICS_update (stats,
1391 "# KX transmitted", 1401 "# KX transmitted",
1392 1, 1402 1,
1393 GNUNET_NO); 1403 GNUNET_NO);
1394} 1404}
1395 1405
1396 1406
@@ -1405,10 +1415,10 @@ send_kx(struct CadetTunnel *t,
1405 * (set if we would like to transmit right now, but cannot) 1415 * (set if we would like to transmit right now, but cannot)
1406 */ 1416 */
1407static void 1417static void
1408send_kx_auth(struct CadetTunnel *t, 1418send_kx_auth (struct CadetTunnel *t,
1409 struct CadetTConnection *ct, 1419 struct CadetTConnection *ct,
1410 struct CadetTunnelAxolotl *ax, 1420 struct CadetTunnelAxolotl *ax,
1411 int force_reply) 1421 int force_reply)
1412{ 1422{
1413 struct CadetConnection *cc; 1423 struct CadetConnection *cc;
1414 struct GNUNET_MQ_Envelope *env; 1424 struct GNUNET_MQ_Envelope *env;
@@ -1417,64 +1427,64 @@ send_kx_auth(struct CadetTunnel *t,
1417 1427
1418 if ((NULL == ct) || 1428 if ((NULL == ct) ||
1419 (GNUNET_NO == ct->is_ready)) 1429 (GNUNET_NO == ct->is_ready))
1420 ct = get_ready_connection(t); 1430 ct = get_ready_connection (t);
1421 if (NULL == ct) 1431 if (NULL == ct)
1422 { 1432 {
1423 LOG(GNUNET_ERROR_TYPE_DEBUG, 1433 LOG (GNUNET_ERROR_TYPE_DEBUG,
1424 "Wanted to send KX_AUTH on %s, but no connection is ready, deferring\n", 1434 "Wanted to send KX_AUTH on %s, but no connection is ready, deferring\n",
1425 GCT_2s(t)); 1435 GCT_2s (t));
1426 t->next_kx_attempt = GNUNET_TIME_absolute_get(); 1436 t->next_kx_attempt = GNUNET_TIME_absolute_get ();
1427 t->kx_auth_requested = GNUNET_YES; /* queue KX_AUTH independent of estate */ 1437 t->kx_auth_requested = GNUNET_YES; /* queue KX_AUTH independent of estate */
1428 return; 1438 return;
1429 } 1439 }
1430 t->kx_auth_requested = GNUNET_NO; /* clear flag */ 1440 t->kx_auth_requested = GNUNET_NO; /* clear flag */
1431 cc = ct->cc; 1441 cc = ct->cc;
1432 env = GNUNET_MQ_msg(msg, 1442 env = GNUNET_MQ_msg (msg,
1433 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH); 1443 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH);
1434 flags = GNUNET_CADET_KX_FLAG_NONE; 1444 flags = GNUNET_CADET_KX_FLAG_NONE;
1435 if (GNUNET_YES == force_reply) 1445 if (GNUNET_YES == force_reply)
1436 flags |= GNUNET_CADET_KX_FLAG_FORCE_REPLY; 1446 flags |= GNUNET_CADET_KX_FLAG_FORCE_REPLY;
1437 msg->kx.flags = htonl(flags); 1447 msg->kx.flags = htonl (flags);
1438 msg->kx.cid = *GCC_get_id(cc); 1448 msg->kx.cid = *GCC_get_id (cc);
1439 GNUNET_CRYPTO_ecdhe_key_get_public(&ax->kx_0, 1449 GNUNET_CRYPTO_ecdhe_key_get_public (&ax->kx_0,
1440 &msg->kx.ephemeral_key); 1450 &msg->kx.ephemeral_key);
1441 GNUNET_CRYPTO_ecdhe_key_get_public(&ax->DHRs, 1451 GNUNET_CRYPTO_ecdhe_key_get_public (&ax->DHRs,
1442 &msg->kx.ratchet_key); 1452 &msg->kx.ratchet_key);
1443#if DEBUG_KX 1453#if DEBUG_KX
1444 msg->kx.ephemeral_key_XXX = ax->kx_0; 1454 msg->kx.ephemeral_key_XXX = ax->kx_0;
1445 msg->kx.private_key_XXX = *my_private_key; 1455 msg->kx.private_key_XXX = *my_private_key;
1446 msg->r_ephemeral_key_XXX = ax->last_ephemeral; 1456 msg->r_ephemeral_key_XXX = ax->last_ephemeral;
1447#endif 1457#endif
1448 LOG(GNUNET_ERROR_TYPE_DEBUG, 1458 LOG (GNUNET_ERROR_TYPE_DEBUG,
1449 "Sending KX_AUTH message to %s with ephemeral %s on CID %s\n", 1459 "Sending KX_AUTH message to %s with ephemeral %s on CID %s\n",
1450 GCT_2s(t), 1460 GCT_2s (t),
1451 GNUNET_e2s(&msg->kx.ephemeral_key), 1461 GNUNET_e2s (&msg->kx.ephemeral_key),
1452 GNUNET_sh2s(&msg->kx.cid.connection_of_tunnel)); 1462 GNUNET_sh2s (&msg->kx.cid.connection_of_tunnel));
1453 1463
1454 /* Compute authenticator (this is the main difference to #send_kx()) */ 1464 /* Compute authenticator (this is the main difference to #send_kx()) */
1455 GNUNET_CRYPTO_hash(&ax->RK, 1465 GNUNET_CRYPTO_hash (&ax->RK,
1456 sizeof(ax->RK), 1466 sizeof(ax->RK),
1457 &msg->auth); 1467 &msg->auth);
1458 /* Compute when to be triggered again; actual job will 1468 /* Compute when to be triggered again; actual job will
1459 be scheduled via #connection_ready_cb() */ 1469 be scheduled via #connection_ready_cb() */
1460 t->kx_retry_delay 1470 t->kx_retry_delay
1461 = GNUNET_TIME_STD_BACKOFF(t->kx_retry_delay); 1471 = GNUNET_TIME_STD_BACKOFF (t->kx_retry_delay);
1462 t->next_kx_attempt 1472 t->next_kx_attempt
1463 = GNUNET_TIME_relative_to_absolute(t->kx_retry_delay); 1473 = GNUNET_TIME_relative_to_absolute (t->kx_retry_delay);
1464 1474
1465 /* Send via cc, mark it as unready */ 1475 /* Send via cc, mark it as unready */
1466 mark_connection_unready(ct); 1476 mark_connection_unready (ct);
1467 1477
1468 /* Update state machine, unless we are already OK */ 1478 /* Update state machine, unless we are already OK */
1469 if (CADET_TUNNEL_KEY_OK != t->estate) 1479 if (CADET_TUNNEL_KEY_OK != t->estate)
1470 GCT_change_estate(t, 1480 GCT_change_estate (t,
1471 CADET_TUNNEL_KEY_AX_AUTH_SENT); 1481 CADET_TUNNEL_KEY_AX_AUTH_SENT);
1472 GCC_transmit(cc, 1482 GCC_transmit (cc,
1473 env); 1483 env);
1474 GNUNET_STATISTICS_update(stats, 1484 GNUNET_STATISTICS_update (stats,
1475 "# KX_AUTH transmitted", 1485 "# KX_AUTH transmitted",
1476 1, 1486 1,
1477 GNUNET_NO); 1487 GNUNET_NO);
1478} 1488}
1479 1489
1480 1490
@@ -1484,14 +1494,14 @@ send_kx_auth(struct CadetTunnel *t,
1484 * @param ax state to free, but not memory of @a ax itself 1494 * @param ax state to free, but not memory of @a ax itself
1485 */ 1495 */
1486static void 1496static void
1487cleanup_ax(struct CadetTunnelAxolotl *ax) 1497cleanup_ax (struct CadetTunnelAxolotl *ax)
1488{ 1498{
1489 while (NULL != ax->skipped_head) 1499 while (NULL != ax->skipped_head)
1490 delete_skipped_key(ax, 1500 delete_skipped_key (ax,
1491 ax->skipped_head); 1501 ax->skipped_head);
1492 GNUNET_assert(0 == ax->skipped); 1502 GNUNET_assert (0 == ax->skipped);
1493 GNUNET_CRYPTO_ecdhe_key_clear(&ax->kx_0); 1503 GNUNET_CRYPTO_ecdhe_key_clear (&ax->kx_0);
1494 GNUNET_CRYPTO_ecdhe_key_clear(&ax->DHRs); 1504 GNUNET_CRYPTO_ecdhe_key_clear (&ax->DHRs);
1495} 1505}
1496 1506
1497 1507
@@ -1509,105 +1519,105 @@ cleanup_ax(struct CadetTunnelAxolotl *ax)
1509 * #GNUNET_SYSERR on hard errors (i.e. @a pid is #my_full_id) 1519 * #GNUNET_SYSERR on hard errors (i.e. @a pid is #my_full_id)
1510 */ 1520 */
1511static int 1521static int
1512update_ax_by_kx(struct CadetTunnelAxolotl *ax, 1522update_ax_by_kx (struct CadetTunnelAxolotl *ax,
1513 const struct GNUNET_PeerIdentity *pid, 1523 const struct GNUNET_PeerIdentity *pid,
1514 const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral_key, 1524 const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral_key,
1515 const struct GNUNET_CRYPTO_EcdhePublicKey *ratchet_key) 1525 const struct GNUNET_CRYPTO_EcdhePublicKey *ratchet_key)
1516{ 1526{
1517 struct GNUNET_HashCode key_material[3]; 1527 struct GNUNET_HashCode key_material[3];
1518 struct GNUNET_CRYPTO_SymmetricSessionKey keys[5]; 1528 struct GNUNET_CRYPTO_SymmetricSessionKey keys[5];
1519 const char salt[] = "CADET Axolotl salt"; 1529 const char salt[] = "CADET Axolotl salt";
1520 int am_I_alice; 1530 int am_I_alice;
1521 1531
1522 if (GNUNET_SYSERR == (am_I_alice = alice_or_betty(pid))) 1532 if (GNUNET_SYSERR == (am_I_alice = alice_or_betty (pid)))
1523 { 1533 {
1524 GNUNET_break_op(0); 1534 GNUNET_break_op (0);
1525 return GNUNET_SYSERR; 1535 return GNUNET_SYSERR;
1526 } 1536 }
1527 if (0 == GNUNET_memcmp(&ax->DHRr, 1537 if (0 == GNUNET_memcmp (&ax->DHRr,
1528 ratchet_key)) 1538 ratchet_key))
1529 { 1539 {
1530 GNUNET_STATISTICS_update(stats, 1540 GNUNET_STATISTICS_update (stats,
1531 "# Ratchet key already known", 1541 "# Ratchet key already known",
1532 1, 1542 1,
1533 GNUNET_NO); 1543 GNUNET_NO);
1534 LOG(GNUNET_ERROR_TYPE_DEBUG, 1544 LOG (GNUNET_ERROR_TYPE_DEBUG,
1535 "Ratchet key already known. Ignoring KX.\n"); 1545 "Ratchet key already known. Ignoring KX.\n");
1536 return GNUNET_NO; 1546 return GNUNET_NO;
1537 } 1547 }
1538 1548
1539 ax->DHRr = *ratchet_key; 1549 ax->DHRr = *ratchet_key;
1540 ax->last_ephemeral = *ephemeral_key; 1550 ax->last_ephemeral = *ephemeral_key;
1541 /* ECDH A B0 */ 1551 /* ECDH A B0 */
1542 if (GNUNET_YES == am_I_alice) 1552 if (GNUNET_YES == am_I_alice)
1543 { 1553 {
1544 GNUNET_CRYPTO_eddsa_ecdh(my_private_key, /* a */ 1554 GNUNET_CRYPTO_eddsa_ecdh (my_private_key, /* a */
1545 ephemeral_key, /* B0 */ 1555 ephemeral_key, /* B0 */
1546 &key_material[0]); 1556 &key_material[0]);
1547 } 1557 }
1548 else 1558 else
1549 { 1559 {
1550 GNUNET_CRYPTO_ecdh_eddsa(&ax->kx_0, /* b0 */ 1560 GNUNET_CRYPTO_ecdh_eddsa (&ax->kx_0, /* b0 */
1551 &pid->public_key, /* A */ 1561 &pid->public_key, /* A */
1552 &key_material[0]); 1562 &key_material[0]);
1553 } 1563 }
1554 /* ECDH A0 B */ 1564 /* ECDH A0 B */
1555 if (GNUNET_YES == am_I_alice) 1565 if (GNUNET_YES == am_I_alice)
1556 { 1566 {
1557 GNUNET_CRYPTO_ecdh_eddsa(&ax->kx_0, /* a0 */ 1567 GNUNET_CRYPTO_ecdh_eddsa (&ax->kx_0, /* a0 */
1558 &pid->public_key, /* B */ 1568 &pid->public_key, /* B */
1559 &key_material[1]); 1569 &key_material[1]);
1560 } 1570 }
1561 else 1571 else
1562 { 1572 {
1563 GNUNET_CRYPTO_eddsa_ecdh(my_private_key, /* b */ 1573 GNUNET_CRYPTO_eddsa_ecdh (my_private_key, /* b */
1564 ephemeral_key, /* A0 */ 1574 ephemeral_key, /* A0 */
1565 &key_material[1]); 1575 &key_material[1]);
1566 } 1576 }
1567 1577
1568 /* ECDH A0 B0 */ 1578 /* ECDH A0 B0 */
1569 GNUNET_CRYPTO_ecc_ecdh(&ax->kx_0, /* a0 or b0 */ 1579 GNUNET_CRYPTO_ecc_ecdh (&ax->kx_0, /* a0 or b0 */
1570 ephemeral_key, /* B0 or A0 */ 1580 ephemeral_key, /* B0 or A0 */
1571 &key_material[2]); 1581 &key_material[2]);
1572 /* KDF */ 1582 /* KDF */
1573 GNUNET_CRYPTO_kdf(keys, sizeof(keys), 1583 GNUNET_CRYPTO_kdf (keys, sizeof(keys),
1574 salt, sizeof(salt), 1584 salt, sizeof(salt),
1575 &key_material, sizeof(key_material), 1585 &key_material, sizeof(key_material),
1576 NULL); 1586 NULL);
1577 1587
1578 if (0 == memcmp(&ax->RK, 1588 if (0 == memcmp (&ax->RK,
1579 &keys[0], 1589 &keys[0],
1580 sizeof(ax->RK))) 1590 sizeof(ax->RK)))
1581 { 1591 {
1582 LOG(GNUNET_ERROR_TYPE_DEBUG, 1592 LOG (GNUNET_ERROR_TYPE_DEBUG,
1583 "Root key already known. Ignoring KX.\n"); 1593 "Root key already known. Ignoring KX.\n");
1584 GNUNET_STATISTICS_update(stats, 1594 GNUNET_STATISTICS_update (stats,
1585 "# Root key already known", 1595 "# Root key already known",
1586 1, 1596 1,
1587 GNUNET_NO); 1597 GNUNET_NO);
1588 return GNUNET_NO; 1598 return GNUNET_NO;
1589 } 1599 }
1590 1600
1591 ax->RK = keys[0]; 1601 ax->RK = keys[0];
1592 if (GNUNET_YES == am_I_alice) 1602 if (GNUNET_YES == am_I_alice)
1593 { 1603 {
1594 ax->HKr = keys[1]; 1604 ax->HKr = keys[1];
1595 ax->NHKs = keys[2]; 1605 ax->NHKs = keys[2];
1596 ax->NHKr = keys[3]; 1606 ax->NHKr = keys[3];
1597 ax->CKr = keys[4]; 1607 ax->CKr = keys[4];
1598 ax->ratchet_flag = GNUNET_YES; 1608 ax->ratchet_flag = GNUNET_YES;
1599 } 1609 }
1600 else 1610 else
1601 { 1611 {
1602 ax->HKs = keys[1]; 1612 ax->HKs = keys[1];
1603 ax->NHKr = keys[2]; 1613 ax->NHKr = keys[2];
1604 ax->NHKs = keys[3]; 1614 ax->NHKs = keys[3];
1605 ax->CKs = keys[4]; 1615 ax->CKs = keys[4];
1606 ax->ratchet_flag = GNUNET_NO; 1616 ax->ratchet_flag = GNUNET_NO;
1607 ax->ratchet_expiration 1617 ax->ratchet_expiration
1608 = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), 1618 = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1609 ratchet_time); 1619 ratchet_time);
1610 } 1620 }
1611 return GNUNET_OK; 1621 return GNUNET_OK;
1612} 1622}
1613 1623
@@ -1618,89 +1628,89 @@ update_ax_by_kx(struct CadetTunnelAxolotl *ax,
1618 * @param cls the `struct CadetTunnel` to do KX for. 1628 * @param cls the `struct CadetTunnel` to do KX for.
1619 */ 1629 */
1620static void 1630static void
1621retry_kx(void *cls) 1631retry_kx (void *cls)
1622{ 1632{
1623 struct CadetTunnel *t = cls; 1633 struct CadetTunnel *t = cls;
1624 struct CadetTunnelAxolotl *ax; 1634 struct CadetTunnelAxolotl *ax;
1625 1635
1626 t->kx_task = NULL; 1636 t->kx_task = NULL;
1627 LOG(GNUNET_ERROR_TYPE_DEBUG, 1637 LOG (GNUNET_ERROR_TYPE_DEBUG,
1628 "Trying to make KX progress on %s in state %s\n", 1638 "Trying to make KX progress on %s in state %s\n",
1629 GCT_2s(t), 1639 GCT_2s (t),
1630 estate2s(t->estate)); 1640 estate2s (t->estate));
1631 switch (t->estate) 1641 switch (t->estate)
1632 { 1642 {
1633 case CADET_TUNNEL_KEY_UNINITIALIZED: /* first attempt */ 1643 case CADET_TUNNEL_KEY_UNINITIALIZED: /* first attempt */
1634 case CADET_TUNNEL_KEY_AX_SENT: /* trying again */ 1644 case CADET_TUNNEL_KEY_AX_SENT: /* trying again */
1635 send_kx(t, 1645 send_kx (t,
1636 NULL, 1646 NULL,
1637 &t->ax); 1647 &t->ax);
1638 break; 1648 break;
1639 1649
1640 case CADET_TUNNEL_KEY_AX_RECV: 1650 case CADET_TUNNEL_KEY_AX_RECV:
1641 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV: 1651 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
1642 /* We are responding, so only require reply 1652 /* We are responding, so only require reply
1643 if WE have a channel waiting. */ 1653 if WE have a channel waiting. */
1644 if (NULL != t->unverified_ax) 1654 if (NULL != t->unverified_ax)
1645 { 1655 {
1646 /* Send AX_AUTH so we might get this one verified */ 1656 /* Send AX_AUTH so we might get this one verified */
1647 ax = t->unverified_ax; 1657 ax = t->unverified_ax;
1648 } 1658 }
1649 else 1659 else
1650 { 1660 {
1651 /* How can this be? */ 1661 /* How can this be? */
1652 GNUNET_break(0); 1662 GNUNET_break (0);
1653 ax = &t->ax; 1663 ax = &t->ax;
1654 } 1664 }
1655 send_kx_auth(t, 1665 send_kx_auth (t,
1656 NULL, 1666 NULL,
1657 ax, 1667 ax,
1658 (0 == GCT_count_channels(t)) 1668 (0 == GCT_count_channels (t))
1659 ? GNUNET_NO 1669 ? GNUNET_NO
1660 : GNUNET_YES); 1670 : GNUNET_YES);
1661 break; 1671 break;
1662 1672
1663 case CADET_TUNNEL_KEY_AX_AUTH_SENT: 1673 case CADET_TUNNEL_KEY_AX_AUTH_SENT:
1664 /* We are responding, so only require reply 1674 /* We are responding, so only require reply
1665 if WE have a channel waiting. */ 1675 if WE have a channel waiting. */
1666 if (NULL != t->unverified_ax) 1676 if (NULL != t->unverified_ax)
1667 { 1677 {
1668 /* Send AX_AUTH so we might get this one verified */ 1678 /* Send AX_AUTH so we might get this one verified */
1669 ax = t->unverified_ax; 1679 ax = t->unverified_ax;
1670 } 1680 }
1671 else 1681 else
1672 { 1682 {
1673 /* How can this be? */ 1683 /* How can this be? */
1674 GNUNET_break(0); 1684 GNUNET_break (0);
1675 ax = &t->ax; 1685 ax = &t->ax;
1676 } 1686 }
1677 send_kx_auth(t, 1687 send_kx_auth (t,
1678 NULL, 1688 NULL,
1679 ax, 1689 ax,
1680 (0 == GCT_count_channels(t)) 1690 (0 == GCT_count_channels (t))
1681 ? GNUNET_NO 1691 ? GNUNET_NO
1682 : GNUNET_YES); 1692 : GNUNET_YES);
1683 break; 1693 break;
1684 1694
1685 case CADET_TUNNEL_KEY_OK: 1695 case CADET_TUNNEL_KEY_OK:
1686 /* Must have been the *other* peer asking us to 1696 /* Must have been the *other* peer asking us to
1687 respond with a KX_AUTH. */ 1697 respond with a KX_AUTH. */
1688 if (NULL != t->unverified_ax) 1698 if (NULL != t->unverified_ax)
1689 { 1699 {
1690 /* Sending AX_AUTH in response to AX so we might get this one verified */ 1700 /* Sending AX_AUTH in response to AX so we might get this one verified */
1691 ax = t->unverified_ax; 1701 ax = t->unverified_ax;
1692 }
1693 else
1694 {
1695 /* Sending AX_AUTH in response to AX_AUTH */
1696 ax = &t->ax;
1697 }
1698 send_kx_auth(t,
1699 NULL,
1700 ax,
1701 GNUNET_NO);
1702 break;
1703 } 1702 }
1703 else
1704 {
1705 /* Sending AX_AUTH in response to AX_AUTH */
1706 ax = &t->ax;
1707 }
1708 send_kx_auth (t,
1709 NULL,
1710 ax,
1711 GNUNET_NO);
1712 break;
1713 }
1704} 1714}
1705 1715
1706 1716
@@ -1713,98 +1723,98 @@ retry_kx(void *cls)
1713 * @param msg the key exchange message 1723 * @param msg the key exchange message
1714 */ 1724 */
1715void 1725void
1716GCT_handle_kx(struct CadetTConnection *ct, 1726GCT_handle_kx (struct CadetTConnection *ct,
1717 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) 1727 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
1718{ 1728{
1719 struct CadetTunnel *t = ct->t; 1729 struct CadetTunnel *t = ct->t;
1720 int ret; 1730 int ret;
1721 1731
1722 GNUNET_STATISTICS_update(stats, 1732 GNUNET_STATISTICS_update (stats,
1723 "# KX received", 1733 "# KX received",
1724 1, 1734 1,
1725 GNUNET_NO); 1735 GNUNET_NO);
1726 if (GNUNET_YES == 1736 if (GNUNET_YES ==
1727 alice_or_betty(GCP_get_id(t->destination))) 1737 alice_or_betty (GCP_get_id (t->destination)))
1728 { 1738 {
1729 /* Betty/Bob is not allowed to send KX! */ 1739 /* Betty/Bob is not allowed to send KX! */
1730 GNUNET_break_op(0); 1740 GNUNET_break_op (0);
1731 return; 1741 return;
1732 } 1742 }
1733 LOG(GNUNET_ERROR_TYPE_DEBUG, 1743 LOG (GNUNET_ERROR_TYPE_DEBUG,
1734 "Received KX message from %s with ephemeral %s from %s on connection %s\n", 1744 "Received KX message from %s with ephemeral %s from %s on connection %s\n",
1735 GCT_2s(t), 1745 GCT_2s (t),
1736 GNUNET_e2s(&msg->ephemeral_key), 1746 GNUNET_e2s (&msg->ephemeral_key),
1737 GNUNET_i2s(GCP_get_id(t->destination)), 1747 GNUNET_i2s (GCP_get_id (t->destination)),
1738 GCC_2s(ct->cc)); 1748 GCC_2s (ct->cc));
1739#if 1 1749#if 1
1740 if ((0 == 1750 if ((0 ==
1741 memcmp(&t->ax.DHRr, 1751 memcmp (&t->ax.DHRr,
1742 &msg->ratchet_key, 1752 &msg->ratchet_key,
1743 sizeof(msg->ratchet_key))) && 1753 sizeof(msg->ratchet_key))) &&
1744 (0 == 1754 (0 ==
1745 memcmp(&t->ax.last_ephemeral, 1755 memcmp (&t->ax.last_ephemeral,
1746 &msg->ephemeral_key, 1756 &msg->ephemeral_key,
1747 sizeof(msg->ephemeral_key)))) 1757 sizeof(msg->ephemeral_key))))
1748 1758
1749 { 1759 {
1750 GNUNET_STATISTICS_update(stats, 1760 GNUNET_STATISTICS_update (stats,
1751 "# Duplicate KX received", 1761 "# Duplicate KX received",
1752 1, 1762 1,
1753 GNUNET_NO); 1763 GNUNET_NO);
1754 send_kx_auth(t, 1764 send_kx_auth (t,
1755 ct, 1765 ct,
1756 &t->ax, 1766 &t->ax,
1757 GNUNET_NO); 1767 GNUNET_NO);
1758 return; 1768 return;
1759 } 1769 }
1760#endif 1770#endif
1761 /* We only keep ONE unverified KX around, so if there is an existing one, 1771 /* We only keep ONE unverified KX around, so if there is an existing one,
1762 clean it up. */ 1772 clean it up. */
1763 if (NULL != t->unverified_ax) 1773 if (NULL != t->unverified_ax)
1764 { 1774 {
1765 if ((0 == 1775 if ((0 ==
1766 memcmp(&t->unverified_ax->DHRr, 1776 memcmp (&t->unverified_ax->DHRr,
1767 &msg->ratchet_key, 1777 &msg->ratchet_key,
1768 sizeof(msg->ratchet_key))) && 1778 sizeof(msg->ratchet_key))) &&
1769 (0 == 1779 (0 ==
1770 memcmp(&t->unverified_ax->last_ephemeral, 1780 memcmp (&t->unverified_ax->last_ephemeral,
1771 &msg->ephemeral_key, 1781 &msg->ephemeral_key,
1772 sizeof(msg->ephemeral_key)))) 1782 sizeof(msg->ephemeral_key))))
1773 { 1783 {
1774 GNUNET_STATISTICS_update(stats, 1784 GNUNET_STATISTICS_update (stats,
1775 "# Duplicate unverified KX received", 1785 "# Duplicate unverified KX received",
1776 1, 1786 1,
1777 GNUNET_NO); 1787 GNUNET_NO);
1778#if 1 1788#if 1
1779 send_kx_auth(t, 1789 send_kx_auth (t,
1780 ct, 1790 ct,
1781 t->unverified_ax, 1791 t->unverified_ax,
1782 GNUNET_NO); 1792 GNUNET_NO);
1783 return; 1793 return;
1784#endif 1794#endif
1785 }
1786 LOG(GNUNET_ERROR_TYPE_DEBUG,
1787 "Dropping old unverified KX state.\n");
1788 GNUNET_STATISTICS_update(stats,
1789 "# Unverified KX dropped for fresh KX",
1790 1,
1791 GNUNET_NO);
1792 GNUNET_break(NULL == t->unverified_ax->skipped_head);
1793 memset(t->unverified_ax,
1794 0,
1795 sizeof(struct CadetTunnelAxolotl));
1796 } 1795 }
1796 LOG (GNUNET_ERROR_TYPE_DEBUG,
1797 "Dropping old unverified KX state.\n");
1798 GNUNET_STATISTICS_update (stats,
1799 "# Unverified KX dropped for fresh KX",
1800 1,
1801 GNUNET_NO);
1802 GNUNET_break (NULL == t->unverified_ax->skipped_head);
1803 memset (t->unverified_ax,
1804 0,
1805 sizeof(struct CadetTunnelAxolotl));
1806 }
1797 else 1807 else
1798 { 1808 {
1799 LOG(GNUNET_ERROR_TYPE_DEBUG, 1809 LOG (GNUNET_ERROR_TYPE_DEBUG,
1800 "Creating fresh unverified KX for %s\n", 1810 "Creating fresh unverified KX for %s\n",
1801 GCT_2s(t)); 1811 GCT_2s (t));
1802 GNUNET_STATISTICS_update(stats, 1812 GNUNET_STATISTICS_update (stats,
1803 "# Fresh KX setup", 1813 "# Fresh KX setup",
1804 1, 1814 1,
1805 GNUNET_NO); 1815 GNUNET_NO);
1806 t->unverified_ax = GNUNET_new(struct CadetTunnelAxolotl); 1816 t->unverified_ax = GNUNET_new (struct CadetTunnelAxolotl);
1807 } 1817 }
1808 /* Set as the 'current' RK/DHRr the one we are currently using, 1818 /* Set as the 'current' RK/DHRr the one we are currently using,
1809 so that the duplicate-detection logic of 1819 so that the duplicate-detection logic of
1810 #update_ax_by_kx can work. */ 1820 #update_ax_by_kx can work. */
@@ -1815,101 +1825,101 @@ GCT_handle_kx(struct CadetTConnection *ct,
1815 t->unverified_attempts = 0; 1825 t->unverified_attempts = 0;
1816 1826
1817 /* Update 'ax' by the new key material */ 1827 /* Update 'ax' by the new key material */
1818 ret = update_ax_by_kx(t->unverified_ax, 1828 ret = update_ax_by_kx (t->unverified_ax,
1819 GCP_get_id(t->destination), 1829 GCP_get_id (t->destination),
1820 &msg->ephemeral_key, 1830 &msg->ephemeral_key,
1821 &msg->ratchet_key); 1831 &msg->ratchet_key);
1822 GNUNET_break(GNUNET_SYSERR != ret); 1832 GNUNET_break (GNUNET_SYSERR != ret);
1823 if (GNUNET_OK != ret) 1833 if (GNUNET_OK != ret)
1824 { 1834 {
1825 GNUNET_STATISTICS_update(stats, 1835 GNUNET_STATISTICS_update (stats,
1826 "# Useless KX", 1836 "# Useless KX",
1827 1, 1837 1,
1828 GNUNET_NO); 1838 GNUNET_NO);
1829 return; /* duplicate KX, nothing to do */ 1839 return; /* duplicate KX, nothing to do */
1830 } 1840 }
1831 /* move ahead in our state machine */ 1841 /* move ahead in our state machine */
1832 if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) 1842 if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate)
1833 GCT_change_estate(t, 1843 GCT_change_estate (t,
1834 CADET_TUNNEL_KEY_AX_RECV); 1844 CADET_TUNNEL_KEY_AX_RECV);
1835 else if (CADET_TUNNEL_KEY_AX_SENT == t->estate) 1845 else if (CADET_TUNNEL_KEY_AX_SENT == t->estate)
1836 GCT_change_estate(t, 1846 GCT_change_estate (t,
1837 CADET_TUNNEL_KEY_AX_SENT_AND_RECV); 1847 CADET_TUNNEL_KEY_AX_SENT_AND_RECV);
1838 1848
1839 /* KX is still not done, try again our end. */ 1849 /* KX is still not done, try again our end. */
1840 if (CADET_TUNNEL_KEY_OK != t->estate) 1850 if (CADET_TUNNEL_KEY_OK != t->estate)
1841 { 1851 {
1842 if (NULL != t->kx_task) 1852 if (NULL != t->kx_task)
1843 GNUNET_SCHEDULER_cancel(t->kx_task); 1853 GNUNET_SCHEDULER_cancel (t->kx_task);
1844 t->kx_task 1854 t->kx_task
1845 = GNUNET_SCHEDULER_add_now(&retry_kx, 1855 = GNUNET_SCHEDULER_add_now (&retry_kx,
1846 t); 1856 t);
1847 } 1857 }
1848} 1858}
1849 1859
1850 1860
1851#if DEBUG_KX 1861#if DEBUG_KX
1852static void 1862static void
1853check_ee(const struct GNUNET_CRYPTO_EcdhePrivateKey *e1, 1863check_ee (const struct GNUNET_CRYPTO_EcdhePrivateKey *e1,
1854 const struct GNUNET_CRYPTO_EcdhePrivateKey *e2) 1864 const struct GNUNET_CRYPTO_EcdhePrivateKey *e2)
1855{ 1865{
1856 struct GNUNET_CRYPTO_EcdhePublicKey p1; 1866 struct GNUNET_CRYPTO_EcdhePublicKey p1;
1857 struct GNUNET_CRYPTO_EcdhePublicKey p2; 1867 struct GNUNET_CRYPTO_EcdhePublicKey p2;
1858 struct GNUNET_HashCode hc1; 1868 struct GNUNET_HashCode hc1;
1859 struct GNUNET_HashCode hc2; 1869 struct GNUNET_HashCode hc2;
1860 1870
1861 GNUNET_CRYPTO_ecdhe_key_get_public(e1, 1871 GNUNET_CRYPTO_ecdhe_key_get_public (e1,
1862 &p1); 1872 &p1);
1863 GNUNET_CRYPTO_ecdhe_key_get_public(e2, 1873 GNUNET_CRYPTO_ecdhe_key_get_public (e2,
1864 &p2); 1874 &p2);
1865 GNUNET_assert(GNUNET_OK == 1875 GNUNET_assert (GNUNET_OK ==
1866 GNUNET_CRYPTO_ecc_ecdh(e1, 1876 GNUNET_CRYPTO_ecc_ecdh (e1,
1867 &p2, 1877 &p2,
1868 &hc1)); 1878 &hc1));
1869 GNUNET_assert(GNUNET_OK == 1879 GNUNET_assert (GNUNET_OK ==
1870 GNUNET_CRYPTO_ecc_ecdh(e2, 1880 GNUNET_CRYPTO_ecc_ecdh (e2,
1871 &p1, 1881 &p1,
1872 &hc2)); 1882 &hc2));
1873 GNUNET_break(0 == GNUNET_memcmp(&hc1, 1883 GNUNET_break (0 == GNUNET_memcmp (&hc1,
1874 &hc2)); 1884 &hc2));
1875} 1885}
1876 1886
1877 1887
1878static void 1888static void
1879check_ed(const struct GNUNET_CRYPTO_EcdhePrivateKey *e1, 1889check_ed (const struct GNUNET_CRYPTO_EcdhePrivateKey *e1,
1880 const struct GNUNET_CRYPTO_EddsaPrivateKey *e2) 1890 const struct GNUNET_CRYPTO_EddsaPrivateKey *e2)
1881{ 1891{
1882 struct GNUNET_CRYPTO_EcdhePublicKey p1; 1892 struct GNUNET_CRYPTO_EcdhePublicKey p1;
1883 struct GNUNET_CRYPTO_EddsaPublicKey p2; 1893 struct GNUNET_CRYPTO_EddsaPublicKey p2;
1884 struct GNUNET_HashCode hc1; 1894 struct GNUNET_HashCode hc1;
1885 struct GNUNET_HashCode hc2; 1895 struct GNUNET_HashCode hc2;
1886 1896
1887 GNUNET_CRYPTO_ecdhe_key_get_public(e1, 1897 GNUNET_CRYPTO_ecdhe_key_get_public (e1,
1888 &p1); 1898 &p1);
1889 GNUNET_CRYPTO_eddsa_key_get_public(e2, 1899 GNUNET_CRYPTO_eddsa_key_get_public (e2,
1890 &p2); 1900 &p2);
1891 GNUNET_assert(GNUNET_OK == 1901 GNUNET_assert (GNUNET_OK ==
1892 GNUNET_CRYPTO_ecdh_eddsa(e1, 1902 GNUNET_CRYPTO_ecdh_eddsa (e1,
1893 &p2, 1903 &p2,
1894 &hc1)); 1904 &hc1));
1895 GNUNET_assert(GNUNET_OK == 1905 GNUNET_assert (GNUNET_OK ==
1896 GNUNET_CRYPTO_eddsa_ecdh(e2, 1906 GNUNET_CRYPTO_eddsa_ecdh (e2,
1897 &p1, 1907 &p1,
1898 &hc2)); 1908 &hc2));
1899 GNUNET_break(0 == GNUNET_memcmp(&hc1, 1909 GNUNET_break (0 == GNUNET_memcmp (&hc1,
1900 &hc2)); 1910 &hc2));
1901} 1911}
1902 1912
1903 1913
1904static void 1914static void
1905test_crypto_bug(const struct GNUNET_CRYPTO_EcdhePrivateKey *e1, 1915test_crypto_bug (const struct GNUNET_CRYPTO_EcdhePrivateKey *e1,
1906 const struct GNUNET_CRYPTO_EcdhePrivateKey *e2, 1916 const struct GNUNET_CRYPTO_EcdhePrivateKey *e2,
1907 const struct GNUNET_CRYPTO_EddsaPrivateKey *d1, 1917 const struct GNUNET_CRYPTO_EddsaPrivateKey *d1,
1908 const struct GNUNET_CRYPTO_EddsaPrivateKey *d2) 1918 const struct GNUNET_CRYPTO_EddsaPrivateKey *d2)
1909{ 1919{
1910 check_ee(e1, e2); 1920 check_ee (e1, e2);
1911 check_ed(e1, d2); 1921 check_ed (e1, d2);
1912 check_ed(e2, d1); 1922 check_ed (e2, d1);
1913} 1923}
1914 1924
1915#endif 1925#endif
@@ -1922,135 +1932,135 @@ test_crypto_bug(const struct GNUNET_CRYPTO_EcdhePrivateKey *e1,
1922 * @param msg the key exchange message 1932 * @param msg the key exchange message
1923 */ 1933 */
1924void 1934void
1925GCT_handle_kx_auth(struct CadetTConnection *ct, 1935GCT_handle_kx_auth (struct CadetTConnection *ct,
1926 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) 1936 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
1927{ 1937{
1928 struct CadetTunnel *t = ct->t; 1938 struct CadetTunnel *t = ct->t;
1929 struct CadetTunnelAxolotl ax_tmp; 1939 struct CadetTunnelAxolotl ax_tmp;
1930 struct GNUNET_HashCode kx_auth; 1940 struct GNUNET_HashCode kx_auth;
1931 int ret; 1941 int ret;
1932 1942
1933 GNUNET_STATISTICS_update(stats, 1943 GNUNET_STATISTICS_update (stats,
1934 "# KX_AUTH received", 1944 "# KX_AUTH received",
1935 1, 1945 1,
1936 GNUNET_NO); 1946 GNUNET_NO);
1937 if ((CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) || 1947 if ((CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) ||
1938 (CADET_TUNNEL_KEY_AX_RECV == t->estate)) 1948 (CADET_TUNNEL_KEY_AX_RECV == t->estate))
1939 { 1949 {
1940 /* Confusing, we got a KX_AUTH before we even send our own 1950 /* Confusing, we got a KX_AUTH before we even send our own
1941 KX. This should not happen. We'll send our own KX ASAP anyway, 1951 KX. This should not happen. We'll send our own KX ASAP anyway,
1942 so let's ignore this here. */ 1952 so let's ignore this here. */
1943 GNUNET_break_op(0); 1953 GNUNET_break_op (0);
1944 return; 1954 return;
1945 } 1955 }
1946 LOG(GNUNET_ERROR_TYPE_DEBUG, 1956 LOG (GNUNET_ERROR_TYPE_DEBUG,
1947 "Handling KX_AUTH message from %s with ephemeral %s\n", 1957 "Handling KX_AUTH message from %s with ephemeral %s\n",
1948 GCT_2s(t), 1958 GCT_2s (t),
1949 GNUNET_e2s(&msg->kx.ephemeral_key)); 1959 GNUNET_e2s (&msg->kx.ephemeral_key));
1950 /* We do everything in ax_tmp until we've checked the authentication 1960 /* We do everything in ax_tmp until we've checked the authentication
1951 so we don't clobber anything we care about by accident. */ 1961 so we don't clobber anything we care about by accident. */
1952 ax_tmp = t->ax; 1962 ax_tmp = t->ax;
1953 1963
1954 /* Update 'ax' by the new key material */ 1964 /* Update 'ax' by the new key material */
1955 ret = update_ax_by_kx(&ax_tmp, 1965 ret = update_ax_by_kx (&ax_tmp,
1956 GCP_get_id(t->destination), 1966 GCP_get_id (t->destination),
1957 &msg->kx.ephemeral_key, 1967 &msg->kx.ephemeral_key,
1958 &msg->kx.ratchet_key); 1968 &msg->kx.ratchet_key);
1959 if (GNUNET_OK != ret) 1969 if (GNUNET_OK != ret)
1970 {
1971 if (GNUNET_NO == ret)
1972 GNUNET_STATISTICS_update (stats,
1973 "# redundant KX_AUTH received",
1974 1,
1975 GNUNET_NO);
1976 else
1977 GNUNET_break (0); /* connect to self!? */
1978 return;
1979 }
1980 GNUNET_CRYPTO_hash (&ax_tmp.RK,
1981 sizeof(ax_tmp.RK),
1982 &kx_auth);
1983 if (0 != GNUNET_memcmp (&kx_auth,
1984 &msg->auth))
1985 {
1986 /* This KX_AUTH is not using the latest KX/KX_AUTH data
1987 we transmitted to the sender, refuse it, try KX again. */
1988 GNUNET_STATISTICS_update (stats,
1989 "# KX_AUTH not using our last KX received (auth failure)",
1990 1,
1991 GNUNET_NO);
1992 LOG (GNUNET_ERROR_TYPE_WARNING,
1993 "KX AUTH mismatch!\n");
1994#if DEBUG_KX
1960 { 1995 {
1961 if (GNUNET_NO == ret) 1996 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
1962 GNUNET_STATISTICS_update(stats, 1997
1963 "# redundant KX_AUTH received", 1998 GNUNET_CRYPTO_ecdhe_key_get_public (&ax_tmp.kx_0,
1964 1, 1999 &ephemeral_key);
1965 GNUNET_NO); 2000 if (0 != GNUNET_memcmp (&ephemeral_key,
2001 &msg->r_ephemeral_key_XXX))
2002 {
2003 LOG (GNUNET_ERROR_TYPE_WARNING,
2004 "My ephemeral is %s!\n",
2005 GNUNET_e2s (&ephemeral_key));
2006 LOG (GNUNET_ERROR_TYPE_WARNING,
2007 "Response is for ephemeral %s!\n",
2008 GNUNET_e2s (&msg->r_ephemeral_key_XXX));
2009 }
1966 else 2010 else
1967 GNUNET_break(0); /* connect to self!? */
1968 return;
1969 }
1970 GNUNET_CRYPTO_hash(&ax_tmp.RK,
1971 sizeof(ax_tmp.RK),
1972 &kx_auth);
1973 if (0 != GNUNET_memcmp(&kx_auth,
1974 &msg->auth))
1975 {
1976 /* This KX_AUTH is not using the latest KX/KX_AUTH data
1977 we transmitted to the sender, refuse it, try KX again. */
1978 GNUNET_STATISTICS_update(stats,
1979 "# KX_AUTH not using our last KX received (auth failure)",
1980 1,
1981 GNUNET_NO);
1982 LOG(GNUNET_ERROR_TYPE_WARNING,
1983 "KX AUTH mismatch!\n");
1984#if DEBUG_KX
1985 { 2011 {
1986 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; 2012 test_crypto_bug (&ax_tmp.kx_0,
1987 2013 &msg->kx.ephemeral_key_XXX,
1988 GNUNET_CRYPTO_ecdhe_key_get_public(&ax_tmp.kx_0, 2014 my_private_key,
1989 &ephemeral_key); 2015 &msg->kx.private_key_XXX);
1990 if (0 != GNUNET_memcmp(&ephemeral_key,
1991 &msg->r_ephemeral_key_XXX))
1992 {
1993 LOG(GNUNET_ERROR_TYPE_WARNING,
1994 "My ephemeral is %s!\n",
1995 GNUNET_e2s(&ephemeral_key));
1996 LOG(GNUNET_ERROR_TYPE_WARNING,
1997 "Response is for ephemeral %s!\n",
1998 GNUNET_e2s(&msg->r_ephemeral_key_XXX));
1999 }
2000 else
2001 {
2002 test_crypto_bug(&ax_tmp.kx_0,
2003 &msg->kx.ephemeral_key_XXX,
2004 my_private_key,
2005 &msg->kx.private_key_XXX);
2006 }
2007 } 2016 }
2008#endif
2009 if (NULL == t->kx_task)
2010 t->kx_task
2011 = GNUNET_SCHEDULER_add_at(t->next_kx_attempt,
2012 &retry_kx,
2013 t);
2014 return;
2015 } 2017 }
2018#endif
2019 if (NULL == t->kx_task)
2020 t->kx_task
2021 = GNUNET_SCHEDULER_add_at (t->next_kx_attempt,
2022 &retry_kx,
2023 t);
2024 return;
2025 }
2016 /* Yep, we're good. */ 2026 /* Yep, we're good. */
2017 t->ax = ax_tmp; 2027 t->ax = ax_tmp;
2018 if (NULL != t->unverified_ax) 2028 if (NULL != t->unverified_ax)
2019 { 2029 {
2020 /* We got some "stale" KX before, drop that. */ 2030 /* We got some "stale" KX before, drop that. */
2021 cleanup_ax(t->unverified_ax); 2031 cleanup_ax (t->unverified_ax);
2022 GNUNET_free(t->unverified_ax); 2032 GNUNET_free (t->unverified_ax);
2023 t->unverified_ax = NULL; 2033 t->unverified_ax = NULL;
2024 } 2034 }
2025 2035
2026 /* move ahead in our state machine */ 2036 /* move ahead in our state machine */
2027 switch (t->estate) 2037 switch (t->estate)
2028 { 2038 {
2029 case CADET_TUNNEL_KEY_UNINITIALIZED: 2039 case CADET_TUNNEL_KEY_UNINITIALIZED:
2030 case CADET_TUNNEL_KEY_AX_RECV: 2040 case CADET_TUNNEL_KEY_AX_RECV:
2031 /* Checked above, this is impossible. */ 2041 /* Checked above, this is impossible. */
2032 GNUNET_assert(0); 2042 GNUNET_assert (0);
2033 break; 2043 break;
2034 2044
2035 case CADET_TUNNEL_KEY_AX_SENT: /* This is the normal case */ 2045 case CADET_TUNNEL_KEY_AX_SENT: /* This is the normal case */
2036 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV: /* both peers started KX */ 2046 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV: /* both peers started KX */
2037 case CADET_TUNNEL_KEY_AX_AUTH_SENT: /* both peers now did KX_AUTH */ 2047 case CADET_TUNNEL_KEY_AX_AUTH_SENT: /* both peers now did KX_AUTH */
2038 GCT_change_estate(t, 2048 GCT_change_estate (t,
2039 CADET_TUNNEL_KEY_OK); 2049 CADET_TUNNEL_KEY_OK);
2040 break; 2050 break;
2041 2051
2042 case CADET_TUNNEL_KEY_OK: 2052 case CADET_TUNNEL_KEY_OK:
2043 /* Did not expect another KX_AUTH, but so what, still acceptable. 2053 /* Did not expect another KX_AUTH, but so what, still acceptable.
2044 Nothing to do here. */ 2054 Nothing to do here. */
2045 break; 2055 break;
2046 } 2056 }
2047 if (0 != (GNUNET_CADET_KX_FLAG_FORCE_REPLY & ntohl(msg->kx.flags))) 2057 if (0 != (GNUNET_CADET_KX_FLAG_FORCE_REPLY & ntohl (msg->kx.flags)))
2048 { 2058 {
2049 send_kx_auth(t, 2059 send_kx_auth (t,
2050 NULL, 2060 NULL,
2051 &t->ax, 2061 &t->ax,
2052 GNUNET_NO); 2062 GNUNET_NO);
2053 } 2063 }
2054} 2064}
2055 2065
2056 2066
@@ -2065,7 +2075,7 @@ GCT_handle_kx_auth(struct CadetTConnection *ct,
2065 * @return unused number that can uniquely identify a channel in the tunnel 2075 * @return unused number that can uniquely identify a channel in the tunnel
2066 */ 2076 */
2067static struct GNUNET_CADET_ChannelTunnelNumber 2077static struct GNUNET_CADET_ChannelTunnelNumber
2068get_next_free_ctn(struct CadetTunnel *t) 2078get_next_free_ctn (struct CadetTunnel *t)
2069{ 2079{
2070#define HIGH_BIT 0x8000000 2080#define HIGH_BIT 0x8000000
2071 struct GNUNET_CADET_ChannelTunnelNumber ret; 2081 struct GNUNET_CADET_ChannelTunnelNumber ret;
@@ -2073,23 +2083,23 @@ get_next_free_ctn(struct CadetTunnel *t)
2073 int cmp; 2083 int cmp;
2074 uint32_t highbit; 2084 uint32_t highbit;
2075 2085
2076 cmp = GNUNET_memcmp(&my_full_id, 2086 cmp = GNUNET_memcmp (&my_full_id,
2077 GCP_get_id(GCT_get_destination(t))); 2087 GCP_get_id (GCT_get_destination (t)));
2078 if (0 < cmp) 2088 if (0 < cmp)
2079 highbit = HIGH_BIT; 2089 highbit = HIGH_BIT;
2080 else if (0 > cmp) 2090 else if (0 > cmp)
2081 highbit = 0; 2091 highbit = 0;
2082 else 2092 else
2083 GNUNET_assert(0); // loopback must never go here! 2093 GNUNET_assert (0); // loopback must never go here!
2084 ctn = ntohl(t->next_ctn.cn); 2094 ctn = ntohl (t->next_ctn.cn);
2085 while (NULL != 2095 while (NULL !=
2086 GNUNET_CONTAINER_multihashmap32_get(t->channels, 2096 GNUNET_CONTAINER_multihashmap32_get (t->channels,
2087 ctn | highbit)) 2097 ctn | highbit))
2088 { 2098 {
2089 ctn = ((ctn + 1) & (~HIGH_BIT)); 2099 ctn = ((ctn + 1) & (~HIGH_BIT));
2090 } 2100 }
2091 t->next_ctn.cn = htonl((ctn + 1) & (~HIGH_BIT)); 2101 t->next_ctn.cn = htonl ((ctn + 1) & (~HIGH_BIT));
2092 ret.cn = htonl(ctn | highbit); 2102 ret.cn = htonl (ctn | highbit);
2093 return ret; 2103 return ret;
2094} 2104}
2095 2105
@@ -2104,53 +2114,53 @@ get_next_free_ctn(struct CadetTunnel *t)
2104 * @return unique number identifying @a ch within @a t 2114 * @return unique number identifying @a ch within @a t
2105 */ 2115 */
2106struct GNUNET_CADET_ChannelTunnelNumber 2116struct GNUNET_CADET_ChannelTunnelNumber
2107GCT_add_channel(struct CadetTunnel *t, 2117GCT_add_channel (struct CadetTunnel *t,
2108 struct CadetChannel *ch) 2118 struct CadetChannel *ch)
2109{ 2119{
2110 struct GNUNET_CADET_ChannelTunnelNumber ctn; 2120 struct GNUNET_CADET_ChannelTunnelNumber ctn;
2111 2121
2112 ctn = get_next_free_ctn(t); 2122 ctn = get_next_free_ctn (t);
2113 if (NULL != t->destroy_task) 2123 if (NULL != t->destroy_task)
2114 { 2124 {
2115 GNUNET_SCHEDULER_cancel(t->destroy_task); 2125 GNUNET_SCHEDULER_cancel (t->destroy_task);
2116 t->destroy_task = NULL; 2126 t->destroy_task = NULL;
2117 } 2127 }
2118 GNUNET_assert(GNUNET_YES == 2128 GNUNET_assert (GNUNET_YES ==
2119 GNUNET_CONTAINER_multihashmap32_put(t->channels, 2129 GNUNET_CONTAINER_multihashmap32_put (t->channels,
2120 ntohl(ctn.cn), 2130 ntohl (ctn.cn),
2121 ch, 2131 ch,
2122 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2132 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2123 LOG(GNUNET_ERROR_TYPE_DEBUG, 2133 LOG (GNUNET_ERROR_TYPE_DEBUG,
2124 "Adding %s to %s\n", 2134 "Adding %s to %s\n",
2125 GCCH_2s(ch), 2135 GCCH_2s (ch),
2126 GCT_2s(t)); 2136 GCT_2s (t));
2127 switch (t->estate) 2137 switch (t->estate)
2128 { 2138 {
2129 case CADET_TUNNEL_KEY_UNINITIALIZED: 2139 case CADET_TUNNEL_KEY_UNINITIALIZED:
2130 /* waiting for connection to start KX */ 2140 /* waiting for connection to start KX */
2131 break; 2141 break;
2132 2142
2133 case CADET_TUNNEL_KEY_AX_RECV: 2143 case CADET_TUNNEL_KEY_AX_RECV:
2134 case CADET_TUNNEL_KEY_AX_SENT: 2144 case CADET_TUNNEL_KEY_AX_SENT:
2135 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV: 2145 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
2136 /* we're currently waiting for KX to complete */ 2146 /* we're currently waiting for KX to complete */
2137 break; 2147 break;
2138 2148
2139 case CADET_TUNNEL_KEY_AX_AUTH_SENT: 2149 case CADET_TUNNEL_KEY_AX_AUTH_SENT:
2140 /* waiting for OTHER peer to send us data, 2150 /* waiting for OTHER peer to send us data,
2141 we might need to prompt more aggressively! */ 2151 we might need to prompt more aggressively! */
2142 if (NULL == t->kx_task) 2152 if (NULL == t->kx_task)
2143 t->kx_task 2153 t->kx_task
2144 = GNUNET_SCHEDULER_add_at(t->next_kx_attempt, 2154 = GNUNET_SCHEDULER_add_at (t->next_kx_attempt,
2145 &retry_kx, 2155 &retry_kx,
2146 t); 2156 t);
2147 break; 2157 break;
2148 2158
2149 case CADET_TUNNEL_KEY_OK: 2159 case CADET_TUNNEL_KEY_OK:
2150 /* We are ready. Tell the new channel that we are up. */ 2160 /* We are ready. Tell the new channel that we are up. */
2151 GCCH_tunnel_up(ch); 2161 GCCH_tunnel_up (ch);
2152 break; 2162 break;
2153 } 2163 }
2154 return ctn; 2164 return ctn;
2155} 2165}
2156 2166
@@ -2162,25 +2172,25 @@ GCT_add_channel(struct CadetTunnel *t,
2162 * @param ct binding of connection to tunnel of the connection that was lost. 2172 * @param ct binding of connection to tunnel of the connection that was lost.
2163 */ 2173 */
2164void 2174void
2165GCT_connection_lost(struct CadetTConnection *ct) 2175GCT_connection_lost (struct CadetTConnection *ct)
2166{ 2176{
2167 struct CadetTunnel *t = ct->t; 2177 struct CadetTunnel *t = ct->t;
2168 2178
2169 if (GNUNET_YES == ct->is_ready) 2179 if (GNUNET_YES == ct->is_ready)
2170 { 2180 {
2171 GNUNET_CONTAINER_DLL_remove(t->connection_ready_head, 2181 GNUNET_CONTAINER_DLL_remove (t->connection_ready_head,
2172 t->connection_ready_tail, 2182 t->connection_ready_tail,
2173 ct); 2183 ct);
2174 t->num_ready_connections--; 2184 t->num_ready_connections--;
2175 } 2185 }
2176 else 2186 else
2177 { 2187 {
2178 GNUNET_CONTAINER_DLL_remove(t->connection_busy_head, 2188 GNUNET_CONTAINER_DLL_remove (t->connection_busy_head,
2179 t->connection_busy_tail, 2189 t->connection_busy_tail,
2180 ct); 2190 ct);
2181 t->num_busy_connections--; 2191 t->num_busy_connections--;
2182 } 2192 }
2183 GNUNET_free(ct); 2193 GNUNET_free (ct);
2184} 2194}
2185 2195
2186 2196
@@ -2191,15 +2201,15 @@ GCT_connection_lost(struct CadetTConnection *ct)
2191 * @param ct connection to clean up 2201 * @param ct connection to clean up
2192 */ 2202 */
2193static void 2203static void
2194destroy_t_connection(void *cls, 2204destroy_t_connection (void *cls,
2195 struct CadetTConnection *ct) 2205 struct CadetTConnection *ct)
2196{ 2206{
2197 struct CadetTunnel *t = cls; 2207 struct CadetTunnel *t = cls;
2198 struct CadetConnection *cc = ct->cc; 2208 struct CadetConnection *cc = ct->cc;
2199 2209
2200 GNUNET_assert(ct->t == t); 2210 GNUNET_assert (ct->t == t);
2201 GCT_connection_lost(ct); 2211 GCT_connection_lost (ct);
2202 GCC_destroy_without_tunnel(cc); 2212 GCC_destroy_without_tunnel (cc);
2203} 2213}
2204 2214
2205 2215
@@ -2209,56 +2219,56 @@ destroy_t_connection(void *cls,
2209 * @param cls the idle tunnel 2219 * @param cls the idle tunnel
2210 */ 2220 */
2211static void 2221static void
2212destroy_tunnel(void *cls) 2222destroy_tunnel (void *cls)
2213{ 2223{
2214 struct CadetTunnel *t = cls; 2224 struct CadetTunnel *t = cls;
2215 struct CadetTunnelQueueEntry *tq; 2225 struct CadetTunnelQueueEntry *tq;
2216 2226
2217 t->destroy_task = NULL; 2227 t->destroy_task = NULL;
2218 LOG(GNUNET_ERROR_TYPE_DEBUG, 2228 LOG (GNUNET_ERROR_TYPE_DEBUG,
2219 "Destroying idle %s\n", 2229 "Destroying idle %s\n",
2220 GCT_2s(t)); 2230 GCT_2s (t));
2221 GNUNET_assert(0 == GCT_count_channels(t)); 2231 GNUNET_assert (0 == GCT_count_channels (t));
2222 GCT_iterate_connections(t, 2232 GCT_iterate_connections (t,
2223 &destroy_t_connection, 2233 &destroy_t_connection,
2224 t); 2234 t);
2225 GNUNET_assert(NULL == t->connection_ready_head); 2235 GNUNET_assert (NULL == t->connection_ready_head);
2226 GNUNET_assert(NULL == t->connection_busy_head); 2236 GNUNET_assert (NULL == t->connection_busy_head);
2227 while (NULL != (tq = t->tq_head)) 2237 while (NULL != (tq = t->tq_head))
2228 { 2238 {
2229 if (NULL != tq->cont) 2239 if (NULL != tq->cont)
2230 tq->cont(tq->cont_cls, 2240 tq->cont (tq->cont_cls,
2231 NULL); 2241 NULL);
2232 GCT_send_cancel(tq); 2242 GCT_send_cancel (tq);
2233 } 2243 }
2234 GCP_drop_tunnel(t->destination, 2244 GCP_drop_tunnel (t->destination,
2235 t); 2245 t);
2236 GNUNET_CONTAINER_multihashmap32_destroy(t->channels); 2246 GNUNET_CONTAINER_multihashmap32_destroy (t->channels);
2237 if (NULL != t->maintain_connections_task) 2247 if (NULL != t->maintain_connections_task)
2238 { 2248 {
2239 GNUNET_SCHEDULER_cancel(t->maintain_connections_task); 2249 GNUNET_SCHEDULER_cancel (t->maintain_connections_task);
2240 t->maintain_connections_task = NULL; 2250 t->maintain_connections_task = NULL;
2241 } 2251 }
2242 if (NULL != t->send_task) 2252 if (NULL != t->send_task)
2243 { 2253 {
2244 GNUNET_SCHEDULER_cancel(t->send_task); 2254 GNUNET_SCHEDULER_cancel (t->send_task);
2245 t->send_task = NULL; 2255 t->send_task = NULL;
2246 } 2256 }
2247 if (NULL != t->kx_task) 2257 if (NULL != t->kx_task)
2248 { 2258 {
2249 GNUNET_SCHEDULER_cancel(t->kx_task); 2259 GNUNET_SCHEDULER_cancel (t->kx_task);
2250 t->kx_task = NULL; 2260 t->kx_task = NULL;
2251 } 2261 }
2252 GNUNET_MST_destroy(t->mst); 2262 GNUNET_MST_destroy (t->mst);
2253 GNUNET_MQ_destroy(t->mq); 2263 GNUNET_MQ_destroy (t->mq);
2254 if (NULL != t->unverified_ax) 2264 if (NULL != t->unverified_ax)
2255 { 2265 {
2256 cleanup_ax(t->unverified_ax); 2266 cleanup_ax (t->unverified_ax);
2257 GNUNET_free(t->unverified_ax); 2267 GNUNET_free (t->unverified_ax);
2258 } 2268 }
2259 cleanup_ax(&t->ax); 2269 cleanup_ax (&t->ax);
2260 GNUNET_assert(NULL == t->destroy_task); 2270 GNUNET_assert (NULL == t->destroy_task);
2261 GNUNET_free(t); 2271 GNUNET_free (t);
2262} 2272}
2263 2273
2264 2274
@@ -2270,27 +2280,27 @@ destroy_tunnel(void *cls)
2270 * @param ctn unique number identifying @a ch within @a t 2280 * @param ctn unique number identifying @a ch within @a t
2271 */ 2281 */
2272void 2282void
2273GCT_remove_channel(struct CadetTunnel *t, 2283GCT_remove_channel (struct CadetTunnel *t,
2274 struct CadetChannel *ch, 2284 struct CadetChannel *ch,
2275 struct GNUNET_CADET_ChannelTunnelNumber ctn) 2285 struct GNUNET_CADET_ChannelTunnelNumber ctn)
2276{ 2286{
2277 LOG(GNUNET_ERROR_TYPE_DEBUG, 2287 LOG (GNUNET_ERROR_TYPE_DEBUG,
2278 "Removing %s from %s\n", 2288 "Removing %s from %s\n",
2279 GCCH_2s(ch), 2289 GCCH_2s (ch),
2280 GCT_2s(t)); 2290 GCT_2s (t));
2281 GNUNET_assert(GNUNET_YES == 2291 GNUNET_assert (GNUNET_YES ==
2282 GNUNET_CONTAINER_multihashmap32_remove(t->channels, 2292 GNUNET_CONTAINER_multihashmap32_remove (t->channels,
2283 ntohl(ctn.cn), 2293 ntohl (ctn.cn),
2284 ch)); 2294 ch));
2285 if ((0 == 2295 if ((0 ==
2286 GCT_count_channels(t)) && 2296 GCT_count_channels (t)) &&
2287 (NULL == t->destroy_task)) 2297 (NULL == t->destroy_task))
2288 { 2298 {
2289 t->destroy_task 2299 t->destroy_task
2290 = GNUNET_SCHEDULER_add_delayed(IDLE_DESTROY_DELAY, 2300 = GNUNET_SCHEDULER_add_delayed (IDLE_DESTROY_DELAY,
2291 &destroy_tunnel, 2301 &destroy_tunnel,
2292 t); 2302 t);
2293 } 2303 }
2294} 2304}
2295 2305
2296 2306
@@ -2303,14 +2313,14 @@ GCT_remove_channel(struct CadetTunnel *t,
2303 * @return #GNUNET_OK (continue to iterate) 2313 * @return #GNUNET_OK (continue to iterate)
2304 */ 2314 */
2305static int 2315static int
2306destroy_remaining_channels(void *cls, 2316destroy_remaining_channels (void *cls,
2307 uint32_t key, 2317 uint32_t key,
2308 void *value) 2318 void *value)
2309{ 2319{
2310 struct CadetChannel *ch = value; 2320 struct CadetChannel *ch = value;
2311 2321
2312 GCCH_handle_remote_destroy(ch, 2322 GCCH_handle_remote_destroy (ch,
2313 NULL); 2323 NULL);
2314 return GNUNET_OK; 2324 return GNUNET_OK;
2315} 2325}
2316 2326
@@ -2321,20 +2331,20 @@ destroy_remaining_channels(void *cls,
2321 * @param t tunnel to destroy 2331 * @param t tunnel to destroy
2322 */ 2332 */
2323void 2333void
2324GCT_destroy_tunnel_now(struct CadetTunnel *t) 2334GCT_destroy_tunnel_now (struct CadetTunnel *t)
2325{ 2335{
2326 GNUNET_assert(GNUNET_YES == shutting_down); 2336 GNUNET_assert (GNUNET_YES == shutting_down);
2327 GNUNET_CONTAINER_multihashmap32_iterate(t->channels, 2337 GNUNET_CONTAINER_multihashmap32_iterate (t->channels,
2328 &destroy_remaining_channels, 2338 &destroy_remaining_channels,
2329 t); 2339 t);
2330 GNUNET_assert(0 == 2340 GNUNET_assert (0 ==
2331 GCT_count_channels(t)); 2341 GCT_count_channels (t));
2332 if (NULL != t->destroy_task) 2342 if (NULL != t->destroy_task)
2333 { 2343 {
2334 GNUNET_SCHEDULER_cancel(t->destroy_task); 2344 GNUNET_SCHEDULER_cancel (t->destroy_task);
2335 t->destroy_task = NULL; 2345 t->destroy_task = NULL;
2336 } 2346 }
2337 destroy_tunnel(t); 2347 destroy_tunnel (t);
2338} 2348}
2339 2349
2340 2350
@@ -2346,40 +2356,40 @@ GCT_destroy_tunnel_now(struct CadetTunnel *t)
2346 * @param ct connection to use for transmission (is ready) 2356 * @param ct connection to use for transmission (is ready)
2347 */ 2357 */
2348static void 2358static void
2349try_send_normal_payload(struct CadetTunnel *t, 2359try_send_normal_payload (struct CadetTunnel *t,
2350 struct CadetTConnection *ct) 2360 struct CadetTConnection *ct)
2351{ 2361{
2352 struct CadetTunnelQueueEntry *tq; 2362 struct CadetTunnelQueueEntry *tq;
2353 2363
2354 GNUNET_assert(GNUNET_YES == ct->is_ready); 2364 GNUNET_assert (GNUNET_YES == ct->is_ready);
2355 tq = t->tq_head; 2365 tq = t->tq_head;
2356 if (NULL == tq) 2366 if (NULL == tq)
2357 { 2367 {
2358 /* no messages pending right now */ 2368 /* no messages pending right now */
2359 LOG(GNUNET_ERROR_TYPE_DEBUG, 2369 LOG (GNUNET_ERROR_TYPE_DEBUG,
2360 "Not sending payload of %s on ready %s (nothing pending)\n", 2370 "Not sending payload of %s on ready %s (nothing pending)\n",
2361 GCT_2s(t), 2371 GCT_2s (t),
2362 GCC_2s(ct->cc)); 2372 GCC_2s (ct->cc));
2363 return; 2373 return;
2364 } 2374 }
2365 /* ready to send message 'tq' on tunnel 'ct' */ 2375 /* ready to send message 'tq' on tunnel 'ct' */
2366 GNUNET_assert(t == tq->t); 2376 GNUNET_assert (t == tq->t);
2367 GNUNET_CONTAINER_DLL_remove(t->tq_head, 2377 GNUNET_CONTAINER_DLL_remove (t->tq_head,
2368 t->tq_tail, 2378 t->tq_tail,
2369 tq); 2379 tq);
2370 if (NULL != tq->cid) 2380 if (NULL != tq->cid)
2371 *tq->cid = *GCC_get_id(ct->cc); 2381 *tq->cid = *GCC_get_id (ct->cc);
2372 mark_connection_unready(ct); 2382 mark_connection_unready (ct);
2373 LOG(GNUNET_ERROR_TYPE_DEBUG, 2383 LOG (GNUNET_ERROR_TYPE_DEBUG,
2374 "Sending payload of %s on %s\n", 2384 "Sending payload of %s on %s\n",
2375 GCT_2s(t), 2385 GCT_2s (t),
2376 GCC_2s(ct->cc)); 2386 GCC_2s (ct->cc));
2377 GCC_transmit(ct->cc, 2387 GCC_transmit (ct->cc,
2378 tq->env); 2388 tq->env);
2379 if (NULL != tq->cont) 2389 if (NULL != tq->cont)
2380 tq->cont(tq->cont_cls, 2390 tq->cont (tq->cont_cls,
2381 GCC_get_id(ct->cc)); 2391 GCC_get_id (ct->cc));
2382 GNUNET_free(tq); 2392 GNUNET_free (tq);
2383} 2393}
2384 2394
2385 2395
@@ -2392,97 +2402,99 @@ try_send_normal_payload(struct CadetTunnel *t,
2392 * #GNUNET_NO if connection are no longer ready 2402 * #GNUNET_NO if connection are no longer ready
2393 */ 2403 */
2394static void 2404static void
2395connection_ready_cb(void *cls, 2405connection_ready_cb (void *cls,
2396 int is_ready) 2406 int is_ready)
2397{ 2407{
2398 struct CadetTConnection *ct = cls; 2408 struct CadetTConnection *ct = cls;
2399 struct CadetTunnel *t = ct->t; 2409 struct CadetTunnel *t = ct->t;
2400 2410
2401 if (GNUNET_NO == is_ready) 2411 if (GNUNET_NO == is_ready)
2402 { 2412 {
2403 LOG(GNUNET_ERROR_TYPE_DEBUG, 2413 LOG (GNUNET_ERROR_TYPE_DEBUG,
2404 "%s no longer ready for %s\n", 2414 "%s no longer ready for %s\n",
2405 GCC_2s(ct->cc), 2415 GCC_2s (ct->cc),
2406 GCT_2s(t)); 2416 GCT_2s (t));
2407 mark_connection_unready(ct); 2417 mark_connection_unready (ct);
2408 return; 2418 return;
2409 } 2419 }
2410 GNUNET_assert(GNUNET_NO == ct->is_ready); 2420 GNUNET_assert (GNUNET_NO == ct->is_ready);
2411 GNUNET_CONTAINER_DLL_remove(t->connection_busy_head, 2421 GNUNET_CONTAINER_DLL_remove (t->connection_busy_head,
2412 t->connection_busy_tail, 2422 t->connection_busy_tail,
2413 ct); 2423 ct);
2414 GNUNET_assert(0 < t->num_busy_connections); 2424 GNUNET_assert (0 < t->num_busy_connections);
2415 t->num_busy_connections--; 2425 t->num_busy_connections--;
2416 ct->is_ready = GNUNET_YES; 2426 ct->is_ready = GNUNET_YES;
2417 GNUNET_CONTAINER_DLL_insert_tail(t->connection_ready_head, 2427 GNUNET_CONTAINER_DLL_insert_tail (t->connection_ready_head,
2418 t->connection_ready_tail, 2428 t->connection_ready_tail,
2419 ct); 2429 ct);
2420 t->num_ready_connections++; 2430 t->num_ready_connections++;
2421 2431
2422 LOG(GNUNET_ERROR_TYPE_DEBUG, 2432 LOG (GNUNET_ERROR_TYPE_DEBUG,
2423 "%s now ready for %s in state %s\n", 2433 "%s now ready for %s in state %s\n",
2424 GCC_2s(ct->cc), 2434 GCC_2s (ct->cc),
2425 GCT_2s(t), 2435 GCT_2s (t),
2426 estate2s(t->estate)); 2436 estate2s (t->estate));
2427 switch (t->estate) 2437 switch (t->estate)
2438 {
2439 case CADET_TUNNEL_KEY_UNINITIALIZED:
2440 /* Do not begin KX if WE have no channels waiting! */
2441 if (0 != GNUNET_TIME_absolute_get_remaining (
2442 t->next_kx_attempt).rel_value_us)
2443 return; /* wait for timeout before retrying */
2444 /* We are uninitialized, just transmit immediately,
2445 without undue delay. */
2446 if (NULL != t->kx_task)
2447 {
2448 GNUNET_SCHEDULER_cancel (t->kx_task);
2449 t->kx_task = NULL;
2450 }
2451 send_kx (t,
2452 ct,
2453 &t->ax);
2454 if ((0 ==
2455 GCT_count_channels (t)) &&
2456 (NULL == t->destroy_task))
2428 { 2457 {
2429 case CADET_TUNNEL_KEY_UNINITIALIZED: 2458 t->destroy_task
2430 /* Do not begin KX if WE have no channels waiting! */ 2459 = GNUNET_SCHEDULER_add_delayed (IDLE_DESTROY_DELAY,
2431 if (0 != GNUNET_TIME_absolute_get_remaining(t->next_kx_attempt).rel_value_us) 2460 &destroy_tunnel,
2432 return; /* wait for timeout before retrying */ 2461 t);
2433 /* We are uninitialized, just transmit immediately, 2462 }
2434 without undue delay. */ 2463 break;
2435 if (NULL != t->kx_task)
2436 {
2437 GNUNET_SCHEDULER_cancel(t->kx_task);
2438 t->kx_task = NULL;
2439 }
2440 send_kx(t,
2441 ct,
2442 &t->ax);
2443 if ((0 ==
2444 GCT_count_channels(t)) &&
2445 (NULL == t->destroy_task))
2446 {
2447 t->destroy_task
2448 = GNUNET_SCHEDULER_add_delayed(IDLE_DESTROY_DELAY,
2449 &destroy_tunnel,
2450 t);
2451 }
2452 break;
2453 2464
2454 case CADET_TUNNEL_KEY_AX_RECV: 2465 case CADET_TUNNEL_KEY_AX_RECV:
2455 case CADET_TUNNEL_KEY_AX_SENT: 2466 case CADET_TUNNEL_KEY_AX_SENT:
2456 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV: 2467 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
2457 case CADET_TUNNEL_KEY_AX_AUTH_SENT: 2468 case CADET_TUNNEL_KEY_AX_AUTH_SENT:
2458 /* we're currently waiting for KX to complete, schedule job */ 2469 /* we're currently waiting for KX to complete, schedule job */
2459 if (NULL == t->kx_task) 2470 if (NULL == t->kx_task)
2460 t->kx_task 2471 t->kx_task
2461 = GNUNET_SCHEDULER_add_at(t->next_kx_attempt, 2472 = GNUNET_SCHEDULER_add_at (t->next_kx_attempt,
2462 &retry_kx, 2473 &retry_kx,
2463 t); 2474 t);
2464 break; 2475 break;
2465 2476
2466 case CADET_TUNNEL_KEY_OK: 2477 case CADET_TUNNEL_KEY_OK:
2467 if (GNUNET_YES == t->kx_auth_requested) 2478 if (GNUNET_YES == t->kx_auth_requested)
2468 { 2479 {
2469 if (0 != GNUNET_TIME_absolute_get_remaining(t->next_kx_attempt).rel_value_us) 2480 if (0 != GNUNET_TIME_absolute_get_remaining (
2470 return; /* wait for timeout */ 2481 t->next_kx_attempt).rel_value_us)
2471 if (NULL != t->kx_task) 2482 return; /* wait for timeout */
2472 { 2483 if (NULL != t->kx_task)
2473 GNUNET_SCHEDULER_cancel(t->kx_task); 2484 {
2474 t->kx_task = NULL; 2485 GNUNET_SCHEDULER_cancel (t->kx_task);
2475 } 2486 t->kx_task = NULL;
2476 send_kx_auth(t, 2487 }
2477 ct, 2488 send_kx_auth (t,
2478 &t->ax, 2489 ct,
2479 GNUNET_NO); 2490 &t->ax,
2480 return; 2491 GNUNET_NO);
2481 } 2492 return;
2482 try_send_normal_payload(t,
2483 ct);
2484 break;
2485 } 2493 }
2494 try_send_normal_payload (t,
2495 ct);
2496 break;
2497 }
2486} 2498}
2487 2499
2488 2500
@@ -2495,7 +2507,7 @@ connection_ready_cb(void *cls,
2495 * @param cls the `struct CadetTunnel` to process messages on 2507 * @param cls the `struct CadetTunnel` to process messages on
2496 */ 2508 */
2497static void 2509static void
2498trigger_transmissions(void *cls) 2510trigger_transmissions (void *cls)
2499{ 2511{
2500 struct CadetTunnel *t = cls; 2512 struct CadetTunnel *t = cls;
2501 struct CadetTConnection *ct; 2513 struct CadetTConnection *ct;
@@ -2503,11 +2515,11 @@ trigger_transmissions(void *cls)
2503 t->send_task = NULL; 2515 t->send_task = NULL;
2504 if (NULL == t->tq_head) 2516 if (NULL == t->tq_head)
2505 return; /* no messages pending right now */ 2517 return; /* no messages pending right now */
2506 ct = get_ready_connection(t); 2518 ct = get_ready_connection (t);
2507 if (NULL == ct) 2519 if (NULL == ct)
2508 return; /* no connections ready */ 2520 return; /* no connections ready */
2509 try_send_normal_payload(t, 2521 try_send_normal_payload (t,
2510 ct); 2522 ct);
2511} 2523}
2512 2524
2513 2525
@@ -2515,7 +2527,8 @@ trigger_transmissions(void *cls)
2515 * Closure for #evaluate_connection. Used to assemble summary information 2527 * Closure for #evaluate_connection. Used to assemble summary information
2516 * about the existing connections so we can evaluate a new path. 2528 * about the existing connections so we can evaluate a new path.
2517 */ 2529 */
2518struct EvaluationSummary { 2530struct EvaluationSummary
2531{
2519 /** 2532 /**
2520 * Minimum length of any of our connections, `UINT_MAX` if we have none. 2533 * Minimum length of any of our connections, `UINT_MAX` if we have none.
2521 */ 2534 */
@@ -2567,8 +2580,8 @@ struct EvaluationSummary {
2567 * @param ct a connection to include in the summary 2580 * @param ct a connection to include in the summary
2568 */ 2581 */
2569static void 2582static void
2570evaluate_connection(void *cls, 2583evaluate_connection (void *cls,
2571 struct CadetTConnection *ct) 2584 struct CadetTConnection *ct)
2572{ 2585{
2573 struct EvaluationSummary *es = cls; 2586 struct EvaluationSummary *es = cls;
2574 struct CadetConnection *cc = ct->cc; 2587 struct CadetConnection *cc = ct->cc;
@@ -2581,79 +2594,80 @@ evaluate_connection(void *cls,
2581 double score; 2594 double score;
2582 double success_rate; 2595 double success_rate;
2583 2596
2584 ps = GCC_get_path(cc, 2597 ps = GCC_get_path (cc,
2585 &ct_length); 2598 &ct_length);
2586 LOG(GNUNET_ERROR_TYPE_DEBUG, 2599 LOG (GNUNET_ERROR_TYPE_DEBUG,
2587 "Evaluating path %s of existing %s\n", 2600 "Evaluating path %s of existing %s\n",
2588 GCPP_2s(ps), 2601 GCPP_2s (ps),
2589 GCC_2s(cc)); 2602 GCC_2s (cc));
2590 if (ps == es->path) 2603 if (ps == es->path)
2604 {
2605 LOG (GNUNET_ERROR_TYPE_DEBUG,
2606 "Ignoring duplicate path %s.\n",
2607 GCPP_2s (es->path));
2608 es->duplicate = GNUNET_YES;
2609 return;
2610 }
2611 if (NULL != es->path)
2612 {
2613 int duplicate = GNUNET_YES;
2614
2615 for (unsigned int i = 0; i < ct_length; i++)
2616 {
2617 GNUNET_assert (GCPP_get_length (es->path) > i);
2618 if (GCPP_get_peer_at_offset (es->path,
2619 i) !=
2620 GCPP_get_peer_at_offset (ps,
2621 i))
2622 {
2623 duplicate = GNUNET_NO;
2624 break;
2625 }
2626 }
2627 if (GNUNET_YES == duplicate)
2591 { 2628 {
2592 LOG(GNUNET_ERROR_TYPE_DEBUG, 2629 LOG (GNUNET_ERROR_TYPE_DEBUG,
2593 "Ignoring duplicate path %s.\n", 2630 "Ignoring overlapping path %s.\n",
2594 GCPP_2s(es->path)); 2631 GCPP_2s (es->path));
2595 es->duplicate = GNUNET_YES; 2632 es->duplicate = GNUNET_YES;
2596 return; 2633 return;
2597 } 2634 }
2598 if (NULL != es->path) 2635 else
2599 { 2636 {
2600 int duplicate = GNUNET_YES; 2637 LOG (GNUNET_ERROR_TYPE_DEBUG,
2601 2638 "Known path %s differs from proposed path\n",
2602 for (unsigned int i = 0; i < ct_length; i++) 2639 GCPP_2s (ps));
2603 {
2604 GNUNET_assert(GCPP_get_length(es->path) > i);
2605 if (GCPP_get_peer_at_offset(es->path,
2606 i) !=
2607 GCPP_get_peer_at_offset(ps,
2608 i))
2609 {
2610 duplicate = GNUNET_NO;
2611 break;
2612 }
2613 }
2614 if (GNUNET_YES == duplicate)
2615 {
2616 LOG(GNUNET_ERROR_TYPE_DEBUG,
2617 "Ignoring overlapping path %s.\n",
2618 GCPP_2s(es->path));
2619 es->duplicate = GNUNET_YES;
2620 return;
2621 }
2622 else
2623 {
2624 LOG(GNUNET_ERROR_TYPE_DEBUG,
2625 "Known path %s differs from proposed path\n",
2626 GCPP_2s(ps));
2627 }
2628 } 2640 }
2641 }
2629 2642
2630 ct_desirability = GCPP_get_desirability(ps); 2643 ct_desirability = GCPP_get_desirability (ps);
2631 metrics = GCC_get_metrics(cc); 2644 metrics = GCC_get_metrics (cc);
2632 uptime = GNUNET_TIME_absolute_get_duration(metrics->age); 2645 uptime = GNUNET_TIME_absolute_get_duration (metrics->age);
2633 last_use = GNUNET_TIME_absolute_get_duration(metrics->last_use); 2646 last_use = GNUNET_TIME_absolute_get_duration (metrics->last_use);
2634 /* We add 1.0 here to avoid division by zero. */ 2647 /* We add 1.0 here to avoid division by zero. */
2635 success_rate = (metrics->num_acked_transmissions + 1.0) / (metrics->num_successes + 1.0); 2648 success_rate = (metrics->num_acked_transmissions + 1.0)
2649 / (metrics->num_successes + 1.0);
2636 score 2650 score
2637 = ct_desirability 2651 = ct_desirability
2638 + 100.0 / (1.0 + ct_length) /* longer paths = better */ 2652 + 100.0 / (1.0 + ct_length) /* longer paths = better */
2639 + sqrt(uptime.rel_value_us / 60000000LL) /* larger uptime = better */ 2653 + sqrt (uptime.rel_value_us / 60000000LL) /* larger uptime = better */
2640 - last_use.rel_value_us / 1000L; /* longer idle = worse */ 2654 - last_use.rel_value_us / 1000L; /* longer idle = worse */
2641 score *= success_rate; /* weigh overall by success rate */ 2655 score *= success_rate; /* weigh overall by success rate */
2642 2656
2643 if ((NULL == es->worst) || 2657 if ((NULL == es->worst) ||
2644 (score < es->worst_score)) 2658 (score < es->worst_score))
2645 { 2659 {
2646 es->worst = ct; 2660 es->worst = ct;
2647 es->worst_score = score; 2661 es->worst_score = score;
2648 } 2662 }
2649 es->min_length = GNUNET_MIN(es->min_length, 2663 es->min_length = GNUNET_MIN (es->min_length,
2650 ct_length); 2664 ct_length);
2651 es->max_length = GNUNET_MAX(es->max_length, 2665 es->max_length = GNUNET_MAX (es->max_length,
2652 ct_length); 2666 ct_length);
2653 es->min_desire = GNUNET_MIN(es->min_desire, 2667 es->min_desire = GNUNET_MIN (es->min_desire,
2654 ct_desirability); 2668 ct_desirability);
2655 es->max_desire = GNUNET_MAX(es->max_desire, 2669 es->max_desire = GNUNET_MAX (es->max_desire,
2656 ct_desirability); 2670 ct_desirability);
2657} 2671}
2658 2672
2659 2673
@@ -2667,17 +2681,17 @@ evaluate_connection(void *cls,
2667 * @return #GNUNET_YES (should keep iterating) 2681 * @return #GNUNET_YES (should keep iterating)
2668 */ 2682 */
2669static int 2683static int
2670consider_path_cb(void *cls, 2684consider_path_cb (void *cls,
2671 struct CadetPeerPath *path, 2685 struct CadetPeerPath *path,
2672 unsigned int off) 2686 unsigned int off)
2673{ 2687{
2674 struct CadetTunnel *t = cls; 2688 struct CadetTunnel *t = cls;
2675 struct EvaluationSummary es; 2689 struct EvaluationSummary es;
2676 struct CadetTConnection *ct; 2690 struct CadetTConnection *ct;
2677 2691
2678 GNUNET_assert(off < GCPP_get_length(path)); 2692 GNUNET_assert (off < GCPP_get_length (path));
2679 GNUNET_assert(GCPP_get_peer_at_offset(path, 2693 GNUNET_assert (GCPP_get_peer_at_offset (path,
2680 off) == t->destination); 2694 off) == t->destination);
2681 es.min_length = UINT_MAX; 2695 es.min_length = UINT_MAX;
2682 es.max_length = 0; 2696 es.max_length = 0;
2683 es.max_desire = 0; 2697 es.max_desire = 0;
@@ -2687,16 +2701,16 @@ consider_path_cb(void *cls,
2687 es.worst = NULL; 2701 es.worst = NULL;
2688 2702
2689 /* Compute evaluation summary over existing connections. */ 2703 /* Compute evaluation summary over existing connections. */
2690 LOG(GNUNET_ERROR_TYPE_DEBUG, 2704 LOG (GNUNET_ERROR_TYPE_DEBUG,
2691 "Evaluating proposed path %s for target %s\n", 2705 "Evaluating proposed path %s for target %s\n",
2692 GCPP_2s(path), 2706 GCPP_2s (path),
2693 GCT_2s(t)); 2707 GCT_2s (t));
2694 /* FIXME: suspect this does not ACTUALLY iterate 2708 /* FIXME: suspect this does not ACTUALLY iterate
2695 over all existing paths, otherwise dup detection 2709 over all existing paths, otherwise dup detection
2696 should work!!! */ 2710 should work!!! */
2697 GCT_iterate_connections(t, 2711 GCT_iterate_connections (t,
2698 &evaluate_connection, 2712 &evaluate_connection,
2699 &es); 2713 &es);
2700 if (GNUNET_YES == es.duplicate) 2714 if (GNUNET_YES == es.duplicate)
2701 return GNUNET_YES; 2715 return GNUNET_YES;
2702 2716
@@ -2707,54 +2721,54 @@ consider_path_cb(void *cls,
2707 /* We iterate by increasing path length; if we have enough paths and 2721 /* We iterate by increasing path length; if we have enough paths and
2708 this one is more than twice as long than what we are currently 2722 this one is more than twice as long than what we are currently
2709 using, then ignore all of these super-long ones! */ 2723 using, then ignore all of these super-long ones! */
2710 if ((GCT_count_any_connections(t) > DESIRED_CONNECTIONS_PER_TUNNEL) && 2724 if ((GCT_count_any_connections (t) > DESIRED_CONNECTIONS_PER_TUNNEL) &&
2711 (es.min_length * 2 < off) && 2725 (es.min_length * 2 < off) &&
2712 (es.max_length < off)) 2726 (es.max_length < off))
2713 { 2727 {
2714 LOG(GNUNET_ERROR_TYPE_DEBUG, 2728 LOG (GNUNET_ERROR_TYPE_DEBUG,
2715 "Ignoring paths of length %u, they are way too long.\n", 2729 "Ignoring paths of length %u, they are way too long.\n",
2716 es.min_length * 2); 2730 es.min_length * 2);
2717 return GNUNET_NO; 2731 return GNUNET_NO;
2718 } 2732 }
2719 /* If we have enough paths and this one looks no better, ignore it. */ 2733 /* If we have enough paths and this one looks no better, ignore it. */
2720 if ((GCT_count_any_connections(t) >= DESIRED_CONNECTIONS_PER_TUNNEL) && 2734 if ((GCT_count_any_connections (t) >= DESIRED_CONNECTIONS_PER_TUNNEL) &&
2721 (es.min_length < GCPP_get_length(path)) && 2735 (es.min_length < GCPP_get_length (path)) &&
2722 (es.min_desire > GCPP_get_desirability(path)) && 2736 (es.min_desire > GCPP_get_desirability (path)) &&
2723 (es.max_length < off)) 2737 (es.max_length < off))
2724 { 2738 {
2725 LOG(GNUNET_ERROR_TYPE_DEBUG, 2739 LOG (GNUNET_ERROR_TYPE_DEBUG,
2726 "Ignoring path (%u/%llu) to %s, got something better already.\n", 2740 "Ignoring path (%u/%llu) to %s, got something better already.\n",
2727 GCPP_get_length(path), 2741 GCPP_get_length (path),
2728 (unsigned long long)GCPP_get_desirability(path), 2742 (unsigned long long) GCPP_get_desirability (path),
2729 GCP_2s(t->destination)); 2743 GCP_2s (t->destination));
2730 return GNUNET_YES; 2744 return GNUNET_YES;
2731 } 2745 }
2732 2746
2733 /* Path is interesting (better by some metric, or we don't have 2747 /* Path is interesting (better by some metric, or we don't have
2734 enough paths yet). */ 2748 enough paths yet). */
2735 ct = GNUNET_new(struct CadetTConnection); 2749 ct = GNUNET_new (struct CadetTConnection);
2736 ct->created = GNUNET_TIME_absolute_get(); 2750 ct->created = GNUNET_TIME_absolute_get ();
2737 ct->t = t; 2751 ct->t = t;
2738 ct->cc = GCC_create(t->destination, 2752 ct->cc = GCC_create (t->destination,
2739 path, 2753 path,
2740 off, 2754 off,
2741 ct, 2755 ct,
2742 &connection_ready_cb, 2756 &connection_ready_cb,
2743 ct); 2757 ct);
2744 2758
2745 /* FIXME: schedule job to kill connection (and path?) if it takes 2759 /* FIXME: schedule job to kill connection (and path?) if it takes
2746 too long to get ready! (And track performance data on how long 2760 too long to get ready! (And track performance data on how long
2747 other connections took with the tunnel!) 2761 other connections took with the tunnel!)
2748 => Note: to be done within 'connection'-logic! */ 2762 => Note: to be done within 'connection'-logic! */
2749 GNUNET_CONTAINER_DLL_insert(t->connection_busy_head, 2763 GNUNET_CONTAINER_DLL_insert (t->connection_busy_head,
2750 t->connection_busy_tail, 2764 t->connection_busy_tail,
2751 ct); 2765 ct);
2752 t->num_busy_connections++; 2766 t->num_busy_connections++;
2753 LOG(GNUNET_ERROR_TYPE_DEBUG, 2767 LOG (GNUNET_ERROR_TYPE_DEBUG,
2754 "Found interesting path %s for %s, created %s\n", 2768 "Found interesting path %s for %s, created %s\n",
2755 GCPP_2s(path), 2769 GCPP_2s (path),
2756 GCT_2s(t), 2770 GCT_2s (t),
2757 GCC_2s(ct->cc)); 2771 GCC_2s (ct->cc));
2758 return GNUNET_YES; 2772 return GNUNET_YES;
2759} 2773}
2760 2774
@@ -2773,16 +2787,16 @@ consider_path_cb(void *cls,
2773 * @param cls the `struct CadetTunnel` 2787 * @param cls the `struct CadetTunnel`
2774 */ 2788 */
2775static void 2789static void
2776maintain_connections_cb(void *cls) 2790maintain_connections_cb (void *cls)
2777{ 2791{
2778 struct CadetTunnel *t = cls; 2792 struct CadetTunnel *t = cls;
2779 struct GNUNET_TIME_Relative delay; 2793 struct GNUNET_TIME_Relative delay;
2780 struct EvaluationSummary es; 2794 struct EvaluationSummary es;
2781 2795
2782 t->maintain_connections_task = NULL; 2796 t->maintain_connections_task = NULL;
2783 LOG(GNUNET_ERROR_TYPE_DEBUG, 2797 LOG (GNUNET_ERROR_TYPE_DEBUG,
2784 "Performing connection maintenance for %s.\n", 2798 "Performing connection maintenance for %s.\n",
2785 GCT_2s(t)); 2799 GCT_2s (t));
2786 2800
2787 es.min_length = UINT_MAX; 2801 es.min_length = UINT_MAX;
2788 es.max_length = 0; 2802 es.max_length = 0;
@@ -2791,21 +2805,21 @@ maintain_connections_cb(void *cls)
2791 es.path = NULL; 2805 es.path = NULL;
2792 es.worst = NULL; 2806 es.worst = NULL;
2793 es.duplicate = GNUNET_NO; 2807 es.duplicate = GNUNET_NO;
2794 GCT_iterate_connections(t, 2808 GCT_iterate_connections (t,
2795 &evaluate_connection, 2809 &evaluate_connection,
2796 &es); 2810 &es);
2797 if ((NULL != es.worst) && 2811 if ((NULL != es.worst) &&
2798 (GCT_count_any_connections(t) > DESIRED_CONNECTIONS_PER_TUNNEL)) 2812 (GCT_count_any_connections (t) > DESIRED_CONNECTIONS_PER_TUNNEL))
2799 { 2813 {
2800 /* Clear out worst-performing connection 'es.worst'. */ 2814 /* Clear out worst-performing connection 'es.worst'. */
2801 destroy_t_connection(t, 2815 destroy_t_connection (t,
2802 es.worst); 2816 es.worst);
2803 } 2817 }
2804 2818
2805 /* Consider additional paths */ 2819 /* Consider additional paths */
2806 (void)GCP_iterate_paths(t->destination, 2820 (void) GCP_iterate_paths (t->destination,
2807 &consider_path_cb, 2821 &consider_path_cb,
2808 t); 2822 t);
2809 2823
2810 /* FIXME: calculate when to try again based on how well we are doing; 2824 /* FIXME: calculate when to try again based on how well we are doing;
2811 in particular, if we have to few connections, we might be able 2825 in particular, if we have to few connections, we might be able
@@ -2817,9 +2831,9 @@ maintain_connections_cb(void *cls)
2817 and then reduce the frequency accordingly. */ 2831 and then reduce the frequency accordingly. */
2818 delay = GNUNET_TIME_UNIT_MINUTES; 2832 delay = GNUNET_TIME_UNIT_MINUTES;
2819 t->maintain_connections_task 2833 t->maintain_connections_task
2820 = GNUNET_SCHEDULER_add_delayed(delay, 2834 = GNUNET_SCHEDULER_add_delayed (delay,
2821 &maintain_connections_cb, 2835 &maintain_connections_cb,
2822 t); 2836 t);
2823} 2837}
2824 2838
2825 2839
@@ -2832,18 +2846,18 @@ maintain_connections_cb(void *cls)
2832 * @param off offset of the destination on path @a path 2846 * @param off offset of the destination on path @a path
2833 */ 2847 */
2834void 2848void
2835GCT_consider_path(struct CadetTunnel *t, 2849GCT_consider_path (struct CadetTunnel *t,
2836 struct CadetPeerPath *p, 2850 struct CadetPeerPath *p,
2837 unsigned int off) 2851 unsigned int off)
2838{ 2852{
2839 LOG(GNUNET_ERROR_TYPE_DEBUG, 2853 LOG (GNUNET_ERROR_TYPE_DEBUG,
2840 "Considering %s for %s (offset %u)\n", 2854 "Considering %s for %s (offset %u)\n",
2841 GCPP_2s(p), 2855 GCPP_2s (p),
2842 GCT_2s(t), 2856 GCT_2s (t),
2843 off); 2857 off);
2844 (void)consider_path_cb(t, 2858 (void) consider_path_cb (t,
2845 p, 2859 p,
2846 off); 2860 off);
2847} 2861}
2848 2862
2849 2863
@@ -2854,18 +2868,18 @@ GCT_consider_path(struct CadetTunnel *t,
2854 * @param msg the message we received on the tunnel 2868 * @param msg the message we received on the tunnel
2855 */ 2869 */
2856static void 2870static void
2857handle_plaintext_keepalive(void *cls, 2871handle_plaintext_keepalive (void *cls,
2858 const struct GNUNET_MessageHeader *msg) 2872 const struct GNUNET_MessageHeader *msg)
2859{ 2873{
2860 struct CadetTunnel *t = cls; 2874 struct CadetTunnel *t = cls;
2861 2875
2862 LOG(GNUNET_ERROR_TYPE_DEBUG, 2876 LOG (GNUNET_ERROR_TYPE_DEBUG,
2863 "Received KEEPALIVE on %s\n", 2877 "Received KEEPALIVE on %s\n",
2864 GCT_2s(t)); 2878 GCT_2s (t));
2865 GNUNET_STATISTICS_update(stats, 2879 GNUNET_STATISTICS_update (stats,
2866 "# keepalives received", 2880 "# keepalives received",
2867 1, 2881 1,
2868 GNUNET_NO); 2882 GNUNET_NO);
2869} 2883}
2870 2884
2871 2885
@@ -2877,8 +2891,8 @@ handle_plaintext_keepalive(void *cls,
2877 * @return #GNUNET_OK (any variable-size payload goes) 2891 * @return #GNUNET_OK (any variable-size payload goes)
2878 */ 2892 */
2879static int 2893static int
2880check_plaintext_data(void *cls, 2894check_plaintext_data (void *cls,
2881 const struct GNUNET_CADET_ChannelAppDataMessage *msg) 2895 const struct GNUNET_CADET_ChannelAppDataMessage *msg)
2882{ 2896{
2883 return GNUNET_OK; 2897 return GNUNET_OK;
2884} 2898}
@@ -2892,29 +2906,29 @@ check_plaintext_data(void *cls,
2892 * @param msg the message we received on the tunnel 2906 * @param msg the message we received on the tunnel
2893 */ 2907 */
2894static void 2908static void
2895handle_plaintext_data(void *cls, 2909handle_plaintext_data (void *cls,
2896 const struct GNUNET_CADET_ChannelAppDataMessage *msg) 2910 const struct GNUNET_CADET_ChannelAppDataMessage *msg)
2897{ 2911{
2898 struct CadetTunnel *t = cls; 2912 struct CadetTunnel *t = cls;
2899 struct CadetChannel *ch; 2913 struct CadetChannel *ch;
2900 2914
2901 ch = lookup_channel(t, 2915 ch = lookup_channel (t,
2902 msg->ctn); 2916 msg->ctn);
2903 if (NULL == ch) 2917 if (NULL == ch)
2904 { 2918 {
2905 /* We don't know about such a channel, might have been destroyed on our 2919 /* We don't know about such a channel, might have been destroyed on our
2906 end in the meantime, or never existed. Send back a DESTROY. */ 2920 end in the meantime, or never existed. Send back a DESTROY. */
2907 LOG(GNUNET_ERROR_TYPE_DEBUG, 2921 LOG (GNUNET_ERROR_TYPE_DEBUG,
2908 "Received %u bytes of application data for unknown channel %u, sending DESTROY\n", 2922 "Received %u bytes of application data for unknown channel %u, sending DESTROY\n",
2909 (unsigned int)(ntohs(msg->header.size) - sizeof(*msg)), 2923 (unsigned int) (ntohs (msg->header.size) - sizeof(*msg)),
2910 ntohl(msg->ctn.cn)); 2924 ntohl (msg->ctn.cn));
2911 GCT_send_channel_destroy(t, 2925 GCT_send_channel_destroy (t,
2912 msg->ctn); 2926 msg->ctn);
2913 return; 2927 return;
2914 } 2928 }
2915 GCCH_handle_channel_plaintext_data(ch, 2929 GCCH_handle_channel_plaintext_data (ch,
2916 GCC_get_id(t->current_ct->cc), 2930 GCC_get_id (t->current_ct->cc),
2917 msg); 2931 msg);
2918} 2932}
2919 2933
2920 2934
@@ -2927,28 +2941,28 @@ handle_plaintext_data(void *cls,
2927 * @param ack the message we received on the tunnel 2941 * @param ack the message we received on the tunnel
2928 */ 2942 */
2929static void 2943static void
2930handle_plaintext_data_ack(void *cls, 2944handle_plaintext_data_ack (void *cls,
2931 const struct GNUNET_CADET_ChannelDataAckMessage *ack) 2945 const struct GNUNET_CADET_ChannelDataAckMessage *ack)
2932{ 2946{
2933 struct CadetTunnel *t = cls; 2947 struct CadetTunnel *t = cls;
2934 struct CadetChannel *ch; 2948 struct CadetChannel *ch;
2935 2949
2936 ch = lookup_channel(t, 2950 ch = lookup_channel (t,
2937 ack->ctn); 2951 ack->ctn);
2938 if (NULL == ch) 2952 if (NULL == ch)
2939 { 2953 {
2940 /* We don't know about such a channel, might have been destroyed on our 2954 /* We don't know about such a channel, might have been destroyed on our
2941 end in the meantime, or never existed. Send back a DESTROY. */ 2955 end in the meantime, or never existed. Send back a DESTROY. */
2942 LOG(GNUNET_ERROR_TYPE_DEBUG, 2956 LOG (GNUNET_ERROR_TYPE_DEBUG,
2943 "Received DATA_ACK for unknown channel %u, sending DESTROY\n", 2957 "Received DATA_ACK for unknown channel %u, sending DESTROY\n",
2944 ntohl(ack->ctn.cn)); 2958 ntohl (ack->ctn.cn));
2945 GCT_send_channel_destroy(t, 2959 GCT_send_channel_destroy (t,
2946 ack->ctn); 2960 ack->ctn);
2947 return; 2961 return;
2948 } 2962 }
2949 GCCH_handle_channel_plaintext_data_ack(ch, 2963 GCCH_handle_channel_plaintext_data_ack (ch,
2950 GCC_get_id(t->current_ct->cc), 2964 GCC_get_id (t->current_ct->cc),
2951 ack); 2965 ack);
2952} 2966}
2953 2967
2954 2968
@@ -2960,43 +2974,44 @@ handle_plaintext_data_ack(void *cls,
2960 * @param copen the message we received on the tunnel 2974 * @param copen the message we received on the tunnel
2961 */ 2975 */
2962static void 2976static void
2963handle_plaintext_channel_open(void *cls, 2977handle_plaintext_channel_open (void *cls,
2964 const struct GNUNET_CADET_ChannelOpenMessage *copen) 2978 const struct
2979 GNUNET_CADET_ChannelOpenMessage *copen)
2965{ 2980{
2966 struct CadetTunnel *t = cls; 2981 struct CadetTunnel *t = cls;
2967 struct CadetChannel *ch; 2982 struct CadetChannel *ch;
2968 2983
2969 ch = GNUNET_CONTAINER_multihashmap32_get(t->channels, 2984 ch = GNUNET_CONTAINER_multihashmap32_get (t->channels,
2970 ntohl(copen->ctn.cn)); 2985 ntohl (copen->ctn.cn));
2971 if (NULL != ch) 2986 if (NULL != ch)
2972 { 2987 {
2973 LOG(GNUNET_ERROR_TYPE_DEBUG, 2988 LOG (GNUNET_ERROR_TYPE_DEBUG,
2974 "Received duplicate channel CHANNEL_OPEN on h_port %s from %s (%s), resending ACK\n", 2989 "Received duplicate channel CHANNEL_OPEN on h_port %s from %s (%s), resending ACK\n",
2975 GNUNET_h2s(&copen->h_port), 2990 GNUNET_h2s (&copen->h_port),
2976 GCT_2s(t), 2991 GCT_2s (t),
2977 GCCH_2s(ch)); 2992 GCCH_2s (ch));
2978 GCCH_handle_duplicate_open(ch, 2993 GCCH_handle_duplicate_open (ch,
2979 GCC_get_id(t->current_ct->cc)); 2994 GCC_get_id (t->current_ct->cc));
2980 return; 2995 return;
2981 } 2996 }
2982 LOG(GNUNET_ERROR_TYPE_DEBUG, 2997 LOG (GNUNET_ERROR_TYPE_DEBUG,
2983 "Received CHANNEL_OPEN on h_port %s from %s\n", 2998 "Received CHANNEL_OPEN on h_port %s from %s\n",
2984 GNUNET_h2s(&copen->h_port), 2999 GNUNET_h2s (&copen->h_port),
2985 GCT_2s(t)); 3000 GCT_2s (t));
2986 ch = GCCH_channel_incoming_new(t, 3001 ch = GCCH_channel_incoming_new (t,
2987 copen->ctn, 3002 copen->ctn,
2988 &copen->h_port, 3003 &copen->h_port,
2989 ntohl(copen->opt)); 3004 ntohl (copen->opt));
2990 if (NULL != t->destroy_task) 3005 if (NULL != t->destroy_task)
2991 { 3006 {
2992 GNUNET_SCHEDULER_cancel(t->destroy_task); 3007 GNUNET_SCHEDULER_cancel (t->destroy_task);
2993 t->destroy_task = NULL; 3008 t->destroy_task = NULL;
2994 } 3009 }
2995 GNUNET_assert(GNUNET_OK == 3010 GNUNET_assert (GNUNET_OK ==
2996 GNUNET_CONTAINER_multihashmap32_put(t->channels, 3011 GNUNET_CONTAINER_multihashmap32_put (t->channels,
2997 ntohl(copen->ctn.cn), 3012 ntohl (copen->ctn.cn),
2998 ch, 3013 ch,
2999 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 3014 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
3000} 3015}
3001 3016
3002 3017
@@ -3007,22 +3022,22 @@ handle_plaintext_channel_open(void *cls,
3007 * @param ctn ID of the channel to destroy 3022 * @param ctn ID of the channel to destroy
3008 */ 3023 */
3009void 3024void
3010GCT_send_channel_destroy(struct CadetTunnel *t, 3025GCT_send_channel_destroy (struct CadetTunnel *t,
3011 struct GNUNET_CADET_ChannelTunnelNumber ctn) 3026 struct GNUNET_CADET_ChannelTunnelNumber ctn)
3012{ 3027{
3013 struct GNUNET_CADET_ChannelDestroyMessage msg; 3028 struct GNUNET_CADET_ChannelDestroyMessage msg;
3014 3029
3015 LOG(GNUNET_ERROR_TYPE_DEBUG, 3030 LOG (GNUNET_ERROR_TYPE_DEBUG,
3016 "Sending DESTORY message for channel ID %u\n", 3031 "Sending DESTORY message for channel ID %u\n",
3017 ntohl(ctn.cn)); 3032 ntohl (ctn.cn));
3018 msg.header.size = htons(sizeof(msg)); 3033 msg.header.size = htons (sizeof(msg));
3019 msg.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); 3034 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
3020 msg.reserved = htonl(0); 3035 msg.reserved = htonl (0);
3021 msg.ctn = ctn; 3036 msg.ctn = ctn;
3022 GCT_send(t, 3037 GCT_send (t,
3023 &msg.header, 3038 &msg.header,
3024 NULL, 3039 NULL,
3025 NULL); 3040 NULL);
3026} 3041}
3027 3042
3028 3043
@@ -3035,32 +3050,33 @@ GCT_send_channel_destroy(struct CadetTunnel *t,
3035 * @param cm the message we received on the tunnel 3050 * @param cm the message we received on the tunnel
3036 */ 3051 */
3037static void 3052static void
3038handle_plaintext_channel_open_ack(void *cls, 3053handle_plaintext_channel_open_ack (void *cls,
3039 const struct GNUNET_CADET_ChannelOpenAckMessage *cm) 3054 const struct
3055 GNUNET_CADET_ChannelOpenAckMessage *cm)
3040{ 3056{
3041 struct CadetTunnel *t = cls; 3057 struct CadetTunnel *t = cls;
3042 struct CadetChannel *ch; 3058 struct CadetChannel *ch;
3043 3059
3044 ch = lookup_channel(t, 3060 ch = lookup_channel (t,
3045 cm->ctn); 3061 cm->ctn);
3046 if (NULL == ch) 3062 if (NULL == ch)
3047 { 3063 {
3048 /* We don't know about such a channel, might have been destroyed on our 3064 /* We don't know about such a channel, might have been destroyed on our
3049 end in the meantime, or never existed. Send back a DESTROY. */ 3065 end in the meantime, or never existed. Send back a DESTROY. */
3050 LOG(GNUNET_ERROR_TYPE_DEBUG, 3066 LOG (GNUNET_ERROR_TYPE_DEBUG,
3051 "Received channel OPEN_ACK for unknown channel %u, sending DESTROY\n", 3067 "Received channel OPEN_ACK for unknown channel %u, sending DESTROY\n",
3052 ntohl(cm->ctn.cn)); 3068 ntohl (cm->ctn.cn));
3053 GCT_send_channel_destroy(t, 3069 GCT_send_channel_destroy (t,
3054 cm->ctn); 3070 cm->ctn);
3055 return; 3071 return;
3056 } 3072 }
3057 LOG(GNUNET_ERROR_TYPE_DEBUG, 3073 LOG (GNUNET_ERROR_TYPE_DEBUG,
3058 "Received channel OPEN_ACK on channel %s from %s\n", 3074 "Received channel OPEN_ACK on channel %s from %s\n",
3059 GCCH_2s(ch), 3075 GCCH_2s (ch),
3060 GCT_2s(t)); 3076 GCT_2s (t));
3061 GCCH_handle_channel_open_ack(ch, 3077 GCCH_handle_channel_open_ack (ch,
3062 GCC_get_id(t->current_ct->cc), 3078 GCC_get_id (t->current_ct->cc),
3063 &cm->port); 3079 &cm->port);
3064} 3080}
3065 3081
3066 3082
@@ -3072,29 +3088,30 @@ handle_plaintext_channel_open_ack(void *cls,
3072 * @param cm the message we received on the tunnel 3088 * @param cm the message we received on the tunnel
3073 */ 3089 */
3074static void 3090static void
3075handle_plaintext_channel_destroy(void *cls, 3091handle_plaintext_channel_destroy (void *cls,
3076 const struct GNUNET_CADET_ChannelDestroyMessage *cm) 3092 const struct
3093 GNUNET_CADET_ChannelDestroyMessage *cm)
3077{ 3094{
3078 struct CadetTunnel *t = cls; 3095 struct CadetTunnel *t = cls;
3079 struct CadetChannel *ch; 3096 struct CadetChannel *ch;
3080 3097
3081 ch = lookup_channel(t, 3098 ch = lookup_channel (t,
3082 cm->ctn); 3099 cm->ctn);
3083 if (NULL == ch) 3100 if (NULL == ch)
3084 { 3101 {
3085 /* We don't know about such a channel, might have been destroyed on our 3102 /* We don't know about such a channel, might have been destroyed on our
3086 end in the meantime, or never existed. */ 3103 end in the meantime, or never existed. */
3087 LOG(GNUNET_ERROR_TYPE_DEBUG, 3104 LOG (GNUNET_ERROR_TYPE_DEBUG,
3088 "Received channel DESTORY for unknown channel %u. Ignoring.\n", 3105 "Received channel DESTORY for unknown channel %u. Ignoring.\n",
3089 ntohl(cm->ctn.cn)); 3106 ntohl (cm->ctn.cn));
3090 return; 3107 return;
3091 } 3108 }
3092 LOG(GNUNET_ERROR_TYPE_DEBUG, 3109 LOG (GNUNET_ERROR_TYPE_DEBUG,
3093 "Received channel DESTROY on %s from %s\n", 3110 "Received channel DESTROY on %s from %s\n",
3094 GCCH_2s(ch), 3111 GCCH_2s (ch),
3095 GCT_2s(t)); 3112 GCT_2s (t));
3096 GCCH_handle_remote_destroy(ch, 3113 GCCH_handle_remote_destroy (ch,
3097 GCC_get_id(t->current_ct->cc)); 3114 GCC_get_id (t->current_ct->cc));
3098} 3115}
3099 3116
3100 3117
@@ -3109,14 +3126,14 @@ handle_plaintext_channel_destroy(void *cls,
3109 * #GNUNET_SYSERR to stop further processing with error 3126 * #GNUNET_SYSERR to stop further processing with error
3110 */ 3127 */
3111static int 3128static int
3112handle_decrypted(void *cls, 3129handle_decrypted (void *cls,
3113 const struct GNUNET_MessageHeader *msg) 3130 const struct GNUNET_MessageHeader *msg)
3114{ 3131{
3115 struct CadetTunnel *t = cls; 3132 struct CadetTunnel *t = cls;
3116 3133
3117 GNUNET_assert(NULL != t->current_ct); 3134 GNUNET_assert (NULL != t->current_ct);
3118 GNUNET_MQ_inject_message(t->mq, 3135 GNUNET_MQ_inject_message (t->mq,
3119 msg); 3136 msg);
3120 return GNUNET_OK; 3137 return GNUNET_OK;
3121} 3138}
3122 3139
@@ -3129,10 +3146,10 @@ handle_decrypted(void *cls,
3129 * @param error error code 3146 * @param error error code
3130 */ 3147 */
3131static void 3148static void
3132decrypted_error_cb(void *cls, 3149decrypted_error_cb (void *cls,
3133 enum GNUNET_MQ_Error error) 3150 enum GNUNET_MQ_Error error)
3134{ 3151{
3135 GNUNET_break_op(0); 3152 GNUNET_break_op (0);
3136} 3153}
3137 3154
3138 3155
@@ -3144,55 +3161,55 @@ decrypted_error_cb(void *cls,
3144 * @return new tunnel to @a destination 3161 * @return new tunnel to @a destination
3145 */ 3162 */
3146struct CadetTunnel * 3163struct CadetTunnel *
3147GCT_create_tunnel(struct CadetPeer *destination) 3164GCT_create_tunnel (struct CadetPeer *destination)
3148{ 3165{
3149 struct CadetTunnel *t = GNUNET_new(struct CadetTunnel); 3166 struct CadetTunnel *t = GNUNET_new (struct CadetTunnel);
3150 struct GNUNET_MQ_MessageHandler handlers[] = { 3167 struct GNUNET_MQ_MessageHandler handlers[] = {
3151 GNUNET_MQ_hd_fixed_size(plaintext_keepalive, 3168 GNUNET_MQ_hd_fixed_size (plaintext_keepalive,
3152 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE, 3169 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE,
3153 struct GNUNET_MessageHeader, 3170 struct GNUNET_MessageHeader,
3154 t), 3171 t),
3155 GNUNET_MQ_hd_var_size(plaintext_data, 3172 GNUNET_MQ_hd_var_size (plaintext_data,
3156 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA, 3173 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA,
3157 struct GNUNET_CADET_ChannelAppDataMessage, 3174 struct GNUNET_CADET_ChannelAppDataMessage,
3158 t), 3175 t),
3159 GNUNET_MQ_hd_fixed_size(plaintext_data_ack, 3176 GNUNET_MQ_hd_fixed_size (plaintext_data_ack,
3160 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK, 3177 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK,
3161 struct GNUNET_CADET_ChannelDataAckMessage, 3178 struct GNUNET_CADET_ChannelDataAckMessage,
3162 t), 3179 t),
3163 GNUNET_MQ_hd_fixed_size(plaintext_channel_open, 3180 GNUNET_MQ_hd_fixed_size (plaintext_channel_open,
3164 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN, 3181 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN,
3165 struct GNUNET_CADET_ChannelOpenMessage, 3182 struct GNUNET_CADET_ChannelOpenMessage,
3166 t), 3183 t),
3167 GNUNET_MQ_hd_fixed_size(plaintext_channel_open_ack, 3184 GNUNET_MQ_hd_fixed_size (plaintext_channel_open_ack,
3168 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK, 3185 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK,
3169 struct GNUNET_CADET_ChannelOpenAckMessage, 3186 struct GNUNET_CADET_ChannelOpenAckMessage,
3170 t), 3187 t),
3171 GNUNET_MQ_hd_fixed_size(plaintext_channel_destroy, 3188 GNUNET_MQ_hd_fixed_size (plaintext_channel_destroy,
3172 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY, 3189 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY,
3173 struct GNUNET_CADET_ChannelDestroyMessage, 3190 struct GNUNET_CADET_ChannelDestroyMessage,
3174 t), 3191 t),
3175 GNUNET_MQ_handler_end() 3192 GNUNET_MQ_handler_end ()
3176 }; 3193 };
3177 3194
3178 t->kx_retry_delay = INITIAL_KX_RETRY_DELAY; 3195 t->kx_retry_delay = INITIAL_KX_RETRY_DELAY;
3179 new_ephemeral(&t->ax); 3196 new_ephemeral (&t->ax);
3180 GNUNET_assert(GNUNET_OK == 3197 GNUNET_assert (GNUNET_OK ==
3181 GNUNET_CRYPTO_ecdhe_key_create2(&t->ax.kx_0)); 3198 GNUNET_CRYPTO_ecdhe_key_create2 (&t->ax.kx_0));
3182 t->destination = destination; 3199 t->destination = destination;
3183 t->channels = GNUNET_CONTAINER_multihashmap32_create(8); 3200 t->channels = GNUNET_CONTAINER_multihashmap32_create (8);
3184 t->maintain_connections_task 3201 t->maintain_connections_task
3185 = GNUNET_SCHEDULER_add_now(&maintain_connections_cb, 3202 = GNUNET_SCHEDULER_add_now (&maintain_connections_cb,
3186 t); 3203 t);
3187 t->mq = GNUNET_MQ_queue_for_callbacks(NULL, 3204 t->mq = GNUNET_MQ_queue_for_callbacks (NULL,
3188 NULL, 3205 NULL,
3189 NULL, 3206 NULL,
3190 NULL, 3207 NULL,
3191 handlers, 3208 handlers,
3192 &decrypted_error_cb, 3209 &decrypted_error_cb,
3193 t); 3210 t);
3194 t->mst = GNUNET_MST_create(&handle_decrypted, 3211 t->mst = GNUNET_MST_create (&handle_decrypted,
3195 t); 3212 t);
3196 return t; 3213 return t;
3197} 3214}
3198 3215
@@ -3208,42 +3225,43 @@ GCT_create_tunnel(struct CadetPeer *destination)
3208 * #GNUNET_SYSERR on failure (duplicate connection) 3225 * #GNUNET_SYSERR on failure (duplicate connection)
3209 */ 3226 */
3210int 3227int
3211GCT_add_inbound_connection(struct CadetTunnel *t, 3228GCT_add_inbound_connection (struct CadetTunnel *t,
3212 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 3229 const struct
3213 struct CadetPeerPath *path) 3230 GNUNET_CADET_ConnectionTunnelIdentifier *cid,
3231 struct CadetPeerPath *path)
3214{ 3232{
3215 struct CadetTConnection *ct; 3233 struct CadetTConnection *ct;
3216 3234
3217 ct = GNUNET_new(struct CadetTConnection); 3235 ct = GNUNET_new (struct CadetTConnection);
3218 ct->created = GNUNET_TIME_absolute_get(); 3236 ct->created = GNUNET_TIME_absolute_get ();
3219 ct->t = t; 3237 ct->t = t;
3220 ct->cc = GCC_create_inbound(t->destination, 3238 ct->cc = GCC_create_inbound (t->destination,
3221 path, 3239 path,
3222 ct, 3240 ct,
3223 cid, 3241 cid,
3224 &connection_ready_cb, 3242 &connection_ready_cb,
3225 ct); 3243 ct);
3226 if (NULL == ct->cc) 3244 if (NULL == ct->cc)
3227 { 3245 {
3228 LOG(GNUNET_ERROR_TYPE_DEBUG, 3246 LOG (GNUNET_ERROR_TYPE_DEBUG,
3229 "%s refused inbound %s (duplicate)\n", 3247 "%s refused inbound %s (duplicate)\n",
3230 GCT_2s(t), 3248 GCT_2s (t),
3231 GCC_2s(ct->cc)); 3249 GCC_2s (ct->cc));
3232 GNUNET_free(ct); 3250 GNUNET_free (ct);
3233 return GNUNET_SYSERR; 3251 return GNUNET_SYSERR;
3234 } 3252 }
3235 /* FIXME: schedule job to kill connection (and path?) if it takes 3253 /* FIXME: schedule job to kill connection (and path?) if it takes
3236 too long to get ready! (And track performance data on how long 3254 too long to get ready! (And track performance data on how long
3237 other connections took with the tunnel!) 3255 other connections took with the tunnel!)
3238 => Note: to be done within 'connection'-logic! */ 3256 => Note: to be done within 'connection'-logic! */
3239 GNUNET_CONTAINER_DLL_insert(t->connection_busy_head, 3257 GNUNET_CONTAINER_DLL_insert (t->connection_busy_head,
3240 t->connection_busy_tail, 3258 t->connection_busy_tail,
3241 ct); 3259 ct);
3242 t->num_busy_connections++; 3260 t->num_busy_connections++;
3243 LOG(GNUNET_ERROR_TYPE_DEBUG, 3261 LOG (GNUNET_ERROR_TYPE_DEBUG,
3244 "%s has new %s\n", 3262 "%s has new %s\n",
3245 GCT_2s(t), 3263 GCT_2s (t),
3246 GCC_2s(ct->cc)); 3264 GCC_2s (ct->cc));
3247 return GNUNET_OK; 3265 return GNUNET_OK;
3248} 3266}
3249 3267
@@ -3255,177 +3273,177 @@ GCT_add_inbound_connection(struct CadetTunnel *t,
3255 * @param msg the encrypted message to decrypt 3273 * @param msg the encrypted message to decrypt
3256 */ 3274 */
3257void 3275void
3258GCT_handle_encrypted(struct CadetTConnection *ct, 3276GCT_handle_encrypted (struct CadetTConnection *ct,
3259 const struct GNUNET_CADET_TunnelEncryptedMessage *msg) 3277 const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
3260{ 3278{
3261 struct CadetTunnel *t = ct->t; 3279 struct CadetTunnel *t = ct->t;
3262 uint16_t size = ntohs(msg->header.size); 3280 uint16_t size = ntohs (msg->header.size);
3263 char cbuf [size] GNUNET_ALIGN; 3281 char cbuf [size] GNUNET_ALIGN;
3264 ssize_t decrypted_size; 3282 ssize_t decrypted_size;
3265 3283
3266 LOG(GNUNET_ERROR_TYPE_DEBUG, 3284 LOG (GNUNET_ERROR_TYPE_DEBUG,
3267 "%s received %u bytes of encrypted data in state %d\n", 3285 "%s received %u bytes of encrypted data in state %d\n",
3268 GCT_2s(t), 3286 GCT_2s (t),
3269 (unsigned int)size, 3287 (unsigned int) size,
3270 t->estate); 3288 t->estate);
3271 3289
3272 switch (t->estate) 3290 switch (t->estate)
3273 { 3291 {
3274 case CADET_TUNNEL_KEY_UNINITIALIZED: 3292 case CADET_TUNNEL_KEY_UNINITIALIZED:
3275 case CADET_TUNNEL_KEY_AX_RECV: 3293 case CADET_TUNNEL_KEY_AX_RECV:
3276 /* We did not even SEND our KX, how can the other peer 3294 /* We did not even SEND our KX, how can the other peer
3277 send us encrypted data? Must have been that we went 3295 send us encrypted data? Must have been that we went
3278 down and the other peer still things we are up. 3296 down and the other peer still things we are up.
3279 Let's send it KX back. */ 3297 Let's send it KX back. */
3280 GNUNET_STATISTICS_update(stats, 3298 GNUNET_STATISTICS_update (stats,
3281 "# received encrypted without any KX", 3299 "# received encrypted without any KX",
3282 1, 3300 1,
3283 GNUNET_NO); 3301 GNUNET_NO);
3284 if (NULL != t->kx_task) 3302 if (NULL != t->kx_task)
3285 { 3303 {
3286 GNUNET_SCHEDULER_cancel(t->kx_task); 3304 GNUNET_SCHEDULER_cancel (t->kx_task);
3287 t->kx_task = NULL; 3305 t->kx_task = NULL;
3288 } 3306 }
3289 send_kx(t, 3307 send_kx (t,
3290 ct, 3308 ct,
3291 &t->ax); 3309 &t->ax);
3292 return; 3310 return;
3293
3294 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
3295 /* We send KX, and other peer send KX to us at the same time.
3296 Neither KX is AUTH'ed, so let's try KX_AUTH this time. */
3297 GNUNET_STATISTICS_update(stats,
3298 "# received encrypted without KX_AUTH",
3299 1,
3300 GNUNET_NO);
3301 if (NULL != t->kx_task)
3302 {
3303 GNUNET_SCHEDULER_cancel(t->kx_task);
3304 t->kx_task = NULL;
3305 }
3306 send_kx_auth(t,
3307 ct,
3308 &t->ax,
3309 GNUNET_YES);
3310 return;
3311 3311
3312 case CADET_TUNNEL_KEY_AX_SENT: 3312 case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
3313 /* We did not get the KX of the other peer, but that 3313 /* We send KX, and other peer send KX to us at the same time.
3314 might have been lost. Send our KX again immediately. */ 3314 Neither KX is AUTH'ed, so let's try KX_AUTH this time. */
3315 GNUNET_STATISTICS_update(stats, 3315 GNUNET_STATISTICS_update (stats,
3316 "# received encrypted without KX", 3316 "# received encrypted without KX_AUTH",
3317 1, 3317 1,
3318 GNUNET_NO); 3318 GNUNET_NO);
3319 if (NULL != t->kx_task) 3319 if (NULL != t->kx_task)
3320 { 3320 {
3321 GNUNET_SCHEDULER_cancel(t->kx_task); 3321 GNUNET_SCHEDULER_cancel (t->kx_task);
3322 t->kx_task = NULL; 3322 t->kx_task = NULL;
3323 } 3323 }
3324 send_kx(t, 3324 send_kx_auth (t,
3325 ct, 3325 ct,
3326 &t->ax); 3326 &t->ax,
3327 return; 3327 GNUNET_YES);
3328 return;
3328 3329
3329 case CADET_TUNNEL_KEY_AX_AUTH_SENT: 3330 case CADET_TUNNEL_KEY_AX_SENT:
3330 /* Great, first payload, we might graduate to OK! */ 3331 /* We did not get the KX of the other peer, but that
3331 case CADET_TUNNEL_KEY_OK: 3332 might have been lost. Send our KX again immediately. */
3332 /* We are up and running, all good. */ 3333 GNUNET_STATISTICS_update (stats,
3333 break; 3334 "# received encrypted without KX",
3335 1,
3336 GNUNET_NO);
3337 if (NULL != t->kx_task)
3338 {
3339 GNUNET_SCHEDULER_cancel (t->kx_task);
3340 t->kx_task = NULL;
3334 } 3341 }
3342 send_kx (t,
3343 ct,
3344 &t->ax);
3345 return;
3346
3347 case CADET_TUNNEL_KEY_AX_AUTH_SENT:
3348 /* Great, first payload, we might graduate to OK! */
3349 case CADET_TUNNEL_KEY_OK:
3350 /* We are up and running, all good. */
3351 break;
3352 }
3335 3353
3336 decrypted_size = -1; 3354 decrypted_size = -1;
3337 if (CADET_TUNNEL_KEY_OK == t->estate) 3355 if (CADET_TUNNEL_KEY_OK == t->estate)
3338 { 3356 {
3339 /* We have well-established key material available, 3357 /* We have well-established key material available,
3340 try that. (This is the common case.) */ 3358 try that. (This is the common case.) */
3341 decrypted_size = t_ax_decrypt_and_validate(&t->ax, 3359 decrypted_size = t_ax_decrypt_and_validate (&t->ax,
3342 cbuf, 3360 cbuf,
3343 msg, 3361 msg,
3344 size); 3362 size);
3345 } 3363 }
3346 3364
3347 if ((-1 == decrypted_size) && 3365 if ((-1 == decrypted_size) &&
3348 (NULL != t->unverified_ax)) 3366 (NULL != t->unverified_ax))
3367 {
3368 /* We have un-authenticated KX material available. We should try
3369 this as a back-up option, in case the sender crashed and
3370 switched keys. */
3371 decrypted_size = t_ax_decrypt_and_validate (t->unverified_ax,
3372 cbuf,
3373 msg,
3374 size);
3375 if (-1 != decrypted_size)
3376 {
3377 /* It worked! Treat this as authentication of the AX data! */
3378 cleanup_ax (&t->ax);
3379 t->ax = *t->unverified_ax;
3380 GNUNET_free (t->unverified_ax);
3381 t->unverified_ax = NULL;
3382 }
3383 if (CADET_TUNNEL_KEY_AX_AUTH_SENT == t->estate)
3349 { 3384 {
3350 /* We have un-authenticated KX material available. We should try 3385 /* First time it worked, move tunnel into production! */
3351 this as a back-up option, in case the sender crashed and 3386 GCT_change_estate (t,
3352 switched keys. */ 3387 CADET_TUNNEL_KEY_OK);
3353 decrypted_size = t_ax_decrypt_and_validate(t->unverified_ax, 3388 if (NULL != t->send_task)
3354 cbuf, 3389 GNUNET_SCHEDULER_cancel (t->send_task);
3355 msg, 3390 t->send_task = GNUNET_SCHEDULER_add_now (&trigger_transmissions,
3356 size); 3391 t);
3357 if (-1 != decrypted_size)
3358 {
3359 /* It worked! Treat this as authentication of the AX data! */
3360 cleanup_ax(&t->ax);
3361 t->ax = *t->unverified_ax;
3362 GNUNET_free(t->unverified_ax);
3363 t->unverified_ax = NULL;
3364 }
3365 if (CADET_TUNNEL_KEY_AX_AUTH_SENT == t->estate)
3366 {
3367 /* First time it worked, move tunnel into production! */
3368 GCT_change_estate(t,
3369 CADET_TUNNEL_KEY_OK);
3370 if (NULL != t->send_task)
3371 GNUNET_SCHEDULER_cancel(t->send_task);
3372 t->send_task = GNUNET_SCHEDULER_add_now(&trigger_transmissions,
3373 t);
3374 }
3375 } 3392 }
3393 }
3376 if (NULL != t->unverified_ax) 3394 if (NULL != t->unverified_ax)
3377 { 3395 {
3378 /* We had unverified KX material that was useless; so increment 3396 /* We had unverified KX material that was useless; so increment
3379 counter and eventually move to ignore it. Note that we even do 3397 counter and eventually move to ignore it. Note that we even do
3380 this increment if we successfully decrypted with the old KX 3398 this increment if we successfully decrypted with the old KX
3381 material and thus didn't even both with the new one. This is 3399 material and thus didn't even both with the new one. This is
3382 the ideal case, as a malicious injection of bogus KX data 3400 the ideal case, as a malicious injection of bogus KX data
3383 basically only causes us to increment a counter a few times. */ 3401 basically only causes us to increment a counter a few times. */
3384 t->unverified_attempts++; 3402 t->unverified_attempts++;
3385 LOG(GNUNET_ERROR_TYPE_DEBUG, 3403 LOG (GNUNET_ERROR_TYPE_DEBUG,
3386 "Failed to decrypt message with unverified KX data %u times\n", 3404 "Failed to decrypt message with unverified KX data %u times\n",
3387 t->unverified_attempts); 3405 t->unverified_attempts);
3388 if (t->unverified_attempts > MAX_UNVERIFIED_ATTEMPTS) 3406 if (t->unverified_attempts > MAX_UNVERIFIED_ATTEMPTS)
3389 { 3407 {
3390 cleanup_ax(t->unverified_ax); 3408 cleanup_ax (t->unverified_ax);
3391 GNUNET_free(t->unverified_ax); 3409 GNUNET_free (t->unverified_ax);
3392 t->unverified_ax = NULL; 3410 t->unverified_ax = NULL;
3393 }
3394 } 3411 }
3412 }
3395 3413
3396 if (-1 == decrypted_size) 3414 if (-1 == decrypted_size)
3397 { 3415 {
3398 /* Decryption failed for good, complain. */ 3416 /* Decryption failed for good, complain. */
3399 LOG(GNUNET_ERROR_TYPE_WARNING, 3417 LOG (GNUNET_ERROR_TYPE_WARNING,
3400 "%s failed to decrypt and validate encrypted data, retrying KX\n", 3418 "%s failed to decrypt and validate encrypted data, retrying KX\n",
3401 GCT_2s(t)); 3419 GCT_2s (t));
3402 GNUNET_STATISTICS_update(stats, 3420 GNUNET_STATISTICS_update (stats,
3403 "# unable to decrypt", 3421 "# unable to decrypt",
3404 1, 3422 1,
3405 GNUNET_NO); 3423 GNUNET_NO);
3406 if (NULL != t->kx_task) 3424 if (NULL != t->kx_task)
3407 { 3425 {
3408 GNUNET_SCHEDULER_cancel(t->kx_task); 3426 GNUNET_SCHEDULER_cancel (t->kx_task);
3409 t->kx_task = NULL; 3427 t->kx_task = NULL;
3410 }
3411 send_kx(t,
3412 ct,
3413 &t->ax);
3414 return;
3415 } 3428 }
3416 GNUNET_STATISTICS_update(stats, 3429 send_kx (t,
3417 "# decrypted bytes", 3430 ct,
3418 decrypted_size, 3431 &t->ax);
3419 GNUNET_NO); 3432 return;
3433 }
3434 GNUNET_STATISTICS_update (stats,
3435 "# decrypted bytes",
3436 decrypted_size,
3437 GNUNET_NO);
3420 3438
3421 /* The MST will ultimately call #handle_decrypted() on each message. */ 3439 /* The MST will ultimately call #handle_decrypted() on each message. */
3422 t->current_ct = ct; 3440 t->current_ct = ct;
3423 GNUNET_break_op(GNUNET_OK == 3441 GNUNET_break_op (GNUNET_OK ==
3424 GNUNET_MST_from_buffer(t->mst, 3442 GNUNET_MST_from_buffer (t->mst,
3425 cbuf, 3443 cbuf,
3426 decrypted_size, 3444 decrypted_size,
3427 GNUNET_YES, 3445 GNUNET_YES,
3428 GNUNET_NO)); 3446 GNUNET_NO));
3429 t->current_ct = NULL; 3447 t->current_ct = NULL;
3430} 3448}
3431 3449
@@ -3441,10 +3459,10 @@ GCT_handle_encrypted(struct CadetTConnection *ct,
3441 * @return Handle to cancel message 3459 * @return Handle to cancel message
3442 */ 3460 */
3443struct CadetTunnelQueueEntry * 3461struct CadetTunnelQueueEntry *
3444GCT_send(struct CadetTunnel *t, 3462GCT_send (struct CadetTunnel *t,
3445 const struct GNUNET_MessageHeader *message, 3463 const struct GNUNET_MessageHeader *message,
3446 GCT_SendContinuation cont, 3464 GCT_SendContinuation cont,
3447 void *cont_cls) 3465 void *cont_cls)
3448{ 3466{
3449 struct CadetTunnelQueueEntry *tq; 3467 struct CadetTunnelQueueEntry *tq;
3450 uint16_t payload_size; 3468 uint16_t payload_size;
@@ -3452,55 +3470,55 @@ GCT_send(struct CadetTunnel *t,
3452 struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg; 3470 struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg;
3453 3471
3454 if (CADET_TUNNEL_KEY_OK != t->estate) 3472 if (CADET_TUNNEL_KEY_OK != t->estate)
3455 { 3473 {
3456 GNUNET_break(0); 3474 GNUNET_break (0);
3457 return NULL; 3475 return NULL;
3458 } 3476 }
3459 payload_size = ntohs(message->size); 3477 payload_size = ntohs (message->size);
3460 LOG(GNUNET_ERROR_TYPE_DEBUG, 3478 LOG (GNUNET_ERROR_TYPE_DEBUG,
3461 "Encrypting %u bytes for %s\n", 3479 "Encrypting %u bytes for %s\n",
3462 (unsigned int)payload_size, 3480 (unsigned int) payload_size,
3463 GCT_2s(t)); 3481 GCT_2s (t));
3464 env = GNUNET_MQ_msg_extra(ax_msg, 3482 env = GNUNET_MQ_msg_extra (ax_msg,
3483 payload_size,
3484 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED);
3485 t_ax_encrypt (&t->ax,
3486 &ax_msg[1],
3487 message,
3488 payload_size);
3489 GNUNET_STATISTICS_update (stats,
3490 "# encrypted bytes",
3465 payload_size, 3491 payload_size,
3466 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED); 3492 GNUNET_NO);
3467 t_ax_encrypt(&t->ax, 3493 ax_msg->ax_header.Ns = htonl (t->ax.Ns++);
3468 &ax_msg[1], 3494 ax_msg->ax_header.PNs = htonl (t->ax.PNs);
3469 message,
3470 payload_size);
3471 GNUNET_STATISTICS_update(stats,
3472 "# encrypted bytes",
3473 payload_size,
3474 GNUNET_NO);
3475 ax_msg->ax_header.Ns = htonl(t->ax.Ns++);
3476 ax_msg->ax_header.PNs = htonl(t->ax.PNs);
3477 /* FIXME: we should do this once, not once per message; 3495 /* FIXME: we should do this once, not once per message;
3478 this is a point multiplication, and DHRs does not 3496 this is a point multiplication, and DHRs does not
3479 change all the time. */ 3497 change all the time. */
3480 GNUNET_CRYPTO_ecdhe_key_get_public(&t->ax.DHRs, 3498 GNUNET_CRYPTO_ecdhe_key_get_public (&t->ax.DHRs,
3481 &ax_msg->ax_header.DHRs); 3499 &ax_msg->ax_header.DHRs);
3482 t_h_encrypt(&t->ax, 3500 t_h_encrypt (&t->ax,
3483 ax_msg); 3501 ax_msg);
3484 t_hmac(&ax_msg->ax_header, 3502 t_hmac (&ax_msg->ax_header,
3485 sizeof(struct GNUNET_CADET_AxHeader) + payload_size, 3503 sizeof(struct GNUNET_CADET_AxHeader) + payload_size,
3486 0, 3504 0,
3487 &t->ax.HKs, 3505 &t->ax.HKs,
3488 &ax_msg->hmac); 3506 &ax_msg->hmac);
3489 3507
3490 tq = GNUNET_malloc(sizeof(*tq)); 3508 tq = GNUNET_malloc (sizeof(*tq));
3491 tq->t = t; 3509 tq->t = t;
3492 tq->env = env; 3510 tq->env = env;
3493 tq->cid = &ax_msg->cid; /* will initialize 'ax_msg->cid' once we know the connection */ 3511 tq->cid = &ax_msg->cid; /* will initialize 'ax_msg->cid' once we know the connection */
3494 tq->cont = cont; 3512 tq->cont = cont;
3495 tq->cont_cls = cont_cls; 3513 tq->cont_cls = cont_cls;
3496 GNUNET_CONTAINER_DLL_insert_tail(t->tq_head, 3514 GNUNET_CONTAINER_DLL_insert_tail (t->tq_head,
3497 t->tq_tail, 3515 t->tq_tail,
3498 tq); 3516 tq);
3499 if (NULL != t->send_task) 3517 if (NULL != t->send_task)
3500 GNUNET_SCHEDULER_cancel(t->send_task); 3518 GNUNET_SCHEDULER_cancel (t->send_task);
3501 t->send_task 3519 t->send_task
3502 = GNUNET_SCHEDULER_add_now(&trigger_transmissions, 3520 = GNUNET_SCHEDULER_add_now (&trigger_transmissions,
3503 t); 3521 t);
3504 return tq; 3522 return tq;
3505} 3523}
3506 3524
@@ -3515,15 +3533,15 @@ GCT_send(struct CadetTunnel *t,
3515 * @param tq Handle to the queue entry to cancel. 3533 * @param tq Handle to the queue entry to cancel.
3516 */ 3534 */
3517void 3535void
3518GCT_send_cancel(struct CadetTunnelQueueEntry *tq) 3536GCT_send_cancel (struct CadetTunnelQueueEntry *tq)
3519{ 3537{
3520 struct CadetTunnel *t = tq->t; 3538 struct CadetTunnel *t = tq->t;
3521 3539
3522 GNUNET_CONTAINER_DLL_remove(t->tq_head, 3540 GNUNET_CONTAINER_DLL_remove (t->tq_head,
3523 t->tq_tail, 3541 t->tq_tail,
3524 tq); 3542 tq);
3525 GNUNET_MQ_discard(tq->env); 3543 GNUNET_MQ_discard (tq->env);
3526 GNUNET_free(tq); 3544 GNUNET_free (tq);
3527} 3545}
3528 3546
3529 3547
@@ -3535,35 +3553,36 @@ GCT_send_cancel(struct CadetTunnelQueueEntry *tq)
3535 * @param iter_cls Closure for @c iter. 3553 * @param iter_cls Closure for @c iter.
3536 */ 3554 */
3537void 3555void
3538GCT_iterate_connections(struct CadetTunnel *t, 3556GCT_iterate_connections (struct CadetTunnel *t,
3539 GCT_ConnectionIterator iter, 3557 GCT_ConnectionIterator iter,
3540 void *iter_cls) 3558 void *iter_cls)
3541{ 3559{
3542 struct CadetTConnection *n; 3560 struct CadetTConnection *n;
3543 3561
3544 for (struct CadetTConnection *ct = t->connection_ready_head; 3562 for (struct CadetTConnection *ct = t->connection_ready_head;
3545 NULL != ct; 3563 NULL != ct;
3546 ct = n) 3564 ct = n)
3547 { 3565 {
3548 n = ct->next; 3566 n = ct->next;
3549 iter(iter_cls, 3567 iter (iter_cls,
3550 ct); 3568 ct);
3551 } 3569 }
3552 for (struct CadetTConnection *ct = t->connection_busy_head; 3570 for (struct CadetTConnection *ct = t->connection_busy_head;
3553 NULL != ct; 3571 NULL != ct;
3554 ct = n) 3572 ct = n)
3555 { 3573 {
3556 n = ct->next; 3574 n = ct->next;
3557 iter(iter_cls, 3575 iter (iter_cls,
3558 ct); 3576 ct);
3559 } 3577 }
3560} 3578}
3561 3579
3562 3580
3563/** 3581/**
3564 * Closure for #iterate_channels_cb. 3582 * Closure for #iterate_channels_cb.
3565 */ 3583 */
3566struct ChanIterCls { 3584struct ChanIterCls
3585{
3567 /** 3586 /**
3568 * Function to call. 3587 * Function to call.
3569 */ 3588 */
@@ -3585,15 +3604,15 @@ struct ChanIterCls {
3585 * @return #GNUNET_OK 3604 * @return #GNUNET_OK
3586 */ 3605 */
3587static int 3606static int
3588iterate_channels_cb(void *cls, 3607iterate_channels_cb (void *cls,
3589 uint32_t key, 3608 uint32_t key,
3590 void *value) 3609 void *value)
3591{ 3610{
3592 struct ChanIterCls *ctx = cls; 3611 struct ChanIterCls *ctx = cls;
3593 struct CadetChannel *ch = value; 3612 struct CadetChannel *ch = value;
3594 3613
3595 ctx->iter(ctx->iter_cls, 3614 ctx->iter (ctx->iter_cls,
3596 ch); 3615 ch);
3597 return GNUNET_OK; 3616 return GNUNET_OK;
3598} 3617}
3599 3618
@@ -3606,17 +3625,17 @@ iterate_channels_cb(void *cls,
3606 * @param iter_cls Closure for @c iter. 3625 * @param iter_cls Closure for @c iter.
3607 */ 3626 */
3608void 3627void
3609GCT_iterate_channels(struct CadetTunnel *t, 3628GCT_iterate_channels (struct CadetTunnel *t,
3610 GCT_ChannelIterator iter, 3629 GCT_ChannelIterator iter,
3611 void *iter_cls) 3630 void *iter_cls)
3612{ 3631{
3613 struct ChanIterCls ctx; 3632 struct ChanIterCls ctx;
3614 3633
3615 ctx.iter = iter; 3634 ctx.iter = iter;
3616 ctx.iter_cls = iter_cls; 3635 ctx.iter_cls = iter_cls;
3617 GNUNET_CONTAINER_multihashmap32_iterate(t->channels, 3636 GNUNET_CONTAINER_multihashmap32_iterate (t->channels,
3618 &iterate_channels_cb, 3637 &iterate_channels_cb,
3619 &ctx); 3638 &ctx);
3620} 3639}
3621 3640
3622 3641
@@ -3629,19 +3648,20 @@ GCT_iterate_channels(struct CadetTunnel *t,
3629 * @return #GNUNET_OK (continue iteration) 3648 * @return #GNUNET_OK (continue iteration)
3630 */ 3649 */
3631static int 3650static int
3632debug_channel(void *cls, 3651debug_channel (void *cls,
3633 uint32_t key, 3652 uint32_t key,
3634 void *value) 3653 void *value)
3635{ 3654{
3636 const enum GNUNET_ErrorType *level = cls; 3655 const enum GNUNET_ErrorType *level = cls;
3637 struct CadetChannel *ch = value; 3656 struct CadetChannel *ch = value;
3638 3657
3639 GCCH_debug(ch, *level); 3658 GCCH_debug (ch, *level);
3640 return GNUNET_OK; 3659 return GNUNET_OK;
3641} 3660}
3642 3661
3643 3662
3644#define LOG2(level, ...) GNUNET_log_from_nocheck(level, "cadet-tun", __VA_ARGS__) 3663#define LOG2(level, ...) GNUNET_log_from_nocheck (level, "cadet-tun", \
3664 __VA_ARGS__)
3645 3665
3646 3666
3647/** 3667/**
@@ -3651,41 +3671,41 @@ debug_channel(void *cls,
3651 * @param level Debug level to use. 3671 * @param level Debug level to use.
3652 */ 3672 */
3653void 3673void
3654GCT_debug(const struct CadetTunnel *t, 3674GCT_debug (const struct CadetTunnel *t,
3655 enum GNUNET_ErrorType level) 3675 enum GNUNET_ErrorType level)
3656{ 3676{
3657#if !defined(GNUNET_CULL_LOGGING) 3677#if ! defined(GNUNET_CULL_LOGGING)
3658 struct CadetTConnection *iter_c; 3678 struct CadetTConnection *iter_c;
3659 int do_log; 3679 int do_log;
3660 3680
3661 do_log = GNUNET_get_log_call_status(level & (~GNUNET_ERROR_TYPE_BULK), 3681 do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK),
3662 "cadet-tun", 3682 "cadet-tun",
3663 __FILE__, __FUNCTION__, __LINE__); 3683 __FILE__, __FUNCTION__, __LINE__);
3664 if (0 == do_log) 3684 if (0 == do_log)
3665 return; 3685 return;
3666 3686
3667 LOG2(level, 3687 LOG2 (level,
3668 "TTT TUNNEL TOWARDS %s in estate %s tq_len: %u #cons: %u\n", 3688 "TTT TUNNEL TOWARDS %s in estate %s tq_len: %u #cons: %u\n",
3669 GCT_2s(t), 3689 GCT_2s (t),
3670 estate2s(t->estate), 3690 estate2s (t->estate),
3671 t->tq_len, 3691 t->tq_len,
3672 GCT_count_any_connections(t)); 3692 GCT_count_any_connections (t));
3673 LOG2(level, 3693 LOG2 (level,
3674 "TTT channels:\n"); 3694 "TTT channels:\n");
3675 GNUNET_CONTAINER_multihashmap32_iterate(t->channels, 3695 GNUNET_CONTAINER_multihashmap32_iterate (t->channels,
3676 &debug_channel, 3696 &debug_channel,
3677 &level); 3697 &level);
3678 LOG2(level, 3698 LOG2 (level,
3679 "TTT connections:\n"); 3699 "TTT connections:\n");
3680 for (iter_c = t->connection_ready_head; NULL != iter_c; iter_c = iter_c->next) 3700 for (iter_c = t->connection_ready_head; NULL != iter_c; iter_c = iter_c->next)
3681 GCC_debug(iter_c->cc, 3701 GCC_debug (iter_c->cc,
3682 level); 3702 level);
3683 for (iter_c = t->connection_busy_head; NULL != iter_c; iter_c = iter_c->next) 3703 for (iter_c = t->connection_busy_head; NULL != iter_c; iter_c = iter_c->next)
3684 GCC_debug(iter_c->cc, 3704 GCC_debug (iter_c->cc,
3685 level); 3705 level);
3686 3706
3687 LOG2(level, 3707 LOG2 (level,
3688 "TTT TUNNEL END\n"); 3708 "TTT TUNNEL END\n");
3689#endif 3709#endif
3690} 3710}
3691 3711
diff --git a/src/cadet/gnunet-service-cadet_tunnels.h b/src/cadet/gnunet-service-cadet_tunnels.h
index 0df35cd23..ef07badea 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.h
+++ b/src/cadet/gnunet-service-cadet_tunnels.h
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of GNUnet. 2 This file is part of GNUnet.
4 Copyright (C) 2001-2017 GNUnet e.V. 3 Copyright (C) 2001-2017 GNUnet e.V.
@@ -41,7 +40,8 @@
41/** 40/**
42 * All the encryption states a tunnel can be in. 41 * All the encryption states a tunnel can be in.
43 */ 42 */
44enum CadetTunnelEState { 43enum CadetTunnelEState
44{
45 /** 45 /**
46 * Uninitialized status, we need to send KX. We will stay 46 * Uninitialized status, we need to send KX. We will stay
47 * in this state until the first connection is up. 47 * in this state until the first connection is up.
@@ -89,7 +89,7 @@ enum CadetTunnelEState {
89 * @return Static string the destination peer's ID. 89 * @return Static string the destination peer's ID.
90 */ 90 */
91const char * 91const char *
92GCT_2s(const struct CadetTunnel *t); 92GCT_2s (const struct CadetTunnel *t);
93 93
94 94
95/** 95/**
@@ -100,7 +100,7 @@ GCT_2s(const struct CadetTunnel *t);
100 * @return new tunnel to @a destination 100 * @return new tunnel to @a destination
101 */ 101 */
102struct CadetTunnel * 102struct CadetTunnel *
103GCT_create_tunnel(struct CadetPeer *destination); 103GCT_create_tunnel (struct CadetPeer *destination);
104 104
105 105
106/** 106/**
@@ -109,7 +109,7 @@ GCT_create_tunnel(struct CadetPeer *destination);
109 * @param t tunnel to destroy 109 * @param t tunnel to destroy
110 */ 110 */
111void 111void
112GCT_destroy_tunnel_now(struct CadetTunnel *t); 112GCT_destroy_tunnel_now (struct CadetTunnel *t);
113 113
114 114
115/** 115/**
@@ -122,9 +122,10 @@ GCT_destroy_tunnel_now(struct CadetTunnel *t);
122 * #GNUNET_SYSERR on failure (duplicate connection) 122 * #GNUNET_SYSERR on failure (duplicate connection)
123 */ 123 */
124int 124int
125GCT_add_inbound_connection(struct CadetTunnel *t, 125GCT_add_inbound_connection (struct CadetTunnel *t,
126 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 126 const struct
127 struct CadetPeerPath *path); 127 GNUNET_CADET_ConnectionTunnelIdentifier *cid,
128 struct CadetPeerPath *path);
128 129
129 130
130/** 131/**
@@ -134,7 +135,7 @@ GCT_add_inbound_connection(struct CadetTunnel *t,
134 * @param ct binding of connection to tunnel of the connection that was lost. 135 * @param ct binding of connection to tunnel of the connection that was lost.
135 */ 136 */
136void 137void
137GCT_connection_lost(struct CadetTConnection *ct); 138GCT_connection_lost (struct CadetTConnection *ct);
138 139
139 140
140/** 141/**
@@ -144,7 +145,7 @@ GCT_connection_lost(struct CadetTConnection *ct);
144 * @return the destination of the tunnel 145 * @return the destination of the tunnel
145 */ 146 */
146struct CadetPeer * 147struct CadetPeer *
147GCT_get_destination(struct CadetTunnel *t); 148GCT_get_destination (struct CadetTunnel *t);
148 149
149 150
150/** 151/**
@@ -156,9 +157,9 @@ GCT_get_destination(struct CadetTunnel *t);
156 * @param off offset of the destination on path @a path 157 * @param off offset of the destination on path @a path
157 */ 158 */
158void 159void
159GCT_consider_path(struct CadetTunnel *t, 160GCT_consider_path (struct CadetTunnel *t,
160 struct CadetPeerPath *p, 161 struct CadetPeerPath *p,
161 unsigned int off); 162 unsigned int off);
162 163
163 164
164/** 165/**
@@ -169,8 +170,8 @@ GCT_consider_path(struct CadetTunnel *t,
169 * @return unique number identifying @a ch within @a t 170 * @return unique number identifying @a ch within @a t
170 */ 171 */
171struct GNUNET_CADET_ChannelTunnelNumber 172struct GNUNET_CADET_ChannelTunnelNumber
172GCT_add_channel(struct CadetTunnel *t, 173GCT_add_channel (struct CadetTunnel *t,
173 struct CadetChannel *ch); 174 struct CadetChannel *ch);
174 175
175 176
176/** 177/**
@@ -181,9 +182,9 @@ GCT_add_channel(struct CadetTunnel *t,
181 * @param ctn unique number identifying @a ch within @a t 182 * @param ctn unique number identifying @a ch within @a t
182 */ 183 */
183void 184void
184GCT_remove_channel(struct CadetTunnel *t, 185GCT_remove_channel (struct CadetTunnel *t,
185 struct CadetChannel *ch, 186 struct CadetChannel *ch,
186 struct GNUNET_CADET_ChannelTunnelNumber ctn); 187 struct GNUNET_CADET_ChannelTunnelNumber ctn);
187 188
188 189
189/** 190/**
@@ -193,8 +194,8 @@ GCT_remove_channel(struct CadetTunnel *t,
193 * @param ctn ID of the channel to destroy 194 * @param ctn ID of the channel to destroy
194 */ 195 */
195void 196void
196GCT_send_channel_destroy(struct CadetTunnel *t, 197GCT_send_channel_destroy (struct CadetTunnel *t,
197 struct GNUNET_CADET_ChannelTunnelNumber ctn); 198 struct GNUNET_CADET_ChannelTunnelNumber ctn);
198 199
199 200
200/** 201/**
@@ -207,7 +208,8 @@ GCT_send_channel_destroy(struct CadetTunnel *t,
207 */ 208 */
208typedef void 209typedef void
209(*GCT_SendContinuation)(void *cls, 210(*GCT_SendContinuation)(void *cls,
210 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid); 211 const struct
212 GNUNET_CADET_ConnectionTunnelIdentifier *cid);
211 213
212 214
213/** 215/**
@@ -221,10 +223,10 @@ typedef void
221 * @return Handle to cancel message. 223 * @return Handle to cancel message.
222 */ 224 */
223struct CadetTunnelQueueEntry * 225struct CadetTunnelQueueEntry *
224GCT_send(struct CadetTunnel *t, 226GCT_send (struct CadetTunnel *t,
225 const struct GNUNET_MessageHeader *message, 227 const struct GNUNET_MessageHeader *message,
226 GCT_SendContinuation cont, 228 GCT_SendContinuation cont,
227 void *cont_cls); 229 void *cont_cls);
228 230
229 231
230/** 232/**
@@ -237,7 +239,7 @@ GCT_send(struct CadetTunnel *t,
237 * @param q Handle to the queue entry to cancel. 239 * @param q Handle to the queue entry to cancel.
238 */ 240 */
239void 241void
240GCT_send_cancel(struct CadetTunnelQueueEntry *q); 242GCT_send_cancel (struct CadetTunnelQueueEntry *q);
241 243
242 244
243/** 245/**
@@ -247,7 +249,7 @@ GCT_send_cancel(struct CadetTunnelQueueEntry *q);
247 * @return number of channels using the tunnel 249 * @return number of channels using the tunnel
248 */ 250 */
249unsigned int 251unsigned int
250GCT_count_channels(struct CadetTunnel *t); 252GCT_count_channels (struct CadetTunnel *t);
251 253
252 254
253/** 255/**
@@ -257,7 +259,7 @@ GCT_count_channels(struct CadetTunnel *t);
257 * @return number of connections available for the tunnel 259 * @return number of connections available for the tunnel
258 */ 260 */
259unsigned int 261unsigned int
260GCT_count_any_connections(const struct CadetTunnel *t); 262GCT_count_any_connections (const struct CadetTunnel *t);
261 263
262 264
263/** 265/**
@@ -279,9 +281,9 @@ typedef void
279 * @param iter_cls Closure for @c iter. 281 * @param iter_cls Closure for @c iter.
280 */ 282 */
281void 283void
282GCT_iterate_connections(struct CadetTunnel *t, 284GCT_iterate_connections (struct CadetTunnel *t,
283 GCT_ConnectionIterator iter, 285 GCT_ConnectionIterator iter,
284 void *iter_cls); 286 void *iter_cls);
285 287
286 288
287/** 289/**
@@ -303,9 +305,9 @@ typedef void
303 * @param iter_cls Closure for @c iter. 305 * @param iter_cls Closure for @c iter.
304 */ 306 */
305void 307void
306GCT_iterate_channels(struct CadetTunnel *t, 308GCT_iterate_channels (struct CadetTunnel *t,
307 GCT_ChannelIterator iter, 309 GCT_ChannelIterator iter,
308 void *iter_cls); 310 void *iter_cls);
309 311
310 312
311/** 313/**
@@ -316,7 +318,7 @@ GCT_iterate_channels(struct CadetTunnel *t,
316 * @return Tunnel's encryption state. 318 * @return Tunnel's encryption state.
317 */ 319 */
318enum CadetTunnelEState 320enum CadetTunnelEState
319GCT_get_estate(struct CadetTunnel *t); 321GCT_get_estate (struct CadetTunnel *t);
320 322
321 323
322/** 324/**
@@ -326,8 +328,8 @@ GCT_get_estate(struct CadetTunnel *t);
326 * @param msg the key exchange message 328 * @param msg the key exchange message
327 */ 329 */
328void 330void
329GCT_handle_kx(struct CadetTConnection *ct, 331GCT_handle_kx (struct CadetTConnection *ct,
330 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg); 332 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
331 333
332 334
333/** 335/**
@@ -337,8 +339,9 @@ GCT_handle_kx(struct CadetTConnection *ct,
337 * @param msg the key exchange message 339 * @param msg the key exchange message
338 */ 340 */
339void 341void
340GCT_handle_kx_auth(struct CadetTConnection *ct, 342GCT_handle_kx_auth (struct CadetTConnection *ct,
341 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg); 343 const struct
344 GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
342 345
343 346
344/** 347/**
@@ -348,8 +351,8 @@ GCT_handle_kx_auth(struct CadetTConnection *ct,
348 * @param msg the encrypted message to decrypt 351 * @param msg the encrypted message to decrypt
349 */ 352 */
350void 353void
351GCT_handle_encrypted(struct CadetTConnection *ct, 354GCT_handle_encrypted (struct CadetTConnection *ct,
352 const struct GNUNET_CADET_TunnelEncryptedMessage *msg); 355 const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
353 356
354 357
355/** 358/**
@@ -359,8 +362,8 @@ GCT_handle_encrypted(struct CadetTConnection *ct,
359 * @param level Debug level to use. 362 * @param level Debug level to use.
360 */ 363 */
361void 364void
362GCT_debug(const struct CadetTunnel *t, 365GCT_debug (const struct CadetTunnel *t,
363 enum GNUNET_ErrorType level); 366 enum GNUNET_ErrorType level);
364 367
365 368
366#endif 369#endif
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index de5e4eef0..354593c4b 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -34,7 +34,8 @@
34/** 34/**
35 * Ugly workaround to unify data handlers on incoming and outgoing channels. 35 * Ugly workaround to unify data handlers on incoming and outgoing channels.
36 */ 36 */
37struct CadetTestChannelWrapper { 37struct CadetTestChannelWrapper
38{
38 /** 39 /**
39 * Channel pointer. 40 * Channel pointer.
40 */ 41 */
@@ -49,17 +50,18 @@ struct CadetTestChannelWrapper {
49/** 50/**
50 * How long until we give up on connecting the peers? 51 * How long until we give up on connecting the peers?
51 */ 52 */
52#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 53#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
53 54
54/** 55/**
55 * Time to wait by default for stuff that should be rather fast. 56 * Time to wait by default for stuff that should be rather fast.
56 */ 57 */
57#define SHORT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) 58#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
58 59
59/** 60/**
60 * How fast do we send messages? 61 * How fast do we send messages?
61 */ 62 */
62#define SEND_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 10) 63#define SEND_INTERVAL GNUNET_TIME_relative_multiply ( \
64 GNUNET_TIME_UNIT_MILLISECONDS, 10)
63 65
64/** 66/**
65 * DIFFERENT TESTS TO RUN 67 * DIFFERENT TESTS TO RUN
@@ -259,9 +261,9 @@ static unsigned int msg_dropped;
259 * or the last peer in the line (for other tests). 261 * or the last peer in the line (for other tests).
260 */ 262 */
261static struct GNUNET_CADET_Channel * 263static struct GNUNET_CADET_Channel *
262get_target_channel() 264get_target_channel ()
263{ 265{
264 if (SPEED == test && GNUNET_YES == test_backwards) 266 if ((SPEED == test)&&(GNUNET_YES == test_backwards))
265 return outgoing_ch; 267 return outgoing_ch;
266 else 268 else
267 return incoming_ch; 269 return incoming_ch;
@@ -272,29 +274,29 @@ get_target_channel()
272 * Show the results of the test (banwidth acheived) and log them to GAUGER 274 * Show the results of the test (banwidth acheived) and log them to GAUGER
273 */ 275 */
274static void 276static void
275show_end_data(void) 277show_end_data (void)
276{ 278{
277 static struct GNUNET_TIME_Absolute end_time; 279 static struct GNUNET_TIME_Absolute end_time;
278 static struct GNUNET_TIME_Relative total_time; 280 static struct GNUNET_TIME_Relative total_time;
279 281
280 end_time = GNUNET_TIME_absolute_get(); 282 end_time = GNUNET_TIME_absolute_get ();
281 total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time); 283 total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time);
282 fprintf(stderr, 284 fprintf (stderr,
283 "\nResults of test \"%s\"\n", 285 "\nResults of test \"%s\"\n",
284 test_name); 286 test_name);
285 fprintf(stderr, 287 fprintf (stderr,
286 "Test time %s\n", 288 "Test time %s\n",
287 GNUNET_STRINGS_relative_time_to_string(total_time, GNUNET_YES)); 289 GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES));
288 fprintf(stderr, 290 fprintf (stderr,
289 "Test bandwidth: %f kb/s\n", 291 "Test bandwidth: %f kb/s\n",
290 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms 292 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms
291 fprintf(stderr, 293 fprintf (stderr,
292 "Test throughput: %f packets/s\n\n", 294 "Test throughput: %f packets/s\n\n",
293 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms 295 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms
294 GAUGER("CADET", 296 GAUGER ("CADET",
295 test_name, 297 test_name,
296 total_packets * 1000.0 / (total_time.rel_value_us / 1000), 298 total_packets * 1000.0 / (total_time.rel_value_us / 1000),
297 "packets/s"); 299 "packets/s");
298} 300}
299 301
300 302
@@ -305,30 +307,30 @@ show_end_data(void)
305 * @param tc Task Context. 307 * @param tc Task Context.
306 */ 308 */
307static void 309static void
308disconnect_cadet_peers(void *cls) 310disconnect_cadet_peers (void *cls)
309{ 311{
310 long line = (long)cls; 312 long line = (long) cls;
311 313
312 disconnect_task = NULL; 314 disconnect_task = NULL;
313 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
314 "disconnecting cadet service of peers, called from line %ld\n", 316 "disconnecting cadet service of peers, called from line %ld\n",
315 line); 317 line);
316 for (unsigned int i = 0; i < 2; i++) 318 for (unsigned int i = 0; i < 2; i++)
317 { 319 {
318 GNUNET_TESTBED_operation_done(t_op[i]); 320 GNUNET_TESTBED_operation_done (t_op[i]);
319 } 321 }
320 if (NULL != outgoing_ch) 322 if (NULL != outgoing_ch)
321 { 323 {
322 GNUNET_CADET_channel_destroy(outgoing_ch); 324 GNUNET_CADET_channel_destroy (outgoing_ch);
323 outgoing_ch = NULL; 325 outgoing_ch = NULL;
324 } 326 }
325 if (NULL != incoming_ch) 327 if (NULL != incoming_ch)
326 { 328 {
327 GNUNET_CADET_channel_destroy(incoming_ch); 329 GNUNET_CADET_channel_destroy (incoming_ch);
328 incoming_ch = NULL; 330 incoming_ch = NULL;
329 } 331 }
330 GNUNET_CADET_TEST_cleanup(test_ctx); 332 GNUNET_CADET_TEST_cleanup (test_ctx);
331 GNUNET_SCHEDULER_shutdown(); 333 GNUNET_SCHEDULER_shutdown ();
332} 334}
333 335
334 336
@@ -339,27 +341,27 @@ disconnect_cadet_peers(void *cls)
339 * @param tc Task Context. 341 * @param tc Task Context.
340 */ 342 */
341static void 343static void
342shutdown_task(void *cls) 344shutdown_task (void *cls)
343{ 345{
344 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
345 "Ending test.\n"); 347 "Ending test.\n");
346 if (NULL != send_next_msg_task) 348 if (NULL != send_next_msg_task)
347 { 349 {
348 GNUNET_SCHEDULER_cancel(send_next_msg_task); 350 GNUNET_SCHEDULER_cancel (send_next_msg_task);
349 send_next_msg_task = NULL; 351 send_next_msg_task = NULL;
350 } 352 }
351 if (NULL != test_task) 353 if (NULL != test_task)
352 { 354 {
353 GNUNET_SCHEDULER_cancel(test_task); 355 GNUNET_SCHEDULER_cancel (test_task);
354 test_task = NULL; 356 test_task = NULL;
355 } 357 }
356 if (NULL != disconnect_task) 358 if (NULL != disconnect_task)
357 { 359 {
358 GNUNET_SCHEDULER_cancel(disconnect_task); 360 GNUNET_SCHEDULER_cancel (disconnect_task);
359 disconnect_task = 361 disconnect_task =
360 GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 362 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
361 (void *)__LINE__); 363 (void *) __LINE__);
362 } 364 }
363} 365}
364 366
365 367
@@ -373,26 +375,26 @@ shutdown_task(void *cls)
373 * operation has executed successfully. 375 * operation has executed successfully.
374 */ 376 */
375static void 377static void
376stats_cont(void *cls, 378stats_cont (void *cls,
377 struct GNUNET_TESTBED_Operation *op, 379 struct GNUNET_TESTBED_Operation *op,
378 const char *emsg) 380 const char *emsg)
379{ 381{
380 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 382 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
381 "KA sent: %u, KA received: %u\n", 383 "KA sent: %u, KA received: %u\n",
382 ka_sent, 384 ka_sent,
383 ka_received); 385 ka_received);
384 if ((KEEPALIVE == test || REOPEN == test) && 386 if (((KEEPALIVE == test)||(REOPEN == test)) &&
385 ((ka_sent < 2) || (ka_sent > ka_received + 1))) 387 ((ka_sent < 2) || (ka_sent > ka_received + 1)))
386 { 388 {
387 GNUNET_break(0); 389 GNUNET_break (0);
388 ok--; 390 ok--;
389 } 391 }
390 GNUNET_TESTBED_operation_done(stats_op); 392 GNUNET_TESTBED_operation_done (stats_op);
391 393
392 if (NULL != disconnect_task) 394 if (NULL != disconnect_task)
393 GNUNET_SCHEDULER_cancel(disconnect_task); 395 GNUNET_SCHEDULER_cancel (disconnect_task);
394 disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 396 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
395 cls); 397 cls);
396} 398}
397 399
398 400
@@ -408,12 +410,12 @@ stats_cont(void *cls,
408 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 410 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
409 */ 411 */
410static int 412static int
411stats_iterator(void *cls, 413stats_iterator (void *cls,
412 const struct GNUNET_TESTBED_Peer *peer, 414 const struct GNUNET_TESTBED_Peer *peer,
413 const char *subsystem, 415 const char *subsystem,
414 const char *name, 416 const char *name,
415 uint64_t value, 417 uint64_t value,
416 int is_persistent) 418 int is_persistent)
417{ 419{
418 static const char *s_sent = "# keepalives sent"; 420 static const char *s_sent = "# keepalives sent";
419 static const char *s_recv = "# keepalives received"; 421 static const char *s_recv = "# keepalives received";
@@ -421,16 +423,17 @@ stats_iterator(void *cls,
421 static const char *cdrops = "# messages dropped due to slow client"; 423 static const char *cdrops = "# messages dropped due to slow client";
422 uint32_t i; 424 uint32_t i;
423 425
424 i = GNUNET_TESTBED_get_index(peer); 426 i = GNUNET_TESTBED_get_index (peer);
425 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n", i, 427 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n", i,
426 subsystem, name, (unsigned long long)value); 428 subsystem, name, (unsigned long long) value);
427 if (0 == strncmp(s_sent, name, strlen(s_sent)) && 0 == i) 429 if ((0 == strncmp (s_sent, name, strlen (s_sent)))&&(0 == i))
428 ka_sent = value; 430 ka_sent = value;
429 if (0 == strncmp(s_recv, name, strlen(s_recv)) && peers_requested - 1 == i) 431 if ((0 == strncmp (s_recv, name, strlen (s_recv)))&&(peers_requested - 1 ==
432 i) )
430 ka_received = value; 433 ka_received = value;
431 if (0 == strncmp(rdrops, name, strlen(rdrops))) 434 if (0 == strncmp (rdrops, name, strlen (rdrops)))
432 msg_dropped += value; 435 msg_dropped += value;
433 if (0 == strncmp(cdrops, name, strlen(cdrops))) 436 if (0 == strncmp (cdrops, name, strlen (cdrops)))
434 msg_dropped += value; 437 msg_dropped += value;
435 438
436 return GNUNET_OK; 439 return GNUNET_OK;
@@ -443,26 +446,26 @@ stats_iterator(void *cls,
443 * @param cls Closure (line from which the task was scheduled). 446 * @param cls Closure (line from which the task was scheduled).
444 */ 447 */
445static void 448static void
446gather_stats_and_exit(void *cls) 449gather_stats_and_exit (void *cls)
447{ 450{
448 long l = (long)cls; 451 long l = (long) cls;
449 452
450 disconnect_task = NULL; 453 disconnect_task = NULL;
451 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 454 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
452 "gathering statistics from line %ld\n", 455 "gathering statistics from line %ld\n",
453 l); 456 l);
454 if (NULL != outgoing_ch) 457 if (NULL != outgoing_ch)
455 { 458 {
456 GNUNET_CADET_channel_destroy(outgoing_ch); 459 GNUNET_CADET_channel_destroy (outgoing_ch);
457 outgoing_ch = NULL; 460 outgoing_ch = NULL;
458 } 461 }
459 stats_op = GNUNET_TESTBED_get_statistics(peers_running, 462 stats_op = GNUNET_TESTBED_get_statistics (peers_running,
460 testbed_peers, 463 testbed_peers,
461 "cadet", 464 "cadet",
462 NULL, 465 NULL,
463 &stats_iterator, 466 &stats_iterator,
464 stats_cont, 467 stats_cont,
465 cls); 468 cls);
466} 469}
467 470
468 471
@@ -474,7 +477,7 @@ gather_stats_and_exit(void *cls)
474 * @param channel Channel to send the message on. 477 * @param channel Channel to send the message on.
475 */ 478 */
476static void 479static void
477send_test_message(struct GNUNET_CADET_Channel *channel); 480send_test_message (struct GNUNET_CADET_Channel *channel);
478 481
479/** 482/**
480 * Check if payload is sane (size contains payload). 483 * Check if payload is sane (size contains payload).
@@ -485,8 +488,8 @@ send_test_message(struct GNUNET_CADET_Channel *channel);
485 * #GNUNET_SYSERR to close it (signal serious error). 488 * #GNUNET_SYSERR to close it (signal serious error).
486 */ 489 */
487static int 490static int
488check_data(void *cls, 491check_data (void *cls,
489 const struct GNUNET_MessageHeader *message); 492 const struct GNUNET_MessageHeader *message);
490 493
491/** 494/**
492 * Function is called whenever a message is received. 495 * Function is called whenever a message is received.
@@ -495,8 +498,8 @@ check_data(void *cls,
495 * @param message the actual message 498 * @param message the actual message
496 */ 499 */
497static void 500static void
498handle_data(void *cls, 501handle_data (void *cls,
499 const struct GNUNET_MessageHeader *message); 502 const struct GNUNET_MessageHeader *message);
500 503
501/** 504/**
502 * Function called whenever an MQ-channel is destroyed, unless the destruction 505 * Function called whenever an MQ-channel is destroyed, unless the destruction
@@ -510,8 +513,8 @@ handle_data(void *cls,
510 * @param channel Connection to the other end (henceforth invalid). 513 * @param channel Connection to the other end (henceforth invalid).
511 */ 514 */
512static void 515static void
513disconnect_handler(void *cls, 516disconnect_handler (void *cls,
514 const struct GNUNET_CADET_Channel *channel); 517 const struct GNUNET_CADET_Channel *channel);
515 518
516 519
517/** 520/**
@@ -520,37 +523,37 @@ disconnect_handler(void *cls,
520 * @param cls Closure (line from which the task was scheduled). 523 * @param cls Closure (line from which the task was scheduled).
521 */ 524 */
522static void 525static void
523reconnect_op(void *cls) 526reconnect_op (void *cls)
524{ 527{
525 struct GNUNET_MQ_MessageHandler handlers[] = { 528 struct GNUNET_MQ_MessageHandler handlers[] = {
526 GNUNET_MQ_hd_var_size(data, 529 GNUNET_MQ_hd_var_size (data,
527 GNUNET_MESSAGE_TYPE_DUMMY, 530 GNUNET_MESSAGE_TYPE_DUMMY,
528 struct GNUNET_MessageHeader, 531 struct GNUNET_MessageHeader,
529 NULL), 532 NULL),
530 GNUNET_MQ_handler_end() 533 GNUNET_MQ_handler_end ()
531 }; 534 };
532 long l = (long)cls; 535 long l = (long) cls;
533 struct CadetTestChannelWrapper *ch; 536 struct CadetTestChannelWrapper *ch;
534 537
535 reconnect_task = NULL; 538 reconnect_task = NULL;
536 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 539 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
537 "reconnecting from line %ld\n", 540 "reconnecting from line %ld\n",
538 l); 541 l);
539 if (NULL != outgoing_ch) 542 if (NULL != outgoing_ch)
540 { 543 {
541 GNUNET_CADET_channel_destroy(outgoing_ch); 544 GNUNET_CADET_channel_destroy (outgoing_ch);
542 outgoing_ch = NULL; 545 outgoing_ch = NULL;
543 } 546 }
544 ch = GNUNET_new(struct CadetTestChannelWrapper); 547 ch = GNUNET_new (struct CadetTestChannelWrapper);
545 outgoing_ch = GNUNET_CADET_channel_create(h1, 548 outgoing_ch = GNUNET_CADET_channel_create (h1,
546 ch, 549 ch,
547 p_id[1], 550 p_id[1],
548 &port, 551 &port,
549 NULL, 552 NULL,
550 &disconnect_handler, 553 &disconnect_handler,
551 handlers); 554 handlers);
552 ch->ch = outgoing_ch; 555 ch->ch = outgoing_ch;
553 send_test_message(outgoing_ch); 556 send_test_message (outgoing_ch);
554} 557}
555 558
556/** 559/**
@@ -565,47 +568,47 @@ reconnect_op(void *cls)
565 * @param channel Connection to the other end (henceforth invalid). 568 * @param channel Connection to the other end (henceforth invalid).
566 */ 569 */
567static void 570static void
568disconnect_handler(void *cls, 571disconnect_handler (void *cls,
569 const struct GNUNET_CADET_Channel *channel) 572 const struct GNUNET_CADET_Channel *channel)
570{ 573{
571 struct CadetTestChannelWrapper *ch_w = cls; 574 struct CadetTestChannelWrapper *ch_w = cls;
572 575
573 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 576 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
574 "Channel disconnected at %d\n", 577 "Channel disconnected at %d\n",
575 ok); 578 ok);
576 GNUNET_assert(ch_w->ch == channel); 579 GNUNET_assert (ch_w->ch == channel);
577 if (channel == incoming_ch) 580 if (channel == incoming_ch)
578 { 581 {
579 ok++; 582 ok++;
580 incoming_ch = NULL; 583 incoming_ch = NULL;
581 } 584 }
582 else if (outgoing_ch == channel) 585 else if (outgoing_ch == channel)
586 {
587 if (P2P_SIGNAL == test)
583 { 588 {
584 if (P2P_SIGNAL == test) 589 ok++;
585 {
586 ok++;
587 }
588 outgoing_ch = NULL;
589 } 590 }
591 outgoing_ch = NULL;
592 }
590 else 593 else
591 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 594 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
592 "Unknown channel! %p\n", 595 "Unknown channel! %p\n",
593 channel); 596 channel);
594 if (NULL != disconnect_task && REOPEN != test) 597 if ((NULL != disconnect_task)&&(REOPEN != test))
595 { 598 {
596 GNUNET_SCHEDULER_cancel(disconnect_task); 599 GNUNET_SCHEDULER_cancel (disconnect_task);
597 disconnect_task = 600 disconnect_task =
598 GNUNET_SCHEDULER_add_now(&gather_stats_and_exit, 601 GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
599 (void *)__LINE__); 602 (void *) __LINE__);
600 } 603 }
601 else if (NULL != reconnect_task && REOPEN == test) 604 else if ((NULL != reconnect_task)&&(REOPEN == test))
602 { 605 {
603 GNUNET_SCHEDULER_cancel(reconnect_task); 606 GNUNET_SCHEDULER_cancel (reconnect_task);
604 reconnect_task = 607 reconnect_task =
605 GNUNET_SCHEDULER_add_now(&reconnect_op, 608 GNUNET_SCHEDULER_add_now (&reconnect_op,
606 (void *)__LINE__); 609 (void *) __LINE__);
607 } 610 }
608 GNUNET_free(ch_w); 611 GNUNET_free (ch_w);
609} 612}
610 613
611 614
@@ -615,18 +618,18 @@ disconnect_handler(void *cls,
615 * @param line Line in the code the abort is requested from (__LINE__). 618 * @param line Line in the code the abort is requested from (__LINE__).
616 */ 619 */
617static void 620static void
618abort_test(long line) 621abort_test (long line)
619{ 622{
620 if (NULL != disconnect_task) 623 if (NULL != disconnect_task)
621 { 624 {
622 GNUNET_SCHEDULER_cancel(disconnect_task); 625 GNUNET_SCHEDULER_cancel (disconnect_task);
623 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 626 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
624 "Aborting test from %ld\n", 627 "Aborting test from %ld\n",
625 line); 628 line);
626 disconnect_task = 629 disconnect_task =
627 GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 630 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
628 (void *)line); 631 (void *) line);
629 } 632 }
630} 633}
631 634
632 635
@@ -638,7 +641,7 @@ abort_test(long line)
638 * @param channel Channel to send the message on. 641 * @param channel Channel to send the message on.
639 */ 642 */
640static void 643static void
641send_test_message(struct GNUNET_CADET_Channel *channel) 644send_test_message (struct GNUNET_CADET_Channel *channel)
642{ 645{
643 struct GNUNET_MQ_Envelope *env; 646 struct GNUNET_MQ_Envelope *env;
644 struct GNUNET_MessageHeader *msg; 647 struct GNUNET_MessageHeader *msg;
@@ -646,64 +649,64 @@ send_test_message(struct GNUNET_CADET_Channel *channel)
646 int payload; 649 int payload;
647 int size; 650 int size;
648 651
649 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
650 "Sending test message on channel %p\n", 653 "Sending test message on channel %p\n",
651 channel); 654 channel);
652 size = size_payload; 655 size = size_payload;
653 if (GNUNET_NO == initialized) 656 if (GNUNET_NO == initialized)
654 { 657 {
655 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n"); 658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n");
656 size += 1000; 659 size += 1000;
657 payload = data_sent; 660 payload = data_sent;
658 if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer 661 if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer
659 data_sent++; 662 data_sent++;
660 } 663 }
661 else if (SPEED == test || SPEED_ACK == test) 664 else if ((SPEED == test)||(SPEED_ACK == test))
662 { 665 {
663 if (get_target_channel() == channel) 666 if (get_target_channel () == channel)
664 {
665 payload = ack_sent;
666 size += ack_sent;
667 ack_sent++;
668 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
669 "Sending ACK %u [%d bytes]\n",
670 payload, size);
671 }
672 else
673 {
674 payload = data_sent;
675 size += data_sent;
676 data_sent++;
677 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
678 "Sending DATA %u [%d bytes]\n",
679 data_sent, size);
680 }
681 }
682 else if (FORWARD == test)
683 { 667 {
684 payload = ack_sent; 668 payload = ack_sent;
669 size += ack_sent;
670 ack_sent++;
671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
672 "Sending ACK %u [%d bytes]\n",
673 payload, size);
685 } 674 }
686 else if (P2P_SIGNAL == test) 675 else
687 {
688 payload = data_sent;
689 }
690 else if (REOPEN == test)
691 { 676 {
692 payload = data_sent; 677 payload = data_sent;
678 size += data_sent;
693 data_sent++; 679 data_sent++;
694 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
695 "Sending DATA %u [%d bytes]\n", 681 "Sending DATA %u [%d bytes]\n",
696 data_sent, size); 682 data_sent, size);
697 } 683 }
684 }
685 else if (FORWARD == test)
686 {
687 payload = ack_sent;
688 }
689 else if (P2P_SIGNAL == test)
690 {
691 payload = data_sent;
692 }
693 else if (REOPEN == test)
694 {
695 payload = data_sent;
696 data_sent++;
697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
698 "Sending DATA %u [%d bytes]\n",
699 data_sent, size);
700 }
698 else 701 else
699 { 702 {
700 GNUNET_assert(0); 703 GNUNET_assert (0);
701 } 704 }
702 env = GNUNET_MQ_msg_extra(msg, size, GNUNET_MESSAGE_TYPE_DUMMY); 705 env = GNUNET_MQ_msg_extra (msg, size, GNUNET_MESSAGE_TYPE_DUMMY);
703 706
704 data = (uint32_t *)&msg[1]; 707 data = (uint32_t *) &msg[1];
705 *data = htonl(payload); 708 *data = htonl (payload);
706 GNUNET_MQ_send(GNUNET_CADET_get_mq(channel), env); 709 GNUNET_MQ_send (GNUNET_CADET_get_mq (channel), env);
707} 710}
708 711
709 712
@@ -714,30 +717,30 @@ send_test_message(struct GNUNET_CADET_Channel *channel)
714 * @param cls Closure (unused). 717 * @param cls Closure (unused).
715 */ 718 */
716static void 719static void
717send_next_msg(void *cls) 720send_next_msg (void *cls)
718{ 721{
719 struct GNUNET_CADET_Channel *channel; 722 struct GNUNET_CADET_Channel *channel;
720 723
721 send_next_msg_task = NULL; 724 send_next_msg_task = NULL;
722 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
723 "Sending next message: %d\n", 726 "Sending next message: %d\n",
724 data_sent); 727 data_sent);
725 728
726 channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch; 729 channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch;
727 GNUNET_assert(NULL != channel); 730 GNUNET_assert (NULL != channel);
728 GNUNET_assert(SPEED == test); 731 GNUNET_assert (SPEED == test);
729 send_test_message(channel); 732 send_test_message (channel);
730 if (data_sent < total_packets) 733 if (data_sent < total_packets)
731 { 734 {
732 /* SPEED test: Send all messages as soon as possible */ 735 /* SPEED test: Send all messages as soon as possible */
733 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
734 "Scheduling message %d\n", 737 "Scheduling message %d\n",
735 data_sent + 1); 738 data_sent + 1);
736 send_next_msg_task = 739 send_next_msg_task =
737 GNUNET_SCHEDULER_add_delayed(SEND_INTERVAL, 740 GNUNET_SCHEDULER_add_delayed (SEND_INTERVAL,
738 &send_next_msg, 741 &send_next_msg,
739 NULL); 742 NULL);
740 } 743 }
741} 744}
742 745
743 746
@@ -748,20 +751,20 @@ send_next_msg(void *cls)
748 * @param line Code line number to log if a timeout occurs. 751 * @param line Code line number to log if a timeout occurs.
749 */ 752 */
750static void 753static void
751reschedule_timeout_task(long line) 754reschedule_timeout_task (long line)
752{ 755{
753 if ((ok % 10) == 0) 756 if ((ok % 10) == 0)
757 {
758 if (NULL != disconnect_task)
754 { 759 {
755 if (NULL != disconnect_task) 760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
756 { 761 "reschedule timeout every 10 messages\n");
757 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 762 GNUNET_SCHEDULER_cancel (disconnect_task);
758 "reschedule timeout every 10 messages\n"); 763 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
759 GNUNET_SCHEDULER_cancel(disconnect_task); 764 &gather_stats_and_exit,
760 disconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 765 (void *) line);
761 &gather_stats_and_exit,
762 (void *)line);
763 }
764 } 766 }
767 }
765} 768}
766 769
767 770
@@ -774,8 +777,8 @@ reschedule_timeout_task(long line)
774 * #GNUNET_SYSERR to close it (signal serious error). 777 * #GNUNET_SYSERR to close it (signal serious error).
775 */ 778 */
776static int 779static int
777check_data(void *cls, 780check_data (void *cls,
778 const struct GNUNET_MessageHeader *message) 781 const struct GNUNET_MessageHeader *message)
779{ 782{
780 return GNUNET_OK; /* all is well-formed */ 783 return GNUNET_OK; /* all is well-formed */
781} 784}
@@ -788,8 +791,8 @@ check_data(void *cls,
788 * @param message the actual message 791 * @param message the actual message
789 */ 792 */
790static void 793static void
791handle_data(void *cls, 794handle_data (void *cls,
792 const struct GNUNET_MessageHeader *message) 795 const struct GNUNET_MessageHeader *message)
793{ 796{
794 struct CadetTestChannelWrapper *ch = cls; 797 struct CadetTestChannelWrapper *ch = cls;
795 struct GNUNET_CADET_Channel *channel = ch->ch; 798 struct GNUNET_CADET_Channel *channel = ch->ch;
@@ -798,101 +801,101 @@ handle_data(void *cls,
798 int *counter; 801 int *counter;
799 802
800 ok++; 803 ok++;
801 GNUNET_CADET_receive_done(channel); 804 GNUNET_CADET_receive_done (channel);
802 counter = get_target_channel() == channel ? &data_received : &ack_received; 805 counter = get_target_channel () == channel ? &data_received : &ack_received;
803 806
804 reschedule_timeout_task((long)__LINE__); 807 reschedule_timeout_task ((long) __LINE__);
805 808
806 if (channel == outgoing_ch) 809 if (channel == outgoing_ch)
807 { 810 {
808 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 811 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
809 "Root client got a message.\n"); 812 "Root client got a message.\n");
810 } 813 }
811 else if (channel == incoming_ch) 814 else if (channel == incoming_ch)
812 { 815 {
813 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 816 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
814 "Leaf client got a message.\n"); 817 "Leaf client got a message.\n");
815 } 818 }
816 else 819 else
817 { 820 {
818 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 821 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
819 "Unknown channel %p.\n", 822 "Unknown channel %p.\n",
820 channel); 823 channel);
821 GNUNET_assert(0); 824 GNUNET_assert (0);
822 } 825 }
823 826
824 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 827 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
825 " ok: (%d/%d)\n", 828 " ok: (%d/%d)\n",
826 ok, 829 ok,
827 ok_goal); 830 ok_goal);
828 data = (uint32_t *)&message[1]; 831 data = (uint32_t *) &message[1];
829 payload = ntohl(*data); 832 payload = ntohl (*data);
830 if (payload == *counter) 833 if (payload == *counter)
831 { 834 {
832 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 835 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
833 " payload as expected: %u\n", 836 " payload as expected: %u\n",
834 payload); 837 payload);
835 } 838 }
836 else 839 else
837 { 840 {
838 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 841 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
839 " payload %u, expected: %u\n", 842 " payload %u, expected: %u\n",
840 payload, *counter); 843 payload, *counter);
841 } 844 }
842 845
843 if (GNUNET_NO == initialized) 846 if (GNUNET_NO == initialized)
847 {
848 initialized = GNUNET_YES;
849 start_time = GNUNET_TIME_absolute_get ();
850 if (SPEED == test)
844 { 851 {
845 initialized = GNUNET_YES; 852 GNUNET_assert (incoming_ch == channel);
846 start_time = GNUNET_TIME_absolute_get(); 853 send_next_msg_task = GNUNET_SCHEDULER_add_now (&send_next_msg,
847 if (SPEED == test) 854 NULL);
848 { 855 return;
849 GNUNET_assert(incoming_ch == channel);
850 send_next_msg_task = GNUNET_SCHEDULER_add_now(&send_next_msg,
851 NULL);
852 return;
853 }
854 } 856 }
857 }
855 858
856 (*counter)++; 859 (*counter)++;
857 if (get_target_channel() == channel) /* Got "data" */ 860 if (get_target_channel () == channel) /* Got "data" */
861 {
862 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received);
863 if ((SPEED != test) ||( (ok_goal - 2) == ok) )
858 { 864 {
859 GNUNET_log(GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received); 865 /* Send ACK */
860 if (SPEED != test || (ok_goal - 2) == ok) 866 send_test_message (channel);
861 { 867 return;
862 /* Send ACK */ 868 }
863 send_test_message(channel); 869 else
864 return; 870 {
865 } 871 if (data_received < total_packets)
866 else 872 return;
867 {
868 if (data_received < total_packets)
869 return;
870 }
871 } 873 }
874 }
872 else /* Got "ack" */ 875 else /* Got "ack" */
876 {
877 if ((SPEED_ACK == test) ||(SPEED == test) )
878 {
879 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received);
880 /* Send more data */
881 send_test_message (channel);
882 if ((ack_received < total_packets) &&(SPEED != test) )
883 return;
884 if ((ok == 2) &&(SPEED == test) )
885 return;
886 show_end_data ();
887 }
888 if (test == P2P_SIGNAL)
889 {
890 GNUNET_CADET_channel_destroy (incoming_ch);
891 incoming_ch = NULL;
892 }
893 else
873 { 894 {
874 if (SPEED_ACK == test || SPEED == test) 895 GNUNET_CADET_channel_destroy (outgoing_ch);
875 { 896 outgoing_ch = NULL;
876 GNUNET_log(GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received);
877 /* Send more data */
878 send_test_message(channel);
879 if (ack_received < total_packets && SPEED != test)
880 return;
881 if (ok == 2 && SPEED == test)
882 return;
883 show_end_data();
884 }
885 if (test == P2P_SIGNAL)
886 {
887 GNUNET_CADET_channel_destroy(incoming_ch);
888 incoming_ch = NULL;
889 }
890 else
891 {
892 GNUNET_CADET_channel_destroy(outgoing_ch);
893 outgoing_ch = NULL;
894 }
895 } 897 }
898 }
896} 899}
897 900
898 901
@@ -909,66 +912,66 @@ handle_data(void *cls,
909 * received on the @a channel. 912 * received on the @a channel.
910 */ 913 */
911static void * 914static void *
912connect_handler(void *cls, 915connect_handler (void *cls,
913 struct GNUNET_CADET_Channel *channel, 916 struct GNUNET_CADET_Channel *channel,
914 const struct GNUNET_PeerIdentity *source) 917 const struct GNUNET_PeerIdentity *source)
915{ 918{
916 struct CadetTestChannelWrapper *ch; 919 struct CadetTestChannelWrapper *ch;
917 long peer = (long)cls; 920 long peer = (long) cls;
918 921
919 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 922 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
920 "Incoming channel from %s to %ld: %p\n", 923 "Incoming channel from %s to %ld: %p\n",
921 GNUNET_i2s(source), 924 GNUNET_i2s (source),
922 peer, 925 peer,
923 channel); 926 channel);
924 ok++; 927 ok++;
925 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 928 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
926 " ok: %d\n", 929 " ok: %d\n",
927 ok); 930 ok);
928 if (peer == peers_requested - 1) 931 if (peer == peers_requested - 1)
932 {
933 if (NULL != incoming_ch)
929 { 934 {
930 if (NULL != incoming_ch) 935 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
931 { 936 "Duplicate incoming channel for client %lu\n",
932 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 937 (long) cls);
933 "Duplicate incoming channel for client %lu\n", 938 GNUNET_assert (0);
934 (long)cls);
935 GNUNET_assert(0);
936 }
937 incoming_ch = channel;
938 } 939 }
940 incoming_ch = channel;
941 }
939 else 942 else
940 { 943 {
941 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 944 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
942 "Incoming channel for unexpected peer #%lu\n", 945 "Incoming channel for unexpected peer #%lu\n",
943 (long)cls); 946 (long) cls);
944 GNUNET_assert(0); 947 GNUNET_assert (0);
945 } 948 }
946 if (NULL != disconnect_task && REOPEN != test) 949 if ((NULL != disconnect_task)&&(REOPEN != test))
947 { 950 {
948 GNUNET_SCHEDULER_cancel(disconnect_task); 951 GNUNET_SCHEDULER_cancel (disconnect_task);
949 disconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 952 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
950 &gather_stats_and_exit, 953 &gather_stats_and_exit,
951 (void *)__LINE__); 954 (void *) __LINE__);
952 } 955 }
953 else if ((NULL != disconnect_task) && (REOPEN == test)) 956 else if ((NULL != disconnect_task) && (REOPEN == test))
954 { 957 {
955 GNUNET_SCHEDULER_cancel(disconnect_task); 958 GNUNET_SCHEDULER_cancel (disconnect_task);
956 disconnect_task = GNUNET_SCHEDULER_add_delayed( 959 disconnect_task = GNUNET_SCHEDULER_add_delayed (
957 GNUNET_TIME_relative_multiply(short_time, 2), 960 GNUNET_TIME_relative_multiply (short_time, 2),
958 &gather_stats_and_exit, 961 &gather_stats_and_exit,
959 (void *)__LINE__); 962 (void *) __LINE__);
960 } 963 }
961 964
962 if ((NULL != reconnect_task) && (REOPEN == test)) 965 if ((NULL != reconnect_task) && (REOPEN == test))
963 { 966 {
964 GNUNET_SCHEDULER_cancel(reconnect_task); 967 GNUNET_SCHEDULER_cancel (reconnect_task);
965 reconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 968 reconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
966 &reconnect_op, 969 &reconnect_op,
967 (void *)__LINE__); 970 (void *) __LINE__);
968 } 971 }
969 972
970 /* TODO: cannot return channel as-is, in order to unify the data handlers */ 973 /* TODO: cannot return channel as-is, in order to unify the data handlers */
971 ch = GNUNET_new(struct CadetTestChannelWrapper); 974 ch = GNUNET_new (struct CadetTestChannelWrapper);
972 ch->ch = channel; 975 ch->ch = channel;
973 976
974 return ch; 977 return ch;
@@ -984,44 +987,44 @@ connect_handler(void *cls,
984 * @param cls Closure (unused). 987 * @param cls Closure (unused).
985 */ 988 */
986static void 989static void
987start_test(void *cls) 990start_test (void *cls)
988{ 991{
989 struct GNUNET_MQ_MessageHandler handlers[] = { 992 struct GNUNET_MQ_MessageHandler handlers[] = {
990 GNUNET_MQ_hd_var_size(data, 993 GNUNET_MQ_hd_var_size (data,
991 GNUNET_MESSAGE_TYPE_DUMMY, 994 GNUNET_MESSAGE_TYPE_DUMMY,
992 struct GNUNET_MessageHeader, 995 struct GNUNET_MessageHeader,
993 NULL), 996 NULL),
994 GNUNET_MQ_handler_end() 997 GNUNET_MQ_handler_end ()
995 }; 998 };
996 struct CadetTestChannelWrapper *ch; 999 struct CadetTestChannelWrapper *ch;
997 1000
998 test_task = NULL; 1001 test_task = NULL;
999 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name); 1002 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name);
1000 if (NULL != disconnect_task) 1003 if (NULL != disconnect_task)
1001 { 1004 {
1002 GNUNET_SCHEDULER_cancel(disconnect_task); 1005 GNUNET_SCHEDULER_cancel (disconnect_task);
1003 disconnect_task = NULL; 1006 disconnect_task = NULL;
1004 } 1007 }
1005 1008
1006 if (SPEED_REL == test) 1009 if (SPEED_REL == test)
1007 { 1010 {
1008 test = SPEED; 1011 test = SPEED;
1009 } 1012 }
1010 1013
1011 ch = GNUNET_new(struct CadetTestChannelWrapper); 1014 ch = GNUNET_new (struct CadetTestChannelWrapper);
1012 outgoing_ch = GNUNET_CADET_channel_create(h1, 1015 outgoing_ch = GNUNET_CADET_channel_create (h1,
1013 ch, 1016 ch,
1014 p_id[1], 1017 p_id[1],
1015 &port, 1018 &port,
1016 NULL, 1019 NULL,
1017 &disconnect_handler, 1020 &disconnect_handler,
1018 handlers); 1021 handlers);
1019 1022
1020 ch->ch = outgoing_ch; 1023 ch->ch = outgoing_ch;
1021 1024
1022 disconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 1025 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1023 &gather_stats_and_exit, 1026 &gather_stats_and_exit,
1024 (void *)__LINE__); 1027 (void *) __LINE__);
1025 if (KEEPALIVE == test) 1028 if (KEEPALIVE == test)
1026 return; /* Don't send any data. */ 1029 return; /* Don't send any data. */
1027 1030
@@ -1029,21 +1032,21 @@ start_test(void *cls)
1029 data_sent = 0; 1032 data_sent = 0;
1030 ack_received = 0; 1033 ack_received = 0;
1031 ack_sent = 0; 1034 ack_sent = 0;
1032 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1033 "Sending data initializer on channel %p...\n", 1036 "Sending data initializer on channel %p...\n",
1034 outgoing_ch); 1037 outgoing_ch);
1035 send_test_message(outgoing_ch); 1038 send_test_message (outgoing_ch);
1036 if (REOPEN == test) 1039 if (REOPEN == test)
1037 { 1040 {
1038 reconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 1041 reconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1039 &reconnect_op, 1042 &reconnect_op,
1040 (void *)__LINE__); 1043 (void *) __LINE__);
1041 GNUNET_SCHEDULER_cancel(disconnect_task); 1044 GNUNET_SCHEDULER_cancel (disconnect_task);
1042 disconnect_task = GNUNET_SCHEDULER_add_delayed( 1045 disconnect_task = GNUNET_SCHEDULER_add_delayed (
1043 GNUNET_TIME_relative_multiply(short_time, 2), 1046 GNUNET_TIME_relative_multiply (short_time, 2),
1044 &gather_stats_and_exit, 1047 &gather_stats_and_exit,
1045 (void *)__LINE__); 1048 (void *) __LINE__);
1046 } 1049 }
1047} 1050}
1048 1051
1049 1052
@@ -1057,35 +1060,35 @@ start_test(void *cls)
1057 * NULL if the operation is successfull 1060 * NULL if the operation is successfull
1058 */ 1061 */
1059static void 1062static void
1060pi_cb(void *cls, 1063pi_cb (void *cls,
1061 struct GNUNET_TESTBED_Operation *op, 1064 struct GNUNET_TESTBED_Operation *op,
1062 const struct GNUNET_TESTBED_PeerInformation *pinfo, 1065 const struct GNUNET_TESTBED_PeerInformation *pinfo,
1063 const char *emsg) 1066 const char *emsg)
1064{ 1067{
1065 long i = (long)cls; 1068 long i = (long) cls;
1066 1069
1067 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1068 "ID callback for %ld\n", 1071 "ID callback for %ld\n",
1069 i); 1072 i);
1070 if ((NULL == pinfo) || 1073 if ((NULL == pinfo) ||
1071 (NULL != emsg)) 1074 (NULL != emsg))
1072 { 1075 {
1073 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1076 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1074 "pi_cb: %s\n", 1077 "pi_cb: %s\n",
1075 emsg); 1078 emsg);
1076 abort_test(__LINE__); 1079 abort_test (__LINE__);
1077 return; 1080 return;
1078 } 1081 }
1079 p_id[i] = pinfo->result.id; 1082 p_id[i] = pinfo->result.id;
1080 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1081 "id: %s\n", 1084 "id: %s\n",
1082 GNUNET_i2s(p_id[i])); 1085 GNUNET_i2s (p_id[i]));
1083 p_ids++; 1086 p_ids++;
1084 if (p_ids < 2) 1087 if (p_ids < 2)
1085 return; 1088 return;
1086 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1087 "Got all IDs, starting test\n"); 1090 "Got all IDs, starting test\n");
1088 test_task = GNUNET_SCHEDULER_add_now(&start_test, NULL); 1091 test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL);
1089} 1092}
1090 1093
1091 1094
@@ -1099,34 +1102,34 @@ pi_cb(void *cls,
1099 * @param cadets Handle to each of the CADETs of the peers. 1102 * @param cadets Handle to each of the CADETs of the peers.
1100 */ 1103 */
1101static void 1104static void
1102tmain(void *cls, 1105tmain (void *cls,
1103 struct GNUNET_CADET_TEST_Context *ctx, 1106 struct GNUNET_CADET_TEST_Context *ctx,
1104 unsigned int num_peers, 1107 unsigned int num_peers,
1105 struct GNUNET_TESTBED_Peer **peers, 1108 struct GNUNET_TESTBED_Peer **peers,
1106 struct GNUNET_CADET_Handle **cadets) 1109 struct GNUNET_CADET_Handle **cadets)
1107{ 1110{
1108 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test main\n"); 1111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
1109 ok = 0; 1112 ok = 0;
1110 test_ctx = ctx; 1113 test_ctx = ctx;
1111 peers_running = num_peers; 1114 peers_running = num_peers;
1112 GNUNET_assert(peers_running == peers_requested); 1115 GNUNET_assert (peers_running == peers_requested);
1113 testbed_peers = peers; 1116 testbed_peers = peers;
1114 h1 = cadets[0]; 1117 h1 = cadets[0];
1115 h2 = cadets[num_peers - 1]; 1118 h2 = cadets[num_peers - 1];
1116 disconnect_task = GNUNET_SCHEDULER_add_delayed(short_time, 1119 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
1117 &disconnect_cadet_peers, 1120 &disconnect_cadet_peers,
1118 (void *)__LINE__); 1121 (void *) __LINE__);
1119 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, 1122 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1120 NULL); 1123 NULL);
1121 t_op[0] = GNUNET_TESTBED_peer_get_information(peers[0], 1124 t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
1122 GNUNET_TESTBED_PIT_IDENTITY, 1125 GNUNET_TESTBED_PIT_IDENTITY,
1123 &pi_cb, 1126 &pi_cb,
1124 (void *)0L); 1127 (void *) 0L);
1125 t_op[1] = GNUNET_TESTBED_peer_get_information(peers[num_peers - 1], 1128 t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1],
1126 GNUNET_TESTBED_PIT_IDENTITY, 1129 GNUNET_TESTBED_PIT_IDENTITY,
1127 &pi_cb, 1130 &pi_cb,
1128 (void *)1L); 1131 (void *) 1L);
1129 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n"); 1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n");
1130} 1133}
1131 1134
1132 1135
@@ -1134,179 +1137,179 @@ tmain(void *cls,
1134 * Main: start test 1137 * Main: start test
1135 */ 1138 */
1136int 1139int
1137main(int argc, char *argv[]) 1140main (int argc, char *argv[])
1138{ 1141{
1139 static const struct GNUNET_HashCode *ports[2]; 1142 static const struct GNUNET_HashCode *ports[2];
1140 struct GNUNET_MQ_MessageHandler handlers[] = { 1143 struct GNUNET_MQ_MessageHandler handlers[] = {
1141 GNUNET_MQ_hd_var_size(data, 1144 GNUNET_MQ_hd_var_size (data,
1142 GNUNET_MESSAGE_TYPE_DUMMY, 1145 GNUNET_MESSAGE_TYPE_DUMMY,
1143 struct GNUNET_MessageHeader, 1146 struct GNUNET_MessageHeader,
1144 NULL), 1147 NULL),
1145 GNUNET_MQ_handler_end() 1148 GNUNET_MQ_handler_end ()
1146 }; 1149 };
1147 const char *config_file; 1150 const char *config_file;
1148 char port_id[] = "test port"; 1151 char port_id[] = "test port";
1149 struct GNUNET_GETOPT_CommandLineOption options[] = { 1152 struct GNUNET_GETOPT_CommandLineOption options[] = {
1150 GNUNET_GETOPT_option_relative_time('t', 1153 GNUNET_GETOPT_option_relative_time ('t',
1151 "time", 1154 "time",
1152 "short_time", 1155 "short_time",
1153 gettext_noop("set short timeout"), 1156 gettext_noop ("set short timeout"),
1154 &short_time), 1157 &short_time),
1155 GNUNET_GETOPT_option_uint('m', 1158 GNUNET_GETOPT_option_uint ('m',
1156 "messages", 1159 "messages",
1157 "NUM_MESSAGES", 1160 "NUM_MESSAGES",
1158 gettext_noop("set number of messages to send"), 1161 gettext_noop ("set number of messages to send"),
1159 &total_packets), 1162 &total_packets),
1160 1163
1161 GNUNET_GETOPT_OPTION_END 1164 GNUNET_GETOPT_OPTION_END
1162 }; 1165 };
1163 1166
1164 1167
1165 initialized = GNUNET_NO; 1168 initialized = GNUNET_NO;
1166 GNUNET_log_setup("test", "DEBUG", NULL); 1169 GNUNET_log_setup ("test", "DEBUG", NULL);
1167 1170
1168 total_packets = TOTAL_PACKETS; 1171 total_packets = TOTAL_PACKETS;
1169 short_time = SHORT_TIME; 1172 short_time = SHORT_TIME;
1170 if (-1 == GNUNET_GETOPT_run(argv[0], options, argc, argv)) 1173 if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv))
1171 { 1174 {
1172 fprintf(stderr, "test failed: problem with CLI parameters\n"); 1175 fprintf (stderr, "test failed: problem with CLI parameters\n");
1173 exit(1); 1176 exit (1);
1174 } 1177 }
1175 1178
1176 config_file = "test_cadet.conf"; 1179 config_file = "test_cadet.conf";
1177 GNUNET_CRYPTO_hash(port_id, sizeof(port_id), &port); 1180 GNUNET_CRYPTO_hash (port_id, sizeof(port_id), &port);
1178 1181
1179 /* Find out requested size */ 1182 /* Find out requested size */
1180 if (strstr(argv[0], "_2_") != NULL) 1183 if (strstr (argv[0], "_2_") != NULL)
1181 { 1184 {
1182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DIRECT CONNECTIONs\n"); 1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DIRECT CONNECTIONs\n");
1183 peers_requested = 2; 1186 peers_requested = 2;
1184 } 1187 }
1185 else if (strstr(argv[0], "_5_") != NULL) 1188 else if (strstr (argv[0], "_5_") != NULL)
1186 { 1189 {
1187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n"); 1190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n");
1188 peers_requested = 5; 1191 peers_requested = 5;
1189 } 1192 }
1190 else if (strstr(argv[0], "_6_") != NULL) 1193 else if (strstr (argv[0], "_6_") != NULL)
1191 { 1194 {
1192 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "6 PEER LINE\n"); 1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "6 PEER LINE\n");
1193 peers_requested = 6; 1196 peers_requested = 6;
1194 } 1197 }
1195 else 1198 else
1196 { 1199 {
1197 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n"); 1200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n");
1198 peers_requested = 2; 1201 peers_requested = 2;
1199 } 1202 }
1200 1203
1201 /* Find out requested test */ 1204 /* Find out requested test */
1202 if (strstr(argv[0], "_forward") != NULL) 1205 if (strstr (argv[0], "_forward") != NULL)
1206 {
1207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FORWARD\n");
1208 test = FORWARD;
1209 test_name = "unicast";
1210 ok_goal = 4;
1211 }
1212 else if (strstr (argv[0], "_signal") != NULL)
1213 {
1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SIGNAL\n");
1215 test = P2P_SIGNAL;
1216 test_name = "signal";
1217 ok_goal = 4;
1218 }
1219 else if (strstr (argv[0], "_speed_ack") != NULL)
1220 {
1221 /* Test is supposed to generate the following callbacks:
1222 * 1 incoming channel (@dest)
1223 * total_packets received data packet (@dest)
1224 * total_packets received data packet (@orig)
1225 * 1 received channel destroy (@dest) FIXME #5818
1226 */
1227 ok_goal = total_packets * 2 + 2;
1228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
1229 test = SPEED_ACK;
1230 test_name = "speed ack";
1231 }
1232 else if (strstr (argv[0], "_speed") != NULL)
1233 {
1234 /* Test is supposed to generate the following callbacks:
1235 * 1 incoming channel (@dest)
1236 * 1 initial packet (@dest)
1237 * total_packets received data packet (@dest)
1238 * 1 received data packet (@orig)
1239 * 1 received channel destroy (@dest) FIXME #5818
1240 */
1241 ok_goal = total_packets + 4;
1242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1243 if (strstr (argv[0], "_reliable") != NULL)
1203 { 1244 {
1204 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "FORWARD\n"); 1245 test = SPEED_REL;
1205 test = FORWARD; 1246 test_name = "speed reliable";
1206 test_name = "unicast"; 1247 config_file = "test_cadet_drop.conf";
1207 ok_goal = 4;
1208 } 1248 }
1209 else if (strstr(argv[0], "_signal") != NULL) 1249 else
1210 { 1250 {
1211 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "SIGNAL\n"); 1251 test = SPEED;
1212 test = P2P_SIGNAL; 1252 test_name = "speed";
1213 test_name = "signal";
1214 ok_goal = 4;
1215 }
1216 else if (strstr(argv[0], "_speed_ack") != NULL)
1217 {
1218 /* Test is supposed to generate the following callbacks:
1219 * 1 incoming channel (@dest)
1220 * total_packets received data packet (@dest)
1221 * total_packets received data packet (@orig)
1222 * 1 received channel destroy (@dest) FIXME #5818
1223 */
1224 ok_goal = total_packets * 2 + 2;
1225 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
1226 test = SPEED_ACK;
1227 test_name = "speed ack";
1228 }
1229 else if (strstr(argv[0], "_speed") != NULL)
1230 {
1231 /* Test is supposed to generate the following callbacks:
1232 * 1 incoming channel (@dest)
1233 * 1 initial packet (@dest)
1234 * total_packets received data packet (@dest)
1235 * 1 received data packet (@orig)
1236 * 1 received channel destroy (@dest) FIXME #5818
1237 */
1238 ok_goal = total_packets + 4;
1239 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
1240 if (strstr(argv[0], "_reliable") != NULL)
1241 {
1242 test = SPEED_REL;
1243 test_name = "speed reliable";
1244 config_file = "test_cadet_drop.conf";
1245 }
1246 else
1247 {
1248 test = SPEED;
1249 test_name = "speed";
1250 }
1251 }
1252 else if (strstr(argv[0], "_keepalive") != NULL)
1253 {
1254 test = KEEPALIVE;
1255 test_name = "keepalive";
1256 /* Test is supposed to generate the following callbacks:
1257 * 1 incoming channel (@dest)
1258 * [wait]
1259 * 1 received channel destroy (@dest) FIXME #5818
1260 */
1261 ok_goal = 1;
1262 }
1263 else if (strstr(argv[0], "_reopen") != NULL)
1264 {
1265 test = REOPEN;
1266 test_name = "reopen";
1267 ///* Test is supposed to generate the following callbacks:
1268 // * 1 incoming channel (@dest)
1269 // * [wait]
1270 // * 1 received channel destroy (@dest) FIXME #5818
1271 // */
1272 ok_goal = 6;
1273 } 1253 }
1254 }
1255 else if (strstr (argv[0], "_keepalive") != NULL)
1256 {
1257 test = KEEPALIVE;
1258 test_name = "keepalive";
1259 /* Test is supposed to generate the following callbacks:
1260 * 1 incoming channel (@dest)
1261 * [wait]
1262 * 1 received channel destroy (@dest) FIXME #5818
1263 */
1264 ok_goal = 1;
1265 }
1266 else if (strstr (argv[0], "_reopen") != NULL)
1267 {
1268 test = REOPEN;
1269 test_name = "reopen";
1270 ///* Test is supposed to generate the following callbacks:
1271 // * 1 incoming channel (@dest)
1272 // * [wait]
1273 // * 1 received channel destroy (@dest) FIXME #5818
1274 // */
1275 ok_goal = 6;
1276 }
1274 else 1277 else
1275 { 1278 {
1276 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n"); 1279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
1277 test = SETUP; 1280 test = SETUP;
1278 ok_goal = 0; 1281 ok_goal = 0;
1279 } 1282 }
1280 1283
1281 if (strstr(argv[0], "backwards") != NULL) 1284 if (strstr (argv[0], "backwards") != NULL)
1282 { 1285 {
1283 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n"); 1286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n");
1284 test_backwards = GNUNET_YES; 1287 test_backwards = GNUNET_YES;
1285 GNUNET_asprintf(&test_name, "backwards %s", test_name); 1288 GNUNET_asprintf (&test_name, "backwards %s", test_name);
1286 } 1289 }
1287 1290
1288 p_ids = 0; 1291 p_ids = 0;
1289 ports[0] = &port; 1292 ports[0] = &port;
1290 ports[1] = NULL; 1293 ports[1] = NULL;
1291 GNUNET_CADET_TEST_ruN("test_cadet_small", 1294 GNUNET_CADET_TEST_ruN ("test_cadet_small",
1292 config_file, 1295 config_file,
1293 peers_requested, 1296 peers_requested,
1294 &tmain, 1297 &tmain,
1295 NULL, /* tmain cls */ 1298 NULL, /* tmain cls */
1296 &connect_handler, 1299 &connect_handler,
1297 NULL, 1300 NULL,
1298 &disconnect_handler, 1301 &disconnect_handler,
1299 handlers, 1302 handlers,
1300 ports); 1303 ports);
1301 if (NULL != strstr(argv[0], "_reliable")) 1304 if (NULL != strstr (argv[0], "_reliable"))
1302 msg_dropped = 0; /* dropped should be retransmitted */ 1305 msg_dropped = 0; /* dropped should be retransmitted */
1303 1306
1304 if (ok_goal > ok - msg_dropped) 1307 if (ok_goal > ok - msg_dropped)
1305 { 1308 {
1306 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "FAILED! (%d/%d)\n", ok, ok_goal); 1309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "FAILED! (%d/%d)\n", ok, ok_goal);
1307 return 1; 1310 return 1;
1308 } 1311 }
1309 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "success\n"); 1312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
1310 return 0; 1313 return 0;
1311} 1314}
1312 1315
diff --git a/src/cadet/test_cadet_flow.c b/src/cadet/test_cadet_flow.c
index 5278dc00f..94e1f1c85 100644
--- a/src/cadet/test_cadet_flow.c
+++ b/src/cadet/test_cadet_flow.c
@@ -34,7 +34,8 @@
34/** 34/**
35 * Ugly workaround to unify data handlers on incoming and outgoing channels. 35 * Ugly workaround to unify data handlers on incoming and outgoing channels.
36 */ 36 */
37struct CadetTestChannelWrapper { 37struct CadetTestChannelWrapper
38{
38 /** 39 /**
39 * Channel pointer. 40 * Channel pointer.
40 */ 41 */
@@ -49,17 +50,18 @@ struct CadetTestChannelWrapper {
49/** 50/**
50 * How long until we give up on connecting the peers? 51 * How long until we give up on connecting the peers?
51 */ 52 */
52#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) 53#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
53 54
54/** 55/**
55 * Time to wait by default for stuff that should be rather fast. 56 * Time to wait by default for stuff that should be rather fast.
56 */ 57 */
57#define SHORT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) 58#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
58 59
59/** 60/**
60 * How fast do we send messages? 61 * How fast do we send messages?
61 */ 62 */
62#define SEND_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 10) 63#define SEND_INTERVAL GNUNET_TIME_relative_multiply ( \
64 GNUNET_TIME_UNIT_MILLISECONDS, 10)
63 65
64 66
65/** 67/**
@@ -208,29 +210,29 @@ static unsigned int msg_dropped;
208 * Show the results of the test (banwidth acheived) and log them to GAUGER 210 * Show the results of the test (banwidth acheived) and log them to GAUGER
209 */ 211 */
210static void 212static void
211show_end_data(void) 213show_end_data (void)
212{ 214{
213 static struct GNUNET_TIME_Absolute end_time; 215 static struct GNUNET_TIME_Absolute end_time;
214 static struct GNUNET_TIME_Relative total_time; 216 static struct GNUNET_TIME_Relative total_time;
215 217
216 end_time = GNUNET_TIME_absolute_get(); 218 end_time = GNUNET_TIME_absolute_get ();
217 total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time); 219 total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time);
218 fprintf(stderr, 220 fprintf (stderr,
219 "\nResults of test \"%s\"\n", 221 "\nResults of test \"%s\"\n",
220 test_name); 222 test_name);
221 fprintf(stderr, 223 fprintf (stderr,
222 "Test time %s\n", 224 "Test time %s\n",
223 GNUNET_STRINGS_relative_time_to_string(total_time, GNUNET_YES)); 225 GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES));
224 fprintf(stderr, 226 fprintf (stderr,
225 "Test bandwidth: %f kb/s\n", 227 "Test bandwidth: %f kb/s\n",
226 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms 228 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms
227 fprintf(stderr, 229 fprintf (stderr,
228 "Test throughput: %f packets/s\n\n", 230 "Test throughput: %f packets/s\n\n",
229 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms 231 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms
230 GAUGER("CADET", 232 GAUGER ("CADET",
231 test_name, 233 test_name,
232 total_packets * 1000.0 / (total_time.rel_value_us / 1000), 234 total_packets * 1000.0 / (total_time.rel_value_us / 1000),
233 "packets/s"); 235 "packets/s");
234} 236}
235 237
236 238
@@ -241,33 +243,33 @@ show_end_data(void)
241 * @param tc Task Context. 243 * @param tc Task Context.
242 */ 244 */
243static void 245static void
244shutdown_task(void *cls) 246shutdown_task (void *cls)
245{ 247{
246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "Ending test.\n"); 249 "Ending test.\n");
248 if (NULL != send_next_msg_task) 250 if (NULL != send_next_msg_task)
249 { 251 {
250 GNUNET_SCHEDULER_cancel(send_next_msg_task); 252 GNUNET_SCHEDULER_cancel (send_next_msg_task);
251 send_next_msg_task = NULL; 253 send_next_msg_task = NULL;
252 } 254 }
253 if (NULL != test_task) 255 if (NULL != test_task)
254 { 256 {
255 GNUNET_SCHEDULER_cancel(test_task); 257 GNUNET_SCHEDULER_cancel (test_task);
256 test_task = NULL; 258 test_task = NULL;
257 } 259 }
258 for (unsigned int i = 0; i < 2; i++) 260 for (unsigned int i = 0; i < 2; i++)
259 GNUNET_TESTBED_operation_done(t_op[i]); 261 GNUNET_TESTBED_operation_done (t_op[i]);
260 if (NULL != outgoing_ch) 262 if (NULL != outgoing_ch)
261 { 263 {
262 GNUNET_CADET_channel_destroy(outgoing_ch); 264 GNUNET_CADET_channel_destroy (outgoing_ch);
263 outgoing_ch = NULL; 265 outgoing_ch = NULL;
264 } 266 }
265 if (NULL != incoming_ch) 267 if (NULL != incoming_ch)
266 { 268 {
267 GNUNET_CADET_channel_destroy(incoming_ch); 269 GNUNET_CADET_channel_destroy (incoming_ch);
268 incoming_ch = NULL; 270 incoming_ch = NULL;
269 } 271 }
270 GNUNET_CADET_TEST_cleanup(test_ctx); 272 GNUNET_CADET_TEST_cleanup (test_ctx);
271} 273}
272 274
273 275
@@ -281,25 +283,25 @@ shutdown_task(void *cls)
281 * operation has executed successfully. 283 * operation has executed successfully.
282 */ 284 */
283static void 285static void
284stats_cont(void *cls, 286stats_cont (void *cls,
285 struct GNUNET_TESTBED_Operation *op, 287 struct GNUNET_TESTBED_Operation *op,
286 const char *emsg) 288 const char *emsg)
287{ 289{
288 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 290 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
289 "KA sent: %u, KA received: %u\n", 291 "KA sent: %u, KA received: %u\n",
290 ka_sent, 292 ka_sent,
291 ka_received); 293 ka_received);
292 if ((KEEPALIVE == test) && ((ka_sent < 2) || (ka_sent > ka_received + 1))) 294 if ((KEEPALIVE == test) && ((ka_sent < 2) || (ka_sent > ka_received + 1)))
293 { 295 {
294 GNUNET_break(0); 296 GNUNET_break (0);
295 ok--; 297 ok--;
296 } 298 }
297 GNUNET_TESTBED_operation_done(stats_op); 299 GNUNET_TESTBED_operation_done (stats_op);
298 300
299 if (NULL != disconnect_task) 301 if (NULL != disconnect_task)
300 GNUNET_SCHEDULER_cancel(disconnect_task); 302 GNUNET_SCHEDULER_cancel (disconnect_task);
301 disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 303 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
302 cls); 304 cls);
303} 305}
304 306
305 307
@@ -315,12 +317,12 @@ stats_cont(void *cls,
315 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 317 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
316 */ 318 */
317static int 319static int
318stats_iterator(void *cls, 320stats_iterator (void *cls,
319 const struct GNUNET_TESTBED_Peer *peer, 321 const struct GNUNET_TESTBED_Peer *peer,
320 const char *subsystem, 322 const char *subsystem,
321 const char *name, 323 const char *name,
322 uint64_t value, 324 uint64_t value,
323 int is_persistent) 325 int is_persistent)
324{ 326{
325 static const char *s_sent = "# keepalives sent"; 327 static const char *s_sent = "# keepalives sent";
326 static const char *s_recv = "# keepalives received"; 328 static const char *s_recv = "# keepalives received";
@@ -328,16 +330,17 @@ stats_iterator(void *cls,
328 static const char *cdrops = "# messages dropped due to slow client"; 330 static const char *cdrops = "# messages dropped due to slow client";
329 uint32_t i; 331 uint32_t i;
330 332
331 i = GNUNET_TESTBED_get_index(peer); 333 i = GNUNET_TESTBED_get_index (peer);
332 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n", i, 334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n", i,
333 subsystem, name, (unsigned long long)value); 335 subsystem, name, (unsigned long long) value);
334 if (0 == strncmp(s_sent, name, strlen(s_sent)) && 0 == i) 336 if ((0 == strncmp (s_sent, name, strlen (s_sent)))&&(0 == i))
335 ka_sent = value; 337 ka_sent = value;
336 if (0 == strncmp(s_recv, name, strlen(s_recv)) && peers_requested - 1 == i) 338 if ((0 == strncmp (s_recv, name, strlen (s_recv)))&&(peers_requested - 1 ==
339 i) )
337 ka_received = value; 340 ka_received = value;
338 if (0 == strncmp(rdrops, name, strlen(rdrops))) 341 if (0 == strncmp (rdrops, name, strlen (rdrops)))
339 msg_dropped += value; 342 msg_dropped += value;
340 if (0 == strncmp(cdrops, name, strlen(cdrops))) 343 if (0 == strncmp (cdrops, name, strlen (cdrops)))
341 msg_dropped += value; 344 msg_dropped += value;
342 345
343 return GNUNET_OK; 346 return GNUNET_OK;
@@ -350,26 +353,26 @@ stats_iterator(void *cls,
350 * @param cls Closure (line from which the task was scheduled). 353 * @param cls Closure (line from which the task was scheduled).
351 */ 354 */
352static void 355static void
353gather_stats_and_exit(void *cls) 356gather_stats_and_exit (void *cls)
354{ 357{
355 long l = (long)cls; 358 long l = (long) cls;
356 359
357 disconnect_task = NULL; 360 disconnect_task = NULL;
358 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 361 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
359 "gathering statistics from line %ld\n", 362 "gathering statistics from line %ld\n",
360 l); 363 l);
361 if (NULL != outgoing_ch) 364 if (NULL != outgoing_ch)
362 { 365 {
363 GNUNET_CADET_channel_destroy(outgoing_ch); 366 GNUNET_CADET_channel_destroy (outgoing_ch);
364 outgoing_ch = NULL; 367 outgoing_ch = NULL;
365 } 368 }
366 stats_op = GNUNET_TESTBED_get_statistics(peers_running, 369 stats_op = GNUNET_TESTBED_get_statistics (peers_running,
367 testbed_peers, 370 testbed_peers,
368 "cadet", 371 "cadet",
369 NULL, 372 NULL,
370 &stats_iterator, 373 &stats_iterator,
371 stats_cont, 374 stats_cont,
372 cls); 375 cls);
373} 376}
374 377
375 378
@@ -379,18 +382,18 @@ gather_stats_and_exit(void *cls)
379 * @param line Line in the code the abort is requested from (__LINE__). 382 * @param line Line in the code the abort is requested from (__LINE__).
380 */ 383 */
381static void 384static void
382abort_test(long line) 385abort_test (long line)
383{ 386{
384 if (NULL != disconnect_task) 387 if (NULL != disconnect_task)
385 { 388 {
386 GNUNET_SCHEDULER_cancel(disconnect_task); 389 GNUNET_SCHEDULER_cancel (disconnect_task);
387 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 390 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
388 "Aborting test from %ld\n", 391 "Aborting test from %ld\n",
389 line); 392 line);
390 disconnect_task = 393 disconnect_task =
391 GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, 394 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
392 (void *)line); 395 (void *) line);
393 } 396 }
394} 397}
395 398
396 399
@@ -402,7 +405,7 @@ abort_test(long line)
402 * @param channel Channel to send the message on. 405 * @param channel Channel to send the message on.
403 */ 406 */
404static void 407static void
405send_test_message(struct GNUNET_CADET_Channel *channel) 408send_test_message (struct GNUNET_CADET_Channel *channel)
406{ 409{
407 struct GNUNET_MQ_Envelope *env; 410 struct GNUNET_MQ_Envelope *env;
408 struct GNUNET_MessageHeader *msg; 411 struct GNUNET_MessageHeader *msg;
@@ -410,56 +413,56 @@ send_test_message(struct GNUNET_CADET_Channel *channel)
410 int payload; 413 int payload;
411 int size; 414 int size;
412 415
413 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
414 "Sending test message on channel %p\n", 417 "Sending test message on channel %p\n",
415 channel); 418 channel);
416 size = size_payload; 419 size = size_payload;
417 if (GNUNET_NO == initialized) 420 if (GNUNET_NO == initialized)
418 { 421 {
419 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n"); 422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n");
420 size += 1000; 423 size += 1000;
421 payload = data_sent; 424 payload = data_sent;
422 if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer 425 if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer
423 data_sent++; 426 data_sent++;
424 } 427 }
425 else if (SPEED == test || SPEED_ACK == test) 428 else if ((SPEED == test)||(SPEED_ACK == test))
426 { 429 {
427 if (get_target_channel() == channel) 430 if (get_target_channel () == channel)
428 {
429 payload = ack_sent;
430 size += ack_sent;
431 ack_sent++;
432 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
433 "Sending ACK %u [%d bytes]\n",
434 payload, size);
435 }
436 else
437 {
438 payload = data_sent;
439 size += data_sent;
440 data_sent++;
441 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
442 "Sending DATA %u [%d bytes]\n",
443 data_sent, size);
444 }
445 }
446 else if (FORWARD == test)
447 { 431 {
448 payload = ack_sent; 432 payload = ack_sent;
433 size += ack_sent;
434 ack_sent++;
435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
436 "Sending ACK %u [%d bytes]\n",
437 payload, size);
449 } 438 }
450 else if (P2P_SIGNAL == test) 439 else
451 { 440 {
452 payload = data_sent; 441 payload = data_sent;
442 size += data_sent;
443 data_sent++;
444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
445 "Sending DATA %u [%d bytes]\n",
446 data_sent, size);
453 } 447 }
448 }
449 else if (FORWARD == test)
450 {
451 payload = ack_sent;
452 }
453 else if (P2P_SIGNAL == test)
454 {
455 payload = data_sent;
456 }
454 else 457 else
455 { 458 {
456 GNUNET_assert(0); 459 GNUNET_assert (0);
457 } 460 }
458 env = GNUNET_MQ_msg_extra(msg, size, GNUNET_MESSAGE_TYPE_DUMMY); 461 env = GNUNET_MQ_msg_extra (msg, size, GNUNET_MESSAGE_TYPE_DUMMY);
459 462
460 data = (uint32_t *)&msg[1]; 463 data = (uint32_t *) &msg[1];
461 *data = htonl(payload); 464 *data = htonl (payload);
462 GNUNET_MQ_send(GNUNET_CADET_get_mq(channel), env); 465 GNUNET_MQ_send (GNUNET_CADET_get_mq (channel), env);
463} 466}
464 467
465 468
@@ -470,30 +473,30 @@ send_test_message(struct GNUNET_CADET_Channel *channel)
470 * @param cls Closure (unused). 473 * @param cls Closure (unused).
471 */ 474 */
472static void 475static void
473send_next_msg(void *cls) 476send_next_msg (void *cls)
474{ 477{
475 struct GNUNET_CADET_Channel *channel; 478 struct GNUNET_CADET_Channel *channel;
476 479
477 send_next_msg_task = NULL; 480 send_next_msg_task = NULL;
478 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "Sending next message: %d\n", 482 "Sending next message: %d\n",
480 data_sent); 483 data_sent);
481 484
482 channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch; 485 channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch;
483 GNUNET_assert(NULL != channel); 486 GNUNET_assert (NULL != channel);
484 GNUNET_assert(SPEED == test); 487 GNUNET_assert (SPEED == test);
485 send_test_message(channel); 488 send_test_message (channel);
486 if (data_sent < total_packets) 489 if (data_sent < total_packets)
487 { 490 {
488 /* SPEED test: Send all messages as soon as possible */ 491 /* SPEED test: Send all messages as soon as possible */
489 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "Scheduling message %d\n", 493 "Scheduling message %d\n",
491 data_sent + 1); 494 data_sent + 1);
492 send_next_msg_task = 495 send_next_msg_task =
493 GNUNET_SCHEDULER_add_delayed(SEND_INTERVAL, 496 GNUNET_SCHEDULER_add_delayed (SEND_INTERVAL,
494 &send_next_msg, 497 &send_next_msg,
495 NULL); 498 NULL);
496 } 499 }
497} 500}
498 501
499 502
@@ -506,8 +509,8 @@ send_next_msg(void *cls)
506 * #GNUNET_SYSERR to close it (signal serious error). 509 * #GNUNET_SYSERR to close it (signal serious error).
507 */ 510 */
508static int 511static int
509check_data(void *cls, 512check_data (void *cls,
510 const struct GNUNET_MessageHeader *message) 513 const struct GNUNET_MessageHeader *message)
511{ 514{
512 return GNUNET_OK; /* all is well-formed */ 515 return GNUNET_OK; /* all is well-formed */
513} 516}
@@ -520,8 +523,8 @@ check_data(void *cls,
520 * @param message the actual message 523 * @param message the actual message
521 */ 524 */
522static void 525static void
523handle_data(void *cls, 526handle_data (void *cls,
524 const struct GNUNET_MessageHeader *message) 527 const struct GNUNET_MessageHeader *message)
525{ 528{
526 struct CadetTestChannelWrapper *ch = cls; 529 struct CadetTestChannelWrapper *ch = cls;
527 struct GNUNET_CADET_Channel *channel = ch->ch; 530 struct GNUNET_CADET_Channel *channel = ch->ch;
@@ -529,73 +532,73 @@ handle_data(void *cls,
529 uint32_t payload; 532 uint32_t payload;
530 int *counter; 533 int *counter;
531 534
532 GNUNET_CADET_receive_done(channel); 535 GNUNET_CADET_receive_done (channel);
533 counter = get_target_channel() == channel ? &data_received : &ack_received; 536 counter = get_target_channel () == channel ? &data_received : &ack_received;
534 if (channel == outgoing_ch) 537 if (channel == outgoing_ch)
535 { 538 {
536 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 539 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
537 "Root client got a message.\n"); 540 "Root client got a message.\n");
538 } 541 }
539 else if (channel == incoming_ch) 542 else if (channel == incoming_ch)
540 { 543 {
541 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 544 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
542 "Leaf client got a message.\n"); 545 "Leaf client got a message.\n");
543 } 546 }
544 else 547 else
545 { 548 {
546 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 549 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
547 "Unknown channel %p.\n", 550 "Unknown channel %p.\n",
548 channel); 551 channel);
549 GNUNET_assert(0); 552 GNUNET_assert (0);
550 } 553 }
551 554
552 data = (uint32_t *)&message[1]; 555 data = (uint32_t *) &message[1];
553 payload = ntohl(*data); 556 payload = ntohl (*data);
554 if (payload == *counter) 557 if (payload == *counter)
555 { 558 {
556 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 559 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
557 "Payload as expected: %u\n", 560 "Payload as expected: %u\n",
558 payload); 561 payload);
559 } 562 }
560 else 563 else
561 { 564 {
562 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 565 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
563 "Received payload %u, expected: %u\n", 566 "Received payload %u, expected: %u\n",
564 payload, *counter); 567 payload, *counter);
565 } 568 }
566 (*counter)++; 569 (*counter)++;
567 if (get_target_channel() == channel) /* Got "data" */ 570 if (get_target_channel () == channel) /* Got "data" */
571 {
572 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
573 " received data %u\n",
574 data_received);
575 if (data_received < total_packets)
576 return;
577 }
578 else /* Got "ack" */
579 {
580 if ((SPEED_ACK == test) ||(SPEED == test) )
568 { 581 {
569 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 582 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received);
570 " received data %u\n", 583 /* Send more data */
571 data_received); 584 send_test_message (channel);
572 if (data_received < total_packets) 585 if ((ack_received < total_packets) &&(SPEED != test) )
586 return;
587 if ((ok == 2) &&(SPEED == test) )
573 return; 588 return;
589 show_end_data ();
574 } 590 }
575 else /* Got "ack" */ 591 if (test == P2P_SIGNAL)
592 {
593 GNUNET_CADET_channel_destroy (incoming_ch);
594 incoming_ch = NULL;
595 }
596 else
576 { 597 {
577 if (SPEED_ACK == test || SPEED == test) 598 GNUNET_CADET_channel_destroy (outgoing_ch);
578 { 599 outgoing_ch = NULL;
579 GNUNET_log(GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received);
580 /* Send more data */
581 send_test_message(channel);
582 if (ack_received < total_packets && SPEED != test)
583 return;
584 if (ok == 2 && SPEED == test)
585 return;
586 show_end_data();
587 }
588 if (test == P2P_SIGNAL)
589 {
590 GNUNET_CADET_channel_destroy(incoming_ch);
591 incoming_ch = NULL;
592 }
593 else
594 {
595 GNUNET_CADET_channel_destroy(outgoing_ch);
596 outgoing_ch = NULL;
597 }
598 } 600 }
601 }
599} 602}
600 603
601 604
@@ -612,37 +615,37 @@ handle_data(void *cls,
612 * received on the @a channel. 615 * received on the @a channel.
613 */ 616 */
614static void * 617static void *
615connect_handler(void *cls, 618connect_handler (void *cls,
616 struct GNUNET_CADET_Channel *channel, 619 struct GNUNET_CADET_Channel *channel,
617 const struct GNUNET_PeerIdentity *source) 620 const struct GNUNET_PeerIdentity *source)
618{ 621{
619 struct CadetTestChannelWrapper *ch; 622 struct CadetTestChannelWrapper *ch;
620 long peer = (long)cls; 623 long peer = (long) cls;
621 624
622 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 625 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
623 "Incoming channel from %s to %ld: %p\n", 626 "Incoming channel from %s to %ld: %p\n",
624 GNUNET_i2s(source), 627 GNUNET_i2s (source),
625 peer, 628 peer,
626 channel); 629 channel);
627 if (peer == peers_requested - 1) 630 if (peer == peers_requested - 1)
631 {
632 if (NULL != incoming_ch)
628 { 633 {
629 if (NULL != incoming_ch) 634 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
630 { 635 "Duplicate incoming channel for client %lu\n",
631 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 636 (long) cls);
632 "Duplicate incoming channel for client %lu\n", 637 GNUNET_assert (0);
633 (long)cls);
634 GNUNET_assert(0);
635 }
636 incoming_ch = channel;
637 } 638 }
639 incoming_ch = channel;
640 }
638 else 641 else
639 { 642 {
640 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 643 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
641 "Incoming channel for unexpected peer #%lu\n", 644 "Incoming channel for unexpected peer #%lu\n",
642 (long)cls); 645 (long) cls);
643 GNUNET_assert(0); 646 GNUNET_assert (0);
644 } 647 }
645 ch = GNUNET_new(struct CadetTestChannelWrapper); 648 ch = GNUNET_new (struct CadetTestChannelWrapper);
646 ch->ch = channel; 649 ch->ch = channel;
647 650
648 return ch; 651 return ch;
@@ -661,28 +664,28 @@ connect_handler(void *cls,
661 * @param channel Connection to the other end (henceforth invalid). 664 * @param channel Connection to the other end (henceforth invalid).
662 */ 665 */
663static void 666static void
664disconnect_handler(void *cls, 667disconnect_handler (void *cls,
665 const struct GNUNET_CADET_Channel *channel) 668 const struct GNUNET_CADET_Channel *channel)
666{ 669{
667 struct CadetTestChannelWrapper *ch_w = cls; 670 struct CadetTestChannelWrapper *ch_w = cls;
668 671
669 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 672 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
670 "Channel disconnected at %d\n", 673 "Channel disconnected at %d\n",
671 ok); 674 ok);
672 GNUNET_assert(ch_w->ch == channel); 675 GNUNET_assert (ch_w->ch == channel);
673 if (channel == incoming_ch) 676 if (channel == incoming_ch)
674 incoming_ch = NULL; 677 incoming_ch = NULL;
675 else if (outgoing_ch == channel) 678 else if (outgoing_ch == channel)
676 outgoing_ch = NULL; 679 outgoing_ch = NULL;
677 else 680 else
678 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 681 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
679 "Disconnect on unknown channel %p\n", 682 "Disconnect on unknown channel %p\n",
680 channel); 683 channel);
681 if (NULL != disconnect_task) 684 if (NULL != disconnect_task)
682 GNUNET_SCHEDULER_cancel(disconnect_task); 685 GNUNET_SCHEDULER_cancel (disconnect_task);
683 disconnect_task = GNUNET_SCHEDULER_add_now(&gather_stats_and_exit, 686 disconnect_task = GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
684 (void *)__LINE__); 687 (void *) __LINE__);
685 GNUNET_free(ch_w); 688 GNUNET_free (ch_w);
686} 689}
687 690
688 691
@@ -695,41 +698,41 @@ disconnect_handler(void *cls,
695 * @param cls Closure (unused). 698 * @param cls Closure (unused).
696 */ 699 */
697static void 700static void
698start_test(void *cls) 701start_test (void *cls)
699{ 702{
700 struct GNUNET_MQ_MessageHandler handlers[] = { 703 struct GNUNET_MQ_MessageHandler handlers[] = {
701 GNUNET_MQ_hd_var_size(data, 704 GNUNET_MQ_hd_var_size (data,
702 GNUNET_MESSAGE_TYPE_DUMMY, 705 GNUNET_MESSAGE_TYPE_DUMMY,
703 struct GNUNET_MessageHeader, 706 struct GNUNET_MessageHeader,
704 NULL), 707 NULL),
705 GNUNET_MQ_handler_end() 708 GNUNET_MQ_handler_end ()
706 }; 709 };
707 struct CadetTestChannelWrapper *ch; 710 struct CadetTestChannelWrapper *ch;
708 enum GNUNET_CADET_ChannelOption flags; 711 enum GNUNET_CADET_ChannelOption flags;
709 712
710 test_task = NULL; 713 test_task = NULL;
711 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
712 "In start_test\n"); 715 "In start_test\n");
713 start_time = GNUNET_TIME_absolute_get(); 716 start_time = GNUNET_TIME_absolute_get ();
714 ch = GNUNET_new(struct CadetTestChannelWrapper); 717 ch = GNUNET_new (struct CadetTestChannelWrapper);
715 outgoing_ch = GNUNET_CADET_channel_create(h1, 718 outgoing_ch = GNUNET_CADET_channel_create (h1,
716 ch, 719 ch,
717 p_id[1], 720 p_id[1],
718 &port, 721 &port,
719 flags, 722 flags,
720 NULL, 723 NULL,
721 &disconnect_handler, 724 &disconnect_handler,
722 handlers); 725 handlers);
723 ch->ch = outgoing_ch; 726 ch->ch = outgoing_ch;
724 GNUNET_assert(NULL == disconnect_task); 727 GNUNET_assert (NULL == disconnect_task);
725 disconnect_task 728 disconnect_task
726 = GNUNET_SCHEDULER_add_delayed(short_time, 729 = GNUNET_SCHEDULER_add_delayed (short_time,
727 &gather_stats_and_exit, 730 &gather_stats_and_exit,
728 (void *)__LINE__); 731 (void *) __LINE__);
729 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
730 "Sending data initializer on channel %p...\n", 733 "Sending data initializer on channel %p...\n",
731 outgoing_ch); 734 outgoing_ch);
732 send_test_message(outgoing_ch); 735 send_test_message (outgoing_ch);
733} 736}
734 737
735 738
@@ -743,36 +746,36 @@ start_test(void *cls)
743 * NULL if the operation is successfull 746 * NULL if the operation is successfull
744 */ 747 */
745static void 748static void
746pi_cb(void *cls, 749pi_cb (void *cls,
747 struct GNUNET_TESTBED_Operation *op, 750 struct GNUNET_TESTBED_Operation *op,
748 const struct GNUNET_TESTBED_PeerInformation *pinfo, 751 const struct GNUNET_TESTBED_PeerInformation *pinfo,
749 const char *emsg) 752 const char *emsg)
750{ 753{
751 long i = (long)cls; 754 long i = (long) cls;
752 755
753 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
754 "ID callback for %ld\n", 757 "ID callback for %ld\n",
755 i); 758 i);
756 if ((NULL == pinfo) || 759 if ((NULL == pinfo) ||
757 (NULL != emsg)) 760 (NULL != emsg))
758 { 761 {
759 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 762 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
760 "pi_cb: %s\n", 763 "pi_cb: %s\n",
761 emsg); 764 emsg);
762 abort_test(__LINE__); 765 abort_test (__LINE__);
763 return; 766 return;
764 } 767 }
765 p_id[i] = pinfo->result.id; 768 p_id[i] = pinfo->result.id;
766 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
767 "id: %s\n", 770 "id: %s\n",
768 GNUNET_i2s(p_id[i])); 771 GNUNET_i2s (p_id[i]));
769 p_ids++; 772 p_ids++;
770 if (p_ids < 2) 773 if (p_ids < 2)
771 return; 774 return;
772 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
773 "Got all IDs, starting test\n"); 776 "Got all IDs, starting test\n");
774 test_task = GNUNET_SCHEDULER_add_now(&start_test, 777 test_task = GNUNET_SCHEDULER_add_now (&start_test,
775 NULL); 778 NULL);
776} 779}
777 780
778 781
@@ -786,33 +789,33 @@ pi_cb(void *cls,
786 * @param cadets Handle to each of the CADETs of the peers. 789 * @param cadets Handle to each of the CADETs of the peers.
787 */ 790 */
788static void 791static void
789tmain(void *cls, 792tmain (void *cls,
790 struct GNUNET_CADET_TEST_Context *ctx, 793 struct GNUNET_CADET_TEST_Context *ctx,
791 unsigned int num_peers, 794 unsigned int num_peers,
792 struct GNUNET_TESTBED_Peer **peers, 795 struct GNUNET_TESTBED_Peer **peers,
793 struct GNUNET_CADET_Handle **cadets) 796 struct GNUNET_CADET_Handle **cadets)
794{ 797{
795 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
796 "test main\n"); 799 "test main\n");
797 test_ctx = ctx; 800 test_ctx = ctx;
798 peers_running = num_peers; 801 peers_running = num_peers;
799 GNUNET_assert(peers_running == peers_requested); 802 GNUNET_assert (peers_running == peers_requested);
800 testbed_peers = peers; 803 testbed_peers = peers;
801 h1 = cadets[0]; 804 h1 = cadets[0];
802 h2 = cadets[num_peers - 1]; 805 h2 = cadets[num_peers - 1];
803 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, 806 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
804 NULL); 807 NULL);
805 p_ids = 0; 808 p_ids = 0;
806 t_op[0] = GNUNET_TESTBED_peer_get_information(peers[0], 809 t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
807 GNUNET_TESTBED_PIT_IDENTITY, 810 GNUNET_TESTBED_PIT_IDENTITY,
808 &pi_cb, 811 &pi_cb,
809 (void *)0L); 812 (void *) 0L);
810 t_op[1] = GNUNET_TESTBED_peer_get_information(peers[num_peers - 1], 813 t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1],
811 GNUNET_TESTBED_PIT_IDENTITY, 814 GNUNET_TESTBED_PIT_IDENTITY,
812 &pi_cb, 815 &pi_cb,
813 (void *)1L); 816 (void *) 1L);
814 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
815 "requested peer ids\n"); 818 "requested peer ids\n");
816} 819}
817 820
818 821
@@ -820,67 +823,67 @@ tmain(void *cls,
820 * Main: start test 823 * Main: start test
821 */ 824 */
822int 825int
823main(int argc, 826main (int argc,
824 char *argv[]) 827 char *argv[])
825{ 828{
826 static const struct GNUNET_HashCode *ports[2]; 829 static const struct GNUNET_HashCode *ports[2];
827 struct GNUNET_MQ_MessageHandler handlers[] = { 830 struct GNUNET_MQ_MessageHandler handlers[] = {
828 GNUNET_MQ_hd_var_size(data, 831 GNUNET_MQ_hd_var_size (data,
829 GNUNET_MESSAGE_TYPE_DUMMY, 832 GNUNET_MESSAGE_TYPE_DUMMY,
830 struct GNUNET_MessageHeader, 833 struct GNUNET_MessageHeader,
831 NULL), 834 NULL),
832 GNUNET_MQ_handler_end() 835 GNUNET_MQ_handler_end ()
833 }; 836 };
834 const char *config_file = "test_cadet.conf"; 837 const char *config_file = "test_cadet.conf";
835 char port_id[] = "test port"; 838 char port_id[] = "test port";
836 struct GNUNET_GETOPT_CommandLineOption options[] = { 839 struct GNUNET_GETOPT_CommandLineOption options[] = {
837 GNUNET_GETOPT_option_relative_time('t', 840 GNUNET_GETOPT_option_relative_time ('t',
838 "time", 841 "time",
839 "short_time", 842 "short_time",
840 gettext_noop("set short timeout"), 843 gettext_noop ("set short timeout"),
841 &short_time), 844 &short_time),
842 GNUNET_GETOPT_option_uint('m', 845 GNUNET_GETOPT_option_uint ('m',
843 "messages", 846 "messages",
844 "NUM_MESSAGES", 847 "NUM_MESSAGES",
845 gettext_noop("set number of messages to send"), 848 gettext_noop ("set number of messages to send"),
846 &total_packets), 849 &total_packets),
847 GNUNET_GETOPT_option_uint('p', 850 GNUNET_GETOPT_option_uint ('p',
848 "peers", 851 "peers",
849 "NUM_PEERS", 852 "NUM_PEERS",
850 gettext_noop("number of peers to launch"), 853 gettext_noop ("number of peers to launch"),
851 &peers_requested), 854 &peers_requested),
852 GNUNET_GETOPT_OPTION_END 855 GNUNET_GETOPT_OPTION_END
853 }; 856 };
854 857
855 GNUNET_log_setup("test-cadet-flow", 858 GNUNET_log_setup ("test-cadet-flow",
856 "DEBUG", 859 "DEBUG",
857 NULL); 860 NULL);
858 total_packets = TOTAL_PACKETS; 861 total_packets = TOTAL_PACKETS;
859 short_time = SHORT_TIME; 862 short_time = SHORT_TIME;
860 if (-1 == GNUNET_GETOPT_run(argv[0], 863 if (-1 == GNUNET_GETOPT_run (argv[0],
861 options, 864 options,
862 argc, 865 argc,
863 argv)) 866 argv))
864 { 867 {
865 fprintf(stderr, 868 fprintf (stderr,
866 "test failed: problem with CLI parameters\n"); 869 "test failed: problem with CLI parameters\n");
867 return 1; 870 return 1;
868 } 871 }
869 GNUNET_CRYPTO_hash(port_id, 872 GNUNET_CRYPTO_hash (port_id,
870 sizeof(port_id), 873 sizeof(port_id),
871 &port); 874 &port);
872 ports[0] = &port; 875 ports[0] = &port;
873 ports[1] = NULL; 876 ports[1] = NULL;
874 GNUNET_CADET_TEST_ruN("test_cadet_flow", 877 GNUNET_CADET_TEST_ruN ("test_cadet_flow",
875 config_file, 878 config_file,
876 peers_requested, 879 peers_requested,
877 &tmain, 880 &tmain,
878 NULL, /* tmain cls */ 881 NULL, /* tmain cls */
879 &connect_handler, 882 &connect_handler,
880 NULL, 883 NULL,
881 &disconnect_handler, 884 &disconnect_handler,
882 handlers, 885 handlers,
883 ports); 886 ports);
884 return 0; 887 return 0;
885} 888}
886 889
diff --git a/src/cadet/test_cadet_local_mq.c b/src/cadet/test_cadet_local_mq.c
index 7ae0a90c4..c56b510ae 100644
--- a/src/cadet/test_cadet_local_mq.c
+++ b/src/cadet/test_cadet_local_mq.c
@@ -36,7 +36,8 @@
36/** 36/**
37 * Test message structure. 37 * Test message structure.
38 */ 38 */
39struct GNUNET_CADET_TestMsg { 39struct GNUNET_CADET_TestMsg
40{
40 /** 41 /**
41 * Type: #TEST_MESSAGE_TYPE 42 * Type: #TEST_MESSAGE_TYPE
42 * 43 *
@@ -73,46 +74,46 @@ static struct GNUNET_SCHEDULER_Task *connect_task;
73 * @param cls Closue (unused). 74 * @param cls Closue (unused).
74 */ 75 */
75static void 76static void
76do_connect(void *cls); 77do_connect (void *cls);
77 78
78 79
79/** 80/**
80 * Shutdown nicely 81 * Shutdown nicely
81 */ 82 */
82static void 83static void
83do_shutdown(void *cls) 84do_shutdown (void *cls)
84{ 85{
85 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "shutdown\n"); 87 "shutdown\n");
87 if (NULL != abort_task) 88 if (NULL != abort_task)
88 { 89 {
89 GNUNET_SCHEDULER_cancel(abort_task); 90 GNUNET_SCHEDULER_cancel (abort_task);
90 abort_task = NULL; 91 abort_task = NULL;
91 } 92 }
92 if (NULL != ch) 93 if (NULL != ch)
93 { 94 {
94 GNUNET_CADET_channel_destroy(ch); 95 GNUNET_CADET_channel_destroy (ch);
95 ch = NULL; 96 ch = NULL;
96 } 97 }
97 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
98 "Disconnect client 1\n"); 99 "Disconnect client 1\n");
99 if (NULL != cadet_peer_1) 100 if (NULL != cadet_peer_1)
100 { 101 {
101 GNUNET_CADET_disconnect(cadet_peer_1); 102 GNUNET_CADET_disconnect (cadet_peer_1);
102 cadet_peer_1 = NULL; 103 cadet_peer_1 = NULL;
103 } 104 }
104 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Disconnect client 2\n"); 106 "Disconnect client 2\n");
106 if (NULL != cadet_peer_2) 107 if (NULL != cadet_peer_2)
107 { 108 {
108 GNUNET_CADET_disconnect(cadet_peer_2); 109 GNUNET_CADET_disconnect (cadet_peer_2);
109 cadet_peer_2 = NULL; 110 cadet_peer_2 = NULL;
110 } 111 }
111 if (NULL != connect_task) 112 if (NULL != connect_task)
112 { 113 {
113 GNUNET_SCHEDULER_cancel(connect_task); 114 GNUNET_SCHEDULER_cancel (connect_task);
114 connect_task = NULL; 115 connect_task = NULL;
115 } 116 }
116} 117}
117 118
118 119
@@ -120,14 +121,14 @@ do_shutdown(void *cls)
120 * Something went wrong and timed out. Kill everything and set error flag 121 * Something went wrong and timed out. Kill everything and set error flag
121 */ 122 */
122static void 123static void
123do_abort(void *cls) 124do_abort (void *cls)
124{ 125{
125 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
126 "ABORT from line %ld\n", 127 "ABORT from line %ld\n",
127 (long)cls); 128 (long) cls);
128 result = GNUNET_SYSERR; 129 result = GNUNET_SYSERR;
129 abort_task = NULL; 130 abort_task = NULL;
130 GNUNET_SCHEDULER_shutdown(); 131 GNUNET_SCHEDULER_shutdown ();
131} 132}
132 133
133/** 134/**
@@ -143,14 +144,14 @@ do_abort(void *cls)
143 * received on the @a channel. 144 * received on the @a channel.
144 */ 145 */
145static void * 146static void *
146connected(void *cls, 147connected (void *cls,
147 struct GNUNET_CADET_Channel *channel, 148 struct GNUNET_CADET_Channel *channel,
148 const struct GNUNET_PeerIdentity *source) 149 const struct GNUNET_PeerIdentity *source)
149{ 150{
150 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
151 "connected %s, cls: %p\n", 152 "connected %s, cls: %p\n",
152 GNUNET_i2s(source), 153 GNUNET_i2s (source),
153 cls); 154 cls);
154 return channel; 155 return channel;
155} 156}
156 157
@@ -166,12 +167,12 @@ connected(void *cls,
166 * @param channel Connection to the other end (henceforth invalid). 167 * @param channel Connection to the other end (henceforth invalid).
167 */ 168 */
168static void 169static void
169disconnected(void *cls, 170disconnected (void *cls,
170 const struct GNUNET_CADET_Channel *channel) 171 const struct GNUNET_CADET_Channel *channel)
171{ 172{
172 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
173 "disconnected channel %p, cls: %p\n", 174 "disconnected channel %p, cls: %p\n",
174 channel, cls); 175 channel, cls);
175 if (channel == ch) 176 if (channel == ch)
176 ch = NULL; 177 ch = NULL;
177} 178}
@@ -184,19 +185,19 @@ disconnected(void *cls,
184 * @param msg A message with the details of the new incoming channel 185 * @param msg A message with the details of the new incoming channel
185 */ 186 */
186static void 187static void
187handle_data_received(void *cls, 188handle_data_received (void *cls,
188 const struct GNUNET_CADET_TestMsg *msg) 189 const struct GNUNET_CADET_TestMsg *msg)
189{ 190{
190 uint64_t payload; 191 uint64_t payload;
191 192
192 payload = GNUNET_ntohll(msg->payload); 193 payload = GNUNET_ntohll (msg->payload);
193 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Data callback payload %llu with cls: %p! Shutting down.\n", 195 "Data callback payload %llu with cls: %p! Shutting down.\n",
195 (unsigned long long)payload, 196 (unsigned long long) payload,
196 cls); 197 cls);
197 GNUNET_assert(42 == payload); 198 GNUNET_assert (42 == payload);
198 got_data = GNUNET_YES; 199 got_data = GNUNET_YES;
199 GNUNET_SCHEDULER_shutdown(); 200 GNUNET_SCHEDULER_shutdown ();
200} 201}
201 202
202 203
@@ -206,10 +207,10 @@ handle_data_received(void *cls,
206 * @param cls Closure (unused). 207 * @param cls Closure (unused).
207 */ 208 */
208static void 209static void
209message_sent(void *cls) 210message_sent (void *cls)
210{ 211{
211 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
212 "message sent\n"); 213 "message sent\n");
213} 214}
214 215
215 216
@@ -219,7 +220,7 @@ message_sent(void *cls)
219 * @param cls Closure (unused). 220 * @param cls Closure (unused).
220 */ 221 */
221static void 222static void
222do_connect(void *cls) 223do_connect (void *cls)
223{ 224{
224 struct GNUNET_PeerIdentity id; 225 struct GNUNET_PeerIdentity id;
225 struct GNUNET_MQ_Handle *mq; 226 struct GNUNET_MQ_Handle *mq;
@@ -227,32 +228,32 @@ do_connect(void *cls)
227 struct GNUNET_CADET_TestMsg *msg; 228 struct GNUNET_CADET_TestMsg *msg;
228 229
229 struct GNUNET_MQ_MessageHandler handlers[] = { 230 struct GNUNET_MQ_MessageHandler handlers[] = {
230 GNUNET_MQ_hd_fixed_size(data_received, 231 GNUNET_MQ_hd_fixed_size (data_received,
231 TEST_MESSAGE_TYPE, 232 TEST_MESSAGE_TYPE,
232 struct GNUNET_CADET_TestMsg, 233 struct GNUNET_CADET_TestMsg,
233 cadet_peer_1), 234 cadet_peer_1),
234 GNUNET_MQ_handler_end() 235 GNUNET_MQ_handler_end ()
235 }; 236 };
236 237
237 connect_task = NULL; 238 connect_task = NULL;
238 GNUNET_TESTING_peer_get_identity(me, &id); 239 GNUNET_TESTING_peer_get_identity (me, &id);
239 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
240 "creating channel\n"); 241 "creating channel\n");
241 ch = GNUNET_CADET_channel_create(cadet_peer_1, /* cadet handle */ 242 ch = GNUNET_CADET_channel_create (cadet_peer_1, /* cadet handle */
242 NULL, /* channel cls */ 243 NULL, /* channel cls */
243 &id, /* destination */ 244 &id, /* destination */
244 GC_u2h(TEST_MESSAGE_TYPE), /* port */ 245 GC_u2h (TEST_MESSAGE_TYPE), /* port */
245 NULL, /* window change */ 246 NULL, /* window change */
246 &disconnected, /* disconnect handler */ 247 &disconnected, /* disconnect handler */
247 handlers /* traffic handlers */ 248 handlers /* traffic handlers */
248 ); 249 );
249 env = GNUNET_MQ_msg(msg, TEST_MESSAGE_TYPE); 250 env = GNUNET_MQ_msg (msg, TEST_MESSAGE_TYPE);
250 msg->payload = GNUNET_htonll(42); 251 msg->payload = GNUNET_htonll (42);
251 mq = GNUNET_CADET_get_mq(ch); 252 mq = GNUNET_CADET_get_mq (ch);
252 GNUNET_MQ_notify_sent(env, &message_sent, NULL); 253 GNUNET_MQ_notify_sent (env, &message_sent, NULL);
253 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
254 "sending message\n"); 255 "sending message\n");
255 GNUNET_MQ_send(mq, env); 256 GNUNET_MQ_send (mq, env);
256} 257}
257 258
258 259
@@ -264,53 +265,53 @@ do_connect(void *cls)
264 * @param peer Testing peer handle. 265 * @param peer Testing peer handle.
265 */ 266 */
266static void 267static void
267run(void *cls, 268run (void *cls,
268 const struct GNUNET_CONFIGURATION_Handle *cfg, 269 const struct GNUNET_CONFIGURATION_Handle *cfg,
269 struct GNUNET_TESTING_Peer *peer) 270 struct GNUNET_TESTING_Peer *peer)
270{ 271{
271 struct GNUNET_MQ_MessageHandler handlers[] = { 272 struct GNUNET_MQ_MessageHandler handlers[] = {
272 GNUNET_MQ_hd_fixed_size(data_received, 273 GNUNET_MQ_hd_fixed_size (data_received,
273 TEST_MESSAGE_TYPE, 274 TEST_MESSAGE_TYPE,
274 struct GNUNET_CADET_TestMsg, 275 struct GNUNET_CADET_TestMsg,
275 cadet_peer_2), 276 cadet_peer_2),
276 GNUNET_MQ_handler_end() 277 GNUNET_MQ_handler_end ()
277 }; 278 };
278 struct GNUNET_TIME_Relative delay; 279 struct GNUNET_TIME_Relative delay;
279 280
280 me = peer; 281 me = peer;
281 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 282 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
282 NULL); 283 NULL);
283 delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15); 284 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15);
284 abort_task = GNUNET_SCHEDULER_add_delayed(delay, 285 abort_task = GNUNET_SCHEDULER_add_delayed (delay,
285 &do_abort, 286 &do_abort,
286 (void *)(long)__LINE__); 287 (void *) (long) __LINE__);
287 cadet_peer_1 = GNUNET_CADET_connect(cfg); 288 cadet_peer_1 = GNUNET_CADET_connect (cfg);
288 cadet_peer_2 = GNUNET_CADET_connect(cfg); 289 cadet_peer_2 = GNUNET_CADET_connect (cfg);
289 290
290 if ((NULL == cadet_peer_1) || 291 if ((NULL == cadet_peer_1) ||
291 (NULL == cadet_peer_2)) 292 (NULL == cadet_peer_2))
292 { 293 {
293 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 294 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
294 "Couldn't connect to cadet\n"); 295 "Couldn't connect to cadet\n");
295 result = GNUNET_SYSERR; 296 result = GNUNET_SYSERR;
296 GNUNET_SCHEDULER_shutdown(); 297 GNUNET_SCHEDULER_shutdown ();
297 return; 298 return;
298 } 299 }
299 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CADET 1: %p\n", cadet_peer_1); 300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CADET 1: %p\n", cadet_peer_1);
300 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CADET 2: %p\n", cadet_peer_2); 301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CADET 2: %p\n", cadet_peer_2);
301 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "handlers 2: %p\n", handlers); 302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handlers 2: %p\n", handlers);
302 GNUNET_CADET_open_port(cadet_peer_2, /* cadet handle */ 303 GNUNET_CADET_open_port (cadet_peer_2, /* cadet handle */
303 GC_u2h(TEST_PORT_ID), /* port id */ 304 GC_u2h (TEST_PORT_ID), /* port id */
304 &connected, /* connect handler */ 305 &connected, /* connect handler */
305 (void *)2L, /* handle for #connected */ 306 (void *) 2L, /* handle for #connected */
306 NULL, /* window size handler */ 307 NULL, /* window size handler */
307 &disconnected, /* disconnect handler */ 308 &disconnected, /* disconnect handler */
308 handlers); /* traffic handlers */ 309 handlers); /* traffic handlers */
309 delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2); 310 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2);
310 if (NULL == connect_task) 311 if (NULL == connect_task)
311 connect_task = GNUNET_SCHEDULER_add_delayed(delay, 312 connect_task = GNUNET_SCHEDULER_add_delayed (delay,
312 &do_connect, 313 &do_connect,
313 NULL); 314 NULL);
314} 315}
315 316
316 317
@@ -318,16 +319,16 @@ run(void *cls,
318 * Main 319 * Main
319 */ 320 */
320int 321int
321main(int argc, char *argv[]) 322main (int argc, char *argv[])
322{ 323{
323 if (0 != GNUNET_TESTING_peer_run("test-cadet-local", 324 if (0 != GNUNET_TESTING_peer_run ("test-cadet-local",
324 "test_cadet.conf", 325 "test_cadet.conf",
325 &run, NULL)) 326 &run, NULL))
326 { 327 {
327 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "run failed\n"); 328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "run failed\n");
328 return 2; 329 return 2;
329 } 330 }
330 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Final result: %d\n", result); 331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Final result: %d\n", result);
331 return (result == GNUNET_OK) ? 0 : 1; 332 return (result == GNUNET_OK) ? 0 : 1;
332} 333}
333 334