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