- ch = th->channel;
- if (GNUNET_YES == th_is_payload (th))
- {
- struct GNUNET_CADET_LocalData *dmsg;
- struct GNUNET_MessageHeader *mh;
-
- LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload\n");
- if (GNUNET_NO == ch->allow_send)
- {
- /* This channel is not ready to transmit yet, try next message */
- next = th->next;
- continue;
- }
- ch->packet_size = 0;
- GNUNET_assert (size >= th->size);
- dmsg = (struct GNUNET_CADET_LocalData *) cbuf;
- mh = (struct GNUNET_MessageHeader *) &dmsg[1];
- psize = th->notify (th->notify_cls,
- size - sizeof (struct GNUNET_CADET_LocalData),
- mh);
- if (psize > 0)
- {
- psize += sizeof (struct GNUNET_CADET_LocalData);
- GNUNET_assert (size >= psize);
- dmsg->header.size = htons (psize);
- dmsg->id = htonl (ch->chid);
- dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload type %s\n",
- GC_m2s (ntohs (mh->type)));
- ch->allow_send = GNUNET_NO;
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "# callback returned size 0, "
- "application canceled transmission\n");
- }
- }
- else
- {
- struct GNUNET_MessageHeader *mh = (struct GNUNET_MessageHeader *) &th[1];
-
- LOG (GNUNET_ERROR_TYPE_DEBUG, "# cadet internal traffic, type %s\n",
- GC_m2s (ntohs (mh->type)));
- memcpy (cbuf, &th[1], th->size);
- psize = th->size;
- }
- if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (th->timeout_task);
- GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th);
- GNUNET_free (th);
- next = h->th_head;
- nsize = message_ready_size (h);
- cbuf += psize;
- size -= psize;
- tsize += psize;
- }
- LOG (GNUNET_ERROR_TYPE_DEBUG, "# total size: %u\n", tsize);
- h->th = NULL;
- size = message_ready_size (h);
- if (0 != size)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "# next size: %u\n", size);
- h->th =
- GNUNET_CLIENT_notify_transmit_ready (h->client, size,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES, &send_callback, h);
- }
- else
- {
- if (NULL != h->th_head)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "# can't transmit any more\n");
- else
- LOG (GNUNET_ERROR_TYPE_DEBUG, "# nothing left to transmit\n");
- }
- if (GNUNET_NO == h->in_receive)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "# start receiving from service\n");
- h->in_receive = GNUNET_YES;
- GNUNET_CLIENT_receive (h->client, &msg_received, h,
- GNUNET_TIME_UNIT_FOREVER_REL);