2 This file is part of GNUnet
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
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
27 #ifndef GNUNET_PEERINFO_SERVICE_H
28 #define GNUNET_PEERINFO_SERVICE_H
30 #include "gnunet_common.h"
31 #include "gnunet_configuration_lib.h"
32 #include "gnunet_crypto_lib.h"
33 #include "gnunet_hello_lib.h"
38 #if 0 /* keep Emacsens' auto-indent happy */
45 * Handle to the peerinfo service.
47 struct GNUNET_PEERINFO_Handle;
51 * Connect to the peerinfo service.
53 * @param sched scheduler to use
54 * @param cfg configuration to use
55 * @return NULL on error (configuration related, actual connection
56 * etablishment may happen asynchronously).
58 struct GNUNET_PEERINFO_Handle *
59 GNUNET_PEERINFO_connect (struct GNUNET_SCHEDULER_Handle *sched,
60 const struct GNUNET_CONFIGURATION_Handle *cfg);
65 * Disconnect from the peerinfo service. Note that all iterators must
66 * have completed or have been cancelled by the time this function is
67 * called (otherwise, calling this function is a serious error).
68 * Furthermore, if 'GNUNET_PEERINFO_add_peer' operations are still
69 * pending, they will be cancelled silently on disconnect.
71 * @param h handle to disconnect
74 GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
78 * Add a host to the persistent list. This method operates in
79 * semi-reliable mode: if the transmission is not completed by
80 * the time 'GNUNET_PEERINFO_disconnect' is called, it will be
81 * aborted. Furthermore, if a second HELLO is added for the
82 * same peer before the first one was transmitted, PEERINFO may
83 * merge the two HELLOs prior to transmission to the service.
85 * @param h handle to the peerinfo service
86 * @param hello the verified (!) HELLO message
89 GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
90 const struct GNUNET_HELLO_Message *hello);
94 * Type of an iterator over the hosts. Note that each
95 * host will be called with each available protocol.
98 * @param peer id of the peer, NULL for last call
99 * @param hello hello message for the peer (can be NULL)
102 (*GNUNET_PEERINFO_Processor) (void *cls,
103 const struct GNUNET_PeerIdentity * peer,
104 const struct GNUNET_HELLO_Message * hello);
108 * Handle for cancellation of iteration over peers.
110 struct GNUNET_PEERINFO_IteratorContext;
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.
119 * Note that the last call can be triggered by timeout or by simply
120 * being done; however, the trust argument will be set to zero if we
121 * are done, 1 if we timed out and 2 for fatal error.
123 * Instead of calling this function with 'peer == NULL'
124 * it is often better to use 'GNUNET_PEERINFO_notify'.
126 * @param h handle to the peerinfo service
127 * @param peer restrict iteration to this peer only (can be NULL)
128 * @param timeout how long to wait until timing out
129 * @param callback the method to call for each peer
130 * @param callback_cls closure for callback
131 * @return NULL on error (in this case, 'callback' is never called!),
132 * otherwise an iterator context
134 struct GNUNET_PEERINFO_IteratorContext *
135 GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
136 const struct GNUNET_PeerIdentity *peer,
137 struct GNUNET_TIME_Relative timeout,
138 GNUNET_PEERINFO_Processor callback,
144 * Cancel an iteration over peer information.
146 * @param ic context of the iterator to cancel
149 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
154 * Handle for notifications about changes to the set of known peers.
156 struct GNUNET_PEERINFO_NotifyContext;
160 * Call a method whenever our known information about peers
161 * changes. Initially calls the given function for all known
162 * peers and then only signals changes. Note that it is
163 * possible (i.e. on disconnects) that the callback is called
164 * twice with the same peer information.
166 * @param cfg configuration to use
167 * @param sched scheduler to use
168 * @param callback the method to call for each peer
169 * @param callback_cls closure for callback
170 * @return NULL on error
172 struct GNUNET_PEERINFO_NotifyContext *
173 GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
174 struct GNUNET_SCHEDULER_Handle *sched,
175 GNUNET_PEERINFO_Processor callback,
180 * Stop notifying about changes.
182 * @param nc context to stop notifying
185 GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
188 #if 0 /* keep Emacsens' auto-indent happy */
196 /* end of gnunet_peerinfo_service.h */