missing function reference
[oweals/gnunet.git] / src / include / gnunet_peerinfo_service.h
1 /*
2      This file is part of GNUnet
3      (C) 2009 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  * Add a host to the persistent list.
47  *
48  * @param cfg configuration to use
49  * @param sched scheduler to use
50  * @param peer identity of the peer
51  * @param hello the verified (!) HELLO message
52  */
53 void
54 GNUNET_PEERINFO_add_peer (const struct GNUNET_CONFIGURATION_Handle *cfg,
55                           struct GNUNET_SCHEDULER_Handle *sched,
56                           const struct GNUNET_PeerIdentity *peer,
57                           const struct GNUNET_HELLO_Message *hello);
58
59 /**
60  * Type of an iterator over the hosts.  Note that each
61  * host will be called with each available protocol.
62  *
63  * @param cls closure
64  * @param peer id of the peer, NULL for last call
65  * @param hello hello message for the peer (can be NULL)
66  * @param trust amount of trust we have in the peer
67  */
68 typedef void
69   (*GNUNET_PEERINFO_Processor) (void *cls,
70                                 const struct GNUNET_PeerIdentity * peer,
71                                 const struct GNUNET_HELLO_Message * hello,
72                                 uint32_t trust);
73
74
75 /**
76  * Handle for cancellation of iteration over peers.
77  */
78 struct GNUNET_PEERINFO_IteratorContext;
79
80
81 /**
82  * Call a method for each known matching host and change
83  * its trust value.  The method will be invoked once for
84  * each host and then finally once with a NULL pointer.  After
85  * that final invocation, the iterator context must no longer
86  * be used.
87  *
88  * Note that the last call can be triggered by timeout or by simply
89  * being done; however, the trust argument will be set to zero if we
90  * are done, 1 if we timed out and 2 for fatal error.
91  *
92  * @param cfg configuration to use
93  * @param sched scheduler to use
94  * @param peer restrict iteration to this peer only (can be NULL)
95  * @param trust_delta how much to change the trust in all matching peers
96  * @param timeout how long to wait until timing out
97  * @param callback the method to call for each peer
98  * @param callback_cls closure for callback
99  * @return NULL on error (in this case, 'callback' is never called!), 
100  *         otherwise an iterator context
101  */
102 struct GNUNET_PEERINFO_IteratorContext *
103 GNUNET_PEERINFO_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
104                          struct GNUNET_SCHEDULER_Handle *sched,
105                          const struct GNUNET_PeerIdentity *peer,
106                          int trust_delta,
107                          struct GNUNET_TIME_Relative timeout,
108                          GNUNET_PEERINFO_Processor callback,
109                          void *callback_cls);
110
111
112 /**
113  * Cancel an iteration over peer information.
114  *
115  * @param ic context of the iterator to cancel
116  */
117 void
118 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
119
120
121 /**
122  * Handle for notifications about changes to the set of known peers.
123  */
124 struct GNUNET_PEERINFO_NotifyContext;
125
126
127 /**
128  * Call a method whenever our known information about peers
129  * changes.  Initially calls the given function for all known
130  * peers and then only signals changes.  Note that it is
131  * possible (i.e. on disconnects) that the callback is called
132  * twice with the same peer information.
133  *
134  * @param cfg configuration to use
135  * @param sched scheduler to use
136  * @param callback the method to call for each peer
137  * @param callback_cls closure for callback
138  * @return NULL on error
139  */
140 struct GNUNET_PEERINFO_NotifyContext *
141 GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
142                         struct GNUNET_SCHEDULER_Handle *sched,
143                         GNUNET_PEERINFO_Processor callback,
144                         void *callback_cls);
145
146
147 /**
148  * Stop notifying about changes.
149  *
150  * @param nc context to stop notifying
151  */
152 void
153 GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
154
155
156 #if 0                           /* keep Emacsens' auto-indent happy */
157 {
158 #endif
159 #ifdef __cplusplus
160 }
161 #endif
162
163
164 /* end of gnunet_peerinfo_service.h */
165 #endif