#include "platform.h"
#include "gnunet_block_plugin.h"
-#define DEBUG_TEST GNUNET_EXTRA_LOGGING
-
/**
* Number of bits we set per entry in the bloomfilter.
struct GNUNET_HashCode chash;
struct GNUNET_HashCode mhash;
- if (type != GNUNET_BLOCK_TYPE_TEST)
+ if ( GNUNET_BLOCK_TYPE_TEST != type)
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
- if (xquery_size != 0)
+ if (0 != xquery_size)
{
GNUNET_break_op (0);
return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
#include "block_fs.h"
#include "gnunet_signatures.h"
-#define DEBUG_FS_BLOCK GNUNET_EXTRA_LOGGING
/**
* Number of bits we set per entry in the bloomfilter.
/**
* Block for storing mesh peers
*/
- GNUNET_BLOCK_TYPE_MESH_PEER = 20
+ GNUNET_BLOCK_TYPE_MESH_PEER = 20,
+
+ /**
+ * Block for finding peers by type
+ */
+ GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE = 21
};
#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;
+ return GNUNET_BLOCK_EVALUATION_OK_LAST;
+ case GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE:
+ /* FIXME: have an xquery? not sure */
+ 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_MORE;
+ default:
+ return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
}
- return GNUNET_BLOCK_EVALUATION_OK_LAST;
}
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;
+
+ switch (type)
+ {
+ case GNUNET_BLOCK_TYPE_MESH_PEER:
+ if (sizeof (struct PBlock) != block_size)
+ return GNUNET_SYSERR;
+ pb = block;
+ *key = pb->id.hashPubKey;
+ return GNUNET_OK;
+ // FIXME: other types...
+ default:
+ return GNUNET_SYSERR;
+ }
}
static enum GNUNET_BLOCK_Type types[] =
{
GNUNET_BLOCK_TYPE_MESH_PEER,
+ GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE,
GNUNET_BLOCK_TYPE_ANY /* end of list */
};
struct GNUNET_BLOCK_PluginFunctions *api;
rrc->op_res = 0;
}
-static void handle_record_remove (void *cls,
- struct GNUNET_SERVER_Client * client,
- const struct GNUNET_MessageHeader * message)
+
+static void
+handle_record_remove (void *cls,
+ struct GNUNET_SERVER_Client * client,
+ const struct GNUNET_MessageHeader * message)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE");
struct GNUNET_NAMESTORE_Client *nc;
+ const struct RecordRemoveMessage * rr_msg;
struct RecordRemoveResponseMessage rrr_msg;
struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
- struct GNUNET_NAMESTORE_CryptoContainer *cc = NULL;
+ struct GNUNET_NAMESTORE_CryptoContainer *cc;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
struct GNUNET_HashCode long_hash;
- char * pkey_tmp = NULL;
- char * name_tmp = NULL;
- char * rd_ser = NULL;
- size_t key_len = 0;
- size_t name_len = 0;
- size_t rd_ser_len = 0;
- size_t msg_size = 0;
+ const char * pkey_tmp;
+ const char * name_tmp;
+ const char * rd_ser;
+ size_t key_len;
+ size_t name_len;
+ size_t rd_ser_len;
+ size_t msg_size;
size_t msg_size_exp = 0;
uint32_t rd_count;
- uint32_t rid = 0;
+ uint32_t rid;
int res = GNUNET_SYSERR;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE");
if (ntohs (message->size) < sizeof (struct RecordRemoveMessage))
{
GNUNET_break_op (0);
return;
}
- struct RecordRemoveMessage * rr_msg = (struct RecordRemoveMessage *) message;
+ rr_msg = (const struct RecordRemoveMessage *) message;
rid = ntohl (rr_msg->gns_header.r_id);
name_len = ntohs (rr_msg->name_len);
rd_ser_len = ntohs (rr_msg->rd_len);
return;
}
- pkey_tmp = (char *) &rr_msg[1];
+ pkey_tmp = (const char *) &rr_msg[1];
name_tmp = &pkey_tmp[key_len];
rd_ser = &name_tmp[name_len];
if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_short_h2s(&pubkey_hash));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received new private key for zone `%s'\n",
+ GNUNET_short_h2s(&pubkey_hash));
cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer));
cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len);
cc->pubkey = GNUNET_malloc(sizeof (pub));