aboutsummaryrefslogtreecommitdiff
path: root/src/block
diff options
context:
space:
mode:
authorgrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2011-09-27 20:07:22 +0000
committergrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2011-09-27 20:07:22 +0000
commitdd8d25af104a7c9877408e92701ad5111ca0c05a (patch)
tree69e2a4ca82a015e3cd25d5702fb674dffb65335b /src/block
parentbb4d0999963afddce40a34ce7e53c51210bad8ad (diff)
better hello block lib
git-svn-id: https://gnunet.org/svn/gnunet@17070 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/block')
-rw-r--r--src/block/plugin_block_dht.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/block/plugin_block_dht.c b/src/block/plugin_block_dht.c
index 614628a406..331eea4f68 100644
--- a/src/block/plugin_block_dht.c
+++ b/src/block/plugin_block_dht.c
@@ -27,6 +27,7 @@
*/
#include "platform.h"
+#include "gnunet_constants.h"
#include "gnunet_hello_lib.h"
#include "gnunet_block_plugin.h"
@@ -56,18 +57,40 @@ block_plugin_dht_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
size_t xquery_size, const void *reply_block,
size_t reply_block_size)
{
- switch (type)
- {
- case GNUNET_BLOCK_TYPE_DHT_HELLO:
- if (xquery_size != 0)
- return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
- if (reply_block_size == 0)
- return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- GNUNET_break (NULL == *bf);
- return GNUNET_BLOCK_EVALUATION_OK_LAST;
- default:
+ GNUNET_HashCode mhash;
+ const struct GNUNET_HELLO_Message *hello;
+ struct GNUNET_PeerIdentity pid;
+ const struct GNUNET_MessageHeader *msg;
+
+ if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
- }
+ if (xquery_size != 0)
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+ if (reply_block_size == 0)
+ return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+ if (reply_block_size < sizeof (struct GNUNET_MessageHeader))
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ msg = reply_block;
+ if (reply_block_size != ntohs (msg->size))
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ hello = reply_block;
+ if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ if (NULL != bf)
+ {
+ GNUNET_BLOCK_mingle_hash (&pid.hashPubKey, bf_mutator, &mhash);
+ if (NULL != *bf)
+ {
+ if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
+ return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
+ }
+ else
+ {
+ *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, GNUNET_CONSTANTS_BLOOMFILTER_K);
+ }
+ GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ }
+ return GNUNET_BLOCK_EVALUATION_OK_MORE;
}