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 a textual representation of an address.
103 * This function will be called several times with different possible
104 * textual representations, and a last time with NULL to signal the end
108 * @param address NULL on error or end of iteration,
109 * otherwise 0-terminated printable UTF-8 string
111 typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
112 const char *address);
116 * Function to call with a binary format of an address
119 * @param peer peer this update is about (never NULL)
120 * @param address address, NULL for disconnect notification in monitor mode
122 typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
124 GNUNET_PeerIdentity *
127 GNUNET_HELLO_Address *
132 * Connect to the transport service. Note that the connection may
133 * complete (or fail) asynchronously.
135 * @param cfg configuration to use
136 * @param self our own identity (API should check that it matches
137 * the identity found by transport), or NULL (no check)
138 * @param cls closure for the callbacks
139 * @param rec receive function to call
140 * @param nc function to call on connect events
141 * @param nd function to call on disconnect events
142 * @return NULL on error
144 struct GNUNET_TRANSPORT_Handle *
145 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
146 const struct GNUNET_PeerIdentity *self, void *cls,
147 GNUNET_TRANSPORT_ReceiveCallback rec,
148 GNUNET_TRANSPORT_NotifyConnect nc,
149 GNUNET_TRANSPORT_NotifyDisconnect nd);
153 * Disconnect from the transport service.
155 * @param handle handle returned from connect
158 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
162 * Ask the transport service to establish a connection to
165 * @param handle connection to transport service
166 * @param target who we should try to connect to
169 GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
170 const struct GNUNET_PeerIdentity *target);
174 * Opaque handle for a transmission-ready request.
176 struct GNUNET_TRANSPORT_TransmitHandle;
180 * Check if we could queue a message of the given size for
181 * transmission. The transport service will take both its internal
182 * buffers and bandwidth limits imposed by the other peer into
183 * consideration when answering this query.
185 * @param handle connection to transport service
186 * @param target who should receive the message
187 * @param size how big is the message we want to transmit?
188 * @param priority how important is the message? @deprecated - remove?
189 * @param timeout after how long should we give up (and call
190 * notify with buf NULL and size 0)?
191 * @param notify function to call when we are ready to
192 * send such a message
193 * @param notify_cls closure for notify
194 * @return NULL if someone else is already waiting to be notified
195 * non-NULL if the notify callback was queued (can be used to cancel
196 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
198 struct GNUNET_TRANSPORT_TransmitHandle *
199 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
200 const struct GNUNET_PeerIdentity
201 *target, size_t size, uint32_t priority,
202 struct GNUNET_TIME_Relative timeout,
203 GNUNET_CONNECTION_TransmitReadyNotify
204 notify, void *notify_cls);
208 * Cancel the specified transmission-ready notification.
210 * @param th handle of the transmission notification request to cancel
213 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
214 GNUNET_TRANSPORT_TransmitHandle
220 * Function called whenever there is an update to the
221 * HELLO of this peer.
224 * @param hello our updated HELLO
226 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
228 GNUNET_MessageHeader *
233 * Handle to cancel a 'GNUNET_TRANSPORT_get_hello' operation.
235 struct GNUNET_TRANSPORT_GetHelloHandle;
239 * Obtain updates on changes to the HELLO message for this peer.
241 * @param handle connection to transport service
242 * @param rec function to call with the HELLO
243 * @param rec_cls closure for rec
244 * @return handle to cancel the operation
246 struct GNUNET_TRANSPORT_GetHelloHandle *
247 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
248 GNUNET_TRANSPORT_HelloUpdateCallback rec,
253 * Stop receiving updates about changes to our HELLO message.
255 * @param ghh handle returned from 'GNUNET_TRANSPORT_get_hello')
258 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
262 * Offer the transport service the HELLO of another peer. Note that
263 * the transport service may just ignore this message if the HELLO is
264 * malformed or useless due to our local configuration.
266 * @param handle connection to transport service
267 * @param hello the hello message
268 * @param cont continuation to call when HELLO has been sent
269 * @param cls closure for continuation
272 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
273 const struct GNUNET_MessageHeader *hello,
274 GNUNET_SCHEDULER_Task cont, void *cls);
278 * Handle to cancel a pending address lookup.
280 struct GNUNET_TRANSPORT_AddressToStringContext;
284 * Convert a binary address into a human readable address.
286 * @param cfg configuration to use
287 * @param address address to convert (binary format)
288 * @param numeric should (IP) addresses be displayed in numeric form
289 * (otherwise do reverse DNS lookup)
290 * @param timeout how long is the lookup allowed to take at most
291 * @param aluc function to call with the results
292 * @param aluc_cls closure for aluc
293 * @return handle to cancel the operation, NULL on error
295 struct GNUNET_TRANSPORT_AddressToStringContext *
296 GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle
298 const struct GNUNET_HELLO_Address *address,
300 struct GNUNET_TIME_Relative timeout,
301 GNUNET_TRANSPORT_AddressToStringCallback
302 aluc, void *aluc_cls);
306 * Cancel request for address conversion.
308 * @param alc handle for the request to cancel
311 GNUNET_TRANSPORT_address_to_string_cancel (struct
312 GNUNET_TRANSPORT_AddressToStringContext
317 * Return all the known addresses for a specific peer or all peers.
318 * Returns continously all address if one_shot is set to GNUNET_NO
320 * CHANGE: Returns the address(es) that we are currently using for this
321 * peer. Upon completion, the 'AddressLookUpCallback' is called one more
322 * time with 'NULL' for the address and the peer. After this, the operation must no
323 * longer be explicitly cancelled.
325 * @param cfg configuration to use
326 * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers
327 * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
328 * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly canceled, NOT implemented yet!)
329 * @param timeout how long is the lookup allowed to take at most
330 * @param peer_address_callback function to call with the results
331 * @param peer_address_callback_cls closure for peer_address_callback
333 struct GNUNET_TRANSPORT_PeerIterateContext *
334 GNUNET_TRANSPORT_peer_get_active_addresses (const struct
335 GNUNET_CONFIGURATION_Handle *cfg,
336 const struct GNUNET_PeerIdentity
338 struct GNUNET_TIME_Relative timeout,
339 GNUNET_TRANSPORT_PeerIterateCallback
340 peer_address_callback,
341 void *peer_address_callback_cls);
345 * Cancel request for peer lookup.
347 * @param alc handle for the request to cancel
350 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
351 GNUNET_TRANSPORT_PeerIterateContext
356 * Handle for blacklisting peers.
358 struct GNUNET_TRANSPORT_Blacklist;
362 * Function that decides if a connection is acceptable or not.
365 * @param pid peer to approve or disapproave
366 * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not
368 typedef int (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
370 GNUNET_PeerIdentity * pid);
374 * Install a blacklist callback. The service will be queried for all
375 * existing connections as well as any fresh connections to check if
376 * they are permitted. If the blacklisting callback is unregistered,
377 * all hosts that were denied in the past will automatically be
378 * whitelisted again. Cancelling the blacklist handle is also the
379 * only way to re-enable connections from peers that were previously
382 * @param cfg configuration to use
383 * @param cb callback to invoke to check if connections are allowed
384 * @param cb_cls closure for cb
385 * @return NULL on error, otherwise handle for cancellation
387 struct GNUNET_TRANSPORT_Blacklist *
388 GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
389 GNUNET_TRANSPORT_BlacklistCallback cb,
394 * Abort the blacklist. Note that this function is the only way for
395 * removing a peer from the blacklist.
397 * @param br handle of the request that is to be cancelled
400 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
404 #if 0 /* keep Emacsens' auto-indent happy */
411 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
413 /* end of gnunet_transport_service.h */