HKDF (does not work yet)
[oweals/gnunet.git] / src / include / gnunet_peerinfo_service.h
1 /*
2      This file is part of GNUnet
3      (C) 2009, 2010 Christian Grothoff (and other contributing authors)
4
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 2, or (at your
8      option) any later version.
9
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.
14
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.
19 */
20 /**
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) and their trust ratings
24  *   (in memory structure of data/trust)
25  * @author Christian Grothoff
26  */
27
28 #ifndef GNUNET_PEERINFO_SERVICE_H
29 #define GNUNET_PEERINFO_SERVICE_H
30
31 #include "gnunet_common.h"
32 #include "gnunet_configuration_lib.h"
33 #include "gnunet_crypto_lib.h"
34 #include "gnunet_hello_lib.h"
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #if 0                           /* keep Emacsens' auto-indent happy */
40 }
41 #endif
42 #endif
43
44
45 /**
46  * Handle to the peerinfo service.
47  */
48 struct GNUNET_PEERINFO_Handle;
49
50
51 /**
52  * Connect to the peerinfo service.
53  *
54  * @param sched scheduler to use
55  * @param cfg configuration to use
56  * @return NULL on error (configuration related, actual connection
57  *         etablishment may happen asynchronously).
58  */
59 struct GNUNET_PEERINFO_Handle *
60 GNUNET_PEERINFO_connect (struct GNUNET_SCHEDULER_Handle *sched,
61                          const struct GNUNET_CONFIGURATION_Handle *cfg);
62                          
63
64
65 /**
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.
71  *
72  * @param h handle to disconnect
73  */
74 void
75 GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
76
77
78 /**
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.
85  *
86  * @param h handle to the peerinfo service
87  * @param hello the verified (!) HELLO message
88  */
89 void
90 GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
91                           const struct GNUNET_HELLO_Message *hello);
92
93
94 /**
95  * Type of an iterator over the hosts.  Note that each
96  * host will be called with each available protocol.
97  *
98  * @param cls closure
99  * @param peer id of the peer, NULL for last call
100  * @param hello hello message for the peer (can be NULL)
101  * @param trust amount of trust we have in the peer
102  */
103 typedef void
104   (*GNUNET_PEERINFO_Processor) (void *cls,
105                                 const struct GNUNET_PeerIdentity * peer,
106                                 const struct GNUNET_HELLO_Message * hello,
107                                 uint32_t trust);
108
109
110 /**
111  * Handle for cancellation of iteration over peers.
112  */
113 struct GNUNET_PEERINFO_IteratorContext;
114
115
116 /**
117  * Call a method for each known matching host and change its trust
118  * value.  The callback method will be invoked once for each matching
119  * host and then finally once with a NULL pointer.  After that final
120  * invocation, the iterator context must no longer be used.
121  *
122  * Note that the last call can be triggered by timeout or by simply
123  * being done; however, the trust argument will be set to zero if we
124  * are done, 1 if we timed out and 2 for fatal error.
125  *
126  * Instead of calling this function with 'peer == NULL' and 'trust ==
127  * 0', it is often better to use 'GNUNET_PEERINFO_notify'.
128  * 
129  * @param h handle to the peerinfo service
130  * @param peer restrict iteration to this peer only (can be NULL)
131  * @param trust_delta how much to change the trust in all matching peers
132  * @param timeout how long to wait until timing out
133  * @param callback the method to call for each peer
134  * @param callback_cls closure for callback
135  * @return NULL on error (in this case, 'callback' is never called!), 
136  *         otherwise an iterator context
137  */
138 struct GNUNET_PEERINFO_IteratorContext *
139 GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
140                          const struct GNUNET_PeerIdentity *peer,
141                          int trust_delta,
142                          struct GNUNET_TIME_Relative timeout,
143                          GNUNET_PEERINFO_Processor callback,
144                          void *callback_cls);
145
146
147
148 /**
149  * Cancel an iteration over peer information.
150  *
151  * @param ic context of the iterator to cancel
152  */
153 void
154 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
155
156
157
158 /**
159  * Handle for notifications about changes to the set of known peers.
160  */
161 struct GNUNET_PEERINFO_NotifyContext;
162
163
164 /**
165  * Call a method whenever our known information about peers
166  * changes.  Initially calls the given function for all known
167  * peers and then only signals changes.  Note that it is
168  * possible (i.e. on disconnects) that the callback is called
169  * twice with the same peer information.
170  *
171  * @param cfg configuration to use
172  * @param sched scheduler to use
173  * @param callback the method to call for each peer
174  * @param callback_cls closure for callback
175  * @return NULL on error
176  */
177 struct GNUNET_PEERINFO_NotifyContext *
178 GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
179                         struct GNUNET_SCHEDULER_Handle *sched,
180                         GNUNET_PEERINFO_Processor callback,
181                         void *callback_cls);
182
183
184 /**
185  * Stop notifying about changes.
186  *
187  * @param nc context to stop notifying
188  */
189 void
190 GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
191
192
193 #if 0                           /* keep Emacsens' auto-indent happy */
194 {
195 #endif
196 #ifdef __cplusplus
197 }
198 #endif
199
200
201 /* end of gnunet_peerinfo_service.h */
202 #endif