fix zombie-fest
[oweals/gnunet.git] / src / include / gnunet_block_plugin.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2010,2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * API for block plugins.
26  *
27  * @defgroup block-plugin  Block plugin API
28  * To be implemented by applications storing data in the DHT.
29  *
30  * Each block plugin must conform to the API specified by this header.
31  *
32  * @{
33  */
34
35 #ifndef PLUGIN_BLOCK_H
36 #define PLUGIN_BLOCK_H
37
38 #include "gnunet_util_lib.h"
39 #include "gnunet_block_lib.h"
40
41
42 /**
43  * Function called to validate a reply or a request.  For
44  * request evaluation, simply pass "NULL" for the @a reply_block.
45  * Note that it is assumed that the reply has already been
46  * matched to the key (and signatures checked) as it would
47  * be done with the "get_key" function.
48  *
49  * @param cls closure
50  * @param type block type
51  * @param eo evaluation options to control evaluation
52  * @param query original query (hash)
53  * @param bf pointer to bloom filter associated with query; possibly updated (!)
54  * @param bf_mutator mutation value for @a bf
55  * @param xquery extrended query data (can be NULL, depending on type)
56  * @param xquery_size number of bytes in @a xquery
57  * @param reply_block response to validate
58  * @param reply_block_size number of bytes in @a reply_block
59  * @return characterization of result
60  */
61 typedef enum GNUNET_BLOCK_EvaluationResult
62 (*GNUNET_BLOCK_EvaluationFunction) (void *cls,
63                                     enum GNUNET_BLOCK_Type type,
64                                     enum GNUNET_BLOCK_EvaluationOptions eo,
65                                     const struct GNUNET_HashCode *query,
66                                     struct GNUNET_CONTAINER_BloomFilter **bf,
67                                     int32_t bf_mutator,
68                                     const void *xquery,
69                                     size_t xquery_size,
70                                     const void *reply_block,
71                                     size_t reply_block_size);
72
73
74 /**
75  * Function called to obtain the key for a block.
76  *
77  * @param cls closure
78  * @param type block type
79  * @param block block to get the key for
80  * @param block_size number of bytes in @a block
81  * @param key set to the key (query) for the given block
82  * @return #GNUNET_YES on success,
83  *         #GNUNET_NO if the block is malformed
84  *         #GNUNET_SYSERR if type not supported
85  *         (or if extracting a key from a block of this type does not work)
86  */
87 typedef int
88 (*GNUNET_BLOCK_GetKeyFunction) (void *cls,
89                                 enum GNUNET_BLOCK_Type type,
90                                 const void *block,
91                                 size_t block_size,
92                                 struct GNUNET_HashCode *key);
93
94
95
96 /**
97  * Each plugin is required to return a pointer to a struct of this
98  * type as the return value from its entry point.
99  */
100 struct GNUNET_BLOCK_PluginFunctions
101 {
102
103   /**
104    * Closure for all of the callbacks.
105    */
106   void *cls;
107
108   /**
109    * 0-terminated array of block types supported by this plugin.
110    */
111   const enum GNUNET_BLOCK_Type *types;
112
113   /**
114    * Main function of a block plugin.  Allows us to check if a
115    * block matches a query.
116    */
117   GNUNET_BLOCK_EvaluationFunction evaluate;
118
119   /**
120    * Obtain the key for a given block (if possible).
121    */
122   GNUNET_BLOCK_GetKeyFunction get_key;
123
124 };
125
126 #endif
127
128 /** @} */  /* end of group */