2 This file is part of GNUnet.
3 (C) 2009 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 2, 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.
22 * @file include/gnunet_core_service.h
23 * @brief core service; this is the main API for encrypted P2P
25 * @author Christian Grothoff
28 #ifndef GNUNET_CORE_SERVICE_H
29 #define GNUNET_CORE_SERVICE_H
34 #if 0 /* keep Emacsens' auto-indent happy */
39 #include "gnunet_util_lib.h"
42 * Version number of GNUnet-core API.
44 #define GNUNET_CORE_VERSION 0x00000000
48 * Opaque handle to the service.
50 struct GNUNET_CORE_Handle;
54 * Method called whenever a given peer either connects or
55 * disconnects (or list of connections was requested).
58 * @param peer peer identity this notification is about
60 typedef void (*GNUNET_CORE_ClientEventHandler) (void *cls,
62 GNUNET_PeerIdentity * peer);
66 * Type of a send callback to fill up buffers.
68 * @param receiver the receiver of the message
69 * @param position is the reference to the
70 * first unused position in the buffer where GNUnet is building
72 * @param padding is the number of bytes left in that buffer.
73 * @return the number of bytes written to
74 * that buffer (must be a positive number).
77 (*GNUNET_CORE_BufferFillCallback) (void *cls,
78 const struct GNUNET_PeerIdentity *
85 * Functions with this signature are called whenever a message is
86 * received or transmitted.
89 * @param peer the other peer involved (sender or receiver, NULL
90 * for loopback messages where we are both sender and receiver)
91 * @param message the actual message
92 * @return GNUNET_OK to keep the connection open,
93 * GNUNET_SYSERR to close it (signal serious error)
96 (*GNUNET_CORE_MessageCallback) (void *cls,
97 const struct GNUNET_PeerIdentity * other,
98 const struct GNUNET_MessageHeader *
103 * Message handler. Each struct specifies how to handle on particular
104 * type of message received.
106 struct GNUNET_CORE_MessageHandler
109 * Function to call for messages of "type".
111 GNUNET_CORE_MessageCallback callback;
114 * Type of the message this handler covers.
119 * Expected size of messages of this type. Use 0 for variable-size.
120 * If non-zero, messages of the given type will be discarded if they
121 * do not have the right size.
123 uint16_t expected_size;
129 * Function called after GNUNET_CORE_connect has succeeded
130 * (or failed for good). Note that the private key of the
131 * peer is intentionally not exposed here; if you need it,
132 * your process should try to read the private key file
133 * directly (which should work if you are authorized...).
136 * @param server handle to the server, NULL if we failed
137 * @param my_identity ID of this peer, NULL if we failed
138 * @param publicKey public key of this peer, NULL if we failed
141 (*GNUNET_CORE_StartupCallback) (void *cls,
142 struct GNUNET_CORE_Handle * server,
143 const struct GNUNET_PeerIdentity *
146 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
151 * Connect to the core service. Note that the connection may
152 * complete (or fail) asynchronously.
154 * @param sched scheduler to use
155 * @param cfg configuration to use
156 * @param timeout after how long should we give up trying to connect to the core service?
157 * @param cls closure for the various callbacks that follow (including handlers in the handlers array)
158 * @param init callback to call on timeout or once we have successfully
159 * connected to the core service; note that timeout is only meaningful if init is not NULL
160 * @param connects function to call on peer connect, can be NULL
161 * @param disconnects function to call on peer disconnect / timeout, can be NULL
162 * @param bfc function to call to fill up spare bandwidth, can be NULL
163 * @param inbound_notify function to call for all inbound messages, can be NULL
164 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the
165 * GNUNET_MessageHeader and hence we do not need to give it the full message;
166 * can be used to improve efficiency, ignored if inbound_notify is NULLL
167 * @param outbound_notify function to call for all outbound messages, can be NULL
168 * @param outbound_hdr_only set to GNUNET_YES if outbound_notify will only read the
169 * GNUNET_MessageHeader and hence we do not need to give it the full message
170 * can be used to improve efficiency, ignored if outbound_notify is NULLL
171 * @param handlers callbacks for messages we care about, NULL-terminated
172 * @return handle to the core service (only useful for disconnect until 'init' is called),
173 * NULL on error (in this case, init is never called)
175 struct GNUNET_CORE_Handle *
176 GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
177 const struct GNUNET_CONFIGURATION_Handle *cfg,
178 struct GNUNET_TIME_Relative timeout,
180 GNUNET_CORE_StartupCallback init,
181 GNUNET_CORE_ClientEventHandler connects,
182 GNUNET_CORE_ClientEventHandler disconnects,
183 GNUNET_CORE_BufferFillCallback bfc,
184 GNUNET_CORE_MessageCallback inbound_notify,
185 int inbound_hdr_only,
186 GNUNET_CORE_MessageCallback outbound_notify,
187 int outbound_hdr_only,
188 const struct GNUNET_CORE_MessageHandler *handlers);
192 * Disconnect from the core service.
194 * @param handle connection to core to disconnect
196 void GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle);
200 * Function called with statistics about the given peer.
203 * @param peer identifies the peer
204 * @param latency current latency estimate, "FOREVER" if we have been
206 * @param bpm_in set to the current bandwidth limit (receiving) for this peer
207 * @param bpm_out set to the current bandwidth limit (sending) for this peer
208 * @param amount set to the amount that was actually reserved or unreserved
209 * @param preference current traffic preference for the given peer
212 (*GNUNET_CORE_PeerConfigurationInfoCallback) (void *cls,
214 GNUNET_PeerIdentity * peer,
216 unsigned int bpm_out,
217 struct GNUNET_TIME_Relative
219 unsigned long long preference);
223 * Obtain statistics and/or change preferences for the given peer.
225 * @param handle connection to core to use
226 * @param peer identifies the peer
227 * @param timeout after how long should we give up (and call "info" with NULL
228 * for "peer" to signal an error)?
229 * @param bpm_out set to the current bandwidth limit (sending) for this peer,
230 * caller should set "bpm_out" to "-1" to avoid changing
231 * the current value; otherwise "bpm_out" will be lowered to
232 * the specified value; passing a pointer to "0" can be used to force
233 * us to disconnect from the peer; "bpm_out" might not increase
234 * as specified since the upper bound is generally
235 * determined by the other peer!
236 * @param amount reserve N bytes for receiving, negative
237 * amounts can be used to undo a (recent) reservation;
238 * @param preference increase incoming traffic share preference by this amount;
239 * in the absence of "amount" reservations, we use this
240 * preference value to assign proportional bandwidth shares
241 * to all connected peers
242 * @param info function to call with the resulting configuration information
243 * @param info_cls closure for info
245 // FIXME: should return handle for cancellation!
247 GNUNET_CORE_peer_configure (struct GNUNET_CORE_Handle *handle,
248 const struct GNUNET_PeerIdentity *peer,
249 struct GNUNET_TIME_Relative timeout,
250 unsigned int bpm_out,
252 unsigned long long preference,
253 GNUNET_CORE_PeerConfigurationInfoCallback info,
258 * Handle for a transmission request.
260 struct GNUNET_CORE_TransmitHandle;
264 * Ask the core to call "notify" once it is ready to transmit the
265 * given number of bytes to the specified "target". If we are not yet
266 * connected to the specified peer, a call to this function will cause
267 * us to try to establish a connection.
269 * @param handle connection to core service
270 * @param priority how important is the message?
271 * @param maxdelay how long can the message wait?
272 * @param target who should receive the message,
273 * use NULL for this peer (loopback)
274 * @param notify_size how many bytes of buffer space does notify want?
275 * @param notify function to call when buffer space is available
276 * @param notify_cls closure for notify
277 * @return non-NULL if the notify callback was queued,
278 * NULL if we can not even queue the request (insufficient
279 * memory); if NULL is returned, "notify" will NOT be called.
281 struct GNUNET_CORE_TransmitHandle *
282 GNUNET_CORE_notify_transmit_ready (struct
297 GNUNET_CONNECTION_TransmitReadyNotify
304 * Cancel the specified transmission-ready notification.
306 * @param h handle that was returned by "notify_transmit_ready".
309 GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle
313 #if 0 /* keep Emacsens' auto-indent happy */
320 /* ifndef GNUNET_CORE_SERVICE_H */
322 /* end of gnunet_core_service.h */