src: for every AGPL3.0 file, add SPDX identifier.
[oweals/gnunet.git] / src / include / gnunet_peerstore_plugin.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2012, 2013 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  * @author Omar Tarabai
23  *
24  * @file
25  * Plugin API for the peerstore database backend
26  *
27  * @defgroup peerstore-plugin  Peer Store service plugin API
28  * Plugin API for the peerstore database backend
29  * @{
30  */
31 #ifndef GNUNET_PEERSTORE_PLUGIN_H
32 #define GNUNET_PEERSTORE_PLUGIN_H
33
34 #include "gnunet_util_lib.h"
35 #include "gnunet_peerstore_service.h"
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #if 0                           /* keep Emacsens' auto-indent happy */
41 }
42 #endif
43 #endif
44
45
46 /**
47  * @brief struct returned by the initialization function of the plugin
48  */
49 struct GNUNET_PEERSTORE_PluginFunctions
50 {
51
52   /**
53    * Closure to pass to all plugin functions.
54    */
55   void *cls;
56
57   /**
58    * Store a record in the peerstore.
59    * Key is the combination of sub system and peer identity.
60    * One key can store multiple values.
61    *
62    * @param cls closure (internal context for the plugin)
63    * @param sub_system name of the GNUnet sub system responsible
64    * @param peer peer identity
65    * @param value value to be stored
66    * @param size size of value to be stored
67    * @param expiry absolute time after which the record is (possibly) deleted
68    * @param options options related to the store operation
69    * @param cont continuation called when record is stored
70    * @param cont_cls continuation closure
71    * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called
72    */
73   int
74   (*store_record) (void *cls,
75                    const char *sub_system,
76                    const struct GNUNET_PeerIdentity *peer,
77                    const char *key,
78                    const void *value,
79                    size_t size,
80                    struct GNUNET_TIME_Absolute expiry,
81                    enum GNUNET_PEERSTORE_StoreOption options,
82                    GNUNET_PEERSTORE_Continuation cont,
83                    void *cont_cls);
84
85   /**
86    * Iterate over the records given an optional peer id
87    * and/or key.
88    *
89    * @param cls closure (internal context for the plugin)
90    * @param sub_system name of sub system
91    * @param peer Peer identity (can be NULL)
92    * @param key entry key string (can be NULL)
93    * @param iter function to call asynchronously with the results, terminated
94    * by a NULL result
95    * @param iter_cls closure for @a iter
96    * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and iter is not
97    * called
98    */
99   int
100   (*iterate_records) (void *cls,
101                       const char *sub_system,
102                       const struct GNUNET_PeerIdentity *peer,
103                       const char *key,
104                       GNUNET_PEERSTORE_Processor iter,
105                       void *iter_cls);
106
107   /**
108    * Delete expired records (expiry < now)
109    *
110    * @param cls closure (internal context for the plugin)
111    * @param now time to use as reference
112    * @param cont continuation called with the number of records expired
113    * @param cont_cls continuation closure
114    * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and cont is not
115    * called
116    */
117   int
118   (*expire_records) (void *cls,
119                      struct GNUNET_TIME_Absolute now,
120                      GNUNET_PEERSTORE_Continuation cont,
121                      void *cont_cls);
122
123 };
124
125
126 #if 0                           /* keep Emacsens' auto-indent happy */
127 {
128 #endif
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif
134
135 /** @} */  /* end of group */