remove 'illegal' (non-reentrant) log logic from signal handler
[oweals/gnunet.git] / src / datacache / plugin_datacache_template.c
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2006, 2009, 2015 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20
21 /**
22  * @file datacache/plugin_datacache_template.c
23  * @brief template for an implementation of a database backend for the datacache
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_datacache_plugin.h"
29
30
31 /**
32  * Context for all functions in this plugin.
33  */
34 struct Plugin
35 {
36   /**
37    * Our execution environment.
38    */
39   struct GNUNET_DATACACHE_PluginEnvironment *env;
40 };
41
42
43 /**
44  * Store an item in the datastore.
45  *
46  * @param cls closure (our `struct Plugin`)
47  * @param key key to store @a data under
48  * @param xor_distance distance of @a key to our PID
49  * @param size number of bytes in @a data
50  * @param data data to store
51  * @param type type of the value
52  * @param discard_time when to discard the value in any case
53  * @param path_info_len number of entries in @a path_info
54  * @param path_info a path through the network
55  * @return 0 if duplicate, -1 on error, number of bytes used otherwise
56  */
57 static ssize_t
58 template_plugin_put (void *cls,
59                      const struct GNUNET_HashCode *key,
60                      uint32_t xor_distance,
61                      size_t size,
62                      const char *data,
63                      enum GNUNET_BLOCK_Type type,
64                      struct GNUNET_TIME_Absolute discard_time,
65                      unsigned int path_info_len,
66                      const struct GNUNET_PeerIdentity *path_info)
67 {
68   GNUNET_break (0);
69   return -1;
70 }
71
72
73 /**
74  * Iterate over the results for a particular key
75  * in the datastore.
76  *
77  * @param cls closure (our `struct Plugin`)
78  * @param key
79  * @param type entries of which type are relevant?
80  * @param iter maybe NULL (to just count)
81  * @param iter_cls closure for @a iter
82  * @return the number of results found
83  */
84 static unsigned int
85 template_plugin_get (void *cls,
86                      const struct GNUNET_HashCode *key,
87                      enum GNUNET_BLOCK_Type type,
88                      GNUNET_DATACACHE_Iterator iter,
89                      void *iter_cls)
90 {
91   GNUNET_break (0);
92   return 0;
93 }
94
95
96 /**
97  * Delete the entry with the lowest expiration value
98  * from the datacache right now.
99  *
100  * @param cls closure (our `struct Plugin`)
101  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
102  */
103 static int
104 template_plugin_del (void *cls)
105 {
106   GNUNET_break (0);
107   return GNUNET_SYSERR;
108 }
109
110
111 /**
112  * Return a random value from the datastore.
113  *
114  * @param cls closure (internal context for the plugin)
115  * @param iter maybe NULL (to just count)
116  * @param iter_cls closure for @a iter
117  * @return the number of results found (zero or one)
118  */
119 static unsigned int
120 template_plugin_get_random (void *cls,
121                             GNUNET_DATACACHE_Iterator iter,
122                             void *iter_cls)
123 {
124   GNUNET_break (0);
125   return 0;
126 }
127
128
129 /**
130  * Iterate over the results that are "close" to a particular key in
131  * the datacache.  "close" is defined as numerically larger than @a
132  * key (when interpreted as a circular address space), with small
133  * distance.
134  *
135  * @param cls closure (internal context for the plugin)
136  * @param key area of the keyspace to look into
137  * @param num_results number of results that should be returned to @a iter
138  * @param iter maybe NULL (to just count)
139  * @param iter_cls closure for @a iter
140  * @return the number of results found
141  */
142 static unsigned int
143 template_plugin_get_closest (void *cls,
144                              const struct GNUNET_HashCode *key,
145                              unsigned int num_results,
146                              GNUNET_DATACACHE_Iterator iter,
147                              void *iter_cls)
148 {
149   GNUNET_break (0);
150   return 0;
151 }
152
153
154 /**
155  * Entry point for the plugin.
156  *
157  * @param cls closure (the `struct GNUNET_DATACACHE_PluginEnvironmnet`)
158  * @return the plugin's closure (our `struct Plugin`)
159  */
160 void *
161 libgnunet_plugin_datacache_template_init (void *cls)
162 {
163   struct GNUNET_DATACACHE_PluginEnvironment *env = cls;
164   struct GNUNET_DATACACHE_PluginFunctions *api;
165   struct Plugin *plugin;
166
167   plugin = GNUNET_new (struct Plugin);
168   plugin->env = env;
169   api = GNUNET_new (struct GNUNET_DATACACHE_PluginFunctions);
170   api->cls = plugin;
171   api->get = &template_plugin_get;
172   api->put = &template_plugin_put;
173   api->del = &template_plugin_del;
174   api->get_random = &template_plugin_get_random;
175   api->get_closest = &template_plugin_get_closest;
176   GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
177                    "template",
178                    "Template datacache running\n");
179   return api;
180 }
181
182
183 /**
184  * Exit point from the plugin.
185  *
186  * @param cls closure (our `struct Plugin`)
187  * @return NULL
188  */
189 void *
190 libgnunet_plugin_datacache_template_done (void *cls)
191 {
192   struct GNUNET_DATACACHE_PluginFunctions *api = cls;
193   struct Plugin *plugin = api->cls;
194
195   GNUNET_free (plugin);
196   GNUNET_free (api);
197   return NULL;
198 }
199
200
201 /* end of plugin_datacache_template.c */