/*
This file is part of GNUnet
- (C) 2012 Christian Grothoff (and other contributing authors)
+ (C) 2012,2013 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
#include "platform.h"
#include "gnunet_block_plugin.h"
+#include "block_mesh.h"
+
+/**
+ * Number of bits we set per entry in the bloomfilter.
+ * Do not change!
+ */
+#define BLOOMFILTER_K 16
-#define DEBUG_MESH_BLOCK GNUNET_EXTRA_LOGGING
/**
* Function called to validate a reply or a request. For
size_t xquery_size, const void *reply_block,
size_t reply_block_size)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Evaluate called\n");
- if (GNUNET_BLOCK_TYPE_MESH_PEER == type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Type MESH PEER\n");
- }
- else
+ struct GNUNET_HashCode chash;
+ struct GNUNET_HashCode mhash;
+
+ switch (type)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Other type\n");
+ case GNUNET_BLOCK_TYPE_MESH_PEER:
+ if (0 != xquery_size)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+ }
+ if (NULL == reply_block)
+ return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+ if (sizeof (struct PBlock) != reply_block_size)
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ if (NULL != bf)
+ {
+ GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
+ GNUNET_BLOCK_mingle_hash (&chash, 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, BLOOMFILTER_K);
+ }
+ GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ }
+ return GNUNET_BLOCK_EVALUATION_OK_LAST;
+
+ default:
+ GNUNET_break(0);
+ return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
}
- return GNUNET_BLOCK_EVALUATION_OK_LAST;
}
* @param cls closure
* @param type block type
* @param block block to get the key for
- * @param block_size number of bytes in block
+ * @param block_size number of bytes in @a block
* @param key set to the key (query) for the given block
- * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
* (or if extracting a key from a block of this type does not work)
*/
static int
const void *block, size_t block_size,
struct GNUNET_HashCode * key)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get key called\n");
- return GNUNET_SYSERR;
+ const struct PBlock *pb;
+ pb = block;
+
+ switch (type)
+ {
+ case GNUNET_BLOCK_TYPE_MESH_PEER:
+ if (sizeof (struct PBlock) != block_size)
+ return GNUNET_SYSERR;
+ GNUNET_CRYPTO_hash (&pb->id,
+ sizeof (struct GNUNET_PeerIdentity),
+ key);
+ return GNUNET_OK;
+ default:
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
}
};
struct GNUNET_BLOCK_PluginFunctions *api;
- api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
+ api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
api->evaluate = &block_plugin_mesh_evaluate;
api->get_key = &block_plugin_mesh_get_key;
api->types = types;