GNUNET_HashCode key;
/**
- * Unique identifier for this request (for key collisions)
+ * Unique identifier for this request (for key collisions). FIXME: redundant!?
*/
uint64_t uid;
_("Failed to connect to the DHT service!\n"));
return GNUNET_NO;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting to process replies from DHT\n");
GNUNET_CLIENT_receive (handle->client,
&service_message_handler,
handle,
}
if (NULL != head->cont)
{
- GNUNET_SCHEDULER_add_now (handle->sched,
- head->cont,
- head->cont_cls);
+ GNUNET_SCHEDULER_add_continuation (handle->sched,
+ head->cont,
+ head->cont_cls,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
head->cont = NULL;
head->cont_cls = NULL;
}
if (GNUNET_YES == head->free_on_send)
GNUNET_free (head);
process_pending_messages (handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Forwarded request of %u bytes to DHT service\n",
+ (unsigned int) tsize);
return tsize;
}
const struct GNUNET_MessageHeader *enc_msg;
size_t enc_size;
uint64_t uid;
+ const struct GNUNET_PeerIdentity **get_path;
+ const struct GNUNET_PeerIdentity **put_path;
+ const struct GNUNET_PeerIdentity *pos;
+ uint16_t gpl;
+ uint16_t ppl;
+ unsigned int i;
uid = GNUNET_ntohll (dht_msg->unique_id);
if (uid != rh->uid)
- return GNUNET_YES;
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Reply UID did not match request UID\n");
+ return GNUNET_YES;
+ }
enc_size = ntohs (dht_msg->header.size) - sizeof (struct GNUNET_DHT_RouteResultMessage);
if (enc_size < sizeof (struct GNUNET_MessageHeader))
{
GNUNET_break (0);
return GNUNET_NO;
}
- enc_msg = (const struct GNUNET_MessageHeader *) &dht_msg[1];
+ pos = (const struct GNUNET_PeerIdentity *) &dht_msg[1];
+ ppl = ntohs (dht_msg->put_path_length);
+ gpl = ntohs (dht_msg->get_path_length);
+ if ( (ppl + gpl) * sizeof (struct GNUNET_PeerIdentity) > enc_size)
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
+ if (ppl > 0)
+ {
+ put_path = GNUNET_malloc ((ppl+1) * sizeof (struct GNUNET_PeerIdentity*));
+ for (i=0;i<ppl;i++)
+ {
+ put_path[i] = pos;
+ pos++;
+ }
+ put_path[ppl] = NULL;
+ }
+ else
+ put_path = NULL;
+ if (gpl > 0)
+ {
+ get_path = GNUNET_malloc ((gpl+1) * sizeof (struct GNUNET_PeerIdentity*));
+ for (i=0;i<gpl;i++)
+ {
+ get_path[i] = pos;
+ pos++;
+ }
+ get_path[gpl] = NULL;
+ }
+ else
+ get_path = NULL;
+ enc_size -= (ppl + gpl) * sizeof (struct GNUNET_PeerIdentity);
+ enc_msg = (const struct GNUNET_MessageHeader *) pos;
if (enc_size != ntohs (enc_msg->size))
{
GNUNET_break (0);
+ GNUNET_free_non_null (get_path);
+ GNUNET_free_non_null (put_path);
return GNUNET_NO;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Processing reply.\n");
rh->iter (rh->iter_cls,
&rh->key,
+ get_path,
+ put_path,
enc_msg);
+ GNUNET_free_non_null (get_path);
+ GNUNET_free_non_null (put_path);
return GNUNET_YES;
}
{
struct GNUNET_DHT_Handle *handle = cls;
const struct GNUNET_DHT_RouteResultMessage *dht_msg;
-
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s called\n",
+ __FUNCTION__);
if (msg == NULL)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error receiving data from DHT service, reconnecting\n");
reconnect (handle);
return;
}
return;
}
dht_msg = (const struct GNUNET_DHT_RouteResultMessage *) msg;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Comparing reply `%s' against %u pending requests.\n",
+ GNUNET_h2s (&dht_msg->key),
+ GNUNET_CONTAINER_multihashmap_size (handle->active_requests));
GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests,
&dht_msg->key,
&process_reply,
(void*) dht_msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Continuing to process replies from DHT\n");
GNUNET_CLIENT_receive (handle->client,
&service_message_handler,
handle, GNUNET_TIME_UNIT_FOREVER_REL);
-/* ***** Special low-level API providing generic routeing abstraction ***** */
+/* ***** Special low-level API providing generic routing abstraction ***** */
/**
*/
struct GNUNET_DHT_RouteHandle *
GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
- const GNUNET_HashCode * key,
+ const GNUNET_HashCode *key,
uint32_t desired_replication_level,
enum GNUNET_DHT_RouteOption options,
const struct GNUNET_MessageHeader *enc,
message->key = *key;
message->options = htonl ((uint32_t) options);
message->desired_replication_level = htonl (desired_replication_level);
+ handle->uid_gen++;
+ message->unique_id = GNUNET_htonll (handle->uid_gen);
memcpy (&message[1], enc, esize);
+
if (iter != NULL)
{
route_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_RouteHandle));
route_handle->iter = iter;
route_handle->iter_cls = iter_cls;
route_handle->dht_handle = handle;
- route_handle->uid = handle->uid_gen++;
+ route_handle->uid = handle->uid_gen;
route_handle->message = pending;
- message->unique_id = GNUNET_htonll (route_handle->uid);
GNUNET_CONTAINER_multihashmap_put (handle->active_requests,
key,
route_handle,
pending);
pending->in_pending_queue = GNUNET_YES;
process_pending_messages (handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DHT route start request processed, returning %p\n",
+ route_handle);
return route_handle;
}
route_handle));
GNUNET_free(route_handle->message);
GNUNET_free(route_handle);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DHT route stop request processed\n");
}