-skeletons for transport-ng
[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
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 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, void *iter_cls);
105
106   /**
107    * Delete expired records (expiry < now)
108    *
109    * @param cls closure (internal context for the plugin)
110    * @param now time to use as reference
111    * @param cont continuation called with the number of records expired
112    * @param cont_cls continuation closure
113    * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and cont is not
114    * called
115    */
116   int
117   (*expire_records) (void *cls,
118       struct GNUNET_TIME_Absolute now,
119       GNUNET_PEERSTORE_Continuation cont,
120       void *cont_cls);
121
122 };
123
124
125 #if 0                           /* keep Emacsens' auto-indent happy */
126 {
127 #endif
128 #ifdef __cplusplus
129 }
130 #endif
131
132 #endif
133
134 /** @} */  /* end of group */