- build rest before jsonapi
[oweals/gnunet.git] / src / include / gnunet_peerinfo_service.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2009, 2010 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  * @author Christian Grothoff
22  *
23  * @file
24  * Maintain the list of currently known hosts
25  *
26  * @defgroup peerinfo  Peer Info service
27  * Maintain the list of currently known hosts.
28  *
29  * Holds an in-memory structure of data/hosts.
30  *
31  * @see [Documentation](https://gnunet.org/gnunets-peerinfo-subsystem)
32  *
33  * @{
34  */
35
36 #ifndef GNUNET_PEERINFO_SERVICE_H
37 #define GNUNET_PEERINFO_SERVICE_H
38
39 #include "gnunet_common.h"
40 #include "gnunet_configuration_lib.h"
41 #include "gnunet_crypto_lib.h"
42 #include "gnunet_hello_lib.h"
43
44 #ifdef __cplusplus
45 extern "C"
46 {
47 #if 0                           /* keep Emacsens' auto-indent happy */
48 }
49 #endif
50 #endif
51
52
53 /**
54  * Handle to the peerinfo service.
55  */
56 struct GNUNET_PEERINFO_Handle;
57
58
59 /**
60  * Connect to the peerinfo service.
61  *
62  * @param cfg configuration to use
63  * @return NULL on error (configuration related, actual connection
64  *         etablishment may happen asynchronously).
65  */
66 struct GNUNET_PEERINFO_Handle *
67 GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
68
69
70 /**
71  * Disconnect from the peerinfo service.  Note that all iterators must
72  * have completed or have been cancelled by the time this function is
73  * called (otherwise, calling this function is a serious error).
74  * Furthermore, if #GNUNET_PEERINFO_add_peer() operations are still
75  * pending, they will be cancelled silently on disconnect.
76  *
77  * @param h handle to disconnect
78  */
79 void
80 GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
81
82
83 /**
84  * Continuation called with a status result.
85  *
86  * @param cls closure
87  * @param emsg error message, NULL on success
88  */
89 typedef void
90 (*GNUNET_PEERINFO_Continuation)(void *cls,
91                                 const char *emsg);
92
93
94 /**
95  * Opaque handle to cancel 'add' operation.
96  */
97 struct GNUNET_PEERINFO_AddContext;
98
99
100 /**
101  * Add a host to the persistent list.  This method operates in
102  * semi-reliable mode: if the transmission is not completed by
103  * the time #GNUNET_PEERINFO_disconnect() is called, it will be
104  * aborted.  Furthermore, if a second HELLO is added for the
105  * same peer before the first one was transmitted, PEERINFO may
106  * merge the two HELLOs prior to transmission to the service.
107  *
108  * @param h handle to the peerinfo service
109  * @param hello the verified (!) HELLO message
110  * @param cont continuation to call when done, NULL is allowed
111  * @param cont_cls closure for @a cont
112  * @return handle to cancel add operation; all pending
113  *         'add' operations will be cancelled automatically
114  *        on disconnect, so it is not necessary to keep this
115  *        handle (unless @a cont is NULL and at some point
116  *        calling @a cont must be prevented)
117  */
118 struct GNUNET_PEERINFO_AddContext *
119 GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
120                           const struct GNUNET_HELLO_Message *hello,
121                           GNUNET_PEERINFO_Continuation cont,
122                           void *cont_cls);
123
124
125 /**
126  * Cancel pending 'add' operation.  Must only be called before
127  * either 'cont' or #GNUNET_PEERINFO_disconnect() are invoked.
128  *
129  * @param ac handle for the add operation to cancel
130  */
131 void
132 GNUNET_PEERINFO_add_peer_cancel (struct GNUNET_PEERINFO_AddContext *ac);
133
134
135 /**
136  * Type of an iterator over the hosts.  Note that each
137  * host will be called with each available protocol.
138  *
139  * @param cls closure
140  * @param peer id of the peer, NULL for last call
141  * @param hello hello message for the peer (can be NULL)
142  * @param error message
143  */
144 typedef void
145 (*GNUNET_PEERINFO_Processor) (void *cls,
146                               const struct GNUNET_PeerIdentity *peer,
147                               const struct GNUNET_HELLO_Message *hello,
148                               const char *err_msg);
149
150
151 /**
152  * Handle for cancellation of iteration over peers.
153  */
154 struct GNUNET_PEERINFO_IteratorContext;
155
156
157 /**
158  * Call a method for each known matching host.  The callback method
159  * will be invoked once for each matching host and then finally once
160  * with a NULL pointer.  After that final invocation, the iterator
161  * context must no longer be used.
162  *
163  * Instead of calling this function with `peer == NULL` it is often
164  * better to use #GNUNET_PEERINFO_notify().
165  *
166  * @param h handle to the peerinfo service
167  * @param include_friend_only include HELLO messages for friends only
168  * @param peer restrict iteration to this peer only (can be NULL)
169  * @param timeout how long to wait until timing out
170  * @param callback the method to call for each peer
171  * @param callback_cls closure for @a callback
172  * @return iterator context
173  */
174 struct GNUNET_PEERINFO_IteratorContext *
175 GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
176                          int include_friend_only,
177                          const struct GNUNET_PeerIdentity *peer,
178                          struct GNUNET_TIME_Relative timeout,
179                          GNUNET_PEERINFO_Processor callback, void *callback_cls);
180
181
182 /**
183  * Cancel an iteration over peer information.
184  *
185  * @param ic context of the iterator to cancel
186  */
187 void
188 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
189
190
191 /**
192  * Handle for notifications about changes to the set of known peers.
193  */
194 struct GNUNET_PEERINFO_NotifyContext;
195
196
197 /**
198  * Call a method whenever our known information about peers
199  * changes.  Initially calls the given function for all known
200  * peers and then only signals changes.
201  *
202  * If include_friend_only is set to GNUNET_YES peerinfo will include HELLO
203  * messages which are intended for friend to friend mode and which do not
204  * have to be gossiped. Otherwise these messages are skipped.
205  *
206  * @param cfg configuration to use
207  * @param include_friend_only include HELLO messages for friends only
208  * @param callback the method to call for each peer
209  * @param callback_cls closure for @a callback
210  * @return NULL on error
211  */
212 struct GNUNET_PEERINFO_NotifyContext *
213 GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
214                         int include_friend_only,
215                         GNUNET_PEERINFO_Processor callback,
216                         void *callback_cls);
217
218
219 /**
220  * Stop notifying about changes.
221  *
222  * @param nc context to stop notifying
223  */
224 void
225 GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
226
227
228 #if 0                           /* keep Emacsens' auto-indent happy */
229 {
230 #endif
231 #ifdef __cplusplus
232 }
233 #endif
234
235 #endif
236
237 /** @} */  /* end of group */