diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-09-27 20:07:22 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-09-27 20:07:22 +0000 |
commit | 8b64acf6f363f5624917d3808a5096577dcd20d5 (patch) | |
tree | 69e2a4ca82a015e3cd25d5702fb674dffb65335b /src/block | |
parent | 1f27b71afdc085c84ca14eb48a3f70549b551e38 (diff) | |
download | gnunet-8b64acf6f363f5624917d3808a5096577dcd20d5.tar.gz gnunet-8b64acf6f363f5624917d3808a5096577dcd20d5.zip |
better hello block lib
Diffstat (limited to 'src/block')
-rw-r--r-- | src/block/plugin_block_dht.c | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/src/block/plugin_block_dht.c b/src/block/plugin_block_dht.c index 614628a40..331eea4f6 100644 --- a/src/block/plugin_block_dht.c +++ b/src/block/plugin_block_dht.c | |||
@@ -27,6 +27,7 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "gnunet_constants.h" | ||
30 | #include "gnunet_hello_lib.h" | 31 | #include "gnunet_hello_lib.h" |
31 | #include "gnunet_block_plugin.h" | 32 | #include "gnunet_block_plugin.h" |
32 | 33 | ||
@@ -56,18 +57,40 @@ block_plugin_dht_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
56 | size_t xquery_size, const void *reply_block, | 57 | size_t xquery_size, const void *reply_block, |
57 | size_t reply_block_size) | 58 | size_t reply_block_size) |
58 | { | 59 | { |
59 | switch (type) | 60 | GNUNET_HashCode mhash; |
60 | { | 61 | const struct GNUNET_HELLO_Message *hello; |
61 | case GNUNET_BLOCK_TYPE_DHT_HELLO: | 62 | struct GNUNET_PeerIdentity pid; |
62 | if (xquery_size != 0) | 63 | const struct GNUNET_MessageHeader *msg; |
63 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 64 | |
64 | if (reply_block_size == 0) | 65 | if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) |
65 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
66 | GNUNET_break (NULL == *bf); | ||
67 | return GNUNET_BLOCK_EVALUATION_OK_LAST; | ||
68 | default: | ||
69 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 66 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
70 | } | 67 | if (xquery_size != 0) |
68 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
69 | if (reply_block_size == 0) | ||
70 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
71 | if (reply_block_size < sizeof (struct GNUNET_MessageHeader)) | ||
72 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
73 | msg = reply_block; | ||
74 | if (reply_block_size != ntohs (msg->size)) | ||
75 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
76 | hello = reply_block; | ||
77 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) | ||
78 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | ||
79 | if (NULL != bf) | ||
80 | { | ||
81 | GNUNET_BLOCK_mingle_hash (&pid.hashPubKey, bf_mutator, &mhash); | ||
82 | if (NULL != *bf) | ||
83 | { | ||
84 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash)) | ||
85 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, GNUNET_CONSTANTS_BLOOMFILTER_K); | ||
90 | } | ||
91 | GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); | ||
92 | } | ||
93 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
71 | } | 94 | } |
72 | 95 | ||
73 | 96 | ||