ce473b508a6cda65ba543c30cd122ac157e443f8
[oweals/gnunet.git] / src / include / gnunet_peerstore_plugin.h
1 /*
2      This file is part of GNUnet
3      (C) 2012, 2013 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_peerstore_plugin.h
23  * @brief plugin API for the peerstore database backend
24  * @author Omar Tarabai
25  */
26 #ifndef GNUNET_PEERSTORE_PLUGIN_H
27 #define GNUNET_PEERSTORE_PLUGIN_H
28
29 #include "gnunet_util_lib.h"
30 #include "gnunet_peerstore_service.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40
41 /**
42  * Function called by for each matching record.
43  *
44  * @param cls closure
45  * @param peer peer identity
46  * @param sub_system name of the GNUnet sub system responsible
47  * @param value stored value
48  * @param size size of stored value
49  */
50 typedef void (*GNUNET_PEERSTORE_RecordIterator) (void *cls,
51     const char *sub_system,
52     const struct GNUNET_PeerIdentity *peer,
53     const char *key,
54     const void *value,
55     size_t size);
56
57 /**
58  * @brief struct returned by the initialization function of the plugin
59  */
60 struct GNUNET_PEERSTORE_PluginFunctions
61 {
62
63   /**
64    * Closure to pass to all plugin functions.
65    */
66   void *cls;
67
68   /**
69    * Store a record in the peerstore.
70    * Key is the combination of sub system and peer identity.
71    * One key can store multiple values.
72    *
73    * @param cls closure (internal context for the plugin)
74    * @param sub_system name of the GNUnet sub system responsible
75    * @param peer peer identity
76    * @param value value to be stored
77    * @param size size of value to be stored
78    * @return #GNUNET_OK on success, else #GNUNET_SYSERR
79    */
80   int
81   (*store_record) (void *cls,
82       const char *sub_system,
83       const struct GNUNET_PeerIdentity *peer,
84       const char *key,
85       const void *value,
86       size_t size,
87       struct GNUNET_TIME_Absolute expiry);
88
89   /**
90    * Iterate over the records given an optional peer id
91    * and/or key.
92    *
93    * @param cls closure (internal context for the plugin)
94    * @param sub_system name of sub system
95    * @param peer Peer identity (can be NULL)
96    * @param key entry key string (can be NULL)
97    * @param iter function to call with the result
98    * @param iter_cls closure for @a iter
99    * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
100    */
101   int
102   (*iterate_records) (void *cls,
103       const char *sub_system,
104       const struct GNUNET_PeerIdentity *peer,
105       const char *key,
106       GNUNET_PEERSTORE_RecordIterator iter, void *iter_cls);
107
108 };
109
110
111 #if 0                           /* keep Emacsens' auto-indent happy */
112 {
113 #endif
114 #ifdef __cplusplus
115 }
116 #endif
117
118 /* end of gnunet_peerstore_plugin.h */
119 #endif