[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: -start to use new block API in DHT
From: |
gnunet |
Subject: |
[gnunet] branch master updated: -start to use new block API in DHT |
Date: |
Wed, 29 Dec 2021 20:16:03 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 985931420 -start to use new block API in DHT
985931420 is described below
commit 9859314207ad10e37b73eacd5dfccac59ec8153e
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Dec 29 20:16:01 2021 +0100
-start to use new block API in DHT
---
src/dht/dht_api.c | 3 +-
src/dht/gnunet-service-dht.h | 4 +-
src/dht/gnunet-service-dht_clients.c | 144 +++++++++---------
src/dht/gnunet-service-dht_datacache.c | 72 +++------
src/dht/gnunet-service-dht_neighbours.c | 253 +++++++++++++++-----------------
src/dht/gnunet-service-dht_routing.c | 128 +++++++---------
src/include/gnunet_block_lib.h | 12 +-
7 files changed, 271 insertions(+), 345 deletions(-)
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 96399cb5a..727f1a1f6 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -1048,8 +1048,7 @@ GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph)
/**
- * Perform an asynchronous GET operation on the DHT identified. See
- * also #GNUNET_BLOCK_evaluate.
+ * Perform an asynchronous GET operation on the DHT identified.
*
* @param handle handle to the DHT service
* @param type expected type of the response object
diff --git a/src/dht/gnunet-service-dht.h b/src/dht/gnunet-service-dht.h
index 6741efb4e..a366367ca 100644
--- a/src/dht/gnunet-service-dht.h
+++ b/src/dht/gnunet-service-dht.h
@@ -65,7 +65,8 @@ extern struct GNUNET_MessageHeader *GDS_my_hello;
* client(s).
*
* @param expiration when will the reply expire
- * @param key the query this reply is for
+ * @param key the key of the query that triggered the reply
+ * @param query_hash the query hash of the response
* @param get_path_length number of peers in @a get_path
* @param get_path path the reply took on get
* @param put_path_length number of peers in @a put_path
@@ -77,6 +78,7 @@ extern struct GNUNET_MessageHeader *GDS_my_hello;
void
GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
const struct GNUNET_HashCode *key,
+ const struct GNUNET_HashCode *query_hash,
unsigned int get_path_length,
const struct GNUNET_PeerIdentity *get_path,
unsigned int put_path_length,
diff --git a/src/dht/gnunet-service-dht_clients.c
b/src/dht/gnunet-service-dht_clients.c
index cfcb25336..feccde8a8 100644
--- a/src/dht/gnunet-service-dht_clients.c
+++ b/src/dht/gnunet-service-dht_clients.c
@@ -125,6 +125,8 @@ struct ClientQueryRecord
/**
* Any message options for this request
+ *
+ * FIXME: why uint32_t instead of enum?
*/
uint32_t msg_options;
@@ -492,6 +494,7 @@ handle_dht_local_put (void *cls,
(unsigned long) (size - sizeof(struct GNUNET_DHT_ClientPutMessage)),
GNUNET_h2s (&dht_msg->key));
GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
+ &dht_msg->key,
&dht_msg->key,
0,
NULL,
@@ -584,6 +587,7 @@ handle_local_result (void *cls,
// FIXME: this needs some clean up: inline the function,
// possibly avoid even looking up the client!
GDS_CLIENTS_handle_reply (expiration_time,
+ key,
key,
0, NULL,
put_path_length, put_path,
@@ -966,6 +970,11 @@ struct ForwardReplyContext
*/
const struct GNUNET_PeerIdentity *put_path;
+ /**
+ * Hash under which the payload is stored.
+ */
+ const struct GNUNET_HashCode *query_hash;
+
/**
* Embedded payload.
*/
@@ -1004,7 +1013,7 @@ struct ForwardReplyContext
* @return #GNUNET_YES (we should continue to iterate),
* if the result is mal-formed, #GNUNET_NO
*/
-static int
+static enum GNUNET_GenericReturnValue
forward_reply (void *cls,
const struct GNUNET_HashCode *key,
void *value)
@@ -1013,14 +1022,14 @@ forward_reply (void *cls,
struct ClientQueryRecord *record = value;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_DHT_ClientResultMessage *reply;
- enum GNUNET_BLOCK_EvaluationResult eval;
- int do_free;
+ enum GNUNET_BLOCK_ReplyEvaluationResult eval;
+ bool do_free;
struct GNUNET_HashCode ch;
struct GNUNET_PeerIdentity *paths;
LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG,
"CLIENT-RESULT %s\n",
- GNUNET_h2s_full (key));
+ GNUNET_h2s_full (frc->query_hash));
if ((record->type != GNUNET_BLOCK_TYPE_ANY) &&
(record->type != frc->type))
{
@@ -1028,13 +1037,24 @@ forward_reply (void *cls,
"Record type mismatch, not passing request for key %s to local
client\n",
GNUNET_h2s (key));
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop
- (
- "# Key match, type mismatches in REPLY to
CLIENT"),
- 1, GNUNET_NO);
+ "# Key match, type mismatches in REPLY to
CLIENT",
+ 1,
+ GNUNET_NO);
return GNUNET_YES; /* type mismatch */
}
- GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch);
+ if ( (0 == (record->msg_options & GNUNET_DHT_RO_FIND_PEER)) &&
+ (0 != GNUNET_memcmp (key,
+ frc->query_hash)) )
+ {
+ GNUNET_STATISTICS_update (GDS_stats,
+ "# Inexact key match, but exact match required",
+ 1,
+ GNUNET_NO);
+ return GNUNET_YES; /* type mismatch */
+ }
+ GNUNET_CRYPTO_hash (frc->data,
+ frc->data_size,
+ &ch);
for (unsigned int i = 0; i < record->seen_replies_count; i++)
if (0 == memcmp (&record->seen_replies[i],
&ch,
@@ -1051,63 +1071,45 @@ forward_reply (void *cls,
return GNUNET_YES; /* duplicate */
}
eval
- = GNUNET_BLOCK_evaluate (GDS_block_context,
- record->type,
- NULL,
- GNUNET_BLOCK_EO_NONE,
- key,
- record->xquery,
- record->xquery_size,
- frc->data,
- frc->data_size);
+ = GNUNET_BLOCK_check_reply (GDS_block_context,
+ record->type,
+ NULL,
+ key,
+ record->xquery,
+ record->xquery_size,
+ frc->data,
+ frc->data_size);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Evaluation result is %d for key %s for local client's query\n",
(int) eval,
GNUNET_h2s (key));
switch (eval)
{
- case GNUNET_BLOCK_EVALUATION_OK_LAST:
- do_free = GNUNET_YES;
+ case GNUNET_BLOCK_REPLY_OK_LAST:
+ do_free = true;
break;
-
- case GNUNET_BLOCK_EVALUATION_OK_MORE:
+ case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED:
+ case GNUNET_BLOCK_REPLY_OK_MORE:
GNUNET_array_append (record->seen_replies,
record->seen_replies_count,
ch);
- do_free = GNUNET_NO;
+ do_free = false;
break;
-
- case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
+ case GNUNET_BLOCK_REPLY_OK_DUPLICATE:
/* should be impossible to encounter here */
GNUNET_break (0);
return GNUNET_YES;
-
- case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
+ case GNUNET_BLOCK_REPLY_INVALID:
GNUNET_break_op (0);
return GNUNET_NO;
-
- case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
- GNUNET_break (0);
- return GNUNET_NO;
-
- case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
- GNUNET_break (0);
- return GNUNET_NO;
-
- case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
+ case GNUNET_BLOCK_REPLY_IRRELEVANT:
return GNUNET_YES;
-
- case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _ ("Unsupported block type (%u) in request!\n"), record->type);
- return GNUNET_NO;
-
default:
GNUNET_break (0);
return GNUNET_NO;
}
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# RESULTS queued for clients"),
+ "# RESULTS queued for clients",
1,
GNUNET_NO);
env = GNUNET_MQ_msg_extra (reply,
@@ -1149,7 +1151,8 @@ forward_reply (void *cls,
* client(s).
*
* @param expiration when will the reply expire
- * @param key the query this reply is for
+ * @param key the key of the query that triggered the reply
+ * @param query_hash the query hash of the response
* @param get_path_length number of peers in @a get_path
* @param get_path path the reply took on get
* @param put_path_length number of peers in @a put_path
@@ -1161,6 +1164,7 @@ forward_reply (void *cls,
void
GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
const struct GNUNET_HashCode *key,
+ const struct GNUNET_HashCode *query_hash,
unsigned int get_path_length,
const struct GNUNET_PeerIdentity *get_path,
unsigned int put_path_length,
@@ -1173,27 +1177,15 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute
expiration,
size_t msize;
msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size
- + (get_path_length + put_path_length) * sizeof(struct
- GNUNET_PeerIdentity);
+ + (get_path_length + put_path_length)
+ * sizeof(struct GNUNET_PeerIdentity);
if (msize >= GNUNET_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
return;
}
- if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map,
- key))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "No matching client for reply for key %s\n",
- GNUNET_h2s (key));
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop (
- "# REPLIES ignored for CLIENTS (no match)"),
- 1,
- GNUNET_NO);
- return; /* no matching request, fast exit! */
- }
frc.expiration = expiration;
+ frc.query_hash = query_hash;
frc.get_path = get_path;
frc.put_path = put_path;
frc.data = data;
@@ -1204,10 +1196,20 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute
expiration,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Forwarding reply for key %s to client\n",
GNUNET_h2s (key));
- GNUNET_CONTAINER_multihashmap_get_multiple (forward_map,
- key,
- &forward_reply,
- &frc);
+ if (0 ==
+ GNUNET_CONTAINER_multihashmap_get_multiple (forward_map,
+ key,
+ &forward_reply,
+ &frc))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "No matching client for reply for key %s\n",
+ GNUNET_h2s (key));
+ GNUNET_STATISTICS_update (GDS_stats,
+ "# REPLIES ignored for CLIENTS (no match)",
+ 1,
+ GNUNET_NO);
+ }
}
@@ -1285,20 +1287,6 @@ GDS_CLIENTS_process_get (uint32_t options,
}
-/**
- * Check if some client is monitoring GET RESP messages and notify
- * them in that case.
- *
- * @param type The type of data in the result.
- * @param get_path Peers on GET path (or NULL if not recorded).
- * @param get_path_length number of entries in get_path.
- * @param put_path peers on the PUT path (or NULL if not recorded).
- * @param put_path_length number of entries in get_path.
- * @param exp Expiration time of the data.
- * @param key Key of the data.
- * @param data Pointer to the result data.
- * @param size Number of bytes in @a data.
- */
void
GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type,
const struct GNUNET_PeerIdentity *get_path,
diff --git a/src/dht/gnunet-service-dht_datacache.c
b/src/dht/gnunet-service-dht_datacache.c
index 7eded2152..8645ea069 100644
--- a/src/dht/gnunet-service-dht_datacache.c
+++ b/src/dht/gnunet-service-dht_datacache.c
@@ -158,7 +158,7 @@ struct GetRequestContext
* @return #GNUNET_OK to continue iteration, anything else
* to stop iteration.
*/
-static int
+static enum GNUNET_GenericReturnValue
datacache_get_iterator (void *cls,
const struct GNUNET_HashCode *key,
size_t data_size,
@@ -170,7 +170,7 @@ datacache_get_iterator (void *cls,
{
static char non_null;
struct GetRequestContext *ctx = cls;
- enum GNUNET_BLOCK_EvaluationResult eval;
+ enum GNUNET_BLOCK_ReplyEvaluationResult eval;
if (0 == GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
{
@@ -182,15 +182,14 @@ datacache_get_iterator (void *cls,
data = &non_null; /* point anywhere, but not to NULL */
eval
- = GNUNET_BLOCK_evaluate (GDS_block_context,
- type,
- ctx->bg,
- GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO,
- key,
- ctx->xquery,
- ctx->xquery_size,
- data,
- data_size);
+ = GNUNET_BLOCK_check_reply (GDS_block_context,
+ type,
+ ctx->bg,
+ key,
+ ctx->xquery,
+ ctx->xquery_size,
+ data,
+ data_size);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Found reply for query %s in datacache, evaluation result is %d\n",
GNUNET_h2s (key),
@@ -198,12 +197,13 @@ datacache_get_iterator (void *cls,
ctx->eval = eval;
switch (eval)
{
- case GNUNET_BLOCK_EVALUATION_OK_MORE:
- case GNUNET_BLOCK_EVALUATION_OK_LAST:
- /* forward to local clients */
+ case GNUNET_BLOCK_REPLY_OK_MORE:
+ case GNUNET_BLOCK_REPLY_OK_LAST:
+ case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED:
+ /* forward to initiator */
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop
- ("# Good RESULTS found in datacache"), 1,
+ "# Good RESULTS found in datacache",
+ 1,
GNUNET_NO);
ctx->gc (ctx->gc_cls,
type,
@@ -213,51 +213,27 @@ datacache_get_iterator (void *cls,
0, NULL,
data, data_size);
break;
-
- case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
+ case GNUNET_BLOCK_REPLY_OK_DUPLICATE:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop (
- "# Duplicate RESULTS found in datacache"),
+ "# Duplicate RESULTS found in datacache",
1,
GNUNET_NO);
break;
-
- case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
+ case GNUNET_BLOCK_REPLY_INVALID:
+ /* maybe it expired? */
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop (
- "# Invalid RESULTS found in datacache"),
+ "# Invalid RESULTS found in datacache",
1,
GNUNET_NO);
break;
-
- case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
+ case GNUNET_BLOCK_REPLY_IRRELEVANT:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop (
- "# Irrelevant RESULTS found in datacache"),
+ "# Irrelevant RESULTS found in datacache",
1,
GNUNET_NO);
break;
-
- case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
- GNUNET_break (0);
- break;
-
- case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
-
- case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop (
- "# Unsupported RESULTS found in datacache"),
- 1,
- GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _ ("Unsupported block type (%u) in local response!\n"),
- type);
- break;
}
- return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK;
+ return (eval == GNUNET_BLOCK_REPLY_OK_LAST) ? GNUNET_NO : GNUNET_OK;
}
diff --git a/src/dht/gnunet-service-dht_neighbours.c
b/src/dht/gnunet-service-dht_neighbours.c
index fb061d5b1..75bdaed53 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -424,7 +424,7 @@ static struct GNUNET_ATS_ConnectivityHandle *ats_ch;
* Find the optimal bucket for this key.
*
* @param hc the hashcode to compare our identity to
- * @return the proper bucket index, or #GNUNET_SYSERR
+ * @return the proper bucket index, or -1
* on error (same hashcode)
*/
static int
@@ -437,7 +437,7 @@ find_bucket (const struct GNUNET_HashCode *hc)
{
/* How can all bits match? Got my own ID? */
GNUNET_break (0);
- return GNUNET_SYSERR;
+ return -1;
}
return MAX_BUCKETS - bits - 1;
}
@@ -466,7 +466,7 @@ offer_hello_done (void *cls)
* @param value the value to remove
* @return #GNUNET_YES
*/
-static int
+static enum GNUNET_GenericReturnValue
free_connect_info (void *cls,
const struct GNUNET_PeerIdentity *peer,
void *value)
@@ -580,7 +580,7 @@ try_connect (const struct GNUNET_PeerIdentity *pid,
* @param value unused
* @return #GNUNET_YES (continue to iterate)
*/
-static int
+static enum GNUNET_GenericReturnValue
update_desire_strength (void *cls,
const struct GNUNET_PeerIdentity *pid,
void *value)
@@ -600,7 +600,7 @@ update_desire_strength (void *cls,
* @param tc scheduler context.
*/
static void
-update_connect_preferences ()
+update_connect_preferences (void)
{
GNUNET_CONTAINER_multipeermap_iterate (all_desired_peers,
&update_desire_strength,
@@ -617,7 +617,7 @@ update_connect_preferences ()
* @param value value the peer information (unused)
* @return #GNUNET_YES (we should continue to iterate)
*/
-static int
+static enum GNUNET_GenericReturnValue
add_known_to_bloom (void *cls,
const struct GNUNET_PeerIdentity *key,
void *value)
@@ -680,7 +680,7 @@ send_find_peer_message (void *cls)
&add_known_to_bloom,
bg);
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# FIND PEER messages initiated"),
+ "# FIND PEER messages initiated",
1,
GNUNET_NO);
peer_bf
@@ -932,7 +932,7 @@ get_distance (const struct GNUNET_HashCode *target,
* @return #GNUNET_YES if node location is closest,
* #GNUNET_NO otherwise.
*/
-int
+enum GNUNET_GenericReturnValue
GDS_am_closest_peer (const struct GNUNET_HashCode *key,
const struct GNUNET_CONTAINER_BloomFilter *bloom)
{
@@ -1222,7 +1222,7 @@ get_target_peers (const struct GNUNET_HashCode *key,
* @param data_size number of bytes in @a data
* @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
*/
-int
+enum GNUNET_GenericReturnValue
GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
enum GNUNET_DHT_RouteOption options,
uint32_t desired_replication_level,
@@ -1359,7 +1359,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
* @param peer_bf filter for peers not to select (again)
* @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
*/
-int
+enum GNUNET_GenericReturnValue
GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
enum GNUNET_DHT_RouteOption options,
uint32_t desired_replication_level,
@@ -1614,7 +1614,7 @@ core_init (void *cls,
* @param message message
* @return #GNUNET_OK if the message is valid
*/
-static int
+static enum GNUNET_GenericReturnValue
check_dht_p2p_put (void *cls,
const struct PeerPutMessage *put)
{
@@ -1655,12 +1655,11 @@ handle_dht_p2p_put (void *cls,
size_t payload_size;
enum GNUNET_DHT_RouteOption options;
struct GNUNET_CONTAINER_BloomFilter *bf;
- struct GNUNET_HashCode test_key;
int forwarded;
struct GNUNET_TIME_Absolute exp_time;
exp_time = GNUNET_TIME_absolute_ntoh (put->expiration_time);
- if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us)
+ if (GNUNET_TIME_absolute_is_past (exp_time))
{
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop ("# Expired PUTs discarded"),
@@ -1710,63 +1709,44 @@ handle_dht_p2p_put (void *cls,
GNUNET_free (pp);
GNUNET_free (tmp);
}
- switch (GNUNET_BLOCK_get_key
- (GDS_block_context,
- ntohl (put->type),
- payload,
- payload_size,
- &test_key))
+
{
- case GNUNET_YES:
- if (0 != memcmp (&test_key,
- &put->key,
- sizeof(struct GNUNET_HashCode)))
- {
- char *put_s = GNUNET_strdup (GNUNET_h2s_full (&put->key));
+ struct GNUNET_HashCode test_key;
+ enum GNUNET_GenericReturnValue ret;
+ ret = GNUNET_BLOCK_get_key (GDS_block_context,
+ ntohl (put->type),
+ payload,
+ payload_size,
+ &test_key);
+ switch (ret)
+ {
+ case GNUNET_YES:
+ if (0 != GNUNET_memcmp (&test_key,
+ &put->key))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ break;
+ case GNUNET_NO:
GNUNET_break_op (0);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "PUT with key `%s' for block with key %s\n",
- put_s,
- GNUNET_h2s_full (&test_key));
- GNUNET_free (put_s);
return;
+ case GNUNET_SYSERR:
+ /* cannot verify, good luck */
+ break;
}
- break;
+ }
- case GNUNET_NO:
+ if (GNUNET_NO ==
+ GNUNET_BLOCK_check_block (GDS_block_context,
+ ntohl (put->type),
+ &put->key,
+ payload,
+ payload_size))
+ {
GNUNET_break_op (0);
return;
-
- case GNUNET_SYSERR:
- /* cannot verify, good luck */
- break;
- }
- if (ntohl (put->type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all
tpyes */
- {
- switch (GNUNET_BLOCK_evaluate (GDS_block_context,
- ntohl (put->type),
- NULL, /* query group */
- GNUNET_BLOCK_EO_NONE,
- NULL, /* query */
- NULL, 0, /* xquery */
- payload,
- payload_size))
- {
- case GNUNET_BLOCK_EVALUATION_OK_MORE:
- case GNUNET_BLOCK_EVALUATION_OK_LAST:
- break;
-
- case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
- case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
- case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
- case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
- case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
- case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
- default:
- GNUNET_break_op (0);
- return;
- }
}
bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter,
@@ -1806,6 +1786,7 @@ handle_dht_p2p_put (void *cls,
/* give to local clients */
GDS_CLIENTS_handle_reply (exp_time,
+ &put->key,
&put->key,
0,
NULL,
@@ -1906,8 +1887,7 @@ handle_find_peer (const struct GNUNET_PeerIdentity
*sender,
else
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop (
- "# FIND PEER requests ignored due to
Bloomfilter"),
+ "# FIND PEER requests ignored due to
Bloomfilter",
1,
GNUNET_NO);
}
@@ -1915,17 +1895,16 @@ handle_find_peer (const struct GNUNET_PeerIdentity
*sender,
else
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop (
- "# FIND PEER requests ignored due to lack of
HELLO"),
+ "# FIND PEER requests ignored due to lack of
HELLO",
1,
GNUNET_NO);
}
/* then, also consider sending a random HELLO from the closest bucket */
/* FIXME: How can this be true? Shouldnt we just do find_bucket() ? */
- if (0 == memcmp (&my_identity_hash,
- key,
- sizeof(struct GNUNET_HashCode)))
+ if (0 ==
+ GNUNET_memcmp (&my_identity_hash,
+ key))
bucket_idx = closest_bucket;
else
bucket_idx = GNUNET_MIN ((int) closest_bucket,
@@ -2005,15 +1984,17 @@ handle_local_result (void *cls,
size_t data_size)
{
struct PeerInfo *peer = cls;
- char *pp;
+ {
+ char *pp;
- pp = GNUNET_STRINGS_pp2s (put_path,
- put_path_length);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found local result for %s (PP: %s)\n",
- GNUNET_h2s (key),
- pp);
- GNUNET_free (pp);
+ pp = GNUNET_STRINGS_pp2s (put_path,
+ put_path_length);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found local result for %s (PP: %s)\n",
+ GNUNET_h2s (key),
+ pp);
+ GNUNET_free (pp);
+ }
GDS_NEIGHBOURS_handle_reply (peer->id,
type,
expiration_time,
@@ -2031,7 +2012,7 @@ handle_local_result (void *cls,
* @param get the message
* @return #GNUNET_OK if the message is well-formed
*/
-static int
+static enum GNUNET_GenericReturnValue
check_dht_p2p_get (void *cls,
const struct PeerGetMessage *get)
{
@@ -2066,11 +2047,11 @@ handle_dht_p2p_get (void *cls,
uint16_t msize;
enum GNUNET_BLOCK_Type type;
enum GNUNET_DHT_RouteOption options;
- enum GNUNET_BLOCK_EvaluationResult eval;
+ enum GNUNET_BLOCK_ReplyEvaluationResult eval = GNUNET_BLOCK_REPLY_OK_MORE;
struct GNUNET_BLOCK_Group *bg;
struct GNUNET_CONTAINER_BloomFilter *peer_bf;
- const char *xquery;
- int forwarded;
+ const void *xquery;
+ enum GNUNET_GenericReturnValue forwarded;
/* parse and validate message */
msize = ntohs (get->header.size);
@@ -2078,7 +2059,7 @@ handle_dht_p2p_get (void *cls,
reply_bf_size = msize - (sizeof(struct PeerGetMessage) + xquery_size);
type = ntohl (get->type);
options = ntohl (get->options);
- xquery = (const char *) &get[1];
+ xquery = (const void *) &get[1];
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop ("# P2P GET requests received"),
1,
@@ -2103,23 +2084,18 @@ handle_dht_p2p_get (void *cls,
GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash,
&get->key),
ntohl (get->xquery_size),
- xquery);
+ (const char *) xquery);
GNUNET_free (tmp);
}
- eval
- = GNUNET_BLOCK_evaluate (GDS_block_context,
- type,
- NULL,
- GNUNET_BLOCK_EO_NONE,
- &get->key,
- xquery,
- xquery_size,
- NULL,
- 0);
- if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID)
+ if (GNUNET_NO ==
+ GNUNET_BLOCK_check_query (GDS_block_context,
+ type,
+ &get->key,
+ xquery,
+ xquery_size))
{
- /* request invalid or block type not supported */
- GNUNET_break_op (eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED);
+ /* request invalid */
+ GNUNET_break_op (0);
return;
}
peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter,
@@ -2131,7 +2107,7 @@ handle_dht_p2p_get (void *cls,
bg = GNUNET_BLOCK_group_create (GDS_block_context,
type,
get->bf_mutator,
- &xquery[xquery_size],
+ xquery + xquery_size,
reply_bf_size,
"filter-size",
reply_bf_size,
@@ -2142,15 +2118,14 @@ handle_dht_p2p_get (void *cls,
GNUNET_i2s (&my_identity),
(unsigned int) ntohl (get->hop_count));
/* local lookup (this may update the reply_bf) */
- if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
- (GDS_am_closest_peer (&get->key,
- peer_bf)))
+ if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
+ (GDS_am_closest_peer (&get->key,
+ peer_bf)) )
{
if ((0 != (options & GNUNET_DHT_RO_FIND_PEER)))
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop (
- "# P2P FIND PEER requests processed"),
+ "# P2P FIND PEER requests processed",
1,
GNUNET_NO);
handle_find_peer (peer->id,
@@ -2171,7 +2146,7 @@ handle_dht_p2p_get (void *cls,
else
{
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# P2P GET requests ONLY routed"),
+ "# P2P GET requests ONLY routed",
1,
GNUNET_NO);
}
@@ -2187,7 +2162,7 @@ handle_dht_p2p_get (void *cls,
/* P2P forwarding */
forwarded = GNUNET_NO;
- if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
+ if (eval != GNUNET_BLOCK_REPLY_OK_LAST)
forwarded = GDS_NEIGHBOURS_handle_get (type,
options,
ntohl (
@@ -2220,7 +2195,7 @@ handle_dht_p2p_get (void *cls,
* @param message message
* @return #GNUNET_YES if the message is well-formed
*/
-static int
+static enum GNUNET_GenericReturnValue
check_dht_p2p_result (void *cls,
const struct PeerResultMessage *prm)
{
@@ -2252,7 +2227,8 @@ check_dht_p2p_result (void *cls,
* Process a reply, after the @a get_path has been updated.
*
* @param expiration_time when does the reply expire
- * @param key key matching the query
+ * @param key key of the original inquiry
+ * @param query_hash key matching the block
* @param get_path_length number of entries in @a get_path
* @param get_path path the reply has taken
* @param put_path_length number of entries in @a put_path
@@ -2264,6 +2240,7 @@ check_dht_p2p_result (void *cls,
static void
process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time,
const struct GNUNET_HashCode *key,
+ const struct GNUNET_HashCode *query_hash,
unsigned int get_path_length,
const struct GNUNET_PeerIdentity *get_path,
unsigned int put_path_length,
@@ -2275,6 +2252,7 @@ process_reply_with_path (struct GNUNET_TIME_Absolute
expiration_time,
/* forward to local clients */
GDS_CLIENTS_handle_reply (expiration_time,
key,
+ query_hash,
get_path_length,
get_path,
put_path_length,
@@ -2288,7 +2266,7 @@ process_reply_with_path (struct GNUNET_TIME_Absolute
expiration_time,
put_path,
put_path_length,
expiration_time,
- key,
+ query_hash,
data,
data_size);
if (GNUNET_YES == cache_results)
@@ -2303,7 +2281,7 @@ process_reply_with_path (struct GNUNET_TIME_Absolute
expiration_time,
get_path_length * sizeof(struct GNUNET_PeerIdentity));
GDS_DATACACHE_handle_put (expiration_time,
- key,
+ query_hash,
get_path_length + put_path_length,
xput_path,
type,
@@ -2343,6 +2321,8 @@ handle_dht_p2p_result (void *cls,
size_t data_size;
enum GNUNET_BLOCK_Type type;
struct GNUNET_TIME_Absolute exp_time;
+ const struct GNUNET_HashCode *pquery;
+ struct GNUNET_HashCode dquery;
/* parse and validate message */
exp_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time);
@@ -2363,8 +2343,8 @@ handle_dht_p2p_result (void *cls,
data = (const void *) &get_path[get_path_length];
data_size = msize - (sizeof(struct PeerResultMessage)
+ (get_path_length
- + put_path_length) * sizeof(struct
- GNUNET_PeerIdentity));
+ + put_path_length)
+ * sizeof(struct GNUNET_PeerIdentity));
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop ("# P2P RESULTS received"),
1,
@@ -2373,6 +2353,31 @@ handle_dht_p2p_result (void *cls,
gettext_noop ("# P2P RESULT bytes received"),
msize,
GNUNET_NO);
+ {
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = GNUNET_BLOCK_get_key (GDS_block_context,
+ type,
+ data,
+ data_size,
+ &dquery);
+ if (GNUNET_NO == ret)
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ pquery = (GNUNET_OK == ret) ? &dquery : &prm->key;
+ if (GNUNET_OK !=
+ GNUNET_BLOCK_check_block (GDS_block_context,
+ type,
+ pquery,
+ data,
+ data_size))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ }
if (GNUNET_YES == log_route_details_stderr)
{
char *tmp;
@@ -2421,9 +2426,8 @@ handle_dht_p2p_result (void *cls,
return;
}
if ((GNUNET_YES != disable_try_connect) &&
- (0 != memcmp (&my_identity,
- &pid,
- sizeof(struct GNUNET_PeerIdentity))))
+ (0 != GNUNET_memcmp (&my_identity,
+ &pid)))
try_connect (&pid,
h);
}
@@ -2431,12 +2435,12 @@ 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 == memcmp (&get_path[i],
- peer->id,
- sizeof(struct GNUNET_PeerIdentity)))
+ if (0 == GNUNET_memcmp (&get_path[i],
+ peer->id))
{
process_reply_with_path (exp_time,
&prm->key,
+ pquery,
i,
get_path,
put_path_length,
@@ -2455,9 +2459,9 @@ handle_dht_p2p_result (void *cls,
get_path,
get_path_length * sizeof(struct GNUNET_PeerIdentity));
xget_path[get_path_length] = *peer->id;
-
process_reply_with_path (exp_time,
&prm->key,
+ pquery,
get_path_length + 1,
xget_path,
put_path_length,
@@ -2469,12 +2473,7 @@ handle_dht_p2p_result (void *cls,
}
-/**
- * Initialize neighbours subsystem.
- *
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
- */
-int
+enum GNUNET_GenericReturnValue
GDS_NEIGHBOURS_init ()
{
struct GNUNET_MQ_MessageHandler core_handlers[] = {
@@ -2528,9 +2527,6 @@ GDS_NEIGHBOURS_init ()
}
-/**
- * Shutdown neighbours subsystem.
- */
void
GDS_NEIGHBOURS_done ()
{
@@ -2553,11 +2549,6 @@ GDS_NEIGHBOURS_done ()
}
-/**
- * Get the ID of the local node.
- *
- * @return identity of the local node
- */
struct GNUNET_PeerIdentity *
GDS_NEIGHBOURS_get_id ()
{
diff --git a/src/dht/gnunet-service-dht_routing.c
b/src/dht/gnunet-service-dht_routing.c
index b05fb76d3..ef3aded77 100644
--- a/src/dht/gnunet-service-dht_routing.c
+++ b/src/dht/gnunet-service-dht_routing.c
@@ -61,11 +61,6 @@ struct RecentRequest
*/
struct GNUNET_BLOCK_Group *bg;
- /**
- * Type of the requested block.
- */
- enum GNUNET_BLOCK_Type type;
-
/**
* extended query (see gnunet_block_lib.h). Allocated at the
* end of this struct.
@@ -77,6 +72,11 @@ struct RecentRequest
*/
size_t xquery_size;
+ /**
+ * Type of the requested block.
+ */
+ enum GNUNET_BLOCK_Type type;
+
/**
* Request options.
*/
@@ -148,17 +148,16 @@ struct ProcessContext
* @param cls the `struct ProcessContext` with the result
* @param key the query
* @param value the `struct RecentRequest` with the request
- * @return #GNUNET_OK (continue to iterate),
- * #GNUNET_SYSERR if the result is malformed or type unsupported
+ * @return #GNUNET_OK (continue to iterate)
*/
-static int
+static enum GNUNET_GenericReturnValue
process (void *cls,
const struct GNUNET_HashCode *key,
void *value)
{
struct ProcessContext *pc = cls;
struct RecentRequest *rr = value;
- enum GNUNET_BLOCK_EvaluationResult eval;
+ enum GNUNET_BLOCK_ReplyEvaluationResult eval;
unsigned int gpl;
unsigned int ppl;
struct GNUNET_HashCode hc;
@@ -178,8 +177,11 @@ process (void *cls,
gpl = 0;
ppl = 0;
}
- if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) &&
- (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO))
+ /* FIXME-SCHANZEN: should we modify FIND_PEER to
+ be a generic approximate search and not check
+ for the DHT_HELLO type here? */
+ if ( (0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) &&
+ (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO) )
{
/* key may not match HELLO, which is OK since
* the search is approximate. Still, the evaluation
@@ -197,15 +199,14 @@ process (void *cls,
eval_key = key;
}
eval
- = GNUNET_BLOCK_evaluate (GDS_block_context,
- pc->type,
- rr->bg,
- GNUNET_BLOCK_EO_NONE,
- eval_key,
- rr->xquery,
- rr->xquery_size,
- pc->data,
- pc->data_size);
+ = GNUNET_BLOCK_check_reply (GDS_block_context,
+ pc->type,
+ rr->bg,
+ eval_key,
+ rr->xquery,
+ rr->xquery_size,
+ pc->data,
+ pc->data_size);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Result for %s of type %d was evaluated as %d\n",
GNUNET_h2s (key),
@@ -213,12 +214,13 @@ process (void *cls,
eval);
switch (eval)
{
- case GNUNET_BLOCK_EVALUATION_OK_MORE:
- case GNUNET_BLOCK_EVALUATION_OK_LAST:
+ case GNUNET_BLOCK_REPLY_OK_MORE:
+ case GNUNET_BLOCK_REPLY_OK_LAST:
+ case GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop
- ("# Good REPLIES matched against routing
table"),
- 1, GNUNET_NO);
+ "# Good REPLIES matched against routing table",
+ 1,
+ GNUNET_NO);
GDS_NEIGHBOURS_handle_reply (&rr->peer,
pc->type,
pc->expiration_time,
@@ -228,50 +230,28 @@ process (void *cls,
pc->data,
pc->data_size);
break;
-
- case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
+ case GNUNET_BLOCK_REPLY_OK_DUPLICATE:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop
- (
- "# Duplicate REPLIES matched against routing
table"),
- 1, GNUNET_NO);
+ "# Duplicate REPLIES matched against routing
table",
+ 1,
+ GNUNET_NO);
return GNUNET_OK;
-
- case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop
- (
- "# Invalid REPLIES matched against routing
table"),
- 1, GNUNET_NO);
- return GNUNET_SYSERR;
-
- case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
- GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop
- (
- "# Irrelevant REPLIES matched against routing
table"),
- 1, GNUNET_NO);
- return GNUNET_OK;
-
- case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
- GNUNET_break (0);
- return GNUNET_OK;
-
- case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
+ case GNUNET_BLOCK_REPLY_INVALID:
GNUNET_break (0);
+ GNUNET_STATISTICS_update (GDS_stats,
+ "# Invalid REPLIES matched against routing
table",
+ 1,
+ GNUNET_NO);
return GNUNET_OK;
-
- case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
+ case GNUNET_BLOCK_REPLY_IRRELEVANT:
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop
- (
- "# Unsupported REPLIES matched against routing
table"),
- 1, GNUNET_NO);
- return GNUNET_SYSERR;
-
+ "# Irrelevant REPLIES matched against routing
table",
+ 1,
+ GNUNET_NO);
+ return GNUNET_OK;
default:
GNUNET_break (0);
- return GNUNET_SYSERR;
+ return GNUNET_OK;
}
return GNUNET_OK;
}
@@ -281,7 +261,7 @@ process (void *cls,
* Handle a reply (route to origin). Only forwards the reply back to
* other peers waiting for it. Does not do local caching or
* forwarding to local clients. Essentially calls
- * GDS_NEIGHBOURS_handle_reply for all peers that sent us a matching
+ * GDS_NEIGHBOURS_handle_reply() for all peers that sent us a matching
* request recently.
*
* @param type type of the block
@@ -315,16 +295,6 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
pc.get_path = get_path;
pc.data = data;
pc.data_size = data_size;
- if (NULL == data)
- {
- /* Some apps might have an 'empty' reply as a valid reply; however,
- 'process' will call GNUNET_BLOCK_evaluate' which treats a 'NULL'
- reply as request-validation (but we need response-validation).
- So we set 'data' to a 0-byte non-NULL value just to be sure */
- GNUNET_break (0 == data_size);
- pc.data_size = 0;
- pc.data = ""; /* something not null */
- }
GNUNET_CONTAINER_multihashmap_get_multiple (recent_map,
key,
&process,
@@ -338,13 +308,13 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
* in the heap and hashmap.
*/
static void
-expire_oldest_entry ()
+expire_oldest_entry (void)
{
struct RecentRequest *recent_req;
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop
- ("# Entries removed from routing table"), 1,
+ "# Entries removed from routing table",
+ 1,
GNUNET_NO);
recent_req = GNUNET_CONTAINER_heap_peek (recent_heap);
GNUNET_assert (recent_req != NULL);
@@ -362,13 +332,13 @@ expire_oldest_entry ()
* Try to combine multiple recent requests for the same value
* (if they come from the same peer).
*
- * @param cls the new 'struct RecentRequest' (to discard upon successful
combination)
+ * @param cls the new `struct RecentRequest` (to discard upon successful
combination)
* @param key the query
* @param value the existing 'struct RecentRequest' (to update upon successful
combination)
* @return #GNUNET_OK (continue to iterate),
* #GNUNET_SYSERR if the request was successfully combined
*/
-static int
+static enum GNUNET_GenericReturnValue
try_combine_recent (void *cls,
const struct GNUNET_HashCode *key,
void *value)
@@ -419,7 +389,7 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT)
expire_oldest_entry ();
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# Entries added to routing table"),
+ "# Entries added to routing table",
1,
GNUNET_NO);
recent_req = GNUNET_malloc (sizeof(struct RecentRequest) + xquery_size);
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 25569c59e..5640209a6 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -339,7 +339,7 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
* @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
* supported, #GNUNET_SYSERR on error
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
uint32_t *nonce,
void **raw_data,
@@ -424,11 +424,11 @@ GNUNET_BLOCK_check_reply (struct GNUNET_BLOCK_Context
*ctx,
* #GNUNET_SYSERR if @a type is not supported
*/
enum GNUNET_GenericReturnValue
-GNUNET_BLOCK_check_request (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- const struct GNUNET_HashCode *query,
- const void *xquery,
- size_t xquery_size);
+GNUNET_BLOCK_check_query (struct GNUNET_BLOCK_Context *ctx,
+ enum GNUNET_BLOCK_Type type,
+ const struct GNUNET_HashCode *query,
+ const void *xquery,
+ size_t xquery_size);
/**
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: -start to use new block API in DHT,
gnunet <=