- added dummy mesh block plugin
[oweals/gnunet.git] / src / mesh / plugin_block_mesh.c
1 /*
2      This file is part of GNUnet
3      (C) 2012 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file mesh/plugin_block_mesh.c
23  * @brief blocks used for mesh peer discovery
24  * @author Bartlomiej Polot
25  */
26
27 #include "platform.h"
28 #include "gnunet_block_plugin.h"
29
30 #define DEBUG_MESH_BLOCK GNUNET_EXTRA_LOGGING
31
32 /**
33  * Function called to validate a reply or a request.  For
34  * request evaluation, simply pass "NULL" for the reply_block.
35  * Note that it is assumed that the reply has already been
36  * matched to the key (and signatures checked) as it would
37  * be done with the "get_key" function.
38  *
39  * @param cls closure
40  * @param type block type
41  * @param query original query (hash)
42  * @param bf pointer to bloom filter associated with query; possibly updated (!)
43  * @param bf_mutator mutation value for bf
44  * @param xquery extrended query data (can be NULL, depending on type)
45  * @param xquery_size number of bytes in xquery
46  * @param reply_block response to validate
47  * @param reply_block_size number of bytes in reply block
48  * @return characterization of result
49  */
50 static enum GNUNET_BLOCK_EvaluationResult
51 block_plugin_mesh_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
52                             const struct GNUNET_HashCode * query,
53                             struct GNUNET_CONTAINER_BloomFilter **bf,
54                             int32_t bf_mutator, const void *xquery,
55                             size_t xquery_size, const void *reply_block,
56                             size_t reply_block_size)
57 {
58   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Evaluate called\n");
59   if (GNUNET_BLOCK_TYPE_MESH_PEER == type)
60   {
61     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Type MESH PEER\n");
62   }
63   else
64   {
65     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Other type\n");
66   }
67   return GNUNET_BLOCK_EVALUATION_OK_LAST;
68 }
69
70
71 /**
72  * Function called to obtain the key for a block.
73  *
74  * @param cls closure
75  * @param type block type
76  * @param block block to get the key for
77  * @param block_size number of bytes in block
78  * @param key set to the key (query) for the given block
79  * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
80  *         (or if extracting a key from a block of this type does not work)
81  */
82 static int
83 block_plugin_mesh_get_key (void *cls, enum GNUNET_BLOCK_Type type,
84                            const void *block, size_t block_size,
85                            struct GNUNET_HashCode * key)
86 {
87   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get key called\n");
88   return GNUNET_SYSERR;
89 }
90
91
92 /**
93  * Entry point for the plugin.
94  */
95 void *
96 libgnunet_plugin_block_mesh_init (void *cls)
97 {
98   static enum GNUNET_BLOCK_Type types[] =
99   {
100     GNUNET_BLOCK_TYPE_MESH_PEER,
101     GNUNET_BLOCK_TYPE_ANY       /* end of list */
102   };
103   struct GNUNET_BLOCK_PluginFunctions *api;
104
105   api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
106   api->evaluate = &block_plugin_mesh_evaluate;
107   api->get_key = &block_plugin_mesh_get_key;
108   api->types = types;
109   return api;
110 }
111
112
113 /**
114  * Exit point from the plugin.
115  */
116 void *
117 libgnunet_plugin_block_mesh_done (void *cls)
118 {
119   struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
120
121   GNUNET_free (api);
122   return NULL;
123 }
124
125 /* end of plugin_block_mesh.c */