diff options
Diffstat (limited to 'src/cadet/cadet_api.c')
-rw-r--r-- | src/cadet/cadet_api.c | 762 |
1 files changed, 379 insertions, 383 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index 7148ab956..61ff71b31 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file cadet/cadet_api.c | 21 | * @file cadet/cadet_api.c |
22 | * @brief cadet api: client implementation of cadet service | 22 | * @brief cadet api: client implementation of cadet service |
@@ -30,13 +30,12 @@ | |||
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 | { | ||
40 | /** | 39 | /** |
41 | * Message queue. | 40 | * Message queue. |
42 | */ | 41 | */ |
@@ -77,9 +76,7 @@ struct GNUNET_CADET_Handle | |||
77 | /** | 76 | /** |
78 | * Opaque handle to a channel. | 77 | * Opaque handle to a channel. |
79 | */ | 78 | */ |
80 | struct GNUNET_CADET_Channel | 79 | struct GNUNET_CADET_Channel { |
81 | { | ||
82 | |||
83 | /** | 80 | /** |
84 | * Other end of the channel. | 81 | * Other end of the channel. |
85 | */ | 82 | */ |
@@ -143,9 +140,7 @@ struct GNUNET_CADET_Channel | |||
143 | /** | 140 | /** |
144 | * Opaque handle to a port. | 141 | * Opaque handle to a port. |
145 | */ | 142 | */ |
146 | struct GNUNET_CADET_Port | 143 | struct GNUNET_CADET_Port { |
147 | { | ||
148 | |||
149 | /** | 144 | /** |
150 | * Port "number" | 145 | * Port "number" |
151 | */ | 146 | */ |
@@ -196,10 +191,10 @@ struct GNUNET_CADET_Port | |||
196 | * @return The port handle if known, NULL otherwise. | 191 | * @return The port handle if known, NULL otherwise. |
197 | */ | 192 | */ |
198 | static struct GNUNET_CADET_Port * | 193 | static struct GNUNET_CADET_Port * |
199 | find_port (const struct GNUNET_CADET_Handle *h, | 194 | find_port(const struct GNUNET_CADET_Handle *h, |
200 | const struct GNUNET_HashCode *hash) | 195 | const struct GNUNET_HashCode *hash) |
201 | { | 196 | { |
202 | return GNUNET_CONTAINER_multihashmap_get (h->ports, hash); | 197 | return GNUNET_CONTAINER_multihashmap_get(h->ports, hash); |
203 | } | 198 | } |
204 | 199 | ||
205 | 200 | ||
@@ -211,11 +206,11 @@ find_port (const struct GNUNET_CADET_Handle *h, | |||
211 | * @return handle to the required channel or NULL if not found | 206 | * @return handle to the required channel or NULL if not found |
212 | */ | 207 | */ |
213 | static struct GNUNET_CADET_Channel * | 208 | static struct GNUNET_CADET_Channel * |
214 | find_channel (struct GNUNET_CADET_Handle *h, | 209 | find_channel(struct GNUNET_CADET_Handle *h, |
215 | struct GNUNET_CADET_ClientChannelNumber ccn) | 210 | struct GNUNET_CADET_ClientChannelNumber ccn) |
216 | { | 211 | { |
217 | return GNUNET_CONTAINER_multihashmap32_get (h->channels, | 212 | return GNUNET_CONTAINER_multihashmap32_get(h->channels, |
218 | ntohl (ccn.channel_of_client)); | 213 | ntohl(ccn.channel_of_client)); |
219 | } | 214 | } |
220 | 215 | ||
221 | 216 | ||
@@ -227,33 +222,33 @@ find_channel (struct GNUNET_CADET_Handle *h, | |||
227 | * @return Handle to the created channel. | 222 | * @return Handle to the created channel. |
228 | */ | 223 | */ |
229 | static struct GNUNET_CADET_Channel * | 224 | static struct GNUNET_CADET_Channel * |
230 | create_channel (struct GNUNET_CADET_Handle *h, | 225 | create_channel(struct GNUNET_CADET_Handle *h, |
231 | const struct GNUNET_CADET_ClientChannelNumber *ccnp) | 226 | const struct GNUNET_CADET_ClientChannelNumber *ccnp) |
232 | { | 227 | { |
233 | struct GNUNET_CADET_Channel *ch; | 228 | struct GNUNET_CADET_Channel *ch; |
234 | struct GNUNET_CADET_ClientChannelNumber ccn; | 229 | struct GNUNET_CADET_ClientChannelNumber ccn; |
235 | 230 | ||
236 | ch = GNUNET_new (struct GNUNET_CADET_Channel); | 231 | ch = GNUNET_new(struct GNUNET_CADET_Channel); |
237 | ch->cadet = h; | 232 | ch->cadet = h; |
238 | if (NULL == ccnp) | 233 | if (NULL == ccnp) |
239 | { | 234 | { |
240 | while (NULL != find_channel (h, h->next_ccn)) | 235 | while (NULL != find_channel(h, h->next_ccn)) |
241 | h->next_ccn.channel_of_client = | 236 | h->next_ccn.channel_of_client = |
242 | htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI | | 237 | htonl(GNUNET_CADET_LOCAL_CHANNEL_ID_CLI | |
243 | (1 + ntohl (h->next_ccn.channel_of_client))); | 238 | (1 + ntohl(h->next_ccn.channel_of_client))); |
244 | ccn = h->next_ccn; | 239 | ccn = h->next_ccn; |
245 | } | 240 | } |
246 | else | 241 | else |
247 | { | 242 | { |
248 | ccn = *ccnp; | 243 | ccn = *ccnp; |
249 | } | 244 | } |
250 | ch->ccn = ccn; | 245 | ch->ccn = ccn; |
251 | GNUNET_assert (GNUNET_OK == | 246 | GNUNET_assert(GNUNET_OK == |
252 | GNUNET_CONTAINER_multihashmap32_put ( | 247 | GNUNET_CONTAINER_multihashmap32_put( |
253 | h->channels, | 248 | h->channels, |
254 | ntohl (ch->ccn.channel_of_client), | 249 | ntohl(ch->ccn.channel_of_client), |
255 | ch, | 250 | ch, |
256 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 251 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
257 | return ch; | 252 | return ch; |
258 | } | 253 | } |
259 | 254 | ||
@@ -269,31 +264,31 @@ create_channel (struct GNUNET_CADET_Handle *h, | |||
269 | * @param call_cleaner Whether to call the cleaner handler. | 264 | * @param call_cleaner Whether to call the cleaner handler. |
270 | */ | 265 | */ |
271 | static void | 266 | static void |
272 | destroy_channel (struct GNUNET_CADET_Channel *ch) | 267 | destroy_channel(struct GNUNET_CADET_Channel *ch) |
273 | { | 268 | { |
274 | struct GNUNET_CADET_Handle *h = ch->cadet; | 269 | struct GNUNET_CADET_Handle *h = ch->cadet; |
275 | 270 | ||
276 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 271 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
277 | "Destroying channel %X of %p\n", | 272 | "Destroying channel %X of %p\n", |
278 | htonl (ch->ccn.channel_of_client), | 273 | htonl(ch->ccn.channel_of_client), |
279 | h); | 274 | h); |
280 | GNUNET_assert ( | 275 | GNUNET_assert( |
281 | GNUNET_YES == | 276 | GNUNET_YES == |
282 | GNUNET_CONTAINER_multihashmap32_remove (h->channels, | 277 | GNUNET_CONTAINER_multihashmap32_remove(h->channels, |
283 | ntohl (ch->ccn.channel_of_client), | 278 | ntohl(ch->ccn.channel_of_client), |
284 | ch)); | 279 | ch)); |
285 | if (NULL != ch->mq_cont) | 280 | if (NULL != ch->mq_cont) |
286 | { | 281 | { |
287 | GNUNET_SCHEDULER_cancel (ch->mq_cont); | 282 | GNUNET_SCHEDULER_cancel(ch->mq_cont); |
288 | ch->mq_cont = NULL; | 283 | ch->mq_cont = NULL; |
289 | } | 284 | } |
290 | /* signal channel destruction */ | 285 | /* signal channel destruction */ |
291 | if (NULL != ch->disconnects) | 286 | if (NULL != ch->disconnects) |
292 | ch->disconnects (ch->ctx, ch); | 287 | ch->disconnects(ch->ctx, ch); |
293 | if (NULL != ch->pending_env) | 288 | if (NULL != ch->pending_env) |
294 | GNUNET_MQ_discard (ch->pending_env); | 289 | GNUNET_MQ_discard(ch->pending_env); |
295 | GNUNET_MQ_destroy (ch->mq); | 290 | GNUNET_MQ_destroy(ch->mq); |
296 | GNUNET_free (ch); | 291 | GNUNET_free(ch); |
297 | } | 292 | } |
298 | 293 | ||
299 | 294 | ||
@@ -304,7 +299,7 @@ destroy_channel (struct GNUNET_CADET_Channel *ch) | |||
304 | * @param h handle to the cadet | 299 | * @param h handle to the cadet |
305 | */ | 300 | */ |
306 | static void | 301 | static void |
307 | reconnect (struct GNUNET_CADET_Handle *h); | 302 | reconnect(struct GNUNET_CADET_Handle *h); |
308 | 303 | ||
309 | 304 | ||
310 | /** | 305 | /** |
@@ -317,17 +312,17 @@ reconnect (struct GNUNET_CADET_Handle *h); | |||
317 | * @return #GNUNET_OK (continue to iterate) | 312 | * @return #GNUNET_OK (continue to iterate) |
318 | */ | 313 | */ |
319 | static int | 314 | static int |
320 | open_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value) | 315 | open_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value) |
321 | { | 316 | { |
322 | struct GNUNET_CADET_Handle *h = cls; | 317 | struct GNUNET_CADET_Handle *h = cls; |
323 | struct GNUNET_CADET_Port *port = value; | 318 | struct GNUNET_CADET_Port *port = value; |
324 | struct GNUNET_CADET_PortMessage *msg; | 319 | struct GNUNET_CADET_PortMessage *msg; |
325 | struct GNUNET_MQ_Envelope *env; | 320 | struct GNUNET_MQ_Envelope *env; |
326 | 321 | ||
327 | (void) id; | 322 | (void)id; |
328 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN); | 323 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN); |
329 | msg->port = port->id; | 324 | msg->port = port->id; |
330 | GNUNET_MQ_send (h->mq, env); | 325 | GNUNET_MQ_send(h->mq, env); |
331 | return GNUNET_OK; | 326 | return GNUNET_OK; |
332 | } | 327 | } |
333 | 328 | ||
@@ -339,14 +334,14 @@ open_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value) | |||
339 | * @param cls closure (cadet handle) | 334 | * @param cls closure (cadet handle) |
340 | */ | 335 | */ |
341 | static void | 336 | static void |
342 | reconnect_cbk (void *cls) | 337 | reconnect_cbk(void *cls) |
343 | { | 338 | { |
344 | struct GNUNET_CADET_Handle *h = cls; | 339 | struct GNUNET_CADET_Handle *h = cls; |
345 | 340 | ||
346 | h->reconnect_task = NULL; | 341 | h->reconnect_task = NULL; |
347 | h->reconnect_time = GNUNET_TIME_STD_BACKOFF (h->reconnect_time); | 342 | h->reconnect_time = GNUNET_TIME_STD_BACKOFF(h->reconnect_time); |
348 | reconnect (h); | 343 | reconnect(h); |
349 | GNUNET_CONTAINER_multihashmap_iterate (h->ports, &open_port_cb, h); | 344 | GNUNET_CONTAINER_multihashmap_iterate(h->ports, &open_port_cb, h); |
350 | } | 345 | } |
351 | 346 | ||
352 | 347 | ||
@@ -356,12 +351,12 @@ reconnect_cbk (void *cls) | |||
356 | * @param ch Channel to notify about. | 351 | * @param ch Channel to notify about. |
357 | */ | 352 | */ |
358 | static void | 353 | static void |
359 | notify_window_size (struct GNUNET_CADET_Channel *ch) | 354 | notify_window_size(struct GNUNET_CADET_Channel *ch) |
360 | { | 355 | { |
361 | if (NULL != ch->window_changes) | 356 | if (NULL != ch->window_changes) |
362 | ch->window_changes (ch->ctx, | 357 | ch->window_changes(ch->ctx, |
363 | ch, /* FIXME: remove 'ch'? */ | 358 | ch, /* FIXME: remove 'ch'? */ |
364 | ch->allow_send); | 359 | ch->allow_send); |
365 | } | 360 | } |
366 | 361 | ||
367 | 362 | ||
@@ -371,32 +366,32 @@ notify_window_size (struct GNUNET_CADET_Channel *ch) | |||
371 | * @param cls Closure (channel whose mq to activate). | 366 | * @param cls Closure (channel whose mq to activate). |
372 | */ | 367 | */ |
373 | static void | 368 | static void |
374 | cadet_mq_send_now (void *cls) | 369 | cadet_mq_send_now(void *cls) |
375 | { | 370 | { |
376 | struct GNUNET_CADET_Channel *ch = cls; | 371 | struct GNUNET_CADET_Channel *ch = cls; |
377 | struct GNUNET_MQ_Envelope *env = ch->pending_env; | 372 | struct GNUNET_MQ_Envelope *env = ch->pending_env; |
378 | 373 | ||
379 | ch->mq_cont = NULL; | 374 | ch->mq_cont = NULL; |
380 | if (0 == ch->allow_send) | 375 | if (0 == ch->allow_send) |
381 | { | 376 | { |
382 | /* how did we get here? */ | 377 | /* how did we get here? */ |
383 | GNUNET_break (0); | 378 | GNUNET_break(0); |
384 | return; | 379 | return; |
385 | } | 380 | } |
386 | if (NULL == env) | 381 | if (NULL == env) |
387 | { | 382 | { |
388 | /* how did we get here? */ | 383 | /* how did we get here? */ |
389 | GNUNET_break (0); | 384 | GNUNET_break(0); |
390 | return; | 385 | return; |
391 | } | 386 | } |
392 | ch->allow_send--; | 387 | ch->allow_send--; |
393 | ch->pending_env = NULL; | 388 | ch->pending_env = NULL; |
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 389 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
395 | "Sending message on channel %s to CADET, new window size is %u\n", | 390 | "Sending message on channel %s to CADET, new window size is %u\n", |
396 | GNUNET_i2s (&ch->peer), | 391 | GNUNET_i2s(&ch->peer), |
397 | ch->allow_send); | 392 | ch->allow_send); |
398 | GNUNET_MQ_send (ch->cadet->mq, env); | 393 | GNUNET_MQ_send(ch->cadet->mq, env); |
399 | GNUNET_MQ_impl_send_continue (ch->mq); | 394 | GNUNET_MQ_impl_send_continue(ch->mq); |
400 | } | 395 | } |
401 | 396 | ||
402 | 397 | ||
@@ -413,9 +408,9 @@ cadet_mq_send_now (void *cls) | |||
413 | * @param impl_state state of the implementation | 408 | * @param impl_state state of the implementation |
414 | */ | 409 | */ |
415 | static void | 410 | static void |
416 | cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq, | 411 | cadet_mq_send_impl(struct GNUNET_MQ_Handle *mq, |
417 | const struct GNUNET_MessageHeader *msg, | 412 | const struct GNUNET_MessageHeader *msg, |
418 | void *impl_state) | 413 | void *impl_state) |
419 | { | 414 | { |
420 | struct GNUNET_CADET_Channel *ch = impl_state; | 415 | struct GNUNET_CADET_Channel *ch = impl_state; |
421 | struct GNUNET_CADET_Handle *h = ch->cadet; | 416 | struct GNUNET_CADET_Handle *h = ch->cadet; |
@@ -426,31 +421,31 @@ cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
426 | enum GNUNET_MQ_PriorityPreferences pp; | 421 | enum GNUNET_MQ_PriorityPreferences pp; |
427 | 422 | ||
428 | if (NULL == h->mq) | 423 | if (NULL == h->mq) |
429 | { | 424 | { |
430 | /* We're currently reconnecting, pretend this worked */ | 425 | /* We're currently reconnecting, pretend this worked */ |
431 | GNUNET_MQ_impl_send_continue (mq); | 426 | GNUNET_MQ_impl_send_continue(mq); |
432 | return; | 427 | return; |
433 | } | 428 | } |
434 | orig_env = GNUNET_MQ_get_current_envelope (mq); | 429 | orig_env = GNUNET_MQ_get_current_envelope(mq); |
435 | pp = GNUNET_MQ_env_get_options (orig_env); | 430 | pp = GNUNET_MQ_env_get_options(orig_env); |
436 | 431 | ||
437 | /* check message size for sanity */ | 432 | /* check message size for sanity */ |
438 | msize = ntohs (msg->size); | 433 | msize = ntohs(msg->size); |
439 | if (msize > GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE) | 434 | if (msize > GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE) |
440 | { | 435 | { |
441 | GNUNET_break (0); | 436 | GNUNET_break(0); |
442 | GNUNET_MQ_impl_send_continue (mq); | 437 | GNUNET_MQ_impl_send_continue(mq); |
443 | return; | 438 | return; |
444 | } | 439 | } |
445 | env = GNUNET_MQ_msg_nested_mh (cadet_msg, | 440 | env = GNUNET_MQ_msg_nested_mh(cadet_msg, |
446 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, | 441 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, |
447 | msg); | 442 | msg); |
448 | cadet_msg->ccn = ch->ccn; | 443 | cadet_msg->ccn = ch->ccn; |
449 | cadet_msg->pp = htonl ((uint32_t) pp); | 444 | cadet_msg->pp = htonl((uint32_t)pp); |
450 | GNUNET_assert (NULL == ch->pending_env); | 445 | GNUNET_assert(NULL == ch->pending_env); |
451 | ch->pending_env = env; | 446 | ch->pending_env = env; |
452 | if (0 < ch->allow_send) | 447 | if (0 < ch->allow_send) |
453 | ch->mq_cont = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, ch); | 448 | ch->mq_cont = GNUNET_SCHEDULER_add_now(&cadet_mq_send_now, ch); |
454 | } | 449 | } |
455 | 450 | ||
456 | 451 | ||
@@ -462,11 +457,11 @@ cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
462 | * @param impl_state state of the implementation | 457 | * @param impl_state state of the implementation |
463 | */ | 458 | */ |
464 | static void | 459 | static void |
465 | cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | 460 | cadet_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) |
466 | { | 461 | { |
467 | struct GNUNET_CADET_Channel *ch = impl_state; | 462 | struct GNUNET_CADET_Channel *ch = impl_state; |
468 | 463 | ||
469 | GNUNET_assert (mq == ch->mq); | 464 | GNUNET_assert(mq == ch->mq); |
470 | ch->mq = NULL; | 465 | ch->mq = NULL; |
471 | } | 466 | } |
472 | 467 | ||
@@ -480,25 +475,25 @@ cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
480 | * @param error error code | 475 | * @param error error code |
481 | */ | 476 | */ |
482 | static void | 477 | static void |
483 | cadet_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 478 | cadet_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
484 | { | 479 | { |
485 | struct GNUNET_CADET_Channel *ch = cls; | 480 | struct GNUNET_CADET_Channel *ch = cls; |
486 | 481 | ||
487 | if (GNUNET_MQ_ERROR_NO_MATCH == error) | 482 | if (GNUNET_MQ_ERROR_NO_MATCH == error) |
488 | { | 483 | { |
489 | /* Got a message we did not understand, still try to continue! */ | 484 | /* Got a message we did not understand, still try to continue! */ |
490 | GNUNET_break_op (0); | 485 | GNUNET_break_op(0); |
491 | GNUNET_CADET_receive_done (ch); | 486 | GNUNET_CADET_receive_done(ch); |
492 | } | 487 | } |
493 | else | 488 | else |
494 | { | 489 | { |
495 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 490 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
496 | "MQ error in communication with CADET: %d\n", | 491 | "MQ error in communication with CADET: %d\n", |
497 | error); | 492 | error); |
498 | if (NULL != ch->disconnects) | 493 | if (NULL != ch->disconnects) |
499 | ch->disconnects (ch->ctx, ch); | 494 | ch->disconnects(ch->ctx, ch); |
500 | GNUNET_CADET_channel_destroy (ch); | 495 | GNUNET_CADET_channel_destroy(ch); |
501 | } | 496 | } |
502 | } | 497 | } |
503 | 498 | ||
504 | 499 | ||
@@ -510,19 +505,19 @@ cadet_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
510 | * @param impl_state state specific to the implementation | 505 | * @param impl_state state specific to the implementation |
511 | */ | 506 | */ |
512 | static void | 507 | static void |
513 | cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | 508 | cadet_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) |
514 | { | 509 | { |
515 | struct GNUNET_CADET_Channel *ch = impl_state; | 510 | struct GNUNET_CADET_Channel *ch = impl_state; |
516 | 511 | ||
517 | (void) mq; | 512 | (void)mq; |
518 | GNUNET_assert (NULL != ch->pending_env); | 513 | GNUNET_assert(NULL != ch->pending_env); |
519 | GNUNET_MQ_discard (ch->pending_env); | 514 | GNUNET_MQ_discard(ch->pending_env); |
520 | ch->pending_env = NULL; | 515 | ch->pending_env = NULL; |
521 | if (NULL != ch->mq_cont) | 516 | if (NULL != ch->mq_cont) |
522 | { | 517 | { |
523 | GNUNET_SCHEDULER_cancel (ch->mq_cont); | 518 | GNUNET_SCHEDULER_cancel(ch->mq_cont); |
524 | ch->mq_cont = NULL; | 519 | ch->mq_cont = NULL; |
525 | } | 520 | } |
526 | } | 521 | } |
527 | 522 | ||
528 | 523 | ||
@@ -533,7 +528,7 @@ cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
533 | * @param msg A message with the details of the new incoming channel | 528 | * @param msg A message with the details of the new incoming channel |
534 | */ | 529 | */ |
535 | static void | 530 | static void |
536 | handle_channel_created ( | 531 | handle_channel_created( |
537 | void *cls, | 532 | void *cls, |
538 | const struct GNUNET_CADET_LocalChannelCreateMessage *msg) | 533 | const struct GNUNET_CADET_LocalChannelCreateMessage *msg) |
539 | { | 534 | { |
@@ -545,52 +540,52 @@ handle_channel_created ( | |||
545 | 540 | ||
546 | ccn = msg->ccn; | 541 | ccn = msg->ccn; |
547 | port_number = &msg->port; | 542 | port_number = &msg->port; |
548 | if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) | 543 | if (ntohl(ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) |
549 | { | 544 | { |
550 | GNUNET_break (0); | 545 | GNUNET_break(0); |
551 | return; | 546 | return; |
552 | } | 547 | } |
553 | port = find_port (h, port_number); | 548 | port = find_port(h, port_number); |
554 | if (NULL == port) | 549 | if (NULL == port) |
555 | { | 550 | { |
556 | /* We could have closed the port but the service didn't know about it yet | 551 | /* We could have closed the port but the service didn't know about it yet |
557 | * This is not an error. | 552 | * This is not an error. |
558 | */ | 553 | */ |
559 | struct GNUNET_CADET_LocalChannelDestroyMessage *d_msg; | 554 | struct GNUNET_CADET_LocalChannelDestroyMessage *d_msg; |
560 | struct GNUNET_MQ_Envelope *env; | 555 | struct GNUNET_MQ_Envelope *env; |
561 | 556 | ||
562 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 557 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
563 | "No handler for incoming channel %X (on port %s, recently closed?)\n", | 558 | "No handler for incoming channel %X (on port %s, recently closed?)\n", |
564 | ntohl (ccn.channel_of_client), | 559 | ntohl(ccn.channel_of_client), |
565 | GNUNET_h2s (port_number)); | 560 | GNUNET_h2s(port_number)); |
566 | env = | 561 | env = |
567 | GNUNET_MQ_msg (d_msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); | 562 | GNUNET_MQ_msg(d_msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); |
568 | d_msg->ccn = msg->ccn; | 563 | d_msg->ccn = msg->ccn; |
569 | GNUNET_MQ_send (h->mq, env); | 564 | GNUNET_MQ_send(h->mq, env); |
570 | return; | 565 | return; |
571 | } | 566 | } |
572 | 567 | ||
573 | ch = create_channel (h, &ccn); | 568 | ch = create_channel(h, &ccn); |
574 | ch->peer = msg->peer; | 569 | ch->peer = msg->peer; |
575 | ch->incoming_port = port; | 570 | ch->incoming_port = port; |
576 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 571 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
577 | "Creating incoming channel %X [%s] %p\n", | 572 | "Creating incoming channel %X [%s] %p\n", |
578 | ntohl (ccn.channel_of_client), | 573 | ntohl(ccn.channel_of_client), |
579 | GNUNET_h2s (port_number), | 574 | GNUNET_h2s(port_number), |
580 | ch); | 575 | ch); |
581 | 576 | ||
582 | GNUNET_assert (NULL != port->connects); | 577 | GNUNET_assert(NULL != port->connects); |
583 | ch->window_changes = port->window_changes; | 578 | ch->window_changes = port->window_changes; |
584 | ch->disconnects = port->disconnects; | 579 | ch->disconnects = port->disconnects; |
585 | ch->mq = GNUNET_MQ_queue_for_callbacks (&cadet_mq_send_impl, | 580 | ch->mq = GNUNET_MQ_queue_for_callbacks(&cadet_mq_send_impl, |
586 | &cadet_mq_destroy_impl, | 581 | &cadet_mq_destroy_impl, |
587 | &cadet_mq_cancel_impl, | 582 | &cadet_mq_cancel_impl, |
588 | ch, | 583 | ch, |
589 | port->handlers, | 584 | port->handlers, |
590 | &cadet_mq_error_handler, | 585 | &cadet_mq_error_handler, |
591 | ch); | 586 | ch); |
592 | ch->ctx = port->connects (port->cls, ch, &msg->peer); | 587 | ch->ctx = port->connects(port->cls, ch, &msg->peer); |
593 | GNUNET_MQ_set_handlers_closure (ch->mq, ch->ctx); | 588 | GNUNET_MQ_set_handlers_closure(ch->mq, ch->ctx); |
594 | } | 589 | } |
595 | 590 | ||
596 | 591 | ||
@@ -601,25 +596,25 @@ handle_channel_created ( | |||
601 | * @param msg A message with the details of the channel being destroyed | 596 | * @param msg A message with the details of the channel being destroyed |
602 | */ | 597 | */ |
603 | static void | 598 | static void |
604 | handle_channel_destroy ( | 599 | handle_channel_destroy( |
605 | void *cls, | 600 | void *cls, |
606 | const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) | 601 | const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) |
607 | { | 602 | { |
608 | struct GNUNET_CADET_Handle *h = cls; | 603 | struct GNUNET_CADET_Handle *h = cls; |
609 | struct GNUNET_CADET_Channel *ch; | 604 | struct GNUNET_CADET_Channel *ch; |
610 | 605 | ||
611 | ch = find_channel (h, msg->ccn); | 606 | ch = find_channel(h, msg->ccn); |
612 | if (NULL == ch) | 607 | if (NULL == ch) |
613 | { | 608 | { |
614 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 609 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
615 | "Received channel destroy for unknown channel %X from CADET service (recently close?)\n", | 610 | "Received channel destroy for unknown channel %X from CADET service (recently close?)\n", |
616 | ntohl (msg->ccn.channel_of_client)); | 611 | ntohl(msg->ccn.channel_of_client)); |
617 | return; | 612 | return; |
618 | } | 613 | } |
619 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 614 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
620 | "Received channel destroy for channel %X from CADET service\n", | 615 | "Received channel destroy for channel %X from CADET service\n", |
621 | ntohl (msg->ccn.channel_of_client)); | 616 | ntohl(msg->ccn.channel_of_client)); |
622 | destroy_channel (ch); | 617 | destroy_channel(ch); |
623 | } | 618 | } |
624 | 619 | ||
625 | 620 | ||
@@ -632,17 +627,17 @@ handle_channel_destroy ( | |||
632 | * #GNUNET_SYSERR otherwise | 627 | * #GNUNET_SYSERR otherwise |
633 | */ | 628 | */ |
634 | static int | 629 | static int |
635 | check_local_data (void *cls, const struct GNUNET_CADET_LocalData *message) | 630 | check_local_data(void *cls, const struct GNUNET_CADET_LocalData *message) |
636 | { | 631 | { |
637 | uint16_t size; | 632 | uint16_t size; |
638 | 633 | ||
639 | (void) cls; | 634 | (void)cls; |
640 | size = ntohs (message->header.size); | 635 | size = ntohs(message->header.size); |
641 | if (sizeof (*message) + sizeof (struct GNUNET_MessageHeader) > size) | 636 | if (sizeof(*message) + sizeof(struct GNUNET_MessageHeader) > size) |
642 | { | 637 | { |
643 | GNUNET_break (0); | 638 | GNUNET_break(0); |
644 | return GNUNET_SYSERR; | 639 | return GNUNET_SYSERR; |
645 | } | 640 | } |
646 | return GNUNET_OK; | 641 | return GNUNET_OK; |
647 | } | 642 | } |
648 | 643 | ||
@@ -654,7 +649,7 @@ check_local_data (void *cls, const struct GNUNET_CADET_LocalData *message) | |||
654 | * @param message A message encapsulating the data | 649 | * @param message A message encapsulating the data |
655 | */ | 650 | */ |
656 | static void | 651 | static void |
657 | handle_local_data (void *cls, const struct GNUNET_CADET_LocalData *message) | 652 | handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message) |
658 | { | 653 | { |
659 | struct GNUNET_CADET_Handle *h = cls; | 654 | struct GNUNET_CADET_Handle *h = cls; |
660 | const struct GNUNET_MessageHeader *payload; | 655 | const struct GNUNET_MessageHeader *payload; |
@@ -662,25 +657,25 @@ handle_local_data (void *cls, const struct GNUNET_CADET_LocalData *message) | |||
662 | uint16_t type; | 657 | uint16_t type; |
663 | int fwd; | 658 | int fwd; |
664 | 659 | ||
665 | ch = find_channel (h, message->ccn); | 660 | ch = find_channel(h, message->ccn); |
666 | if (NULL == ch) | 661 | if (NULL == ch) |
667 | { | 662 | { |
668 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 663 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
669 | "Unknown channel %X for incoming data (recently closed?)\n", | 664 | "Unknown channel %X for incoming data (recently closed?)\n", |
670 | ntohl (message->ccn.channel_of_client)); | 665 | ntohl(message->ccn.channel_of_client)); |
671 | return; | 666 | return; |
672 | } | 667 | } |
673 | 668 | ||
674 | payload = (const struct GNUNET_MessageHeader *) &message[1]; | 669 | payload = (const struct GNUNET_MessageHeader *)&message[1]; |
675 | type = ntohs (payload->type); | 670 | type = ntohs(payload->type); |
676 | fwd = ntohl (ch->ccn.channel_of_client) <= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; | 671 | fwd = ntohl(ch->ccn.channel_of_client) <= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; |
677 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 672 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
678 | "Got a %s data on channel %s [%X] of type %u\n", | 673 | "Got a %s data on channel %s [%X] of type %u\n", |
679 | fwd ? "FWD" : "BWD", | 674 | fwd ? "FWD" : "BWD", |
680 | GNUNET_i2s (&ch->peer), | 675 | GNUNET_i2s(&ch->peer), |
681 | ntohl (message->ccn.channel_of_client), | 676 | ntohl(message->ccn.channel_of_client), |
682 | type); | 677 | type); |
683 | GNUNET_MQ_inject_message (ch->mq, payload); | 678 | GNUNET_MQ_inject_message(ch->mq, payload); |
684 | } | 679 | } |
685 | 680 | ||
686 | 681 | ||
@@ -692,37 +687,37 @@ handle_local_data (void *cls, const struct GNUNET_CADET_LocalData *message) | |||
692 | * @param message Message itself. | 687 | * @param message Message itself. |
693 | */ | 688 | */ |
694 | static void | 689 | static void |
695 | handle_local_ack (void *cls, const struct GNUNET_CADET_LocalAck *message) | 690 | handle_local_ack(void *cls, const struct GNUNET_CADET_LocalAck *message) |
696 | { | 691 | { |
697 | struct GNUNET_CADET_Handle *h = cls; | 692 | struct GNUNET_CADET_Handle *h = cls; |
698 | struct GNUNET_CADET_Channel *ch; | 693 | struct GNUNET_CADET_Channel *ch; |
699 | 694 | ||
700 | ch = find_channel (h, message->ccn); | 695 | ch = find_channel(h, message->ccn); |
701 | if (NULL == ch) | 696 | if (NULL == ch) |
702 | { | 697 | { |
703 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 698 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
704 | "ACK on unknown channel %X\n", | 699 | "ACK on unknown channel %X\n", |
705 | ntohl (message->ccn.channel_of_client)); | 700 | ntohl(message->ccn.channel_of_client)); |
706 | return; | 701 | return; |
707 | } | 702 | } |
708 | ch->allow_send++; | 703 | ch->allow_send++; |
709 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 704 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
710 | "Got an ACK on mq channel %X (peer %s); new window size is %u!\n", | 705 | "Got an ACK on mq channel %X (peer %s); new window size is %u!\n", |
711 | ntohl (ch->ccn.channel_of_client), | 706 | ntohl(ch->ccn.channel_of_client), |
712 | GNUNET_i2s (&ch->peer), | 707 | GNUNET_i2s(&ch->peer), |
713 | ch->allow_send); | 708 | ch->allow_send); |
714 | if (NULL == ch->pending_env) | 709 | if (NULL == ch->pending_env) |
715 | { | 710 | { |
716 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 711 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
717 | "Got an ACK on mq channel %X, allow send now %u!\n", | 712 | "Got an ACK on mq channel %X, allow send now %u!\n", |
718 | ntohl (ch->ccn.channel_of_client), | 713 | ntohl(ch->ccn.channel_of_client), |
719 | ch->allow_send); | 714 | ch->allow_send); |
720 | notify_window_size (ch); | 715 | notify_window_size(ch); |
721 | return; | 716 | return; |
722 | } | 717 | } |
723 | if (NULL != ch->mq_cont) | 718 | if (NULL != ch->mq_cont) |
724 | return; /* already working on it! */ | 719 | return; /* already working on it! */ |
725 | ch->mq_cont = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, ch); | 720 | ch->mq_cont = GNUNET_SCHEDULER_add_now(&cadet_mq_send_now, ch); |
726 | } | 721 | } |
727 | 722 | ||
728 | 723 | ||
@@ -736,16 +731,16 @@ handle_local_ack (void *cls, const struct GNUNET_CADET_LocalAck *message) | |||
736 | * @return #GNUNET_OK (continue to iterate) | 731 | * @return #GNUNET_OK (continue to iterate) |
737 | */ | 732 | */ |
738 | static int | 733 | static int |
739 | destroy_channel_cb (void *cls, uint32_t cid, void *value) | 734 | destroy_channel_cb(void *cls, uint32_t cid, void *value) |
740 | { | 735 | { |
741 | /* struct GNUNET_CADET_Handle *handle = cls; */ | 736 | /* struct GNUNET_CADET_Handle *handle = cls; */ |
742 | struct GNUNET_CADET_Channel *ch = value; | 737 | struct GNUNET_CADET_Channel *ch = value; |
743 | 738 | ||
744 | (void) cls; | 739 | (void)cls; |
745 | (void) cid; | 740 | (void)cid; |
746 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 741 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
747 | "Destroying channel due to GNUNET_CADET_disconnect()\n"); | 742 | "Destroying channel due to GNUNET_CADET_disconnect()\n"); |
748 | destroy_channel (ch); | 743 | destroy_channel(ch); |
749 | return GNUNET_OK; | 744 | return GNUNET_OK; |
750 | } | 745 | } |
751 | 746 | ||
@@ -759,17 +754,17 @@ destroy_channel_cb (void *cls, uint32_t cid, void *value) | |||
759 | * @param error error code | 754 | * @param error error code |
760 | */ | 755 | */ |
761 | static void | 756 | static void |
762 | handle_mq_error (void *cls, enum GNUNET_MQ_Error error) | 757 | handle_mq_error(void *cls, enum GNUNET_MQ_Error error) |
763 | { | 758 | { |
764 | struct GNUNET_CADET_Handle *h = cls; | 759 | struct GNUNET_CADET_Handle *h = cls; |
765 | 760 | ||
766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error); | 761 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error); |
767 | GNUNET_CONTAINER_multihashmap32_iterate (h->channels, &destroy_channel_cb, h); | 762 | GNUNET_CONTAINER_multihashmap32_iterate(h->channels, &destroy_channel_cb, h); |
768 | GNUNET_MQ_destroy (h->mq); | 763 | GNUNET_MQ_destroy(h->mq); |
769 | h->mq = NULL; | 764 | h->mq = NULL; |
770 | GNUNET_assert (NULL == h->reconnect_task); | 765 | GNUNET_assert(NULL == h->reconnect_task); |
771 | h->reconnect_task = | 766 | h->reconnect_task = |
772 | GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h); | 767 | GNUNET_SCHEDULER_add_delayed(h->reconnect_time, &reconnect_cbk, h); |
773 | } | 768 | } |
774 | 769 | ||
775 | 770 | ||
@@ -780,30 +775,30 @@ handle_mq_error (void *cls, enum GNUNET_MQ_Error error) | |||
780 | * @param h handle to the cadet | 775 | * @param h handle to the cadet |
781 | */ | 776 | */ |
782 | static void | 777 | static void |
783 | reconnect (struct GNUNET_CADET_Handle *h) | 778 | reconnect(struct GNUNET_CADET_Handle *h) |
784 | { | 779 | { |
785 | struct GNUNET_MQ_MessageHandler handlers[] = | 780 | struct GNUNET_MQ_MessageHandler handlers[] = |
786 | {GNUNET_MQ_hd_fixed_size (channel_created, | 781 | { GNUNET_MQ_hd_fixed_size(channel_created, |
787 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, | 782 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, |
788 | struct GNUNET_CADET_LocalChannelCreateMessage, | 783 | struct GNUNET_CADET_LocalChannelCreateMessage, |
789 | h), | 784 | h), |
790 | GNUNET_MQ_hd_fixed_size (channel_destroy, | 785 | GNUNET_MQ_hd_fixed_size(channel_destroy, |
791 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, | 786 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, |
792 | struct GNUNET_CADET_LocalChannelDestroyMessage, | 787 | struct GNUNET_CADET_LocalChannelDestroyMessage, |
793 | h), | 788 | h), |
794 | GNUNET_MQ_hd_var_size (local_data, | 789 | GNUNET_MQ_hd_var_size(local_data, |
795 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, | 790 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, |
796 | struct GNUNET_CADET_LocalData, | 791 | struct GNUNET_CADET_LocalData, |
792 | h), | ||
793 | GNUNET_MQ_hd_fixed_size(local_ack, | ||
794 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, | ||
795 | struct GNUNET_CADET_LocalAck, | ||
797 | h), | 796 | h), |
798 | GNUNET_MQ_hd_fixed_size (local_ack, | 797 | GNUNET_MQ_handler_end() }; |
799 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, | ||
800 | struct GNUNET_CADET_LocalAck, | ||
801 | h), | ||
802 | GNUNET_MQ_handler_end ()}; | ||
803 | 798 | ||
804 | GNUNET_assert (NULL == h->mq); | 799 | GNUNET_assert(NULL == h->mq); |
805 | h->mq = | 800 | h->mq = |
806 | GNUNET_CLIENT_connect (h->cfg, "cadet", handlers, &handle_mq_error, h); | 801 | GNUNET_CLIENT_connect(h->cfg, "cadet", handlers, &handle_mq_error, h); |
807 | } | 802 | } |
808 | 803 | ||
809 | 804 | ||
@@ -817,16 +812,16 @@ reconnect (struct GNUNET_CADET_Handle *h) | |||
817 | * @return #GNUNET_OK (continue to iterate) | 812 | * @return #GNUNET_OK (continue to iterate) |
818 | */ | 813 | */ |
819 | static int | 814 | static int |
820 | destroy_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value) | 815 | destroy_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value) |
821 | { | 816 | { |
822 | /* struct GNUNET_CADET_Handle *handle = cls; */ | 817 | /* struct GNUNET_CADET_Handle *handle = cls; */ |
823 | struct GNUNET_CADET_Port *port = value; | 818 | struct GNUNET_CADET_Port *port = value; |
824 | 819 | ||
825 | (void) cls; | 820 | (void)cls; |
826 | (void) id; | 821 | (void)id; |
827 | /* This is a warning, the app should have cleanly closed all open ports */ | 822 | /* This is a warning, the app should have cleanly closed all open ports */ |
828 | GNUNET_break (0); | 823 | GNUNET_break(0); |
829 | GNUNET_CADET_close_port (port); | 824 | GNUNET_CADET_close_port(port); |
830 | return GNUNET_OK; | 825 | return GNUNET_OK; |
831 | } | 826 | } |
832 | 827 | ||
@@ -840,29 +835,29 @@ destroy_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value) | |||
840 | * @param handle connection to cadet to disconnect | 835 | * @param handle connection to cadet to disconnect |
841 | */ | 836 | */ |
842 | void | 837 | void |
843 | GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle) | 838 | GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle) |
844 | { | 839 | { |
845 | GNUNET_CONTAINER_multihashmap_iterate (handle->ports, | 840 | GNUNET_CONTAINER_multihashmap_iterate(handle->ports, |
846 | &destroy_port_cb, | 841 | &destroy_port_cb, |
847 | handle); | 842 | handle); |
848 | GNUNET_CONTAINER_multihashmap_destroy (handle->ports); | 843 | GNUNET_CONTAINER_multihashmap_destroy(handle->ports); |
849 | handle->ports = NULL; | 844 | handle->ports = NULL; |
850 | GNUNET_CONTAINER_multihashmap32_iterate (handle->channels, | 845 | GNUNET_CONTAINER_multihashmap32_iterate(handle->channels, |
851 | &destroy_channel_cb, | 846 | &destroy_channel_cb, |
852 | handle); | 847 | handle); |
853 | GNUNET_CONTAINER_multihashmap32_destroy (handle->channels); | 848 | GNUNET_CONTAINER_multihashmap32_destroy(handle->channels); |
854 | handle->channels = NULL; | 849 | handle->channels = NULL; |
855 | if (NULL != handle->mq) | 850 | if (NULL != handle->mq) |
856 | { | 851 | { |
857 | GNUNET_MQ_destroy (handle->mq); | 852 | GNUNET_MQ_destroy(handle->mq); |
858 | handle->mq = NULL; | 853 | handle->mq = NULL; |
859 | } | 854 | } |
860 | if (NULL != handle->reconnect_task) | 855 | if (NULL != handle->reconnect_task) |
861 | { | 856 | { |
862 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | 857 | GNUNET_SCHEDULER_cancel(handle->reconnect_task); |
863 | handle->reconnect_task = NULL; | 858 | handle->reconnect_task = NULL; |
864 | } | 859 | } |
865 | GNUNET_free (handle); | 860 | GNUNET_free(handle); |
866 | } | 861 | } |
867 | 862 | ||
868 | 863 | ||
@@ -873,22 +868,22 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle) | |||
873 | * @param p Port handle. | 868 | * @param p Port handle. |
874 | */ | 869 | */ |
875 | void | 870 | void |
876 | GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p) | 871 | GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p) |
877 | { | 872 | { |
878 | GNUNET_assert ( | 873 | GNUNET_assert( |
879 | GNUNET_YES == | 874 | GNUNET_YES == |
880 | GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports, &p->id, p)); | 875 | GNUNET_CONTAINER_multihashmap_remove(p->cadet->ports, &p->id, p)); |
881 | if (NULL != p->cadet->mq) | 876 | if (NULL != p->cadet->mq) |
882 | { | 877 | { |
883 | struct GNUNET_CADET_PortMessage *msg; | 878 | struct GNUNET_CADET_PortMessage *msg; |
884 | struct GNUNET_MQ_Envelope *env; | 879 | struct GNUNET_MQ_Envelope *env; |
885 | 880 | ||
886 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE); | 881 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE); |
887 | msg->port = p->id; | 882 | msg->port = p->id; |
888 | GNUNET_MQ_send (p->cadet->mq, env); | 883 | GNUNET_MQ_send(p->cadet->mq, env); |
889 | } | 884 | } |
890 | GNUNET_free_non_null (p->handlers); | 885 | GNUNET_free_non_null(p->handlers); |
891 | GNUNET_free (p); | 886 | GNUNET_free(p); |
892 | } | 887 | } |
893 | 888 | ||
894 | 889 | ||
@@ -902,22 +897,22 @@ GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p) | |||
902 | * @param channel Channel handle, becomes invalid after this call. | 897 | * @param channel Channel handle, becomes invalid after this call. |
903 | */ | 898 | */ |
904 | void | 899 | void |
905 | GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel) | 900 | GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel) |
906 | { | 901 | { |
907 | struct GNUNET_CADET_Handle *h = channel->cadet; | 902 | struct GNUNET_CADET_Handle *h = channel->cadet; |
908 | struct GNUNET_CADET_LocalChannelDestroyMessage *msg; | 903 | struct GNUNET_CADET_LocalChannelDestroyMessage *msg; |
909 | struct GNUNET_MQ_Envelope *env; | 904 | struct GNUNET_MQ_Envelope *env; |
910 | 905 | ||
911 | if (NULL != h->mq) | 906 | if (NULL != h->mq) |
912 | { | 907 | { |
913 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); | 908 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); |
914 | msg->ccn = channel->ccn; | 909 | msg->ccn = channel->ccn; |
915 | GNUNET_MQ_send (h->mq, env); | 910 | GNUNET_MQ_send(h->mq, env); |
916 | } | 911 | } |
917 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 912 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
918 | "Destroying channel due to GNUNET_CADET_channel_destroy()\n"); | 913 | "Destroying channel due to GNUNET_CADET_channel_destroy()\n"); |
919 | channel->disconnects = NULL; | 914 | channel->disconnects = NULL; |
920 | destroy_channel (channel); | 915 | destroy_channel(channel); |
921 | } | 916 | } |
922 | 917 | ||
923 | 918 | ||
@@ -931,18 +926,19 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel) | |||
931 | * @return Union with an answer to the query. | 926 | * @return Union with an answer to the query. |
932 | */ | 927 | */ |
933 | const union GNUNET_CADET_ChannelInfo * | 928 | const union GNUNET_CADET_ChannelInfo * |
934 | GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel, | 929 | GNUNET_CADET_channel_get_info(struct GNUNET_CADET_Channel *channel, |
935 | enum GNUNET_CADET_ChannelInfoOption option, | 930 | enum GNUNET_CADET_ChannelInfoOption option, |
936 | ...) | 931 | ...) |
937 | { | 932 | { |
938 | switch (option) | 933 | switch (option) |
939 | { | 934 | { |
940 | case GNUNET_CADET_OPTION_PEER: | 935 | case GNUNET_CADET_OPTION_PEER: |
941 | return (const union GNUNET_CADET_ChannelInfo *) &channel->peer; | 936 | return (const union GNUNET_CADET_ChannelInfo *)&channel->peer; |
942 | default: | 937 | |
943 | GNUNET_break (0); | 938 | default: |
944 | return NULL; | 939 | GNUNET_break(0); |
945 | } | 940 | return NULL; |
941 | } | ||
946 | } | 942 | } |
947 | 943 | ||
948 | 944 | ||
@@ -952,17 +948,17 @@ GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel, | |||
952 | * @param ch Channel on which to send the ACK. | 948 | * @param ch Channel on which to send the ACK. |
953 | */ | 949 | */ |
954 | void | 950 | void |
955 | GNUNET_CADET_receive_done (struct GNUNET_CADET_Channel *channel) | 951 | GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel) |
956 | { | 952 | { |
957 | struct GNUNET_CADET_LocalAck *msg; | 953 | struct GNUNET_CADET_LocalAck *msg; |
958 | struct GNUNET_MQ_Envelope *env; | 954 | struct GNUNET_MQ_Envelope *env; |
959 | 955 | ||
960 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); | 956 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); |
961 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 957 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
962 | "Sending ACK on channel %X\n", | 958 | "Sending ACK on channel %X\n", |
963 | ntohl (channel->ccn.channel_of_client)); | 959 | ntohl(channel->ccn.channel_of_client)); |
964 | msg->ccn = channel->ccn; | 960 | msg->ccn = channel->ccn; |
965 | GNUNET_MQ_send (channel->cadet->mq, env); | 961 | GNUNET_MQ_send(channel->cadet->mq, env); |
966 | } | 962 | } |
967 | 963 | ||
968 | 964 | ||
@@ -974,23 +970,23 @@ GNUNET_CADET_receive_done (struct GNUNET_CADET_Channel *channel) | |||
974 | * @return Handle to the cadet service NULL on error. | 970 | * @return Handle to the cadet service NULL on error. |
975 | */ | 971 | */ |
976 | struct GNUNET_CADET_Handle * | 972 | struct GNUNET_CADET_Handle * |
977 | GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 973 | GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) |
978 | { | 974 | { |
979 | struct GNUNET_CADET_Handle *h; | 975 | struct GNUNET_CADET_Handle *h; |
980 | 976 | ||
981 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n"); | 977 | LOG(GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n"); |
982 | h = GNUNET_new (struct GNUNET_CADET_Handle); | 978 | h = GNUNET_new(struct GNUNET_CADET_Handle); |
983 | h->cfg = cfg; | 979 | h->cfg = cfg; |
984 | h->ports = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_YES); | 980 | h->ports = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_YES); |
985 | h->channels = GNUNET_CONTAINER_multihashmap32_create (4); | 981 | h->channels = GNUNET_CONTAINER_multihashmap32_create(4); |
986 | reconnect (h); | 982 | reconnect(h); |
987 | if (NULL == h->mq) | 983 | if (NULL == h->mq) |
988 | { | 984 | { |
989 | GNUNET_break (0); | 985 | GNUNET_break(0); |
990 | GNUNET_CADET_disconnect (h); | 986 | GNUNET_CADET_disconnect(h); |
991 | return NULL; | 987 | return NULL; |
992 | } | 988 | } |
993 | h->next_ccn.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); | 989 | h->next_ccn.channel_of_client = htonl(GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); |
994 | return h; | 990 | return h; |
995 | } | 991 | } |
996 | 992 | ||
@@ -1008,41 +1004,41 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1008 | * @return Port handle, NULL if port is in use | 1004 | * @return Port handle, NULL if port is in use |
1009 | */ | 1005 | */ |
1010 | struct GNUNET_CADET_Port * | 1006 | struct GNUNET_CADET_Port * |
1011 | GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, | 1007 | GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, |
1012 | const struct GNUNET_HashCode *port, | 1008 | const struct GNUNET_HashCode *port, |
1013 | GNUNET_CADET_ConnectEventHandler connects, | 1009 | GNUNET_CADET_ConnectEventHandler connects, |
1014 | void *connects_cls, | 1010 | void *connects_cls, |
1015 | GNUNET_CADET_WindowSizeEventHandler window_changes, | 1011 | GNUNET_CADET_WindowSizeEventHandler window_changes, |
1016 | GNUNET_CADET_DisconnectEventHandler disconnects, | 1012 | GNUNET_CADET_DisconnectEventHandler disconnects, |
1017 | const struct GNUNET_MQ_MessageHandler *handlers) | 1013 | const struct GNUNET_MQ_MessageHandler *handlers) |
1018 | { | 1014 | { |
1019 | struct GNUNET_CADET_Port *p; | 1015 | struct GNUNET_CADET_Port *p; |
1020 | 1016 | ||
1021 | GNUNET_assert (NULL != connects); | 1017 | GNUNET_assert(NULL != connects); |
1022 | GNUNET_assert (NULL != disconnects); | 1018 | GNUNET_assert(NULL != disconnects); |
1023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1019 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1024 | "Listening to CADET port %s\n", | 1020 | "Listening to CADET port %s\n", |
1025 | GNUNET_h2s (port)); | 1021 | GNUNET_h2s(port)); |
1026 | 1022 | ||
1027 | p = GNUNET_new (struct GNUNET_CADET_Port); | 1023 | p = GNUNET_new(struct GNUNET_CADET_Port); |
1028 | p->cadet = h; | 1024 | p->cadet = h; |
1029 | p->id = *port; | 1025 | p->id = *port; |
1030 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( | 1026 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( |
1031 | h->ports, | 1027 | h->ports, |
1032 | &p->id, | 1028 | &p->id, |
1033 | p, | 1029 | p, |
1034 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 1030 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
1035 | { | 1031 | { |
1036 | GNUNET_free (p); | 1032 | GNUNET_free(p); |
1037 | return NULL; | 1033 | return NULL; |
1038 | } | 1034 | } |
1039 | p->connects = connects; | 1035 | p->connects = connects; |
1040 | p->cls = connects_cls; | 1036 | p->cls = connects_cls; |
1041 | p->window_changes = window_changes; | 1037 | p->window_changes = window_changes; |
1042 | p->disconnects = disconnects; | 1038 | p->disconnects = disconnects; |
1043 | p->handlers = GNUNET_MQ_copy_handlers (handlers); | 1039 | p->handlers = GNUNET_MQ_copy_handlers(handlers); |
1044 | 1040 | ||
1045 | GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p)); | 1041 | GNUNET_assert(GNUNET_OK == open_port_cb(h, &p->id, p)); |
1046 | return p; | 1042 | return p; |
1047 | } | 1043 | } |
1048 | 1044 | ||
@@ -1066,45 +1062,45 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, | |||
1066 | * @return Handle to the channel. | 1062 | * @return Handle to the channel. |
1067 | */ | 1063 | */ |
1068 | struct GNUNET_CADET_Channel * | 1064 | struct GNUNET_CADET_Channel * |
1069 | GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h, | 1065 | GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h, |
1070 | void *channel_cls, | 1066 | void *channel_cls, |
1071 | const struct GNUNET_PeerIdentity *destination, | 1067 | const struct GNUNET_PeerIdentity *destination, |
1072 | const struct GNUNET_HashCode *port, | 1068 | const struct GNUNET_HashCode *port, |
1073 | GNUNET_CADET_WindowSizeEventHandler window_changes, | 1069 | GNUNET_CADET_WindowSizeEventHandler window_changes, |
1074 | GNUNET_CADET_DisconnectEventHandler disconnects, | 1070 | GNUNET_CADET_DisconnectEventHandler disconnects, |
1075 | const struct GNUNET_MQ_MessageHandler *handlers) | 1071 | const struct GNUNET_MQ_MessageHandler *handlers) |
1076 | { | 1072 | { |
1077 | struct GNUNET_CADET_Channel *ch; | 1073 | struct GNUNET_CADET_Channel *ch; |
1078 | struct GNUNET_CADET_LocalChannelCreateMessage *msg; | 1074 | struct GNUNET_CADET_LocalChannelCreateMessage *msg; |
1079 | struct GNUNET_MQ_Envelope *env; | 1075 | struct GNUNET_MQ_Envelope *env; |
1080 | 1076 | ||
1081 | GNUNET_assert (NULL != disconnects); | 1077 | GNUNET_assert(NULL != disconnects); |
1082 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1078 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1083 | "Creating channel to peer %s at port %s\n", | 1079 | "Creating channel to peer %s at port %s\n", |
1084 | GNUNET_i2s (destination), | 1080 | GNUNET_i2s(destination), |
1085 | GNUNET_h2s (port)); | 1081 | GNUNET_h2s(port)); |
1086 | ch = create_channel (h, NULL); | 1082 | ch = create_channel(h, NULL); |
1087 | ch->ctx = channel_cls; | 1083 | ch->ctx = channel_cls; |
1088 | ch->peer = *destination; | 1084 | ch->peer = *destination; |
1089 | ch->window_changes = window_changes; | 1085 | ch->window_changes = window_changes; |
1090 | ch->disconnects = disconnects; | 1086 | ch->disconnects = disconnects; |
1091 | 1087 | ||
1092 | /* Create MQ for channel */ | 1088 | /* Create MQ for channel */ |
1093 | ch->mq = GNUNET_MQ_queue_for_callbacks (&cadet_mq_send_impl, | 1089 | ch->mq = GNUNET_MQ_queue_for_callbacks(&cadet_mq_send_impl, |
1094 | &cadet_mq_destroy_impl, | 1090 | &cadet_mq_destroy_impl, |
1095 | &cadet_mq_cancel_impl, | 1091 | &cadet_mq_cancel_impl, |
1096 | ch, | 1092 | ch, |
1097 | handlers, | 1093 | handlers, |
1098 | &cadet_mq_error_handler, | 1094 | &cadet_mq_error_handler, |
1099 | ch); | 1095 | ch); |
1100 | GNUNET_MQ_set_handlers_closure (ch->mq, channel_cls); | 1096 | GNUNET_MQ_set_handlers_closure(ch->mq, channel_cls); |
1101 | 1097 | ||
1102 | /* Request channel creation to service */ | 1098 | /* Request channel creation to service */ |
1103 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); | 1099 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); |
1104 | msg->ccn = ch->ccn; | 1100 | msg->ccn = ch->ccn; |
1105 | msg->port = *port; | 1101 | msg->port = *port; |
1106 | msg->peer = *destination; | 1102 | msg->peer = *destination; |
1107 | GNUNET_MQ_send (h->mq, env); | 1103 | GNUNET_MQ_send(h->mq, env); |
1108 | return ch; | 1104 | return ch; |
1109 | } | 1105 | } |
1110 | 1106 | ||
@@ -1117,7 +1113,7 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h, | |||
1117 | * @return NULL if @a channel is not yet connected. | 1113 | * @return NULL if @a channel is not yet connected. |
1118 | */ | 1114 | */ |
1119 | struct GNUNET_MQ_Handle * | 1115 | struct GNUNET_MQ_Handle * |
1120 | GNUNET_CADET_get_mq (const struct GNUNET_CADET_Channel *channel) | 1116 | GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel) |
1121 | { | 1117 | { |
1122 | return channel->mq; | 1118 | return channel->mq; |
1123 | } | 1119 | } |