summaryrefslogtreecommitdiff
path: root/src/util/mq.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/mq.c')
-rw-r--r--src/util/mq.c680
1 files changed, 340 insertions, 340 deletions
diff --git a/src/util/mq.c b/src/util/mq.c
index 03b0f3a2a..188606fb4 100644
--- a/src/util/mq.c
+++ b/src/util/mq.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/** 21/**
22 * @author Florian Dold 22 * @author Florian Dold
@@ -26,11 +26,10 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28 28
29#define LOG(kind, ...) GNUNET_log_from (kind, "util-mq", __VA_ARGS__) 29#define LOG(kind, ...) GNUNET_log_from(kind, "util-mq", __VA_ARGS__)
30 30
31 31
32struct GNUNET_MQ_Envelope 32struct GNUNET_MQ_Envelope {
33{
34 /** 33 /**
35 * Messages are stored in a linked list. 34 * Messages are stored in a linked list.
36 * Each queue has its own list of envelopes. 35 * Each queue has its own list of envelopes.
@@ -82,8 +81,7 @@ struct GNUNET_MQ_Envelope
82/** 81/**
83 * Handle to a message queue. 82 * Handle to a message queue.
84 */ 83 */
85struct GNUNET_MQ_Handle 84struct GNUNET_MQ_Handle {
86{
87 /** 85 /**
88 * Handlers array, or NULL if the queue should not receive messages 86 * Handlers array, or NULL if the queue should not receive messages
89 */ 87 */
@@ -199,17 +197,17 @@ struct GNUNET_MQ_Handle
199 * @param mh message to dispatch 197 * @param mh message to dispatch
200 */ 198 */
201void 199void
202GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, 200GNUNET_MQ_inject_message(struct GNUNET_MQ_Handle *mq,
203 const struct GNUNET_MessageHeader *mh) 201 const struct GNUNET_MessageHeader *mh)
204{ 202{
205 int ret; 203 int ret;
206 204
207 ret = GNUNET_MQ_handle_message (mq->handlers, mh); 205 ret = GNUNET_MQ_handle_message(mq->handlers, mh);
208 if (GNUNET_SYSERR == ret) 206 if (GNUNET_SYSERR == ret)
209 { 207 {
210 GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_MALFORMED); 208 GNUNET_MQ_inject_error(mq, GNUNET_MQ_ERROR_MALFORMED);
211 return; 209 return;
212 } 210 }
213} 211}
214 212
215 213
@@ -226,62 +224,62 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
226 * #GNUNET_SYSERR if message was rejected by check function 224 * #GNUNET_SYSERR if message was rejected by check function
227 */ 225 */
228int 226int
229GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers, 227GNUNET_MQ_handle_message(const struct GNUNET_MQ_MessageHandler *handlers,
230 const struct GNUNET_MessageHeader *mh) 228 const struct GNUNET_MessageHeader *mh)
231{ 229{
232 const struct GNUNET_MQ_MessageHandler *handler; 230 const struct GNUNET_MQ_MessageHandler *handler;
233 int handled = GNUNET_NO; 231 int handled = GNUNET_NO;
234 uint16_t msize = ntohs (mh->size); 232 uint16_t msize = ntohs(mh->size);
235 uint16_t mtype = ntohs (mh->type); 233 uint16_t mtype = ntohs(mh->type);
236 234
237 LOG (GNUNET_ERROR_TYPE_DEBUG, 235 LOG(GNUNET_ERROR_TYPE_DEBUG,
238 "Received message of type %u and size %u\n", 236 "Received message of type %u and size %u\n",
239 mtype, 237 mtype,
240 msize); 238 msize);
241 239
242 if (NULL == handlers) 240 if (NULL == handlers)
243 goto done; 241 goto done;
244 for (handler = handlers; NULL != handler->cb; handler++) 242 for (handler = handlers; NULL != handler->cb; handler++)
245 {
246 if (handler->type == mtype)
247 { 243 {
248 handled = GNUNET_YES; 244 if (handler->type == mtype)
249 if ((handler->expected_size > msize) || 245 {
250 ((handler->expected_size != msize) && (NULL == handler->mv))) 246 handled = GNUNET_YES;
251 { 247 if ((handler->expected_size > msize) ||
252 /* Too small, or not an exact size and 248 ((handler->expected_size != msize) && (NULL == handler->mv)))
253 no 'mv' handler to check rest */ 249 {
254 LOG (GNUNET_ERROR_TYPE_ERROR, 250 /* Too small, or not an exact size and
255 "Received malformed message of type %u\n", 251 no 'mv' handler to check rest */
256 (unsigned int) handler->type); 252 LOG(GNUNET_ERROR_TYPE_ERROR,
257 return GNUNET_SYSERR; 253 "Received malformed message of type %u\n",
258 } 254 (unsigned int)handler->type);
259 if ((NULL == handler->mv) || 255 return GNUNET_SYSERR;
260 (GNUNET_OK == handler->mv (handler->cls, mh))) 256 }
261 { 257 if ((NULL == handler->mv) ||
262 /* message well-formed, pass to handler */ 258 (GNUNET_OK == handler->mv(handler->cls, mh)))
263 handler->cb (handler->cls, mh); 259 {
264 } 260 /* message well-formed, pass to handler */
265 else 261 handler->cb(handler->cls, mh);
266 { 262 }
267 /* Message rejected by check routine */ 263 else
268 LOG (GNUNET_ERROR_TYPE_ERROR, 264 {
269 "Received malformed message of type %u\n", 265 /* Message rejected by check routine */
270 (unsigned int) handler->type); 266 LOG(GNUNET_ERROR_TYPE_ERROR,
271 return GNUNET_SYSERR; 267 "Received malformed message of type %u\n",
272 } 268 (unsigned int)handler->type);
273 break; 269 return GNUNET_SYSERR;
270 }
271 break;
272 }
274 } 273 }
275 }
276done: 274done:
277 if (GNUNET_NO == handled) 275 if (GNUNET_NO == handled)
278 { 276 {
279 LOG (GNUNET_ERROR_TYPE_INFO, 277 LOG(GNUNET_ERROR_TYPE_INFO,
280 "No handler for message of type %u and size %u\n", 278 "No handler for message of type %u and size %u\n",
281 mtype, 279 mtype,
282 msize); 280 msize);
283 return GNUNET_NO; 281 return GNUNET_NO;
284 } 282 }
285 return GNUNET_OK; 283 return GNUNET_OK;
286} 284}
287 285
@@ -297,16 +295,16 @@ done:
297 * @param error the error type 295 * @param error the error type
298 */ 296 */
299void 297void
300GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_Error error) 298GNUNET_MQ_inject_error(struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_Error error)
301{ 299{
302 if (NULL == mq->error_handler) 300 if (NULL == mq->error_handler)
303 { 301 {
304 LOG (GNUNET_ERROR_TYPE_WARNING, 302 LOG(GNUNET_ERROR_TYPE_WARNING,
305 "Got error %d, but no handler installed\n", 303 "Got error %d, but no handler installed\n",
306 (int) error); 304 (int)error);
307 return; 305 return;
308 } 306 }
309 mq->error_handler (mq->error_handler_cls, error); 307 mq->error_handler(mq->error_handler_cls, error);
310} 308}
311 309
312 310
@@ -318,10 +316,10 @@ GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_Error error)
318 * @param mqm the message to discard 316 * @param mqm the message to discard
319 */ 317 */
320void 318void
321GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *ev) 319GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *ev)
322{ 320{
323 GNUNET_assert (NULL == ev->parent_queue); 321 GNUNET_assert(NULL == ev->parent_queue);
324 GNUNET_free (ev); 322 GNUNET_free(ev);
325} 323}
326 324
327 325
@@ -332,12 +330,12 @@ GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *ev)
332 * @return number of queued, non-transmitted messages 330 * @return number of queued, non-transmitted messages
333 */ 331 */
334unsigned int 332unsigned int
335GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq) 333GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
336{ 334{
337 if (GNUNET_YES != mq->in_flight) 335 if (GNUNET_YES != mq->in_flight)
338 { 336 {
339 return mq->queue_length; 337 return mq->queue_length;
340 } 338 }
341 return mq->queue_length - 1; 339 return mq->queue_length - 1;
342} 340}
343 341
@@ -350,36 +348,36 @@ GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq)
350 * @param ev the envelope with the message to send. 348 * @param ev the envelope with the message to send.
351 */ 349 */
352void 350void
353GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev) 351GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
354{ 352{
355 GNUNET_assert (NULL != mq); 353 GNUNET_assert(NULL != mq);
356 GNUNET_assert (NULL == ev->parent_queue); 354 GNUNET_assert(NULL == ev->parent_queue);
357 355
358 mq->queue_length++; 356 mq->queue_length++;
359 if (mq->queue_length >= 10000) 357 if (mq->queue_length >= 10000)
360 { 358 {
361 /* This would seem like a bug... */ 359 /* This would seem like a bug... */
362 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 360 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
363 "MQ with %u entries extended by message of type %u (FC broken?)\n", 361 "MQ with %u entries extended by message of type %u (FC broken?)\n",
364 (unsigned int) mq->queue_length, 362 (unsigned int)mq->queue_length,
365 (unsigned int) ntohs (ev->mh->type)); 363 (unsigned int)ntohs(ev->mh->type));
366 } 364 }
367 ev->parent_queue = mq; 365 ev->parent_queue = mq;
368 /* is the implementation busy? queue it! */ 366 /* is the implementation busy? queue it! */
369 if ((NULL != mq->current_envelope) || (NULL != mq->send_task)) 367 if ((NULL != mq->current_envelope) || (NULL != mq->send_task))
370 { 368 {
371 GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head, mq->envelope_tail, ev); 369 GNUNET_CONTAINER_DLL_insert_tail(mq->envelope_head, mq->envelope_tail, ev);
372 return; 370 return;
373 } 371 }
374 GNUNET_assert (NULL == mq->envelope_head); 372 GNUNET_assert(NULL == mq->envelope_head);
375 mq->current_envelope = ev; 373 mq->current_envelope = ev;
376 374
377 LOG (GNUNET_ERROR_TYPE_DEBUG, 375 LOG(GNUNET_ERROR_TYPE_DEBUG,
378 "sending message of type %u, queue empty (MQ: %p)\n", 376 "sending message of type %u, queue empty (MQ: %p)\n",
379 ntohs (ev->mh->type), 377 ntohs(ev->mh->type),
380 mq); 378 mq);
381 379
382 mq->send_impl (mq, ev->mh, mq->impl_state); 380 mq->send_impl(mq, ev->mh, mq->impl_state);
383} 381}
384 382
385 383
@@ -391,12 +389,12 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
391 * @return NULL if queue is empty (or has no envelope that is not under transmission) 389 * @return NULL if queue is empty (or has no envelope that is not under transmission)
392 */ 390 */
393struct GNUNET_MQ_Envelope * 391struct GNUNET_MQ_Envelope *
394GNUNET_MQ_unsent_head (struct GNUNET_MQ_Handle *mq) 392GNUNET_MQ_unsent_head(struct GNUNET_MQ_Handle *mq)
395{ 393{
396 struct GNUNET_MQ_Envelope *env; 394 struct GNUNET_MQ_Envelope *env;
397 395
398 env = mq->envelope_head; 396 env = mq->envelope_head;
399 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, env); 397 GNUNET_CONTAINER_DLL_remove(mq->envelope_head, mq->envelope_tail, env);
400 mq->queue_length--; 398 mq->queue_length--;
401 env->parent_queue = NULL; 399 env->parent_queue = NULL;
402 return env; 400 return env;
@@ -411,13 +409,13 @@ GNUNET_MQ_unsent_head (struct GNUNET_MQ_Handle *mq)
411 * @return copy of @a env 409 * @return copy of @a env
412 */ 410 */
413struct GNUNET_MQ_Envelope * 411struct GNUNET_MQ_Envelope *
414GNUNET_MQ_env_copy (struct GNUNET_MQ_Envelope *env) 412GNUNET_MQ_env_copy(struct GNUNET_MQ_Envelope *env)
415{ 413{
416 GNUNET_assert (NULL == env->next); 414 GNUNET_assert(NULL == env->next);
417 GNUNET_assert (NULL == env->parent_queue); 415 GNUNET_assert(NULL == env->parent_queue);
418 GNUNET_assert (NULL == env->sent_cb); 416 GNUNET_assert(NULL == env->sent_cb);
419 GNUNET_assert (GNUNET_NO == env->have_custom_options); 417 GNUNET_assert(GNUNET_NO == env->have_custom_options);
420 return GNUNET_MQ_msg_copy (env->mh); 418 return GNUNET_MQ_msg_copy(env->mh);
421} 419}
422 420
423 421
@@ -429,19 +427,19 @@ GNUNET_MQ_env_copy (struct GNUNET_MQ_Envelope *env)
429 * @param ev the envelope with the message to send. 427 * @param ev the envelope with the message to send.
430 */ 428 */
431void 429void
432GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq, 430GNUNET_MQ_send_copy(struct GNUNET_MQ_Handle *mq,
433 const struct GNUNET_MQ_Envelope *ev) 431 const struct GNUNET_MQ_Envelope *ev)
434{ 432{
435 struct GNUNET_MQ_Envelope *env; 433 struct GNUNET_MQ_Envelope *env;
436 uint16_t msize; 434 uint16_t msize;
437 435
438 msize = ntohs (ev->mh->size); 436 msize = ntohs(ev->mh->size);
439 env = GNUNET_malloc (sizeof (struct GNUNET_MQ_Envelope) + msize); 437 env = GNUNET_malloc(sizeof(struct GNUNET_MQ_Envelope) + msize);
440 env->mh = (struct GNUNET_MessageHeader *) &env[1]; 438 env->mh = (struct GNUNET_MessageHeader *)&env[1];
441 env->sent_cb = ev->sent_cb; 439 env->sent_cb = ev->sent_cb;
442 env->sent_cls = ev->sent_cls; 440 env->sent_cls = ev->sent_cls;
443 GNUNET_memcpy (&env[1], ev->mh, msize); 441 GNUNET_memcpy(&env[1], ev->mh, msize);
444 GNUNET_MQ_send (mq, env); 442 GNUNET_MQ_send(mq, env);
445} 443}
446 444
447 445
@@ -453,7 +451,7 @@ GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq,
453 * @param cls message queue to send the next message with 451 * @param cls message queue to send the next message with
454 */ 452 */
455static void 453static void
456impl_send_continue (void *cls) 454impl_send_continue(void *cls)
457{ 455{
458 struct GNUNET_MQ_Handle *mq = cls; 456 struct GNUNET_MQ_Handle *mq = cls;
459 457
@@ -463,15 +461,15 @@ impl_send_continue (void *cls)
463 if (NULL == mq->envelope_head) 461 if (NULL == mq->envelope_head)
464 return; 462 return;
465 mq->current_envelope = mq->envelope_head; 463 mq->current_envelope = mq->envelope_head;
466 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 464 GNUNET_CONTAINER_DLL_remove(mq->envelope_head,
467 mq->envelope_tail, 465 mq->envelope_tail,
468 mq->current_envelope); 466 mq->current_envelope);
469 467
470 LOG (GNUNET_ERROR_TYPE_DEBUG, 468 LOG(GNUNET_ERROR_TYPE_DEBUG,
471 "sending message of type %u from queue\n", 469 "sending message of type %u from queue\n",
472 ntohs (mq->current_envelope->mh->type)); 470 ntohs(mq->current_envelope->mh->type));
473 471
474 mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state); 472 mq->send_impl(mq, mq->current_envelope->mh, mq->impl_state);
475} 473}
476 474
477 475
@@ -483,25 +481,25 @@ impl_send_continue (void *cls)
483 * @param mq message queue to send the next message with 481 * @param mq message queue to send the next message with
484 */ 482 */
485void 483void
486GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq) 484GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
487{ 485{
488 struct GNUNET_MQ_Envelope *current_envelope; 486 struct GNUNET_MQ_Envelope *current_envelope;
489 GNUNET_SCHEDULER_TaskCallback cb; 487 GNUNET_SCHEDULER_TaskCallback cb;
490 488
491 GNUNET_assert (0 < mq->queue_length); 489 GNUNET_assert(0 < mq->queue_length);
492 mq->queue_length--; 490 mq->queue_length--;
493 mq->in_flight = GNUNET_NO; 491 mq->in_flight = GNUNET_NO;
494 current_envelope = mq->current_envelope; 492 current_envelope = mq->current_envelope;
495 current_envelope->parent_queue = NULL; 493 current_envelope->parent_queue = NULL;
496 mq->current_envelope = NULL; 494 mq->current_envelope = NULL;
497 GNUNET_assert (NULL == mq->send_task); 495 GNUNET_assert(NULL == mq->send_task);
498 mq->send_task = GNUNET_SCHEDULER_add_now (&impl_send_continue, mq); 496 mq->send_task = GNUNET_SCHEDULER_add_now(&impl_send_continue, mq);
499 if (NULL != (cb = current_envelope->sent_cb)) 497 if (NULL != (cb = current_envelope->sent_cb))
500 { 498 {
501 current_envelope->sent_cb = NULL; 499 current_envelope->sent_cb = NULL;
502 cb (current_envelope->sent_cls); 500 cb(current_envelope->sent_cls);
503 } 501 }
504 GNUNET_free (current_envelope); 502 GNUNET_free(current_envelope);
505} 503}
506 504
507 505
@@ -516,7 +514,7 @@ GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq)
516 * @param mq message queue to send the next message with 514 * @param mq message queue to send the next message with
517 */ 515 */
518void 516void
519GNUNET_MQ_impl_send_in_flight (struct GNUNET_MQ_Handle *mq) 517GNUNET_MQ_impl_send_in_flight(struct GNUNET_MQ_Handle *mq)
520{ 518{
521 struct GNUNET_MQ_Envelope *current_envelope; 519 struct GNUNET_MQ_Envelope *current_envelope;
522 GNUNET_SCHEDULER_TaskCallback cb; 520 GNUNET_SCHEDULER_TaskCallback cb;
@@ -525,14 +523,14 @@ GNUNET_MQ_impl_send_in_flight (struct GNUNET_MQ_Handle *mq)
525 /* call is only valid if we're actually currently sending 523 /* call is only valid if we're actually currently sending
526 * a message */ 524 * a message */
527 current_envelope = mq->current_envelope; 525 current_envelope = mq->current_envelope;
528 GNUNET_assert (NULL != current_envelope); 526 GNUNET_assert(NULL != current_envelope);
529 /* can't call cancel from now on anymore */ 527 /* can't call cancel from now on anymore */
530 current_envelope->parent_queue = NULL; 528 current_envelope->parent_queue = NULL;
531 if (NULL != (cb = current_envelope->sent_cb)) 529 if (NULL != (cb = current_envelope->sent_cb))
532 { 530 {
533 current_envelope->sent_cb = NULL; 531 current_envelope->sent_cb = NULL;
534 cb (current_envelope->sent_cls); 532 cb(current_envelope->sent_cls);
535 } 533 }
536} 534}
537 535
538 536
@@ -549,21 +547,21 @@ GNUNET_MQ_impl_send_in_flight (struct GNUNET_MQ_Handle *mq)
549 * @return a new message queue 547 * @return a new message queue
550 */ 548 */
551struct GNUNET_MQ_Handle * 549struct GNUNET_MQ_Handle *
552GNUNET_MQ_queue_for_callbacks (GNUNET_MQ_SendImpl send, 550GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send,
553 GNUNET_MQ_DestroyImpl destroy, 551 GNUNET_MQ_DestroyImpl destroy,
554 GNUNET_MQ_CancelImpl cancel, 552 GNUNET_MQ_CancelImpl cancel,
555 void *impl_state, 553 void *impl_state,
556 const struct GNUNET_MQ_MessageHandler *handlers, 554 const struct GNUNET_MQ_MessageHandler *handlers,
557 GNUNET_MQ_ErrorHandler error_handler, 555 GNUNET_MQ_ErrorHandler error_handler,
558 void *error_handler_cls) 556 void *error_handler_cls)
559{ 557{
560 struct GNUNET_MQ_Handle *mq; 558 struct GNUNET_MQ_Handle *mq;
561 559
562 mq = GNUNET_new (struct GNUNET_MQ_Handle); 560 mq = GNUNET_new(struct GNUNET_MQ_Handle);
563 mq->send_impl = send; 561 mq->send_impl = send;
564 mq->destroy_impl = destroy; 562 mq->destroy_impl = destroy;
565 mq->cancel_impl = cancel; 563 mq->cancel_impl = cancel;
566 mq->handlers = GNUNET_MQ_copy_handlers (handlers); 564 mq->handlers = GNUNET_MQ_copy_handlers(handlers);
567 mq->error_handler = error_handler; 565 mq->error_handler = error_handler;
568 mq->error_handler_cls = error_handler_cls; 566 mq->error_handler_cls = error_handler_cls;
569 mq->impl_state = impl_state; 567 mq->impl_state = impl_state;
@@ -580,7 +578,7 @@ GNUNET_MQ_queue_for_callbacks (GNUNET_MQ_SendImpl send,
580 * @param handlers_cls new closure to use 578 * @param handlers_cls new closure to use
581 */ 579 */
582void 580void
583GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq, void *handlers_cls) 581GNUNET_MQ_set_handlers_closure(struct GNUNET_MQ_Handle *mq, void *handlers_cls)
584{ 582{
585 if (NULL == mq->handlers) 583 if (NULL == mq->handlers)
586 return; 584 return;
@@ -599,10 +597,10 @@ GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq, void *handlers_cls)
599 * @return message to send, never NULL 597 * @return message to send, never NULL
600 */ 598 */
601const struct GNUNET_MessageHeader * 599const struct GNUNET_MessageHeader *
602GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq) 600GNUNET_MQ_impl_current(struct GNUNET_MQ_Handle *mq)
603{ 601{
604 GNUNET_assert (NULL != mq->current_envelope); 602 GNUNET_assert(NULL != mq->current_envelope);
605 GNUNET_assert (NULL != mq->current_envelope->mh); 603 GNUNET_assert(NULL != mq->current_envelope->mh);
606 return mq->current_envelope->mh; 604 return mq->current_envelope->mh;
607} 605}
608 606
@@ -622,21 +620,21 @@ GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq)
622 * @return message to send, never NULL 620 * @return message to send, never NULL
623 */ 621 */
624void * 622void *
625GNUNET_MQ_impl_state (struct GNUNET_MQ_Handle *mq) 623GNUNET_MQ_impl_state(struct GNUNET_MQ_Handle *mq)
626{ 624{
627 return mq->impl_state; 625 return mq->impl_state;
628} 626}
629 627
630 628
631struct GNUNET_MQ_Envelope * 629struct GNUNET_MQ_Envelope *
632GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type) 630GNUNET_MQ_msg_(struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
633{ 631{
634 struct GNUNET_MQ_Envelope *ev; 632 struct GNUNET_MQ_Envelope *ev;
635 633
636 ev = GNUNET_malloc (size + sizeof (struct GNUNET_MQ_Envelope)); 634 ev = GNUNET_malloc(size + sizeof(struct GNUNET_MQ_Envelope));
637 ev->mh = (struct GNUNET_MessageHeader *) &ev[1]; 635 ev->mh = (struct GNUNET_MessageHeader *)&ev[1];
638 ev->mh->size = htons (size); 636 ev->mh->size = htons(size);
639 ev->mh->type = htons (type); 637 ev->mh->type = htons(type);
640 if (NULL != mhp) 638 if (NULL != mhp)
641 *mhp = ev->mh; 639 *mhp = ev->mh;
642 return ev; 640 return ev;
@@ -650,14 +648,14 @@ GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
650 * @return envelope containing @a hdr 648 * @return envelope containing @a hdr
651 */ 649 */
652struct GNUNET_MQ_Envelope * 650struct GNUNET_MQ_Envelope *
653GNUNET_MQ_msg_copy (const struct GNUNET_MessageHeader *hdr) 651GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
654{ 652{
655 struct GNUNET_MQ_Envelope *mqm; 653 struct GNUNET_MQ_Envelope *mqm;
656 uint16_t size = ntohs (hdr->size); 654 uint16_t size = ntohs(hdr->size);
657 655
658 mqm = GNUNET_malloc (sizeof (*mqm) + size); 656 mqm = GNUNET_malloc(sizeof(*mqm) + size);
659 mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1]; 657 mqm->mh = (struct GNUNET_MessageHeader *)&mqm[1];
660 GNUNET_memcpy (mqm->mh, hdr, size); 658 GNUNET_memcpy(mqm->mh, hdr, size);
661 return mqm; 659 return mqm;
662} 660}
663 661
@@ -672,27 +670,27 @@ GNUNET_MQ_msg_copy (const struct GNUNET_MessageHeader *hdr)
672 * @param nested_mh the message to append to the message after base_size 670 * @param nested_mh the message to append to the message after base_size
673 */ 671 */
674struct GNUNET_MQ_Envelope * 672struct GNUNET_MQ_Envelope *
675GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp, 673GNUNET_MQ_msg_nested_mh_(struct GNUNET_MessageHeader **mhp,
676 uint16_t base_size, 674 uint16_t base_size,
677 uint16_t type, 675 uint16_t type,
678 const struct GNUNET_MessageHeader *nested_mh) 676 const struct GNUNET_MessageHeader *nested_mh)
679{ 677{
680 struct GNUNET_MQ_Envelope *mqm; 678 struct GNUNET_MQ_Envelope *mqm;
681 uint16_t size; 679 uint16_t size;
682 680
683 if (NULL == nested_mh) 681 if (NULL == nested_mh)
684 return GNUNET_MQ_msg_ (mhp, base_size, type); 682 return GNUNET_MQ_msg_(mhp, base_size, type);
685 683
686 size = base_size + ntohs (nested_mh->size); 684 size = base_size + ntohs(nested_mh->size);
687 685
688 /* check for uint16_t overflow */ 686 /* check for uint16_t overflow */
689 if (size < base_size) 687 if (size < base_size)
690 return NULL; 688 return NULL;
691 689
692 mqm = GNUNET_MQ_msg_ (mhp, size, type); 690 mqm = GNUNET_MQ_msg_(mhp, size, type);
693 GNUNET_memcpy ((char *) mqm->mh + base_size, 691 GNUNET_memcpy((char *)mqm->mh + base_size,
694 nested_mh, 692 nested_mh,
695 ntohs (nested_mh->size)); 693 ntohs(nested_mh->size));
696 694
697 return mqm; 695 return mqm;
698} 696}
@@ -705,22 +703,22 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp,
705 * @param assoc_data to associate 703 * @param assoc_data to associate
706 */ 704 */
707uint32_t 705uint32_t
708GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data) 706GNUNET_MQ_assoc_add(struct GNUNET_MQ_Handle *mq, void *assoc_data)
709{ 707{
710 uint32_t id; 708 uint32_t id;
711 709
712 if (NULL == mq->assoc_map) 710 if (NULL == mq->assoc_map)
713 { 711 {
714 mq->assoc_map = GNUNET_CONTAINER_multihashmap32_create (8); 712 mq->assoc_map = GNUNET_CONTAINER_multihashmap32_create(8);
715 mq->assoc_id = 1; 713 mq->assoc_id = 1;
716 } 714 }
717 id = mq->assoc_id++; 715 id = mq->assoc_id++;
718 GNUNET_assert (GNUNET_OK == 716 GNUNET_assert(GNUNET_OK ==
719 GNUNET_CONTAINER_multihashmap32_put ( 717 GNUNET_CONTAINER_multihashmap32_put(
720 mq->assoc_map, 718 mq->assoc_map,
721 id, 719 id,
722 assoc_data, 720 assoc_data,
723 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 721 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
724 return id; 722 return id;
725} 723}
726 724
@@ -733,11 +731,11 @@ GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data)
733 * @return the associated data 731 * @return the associated data
734 */ 732 */
735void * 733void *
736GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id) 734GNUNET_MQ_assoc_get(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
737{ 735{
738 if (NULL == mq->assoc_map) 736 if (NULL == mq->assoc_map)
739 return NULL; 737 return NULL;
740 return GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id); 738 return GNUNET_CONTAINER_multihashmap32_get(mq->assoc_map, request_id);
741} 739}
742 740
743 741
@@ -749,14 +747,14 @@ GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
749 * @return the associated data 747 * @return the associated data
750 */ 748 */
751void * 749void *
752GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id) 750GNUNET_MQ_assoc_remove(struct GNUNET_MQ_Handle *mq, uint32_t request_id)
753{ 751{
754 void *val; 752 void *val;
755 753
756 if (NULL == mq->assoc_map) 754 if (NULL == mq->assoc_map)
757 return NULL; 755 return NULL;
758 val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id); 756 val = GNUNET_CONTAINER_multihashmap32_get(mq->assoc_map, request_id);
759 GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map, request_id); 757 GNUNET_CONTAINER_multihashmap32_remove_all(mq->assoc_map, request_id);
760 return val; 758 return val;
761} 759}
762 760
@@ -771,12 +769,12 @@ GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
771 * @param cb_cls closure for the callback 769 * @param cb_cls closure for the callback
772 */ 770 */
773void 771void
774GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev, 772GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev,
775 GNUNET_SCHEDULER_TaskCallback cb, 773 GNUNET_SCHEDULER_TaskCallback cb,
776 void *cb_cls) 774 void *cb_cls)
777{ 775{
778 /* allow setting *OR* clearing callback */ 776 /* allow setting *OR* clearing callback */
779 GNUNET_assert ((NULL == ev->sent_cb) || (NULL == cb)); 777 GNUNET_assert((NULL == ev->sent_cb) || (NULL == cb));
780 ev->sent_cb = cb; 778 ev->sent_cb = cb;
781 ev->sent_cls = cb_cls; 779 ev->sent_cls = cb_cls;
782} 780}
@@ -786,8 +784,7 @@ GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev,
786 * Handle we return for callbacks registered to be 784 * Handle we return for callbacks registered to be
787 * notified when #GNUNET_MQ_destroy() is called on a queue. 785 * notified when #GNUNET_MQ_destroy() is called on a queue.
788 */ 786 */
789struct GNUNET_MQ_DestroyNotificationHandle 787struct GNUNET_MQ_DestroyNotificationHandle {
790{
791 /** 788 /**
792 * Kept in a DLL. 789 * Kept in a DLL.
793 */ 790 */
@@ -821,86 +818,86 @@ struct GNUNET_MQ_DestroyNotificationHandle
821 * @param mq message queue to destroy 818 * @param mq message queue to destroy
822 */ 819 */
823void 820void
824GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq) 821GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
825{ 822{
826 struct GNUNET_MQ_DestroyNotificationHandle *dnh; 823 struct GNUNET_MQ_DestroyNotificationHandle *dnh;
827 824
828 if (NULL != mq->destroy_impl) 825 if (NULL != mq->destroy_impl)
829 { 826 {
830 mq->destroy_impl (mq, mq->impl_state); 827 mq->destroy_impl(mq, mq->impl_state);
831 } 828 }
832 if (NULL != mq->send_task) 829 if (NULL != mq->send_task)
833 { 830 {
834 GNUNET_SCHEDULER_cancel (mq->send_task); 831 GNUNET_SCHEDULER_cancel(mq->send_task);
835 mq->send_task = NULL; 832 mq->send_task = NULL;
836 } 833 }
837 while (NULL != mq->envelope_head) 834 while (NULL != mq->envelope_head)
838 { 835 {
839 struct GNUNET_MQ_Envelope *ev; 836 struct GNUNET_MQ_Envelope *ev;
840 837
841 ev = mq->envelope_head; 838 ev = mq->envelope_head;
842 ev->parent_queue = NULL; 839 ev->parent_queue = NULL;
843 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev); 840 GNUNET_CONTAINER_DLL_remove(mq->envelope_head, mq->envelope_tail, ev);
844 GNUNET_assert (0 < mq->queue_length); 841 GNUNET_assert(0 < mq->queue_length);
845 mq->queue_length--; 842 mq->queue_length--;
846 LOG (GNUNET_ERROR_TYPE_DEBUG, 843 LOG(GNUNET_ERROR_TYPE_DEBUG,
847 "MQ destroy drops message of type %u\n", 844 "MQ destroy drops message of type %u\n",
848 ntohs (ev->mh->type)); 845 ntohs(ev->mh->type));
849 GNUNET_MQ_discard (ev); 846 GNUNET_MQ_discard(ev);
850 } 847 }
851 if (NULL != mq->current_envelope) 848 if (NULL != mq->current_envelope)
852 { 849 {
853 /* we can only discard envelopes that 850 /* we can only discard envelopes that
854 * are not queued! */ 851 * are not queued! */
855 mq->current_envelope->parent_queue = NULL; 852 mq->current_envelope->parent_queue = NULL;
856 LOG (GNUNET_ERROR_TYPE_DEBUG, 853 LOG(GNUNET_ERROR_TYPE_DEBUG,
857 "MQ destroy drops current message of type %u\n", 854 "MQ destroy drops current message of type %u\n",
858 ntohs (mq->current_envelope->mh->type)); 855 ntohs(mq->current_envelope->mh->type));
859 GNUNET_MQ_discard (mq->current_envelope); 856 GNUNET_MQ_discard(mq->current_envelope);
860 mq->current_envelope = NULL; 857 mq->current_envelope = NULL;
861 GNUNET_assert (0 < mq->queue_length); 858 GNUNET_assert(0 < mq->queue_length);
862 mq->queue_length--; 859 mq->queue_length--;
863 } 860 }
864 GNUNET_assert (0 == mq->queue_length); 861 GNUNET_assert(0 == mq->queue_length);
865 while (NULL != (dnh = mq->dnh_head)) 862 while (NULL != (dnh = mq->dnh_head))
866 { 863 {
867 dnh->cb (dnh->cb_cls); 864 dnh->cb(dnh->cb_cls);
868 GNUNET_MQ_destroy_notify_cancel (dnh); 865 GNUNET_MQ_destroy_notify_cancel(dnh);
869 } 866 }
870 if (NULL != mq->assoc_map) 867 if (NULL != mq->assoc_map)
871 { 868 {
872 GNUNET_CONTAINER_multihashmap32_destroy (mq->assoc_map); 869 GNUNET_CONTAINER_multihashmap32_destroy(mq->assoc_map);
873 mq->assoc_map = NULL; 870 mq->assoc_map = NULL;
874 } 871 }
875 GNUNET_free_non_null (mq->handlers); 872 GNUNET_free_non_null(mq->handlers);
876 GNUNET_free (mq); 873 GNUNET_free(mq);
877} 874}
878 875
879 876
880const struct GNUNET_MessageHeader * 877const struct GNUNET_MessageHeader *
881GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh, 878GNUNET_MQ_extract_nested_mh_(const struct GNUNET_MessageHeader *mh,
882 uint16_t base_size) 879 uint16_t base_size)
883{ 880{
884 uint16_t whole_size; 881 uint16_t whole_size;
885 uint16_t nested_size; 882 uint16_t nested_size;
886 const struct GNUNET_MessageHeader *nested_msg; 883 const struct GNUNET_MessageHeader *nested_msg;
887 884
888 whole_size = ntohs (mh->size); 885 whole_size = ntohs(mh->size);
889 GNUNET_assert (whole_size >= base_size); 886 GNUNET_assert(whole_size >= base_size);
890 nested_size = whole_size - base_size; 887 nested_size = whole_size - base_size;
891 if (0 == nested_size) 888 if (0 == nested_size)
892 return NULL; 889 return NULL;
893 if (nested_size < sizeof (struct GNUNET_MessageHeader)) 890 if (nested_size < sizeof(struct GNUNET_MessageHeader))
894 { 891 {
895 GNUNET_break_op (0); 892 GNUNET_break_op(0);
896 return NULL; 893 return NULL;
897 } 894 }
898 nested_msg = (const struct GNUNET_MessageHeader *) ((char *) mh + base_size); 895 nested_msg = (const struct GNUNET_MessageHeader *)((char *)mh + base_size);
899 if (ntohs (nested_msg->size) != nested_size) 896 if (ntohs(nested_msg->size) != nested_size)
900 { 897 {
901 GNUNET_break_op (0); 898 GNUNET_break_op(0);
902 return NULL; 899 return NULL;
903 } 900 }
904 return nested_msg; 901 return nested_msg;
905} 902}
906 903
@@ -913,53 +910,53 @@ GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh,
913 * @param ev queued envelope to cancel 910 * @param ev queued envelope to cancel
914 */ 911 */
915void 912void
916GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) 913GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
917{ 914{
918 struct GNUNET_MQ_Handle *mq = ev->parent_queue; 915 struct GNUNET_MQ_Handle *mq = ev->parent_queue;
919 916
920 GNUNET_assert (NULL != mq); 917 GNUNET_assert(NULL != mq);
921 GNUNET_assert (NULL != mq->cancel_impl); 918 GNUNET_assert(NULL != mq->cancel_impl);
922 919
923 mq->evacuate_called = GNUNET_NO; 920 mq->evacuate_called = GNUNET_NO;
924 921
925 if (mq->current_envelope == ev) 922 if (mq->current_envelope == ev)
926 {
927 /* complex case, we already started with transmitting
928 the message using the callbacks. */
929 GNUNET_assert (GNUNET_NO == mq->in_flight);
930 GNUNET_assert (0 < mq->queue_length);
931 mq->queue_length--;
932 mq->cancel_impl (mq, mq->impl_state);
933 /* continue sending the next message, if any */
934 mq->current_envelope = mq->envelope_head;
935 if (NULL != mq->current_envelope)
936 { 923 {
937 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 924 /* complex case, we already started with transmitting
938 mq->envelope_tail, 925 the message using the callbacks. */
939 mq->current_envelope); 926 GNUNET_assert(GNUNET_NO == mq->in_flight);
940 927 GNUNET_assert(0 < mq->queue_length);
941 LOG (GNUNET_ERROR_TYPE_DEBUG, 928 mq->queue_length--;
942 "sending canceled message of type %u queue\n", 929 mq->cancel_impl(mq, mq->impl_state);
943 ntohs (ev->mh->type)); 930 /* continue sending the next message, if any */
944 931 mq->current_envelope = mq->envelope_head;
945 mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state); 932 if (NULL != mq->current_envelope)
933 {
934 GNUNET_CONTAINER_DLL_remove(mq->envelope_head,
935 mq->envelope_tail,
936 mq->current_envelope);
937
938 LOG(GNUNET_ERROR_TYPE_DEBUG,
939 "sending canceled message of type %u queue\n",
940 ntohs(ev->mh->type));
941
942 mq->send_impl(mq, mq->current_envelope->mh, mq->impl_state);
943 }
946 } 944 }
947 }
948 else 945 else
949 { 946 {
950 /* simple case, message is still waiting in the queue */ 947 /* simple case, message is still waiting in the queue */
951 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev); 948 GNUNET_CONTAINER_DLL_remove(mq->envelope_head, mq->envelope_tail, ev);
952 GNUNET_assert (0 < mq->queue_length); 949 GNUNET_assert(0 < mq->queue_length);
953 mq->queue_length--; 950 mq->queue_length--;
954 } 951 }
955 952
956 if (GNUNET_YES != mq->evacuate_called) 953 if (GNUNET_YES != mq->evacuate_called)
957 { 954 {
958 ev->parent_queue = NULL; 955 ev->parent_queue = NULL;
959 ev->mh = NULL; 956 ev->mh = NULL;
960 /* also frees ev */ 957 /* also frees ev */
961 GNUNET_free (ev); 958 GNUNET_free(ev);
962 } 959 }
963} 960}
964 961
965 962
@@ -971,7 +968,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
971 * @return the current envelope 968 * @return the current envelope
972 */ 969 */
973struct GNUNET_MQ_Envelope * 970struct GNUNET_MQ_Envelope *
974GNUNET_MQ_get_current_envelope (struct GNUNET_MQ_Handle *mq) 971GNUNET_MQ_get_current_envelope(struct GNUNET_MQ_Handle *mq)
975{ 972{
976 return mq->current_envelope; 973 return mq->current_envelope;
977} 974}
@@ -984,7 +981,7 @@ GNUNET_MQ_get_current_envelope (struct GNUNET_MQ_Handle *mq)
984 * @return the last envelope in the queue 981 * @return the last envelope in the queue
985 */ 982 */
986struct GNUNET_MQ_Envelope * 983struct GNUNET_MQ_Envelope *
987GNUNET_MQ_get_last_envelope (struct GNUNET_MQ_Handle *mq) 984GNUNET_MQ_get_last_envelope(struct GNUNET_MQ_Handle *mq)
988{ 985{
989 if (NULL != mq->envelope_tail) 986 if (NULL != mq->envelope_tail)
990 return mq->envelope_tail; 987 return mq->envelope_tail;
@@ -1002,8 +999,8 @@ GNUNET_MQ_get_last_envelope (struct GNUNET_MQ_Handle *mq)
1002 * @param pp priorities and preferences to apply 999 * @param pp priorities and preferences to apply
1003 */ 1000 */
1004void 1001void
1005GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env, 1002GNUNET_MQ_env_set_options(struct GNUNET_MQ_Envelope *env,
1006 enum GNUNET_MQ_PriorityPreferences pp) 1003 enum GNUNET_MQ_PriorityPreferences pp)
1007{ 1004{
1008 env->priority = pp; 1005 env->priority = pp;
1009 env->have_custom_options = GNUNET_YES; 1006 env->have_custom_options = GNUNET_YES;
@@ -1017,7 +1014,7 @@ GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env,
1017 * @return priorities and preferences to apply for @a env 1014 * @return priorities and preferences to apply for @a env
1018 */ 1015 */
1019enum GNUNET_MQ_PriorityPreferences 1016enum GNUNET_MQ_PriorityPreferences
1020GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env) 1017GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
1021{ 1018{
1022 struct GNUNET_MQ_Handle *mq = env->parent_queue; 1019 struct GNUNET_MQ_Handle *mq = env->parent_queue;
1023 1020
@@ -1038,12 +1035,12 @@ GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env)
1038 * @return combined priority and preferences to use 1035 * @return combined priority and preferences to use
1039 */ 1036 */
1040enum GNUNET_MQ_PriorityPreferences 1037enum GNUNET_MQ_PriorityPreferences
1041GNUNET_MQ_env_combine_options (enum GNUNET_MQ_PriorityPreferences p1, 1038GNUNET_MQ_env_combine_options(enum GNUNET_MQ_PriorityPreferences p1,
1042 enum GNUNET_MQ_PriorityPreferences p2) 1039 enum GNUNET_MQ_PriorityPreferences p2)
1043{ 1040{
1044 enum GNUNET_MQ_PriorityPreferences ret; 1041 enum GNUNET_MQ_PriorityPreferences ret;
1045 1042
1046 ret = GNUNET_MAX (p1 & GNUNET_MQ_PRIORITY_MASK, p2 & GNUNET_MQ_PRIORITY_MASK); 1043 ret = GNUNET_MAX(p1 & GNUNET_MQ_PRIORITY_MASK, p2 & GNUNET_MQ_PRIORITY_MASK);
1047 ret |= ((p1 & GNUNET_MQ_PREF_UNRELIABLE) & (p2 & GNUNET_MQ_PREF_UNRELIABLE)); 1044 ret |= ((p1 & GNUNET_MQ_PREF_UNRELIABLE) & (p2 & GNUNET_MQ_PREF_UNRELIABLE));
1048 ret |= 1045 ret |=
1049 ((p1 & GNUNET_MQ_PREF_LOW_LATENCY) | (p2 & GNUNET_MQ_PREF_LOW_LATENCY)); 1046 ((p1 & GNUNET_MQ_PREF_LOW_LATENCY) | (p2 & GNUNET_MQ_PREF_LOW_LATENCY));
@@ -1063,8 +1060,8 @@ GNUNET_MQ_env_combine_options (enum GNUNET_MQ_PriorityPreferences p1,
1063 * @param pp priorities and preferences to apply 1060 * @param pp priorities and preferences to apply
1064 */ 1061 */
1065void 1062void
1066GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq, 1063GNUNET_MQ_set_options(struct GNUNET_MQ_Handle *mq,
1067 enum GNUNET_MQ_PriorityPreferences pp) 1064 enum GNUNET_MQ_PriorityPreferences pp)
1068{ 1065{
1069 mq->priority = pp; 1066 mq->priority = pp;
1070} 1067}
@@ -1077,7 +1074,7 @@ GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
1077 * @return message contained in the envelope 1074 * @return message contained in the envelope
1078 */ 1075 */
1079const struct GNUNET_MessageHeader * 1076const struct GNUNET_MessageHeader *
1080GNUNET_MQ_env_get_msg (const struct GNUNET_MQ_Envelope *env) 1077GNUNET_MQ_env_get_msg(const struct GNUNET_MQ_Envelope *env)
1081{ 1078{
1082 return env->mh; 1079 return env->mh;
1083} 1080}
@@ -1090,7 +1087,7 @@ GNUNET_MQ_env_get_msg (const struct GNUNET_MQ_Envelope *env)
1090 * @return next one, or NULL 1087 * @return next one, or NULL
1091 */ 1088 */
1092const struct GNUNET_MQ_Envelope * 1089const struct GNUNET_MQ_Envelope *
1093GNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env) 1090GNUNET_MQ_env_next(const struct GNUNET_MQ_Envelope *env)
1094{ 1091{
1095 return env->next; 1092 return env->next;
1096} 1093}
@@ -1106,17 +1103,17 @@ GNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env)
1106 * @return handle for #GNUNET_MQ_destroy_notify_cancel(). 1103 * @return handle for #GNUNET_MQ_destroy_notify_cancel().
1107 */ 1104 */
1108struct GNUNET_MQ_DestroyNotificationHandle * 1105struct GNUNET_MQ_DestroyNotificationHandle *
1109GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq, 1106GNUNET_MQ_destroy_notify(struct GNUNET_MQ_Handle *mq,
1110 GNUNET_SCHEDULER_TaskCallback cb, 1107 GNUNET_SCHEDULER_TaskCallback cb,
1111 void *cb_cls) 1108 void *cb_cls)
1112{ 1109{
1113 struct GNUNET_MQ_DestroyNotificationHandle *dnh; 1110 struct GNUNET_MQ_DestroyNotificationHandle *dnh;
1114 1111
1115 dnh = GNUNET_new (struct GNUNET_MQ_DestroyNotificationHandle); 1112 dnh = GNUNET_new(struct GNUNET_MQ_DestroyNotificationHandle);
1116 dnh->mq = mq; 1113 dnh->mq = mq;
1117 dnh->cb = cb; 1114 dnh->cb = cb;
1118 dnh->cb_cls = cb_cls; 1115 dnh->cb_cls = cb_cls;
1119 GNUNET_CONTAINER_DLL_insert (mq->dnh_head, mq->dnh_tail, dnh); 1116 GNUNET_CONTAINER_DLL_insert(mq->dnh_head, mq->dnh_tail, dnh);
1120 return dnh; 1117 return dnh;
1121} 1118}
1122 1119
@@ -1127,13 +1124,13 @@ GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
1127 * @param dnh handle for registration to cancel 1124 * @param dnh handle for registration to cancel
1128 */ 1125 */
1129void 1126void
1130GNUNET_MQ_destroy_notify_cancel ( 1127GNUNET_MQ_destroy_notify_cancel(
1131 struct GNUNET_MQ_DestroyNotificationHandle *dnh) 1128 struct GNUNET_MQ_DestroyNotificationHandle *dnh)
1132{ 1129{
1133 struct GNUNET_MQ_Handle *mq = dnh->mq; 1130 struct GNUNET_MQ_Handle *mq = dnh->mq;
1134 1131
1135 GNUNET_CONTAINER_DLL_remove (mq->dnh_head, mq->dnh_tail, dnh); 1132 GNUNET_CONTAINER_DLL_remove(mq->dnh_head, mq->dnh_tail, dnh);
1136 GNUNET_free (dnh); 1133 GNUNET_free(dnh);
1137} 1134}
1138 1135
1139 1136
@@ -1150,12 +1147,11 @@ GNUNET_MQ_destroy_notify_cancel (
1150 * @param[in|out] env element to insert at the tail 1147 * @param[in|out] env element to insert at the tail
1151 */ 1148 */
1152void 1149void
1153GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head, 1150GNUNET_MQ_dll_insert_head(struct GNUNET_MQ_Envelope **env_head,
1154 struct GNUNET_MQ_Envelope **env_tail, 1151 struct GNUNET_MQ_Envelope **env_tail,
1155 struct GNUNET_MQ_Envelope *env) 1152 struct GNUNET_MQ_Envelope *env)
1156{ 1153{
1157 1154 GNUNET_CONTAINER_DLL_insert(*env_head, *env_tail, env);
1158 GNUNET_CONTAINER_DLL_insert (*env_head, *env_tail, env);
1159} 1155}
1160 1156
1161 1157
@@ -1172,11 +1168,11 @@ GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head,
1172 * @param[in|out] env element to insert at the tail 1168 * @param[in|out] env element to insert at the tail
1173 */ 1169 */
1174void 1170void
1175GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head, 1171GNUNET_MQ_dll_insert_tail(struct GNUNET_MQ_Envelope **env_head,
1176 struct GNUNET_MQ_Envelope **env_tail, 1172 struct GNUNET_MQ_Envelope **env_tail,
1177 struct GNUNET_MQ_Envelope *env) 1173 struct GNUNET_MQ_Envelope *env)
1178{ 1174{
1179 GNUNET_CONTAINER_DLL_insert_tail (*env_head, *env_tail, env); 1175 GNUNET_CONTAINER_DLL_insert_tail(*env_head, *env_tail, env);
1180} 1176}
1181 1177
1182 1178
@@ -1193,11 +1189,11 @@ GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
1193 * @param[in|out] env element to remove from the DLL 1189 * @param[in|out] env element to remove from the DLL
1194 */ 1190 */
1195void 1191void
1196GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head, 1192GNUNET_MQ_dll_remove(struct GNUNET_MQ_Envelope **env_head,
1197 struct GNUNET_MQ_Envelope **env_tail, 1193 struct GNUNET_MQ_Envelope **env_tail,
1198 struct GNUNET_MQ_Envelope *env) 1194 struct GNUNET_MQ_Envelope *env)
1199{ 1195{
1200 GNUNET_CONTAINER_DLL_remove (*env_head, *env_tail, env); 1196 GNUNET_CONTAINER_DLL_remove(*env_head, *env_tail, env);
1201} 1197}
1202 1198
1203 1199
@@ -1212,7 +1208,7 @@ GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head,
1212 * Needs to be freed with #GNUNET_free. 1208 * Needs to be freed with #GNUNET_free.
1213 */ 1209 */
1214struct GNUNET_MQ_MessageHandler * 1210struct GNUNET_MQ_MessageHandler *
1215GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers) 1211GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
1216{ 1212{
1217 struct GNUNET_MQ_MessageHandler *copy; 1213 struct GNUNET_MQ_MessageHandler *copy;
1218 unsigned int count; 1214 unsigned int count;
@@ -1220,11 +1216,11 @@ GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
1220 if (NULL == handlers) 1216 if (NULL == handlers)
1221 return NULL; 1217 return NULL;
1222 1218
1223 count = GNUNET_MQ_count_handlers (handlers); 1219 count = GNUNET_MQ_count_handlers(handlers);
1224 copy = GNUNET_new_array (count + 1, struct GNUNET_MQ_MessageHandler); 1220 copy = GNUNET_new_array(count + 1, struct GNUNET_MQ_MessageHandler);
1225 GNUNET_memcpy (copy, 1221 GNUNET_memcpy(copy,
1226 handlers, 1222 handlers,
1227 count * sizeof (struct GNUNET_MQ_MessageHandler)); 1223 count * sizeof(struct GNUNET_MQ_MessageHandler));
1228 return copy; 1224 return copy;
1229} 1225}
1230 1226
@@ -1242,25 +1238,25 @@ GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
1242 * Needs to be freed with #GNUNET_free. 1238 * Needs to be freed with #GNUNET_free.
1243 */ 1239 */
1244struct GNUNET_MQ_MessageHandler * 1240struct GNUNET_MQ_MessageHandler *
1245GNUNET_MQ_copy_handlers2 (const struct GNUNET_MQ_MessageHandler *handlers, 1241GNUNET_MQ_copy_handlers2(const struct GNUNET_MQ_MessageHandler *handlers,
1246 GNUNET_MQ_MessageCallback agpl_handler, 1242 GNUNET_MQ_MessageCallback agpl_handler,
1247 void *agpl_cls) 1243 void *agpl_cls)
1248{ 1244{
1249 struct GNUNET_MQ_MessageHandler *copy; 1245 struct GNUNET_MQ_MessageHandler *copy;
1250 unsigned int count; 1246 unsigned int count;
1251 1247
1252 if (NULL == handlers) 1248 if (NULL == handlers)
1253 return NULL; 1249 return NULL;
1254 count = GNUNET_MQ_count_handlers (handlers); 1250 count = GNUNET_MQ_count_handlers(handlers);
1255 copy = GNUNET_new_array (count + 2, struct GNUNET_MQ_MessageHandler); 1251 copy = GNUNET_new_array(count + 2, struct GNUNET_MQ_MessageHandler);
1256 GNUNET_memcpy (copy, 1252 GNUNET_memcpy(copy,
1257 handlers, 1253 handlers,
1258 count * sizeof (struct GNUNET_MQ_MessageHandler)); 1254 count * sizeof(struct GNUNET_MQ_MessageHandler));
1259 copy[count].mv = NULL; 1255 copy[count].mv = NULL;
1260 copy[count].cb = agpl_handler; 1256 copy[count].cb = agpl_handler;
1261 copy[count].cls = agpl_cls; 1257 copy[count].cls = agpl_cls;
1262 copy[count].type = GNUNET_MESSAGE_TYPE_REQUEST_AGPL; 1258 copy[count].type = GNUNET_MESSAGE_TYPE_REQUEST_AGPL;
1263 copy[count].expected_size = sizeof (struct GNUNET_MessageHeader); 1259 copy[count].expected_size = sizeof(struct GNUNET_MessageHeader);
1264 return copy; 1260 return copy;
1265} 1261}
1266 1262
@@ -1272,7 +1268,7 @@ GNUNET_MQ_copy_handlers2 (const struct GNUNET_MQ_MessageHandler *handlers,
1272 * @return The number of handlers in the array. 1268 * @return The number of handlers in the array.
1273 */ 1269 */
1274unsigned int 1270unsigned int
1275GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers) 1271GNUNET_MQ_count_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
1276{ 1272{
1277 unsigned int i; 1273 unsigned int i;
1278 1274
@@ -1293,19 +1289,23 @@ GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
1293 * @return a string or NULL if invalid 1289 * @return a string or NULL if invalid
1294 */ 1290 */
1295const char * 1291const char *
1296GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type) 1292GNUNET_MQ_preference_to_string(enum GNUNET_MQ_PreferenceKind type)
1297{ 1293{
1298 switch (type) 1294 switch (type)
1299 { 1295 {
1300 case GNUNET_MQ_PREFERENCE_NONE: 1296 case GNUNET_MQ_PREFERENCE_NONE:
1301 return "NONE"; 1297 return "NONE";
1302 case GNUNET_MQ_PREFERENCE_BANDWIDTH: 1298
1303 return "BANDWIDTH"; 1299 case GNUNET_MQ_PREFERENCE_BANDWIDTH:
1304 case GNUNET_MQ_PREFERENCE_LATENCY: 1300 return "BANDWIDTH";
1305 return "LATENCY"; 1301
1306 case GNUNET_MQ_PREFERENCE_RELIABILITY: 1302 case GNUNET_MQ_PREFERENCE_LATENCY:
1307 return "RELIABILITY"; 1303 return "LATENCY";
1308 }; 1304
1305 case GNUNET_MQ_PREFERENCE_RELIABILITY:
1306 return "RELIABILITY";
1307 }
1308 ;
1309 return NULL; 1309 return NULL;
1310} 1310}
1311 1311