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
46 enum TRAFFIC_METRIC_DIRECTION
55 * Function called by the transport for each received message.
58 * @param peer (claimed) identity of the other peer
59 * @param message the message
60 * @param ats performance data
61 * @param ats_count number of entries in ats
63 typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
65 GNUNET_PeerIdentity * peer,
67 GNUNET_MessageHeader *
70 GNUNET_ATS_Information * ats,
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 ats performance data
87 * @param ats_count number of entries in ats (excluding 0-termination)
89 typedef void (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
90 const struct GNUNET_PeerIdentity
93 GNUNET_ATS_Information * ats,
97 * Function called to notify transport users that another
98 * peer disconnected from us.
101 * @param peer the peer that disconnected
103 typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
105 GNUNET_PeerIdentity * peer);
109 * Function to call with result of the try connect request.
113 * @param result GNUNET_OK if message was transmitted to transport service
114 * GNUNET_SYSERR if message was not transmitted to transport service
116 typedef void (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls,
121 * Function to call with a textual representation of an address.
122 * This function will be called several times with different possible
123 * textual representations, and a last time with NULL to signal the end
127 * @param address NULL on error or end of iteration,
128 * otherwise 0-terminated printable UTF-8 string
130 typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
131 const char *address);
135 * Function to call with a binary format of an address
138 * @param peer peer this update is about (never NULL)
139 * @param address address, NULL for disconnect notification in monitor mode
141 typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
143 GNUNET_PeerIdentity *
146 GNUNET_HELLO_Address *
151 * Connect to the transport service. Note that the connection may
152 * complete (or fail) asynchronously.
154 * @param cfg configuration to use
155 * @param self our own identity (API should check that it matches
156 * the identity found by transport), or NULL (no check)
157 * @param cls closure for the callbacks
158 * @param rec receive function to call
159 * @param nc function to call on connect events
160 * @param nd function to call on disconnect events
161 * @return NULL on error
163 struct GNUNET_TRANSPORT_Handle *
164 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
165 const struct GNUNET_PeerIdentity *self, void *cls,
166 GNUNET_TRANSPORT_ReceiveCallback rec,
167 GNUNET_TRANSPORT_NotifyConnect nc,
168 GNUNET_TRANSPORT_NotifyDisconnect nd);
172 * Disconnect from the transport service.
174 * @param handle handle returned from connect
177 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
181 * Opaque handle for a transmission-ready request.
183 struct GNUNET_TRANSPORT_TryConnectHandle;
187 * Ask the transport service to establish a connection to
190 * @param handle connection to transport service
191 * @param target who we should try to connect to
192 * @param cb callback to be called when request was transmitted to transport
194 * @param cb_cls closure for the callback
195 * @return a GNUNET_TRANSPORT_TryConnectHandle handle or
196 * NULL on failure (cb will not be called)
198 struct GNUNET_TRANSPORT_TryConnectHandle *
199 GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
200 const struct GNUNET_PeerIdentity *target,
201 GNUNET_TRANSPORT_TryConnectCallback cb,
206 * Cancel the request to transport to try a connect
207 * Callback will not be called
209 * @param tch GNUNET_TRANSPORT_TryConnectHandle handle to cancel
212 GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch);
215 * Opaque handle for a transmission-ready request.
217 struct GNUNET_TRANSPORT_TransmitHandle;
221 * Check if we could queue a message of the given size for
222 * transmission. The transport service will take both its internal
223 * buffers and bandwidth limits imposed by the other peer into
224 * consideration when answering this query.
226 * @param handle connection to transport service
227 * @param target who should receive the message
228 * @param size how big is the message we want to transmit?
229 * @param priority how important is the message? @deprecated - remove?
230 * @param timeout after how long should we give up (and call
231 * notify with buf NULL and size 0)?
232 * @param notify function to call when we are ready to
233 * send such a message
234 * @param notify_cls closure for notify
235 * @return NULL if someone else is already waiting to be notified
236 * non-NULL if the notify callback was queued (can be used to cancel
237 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
239 struct GNUNET_TRANSPORT_TransmitHandle *
240 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
241 const struct GNUNET_PeerIdentity
242 *target, size_t size, uint32_t priority,
243 struct GNUNET_TIME_Relative timeout,
244 GNUNET_CONNECTION_TransmitReadyNotify
245 notify, void *notify_cls);
249 * Cancel the specified transmission-ready notification.
251 * @param th handle of the transmission notification request to cancel
254 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
255 GNUNET_TRANSPORT_TransmitHandle
261 * Function called whenever there is an update to the
262 * HELLO of this peer.
265 * @param hello our updated HELLO
267 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
269 GNUNET_MessageHeader *
274 * Handle to cancel a 'GNUNET_TRANSPORT_get_hello' operation.
276 struct GNUNET_TRANSPORT_GetHelloHandle;
280 * Checks if a neighbour is connected
282 * @param handle connection to transport service
283 * @peer the peer to check
284 * @return GNUNET_YES or GNUNET_NO
288 GNUNET_TRANSPORT_check_neighbour_connected (struct GNUNET_TRANSPORT_Handle *handle,
289 const struct GNUNET_PeerIdentity *peer);
293 * Set transport metrics for a peer and a direction
295 * @param handle transport handle
296 * @param peer the peer to set the metric for
297 * @param direction can be: TM_SEND, TM_RECV, TM_BOTH
298 * @param ats the metric as ATS information
299 * @param ats_count the number of metrics
301 * Supported ATS values:
302 * GNUNET_ATS_QUALITY_NET_DELAY (value in ms)
303 * GNUNET_ATS_QUALITY_NET_DISTANCE (value in #hops)
306 * To enforce a delay of 10 ms for peer p1 in sending direction use:
308 * struct GNUNET_ATS_Information ats;
309 * ats.type = ntohl (GNUNET_ATS_QUALITY_NET_DELAY);
310 * ats.value = ntohl (10);
311 * GNUNET_TRANSPORT_set_traffic_metric (th, p1, TM_SEND, &ats, 1);
314 * Delay restrictions in receiving direction will be enforced with
318 GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
319 const struct GNUNET_PeerIdentity *peer,
321 const struct GNUNET_ATS_Information *ats,
326 * Obtain updates on changes to the HELLO message for this peer. The callback
327 * given in this function is never called synchronously.
329 * @param handle connection to transport service
330 * @param rec function to call with the HELLO
331 * @param rec_cls closure for rec
332 * @return handle to cancel the operation
334 struct GNUNET_TRANSPORT_GetHelloHandle *
335 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
336 GNUNET_TRANSPORT_HelloUpdateCallback rec,
341 * Stop receiving updates about changes to our HELLO message.
343 * @param ghh handle to cancel
346 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
350 * Offer the transport service the HELLO of another peer. Note that
351 * the transport service may just ignore this message if the HELLO is
352 * malformed or useless due to our local configuration.
354 * @param handle connection to transport service
355 * @param hello the hello message
356 * @param cont continuation to call when HELLO has been sent,
357 * tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail
358 * tc reasong GNUNET_SCHEDULER_REASON_READ_READY for success
359 * @param cls closure for continuation
360 * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure,
361 * in case of failure cont will not be called
364 struct GNUNET_TRANSPORT_OfferHelloHandle *
365 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
366 const struct GNUNET_MessageHeader *hello,
367 GNUNET_SCHEDULER_Task cont, void *cls);
371 * Cancel the request to transport to offer the HELLO message
373 * @param ohh the GNUNET_TRANSPORT_OfferHelloHandle to cancel
376 GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
379 * Handle to cancel a pending address lookup.
381 struct GNUNET_TRANSPORT_AddressToStringContext;
385 * Convert a binary address into a human readable address.
387 * @param cfg configuration to use
388 * @param address address to convert (binary format)
389 * @param numeric should (IP) addresses be displayed in numeric form
390 * (otherwise do reverse DNS lookup)
391 * @param timeout how long is the lookup allowed to take at most
392 * @param aluc function to call with the results
393 * @param aluc_cls closure for aluc
394 * @return handle to cancel the operation, NULL on error
396 struct GNUNET_TRANSPORT_AddressToStringContext *
397 GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
399 const struct GNUNET_HELLO_Address *address,
401 struct GNUNET_TIME_Relative timeout,
402 GNUNET_TRANSPORT_AddressToStringCallback
403 aluc, void *aluc_cls);
407 * Cancel request for address conversion.
409 * @param alc handle for the request to cancel
412 GNUNET_TRANSPORT_address_to_string_cancel (struct
413 GNUNET_TRANSPORT_AddressToStringContext
418 * Return all the known addresses for a specific peer or all peers.
419 * Returns continuously all address if one_shot is set to GNUNET_NO
421 * CHANGE: Returns the address(es) that we are currently using for this
422 * peer. Upon completion, the 'AddressLookUpCallback' is called one more
423 * time with 'NULL' for the address and the peer. After this, the operation must no
424 * longer be explicitly cancelled.
426 * @param cfg configuration to use
427 * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers
428 * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
429 * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly canceled, NOT implemented yet!)
430 * @param timeout how long is the lookup allowed to take at most
431 * @param peer_address_callback function to call with the results
432 * @param peer_address_callback_cls closure for peer_address_callback
434 struct GNUNET_TRANSPORT_PeerIterateContext *
435 GNUNET_TRANSPORT_peer_get_active_addresses (const struct
436 GNUNET_CONFIGURATION_Handle *cfg,
437 const struct GNUNET_PeerIdentity
439 struct GNUNET_TIME_Relative timeout,
440 GNUNET_TRANSPORT_PeerIterateCallback
441 peer_address_callback,
442 void *peer_address_callback_cls);
446 * Cancel request for peer lookup.
448 * @param alc handle for the request to cancel
451 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
452 GNUNET_TRANSPORT_PeerIterateContext
457 * Handle for blacklisting peers.
459 struct GNUNET_TRANSPORT_Blacklist;
463 * Function that decides if a connection is acceptable or not.
466 * @param pid peer to approve or disapproave
467 * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not
469 typedef int (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
471 GNUNET_PeerIdentity * pid);
475 * Install a blacklist callback. The service will be queried for all
476 * existing connections as well as any fresh connections to check if
477 * they are permitted. If the blacklisting callback is unregistered,
478 * all hosts that were denied in the past will automatically be
479 * whitelisted again. Cancelling the blacklist handle is also the
480 * only way to re-enable connections from peers that were previously
483 * @param cfg configuration to use
484 * @param cb callback to invoke to check if connections are allowed
485 * @param cb_cls closure for cb
486 * @return NULL on error, otherwise handle for cancellation
488 struct GNUNET_TRANSPORT_Blacklist *
489 GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
490 GNUNET_TRANSPORT_BlacklistCallback cb,
495 * Abort the blacklist. Note that this function is the only way for
496 * removing a peer from the blacklist.
498 * @param br handle of the request that is to be cancelled
501 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
505 #if 0 /* keep Emacsens' auto-indent happy */
512 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
514 /* end of gnunet_transport_service.h */