indentation
[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 *GNUNET_PEERINFO_connect (const struct
58                                                         GNUNET_CONFIGURATION_Handle
59                                                         *cfg);
60
61
62
63 /**
64  * Disconnect from the peerinfo service.  Note that all iterators must
65  * have completed or have been cancelled by the time this function is
66  * called (otherwise, calling this function is a serious error).
67  * Furthermore, if 'GNUNET_PEERINFO_add_peer' operations are still
68  * pending, they will be cancelled silently on disconnect.
69  *
70  * @param h handle to disconnect
71  */
72 void GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
73
74
75 /**
76  * Add a host to the persistent list.  This method operates in 
77  * semi-reliable mode: if the transmission is not completed by
78  * the time 'GNUNET_PEERINFO_disconnect' is called, it will be
79  * aborted.  Furthermore, if a second HELLO is added for the
80  * same peer before the first one was transmitted, PEERINFO may
81  * merge the two HELLOs prior to transmission to the service.
82  *
83  * @param h handle to the peerinfo service
84  * @param hello the verified (!) HELLO message
85  */
86 void
87 GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
88                           const struct GNUNET_HELLO_Message *hello);
89
90
91 /**
92  * Type of an iterator over the hosts.  Note that each
93  * host will be called with each available protocol.
94  *
95  * @param cls closure
96  * @param peer id of the peer, NULL for last call
97  * @param hello hello message for the peer (can be NULL)
98  * @param error message
99  */
100 typedef void
101     (*GNUNET_PEERINFO_Processor) (void *cls,
102                                   const struct GNUNET_PeerIdentity * peer,
103                                   const struct GNUNET_HELLO_Message * hello,
104                                   const char *err_msg);
105
106
107 /**
108  * Handle for cancellation of iteration over peers.
109  */
110 struct GNUNET_PEERINFO_IteratorContext;
111
112
113 /**
114  * Call a method for each known matching host and change its trust
115  * value.  The callback method will be invoked once for each matching
116  * host and then finally once with a NULL pointer.  After that final
117  * invocation, the iterator context must no longer be used.
118  *
119  * Instead of calling this function with 'peer == NULL' 
120  * it is often better to use 'GNUNET_PEERINFO_notify'.
121  * 
122  * @param h handle to the peerinfo service
123  * @param peer restrict iteration to this peer only (can be NULL)
124  * @param timeout how long to wait until timing out
125  * @param callback the method to call for each peer
126  * @param callback_cls closure for callback
127  * @return NULL on error (in this case, 'callback' is never called!), 
128  *         otherwise an iterator context
129  */
130 struct GNUNET_PEERINFO_IteratorContext *GNUNET_PEERINFO_iterate (struct
131                                                                  GNUNET_PEERINFO_Handle
132                                                                  *h,
133                                                                  const struct
134                                                                  GNUNET_PeerIdentity
135                                                                  *peer,
136                                                                  struct
137                                                                  GNUNET_TIME_Relative
138                                                                  timeout,
139                                                                  GNUNET_PEERINFO_Processor
140                                                                  callback,
141                                                                  void
142                                                                  *callback_cls);
143
144
145
146 /**
147  * Cancel an iteration over peer information.
148  *
149  * @param ic context of the iterator to cancel
150  */
151 void
152 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
153
154
155
156 /**
157  * Handle for notifications about changes to the set of known peers.
158  */
159 struct GNUNET_PEERINFO_NotifyContext;
160
161
162 /**
163  * Call a method whenever our known information about peers
164  * changes.  Initially calls the given function for all known
165  * peers and then only signals changes.  Note that it is
166  * possible (i.e. on disconnects) that the callback is called
167  * twice with the same peer information.
168  *
169  * @param cfg configuration to use
170  * @param callback the method to call for each peer
171  * @param callback_cls closure for callback
172  * @return NULL on error
173  */
174 struct GNUNET_PEERINFO_NotifyContext *GNUNET_PEERINFO_notify (const struct
175                                                               GNUNET_CONFIGURATION_Handle
176                                                               *cfg,
177                                                               GNUNET_PEERINFO_Processor
178                                                               callback,
179                                                               void
180                                                               *callback_cls);
181
182
183 /**
184  * Stop notifying about changes.
185  *
186  * @param nc context to stop notifying
187  */
188 void GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
189
190
191 #if 0                           /* keep Emacsens' auto-indent happy */
192 {
193 #endif
194 #ifdef __cplusplus
195 }
196 #endif
197
198
199 /* end of gnunet_peerinfo_service.h */
200 #endif