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_transport_service.h
23 * @brief low-level P2P IO
24 * @author Christian Grothoff
27 #ifndef GNUNET_TRANSPORT_SERVICE_H
28 #define GNUNET_TRANSPORT_SERVICE_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_bandwidth_lib.h"
39 #include "gnunet_configuration_lib.h"
40 #include "gnunet_crypto_lib.h"
41 #include "gnunet_connection_lib.h"
42 #include "gnunet_scheduler_lib.h"
43 #include "gnunet_time_lib.h"
46 * Version number of the transport API.
48 #define GNUNET_TRANSPORT_VERSION 0x00000000
51 * Function called by the transport for each received message.
54 * @param peer (claimed) identity of the other peer
55 * @param message the message
56 * @param latency estimated latency for communicating with the
57 * given peer (round-trip)
58 * @param distance in overlay hops, as given by transport plugin
60 typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
62 GNUNET_PeerIdentity * peer,
64 GNUNET_MessageHeader *
66 struct GNUNET_TIME_Relative
72 * Opaque handle to the service.
74 struct GNUNET_TRANSPORT_Handle;
78 * Function called to notify transport users that another
79 * peer connected to us.
82 * @param peer the peer that connected
83 * @param latency estimated latency for communicating with the
84 * given peer (round-trip)
85 * @param distance in overlay hops, as given by transport plugin
88 (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
89 const struct GNUNET_PeerIdentity * peer,
90 struct GNUNET_TIME_Relative latency,
94 * Function called to notify transport users that another
95 * peer disconnected from us.
98 * @param peer the peer that disconnected
101 (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
102 const struct GNUNET_PeerIdentity *
107 * Function to call with a human-readable format of an address
110 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
113 (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
114 const char *address);
118 * Connect to the transport service. Note that the connection may
119 * complete (or fail) asynchronously.
121 * @param sched scheduler to use
122 * @param cfg configuration to use
123 * @param cls closure for the callbacks
124 * @param rec receive function to call
125 * @param nc function to call on connect events
126 * @param nd function to call on disconnect events
127 * @return NULL on error
129 struct GNUNET_TRANSPORT_Handle *GNUNET_TRANSPORT_connect (struct
130 GNUNET_SCHEDULER_Handle
133 GNUNET_CONFIGURATION_Handle
135 GNUNET_TRANSPORT_ReceiveCallback
137 GNUNET_TRANSPORT_NotifyConnect
139 GNUNET_TRANSPORT_NotifyDisconnect
144 * Disconnect from the transport service.
146 * @param handle handle returned from connect
148 void GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
152 * Set the share of incoming/outgoing bandwidth for the given
153 * peer to the specified amount.
155 * @param handle connection to transport service
156 * @param target who's bandwidth quota is being changed
157 * @param quota_in incoming bandwidth quota
158 * @param quota_out outgoing bandwidth quota
159 * @param timeout how long to wait until signaling failure if
160 * we can not communicate the quota change
161 * @param cont continuation to call when done, will be called
162 * either with reason "TIMEOUT" or with reason "PREREQ_DONE"
163 * @param cont_cls closure for continuation
166 GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
167 const struct GNUNET_PeerIdentity *target,
168 struct GNUNET_BANDWIDTH_Value32NBO quota_in,
169 struct GNUNET_BANDWIDTH_Value32NBO quota_out,
170 struct GNUNET_TIME_Relative timeout,
171 GNUNET_SCHEDULER_Task cont, void *cont_cls);
175 * Opaque handle for a transmission-ready request.
177 struct GNUNET_TRANSPORT_TransmitHandle;
181 * Check if we could queue a message of the given size for
182 * transmission. The transport service will take both its
183 * internal buffers and bandwidth limits imposed by the
184 * other peer into consideration when answering this query.
186 * @param handle connection to transport service
187 * @param target who should receive the message
188 * @param size how big is the message we want to transmit?
189 * @param priority how important is the message?
190 * @param timeout after how long should we give up (and call
191 * notify with buf NULL and size 0)?
192 * @param notify function to call when we are ready to
193 * send such a message
194 * @param notify_cls closure for notify
195 * @return NULL if someone else is already waiting to be notified
196 * non-NULL if the notify callback was queued (can be used to cancel
197 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
199 struct GNUNET_TRANSPORT_TransmitHandle
200 *GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
202 const struct GNUNET_PeerIdentity
203 *target, size_t size,
205 struct GNUNET_TIME_Relative
207 GNUNET_CONNECTION_TransmitReadyNotify
208 notify, void *notify_cls);
212 * Cancel the specified transmission-ready notification.
214 * @param h handle of the transmission notification request to cancel
217 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
218 GNUNET_TRANSPORT_TransmitHandle
224 * Function called whenever there is an update to the
225 * HELLO of this peer.
228 * @param hello our updated HELLO
230 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls,
231 const struct GNUNET_MessageHeader *hello);
235 * Obtain updates on changes to the HELLO message for this peer.
237 * @param handle connection to transport service
238 * @param rec function to call with the HELLO
239 * @param rec_cls closure for rec
242 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
243 GNUNET_TRANSPORT_HelloUpdateCallback rec,
248 * Stop receiving updates about changes to our HELLO message.
250 * @param handle connection to transport service
251 * @param rec function previously registered to be called with the HELLOs
252 * @param rec_cls closure for rec
255 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
256 GNUNET_TRANSPORT_HelloUpdateCallback rec,
261 * Offer the transport service the HELLO of another peer. Note that
262 * the transport service may just ignore this message if the HELLO is
263 * malformed or useless due to our local configuration. If the HELLO
264 * is working, we should add it to PEERINFO.
266 * @param handle connection to transport service
267 * @param hello the hello message
270 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
271 const struct GNUNET_MessageHeader *hello);
275 * Convert a binary address into a human readable address.
277 * @param sched scheduler to use
278 * @param cfg configuration to use
279 * @param address address to convert (binary format)
280 * @param addressLen number of bytes in address
281 * @param numeric should (IP) addresses be displayed in numeric form
282 * (otherwise do reverse DNS lookup)
283 * @param nameTrans name of the transport to which the address belongs
284 * @param timeout how long is the lookup allowed to take at most
285 * @param aluc function to call with the results
286 * @param aluc_cls closure for aluc
289 GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched,
290 const struct GNUNET_CONFIGURATION_Handle *cfg,
291 const char * address,
294 const char * nameTrans,
295 struct GNUNET_TIME_Relative timeout,
296 GNUNET_TRANSPORT_AddressLookUpCallback aluc,
302 * Handle for blacklisting requests.
304 struct GNUNET_TRANSPORT_BlacklistRequest;
308 * Blacklist a peer for a given period of time. All connections
309 * (inbound and outbound) to a peer that is blacklisted will be
310 * dropped (as soon as we learn who the connection is for). A second
311 * call to this function for the same peer overrides previous
312 * blacklisting requests.
314 * @param sched scheduler to use
315 * @param cfg configuration to use
316 * @param peer identity of peer to blacklist
317 * @param duration how long to blacklist, use GNUNET_TIME_UNIT_ZERO to
318 * re-enable connections
319 * @param timeout when should this operation (trying to establish the
320 * blacklisting time out)
321 * @param cont continuation to call once the request has been processed
322 * @param cont_cls closure for cont
323 * @return NULL on error, otherwise handle for cancellation
325 struct GNUNET_TRANSPORT_BlacklistRequest *
326 GNUNET_TRANSPORT_blacklist (struct GNUNET_SCHEDULER_Handle *sched,
327 const struct GNUNET_CONFIGURATION_Handle *cfg,
328 const struct GNUNET_PeerIdentity *peer,
329 struct GNUNET_TIME_Relative duration,
330 struct GNUNET_TIME_Relative timeout,
331 GNUNET_SCHEDULER_Task cont,
336 * Abort transmitting the blacklist request. Note that this function
337 * is NOT for removing a peer from the blacklist (for that, call
338 * GNUNET_TRANSPORT_blacklist with a duration of zero). This function
339 * is only for aborting the transmission of a blacklist request
340 * (i.e. because of shutdown).
342 * @param br handle of the request that is to be cancelled
345 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_BlacklistRequest * br);
349 * Handle for blacklist notifications.
351 struct GNUNET_TRANSPORT_BlacklistNotification;
355 * Signature of function called whenever the blacklist status of
356 * a peer changes. This includes changes to the duration of the
357 * blacklist status as well as the expiration of an existing
361 * @param peer identity of peer with the change
362 * @param until GNUNET_TIME_UNIT_ZERO_ABS if the peer is no
363 * longer blacklisted, otherwise the time at
364 * which the current blacklisting will expire
366 typedef void (*GNUNET_TRANSPORT_BlacklistCallback)(void *cls,
367 const struct GNUNET_PeerIdentity *peer,
368 struct GNUNET_TIME_Absolute until);
372 * Call a function whenever a peer's blacklisting status changes.
374 * @param sched scheduler to use
375 * @param cfg configuration to use
376 * @param bc function to call on status changes
377 * @param bc_cls closure for bc
378 * @return NULL on error, otherwise handle for cancellation
380 struct GNUNET_TRANSPORT_BlacklistNotification *
381 GNUNET_TRANSPORT_blacklist_notify (struct GNUNET_SCHEDULER_Handle *sched,
382 const struct GNUNET_CONFIGURATION_Handle *cfg,
383 GNUNET_TRANSPORT_BlacklistCallback bc,
388 * Stop calling the notification callback associated with
389 * the given blacklist notification.
391 * @param bn handle of the request that is to be cancelled
394 GNUNET_TRANSPORT_blacklist_notify_cancel (struct GNUNET_TRANSPORT_BlacklistNotification * bn);
398 #if 0 /* keep Emacsens' auto-indent happy */
405 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
407 /* end of gnunet_transport_service.h */