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