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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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 * Add a host to the persistent list. This method operates in
85 * semi-reliable mode: if the transmission is not completed by
86 * the time #GNUNET_PEERINFO_disconnect() is called, it will be
87 * aborted. Furthermore, if a second HELLO is added for the
88 * same peer before the first one was transmitted, PEERINFO may
89 * merge the two HELLOs prior to transmission to the service.
91 * @param h handle to the peerinfo service
92 * @param hello the verified (!) HELLO message
93 * @param cont continuation to call when done, NULL is allowed
94 * @param cont_cls closure for @a cont
95 * @return handle to cancel add operation; all pending
96 * 'add' operations will be cancelled automatically
97 * on disconnect, so it is not necessary to keep this
98 * handle (unless @a cont is non-NULL and at some point
99 * calling @a cont must be prevented)
101 struct GNUNET_MQ_Envelope *
102 GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
103 const struct GNUNET_HELLO_Message *hello,
104 GNUNET_SCHEDULER_TaskCallback cont,
109 * Type of an iterator over the hosts. Note that each
110 * host will be called with each available protocol.
113 * @param peer id of the peer, NULL for last call
114 * @param hello hello message for the peer (can be NULL)
115 * @param error message
118 (*GNUNET_PEERINFO_Processor) (void *cls,
119 const struct GNUNET_PeerIdentity *peer,
120 const struct GNUNET_HELLO_Message *hello,
121 const char *err_msg);
125 * Handle for cancellation of iteration over peers.
127 struct GNUNET_PEERINFO_IteratorContext;
131 * Call a method for each known matching host. The callback method
132 * will be invoked once for each matching host and then finally once
133 * with a NULL pointer. After that final invocation, the iterator
134 * context must no longer be used.
136 * Instead of calling this function with `peer == NULL` it is often
137 * better to use #GNUNET_PEERINFO_notify().
139 * @param h handle to the peerinfo service
140 * @param include_friend_only include HELLO messages for friends only
141 * @param peer restrict iteration to this peer only (can be NULL)
142 * @param timeout how long to wait until timing out
143 * @param callback the method to call for each peer
144 * @param callback_cls closure for @a callback
145 * @return iterator context
147 struct GNUNET_PEERINFO_IteratorContext *
148 GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
149 int include_friend_only,
150 const struct GNUNET_PeerIdentity *peer,
151 GNUNET_PEERINFO_Processor callback,
156 * Cancel an iteration over peer information.
158 * @param ic context of the iterator to cancel
161 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
165 * Handle for notifications about changes to the set of known peers.
167 struct GNUNET_PEERINFO_NotifyContext;
171 * Call a method whenever our known information about peers
172 * changes. Initially calls the given function for all known
173 * peers and then only signals changes.
175 * If @a include_friend_only is set to #GNUNET_YES peerinfo will include HELLO
176 * messages which are intended for friend to friend mode and which do not
177 * have to be gossiped. Otherwise these messages are skipped.
179 * @param cfg configuration to use
180 * @param include_friend_only include HELLO messages for friends only
181 * @param callback the method to call for each peer
182 * @param callback_cls closure for @a callback
183 * @return NULL on error
185 struct GNUNET_PEERINFO_NotifyContext *
186 GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
187 int include_friend_only,
188 GNUNET_PEERINFO_Processor callback,
193 * Stop notifying about changes.
195 * @param nc context to stop notifying
198 GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
201 #if 0 /* keep Emacsens' auto-indent happy */
210 /** @} */ /* end of group */