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 *
65 * Opaque handle to the service.
67 struct GNUNET_TRANSPORT_Handle;
71 * Function called to notify transport users that another
72 * peer connected to us.
75 * @param peer the peer that connected
76 * @param ats performance data
77 * @param ats_count number of entries in ats (excluding 0-termination)
79 typedef void (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
80 const struct GNUNET_PeerIdentity
84 * Function called to notify transport users that another
85 * peer disconnected from us.
88 * @param peer the peer that disconnected
90 typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
92 GNUNET_PeerIdentity * peer);
96 * Function to call with result of the try connect request.
100 * @param result GNUNET_OK if message was transmitted to transport service
101 * GNUNET_SYSERR if message was not transmitted to transport service
103 typedef void (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls,
108 * Function to call with a textual representation of an address.
109 * This function will be called several times with different possible
110 * textual representations, and a last time with NULL to signal the end
114 * @param address NULL on error or end of iteration,
115 * otherwise 0-terminated printable UTF-8 string
117 typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
118 const char *address);
122 * Function to call with a binary format of an address
125 * @param peer peer this update is about (never NULL)
126 * @param address address, NULL for disconnect notification in monitor mode
128 typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
130 GNUNET_PeerIdentity *
133 GNUNET_HELLO_Address *
138 * Connect to the transport service. Note that the connection may
139 * complete (or fail) asynchronously.
141 * @param cfg configuration to use
142 * @param self our own identity (API should check that it matches
143 * the identity found by transport), or NULL (no check)
144 * @param cls closure for the callbacks
145 * @param rec receive function to call, or NULL
146 * @param nc function to call on connect events, or NULL
147 * @param nd function to call on disconnect events, or NULL
148 * @return NULL on error
150 struct GNUNET_TRANSPORT_Handle *
151 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
152 const struct GNUNET_PeerIdentity *self, void *cls,
153 GNUNET_TRANSPORT_ReceiveCallback rec,
154 GNUNET_TRANSPORT_NotifyConnect nc,
155 GNUNET_TRANSPORT_NotifyDisconnect nd);
159 * Disconnect from the transport service.
161 * @param handle handle returned from connect
164 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
168 * Opaque handle for a transmission-ready request.
170 struct GNUNET_TRANSPORT_TryConnectHandle;
174 * Ask the transport service to establish a connection to
177 * @param handle connection to transport service
178 * @param target who we should try to connect to
179 * @param cb callback to be called when request was transmitted to transport
181 * @param cb_cls closure for the callback
182 * @return a GNUNET_TRANSPORT_TryConnectHandle handle or
183 * NULL on failure (cb will not be called)
185 struct GNUNET_TRANSPORT_TryConnectHandle *
186 GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
187 const struct GNUNET_PeerIdentity *target,
188 GNUNET_TRANSPORT_TryConnectCallback cb,
193 * Cancel the request to transport to try a connect
194 * Callback will not be called
196 * @param tch GNUNET_TRANSPORT_TryConnectHandle handle to cancel
199 GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch);
203 * Opaque handle for a transmission-ready request.
205 struct GNUNET_TRANSPORT_TransmitHandle;
209 * Check if we could queue a message of the given size for
210 * transmission. The transport service will take both its internal
211 * buffers and bandwidth limits imposed by the other peer into
212 * consideration when answering this query.
214 * @param handle connection to transport service
215 * @param target who should receive the message
216 * @param size how big is the message we want to transmit?
217 * @param priority how important is the message? @deprecated - remove?
218 * @param timeout after how long should we give up (and call
219 * notify with buf NULL and size 0)?
220 * @param notify function to call when we are ready to
221 * send such a message
222 * @param notify_cls closure for notify
223 * @return NULL if someone else is already waiting to be notified
224 * non-NULL if the notify callback was queued (can be used to cancel
225 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
227 struct GNUNET_TRANSPORT_TransmitHandle *
228 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
229 const struct GNUNET_PeerIdentity
230 *target, size_t size, uint32_t priority,
231 struct GNUNET_TIME_Relative timeout,
232 GNUNET_CONNECTION_TransmitReadyNotify
233 notify, void *notify_cls);
237 * Cancel the specified transmission-ready notification.
239 * @param th handle of the transmission notification request to cancel
242 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
243 GNUNET_TRANSPORT_TransmitHandle
249 * Function called whenever there is an update to the
250 * HELLO of this peer.
253 * @param hello our updated HELLO
255 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
257 GNUNET_MessageHeader *
262 * Handle to cancel a 'GNUNET_TRANSPORT_get_hello' operation.
264 struct GNUNET_TRANSPORT_GetHelloHandle;
268 * Checks if a neighbour is connected
270 * @param handle connection to transport service
271 * @param peer the peer to check
272 * @return GNUNET_YES or GNUNET_NO
276 GNUNET_TRANSPORT_check_neighbour_connected (struct GNUNET_TRANSPORT_Handle *handle,
277 const struct GNUNET_PeerIdentity *peer);
281 * Set transport metrics for a peer and a direction
283 * @param handle transport handle
284 * @param peer the peer to set the metric for
285 * @param inbound set inbound direction (GNUNET_YES or GNUNET_NO)
286 * @param outbound set outbound direction (GNUNET_YES or GNUNET_NO)
287 * @param ats the metric as ATS information
288 * @param ats_count the number of metrics
290 * Supported ATS values:
291 * GNUNET_ATS_QUALITY_NET_DELAY (value in ms)
292 * GNUNET_ATS_QUALITY_NET_DISTANCE (value in count(hops))
295 * To enforce a delay of 10 ms for peer p1 in sending direction use:
297 * struct GNUNET_ATS_Information ats;
298 * ats.type = ntohl (GNUNET_ATS_QUALITY_NET_DELAY);
299 * ats.value = ntohl (10);
300 * GNUNET_TRANSPORT_set_traffic_metric (th, p1, TM_SEND, &ats, 1);
303 * Delay restrictions in receiving direction will be enforced with
307 GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
308 const struct GNUNET_PeerIdentity *peer,
311 const struct GNUNET_ATS_Information *ats,
316 * Obtain updates on changes to the HELLO message for this peer. The callback
317 * given in this function is never called synchronously.
319 * @param handle connection to transport service
320 * @param rec function to call with the HELLO
321 * @param rec_cls closure for rec
322 * @return handle to cancel the operation
324 struct GNUNET_TRANSPORT_GetHelloHandle *
325 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
326 GNUNET_TRANSPORT_HelloUpdateCallback rec,
331 * Stop receiving updates about changes to our HELLO message.
333 * @param ghh handle to cancel
336 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
340 * Offer the transport service the HELLO of another peer. Note that
341 * the transport service may just ignore this message if the HELLO is
342 * malformed or useless due to our local configuration.
344 * @param handle connection to transport service
345 * @param hello the hello message
346 * @param cont continuation to call when HELLO has been sent,
347 * tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail
348 * tc reasong GNUNET_SCHEDULER_REASON_READ_READY for success
349 * @param cls closure for continuation
350 * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure,
351 * in case of failure cont will not be called
354 struct GNUNET_TRANSPORT_OfferHelloHandle *
355 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
356 const struct GNUNET_MessageHeader *hello,
357 GNUNET_SCHEDULER_Task cont, void *cls);
361 * Cancel the request to transport to offer the HELLO message
363 * @param ohh the GNUNET_TRANSPORT_OfferHelloHandle to cancel
366 GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
370 * Handle to cancel a pending address lookup.
372 struct GNUNET_TRANSPORT_AddressToStringContext;
376 * Convert a binary address into a human readable address.
378 * @param cfg configuration to use
379 * @param address address to convert (binary format)
380 * @param numeric should (IP) addresses be displayed in numeric form
381 * (otherwise do reverse DNS lookup)
382 * @param timeout how long is the lookup allowed to take at most
383 * @param aluc function to call with the results
384 * @param aluc_cls closure for aluc
385 * @return handle to cancel the operation, NULL on error
387 struct GNUNET_TRANSPORT_AddressToStringContext *
388 GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
390 const struct GNUNET_HELLO_Address *address,
392 struct GNUNET_TIME_Relative timeout,
393 GNUNET_TRANSPORT_AddressToStringCallback
394 aluc, void *aluc_cls);
398 * Cancel request for address conversion.
400 * @param alc handle for the request to cancel
403 GNUNET_TRANSPORT_address_to_string_cancel (struct
404 GNUNET_TRANSPORT_AddressToStringContext
409 * Return all the known addresses for a specific peer or all peers.
410 * Returns continuously all address if one_shot is set to GNUNET_NO
412 * CHANGE: Returns the address(es) that we are currently using for this
413 * peer. Upon completion, the 'AddressLookUpCallback' is called one more
414 * time with 'NULL' for the address and the peer. After this, the operation must no
415 * longer be explicitly cancelled.
417 * @param cfg configuration to use
418 * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers
419 * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
420 * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly canceled, NOT implemented yet!)
421 * @param timeout how long is the lookup allowed to take at most
422 * @param peer_address_callback function to call with the results
423 * @param peer_address_callback_cls closure for peer_address_callback
425 struct GNUNET_TRANSPORT_PeerIterateContext *
426 GNUNET_TRANSPORT_peer_get_active_addresses (const struct
427 GNUNET_CONFIGURATION_Handle *cfg,
428 const struct GNUNET_PeerIdentity
430 struct GNUNET_TIME_Relative timeout,
431 GNUNET_TRANSPORT_PeerIterateCallback
432 peer_address_callback,
433 void *peer_address_callback_cls);
437 * Cancel request for peer lookup.
439 * @param alc handle for the request to cancel
442 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
443 GNUNET_TRANSPORT_PeerIterateContext
448 * Handle for blacklisting peers.
450 struct GNUNET_TRANSPORT_Blacklist;
454 * Function that decides if a connection is acceptable or not.
457 * @param pid peer to approve or disapproave
458 * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not
460 typedef int (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
462 GNUNET_PeerIdentity * pid);
466 * Install a blacklist callback. The service will be queried for all
467 * existing connections as well as any fresh connections to check if
468 * they are permitted. If the blacklisting callback is unregistered,
469 * all hosts that were denied in the past will automatically be
470 * whitelisted again. Cancelling the blacklist handle is also the
471 * only way to re-enable connections from peers that were previously
474 * @param cfg configuration to use
475 * @param cb callback to invoke to check if connections are allowed
476 * @param cb_cls closure for cb
477 * @return NULL on error, otherwise handle for cancellation
479 struct GNUNET_TRANSPORT_Blacklist *
480 GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
481 GNUNET_TRANSPORT_BlacklistCallback cb,
486 * Abort the blacklist. Note that this function is the only way for
487 * removing a peer from the blacklist.
489 * @param br handle of the request that is to be cancelled
492 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
496 #if 0 /* keep Emacsens' auto-indent happy */
503 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
505 /* end of gnunet_transport_service.h */