2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 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 3, 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_util_lib.h"
39 #include "gnunet_ats_service.h"
42 * Version number of the transport API.
44 #define GNUNET_TRANSPORT_VERSION 0x00000000
48 * Function called by the transport for each received message.
51 * @param peer (claimed) identity of the other peer
52 * @param message the message
53 * @param ats performance data
54 * @param ats_count number of entries in ats
56 typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
58 GNUNET_PeerIdentity * peer,
60 GNUNET_MessageHeader *
63 GNUNET_ATS_Information * ats,
68 * Opaque handle to the service.
70 struct GNUNET_TRANSPORT_Handle;
74 * Function called to notify transport users that another
75 * peer connected to us.
78 * @param peer the peer that connected
79 * @param ats performance data
80 * @param ats_count number of entries in ats (excluding 0-termination)
82 typedef void (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
83 const struct GNUNET_PeerIdentity
86 GNUNET_ATS_Information * ats,
90 * Function called to notify transport users that another
91 * peer disconnected from us.
94 * @param peer the peer that disconnected
96 typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
98 GNUNET_PeerIdentity * peer);
102 * Function to call with result of the try connect request.
106 * @param result GNUNET_OK if message was transmitted to transport service
107 * GNUNET_SYSERR if message was not transmitted to transport service
109 typedef void (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls,
114 * Function to call with a textual representation of an address.
115 * This function will be called several times with different possible
116 * textual representations, and a last time with NULL to signal the end
120 * @param address NULL on error or end of iteration,
121 * otherwise 0-terminated printable UTF-8 string
123 typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
124 const char *address);
128 * Function to call with a binary format of an address
131 * @param peer peer this update is about (never NULL)
132 * @param address address, NULL for disconnect notification in monitor mode
134 typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
136 GNUNET_PeerIdentity *
139 GNUNET_HELLO_Address *
144 * Connect to the transport service. Note that the connection may
145 * complete (or fail) asynchronously.
147 * @param cfg configuration to use
148 * @param self our own identity (API should check that it matches
149 * the identity found by transport), or NULL (no check)
150 * @param cls closure for the callbacks
151 * @param rec receive function to call
152 * @param nc function to call on connect events
153 * @param nd function to call on disconnect events
154 * @return NULL on error
156 struct GNUNET_TRANSPORT_Handle *
157 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
158 const struct GNUNET_PeerIdentity *self, void *cls,
159 GNUNET_TRANSPORT_ReceiveCallback rec,
160 GNUNET_TRANSPORT_NotifyConnect nc,
161 GNUNET_TRANSPORT_NotifyDisconnect nd);
165 * Disconnect from the transport service.
167 * @param handle handle returned from connect
170 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
174 * Opaque handle for a transmission-ready request.
176 struct GNUNET_TRANSPORT_TryConnectHandle;
180 * Ask the transport service to establish a connection to
183 * @param handle connection to transport service
184 * @param target who we should try to connect to
185 * @param cb callback to be called when request was transmitted to transport
187 * @param cb_cls closure for the callback
188 * @return a GNUNET_TRANSPORT_TryConnectHandle handle or
189 * NULL on failure (cb will not be called)
191 struct GNUNET_TRANSPORT_TryConnectHandle *
192 GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
193 const struct GNUNET_PeerIdentity *target,
194 GNUNET_TRANSPORT_TryConnectCallback cb,
199 * Cancel the request to transport to try a connect
200 * Callback will not be called
202 * @param tch GNUNET_TRANSPORT_TryConnectHandle handle to cancel
205 GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch);
208 * Opaque handle for a transmission-ready request.
210 struct GNUNET_TRANSPORT_TransmitHandle;
214 * Check if we could queue a message of the given size for
215 * transmission. The transport service will take both its internal
216 * buffers and bandwidth limits imposed by the other peer into
217 * consideration when answering this query.
219 * @param handle connection to transport service
220 * @param target who should receive the message
221 * @param size how big is the message we want to transmit?
222 * @param priority how important is the message? @deprecated - remove?
223 * @param timeout after how long should we give up (and call
224 * notify with buf NULL and size 0)?
225 * @param notify function to call when we are ready to
226 * send such a message
227 * @param notify_cls closure for notify
228 * @return NULL if someone else is already waiting to be notified
229 * non-NULL if the notify callback was queued (can be used to cancel
230 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
232 struct GNUNET_TRANSPORT_TransmitHandle *
233 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
234 const struct GNUNET_PeerIdentity
235 *target, size_t size, uint32_t priority,
236 struct GNUNET_TIME_Relative timeout,
237 GNUNET_CONNECTION_TransmitReadyNotify
238 notify, void *notify_cls);
242 * Cancel the specified transmission-ready notification.
244 * @param th handle of the transmission notification request to cancel
247 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
248 GNUNET_TRANSPORT_TransmitHandle
254 * Function called whenever there is an update to the
255 * HELLO of this peer.
258 * @param hello our updated HELLO
260 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
262 GNUNET_MessageHeader *
267 * Handle to cancel a 'GNUNET_TRANSPORT_get_hello' operation.
269 struct GNUNET_TRANSPORT_GetHelloHandle;
273 * Obtain updates on changes to the HELLO message for this peer.
275 * @param handle connection to transport service
276 * @param rec function to call with the HELLO
277 * @param rec_cls closure for rec
278 * @return handle to cancel the operation
280 struct GNUNET_TRANSPORT_GetHelloHandle *
281 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
282 GNUNET_TRANSPORT_HelloUpdateCallback rec,
287 * Stop receiving updates about changes to our HELLO message.
289 * @param ghh handle to cancel
292 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
296 * Offer the transport service the HELLO of another peer. Note that
297 * the transport service may just ignore this message if the HELLO is
298 * malformed or useless due to our local configuration.
300 * @param handle connection to transport service
301 * @param hello the hello message
302 * @param cont continuation to call when HELLO has been sent,
303 * tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail
304 * tc reasong GNUNET_SCHEDULER_REASON_READ_READY for success
305 * @param cls closure for continuation
306 * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure,
307 * in case of failure cont will not be called
310 struct GNUNET_TRANSPORT_OfferHelloHandle *
311 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
312 const struct GNUNET_MessageHeader *hello,
313 GNUNET_SCHEDULER_Task cont, void *cls);
317 * Cancel the request to transport to offer the HELLO message
319 * @param ohh the GNUNET_TRANSPORT_OfferHelloHandle to cancel
322 GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
325 * Handle to cancel a pending address lookup.
327 struct GNUNET_TRANSPORT_AddressToStringContext;
331 * Convert a binary address into a human readable address.
333 * @param cfg configuration to use
334 * @param address address to convert (binary format)
335 * @param numeric should (IP) addresses be displayed in numeric form
336 * (otherwise do reverse DNS lookup)
337 * @param timeout how long is the lookup allowed to take at most
338 * @param aluc function to call with the results
339 * @param aluc_cls closure for aluc
340 * @return handle to cancel the operation, NULL on error
342 struct GNUNET_TRANSPORT_AddressToStringContext *
343 GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
345 const struct GNUNET_HELLO_Address *address,
347 struct GNUNET_TIME_Relative timeout,
348 GNUNET_TRANSPORT_AddressToStringCallback
349 aluc, void *aluc_cls);
353 * Cancel request for address conversion.
355 * @param alc handle for the request to cancel
358 GNUNET_TRANSPORT_address_to_string_cancel (struct
359 GNUNET_TRANSPORT_AddressToStringContext
364 * Return all the known addresses for a specific peer or all peers.
365 * Returns continuously all address if one_shot is set to GNUNET_NO
367 * CHANGE: Returns the address(es) that we are currently using for this
368 * peer. Upon completion, the 'AddressLookUpCallback' is called one more
369 * time with 'NULL' for the address and the peer. After this, the operation must no
370 * longer be explicitly cancelled.
372 * @param cfg configuration to use
373 * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers
374 * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
375 * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly canceled, NOT implemented yet!)
376 * @param timeout how long is the lookup allowed to take at most
377 * @param peer_address_callback function to call with the results
378 * @param peer_address_callback_cls closure for peer_address_callback
380 struct GNUNET_TRANSPORT_PeerIterateContext *
381 GNUNET_TRANSPORT_peer_get_active_addresses (const struct
382 GNUNET_CONFIGURATION_Handle *cfg,
383 const struct GNUNET_PeerIdentity
385 struct GNUNET_TIME_Relative timeout,
386 GNUNET_TRANSPORT_PeerIterateCallback
387 peer_address_callback,
388 void *peer_address_callback_cls);
392 * Cancel request for peer lookup.
394 * @param alc handle for the request to cancel
397 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
398 GNUNET_TRANSPORT_PeerIterateContext
403 * Handle for blacklisting peers.
405 struct GNUNET_TRANSPORT_Blacklist;
409 * Function that decides if a connection is acceptable or not.
412 * @param pid peer to approve or disapproave
413 * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not
415 typedef int (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
417 GNUNET_PeerIdentity * pid);
421 * Install a blacklist callback. The service will be queried for all
422 * existing connections as well as any fresh connections to check if
423 * they are permitted. If the blacklisting callback is unregistered,
424 * all hosts that were denied in the past will automatically be
425 * whitelisted again. Cancelling the blacklist handle is also the
426 * only way to re-enable connections from peers that were previously
429 * @param cfg configuration to use
430 * @param cb callback to invoke to check if connections are allowed
431 * @param cb_cls closure for cb
432 * @return NULL on error, otherwise handle for cancellation
434 struct GNUNET_TRANSPORT_Blacklist *
435 GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
436 GNUNET_TRANSPORT_BlacklistCallback cb,
441 * Abort the blacklist. Note that this function is the only way for
442 * removing a peer from the blacklist.
444 * @param br handle of the request that is to be cancelled
447 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
451 #if 0 /* keep Emacsens' auto-indent happy */
458 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
460 /* end of gnunet_transport_service.h */