From: Bart Polot Date: Tue, 19 Jun 2012 14:26:38 +0000 (+0000) Subject: - added dummy mesh block plugin X-Git-Tag: initial-import-from-subversion-38251~12967 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=809906cfb208342b0894dbbfa3cb43a102caa42f;p=oweals%2Fgnunet.git - added dummy mesh block plugin --- diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index 41001fb0b..d651476a8 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h @@ -98,7 +98,12 @@ enum GNUNET_BLOCK_Type /** * Block for storing record data */ - GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11 + GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11, + + /** + * Block for storing mesh peers + */ + GNUNET_BLOCK_TYPE_MESH_PEER = 20 }; diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index e116b889a..59131f2b1 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am @@ -14,6 +14,8 @@ pkgcfgdir= $(pkgdatadir)/config.d/ pkgcfg_DATA = \ mesh.conf +plugindir = $(libdir)/gnunet + AM_CLFAGS = -g bin_PROGRAMS = \ @@ -22,12 +24,27 @@ bin_PROGRAMS = \ lib_LTLIBRARIES = \ libgnunetmesh.la +plugin_LTLIBRARIES = \ + libgnunet_plugin_block_mesh.la + +libgnunet_plugin_block_mesh_la_SOURCES = \ + plugin_block_mesh.c +libgnunet_plugin_block_mesh_la_LIBADD = \ + $(top_builddir)/src/block/libgnunetblock.la \ + $(top_builddir)/src/util/libgnunetutil.la +libgnunet_plugin_block_mesh_la_LDFLAGS = \ + $(GN_PLUGIN_LDFLAGS) +libgnunet_plugin_block_mesh_la_DEPENDENCIES = \ + $(top_builddir)/src/block/libgnunetblock.la + + gnunet_service_mesh_SOURCES = \ gnunet-service-mesh.c \ mesh_tunnel_tree.c mesh_tunnel_tree.h gnunet_service_mesh_LDADD = \ - $(top_builddir)/src/core/libgnunetcore.la\ + $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/dht/libgnunetdht.la \ + $(top_builddir)/src/block/libgnunetblock.la \ $(top_builddir)/src/util/libgnunetutil.la gnunet_service_mesh_DEPENDENCIES = \ $(top_builddir)/src/core/libgnunetcore.la\ diff --git a/src/mesh/gnunet-service-mesh_new.c b/src/mesh/gnunet-service-mesh_new.c index 9d737c9c0..a6e43dc46 100644 --- a/src/mesh/gnunet-service-mesh_new.c +++ b/src/mesh/gnunet-service-mesh_new.c @@ -70,8 +70,10 @@ /* TODO END */ -#define MESH_DEBUG_DHT GNUNET_YES -#define MESH_DEBUG_CONNECTION GNUNET_NO +#define MESH_BLOOM_SIZE 128 + +#define MESH_DEBUG_DHT GNUNET_YES +#define MESH_DEBUG_CONNECTION GNUNET_NO #if MESH_DEBUG_CONNECTION #define DEBUG_CONN(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) @@ -381,6 +383,11 @@ struct MeshTunnel */ unsigned int nblacklisted; + /** + * Bloomfilter (for peer identities) to stop circular routes + */ + char bloomfilter[MESH_BLOOM_SIZE]; + /** * Tunnel paths */ @@ -655,7 +662,8 @@ announce_application (void *cls, const struct GNUNET_HashCode * key, void *value /* FIXME: keep return value of 'put' to possibly cancel!? */ GNUNET_DHT_put (dht_handle, key, 10, GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_BLOCK_TYPE_TEST, + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, + GNUNET_BLOCK_TYPE_MESH_PEER, sizeof (struct GNUNET_PeerIdentity), (const char *) &my_full_id, GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), @@ -717,7 +725,7 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) &my_full_id.hashPubKey, /* Key to use */ 10, /* Replication level */ GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ - GNUNET_BLOCK_TYPE_TEST, /* Block type */ + GNUNET_BLOCK_TYPE_MESH_PEER, /* Block type */ sizeof (my_full_id), /* Size of the data */ (char *) &my_full_id, /* Data itself */ GNUNET_TIME_UNIT_FOREVER_ABS, /* Data expiration */ @@ -1514,11 +1522,13 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t) " Starting DHT GET for peer %s\n", GNUNET_i2s (&id)); peer->dhtgetcls = path_info; peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ - GNUNET_BLOCK_TYPE_TEST, /* type */ - &id.hashPubKey, /* key to search */ + GNUNET_BLOCK_TYPE_MESH_PEER, /* type */ + &id.hashPubKey, /* key to search */ 10, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ - 0, /* xquery bits */ + GNUNET_DHT_RO_RECORD_ROUTE | + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, + NULL, /* xquery */ // FIXME BLOOMFILTER + 0, /* xquery bits */ // FIXME BLOOMFILTER SIZE &dht_get_id_handler, path_info); } /* Otherwise, there is no path but the DHT get is already started. */ @@ -4449,9 +4459,12 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_h2s (&hash)); t->dht_get_type = GNUNET_DHT_get_start (dht_handle, - GNUNET_BLOCK_TYPE_TEST, &hash, 10, + GNUNET_BLOCK_TYPE_MESH_PEER, + &hash, + 10, GNUNET_DHT_RO_RECORD_ROUTE | - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, 0, + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, + NULL, 0, &dht_get_type_handler, t); GNUNET_SERVER_receive_done (client, GNUNET_OK); diff --git a/src/mesh/plugin_block_mesh.c b/src/mesh/plugin_block_mesh.c new file mode 100644 index 000000000..c5bb458bd --- /dev/null +++ b/src/mesh/plugin_block_mesh.c @@ -0,0 +1,125 @@ +/* + This file is part of GNUnet + (C) 2012 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 + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file mesh/plugin_block_mesh.c + * @brief blocks used for mesh peer discovery + * @author Bartlomiej Polot + */ + +#include "platform.h" +#include "gnunet_block_plugin.h" + +#define DEBUG_MESH_BLOCK GNUNET_EXTRA_LOGGING + +/** + * Function called to validate a reply or a request. For + * request evaluation, simply pass "NULL" for the reply_block. + * Note that it is assumed that the reply has already been + * matched to the key (and signatures checked) as it would + * be done with the "get_key" function. + * + * @param cls closure + * @param type block type + * @param query original query (hash) + * @param bf pointer to bloom filter associated with query; possibly updated (!) + * @param bf_mutator mutation value for bf + * @param xquery extrended query data (can be NULL, depending on type) + * @param xquery_size number of bytes in xquery + * @param reply_block response to validate + * @param reply_block_size number of bytes in reply block + * @return characterization of result + */ +static enum GNUNET_BLOCK_EvaluationResult +block_plugin_mesh_evaluate (void *cls, enum GNUNET_BLOCK_Type type, + const struct GNUNET_HashCode * query, + struct GNUNET_CONTAINER_BloomFilter **bf, + int32_t bf_mutator, const void *xquery, + 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 + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Other type\n"); + } + return GNUNET_BLOCK_EVALUATION_OK_LAST; +} + + +/** + * Function called to obtain the key for a block. + * + * @param cls closure + * @param type block type + * @param block block to get the key for + * @param block_size number of bytes in block + * @param key set to the key (query) for the given block + * @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 +block_plugin_mesh_get_key (void *cls, enum GNUNET_BLOCK_Type type, + const void *block, size_t block_size, + struct GNUNET_HashCode * key) +{ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get key called\n"); + return GNUNET_SYSERR; +} + + +/** + * Entry point for the plugin. + */ +void * +libgnunet_plugin_block_mesh_init (void *cls) +{ + static enum GNUNET_BLOCK_Type types[] = + { + GNUNET_BLOCK_TYPE_MESH_PEER, + GNUNET_BLOCK_TYPE_ANY /* end of list */ + }; + struct GNUNET_BLOCK_PluginFunctions *api; + + api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions)); + api->evaluate = &block_plugin_mesh_evaluate; + api->get_key = &block_plugin_mesh_get_key; + api->types = types; + return api; +} + + +/** + * Exit point from the plugin. + */ +void * +libgnunet_plugin_block_mesh_done (void *cls) +{ + struct GNUNET_TRANSPORT_PluginFunctions *api = cls; + + GNUNET_free (api); + return NULL; +} + +/* end of plugin_block_mesh.c */