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 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.
16 * @author Christian Grothoff
19 * Maintain the list of currently known hosts
21 * @defgroup peerinfo Peer Info service
22 * Maintain the list of currently known hosts.
24 * Holds an in-memory structure of data/hosts.
26 * @see [Documentation](https://gnunet.org/gnunets-peerinfo-subsystem)
31 #ifndef GNUNET_PEERINFO_SERVICE_H
32 #define GNUNET_PEERINFO_SERVICE_H
34 #include "gnunet_common.h"
35 #include "gnunet_configuration_lib.h"
36 #include "gnunet_crypto_lib.h"
37 #include "gnunet_hello_lib.h"
42 #if 0 /* keep Emacsens' auto-indent happy */
49 * Handle to the peerinfo service.
51 struct GNUNET_PEERINFO_Handle;
55 * Connect to the peerinfo service.
57 * @param cfg configuration to use
58 * @return NULL on error (configuration related, actual connection
59 * etablishment may happen asynchronously).
61 struct GNUNET_PEERINFO_Handle *
62 GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
66 * Disconnect from the peerinfo service. Note that all iterators must
67 * have completed or have been cancelled by the time this function is
68 * called (otherwise, calling this function is a serious error).
69 * Furthermore, if #GNUNET_PEERINFO_add_peer() operations are still
70 * pending, they will be cancelled silently on disconnect.
72 * @param h handle to disconnect
75 GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
79 * Add a host to the persistent list. This method operates in
80 * semi-reliable mode: if the transmission is not completed by
81 * the time #GNUNET_PEERINFO_disconnect() is called, it will be
82 * aborted. Furthermore, if a second HELLO is added for the
83 * same peer before the first one was transmitted, PEERINFO may
84 * merge the two HELLOs prior to transmission to the service.
86 * @param h handle to the peerinfo service
87 * @param hello the verified (!) HELLO message
88 * @param cont continuation to call when done, NULL is allowed
89 * @param cont_cls closure for @a cont
90 * @return handle to cancel add operation; all pending
91 * 'add' operations will be cancelled automatically
92 * on disconnect, so it is not necessary to keep this
93 * handle (unless @a cont is non-NULL and at some point
94 * calling @a cont must be prevented)
96 struct GNUNET_MQ_Envelope *
97 GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
98 const struct GNUNET_HELLO_Message *hello,
99 GNUNET_SCHEDULER_TaskCallback cont,
104 * Type of an iterator over the hosts. Note that each
105 * host will be called with each available protocol.
108 * @param peer id of the peer, NULL for last call
109 * @param hello hello message for the peer (can be NULL)
110 * @param error message
113 (*GNUNET_PEERINFO_Processor) (void *cls,
114 const struct GNUNET_PeerIdentity *peer,
115 const struct GNUNET_HELLO_Message *hello,
116 const char *err_msg);
120 * Handle for cancellation of iteration over peers.
122 struct GNUNET_PEERINFO_IteratorContext;
126 * Call a method for each known matching host. The callback method
127 * will be invoked once for each matching host and then finally once
128 * with a NULL pointer. After that final invocation, the iterator
129 * context must no longer be used.
131 * Instead of calling this function with `peer == NULL` it is often
132 * better to use #GNUNET_PEERINFO_notify().
134 * @param h handle to the peerinfo service
135 * @param include_friend_only include HELLO messages for friends only
136 * @param peer restrict iteration to this peer only (can be NULL)
137 * @param timeout how long to wait until timing out
138 * @param callback the method to call for each peer
139 * @param callback_cls closure for @a callback
140 * @return iterator context
142 struct GNUNET_PEERINFO_IteratorContext *
143 GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
144 int include_friend_only,
145 const struct GNUNET_PeerIdentity *peer,
146 GNUNET_PEERINFO_Processor callback,
151 * Cancel an iteration over peer information.
153 * @param ic context of the iterator to cancel
156 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
160 * Handle for notifications about changes to the set of known peers.
162 struct GNUNET_PEERINFO_NotifyContext;
166 * Call a method whenever our known information about peers
167 * changes. Initially calls the given function for all known
168 * peers and then only signals changes.
170 * If @a include_friend_only is set to #GNUNET_YES peerinfo will include HELLO
171 * messages which are intended for friend to friend mode and which do not
172 * have to be gossiped. Otherwise these messages are skipped.
174 * @param cfg configuration to use
175 * @param include_friend_only include HELLO messages for friends only
176 * @param callback the method to call for each peer
177 * @param callback_cls closure for @a callback
178 * @return NULL on error
180 struct GNUNET_PEERINFO_NotifyContext *
181 GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
182 int include_friend_only,
183 GNUNET_PEERINFO_Processor callback,
188 * Stop notifying about changes.
190 * @param nc context to stop notifying
193 GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
196 #if 0 /* keep Emacsens' auto-indent happy */
205 /** @} */ /* end of group */