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_configuration_lib.h"
39 #include "gnunet_crypto_lib.h"
40 #include "gnunet_connection_lib.h"
41 #include "gnunet_scheduler_lib.h"
42 #include "gnunet_time_lib.h"
45 * Version number of the transport API.
47 #define GNUNET_TRANSPORT_VERSION 0x00000000
50 * Function called by the transport for each received message.
53 * @param peer (claimed) identity of the other peer
54 * @param message the message
55 * @param latency estimated latency for communicating with the
56 * given peer (round-trip)
57 * @param distance in overlay hops, as given by transport plugin
59 typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
61 GNUNET_PeerIdentity * peer,
63 GNUNET_MessageHeader *
65 struct GNUNET_TIME_Relative
71 * Opaque handle to the service.
73 struct GNUNET_TRANSPORT_Handle;
77 * Function called to notify transport users that another
78 * peer connected to us.
81 * @param peer the peer that connected
82 * @param latency estimated latency for communicating with the
83 * given peer (round-trip)
84 * @param distance in overlay hops, as given by transport plugin
87 (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
88 const struct GNUNET_PeerIdentity * peer,
89 struct GNUNET_TIME_Relative latency,
93 * Function called to notify transport users that another
94 * peer disconnected from us.
97 * @param peer the peer that disconnected
100 (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
101 const struct GNUNET_PeerIdentity *
106 * Function to call with a human-readable format of an address
109 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
112 (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
113 const char *address);
117 * Connect to the transport service. Note that the connection may
118 * complete (or fail) asynchronously.
120 * @param sched scheduler to use
121 * @param cfg configuration to use
122 * @param cls closure for the callbacks
123 * @param rec receive function to call
124 * @param nc function to call on connect events
125 * @param nd function to call on disconnect events
126 * @return NULL on error
128 struct GNUNET_TRANSPORT_Handle *GNUNET_TRANSPORT_connect (struct
129 GNUNET_SCHEDULER_Handle
132 GNUNET_CONFIGURATION_Handle
134 GNUNET_TRANSPORT_ReceiveCallback
136 GNUNET_TRANSPORT_NotifyConnect
138 GNUNET_TRANSPORT_NotifyDisconnect
143 * Disconnect from the transport service.
145 * @param handle handle returned from connect
147 void GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
151 * Set the share of incoming/outgoing bandwidth for the given
152 * peer to the specified amount.
154 * @param handle connection to transport service
155 * @param target who's bandwidth quota is being changed
156 * @param quota_in incoming bandwidth quota in bytes per ms
157 * @param quota_out outgoing bandwidth quota in bytes per ms
158 * @param timeout how long to wait until signaling failure if
159 * we can not communicate the quota change
160 * @param cont continuation to call when done, will be called
161 * either with reason "TIMEOUT" or with reason "PREREQ_DONE"
162 * @param cont_cls closure for continuation
165 GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
166 const struct GNUNET_PeerIdentity *target,
169 struct GNUNET_TIME_Relative timeout,
170 GNUNET_SCHEDULER_Task cont, void *cont_cls);
174 * Opaque handle for a transmission-ready request.
176 struct GNUNET_TRANSPORT_TransmitHandle;
180 * Check if we could queue a message of the given size for
181 * transmission. The transport service will take both its
182 * internal buffers and bandwidth limits imposed by the
183 * other peer into consideration when answering this query.
185 * @param handle connection to transport service
186 * @param target who should receive the message
187 * @param size how big is the message we want to transmit?
188 * @param priority how important is the message?
189 * @param timeout after how long should we give up (and call
190 * notify with buf NULL and size 0)?
191 * @param notify function to call when we are ready to
192 * send such a message
193 * @param notify_cls closure for notify
194 * @return NULL if someone else is already waiting to be notified
195 * non-NULL if the notify callback was queued (can be used to cancel
196 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
198 struct GNUNET_TRANSPORT_TransmitHandle
199 *GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
201 const struct GNUNET_PeerIdentity
202 *target, size_t size,
204 struct GNUNET_TIME_Relative
206 GNUNET_CONNECTION_TransmitReadyNotify
207 notify, void *notify_cls);
211 * Cancel the specified transmission-ready notification.
213 * @param h handle of the transmission notification request to cancel
216 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
217 GNUNET_TRANSPORT_TransmitHandle
223 * Function called whenever there is an update to the
224 * HELLO of this peer.
227 * @param hello our updated HELLO
229 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls,
230 const struct GNUNET_MessageHeader *hello);
234 * Obtain updates on changes to the HELLO message for this peer.
236 * @param handle connection to transport service
237 * @param rec function to call with the HELLO
238 * @param rec_cls closure for rec
241 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
242 GNUNET_TRANSPORT_HelloUpdateCallback rec,
247 * Stop receiving updates about changes to our HELLO message.
249 * @param handle connection to transport service
250 * @param rec function previously registered to be called with the HELLOs
251 * @param rec_cls closure for rec
254 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
255 GNUNET_TRANSPORT_HelloUpdateCallback rec,
260 * Offer the transport service the HELLO of another peer. Note that
261 * the transport service may just ignore this message if the HELLO is
262 * malformed or useless due to our local configuration. If the HELLO
263 * is working, we should add it to PEERINFO.
265 * @param handle connection to transport service
266 * @param hello the hello message
269 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
270 const struct GNUNET_MessageHeader *hello);
274 * Convert a binary address into a human readable address.
276 * @param sched scheduler to use
277 * @param cfg configuration to use
278 * @param address address to convert (binary format)
279 * @param addressLen number of bytes in address
280 * @param numeric should (IP) addresses be displayed in numeric form
281 * (otherwise do reverse DNS lookup)
282 * @param nameTrans name of the transport to which the address belongs
283 * @param timeout how long is the lookup allowed to take at most
284 * @param aluc function to call with the results
285 * @param aluc_cls closure for aluc
288 GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched,
289 const struct GNUNET_CONFIGURATION_Handle *cfg,
290 const char * address,
293 const char * nameTrans,
294 struct GNUNET_TIME_Relative timeout,
295 GNUNET_TRANSPORT_AddressLookUpCallback aluc,
301 * Handle for blacklisting requests.
303 struct GNUNET_TRANSPORT_BlacklistRequest;
307 * Blacklist a peer for a given period of time. All connections
308 * (inbound and outbound) to a peer that is blacklisted will be
309 * dropped (as soon as we learn who the connection is for). A second
310 * call to this function for the same peer overrides previous
311 * blacklisting requests.
313 * @param sched scheduler to use
314 * @param cfg configuration to use
315 * @param peer identity of peer to blacklist
316 * @param duration how long to blacklist, use GNUNET_TIME_UNIT_ZERO to
317 * re-enable connections
318 * @param timeout when should this operation (trying to establish the
319 * blacklisting time out)
320 * @param cont continuation to call once the request has been processed
321 * @param cont_cls closure for cont
322 * @return NULL on error, otherwise handle for cancellation
324 struct GNUNET_TRANSPORT_BlacklistRequest *
325 GNUNET_TRANSPORT_blacklist (struct GNUNET_SCHEDULER_Handle *sched,
326 const struct GNUNET_CONFIGURATION_Handle *cfg,
327 const struct GNUNET_PeerIdentity *peer,
328 struct GNUNET_TIME_Relative duration,
329 struct GNUNET_TIME_Relative timeout,
330 GNUNET_SCHEDULER_Task cont,
335 * Abort transmitting the blacklist request. Note that this function
336 * is NOT for removing a peer from the blacklist (for that, call
337 * GNUNET_TRANSPORT_blacklist with a duration of zero). This function
338 * is only for aborting the transmission of a blacklist request
339 * (i.e. because of shutdown).
341 * @param br handle of the request that is to be cancelled
344 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_BlacklistRequest * br);
348 * Handle for blacklist notifications.
350 struct GNUNET_TRANSPORT_BlacklistNotification;
354 * Signature of function called whenever the blacklist status of
355 * a peer changes. This includes changes to the duration of the
356 * blacklist status as well as the expiration of an existing
360 * @param peer identity of peer with the change
361 * @param until GNUNET_TIME_UNIT_ZERO_ABS if the peer is no
362 * longer blacklisted, otherwise the time at
363 * which the current blacklisting will expire
365 typedef void (*GNUNET_TRANSPORT_BlacklistCallback)(void *cls,
366 const struct GNUNET_PeerIdentity *peer,
367 struct GNUNET_TIME_Absolute until);
371 * Call a function whenever a peer's blacklisting status changes.
373 * @param sched scheduler to use
374 * @param cfg configuration to use
375 * @param bc function to call on status changes
376 * @param bc_cls closure for bc
377 * @return NULL on error, otherwise handle for cancellation
379 struct GNUNET_TRANSPORT_BlacklistNotification *
380 GNUNET_TRANSPORT_blacklist_notify (struct GNUNET_SCHEDULER_Handle *sched,
381 const struct GNUNET_CONFIGURATION_Handle *cfg,
382 GNUNET_TRANSPORT_BlacklistCallback bc,
387 * Stop calling the notification callback associated with
388 * the given blacklist notification.
390 * @param bn handle of the request that is to be cancelled
393 GNUNET_TRANSPORT_blacklist_notify_cancel (struct GNUNET_TRANSPORT_BlacklistNotification * bn);
397 #if 0 /* keep Emacsens' auto-indent happy */
404 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
406 /* end of gnunet_transport_service.h */