reconnect (struct GNUNET_DV_ServiceHandle *sh);
+/**
+ * Start sending messages from our queue to the service.
+ *
+ * @param sh service handle
+ */
+static void
+start_transmit (struct GNUNET_DV_ServiceHandle *sh);
+
+
/**
* Gives a message from our queue to the DV service.
*
- * @param cls handle to the dv service (struct GNUNET_DV_ServiceHandle)
+ * @param cls handle to the dv service (`struct GNUNET_DV_ServiceHandle`)
* @param size how many bytes can we send
* @param buf where to copy the message to send
* @return how many bytes we copied to @a buf
sh->th_tail,
th);
memcpy (&cbuf[ret], th->msg, tsize);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Passing %u bytes of type %u to DV service\n",
+ tsize,
+ ntohs (th->msg->type));
th->msg = NULL;
ret += tsize;
if (NULL != th->cb)
{
- GNUNET_CONTAINER_DLL_insert (th->target->head,
- th->target->tail,
- th);
+ GNUNET_CONTAINER_DLL_insert_tail (th->target->head,
+ th->target->tail,
+ th);
}
else
{
GNUNET_free (th);
}
}
+ if (NULL != sh->th_head)
+ start_transmit (sh);
return ret;
}
th->cb (th->cb_cls, GNUNET_SYSERR);
GNUNET_free (th);
}
+ GNUNET_free (peer);
return GNUNET_OK;
}
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %u from DV service\n",
- (unsigned int) msg->type);
+ "Received message of type %u with %u bytes from DV service\n",
+ (unsigned int) ntohs (msg->type),
+ (unsigned int) ntohs (msg->size));
switch (ntohs (msg->type))
{
case GNUNET_MESSAGE_TYPE_DV_CONNECT:
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
sh->connect_cb (sh->cls,
&cm->peer,
- ntohl (cm->distance), ntohl (cm->network));
+ ntohl (cm->distance),
+ (enum GNUNET_ATS_Network_Type) ntohl (cm->network));
break;
case GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED:
if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DistanceUpdateMessage))
dum = (const struct GNUNET_DV_DistanceUpdateMessage *) msg;
sh->distance_cb (sh->cls,
&dum->peer,
- ntohl (dum->distance));
+ ntohl (dum->distance),
+ (enum GNUNET_ATS_Network_Type) ntohl (dum->network));
break;
case GNUNET_MESSAGE_TYPE_DV_DISCONNECT:
if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DisconnectMessage))
reconnect (sh);
return;
}
+ if (NULL ==
+ GNUNET_CONTAINER_multipeermap_get (sh->peers,
+ &rm->sender))
+ {
+ GNUNET_break (0);
+ reconnect (sh);
+ return;
+ }
sh->message_cb (sh->cls,
&rm->sender,
ntohl (rm->distance),
peer = GNUNET_CONTAINER_multipeermap_get (sh->peers,
&ack->target);
if (NULL == peer)
- return; /* this happens, just ignore */
+ break; /* this happens, just ignore */
for (th = peer->head; NULL != th; th = th->next)
{
if (th->uid != ntohl (ack->uid))
reconnect (sh);
break;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message, continuing receive loop for %p\n",
+ sh->client);
GNUNET_CLIENT_receive (sh->client,
&handle_message_receipt, sh,
GNUNET_TIME_UNIT_FOREVER_REL);
start_message.size = htons (sizeof (struct GNUNET_MessageHeader));
start_message.type = htons (GNUNET_MESSAGE_TYPE_DV_START);
memcpy (buf, &start_message, sizeof (start_message));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting START request, starting receive loop for %p\n",
+ sh->client);
GNUNET_CLIENT_receive (sh->client,
&handle_message_receipt, sh,
GNUNET_TIME_UNIT_FOREVER_REL);
GNUNET_CLIENT_notify_transmit_ready_cancel (sh->th);
sh->th = NULL;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting from DV service at %p\n",
+ sh->client);
if (NULL != sh->client)
{
GNUNET_CLIENT_disconnect (sh->client);
return NULL;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to send %u bytes of type %u to %s\n",
- (unsigned int) msg->size,
- (unsigned int) msg->type,
- GNUNET_i2s (target));
+ "Asked to send %u bytes of type %u to %s via %p\n",
+ (unsigned int) ntohs (msg->size),
+ (unsigned int) ntohs (msg->type),
+ GNUNET_i2s (target),
+ sh->client);
peer = GNUNET_CONTAINER_multipeermap_get (sh->peers,
target);
if (NULL == peer)
/* use memcpy here as 'target' may not be sufficiently aligned */
memcpy (&sm->target, target, sizeof (struct GNUNET_PeerIdentity));
memcpy (&sm[1], msg, ntohs (msg->size));
- GNUNET_CONTAINER_DLL_insert (sh->th_head,
- sh->th_tail,
- th);
+ GNUNET_CONTAINER_DLL_insert_tail (sh->th_head,
+ sh->th_tail,
+ th);
start_transmit (sh);
return th;
}