2 This file is part of GNUnet
3 Copyright (C) 2009, 2010 GNUnet e.V.
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.
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.
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.
21 * @author Christian Grothoff
24 * Maintain the list of currently known hosts
26 * @defgroup peerinfo Peer Info service
27 * Maintain the list of currently known hosts.
29 * Holds an in-memory structure of data/hosts.
31 * @see [Documentation](https://gnunet.org/gnunets-peerinfo-subsystem)
36 #ifndef GNUNET_PEERINFO_SERVICE_H
37 #define GNUNET_PEERINFO_SERVICE_H
39 #include "gnunet_common.h"
40 #include "gnunet_configuration_lib.h"
41 #include "gnunet_crypto_lib.h"
42 #include "gnunet_hello_lib.h"
47 #if 0 /* keep Emacsens' auto-indent happy */
54 * Handle to the peerinfo service.
56 struct GNUNET_PEERINFO_Handle;
60 * Connect to the peerinfo service.
62 * @param cfg configuration to use
63 * @return NULL on error (configuration related, actual connection
64 * etablishment may happen asynchronously).
66 struct GNUNET_PEERINFO_Handle *
67 GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
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.
77 * @param h handle to disconnect
80 GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
84 * Continuation called with a status result.
87 * @param emsg error message, NULL on success
90 (*GNUNET_PEERINFO_Continuation)(void *cls,
95 * Opaque handle to cancel 'add' operation.
97 struct GNUNET_PEERINFO_AddContext;
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.
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)
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,
126 * Cancel pending 'add' operation. Must only be called before
127 * either 'cont' or #GNUNET_PEERINFO_disconnect() are invoked.
129 * @param ac handle for the add operation to cancel
132 GNUNET_PEERINFO_add_peer_cancel (struct GNUNET_PEERINFO_AddContext *ac);
136 * Type of an iterator over the hosts. Note that each
137 * host will be called with each available protocol.
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
145 (*GNUNET_PEERINFO_Processor) (void *cls,
146 const struct GNUNET_PeerIdentity *peer,
147 const struct GNUNET_HELLO_Message *hello,
148 const char *err_msg);
152 * Handle for cancellation of iteration over peers.
154 struct GNUNET_PEERINFO_IteratorContext;
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.
163 * Instead of calling this function with `peer == NULL` it is often
164 * better to use #GNUNET_PEERINFO_notify().
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
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);
183 * Cancel an iteration over peer information.
185 * @param ic context of the iterator to cancel
188 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
192 * Handle for notifications about changes to the set of known peers.
194 struct GNUNET_PEERINFO_NotifyContext;
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.
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.
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
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,
220 * Stop notifying about changes.
222 * @param nc context to stop notifying
225 GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
228 #if 0 /* keep Emacsens' auto-indent happy */
237 /** @} */ /* end of group */