- FragmentBMC *ctx = cls;
- static int idGen = 0;
- P2P_fragmentation_MESSAGE *frag;
- unsigned int pos;
- int id;
- unsigned short mlen;
-
- if ((len < ctx->mtu) || (buf == NULL))
- {
- GNUNET_free (ctx);
- return GNUNET_SYSERR;
- }
- if (stats != NULL)
- stats->change (stat_fragmented, 1);
- id = (idGen++) + GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 512);
- /* write first fragment to buf */
- frag = (P2P_fragmentation_MESSAGE *) buf;
- frag->header.size = htons (len);
- frag->header.type = htons (GNUNET_P2P_PROTO_MESSAGE_FRAGMENT);
- frag->id = id;
- frag->off = htons (0);
- frag->len = htons (ctx->len);
- memcpy (&frag[1], &ctx[1], len - sizeof (P2P_fragmentation_MESSAGE));
-
- /* create remaining fragments, add to queue! */
- pos = len - sizeof (P2P_fragmentation_MESSAGE);
- frag = GNUNET_malloc (ctx->mtu);
- while (pos < ctx->len)
- {
- mlen = sizeof (P2P_fragmentation_MESSAGE) + ctx->len - pos;
- if (mlen > ctx->mtu)
- mlen = ctx->mtu;
- GNUNET_GE_ASSERT (NULL, mlen > sizeof (P2P_fragmentation_MESSAGE));
- frag->header.size = htons (mlen);
- frag->header.type = htons (GNUNET_P2P_PROTO_MESSAGE_FRAGMENT);
- frag->id = id;
- frag->off = htons (pos);
- frag->len = htons (ctx->len);
- memcpy (&frag[1],
- &((char *) (&ctx[1]))[pos],
- mlen - sizeof (P2P_fragmentation_MESSAGE));
- coreAPI->ciphertext_send (&ctx->sender,
- &frag->header,
- GNUNET_EXTREME_PRIORITY,
- ctx->transmissionTime - GNUNET_get_time ());
- pos += mlen - sizeof (P2P_fragmentation_MESSAGE);
- }
- GNUNET_GE_ASSERT (NULL, pos == ctx->len);
- GNUNET_free (frag);
- GNUNET_free (ctx);
- return GNUNET_OK;
+ FragmentBMC *ctx = cls;
+ static int idGen = 0;
+ P2P_fragmentation_MESSAGE *frag;
+ unsigned int pos;
+ int id;
+ unsigned short mlen;
+
+ if ((len < ctx->mtu) || (buf == NULL))
+ {
+ GNUNET_free (ctx);
+ return GNUNET_SYSERR;
+ }
+ if (stats != NULL)
+ stats->change (stat_fragmented, 1);
+ id = (idGen++) + GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 512);
+ /* write first fragment to buf */
+ frag = (P2P_fragmentation_MESSAGE *) buf;
+ frag->header.size = htons (len);
+ frag->header.type = htons (GNUNET_P2P_PROTO_MESSAGE_FRAGMENT);
+ frag->id = id;
+ frag->off = htons (0);
+ frag->len = htons (ctx->len);
+ memcpy (&frag[1], &ctx[1], len - sizeof (P2P_fragmentation_MESSAGE));
+
+ /* create remaining fragments, add to queue! */
+ pos = len - sizeof (P2P_fragmentation_MESSAGE);
+ frag = GNUNET_malloc (ctx->mtu);
+ while (pos < ctx->len)
+ {
+ mlen = sizeof (P2P_fragmentation_MESSAGE) + ctx->len - pos;
+ if (mlen > ctx->mtu)
+ mlen = ctx->mtu;
+ GNUNET_GE_ASSERT (NULL, mlen > sizeof (P2P_fragmentation_MESSAGE));
+ frag->header.size = htons (mlen);
+ frag->header.type = htons (GNUNET_P2P_PROTO_MESSAGE_FRAGMENT);
+ frag->id = id;
+ frag->off = htons (pos);
+ frag->len = htons (ctx->len);
+ memcpy (&frag[1],
+ &((char *) (&ctx[1]))[pos],
+ mlen - sizeof (P2P_fragmentation_MESSAGE));
+ coreAPI->ciphertext_send (&ctx->sender,
+ &frag->header,
+ GNUNET_EXTREME_PRIORITY,
+ ctx->transmissionTime - GNUNET_get_time ());
+ pos += mlen - sizeof (P2P_fragmentation_MESSAGE);
+ }
+ GNUNET_GE_ASSERT (NULL, pos == ctx->len);
+ GNUNET_free (frag);
+ GNUNET_free (ctx);
+ return GNUNET_OK;