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 binary format of an address
105 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
107 typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
108 const char *address);
112 * Function to call with a binary format of an address
115 * @param peer peer identity
116 * @param transport transport plugin
117 * @param addr address
118 * @param addrlen address length
120 // FIXME: use GNUNET_HELLO_Address (as 2nd arg, replacing others)
121 // FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO)
122 typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
123 const struct GNUNET_HELLO_Address *address);
127 * Connect to the transport service. Note that the connection may
128 * complete (or fail) asynchronously.
130 * @param cfg configuration to use
131 * @param self our own identity (API should check that it matches
132 * the identity found by transport), or NULL (no check)
133 * @param cls closure for the callbacks
134 * @param rec receive function to call
135 * @param nc function to call on connect events
136 * @param nd function to call on disconnect events
137 * @return NULL on error
139 struct GNUNET_TRANSPORT_Handle *
140 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
141 const struct GNUNET_PeerIdentity *self, void *cls,
142 GNUNET_TRANSPORT_ReceiveCallback rec,
143 GNUNET_TRANSPORT_NotifyConnect nc,
144 GNUNET_TRANSPORT_NotifyDisconnect nd);
148 * Disconnect from the transport service.
150 * @param handle handle returned from connect
153 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
157 * Ask the transport service to establish a connection to
160 * @param handle connection to transport service
161 * @param target who we should try to connect to
164 GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
165 const struct GNUNET_PeerIdentity *target);
169 * Opaque handle for a transmission-ready request.
171 struct GNUNET_TRANSPORT_TransmitHandle;
175 * Check if we could queue a message of the given size for
176 * transmission. The transport service will take both its internal
177 * buffers and bandwidth limits imposed by the other peer into
178 * consideration when answering this query.
180 * @param handle connection to transport service
181 * @param target who should receive the message
182 * @param size how big is the message we want to transmit?
183 * @param priority how important is the message? @deprecated - remove?
184 * @param timeout after how long should we give up (and call
185 * notify with buf NULL and size 0)?
186 * @param notify function to call when we are ready to
187 * send such a message
188 * @param notify_cls closure for notify
189 * @return NULL if someone else is already waiting to be notified
190 * non-NULL if the notify callback was queued (can be used to cancel
191 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
193 struct GNUNET_TRANSPORT_TransmitHandle *
194 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
195 const struct GNUNET_PeerIdentity
196 *target, size_t size, uint32_t priority,
197 struct GNUNET_TIME_Relative timeout,
198 GNUNET_CONNECTION_TransmitReadyNotify
199 notify, void *notify_cls);
203 * Cancel the specified transmission-ready notification.
205 * @param th handle of the transmission notification request to cancel
208 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
209 GNUNET_TRANSPORT_TransmitHandle
215 * Function called whenever there is an update to the
216 * HELLO of this peer.
219 * @param hello our updated HELLO
221 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
223 GNUNET_MessageHeader *
228 * Handle to cancel a 'GNUNET_TRANSPORT_get_hello' operation.
230 struct GNUNET_TRANSPORT_GetHelloHandle;
234 * Obtain updates on changes to the HELLO message for this peer.
236 * @param handle connection to transport service
237 * @param rec function to call with the HELLO
238 * @param rec_cls closure for rec
239 * @return handle to cancel the operation
241 struct GNUNET_TRANSPORT_GetHelloHandle *
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 ghh handle returned from 'GNUNET_TRANSPORT_get_hello')
253 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
257 * Offer the transport service the HELLO of another peer. Note that
258 * the transport service may just ignore this message if the HELLO is
259 * malformed or useless due to our local configuration.
261 * @param handle connection to transport service
262 * @param hello the hello message
263 * @param cont continuation to call when HELLO has been sent
264 * @param cls closure for continuation
267 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
268 const struct GNUNET_MessageHeader *hello,
269 GNUNET_SCHEDULER_Task cont, void *cls);
273 * Handle to cancel a pending address lookup.
275 struct GNUNET_TRANSPORT_AddressToStringContext;
279 * Convert a binary address into a human readable address.
281 * @param cfg configuration to use
282 * @param address address to convert (binary format)
283 * @param addressLen number of bytes in address
284 * @param numeric should (IP) addresses be displayed in numeric form
285 * (otherwise do reverse DNS lookup)
286 * @param nameTrans name of the transport to which the address belongs
287 * @param timeout how long is the lookup allowed to take at most
288 * @param aluc function to call with the results
289 * @param aluc_cls closure for aluc
290 * @return handle to cancel the operation, NULL on error
292 struct GNUNET_TRANSPORT_AddressToStringContext *
293 GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
294 const struct GNUNET_HELLO_Address *address,
296 struct GNUNET_TIME_Relative timeout,
297 GNUNET_TRANSPORT_AddressToStringCallback aluc,
302 * Cancel request for address conversion.
304 * @param alc handle for the request to cancel
307 GNUNET_TRANSPORT_address_to_string_cancel (struct
308 GNUNET_TRANSPORT_AddressToStringContext
313 * Return all the known addresses for a peer. FIXME: document better!
314 * FIXME: use better name!
315 * CHANGE: Returns the address(es) that we are currently using for this
316 * peer. Upon completion, the 'AddressLookUpCallback' is called one more
317 * time with 'NULL' for the address and the peer. After this, the operation must no
318 * longer be explicitly cancelled.
319 * TODO: change code that uses this API to see if this is fine...
321 * @param cfg configuration to use
322 * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers
323 * FIXME: @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
324 * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly cancelled)
325 * @param timeout how long is the lookup allowed to take at most
326 * @param peer_address_callback function to call with the results
327 * @param peer_address_callback_cls closure for peer_address_callback
329 struct GNUNET_TRANSPORT_PeerAddressLookupContext *
330 GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg,
331 const struct GNUNET_PeerIdentity *peer,
332 // FIXME: add argument: one_shot
333 struct GNUNET_TIME_Relative timeout,
334 GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback,
335 void *peer_address_callback_cls);
339 * Cancel request for peer lookup.
341 * @param alc handle for the request to cancel
344 GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
345 GNUNET_TRANSPORT_PeerAddressLookupContext
350 * Return all the known addresses. FIXME: document better!
352 * FIXME: remove, replace with new 'peer_address_lookup' API
355 * @param cfg configuration to use
356 * @param timeout how long is the lookup allowed to take at most
357 * @param peer_address_callback function to call with the results
358 * @param peer_address_callback_cls closure for peer_address_callback
361 GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
362 struct GNUNET_TIME_Relative timeout,
363 GNUNET_TRANSPORT_AddressLookUpCallback
364 peer_address_callback,
365 void *peer_address_callback_cls);
369 * Handle for blacklisting peers.
371 struct GNUNET_TRANSPORT_Blacklist;
375 * Function that decides if a connection is acceptable or not.
378 * @param pid peer to approve or disapproave
379 * @return GNUNET_OK if the connection is allowed
381 typedef int (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
383 GNUNET_PeerIdentity * pid);
387 * Install a blacklist callback. The service will be queried for all
388 * existing connections as well as any fresh connections to check if
389 * they are permitted. If the blacklisting callback is unregistered,
390 * all hosts that were denied in the past will automatically be
391 * whitelisted again. Cancelling the blacklist handle is also the
392 * only way to re-enable connections from peers that were previously
395 * @param cfg configuration to use
396 * @param cb callback to invoke to check if connections are allowed
397 * @param cb_cls closure for cb
398 * @return NULL on error, otherwise handle for cancellation
400 struct GNUNET_TRANSPORT_Blacklist *
401 GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
402 GNUNET_TRANSPORT_BlacklistCallback cb,
407 * Abort the blacklist. Note that this function is the only way for
408 * removing a peer from the blacklist.
410 * @param br handle of the request that is to be cancelled
413 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
417 #if 0 /* keep Emacsens' auto-indent happy */
424 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
426 /* end of gnunet_transport_service.h */