From ec19c1e316efdd29a7af0524fc2ff33cc4b19d09 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 9 Jan 2022 12:22:04 +0100 Subject: DHT: modify API and protocol messages to add path signatures, except for now the actual signatures are just placeholders (signing and signature verification are missing) --- src/dht/dht_api.c | 177 +++++++++------------------- src/dht/gnunet-dht-get.c | 78 ++++++++----- src/dht/gnunet-dht-monitor.c | 8 +- src/dht/gnunet-dht-put.c | 75 ++++++------ src/dht/gnunet-service-dht.h | 6 +- src/dht/gnunet-service-dht_clients.c | 55 ++++----- src/dht/gnunet-service-dht_datacache.c | 5 +- src/dht/gnunet-service-dht_datacache.h | 2 +- src/dht/gnunet-service-dht_neighbours.c | 200 +++++++++----------------------- src/dht/gnunet-service-dht_neighbours.h | 4 +- src/dht/gnunet-service-dht_routing.c | 6 +- src/dht/gnunet-service-dht_routing.h | 2 +- src/dht/gnunet_dht_profiler.c | 4 +- src/dht/test_dht_api.c | 4 +- src/dht/test_dht_monitor.c | 12 +- src/dht/test_dht_topo.c | 4 +- 16 files changed, 259 insertions(+), 383 deletions(-) (limited to 'src/dht') diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 727f1a1f6..1ba2f7277 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c @@ -260,7 +260,7 @@ struct GNUNET_DHT_Handle * @param h DHT handle to reconnect * @return #GNUNET_YES on success, #GNUNET_NO on failure. */ -static int +static enum GNUNET_GenericReturnValue try_connect (struct GNUNET_DHT_Handle *h); @@ -344,7 +344,7 @@ send_get_known_results (struct GNUNET_DHT_GetHandle *gh, * @param value the `struct GNUNET_DHT_GetHandle *` * @return #GNUNET_YES (always) */ -static int +static enum GNUNET_GenericReturnValue add_get_request_to_pending (void *cls, const struct GNUNET_HashCode *key, void *value) @@ -488,7 +488,7 @@ mq_error_handler (void *cls, * @return #GNUNET_OK if everything went fine, * #GNUNET_SYSERR if the message is malformed. */ -static int +static enum GNUNET_GenericReturnValue check_monitor_get (void *cls, const struct GNUNET_DHT_MonitorGetMessage *msg) { @@ -496,7 +496,7 @@ check_monitor_get (void *cls, uint16_t msize = ntohs (msg->header.size) - sizeof(*msg); if ((plen > UINT16_MAX) || - (plen * sizeof(struct GNUNET_PeerIdentity) != msize)) + (plen * sizeof(struct GNUNET_DHT_PathElement) != msize)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -534,7 +534,7 @@ handle_monitor_get (void *cls, ntohl (msg->hop_count), ntohl (msg->desired_replication_level), ntohl (msg->get_path_length), - (struct GNUNET_PeerIdentity *) &msg[1], + (struct GNUNET_DHT_PathElement *) &msg[1], &msg->key); } } @@ -548,7 +548,7 @@ handle_monitor_get (void *cls, * @return #GNUNET_OK if everything went fine, * #GNUNET_SYSERR if the message is malformed. */ -static int +static enum GNUNET_GenericReturnValue check_monitor_get_resp (void *cls, const struct GNUNET_DHT_MonitorGetRespMessage *msg) { @@ -557,7 +557,7 @@ check_monitor_get_resp (void *cls, uint32_t putl = ntohl (msg->put_path_length); if ((getl + putl < getl) || - ((msize / sizeof(struct GNUNET_PeerIdentity)) < getl + putl)) + ((msize / sizeof(struct GNUNET_DHT_PathElement)) < getl + putl)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -578,12 +578,12 @@ handle_monitor_get_resp (void *cls, { struct GNUNET_DHT_Handle *handle = cls; size_t msize = ntohs (msg->header.size) - sizeof(*msg); - const struct GNUNET_PeerIdentity *path; + const struct GNUNET_DHT_PathElement *path; uint32_t getl = ntohl (msg->get_path_length); uint32_t putl = ntohl (msg->put_path_length); struct GNUNET_DHT_MonitorHandle *mh; - path = (const struct GNUNET_PeerIdentity *) &msg[1]; + path = (const struct GNUNET_DHT_PathElement *) &msg[1]; for (mh = handle->monitor_head; NULL != mh; mh = mh->next) { if (NULL == mh->get_resp_cb) @@ -603,8 +603,8 @@ handle_monitor_get_resp (void *cls, GNUNET_TIME_absolute_ntoh (msg->expiration_time), &msg->key, (const void *) &path[getl + putl], - msize - sizeof(struct GNUNET_PeerIdentity) * (putl - + getl)); + msize - sizeof(struct GNUNET_DHT_PathElement) * (putl + + getl)); } } @@ -617,7 +617,7 @@ handle_monitor_get_resp (void *cls, * @return #GNUNET_OK if everything went fine, * #GNUNET_SYSERR if the message is malformed. */ -static int +static enum GNUNET_GenericReturnValue check_monitor_put (void *cls, const struct GNUNET_DHT_MonitorPutMessage *msg) { @@ -626,7 +626,7 @@ check_monitor_put (void *cls, msize = ntohs (msg->header.size) - sizeof(*msg); putl = ntohl (msg->put_path_length); - if ((msize / sizeof(struct GNUNET_PeerIdentity)) < putl) + if ((msize / sizeof(struct GNUNET_DHT_PathElement)) < putl) { GNUNET_break (0); return GNUNET_SYSERR; @@ -648,10 +648,10 @@ handle_monitor_put (void *cls, struct GNUNET_DHT_Handle *handle = cls; size_t msize = ntohs (msg->header.size) - sizeof(*msg); uint32_t putl = ntohl (msg->put_path_length); - const struct GNUNET_PeerIdentity *path; + const struct GNUNET_DHT_PathElement *path; struct GNUNET_DHT_MonitorHandle *mh; - path = (const struct GNUNET_PeerIdentity *) &msg[1]; + path = (const struct GNUNET_DHT_PathElement *) &msg[1]; for (mh = handle->monitor_head; NULL != mh; mh = mh->next) { if (NULL == mh->put_cb) @@ -672,7 +672,7 @@ handle_monitor_put (void *cls, GNUNET_TIME_absolute_ntoh (msg->expiration_time), &msg->key, (const void *) &path[putl], - msize - sizeof(struct GNUNET_PeerIdentity) * putl); + msize - sizeof(struct GNUNET_DHT_PathElement) * putl); } } @@ -685,7 +685,7 @@ handle_monitor_put (void *cls, * @return #GNUNET_OK if everything went fine, * #GNUNET_SYSERR if the message is malformed. */ -static int +static enum GNUNET_GenericReturnValue check_client_result (void *cls, const struct GNUNET_DHT_ClientResultMessage *msg) { @@ -695,12 +695,12 @@ check_client_result (void *cls, size_t meta_length; meta_length = - sizeof(struct GNUNET_PeerIdentity) * (get_path_length + put_path_length); + sizeof(struct GNUNET_DHT_PathElement) * (get_path_length + put_path_length); if ((msize < meta_length) || (get_path_length > - GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || + GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || (put_path_length > - GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) + GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement))) { GNUNET_break (0); return GNUNET_SYSERR; @@ -717,7 +717,7 @@ check_client_result (void *cls, * @param value the `struct GNUNET_DHT_GetHandle` of a request matching the same key * @return #GNUNET_YES to continue to iterate over all results */ -static int +static enum GNUNET_GenericReturnValue process_client_result (void *cls, const struct GNUNET_HashCode *key, void *value) @@ -727,8 +727,8 @@ process_client_result (void *cls, size_t msize = ntohs (crm->header.size) - sizeof(*crm); uint32_t put_path_length = ntohl (crm->put_path_length); uint32_t get_path_length = ntohl (crm->get_path_length); - const struct GNUNET_PeerIdentity *put_path; - const struct GNUNET_PeerIdentity *get_path; + const struct GNUNET_DHT_PathElement *put_path; + const struct GNUNET_DHT_PathElement *get_path; struct GNUNET_HashCode hc; size_t data_length; size_t meta_length; @@ -746,18 +746,18 @@ process_client_result (void *cls, } /* FIXME: might want to check that type matches */ meta_length = - sizeof(struct GNUNET_PeerIdentity) * (get_path_length + put_path_length); + sizeof(struct GNUNET_DHT_PathElement) * (get_path_length + put_path_length); data_length = msize - meta_length; - put_path = (const struct GNUNET_PeerIdentity *) &crm[1]; + put_path = (const struct GNUNET_DHT_PathElement *) &crm[1]; get_path = &put_path[put_path_length]; { char *pp; char *gp; - gp = GNUNET_STRINGS_pp2s (get_path, - get_path_length); - pp = GNUNET_STRINGS_pp2s (put_path, - put_path_length); + gp = GNUNET_DHT_pp2s (get_path, + get_path_length); + pp = GNUNET_DHT_pp2s (put_path, + put_path_length); LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n", (unsigned int) data_length, @@ -838,7 +838,7 @@ handle_put_cont (void *cls) * @param h DHT handle to reconnect * @return #GNUNET_YES on success, #GNUNET_NO on failure. */ -static int +static enum GNUNET_GenericReturnValue try_connect (struct GNUNET_DHT_Handle *h) { struct GNUNET_MQ_MessageHandler handlers[] = { @@ -878,14 +878,6 @@ try_connect (struct GNUNET_DHT_Handle *h) } -/** - * Initialize the connection with the DHT service. - * - * @param cfg configuration to use - * @param ht_len size of the internal hash table to use for - * processing multiple GET/FIND requests in parallel - * @return handle to the DHT service, or NULL on error - */ struct GNUNET_DHT_Handle * GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len) @@ -909,11 +901,6 @@ GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Shutdown connection with the DHT service. - * - * @param handle handle of the DHT connection to stop - */ void GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) { @@ -942,26 +929,6 @@ GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) } -/** - * Perform a PUT operation storing data in the DHT. FIXME: we should - * change the protocol to get a confirmation for the PUT from the DHT - * and call 'cont' only after getting the confirmation; otherwise, the - * client has no good way of telling if the 'PUT' message actually got - * to the DHT service! - * - * @param handle handle to DHT service - * @param key the key to store under - * @param desired_replication_level estimate of how many - * nearest peers this request should reach - * @param options routing options for this message - * @param type type of the value - * @param size number of bytes in data; must be less than 64k - * @param data the data to store - * @param exp desired expiration time for the value - * @param cont continuation to call when done (transmitting request to service) - * You must not call #GNUNET_DHT_disconnect in this continuation - * @param cont_cls closure for @a cont - */ struct GNUNET_DHT_PutHandle * GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const struct GNUNET_HashCode *key, @@ -1020,17 +987,6 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, } -/** - * Cancels a DHT PUT operation. Note that the PUT request may still - * go out over the network (we can't stop that); However, if the PUT - * has not yet been sent to the service, cancelling the PUT will stop - * this from happening (but there is no way for the user of this API - * to tell if that is the case). The only use for this API is to - * prevent a later call to 'cont' from #GNUNET_DHT_put (e.g. because - * the system is shutting down). - * - * @param ph put operation to cancel ('cont' will no longer be called) - */ void GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph) { @@ -1047,21 +1003,6 @@ GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph) } -/** - * Perform an asynchronous GET operation on the DHT identified. - * - * @param handle handle to the DHT service - * @param type expected type of the response object - * @param key the key to look up - * @param desired_replication_level estimate of how many - nearest peers this request should reach - * @param options routing options for this message - * @param xquery extended query data (can be NULL, depending on type) - * @param xquery_size number of bytes in @a xquery - * @param iter function to call on each result - * @param iter_cls closure for @a iter - * @return handle to stop the async get - */ struct GNUNET_DHT_GetHandle * GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, @@ -1111,16 +1052,6 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, } -/** - * Tell the DHT not to return any of the following known results - * to this client. - * - * @param get_handle get operation for which results should be filtered - * @param num_results number of results to be blocked that are - * provided in this call (size of the @a results array) - * @param results array of hash codes over the 'data' of the results - * to be blocked - */ void GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle, unsigned int num_results, @@ -1145,11 +1076,6 @@ GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle, } -/** - * Stop async DHT-get. - * - * @param get_handle handle to the GET operation to stop - */ void GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) { @@ -1183,18 +1109,6 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) } -/** - * Start monitoring the local DHT service. - * - * @param handle Handle to the DHT service. - * @param type Type of blocks that are of interest. - * @param key Key of data of interest, NULL for all. - * @param get_cb Callback to process monitored get messages. - * @param get_resp_cb Callback to process monitored get response messages. - * @param put_cb Callback to process monitored put messages. - * @param cb_cls Closure for callbacks. - * @return Handle to stop monitoring. - */ struct GNUNET_DHT_MonitorHandle * GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, @@ -1227,13 +1141,6 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, } -/** - * Stop monitoring. - * - * @param mh The handle to the monitor request returned by monitor_start. - * - * On return get_handle will no longer be valid, caller must not use again!!! - */ void GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *mh) { @@ -1262,4 +1169,28 @@ GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *mh) } +char * +GNUNET_DHT_pp2s (const struct GNUNET_DHT_PathElement *path, + unsigned int path_len) +{ + char *buf; + size_t off; + size_t plen = path_len * 5 + 1; + + GNUNET_assert (path_len < UINT32_MAX / 5); + off = 0; + buf = GNUNET_malloc (plen); + for (unsigned int i = 0; i < path_len; i++) + { + off += GNUNET_snprintf (&buf[off], + plen - off, + "%s%s", + GNUNET_i2s (&path[i].pred), + (i == path_len - 1) ? "" : "-"); + } + return buf; + +} + + /* end of dht_api.c */ diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c index c8a1cb735..f1076490b 100644 --- a/src/dht/gnunet-dht-get.c +++ b/src/dht/gnunet-dht-get.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 GNUnet e.V. + Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009, 2022 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -146,16 +146,17 @@ static void get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, - const struct GNUNET_PeerIdentity *get_path, + const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, + const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data) { fprintf (stdout, - (GNUNET_BLOCK_TYPE_TEST == type) ? _ ("Result %d, type %d:\n%.*s\n") + (GNUNET_BLOCK_TYPE_TEST == type) + ? _ ("Result %d, type %d:\n%.*s\n") : _ ("Result %d, type %d:\n"), result_count, type, @@ -163,13 +164,22 @@ get_result_iterator (void *cls, (char *) data); if (verbose) { - fprintf (stdout, " GET path: "); + fprintf (stdout, + " GET path: "); for (unsigned int i = 0; i < get_path_length; i++) - fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&get_path[i])); - fprintf (stdout, "\n PUT path: "); + fprintf (stdout, + "%s%s", + (0 == i) ? "" : "-", + GNUNET_i2s (&get_path[i].pred)); + fprintf (stdout, + "\n PUT path: "); for (unsigned int i = 0; i < put_path_length; i++) - fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&put_path[i])); - fprintf (stdout, "\n"); + fprintf (stdout, + "%s%s", + (0 == i) ? "" : "-", + GNUNET_i2s (&put_path[i].pred)); + fprintf (stdout, + "\n"); } result_count++; } @@ -194,13 +204,17 @@ run (void *cls, cfg = c; if (NULL == query_key) { - fprintf (stderr, "%s", _ ("Must provide key for DHT GET!\n")); + fprintf (stderr, + "%s", + _ ("Must provide key for DHT GET!\n")); ret = 1; return; } if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) { - fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n")); + fprintf (stderr, + "%s", + _ ("Failed to connect to DHT service!\n")); ret = 1; return; } @@ -238,39 +252,45 @@ run (void *cls, int main (int argc, char *const *argv) { - struct GNUNET_GETOPT_CommandLineOption options[] = - { GNUNET_GETOPT_option_string ('k', - "key", - "KEY", - gettext_noop ("the query key"), - &query_key), + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_string ( + 'k', + "key", + "KEY", + gettext_noop ("the query key"), + &query_key), GNUNET_GETOPT_option_uint ( 'r', "replication", "LEVEL", gettext_noop ("how many parallel requests (replicas) to create"), &replication), - GNUNET_GETOPT_option_uint ('t', - "type", - "TYPE", - gettext_noop ("the type of data to look for"), - &query_type), + GNUNET_GETOPT_option_uint ( + 't', + "type", + "TYPE", + gettext_noop ("the type of data to look for"), + &query_type), GNUNET_GETOPT_option_relative_time ( 'T', "timeout", "TIMEOUT", gettext_noop ("how long to execute this query before giving up?"), &timeout_request), - GNUNET_GETOPT_option_flag ('x', - "demultiplex", - gettext_noop ( - "use DHT's demultiplex everywhere option"), - &demultixplex_everywhere), + GNUNET_GETOPT_option_flag ( + 'x', + "demultiplex", + gettext_noop ( + "use DHT's demultiplex everywhere option"), + &demultixplex_everywhere), GNUNET_GETOPT_option_verbose (&verbose), - GNUNET_GETOPT_OPTION_END }; + GNUNET_GETOPT_OPTION_END + }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != + GNUNET_STRINGS_get_utf8_args (argc, argv, + &argc, &argv)) return 2; return (GNUNET_OK == GNUNET_PROGRAM_run ( diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c index 8dc14e223..b4ec497e4 100644 --- a/src/dht/gnunet-dht-monitor.c +++ b/src/dht/gnunet-dht-monitor.c @@ -137,7 +137,7 @@ get_callback (void *cls, uint32_t hop_count, uint32_t desired_replication_level, unsigned int path_length, - const struct GNUNET_PeerIdentity *path, + const struct GNUNET_DHT_PathElement *path, const struct GNUNET_HashCode *key) { fprintf (stdout, @@ -166,9 +166,9 @@ get_callback (void *cls, static void get_resp_callback (void *cls, enum GNUNET_BLOCK_Type type, - const struct GNUNET_PeerIdentity *get_path, + const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, + const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, @@ -211,7 +211,7 @@ put_callback (void *cls, uint32_t hop_count, uint32_t desired_replication_level, unsigned int path_length, - const struct GNUNET_PeerIdentity *path, + const struct GNUNET_DHT_PathElement *path, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const void *data, diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c index 7ee4ec185..531107ef2 100644 --- a/src/dht/gnunet-dht-put.c +++ b/src/dht/gnunet-dht-put.c @@ -179,48 +179,57 @@ run (void *cls, int main (int argc, char *const *argv) { - struct GNUNET_GETOPT_CommandLineOption options[] = - { GNUNET_GETOPT_option_string ('d', - "data", - "DATA", - gettext_noop ( - "the data to insert under the key"), - &data), + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_string ( + 'd', + "data", + "DATA", + gettext_noop ( + "the data to insert under the key"), + &data), GNUNET_GETOPT_option_relative_time ( 'e', "expiration", "EXPIRATION", gettext_noop ("how long to store this entry in the dht (in seconds)"), &expiration), - GNUNET_GETOPT_option_string ('k', - "key", - "KEY", - gettext_noop ("the query key"), - &query_key), - GNUNET_GETOPT_option_flag ('x', - "demultiplex", - gettext_noop ( - "use DHT's demultiplex everywhere option"), - &demultixplex_everywhere), - GNUNET_GETOPT_option_uint ('r', - "replication", - "LEVEL", - gettext_noop ("how many replicas to create"), - &replication), - GNUNET_GETOPT_option_flag ('R', - "record", - gettext_noop ("use DHT's record route option"), - &record_route), - GNUNET_GETOPT_option_uint ('t', - "type", - "TYPE", - gettext_noop ("the type to insert data as"), - &query_type), + GNUNET_GETOPT_option_string ( + 'k', + "key", + "KEY", + gettext_noop ("the query key"), + &query_key), + GNUNET_GETOPT_option_flag ( + 'x', + "demultiplex", + gettext_noop ( + "use DHT's demultiplex everywhere option"), + &demultixplex_everywhere), + GNUNET_GETOPT_option_uint ( + 'r', + "replication", + "LEVEL", + gettext_noop ("how many replicas to create"), + &replication), + GNUNET_GETOPT_option_flag ( + 'R', + "record", + gettext_noop ("use DHT's record route option"), + &record_route), + GNUNET_GETOPT_option_uint ( + 't', + "type", + "TYPE", + gettext_noop ("the type to insert data as"), + &query_type), GNUNET_GETOPT_option_verbose (&verbose), - GNUNET_GETOPT_OPTION_END }; + GNUNET_GETOPT_OPTION_END + }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != + GNUNET_STRINGS_get_utf8_args (argc, argv, + &argc, &argv)) return 2; expiration = GNUNET_TIME_UNIT_HOURS; return (GNUNET_OK == diff --git a/src/dht/gnunet-service-dht.h b/src/dht/gnunet-service-dht.h index e9b1ff63a..367ff426e 100644 --- a/src/dht/gnunet-service-dht.h +++ b/src/dht/gnunet-service-dht.h @@ -73,7 +73,7 @@ void GDS_CLIENTS_handle_reply (const struct GDS_DATACACHE_BlockData *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path); + const struct GNUNET_DHT_PathElement *get_path); /** @@ -94,7 +94,7 @@ GDS_CLIENTS_process_get (enum GNUNET_DHT_RouteOption options, uint32_t hop_count, uint32_t desired_replication_level, unsigned int path_length, - const struct GNUNET_PeerIdentity *path, + const struct GNUNET_DHT_PathElement *path, const struct GNUNET_HashCode *key); @@ -108,7 +108,7 @@ GDS_CLIENTS_process_get (enum GNUNET_DHT_RouteOption options, */ void GDS_CLIENTS_process_get_resp (const struct GDS_DATACACHE_BlockData *bd, - const struct GNUNET_PeerIdentity *get_path, + const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length); diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 245130dbc..a1c3024de 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c @@ -644,8 +644,8 @@ handle_dht_local_get (void *cls, cqr->type, 0, /* hop count */ cqr->replication, - 1, /* path length */ - GDS_NEIGHBOURS_get_id (), + 0, /* path length */ + NULL, &get->key); /* start remote requests */ if (NULL != retry_task) @@ -867,7 +867,7 @@ struct ForwardReplyContext /** * GET path taken. */ - const struct GNUNET_PeerIdentity *get_path; + const struct GNUNET_DHT_PathElement *get_path; /** * Number of entries in @e get_path. @@ -900,7 +900,7 @@ forward_reply (void *cls, enum GNUNET_BLOCK_ReplyEvaluationResult eval; bool do_free; struct GNUNET_HashCode ch; - struct GNUNET_PeerIdentity *paths; + struct GNUNET_DHT_PathElement *paths; LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "CLIENT-RESULT %s\n", @@ -989,7 +989,7 @@ forward_reply (void *cls, env = GNUNET_MQ_msg_extra (reply, frc->bd->data_size + (frc->get_path_length + frc->bd->put_path_length) - * sizeof(struct GNUNET_PeerIdentity), + * sizeof(struct GNUNET_DHT_PathElement), GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT); reply->type = htonl (frc->bd->type); reply->get_path_length = htonl (frc->get_path_length); @@ -997,13 +997,14 @@ forward_reply (void *cls, reply->unique_id = record->unique_id; reply->expiration = GNUNET_TIME_absolute_hton (frc->bd->expiration_time); reply->key = frc->bd->key; - paths = (struct GNUNET_PeerIdentity *) &reply[1]; + paths = (struct GNUNET_DHT_PathElement *) &reply[1]; GNUNET_memcpy (paths, frc->bd->put_path, - sizeof(struct GNUNET_PeerIdentity) * frc->bd->put_path_length); + sizeof(struct GNUNET_DHT_PathElement) + * frc->bd->put_path_length); GNUNET_memcpy (&paths[frc->bd->put_path_length], frc->get_path, - sizeof(struct GNUNET_PeerIdentity) * frc->get_path_length); + sizeof(struct GNUNET_DHT_PathElement) * frc->get_path_length); GNUNET_memcpy (&paths[frc->get_path_length + frc->bd->put_path_length], frc->bd->data, frc->bd->data_size); @@ -1023,13 +1024,13 @@ void GDS_CLIENTS_handle_reply (const struct GDS_DATACACHE_BlockData *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path) + const struct GNUNET_DHT_PathElement *get_path) { struct ForwardReplyContext frc; size_t msize = sizeof (struct GNUNET_DHT_ClientResultMessage) + bd->data_size + (get_path_length + bd->put_path_length) - * sizeof(struct GNUNET_PeerIdentity); + * sizeof(struct GNUNET_DHT_PathElement); if (msize >= GNUNET_MAX_MESSAGE_SIZE) { @@ -1203,7 +1204,7 @@ struct GetActionContext uint32_t hop_count; uint32_t desired_replication_level; unsigned int get_path_length; - const struct GNUNET_PeerIdentity *get_path; + const struct GNUNET_DHT_PathElement *get_path; const struct GNUNET_HashCode *key; }; @@ -1222,10 +1223,10 @@ get_action (void *cls, struct GetActionContext *gac = cls; struct GNUNET_MQ_Envelope *env; struct GNUNET_DHT_MonitorGetMessage *mmsg; - struct GNUNET_PeerIdentity *msg_path; + struct GNUNET_DHT_PathElement *msg_path; size_t msize; - msize = gac->get_path_length * sizeof(struct GNUNET_PeerIdentity); + msize = gac->get_path_length * sizeof(struct GNUNET_DHT_PathElement); env = GNUNET_MQ_msg_extra (mmsg, msize, GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET); @@ -1235,10 +1236,10 @@ get_action (void *cls, mmsg->desired_replication_level = htonl (gac->desired_replication_level); mmsg->get_path_length = htonl (gac->get_path_length); mmsg->key = *gac->key; - msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1]; + msg_path = (struct GNUNET_DHT_PathElement *) &mmsg[1]; GNUNET_memcpy (msg_path, gac->get_path, - gac->get_path_length * sizeof(struct GNUNET_PeerIdentity)); + gac->get_path_length * sizeof(struct GNUNET_DHT_PathElement)); GNUNET_MQ_send (m->ch->mq, env); } @@ -1262,7 +1263,7 @@ GDS_CLIENTS_process_get (enum GNUNET_DHT_RouteOption options, uint32_t hop_count, uint32_t desired_replication_level, unsigned int path_length, - const struct GNUNET_PeerIdentity *path, + const struct GNUNET_DHT_PathElement *path, const struct GNUNET_HashCode *key) { struct GetActionContext gac = { @@ -1288,7 +1289,7 @@ GDS_CLIENTS_process_get (enum GNUNET_DHT_RouteOption options, struct ResponseActionContext { const struct GDS_DATACACHE_BlockData *bd; - const struct GNUNET_PeerIdentity *get_path; + const struct GNUNET_DHT_PathElement *get_path; unsigned int get_path_length; }; @@ -1309,12 +1310,12 @@ response_action (void *cls, struct GNUNET_MQ_Envelope *env; struct GNUNET_DHT_MonitorGetRespMessage *mmsg; - struct GNUNET_PeerIdentity *path; + struct GNUNET_DHT_PathElement *path; size_t msize; msize = bd->data_size; msize += (resp_ctx->get_path_length + bd->put_path_length) - * sizeof(struct GNUNET_PeerIdentity); + * sizeof(struct GNUNET_DHT_PathElement); env = GNUNET_MQ_msg_extra (mmsg, msize, GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP); @@ -1323,14 +1324,14 @@ response_action (void *cls, mmsg->get_path_length = htonl (resp_ctx->get_path_length); mmsg->expiration_time = GNUNET_TIME_absolute_hton (bd->expiration_time); mmsg->key = bd->key; - path = (struct GNUNET_PeerIdentity *) &mmsg[1]; + path = (struct GNUNET_DHT_PathElement *) &mmsg[1]; GNUNET_memcpy (path, bd->put_path, - bd->put_path_length * sizeof(struct GNUNET_PeerIdentity)); + bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement)); GNUNET_memcpy (path, resp_ctx->get_path, resp_ctx->get_path_length * sizeof(struct - GNUNET_PeerIdentity)); + GNUNET_DHT_PathElement)); GNUNET_memcpy (&path[resp_ctx->get_path_length], bd->data, bd->data_size); @@ -1341,7 +1342,7 @@ response_action (void *cls, void GDS_CLIENTS_process_get_resp (const struct GDS_DATACACHE_BlockData *bd, - const struct GNUNET_PeerIdentity *get_path, + const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length) { struct ResponseActionContext rac = { @@ -1384,12 +1385,12 @@ put_action (void *cls, const struct GDS_DATACACHE_BlockData *bd = put_ctx->bd; struct GNUNET_MQ_Envelope *env; struct GNUNET_DHT_MonitorPutMessage *mmsg; - struct GNUNET_PeerIdentity *msg_path; + struct GNUNET_DHT_PathElement *msg_path; size_t msize; msize = bd->data_size + bd->put_path_length - * sizeof(struct GNUNET_PeerIdentity); + * sizeof(struct GNUNET_DHT_PathElement); env = GNUNET_MQ_msg_extra (mmsg, msize, GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT); @@ -1400,10 +1401,10 @@ put_action (void *cls, mmsg->put_path_length = htonl (bd->put_path_length); mmsg->key = bd->key; mmsg->expiration_time = GNUNET_TIME_absolute_hton (bd->expiration_time); - msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1]; + msg_path = (struct GNUNET_DHT_PathElement *) &mmsg[1]; GNUNET_memcpy (msg_path, bd->put_path, - bd->put_path_length * sizeof(struct GNUNET_PeerIdentity)); + bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement)); GNUNET_memcpy (&msg_path[bd->put_path_length], bd->data, bd->data_size); diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index 214c4a3f4..cb778717b 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c @@ -152,7 +152,7 @@ datacache_get_iterator (void *cls, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute exp, unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path) + const struct GNUNET_DHT_PathElement *put_path) { struct GetRequestContext *ctx = cls; enum GNUNET_BLOCK_ReplyEvaluationResult eval; @@ -301,7 +301,8 @@ datacache_get_successors_iterator (void *cls, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute exp, unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path) + const struct + GNUNET_DHT_PathElement *put_path) { const struct SuccContext *sc = cls; struct GDS_DATACACHE_BlockData bd = { diff --git a/src/dht/gnunet-service-dht_datacache.h b/src/dht/gnunet-service-dht_datacache.h index 249bb8ee3..691a51e0e 100644 --- a/src/dht/gnunet-service-dht_datacache.h +++ b/src/dht/gnunet-service-dht_datacache.h @@ -50,7 +50,7 @@ struct GDS_DATACACHE_BlockData /** * PUT path taken by the block, array of peer identities. */ - const struct GNUNET_PeerIdentity *put_path; + const struct GNUNET_DHT_PathElement *put_path; /** * Actual block data. diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 35502e0f5..e100ae2ee 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -345,11 +345,6 @@ struct ConnectInfo */ static int cache_results; -/** - * Should routing details be logged to stderr (for debugging)? - */ -static int log_route_details_stderr; - /** * The lowest currently used bucket, initially 0 (for 0-bits matching bucket). */ @@ -1437,7 +1432,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, struct GNUNET_MQ_Envelope *env; struct PeerGetMessage *pgm; char *xq; - + if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) { /* skip */ @@ -1503,20 +1498,20 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, const struct GDS_DATACACHE_BlockData *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path) + const struct GNUNET_DHT_PathElement *get_path) { struct GNUNET_MQ_Envelope *env; struct PeerResultMessage *prm; - struct GNUNET_PeerIdentity *paths; + struct GNUNET_DHT_PathElement *paths; size_t msize; msize = bd->data_size + (get_path_length + bd->put_path_length) - * sizeof(struct GNUNET_PeerIdentity); + * sizeof(struct GNUNET_DHT_PathElement); if ( (msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) || (get_path_length > - GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || + GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || (bd->put_path_length > - GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || + GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || (bd->data_size > GNUNET_MAX_MESSAGE_SIZE)) { GNUNET_break (0); @@ -1551,13 +1546,13 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, prm->get_path_length = htonl (get_path_length); prm->expiration_time = GNUNET_TIME_absolute_hton (bd->expiration_time); prm->key = *query_hash; - paths = (struct GNUNET_PeerIdentity *) &prm[1]; + paths = (struct GNUNET_DHT_PathElement *) &prm[1]; GNUNET_memcpy (paths, bd->put_path, - bd->put_path_length * sizeof(struct GNUNET_PeerIdentity)); + bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement)); GNUNET_memcpy (&paths[bd->put_path_length], get_path, - get_path_length * sizeof(struct GNUNET_PeerIdentity)); + get_path_length * sizeof(struct GNUNET_DHT_PathElement)); GNUNET_memcpy (&paths[bd->put_path_length + get_path_length], bd->data, bd->data_size); @@ -1582,7 +1577,7 @@ core_init (void *cls, GNUNET_i2s (identity)); my_identity = *identity; GNUNET_CRYPTO_hash (identity, - sizeof(struct GNUNET_PeerIdentity), + sizeof(struct GNUNET_PeerIdentity), &my_identity_hash); GNUNET_SERVICE_resume (GDS_service); } @@ -1605,9 +1600,9 @@ check_dht_p2p_put (void *cls, (void) cls; if ( (msize < sizeof(struct PeerPutMessage) - + putlen * sizeof(struct GNUNET_PeerIdentity)) || + + putlen * sizeof(struct GNUNET_DHT_PathElement)) || (putlen > - GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ) + GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) ) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -1635,13 +1630,13 @@ handle_dht_p2p_put (void *cls, .expiration_time = GNUNET_TIME_absolute_ntoh (put->expiration_time), .type = ntohl (put->type) }; - const struct GNUNET_PeerIdentity *put_path - = (const struct GNUNET_PeerIdentity *) &put[1]; + const struct GNUNET_DHT_PathElement *put_path + = (const struct GNUNET_DHT_PathElement *) &put[1]; uint32_t putlen = ntohl (put->put_path_length); bd.data_size = msize - (sizeof(*put) - + putlen * sizeof(struct GNUNET_PeerIdentity)); + + putlen * sizeof(struct GNUNET_DHT_PathElement)); bd.data = &put_path[putlen]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT for `%s' from %s\n", @@ -1663,35 +1658,6 @@ handle_dht_p2p_put (void *cls, "# P2P PUT bytes received", msize, GNUNET_NO); - if (GNUNET_YES == log_route_details_stderr) - { - char *tmp; - char *pp; - struct GNUNET_HashCode mxor; - struct GNUNET_HashCode pxor; - - GNUNET_CRYPTO_hash_xor (&my_identity_hash, - &put->key, - &mxor); - GNUNET_CRYPTO_hash_xor (&peer->phash, - &put->key, - &pxor); - pp = GNUNET_STRINGS_pp2s (put_path, - putlen); - tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); - LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, - "R5N PUT %s: %s->%s (%u, %u=>%u, PP: %s)\n", - GNUNET_h2s (&put->key), - GNUNET_i2s (peer->id), - tmp, - ntohl (put->hop_count), - GNUNET_CRYPTO_hash_count_leading_zeros (&pxor), - GNUNET_CRYPTO_hash_count_leading_zeros (&mxor), - pp); - GNUNET_free (pp); - GNUNET_free (tmp); - } - { struct GNUNET_HashCode test_key; enum GNUNET_GenericReturnValue ret; @@ -1733,7 +1699,7 @@ handle_dht_p2p_put (void *cls, { struct GNUNET_CONTAINER_BloomFilter *bf; - struct GNUNET_PeerIdentity pp[putlen + 1]; + struct GNUNET_DHT_PathElement pp[putlen + 1]; bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, DHT_BLOOM_SIZE, @@ -1742,7 +1708,7 @@ handle_dht_p2p_put (void *cls, GNUNET_CONTAINER_bloomfilter_test (bf, &peer->phash)); /* extend 'put path' by sender */ - bd.put_path = (const struct GNUNET_PeerIdentity *) pp; + bd.put_path = (const struct GNUNET_DHT_PathElement *) pp; bd.put_path_length = putlen + 1; if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) { @@ -1752,18 +1718,22 @@ handle_dht_p2p_put (void *cls, for (unsigned int j = 0; j < i; j++) { GNUNET_break (0 != - GNUNET_memcmp (&pp[i], - &pp[j])); + GNUNET_memcmp (&pp[i].pred, + &pp[j].pred)); } GNUNET_break (0 != - GNUNET_memcmp (&pp[i], + GNUNET_memcmp (&pp[i].pred, peer->id)); } #endif GNUNET_memcpy (pp, put_path, - putlen * sizeof(struct GNUNET_PeerIdentity)); - pp[putlen] = *peer->id; + putlen * sizeof(struct GNUNET_DHT_PathElement)); + pp[putlen].pred = *peer->id; + /* zero-out signature, not valid until we actually do forward! */ + memset (&pp[putlen].sig, + 0, + sizeof (pp[putlen].sig)); putlen++; } else @@ -1938,17 +1908,6 @@ handle_local_result (void *cls, { struct PeerInfo *peer = cls; - { - char *pp; - - pp = GNUNET_STRINGS_pp2s (bd->put_path, - bd->put_path_length); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found local result for %s (PP: %s)\n", - GNUNET_h2s (&bd->key), - pp); - GNUNET_free (pp); - } GDS_NEIGHBOURS_handle_reply (peer, bd, &bd->key, @@ -1996,7 +1955,8 @@ handle_dht_p2p_get (void *cls, uint32_t hop_count = ntohl (get->hop_count); size_t reply_bf_size = msize - (sizeof(*get) + xquery_size); enum GNUNET_BLOCK_Type type = (enum GNUNET_BLOCK_Type) ntohl (get->type); - enum GNUNET_DHT_RouteOption options = (enum GNUNET_DHT_RouteOption) ntohl (get->options); + enum GNUNET_DHT_RouteOption options = (enum GNUNET_DHT_RouteOption) ntohl ( + get->options); enum GNUNET_BLOCK_ReplyEvaluationResult eval = GNUNET_BLOCK_REPLY_OK_MORE; const void *xquery = (const void *) &get[1]; @@ -2009,31 +1969,6 @@ handle_dht_p2p_get (void *cls, "# P2P GET bytes received", msize, GNUNET_NO); - if (GNUNET_YES == log_route_details_stderr) - { - char *tmp; - struct GNUNET_HashCode mxor; - struct GNUNET_HashCode pxor; - - GNUNET_CRYPTO_hash_xor (&my_identity_hash, - &get->key, - &mxor); - GNUNET_CRYPTO_hash_xor (&peer->phash, - &get->key, - &pxor); - tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); - LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, - "R5N GET %s: %s->%s (%u, %u=>%u) xq: %.*s\n", - GNUNET_h2s (&get->key), - GNUNET_i2s (peer->id), - tmp, - hop_count, - GNUNET_CRYPTO_hash_count_leading_zeros (&pxor), - GNUNET_CRYPTO_hash_count_leading_zeros (&mxor), - ntohl (get->xquery_size), - (const char *) xquery); - GNUNET_free (tmp); - } if (GNUNET_NO == GNUNET_BLOCK_check_query (GDS_block_context, type, @@ -2096,13 +2031,13 @@ handle_dht_p2p_get (void *cls, } } else - { - GNUNET_STATISTICS_update (GDS_stats, - "# P2P GET requests ONLY routed", - 1, - GNUNET_NO); - } - + { + GNUNET_STATISTICS_update (GDS_stats, + "# P2P GET requests ONLY routed", + 1, + GNUNET_NO); + } + /* remember request for routing replies */ GDS_ROUTING_add (peer->id, type, @@ -2115,7 +2050,8 @@ handle_dht_p2p_get (void *cls, /* P2P forwarding */ { bool forwarded = false; - uint32_t desired_replication_level = ntohl (get->desired_replication_level); + uint32_t desired_replication_level = ntohl ( + get->desired_replication_level); if (eval != GNUNET_BLOCK_REPLY_OK_LAST) forwarded = (GNUNET_OK == @@ -2129,8 +2065,8 @@ handle_dht_p2p_get (void *cls, bg, peer_bf)); GDS_CLIENTS_process_get ( - options | - (forwarded + options + | (forwarded ? 0 : GNUNET_DHT_RO_LAST_HOP), type, @@ -2158,7 +2094,7 @@ static void process_reply_with_path (const struct GDS_DATACACHE_BlockData *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path) + const struct GNUNET_DHT_PathElement *get_path) { /* forward to local clients */ GDS_CLIENTS_handle_reply (bd, @@ -2170,16 +2106,16 @@ process_reply_with_path (const struct GDS_DATACACHE_BlockData *bd, get_path_length); if (GNUNET_YES == cache_results) { - struct GNUNET_PeerIdentity xput_path[GNUNET_NZL (get_path_length - + bd->put_path_length)]; + struct GNUNET_DHT_PathElement xput_path[GNUNET_NZL (get_path_length + + bd->put_path_length)]; struct GDS_DATACACHE_BlockData bdx = *bd; GNUNET_memcpy (xput_path, bd->put_path, - bd->put_path_length * sizeof(struct GNUNET_PeerIdentity)); + bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement)); GNUNET_memcpy (&xput_path[bd->put_path_length], get_path, - get_path_length * sizeof(struct GNUNET_PeerIdentity)); + get_path_length * sizeof(struct GNUNET_DHT_PathElement)); bdx.put_path = xput_path; bdx.put_path_length += get_path_length; GDS_DATACACHE_handle_put (&bdx); @@ -2211,11 +2147,11 @@ check_dht_p2p_result (void *cls, if ( (msize < sizeof(struct PeerResultMessage) + (get_path_length + put_path_length) - * sizeof(struct GNUNET_PeerIdentity)) || + * sizeof(struct GNUNET_DHT_PathElement)) || (get_path_length > - GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || + GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || (put_path_length > - GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ) + GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) ) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -2239,11 +2175,11 @@ handle_dht_p2p_result (void *cls, uint32_t get_path_length = ntohl (prm->get_path_length); struct GDS_DATACACHE_BlockData bd = { .expiration_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time), - .put_path = (const struct GNUNET_PeerIdentity *) &prm[1], + .put_path = (const struct GNUNET_DHT_PathElement *) &prm[1], .put_path_length = ntohl (prm->put_path_length), .type = ntohl (prm->type) }; - const struct GNUNET_PeerIdentity *get_path + const struct GNUNET_DHT_PathElement *get_path = &bd.put_path[bd.put_path_length]; /* parse and validate message */ @@ -2259,7 +2195,7 @@ handle_dht_p2p_result (void *cls, bd.data = (const void *) &get_path[get_path_length]; bd.data_size = msize - (sizeof(struct PeerResultMessage) + (get_path_length + bd.put_path_length) - * sizeof(struct GNUNET_PeerIdentity)); + * sizeof(struct GNUNET_DHT_PathElement)); GNUNET_STATISTICS_update (GDS_stats, "# P2P RESULTS received", 1, @@ -2295,29 +2231,6 @@ handle_dht_p2p_result (void *cls, } } - if (GNUNET_YES == log_route_details_stderr) - { - char *tmp; - char *pp; - char *gp; - - gp = GNUNET_STRINGS_pp2s (get_path, - get_path_length); - pp = GNUNET_STRINGS_pp2s (bd.put_path, - bd.put_path_length); - tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); - LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, - "R5N RESULT %s: %s->%s (GP: %s, PP: %s)\n", - GNUNET_h2s (&prm->key), - GNUNET_i2s (peer->id), - tmp, - gp, - pp); - GNUNET_free (gp); - GNUNET_free (pp); - GNUNET_free (tmp); - } - /* if we got a HELLO, consider it for our own routing table */ if (GNUNET_BLOCK_TYPE_DHT_HELLO == bd.type) { @@ -2352,7 +2265,7 @@ handle_dht_p2p_result (void *cls, /* First, check if 'peer' is already on the path, and if so, truncate it instead of expanding. */ for (unsigned int i = 0; i <= get_path_length; i++) - if (0 == GNUNET_memcmp (&get_path[i], + if (0 == GNUNET_memcmp (&get_path[i].pred, peer->id)) { process_reply_with_path (&bd, @@ -2363,12 +2276,15 @@ handle_dht_p2p_result (void *cls, /* Need to append 'peer' to 'get_path' (normal case) */ { - struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; + struct GNUNET_DHT_PathElement xget_path[get_path_length + 1]; GNUNET_memcpy (xget_path, get_path, - get_path_length * sizeof(struct GNUNET_PeerIdentity)); - xget_path[get_path_length] = *peer->id; + get_path_length * sizeof(struct GNUNET_DHT_PathElement)); + xget_path[get_path_length].pred = *peer->id; + memset (&xget_path[get_path_length].sig, + 0, + sizeof (xget_path[get_path_length].sig)); process_reply_with_path (&bd, &prm->key, get_path_length + 1, xget_path); @@ -2411,8 +2327,6 @@ GDS_NEIGHBOURS_init () "DHT", "CACHE_RESULTS"); - log_route_details_stderr = - (NULL != getenv ("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO; ats_ch = GNUNET_ATS_connectivity_init (GDS_cfg); core_api = GNUNET_CORE_connect (GDS_cfg, NULL, diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h index 28468c740..35bbb125d 100644 --- a/src/dht/gnunet-service-dht_neighbours.h +++ b/src/dht/gnunet-service-dht_neighbours.h @@ -42,7 +42,7 @@ struct PeerInfo; /** * Lookup peer by peer's identity. - * + * * @param target peer to look up * @return NULL if we are not connected to @a target */ @@ -118,7 +118,7 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, const struct GDS_DATACACHE_BlockData *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path); + const struct GNUNET_DHT_PathElement *get_path); /** diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c index ec36eae75..e7b5c3571 100644 --- a/src/dht/gnunet-service-dht_routing.c +++ b/src/dht/gnunet-service-dht_routing.c @@ -109,7 +109,7 @@ struct ProcessContext /** * Path of the reply. */ - const struct GNUNET_PeerIdentity *get_path; + const struct GNUNET_DHT_PathElement *get_path; /** * Number of entries in @e get_path. @@ -181,7 +181,7 @@ process (void *cls, case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED: { struct PeerInfo *pi; - + GNUNET_STATISTICS_update (GDS_stats, "# Good REPLIES matched against routing table", 1, @@ -244,7 +244,7 @@ void GDS_ROUTING_process (const struct GDS_DATACACHE_BlockData *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path) + const struct GNUNET_DHT_PathElement *get_path) { struct ProcessContext pc = { .bd = bd, diff --git a/src/dht/gnunet-service-dht_routing.h b/src/dht/gnunet-service-dht_routing.h index 1a1514cc5..1e35f3dc0 100644 --- a/src/dht/gnunet-service-dht_routing.h +++ b/src/dht/gnunet-service-dht_routing.h @@ -47,7 +47,7 @@ void GDS_ROUTING_process (const struct GDS_DATACACHE_BlockData *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path); + const struct GNUNET_DHT_PathElement *get_path); /** diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index ba50c3d1a..bac101bdd 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c @@ -469,9 +469,9 @@ static void get_iter (void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, - const struct GNUNET_PeerIdentity *get_path, + const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, + const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data) diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 957c71d7f..4d557bba8 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c @@ -87,9 +87,9 @@ static void test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, - const struct GNUNET_PeerIdentity *get_path, + const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, + const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, diff --git a/src/dht/test_dht_monitor.c b/src/dht/test_dht_monitor.c index 95fb37bcd..8af02ad8a 100644 --- a/src/dht/test_dht_monitor.c +++ b/src/dht/test_dht_monitor.c @@ -174,9 +174,9 @@ timeout_task_cb (void *cls) static void dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, - const struct GNUNET_PeerIdentity *get_path, + const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, + const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data) @@ -261,7 +261,7 @@ monitor_get_cb (void *cls, uint32_t hop_count, uint32_t desired_replication_level, unsigned int path_length, - const struct GNUNET_PeerIdentity *path, + const struct GNUNET_DHT_PathElement *path, const struct GNUNET_HashCode *key) { unsigned int i; @@ -298,7 +298,7 @@ monitor_put_cb (void *cls, uint32_t hop_count, uint32_t desired_replication_level, unsigned int path_length, - const struct GNUNET_PeerIdentity *path, + const struct GNUNET_DHT_PathElement *path, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const void *data, @@ -334,9 +334,9 @@ monitor_put_cb (void *cls, static void monitor_res_cb (void *cls, enum GNUNET_BLOCK_Type type, - const struct GNUNET_PeerIdentity *get_path, + const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, + const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c index 7f737ea03..dfe969bb9 100644 --- a/src/dht/test_dht_topo.c +++ b/src/dht/test_dht_topo.c @@ -302,9 +302,9 @@ static void dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, - const struct GNUNET_PeerIdentity *get_path, + const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, + const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, -- cgit v1.2.3