/**
* Minimum value for channel IDs of local clients.
*/
-#define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000
+#define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000U
/**
* FIXME.
size_t osize;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting Data: %u bytes\n",
- th->size);
+ "Requesting Data: %u bytes (allow send is %u)\n",
+ th->size,
+ th->channel->allow_send);
GNUNET_assert (0 < th->channel->allow_send);
th->channel->allow_send--;
unsigned int i;
uint16_t type;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Got a data message!\n");
ch = retrieve_channel (h,
message->ccn);
GNUNET_assert (NULL != ch);
payload = (struct GNUNET_MessageHeader *) &message[1];
- LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n",
+ type = ntohs (payload->type);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got a %s data on channel %s [%X] of type %s\n",
GC_f2s (ntohl (ch->ccn.channel_of_client) >=
GNUNET_CADET_LOCAL_CHANNEL_ID_CLI),
GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)),
- ntohl (message->ccn.channel_of_client));
+ ntohl (message->ccn.channel_of_client),
+ GC_m2s (type));
- type = ntohs (payload->type);
- LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %s\n", GC_m2s (type));
for (i = 0; i < h->n_handlers; i++)
{
handler = &h->message_handlers[i];
- LOG (GNUNET_ERROR_TYPE_DEBUG, " checking handler for type %u\n",
- handler->type);
if (handler->type == type)
{
if (GNUNET_OK !=
handler->callback (h->cls, ch, &ch->ctx, payload))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "callback caused disconnection\n");
- GNUNET_CADET_channel_destroy (ch);
- break;
- }
- else
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "callback completed successfully\n");
+ "callback caused disconnection\n");
+ GNUNET_CADET_channel_destroy (ch);
break;
}
+ break;
}
}
}
ntohl (ccn.channel_of_client));
return;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Got an ACK on channel %X!\n",
- ntohl (ch->ccn.channel_of_client));
ch->allow_send++;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Checking for pending data\n");
+ "Got an ACK on channel %X, allow send now %u!\n",
+ ntohl (ch->ccn.channel_of_client),
+ ch->allow_send);
for (th = h->th_head; NULL != th; th = th->next)
{
if ( (th->channel == ch) &&
* original state.
*
* @param h handle to the cadet
- *
- * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...)
+ * @return #GNUNET_YES in case of success, #GNUNET_NO otherwise (service down...)
*/
static int
do_reconnect (struct GNUNET_CADET_Handle *h)
struct GNUNET_CADET_TransmitHandle *th;
GNUNET_assert (NULL != channel);
- GNUNET_assert (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE >= notify_size);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET NOTIFY TRANSMIT READY\n");
- LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->ccn);
- LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send);
- if (ntohl (channel->ccn.channel_of_client) >=
- GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
- LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n");
- else
- LOG (GNUNET_ERROR_TYPE_DEBUG, " to destination\n");
- LOG (GNUNET_ERROR_TYPE_DEBUG, " payload size %u\n", notify_size);
GNUNET_assert (NULL != notify);
+ GNUNET_assert (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE >= notify_size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "CADET NOTIFY TRANSMIT READY on channel %X allow_send is %u to %s with %u bytes\n",
+ channel->ccn,
+ channel->allow_send,
+ (ntohl (channel->ccn.channel_of_client) >=
+ GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
+ ? "origin"
+ : "destination",
+ (unsigned int) notify_size);
if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != maxdelay.rel_value_us)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
th = GNUNET_new (struct GNUNET_CADET_TransmitHandle);
th->channel = channel;
th->size = notify_size;
- LOG (GNUNET_ERROR_TYPE_DEBUG, " total size %u\n", th->size);
th->notify = notify;
th->notify_cls = notify_cls;
if (0 != channel->allow_send)
- th->request_data_task = GNUNET_SCHEDULER_add_now (&request_data, th);
+ th->request_data_task
+ = GNUNET_SCHEDULER_add_now (&request_data,
+ th);
else
- add_to_queue (channel->cadet, th);
-
- LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET NOTIFY TRANSMIT READY END\n");
+ add_to_queue (channel->cadet,
+ th);
return th;
}
ch,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Accepting incoming %s from %s on open port %s (%u)\n",
+ "Accepting incoming %s from %s on open port %s (%u), assigning ccn %X\n",
GCCH_2s (ch),
GCP_2s (dest),
GNUNET_h2s (port),
- ntohl (options));
+ ntohl (options),
+ ntohl (ccn.channel_of_client));
/* notify local client about incoming connection! */
env = GNUNET_MQ_msg (cm,
GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
GCCH_2s (ch));
if (GNUNET_OK !=
GCCH_handle_local_data (ch,
- c,
+ msg->ccn,
buf,
payload_size))
{
ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER));
ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE));
ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER));
- ch->max_pending_messages = (ch->nobuffer) ? 1 : 32; /* FIXME: 32!? Do not hardcode! */
+ ch->max_pending_messages = (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */
ch->owner = owner;
ch->ccn_owner = ccn;
ch->port = *port;
ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER));
ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE));
ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER));
- ch->max_pending_messages = (ch->nobuffer) ? 1 : 32; /* FIXME: 32!? Do not hardcode! */
+ ch->max_pending_messages = (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */
GNUNET_STATISTICS_update (stats,
"# channels",
1,
/**
- * Send a #GNUNET_MESSAGE_TYPE_CADET_LOCAL ACK to the client to solicit more messages.
+ * Send a #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK to the client to solicit more messages.
*
* @param ch channel the ack is for
- * @param c client to send the ACK to
+ * @param to_owner #GNUNET_YES to send to owner,
+ * #GNUNET_NO to send to dest
*/
static void
send_ack_to_client (struct CadetChannel *ch,
- struct CadetClient *c)
+ int to_owner)
{
struct GNUNET_MQ_Envelope *env;
struct GNUNET_CADET_LocalAck *ack;
+ struct CadetClient *c;
env = GNUNET_MQ_msg (ack,
GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
- ack->ccn = (c == ch->owner) ? ch->ccn_owner : ch->ccn_dest;
+ ack->ccn = (GNUNET_YES == to_owner) ? ch->ccn_owner : ch->ccn_dest;
+ c = (GNUNET_YES == to_owner)
+ ? ch->owner
+ : ch->dest;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X\n",
+ GSC_2s (c),
+ (GNUNET_YES == to_owner) ? "owner" : "dest",
+ ntohl (ack->ccn.channel_of_client));
GSC_send_to_client (c,
env);
}
: GCT_get_destination (ch->t),
&ch->port,
options);
+ GNUNET_assert (ntohl (ch->ccn_dest.channel_of_client) <
+ GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
ch->mid_recv.mid = htonl (1); /* The CONNECT counts as message 0! */
if (GNUNET_YES == ch->is_loopback)
{
ch);
}
/* give client it's initial supply of ACKs */
+ GNUNET_assert (ntohl (ch->ccn_dest.channel_of_client) <
+ GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
for (unsigned int i=0;i<ch->max_pending_messages;i++)
send_ack_to_client (ch,
- ch->dest);
+ GNUNET_NO);
}
to be buffered! */
for (unsigned int i=0;i<ch->max_pending_messages;i++)
send_ack_to_client (ch,
- ch->owner);
+ GNUNET_YES);
break;
case CADET_CHANNEL_READY:
/* duplicate ACK, maybe we retried the CREATE. Ignore. */
(unsigned int) ntohl (ack->mid.mid),
ch->pending_messages);
send_ack_to_client (ch,
- (NULL == ch->owner) ? ch->dest : ch->owner);
+ (NULL == ch->owner)
+ ? GNUNET_NO
+ : GNUNET_YES);
}
* buffer space in the tunnel.
*
* @param ch Channel.
- * @param sender client sending the data
+ * @param sender_ccn ccn of the sender
* @param buf payload to transmit.
* @param buf_len number of bytes in @a buf
* @return #GNUNET_OK if everything goes well,
*/
int
GCCH_handle_local_data (struct CadetChannel *ch,
- struct CadetClient *sender,
+ struct GNUNET_CADET_ClientChannelNumber sender_ccn,
const char *buf,
size_t buf_len)
{
struct CadetClient *receiver;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_CADET_LocalData *ld;
+ int to_owner;
env = GNUNET_MQ_msg_extra (ld,
buf_len,
GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
- receiver = (ch->owner == sender) ? ch->dest : ch->owner;
- ld->ccn = (ch->owner == sender) ? ch->ccn_dest : ch->ccn_owner;
+ if (sender_ccn.channel_of_client ==
+ ch->ccn_owner.channel_of_client)
+ {
+ receiver = ch->dest;
+ ld->ccn = ch->ccn_dest;
+ to_owner = GNUNET_NO;
+ }
+ else
+ {
+ GNUNET_assert (sender_ccn.channel_of_client ==
+ ch->ccn_dest.channel_of_client);
+ receiver = ch->owner;
+ ld->ccn = ch->ccn_owner;
+ to_owner = GNUNET_YES;
+ }
GNUNET_memcpy (&ld[1],
buf,
buf_len);
GSC_send_to_client (receiver,
env);
send_ack_to_client (ch,
- sender);
+ to_owner);
return GNUNET_OK;
}
* buffer space in the tunnel.
*
* @param ch Channel.
- * @param sender client sending the data
+ * @param sender_ccn ccn of the sender
* @param buf payload to transmit.
* @param buf_len number of bytes in @a buf
* @return #GNUNET_OK if everything goes well,
*/
int
GCCH_handle_local_data (struct CadetChannel *ch,
- struct CadetClient *sender,
+ struct GNUNET_CADET_ClientChannelNumber sender_ccn,
const char *buf,
size_t buf_len);
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Receicved channel OPEN_ACK on channel %s from %s\n",
+ "Received channel OPEN_ACK on channel %s from %s\n",
GCCH_2s (ch),
GCT_2s (t));
GCCH_handle_channel_open_ack (ch);