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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @author Christian Grothoff
22 * Maintain the list of currently known hosts
24 * @defgroup peerinfo Peer Info service
25 * Maintain the list of currently known hosts.
27 * Holds an in-memory structure of data/hosts.
29 * @see [Documentation](https://gnunet.org/gnunets-peerinfo-subsystem)
34 #ifndef GNUNET_PEERINFO_SERVICE_H
35 #define GNUNET_PEERINFO_SERVICE_H
37 #include "gnunet_common.h"
38 #include "gnunet_configuration_lib.h"
39 #include "gnunet_crypto_lib.h"
40 #include "gnunet_hello_lib.h"
45 #if 0 /* keep Emacsens' auto-indent happy */
52 * Handle to the peerinfo service.
54 struct GNUNET_PEERINFO_Handle;
58 * Connect to the peerinfo service.
60 * @param cfg configuration to use
61 * @return NULL on error (configuration related, actual connection
62 * etablishment may happen asynchronously).
64 struct GNUNET_PEERINFO_Handle *
65 GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
69 * Disconnect from the peerinfo service. Note that all iterators must
70 * have completed or have been cancelled by the time this function is
71 * called (otherwise, calling this function is a serious error).
72 * Furthermore, if #GNUNET_PEERINFO_add_peer() operations are still
73 * pending, they will be cancelled silently on disconnect.
75 * @param h handle to disconnect
78 GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
82 * Add a host to the persistent list. This method operates in
83 * semi-reliable mode: if the transmission is not completed by
84 * the time #GNUNET_PEERINFO_disconnect() is called, it will be
85 * aborted. Furthermore, if a second HELLO is added for the
86 * same peer before the first one was transmitted, PEERINFO may
87 * merge the two HELLOs prior to transmission to the service.
89 * @param h handle to the peerinfo service
90 * @param hello the verified (!) HELLO message
91 * @param cont continuation to call when done, NULL is allowed
92 * @param cont_cls closure for @a cont
93 * @return handle to cancel add operation; all pending
94 * 'add' operations will be cancelled automatically
95 * on disconnect, so it is not necessary to keep this
96 * handle (unless @a cont is non-NULL and at some point
97 * calling @a cont must be prevented)
99 struct GNUNET_MQ_Envelope *
100 GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
101 const struct GNUNET_HELLO_Message *hello,
102 GNUNET_SCHEDULER_TaskCallback cont,
107 * Type of an iterator over the hosts. Note that each
108 * host will be called with each available protocol.
111 * @param peer id of the peer, NULL for last call
112 * @param hello hello message for the peer (can be NULL)
113 * @param error message
116 (*GNUNET_PEERINFO_Processor) (void *cls,
117 const struct GNUNET_PeerIdentity *peer,
118 const struct GNUNET_HELLO_Message *hello,
119 const char *err_msg);
123 * Handle for cancellation of iteration over peers.
125 struct GNUNET_PEERINFO_IteratorContext;
129 * Call a method for each known matching host. The callback method
130 * will be invoked once for each matching host and then finally once
131 * with a NULL pointer. After that final invocation, the iterator
132 * context must no longer be used.
134 * Instead of calling this function with `peer == NULL` it is often
135 * better to use #GNUNET_PEERINFO_notify().
137 * @param h handle to the peerinfo service
138 * @param include_friend_only include HELLO messages for friends only
139 * @param peer restrict iteration to this peer only (can be NULL)
140 * @param timeout how long to wait until timing out
141 * @param callback the method to call for each peer
142 * @param callback_cls closure for @a callback
143 * @return iterator context
145 struct GNUNET_PEERINFO_IteratorContext *
146 GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
147 int include_friend_only,
148 const struct GNUNET_PeerIdentity *peer,
149 GNUNET_PEERINFO_Processor callback,
154 * Cancel an iteration over peer information.
156 * @param ic context of the iterator to cancel
159 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
163 * Handle for notifications about changes to the set of known peers.
165 struct GNUNET_PEERINFO_NotifyContext;
169 * Call a method whenever our known information about peers
170 * changes. Initially calls the given function for all known
171 * peers and then only signals changes.
173 * If @a include_friend_only is set to #GNUNET_YES peerinfo will include HELLO
174 * messages which are intended for friend to friend mode and which do not
175 * have to be gossiped. Otherwise these messages are skipped.
177 * @param cfg configuration to use
178 * @param include_friend_only include HELLO messages for friends only
179 * @param callback the method to call for each peer
180 * @param callback_cls closure for @a callback
181 * @return NULL on error
183 struct GNUNET_PEERINFO_NotifyContext *
184 GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
185 int include_friend_only,
186 GNUNET_PEERINFO_Processor callback,
191 * Stop notifying about changes.
193 * @param nc context to stop notifying
196 GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
199 #if 0 /* keep Emacsens' auto-indent happy */
208 /** @} */ /* end of group */