diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-06-03 10:53:49 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-06-03 10:53:49 +0000 |
commit | 68403fa780bf94ace2ebc13c2c09463cbbc0b57c (patch) | |
tree | 3442e4f25de90eab67c4f9813cb6e433c50b7482 /src/util/mq.c | |
parent | fae7f583f2e11cac15fefcbefef64287ab6915d3 (diff) | |
download | gnunet-68403fa780bf94ace2ebc13c2c09463cbbc0b57c.tar.gz gnunet-68403fa780bf94ace2ebc13c2c09463cbbc0b57c.zip |
- conclude for SET
- consensus with SET
Diffstat (limited to 'src/util/mq.c')
-rw-r--r-- | src/util/mq.c | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/src/util/mq.c b/src/util/mq.c index 36cacd30b..dc87b9711 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -119,33 +119,31 @@ GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type) | |||
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | int | 122 | struct GNUNET_MQ_Message * |
123 | GNUNET_MQ_nest_ (struct GNUNET_MQ_Message **mqmp, | 123 | GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp, uint16_t base_size, uint16_t type, |
124 | const void *data, uint16_t len) | 124 | const struct GNUNET_MessageHeader *nested_mh) |
125 | { | 125 | { |
126 | size_t new_size; | 126 | struct GNUNET_MQ_Message *mqm; |
127 | size_t old_size; | 127 | uint16_t size; |
128 | 128 | ||
129 | GNUNET_assert (NULL != mqmp); | 129 | if (NULL == nested_mh) |
130 | /* there's no data to append => do nothing */ | 130 | return GNUNET_MQ_msg_ (mhp, base_size, type); |
131 | if (NULL == data) | ||
132 | return GNUNET_OK; | ||
133 | old_size = ntohs ((*mqmp)->mh->size); | ||
134 | /* message too large to concatenate? */ | ||
135 | if (((uint16_t) (old_size + len)) < len) | ||
136 | return GNUNET_SYSERR; | ||
137 | new_size = old_size + len; | ||
138 | *mqmp = GNUNET_realloc (*mqmp, sizeof (struct GNUNET_MQ_Message) + new_size); | ||
139 | (*mqmp)->mh = (struct GNUNET_MessageHeader *) &(*mqmp)[1]; | ||
140 | memcpy (((void *) (*mqmp)->mh) + old_size, data, new_size - old_size); | ||
141 | (*mqmp)->mh->size = htons (new_size); | ||
142 | return GNUNET_OK; | ||
143 | } | ||
144 | 131 | ||
132 | size = base_size + ntohs (nested_mh->size); | ||
145 | 133 | ||
134 | /* check for uint16_t overflow */ | ||
135 | if (size < base_size) | ||
136 | return NULL; | ||
137 | |||
138 | mqm = GNUNET_MQ_msg_ (mhp, size, type); | ||
139 | memcpy ((char *) mqm->mh + base_size, nested_mh, ntohs (nested_mh->size)); | ||
140 | |||
141 | return mqm; | ||
142 | } | ||
146 | 143 | ||
147 | 144 | ||
148 | /*** Transmit a queued message to the session's client. | 145 | /** |
146 | * Transmit a queued message to the session's client. | ||
149 | * | 147 | * |
150 | * @param cls consensus session | 148 | * @param cls consensus session |
151 | * @param size number of bytes available in buf | 149 | * @param size number of bytes available in buf |
@@ -265,7 +263,8 @@ handle_client_message (void *cls, | |||
265 | { | 263 | { |
266 | if (NULL == mq->error_handler) | 264 | if (NULL == mq->error_handler) |
267 | LOG (GNUNET_ERROR_TYPE_WARNING, "ignoring read error (no handler installed)\n"); | 265 | LOG (GNUNET_ERROR_TYPE_WARNING, "ignoring read error (no handler installed)\n"); |
268 | mq->error_handler (mq->handlers_cls, GNUNET_MQ_ERROR_READ); | 266 | else |
267 | mq->error_handler (mq->handlers_cls, GNUNET_MQ_ERROR_READ); | ||
269 | return; | 268 | return; |
270 | } | 269 | } |
271 | 270 | ||
@@ -479,3 +478,39 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_MessageQueue *mq) | |||
479 | GNUNET_free (mq); | 478 | GNUNET_free (mq); |
480 | } | 479 | } |
481 | 480 | ||
481 | |||
482 | |||
483 | |||
484 | struct GNUNET_MessageHeader * | ||
485 | GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh, uint16_t base_size) | ||
486 | { | ||
487 | uint16_t whole_size; | ||
488 | uint16_t nested_size; | ||
489 | struct GNUNET_MessageHeader *nested_msg; | ||
490 | |||
491 | whole_size = ntohs (mh->size); | ||
492 | GNUNET_assert (whole_size >= base_size); | ||
493 | |||
494 | nested_size = whole_size - base_size; | ||
495 | |||
496 | if (0 == nested_size) | ||
497 | return NULL; | ||
498 | |||
499 | if (nested_size < sizeof (struct GNUNET_MessageHeader)) | ||
500 | { | ||
501 | GNUNET_break_op (0); | ||
502 | return NULL; | ||
503 | } | ||
504 | |||
505 | nested_msg = (struct GNUNET_MessageHeader *) ((char *) mh + base_size); | ||
506 | |||
507 | if (ntohs (nested_msg->size) != nested_size) | ||
508 | { | ||
509 | GNUNET_break_op (0); | ||
510 | nested_msg->size = htons (nested_size); | ||
511 | } | ||
512 | |||
513 | return nested_msg; | ||
514 | } | ||
515 | |||
516 | |||