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 * - define API for blacklisting, un-blacklisting and notifications
28 * about blacklisted peers
31 #ifndef GNUNET_TRANSPORT_SERVICE_H
32 #define GNUNET_TRANSPORT_SERVICE_H
37 #if 0 /* keep Emacsens' auto-indent happy */
42 #include "gnunet_configuration_lib.h"
43 #include "gnunet_crypto_lib.h"
44 #include "gnunet_connection_lib.h"
45 #include "gnunet_scheduler_lib.h"
46 #include "gnunet_time_lib.h"
49 * Version number of the transport API.
51 #define GNUNET_TRANSPORT_VERSION 0x00000000
54 * Function called by the transport for each received message.
57 * @param peer (claimed) identity of the other peer
58 * @param message the message
59 * @param latency estimated latency for communicating with the
60 * given peer (round-trip)
61 * @param distance in overlay hops, as given by transport plugin
63 typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
65 GNUNET_PeerIdentity * peer,
67 GNUNET_MessageHeader *
69 struct GNUNET_TIME_Relative
71 unsigned int distance);
75 * Opaque handle to the service.
77 struct GNUNET_TRANSPORT_Handle;
81 * Function called to notify transport users that another
82 * peer connected to us.
85 * @param peer the peer that connected
86 * @param latency estimated latency for communicating with the
87 * given peer (round-trip)
88 * @param distance in overlay hops, as given by transport plugin
91 (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
92 const struct GNUNET_PeerIdentity * peer,
93 struct GNUNET_TIME_Relative latency,
94 unsigned int distance);
97 * Function called to notify transport users that another
98 * peer disconnected from us.
101 * @param peer the peer that disconnected
104 (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
105 const struct GNUNET_PeerIdentity *
110 * Function to call with a human-readable format of an address
113 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
116 (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
117 const char *address);
121 * Connect to the transport service. Note that the connection may
122 * complete (or fail) asynchronously.
124 * @param sched scheduler to use
125 * @param cfg configuration to use
126 * @param cls closure for the callbacks
127 * @param rec receive function to call
128 * @param nc function to call on connect events
129 * @param nd function to call on disconnect events
130 * @return NULL on error
132 struct GNUNET_TRANSPORT_Handle *GNUNET_TRANSPORT_connect (struct
133 GNUNET_SCHEDULER_Handle
136 GNUNET_CONFIGURATION_Handle
138 GNUNET_TRANSPORT_ReceiveCallback
140 GNUNET_TRANSPORT_NotifyConnect
142 GNUNET_TRANSPORT_NotifyDisconnect
147 * Disconnect from the transport service.
149 * @param handle handle returned from connect
151 void GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
155 * Set the share of incoming/outgoing bandwidth for the given
156 * peer to the specified amount.
158 * @param handle connection to transport service
159 * @param target who's bandwidth quota is being changed
160 * @param quota_in incoming bandwidth quota in bytes per ms
161 * @param quota_out outgoing bandwidth quota in bytes per ms
162 * @param timeout how long to wait until signaling failure if
163 * we can not communicate the quota change
164 * @param cont continuation to call when done, will be called
165 * either with reason "TIMEOUT" or with reason "PREREQ_DONE"
166 * @param cont_cls closure for continuation
169 GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
170 const struct GNUNET_PeerIdentity *target,
173 struct GNUNET_TIME_Relative timeout,
174 GNUNET_SCHEDULER_Task cont, void *cont_cls);
178 * Opaque handle for a transmission-ready request.
180 struct GNUNET_TRANSPORT_TransmitHandle;
184 * Check if we could queue a message of the given size for
185 * transmission. The transport service will take both its
186 * internal buffers and bandwidth limits imposed by the
187 * other peer into consideration when answering this query.
189 * @param handle connection to transport service
190 * @param target who should receive the message
191 * @param size how big is the message we want to transmit?
192 * @param priority how important is the message?
193 * @param timeout after how long should we give up (and call
194 * notify with buf NULL and size 0)?
195 * @param notify function to call when we are ready to
196 * send such a message
197 * @param notify_cls closure for notify
198 * @return NULL if someone else is already waiting to be notified
199 * non-NULL if the notify callback was queued (can be used to cancel
200 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
202 struct GNUNET_TRANSPORT_TransmitHandle
203 *GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
205 const struct GNUNET_PeerIdentity
206 *target, size_t size,
207 unsigned int priority,
208 struct GNUNET_TIME_Relative
210 GNUNET_CONNECTION_TransmitReadyNotify
211 notify, void *notify_cls);
215 * Cancel the specified transmission-ready notification.
217 * @param h handle of the transmission notification request to cancel
220 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
221 GNUNET_TRANSPORT_TransmitHandle
226 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls,
227 const struct GNUNET_MessageHeader *hello);
231 * Obtain updates on changes to the HELLO message for this peer.
233 * @param handle connection to transport service
234 * @param rec function to call with the HELLO
235 * @param rec_cls closure for rec
238 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
239 GNUNET_TRANSPORT_HelloUpdateCallback rec,
244 * Stop receiving updates about changes to our HELLO message.
246 * @param handle connection to transport service
247 * @param rec function previously registered to be called with the HELLOs
248 * @param rec_cls closure for rec
251 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
252 GNUNET_TRANSPORT_HelloUpdateCallback rec,
257 * Offer the transport service the HELLO of another peer. Note that
258 * the transport service may just ignore this message if the HELLO is
259 * malformed or useless due to our local configuration. If the HELLO
260 * is working, we should add it to PEERINFO.
262 * @param handle connection to transport service
263 * @param hello the hello message
266 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
267 const struct GNUNET_MessageHeader *hello);
271 * Convert a binary address into a human readable address.
273 * @param sched scheduler to use
274 * @param cfg configuration to use
275 * @param address address to convert (binary format)
276 * @param addressLen number of bytes in address
277 * @param numeric should (IP) addresses be displayed in numeric form
278 * (otherwise do reverse DNS lookup)
279 * @param nameTrans name of the transport to which the address belongs
280 * @param timeout how long is the lookup allowed to take at most
281 * @param aluc function to call with the results
282 * @param aluc_cls closure for aluc
285 GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched,
286 const struct GNUNET_CONFIGURATION_Handle *cfg,
287 const char * address,
290 const char * nameTrans,
291 struct GNUNET_TIME_Relative timeout,
292 GNUNET_TRANSPORT_AddressLookUpCallback aluc,
299 * Blacklist a peer for a given period of time. All connections
300 * (inbound and outbound) to a peer that is blacklisted will be
301 * dropped (as soon as we learn who the connection is for). A second
302 * call to this function for the same peer overrides previous
303 * blacklisting requests.
305 * @param sched scheduler to use
306 * @param cfg configuration to use
307 * @param peer identity of peer to blacklist
308 * @param duration how long to blacklist, use GNUNET_TIME_UNIT_ZERO to
309 * re-enable connections
312 GNUNET_TRANSPORT_blacklist (struct GNUNET_SCHEDULER_Handle *sched,
313 const struct GNUNET_CONFIGURATION_Handle *cfg,
314 const struct GNUNET_PeerIdentity *peer,
315 struct GNUNET_TIME_Relative duration);
319 * Handle for blacklist notifications.
321 struct GNUNET_TRANSPORT_BlacklistNotification;
325 * Signature of function called whenever the blacklist status of
326 * a peer changes. This includes changes to the duration of the
327 * blacklist status as well as the expiration of an existing
331 * @param peer identity of peer with the change
332 * @param until GNUNET_TIME_UNIT_ZERO_ABS if the peer is no
333 * longer blacklisted, otherwise the time at
334 * which the current blacklisting will expire
336 typedef void (*GNUNET_TRANSPORT_BlacklistCallback)(void *cls,
337 const struct GNUNET_PeerIdentity *peer,
338 struct GNUNET_TIME_Absolute until);
342 * Call a function whenever a peer's blacklisting status changes.
344 * @param sched scheduler to use
345 * @param cfg configuration to use
346 * @param bc function to call on status changes
347 * @param bc_cls closure for bc
348 * @return NULL on error, otherwise handle for cancellation
350 struct GNUNET_TRANSPORT_BlacklistNotification *
351 GNUNET_TRANSPORT_blacklist_notify (struct GNUNET_SCHEDULER_Handle *sched,
352 const struct GNUNET_CONFIGURATION_Handle *cfg,
353 GNUNET_TRANSPORT_BlacklistCallback bc,
358 * Stop calling the notification callback associated with
359 * the given blacklist notification.
361 * @param bn handle of the request that is to be cancelled
364 GNUNET_TRANSPORT_blacklist_notify_cancel (struct GNUNET_TRANSPORT_BlacklistNotification * bn);
368 #if 0 /* keep Emacsens' auto-indent happy */
375 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
377 /* end of gnunet_transport_service.h */