client-side path tracking support
authorChristian Grothoff <christian@grothoff.org>
Mon, 4 Oct 2010 20:22:32 +0000 (20:22 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 4 Oct 2010 20:22:32 +0000 (20:22 +0000)
TODO
src/dht/dht.h
src/dht/dht_api.c
src/dht/gnunet-service-dht.c

diff --git a/TODO b/TODO
index c1154ca657e35d79b8a13bf9a6c41fe93d6ac22e..be292e2bfdcc4ee98e24b83cda6943b4fadc736e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -5,8 +5,8 @@
   - integrate with DHT (need DHT API to fit block API better first; also, get rid of the continuation!)
 * DHT: [Nate]
   - use new block lib in service
-  - provide block-lib compatible API in gnunet_dht_service.h
-  - eliminate continuations in DHT API (not needed, we have auto-retransmit!)
+  - track paths content travels (PUT, reply-to-get) in messages,
+    pass to client (client API & protocol already support this!)
 * CORE:
   - authentication of ciphertexts [Nils]
   - Jun 27 11:51:54 core-7670 ERROR Assertion failed at gnunet-service-core.c:3616.
index 63e95e1138ce4d1acb56449aa10de3af1e0d94d3..9c2e889a7b050763d99fcf08d646812cbe227e1f 100644 (file)
@@ -212,9 +212,18 @@ struct GNUNET_DHT_RouteResultMessage
   struct GNUNET_MessageHeader header;
 
   /**
-   * For alignment, always zero.
+   * Number of peers recorded in the "PUT" path.
+   * (original path message took during "PUT").  These
+   * peer identities follow this message.
    */
-  uint32_t reserved GNUNET_PACKED;
+  uint16_t put_path_length GNUNET_PACKED;
+
+  /**
+   * Number of peers recorded in the "GET" path
+   * (inverse of the path the GET message took).  These
+   * peer identities follow this message.
+   */
+  uint16_t get_path_length GNUNET_PACKED;
 
   /**
    * Unique ID identifying this request (necessary for
@@ -227,6 +236,10 @@ struct GNUNET_DHT_RouteResultMessage
    */
   GNUNET_HashCode key;
 
+  /* PUT path */
+
+  /* GET path */
+
   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
 };
 
@@ -241,6 +254,11 @@ struct GNUNET_DHT_P2PRouteMessage
    */
   struct GNUNET_MessageHeader header;
 
+  /**
+   * Always zero.
+   */
+  uint32_t reserved GNUNET_PACKED;
+
   /**
    * Message options
    */
@@ -252,14 +270,14 @@ struct GNUNET_DHT_P2PRouteMessage
   uint32_t hop_count GNUNET_PACKED;
 
   /**
-   * Network size estimate
+   * Replication level for this message
    */
-  uint32_t network_size GNUNET_PACKED;
+  uint32_t desired_replication_level GNUNET_PACKED;
 
   /**
-   * Replication level for this message
+   * Network size estimate
    */
-  uint32_t desired_replication_level GNUNET_PACKED;
+  uint32_t network_size GNUNET_PACKED;
 
   /**
    * Unique ID identifying this request
@@ -297,6 +315,20 @@ struct GNUNET_DHT_P2PRouteResultMessage
    */
   struct GNUNET_MessageHeader header;
 
+  /**
+   * Number of peers recorded in the "PUT" path.
+   * (original path message took during "PUT").  These
+   * peer identities follow this message.
+   */
+  uint16_t put_path_length GNUNET_PACKED;
+
+  /**
+   * Number of peers recorded in the "GET" path
+   * (inverse of the path the GET message took).  These
+   * peer identities follow this message.
+   */
+  uint16_t get_path_length GNUNET_PACKED;
+
   /**
    * Message options
    */
@@ -329,6 +361,11 @@ struct GNUNET_DHT_P2PRouteResultMessage
   uint32_t network_size GNUNET_PACKED;
 #endif
 
+
+  /* PUT path */
+
+  /* GET path */
+
   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
 };
 
index 0dd40a73542fddd1069d9462ed95ca18f4acfb78..62078b5cfebe15703dd2737d6b125a6fbf6b23f9 100644 (file)
@@ -398,8 +398,12 @@ process_reply (void *cls,
   const struct GNUNET_MessageHeader *enc_msg;
   size_t enc_size;
   uint64_t uid;
-  const struct GNUNET_PeerIdentity *const*get_path;
-  const struct GNUNET_PeerIdentity *const*put_path;
+  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)
@@ -414,21 +418,56 @@ process_reply (void *cls,
       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");
-  get_path = NULL; // FIXME: parse path info!
-  put_path = NULL; // FIXME: parse path info!
   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;
 }
 
index c03e0b1ac7e4f951971c385b87237fd8278cd8a0..48661fd888753bceb62ea6e7919f163416bb10b1 100644 (file)
@@ -1024,10 +1024,11 @@ try_core_send (void *cls,
  * @param peer the peer to forward the message to
  * @param msg_ctx the context of the message (hop count, bloom, etc.)
  */
-static void forward_result_message (void *cls,
-                                    const struct GNUNET_MessageHeader *msg,
-                                    struct PeerInfo *peer,
-                                    struct DHT_MessageContext *msg_ctx)
+static void 
+forward_result_message (void *cls,
+                       const struct GNUNET_MessageHeader *msg,
+                       struct PeerInfo *peer,
+                       struct DHT_MessageContext *msg_ctx)
 {
   struct GNUNET_DHT_P2PRouteResultMessage *result_message;
   struct P2PPendingMessage *pending;
@@ -1045,6 +1046,8 @@ static void forward_result_message (void *cls,
   result_message = (struct GNUNET_DHT_P2PRouteResultMessage *)pending->msg;
   result_message->header.size = htons(msize);
   result_message->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_P2P_ROUTE_RESULT);
+  result_message->put_path_length = htons(0); /* FIXME: implement */
+  result_message->get_path_length = htons(0); /* FIXME: implement */
   result_message->options = htonl(msg_ctx->msg_options);
   result_message->hop_count = htonl(msg_ctx->hop_count + 1);
   GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_bloomfilter_get_raw_data(msg_ctx->bloom, result_message->bloomfilter, DHT_BLOOM_SIZE));
@@ -1882,7 +1885,8 @@ send_reply_to_client (struct ClientList *client,
   reply = (struct GNUNET_DHT_RouteResultMessage *)&pending_message[1];
   reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_RESULT);
   reply->header.size = htons (tsize);
-  reply->reserved = 0;
+  reply->put_path_length = htons(0); /* FIXME: implement */
+  reply->get_path_length = htons(0); /* FIXME: implement */
   reply->unique_id = GNUNET_htonll (uid);
   reply->key = *key;
   memcpy (&reply[1], message, msize);