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 internal
183 * buffers and bandwidth limits imposed by the other peer into
184 * 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 peers.
304 struct GNUNET_TRANSPORT_Blacklist;
308 * Function that decides if a connection is acceptable or not.
311 * @param pid peer to approve or disapproave
312 * @return GNUNET_OK if the connection is allowed
314 typedef int (*GNUNET_TRANSPORT_BlacklistCallback)(void *cls,
315 const struct GNUNET_PeerIdentity *pid);
319 * Install a blacklist callback. The service will be queried for all
320 * existing connections as well as any fresh connections to check if
321 * they are permitted. If the blacklisting callback is unregistered,
322 * all hosts that were denied in the past will automatically be
323 * whitelisted again. Cancelling the blacklist handle is also the
324 * only way to re-enable connections from peers that were previously
327 * @param sched scheduler to use
328 * @param cfg configuration to use
329 * @param cb callback to invoke to check if connections are allowed
330 * @param cb_cls closure for cb
331 * @return NULL on error, otherwise handle for cancellation
333 struct GNUNET_TRANSPORT_Blacklist *
334 GNUNET_TRANSPORT_blacklist (struct GNUNET_SCHEDULER_Handle *sched,
335 const struct GNUNET_CONFIGURATION_Handle *cfg,
336 GNUNET_TRANSPORT_BlacklistCallback cb,
341 * Abort the blacklist. Note that this function is the only way for
342 * removing a peer from the blacklist.
344 * @param br handle of the request that is to be cancelled
347 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
351 #if 0 /* keep Emacsens' auto-indent happy */
358 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
360 /* end of gnunet_transport_service.h */