diff options
Diffstat (limited to 'src/psycutil/psyc_slicer.c')
-rw-r--r-- | src/psycutil/psyc_slicer.c | 95 |
1 files changed, 49 insertions, 46 deletions
diff --git a/src/psycutil/psyc_slicer.c b/src/psycutil/psyc_slicer.c index 735eb1511..a9c96ff04 100644 --- a/src/psycutil/psyc_slicer.c +++ b/src/psycutil/psyc_slicer.c | |||
@@ -55,9 +55,14 @@ struct GNUNET_PSYC_Slicer | |||
55 | struct GNUNET_PSYC_ReceiveHandle *recv; | 55 | struct GNUNET_PSYC_ReceiveHandle *recv; |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Currently being processed message. | ||
59 | */ | ||
60 | const struct GNUNET_PSYC_MessageHeader *msg; | ||
61 | |||
62 | /** | ||
58 | * Currently being processed message part. | 63 | * Currently being processed message part. |
59 | */ | 64 | */ |
60 | const struct GNUNET_MessageHeader *msg; | 65 | const struct GNUNET_MessageHeader *pmsg; |
61 | 66 | ||
62 | /** | 67 | /** |
63 | * ID of currently being received message. | 68 | * ID of currently being received message. |
@@ -131,6 +136,7 @@ struct GNUNET_PSYC_Slicer | |||
131 | */ | 136 | */ |
132 | struct SlicerMethodCallbacks | 137 | struct SlicerMethodCallbacks |
133 | { | 138 | { |
139 | GNUNET_PSYC_MessageCallback msg_cb; | ||
134 | GNUNET_PSYC_MethodCallback method_cb; | 140 | GNUNET_PSYC_MethodCallback method_cb; |
135 | GNUNET_PSYC_ModifierCallback modifier_cb; | 141 | GNUNET_PSYC_ModifierCallback modifier_cb; |
136 | GNUNET_PSYC_DataCallback data_cb; | 142 | GNUNET_PSYC_DataCallback data_cb; |
@@ -171,22 +177,21 @@ slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key, | |||
171 | void *value) | 177 | void *value) |
172 | { | 178 | { |
173 | struct GNUNET_PSYC_Slicer *slicer = cls; | 179 | struct GNUNET_PSYC_Slicer *slicer = cls; |
174 | const struct GNUNET_MessageHeader *msg = slicer->msg; | 180 | const struct GNUNET_MessageHeader *pmsg = slicer->pmsg; |
175 | struct SlicerMethodCallbacks *cbs = value; | 181 | struct SlicerMethodCallbacks *cbs = value; |
176 | uint16_t ptype = ntohs (msg->type); | ||
177 | 182 | ||
183 | uint16_t ptype = ntohs (pmsg->type); | ||
178 | switch (ptype) | 184 | switch (ptype) |
179 | { | 185 | { |
180 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD: | 186 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD: |
181 | { | 187 | { |
188 | if (NULL != cbs->msg_cb) | ||
189 | cbs->msg_cb (cbs->cls, slicer->msg); | ||
182 | if (NULL == cbs->method_cb) | 190 | if (NULL == cbs->method_cb) |
183 | break; | 191 | break; |
184 | struct GNUNET_PSYC_MessageMethod * | 192 | struct GNUNET_PSYC_MessageMethod * |
185 | meth = (struct GNUNET_PSYC_MessageMethod *) msg; | 193 | meth = (struct GNUNET_PSYC_MessageMethod *) pmsg; |
186 | cbs->method_cb (cbs->cls, meth, slicer->message_id, | 194 | cbs->method_cb (cbs->cls, slicer->msg, meth, slicer->message_id, |
187 | slicer->flags, slicer->fragment_offset, | ||
188 | ntohl (meth->flags), | ||
189 | &slicer->nym_pub_key, | ||
190 | slicer->method_name); | 195 | slicer->method_name); |
191 | break; | 196 | break; |
192 | } | 197 | } |
@@ -196,9 +201,8 @@ slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key, | |||
196 | if (NULL == cbs->modifier_cb) | 201 | if (NULL == cbs->modifier_cb) |
197 | break; | 202 | break; |
198 | struct GNUNET_PSYC_MessageModifier * | 203 | struct GNUNET_PSYC_MessageModifier * |
199 | mod = (struct GNUNET_PSYC_MessageModifier *) msg; | 204 | mod = (struct GNUNET_PSYC_MessageModifier *) pmsg; |
200 | cbs->modifier_cb (cbs->cls, &mod->header, slicer->message_id, | 205 | cbs->modifier_cb (cbs->cls, slicer->msg, &mod->header, slicer->message_id, |
201 | slicer->flags, slicer->fragment_offset, | ||
202 | mod->oper, (const char *) &mod[1], | 206 | mod->oper, (const char *) &mod[1], |
203 | (const void *) &mod[1] + ntohs (mod->name_size), | 207 | (const void *) &mod[1] + ntohs (mod->name_size), |
204 | ntohs (mod->header.size) - sizeof (*mod) - ntohs (mod->name_size), | 208 | ntohs (mod->header.size) - sizeof (*mod) - ntohs (mod->name_size), |
@@ -210,10 +214,9 @@ slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key, | |||
210 | { | 214 | { |
211 | if (NULL == cbs->modifier_cb) | 215 | if (NULL == cbs->modifier_cb) |
212 | break; | 216 | break; |
213 | cbs->modifier_cb (cbs->cls, msg, slicer->message_id, | 217 | cbs->modifier_cb (cbs->cls, slicer->msg, pmsg, slicer->message_id, |
214 | slicer->flags, slicer->fragment_offset, | 218 | slicer->mod_oper, slicer->mod_name, &pmsg[1], |
215 | slicer->mod_oper, slicer->mod_name, &msg[1], | 219 | ntohs (pmsg->size) - sizeof (*pmsg), |
216 | ntohs (msg->size) - sizeof (*msg), | ||
217 | slicer->mod_full_value_size); | 220 | slicer->mod_full_value_size); |
218 | break; | 221 | break; |
219 | } | 222 | } |
@@ -222,24 +225,21 @@ slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key, | |||
222 | { | 225 | { |
223 | if (NULL == cbs->data_cb) | 226 | if (NULL == cbs->data_cb) |
224 | break; | 227 | break; |
225 | cbs->data_cb (cbs->cls, msg, slicer->message_id, | 228 | cbs->data_cb (cbs->cls, slicer->msg, pmsg, slicer->message_id, |
226 | slicer->flags, slicer->fragment_offset, | 229 | &pmsg[1], ntohs (pmsg->size) - sizeof (*pmsg)); |
227 | &msg[1], ntohs (msg->size) - sizeof (*msg)); | ||
228 | break; | 230 | break; |
229 | } | 231 | } |
230 | 232 | ||
231 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END: | 233 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END: |
232 | if (NULL == cbs->eom_cb) | 234 | if (NULL == cbs->eom_cb) |
233 | break; | 235 | break; |
234 | cbs->eom_cb (cbs->cls, msg, slicer->message_id, | 236 | cbs->eom_cb (cbs->cls, slicer->msg, pmsg, slicer->message_id, GNUNET_NO); |
235 | slicer->flags, slicer->fragment_offset, GNUNET_NO); | ||
236 | break; | 237 | break; |
237 | 238 | ||
238 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL: | 239 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL: |
239 | if (NULL == cbs->eom_cb) | 240 | if (NULL == cbs->eom_cb) |
240 | break; | 241 | break; |
241 | cbs->eom_cb (cbs->cls, msg, slicer->message_id, | 242 | cbs->eom_cb (cbs->cls, slicer->msg, pmsg, slicer->message_id, GNUNET_YES); |
242 | slicer->flags, slicer->fragment_offset, GNUNET_YES); | ||
243 | break; | 243 | break; |
244 | } | 244 | } |
245 | return GNUNET_YES; | 245 | return GNUNET_YES; |
@@ -256,8 +256,7 @@ slicer_modifier_handler_notify (void *cls, const struct GNUNET_HashCode *key, | |||
256 | struct GNUNET_PSYC_Slicer *slicer = cls; | 256 | struct GNUNET_PSYC_Slicer *slicer = cls; |
257 | struct SlicerModifierCallbacks *cbs = value; | 257 | struct SlicerModifierCallbacks *cbs = value; |
258 | 258 | ||
259 | cbs->modifier_cb (cbs->cls, slicer->msg, | 259 | cbs->modifier_cb (cbs->cls, slicer->msg, slicer->pmsg, slicer->message_id, |
260 | slicer->message_id, slicer->flags, slicer->fragment_offset, | ||
261 | slicer->mod_oper, slicer->mod_name, slicer->mod_value, | 260 | slicer->mod_oper, slicer->mod_name, slicer->mod_value, |
262 | slicer->mod_value_size, slicer->mod_full_value_size); | 261 | slicer->mod_value_size, slicer->mod_full_value_size); |
263 | return GNUNET_YES; | 262 | return GNUNET_YES; |
@@ -295,40 +294,36 @@ GNUNET_PSYC_slicer_message (struct GNUNET_PSYC_Slicer *slicer, | |||
295 | */ | 294 | */ |
296 | void | 295 | void |
297 | GNUNET_PSYC_slicer_message_part (struct GNUNET_PSYC_Slicer *slicer, | 296 | GNUNET_PSYC_slicer_message_part (struct GNUNET_PSYC_Slicer *slicer, |
298 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_pub_key, | 297 | const struct GNUNET_PSYC_MessageHeader *msg, |
299 | uint64_t message_id, | 298 | const struct GNUNET_MessageHeader *pmsg) |
300 | uint32_t flags, | ||
301 | uint64_t fragment_offset, | ||
302 | const struct GNUNET_MessageHeader *msg) | ||
303 | { | 299 | { |
304 | slicer->nym_pub_key = *slave_pub_key; | 300 | slicer->msg = msg; |
301 | slicer->pmsg = pmsg; | ||
305 | 302 | ||
306 | uint16_t ptype = ntohs (msg->type); | 303 | uint64_t message_id = GNUNET_ntohll (msg->message_id); |
304 | |||
305 | uint16_t ptype = ntohs (pmsg->type); | ||
307 | if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == ptype) | 306 | if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == ptype) |
308 | { | 307 | { |
309 | struct GNUNET_PSYC_MessageMethod * | 308 | struct GNUNET_PSYC_MessageMethod * |
310 | meth = (struct GNUNET_PSYC_MessageMethod *) msg; | 309 | meth = (struct GNUNET_PSYC_MessageMethod *) pmsg; |
311 | slicer->method_name_size = ntohs (meth->header.size) - sizeof (*meth); | 310 | slicer->method_name_size = ntohs (meth->header.size) - sizeof (*meth); |
312 | slicer->method_name = GNUNET_malloc (slicer->method_name_size); | 311 | slicer->method_name = GNUNET_malloc (slicer->method_name_size); |
313 | memcpy (slicer->method_name, &meth[1], slicer->method_name_size); | 312 | memcpy (slicer->method_name, &meth[1], slicer->method_name_size); |
314 | slicer->message_id = message_id; | 313 | slicer->message_id = message_id; |
315 | slicer->flags = flags; | ||
316 | slicer->fragment_offset = fragment_offset; | ||
317 | } | 314 | } |
318 | else | 315 | else |
319 | { | 316 | { |
320 | GNUNET_assert (message_id == slicer->message_id); | 317 | GNUNET_assert (message_id == slicer->message_id); |
321 | } | 318 | } |
322 | 319 | ||
323 | char *nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (slave_pub_key); | 320 | char *nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&msg->slave_pub_key); |
324 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 321 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
325 | "Slicer received message of type %u and size %u, " | 322 | "Slicer received message of type %u and size %u, " |
326 | "with ID %" PRIu64 " and method %s from %s\n", | 323 | "with ID %" PRIu64 " and method %s from %s\n", |
327 | ptype, ntohs (msg->size), message_id, slicer->method_name, nym_str); | 324 | ptype, ntohs (pmsg->size), message_id, slicer->method_name, nym_str); |
328 | GNUNET_free (nym_str); | 325 | GNUNET_free (nym_str); |
329 | 326 | ||
330 | slicer->msg = msg; | ||
331 | |||
332 | /* try-and-slice modifier */ | 327 | /* try-and-slice modifier */ |
333 | 328 | ||
334 | switch (ptype) | 329 | switch (ptype) |
@@ -336,7 +331,7 @@ GNUNET_PSYC_slicer_message_part (struct GNUNET_PSYC_Slicer *slicer, | |||
336 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER: | 331 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER: |
337 | { | 332 | { |
338 | struct GNUNET_PSYC_MessageModifier * | 333 | struct GNUNET_PSYC_MessageModifier * |
339 | mod = (struct GNUNET_PSYC_MessageModifier *) msg; | 334 | mod = (struct GNUNET_PSYC_MessageModifier *) pmsg; |
340 | slicer->mod_oper = mod->oper; | 335 | slicer->mod_oper = mod->oper; |
341 | slicer->mod_name_size = ntohs (mod->name_size); | 336 | slicer->mod_name_size = ntohs (mod->name_size); |
342 | slicer->mod_name = GNUNET_malloc (slicer->mod_name_size); | 337 | slicer->mod_name = GNUNET_malloc (slicer->mod_name_size); |
@@ -350,8 +345,8 @@ GNUNET_PSYC_slicer_message_part (struct GNUNET_PSYC_Slicer *slicer, | |||
350 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT: | 345 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT: |
351 | if (ptype == GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT) | 346 | if (ptype == GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT) |
352 | { | 347 | { |
353 | slicer->mod_value = (char *) &msg[1]; | 348 | slicer->mod_value = (char *) &pmsg[1]; |
354 | slicer->mod_value_size = ntohs (msg->size) - sizeof (*msg); | 349 | slicer->mod_value_size = ntohs (pmsg->size) - sizeof (*pmsg); |
355 | } | 350 | } |
356 | slicer->mod_value_remaining -= slicer->mod_value_size; | 351 | slicer->mod_value_remaining -= slicer->mod_value_size; |
357 | char *name = GNUNET_malloc (slicer->mod_name_size); | 352 | char *name = GNUNET_malloc (slicer->mod_name_size); |
@@ -405,6 +400,7 @@ GNUNET_PSYC_slicer_message_part (struct GNUNET_PSYC_Slicer *slicer, | |||
405 | } | 400 | } |
406 | 401 | ||
407 | slicer->msg = NULL; | 402 | slicer->msg = NULL; |
403 | slicer->pmsg = NULL; | ||
408 | } | 404 | } |
409 | 405 | ||
410 | 406 | ||
@@ -454,6 +450,7 @@ GNUNET_PSYC_slicer_create (void) | |||
454 | void | 450 | void |
455 | GNUNET_PSYC_slicer_method_add (struct GNUNET_PSYC_Slicer *slicer, | 451 | GNUNET_PSYC_slicer_method_add (struct GNUNET_PSYC_Slicer *slicer, |
456 | const char *method_name, | 452 | const char *method_name, |
453 | GNUNET_PSYC_MessageCallback msg_cb, | ||
457 | GNUNET_PSYC_MethodCallback method_cb, | 454 | GNUNET_PSYC_MethodCallback method_cb, |
458 | GNUNET_PSYC_ModifierCallback modifier_cb, | 455 | GNUNET_PSYC_ModifierCallback modifier_cb, |
459 | GNUNET_PSYC_DataCallback data_cb, | 456 | GNUNET_PSYC_DataCallback data_cb, |
@@ -464,6 +461,7 @@ GNUNET_PSYC_slicer_method_add (struct GNUNET_PSYC_Slicer *slicer, | |||
464 | GNUNET_CRYPTO_hash (method_name, strlen (method_name), &key); | 461 | GNUNET_CRYPTO_hash (method_name, strlen (method_name), &key); |
465 | 462 | ||
466 | struct SlicerMethodCallbacks *cbs = GNUNET_malloc (sizeof (*cbs)); | 463 | struct SlicerMethodCallbacks *cbs = GNUNET_malloc (sizeof (*cbs)); |
464 | cbs->msg_cb = msg_cb, | ||
467 | cbs->method_cb = method_cb; | 465 | cbs->method_cb = method_cb; |
468 | cbs->modifier_cb = modifier_cb; | 466 | cbs->modifier_cb = modifier_cb; |
469 | cbs->data_cb = data_cb; | 467 | cbs->data_cb = data_cb; |
@@ -483,10 +481,11 @@ slicer_method_remove (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
483 | struct SlicerMethodCallbacks *rm_cbs = &rm_cls->rm_cbs; | 481 | struct SlicerMethodCallbacks *rm_cbs = &rm_cls->rm_cbs; |
484 | struct SlicerMethodCallbacks *cbs = value; | 482 | struct SlicerMethodCallbacks *cbs = value; |
485 | 483 | ||
486 | if (cbs->method_cb == rm_cbs->method_cb | 484 | if ((NULL == rm_cbs->msg_cb || cbs->msg_cb == rm_cbs->msg_cb) |
487 | && cbs->modifier_cb == rm_cbs->modifier_cb | 485 | && (NULL == rm_cbs->method_cb || cbs->method_cb == rm_cbs->method_cb) |
488 | && cbs->data_cb == rm_cbs->data_cb | 486 | && (NULL == rm_cbs->modifier_cb || cbs->modifier_cb == rm_cbs->modifier_cb) |
489 | && cbs->eom_cb == rm_cbs->eom_cb) | 487 | && (NULL == rm_cbs->data_cb || cbs->data_cb == rm_cbs->data_cb) |
488 | && (NULL == rm_cbs->eom_cb || cbs->eom_cb == rm_cbs->eom_cb)) | ||
490 | { | 489 | { |
491 | GNUNET_CONTAINER_multihashmap_remove (slicer->method_handlers, key, cbs); | 490 | GNUNET_CONTAINER_multihashmap_remove (slicer->method_handlers, key, cbs); |
492 | GNUNET_free (cbs); | 491 | GNUNET_free (cbs); |
@@ -521,6 +520,7 @@ slicer_method_remove (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
521 | int | 520 | int |
522 | GNUNET_PSYC_slicer_method_remove (struct GNUNET_PSYC_Slicer *slicer, | 521 | GNUNET_PSYC_slicer_method_remove (struct GNUNET_PSYC_Slicer *slicer, |
523 | const char *method_name, | 522 | const char *method_name, |
523 | GNUNET_PSYC_MessageCallback msg_cb, | ||
524 | GNUNET_PSYC_MethodCallback method_cb, | 524 | GNUNET_PSYC_MethodCallback method_cb, |
525 | GNUNET_PSYC_ModifierCallback modifier_cb, | 525 | GNUNET_PSYC_ModifierCallback modifier_cb, |
526 | GNUNET_PSYC_DataCallback data_cb, | 526 | GNUNET_PSYC_DataCallback data_cb, |
@@ -532,6 +532,7 @@ GNUNET_PSYC_slicer_method_remove (struct GNUNET_PSYC_Slicer *slicer, | |||
532 | struct SlicerMethodRemoveClosure rm_cls; | 532 | struct SlicerMethodRemoveClosure rm_cls; |
533 | rm_cls.slicer = slicer; | 533 | rm_cls.slicer = slicer; |
534 | struct SlicerMethodCallbacks *rm_cbs = &rm_cls.rm_cbs; | 534 | struct SlicerMethodCallbacks *rm_cbs = &rm_cls.rm_cbs; |
535 | rm_cbs->msg_cb = msg_cb; | ||
535 | rm_cbs->method_cb = method_cb; | 536 | rm_cbs->method_cb = method_cb; |
536 | rm_cbs->modifier_cb = modifier_cb; | 537 | rm_cbs->modifier_cb = modifier_cb; |
537 | rm_cbs->data_cb = data_cb; | 538 | rm_cbs->data_cb = data_cb; |
@@ -659,6 +660,7 @@ GNUNET_PSYC_slicer_method_clear (struct GNUNET_PSYC_Slicer *slicer) | |||
659 | { | 660 | { |
660 | GNUNET_CONTAINER_multihashmap_iterate (slicer->method_handlers, | 661 | GNUNET_CONTAINER_multihashmap_iterate (slicer->method_handlers, |
661 | slicer_method_free, NULL); | 662 | slicer_method_free, NULL); |
663 | GNUNET_CONTAINER_multihashmap_clear (slicer->method_handlers); | ||
662 | } | 664 | } |
663 | 665 | ||
664 | 666 | ||
@@ -673,6 +675,7 @@ GNUNET_PSYC_slicer_modifier_clear (struct GNUNET_PSYC_Slicer *slicer) | |||
673 | { | 675 | { |
674 | GNUNET_CONTAINER_multihashmap_iterate (slicer->modifier_handlers, | 676 | GNUNET_CONTAINER_multihashmap_iterate (slicer->modifier_handlers, |
675 | slicer_modifier_free, NULL); | 677 | slicer_modifier_free, NULL); |
678 | GNUNET_CONTAINER_multihashmap_clear (slicer->modifier_handlers); | ||
676 | } | 679 | } |
677 | 680 | ||
678 | 681 | ||