diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/cadet/cadet_api.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/cadet/cadet_api.c')
-rw-r--r-- | src/cadet/cadet_api.c | 753 |
1 files changed, 378 insertions, 375 deletions
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 | */ |
38 | struct GNUNET_CADET_Handle { | 38 | struct 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 | */ |
79 | struct GNUNET_CADET_Channel { | 80 | struct 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 | */ |
143 | struct GNUNET_CADET_Port { | 145 | struct 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 | */ |
193 | static struct GNUNET_CADET_Port * | 196 | static struct GNUNET_CADET_Port * |
194 | find_port(const struct GNUNET_CADET_Handle *h, | 197 | find_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 | */ |
208 | static struct GNUNET_CADET_Channel * | 211 | static struct GNUNET_CADET_Channel * |
209 | find_channel(struct GNUNET_CADET_Handle *h, | 212 | find_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 | */ |
224 | static struct GNUNET_CADET_Channel * | 227 | static struct GNUNET_CADET_Channel * |
225 | create_channel(struct GNUNET_CADET_Handle *h, | 228 | create_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 | */ |
266 | static void | 269 | static void |
267 | destroy_channel(struct GNUNET_CADET_Channel *ch) | 270 | destroy_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 | */ |
301 | static void | 304 | static void |
302 | reconnect(struct GNUNET_CADET_Handle *h); | 305 | reconnect (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 | */ |
314 | static int | 317 | static int |
315 | open_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value) | 318 | open_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 | */ |
336 | static void | 339 | static void |
337 | reconnect_cbk(void *cls) | 340 | reconnect_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 | */ |
353 | static void | 356 | static void |
354 | notify_window_size(struct GNUNET_CADET_Channel *ch) | 357 | notify_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 | */ |
368 | static void | 371 | static void |
369 | cadet_mq_send_now(void *cls) | 372 | cadet_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 | */ |
410 | static void | 413 | static void |
411 | cadet_mq_send_impl(struct GNUNET_MQ_Handle *mq, | 414 | cadet_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 | */ |
459 | static void | 462 | static void |
460 | cadet_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) | 463 | cadet_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 | */ |
477 | static void | 480 | static void |
478 | cadet_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 481 | cadet_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 | */ |
507 | static void | 510 | static void |
508 | cadet_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) | 511 | cadet_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 | */ |
530 | static void | 533 | static void |
531 | handle_channel_created( | 534 | handle_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 | */ |
598 | static void | 601 | static void |
599 | handle_channel_destroy( | 602 | handle_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 | */ |
629 | static int | 632 | static int |
630 | check_local_data(void *cls, const struct GNUNET_CADET_LocalData *message) | 633 | check_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 | */ |
651 | static void | 654 | static void |
652 | handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message) | 655 | handle_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 | */ |
689 | static void | 692 | static void |
690 | handle_local_ack(void *cls, const struct GNUNET_CADET_LocalAck *message) | 693 | handle_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 | */ |
733 | static int | 736 | static int |
734 | destroy_channel_cb(void *cls, uint32_t cid, void *value) | 737 | destroy_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 | */ |
756 | static void | 759 | static void |
757 | handle_mq_error(void *cls, enum GNUNET_MQ_Error error) | 760 | handle_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 | */ |
777 | static void | 780 | static void |
778 | reconnect(struct GNUNET_CADET_Handle *h) | 781 | reconnect (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 | */ |
814 | static int | 817 | static int |
815 | destroy_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value) | 818 | destroy_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 | */ |
837 | void | 840 | void |
838 | GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle) | 841 | GNUNET_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 | */ |
870 | void | 873 | void |
871 | GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p) | 874 | GNUNET_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 | */ |
899 | void | 902 | void |
900 | GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel) | 903 | GNUNET_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 | */ |
928 | const union GNUNET_CADET_ChannelInfo * | 931 | const union GNUNET_CADET_ChannelInfo * |
929 | GNUNET_CADET_channel_get_info(struct GNUNET_CADET_Channel *channel, | 932 | GNUNET_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 | */ |
950 | void | 953 | void |
951 | GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel) | 954 | GNUNET_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 | */ |
972 | struct GNUNET_CADET_Handle * | 975 | struct GNUNET_CADET_Handle * |
973 | GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) | 976 | GNUNET_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 | */ |
1006 | struct GNUNET_CADET_Port * | 1009 | struct GNUNET_CADET_Port * |
1007 | GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, | 1010 | GNUNET_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 | */ |
1064 | struct GNUNET_CADET_Channel * | 1067 | struct GNUNET_CADET_Channel * |
1065 | GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h, | 1068 | GNUNET_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 | */ |
1115 | struct GNUNET_MQ_Handle * | 1118 | struct GNUNET_MQ_Handle * |
1116 | GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel) | 1119 | GNUNET_CADET_get_mq (const struct GNUNET_CADET_Channel *channel) |
1117 | { | 1120 | { |
1118 | return channel->mq; | 1121 | return channel->mq; |
1119 | } | 1122 | } |