From f14b2cfede0715af893421288592d2e3868790b3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 4 Oct 2010 20:22:32 +0000 Subject: [PATCH] client-side path tracking support --- TODO | 4 +-- src/dht/dht.h | 49 +++++++++++++++++++++++++++++++----- src/dht/dht_api.c | 49 ++++++++++++++++++++++++++++++++---- src/dht/gnunet-service-dht.c | 14 +++++++---- 4 files changed, 98 insertions(+), 18 deletions(-) diff --git a/TODO b/TODO index c1154ca65..be292e2bf 100644 --- 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. diff --git a/src/dht/dht.h b/src/dht/dht.h index 63e95e113..9c2e889a7 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h @@ -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 */ }; diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 0dd40a735..62078b5cf 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c @@ -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 0) + { + get_path = GNUNET_malloc ((gpl+1) * sizeof (struct GNUNET_PeerIdentity*)); + for (i=0;isize)) { 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; } diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index c03e0b1ac..48661fd88 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -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); -- 2.25.1